Pavankumar Kondeti | 33f82f38 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 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. |
Pavankumar Kondeti | 33f82f38 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/platform_device.h> |
Pavankumar Kondeti | 2d0cdcc | 2010-12-07 17:54:05 +0530 | [diff] [blame] | 10 | #include <linux/pm_runtime.h> |
Pavankumar Kondeti | 33f82f38 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 11 | #include <linux/usb/msm_hsusb_hw.h> |
| 12 | #include <linux/usb/ulpi.h> |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame] | 13 | #include <linux/usb/gadget.h> |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 14 | #include <linux/usb/chipidea.h> |
Pavankumar Kondeti | 33f82f38 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 15 | |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 16 | #include "ci.h" |
Pavankumar Kondeti | 33f82f38 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 17 | |
Alexander Shishkin | f8c1376 | 2012-05-11 17:25:48 +0300 | [diff] [blame] | 18 | #define MSM_USB_BASE (udc->hw_bank.abs) |
Pavankumar Kondeti | 33f82f38 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 19 | |
Pavankumar Kondeti | 33f82f38 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 20 | static void ci13xxx_msm_notify_event(struct ci13xxx *udc, unsigned event) |
| 21 | { |
| 22 | struct device *dev = udc->gadget.dev.parent; |
| 23 | int val; |
| 24 | |
| 25 | switch (event) { |
| 26 | case CI13XXX_CONTROLLER_RESET_EVENT: |
| 27 | dev_dbg(dev, "CI13XXX_CONTROLLER_RESET_EVENT received\n"); |
| 28 | writel(0, USB_AHBBURST); |
| 29 | writel(0, USB_AHBMODE); |
| 30 | break; |
| 31 | case CI13XXX_CONTROLLER_STOPPED_EVENT: |
| 32 | dev_dbg(dev, "CI13XXX_CONTROLLER_STOPPED_EVENT received\n"); |
| 33 | /* |
| 34 | * Put the transceiver in non-driving mode. Otherwise host |
| 35 | * may not detect soft-disconnection. |
| 36 | */ |
Heikki Krogerus | b96d3b0 | 2012-02-13 13:24:18 +0200 | [diff] [blame] | 37 | val = usb_phy_io_read(udc->transceiver, ULPI_FUNC_CTRL); |
Pavankumar Kondeti | 33f82f38 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 38 | val &= ~ULPI_FUNC_CTRL_OPMODE_MASK; |
| 39 | val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING; |
Heikki Krogerus | b96d3b0 | 2012-02-13 13:24:18 +0200 | [diff] [blame] | 40 | usb_phy_io_write(udc->transceiver, val, ULPI_FUNC_CTRL); |
Pavankumar Kondeti | 33f82f38 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 41 | break; |
| 42 | default: |
| 43 | dev_dbg(dev, "unknown ci13xxx_udc event\n"); |
| 44 | break; |
| 45 | } |
| 46 | } |
| 47 | |
Richard Zhao | 77c4400 | 2012-06-29 17:48:53 +0800 | [diff] [blame^] | 48 | static struct ci13xxx_platform_data ci13xxx_msm_platdata = { |
Pavankumar Kondeti | 33f82f38 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 49 | .name = "ci13xxx_msm", |
| 50 | .flags = CI13XXX_REGS_SHARED | |
| 51 | CI13XXX_REQUIRE_TRANSCEIVER | |
| 52 | CI13XXX_PULLUP_ON_VBUS | |
| 53 | CI13XXX_DISABLE_STREAMING, |
| 54 | |
| 55 | .notify_event = ci13xxx_msm_notify_event, |
| 56 | }; |
| 57 | |
Felipe Balbi | 17d2fcc | 2012-06-29 17:48:51 +0800 | [diff] [blame] | 58 | static int __devinit ci13xxx_msm_probe(struct platform_device *pdev) |
Pavankumar Kondeti | 33f82f38 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 59 | { |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame] | 60 | struct platform_device *plat_ci; |
Pavankumar Kondeti | 33f82f38 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 61 | int ret; |
| 62 | |
| 63 | dev_dbg(&pdev->dev, "ci13xxx_msm_probe\n"); |
| 64 | |
Alexander Shishkin | 5f36e23 | 2012-05-11 17:25:47 +0300 | [diff] [blame] | 65 | plat_ci = platform_device_alloc("ci_hdrc", -1); |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame] | 66 | if (!plat_ci) { |
Alexander Shishkin | 5f36e23 | 2012-05-11 17:25:47 +0300 | [diff] [blame] | 67 | dev_err(&pdev->dev, "can't allocate ci_hdrc platform device\n"); |
Pavankumar Kondeti | 33f82f38 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 68 | return -ENOMEM; |
| 69 | } |
| 70 | |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame] | 71 | ret = platform_device_add_resources(plat_ci, pdev->resource, |
| 72 | pdev->num_resources); |
| 73 | if (ret) { |
| 74 | dev_err(&pdev->dev, "can't add resources to platform device\n"); |
| 75 | goto put_platform; |
Pavankumar Kondeti | 33f82f38 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 76 | } |
| 77 | |
Richard Zhao | 77c4400 | 2012-06-29 17:48:53 +0800 | [diff] [blame^] | 78 | ret = platform_device_add_data(plat_ci, &ci13xxx_msm_platdata, |
| 79 | sizeof(ci13xxx_msm_platdata)); |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame] | 80 | if (ret) |
| 81 | goto put_platform; |
Pavankumar Kondeti | 33f82f38 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 82 | |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame] | 83 | ret = platform_device_add(plat_ci); |
| 84 | if (ret) |
| 85 | goto put_platform; |
Pavankumar Kondeti | 33f82f38 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 86 | |
Felipe Balbi | 6bf8359 | 2012-06-29 17:48:52 +0800 | [diff] [blame] | 87 | platform_set_drvdata(pdev, plat_ci); |
| 88 | |
Pavankumar Kondeti | 2d0cdcc | 2010-12-07 17:54:05 +0530 | [diff] [blame] | 89 | pm_runtime_no_callbacks(&pdev->dev); |
| 90 | pm_runtime_enable(&pdev->dev); |
| 91 | |
Pavankumar Kondeti | 33f82f38 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 92 | return 0; |
| 93 | |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame] | 94 | put_platform: |
| 95 | platform_device_put(plat_ci); |
Pavankumar Kondeti | 33f82f38 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 96 | |
| 97 | return ret; |
| 98 | } |
| 99 | |
Felipe Balbi | 6bf8359 | 2012-06-29 17:48:52 +0800 | [diff] [blame] | 100 | static int __devexit ci13xxx_msm_remove(struct platform_device *pdev) |
| 101 | { |
| 102 | struct platform_device *plat_ci = platform_get_drvdata(pdev); |
| 103 | |
| 104 | pm_runtime_disable(&pdev->dev); |
| 105 | platform_device_unregister(plat_ci); |
| 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | |
Pavankumar Kondeti | 33f82f38 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 110 | static struct platform_driver ci13xxx_msm_driver = { |
| 111 | .probe = ci13xxx_msm_probe, |
Felipe Balbi | 6bf8359 | 2012-06-29 17:48:52 +0800 | [diff] [blame] | 112 | .remove = __devexit_p(ci13xxx_msm_remove), |
Pavankumar Kondeti | 33f82f38 | 2010-12-07 17:54:03 +0530 | [diff] [blame] | 113 | .driver = { .name = "msm_hsusb", }, |
| 114 | }; |
Felipe Balbi | 6bf8359 | 2012-06-29 17:48:52 +0800 | [diff] [blame] | 115 | |
| 116 | module_platform_driver(ci13xxx_msm_driver); |
| 117 | |
Sebastian Andrzej Siewior | 86081d7 | 2011-06-29 16:41:55 +0300 | [diff] [blame] | 118 | MODULE_ALIAS("platform:msm_hsusb"); |
Marc Kleine-Budde | 4703d2e | 2011-10-10 18:38:11 +0200 | [diff] [blame] | 119 | MODULE_LICENSE("GPL v2"); |