Linux 4.2.1
[linux/fpc-iii.git] / drivers / usb / chipidea / ci_hdrc_usb2.c
blob9eae1a16cef9c7aa7f7aa8eaec602af7e75a46cd
1 /*
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.
9 */
11 #include <linux/clk.h>
12 #include <linux/dma-mapping.h>
13 #include <linux/module.h>
14 #include <linux/of.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>
21 #include "ci.h"
23 struct ci_hdrc_usb2_priv {
24 struct platform_device *ci_pdev;
25 struct clk *clk;
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);
38 int ret;
40 if (!ci_pdata) {
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);
46 if (!priv)
47 return -ENOMEM;
49 priv->clk = devm_clk_get(dev, NULL);
50 if (!IS_ERR(priv->clk)) {
51 ret = clk_prepare_enable(priv->clk);
52 if (ret) {
53 dev_err(dev, "failed to enable the clock: %d\n", ret);
54 return ret;
58 ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
59 if (ret)
60 goto clk_err;
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)
69 dev_err(dev,
70 "failed to register ci_hdrc platform device: %d\n",
71 ret);
72 goto clk_err;
75 platform_set_drvdata(pdev, priv);
77 pm_runtime_no_callbacks(dev);
78 pm_runtime_enable(dev);
80 return 0;
82 clk_err:
83 if (!IS_ERR(priv->clk))
84 clk_disable_unprepare(priv->clk);
85 return ret;
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);
96 return 0;
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,
108 .driver = {
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");