blob: 9f7affcaf92d0f474649315b32f0ea9f951e513d [file] [log] [blame]
Lena Salman20984752012-03-12 17:26:39 +02001/* Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved.
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +05302 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +053012 */
13
14#include <linux/module.h>
15#include <linux/platform_device.h>
Pavankumar Kondeti2d0cdcc2010-12-07 17:54:05 +053016#include <linux/pm_runtime.h>
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +053017#include <linux/usb/msm_hsusb_hw.h>
18#include <linux/usb/ulpi.h>
19
20#include "ci13xxx_udc.c"
21
22#define MSM_USB_BASE (udc->regs)
23
Lena Salman20984752012-03-12 17:26:39 +020024struct ci13xxx_udc_context {
25 int irq;
26 void __iomem *regs;
27};
28static struct ci13xxx_udc_context _udc_ctxt;
29
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +053030static irqreturn_t msm_udc_irq(int irq, void *data)
31{
32 return udc_irq();
33}
34
35static void ci13xxx_msm_notify_event(struct ci13xxx *udc, unsigned event)
36{
37 struct device *dev = udc->gadget.dev.parent;
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +053038
39 switch (event) {
40 case CI13XXX_CONTROLLER_RESET_EVENT:
41 dev_dbg(dev, "CI13XXX_CONTROLLER_RESET_EVENT received\n");
42 writel(0, USB_AHBBURST);
Vijayavardhan Vennapusa5f32d7a2012-03-14 16:30:26 +053043 writel_relaxed(0x08, USB_AHBMODE);
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +053044 break;
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +053045 default:
46 dev_dbg(dev, "unknown ci13xxx_udc event\n");
47 break;
48 }
49}
50
51static struct ci13xxx_udc_driver ci13xxx_msm_udc_driver = {
52 .name = "ci13xxx_msm",
53 .flags = CI13XXX_REGS_SHARED |
54 CI13XXX_REQUIRE_TRANSCEIVER |
55 CI13XXX_PULLUP_ON_VBUS |
Vijayavardhan Vennapusad450cb02012-02-25 14:35:26 +053056 CI13XXX_ZERO_ITC |
57 CI13XXX_IS_OTG,
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +053058
59 .notify_event = ci13xxx_msm_notify_event,
60};
61
62static int ci13xxx_msm_probe(struct platform_device *pdev)
63{
64 struct resource *res;
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +053065 int ret;
66
67 dev_dbg(&pdev->dev, "ci13xxx_msm_probe\n");
68
69 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
70 if (!res) {
71 dev_err(&pdev->dev, "failed to get platform resource mem\n");
72 return -ENXIO;
73 }
74
Lena Salman20984752012-03-12 17:26:39 +020075 _udc_ctxt.regs = ioremap(res->start, resource_size(res));
76 if (!_udc_ctxt.regs) {
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +053077 dev_err(&pdev->dev, "ioremap failed\n");
78 return -ENOMEM;
79 }
80
Lena Salman20984752012-03-12 17:26:39 +020081 ret = udc_probe(&ci13xxx_msm_udc_driver, &pdev->dev, _udc_ctxt.regs);
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +053082 if (ret < 0) {
83 dev_err(&pdev->dev, "udc_probe failed\n");
84 goto iounmap;
85 }
86
Lena Salman20984752012-03-12 17:26:39 +020087 _udc_ctxt.irq = platform_get_irq(pdev, 0);
88 if (_udc_ctxt.irq < 0) {
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +053089 dev_err(&pdev->dev, "IRQ not found\n");
90 ret = -ENXIO;
91 goto udc_remove;
92 }
93
Lena Salman20984752012-03-12 17:26:39 +020094 ret = request_irq(_udc_ctxt.irq, msm_udc_irq, IRQF_SHARED, pdev->name,
95 pdev);
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +053096 if (ret < 0) {
97 dev_err(&pdev->dev, "request_irq failed\n");
98 goto udc_remove;
99 }
100
Pavankumar Kondeti2d0cdcc2010-12-07 17:54:05 +0530101 pm_runtime_no_callbacks(&pdev->dev);
102 pm_runtime_enable(&pdev->dev);
103
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +0530104 return 0;
105
106udc_remove:
107 udc_remove();
108iounmap:
Lena Salman20984752012-03-12 17:26:39 +0200109 iounmap(_udc_ctxt.regs);
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +0530110
111 return ret;
112}
113
Lena Salman20984752012-03-12 17:26:39 +0200114int ci13xxx_msm_remove(struct platform_device *pdev)
115{
116 pm_runtime_disable(&pdev->dev);
117 free_irq(_udc_ctxt.irq, pdev);
118 udc_remove();
119 iounmap(_udc_ctxt.regs);
120 return 0;
121}
122
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +0530123static struct platform_driver ci13xxx_msm_driver = {
124 .probe = ci13xxx_msm_probe,
125 .driver = { .name = "msm_hsusb", },
Lena Salman20984752012-03-12 17:26:39 +0200126 .remove = ci13xxx_msm_remove,
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +0530127};
128
129static int __init ci13xxx_msm_init(void)
130{
131 return platform_driver_register(&ci13xxx_msm_driver);
132}
133module_init(ci13xxx_msm_init);
Lena Salman20984752012-03-12 17:26:39 +0200134
135static void __exit ci13xxx_msm_exit(void)
136{
137 platform_driver_unregister(&ci13xxx_msm_driver);
138}
139module_exit(ci13xxx_msm_exit);
140
141MODULE_LICENSE("GPL v2");