183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
24e280b91SChristophe Kerello /*
33bc599c9SPatrice Chotard * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
43bc599c9SPatrice Chotard * Author(s): Patrice Chotard, <patrice.chotard@st.com> for STMicroelectronics.
54e280b91SChristophe Kerello */
64e280b91SChristophe Kerello
74e280b91SChristophe Kerello #include <common.h>
84e280b91SChristophe Kerello #include <dm.h>
94e280b91SChristophe Kerello #include <misc.h>
10928954feSPatrice Chotard #include <stm32_rcc.h>
11928954feSPatrice Chotard #include <dm/device-internal.h>
124e280b91SChristophe Kerello #include <dm/lists.h>
134e280b91SChristophe Kerello
148b414645SPatrice Chotard struct stm32_rcc_clk stm32_rcc_clk_f42x = {
15928954feSPatrice Chotard .drv_name = "stm32fx_rcc_clock",
168b414645SPatrice Chotard .soc = STM32F42X,
178b414645SPatrice Chotard };
188b414645SPatrice Chotard
198b414645SPatrice Chotard struct stm32_rcc_clk stm32_rcc_clk_f469 = {
208b414645SPatrice Chotard .drv_name = "stm32fx_rcc_clock",
218b414645SPatrice Chotard .soc = STM32F469,
22928954feSPatrice Chotard };
23928954feSPatrice Chotard
24928954feSPatrice Chotard struct stm32_rcc_clk stm32_rcc_clk_f7 = {
25928954feSPatrice Chotard .drv_name = "stm32fx_rcc_clock",
26928954feSPatrice Chotard .soc = STM32F7,
27928954feSPatrice Chotard };
28928954feSPatrice Chotard
29928954feSPatrice Chotard struct stm32_rcc_clk stm32_rcc_clk_h7 = {
30928954feSPatrice Chotard .drv_name = "stm32h7_rcc_clock",
31928954feSPatrice Chotard };
32928954feSPatrice Chotard
33*d090cbabSPatrick Delaunay struct stm32_rcc_clk stm32_rcc_clk_mp1 = {
34*d090cbabSPatrick Delaunay .drv_name = "stm32mp1_clk",
35*d090cbabSPatrick Delaunay .soc = STM32MP1,
36*d090cbabSPatrick Delaunay };
37*d090cbabSPatrick Delaunay
stm32_rcc_bind(struct udevice * dev)384e280b91SChristophe Kerello static int stm32_rcc_bind(struct udevice *dev)
394e280b91SChristophe Kerello {
404e280b91SChristophe Kerello struct udevice *child;
41928954feSPatrice Chotard struct driver *drv;
42928954feSPatrice Chotard struct stm32_rcc_clk *rcc_clk =
43928954feSPatrice Chotard (struct stm32_rcc_clk *)dev_get_driver_data(dev);
44928954feSPatrice Chotard int ret;
454e280b91SChristophe Kerello
464e280b91SChristophe Kerello debug("%s(dev=%p)\n", __func__, dev);
47928954feSPatrice Chotard drv = lists_driver_lookup_name(rcc_clk->drv_name);
48928954feSPatrice Chotard if (!drv) {
49928954feSPatrice Chotard debug("Cannot find driver '%s'\n", rcc_clk->drv_name);
50928954feSPatrice Chotard return -ENOENT;
51928954feSPatrice Chotard }
52928954feSPatrice Chotard
53928954feSPatrice Chotard ret = device_bind_with_driver_data(dev, drv, rcc_clk->drv_name,
54928954feSPatrice Chotard rcc_clk->soc,
554e280b91SChristophe Kerello dev_ofnode(dev), &child);
56928954feSPatrice Chotard
574e280b91SChristophe Kerello if (ret)
584e280b91SChristophe Kerello return ret;
594e280b91SChristophe Kerello
60*d090cbabSPatrick Delaunay drv = lists_driver_lookup_name("stm32_rcc_reset");
61*d090cbabSPatrick Delaunay if (!drv) {
62*d090cbabSPatrick Delaunay dev_err(dev, "Cannot find driver stm32_rcc_reset'\n");
63*d090cbabSPatrick Delaunay return -ENOENT;
64*d090cbabSPatrick Delaunay }
65*d090cbabSPatrick Delaunay
66*d090cbabSPatrick Delaunay return device_bind_with_driver_data(dev, drv, "stm32_rcc_reset",
67*d090cbabSPatrick Delaunay rcc_clk->soc,
684e280b91SChristophe Kerello dev_ofnode(dev), &child);
694e280b91SChristophe Kerello }
704e280b91SChristophe Kerello
714e280b91SChristophe Kerello static const struct misc_ops stm32_rcc_ops = {
724e280b91SChristophe Kerello };
734e280b91SChristophe Kerello
744e280b91SChristophe Kerello static const struct udevice_id stm32_rcc_ids[] = {
758b414645SPatrice Chotard {.compatible = "st,stm32f42xx-rcc", .data = (ulong)&stm32_rcc_clk_f42x },
768b414645SPatrice Chotard {.compatible = "st,stm32f469-rcc", .data = (ulong)&stm32_rcc_clk_f469 },
77928954feSPatrice Chotard {.compatible = "st,stm32f746-rcc", .data = (ulong)&stm32_rcc_clk_f7 },
78928954feSPatrice Chotard {.compatible = "st,stm32h743-rcc", .data = (ulong)&stm32_rcc_clk_h7 },
79*d090cbabSPatrick Delaunay {.compatible = "st,stm32mp1-rcc", .data = (ulong)&stm32_rcc_clk_mp1 },
804e280b91SChristophe Kerello { }
814e280b91SChristophe Kerello };
824e280b91SChristophe Kerello
834e280b91SChristophe Kerello U_BOOT_DRIVER(stm32_rcc) = {
844e280b91SChristophe Kerello .name = "stm32-rcc",
854e280b91SChristophe Kerello .id = UCLASS_MISC,
864e280b91SChristophe Kerello .of_match = stm32_rcc_ids,
874e280b91SChristophe Kerello .bind = stm32_rcc_bind,
884e280b91SChristophe Kerello .ops = &stm32_rcc_ops,
894e280b91SChristophe Kerello };
90