Lena Salman | 2098475 | 2012-03-12 17:26:39 +0200 | [diff] [blame] | 1 | /* Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved. |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 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 | * |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/platform_device.h> |
Pavankumar Kondeti | 2d0cdcc | 2010-12-07 17:54:05 +0530 | [diff] [blame] | 16 | #include <linux/pm_runtime.h> |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 17 | #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 Salman | 2098475 | 2012-03-12 17:26:39 +0200 | [diff] [blame] | 24 | struct ci13xxx_udc_context { |
| 25 | int irq; |
| 26 | void __iomem *regs; |
| 27 | }; |
| 28 | static struct ci13xxx_udc_context _udc_ctxt; |
| 29 | |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 30 | static irqreturn_t msm_udc_irq(int irq, void *data) |
| 31 | { |
| 32 | return udc_irq(); |
| 33 | } |
| 34 | |
| 35 | static void ci13xxx_msm_notify_event(struct ci13xxx *udc, unsigned event) |
| 36 | { |
| 37 | struct device *dev = udc->gadget.dev.parent; |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 38 | |
| 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 Vennapusa | 5f32d7a | 2012-03-14 16:30:26 +0530 | [diff] [blame^] | 43 | writel_relaxed(0x08, USB_AHBMODE); |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 44 | break; |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 45 | default: |
| 46 | dev_dbg(dev, "unknown ci13xxx_udc event\n"); |
| 47 | break; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | static 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 Vennapusa | d450cb0 | 2012-02-25 14:35:26 +0530 | [diff] [blame] | 56 | CI13XXX_ZERO_ITC | |
| 57 | CI13XXX_IS_OTG, |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 58 | |
| 59 | .notify_event = ci13xxx_msm_notify_event, |
| 60 | }; |
| 61 | |
| 62 | static int ci13xxx_msm_probe(struct platform_device *pdev) |
| 63 | { |
| 64 | struct resource *res; |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 65 | 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 Salman | 2098475 | 2012-03-12 17:26:39 +0200 | [diff] [blame] | 75 | _udc_ctxt.regs = ioremap(res->start, resource_size(res)); |
| 76 | if (!_udc_ctxt.regs) { |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 77 | dev_err(&pdev->dev, "ioremap failed\n"); |
| 78 | return -ENOMEM; |
| 79 | } |
| 80 | |
Lena Salman | 2098475 | 2012-03-12 17:26:39 +0200 | [diff] [blame] | 81 | ret = udc_probe(&ci13xxx_msm_udc_driver, &pdev->dev, _udc_ctxt.regs); |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 82 | if (ret < 0) { |
| 83 | dev_err(&pdev->dev, "udc_probe failed\n"); |
| 84 | goto iounmap; |
| 85 | } |
| 86 | |
Lena Salman | 2098475 | 2012-03-12 17:26:39 +0200 | [diff] [blame] | 87 | _udc_ctxt.irq = platform_get_irq(pdev, 0); |
| 88 | if (_udc_ctxt.irq < 0) { |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 89 | dev_err(&pdev->dev, "IRQ not found\n"); |
| 90 | ret = -ENXIO; |
| 91 | goto udc_remove; |
| 92 | } |
| 93 | |
Lena Salman | 2098475 | 2012-03-12 17:26:39 +0200 | [diff] [blame] | 94 | ret = request_irq(_udc_ctxt.irq, msm_udc_irq, IRQF_SHARED, pdev->name, |
| 95 | pdev); |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 96 | if (ret < 0) { |
| 97 | dev_err(&pdev->dev, "request_irq failed\n"); |
| 98 | goto udc_remove; |
| 99 | } |
| 100 | |
Pavankumar Kondeti | 2d0cdcc | 2010-12-07 17:54:05 +0530 | [diff] [blame] | 101 | pm_runtime_no_callbacks(&pdev->dev); |
| 102 | pm_runtime_enable(&pdev->dev); |
| 103 | |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 104 | return 0; |
| 105 | |
| 106 | udc_remove: |
| 107 | udc_remove(); |
| 108 | iounmap: |
Lena Salman | 2098475 | 2012-03-12 17:26:39 +0200 | [diff] [blame] | 109 | iounmap(_udc_ctxt.regs); |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 110 | |
| 111 | return ret; |
| 112 | } |
| 113 | |
Lena Salman | 2098475 | 2012-03-12 17:26:39 +0200 | [diff] [blame] | 114 | int 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 Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 123 | static struct platform_driver ci13xxx_msm_driver = { |
| 124 | .probe = ci13xxx_msm_probe, |
| 125 | .driver = { .name = "msm_hsusb", }, |
Lena Salman | 2098475 | 2012-03-12 17:26:39 +0200 | [diff] [blame] | 126 | .remove = ci13xxx_msm_remove, |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | static int __init ci13xxx_msm_init(void) |
| 130 | { |
| 131 | return platform_driver_register(&ci13xxx_msm_driver); |
| 132 | } |
| 133 | module_init(ci13xxx_msm_init); |
Lena Salman | 2098475 | 2012-03-12 17:26:39 +0200 | [diff] [blame] | 134 | |
| 135 | static void __exit ci13xxx_msm_exit(void) |
| 136 | { |
| 137 | platform_driver_unregister(&ci13xxx_msm_driver); |
| 138 | } |
| 139 | module_exit(ci13xxx_msm_exit); |
| 140 | |
| 141 | MODULE_LICENSE("GPL v2"); |