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