blob: 30bdd51a6d77004b65420a13fc3c3be043803044 [file] [log] [blame]
Alexander Shishkin8e229782013-06-24 14:46:36 +03001/* 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
20static void ci_hdrc_msm_notify_event(struct ci_hdrc *ci, unsigned event)
21{
22 struct device *dev = ci->gadget.dev.parent;
Alexander Shishkin8e229782013-06-24 14:46:36 +030023
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);
28 writel(0, USB_AHBMODE);
29 break;
30 case CI_HDRC_CONTROLLER_STOPPED_EVENT:
31 dev_dbg(dev, "CI_HDRC_CONTROLLER_STOPPED_EVENT received\n");
32 /*
33 * Put the transceiver in non-driving mode. Otherwise host
34 * may not detect soft-disconnection.
35 */
Ivan T. Ivanovea290052014-09-11 08:18:59 +080036 usb_phy_notify_disconnect(ci->transceiver, USB_SPEED_UNKNOWN);
Alexander Shishkin8e229782013-06-24 14:46:36 +030037 break;
38 default:
39 dev_dbg(dev, "unknown ci_hdrc event\n");
40 break;
41 }
42}
43
44static struct ci_hdrc_platform_data ci_hdrc_msm_platdata = {
45 .name = "ci_hdrc_msm",
Ivan T. Ivanov3c6d9822014-05-04 09:24:42 +080046 .capoffset = DEF_CAPOFFSET,
Alexander Shishkin8e229782013-06-24 14:46:36 +030047 .flags = CI_HDRC_REGS_SHARED |
48 CI_HDRC_REQUIRE_TRANSCEIVER |
Alexander Shishkin8e229782013-06-24 14:46:36 +030049 CI_HDRC_DISABLE_STREAMING,
50
51 .notify_event = ci_hdrc_msm_notify_event,
52};
53
54static int ci_hdrc_msm_probe(struct platform_device *pdev)
55{
56 struct platform_device *plat_ci;
Ivan T. Ivanov2629b102014-05-04 09:24:41 +080057 struct usb_phy *phy;
Alexander Shishkin8e229782013-06-24 14:46:36 +030058
59 dev_dbg(&pdev->dev, "ci_hdrc_msm_probe\n");
60
Ivan T. Ivanov2629b102014-05-04 09:24:41 +080061 /*
62 * OTG(PHY) driver takes care of PHY initialization, clock management,
63 * powering up VBUS, mapping of registers address space and power
64 * management.
65 */
66 phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0);
67 if (IS_ERR(phy))
68 return PTR_ERR(phy);
69
70 ci_hdrc_msm_platdata.phy = phy;
71
Alexander Shishkin8e229782013-06-24 14:46:36 +030072 plat_ci = ci_hdrc_add_device(&pdev->dev,
73 pdev->resource, pdev->num_resources,
74 &ci_hdrc_msm_platdata);
75 if (IS_ERR(plat_ci)) {
76 dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n");
77 return PTR_ERR(plat_ci);
78 }
79
80 platform_set_drvdata(pdev, plat_ci);
81
82 pm_runtime_no_callbacks(&pdev->dev);
83 pm_runtime_enable(&pdev->dev);
84
85 return 0;
86}
87
88static int ci_hdrc_msm_remove(struct platform_device *pdev)
89{
90 struct platform_device *plat_ci = platform_get_drvdata(pdev);
91
92 pm_runtime_disable(&pdev->dev);
93 ci_hdrc_remove_device(plat_ci);
94
95 return 0;
96}
97
Ivan T. Ivanov2629b102014-05-04 09:24:41 +080098static const struct of_device_id msm_ci_dt_match[] = {
99 { .compatible = "qcom,ci-hdrc", },
100 { }
101};
102MODULE_DEVICE_TABLE(of, msm_ci_dt_match);
103
Alexander Shishkin8e229782013-06-24 14:46:36 +0300104static struct platform_driver ci_hdrc_msm_driver = {
105 .probe = ci_hdrc_msm_probe,
106 .remove = ci_hdrc_msm_remove,
Ivan T. Ivanov2629b102014-05-04 09:24:41 +0800107 .driver = {
108 .name = "msm_hsusb",
109 .of_match_table = msm_ci_dt_match,
110 },
Alexander Shishkin8e229782013-06-24 14:46:36 +0300111};
112
113module_platform_driver(ci_hdrc_msm_driver);
114
115MODULE_ALIAS("platform:msm_hsusb");
116MODULE_ALIAS("platform:ci13xxx_msm");
117MODULE_LICENSE("GPL v2");