Commit | Line | Data |
---|---|---|
33f82f38 PK |
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. | |
33f82f38 PK |
6 | */ |
7 | ||
8 | #include <linux/module.h> | |
9 | #include <linux/platform_device.h> | |
2d0cdcc5 | 10 | #include <linux/pm_runtime.h> |
33f82f38 PK |
11 | #include <linux/usb/msm_hsusb_hw.h> |
12 | #include <linux/usb/ulpi.h> | |
62bb84ed | 13 | #include <linux/usb/gadget.h> |
e443b333 | 14 | #include <linux/usb/chipidea.h> |
33f82f38 | 15 | |
e443b333 | 16 | #include "ci.h" |
33f82f38 | 17 | |
26c696c6 | 18 | #define MSM_USB_BASE (ci->hw_bank.abs) |
33f82f38 | 19 | |
8e22978c | 20 | static void ci_hdrc_msm_notify_event(struct ci_hdrc *ci, unsigned event) |
33f82f38 | 21 | { |
26c696c6 | 22 | struct device *dev = ci->gadget.dev.parent; |
33f82f38 PK |
23 | int val; |
24 | ||
25 | switch (event) { | |
8e22978c AS |
26 | case CI_HDRC_CONTROLLER_RESET_EVENT: |
27 | dev_dbg(dev, "CI_HDRC_CONTROLLER_RESET_EVENT received\n"); | |
33f82f38 PK |
28 | writel(0, USB_AHBBURST); |
29 | writel(0, USB_AHBMODE); | |
30 | break; | |
8e22978c AS |
31 | case CI_HDRC_CONTROLLER_STOPPED_EVENT: |
32 | dev_dbg(dev, "CI_HDRC_CONTROLLER_STOPPED_EVENT received\n"); | |
33f82f38 PK |
33 | /* |
34 | * Put the transceiver in non-driving mode. Otherwise host | |
35 | * may not detect soft-disconnection. | |
36 | */ | |
26c696c6 | 37 | val = usb_phy_io_read(ci->transceiver, ULPI_FUNC_CTRL); |
33f82f38 PK |
38 | val &= ~ULPI_FUNC_CTRL_OPMODE_MASK; |
39 | val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING; | |
26c696c6 | 40 | usb_phy_io_write(ci->transceiver, val, ULPI_FUNC_CTRL); |
33f82f38 PK |
41 | break; |
42 | default: | |
8e22978c | 43 | dev_dbg(dev, "unknown ci_hdrc event\n"); |
33f82f38 PK |
44 | break; |
45 | } | |
46 | } | |
47 | ||
8e22978c AS |
48 | static struct ci_hdrc_platform_data ci_hdrc_msm_platdata = { |
49 | .name = "ci_hdrc_msm", | |
3c6d9826 | 50 | .capoffset = DEF_CAPOFFSET, |
8e22978c AS |
51 | .flags = CI_HDRC_REGS_SHARED | |
52 | CI_HDRC_REQUIRE_TRANSCEIVER | | |
8e22978c | 53 | CI_HDRC_DISABLE_STREAMING, |
33f82f38 | 54 | |
8e22978c | 55 | .notify_event = ci_hdrc_msm_notify_event, |
33f82f38 PK |
56 | }; |
57 | ||
8e22978c | 58 | static int ci_hdrc_msm_probe(struct platform_device *pdev) |
33f82f38 | 59 | { |
62bb84ed | 60 | struct platform_device *plat_ci; |
2629b101 | 61 | struct usb_phy *phy; |
33f82f38 | 62 | |
8e22978c | 63 | dev_dbg(&pdev->dev, "ci_hdrc_msm_probe\n"); |
33f82f38 | 64 | |
2629b101 II |
65 | /* |
66 | * OTG(PHY) driver takes care of PHY initialization, clock management, | |
67 | * powering up VBUS, mapping of registers address space and power | |
68 | * management. | |
69 | */ | |
70 | phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0); | |
71 | if (IS_ERR(phy)) | |
72 | return PTR_ERR(phy); | |
73 | ||
74 | ci_hdrc_msm_platdata.phy = phy; | |
75 | ||
8e22978c | 76 | plat_ci = ci_hdrc_add_device(&pdev->dev, |
cbc6dc2a | 77 | pdev->resource, pdev->num_resources, |
8e22978c | 78 | &ci_hdrc_msm_platdata); |
cbc6dc2a | 79 | if (IS_ERR(plat_ci)) { |
8e22978c | 80 | dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n"); |
cbc6dc2a | 81 | return PTR_ERR(plat_ci); |
33f82f38 PK |
82 | } |
83 | ||
6bf83594 FB |
84 | platform_set_drvdata(pdev, plat_ci); |
85 | ||
2d0cdcc5 PK |
86 | pm_runtime_no_callbacks(&pdev->dev); |
87 | pm_runtime_enable(&pdev->dev); | |
88 | ||
33f82f38 | 89 | return 0; |
33f82f38 PK |
90 | } |
91 | ||
8e22978c | 92 | static int ci_hdrc_msm_remove(struct platform_device *pdev) |
6bf83594 FB |
93 | { |
94 | struct platform_device *plat_ci = platform_get_drvdata(pdev); | |
95 | ||
96 | pm_runtime_disable(&pdev->dev); | |
8e22978c | 97 | ci_hdrc_remove_device(plat_ci); |
6bf83594 FB |
98 | |
99 | return 0; | |
100 | } | |
101 | ||
2629b101 II |
102 | static const struct of_device_id msm_ci_dt_match[] = { |
103 | { .compatible = "qcom,ci-hdrc", }, | |
104 | { } | |
105 | }; | |
106 | MODULE_DEVICE_TABLE(of, msm_ci_dt_match); | |
107 | ||
8e22978c AS |
108 | static struct platform_driver ci_hdrc_msm_driver = { |
109 | .probe = ci_hdrc_msm_probe, | |
110 | .remove = ci_hdrc_msm_remove, | |
2629b101 II |
111 | .driver = { |
112 | .name = "msm_hsusb", | |
113 | .of_match_table = msm_ci_dt_match, | |
114 | }, | |
33f82f38 PK |
115 | }; |
116 | ||
8e22978c | 117 | module_platform_driver(ci_hdrc_msm_driver); |
4703d2e9 | 118 | |
6bf83594 | 119 | MODULE_ALIAS("platform:msm_hsusb"); |
8e22978c | 120 | MODULE_ALIAS("platform:ci13xxx_msm"); |
4703d2e9 | 121 | MODULE_LICENSE("GPL v2"); |