2 * Copyright 2012 Freescale Semiconductor, Inc.
3 * Copyright (C) 2012 Marek Vasut <marex@denx.de>
4 * on behalf of DENX Software Engineering GmbH
6 * The code contained herein is licensed under the GNU General Public
7 * License. You may obtain a copy of the GNU General Public License
8 * Version 2 or later at the following locations:
10 * http://www.opensource.org/licenses/gpl-license.html
11 * http://www.gnu.org/copyleft/gpl.html
14 #include <linux/module.h>
15 #include <linux/of_platform.h>
16 #include <linux/of_gpio.h>
17 #include <linux/platform_device.h>
18 #include <linux/pm_runtime.h>
19 #include <linux/dma-mapping.h>
20 #include <linux/usb/chipidea.h>
21 #include <linux/clk.h>
22 #include <linux/regulator/consumer.h>
26 #define pdev_to_phy(pdev) \
27 ((struct usb_phy *)platform_get_drvdata(pdev))
29 struct ci13xxx_imx_data {
30 struct device_node *phy_np;
32 struct platform_device *ci_pdev;
34 struct regulator *reg_vbus;
37 static struct ci13xxx_platform_data ci13xxx_imx_platdata __devinitdata = {
38 .name = "ci13xxx_imx",
39 .flags = CI13XXX_REQUIRE_TRANSCEIVER |
40 CI13XXX_PULLUP_ON_VBUS |
41 CI13XXX_DISABLE_STREAMING,
42 .capoffset = DEF_CAPOFFSET,
45 static int __devinit ci13xxx_imx_probe(struct platform_device *pdev)
47 struct ci13xxx_imx_data *data;
48 struct platform_device *plat_ci, *phy_pdev;
49 struct device_node *phy_np;
51 struct regulator *reg_vbus;
54 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
56 dev_err(&pdev->dev, "Failed to allocate CI13xxx-IMX data!\n");
60 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
62 dev_err(&pdev->dev, "Can't get device resources!\n");
66 data->clk = devm_clk_get(&pdev->dev, NULL);
67 if (IS_ERR(data->clk)) {
69 "Failed to get clock, err=%ld\n", PTR_ERR(data->clk));
70 return PTR_ERR(data->clk);
73 ret = clk_prepare_enable(data->clk);
76 "Failed to prepare or enable clock, err=%d\n", ret);
80 phy_np = of_parse_phandle(pdev->dev.of_node, "fsl,usbphy", 0);
82 data->phy_np = phy_np;
83 phy_pdev = of_find_device_by_node(phy_np);
86 phy = pdev_to_phy(phy_pdev);
88 try_module_get(phy_pdev->dev.driver->owner)) {
95 /* we only support host now, so enable vbus here */
96 reg_vbus = devm_regulator_get(&pdev->dev, "vbus");
97 if (!IS_ERR(reg_vbus)) {
98 ret = regulator_enable(reg_vbus);
101 "Failed to enable vbus regulator, err=%d\n",
105 data->reg_vbus = reg_vbus;
110 ci13xxx_imx_platdata.phy = data->phy;
112 if (!pdev->dev.dma_mask) {
113 pdev->dev.dma_mask = devm_kzalloc(&pdev->dev,
114 sizeof(*pdev->dev.dma_mask), GFP_KERNEL);
115 if (!pdev->dev.dma_mask) {
117 dev_err(&pdev->dev, "Failed to alloc dma_mask!\n");
120 *pdev->dev.dma_mask = DMA_BIT_MASK(32);
121 dma_set_coherent_mask(&pdev->dev, *pdev->dev.dma_mask);
123 plat_ci = ci13xxx_add_device(&pdev->dev,
124 pdev->resource, pdev->num_resources,
125 &ci13xxx_imx_platdata);
126 if (IS_ERR(plat_ci)) {
127 ret = PTR_ERR(plat_ci);
129 "Can't register ci_hdrc platform device, err=%d\n",
134 data->ci_pdev = plat_ci;
135 platform_set_drvdata(pdev, data);
137 pm_runtime_no_callbacks(&pdev->dev);
138 pm_runtime_enable(&pdev->dev);
144 regulator_disable(reg_vbus);
148 clk_disable_unprepare(data->clk);
152 static int __devexit ci13xxx_imx_remove(struct platform_device *pdev)
154 struct ci13xxx_imx_data *data = platform_get_drvdata(pdev);
156 pm_runtime_disable(&pdev->dev);
157 ci13xxx_remove_device(data->ci_pdev);
160 regulator_disable(data->reg_vbus);
163 usb_phy_shutdown(data->phy);
164 module_put(data->phy->dev->driver->owner);
167 of_node_put(data->phy_np);
169 clk_disable_unprepare(data->clk);
171 platform_set_drvdata(pdev, NULL);
176 static const struct of_device_id ci13xxx_imx_dt_ids[] = {
177 { .compatible = "fsl,imx27-usb", },
180 MODULE_DEVICE_TABLE(of, ci13xxx_imx_dt_ids);
182 static struct platform_driver ci13xxx_imx_driver = {
183 .probe = ci13xxx_imx_probe,
184 .remove = __devexit_p(ci13xxx_imx_remove),
187 .owner = THIS_MODULE,
188 .of_match_table = ci13xxx_imx_dt_ids,
192 module_platform_driver(ci13xxx_imx_driver);
194 MODULE_ALIAS("platform:imx-usb");
195 MODULE_LICENSE("GPL v2");
196 MODULE_DESCRIPTION("CI13xxx i.MX USB binding");
197 MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
198 MODULE_AUTHOR("Richard Zhao <richard.zhao@freescale.com>");