Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [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. |
| 6 | */ |
| 7 | |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/platform_device.h> |
| 10 | #include <linux/pm_runtime.h> |
| 11 | #include <linux/usb/msm_hsusb_hw.h> |
| 12 | #include <linux/usb/ulpi.h> |
| 13 | #include <linux/usb/gadget.h> |
| 14 | #include <linux/usb/chipidea.h> |
| 15 | |
| 16 | #include "ci.h" |
| 17 | |
| 18 | #define MSM_USB_BASE (ci->hw_bank.abs) |
| 19 | |
| 20 | static void ci_hdrc_msm_notify_event(struct ci_hdrc *ci, unsigned event) |
| 21 | { |
| 22 | struct device *dev = ci->gadget.dev.parent; |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 23 | |
| 24 | switch (event) { |
| 25 | case CI_HDRC_CONTROLLER_RESET_EVENT: |
| 26 | dev_dbg(dev, "CI_HDRC_CONTROLLER_RESET_EVENT received\n"); |
| 27 | writel(0, USB_AHBBURST); |
Andy Gross | 5ce7d27 | 2015-11-06 00:04:06 -0600 | [diff] [blame] | 28 | /* use AHB transactor, allow posted data writes */ |
| 29 | writel(0x8, USB_AHBMODE); |
Antoine Tenart | ef44cb4 | 2014-10-30 18:41:16 +0100 | [diff] [blame] | 30 | usb_phy_init(ci->usb_phy); |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 31 | break; |
| 32 | case CI_HDRC_CONTROLLER_STOPPED_EVENT: |
| 33 | dev_dbg(dev, "CI_HDRC_CONTROLLER_STOPPED_EVENT received\n"); |
| 34 | /* |
Antoine Tenart | ef44cb4 | 2014-10-30 18:41:16 +0100 | [diff] [blame] | 35 | * Put the phy in non-driving mode. Otherwise host |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 36 | * may not detect soft-disconnection. |
| 37 | */ |
Antoine Tenart | ef44cb4 | 2014-10-30 18:41:16 +0100 | [diff] [blame] | 38 | usb_phy_notify_disconnect(ci->usb_phy, USB_SPEED_UNKNOWN); |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 39 | break; |
| 40 | default: |
| 41 | dev_dbg(dev, "unknown ci_hdrc event\n"); |
| 42 | break; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | static struct ci_hdrc_platform_data ci_hdrc_msm_platdata = { |
| 47 | .name = "ci_hdrc_msm", |
Ivan T. Ivanov | 3c6d982 | 2014-05-04 09:24:42 +0800 | [diff] [blame] | 48 | .capoffset = DEF_CAPOFFSET, |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 49 | .flags = CI_HDRC_REGS_SHARED | |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 50 | CI_HDRC_DISABLE_STREAMING, |
| 51 | |
| 52 | .notify_event = ci_hdrc_msm_notify_event, |
| 53 | }; |
| 54 | |
| 55 | static int ci_hdrc_msm_probe(struct platform_device *pdev) |
| 56 | { |
| 57 | struct platform_device *plat_ci; |
Ivan T. Ivanov | 2629b10 | 2014-05-04 09:24:41 +0800 | [diff] [blame] | 58 | struct usb_phy *phy; |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 59 | |
| 60 | dev_dbg(&pdev->dev, "ci_hdrc_msm_probe\n"); |
| 61 | |
Ivan T. Ivanov | 2629b10 | 2014-05-04 09:24:41 +0800 | [diff] [blame] | 62 | /* |
| 63 | * OTG(PHY) driver takes care of PHY initialization, clock management, |
| 64 | * powering up VBUS, mapping of registers address space and power |
| 65 | * management. |
| 66 | */ |
| 67 | phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0); |
| 68 | if (IS_ERR(phy)) |
| 69 | return PTR_ERR(phy); |
| 70 | |
Antoine Tenart | ef44cb4 | 2014-10-30 18:41:16 +0100 | [diff] [blame] | 71 | ci_hdrc_msm_platdata.usb_phy = phy; |
Ivan T. Ivanov | 2629b10 | 2014-05-04 09:24:41 +0800 | [diff] [blame] | 72 | |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 73 | plat_ci = ci_hdrc_add_device(&pdev->dev, |
| 74 | pdev->resource, pdev->num_resources, |
| 75 | &ci_hdrc_msm_platdata); |
| 76 | if (IS_ERR(plat_ci)) { |
| 77 | dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n"); |
| 78 | return PTR_ERR(plat_ci); |
| 79 | } |
| 80 | |
| 81 | platform_set_drvdata(pdev, plat_ci); |
| 82 | |
| 83 | pm_runtime_no_callbacks(&pdev->dev); |
| 84 | pm_runtime_enable(&pdev->dev); |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | static int ci_hdrc_msm_remove(struct platform_device *pdev) |
| 90 | { |
| 91 | struct platform_device *plat_ci = platform_get_drvdata(pdev); |
| 92 | |
| 93 | pm_runtime_disable(&pdev->dev); |
| 94 | ci_hdrc_remove_device(plat_ci); |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
Ivan T. Ivanov | 2629b10 | 2014-05-04 09:24:41 +0800 | [diff] [blame] | 99 | static const struct of_device_id msm_ci_dt_match[] = { |
| 100 | { .compatible = "qcom,ci-hdrc", }, |
| 101 | { } |
| 102 | }; |
| 103 | MODULE_DEVICE_TABLE(of, msm_ci_dt_match); |
| 104 | |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 105 | static struct platform_driver ci_hdrc_msm_driver = { |
| 106 | .probe = ci_hdrc_msm_probe, |
| 107 | .remove = ci_hdrc_msm_remove, |
Ivan T. Ivanov | 2629b10 | 2014-05-04 09:24:41 +0800 | [diff] [blame] | 108 | .driver = { |
| 109 | .name = "msm_hsusb", |
| 110 | .of_match_table = msm_ci_dt_match, |
| 111 | }, |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | module_platform_driver(ci_hdrc_msm_driver); |
| 115 | |
| 116 | MODULE_ALIAS("platform:msm_hsusb"); |
| 117 | MODULE_ALIAS("platform:ci13xxx_msm"); |
| 118 | MODULE_LICENSE("GPL v2"); |