linux/drivers/usb/gadget/ci13xxx_msm.c
<<
>>
Prefs
   1/* 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/pm_runtime.h>
  22#include <linux/usb/msm_hsusb_hw.h>
  23#include <linux/usb/ulpi.h>
  24
  25#include "ci13xxx_udc.c"
  26
  27#define MSM_USB_BASE    (udc->regs)
  28
  29static irqreturn_t msm_udc_irq(int irq, void *data)
  30{
  31        return udc_irq();
  32}
  33
  34static void ci13xxx_msm_notify_event(struct ci13xxx *udc, unsigned event)
  35{
  36        struct device *dev = udc->gadget.dev.parent;
  37        int val;
  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);
  43                writel(0, USB_AHBMODE);
  44                break;
  45        case CI13XXX_CONTROLLER_STOPPED_EVENT:
  46                dev_dbg(dev, "CI13XXX_CONTROLLER_STOPPED_EVENT received\n");
  47                /*
  48                 * Put the transceiver in non-driving mode. Otherwise host
  49                 * may not detect soft-disconnection.
  50                 */
  51                val = otg_io_read(udc->transceiver, ULPI_FUNC_CTRL);
  52                val &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
  53                val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING;
  54                otg_io_write(udc->transceiver, val, ULPI_FUNC_CTRL);
  55                break;
  56        default:
  57                dev_dbg(dev, "unknown ci13xxx_udc event\n");
  58                break;
  59        }
  60}
  61
  62static struct ci13xxx_udc_driver ci13xxx_msm_udc_driver = {
  63        .name                   = "ci13xxx_msm",
  64        .flags                  = CI13XXX_REGS_SHARED |
  65                                  CI13XXX_REQUIRE_TRANSCEIVER |
  66                                  CI13XXX_PULLUP_ON_VBUS |
  67                                  CI13XXX_DISABLE_STREAMING,
  68
  69        .notify_event           = ci13xxx_msm_notify_event,
  70};
  71
  72static int ci13xxx_msm_probe(struct platform_device *pdev)
  73{
  74        struct resource *res;
  75        void __iomem *regs;
  76        int irq;
  77        int ret;
  78
  79        dev_dbg(&pdev->dev, "ci13xxx_msm_probe\n");
  80
  81        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  82        if (!res) {
  83                dev_err(&pdev->dev, "failed to get platform resource mem\n");
  84                return -ENXIO;
  85        }
  86
  87        regs = ioremap(res->start, resource_size(res));
  88        if (!regs) {
  89                dev_err(&pdev->dev, "ioremap failed\n");
  90                return -ENOMEM;
  91        }
  92
  93        ret = udc_probe(&ci13xxx_msm_udc_driver, &pdev->dev, regs);
  94        if (ret < 0) {
  95                dev_err(&pdev->dev, "udc_probe failed\n");
  96                goto iounmap;
  97        }
  98
  99        irq = platform_get_irq(pdev, 0);
 100        if (irq < 0) {
 101                dev_err(&pdev->dev, "IRQ not found\n");
 102                ret = -ENXIO;
 103                goto udc_remove;
 104        }
 105
 106        ret = request_irq(irq, msm_udc_irq, IRQF_SHARED, pdev->name, pdev);
 107        if (ret < 0) {
 108                dev_err(&pdev->dev, "request_irq failed\n");
 109                goto udc_remove;
 110        }
 111
 112        pm_runtime_no_callbacks(&pdev->dev);
 113        pm_runtime_enable(&pdev->dev);
 114
 115        return 0;
 116
 117udc_remove:
 118        udc_remove();
 119iounmap:
 120        iounmap(regs);
 121
 122        return ret;
 123}
 124
 125static struct platform_driver ci13xxx_msm_driver = {
 126        .probe = ci13xxx_msm_probe,
 127        .driver = { .name = "msm_hsusb", },
 128};
 129
 130static int __init ci13xxx_msm_init(void)
 131{
 132        return platform_driver_register(&ci13xxx_msm_driver);
 133}
 134module_init(ci13xxx_msm_init);
 135