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 | |
Chiranjeevi Velempati | f117601 | 2012-03-29 13:02:13 +0530 | [diff] [blame^] | 57 | CI13XXX_DISABLE_STREAMING | |
Vijayavardhan Vennapusa | d450cb0 | 2012-02-25 14:35:26 +0530 | [diff] [blame] | 58 | CI13XXX_IS_OTG, |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 59 | |
| 60 | .notify_event = ci13xxx_msm_notify_event, |
| 61 | }; |
| 62 | |
| 63 | static int ci13xxx_msm_probe(struct platform_device *pdev) |
| 64 | { |
| 65 | struct resource *res; |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 66 | 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 Salman | 2098475 | 2012-03-12 17:26:39 +0200 | [diff] [blame] | 76 | _udc_ctxt.regs = ioremap(res->start, resource_size(res)); |
| 77 | if (!_udc_ctxt.regs) { |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 78 | dev_err(&pdev->dev, "ioremap failed\n"); |
| 79 | return -ENOMEM; |
| 80 | } |
| 81 | |
Lena Salman | 2098475 | 2012-03-12 17:26:39 +0200 | [diff] [blame] | 82 | ret = udc_probe(&ci13xxx_msm_udc_driver, &pdev->dev, _udc_ctxt.regs); |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 83 | if (ret < 0) { |
| 84 | dev_err(&pdev->dev, "udc_probe failed\n"); |
| 85 | goto iounmap; |
| 86 | } |
| 87 | |
Lena Salman | 2098475 | 2012-03-12 17:26:39 +0200 | [diff] [blame] | 88 | _udc_ctxt.irq = platform_get_irq(pdev, 0); |
| 89 | if (_udc_ctxt.irq < 0) { |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 90 | dev_err(&pdev->dev, "IRQ not found\n"); |
| 91 | ret = -ENXIO; |
| 92 | goto udc_remove; |
| 93 | } |
| 94 | |
Lena Salman | 2098475 | 2012-03-12 17:26:39 +0200 | [diff] [blame] | 95 | ret = request_irq(_udc_ctxt.irq, msm_udc_irq, IRQF_SHARED, pdev->name, |
| 96 | pdev); |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 97 | if (ret < 0) { |
| 98 | dev_err(&pdev->dev, "request_irq failed\n"); |
| 99 | goto udc_remove; |
| 100 | } |
| 101 | |
Pavankumar Kondeti | 2d0cdcc | 2010-12-07 17:54:05 +0530 | [diff] [blame] | 102 | pm_runtime_no_callbacks(&pdev->dev); |
| 103 | pm_runtime_enable(&pdev->dev); |
| 104 | |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 105 | return 0; |
| 106 | |
| 107 | udc_remove: |
| 108 | udc_remove(); |
| 109 | iounmap: |
Lena Salman | 2098475 | 2012-03-12 17:26:39 +0200 | [diff] [blame] | 110 | iounmap(_udc_ctxt.regs); |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 111 | |
| 112 | return ret; |
| 113 | } |
| 114 | |
Lena Salman | 2098475 | 2012-03-12 17:26:39 +0200 | [diff] [blame] | 115 | int 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 Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 124 | static struct platform_driver ci13xxx_msm_driver = { |
| 125 | .probe = ci13xxx_msm_probe, |
| 126 | .driver = { .name = "msm_hsusb", }, |
Lena Salman | 2098475 | 2012-03-12 17:26:39 +0200 | [diff] [blame] | 127 | .remove = ci13xxx_msm_remove, |
Pavankumar Kondeti | 33f82f3 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | static int __init ci13xxx_msm_init(void) |
| 131 | { |
| 132 | return platform_driver_register(&ci13xxx_msm_driver); |
| 133 | } |
| 134 | module_init(ci13xxx_msm_init); |
Lena Salman | 2098475 | 2012-03-12 17:26:39 +0200 | [diff] [blame] | 135 | |
| 136 | static void __exit ci13xxx_msm_exit(void) |
| 137 | { |
| 138 | platform_driver_unregister(&ci13xxx_msm_driver); |
| 139 | } |
| 140 | module_exit(ci13xxx_msm_exit); |
| 141 | |
| 142 | MODULE_LICENSE("GPL v2"); |