1
1
/*
2
2
* Copyright (c) 2024, Yishai Jaffe
3
+ * Copyright (c) 2025 Silicon Laboratories Inc.
3
4
*
4
5
* SPDX-License-Identifier: Apache-2.0
5
6
*/
@@ -79,16 +80,12 @@ static int uart_silabs_eusart_err_check(const struct device *dev)
79
80
}
80
81
81
82
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
82
- static int uart_silabs_eusart_fifo_fill (const struct device * dev ,
83
- const uint8_t * tx_data ,
84
- int len )
83
+ static int uart_silabs_eusart_fifo_fill (const struct device * dev , const uint8_t * tx_data , int len )
85
84
{
86
85
const struct uart_silabs_eusart_config * config = dev -> config ;
87
86
int num_tx = 0 ;
88
87
89
- while ((len - num_tx > 0 ) &&
90
- (EUSART_StatusGet (config -> eusart ) & EUSART_STATUS_TXFL )) {
91
-
88
+ while ((len - num_tx > 0 ) && (EUSART_StatusGet (config -> eusart ) & EUSART_STATUS_TXFL )) {
92
89
config -> eusart -> TXDATA = (uint32_t )tx_data [num_tx ++ ];
93
90
}
94
91
@@ -99,14 +96,12 @@ static int uart_silabs_eusart_fifo_fill(const struct device *dev,
99
96
return num_tx ;
100
97
}
101
98
102
- static int uart_silabs_eusart_fifo_read (const struct device * dev , uint8_t * rx_data ,
103
- const int len )
99
+ static int uart_silabs_eusart_fifo_read (const struct device * dev , uint8_t * rx_data , const int len )
104
100
{
105
101
const struct uart_silabs_eusart_config * config = dev -> config ;
106
102
int num_rx = 0 ;
107
103
108
- while ((len - num_rx > 0 ) &&
109
- (EUSART_StatusGet (config -> eusart ) & EUSART_STATUS_RXFL )) {
104
+ while ((len - num_rx > 0 ) && (EUSART_StatusGet (config -> eusart ) & EUSART_STATUS_RXFL )) {
110
105
rx_data [num_rx ++ ] = (uint8_t )config -> eusart -> RXDATA ;
111
106
}
112
107
@@ -147,8 +142,8 @@ static int uart_silabs_eusart_irq_tx_ready(const struct device *dev)
147
142
{
148
143
const struct uart_silabs_eusart_config * config = dev -> config ;
149
144
150
- return (config -> eusart -> IEN & EUSART_IEN_TXFL )
151
- && (EUSART_IntGet (config -> eusart ) & EUSART_IF_TXFL );
145
+ return (config -> eusart -> IEN & EUSART_IEN_TXFL ) &&
146
+ (EUSART_IntGet (config -> eusart ) & EUSART_IF_TXFL );
152
147
}
153
148
154
149
static void uart_silabs_eusart_irq_rx_enable (const struct device * dev )
@@ -171,8 +166,8 @@ static int uart_silabs_eusart_irq_rx_ready(const struct device *dev)
171
166
{
172
167
const struct uart_silabs_eusart_config * config = dev -> config ;
173
168
174
- return (config -> eusart -> IEN & EUSART_IEN_RXFL )
175
- && (EUSART_IntGet (config -> eusart ) & EUSART_IF_RXFL );
169
+ return (config -> eusart -> IEN & EUSART_IEN_RXFL ) &&
170
+ (EUSART_IntGet (config -> eusart ) & EUSART_IF_RXFL );
176
171
}
177
172
178
173
static void uart_silabs_eusart_irq_err_enable (const struct device * dev )
@@ -202,8 +197,7 @@ static int uart_silabs_eusart_irq_update(const struct device *dev)
202
197
}
203
198
204
199
static void uart_silabs_eusart_irq_callback_set (const struct device * dev ,
205
- uart_irq_callback_user_data_t cb ,
206
- void * cb_data )
200
+ uart_irq_callback_user_data_t cb , void * cb_data )
207
201
{
208
202
struct uart_silabs_eusart_data * data = dev -> data ;
209
203
@@ -221,8 +215,7 @@ static void uart_silabs_eusart_isr(const struct device *dev)
221
215
}
222
216
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
223
217
224
- static inline EUSART_Parity_TypeDef uart_silabs_eusart_cfg2ll_parity (
225
- enum uart_config_parity parity )
218
+ static inline EUSART_Parity_TypeDef uart_silabs_eusart_cfg2ll_parity (enum uart_config_parity parity )
226
219
{
227
220
switch (parity ) {
228
221
case UART_CFG_PARITY_ODD :
@@ -235,8 +228,7 @@ static inline EUSART_Parity_TypeDef uart_silabs_eusart_cfg2ll_parity(
235
228
}
236
229
}
237
230
238
- static inline enum uart_config_parity uart_silabs_eusart_ll2cfg_parity (
239
- EUSART_Parity_TypeDef parity )
231
+ static inline enum uart_config_parity uart_silabs_eusart_ll2cfg_parity (EUSART_Parity_TypeDef parity )
240
232
{
241
233
switch (parity ) {
242
234
case eusartOddParity :
@@ -249,8 +241,8 @@ static inline enum uart_config_parity uart_silabs_eusart_ll2cfg_parity(
249
241
}
250
242
}
251
243
252
- static inline EUSART_Stopbits_TypeDef uart_silabs_eusart_cfg2ll_stopbits (
253
- enum uart_config_stop_bits sb )
244
+ static inline EUSART_Stopbits_TypeDef
245
+ uart_silabs_eusart_cfg2ll_stopbits ( enum uart_config_stop_bits sb )
254
246
{
255
247
switch (sb ) {
256
248
case UART_CFG_STOP_BITS_0_5 :
@@ -266,8 +258,8 @@ static inline EUSART_Stopbits_TypeDef uart_silabs_eusart_cfg2ll_stopbits(
266
258
}
267
259
}
268
260
269
- static inline enum uart_config_stop_bits uart_silabs_eusart_ll2cfg_stopbits (
270
- EUSART_Stopbits_TypeDef sb )
261
+ static inline enum uart_config_stop_bits
262
+ uart_silabs_eusart_ll2cfg_stopbits ( EUSART_Stopbits_TypeDef sb )
271
263
{
272
264
switch (sb ) {
273
265
case eusartStopbits0p5 :
@@ -283,8 +275,8 @@ static inline enum uart_config_stop_bits uart_silabs_eusart_ll2cfg_stopbits(
283
275
}
284
276
}
285
277
286
- static inline EUSART_Databits_TypeDef uart_silabs_eusart_cfg2ll_databits (
287
- enum uart_config_data_bits db , enum uart_config_parity p )
278
+ static inline EUSART_Databits_TypeDef
279
+ uart_silabs_eusart_cfg2ll_databits ( enum uart_config_data_bits db , enum uart_config_parity p )
288
280
{
289
281
switch (db ) {
290
282
case UART_CFG_DATA_BITS_7 :
@@ -306,8 +298,8 @@ static inline EUSART_Databits_TypeDef uart_silabs_eusart_cfg2ll_databits(
306
298
}
307
299
}
308
300
309
- static inline enum uart_config_data_bits uart_silabs_eusart_ll2cfg_databits (
310
- EUSART_Databits_TypeDef db , EUSART_Parity_TypeDef p )
301
+ static inline enum uart_config_data_bits
302
+ uart_silabs_eusart_ll2cfg_databits ( EUSART_Databits_TypeDef db , EUSART_Parity_TypeDef p )
311
303
{
312
304
switch (db ) {
313
305
case eusartDataBits7 :
@@ -339,8 +331,8 @@ static inline enum uart_config_data_bits uart_silabs_eusart_ll2cfg_databits(
339
331
* @param fc: Zephyr hardware flow control option.
340
332
* @retval eusartHwFlowControlCtsAndRts, or eusartHwFlowControlNone.
341
333
*/
342
- static inline EUSART_HwFlowControl_TypeDef uart_silabs_eusart_cfg2ll_hwctrl (
343
- enum uart_config_flow_control fc )
334
+ static inline EUSART_HwFlowControl_TypeDef
335
+ uart_silabs_eusart_cfg2ll_hwctrl ( enum uart_config_flow_control fc )
344
336
{
345
337
if (fc == UART_CFG_FLOW_CTRL_RTS_CTS ) {
346
338
return eusartHwFlowControlCtsAndRts ;
@@ -356,8 +348,8 @@ static inline EUSART_HwFlowControl_TypeDef uart_silabs_eusart_cfg2ll_hwctrl(
356
348
* @param fc: LL hardware flow control definition.
357
349
* @retval UART_CFG_FLOW_CTRL_RTS_CTS, or UART_CFG_FLOW_CTRL_NONE.
358
350
*/
359
- static inline enum uart_config_flow_control uart_silabs_eusart_ll2cfg_hwctrl (
360
- EUSART_HwFlowControl_TypeDef fc )
351
+ static inline enum uart_config_flow_control
352
+ uart_silabs_eusart_ll2cfg_hwctrl ( EUSART_HwFlowControl_TypeDef fc )
361
353
{
362
354
if (fc == eusartHwFlowControlCtsAndRts ) {
363
355
return UART_CFG_FLOW_CTRL_RTS_CTS ;
@@ -382,9 +374,7 @@ static int uart_silabs_eusart_init(const struct device *dev)
382
374
EUSART_UartInit_TypeDef eusartInit = EUSART_UART_INIT_DEFAULT_HF ;
383
375
EUSART_AdvancedInit_TypeDef advancedSettings = EUSART_ADVANCED_INIT_DEFAULT ;
384
376
385
- /* The peripheral and gpio clock are already enabled from soc and gpio
386
- * driver
387
- */
377
+ /* The peripheral and gpio clock are already enabled from soc and gpio driver */
388
378
/* Enable EUSART clock */
389
379
err = clock_control_on (config -> clock_dev , (clock_control_subsys_t )& config -> clock_cfg );
390
380
if (err < 0 ) {
@@ -400,8 +390,8 @@ static int uart_silabs_eusart_init(const struct device *dev)
400
390
eusartInit .baudrate = uart_cfg -> baudrate ;
401
391
eusartInit .parity = uart_silabs_eusart_cfg2ll_parity (uart_cfg -> parity );
402
392
eusartInit .stopbits = uart_silabs_eusart_cfg2ll_stopbits (uart_cfg -> stop_bits );
403
- eusartInit .databits = uart_silabs_eusart_cfg2ll_databits ( uart_cfg -> data_bits ,
404
- uart_cfg -> parity );
393
+ eusartInit .databits =
394
+ uart_silabs_eusart_cfg2ll_databits ( uart_cfg -> data_bits , uart_cfg -> parity );
405
395
advancedSettings .hwFlowControl = uart_silabs_eusart_cfg2ll_hwctrl (uart_cfg -> flow_ctrl );
406
396
eusartInit .advancedSettings = & advancedSettings ;
407
397
@@ -462,57 +452,54 @@ static DEVICE_API(uart, uart_silabs_eusart_driver_api) = {
462
452
};
463
453
464
454
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
465
- #define UART_IRQ_HANDLER_FUNC (idx ) \
466
- .irq_config_func = uart_silabs_eusart_config_func_##idx,
467
- #define UART_IRQ_HANDLER (idx ) \
468
- static void uart_silabs_eusart_config_func_##idx(const struct device *dev) \
469
- { \
470
- IRQ_CONNECT(DT_INST_IRQ_BY_NAME(idx, rx, irq), \
471
- DT_INST_IRQ_BY_NAME(idx, rx, priority), \
472
- uart_silabs_eusart_isr, DEVICE_DT_INST_GET(idx), 0); \
473
- IRQ_CONNECT(DT_INST_IRQ_BY_NAME(idx, tx, irq), \
474
- DT_INST_IRQ_BY_NAME(idx, tx, priority), \
475
- uart_silabs_eusart_isr, DEVICE_DT_INST_GET(idx), 0); \
476
- \
477
- irq_enable(DT_INST_IRQ_BY_NAME(idx, rx, irq)); \
478
- irq_enable(DT_INST_IRQ_BY_NAME(idx, tx, irq)); \
455
+ #define UART_IRQ_HANDLER_FUNC (idx ) .irq_config_func = uart_silabs_eusart_config_func_##idx,
456
+ #define UART_IRQ_HANDLER (idx ) \
457
+ static void uart_silabs_eusart_config_func_##idx(const struct device *dev) \
458
+ { \
459
+ IRQ_CONNECT(DT_INST_IRQ_BY_NAME(idx, rx, irq), \
460
+ DT_INST_IRQ_BY_NAME(idx, rx, priority), uart_silabs_eusart_isr, \
461
+ DEVICE_DT_INST_GET(idx), 0); \
462
+ IRQ_CONNECT(DT_INST_IRQ_BY_NAME(idx, tx, irq), \
463
+ DT_INST_IRQ_BY_NAME(idx, tx, priority), uart_silabs_eusart_isr, \
464
+ DEVICE_DT_INST_GET(idx), 0); \
465
+ \
466
+ irq_enable(DT_INST_IRQ_BY_NAME(idx, rx, irq)); \
467
+ irq_enable(DT_INST_IRQ_BY_NAME(idx, tx, irq)); \
479
468
}
480
469
#else
481
470
#define UART_IRQ_HANDLER_FUNC (idx )
482
471
#define UART_IRQ_HANDLER (idx )
483
472
#endif
484
473
485
- #define UART_INIT (idx ) \
486
- UART_IRQ_HANDLER(idx) \
487
- \
488
- PINCTRL_DT_INST_DEFINE(idx); \
489
- \
490
- static const struct uart_silabs_eusart_config uart_silabs_eusart_cfg_##idx = { \
491
- .eusart = (EUSART_TypeDef *)DT_INST_REG_ADDR(idx), \
492
- .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(idx), \
493
- .clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(idx)), \
494
- .clock_cfg = SILABS_DT_INST_CLOCK_CFG(idx), \
495
- UART_IRQ_HANDLER_FUNC(idx) \
496
- }; \
497
- \
498
- static struct uart_silabs_eusart_data uart_silabs_eusart_data_##idx = { \
499
- .uart_cfg = { \
500
- .baudrate = DT_INST_PROP(idx, current_speed), \
501
- .parity = DT_INST_ENUM_IDX(idx, parity), \
502
- .stop_bits = DT_INST_ENUM_IDX(idx, stop_bits), \
503
- .data_bits = DT_INST_ENUM_IDX(idx, data_bits), \
504
- .flow_ctrl = DT_INST_PROP(idx, hw_flow_control) \
505
- ? UART_CFG_FLOW_CTRL_RTS_CTS \
506
- : UART_CFG_FLOW_CTRL_NONE, \
507
- }, \
508
- }; \
509
- \
510
- PM_DEVICE_DT_INST_DEFINE(idx, uart_silabs_eusart_pm_action); \
511
- \
512
- DEVICE_DT_INST_DEFINE(idx, uart_silabs_eusart_init, PM_DEVICE_DT_INST_GET(idx), \
513
- &uart_silabs_eusart_data_##idx, \
514
- &uart_silabs_eusart_cfg_##idx, PRE_KERNEL_1, \
515
- CONFIG_SERIAL_INIT_PRIORITY, \
516
- &uart_silabs_eusart_driver_api);
474
+ #define UART_INIT (idx ) \
475
+ UART_IRQ_HANDLER(idx) \
476
+ PINCTRL_DT_INST_DEFINE(idx); \
477
+ \
478
+ static const struct uart_silabs_eusart_config uart_silabs_eusart_cfg_##idx = { \
479
+ .eusart = (EUSART_TypeDef *)DT_INST_REG_ADDR(idx), \
480
+ .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(idx), \
481
+ .clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(idx)), \
482
+ .clock_cfg = SILABS_DT_INST_CLOCK_CFG(idx), \
483
+ UART_IRQ_HANDLER_FUNC(idx) \
484
+ }; \
485
+ \
486
+ static struct uart_silabs_eusart_data uart_silabs_eusart_data_##idx = { \
487
+ .uart_cfg = { \
488
+ .baudrate = DT_INST_PROP(idx, current_speed), \
489
+ .parity = DT_INST_ENUM_IDX(idx, parity), \
490
+ .stop_bits = DT_INST_ENUM_IDX(idx, stop_bits), \
491
+ .data_bits = DT_INST_ENUM_IDX(idx, data_bits), \
492
+ .flow_ctrl = DT_INST_PROP(idx, hw_flow_control) \
493
+ ? UART_CFG_FLOW_CTRL_RTS_CTS \
494
+ : UART_CFG_FLOW_CTRL_NONE, \
495
+ }, \
496
+ }; \
497
+ \
498
+ PM_DEVICE_DT_INST_DEFINE(idx, uart_silabs_eusart_pm_action); \
499
+ \
500
+ DEVICE_DT_INST_DEFINE(idx, uart_silabs_eusart_init, PM_DEVICE_DT_INST_GET(idx), \
501
+ &uart_silabs_eusart_data_##idx, &uart_silabs_eusart_cfg_##idx, \
502
+ PRE_KERNEL_1, CONFIG_SERIAL_INIT_PRIORITY, \
503
+ &uart_silabs_eusart_driver_api);
517
504
518
505
DT_INST_FOREACH_STATUS_OKAY (UART_INIT )
0 commit comments