Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Christophe Kerello | 4e280b9 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 2 | /* |
Patrice Chotard | 3bc599c | 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 | 4e280b9 | 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 | 928954f | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 10 | #include <stm32_rcc.h> |
| 11 | #include <dm/device-internal.h> |
Christophe Kerello | 4e280b9 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 12 | #include <dm/lists.h> |
| 13 | |
Patrice Chotard | 8b41464 | 2018-04-11 17:07:45 +0200 | [diff] [blame] | 14 | struct stm32_rcc_clk stm32_rcc_clk_f42x = { |
Patrice Chotard | 928954f | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 15 | .drv_name = "stm32fx_rcc_clock", |
Patrice Chotard | 8b41464 | 2018-04-11 17:07:45 +0200 | [diff] [blame] | 16 | .soc = STM32F42X, |
| 17 | }; |
| 18 | |
| 19 | struct stm32_rcc_clk stm32_rcc_clk_f469 = { |
| 20 | .drv_name = "stm32fx_rcc_clock", |
| 21 | .soc = STM32F469, |
Patrice Chotard | 928954f | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 22 | }; |
| 23 | |
| 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 | |
Patrick Delaunay | d090cba | 2018-07-09 15:17:20 +0200 | [diff] [blame] | 33 | struct stm32_rcc_clk stm32_rcc_clk_mp1 = { |
| 34 | .drv_name = "stm32mp1_clk", |
| 35 | .soc = STM32MP1, |
| 36 | }; |
| 37 | |
Christophe Kerello | 4e280b9 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 38 | static int stm32_rcc_bind(struct udevice *dev) |
| 39 | { |
Christophe Kerello | 4e280b9 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 40 | struct udevice *child; |
Patrice Chotard | 928954f | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 41 | struct driver *drv; |
| 42 | struct stm32_rcc_clk *rcc_clk = |
| 43 | (struct stm32_rcc_clk *)dev_get_driver_data(dev); |
| 44 | int ret; |
Christophe Kerello | 4e280b9 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 45 | |
| 46 | debug("%s(dev=%p)\n", __func__, dev); |
Patrice Chotard | 928954f | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 47 | drv = lists_driver_lookup_name(rcc_clk->drv_name); |
| 48 | if (!drv) { |
| 49 | debug("Cannot find driver '%s'\n", rcc_clk->drv_name); |
| 50 | return -ENOENT; |
| 51 | } |
| 52 | |
| 53 | ret = device_bind_with_driver_data(dev, drv, rcc_clk->drv_name, |
| 54 | rcc_clk->soc, |
| 55 | dev_ofnode(dev), &child); |
| 56 | |
Christophe Kerello | 4e280b9 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 57 | if (ret) |
| 58 | return ret; |
| 59 | |
Patrick Delaunay | d090cba | 2018-07-09 15:17:20 +0200 | [diff] [blame] | 60 | drv = lists_driver_lookup_name("stm32_rcc_reset"); |
| 61 | if (!drv) { |
| 62 | dev_err(dev, "Cannot find driver stm32_rcc_reset'\n"); |
| 63 | return -ENOENT; |
| 64 | } |
| 65 | |
| 66 | return device_bind_with_driver_data(dev, drv, "stm32_rcc_reset", |
| 67 | rcc_clk->soc, |
| 68 | dev_ofnode(dev), &child); |
Christophe Kerello | 4e280b9 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static const struct misc_ops stm32_rcc_ops = { |
| 72 | }; |
| 73 | |
| 74 | static const struct udevice_id stm32_rcc_ids[] = { |
Patrice Chotard | 8b41464 | 2018-04-11 17:07:45 +0200 | [diff] [blame] | 75 | {.compatible = "st,stm32f42xx-rcc", .data = (ulong)&stm32_rcc_clk_f42x }, |
| 76 | {.compatible = "st,stm32f469-rcc", .data = (ulong)&stm32_rcc_clk_f469 }, |
Patrice Chotard | 928954f | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 77 | {.compatible = "st,stm32f746-rcc", .data = (ulong)&stm32_rcc_clk_f7 }, |
| 78 | {.compatible = "st,stm32h743-rcc", .data = (ulong)&stm32_rcc_clk_h7 }, |
Patrick Delaunay | d090cba | 2018-07-09 15:17:20 +0200 | [diff] [blame] | 79 | {.compatible = "st,stm32mp1-rcc", .data = (ulong)&stm32_rcc_clk_mp1 }, |
Christophe Kerello | 4e280b9 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 80 | { } |
| 81 | }; |
| 82 | |
| 83 | U_BOOT_DRIVER(stm32_rcc) = { |
| 84 | .name = "stm32-rcc", |
| 85 | .id = UCLASS_MISC, |
| 86 | .of_match = stm32_rcc_ids, |
| 87 | .bind = stm32_rcc_bind, |
| 88 | .ops = &stm32_rcc_ops, |
| 89 | }; |