Skip to content

Commit b985b94

Browse files
congnguyenhuukartben
authored andcommitted
drivers: uart_nxp_s32_linflexd: support config via devicetree
Added support for initialization configuration via Devicetree. Signed-off-by: Cong Nguyen Huu <cong.nguyenhuu@nxp.com>
1 parent 92b57ac commit b985b94

File tree

4 files changed

+95
-9
lines changed

4 files changed

+95
-9
lines changed

drivers/serial/uart_nxp_s32_linflexd.c

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2024 NXP
2+
* Copyright 2022-2025 NXP
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -10,6 +10,7 @@
1010
#include <zephyr/irq.h>
1111
#include <zephyr/drivers/uart.h>
1212
#include <zephyr/drivers/pinctrl.h>
13+
#include <zephyr/drivers/clock_control.h>
1314

1415
#include <Linflexd_Uart_Ip.h>
1516
#include <Linflexd_Uart_Ip_Irq.h>
@@ -295,14 +296,36 @@ static int uart_nxp_s32_init(const struct device *dev)
295296
{
296297
const struct uart_nxp_s32_config *config = dev->config;
297298
int err;
299+
uint32_t clock_rate;
300+
Linflexd_Uart_Ip_StatusType status;
298301

299302
err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT);
300303
if (err < 0) {
301304
return err;
302305
}
303306

307+
if (!device_is_ready(config->clock_dev)) {
308+
return -ENODEV;
309+
}
310+
311+
err = clock_control_on(config->clock_dev, config->clock_subsys);
312+
if (err) {
313+
return err;
314+
}
315+
316+
err = clock_control_get_rate(config->clock_dev, config->clock_subsys, &clock_rate);
317+
if (err) {
318+
return err;
319+
}
320+
304321
Linflexd_Uart_Ip_Init(config->instance, &config->hw_cfg);
305322

323+
status = Linflexd_Uart_Ip_SetBaudrate(config->instance, config->hw_cfg.BaudRate,
324+
clock_rate);
325+
if (status != LINFLEXD_UART_IP_STATUS_SUCCESS) {
326+
return -EIO;
327+
}
328+
306329
return 0;
307330
}
308331

@@ -345,14 +368,30 @@ static DEVICE_API(uart, uart_nxp_s32_driver_api) = {
345368

346369
#define UART_NXP_S32_HW_CONFIG(n) \
347370
{ \
348-
.BaudRate = 115200, \
371+
.BaudRate = DT_INST_PROP(n, current_speed), \
349372
.BaudRateMantissa = 26U, \
350373
.BaudRateDivisor = 16U, \
351374
.BaudRateFractionalDivisor = 1U, \
352-
.ParityCheck = false, \
353-
.ParityType = LINFLEXD_UART_IP_PARITY_EVEN, \
354-
.StopBitsCount = LINFLEXD_UART_IP_ONE_STOP_BIT, \
355-
.WordLength = LINFLEXD_UART_IP_8_BITS, \
375+
.ParityCheck = DT_INST_ENUM_IDX(n, parity) == \
376+
UART_CFG_PARITY_NONE ? false : true, \
377+
.ParityType = DT_INST_ENUM_IDX(n, parity) == \
378+
UART_CFG_PARITY_ODD ? \
379+
LINFLEXD_UART_IP_PARITY_ODD : \
380+
(DT_INST_ENUM_IDX(n, parity) == \
381+
UART_CFG_PARITY_EVEN ? \
382+
LINFLEXD_UART_IP_PARITY_ONE : \
383+
(DT_INST_ENUM_IDX(n, parity) == \
384+
UART_CFG_PARITY_MARK ? \
385+
LINFLEXD_UART_IP_PARITY_EVEN : \
386+
LINFLEXD_UART_IP_PARITY_ZERO)), \
387+
.StopBitsCount = DT_INST_ENUM_IDX(n, stop_bits) == \
388+
UART_CFG_STOP_BITS_1 ? \
389+
LINFLEXD_UART_IP_ONE_STOP_BIT : \
390+
LINFLEXD_UART_IP_TWO_STOP_BIT, \
391+
.WordLength = DT_INST_ENUM_IDX(n, data_bits) == \
392+
UART_CFG_DATA_BITS_7 ? \
393+
LINFLEXD_UART_IP_7_BITS : \
394+
LINFLEXD_UART_IP_8_BITS, \
356395
.TransferType = LINFLEXD_UART_IP_USING_INTERRUPTS, \
357396
.StateStruct = &Linflexd_Uart_Ip_apStateStructure[n], \
358397
IF_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN, ( \
@@ -362,6 +401,17 @@ static DEVICE_API(uart, uart_nxp_s32_driver_api) = {
362401
}
363402

364403
#define UART_NXP_S32_INIT_DEVICE(n) \
404+
BUILD_ASSERT(DT_INST_ENUM_IDX(n, stop_bits) == UART_CFG_STOP_BITS_1 || \
405+
DT_INST_ENUM_IDX(n, stop_bits) == UART_CFG_STOP_BITS_2, \
406+
"Node " DT_NODE_PATH(DT_DRV_INST(n)) \
407+
" has unsupported stop bits configuration"); \
408+
BUILD_ASSERT(DT_INST_ENUM_IDX(n, data_bits) == UART_CFG_DATA_BITS_7 || \
409+
DT_INST_ENUM_IDX(n, data_bits) == UART_CFG_DATA_BITS_8, \
410+
"Node " DT_NODE_PATH(DT_DRV_INST(n)) \
411+
" has unsupported data bits configuration"); \
412+
BUILD_ASSERT(DT_INST_PROP(n, hw_flow_control) == UART_CFG_FLOW_CTRL_NONE,\
413+
"Node " DT_NODE_PATH(DT_DRV_INST(n)) \
414+
" has unsupported flow control configuration"); \
365415
PINCTRL_DT_INST_DEFINE(n); \
366416
IF_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN, \
367417
(static struct uart_nxp_s32_data uart_nxp_s32_data_##n;)) \
@@ -370,6 +420,9 @@ static DEVICE_API(uart, uart_nxp_s32_driver_api) = {
370420
.base = (LINFLEXD_Type *)DT_INST_REG_ADDR(n), \
371421
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
372422
.hw_cfg = UART_NXP_S32_HW_CONFIG(n), \
423+
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(n)), \
424+
.clock_subsys = (clock_control_subsys_t) \
425+
DT_INST_CLOCKS_CELL(n, name), \
373426
}; \
374427
static int uart_nxp_s32_init_##n(const struct device *dev) \
375428
{ \

drivers/serial/uart_nxp_s32_linflexd.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2023 NXP
2+
* Copyright 2022-2023, 2025 NXP
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -12,6 +12,8 @@ struct uart_nxp_s32_config {
1212
LINFLEXD_Type *base;
1313
const struct pinctrl_dev_config *pincfg;
1414
Linflexd_Uart_Ip_UserConfigType hw_cfg;
15+
const struct device *clock_dev;
16+
clock_control_subsys_t clock_subsys;
1517
};
1618

1719
#ifdef CONFIG_UART_INTERRUPT_DRIVEN

dts/arm/nxp/nxp_s32z27x_r52.dtsi

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2024 NXP
2+
* Copyright 2022-2025 NXP
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -125,90 +125,103 @@
125125
compatible = "nxp,s32-linflexd";
126126
reg = <0x40170000 0x1000>;
127127
interrupts = <GIC_SPI 212 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
128+
clocks = <&clock NXP_S32_LIN0_CLK>;
128129
status = "disabled";
129130
};
130131

131132
uart1: uart@40180000 {
132133
compatible = "nxp,s32-linflexd";
133134
reg = <0x40180000 0x1000>;
134135
interrupts = <GIC_SPI 213 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
136+
clocks = <&clock NXP_S32_LIN1_CLK>;
135137
status = "disabled";
136138
};
137139

138140
uart2: uart@40190000 {
139141
compatible = "nxp,s32-linflexd";
140142
reg = <0x40190000 0x1000>;
141143
interrupts = <GIC_SPI 214 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
144+
clocks = <&clock NXP_S32_LIN2_CLK>;
142145
status = "disabled";
143146
};
144147

145148
uart3: uart@40970000 {
146149
compatible = "nxp,s32-linflexd";
147150
reg = <0x40970000 0x1000>;
148151
interrupts = <GIC_SPI 215 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
152+
clocks = <&clock NXP_S32_LIN3_CLK>;
149153
status = "disabled";
150154
};
151155

152156
uart4: uart@40980000 {
153157
compatible = "nxp,s32-linflexd";
154158
reg = <0x40980000 0x1000>;
155159
interrupts = <GIC_SPI 216 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
160+
clocks = <&clock NXP_S32_LIN4_CLK>;
156161
status = "disabled";
157162
};
158163

159164
uart5: uart@40990000 {
160165
compatible = "nxp,s32-linflexd";
161166
reg = <0x40990000 0x1000>;
162167
interrupts = <GIC_SPI 217 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
168+
clocks = <&clock NXP_S32_LIN5_CLK>;
163169
status = "disabled";
164170
};
165171

166172
uart6: uart@42170000 {
167173
compatible = "nxp,s32-linflexd";
168174
reg = <0x42170000 0x1000>;
169175
interrupts = <GIC_SPI 218 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
176+
clocks = <&clock NXP_S32_LIN6_CLK>;
170177
status = "disabled";
171178
};
172179

173180
uart7: uart@42180000 {
174181
compatible = "nxp,s32-linflexd";
175182
reg = <0x42180000 0x1000>;
176183
interrupts = <GIC_SPI 219 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
184+
clocks = <&clock NXP_S32_LIN7_CLK>;
177185
status = "disabled";
178186
};
179187

180188
uart8: uart@42190000 {
181189
compatible = "nxp,s32-linflexd";
182190
reg = <0x42190000 0x1000>;
183191
interrupts = <GIC_SPI 220 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
192+
clocks = <&clock NXP_S32_LIN8_CLK>;
184193
status = "disabled";
185194
};
186195

187196
uart9: uart@42980000 {
188197
compatible = "nxp,s32-linflexd";
189198
reg = <0x42980000 0x1000>;
190199
interrupts = <GIC_SPI 221 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
200+
clocks = <&clock NXP_S32_LIN9_CLK>;
191201
status = "disabled";
192202
};
193203

194204
uart10: uart@42990000 {
195205
compatible = "nxp,s32-linflexd";
196206
reg = <0x42990000 0x1000>;
197207
interrupts = <GIC_SPI 222 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
208+
clocks = <&clock NXP_S32_LIN10_CLK>;
198209
status = "disabled";
199210
};
200211

201212
uart11: uart@429a0000 {
202213
compatible = "nxp,s32-linflexd";
203214
reg = <0x429a0000 0x1000>;
204215
interrupts = <GIC_SPI 223 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
216+
clocks = <&clock NXP_S32_LIN11_CLK>;
205217
status = "disabled";
206218
};
207219

208220
uart12: uart@40330000 {
209221
compatible = "nxp,s32-linflexd";
210222
reg = <0x40330000 0x1000>;
211223
interrupts = <GIC_SPI 205 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
224+
clocks = <&clock NXP_S32_MSCLIN_CLK>;
212225
status = "disabled";
213226
};
214227

dts/bindings/serial/nxp,s32-linflexd.yaml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2022 NXP
1+
# Copyright 2022, 2025 NXP
22
# SPDX-License-Identifier: Apache-2.0
33

44
description: NXP S32 LINFlexD
@@ -19,3 +19,21 @@ properties:
1919

2020
pinctrl-names:
2121
required: true
22+
23+
clocks:
24+
required: true
25+
26+
current-speed:
27+
description: |
28+
Initial baud rate setting for UART. Defaults to standard baudrate of 115200 if not specified.
29+
default: 115200
30+
31+
stop-bits:
32+
description: |
33+
Sets the number of stop bits. Defaults to standard of 1 if not specified.
34+
default: "1"
35+
36+
data-bits:
37+
description: |
38+
Sets the number of data bits. Defaults to standard of 8 if not specified.
39+
default: 8

0 commit comments

Comments
 (0)