1 /* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
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.
8 #include <linux/module.h>
9 #include <linux/platform_device.h>
10 #include <linux/pm_runtime.h>
11 #include <linux/usb/gadget.h>
12 #include <linux/usb/chipidea.h>
13 #include <linux/clk.h>
14 #include <linux/reset.h>
18 #define HS_PHY_AHB_MODE 0x0098
21 struct platform_device *ci;
23 struct clk *iface_clk;
27 static void ci_hdrc_msm_notify_event(struct ci_hdrc *ci, unsigned event)
29 struct device *dev = ci->gadget.dev.parent;
32 case CI_HDRC_CONTROLLER_RESET_EVENT:
33 dev_dbg(dev, "CI_HDRC_CONTROLLER_RESET_EVENT received\n");
34 /* use AHB transactor, allow posted data writes */
35 hw_write_id_reg(ci, HS_PHY_AHB_MODE, 0xffffffff, 0x8);
36 usb_phy_init(ci->usb_phy);
38 case CI_HDRC_CONTROLLER_STOPPED_EVENT:
39 dev_dbg(dev, "CI_HDRC_CONTROLLER_STOPPED_EVENT received\n");
41 * Put the phy in non-driving mode. Otherwise host
42 * may not detect soft-disconnection.
44 usb_phy_notify_disconnect(ci->usb_phy, USB_SPEED_UNKNOWN);
47 dev_dbg(dev, "unknown ci_hdrc event\n");
52 static struct ci_hdrc_platform_data ci_hdrc_msm_platdata = {
53 .name = "ci_hdrc_msm",
54 .capoffset = DEF_CAPOFFSET,
55 .flags = CI_HDRC_REGS_SHARED |
56 CI_HDRC_DISABLE_STREAMING |
57 CI_HDRC_OVERRIDE_AHB_BURST,
59 .notify_event = ci_hdrc_msm_notify_event,
62 static int ci_hdrc_msm_probe(struct platform_device *pdev)
64 struct ci_hdrc_msm *ci;
65 struct platform_device *plat_ci;
68 struct reset_control *reset;
71 dev_dbg(&pdev->dev, "ci_hdrc_msm_probe\n");
73 ci = devm_kzalloc(&pdev->dev, sizeof(*ci), GFP_KERNEL);
76 platform_set_drvdata(pdev, ci);
79 * OTG(PHY) driver takes care of PHY initialization, clock management,
80 * powering up VBUS, mapping of registers address space and power
83 phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0);
87 ci_hdrc_msm_platdata.usb_phy = phy;
89 reset = devm_reset_control_get(&pdev->dev, "core");
91 return PTR_ERR(reset);
93 ci->core_clk = clk = devm_clk_get(&pdev->dev, "core");
97 ci->iface_clk = clk = devm_clk_get(&pdev->dev, "iface");
101 ci->fs_clk = clk = devm_clk_get(&pdev->dev, "fs");
103 if (PTR_ERR(clk) == -EPROBE_DEFER)
104 return -EPROBE_DEFER;
108 ret = clk_prepare_enable(ci->fs_clk);
112 reset_control_assert(reset);
113 usleep_range(10000, 12000);
114 reset_control_deassert(reset);
116 clk_disable_unprepare(ci->fs_clk);
118 ret = clk_prepare_enable(ci->core_clk);
122 ret = clk_prepare_enable(ci->iface_clk);
126 plat_ci = ci_hdrc_add_device(&pdev->dev,
127 pdev->resource, pdev->num_resources,
128 &ci_hdrc_msm_platdata);
129 if (IS_ERR(plat_ci)) {
130 dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n");
131 ret = PTR_ERR(plat_ci);
137 pm_runtime_set_active(&pdev->dev);
138 pm_runtime_no_callbacks(&pdev->dev);
139 pm_runtime_enable(&pdev->dev);
144 clk_disable_unprepare(ci->iface_clk);
146 clk_disable_unprepare(ci->core_clk);
150 static int ci_hdrc_msm_remove(struct platform_device *pdev)
152 struct ci_hdrc_msm *ci = platform_get_drvdata(pdev);
154 pm_runtime_disable(&pdev->dev);
155 ci_hdrc_remove_device(ci->ci);
156 clk_disable_unprepare(ci->iface_clk);
157 clk_disable_unprepare(ci->core_clk);
162 static const struct of_device_id msm_ci_dt_match[] = {
163 { .compatible = "qcom,ci-hdrc", },
166 MODULE_DEVICE_TABLE(of, msm_ci_dt_match);
168 static struct platform_driver ci_hdrc_msm_driver = {
169 .probe = ci_hdrc_msm_probe,
170 .remove = ci_hdrc_msm_remove,
173 .of_match_table = msm_ci_dt_match,
177 module_platform_driver(ci_hdrc_msm_driver);
179 MODULE_ALIAS("platform:msm_hsusb");
180 MODULE_ALIAS("platform:ci13xxx_msm");
181 MODULE_LICENSE("GPL v2");