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 | 03f10a1 | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 14 | struct stm32_rcc_clk stm32_rcc_clk_f4 = { |
| 15 | .drv_name = "stm32fx_rcc_clock", |
| 16 | .soc = STM32F4, |
| 17 | }; |
| 18 | |
| 19 | struct stm32_rcc_clk stm32_rcc_clk_f7 = { |
| 20 | .drv_name = "stm32fx_rcc_clock", |
| 21 | .soc = STM32F7, |
| 22 | }; |
| 23 | |
| 24 | struct stm32_rcc_clk stm32_rcc_clk_h7 = { |
| 25 | .drv_name = "stm32h7_rcc_clock", |
| 26 | }; |
| 27 | |
Christophe Kerello | 275f706 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 28 | static int stm32_rcc_bind(struct udevice *dev) |
| 29 | { |
Christophe Kerello | 275f706 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 30 | struct udevice *child; |
Patrice Chotard | 03f10a1 | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 31 | struct driver *drv; |
| 32 | struct stm32_rcc_clk *rcc_clk = |
| 33 | (struct stm32_rcc_clk *)dev_get_driver_data(dev); |
| 34 | int ret; |
Christophe Kerello | 275f706 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 35 | |
| 36 | debug("%s(dev=%p)\n", __func__, dev); |
| 37 | |
Patrice Chotard | 03f10a1 | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 38 | 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 Kerello | 275f706 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 48 | if (ret) |
| 49 | return ret; |
| 50 | |
Patrice Chotard | 03f10a1 | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 51 | #ifdef CONFIG_SPL_BUILD |
| 52 | return 0; |
| 53 | #else |
Christophe Kerello | 275f706 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 54 | return device_bind_driver_to_node(dev, "stm32_rcc_reset", |
| 55 | "stm32_rcc_reset", |
| 56 | dev_ofnode(dev), &child); |
Patrice Chotard | 03f10a1 | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 57 | #endif |
Christophe Kerello | 275f706 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | static const struct misc_ops stm32_rcc_ops = { |
| 61 | }; |
| 62 | |
| 63 | static const struct udevice_id stm32_rcc_ids[] = { |
Patrice Chotard | 03f10a1 | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 64 | {.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 Kerello | 275f706 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 67 | { } |
| 68 | }; |
| 69 | |
| 70 | U_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 | }; |