1 // SPDX-License-Identifier: GPL-2.0
3 * dwc3-of-simple.c - OF glue layer for simple integrations
5 * Copyright (c) 2015 Texas Instruments Incorporated - http://www.ti.com
7 * Author: Felipe Balbi <balbi@ti.com>
9 * This is a combination of the old dwc3-qcom.c by Ivan T. Ivanov
10 * <iivanov@mm-sol.com> and the original patch adding support for Xilinx' SoC
11 * by Subbaraya Sundeep Bhatta <subbaraya.sundeep.bhatta@xilinx.com>
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/slab.h>
17 #include <linux/platform_device.h>
18 #include <linux/dma-mapping.h>
19 #include <linux/clk.h>
21 #include <linux/of_platform.h>
22 #include <linux/pm_runtime.h>
23 #include <linux/reset.h>
25 struct dwc3_of_simple
{
27 struct clk_bulk_data
*clks
;
29 struct reset_control
*resets
;
34 static int dwc3_of_simple_probe(struct platform_device
*pdev
)
36 struct dwc3_of_simple
*simple
;
37 struct device
*dev
= &pdev
->dev
;
38 struct device_node
*np
= dev
->of_node
;
41 bool shared_resets
= false;
43 simple
= devm_kzalloc(dev
, sizeof(*simple
), GFP_KERNEL
);
47 platform_set_drvdata(pdev
, simple
);
51 * Some controllers need to toggle the usb3-otg reset before trying to
52 * initialize the PHY, otherwise the PHY times out.
54 if (of_device_is_compatible(np
, "rockchip,rk3399-dwc3"))
55 simple
->need_reset
= true;
57 if (of_device_is_compatible(np
, "amlogic,meson-axg-dwc3") ||
58 of_device_is_compatible(np
, "amlogic,meson-gxl-dwc3")) {
60 simple
->pulse_resets
= true;
63 simple
->resets
= of_reset_control_array_get(np
, shared_resets
, true,
65 if (IS_ERR(simple
->resets
)) {
66 ret
= PTR_ERR(simple
->resets
);
67 dev_err(dev
, "failed to get device resets, err=%d\n", ret
);
71 if (simple
->pulse_resets
) {
72 ret
= reset_control_reset(simple
->resets
);
76 ret
= reset_control_deassert(simple
->resets
);
81 ret
= clk_bulk_get_all(simple
->dev
, &simple
->clks
);
83 goto err_resetc_assert
;
85 simple
->num_clocks
= ret
;
86 ret
= clk_bulk_prepare_enable(simple
->num_clocks
, simple
->clks
);
88 goto err_resetc_assert
;
90 ret
= of_platform_populate(np
, NULL
, NULL
, dev
);
94 pm_runtime_set_active(dev
);
95 pm_runtime_enable(dev
);
96 pm_runtime_get_sync(dev
);
101 clk_bulk_disable_unprepare(simple
->num_clocks
, simple
->clks
);
102 clk_bulk_put_all(simple
->num_clocks
, simple
->clks
);
105 if (!simple
->pulse_resets
)
106 reset_control_assert(simple
->resets
);
109 reset_control_put(simple
->resets
);
113 static int dwc3_of_simple_remove(struct platform_device
*pdev
)
115 struct dwc3_of_simple
*simple
= platform_get_drvdata(pdev
);
116 struct device
*dev
= &pdev
->dev
;
118 of_platform_depopulate(dev
);
120 clk_bulk_disable_unprepare(simple
->num_clocks
, simple
->clks
);
121 clk_bulk_put_all(simple
->num_clocks
, simple
->clks
);
122 simple
->num_clocks
= 0;
124 if (!simple
->pulse_resets
)
125 reset_control_assert(simple
->resets
);
127 reset_control_put(simple
->resets
);
129 pm_runtime_disable(dev
);
130 pm_runtime_put_noidle(dev
);
131 pm_runtime_set_suspended(dev
);
136 static int __maybe_unused
dwc3_of_simple_runtime_suspend(struct device
*dev
)
138 struct dwc3_of_simple
*simple
= dev_get_drvdata(dev
);
140 clk_bulk_disable(simple
->num_clocks
, simple
->clks
);
145 static int __maybe_unused
dwc3_of_simple_runtime_resume(struct device
*dev
)
147 struct dwc3_of_simple
*simple
= dev_get_drvdata(dev
);
149 return clk_bulk_enable(simple
->num_clocks
, simple
->clks
);
152 static int __maybe_unused
dwc3_of_simple_suspend(struct device
*dev
)
154 struct dwc3_of_simple
*simple
= dev_get_drvdata(dev
);
156 if (simple
->need_reset
)
157 reset_control_assert(simple
->resets
);
162 static int __maybe_unused
dwc3_of_simple_resume(struct device
*dev
)
164 struct dwc3_of_simple
*simple
= dev_get_drvdata(dev
);
166 if (simple
->need_reset
)
167 reset_control_deassert(simple
->resets
);
172 static const struct dev_pm_ops dwc3_of_simple_dev_pm_ops
= {
173 SET_SYSTEM_SLEEP_PM_OPS(dwc3_of_simple_suspend
, dwc3_of_simple_resume
)
174 SET_RUNTIME_PM_OPS(dwc3_of_simple_runtime_suspend
,
175 dwc3_of_simple_runtime_resume
, NULL
)
178 static const struct of_device_id of_dwc3_simple_match
[] = {
179 { .compatible
= "rockchip,rk3399-dwc3" },
180 { .compatible
= "xlnx,zynqmp-dwc3" },
181 { .compatible
= "cavium,octeon-7130-usb-uctl" },
182 { .compatible
= "sprd,sc9860-dwc3" },
183 { .compatible
= "amlogic,meson-axg-dwc3" },
184 { .compatible
= "amlogic,meson-gxl-dwc3" },
185 { .compatible
= "allwinner,sun50i-h6-dwc3" },
188 MODULE_DEVICE_TABLE(of
, of_dwc3_simple_match
);
190 static struct platform_driver dwc3_of_simple_driver
= {
191 .probe
= dwc3_of_simple_probe
,
192 .remove
= dwc3_of_simple_remove
,
194 .name
= "dwc3-of-simple",
195 .of_match_table
= of_dwc3_simple_match
,
196 .pm
= &dwc3_of_simple_dev_pm_ops
,
200 module_platform_driver(dwc3_of_simple_driver
);
201 MODULE_LICENSE("GPL v2");
202 MODULE_DESCRIPTION("DesignWare USB3 OF Simple Glue Layer");
203 MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");