Skip to content

Commit 5cdfd12

Browse files
galakcarlescufi
authored andcommitted
drivers: clock_control: beetle: Use devicetree for clock control
Add simple clock control node in devicetree for beetle to handle relationship between drivers (uart, timers, gpio) and clock controller device. Signed-off-by: Kumar Gala <[email protected]>
1 parent 762eadc commit 5cdfd12

File tree

8 files changed

+60
-27
lines changed

8 files changed

+60
-27
lines changed

boards/arm/v2m_beetle/v2m_beetle.dts

+15-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
/dts-v1/;
44

55
#include <arm/armv7-m.dtsi>
6-
76
/ {
87
compatible = "arm,beetle";
98
#address-cells = <1>;
@@ -53,27 +52,30 @@
5352
reg = <0x40000000 0x1000>;
5453
interrupts = <8 3>;
5554
label = "TIMER_0";
55+
clocks = <&syscon>;
5656
};
5757

5858
timer1: timer@40001000 {
5959
compatible = "arm,cmsdk-timer";
6060
reg = <0x40001000 0x1000>;
6161
interrupts = <9 3>;
6262
label = "TIMER_1";
63+
clocks = <&syscon>;
6364
};
6465

6566
dtimer0: dtimer@40002000 {
6667
compatible = "arm,cmsdk-dtimer";
6768
reg = <0x40002000 0x1000>;
6869
interrupts = <10 3>;
6970
label = "DTIMER_0";
71+
clocks = <&syscon>;
7072
};
7173

7274
uart0: uart@40004000 {
7375
compatible = "arm,cmsdk-uart";
7476
reg = <0x40004000 0x1000>;
7577
interrupts = <0 3>;
76-
clocks = <&sysclk>;
78+
clocks = <&sysclk &syscon>;
7779
current-speed = <115200>;
7880
label = "UART_0";
7981
};
@@ -82,7 +84,7 @@
8284
compatible = "arm,cmsdk-uart";
8385
reg = <0x40005000 0x1000>;
8486
interrupts = <2 3>;
85-
clocks = <&sysclk>;
87+
clocks = <&sysclk &syscon>;
8688
current-speed = <115200>;
8789
label = "UART_1";
8890
};
@@ -101,6 +103,7 @@
101103
gpio-controller;
102104
#gpio-cells = <2>;
103105
label = "GPIO_0";
106+
clocks = <&syscon>;
104107
};
105108

106109
gpio1: gpio@40011000 {
@@ -110,6 +113,7 @@
110113
gpio-controller;
111114
#gpio-cells = <2>;
112115
label = "GPIO_1";
116+
clocks = <&syscon>;
113117
};
114118

115119
gpio2: gpio@40012000 {
@@ -119,6 +123,7 @@
119123
gpio-controller;
120124
#gpio-cells = <2>;
121125
label = "GPIO_2";
126+
clocks = <&syscon>;
122127
};
123128

124129
gpio3: gpio@40013000 {
@@ -128,6 +133,13 @@
128133
gpio-controller;
129134
#gpio-cells = <2>;
130135
label = "GPIO_3";
136+
clocks = <&syscon>;
137+
};
138+
139+
syscon: syscon@4001f000 {
140+
compatible = "arm,beetle-syscon";
141+
reg = <0x4001f000 0x1000>;
142+
#clock-cells = <0>;
131143
};
132144
};
133145
};

drivers/clock_control/Kconfig.beetle

+3-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ menuconfig CLOCK_CONTROL_BEETLE
1313
Enable driver for Reset & Clock Control subsystem found
1414
in STM32F4 family of MCUs
1515

16-
config ARM_CLOCK_CONTROL_DEV_NAME
17-
string "Clock Config Device name"
18-
default "CLOCK_CONTROL_0"
19-
depends on CLOCK_CONTROL_BEETLE
20-
help
21-
Configure Clock Config Device name
16+
if CLOCK_CONTROL_BEETLE
2217

2318
config CLOCK_CONTROL_BEETLE_ENABLE_PLL
2419
bool "PLL on Beetle"
@@ -28,4 +23,6 @@ config CLOCK_CONTROL_BEETLE_ENABLE_PLL
2823

2924
Select n if not sure.
3025

26+
endif # CLOCK_CONTROL_BEETLE
27+
3128
endif # SOC_FAMILY_ARM

drivers/clock_control/beetle_clock_control.c

+6-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#define DT_DRV_COMPAT arm_cortex_m3
7+
#define DT_DRV_COMPAT arm_beetle_syscon
88

99
/**
1010
* @file
@@ -235,17 +235,14 @@ static int beetle_clock_control_init(const struct device *dev)
235235

236236
static const struct beetle_clock_control_cfg_t beetle_cc_cfg = {
237237
.clock_control_id = 0,
238-
.freq = DT_INST_PROP(0, clock_frequency),
238+
.freq = DT_PROP(DT_PATH(cpus, cpu_0), clock_frequency),
239239
};
240240

241241
/**
242242
* @brief Clock Control device init
243243
*
244244
*/
245-
DEVICE_DEFINE(clock_control_beetle, CONFIG_ARM_CLOCK_CONTROL_DEV_NAME,
246-
&beetle_clock_control_init,
247-
NULL,
248-
NULL, &beetle_cc_cfg,
249-
PRE_KERNEL_1,
250-
CONFIG_CLOCK_CONTROL_INIT_PRIORITY,
251-
&beetle_clock_control_api);
245+
DEVICE_DT_INST_DEFINE(0, &beetle_clock_control_init, NULL,
246+
NULL, &beetle_cc_cfg, PRE_KERNEL_1,
247+
CONFIG_CLOCK_CONTROL_INIT_PRIORITY,
248+
&beetle_clock_control_api);

drivers/counter/timer_dtmr_cmsdk_apb.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,11 @@ static int dtmr_cmsdk_apb_init(const struct device *dev)
144144

145145
#ifdef CONFIG_CLOCK_CONTROL
146146
/* Enable clock for subsystem */
147-
const struct device *clk =
148-
device_get_binding(CONFIG_ARM_CLOCK_CONTROL_DEV_NAME);
147+
const struct device *clk = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(0));
148+
149+
if (!device_is_ready(clk)) {
150+
return -ENODEV;
151+
}
149152

150153
#ifdef CONFIG_SOC_SERIES_BEETLE
151154
clock_control_on(clk, (clock_control_subsys_t *) &cfg->dtimer_cc_as);

drivers/counter/timer_tmr_cmsdk_apb.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,11 @@ static int tmr_cmsdk_apb_init(const struct device *dev)
147147

148148
#ifdef CONFIG_CLOCK_CONTROL
149149
/* Enable clock for subsystem */
150-
const struct device *clk =
151-
device_get_binding(CONFIG_ARM_CLOCK_CONTROL_DEV_NAME);
150+
const struct device *clk = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(0));
151+
152+
if (!device_is_ready(clk)) {
153+
return -ENODEV;
154+
}
152155

153156
#ifdef CONFIG_SOC_SERIES_BEETLE
154157
clock_control_on(clk, (clock_control_subsys_t *) &cfg->timer_cc_as);

drivers/gpio/gpio_cmsdk_ahb.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,11 @@ static int gpio_cmsdk_ahb_init(const struct device *dev)
238238

239239
#ifdef CONFIG_CLOCK_CONTROL
240240
/* Enable clock for subsystem */
241-
const struct device *clk =
242-
device_get_binding(CONFIG_ARM_CLOCK_CONTROL_DEV_NAME);
241+
const struct device *clk = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(0));
242+
243+
if (!device_is_ready(clk)) {
244+
return -ENODEV;
245+
}
243246

244247
#ifdef CONFIG_SOC_SERIES_BEETLE
245248
clock_control_on(clk, (clock_control_subsys_t *) &cfg->gpio_cc_as);

drivers/serial/uart_cmsdk_apb.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,13 @@ static int uart_cmsdk_apb_init(const struct device *dev)
126126

127127
#ifdef CONFIG_CLOCK_CONTROL
128128
/* Enable clock for subsystem */
129-
const struct device *clk =
130-
device_get_binding(CONFIG_ARM_CLOCK_CONTROL_DEV_NAME);
131-
129+
const struct device *clk = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR_BY_IDX(0, 1));
132130
struct uart_cmsdk_apb_dev_data * const data = dev->data;
133131

132+
if (!device_is_ready(clk)) {
133+
return -ENODEV;
134+
}
135+
134136
#ifdef CONFIG_SOC_SERIES_BEETLE
135137
clock_control_on(clk, (clock_control_subsys_t *) &data->uart_cc_as);
136138
clock_control_on(clk, (clock_control_subsys_t *) &data->uart_cc_ss);
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright (c) 2022, Kumar Gala <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: ARM V2M Beetle System Control
5+
6+
compatible: "arm,beetle-syscon"
7+
8+
include: [clock-controller.yaml, base.yaml]
9+
10+
properties:
11+
reg:
12+
required: true
13+
14+
"#clock-cells":
15+
required: true
16+
const: 0

0 commit comments

Comments
 (0)