blob: 980b84453e1973efed2cea8778f2528fc81d26f4 [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>
Simon Glass336d4612020-02-03 07:36:16 -070012#include <dm/device_compat.h>
Christophe Kerello4e280b92017-09-13 18:00:08 +020013#include <dm/lists.h>
14
Patrice Chotard8b414642018-04-11 17:07:45 +020015struct stm32_rcc_clk stm32_rcc_clk_f42x = {
Patrice Chotard928954f2017-11-15 13:14:51 +010016 .drv_name = "stm32fx_rcc_clock",
Patrice Chotard8b414642018-04-11 17:07:45 +020017 .soc = STM32F42X,
18};
19
20struct stm32_rcc_clk stm32_rcc_clk_f469 = {
21 .drv_name = "stm32fx_rcc_clock",
22 .soc = STM32F469,
Patrice Chotard928954f2017-11-15 13:14:51 +010023};
24
25struct 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 Delaunayd090cba2018-07-09 15:17:20 +020034struct stm32_rcc_clk stm32_rcc_clk_mp1 = {
35 .drv_name = "stm32mp1_clk",
36 .soc = STM32MP1,
37};
38
Christophe Kerello4e280b92017-09-13 18:00:08 +020039static int stm32_rcc_bind(struct udevice *dev)
40{
Christophe Kerello4e280b92017-09-13 18:00:08 +020041 struct udevice *child;
Patrice Chotard928954f2017-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 Kerello4e280b92017-09-13 18:00:08 +020046
47 debug("%s(dev=%p)\n", __func__, dev);
Patrice Chotard928954f2017-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 Kerello4e280b92017-09-13 18:00:08 +020058 if (ret)
59 return ret;
60
Patrick Delaunayd090cba2018-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 Kerello4e280b92017-09-13 18:00:08 +020070}
71
Christophe Kerello4e280b92017-09-13 18:00:08 +020072
73static const struct udevice_id stm32_rcc_ids[] = {
Patrice Chotard8b414642018-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 Chotard928954f2017-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 Delaunayd090cba2018-07-09 15:17:20 +020078 {.compatible = "st,stm32mp1-rcc", .data = (ulong)&stm32_rcc_clk_mp1 },
Christophe Kerello4e280b92017-09-13 18:00:08 +020079 { }
80};
81
82U_BOOT_DRIVER(stm32_rcc) = {
83 .name = "stm32-rcc",
Patrick Delaunay13234702019-08-02 13:08:08 +020084 .id = UCLASS_NOP,
Christophe Kerello4e280b92017-09-13 18:00:08 +020085 .of_match = stm32_rcc_ids,
86 .bind = stm32_rcc_bind,
Christophe Kerello4e280b92017-09-13 18:00:08 +020087};