1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
4 * Author(s): Patrice Chotard, <patrice.chotard@foss.st.com> for STMicroelectronics.
5 */
6
7 #define LOG_CATEGORY UCLASS_NOP
8
9 #include <dm.h>
10 #include <log.h>
11 #include <misc.h>
12 #include <stm32_rcc.h>
13 #include <dm/device-internal.h>
14 #include <dm/device_compat.h>
15 #include <dm/lists.h>
16
17 static const struct stm32_rcc stm32_rcc_f42x = {
18 .drv_name_clk = "stm32fx_rcc_clock",
19 .drv_name_rst = "stm32_rcc_reset",
20 .soc = STM32F42X,
21 };
22
23 static const struct stm32_rcc stm32_rcc_f469 = {
24 .drv_name_clk = "stm32fx_rcc_clock",
25 .drv_name_rst = "stm32_rcc_reset",
26 .soc = STM32F469,
27 };
28
29 static const struct stm32_rcc stm32_rcc_f7 = {
30 .drv_name_clk = "stm32fx_rcc_clock",
31 .drv_name_rst = "stm32_rcc_reset",
32 .soc = STM32F7,
33 };
34
35 static const struct stm32_rcc stm32_rcc_h7 = {
36 .drv_name_clk = "stm32h7_rcc_clock",
37 .drv_name_rst = "stm32_rcc_reset",
38 };
39
40 static const struct stm32_rcc stm32_rcc_mp15 = {
41 .drv_name_clk = "stm32mp1_clk",
42 .drv_name_rst = "stm32mp1_reset",
43 };
44
45 static const struct stm32_rcc stm32_rcc_mp13 = {
46 .drv_name_clk = "stm32mp13_clk",
47 .drv_name_rst = "stm32mp1_reset",
48 };
49
50 static const struct stm32_rcc stm32_rcc_mp25 = {
51 .drv_name_clk = "stm32mp25_clk",
52 .drv_name_rst = "stm32mp25_reset",
53 };
54
stm32_rcc_bind(struct udevice * dev)55 static int stm32_rcc_bind(struct udevice *dev)
56 {
57 struct udevice *child;
58 struct driver *drv;
59 struct stm32_rcc *rcc_clk =
60 (struct stm32_rcc *)dev_get_driver_data(dev);
61 int ret;
62
63 dev_dbg(dev, "RCC bind\n");
64 drv = lists_driver_lookup_name(rcc_clk->drv_name_clk);
65 if (!drv) {
66 dev_err(dev, "Cannot find driver '%s'\n", rcc_clk->drv_name_clk);
67 return -ENOENT;
68 }
69
70 ret = device_bind_with_driver_data(dev, drv, dev->name,
71 rcc_clk->soc,
72 dev_ofnode(dev), &child);
73
74 if (ret)
75 return ret;
76
77 drv = lists_driver_lookup_name(rcc_clk->drv_name_rst);
78 if (!drv) {
79 dev_err(dev, "Cannot find driver stm32_rcc_reset'\n");
80 return -ENOENT;
81 }
82
83 return device_bind(dev, drv, dev->name, NULL, dev_ofnode(dev), &child);
84 }
85
86 static const struct udevice_id stm32_rcc_ids[] = {
87 {.compatible = "st,stm32f42xx-rcc", .data = (ulong)&stm32_rcc_f42x },
88 {.compatible = "st,stm32f469-rcc", .data = (ulong)&stm32_rcc_f469 },
89 {.compatible = "st,stm32f746-rcc", .data = (ulong)&stm32_rcc_f7 },
90 {.compatible = "st,stm32h743-rcc", .data = (ulong)&stm32_rcc_h7 },
91 {.compatible = "st,stm32mp1-rcc", .data = (ulong)&stm32_rcc_mp15 },
92 {.compatible = "st,stm32mp1-rcc-secure", .data = (ulong)&stm32_rcc_mp15 },
93 {.compatible = "st,stm32mp13-rcc", .data = (ulong)&stm32_rcc_mp13 },
94 {.compatible = "st,stm32mp25-rcc", .data = (ulong)&stm32_rcc_mp25 },
95 { }
96 };
97
98 U_BOOT_DRIVER(stm32_rcc) = {
99 .name = "stm32-rcc",
100 .id = UCLASS_NOP,
101 .of_match = stm32_rcc_ids,
102 .bind = stm32_rcc_bind,
103 };
104