blob: b436900d7cba6adab3d8c8a305213f6e01f1946b [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 Chotard928954f2017-11-15 13:14:51 +010014struct stm32_rcc_clk stm32_rcc_clk_f4 = {
15 .drv_name = "stm32fx_rcc_clock",
16 .soc = STM32F4,
17};
18
19struct stm32_rcc_clk stm32_rcc_clk_f7 = {
20 .drv_name = "stm32fx_rcc_clock",
21 .soc = STM32F7,
22};
23
24struct stm32_rcc_clk stm32_rcc_clk_h7 = {
25 .drv_name = "stm32h7_rcc_clock",
26};
27
Christophe Kerello4e280b92017-09-13 18:00:08 +020028static int stm32_rcc_bind(struct udevice *dev)
29{
Christophe Kerello4e280b92017-09-13 18:00:08 +020030 struct udevice *child;
Patrice Chotard928954f2017-11-15 13:14:51 +010031 struct driver *drv;
32 struct stm32_rcc_clk *rcc_clk =
33 (struct stm32_rcc_clk *)dev_get_driver_data(dev);
34 int ret;
Christophe Kerello4e280b92017-09-13 18:00:08 +020035
36 debug("%s(dev=%p)\n", __func__, dev);
37
Patrice Chotard928954f2017-11-15 13:14:51 +010038 drv = lists_driver_lookup_name(rcc_clk->drv_name);
39 if (!drv) {
40 debug("Cannot find driver '%s'\n", rcc_clk->drv_name);
41 return -ENOENT;
42 }
43
44 ret = device_bind_with_driver_data(dev, drv, rcc_clk->drv_name,
45 rcc_clk->soc,
46 dev_ofnode(dev), &child);
47
Christophe Kerello4e280b92017-09-13 18:00:08 +020048 if (ret)
49 return ret;
50
Patrice Chotard928954f2017-11-15 13:14:51 +010051#ifdef CONFIG_SPL_BUILD
52 return 0;
53#else
Christophe Kerello4e280b92017-09-13 18:00:08 +020054 return device_bind_driver_to_node(dev, "stm32_rcc_reset",
55 "stm32_rcc_reset",
56 dev_ofnode(dev), &child);
Patrice Chotard928954f2017-11-15 13:14:51 +010057#endif
Christophe Kerello4e280b92017-09-13 18:00:08 +020058}
59
60static const struct misc_ops stm32_rcc_ops = {
61};
62
63static const struct udevice_id stm32_rcc_ids[] = {
Patrice Chotard928954f2017-11-15 13:14:51 +010064 {.compatible = "st,stm32f42xx-rcc", .data = (ulong)&stm32_rcc_clk_f4 },
65 {.compatible = "st,stm32f746-rcc", .data = (ulong)&stm32_rcc_clk_f7 },
66 {.compatible = "st,stm32h743-rcc", .data = (ulong)&stm32_rcc_clk_h7 },
Christophe Kerello4e280b92017-09-13 18:00:08 +020067 { }
68};
69
70U_BOOT_DRIVER(stm32_rcc) = {
71 .name = "stm32-rcc",
72 .id = UCLASS_MISC,
73 .of_match = stm32_rcc_ids,
74 .bind = stm32_rcc_bind,
75 .ops = &stm32_rcc_ops,
76};