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 | |
24 | switch (event) { | |
8e22978c AS |
25 | case CI_HDRC_CONTROLLER_RESET_EVENT: |
26 | dev_dbg(dev, "CI_HDRC_CONTROLLER_RESET_EVENT received\n"); | |
33f82f38 PK |
27 | writel(0, USB_AHBBURST); |
28 | writel(0, USB_AHBMODE); | |
ef44cb42 | 29 | usb_phy_init(ci->usb_phy); |
33f82f38 | 30 | break; |
8e22978c AS |
31 | case CI_HDRC_CONTROLLER_STOPPED_EVENT: |
32 | dev_dbg(dev, "CI_HDRC_CONTROLLER_STOPPED_EVENT received\n"); | |
33f82f38 | 33 | /* |
ef44cb42 | 34 | * Put the phy in non-driving mode. Otherwise host |
33f82f38 PK |
35 | * may not detect soft-disconnection. |
36 | */ | |
ef44cb42 | 37 | usb_phy_notify_disconnect(ci->usb_phy, USB_SPEED_UNKNOWN); |
33f82f38 PK |
38 | break; |
39 | default: | |
8e22978c | 40 | dev_dbg(dev, "unknown ci_hdrc event\n"); |
33f82f38 PK |
41 | break; |
42 | } | |
43 | } | |
44 | ||
8e22978c AS |
45 | static struct ci_hdrc_platform_data ci_hdrc_msm_platdata = { |
46 | .name = "ci_hdrc_msm", | |
3c6d9826 | 47 | .capoffset = DEF_CAPOFFSET, |
8e22978c | 48 | .flags = CI_HDRC_REGS_SHARED | |
8e22978c | 49 | CI_HDRC_DISABLE_STREAMING, |
33f82f38 | 50 | |
8e22978c | 51 | .notify_event = ci_hdrc_msm_notify_event, |
33f82f38 PK |
52 | }; |
53 | ||
8e22978c | 54 | static int ci_hdrc_msm_probe(struct platform_device *pdev) |
33f82f38 | 55 | { |
62bb84ed | 56 | struct platform_device *plat_ci; |
2629b101 | 57 | struct usb_phy *phy; |
33f82f38 | 58 | |
8e22978c | 59 | dev_dbg(&pdev->dev, "ci_hdrc_msm_probe\n"); |
33f82f38 | 60 | |
2629b101 II |
61 | /* |
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 | ||
ef44cb42 | 70 | ci_hdrc_msm_platdata.usb_phy = phy; |
2629b101 | 71 | |
8e22978c | 72 | plat_ci = ci_hdrc_add_device(&pdev->dev, |
cbc6dc2a | 73 | pdev->resource, pdev->num_resources, |
8e22978c | 74 | &ci_hdrc_msm_platdata); |
cbc6dc2a | 75 | if (IS_ERR(plat_ci)) { |
8e22978c | 76 | dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n"); |
cbc6dc2a | 77 | return PTR_ERR(plat_ci); |
33f82f38 PK |
78 | } |
79 | ||
6bf83594 FB |
80 | platform_set_drvdata(pdev, plat_ci); |
81 | ||
2d0cdcc5 PK |
82 | pm_runtime_no_callbacks(&pdev->dev); |
83 | pm_runtime_enable(&pdev->dev); | |
84 | ||
33f82f38 | 85 | return 0; |
33f82f38 PK |
86 | } |
87 | ||
8e22978c | 88 | static int ci_hdrc_msm_remove(struct platform_device *pdev) |
6bf83594 FB |
89 | { |
90 | struct platform_device *plat_ci = platform_get_drvdata(pdev); | |
91 | ||
92 | pm_runtime_disable(&pdev->dev); | |
8e22978c | 93 | ci_hdrc_remove_device(plat_ci); |
6bf83594 FB |
94 | |
95 | return 0; | |
96 | } | |
97 | ||
2629b101 II |
98 | static const struct of_device_id msm_ci_dt_match[] = { |
99 | { .compatible = "qcom,ci-hdrc", }, | |
100 | { } | |
101 | }; | |
102 | MODULE_DEVICE_TABLE(of, msm_ci_dt_match); | |
103 | ||
8e22978c AS |
104 | static struct platform_driver ci_hdrc_msm_driver = { |
105 | .probe = ci_hdrc_msm_probe, | |
106 | .remove = ci_hdrc_msm_remove, | |
2629b101 II |
107 | .driver = { |
108 | .name = "msm_hsusb", | |
109 | .of_match_table = msm_ci_dt_match, | |
110 | }, | |
33f82f38 PK |
111 | }; |
112 | ||
8e22978c | 113 | module_platform_driver(ci_hdrc_msm_driver); |
4703d2e9 | 114 | |
6bf83594 | 115 | MODULE_ALIAS("platform:msm_hsusb"); |
8e22978c | 116 | MODULE_ALIAS("platform:ci13xxx_msm"); |
4703d2e9 | 117 | MODULE_LICENSE("GPL v2"); |