blob: b816503bfa27c2212834e047b90b3cad790faf2f [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Christophe Kerello4e280b92017-09-13 18:00:08 +02002/*
Patrice Chotard3bc599c2017-10-23 09:53:58 +02003 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
Patrice Chotard0f8106f2020-12-02 18:47:30 +01004 * Author(s): Patrice Chotard, <patrice.chotard@foss.st.com> for STMicroelectronics.
Christophe Kerello4e280b92017-09-13 18:00:08 +02005 */
6
Patrick Delaunay8e80ba52020-11-06 19:01:43 +01007#define LOG_CATEGORY UCLASS_NOP
8
Christophe Kerello4e280b92017-09-13 18:00:08 +02009#include <common.h>
10#include <dm.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060011#include <log.h>
Christophe Kerello4e280b92017-09-13 18:00:08 +020012#include <misc.h>
Patrice Chotard928954f2017-11-15 13:14:51 +010013#include <stm32_rcc.h>
14#include <dm/device-internal.h>
Simon Glass336d4612020-02-03 07:36:16 -070015#include <dm/device_compat.h>
Christophe Kerello4e280b92017-09-13 18:00:08 +020016#include <dm/lists.h>
17
Patrice Chotard8b414642018-04-11 17:07:45 +020018struct stm32_rcc_clk stm32_rcc_clk_f42x = {
Patrice Chotard928954f2017-11-15 13:14:51 +010019 .drv_name = "stm32fx_rcc_clock",
Patrice Chotard8b414642018-04-11 17:07:45 +020020 .soc = STM32F42X,
21};
22
23struct stm32_rcc_clk stm32_rcc_clk_f469 = {
24 .drv_name = "stm32fx_rcc_clock",
25 .soc = STM32F469,
Patrice Chotard928954f2017-11-15 13:14:51 +010026};
27
28struct stm32_rcc_clk stm32_rcc_clk_f7 = {
29 .drv_name = "stm32fx_rcc_clock",
30 .soc = STM32F7,
31};
32
33struct stm32_rcc_clk stm32_rcc_clk_h7 = {
34 .drv_name = "stm32h7_rcc_clock",
35};
36
Patrick Delaunayd090cba2018-07-09 15:17:20 +020037struct stm32_rcc_clk stm32_rcc_clk_mp1 = {
38 .drv_name = "stm32mp1_clk",
39 .soc = STM32MP1,
40};
41
Patrick Delaunayf8a0f4a2022-05-19 17:56:46 +020042struct stm32_rcc_clk stm32_rcc_clk_mp13 = {
43 .drv_name = "stm32mp13_clk",
44 .soc = STM32MP1,
45};
46
Christophe Kerello4e280b92017-09-13 18:00:08 +020047static int stm32_rcc_bind(struct udevice *dev)
48{
Christophe Kerello4e280b92017-09-13 18:00:08 +020049 struct udevice *child;
Patrice Chotard928954f2017-11-15 13:14:51 +010050 struct driver *drv;
51 struct stm32_rcc_clk *rcc_clk =
52 (struct stm32_rcc_clk *)dev_get_driver_data(dev);
53 int ret;
Christophe Kerello4e280b92017-09-13 18:00:08 +020054
Patrick Delaunay8e80ba52020-11-06 19:01:43 +010055 dev_dbg(dev, "RCC bind\n");
Patrice Chotard928954f2017-11-15 13:14:51 +010056 drv = lists_driver_lookup_name(rcc_clk->drv_name);
57 if (!drv) {
Patrick Delaunay8e80ba52020-11-06 19:01:43 +010058 dev_err(dev, "Cannot find driver '%s'\n", rcc_clk->drv_name);
Patrice Chotard928954f2017-11-15 13:14:51 +010059 return -ENOENT;
60 }
61
Patrick Delaunay75760652020-11-06 19:01:44 +010062 ret = device_bind_with_driver_data(dev, drv, dev->name,
Patrice Chotard928954f2017-11-15 13:14:51 +010063 rcc_clk->soc,
64 dev_ofnode(dev), &child);
65
Christophe Kerello4e280b92017-09-13 18:00:08 +020066 if (ret)
67 return ret;
68
Patrick Delaunayd090cba2018-07-09 15:17:20 +020069 drv = lists_driver_lookup_name("stm32_rcc_reset");
70 if (!drv) {
71 dev_err(dev, "Cannot find driver stm32_rcc_reset'\n");
72 return -ENOENT;
73 }
74
Patrick Delaunay75760652020-11-06 19:01:44 +010075 return device_bind_with_driver_data(dev, drv, dev->name,
Patrick Delaunayd090cba2018-07-09 15:17:20 +020076 rcc_clk->soc,
77 dev_ofnode(dev), &child);
Christophe Kerello4e280b92017-09-13 18:00:08 +020078}
79
Christophe Kerello4e280b92017-09-13 18:00:08 +020080
81static const struct udevice_id stm32_rcc_ids[] = {
Patrice Chotard8b414642018-04-11 17:07:45 +020082 {.compatible = "st,stm32f42xx-rcc", .data = (ulong)&stm32_rcc_clk_f42x },
83 {.compatible = "st,stm32f469-rcc", .data = (ulong)&stm32_rcc_clk_f469 },
Patrice Chotard928954f2017-11-15 13:14:51 +010084 {.compatible = "st,stm32f746-rcc", .data = (ulong)&stm32_rcc_clk_f7 },
85 {.compatible = "st,stm32h743-rcc", .data = (ulong)&stm32_rcc_clk_h7 },
Patrick Delaunayd090cba2018-07-09 15:17:20 +020086 {.compatible = "st,stm32mp1-rcc", .data = (ulong)&stm32_rcc_clk_mp1 },
Patrick Delaunayf8a0f4a2022-05-19 17:56:46 +020087 {.compatible = "st,stm32mp13-rcc", .data = (ulong)&stm32_rcc_clk_mp13 },
Christophe Kerello4e280b92017-09-13 18:00:08 +020088 { }
89};
90
91U_BOOT_DRIVER(stm32_rcc) = {
92 .name = "stm32-rcc",
Patrick Delaunay13234702019-08-02 13:08:08 +020093 .id = UCLASS_NOP,
Christophe Kerello4e280b92017-09-13 18:00:08 +020094 .of_match = stm32_rcc_ids,
95 .bind = stm32_rcc_bind,
Christophe Kerello4e280b92017-09-13 18:00:08 +020096};