blob: d52e7d22d1a74cfdd5d751d460f878c999501fb3 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Neil Armstrong069421e2018-04-11 17:08:00 +02002/*
3 * dwc3-of-simple.c - OF glue layer for simple integrations
4 *
Nishanth Menoneaa39c62023-11-01 15:56:03 -05005 * Copyright (c) 2015 Texas Instruments Incorporated - https://www.ti.com
Neil Armstrong069421e2018-04-11 17:08:00 +02006 *
7 * Author: Felipe Balbi <balbi@ti.com>
8 *
9 * Copyright (C) 2018 BayLibre, SAS
10 * Author: Neil Armstrong <narmstron@baylibre.com>
Neil Armstrong069421e2018-04-11 17:08:00 +020011 */
12
Neil Armstrong069421e2018-04-11 17:08:00 +020013#include <dm.h>
Neil Armstrong069421e2018-04-11 17:08:00 +020014#include <reset.h>
15#include <clk.h>
16
Neil Armstrong069421e2018-04-11 17:08:00 +020017struct dwc3_of_simple {
18 struct clk_bulk clks;
19 struct reset_ctl_bulk resets;
20};
21
22static 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
42static 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 Armstrong94239a82018-04-12 10:13:50 +020048 if (ret == -ENOSYS)
Neil Armstrong069421e2018-04-11 17:08:00 +020049 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
64static int dwc3_of_simple_probe(struct udevice *dev)
65{
Simon Glassfa20e932020-12-03 16:55:20 -070066 struct dwc3_of_simple *simple = dev_get_plat(dev);
Neil Armstrong069421e2018-04-11 17:08:00 +020067 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
80static int dwc3_of_simple_remove(struct udevice *dev)
81{
Simon Glassfa20e932020-12-03 16:55:20 -070082 struct dwc3_of_simple *simple = dev_get_plat(dev);
Neil Armstrong069421e2018-04-11 17:08:00 +020083
84 reset_release_bulk(&simple->resets);
85
86 clk_release_bulk(&simple->clks);
87
88 return dm_scan_fdt_dev(dev);
89}
90
91static const struct udevice_id dwc3_of_simple_ids[] = {
92 { .compatible = "amlogic,meson-gxl-dwc3" },
Mark Kettenis06ec9132019-06-30 18:01:54 +020093 { .compatible = "rockchip,rk3399-dwc3" },
Jean-Jacques Hiblot6c705f42018-04-12 10:41:11 +020094 { .compatible = "ti,dwc3" },
Neil Armstrong069421e2018-04-11 17:08:00 +020095 { }
96};
97
98U_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 Glass71fa5b42020-12-03 16:55:18 -0700104 .plat_auto = sizeof(struct dwc3_of_simple),
Neil Armstrong069421e2018-04-11 17:08:00 +0200105 .flags = DM_FLAG_ALLOC_PRIV_DMA,
106};