Skip to content

Commit a190843

Browse files
author
Declan Snyder
committed
drivers: nxp: Convert to unified clock control macros
Convert NXP clock control drivers and clock consumer drivers to the new unified macros. This has to be all in one commit because it is very hard to make it bisectable otherwise. This is because many of the drivers are actually benefitting from these macros due to they have a bunch of code that is coupling to multiple different consumers and so forth. NOTE: right now this commit is only containing clock driver changes, not consumers. And they are not finished Signed-off-by: Declan Snyder <[email protected]>
1 parent 9b86492 commit a190843

File tree

3 files changed

+99
-7
lines changed

3 files changed

+99
-7
lines changed

drivers/clock_control/clock_control_mcux_sim.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,42 @@
1515
#include <zephyr/logging/log.h>
1616
LOG_MODULE_REGISTER(clock_control);
1717

18+
struct kinetis_sim_spec {
19+
uint32_t name;
20+
uint32_t offset;
21+
uint32_t bits;
22+
};
23+
24+
static int kinetis_sim_get_spec(clock_control_subsys_t subsys, struct kinetis_sim_spec *spec)
25+
{
26+
struct clock_control_dt_spec *dt_spec = subsys;
27+
28+
if (dt_spec->len != 3) {
29+
return -EINVAL;
30+
}
31+
32+
spec->name = dt_spec->cells[0];
33+
spec->offset = dt_spec->cells[1];
34+
spec->bits = dt_spec->cells[2];
35+
36+
return 0;
37+
}
38+
39+
static int kinetis_sim_get_key(clock_control_subsys_t subsys, uint32_t *key)
40+
{
41+
struct kinetis_sim_spec spec;
42+
int ret;
43+
44+
ret = kinetis_sim_get_spec(subsys, &spec);
45+
if (ret) {
46+
return ret;
47+
}
48+
49+
*key = CLK_GATE_DEFINE(spec.offset, spec.bits);
50+
51+
return 0;
52+
}
53+
1854
static int mcux_sim_on(const struct device *dev,
1955
clock_control_subsys_t sub_system)
2056
{

drivers/clock_control/clock_control_mcux_syscon.c

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,48 @@
1515
#include <zephyr/logging/log.h>
1616
LOG_MODULE_REGISTER(clock_control);
1717

18+
struct lpc_syscon_spec {
19+
uint32_t name;
20+
};
21+
22+
static int lpc_syscon_get_spec(clock_control_subsys_t subsys, struct lpc_syscon_spec *spec)
23+
{
24+
struct clock_control_dt_spec *dt_spec = subsys;
25+
26+
if (dt_spec->len != 1) {
27+
return -EINVAL;
28+
}
29+
30+
spec->name = *(dt_spec->cells);
31+
32+
return 0;
33+
}
34+
35+
static int lpc_syscon_get_name(clock_control_subsys_t dt_spec, uint32_t *name)
36+
{
37+
struct lpc_syscon_spec spec;
38+
int ret;
39+
40+
ret = lpc_syscon_get_spec(dt_spec, &spec);
41+
if (ret) {
42+
return ret;
43+
}
44+
45+
*name = spec.name;
46+
47+
return 0;
48+
}
49+
1850
static int mcux_lpc_syscon_clock_control_on(const struct device *dev,
19-
clock_control_subsys_t sub_system)
51+
clock_control_subsys_t subsys)
2052
{
53+
uint32_t sub_system;
54+
55+
lpc_syscon_get_name(subsys, &sub_system);
56+
if (ret) {
57+
return ret;
58+
}
59+
2160
#if defined(CONFIG_CAN_MCUX_MCAN)
2261
if ((uint32_t)sub_system == MCUX_MCAN_CLK) {
2362
CLOCK_EnableClock(kCLOCK_Mcan);
@@ -149,7 +188,12 @@ static int mcux_lpc_syscon_clock_control_get_subsys_rate(const struct device *de
149188
clock_control_subsys_t sub_system,
150189
uint32_t *rate)
151190
{
152-
uint32_t clock_name = (uint32_t)sub_system;
191+
uint32_t clock_name = 0;
192+
193+
lpc_syscon_get_name(sub_system, &clock_name);
194+
if (ret) {
195+
return ret;
196+
}
153197

154198
switch (clock_name) {
155199

@@ -602,9 +646,14 @@ __weak int flexspi_clock_set_freq(uint32_t clock_name, uint32_t freq)
602646
static int SYSCON_SET_FUNC_ATTR mcux_lpc_syscon_clock_control_set_subsys_rate(
603647
const struct device *dev, clock_control_subsys_t subsys, clock_control_subsys_rate_t rate)
604648
{
605-
uint32_t clock_name = (uintptr_t)subsys;
649+
uint32_t clock_name;
606650
uint32_t clock_rate = (uintptr_t)rate;
607651

652+
lpc_syscon_get_name(subsys, &clock_name);
653+
if (ret) {
654+
return ret;
655+
}
656+
608657
switch (clock_name) {
609658
case MCUX_FLEXSPI_CLK:
610659
#if defined(CONFIG_MEMC)
@@ -632,10 +681,16 @@ static int SYSCON_SET_FUNC_ATTR mcux_lpc_syscon_clock_control_set_subsys_rate(
632681
static int mcux_lpc_syscon_clock_control_configure(const struct device *dev,
633682
clock_control_subsys_t sub_system, void *data)
634683
{
684+
uint32_t clock_name = 0;
685+
int flexcomm_num = -1;
686+
687+
lpc_syscon_get_name(sub_system, &clock_name);
688+
if (ret) {
689+
return ret;
690+
}
691+
635692
#ifdef CONFIG_SOC_SERIES_RW6XX
636693
#define FLEXCOMM_LP_CLK_DECODE(n) (n & 0x80)
637-
uint32_t clock_name = (uint32_t)sub_system;
638-
int flexcomm_num = -1;
639694

640695
switch (clock_name) {
641696
case MCUX_FLEXCOMM0_CLK:

drivers/serial/uart_mcux_flexcomm.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,8 +1417,7 @@ static void serial_mcux_flexcomm_##n##_pm_exit(enum pm_state state) \
14171417
static const struct mcux_flexcomm_config mcux_flexcomm_##n##_config = { \
14181418
.base = (USART_Type *)DT_INST_REG_ADDR(n), \
14191419
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(n)), \
1420-
.clock_subsys = \
1421-
(clock_control_subsys_t)DT_INST_CLOCKS_CELL(n, name), \
1420+
.clock_subsys = CLOCK_CONTROL_DT_SPEC_INST_GET(n, clocks), \
14221421
.baud_rate = DT_INST_PROP(n, current_speed), \
14231422
.parity = DT_INST_ENUM_IDX(n, parity), \
14241423
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
@@ -1438,6 +1437,8 @@ static struct mcux_flexcomm_data mcux_flexcomm_##n##_data = { \
14381437
\
14391438
PINCTRL_DT_INST_DEFINE(n); \
14401439
\
1440+
CLOCK_CONTROL_DT_SPEC_INST_DEFINE(n, clocks); \
1441+
\
14411442
UART_MCUX_FLEXCOMM_PM_UNLOCK_FUNC_DEFINE(n) \
14421443
UART_MCUX_FLEXCOMM_WAKEUP_CFG_DEFINE(n) \
14431444
UART_MCUX_FLEXCOMM_PM_HANDLES_DEFINE(n) \

0 commit comments

Comments
 (0)