2 * dwc3-of-simple.c - OF glue layer for simple integrations
4 * Copyright (c) 2015 Texas Instruments Incorporated - http://www.ti.com
6 * Author: Felipe Balbi <balbi@ti.com>
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 of
10 * the License as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * This is a combination of the old dwc3-qcom.c by Ivan T. Ivanov
18 * <iivanov@mm-sol.com> and the original patch adding support for Xilinx' SoC
19 * by Subbaraya Sundeep Bhatta <subbaraya.sundeep.bhatta@xilinx.com>
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/slab.h>
25 #include <linux/platform_device.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/clk.h>
28 #include <linux/clk-provider.h>
30 #include <linux/of_platform.h>
31 #include <linux/pm_runtime.h>
33 struct dwc3_of_simple
{
39 static int dwc3_of_simple_probe(struct platform_device
*pdev
)
41 struct dwc3_of_simple
*simple
;
42 struct device
*dev
= &pdev
->dev
;
43 struct device_node
*np
= dev
->of_node
;
49 simple
= devm_kzalloc(dev
, sizeof(*simple
), GFP_KERNEL
);
53 count
= of_clk_get_parent_count(np
);
57 simple
->num_clocks
= count
;
59 simple
->clks
= devm_kcalloc(dev
, simple
->num_clocks
,
60 sizeof(struct clk
*), GFP_KERNEL
);
66 for (i
= 0; i
< simple
->num_clocks
; i
++) {
69 clk
= of_clk_get(np
, i
);
72 clk_put(simple
->clks
[i
]);
76 ret
= clk_prepare_enable(clk
);
79 clk_disable_unprepare(simple
->clks
[i
]);
80 clk_put(simple
->clks
[i
]);
87 simple
->clks
[i
] = clk
;
90 ret
= of_platform_populate(np
, NULL
, NULL
, dev
);
92 for (i
= 0; i
< simple
->num_clocks
; i
++) {
93 clk_disable_unprepare(simple
->clks
[i
]);
94 clk_put(simple
->clks
[i
]);
100 pm_runtime_set_active(dev
);
101 pm_runtime_enable(dev
);
102 pm_runtime_get_sync(dev
);
107 static int dwc3_of_simple_remove(struct platform_device
*pdev
)
109 struct dwc3_of_simple
*simple
= platform_get_drvdata(pdev
);
110 struct device
*dev
= &pdev
->dev
;
113 for (i
= 0; i
< simple
->num_clocks
; i
++) {
114 clk_unprepare(simple
->clks
[i
]);
115 clk_put(simple
->clks
[i
]);
118 of_platform_depopulate(dev
);
120 pm_runtime_put_sync(dev
);
121 pm_runtime_disable(dev
);
127 static int dwc3_of_simple_runtime_suspend(struct device
*dev
)
129 struct dwc3_of_simple
*simple
= dev_get_drvdata(dev
);
132 for (i
= 0; i
< simple
->num_clocks
; i
++)
133 clk_disable(simple
->clks
[i
]);
138 static int dwc3_of_simple_runtime_resume(struct device
*dev
)
140 struct dwc3_of_simple
*simple
= dev_get_drvdata(dev
);
144 for (i
= 0; i
< simple
->num_clocks
; i
++) {
145 ret
= clk_enable(simple
->clks
[i
]);
148 clk_disable(simple
->clks
[i
]);
157 static const struct dev_pm_ops dwc3_of_simple_dev_pm_ops
= {
158 SET_RUNTIME_PM_OPS(dwc3_of_simple_runtime_suspend
,
159 dwc3_of_simple_runtime_resume
, NULL
)
162 static const struct of_device_id of_dwc3_simple_match
[] = {
163 { .compatible
= "qcom,dwc3" },
164 { .compatible
= "xlnx,zynqmp-dwc3" },
167 MODULE_DEVICE_TABLE(of
, of_dwc3_simple_match
);
169 static struct platform_driver dwc3_of_simple_driver
= {
170 .probe
= dwc3_of_simple_probe
,
171 .remove
= dwc3_of_simple_remove
,
173 .name
= "dwc3-of-simple",
174 .of_match_table
= of_dwc3_simple_match
,
178 module_platform_driver(dwc3_of_simple_driver
);
179 MODULE_LICENSE("GPL v2");
180 MODULE_DESCRIPTION("DesignWare USB3 OF Simple Glue Layer");
181 MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");