blob: c497337bb72be544f7d1c0ed1388e76d1cf958dd [file] [log] [blame]
Pavankumar Kondeti33f82f382010-12-07 17:54:03 +05301/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
2 *
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 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 *
17 */
18
19#include <linux/module.h>
20#include <linux/platform_device.h>
21#include <linux/usb/msm_hsusb_hw.h>
22#include <linux/usb/ulpi.h>
23
24#include "ci13xxx_udc.c"
25
26#define MSM_USB_BASE (udc->regs)
27
28static irqreturn_t msm_udc_irq(int irq, void *data)
29{
30 return udc_irq();
31}
32
33static void ci13xxx_msm_notify_event(struct ci13xxx *udc, unsigned event)
34{
35 struct device *dev = udc->gadget.dev.parent;
36 int val;
37
38 switch (event) {
39 case CI13XXX_CONTROLLER_RESET_EVENT:
40 dev_dbg(dev, "CI13XXX_CONTROLLER_RESET_EVENT received\n");
41 writel(0, USB_AHBBURST);
42 writel(0, USB_AHBMODE);
43 break;
44 case CI13XXX_CONTROLLER_STOPPED_EVENT:
45 dev_dbg(dev, "CI13XXX_CONTROLLER_STOPPED_EVENT received\n");
46 /*
47 * Put the transceiver in non-driving mode. Otherwise host
48 * may not detect soft-disconnection.
49 */
50 val = otg_io_read(udc->transceiver, ULPI_FUNC_CTRL);
51 val &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
52 val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING;
53 otg_io_write(udc->transceiver, val, ULPI_FUNC_CTRL);
54 break;
55 default:
56 dev_dbg(dev, "unknown ci13xxx_udc event\n");
57 break;
58 }
59}
60
61static struct ci13xxx_udc_driver ci13xxx_msm_udc_driver = {
62 .name = "ci13xxx_msm",
63 .flags = CI13XXX_REGS_SHARED |
64 CI13XXX_REQUIRE_TRANSCEIVER |
65 CI13XXX_PULLUP_ON_VBUS |
66 CI13XXX_DISABLE_STREAMING,
67
68 .notify_event = ci13xxx_msm_notify_event,
69};
70
71static int ci13xxx_msm_probe(struct platform_device *pdev)
72{
73 struct resource *res;
74 void __iomem *regs;
75 int irq;
76 int ret;
77
78 dev_dbg(&pdev->dev, "ci13xxx_msm_probe\n");
79
80 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
81 if (!res) {
82 dev_err(&pdev->dev, "failed to get platform resource mem\n");
83 return -ENXIO;
84 }
85
86 regs = ioremap(res->start, resource_size(res));
87 if (!regs) {
88 dev_err(&pdev->dev, "ioremap failed\n");
89 return -ENOMEM;
90 }
91
92 ret = udc_probe(&ci13xxx_msm_udc_driver, &pdev->dev, regs);
93 if (ret < 0) {
94 dev_err(&pdev->dev, "udc_probe failed\n");
95 goto iounmap;
96 }
97
98 irq = platform_get_irq(pdev, 0);
99 if (irq < 0) {
100 dev_err(&pdev->dev, "IRQ not found\n");
101 ret = -ENXIO;
102 goto udc_remove;
103 }
104
105 ret = request_irq(irq, msm_udc_irq, IRQF_SHARED, pdev->name, pdev);
106 if (ret < 0) {
107 dev_err(&pdev->dev, "request_irq failed\n");
108 goto udc_remove;
109 }
110
111 return 0;
112
113udc_remove:
114 udc_remove();
115iounmap:
116 iounmap(regs);
117
118 return ret;
119}
120
121static struct platform_driver ci13xxx_msm_driver = {
122 .probe = ci13xxx_msm_probe,
123 .driver = { .name = "msm_hsusb", },
124};
125
126static int __init ci13xxx_msm_init(void)
127{
128 return platform_driver_register(&ci13xxx_msm_driver);
129}
130module_init(ci13xxx_msm_init);