1 /*
2 * Copyright (c) 2022 Jiangsu Hoperun Software Co., Ltd.
3 *
4 * This file is dual licensed: you can use it either under the terms of
5 * the GPL, or the BSD license, at your option.
6 * See the LICENSE file in the root of this repository for complete details.
7 */
8 #include <stdlib.h>
9 #include <string.h>
10 #include "osal_time.h"
11 #include "osal_sem.h"
12 #include "device_resource_if.h"
13 #include "hdf_log.h"
14 #include "wm_gpio_afsel.h"
15 #include "uart_if.h"
16 #include "uart_core.h"
17 #include "wm_uart.h"
18
19 #define HDF_UART_TMO 1000
20 #define TMO_MS_UNIT_CONV (1000)
21 #define HDF_LOG_TAG uartDev
22
23 #define UART_DEV_SERVICE_NAME_PREFIX "HDF_PLATFORM_UART%d"
24 #define MAX_DEV_NAME_SIZE 32
25
26 struct UartResource {
27 uint32_t num; /* UART port num */
28 uint32_t baudRate; /* Default baudrate */
29 uint32_t wLen; /* Default word length */
30 uint32_t parity; /* Default parity */
31 uint32_t stopBit; /* Default stop bits */
32 bool txDMA;
33 bool rxDMA;
34 };
35
36 enum UartDeviceState {
37 UART_DEVICE_UNINITIALIZED = 0x0u,
38 UART_DEVICE_INITIALIZED = 0x1u,
39 };
40
41 struct UART_CTX_OBJ {
42 bool txDMA;
43 bool rxDMA;
44 bool isBlock;
45 struct OsalSem rxSem;
46 struct OsalSem txSem;
47 };
48
49 struct UartDevice {
50 struct IDeviceIoService ioService;
51 struct UartResource resource;
52 tls_uart_options_t config;
53 uint32_t uartId;
54 bool initFlag;
55 uint32_t transMode;
56 };
57
58 enum {
59 UART_READ = 0,
60 UART_WRITE
61 };
62
63 static struct UART_CTX_OBJ g_uartCtx[4] = {0};
64 static unsigned char *g_uartKfifoBuffer[4] = {NULL, NULL, NULL, NULL};
65
HalSetUartIomux(int uartId)66 static void HalSetUartIomux(int uartId)
67 {
68 switch (uartId) {
69 case TLS_UART_0:
70 wm_uart0_tx_config(WM_IO_PB_19);
71 wm_uart0_rx_config(WM_IO_PB_20);
72 break;
73 case TLS_UART_1:
74 wm_uart1_tx_config(WM_IO_PB_06);
75 wm_uart1_rx_config(WM_IO_PB_07);
76 break;
77 case TLS_UART_2:
78 wm_uart2_tx_scio_config(WM_IO_PB_02);
79 wm_uart2_rx_config(WM_IO_PB_03);
80 break;
81 case TLS_UART_3:
82 wm_uart3_tx_config(WM_IO_PB_00);
83 wm_uart3_rx_config(WM_IO_PB_01);
84 break;
85 case TLS_UART_4:
86 wm_uart4_tx_config(WM_IO_PB_04);
87 wm_uart4_rx_config(WM_IO_PB_05);
88 break;
89 default:
90 HDF_LOGE("%s: uartId(%d) invalid", __func__, uartId);
91 break;
92 }
93 }
94
dma_tx_cmpl_callback(uint32_t arg)95 static void dma_tx_cmpl_callback(uint32_t arg)
96 {
97 uint32_t uartId = arg;
98 OsalSemPost(&g_uartCtx[uartId].txSem);
99 }
100
HalUartSend(uint32_t uartId,const uint8_t * data,uint32_t size,uint32_t timeOut)101 static int32_t HalUartSend(uint32_t uartId, const uint8_t *data, uint32_t size, uint32_t timeOut)
102 {
103 int32_t ret = HDF_FAILURE;
104
105 if (data == NULL || size == 0) {
106 HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__);
107 return HDF_ERR_INVALID_PARAM;
108 }
109
110 tls_uart_dma_write(data, (uint16_t)size, dma_tx_cmpl_callback, (uint16_t)uartId);
111 ret = OsalSemWait(&g_uartCtx[uartId].txSem, timeOut);
112
113 return ret;
114 }
115
HalUartRecv(uint8_t uartId,uint8_t * data,uint32_t expectSize,uint32_t * recvSize,uint32_t timeOut)116 static int32_t HalUartRecv(uint8_t uartId, uint8_t *data, uint32_t expectSize,
117 uint32_t *recvSize, uint32_t timeOut)
118 {
119 uint32_t fifoPopLen;
120 uint32_t recvedLen = 0;
121 uint32_t expectLen = expectSize;
122 OsalTimespec hdfTs1 = { 0, 0 };
123 OsalTimespec hdfTs2 = { 0, 0 };
124 OsalTimespec hdfTsDiff = { 0, 0 };
125
126 if (data == NULL || expectSize == 0 || recvSize == NULL) {
127 HDF_LOGE("%s %d Invalid input \r\n", __FILE__, __LINE__);
128 return HDF_ERR_INVALID_PARAM;
129 }
130 OsalGetTime(&hdfTs1);
131 do {
132 fifoPopLen = tls_uart_read(uartId, (uint8_t *)data + recvedLen, expectLen);
133 recvedLen += fifoPopLen;
134 expectLen -= fifoPopLen;
135 if (recvedLen >= expectSize) {
136 break;
137 }
138 /* haven't get any data from fifo */
139 if (recvedLen == 0) {
140 break;
141 }
142 /* if reaches here, it means need to wait for more data come */
143 OsalMSleep(1);
144 /* time out break */
145 OsalGetTime(&hdfTs2);
146 OsalDiffTime(&hdfTs1, &hdfTs2, &hdfTsDiff);
147 if ((uint32_t)(hdfTsDiff.sec * TMO_MS_UNIT_CONV + hdfTsDiff.usec / TMO_MS_UNIT_CONV) >= timeOut) {
148 break;
149 }
150 } while (true);
151
152 *recvSize = recvedLen;
153 return HDF_SUCCESS;
154 }
155
HalUartHandlerInit(const struct UartDevice * device)156 static void HalUartHandlerInit(const struct UartDevice *device)
157 {
158 uint32_t uartId;
159
160 if (device == NULL) {
161 HDF_LOGE("%s: INVALID PARAM", __func__);
162 return;
163 }
164
165 uartId = device->uartId;
166 OsalSemInit(&g_uartCtx[uartId].rxSem, 0);
167 OsalSemInit(&g_uartCtx[uartId].txSem, 0);
168 }
169
UartStart(struct UartDevice * device)170 static void UartStart(struct UartDevice *device)
171 {
172 uint32_t uartId;
173 tls_uart_options_t *uartCfg = NULL;
174 if (device == NULL) {
175 HDF_LOGE("%s: INVALID PARAM", __func__);
176 return;
177 }
178 uartId = device->uartId;
179 uartCfg = &device->config;
180 if (uartCfg == NULL) {
181 HDF_LOGE("%s: INVALID OBJECT", __func__);
182 return;
183 }
184 if (WM_SUCCESS != tls_uart_port_init(uartId, uartCfg, 0)) {
185 HDF_LOGE("uart %d init error", uartId);
186 }
187 HDF_LOGI("%s %ld\r\n", __FUNCTION__, uartId);
188 HalUartHandlerInit(device);
189 }
190
191 /* HdfDriverEntry method definitions */
192 static int32_t UartDriverBind(struct HdfDeviceObject *device);
193 static int32_t UartDriverInit(struct HdfDeviceObject *device);
194 static void UartDriverRelease(struct HdfDeviceObject *device);
195
196 /* HdfDriverEntry definitions */
197 struct HdfDriverEntry g_UartDriverEntry = {
198 .moduleVersion = 1,
199 .moduleName = "W800_UART_MODULE_HDF",
200 .Bind = UartDriverBind,
201 .Init = UartDriverInit,
202 .Release = UartDriverRelease,
203 };
204
205 /* Initialize HdfDriverEntry */
206 HDF_INIT(g_UartDriverEntry);
207
208 /* UartHostMethod method definitions */
209 static int32_t UartHostDevInit(struct UartHost *host);
210 static int32_t UartHostDevDeinit(struct UartHost *host);
211 static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t size);
212 static int32_t UartHostDevSetBaud(struct UartHost *host, uint32_t baudRate);
213 static int32_t UartHostDevGetBaud(struct UartHost *host, uint32_t *baudRate);
214 static int32_t UartHostDevRead(struct UartHost *host, uint8_t *data, uint32_t size);
215 static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribute *attribute);
216 static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribute *attribute);
217 static int32_t UartHostDevSetTransMode(struct UartHost *host, enum UartTransMode mode);
218
219 /* UartHostMethod definitions */
220 struct UartHostMethod g_uartHostMethod = {
221 .Init = UartHostDevInit,
222 .Deinit = UartHostDevDeinit,
223 .Read = UartHostDevRead,
224 .Write = UartHostDevWrite,
225 .SetBaud = UartHostDevSetBaud,
226 .GetBaud = UartHostDevGetBaud,
227 .SetAttribute = UartHostDevSetAttribute,
228 .GetAttribute = UartHostDevGetAttribute,
229 .SetTransMode = UartHostDevSetTransMode,
230 };
231
InitUartDevice(struct UartHost * host)232 static int InitUartDevice(struct UartHost *host)
233 {
234 HDF_LOGI("%s: Enter", __func__);
235 struct UartDevice *uartDevice = NULL;
236
237 if (host == NULL || host->priv == NULL) {
238 HDF_LOGE("%s: invalid parameter", __func__);
239 return HDF_ERR_INVALID_PARAM;
240 }
241
242 uartDevice = (struct UartDevice *)host->priv;
243 if (!uartDevice->initFlag) {
244 HDF_LOGI("uart %ld device init", uartDevice->uartId);
245 HalSetUartIomux(uartDevice->uartId);
246 UartStart(uartDevice);
247 uartDevice->initFlag = true;
248 }
249
250 return HDF_SUCCESS;
251 }
252
GetUartDeviceResource(struct UartDevice * device,const struct DeviceResourceNode * resourceNode)253 static uint32_t GetUartDeviceResource(struct UartDevice *device, const struct DeviceResourceNode *resourceNode)
254 {
255 struct DeviceResourceIface *dri = NULL;
256 struct UartResource *resource = NULL;
257 if (device == NULL || resourceNode == NULL) {
258 HDF_LOGE("%s: INVALID PARAM", __func__);
259 return HDF_ERR_INVALID_PARAM;
260 }
261 resource = &device->resource;
262 if (resource == NULL) {
263 HDF_LOGE("%s: INVALID OBJECT", __func__);
264 return HDF_ERR_INVALID_OBJECT;
265 }
266
267 dri = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
268 if (dri == NULL || dri->GetUint32 == NULL) {
269 HDF_LOGE("DeviceResourceIface is invalid");
270 return HDF_ERR_INVALID_PARAM;
271 }
272 if (dri->GetUint32(resourceNode, "num", &resource->num, 0) != HDF_SUCCESS) {
273 HDF_LOGE("uart config read num fail");
274 return HDF_FAILURE;
275 }
276 if (dri->GetUint32(resourceNode, "baudrate", &resource->baudRate, 0) != HDF_SUCCESS) {
277 HDF_LOGE("uart config read baudrate fail");
278 return HDF_FAILURE;
279 }
280 if (dri->GetUint32(resourceNode, "parity", &resource->parity, 0) != HDF_SUCCESS) {
281 HDF_LOGE("uart config read parity fail");
282 return HDF_FAILURE;
283 }
284 if (dri->GetUint32(resourceNode, "stopBit", &resource->stopBit, 0) != HDF_SUCCESS) {
285 HDF_LOGE("uart config read stopBit fail");
286 return HDF_FAILURE;
287 }
288
289 HDF_LOGI("%d, %d, %d", resource->num, resource->baudRate, resource->parity);
290
291 // copy config
292 device->uartId = resource->num;
293 device->config.baudrate = resource->baudRate;
294 device->config.paritytype = (TLS_UART_PMODE_T)resource->parity;
295 device->config.stopbits = (TLS_UART_STOPBITS_T)resource->stopBit;
296 device->config.charlength = TLS_UART_CHSIZE_8BIT;
297 device->config.flow_ctrl = TLS_UART_FLOW_CTRL_NONE;
298 return HDF_SUCCESS;
299 }
300
AttachUartDevice(struct UartHost * uartHost,const struct HdfDeviceObject * device)301 static int32_t AttachUartDevice(struct UartHost *uartHost, const struct HdfDeviceObject *device)
302 {
303 int32_t ret;
304 struct UartDevice *uartDevice = NULL;
305
306 if (uartHost == NULL || device == NULL || device->property == NULL) {
307 HDF_LOGE("%s: property is NULL", __func__);
308 return HDF_ERR_INVALID_PARAM;
309 }
310
311 uartDevice = (struct UartDevice *)OsalMemAlloc(sizeof(struct UartDevice));
312 if (uartDevice == NULL) {
313 HDF_LOGE("%s: OsalMemCalloc uartDevice error", __func__);
314 return HDF_ERR_MALLOC_FAIL;
315 }
316
317 ret = GetUartDeviceResource(uartDevice, device->property);
318 if (ret != HDF_SUCCESS) {
319 (void)OsalMemFree(uartDevice);
320 return HDF_FAILURE;
321 }
322
323 uartHost->priv = uartDevice;
324
325 return InitUartDevice(uartHost);
326 }
327
UartDriverBind(struct HdfDeviceObject * device)328 static int32_t UartDriverBind(struct HdfDeviceObject *device)
329 {
330 struct UartHost *devService;
331 if (device == NULL) {
332 HDF_LOGE("%s: invalid parameter", __func__);
333 return HDF_ERR_INVALID_PARAM;
334 }
335 devService = (struct UartHost *)OsalMemAlloc(sizeof(*devService));
336 if (devService == NULL) {
337 HDF_LOGE("%s: OsalMemCalloc error", __func__);
338 return HDF_ERR_INVALID_OBJECT;
339 }
340 devService->device = device;
341 device->service = &(devService->service);
342 devService->priv = NULL;
343 devService->method = NULL;
344 return HDF_SUCCESS;
345 }
346
UartDriverRelease(struct HdfDeviceObject * device)347 static void UartDriverRelease(struct HdfDeviceObject *device)
348 {
349 HDF_LOGI("Enter %s:", __func__);
350 uint32_t uartId;
351 struct UartHost *host = NULL;
352 struct UartDevice *uartDevice = NULL;
353
354 if (device == NULL) {
355 HDF_LOGE("%s: device is NULL", __func__);
356 return;
357 }
358
359 host = UartHostFromDevice(device);
360 if (host == NULL || host->priv == NULL) {
361 HDF_LOGE("%s: host is NULL", __func__);
362 return;
363 }
364
365 uartDevice = (struct UartDevice *)host->priv;
366 uartId = uartDevice->uartId;
367 host->method = NULL;
368
369 OsalSemDestroy(&g_uartCtx[uartId].rxSem);
370 OsalSemDestroy(&g_uartCtx[uartId].txSem);
371 OsalMemFree(uartDevice);
372 OsalMemFree(host);
373 }
374
UartDriverInit(struct HdfDeviceObject * device)375 static int32_t UartDriverInit(struct HdfDeviceObject *device)
376 {
377 HDF_LOGI("Enter %s:", __func__);
378 int32_t ret;
379 struct UartHost *host = NULL;
380
381 if (device == NULL) {
382 HDF_LOGE("%s: device is NULL", __func__);
383 return HDF_ERR_INVALID_OBJECT;
384 }
385
386 host = UartHostFromDevice(device);
387 if (host == NULL) {
388 HDF_LOGE("%s: host is NULL", __func__);
389 return HDF_ERR_INVALID_OBJECT;
390 }
391
392 ret = AttachUartDevice(host, device);
393 if (ret != HDF_SUCCESS) {
394 HDF_LOGE("%s: attach error", __func__);
395 return HDF_FAILURE;
396 }
397
398 host->method = &g_uartHostMethod;
399
400 return ret;
401 }
402
403 /* UartHostMethod implementations */
UartHostDevInit(struct UartHost * host)404 static int32_t UartHostDevInit(struct UartHost *host)
405 {
406 HDF_LOGI("%s: Enter\r\n", __func__);
407 if (host == NULL) {
408 HDF_LOGE("%s: invalid parameter", __func__);
409 return HDF_ERR_INVALID_PARAM;
410 }
411 InitUartDevice(host);
412 return HDF_SUCCESS;
413 }
414
UartHostDevDeinit(struct UartHost * host)415 static int32_t UartHostDevDeinit(struct UartHost *host)
416 {
417 HDF_LOGI("%s: Enter", __func__);
418 uint32_t uartId;
419 struct UartDevice *uartDevice = NULL;
420
421 if (host == NULL || host->priv == NULL) {
422 HDF_LOGE("%s: invalid parameter", __func__);
423 return HDF_ERR_INVALID_PARAM;
424 }
425
426 uartDevice = (struct UartDevice *)host->priv;
427 uartId = uartDevice->uartId;
428 uartDevice->initFlag = false;
429 return HDF_SUCCESS;
430 }
UartHostDevWrite(struct UartHost * host,uint8_t * data,uint32_t size)431 static int32_t UartHostDevWrite(struct UartHost *host, uint8_t *data, uint32_t size)
432 {
433 struct UartDevice *device = NULL;
434 uint32_t portId;
435
436 if (host == NULL || data == NULL || size == 0 || host->priv == NULL) {
437 HDF_LOGE("%s: invalid parameter", __func__);
438 return HDF_ERR_INVALID_PARAM;
439 }
440
441 device = (struct UartDevice *)host->priv;
442 portId = device->uartId;
443 if (g_uartCtx[portId].txDMA) {
444 return HalUartSend(portId, data, size, HDF_UART_TMO);
445 } else {
446 if (tls_uart_write(portId, data, size) < 0) {
447 return HDF_FAILURE;
448 }
449 }
450 return HDF_SUCCESS;
451 }
452
UartHostDevRead(struct UartHost * host,uint8_t * data,uint32_t size)453 static int32_t UartHostDevRead(struct UartHost *host, uint8_t *data, uint32_t size)
454 {
455 uint32_t recvSize = 0;
456 int32_t ret;
457 uint32_t uartId;
458 struct UartDevice *uartDevice = NULL;
459
460 if (host == NULL || data == NULL || host->priv == NULL) {
461 HDF_LOGE("%s: invalid parameter", __func__);
462 return HDF_ERR_INVALID_PARAM;
463 }
464
465 uartDevice = (struct UartDevice *)host->priv;
466 uartId = uartDevice->uartId;
467 if (g_uartCtx[uartId].rxDMA) {
468 ret = HalUartRecv(uartId, data, size, &recvSize, HDF_UART_TMO);
469 if (ret != HDF_SUCCESS) {
470 HDF_LOGE("uart %ld recev error\r\n", uartId);
471 return ret;
472 }
473 ret = recvSize;
474 } else {
475 if (g_uartCtx[uartId].isBlock) {
476 while (tls_uart_try_read(uartId, 1) == 0) { }
477 ret = tls_uart_read(uartId, data, 1);
478 } else {
479 ret = tls_uart_read(uartId, data, 1);
480 }
481 ret = 1;
482 }
483 return ret;
484 }
485
UartHostDevSetBaud(struct UartHost * host,uint32_t baudRate)486 static int32_t UartHostDevSetBaud(struct UartHost *host, uint32_t baudRate)
487 {
488 HDF_LOGI("%s: Enter", __func__);
489 struct UartDevice *uartDevice = NULL;
490 tls_uart_options_t *uartCfg = NULL;
491 uint32_t uartId;
492
493 if (host == NULL || host->priv == NULL) {
494 HDF_LOGE("%s: invalid parameter", __func__);
495 return HDF_ERR_INVALID_PARAM;
496 }
497
498 uartDevice = (struct UartDevice *)host->priv;
499 uartId = uartDevice->uartId;
500 uartCfg = &uartDevice->config;
501 if (uartCfg == NULL) {
502 HDF_LOGE("%s: device config is NULL", __func__);
503 return HDF_ERR_INVALID_OBJECT;
504 }
505 uartCfg->baudrate = baudRate;
506
507 tls_uart_set_baud_rate(uartId, uartCfg->baudrate);
508
509 return HDF_SUCCESS;
510 }
511
UartHostDevGetBaud(struct UartHost * host,uint32_t * baudRate)512 static int32_t UartHostDevGetBaud(struct UartHost *host, uint32_t *baudRate)
513 {
514 HDF_LOGI("%s: Enter", __func__);
515 struct UartDevice *uartDevice = NULL;
516 tls_uart_options_t *uartCfg = NULL;
517 uint32_t uartId;
518
519 if (host == NULL || baudRate == NULL || host->priv == NULL) {
520 HDF_LOGE("%s: invalid parameter", __func__);
521 return HDF_ERR_INVALID_PARAM;
522 }
523 uartDevice = (struct UartDevice *)host->priv;
524 uartId = uartDevice->uartId;
525 uartCfg = &uartDevice->config;
526 if (uartCfg == NULL) {
527 HDF_LOGE("%s: device is NULL", __func__);
528 return HDF_ERR_INVALID_OBJECT;
529 }
530 *baudRate = uartCfg->baudrate;
531 return HDF_SUCCESS;
532 }
533
UartHostDevSetAttribute(struct UartHost * host,struct UartAttribute * attribute)534 static int32_t UartHostDevSetAttribute(struct UartHost *host, struct UartAttribute *attribute)
535 {
536 struct UartDevice *uartDevice = NULL;
537 tls_uart_options_t *uartCfg = NULL;
538 uint32_t uartId;
539
540 if (host == NULL || attribute == NULL || host->priv == NULL) {
541 HDF_LOGE("%s: invalid parameter", __func__);
542 return HDF_ERR_INVALID_PARAM;
543 }
544
545 uartDevice = (struct UartDevice *)host->priv;
546 uartId = uartDevice->uartId;
547 uartCfg = &uartDevice->config;
548 if (uartCfg == NULL) {
549 HDF_LOGE("%s: config is NULL", __func__);
550 return HDF_ERR_INVALID_OBJECT;
551 }
552
553 uartCfg->paritytype = attribute->parity;
554 tls_uart_set_parity(uartId, uartCfg->paritytype);
555
556 switch (attribute->stopBits) {
557 case UART_ATTR_STOPBIT_1:
558 uartCfg->stopbits = TLS_UART_ONE_STOPBITS;
559 break;
560 case UART_ATTR_STOPBIT_2:
561 uartCfg->stopbits = TLS_UART_TWO_STOPBITS;
562 break;
563 default:
564 uartCfg->stopbits = TLS_UART_ONE_STOPBITS;
565 break;
566 }
567 tls_uart_set_stop_bits(uartId, uartCfg->stopbits);
568
569 if (attribute->rts && attribute->cts) {
570 uartCfg->flow_ctrl = TLS_UART_FLOW_CTRL_HARDWARE;
571 } else {
572 uartCfg->flow_ctrl = TLS_UART_FLOW_CTRL_NONE;
573 }
574 tls_uart_set_fc_status(uartId, uartCfg->flow_ctrl);
575 return HDF_SUCCESS;
576 }
577
UartHostDevGetAttribute(struct UartHost * host,struct UartAttribute * attribute)578 static int32_t UartHostDevGetAttribute(struct UartHost *host, struct UartAttribute *attribute)
579 {
580 HDF_LOGI("%s: Enter", __func__);
581 struct UartDevice *uartDevice = NULL;
582 tls_uart_options_t *uartCfg = NULL;
583
584 if (host == NULL || attribute == NULL || host->priv == NULL) {
585 HDF_LOGE("%s: invalid parameter", __func__);
586 return HDF_ERR_INVALID_PARAM;
587 }
588
589 uartDevice = (struct UartDevice *)host->priv;
590 uartCfg = &uartDevice->config;
591 if (uartCfg == NULL) {
592 HDF_LOGE("%s: config is NULL", __func__);
593 return HDF_ERR_INVALID_OBJECT;
594 }
595
596 attribute->parity = uartCfg->paritytype;
597
598 switch (uartCfg->stopbits) {
599 case TLS_UART_ONE_STOPBITS:
600 attribute->stopBits = UART_ATTR_STOPBIT_1;
601 break;
602 case TLS_UART_TWO_STOPBITS:
603 attribute->stopBits = UART_ATTR_STOPBIT_2;
604 break;
605 default:
606 attribute->stopBits = UART_ATTR_STOPBIT_1;
607 break;
608 }
609
610 switch (uartCfg->flow_ctrl) {
611 case TLS_UART_FLOW_CTRL_HARDWARE:
612 attribute->rts = 1;
613 attribute->cts = 1;
614 break;
615 default:
616 attribute->rts = 0;
617 attribute->cts = 0;
618 break;
619 }
620
621 return HDF_SUCCESS;
622 }
623
UartHostDevSetTransMode(struct UartHost * host,enum UartTransMode mode)624 static int32_t UartHostDevSetTransMode(struct UartHost *host, enum UartTransMode mode)
625 {
626 HDF_LOGI("%s: Enter", __func__);
627 struct UartDevice *uartDevice = NULL;
628 uint32_t uartId;
629
630 if (host == NULL || host->priv == NULL) {
631 HDF_LOGE("%s: invalid parameter", __func__);
632 return HDF_ERR_INVALID_PARAM;
633 }
634
635 uartDevice = (struct UartDevice *)host->priv;
636 uartId = uartDevice->uartId;
637 switch (mode) {
638 case UART_MODE_RD_BLOCK:
639 g_uartCtx[uartId].isBlock = true;
640 break;
641 case UART_MODE_RD_NONBLOCK:
642 g_uartCtx[uartId].isBlock = false;
643 break;
644 case UART_MODE_DMA_RX_EN:
645 g_uartCtx[uartId].rxDMA = true;
646 break;
647 case UART_MODE_DMA_RX_DIS:
648 g_uartCtx[uartId].rxDMA = false;
649 break;
650 case UART_MODE_DMA_TX_EN:
651 g_uartCtx[uartId].txDMA = true;
652 break;
653 case UART_MODE_DMA_TX_DIS:
654 g_uartCtx[uartId].txDMA = false;
655 break;
656 default:
657 HDF_LOGE("%s: UartTransMode(%d) invalid", __func__, mode);
658 break;
659 }
660 return HDF_SUCCESS;
661 }
662