blob: 87d9928362be9ec7260ad54b94cb5f6b34a43996 [file] [log] [blame]
Christophe Kerello275f7062017-09-13 18:00:08 +02001/*
Patrice Chotard789ee0e2017-10-23 09:53:58 +02002 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
3 * Author(s): Patrice Chotard, <patrice.chotard@st.com> for STMicroelectronics.
Christophe Kerello275f7062017-09-13 18:00:08 +02004 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <dm.h>
10#include <misc.h>
Patrice Chotard03f10a12017-11-15 13:14:51 +010011#include <stm32_rcc.h>
12#include <dm/device-internal.h>
Christophe Kerello275f7062017-09-13 18:00:08 +020013#include <dm/lists.h>
14
Patrice Chotard03f10a12017-11-15 13:14:51 +010015struct stm32_rcc_clk stm32_rcc_clk_f4 = {
16 .drv_name = "stm32fx_rcc_clock",
17 .soc = STM32F4,
18};
19
20struct stm32_rcc_clk stm32_rcc_clk_f7 = {
21 .drv_name = "stm32fx_rcc_clock",
22 .soc = STM32F7,
23};
24
25struct stm32_rcc_clk stm32_rcc_clk_h7 = {
26 .drv_name = "stm32h7_rcc_clock",
27};
28
Christophe Kerello275f7062017-09-13 18:00:08 +020029static int stm32_rcc_bind(struct udevice *dev)
30{
Christophe Kerello275f7062017-09-13 18:00:08 +020031 struct udevice *child;
Patrice Chotard03f10a12017-11-15 13:14:51 +010032 struct driver *drv;
33 struct stm32_rcc_clk *rcc_clk =
34 (struct stm32_rcc_clk *)dev_get_driver_data(dev);
35 int ret;
Christophe Kerello275f7062017-09-13 18:00:08 +020036
37 debug("%s(dev=%p)\n", __func__, dev);
38
Patrice Chotard03f10a12017-11-15 13:14:51 +010039 drv = lists_driver_lookup_name(rcc_clk->drv_name);
40 if (!drv) {
41 debug("Cannot find driver '%s'\n", rcc_clk->drv_name);
42 return -ENOENT;
43 }
44
45 ret = device_bind_with_driver_data(dev, drv, rcc_clk->drv_name,
46 rcc_clk->soc,
47 dev_ofnode(dev), &child);
48
Christophe Kerello275f7062017-09-13 18:00:08 +020049 if (ret)
50 return ret;
51
Patrice Chotard03f10a12017-11-15 13:14:51 +010052#ifdef CONFIG_SPL_BUILD
53 return 0;
54#else
Christophe Kerello275f7062017-09-13 18:00:08 +020055 return device_bind_driver_to_node(dev, "stm32_rcc_reset",
56 "stm32_rcc_reset",
57 dev_ofnode(dev), &child);
Patrice Chotard03f10a12017-11-15 13:14:51 +010058#endif
Christophe Kerello275f7062017-09-13 18:00:08 +020059}
60
61static const struct misc_ops stm32_rcc_ops = {
62};
63
64static const struct udevice_id stm32_rcc_ids[] = {
Patrice Chotard03f10a12017-11-15 13:14:51 +010065 {.compatible = "st,stm32f42xx-rcc", .data = (ulong)&stm32_rcc_clk_f4 },
66 {.compatible = "st,stm32f746-rcc", .data = (ulong)&stm32_rcc_clk_f7 },
67 {.compatible = "st,stm32h743-rcc", .data = (ulong)&stm32_rcc_clk_h7 },
Christophe Kerello275f7062017-09-13 18:00:08 +020068 { }
69};
70
71U_BOOT_DRIVER(stm32_rcc) = {
72 .name = "stm32-rcc",
73 .id = UCLASS_MISC,
74 .of_match = stm32_rcc_ids,
75 .bind = stm32_rcc_bind,
76 .ops = &stm32_rcc_ops,
77};