Merge tag 'xilinx-for-v2022.01-rc3' of https://source.denx.de/u-boot/custodians/u...
[platform/kernel/u-boot.git] / drivers / misc / stm32_rcc.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
4  * Author(s): Patrice Chotard, <patrice.chotard@foss.st.com> for STMicroelectronics.
5  */
6
7 #define LOG_CATEGORY UCLASS_NOP
8
9 #include <common.h>
10 #include <dm.h>
11 #include <log.h>
12 #include <misc.h>
13 #include <stm32_rcc.h>
14 #include <dm/device-internal.h>
15 #include <dm/device_compat.h>
16 #include <dm/lists.h>
17
18 struct stm32_rcc_clk stm32_rcc_clk_f42x = {
19         .drv_name = "stm32fx_rcc_clock",
20         .soc = STM32F42X,
21 };
22
23 struct stm32_rcc_clk stm32_rcc_clk_f469 = {
24         .drv_name = "stm32fx_rcc_clock",
25         .soc = STM32F469,
26 };
27
28 struct stm32_rcc_clk stm32_rcc_clk_f7 = {
29         .drv_name = "stm32fx_rcc_clock",
30         .soc = STM32F7,
31 };
32
33 struct stm32_rcc_clk stm32_rcc_clk_h7 = {
34         .drv_name = "stm32h7_rcc_clock",
35 };
36
37 struct stm32_rcc_clk stm32_rcc_clk_mp1 = {
38         .drv_name = "stm32mp1_clk",
39         .soc = STM32MP1,
40 };
41
42 static int stm32_rcc_bind(struct udevice *dev)
43 {
44         struct udevice *child;
45         struct driver *drv;
46         struct stm32_rcc_clk *rcc_clk =
47                 (struct stm32_rcc_clk *)dev_get_driver_data(dev);
48         int ret;
49
50         dev_dbg(dev, "RCC bind\n");
51         drv = lists_driver_lookup_name(rcc_clk->drv_name);
52         if (!drv) {
53                 dev_err(dev, "Cannot find driver '%s'\n", rcc_clk->drv_name);
54                 return -ENOENT;
55         }
56
57         ret = device_bind_with_driver_data(dev, drv, dev->name,
58                                            rcc_clk->soc,
59                                            dev_ofnode(dev), &child);
60
61         if (ret)
62                 return ret;
63
64         drv = lists_driver_lookup_name("stm32_rcc_reset");
65         if (!drv) {
66                 dev_err(dev, "Cannot find driver stm32_rcc_reset'\n");
67                 return -ENOENT;
68         }
69
70         return device_bind_with_driver_data(dev, drv, dev->name,
71                                             rcc_clk->soc,
72                                             dev_ofnode(dev), &child);
73 }
74
75
76 static const struct udevice_id stm32_rcc_ids[] = {
77         {.compatible = "st,stm32f42xx-rcc", .data = (ulong)&stm32_rcc_clk_f42x },
78         {.compatible = "st,stm32f469-rcc", .data = (ulong)&stm32_rcc_clk_f469 },
79         {.compatible = "st,stm32f746-rcc", .data = (ulong)&stm32_rcc_clk_f7 },
80         {.compatible = "st,stm32h743-rcc", .data = (ulong)&stm32_rcc_clk_h7 },
81         {.compatible = "st,stm32mp1-rcc", .data = (ulong)&stm32_rcc_clk_mp1 },
82         { }
83 };
84
85 U_BOOT_DRIVER(stm32_rcc) = {
86         .name           = "stm32-rcc",
87         .id             = UCLASS_NOP,
88         .of_match       = stm32_rcc_ids,
89         .bind           = stm32_rcc_bind,
90 };