Commit | Line | Data |
---|---|---|
4bc36fd3 MYK |
1 | /* |
2 | * Copyright (C) 2010 ST-Ericsson AB | |
3 | * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com> | |
4 | * | |
5 | * Based on omap2430.c | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
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. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
20 | */ | |
21 | ||
22 | #include <linux/module.h> | |
23 | #include <linux/kernel.h> | |
24 | #include <linux/init.h> | |
25 | #include <linux/clk.h> | |
ded017ee | 26 | #include <linux/err.h> |
4bc36fd3 MYK |
27 | #include <linux/io.h> |
28 | #include <linux/platform_device.h> | |
29 | ||
30 | #include "musb_core.h" | |
31 | ||
32 | struct ux500_glue { | |
33 | struct device *dev; | |
34 | struct platform_device *musb; | |
35 | struct clk *clk; | |
36 | }; | |
37 | #define glue_to_musb(g) platform_get_drvdata(g->musb) | |
38 | ||
39 | static int ux500_musb_init(struct musb *musb) | |
40 | { | |
662dca54 | 41 | musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); |
ded017ee | 42 | if (IS_ERR_OR_NULL(musb->xceiv)) { |
4bc36fd3 MYK |
43 | pr_err("HS USB OTG: no transceiver configured\n"); |
44 | return -ENODEV; | |
45 | } | |
46 | ||
47 | return 0; | |
48 | } | |
49 | ||
50 | static int ux500_musb_exit(struct musb *musb) | |
51 | { | |
721002ec | 52 | usb_put_phy(musb->xceiv); |
4bc36fd3 MYK |
53 | |
54 | return 0; | |
55 | } | |
56 | ||
57 | static const struct musb_platform_ops ux500_ops = { | |
58 | .init = ux500_musb_init, | |
59 | .exit = ux500_musb_exit, | |
60 | }; | |
61 | ||
e9e8c85e | 62 | static int __devinit ux500_probe(struct platform_device *pdev) |
4bc36fd3 MYK |
63 | { |
64 | struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; | |
65 | struct platform_device *musb; | |
66 | struct ux500_glue *glue; | |
67 | struct clk *clk; | |
68 | ||
69 | int ret = -ENOMEM; | |
70 | ||
71 | glue = kzalloc(sizeof(*glue), GFP_KERNEL); | |
72 | if (!glue) { | |
73 | dev_err(&pdev->dev, "failed to allocate glue context\n"); | |
74 | goto err0; | |
75 | } | |
76 | ||
65b3d52d R |
77 | /* get the musb id */ |
78 | musbid = musb_get_id(&pdev->dev, GFP_KERNEL); | |
79 | if (musbid < 0) { | |
80 | dev_err(&pdev->dev, "failed to allocate musb id\n"); | |
81 | ret = -ENOMEM; | |
82 | goto err1; | |
83 | } | |
84 | ||
85 | musb = platform_device_alloc("musb-hdrc", musbid); | |
4bc36fd3 MYK |
86 | if (!musb) { |
87 | dev_err(&pdev->dev, "failed to allocate musb device\n"); | |
65b3d52d | 88 | goto err2; |
4bc36fd3 MYK |
89 | } |
90 | ||
91 | clk = clk_get(&pdev->dev, "usb"); | |
92 | if (IS_ERR(clk)) { | |
93 | dev_err(&pdev->dev, "failed to get clock\n"); | |
94 | ret = PTR_ERR(clk); | |
65b3d52d | 95 | goto err3; |
4bc36fd3 MYK |
96 | } |
97 | ||
98 | ret = clk_enable(clk); | |
99 | if (ret) { | |
100 | dev_err(&pdev->dev, "failed to enable clock\n"); | |
65b3d52d | 101 | goto err4; |
4bc36fd3 MYK |
102 | } |
103 | ||
65b3d52d | 104 | musb->id = musbid; |
4bc36fd3 | 105 | musb->dev.parent = &pdev->dev; |
87266064 MYK |
106 | musb->dev.dma_mask = pdev->dev.dma_mask; |
107 | musb->dev.coherent_dma_mask = pdev->dev.coherent_dma_mask; | |
4bc36fd3 MYK |
108 | |
109 | glue->dev = &pdev->dev; | |
110 | glue->musb = musb; | |
111 | glue->clk = clk; | |
112 | ||
113 | pdata->platform_ops = &ux500_ops; | |
114 | ||
115 | platform_set_drvdata(pdev, glue); | |
116 | ||
117 | ret = platform_device_add_resources(musb, pdev->resource, | |
118 | pdev->num_resources); | |
119 | if (ret) { | |
120 | dev_err(&pdev->dev, "failed to add resources\n"); | |
65b3d52d | 121 | goto err5; |
4bc36fd3 MYK |
122 | } |
123 | ||
124 | ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); | |
125 | if (ret) { | |
126 | dev_err(&pdev->dev, "failed to add platform_data\n"); | |
65b3d52d | 127 | goto err5; |
4bc36fd3 MYK |
128 | } |
129 | ||
130 | ret = platform_device_add(musb); | |
131 | if (ret) { | |
132 | dev_err(&pdev->dev, "failed to register musb device\n"); | |
65b3d52d | 133 | goto err5; |
4bc36fd3 MYK |
134 | } |
135 | ||
136 | return 0; | |
137 | ||
65b3d52d | 138 | err5: |
4bc36fd3 MYK |
139 | clk_disable(clk); |
140 | ||
65b3d52d | 141 | err4: |
4bc36fd3 MYK |
142 | clk_put(clk); |
143 | ||
65b3d52d | 144 | err3: |
4bc36fd3 MYK |
145 | platform_device_put(musb); |
146 | ||
65b3d52d R |
147 | err2: |
148 | musb_put_id(&pdev->dev, musbid); | |
149 | ||
4bc36fd3 MYK |
150 | err1: |
151 | kfree(glue); | |
152 | ||
153 | err0: | |
154 | return ret; | |
155 | } | |
156 | ||
e9e8c85e | 157 | static int __devexit ux500_remove(struct platform_device *pdev) |
4bc36fd3 MYK |
158 | { |
159 | struct ux500_glue *glue = platform_get_drvdata(pdev); | |
160 | ||
65b3d52d | 161 | musb_put_id(&pdev->dev, glue->musb->id); |
4b0de6f3 | 162 | platform_device_unregister(glue->musb); |
4bc36fd3 MYK |
163 | clk_disable(glue->clk); |
164 | clk_put(glue->clk); | |
165 | kfree(glue); | |
166 | ||
167 | return 0; | |
168 | } | |
169 | ||
170 | #ifdef CONFIG_PM | |
171 | static int ux500_suspend(struct device *dev) | |
172 | { | |
173 | struct ux500_glue *glue = dev_get_drvdata(dev); | |
174 | struct musb *musb = glue_to_musb(glue); | |
175 | ||
b96d3b08 | 176 | usb_phy_set_suspend(musb->xceiv, 1); |
4bc36fd3 MYK |
177 | clk_disable(glue->clk); |
178 | ||
179 | return 0; | |
180 | } | |
181 | ||
182 | static int ux500_resume(struct device *dev) | |
183 | { | |
184 | struct ux500_glue *glue = dev_get_drvdata(dev); | |
185 | struct musb *musb = glue_to_musb(glue); | |
186 | int ret; | |
187 | ||
188 | ret = clk_enable(glue->clk); | |
189 | if (ret) { | |
190 | dev_err(dev, "failed to enable clock\n"); | |
191 | return ret; | |
192 | } | |
193 | ||
b96d3b08 | 194 | usb_phy_set_suspend(musb->xceiv, 0); |
4bc36fd3 MYK |
195 | |
196 | return 0; | |
197 | } | |
198 | ||
199 | static const struct dev_pm_ops ux500_pm_ops = { | |
200 | .suspend = ux500_suspend, | |
201 | .resume = ux500_resume, | |
202 | }; | |
203 | ||
204 | #define DEV_PM_OPS (&ux500_pm_ops) | |
205 | #else | |
206 | #define DEV_PM_OPS NULL | |
207 | #endif | |
208 | ||
209 | static struct platform_driver ux500_driver = { | |
e9e8c85e FB |
210 | .probe = ux500_probe, |
211 | .remove = __devexit_p(ux500_remove), | |
4bc36fd3 MYK |
212 | .driver = { |
213 | .name = "musb-ux500", | |
214 | .pm = DEV_PM_OPS, | |
215 | }, | |
216 | }; | |
217 | ||
218 | MODULE_DESCRIPTION("UX500 MUSB Glue Layer"); | |
219 | MODULE_AUTHOR("Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>"); | |
220 | MODULE_LICENSE("GPL v2"); | |
0e7090a6 | 221 | module_platform_driver(ux500_driver); |