Skip to content

Commit c77c1cc

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

File tree

10 files changed

+60
-47
lines changed

10 files changed

+60
-47
lines changed

drivers/gpio/gpio_sam.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2018 Justin Watson
3+
* Copyright (c) 2023 Gerson Fernando Budke
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
@@ -12,6 +13,7 @@
1213
#include <zephyr/init.h>
1314
#include <soc.h>
1415
#include <zephyr/drivers/gpio.h>
16+
#include <zephyr/drivers/clock_control/atmel_sam_pmc.h>
1517
#include <zephyr/dt-bindings/gpio/atmel-sam-gpio.h>
1618
#include <zephyr/irq.h>
1719

@@ -24,7 +26,8 @@ struct gpio_sam_config {
2426
struct gpio_driver_config common;
2527
Pio *regs;
2628
config_func_t config_func;
27-
uint32_t periph_id;
29+
30+
const struct atmel_sam_pmc_config clock_cfg;
2831
};
2932

3033
struct gpio_sam_runtime {
@@ -305,8 +308,9 @@ int gpio_sam_init(const struct device *dev)
305308
{
306309
const struct gpio_sam_config * const cfg = dev->config;
307310

308-
/* The peripheral clock must be enabled for the interrupts to work. */
309-
soc_pmc_peripheral_enable(cfg->periph_id);
311+
/* Enable GPIO clock in PMC. This is necessary to enable interrupts */
312+
(void)clock_control_on(SAM_DT_PMC_CONTROLLER,
313+
(clock_control_subsys_t *)&cfg->clock_cfg);
310314

311315
cfg->config_func(dev);
312316

@@ -321,7 +325,7 @@ int gpio_sam_init(const struct device *dev)
321325
.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(n),\
322326
}, \
323327
.regs = (Pio *)DT_INST_REG_ADDR(n), \
324-
.periph_id = DT_INST_PROP(n, peripheral_id), \
328+
.clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(n), \
325329
.config_func = port_##n##_sam_config_func, \
326330
}; \
327331
\

drivers/gpio/gpio_sam4l.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2018 Justin Watson
3-
* Copyright (c) 2020 Gerson Fernando Budke <[email protected]>
3+
* Copyright (c) 2020-2023 Gerson Fernando Budke <[email protected]>
44
*
55
* SPDX-License-Identifier: Apache-2.0
66
*/
@@ -13,6 +13,7 @@
1313
#include <zephyr/init.h>
1414
#include <soc.h>
1515
#include <zephyr/drivers/gpio.h>
16+
#include <zephyr/drivers/clock_control/atmel_sam_pmc.h>
1617
#include <zephyr/irq.h>
1718

1819
#include <zephyr/drivers/gpio/gpio_utils.h>
@@ -24,7 +25,8 @@ struct gpio_sam_config {
2425
struct gpio_driver_config common;
2526
Gpio *regs;
2627
config_func_t config_func;
27-
uint32_t periph_id;
28+
29+
const struct atmel_sam_pmc_config clock_cfg;
2830
};
2931

3032
struct gpio_sam_runtime {
@@ -230,7 +232,9 @@ int gpio_sam_init(const struct device *dev)
230232
{
231233
const struct gpio_sam_config * const cfg = dev->config;
232234

233-
soc_pmc_peripheral_enable(cfg->periph_id);
235+
/* Enable GPIO clock in PM */
236+
(void)clock_control_on(SAM_DT_PMC_CONTROLLER,
237+
(clock_control_subsys_t *)&cfg->clock_cfg);
234238

235239
cfg->config_func(dev);
236240

@@ -254,7 +258,7 @@ int gpio_sam_init(const struct device *dev)
254258
.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(n),\
255259
}, \
256260
.regs = (Gpio *)DT_INST_REG_ADDR(n), \
257-
.periph_id = DT_INST_PROP(n, peripheral_id), \
261+
.clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(n), \
258262
.config_func = port_##n##_sam_config_func, \
259263
}; \
260264
\

drivers/pinctrl/pinctrl_sam.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/*
2-
* Copyright (c) 2022, Gerson Fernando Budke <[email protected]>
2+
* Copyright (c) 2022-2023, Gerson Fernando Budke <[email protected]>
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

77
#include <zephyr/drivers/pinctrl.h>
8+
#include <zephyr/drivers/clock_control/atmel_sam_pmc.h>
89
#include <soc_gpio.h>
910

1011
/** Utility macro that expands to the GPIO port address if it exists */
@@ -13,9 +14,9 @@
1314
(DT_REG_ADDR(DT_NODELABEL(nodelabel)),))
1415

1516
/** Utility macro that expands to the GPIO Peripheral ID if it exists */
16-
#define SAM_PORT_PERIPH_ID_OR_NONE(nodelabel) \
17+
#define SAM_PORT_CLOCKS_OR_NONE(nodelabel) \
1718
IF_ENABLED(DT_NODE_EXISTS(DT_NODELABEL(nodelabel)), \
18-
(DT_PROP(DT_NODELABEL(nodelabel), peripheral_id),))
19+
(SAM_DT_CLOCK_PMC_CFG(0, DT_NODELABEL(nodelabel)),))
1920

2021
/** SAM port addresses */
2122
static const uint32_t sam_port_addrs[] = {
@@ -33,19 +34,19 @@ static const uint32_t sam_port_addrs[] = {
3334
#endif
3435
};
3536

36-
/** SAM port peripheral id */
37-
static const uint32_t sam_port_periph_id[] = {
37+
/** SAM port clocks */
38+
static const struct atmel_sam_pmc_config sam_port_clocks[] = {
3839
#ifdef ID_GPIO
39-
SAM_PORT_PERIPH_ID_OR_NONE(gpioa)
40-
SAM_PORT_PERIPH_ID_OR_NONE(gpiob)
41-
SAM_PORT_PERIPH_ID_OR_NONE(gpioc)
40+
SAM_PORT_CLOCKS_OR_NONE(gpioa)
41+
SAM_PORT_CLOCKS_OR_NONE(gpiob)
42+
SAM_PORT_CLOCKS_OR_NONE(gpioc)
4243
#else
43-
SAM_PORT_PERIPH_ID_OR_NONE(pioa)
44-
SAM_PORT_PERIPH_ID_OR_NONE(piob)
45-
SAM_PORT_PERIPH_ID_OR_NONE(pioc)
46-
SAM_PORT_PERIPH_ID_OR_NONE(piod)
47-
SAM_PORT_PERIPH_ID_OR_NONE(pioe)
48-
SAM_PORT_PERIPH_ID_OR_NONE(piof)
44+
SAM_PORT_CLOCKS_OR_NONE(pioa)
45+
SAM_PORT_CLOCKS_OR_NONE(piob)
46+
SAM_PORT_CLOCKS_OR_NONE(pioc)
47+
SAM_PORT_CLOCKS_OR_NONE(piod)
48+
SAM_PORT_CLOCKS_OR_NONE(pioe)
49+
SAM_PORT_CLOCKS_OR_NONE(piof)
4950
#endif
5051
};
5152

@@ -63,7 +64,7 @@ static void pinctrl_configure_pin(pinctrl_soc_pin_t pin)
6364
#else
6465
soc_pin.regs = (Pio *) sam_port_addrs[port_idx];
6566
#endif
66-
soc_pin.periph_id = sam_port_periph_id[port_idx];
67+
soc_pin.periph_id = sam_port_clocks[port_idx].peripheral_id;
6768
soc_pin.mask = 1 << SAM_PINMUX_PIN_GET(pin);
6869
soc_pin.flags = SAM_PINCTRL_FLAGS_GET(pin) << SOC_GPIO_FLAGS_POS;
6970

dts/arm/atmel/sam3x.dtsi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
compatible = "atmel,sam-gpio";
147147
reg = <0x400e0e00 0x190>;
148148
interrupts = <11 1>;
149-
peripheral-id = <11>;
149+
clocks = <&pmc PMC_TYPE_PERIPHERAL 11>;
150150
gpio-controller;
151151
#gpio-cells = <2>;
152152
#atmel,pin-cells = <2>;
@@ -156,7 +156,7 @@
156156
compatible = "atmel,sam-gpio";
157157
reg = <0x400e1000 0x190>;
158158
interrupts = <12 1>;
159-
peripheral-id = <12>;
159+
clocks = <&pmc PMC_TYPE_PERIPHERAL 12>;
160160
gpio-controller;
161161
#gpio-cells = <2>;
162162
#atmel,pin-cells = <2>;
@@ -166,7 +166,7 @@
166166
compatible = "atmel,sam-gpio";
167167
reg = <0x400e1200 0x190>;
168168
interrupts = <13 1>;
169-
peripheral-id = <13>;
169+
clocks = <&pmc PMC_TYPE_PERIPHERAL 13>;
170170
gpio-controller;
171171
#gpio-cells = <2>;
172172
#atmel,pin-cells = <2>;
@@ -176,7 +176,7 @@
176176
compatible = "atmel,sam-gpio";
177177
reg = <0x400e1400 0x190>;
178178
interrupts = <14 1>;
179-
peripheral-id = <14>;
179+
clocks = <&pmc PMC_TYPE_PERIPHERAL 14>;
180180
gpio-controller;
181181
#gpio-cells = <2>;
182182
#atmel,pin-cells = <2>;
@@ -186,7 +186,7 @@
186186
compatible = "atmel,sam-gpio";
187187
reg = <0x400e1600 0x190>;
188188
interrupts = <15 1>;
189-
peripheral-id = <15>;
189+
clocks = <&pmc PMC_TYPE_PERIPHERAL 15>;
190190
gpio-controller;
191191
#gpio-cells = <2>;
192192
#atmel,pin-cells = <2>;

dts/arm/atmel/sam4e.dtsi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
compatible = "atmel,sam-gpio";
166166
reg = <0x400e0e00 0x200>;
167167
interrupts = <9 1>;
168-
peripheral-id = <9>;
168+
clocks = <&pmc PMC_TYPE_PERIPHERAL 9>;
169169
gpio-controller;
170170
#gpio-cells = <2>;
171171
#atmel,pin-cells = <2>;
@@ -175,7 +175,7 @@
175175
compatible = "atmel,sam-gpio";
176176
reg = <0x400e1000 0x200>;
177177
interrupts = <10 1>;
178-
peripheral-id = <10>;
178+
clocks = <&pmc PMC_TYPE_PERIPHERAL 10>;
179179
gpio-controller;
180180
#gpio-cells = <2>;
181181
#atmel,pin-cells = <2>;
@@ -185,7 +185,7 @@
185185
compatible = "atmel,sam-gpio";
186186
reg = <0x400e1200 0x200>;
187187
interrupts = <11 1>;
188-
peripheral-id = <11>;
188+
clocks = <&pmc PMC_TYPE_PERIPHERAL 11>;
189189
gpio-controller;
190190
#gpio-cells = <2>;
191191
#atmel,pin-cells = <2>;
@@ -195,7 +195,7 @@
195195
compatible = "atmel,sam-gpio";
196196
reg = <0x400e1400 0x200>;
197197
interrupts = <12 1>;
198-
peripheral-id = <12>;
198+
clocks = <&pmc PMC_TYPE_PERIPHERAL 12>;
199199
gpio-controller;
200200
#gpio-cells = <2>;
201201
#atmel,pin-cells = <2>;
@@ -205,7 +205,7 @@
205205
compatible = "atmel,sam-gpio";
206206
reg = <0x400e1600 0x200>;
207207
interrupts = <13 1>;
208-
peripheral-id = <13>;
208+
clocks = <&pmc PMC_TYPE_PERIPHERAL 13>;
209209
gpio-controller;
210210
#gpio-cells = <2>;
211211
#atmel,pin-cells = <2>;

dts/arm/atmel/sam4l.dtsi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180
compatible = "atmel,sam4l-gpio";
181181
reg = <0x400e1000 0x200>;
182182
interrupts = <25 1>, <26 1>, <27 1>, <28 1>;
183-
peripheral-id = <68>;
183+
clocks = <&pmc PMC_TYPE_PERIPHERAL 68>;
184184
gpio-controller;
185185
#gpio-cells = <2>;
186186
#atmel,pin-cells = <2>;
@@ -189,7 +189,7 @@
189189
compatible = "atmel,sam4l-gpio";
190190
reg = <0x400e1200 0x200>;
191191
interrupts = <29 1>, <30 1>, <31 1>, <32 1>;
192-
peripheral-id = <68>;
192+
clocks = <&pmc PMC_TYPE_PERIPHERAL 68>;
193193
gpio-controller;
194194
#gpio-cells = <2>;
195195
#atmel,pin-cells = <2>;
@@ -198,7 +198,7 @@
198198
compatible = "atmel,sam4l-gpio";
199199
reg = <0x400e1400 0x200>;
200200
interrupts = <33 1>, <34 1>, <35 1>, <36 1>;
201-
peripheral-id = <68>;
201+
clocks = <&pmc PMC_TYPE_PERIPHERAL 68>;
202202
gpio-controller;
203203
#gpio-cells = <2>;
204204
#atmel,pin-cells = <2>;

dts/arm/atmel/sam4s.dtsi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
compatible = "atmel,sam-gpio";
163163
reg = <0x400e0e00 0x190>;
164164
interrupts = <11 1>;
165-
peripheral-id = <11>;
165+
clocks = <&pmc PMC_TYPE_PERIPHERAL 11>;
166166
gpio-controller;
167167
#gpio-cells = <2>;
168168
#atmel,pin-cells = <2>;
@@ -172,7 +172,7 @@
172172
compatible = "atmel,sam-gpio";
173173
reg = <0x400e1000 0x190>;
174174
interrupts = <12 1>;
175-
peripheral-id = <12>;
175+
clocks = <&pmc PMC_TYPE_PERIPHERAL 12>;
176176
gpio-controller;
177177
#gpio-cells = <2>;
178178
#atmel,pin-cells = <2>;
@@ -182,7 +182,7 @@
182182
compatible = "atmel,sam-gpio";
183183
reg = <0x400e1200 0x190>;
184184
interrupts = <13 1>;
185-
peripheral-id = <13>;
185+
clocks = <&pmc PMC_TYPE_PERIPHERAL 13>;
186186
gpio-controller;
187187
#gpio-cells = <2>;
188188
#atmel,pin-cells = <2>;

dts/arm/atmel/same70.dtsi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@
236236
compatible = "atmel,sam-gpio";
237237
reg = <0x400e0e00 0x190>;
238238
interrupts = <10 1>;
239-
peripheral-id = <10>;
239+
clocks = <&pmc PMC_TYPE_PERIPHERAL 10>;
240240
gpio-controller;
241241
#gpio-cells = <2>;
242242
#atmel,pin-cells = <2>;
@@ -246,7 +246,7 @@
246246
compatible = "atmel,sam-gpio";
247247
reg = <0x400e1000 0x190>;
248248
interrupts = <11 1>;
249-
peripheral-id = <11>;
249+
clocks = <&pmc PMC_TYPE_PERIPHERAL 11>;
250250
gpio-controller;
251251
#gpio-cells = <2>;
252252
#atmel,pin-cells = <2>;
@@ -256,7 +256,7 @@
256256
compatible = "atmel,sam-gpio";
257257
reg = <0x400e1200 0x190>;
258258
interrupts = <12 1>;
259-
peripheral-id = <12>;
259+
clocks = <&pmc PMC_TYPE_PERIPHERAL 12>;
260260
gpio-controller;
261261
#gpio-cells = <2>;
262262
#atmel,pin-cells = <2>;
@@ -266,7 +266,7 @@
266266
compatible = "atmel,sam-gpio";
267267
reg = <0x400e1400 0x190>;
268268
interrupts = <16 1>;
269-
peripheral-id = <16>;
269+
clocks = <&pmc PMC_TYPE_PERIPHERAL 16>;
270270
gpio-controller;
271271
#gpio-cells = <2>;
272272
#atmel,pin-cells = <2>;
@@ -276,7 +276,7 @@
276276
compatible = "atmel,sam-gpio";
277277
reg = <0x400e1600 0x190>;
278278
interrupts = <17 1>;
279-
peripheral-id = <17>;
279+
clocks = <&pmc PMC_TYPE_PERIPHERAL 17>;
280280
gpio-controller;
281281
#gpio-cells = <2>;
282282
#atmel,pin-cells = <2>;

dts/bindings/gpio/atmel,sam-gpio.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) 2021-2023, Gerson Fernando Budke <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
14
description: SAM GPIO PORT node
25

36
compatible: "atmel,sam-gpio"
@@ -11,9 +14,7 @@ properties:
1114
interrupts:
1215
required: true
1316

14-
peripheral-id:
15-
type: int
16-
description: peripheral ID
17+
clocks:
1718
required: true
1819

1920
"#gpio-cells":

dts/bindings/gpio/atmel,sam4l-gpio.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) 2021-2023, Gerson Fernando Budke <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
14
description: SAM4L GPIO PORT node
25

36
compatible: "atmel,sam4l-gpio"

0 commit comments

Comments
 (0)