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> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 12 | #include <dm/device_compat.h> |
Christophe Kerello | 4e280b9 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 13 | #include <dm/lists.h> |
| 14 | |
Patrice Chotard | 8b41464 | 2018-04-11 17:07:45 +0200 | [diff] [blame] | 15 | struct stm32_rcc_clk stm32_rcc_clk_f42x = { |
Patrice Chotard | 928954f | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 16 | .drv_name = "stm32fx_rcc_clock", |
Patrice Chotard | 8b41464 | 2018-04-11 17:07:45 +0200 | [diff] [blame] | 17 | .soc = STM32F42X, |
| 18 | }; |
| 19 | |
| 20 | struct stm32_rcc_clk stm32_rcc_clk_f469 = { |
| 21 | .drv_name = "stm32fx_rcc_clock", |
| 22 | .soc = STM32F469, |
Patrice Chotard | 928954f | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 23 | }; |
| 24 | |
| 25 | struct stm32_rcc_clk stm32_rcc_clk_f7 = { |
| 26 | .drv_name = "stm32fx_rcc_clock", |
| 27 | .soc = STM32F7, |
| 28 | }; |
| 29 | |
| 30 | struct stm32_rcc_clk stm32_rcc_clk_h7 = { |
| 31 | .drv_name = "stm32h7_rcc_clock", |
| 32 | }; |
| 33 | |
Patrick Delaunay | d090cba | 2018-07-09 15:17:20 +0200 | [diff] [blame] | 34 | struct stm32_rcc_clk stm32_rcc_clk_mp1 = { |
| 35 | .drv_name = "stm32mp1_clk", |
| 36 | .soc = STM32MP1, |
| 37 | }; |
| 38 | |
Christophe Kerello | 4e280b9 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 39 | static int stm32_rcc_bind(struct udevice *dev) |
| 40 | { |
Christophe Kerello | 4e280b9 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 41 | struct udevice *child; |
Patrice Chotard | 928954f | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 42 | struct driver *drv; |
| 43 | struct stm32_rcc_clk *rcc_clk = |
| 44 | (struct stm32_rcc_clk *)dev_get_driver_data(dev); |
| 45 | int ret; |
Christophe Kerello | 4e280b9 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 46 | |
| 47 | debug("%s(dev=%p)\n", __func__, dev); |
Patrice Chotard | 928954f | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 48 | drv = lists_driver_lookup_name(rcc_clk->drv_name); |
| 49 | if (!drv) { |
| 50 | debug("Cannot find driver '%s'\n", rcc_clk->drv_name); |
| 51 | return -ENOENT; |
| 52 | } |
| 53 | |
| 54 | ret = device_bind_with_driver_data(dev, drv, rcc_clk->drv_name, |
| 55 | rcc_clk->soc, |
| 56 | dev_ofnode(dev), &child); |
| 57 | |
Christophe Kerello | 4e280b9 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 58 | if (ret) |
| 59 | return ret; |
| 60 | |
Patrick Delaunay | d090cba | 2018-07-09 15:17:20 +0200 | [diff] [blame] | 61 | drv = lists_driver_lookup_name("stm32_rcc_reset"); |
| 62 | if (!drv) { |
| 63 | dev_err(dev, "Cannot find driver stm32_rcc_reset'\n"); |
| 64 | return -ENOENT; |
| 65 | } |
| 66 | |
| 67 | return device_bind_with_driver_data(dev, drv, "stm32_rcc_reset", |
| 68 | rcc_clk->soc, |
| 69 | dev_ofnode(dev), &child); |
Christophe Kerello | 4e280b9 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 70 | } |
| 71 | |
Christophe Kerello | 4e280b9 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 72 | |
| 73 | static const struct udevice_id stm32_rcc_ids[] = { |
Patrice Chotard | 8b41464 | 2018-04-11 17:07:45 +0200 | [diff] [blame] | 74 | {.compatible = "st,stm32f42xx-rcc", .data = (ulong)&stm32_rcc_clk_f42x }, |
| 75 | {.compatible = "st,stm32f469-rcc", .data = (ulong)&stm32_rcc_clk_f469 }, |
Patrice Chotard | 928954f | 2017-11-15 13:14:51 +0100 | [diff] [blame] | 76 | {.compatible = "st,stm32f746-rcc", .data = (ulong)&stm32_rcc_clk_f7 }, |
| 77 | {.compatible = "st,stm32h743-rcc", .data = (ulong)&stm32_rcc_clk_h7 }, |
Patrick Delaunay | d090cba | 2018-07-09 15:17:20 +0200 | [diff] [blame] | 78 | {.compatible = "st,stm32mp1-rcc", .data = (ulong)&stm32_rcc_clk_mp1 }, |
Christophe Kerello | 4e280b9 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 79 | { } |
| 80 | }; |
| 81 | |
| 82 | U_BOOT_DRIVER(stm32_rcc) = { |
| 83 | .name = "stm32-rcc", |
Patrick Delaunay | 1323470 | 2019-08-02 13:08:08 +0200 | [diff] [blame] | 84 | .id = UCLASS_NOP, |
Christophe Kerello | 4e280b9 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 85 | .of_match = stm32_rcc_ids, |
| 86 | .bind = stm32_rcc_bind, |
Christophe Kerello | 4e280b9 | 2017-09-13 18:00:08 +0200 | [diff] [blame] | 87 | }; |