blob: b118997f6ee516c460faabe09d09b8dc4838d0a6 [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 *
5 * Copyright (c) 2015 Texas Instruments Incorporated - http://www.ti.com
6 *
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
13#include <common.h>
14#include <dm.h>
15#include <fdtdec.h>
16#include <reset.h>
17#include <clk.h>
18
Neil Armstrong069421e2018-04-11 17:08:00 +020019struct dwc3_of_simple {
20 struct clk_bulk clks;
21 struct reset_ctl_bulk resets;
22};
23
24static int dwc3_of_simple_reset_init(struct udevice *dev,
25 struct dwc3_of_simple *simple)
26{
27 int ret;
28
29 ret = reset_get_bulk(dev, &simple->resets);
30 if (ret == -ENOTSUPP)
31 return 0;
32 else if (ret)
33 return ret;
34
35 ret = reset_deassert_bulk(&simple->resets);
36 if (ret) {
37 reset_release_bulk(&simple->resets);
38 return ret;
39 }
40
41 return 0;
42}
43
44static int dwc3_of_simple_clk_init(struct udevice *dev,
45 struct dwc3_of_simple *simple)
46{
47 int ret;
48
49 ret = clk_get_bulk(dev, &simple->clks);
Neil Armstrong94239a82018-04-12 10:13:50 +020050 if (ret == -ENOSYS)
Neil Armstrong069421e2018-04-11 17:08:00 +020051 return 0;
52 if (ret)
53 return ret;
54
55#if CONFIG_IS_ENABLED(CLK)
56 ret = clk_enable_bulk(&simple->clks);
57 if (ret) {
58 clk_release_bulk(&simple->clks);
59 return ret;
60 }
61#endif
62
63 return 0;
64}
65
66static int dwc3_of_simple_probe(struct udevice *dev)
67{
68 struct dwc3_of_simple *simple = dev_get_platdata(dev);
69 int ret;
70
71 ret = dwc3_of_simple_clk_init(dev, simple);
72 if (ret)
73 return ret;
74
75 ret = dwc3_of_simple_reset_init(dev, simple);
76 if (ret)
77 return ret;
78
79 return 0;
80}
81
82static int dwc3_of_simple_remove(struct udevice *dev)
83{
84 struct dwc3_of_simple *simple = dev_get_platdata(dev);
85
86 reset_release_bulk(&simple->resets);
87
88 clk_release_bulk(&simple->clks);
89
90 return dm_scan_fdt_dev(dev);
91}
92
93static const struct udevice_id dwc3_of_simple_ids[] = {
94 { .compatible = "amlogic,meson-gxl-dwc3" },
Jean-Jacques Hiblot6c705f42018-04-12 10:41:11 +020095 { .compatible = "ti,dwc3" },
Neil Armstrong069421e2018-04-11 17:08:00 +020096 { }
97};
98
99U_BOOT_DRIVER(dwc3_of_simple) = {
100 .name = "dwc3-of-simple",
101 .id = UCLASS_SIMPLE_BUS,
102 .of_match = dwc3_of_simple_ids,
103 .probe = dwc3_of_simple_probe,
104 .remove = dwc3_of_simple_remove,
105 .platdata_auto_alloc_size = sizeof(struct dwc3_of_simple),
106 .flags = DM_FLAG_ALLOC_PRIV_DMA,
107};