blob: 980b84453e1973efed2cea8778f2528fc81d26f4 [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
4 * Author(s): Patrice Chotard, <patrice.chotard@st.com> for STMicroelectronics.
Christophe Kerello275f7062017-09-13 18:00:08 +02005 */
6
7#include <common.h>
8#include <dm.h>
9#include <misc.h>
Patrice Chotard03f10a12017-11-15 13:14:51 +010010#include <stm32_rcc.h>
11#include <dm/device-internal.h>
Simon Glass9bc15642020-02-03 07:36:16 -070012#include <dm/device_compat.h>
Christophe Kerello275f7062017-09-13 18:00:08 +020013#include <dm/lists.h>
14
Patrice Chotard7264aae2018-04-11 17:07:45 +020015struct stm32_rcc_clk stm32_rcc_clk_f42x = {
Patrice Chotard03f10a12017-11-15 13:14:51 +010016 .drv_name = "stm32fx_rcc_clock",
Patrice Chotard7264aae2018-04-11 17:07:45 +020017 .soc = STM32F42X,
Patrice Chotard03f10a12017-11-15 13:14:51 +010018};
19
Patrice Chotard7264aae2018-04-11 17:07:45 +020020struct stm32_rcc_clk stm32_rcc_clk_f469 = {
21 .drv_name = "stm32fx_rcc_clock",
22 .soc = STM32F469,
23};
24
Patrice Chotard03f10a12017-11-15 13:14:51 +010025struct stm32_rcc_clk stm32_rcc_clk_f7 = {
26 .drv_name = "stm32fx_rcc_clock",
27 .soc = STM32F7,
28};
29
30struct stm32_rcc_clk stm32_rcc_clk_h7 = {
31 .drv_name = "stm32h7_rcc_clock",
32};
33
Patrick Delaunayb139a5b2018-07-09 15:17:20 +020034struct stm32_rcc_clk stm32_rcc_clk_mp1 = {
35 .drv_name = "stm32mp1_clk",
36 .soc = STM32MP1,
37};
38
Christophe Kerello275f7062017-09-13 18:00:08 +020039static int stm32_rcc_bind(struct udevice *dev)
40{
Christophe Kerello275f7062017-09-13 18:00:08 +020041 struct udevice *child;
Patrice Chotard03f10a12017-11-15 13:14:51 +010042 struct driver *drv;
43 struct stm32_rcc_clk *rcc_clk =
44 (struct stm32_rcc_clk *)dev_get_driver_data(dev);
45 int ret;
Christophe Kerello275f7062017-09-13 18:00:08 +020046
47 debug("%s(dev=%p)\n", __func__, dev);
Patrice Chotard03f10a12017-11-15 13:14:51 +010048 drv = lists_driver_lookup_name(rcc_clk->drv_name);
49 if (!drv) {
50 debug("Cannot find driver '%s'\n", rcc_clk->drv_name);
51 return -ENOENT;
52 }
53
54 ret = device_bind_with_driver_data(dev, drv, rcc_clk->drv_name,
55 rcc_clk->soc,
56 dev_ofnode(dev), &child);
57
Christophe Kerello275f7062017-09-13 18:00:08 +020058 if (ret)
59 return ret;
60
Patrick Delaunayb139a5b2018-07-09 15:17:20 +020061 drv = lists_driver_lookup_name("stm32_rcc_reset");
62 if (!drv) {
63 dev_err(dev, "Cannot find driver stm32_rcc_reset'\n");
64 return -ENOENT;
65 }
66
67 return device_bind_with_driver_data(dev, drv, "stm32_rcc_reset",
68 rcc_clk->soc,
69 dev_ofnode(dev), &child);
Christophe Kerello275f7062017-09-13 18:00:08 +020070}
71
Christophe Kerello275f7062017-09-13 18:00:08 +020072
73static const struct udevice_id stm32_rcc_ids[] = {
Patrice Chotard7264aae2018-04-11 17:07:45 +020074 {.compatible = "st,stm32f42xx-rcc", .data = (ulong)&stm32_rcc_clk_f42x },
75 {.compatible = "st,stm32f469-rcc", .data = (ulong)&stm32_rcc_clk_f469 },
Patrice Chotard03f10a12017-11-15 13:14:51 +010076 {.compatible = "st,stm32f746-rcc", .data = (ulong)&stm32_rcc_clk_f7 },
77 {.compatible = "st,stm32h743-rcc", .data = (ulong)&stm32_rcc_clk_h7 },
Patrick Delaunayb139a5b2018-07-09 15:17:20 +020078 {.compatible = "st,stm32mp1-rcc", .data = (ulong)&stm32_rcc_clk_mp1 },
Christophe Kerello275f7062017-09-13 18:00:08 +020079 { }
80};
81
82U_BOOT_DRIVER(stm32_rcc) = {
83 .name = "stm32-rcc",
Patrick Delaunayd79f8ee2019-08-02 13:08:08 +020084 .id = UCLASS_NOP,
Christophe Kerello275f7062017-09-13 18:00:08 +020085 .of_match = stm32_rcc_ids,
86 .bind = stm32_rcc_bind,
Christophe Kerello275f7062017-09-13 18:00:08 +020087};