Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Christophe Kerello | 275f706 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 2 | /* |
Patrice Chotard | 789ee0e | 2017-10-23 09:53:58 +0200 | [diff] [blame] | 3 | * Copyright (C) 2017, STMicroelectronics - All Rights Reserved |
| 4 | * Author(s): Patrice Chotard, <patrice.chotard@st.com> for STMicroelectronics. |
Christophe Kerello | 275f706 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
| 9 | #include <misc.h> |
Patrice Chotard | 03f10a1 | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 10 | #include <stm32_rcc.h> |
| 11 | #include <dm/device-internal.h> |
Christophe Kerello | 275f706 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 12 | #include <dm/lists.h> |
| 13 | |
Patrice Chotard | 7264aae | 2018-04-11 17:07:45 +0200 | [diff] [blame] | 14 | struct stm32_rcc_clk stm32_rcc_clk_f42x = { |
Patrice Chotard | 03f10a1 | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 15 | .drv_name = "stm32fx_rcc_clock", |
Patrice Chotard | 7264aae | 2018-04-11 17:07:45 +0200 | [diff] [blame] | 16 | .soc = STM32F42X, |
Patrice Chotard | 03f10a1 | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 17 | }; |
| 18 | |
Patrice Chotard | 7264aae | 2018-04-11 17:07:45 +0200 | [diff] [blame] | 19 | struct stm32_rcc_clk stm32_rcc_clk_f469 = { |
| 20 | .drv_name = "stm32fx_rcc_clock", |
| 21 | .soc = STM32F469, |
| 22 | }; |
| 23 | |
Patrice Chotard | 03f10a1 | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 24 | struct stm32_rcc_clk stm32_rcc_clk_f7 = { |
| 25 | .drv_name = "stm32fx_rcc_clock", |
| 26 | .soc = STM32F7, |
| 27 | }; |
| 28 | |
| 29 | struct stm32_rcc_clk stm32_rcc_clk_h7 = { |
| 30 | .drv_name = "stm32h7_rcc_clock", |
| 31 | }; |
| 32 | |
Christophe Kerello | 275f706 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 33 | static int stm32_rcc_bind(struct udevice *dev) |
| 34 | { |
Christophe Kerello | 275f706 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 35 | struct udevice *child; |
Patrice Chotard | 03f10a1 | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 36 | struct driver *drv; |
| 37 | struct stm32_rcc_clk *rcc_clk = |
| 38 | (struct stm32_rcc_clk *)dev_get_driver_data(dev); |
| 39 | int ret; |
Christophe Kerello | 275f706 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 40 | |
| 41 | debug("%s(dev=%p)\n", __func__, dev); |
| 42 | |
Patrice Chotard | 03f10a1 | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 43 | drv = lists_driver_lookup_name(rcc_clk->drv_name); |
| 44 | if (!drv) { |
| 45 | debug("Cannot find driver '%s'\n", rcc_clk->drv_name); |
| 46 | return -ENOENT; |
| 47 | } |
| 48 | |
| 49 | ret = device_bind_with_driver_data(dev, drv, rcc_clk->drv_name, |
| 50 | rcc_clk->soc, |
| 51 | dev_ofnode(dev), &child); |
| 52 | |
Christophe Kerello | 275f706 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 53 | if (ret) |
| 54 | return ret; |
| 55 | |
Patrice Chotard | 03f10a1 | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 56 | #ifdef CONFIG_SPL_BUILD |
| 57 | return 0; |
| 58 | #else |
Christophe Kerello | 275f706 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 59 | return device_bind_driver_to_node(dev, "stm32_rcc_reset", |
| 60 | "stm32_rcc_reset", |
| 61 | dev_ofnode(dev), &child); |
Patrice Chotard | 03f10a1 | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 62 | #endif |
Christophe Kerello | 275f706 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | static const struct misc_ops stm32_rcc_ops = { |
| 66 | }; |
| 67 | |
| 68 | static const struct udevice_id stm32_rcc_ids[] = { |
Patrice Chotard | 7264aae | 2018-04-11 17:07:45 +0200 | [diff] [blame] | 69 | {.compatible = "st,stm32f42xx-rcc", .data = (ulong)&stm32_rcc_clk_f42x }, |
| 70 | {.compatible = "st,stm32f469-rcc", .data = (ulong)&stm32_rcc_clk_f469 }, |
Patrice Chotard | 03f10a1 | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 71 | {.compatible = "st,stm32f746-rcc", .data = (ulong)&stm32_rcc_clk_f7 }, |
| 72 | {.compatible = "st,stm32h743-rcc", .data = (ulong)&stm32_rcc_clk_h7 }, |
Christophe Kerello | 275f706 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 73 | { } |
| 74 | }; |
| 75 | |
| 76 | U_BOOT_DRIVER(stm32_rcc) = { |
| 77 | .name = "stm32-rcc", |
| 78 | .id = UCLASS_MISC, |
| 79 | .of_match = stm32_rcc_ids, |
| 80 | .bind = stm32_rcc_bind, |
| 81 | .ops = &stm32_rcc_ops, |
| 82 | }; |