blob: e7efcdeafa3434c2ebebb39337a09e78ce6cf4c9 [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
4 * Author(s): Patrice Chotard, <patrice.chotard@st.com> for STMicroelectronics.
Christophe Kerello4e280b92017-09-13 18:00:08 +02005 */
6
7#include <common.h>
8#include <dm.h>
9#include <misc.h>
Patrice Chotard928954f2017-11-15 13:14:51 +010010#include <stm32_rcc.h>
11#include <dm/device-internal.h>
Christophe Kerello4e280b92017-09-13 18:00:08 +020012#include <dm/lists.h>
13
Patrice Chotard8b414642018-04-11 17:07:45 +020014struct stm32_rcc_clk stm32_rcc_clk_f42x = {
Patrice Chotard928954f2017-11-15 13:14:51 +010015 .drv_name = "stm32fx_rcc_clock",
Patrice Chotard8b414642018-04-11 17:07:45 +020016 .soc = STM32F42X,
17};
18
19struct stm32_rcc_clk stm32_rcc_clk_f469 = {
20 .drv_name = "stm32fx_rcc_clock",
21 .soc = STM32F469,
Patrice Chotard928954f2017-11-15 13:14:51 +010022};
23
24struct stm32_rcc_clk stm32_rcc_clk_f7 = {
25 .drv_name = "stm32fx_rcc_clock",
26 .soc = STM32F7,
27};
28
29struct stm32_rcc_clk stm32_rcc_clk_h7 = {
30 .drv_name = "stm32h7_rcc_clock",
31};
32
Patrick Delaunayd090cba2018-07-09 15:17:20 +020033struct stm32_rcc_clk stm32_rcc_clk_mp1 = {
34 .drv_name = "stm32mp1_clk",
35 .soc = STM32MP1,
36};
37
Christophe Kerello4e280b92017-09-13 18:00:08 +020038static int stm32_rcc_bind(struct udevice *dev)
39{
Christophe Kerello4e280b92017-09-13 18:00:08 +020040 struct udevice *child;
Patrice Chotard928954f2017-11-15 13:14:51 +010041 struct driver *drv;
42 struct stm32_rcc_clk *rcc_clk =
43 (struct stm32_rcc_clk *)dev_get_driver_data(dev);
44 int ret;
Christophe Kerello4e280b92017-09-13 18:00:08 +020045
46 debug("%s(dev=%p)\n", __func__, dev);
Patrice Chotard928954f2017-11-15 13:14:51 +010047 drv = lists_driver_lookup_name(rcc_clk->drv_name);
48 if (!drv) {
49 debug("Cannot find driver '%s'\n", rcc_clk->drv_name);
50 return -ENOENT;
51 }
52
53 ret = device_bind_with_driver_data(dev, drv, rcc_clk->drv_name,
54 rcc_clk->soc,
55 dev_ofnode(dev), &child);
56
Christophe Kerello4e280b92017-09-13 18:00:08 +020057 if (ret)
58 return ret;
59
Patrick Delaunayd090cba2018-07-09 15:17:20 +020060 drv = lists_driver_lookup_name("stm32_rcc_reset");
61 if (!drv) {
62 dev_err(dev, "Cannot find driver stm32_rcc_reset'\n");
63 return -ENOENT;
64 }
65
66 return device_bind_with_driver_data(dev, drv, "stm32_rcc_reset",
67 rcc_clk->soc,
68 dev_ofnode(dev), &child);
Christophe Kerello4e280b92017-09-13 18:00:08 +020069}
70
Christophe Kerello4e280b92017-09-13 18:00:08 +020071
72static const struct udevice_id stm32_rcc_ids[] = {
Patrice Chotard8b414642018-04-11 17:07:45 +020073 {.compatible = "st,stm32f42xx-rcc", .data = (ulong)&stm32_rcc_clk_f42x },
74 {.compatible = "st,stm32f469-rcc", .data = (ulong)&stm32_rcc_clk_f469 },
Patrice Chotard928954f2017-11-15 13:14:51 +010075 {.compatible = "st,stm32f746-rcc", .data = (ulong)&stm32_rcc_clk_f7 },
76 {.compatible = "st,stm32h743-rcc", .data = (ulong)&stm32_rcc_clk_h7 },
Patrick Delaunayd090cba2018-07-09 15:17:20 +020077 {.compatible = "st,stm32mp1-rcc", .data = (ulong)&stm32_rcc_clk_mp1 },
Christophe Kerello4e280b92017-09-13 18:00:08 +020078 { }
79};
80
81U_BOOT_DRIVER(stm32_rcc) = {
82 .name = "stm32-rcc",
Patrick Delaunay13234702019-08-02 13:08:08 +020083 .id = UCLASS_NOP,
Christophe Kerello4e280b92017-09-13 18:00:08 +020084 .of_match = stm32_rcc_ids,
85 .bind = stm32_rcc_bind,
Christophe Kerello4e280b92017-09-13 18:00:08 +020086};