blob: 863143b310c6d6f32d84cfcee385c81393854369 [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 |
Chiranjeevi Velempatif1176012012-03-29 13:02:13 +053057 CI13XXX_DISABLE_STREAMING |
Vijayavardhan Vennapusad450cb02012-02-25 14:35:26 +053058 CI13XXX_IS_OTG,
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +053059
60 .notify_event = ci13xxx_msm_notify_event,
61};
62
63static int ci13xxx_msm_probe(struct platform_device *pdev)
64{
65 struct resource *res;
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +053066 int ret;
67
68 dev_dbg(&pdev->dev, "ci13xxx_msm_probe\n");
69
70 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
71 if (!res) {
72 dev_err(&pdev->dev, "failed to get platform resource mem\n");
73 return -ENXIO;
74 }
75
Lena Salman20984752012-03-12 17:26:39 +020076 _udc_ctxt.regs = ioremap(res->start, resource_size(res));
77 if (!_udc_ctxt.regs) {
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +053078 dev_err(&pdev->dev, "ioremap failed\n");
79 return -ENOMEM;
80 }
81
Lena Salman20984752012-03-12 17:26:39 +020082 ret = udc_probe(&ci13xxx_msm_udc_driver, &pdev->dev, _udc_ctxt.regs);
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +053083 if (ret < 0) {
84 dev_err(&pdev->dev, "udc_probe failed\n");
85 goto iounmap;
86 }
87
Lena Salman20984752012-03-12 17:26:39 +020088 _udc_ctxt.irq = platform_get_irq(pdev, 0);
89 if (_udc_ctxt.irq < 0) {
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +053090 dev_err(&pdev->dev, "IRQ not found\n");
91 ret = -ENXIO;
92 goto udc_remove;
93 }
94
Lena Salman20984752012-03-12 17:26:39 +020095 ret = request_irq(_udc_ctxt.irq, msm_udc_irq, IRQF_SHARED, pdev->name,
96 pdev);
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +053097 if (ret < 0) {
98 dev_err(&pdev->dev, "request_irq failed\n");
99 goto udc_remove;
100 }
101
Pavankumar Kondeti2d0cdcc2010-12-07 17:54:05 +0530102 pm_runtime_no_callbacks(&pdev->dev);
103 pm_runtime_enable(&pdev->dev);
104
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +0530105 return 0;
106
107udc_remove:
108 udc_remove();
109iounmap:
Lena Salman20984752012-03-12 17:26:39 +0200110 iounmap(_udc_ctxt.regs);
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +0530111
112 return ret;
113}
114
Lena Salman20984752012-03-12 17:26:39 +0200115int ci13xxx_msm_remove(struct platform_device *pdev)
116{
117 pm_runtime_disable(&pdev->dev);
118 free_irq(_udc_ctxt.irq, pdev);
119 udc_remove();
120 iounmap(_udc_ctxt.regs);
121 return 0;
122}
123
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +0530124static struct platform_driver ci13xxx_msm_driver = {
125 .probe = ci13xxx_msm_probe,
126 .driver = { .name = "msm_hsusb", },
Lena Salman20984752012-03-12 17:26:39 +0200127 .remove = ci13xxx_msm_remove,
Pavankumar Kondeti33f82f32010-12-07 17:54:03 +0530128};
129
130static int __init ci13xxx_msm_init(void)
131{
132 return platform_driver_register(&ci13xxx_msm_driver);
133}
134module_init(ci13xxx_msm_init);
Lena Salman20984752012-03-12 17:26:39 +0200135
136static void __exit ci13xxx_msm_exit(void)
137{
138 platform_driver_unregister(&ci13xxx_msm_driver);
139}
140module_exit(ci13xxx_msm_exit);
141
142MODULE_LICENSE("GPL v2");