Skip to content

Commit f21c936

Browse files
nandojvembolivar-nordic
authored andcommitted
drivers: serial: sam: Update to use clock control
This update Atmel SAM uart and usart drivers to use clock control drivers. Signed-off-by: Gerson Fernando Budke <[email protected]>
1 parent 88cedcf commit f21c936

File tree

9 files changed

+42
-48
lines changed

9 files changed

+42
-48
lines changed

drivers/serial/uart_sam.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
/*
22
* Copyright (c) 2017 Piotr Mienkowski
33
* Copyright (c) 2018 Justin Watson
4+
* Copyright (c) 2023 Gerson Fernando Budke
45
* SPDX-License-Identifier: Apache-2.0
56
*/
67

78
#define DT_DRV_COMPAT atmel_sam_uart
89

910
/** @file
1011
* @brief UART driver for Atmel SAM MCU family.
11-
*
12-
* Note:
13-
* - Error handling is not implemented.
14-
* - The driver works only in polling mode, interrupt mode is not implemented.
1512
*/
1613

1714
#include <errno.h>
@@ -21,12 +18,13 @@
2118
#include <soc.h>
2219
#include <zephyr/drivers/uart.h>
2320
#include <zephyr/drivers/pinctrl.h>
21+
#include <zephyr/drivers/clock_control/atmel_sam_pmc.h>
2422
#include <zephyr/irq.h>
2523

2624
/* Device constant configuration parameters */
2725
struct uart_sam_dev_cfg {
2826
Uart *regs;
29-
uint32_t periph_id;
27+
const struct atmel_sam_pmc_config clock_cfg;
3028
const struct pinctrl_dev_config *pcfg;
3129

3230
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
@@ -40,7 +38,7 @@ struct uart_sam_dev_data {
4038

4139
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
4240
uart_irq_callback_user_data_t irq_cb; /* Interrupt Callback */
43-
void *irq_cb_data; /* Interrupt Callback Arg */
41+
void *irq_cb_data; /* Interrupt Callback Arg */
4442
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
4543
};
4644

@@ -391,7 +389,8 @@ static int uart_sam_init(const struct device *dev)
391389
Uart * const uart = cfg->regs;
392390

393391
/* Enable UART clock in PMC */
394-
soc_pmc_peripheral_enable(cfg->periph_id);
392+
(void)clock_control_on(SAM_DT_PMC_CONTROLLER,
393+
(clock_control_subsys_t *)&cfg->clock_cfg);
395394

396395
/* Connect pins to the peripheral */
397396
retval = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT);
@@ -445,7 +444,7 @@ static const struct uart_driver_api uart_sam_driver_api = {
445444
#define UART_SAM_DECLARE_CFG(n, IRQ_FUNC_INIT) \
446445
static const struct uart_sam_dev_cfg uart##n##_sam_config = { \
447446
.regs = (Uart *)DT_INST_REG_ADDR(n), \
448-
.periph_id = DT_INST_PROP(n, peripheral_id), \
447+
.clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(n), \
449448
\
450449
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
451450
\

drivers/serial/usart_sam.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
/*
2-
* Copyright (c) 2018 Justin Watson
32
* Copyright (c) 2016 Piotr Mienkowski
3+
* Copyright (c) 2018 Justin Watson
4+
* Copyright (c) 2023 Gerson Fernando Budke
45
* SPDX-License-Identifier: Apache-2.0
56
*/
67

78
#define DT_DRV_COMPAT atmel_sam_usart
89

910
/** @file
1011
* @brief USART driver for Atmel SAM MCU family.
11-
*
12-
* Note:
13-
* - Only basic USART features sufficient to support printf functionality
14-
* are currently implemented.
1512
*/
1613

1714
#include <errno.h>
@@ -21,14 +18,15 @@
2118
#include <soc.h>
2219
#include <zephyr/drivers/uart.h>
2320
#include <zephyr/drivers/pinctrl.h>
21+
#include <zephyr/drivers/clock_control/atmel_sam_pmc.h>
2422
#include <zephyr/irq.h>
2523

2624
/* Device constant configuration parameters */
2725
struct usart_sam_dev_cfg {
2826
Usart *regs;
29-
uint32_t periph_id;
30-
bool hw_flow_control;
27+
const struct atmel_sam_pmc_config clock_cfg;
3128
const struct pinctrl_dev_config *pcfg;
29+
bool hw_flow_control;
3230

3331
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
3432
uart_irq_config_func_t irq_config_func;
@@ -485,7 +483,8 @@ static int usart_sam_init(const struct device *dev)
485483
Usart * const usart = cfg->regs;
486484

487485
/* Enable USART clock in PMC */
488-
soc_pmc_peripheral_enable(cfg->periph_id);
486+
(void)clock_control_on(SAM_DT_PMC_CONTROLLER,
487+
(clock_control_subsys_t *)&cfg->clock_cfg);
489488

490489
/* Connect pins to the peripheral */
491490
retval = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT);
@@ -542,7 +541,7 @@ static const struct uart_driver_api usart_sam_driver_api = {
542541
#define USART_SAM_DECLARE_CFG(n, IRQ_FUNC_INIT) \
543542
static const struct usart_sam_dev_cfg usart##n##_sam_config = { \
544543
.regs = (Usart *)DT_INST_REG_ADDR(n), \
545-
.periph_id = DT_INST_PROP(n, peripheral_id), \
544+
.clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(n), \
546545
.hw_flow_control = DT_INST_PROP(n, hw_flow_control), \
547546
\
548547
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \

dts/arm/atmel/sam3x.dtsi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,39 +100,39 @@
100100
compatible = "atmel,sam-uart";
101101
reg = <0x400e0800 0x124>;
102102
interrupts = <8 1>;
103-
peripheral-id = <8>;
103+
clocks = <&pmc PMC_TYPE_PERIPHERAL 8>;
104104
status = "disabled";
105105
};
106106

107107
usart0: usart@40098000 {
108108
compatible = "atmel,sam-usart";
109109
reg = <0x40098000 0x130>;
110110
interrupts = <17 0>;
111-
peripheral-id = <17>;
111+
clocks = <&pmc PMC_TYPE_PERIPHERAL 17>;
112112
status = "disabled";
113113
};
114114

115115
usart1: usart@4009c000 {
116116
compatible = "atmel,sam-usart";
117117
reg = <0x4009c000 0x130>;
118118
interrupts = <18 0>;
119-
peripheral-id = <18>;
119+
clocks = <&pmc PMC_TYPE_PERIPHERAL 18>;
120120
status = "disabled";
121121
};
122122

123123
usart2: usart@400a0000 {
124124
compatible = "atmel,sam-usart";
125125
reg = <0x400a0000 0x130>;
126126
interrupts = <19 0>;
127-
peripheral-id = <19>;
127+
clocks = <&pmc PMC_TYPE_PERIPHERAL 19>;
128128
status = "disabled";
129129
};
130130

131131
usart3: usart@400a4000 {
132132
compatible = "atmel,sam-usart";
133133
reg = <0x400a4000 0x130>;
134134
interrupts = <20 0>;
135-
peripheral-id = <20>;
135+
clocks = <&pmc PMC_TYPE_PERIPHERAL 20>;
136136
status = "disabled";
137137
};
138138

dts/arm/atmel/sam4e.dtsi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,31 +110,31 @@
110110
compatible = "atmel,sam-uart";
111111
reg = <0x400e0600 0x140>;
112112
interrupts = <7 1>;
113-
peripheral-id = <7>;
113+
clocks = <&pmc PMC_TYPE_PERIPHERAL 7>;
114114
status = "disabled";
115115
};
116116

117117
uart1: uart@40060600 {
118118
compatible = "atmel,sam-uart";
119119
reg = <0x40060600 0x200>;
120120
interrupts = <45 1>;
121-
peripheral-id = <45>;
121+
clocks = <&pmc PMC_TYPE_PERIPHERAL 45>;
122122
status = "disabled";
123123
};
124124

125125
usart0: usart@400a0000 {
126126
compatible = "atmel,sam-usart";
127127
reg = <0x400a0000 0x4000>;
128128
interrupts = <14 1>;
129-
peripheral-id = <14>;
129+
clocks = <&pmc PMC_TYPE_PERIPHERAL 14>;
130130
status = "disabled";
131131
};
132132

133133
usart1: usart@400a4000 {
134134
compatible = "atmel,sam-usart";
135135
reg = <0x400a4000 0x4000>;
136136
interrupts = <15 1>;
137-
peripheral-id = <15>;
137+
clocks = <&pmc PMC_TYPE_PERIPHERAL 15>;
138138
status = "disabled";
139139
};
140140

dts/arm/atmel/sam4l.dtsi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,28 +134,28 @@
134134
compatible = "atmel,sam-usart";
135135
reg = <0x40024000 0x4000>;
136136
interrupts = <65 1>;
137-
peripheral-id = <8>;
137+
clocks = <&pmc PMC_TYPE_PERIPHERAL 8>;
138138
status = "disabled";
139139
};
140140
usart1: usart@40028000 {
141141
compatible = "atmel,sam-usart";
142142
reg = <0x40028000 0x4000>;
143143
interrupts = <66 1>;
144-
peripheral-id = <9>;
144+
clocks = <&pmc PMC_TYPE_PERIPHERAL 9>;
145145
status = "disabled";
146146
};
147147
usart2: usart@4002c000 {
148148
compatible = "atmel,sam-usart";
149149
reg = <0x4002c000 0x4000>;
150150
interrupts = <67 1>;
151-
peripheral-id = <10>;
151+
clocks = <&pmc PMC_TYPE_PERIPHERAL 10>;
152152
status = "disabled";
153153
};
154154
usart3: usart@40030000 {
155155
compatible = "atmel,sam-usart";
156156
reg = <0x40030000 0x4000>;
157157
interrupts = <68 1>;
158-
peripheral-id = <11>;
158+
clocks = <&pmc PMC_TYPE_PERIPHERAL 11>;
159159
status = "disabled";
160160
};
161161

dts/arm/atmel/sam4s.dtsi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@
112112
compatible = "atmel,sam-uart";
113113
reg = <0x400e0600 0x200>;
114114
interrupts = <8 1>;
115-
peripheral-id = <8>;
115+
clocks = <&pmc PMC_TYPE_PERIPHERAL 8>;
116116
status = "disabled";
117117
};
118118

119119
uart1: uart@400e0800 {
120120
compatible = "atmel,sam-uart";
121121
reg = <0x400e0800 0x200>;
122122
interrupts = <9 1>;
123-
peripheral-id = <9>;
123+
clocks = <&pmc PMC_TYPE_PERIPHERAL 9>;
124124
status = "disabled";
125125
};
126126

@@ -139,15 +139,15 @@
139139
compatible = "atmel,sam-usart";
140140
reg = <0x40024000 0x130>;
141141
interrupts = <14 1>;
142-
peripheral-id = <14>;
142+
clocks = <&pmc PMC_TYPE_PERIPHERAL 14>;
143143
status = "disabled";
144144
};
145145

146146
usart1: usart@40028000 {
147147
compatible = "atmel,sam-usart";
148148
reg = <0x40028000 0x130>;
149149
interrupts = <15 1>;
150-
peripheral-id = <15>;
150+
clocks = <&pmc PMC_TYPE_PERIPHERAL 15>;
151151
status = "disabled";
152152
};
153153

dts/arm/atmel/same70.dtsi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,63 +139,63 @@
139139
compatible = "atmel,sam-uart";
140140
reg = <0x400e0800 0x100>;
141141
interrupts = <7 1>;
142-
peripheral-id = <7>;
142+
clocks = <&pmc PMC_TYPE_PERIPHERAL 7>;
143143
status = "disabled";
144144
};
145145

146146
uart1: uart@400e0a00 {
147147
compatible = "atmel,sam-uart";
148148
reg = <0x400e0a00 0x100>;
149149
interrupts = <8 1>;
150-
peripheral-id = <8>;
150+
clocks = <&pmc PMC_TYPE_PERIPHERAL 8>;
151151
status = "disabled";
152152
};
153153

154154
uart2: uart@400e1a00 {
155155
compatible = "atmel,sam-uart";
156156
reg = <0x400e1a00 0x100>;
157157
interrupts = <44 1>;
158-
peripheral-id = <44>;
158+
clocks = <&pmc PMC_TYPE_PERIPHERAL 44>;
159159
status = "disabled";
160160
};
161161

162162
uart3: uart@400e1c00 {
163163
compatible = "atmel,sam-uart";
164164
reg = <0x400e1c00 0x100>;
165165
interrupts = <45 1>;
166-
peripheral-id = <45>;
166+
clocks = <&pmc PMC_TYPE_PERIPHERAL 45>;
167167
status = "disabled";
168168
};
169169

170170
uart4: uart@400e1e00 {
171171
compatible = "atmel,sam-uart";
172172
reg = <0x400e1e00 0x100>;
173173
interrupts = <46 1>;
174-
peripheral-id = <46>;
174+
clocks = <&pmc PMC_TYPE_PERIPHERAL 46>;
175175
status = "disabled";
176176
};
177177

178178
usart0: usart@40024000 {
179179
compatible = "atmel,sam-usart";
180180
reg = <0x40024000 0x100>;
181181
interrupts = <13 0>;
182-
peripheral-id = <13>;
182+
clocks = <&pmc PMC_TYPE_PERIPHERAL 13>;
183183
status = "disabled";
184184
};
185185

186186
usart1: usart@40028000 {
187187
compatible = "atmel,sam-usart";
188188
reg = <0x40028000 0x100>;
189189
interrupts = <14 0>;
190-
peripheral-id = <14>;
190+
clocks = <&pmc PMC_TYPE_PERIPHERAL 14>;
191191
status = "disabled";
192192
};
193193

194194
usart2: usart@4002c000 {
195195
compatible = "atmel,sam-usart";
196196
reg = <0x4002c000 0x100>;
197197
interrupts = <15 0>;
198-
peripheral-id = <15>;
198+
clocks = <&pmc PMC_TYPE_PERIPHERAL 15>;
199199
status = "disabled";
200200
};
201201

dts/bindings/serial/atmel,sam-uart.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,5 @@ properties:
1313
interrupts:
1414
required: true
1515

16-
peripheral-id:
17-
type: int
18-
description: peripheral ID
16+
clocks:
1917
required: true

dts/bindings/serial/atmel,sam-usart.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,5 @@ properties:
1313
interrupts:
1414
required: true
1515

16-
peripheral-id:
17-
type: int
18-
description: peripheral ID
16+
clocks:
1917
required: true

0 commit comments

Comments
 (0)