blob: 8a754201b9855335db30ec3986694ad7e755e2fb [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2010-2011, 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
24static irqreturn_t msm_udc_irq(int irq, void *data)
25{
26 return udc_irq();
27}
28
29static void ci13xxx_msm_notify_event(struct ci13xxx *udc, unsigned event)
30{
31 struct device *dev = udc->gadget.dev.parent;
32 int val;
33
34 switch (event) {
35 case CI13XXX_CONTROLLER_RESET_EVENT:
36 dev_dbg(dev, "CI13XXX_CONTROLLER_RESET_EVENT received\n");
37 writel(0, USB_AHBBURST);
38 writel(0, USB_AHBMODE);
39 break;
40 case CI13XXX_CONTROLLER_STOPPED_EVENT:
41 dev_dbg(dev, "CI13XXX_CONTROLLER_STOPPED_EVENT received\n");
42 /*
43 * Put the transceiver in non-driving mode. Otherwise host
44 * may not detect soft-disconnection.
45 */
46 val = otg_io_read(udc->transceiver, ULPI_FUNC_CTRL);
47 val &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
48 val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING;
49 otg_io_write(udc->transceiver, val, ULPI_FUNC_CTRL);
50 break;
51 default:
52 dev_dbg(dev, "unknown ci13xxx_udc event\n");
53 break;
54 }
55}
56
57static struct ci13xxx_udc_driver ci13xxx_msm_udc_driver = {
58 .name = "ci13xxx_msm",
59 .flags = CI13XXX_REGS_SHARED |
60 CI13XXX_REQUIRE_TRANSCEIVER |
61 CI13XXX_PULLUP_ON_VBUS |
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070062 CI13XXX_DISABLE_STREAMING |
63 CI13XXX_ZERO_ITC,
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +053064
65 .notify_event = ci13xxx_msm_notify_event,
66};
67
68static int ci13xxx_msm_probe(struct platform_device *pdev)
69{
70 struct resource *res;
71 void __iomem *regs;
72 int irq;
73 int ret;
74
75 dev_dbg(&pdev->dev, "ci13xxx_msm_probe\n");
76
77 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
78 if (!res) {
79 dev_err(&pdev->dev, "failed to get platform resource mem\n");
80 return -ENXIO;
81 }
82
83 regs = ioremap(res->start, resource_size(res));
84 if (!regs) {
85 dev_err(&pdev->dev, "ioremap failed\n");
86 return -ENOMEM;
87 }
88
89 ret = udc_probe(&ci13xxx_msm_udc_driver, &pdev->dev, regs);
90 if (ret < 0) {
91 dev_err(&pdev->dev, "udc_probe failed\n");
92 goto iounmap;
93 }
94
95 irq = platform_get_irq(pdev, 0);
96 if (irq < 0) {
97 dev_err(&pdev->dev, "IRQ not found\n");
98 ret = -ENXIO;
99 goto udc_remove;
100 }
101
102 ret = request_irq(irq, msm_udc_irq, IRQF_SHARED, pdev->name, pdev);
103 if (ret < 0) {
104 dev_err(&pdev->dev, "request_irq failed\n");
105 goto udc_remove;
106 }
107
Pavankumar Kondeti2d0cdcc2010-12-07 17:54:05 +0530108 pm_runtime_no_callbacks(&pdev->dev);
109 pm_runtime_enable(&pdev->dev);
110
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +0530111 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);