2 * Copyright (C) 2014 Marvell Technology Group Ltd.
4 * Antoine Tenart <antoine.tenart@free-electrons.com>
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
11 #include <linux/clk.h>
12 #include <linux/dma-mapping.h>
13 #include <linux/module.h>
15 #include <linux/phy/phy.h>
16 #include <linux/platform_device.h>
17 #include <linux/usb/chipidea.h>
18 #include <linux/usb/hcd.h>
19 #include <linux/usb/ulpi.h>
23 struct ci_hdrc_usb2_priv {
24 struct platform_device *ci_pdev;
28 static const struct ci_hdrc_platform_data ci_default_pdata = {
29 .capoffset = DEF_CAPOFFSET,
30 .flags = CI_HDRC_DISABLE_STREAMING,
33 static int ci_hdrc_usb2_probe(struct platform_device *pdev)
35 struct device *dev = &pdev->dev;
36 struct ci_hdrc_usb2_priv *priv;
37 struct ci_hdrc_platform_data *ci_pdata = dev_get_platdata(dev);
41 ci_pdata = devm_kmalloc(dev, sizeof(*ci_pdata), GFP_KERNEL);
42 *ci_pdata = ci_default_pdata; /* struct copy */
45 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
49 priv->clk = devm_clk_get(dev, NULL);
50 if (!IS_ERR(priv->clk)) {
51 ret = clk_prepare_enable(priv->clk);
53 dev_err(dev, "failed to enable the clock: %d\n", ret);
58 ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
62 ci_pdata->name = dev_name(dev);
64 priv->ci_pdev = ci_hdrc_add_device(dev, pdev->resource,
65 pdev->num_resources, ci_pdata);
66 if (IS_ERR(priv->ci_pdev)) {
67 ret = PTR_ERR(priv->ci_pdev);
68 if (ret != -EPROBE_DEFER)
70 "failed to register ci_hdrc platform device: %d\n",
75 platform_set_drvdata(pdev, priv);
77 pm_runtime_no_callbacks(dev);
78 pm_runtime_enable(dev);
83 if (!IS_ERR(priv->clk))
84 clk_disable_unprepare(priv->clk);
88 static int ci_hdrc_usb2_remove(struct platform_device *pdev)
90 struct ci_hdrc_usb2_priv *priv = platform_get_drvdata(pdev);
92 pm_runtime_disable(&pdev->dev);
93 ci_hdrc_remove_device(priv->ci_pdev);
94 clk_disable_unprepare(priv->clk);
99 static const struct of_device_id ci_hdrc_usb2_of_match[] = {
100 { .compatible = "chipidea,usb2" },
103 MODULE_DEVICE_TABLE(of, ci_hdrc_usb2_of_match);
105 static struct platform_driver ci_hdrc_usb2_driver = {
106 .probe = ci_hdrc_usb2_probe,
107 .remove = ci_hdrc_usb2_remove,
109 .name = "chipidea-usb2",
110 .of_match_table = of_match_ptr(ci_hdrc_usb2_of_match),
113 module_platform_driver(ci_hdrc_usb2_driver);
115 MODULE_DESCRIPTION("ChipIdea HDRC USB2 binding for ci13xxx");
116 MODULE_AUTHOR("Antoine Tenart <antoine.tenart@free-electrons.com>");
117 MODULE_LICENSE("GPL");