Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Neil Armstrong | 069421e | 2018-04-11 17:08:00 +0200 | [diff] [blame] | 2 | /* |
| 3 | * dwc3-of-simple.c - OF glue layer for simple integrations |
| 4 | * |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 5 | * Copyright (c) 2015 Texas Instruments Incorporated - https://www.ti.com |
Neil Armstrong | 069421e | 2018-04-11 17:08:00 +0200 | [diff] [blame] | 6 | * |
| 7 | * Author: Felipe Balbi <balbi@ti.com> |
| 8 | * |
| 9 | * Copyright (C) 2018 BayLibre, SAS |
| 10 | * Author: Neil Armstrong <narmstron@baylibre.com> |
Neil Armstrong | 069421e | 2018-04-11 17:08:00 +0200 | [diff] [blame] | 11 | */ |
| 12 | |
Neil Armstrong | 069421e | 2018-04-11 17:08:00 +0200 | [diff] [blame] | 13 | #include <dm.h> |
Neil Armstrong | 069421e | 2018-04-11 17:08:00 +0200 | [diff] [blame] | 14 | #include <reset.h> |
| 15 | #include <clk.h> |
| 16 | |
Neil Armstrong | 069421e | 2018-04-11 17:08:00 +0200 | [diff] [blame] | 17 | struct dwc3_of_simple { |
| 18 | struct clk_bulk clks; |
| 19 | struct reset_ctl_bulk resets; |
| 20 | }; |
| 21 | |
| 22 | static int dwc3_of_simple_reset_init(struct udevice *dev, |
| 23 | struct dwc3_of_simple *simple) |
| 24 | { |
| 25 | int ret; |
| 26 | |
| 27 | ret = reset_get_bulk(dev, &simple->resets); |
| 28 | if (ret == -ENOTSUPP) |
| 29 | return 0; |
| 30 | else if (ret) |
| 31 | return ret; |
| 32 | |
| 33 | ret = reset_deassert_bulk(&simple->resets); |
| 34 | if (ret) { |
| 35 | reset_release_bulk(&simple->resets); |
| 36 | return ret; |
| 37 | } |
| 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | static int dwc3_of_simple_clk_init(struct udevice *dev, |
| 43 | struct dwc3_of_simple *simple) |
| 44 | { |
| 45 | int ret; |
| 46 | |
| 47 | ret = clk_get_bulk(dev, &simple->clks); |
Neil Armstrong | 94239a8 | 2018-04-12 10:13:50 +0200 | [diff] [blame] | 48 | if (ret == -ENOSYS) |
Neil Armstrong | 069421e | 2018-04-11 17:08:00 +0200 | [diff] [blame] | 49 | return 0; |
| 50 | if (ret) |
| 51 | return ret; |
| 52 | |
| 53 | #if CONFIG_IS_ENABLED(CLK) |
| 54 | ret = clk_enable_bulk(&simple->clks); |
| 55 | if (ret) { |
| 56 | clk_release_bulk(&simple->clks); |
| 57 | return ret; |
| 58 | } |
| 59 | #endif |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static int dwc3_of_simple_probe(struct udevice *dev) |
| 65 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 66 | struct dwc3_of_simple *simple = dev_get_plat(dev); |
Neil Armstrong | 069421e | 2018-04-11 17:08:00 +0200 | [diff] [blame] | 67 | int ret; |
| 68 | |
| 69 | ret = dwc3_of_simple_clk_init(dev, simple); |
| 70 | if (ret) |
| 71 | return ret; |
| 72 | |
| 73 | ret = dwc3_of_simple_reset_init(dev, simple); |
| 74 | if (ret) |
| 75 | return ret; |
| 76 | |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | static int dwc3_of_simple_remove(struct udevice *dev) |
| 81 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 82 | struct dwc3_of_simple *simple = dev_get_plat(dev); |
Neil Armstrong | 069421e | 2018-04-11 17:08:00 +0200 | [diff] [blame] | 83 | |
| 84 | reset_release_bulk(&simple->resets); |
| 85 | |
| 86 | clk_release_bulk(&simple->clks); |
| 87 | |
| 88 | return dm_scan_fdt_dev(dev); |
| 89 | } |
| 90 | |
| 91 | static const struct udevice_id dwc3_of_simple_ids[] = { |
| 92 | { .compatible = "amlogic,meson-gxl-dwc3" }, |
Mark Kettenis | 06ec913 | 2019-06-30 18:01:54 +0200 | [diff] [blame] | 93 | { .compatible = "rockchip,rk3399-dwc3" }, |
Jean-Jacques Hiblot | 6c705f4 | 2018-04-12 10:41:11 +0200 | [diff] [blame] | 94 | { .compatible = "ti,dwc3" }, |
Neil Armstrong | 069421e | 2018-04-11 17:08:00 +0200 | [diff] [blame] | 95 | { } |
| 96 | }; |
| 97 | |
| 98 | U_BOOT_DRIVER(dwc3_of_simple) = { |
| 99 | .name = "dwc3-of-simple", |
| 100 | .id = UCLASS_SIMPLE_BUS, |
| 101 | .of_match = dwc3_of_simple_ids, |
| 102 | .probe = dwc3_of_simple_probe, |
| 103 | .remove = dwc3_of_simple_remove, |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 104 | .plat_auto = sizeof(struct dwc3_of_simple), |
Neil Armstrong | 069421e | 2018-04-11 17:08:00 +0200 | [diff] [blame] | 105 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 106 | }; |