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 irqreturn_t
ux500_musb_interrupt(int irq
, void *__hci
)
42 irqreturn_t retval
= IRQ_NONE
;
43 struct musb
*musb
= __hci
;
45 spin_lock_irqsave(&musb
->lock
, flags
);
47 musb
->int_usb
= musb_readb(musb
->mregs
, MUSB_INTRUSB
);
48 musb
->int_tx
= musb_readw(musb
->mregs
, MUSB_INTRTX
);
49 musb
->int_rx
= musb_readw(musb
->mregs
, MUSB_INTRRX
);
51 if (musb
->int_usb
|| musb
->int_tx
|| musb
->int_rx
)
52 retval
= musb_interrupt(musb
);
54 spin_unlock_irqrestore(&musb
->lock
, flags
);
59 static int ux500_musb_init(struct musb
*musb
)
61 musb
->xceiv
= usb_get_phy(USB_PHY_TYPE_USB2
);
62 if (IS_ERR_OR_NULL(musb
->xceiv
)) {
63 pr_err("HS USB OTG: no transceiver configured\n");
67 musb
->isr
= ux500_musb_interrupt
;
72 static int ux500_musb_exit(struct musb
*musb
)
74 usb_put_phy(musb
->xceiv
);
79 static const struct musb_platform_ops ux500_ops
= {
80 .init
= ux500_musb_init
,
81 .exit
= ux500_musb_exit
,
84 static int ux500_probe(struct platform_device
*pdev
)
86 struct musb_hdrc_platform_data
*pdata
= pdev
->dev
.platform_data
;
87 struct platform_device
*musb
;
88 struct ux500_glue
*glue
;
92 glue
= kzalloc(sizeof(*glue
), GFP_KERNEL
);
94 dev_err(&pdev
->dev
, "failed to allocate glue context\n");
98 musb
= platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO
);
100 dev_err(&pdev
->dev
, "failed to allocate musb device\n");
104 clk
= clk_get(&pdev
->dev
, "usb");
106 dev_err(&pdev
->dev
, "failed to get clock\n");
111 ret
= clk_enable(clk
);
113 dev_err(&pdev
->dev
, "failed to enable clock\n");
117 musb
->dev
.parent
= &pdev
->dev
;
118 musb
->dev
.dma_mask
= pdev
->dev
.dma_mask
;
119 musb
->dev
.coherent_dma_mask
= pdev
->dev
.coherent_dma_mask
;
121 glue
->dev
= &pdev
->dev
;
125 pdata
->platform_ops
= &ux500_ops
;
127 platform_set_drvdata(pdev
, glue
);
129 ret
= platform_device_add_resources(musb
, pdev
->resource
,
130 pdev
->num_resources
);
132 dev_err(&pdev
->dev
, "failed to add resources\n");
136 ret
= platform_device_add_data(musb
, pdata
, sizeof(*pdata
));
138 dev_err(&pdev
->dev
, "failed to add platform_data\n");
142 ret
= platform_device_add(musb
);
144 dev_err(&pdev
->dev
, "failed to register musb device\n");
157 platform_device_put(musb
);
166 static int __devexit
ux500_remove(struct platform_device
*pdev
)
168 struct ux500_glue
*glue
= platform_get_drvdata(pdev
);
170 platform_device_unregister(glue
->musb
);
171 clk_disable(glue
->clk
);
179 static int ux500_suspend(struct device
*dev
)
181 struct ux500_glue
*glue
= dev_get_drvdata(dev
);
182 struct musb
*musb
= glue_to_musb(glue
);
184 usb_phy_set_suspend(musb
->xceiv
, 1);
185 clk_disable(glue
->clk
);
190 static int ux500_resume(struct device
*dev
)
192 struct ux500_glue
*glue
= dev_get_drvdata(dev
);
193 struct musb
*musb
= glue_to_musb(glue
);
196 ret
= clk_enable(glue
->clk
);
198 dev_err(dev
, "failed to enable clock\n");
202 usb_phy_set_suspend(musb
->xceiv
, 0);
207 static const struct dev_pm_ops ux500_pm_ops
= {
208 .suspend
= ux500_suspend
,
209 .resume
= ux500_resume
,
212 #define DEV_PM_OPS (&ux500_pm_ops)
214 #define DEV_PM_OPS NULL
217 static struct platform_driver ux500_driver
= {
218 .probe
= ux500_probe
,
219 .remove
= ux500_remove
,
221 .name
= "musb-ux500",
226 MODULE_DESCRIPTION("UX500 MUSB Glue Layer");
227 MODULE_AUTHOR("Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>");
228 MODULE_LICENSE("GPL v2");
229 module_platform_driver(ux500_driver
);