blob: 15bf69f7d5787b552be07460ae1ee663ce732d79 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Christophe Kerello275f7062017-09-13 18:00:08 +02002/*
Patrice Chotard789ee0e2017-10-23 09:53:58 +02003 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
Patrice Chotard5d9950d2020-12-02 18:47:30 +01004 * Author(s): Patrice Chotard, <patrice.chotard@foss.st.com> for STMicroelectronics.
Christophe Kerello275f7062017-09-13 18:00:08 +02005 */
6
Patrick Delaunayeec21f32020-11-06 19:01:43 +01007#define LOG_CATEGORY UCLASS_NOP
8
Christophe Kerello275f7062017-09-13 18:00:08 +02009#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Christophe Kerello275f7062017-09-13 18:00:08 +020011#include <misc.h>
Patrice Chotard03f10a12017-11-15 13:14:51 +010012#include <stm32_rcc.h>
13#include <dm/device-internal.h>
Simon Glass9bc15642020-02-03 07:36:16 -070014#include <dm/device_compat.h>
Christophe Kerello275f7062017-09-13 18:00:08 +020015#include <dm/lists.h>
16
Gabriel Fernandezafdc1ae2025-05-27 15:27:53 +020017static const struct stm32_rcc stm32_rcc_f42x = {
18 .drv_name_clk = "stm32fx_rcc_clock",
19 .drv_name_rst = "stm32_rcc_reset",
Patrice Chotard7264aae2018-04-11 17:07:45 +020020 .soc = STM32F42X,
Patrice Chotard03f10a12017-11-15 13:14:51 +010021};
22
Gabriel Fernandezafdc1ae2025-05-27 15:27:53 +020023static const struct stm32_rcc stm32_rcc_f469 = {
24 .drv_name_clk = "stm32fx_rcc_clock",
25 .drv_name_rst = "stm32_rcc_reset",
Patrice Chotard7264aae2018-04-11 17:07:45 +020026 .soc = STM32F469,
27};
28
Gabriel Fernandezafdc1ae2025-05-27 15:27:53 +020029static const struct stm32_rcc stm32_rcc_f7 = {
30 .drv_name_clk = "stm32fx_rcc_clock",
31 .drv_name_rst = "stm32_rcc_reset",
Patrice Chotard03f10a12017-11-15 13:14:51 +010032 .soc = STM32F7,
33};
34
Gabriel Fernandezafdc1ae2025-05-27 15:27:53 +020035static const struct stm32_rcc stm32_rcc_h7 = {
36 .drv_name_clk = "stm32h7_rcc_clock",
37 .drv_name_rst = "stm32_rcc_reset",
Patrice Chotard03f10a12017-11-15 13:14:51 +010038};
39
Gabriel Fernandezafdc1ae2025-05-27 15:27:53 +020040static const struct stm32_rcc stm32_rcc_mp15 = {
41 .drv_name_clk = "stm32mp1_clk",
42 .drv_name_rst = "stm32mp1_reset",
Patrick Delaunayb139a5b2018-07-09 15:17:20 +020043};
44
Gabriel Fernandezafdc1ae2025-05-27 15:27:53 +020045static const struct stm32_rcc stm32_rcc_mp13 = {
46 .drv_name_clk = "stm32mp13_clk",
47 .drv_name_rst = "stm32mp1_reset",
Patrick Delaunay6b4490c2022-05-19 17:56:46 +020048};
49
Gabriel Fernandezafdc1ae2025-05-27 15:27:53 +020050static const struct stm32_rcc stm32_rcc_mp25 = {
51 .drv_name_clk = "stm32mp25_clk",
52 .drv_name_rst = "stm32mp25_reset",
53};
54
Christophe Kerello275f7062017-09-13 18:00:08 +020055static int stm32_rcc_bind(struct udevice *dev)
56{
Christophe Kerello275f7062017-09-13 18:00:08 +020057 struct udevice *child;
Patrice Chotard03f10a12017-11-15 13:14:51 +010058 struct driver *drv;
Gabriel Fernandezafdc1ae2025-05-27 15:27:53 +020059 struct stm32_rcc *rcc_clk =
60 (struct stm32_rcc *)dev_get_driver_data(dev);
Patrice Chotard03f10a12017-11-15 13:14:51 +010061 int ret;
Christophe Kerello275f7062017-09-13 18:00:08 +020062
Patrick Delaunayeec21f32020-11-06 19:01:43 +010063 dev_dbg(dev, "RCC bind\n");
Gabriel Fernandezafdc1ae2025-05-27 15:27:53 +020064 drv = lists_driver_lookup_name(rcc_clk->drv_name_clk);
Patrice Chotard03f10a12017-11-15 13:14:51 +010065 if (!drv) {
Gabriel Fernandezafdc1ae2025-05-27 15:27:53 +020066 dev_err(dev, "Cannot find driver '%s'\n", rcc_clk->drv_name_clk);
Patrice Chotard03f10a12017-11-15 13:14:51 +010067 return -ENOENT;
68 }
69
Patrick Delaunay78075bb2020-11-06 19:01:44 +010070 ret = device_bind_with_driver_data(dev, drv, dev->name,
Patrice Chotard03f10a12017-11-15 13:14:51 +010071 rcc_clk->soc,
72 dev_ofnode(dev), &child);
73
Christophe Kerello275f7062017-09-13 18:00:08 +020074 if (ret)
75 return ret;
76
Gabriel Fernandezafdc1ae2025-05-27 15:27:53 +020077 drv = lists_driver_lookup_name(rcc_clk->drv_name_rst);
Patrick Delaunayb139a5b2018-07-09 15:17:20 +020078 if (!drv) {
79 dev_err(dev, "Cannot find driver stm32_rcc_reset'\n");
80 return -ENOENT;
81 }
82
Gabriel Fernandezafdc1ae2025-05-27 15:27:53 +020083 return device_bind(dev, drv, dev->name, NULL, dev_ofnode(dev), &child);
Christophe Kerello275f7062017-09-13 18:00:08 +020084}
85
Christophe Kerello275f7062017-09-13 18:00:08 +020086static const struct udevice_id stm32_rcc_ids[] = {
Gabriel Fernandezafdc1ae2025-05-27 15:27:53 +020087 {.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 },
Christophe Kerello275f7062017-09-13 18:00:08 +020095 { }
96};
97
98U_BOOT_DRIVER(stm32_rcc) = {
99 .name = "stm32-rcc",
Patrick Delaunayd79f8ee2019-08-02 13:08:08 +0200100 .id = UCLASS_NOP,
Christophe Kerello275f7062017-09-13 18:00:08 +0200101 .of_match = stm32_rcc_ids,
102 .bind = stm32_rcc_bind,
Christophe Kerello275f7062017-09-13 18:00:08 +0200103};