2 * Copyright (C) 2010 ST-Ericsson AB
3 * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
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.
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 * 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.
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/init.h>
25 #include <linux/clk.h>
26 #include <linux/err.h>
28 #include <linux/platform_device.h>
30 #include "musb_core.h"
34 struct platform_device *musb;
37 #define glue_to_musb(g) platform_get_drvdata(g->musb)
39 static int ux500_musb_init(struct musb *musb)
41 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
42 if (IS_ERR_OR_NULL(musb->xceiv)) {
43 pr_err("HS USB OTG: no transceiver configured\n");
50 static int ux500_musb_exit(struct musb *musb)
52 usb_put_phy(musb->xceiv);
57 static const struct musb_platform_ops ux500_ops = {
58 .init = ux500_musb_init,
59 .exit = ux500_musb_exit,
62 static int __devinit ux500_probe(struct platform_device *pdev)
64 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data;
65 struct platform_device *musb;
66 struct ux500_glue *glue;
71 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
73 dev_err(&pdev->dev, "failed to allocate glue context\n");
78 musbid = musb_get_id(&pdev->dev, GFP_KERNEL);
80 dev_err(&pdev->dev, "failed to allocate musb id\n");
85 musb = platform_device_alloc("musb-hdrc", musbid);
87 dev_err(&pdev->dev, "failed to allocate musb device\n");
91 clk = clk_get(&pdev->dev, "usb");
93 dev_err(&pdev->dev, "failed to get clock\n");
98 ret = clk_enable(clk);
100 dev_err(&pdev->dev, "failed to enable clock\n");
105 musb->dev.parent = &pdev->dev;
106 musb->dev.dma_mask = pdev->dev.dma_mask;
107 musb->dev.coherent_dma_mask = pdev->dev.coherent_dma_mask;
109 glue->dev = &pdev->dev;
113 pdata->platform_ops = &ux500_ops;
115 platform_set_drvdata(pdev, glue);
117 ret = platform_device_add_resources(musb, pdev->resource,
118 pdev->num_resources);
120 dev_err(&pdev->dev, "failed to add resources\n");
124 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
126 dev_err(&pdev->dev, "failed to add platform_data\n");
130 ret = platform_device_add(musb);
132 dev_err(&pdev->dev, "failed to register musb device\n");
145 platform_device_put(musb);
148 musb_put_id(&pdev->dev, musbid);
157 static int __devexit ux500_remove(struct platform_device *pdev)
159 struct ux500_glue *glue = platform_get_drvdata(pdev);
161 musb_put_id(&pdev->dev, glue->musb->id);
162 platform_device_del(glue->musb);
163 platform_device_put(glue->musb);
164 clk_disable(glue->clk);
172 static int ux500_suspend(struct device *dev)
174 struct ux500_glue *glue = dev_get_drvdata(dev);
175 struct musb *musb = glue_to_musb(glue);
177 usb_phy_set_suspend(musb->xceiv, 1);
178 clk_disable(glue->clk);
183 static int ux500_resume(struct device *dev)
185 struct ux500_glue *glue = dev_get_drvdata(dev);
186 struct musb *musb = glue_to_musb(glue);
189 ret = clk_enable(glue->clk);
191 dev_err(dev, "failed to enable clock\n");
195 usb_phy_set_suspend(musb->xceiv, 0);
200 static const struct dev_pm_ops ux500_pm_ops = {
201 .suspend = ux500_suspend,
202 .resume = ux500_resume,
205 #define DEV_PM_OPS (&ux500_pm_ops)
207 #define DEV_PM_OPS NULL
210 static struct platform_driver ux500_driver = {
211 .probe = ux500_probe,
212 .remove = __devexit_p(ux500_remove),
214 .name = "musb-ux500",
219 MODULE_DESCRIPTION("UX500 MUSB Glue Layer");
220 MODULE_AUTHOR("Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>");
221 MODULE_LICENSE("GPL v2");
223 static int __init ux500_init(void)
225 return platform_driver_register(&ux500_driver);
227 module_init(ux500_init);
229 static void __exit ux500_exit(void)
231 platform_driver_unregister(&ux500_driver);
233 module_exit(ux500_exit);