lib/interval-tree: correct comment wrt generic flavor
[cris-mirror.git] / drivers / usb / chipidea / ci_hdrc_usb2.c
blob99425db9ba62b20beda2c08c0cd2e49639c87e52
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/of_platform.h>
16 #include <linux/phy/phy.h>
17 #include <linux/platform_device.h>
18 #include <linux/usb/chipidea.h>
19 #include <linux/usb/hcd.h>
20 #include <linux/usb/ulpi.h>
22 #include "ci.h"
24 struct ci_hdrc_usb2_priv {
25 struct platform_device *ci_pdev;
26 struct clk *clk;
29 static const struct ci_hdrc_platform_data ci_default_pdata = {
30 .capoffset = DEF_CAPOFFSET,
31 .flags = CI_HDRC_DISABLE_STREAMING,
34 static struct ci_hdrc_platform_data ci_zynq_pdata = {
35 .capoffset = DEF_CAPOFFSET,
38 static const struct of_device_id ci_hdrc_usb2_of_match[] = {
39 { .compatible = "chipidea,usb2"},
40 { .compatible = "xlnx,zynq-usb-2.20a", .data = &ci_zynq_pdata},
41 { }
43 MODULE_DEVICE_TABLE(of, ci_hdrc_usb2_of_match);
45 static int ci_hdrc_usb2_probe(struct platform_device *pdev)
47 struct device *dev = &pdev->dev;
48 struct ci_hdrc_usb2_priv *priv;
49 struct ci_hdrc_platform_data *ci_pdata = dev_get_platdata(dev);
50 int ret;
51 const struct of_device_id *match;
53 if (!ci_pdata) {
54 ci_pdata = devm_kmalloc(dev, sizeof(*ci_pdata), GFP_KERNEL);
55 if (!ci_pdata)
56 return -ENOMEM;
57 *ci_pdata = ci_default_pdata; /* struct copy */
60 match = of_match_device(ci_hdrc_usb2_of_match, &pdev->dev);
61 if (match && match->data) {
62 /* struct copy */
63 *ci_pdata = *(struct ci_hdrc_platform_data *)match->data;
66 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
67 if (!priv)
68 return -ENOMEM;
70 priv->clk = devm_clk_get(dev, NULL);
71 if (!IS_ERR(priv->clk)) {
72 ret = clk_prepare_enable(priv->clk);
73 if (ret) {
74 dev_err(dev, "failed to enable the clock: %d\n", ret);
75 return ret;
79 ci_pdata->name = dev_name(dev);
81 priv->ci_pdev = ci_hdrc_add_device(dev, pdev->resource,
82 pdev->num_resources, ci_pdata);
83 if (IS_ERR(priv->ci_pdev)) {
84 ret = PTR_ERR(priv->ci_pdev);
85 if (ret != -EPROBE_DEFER)
86 dev_err(dev,
87 "failed to register ci_hdrc platform device: %d\n",
88 ret);
89 goto clk_err;
92 platform_set_drvdata(pdev, priv);
94 pm_runtime_no_callbacks(dev);
95 pm_runtime_enable(dev);
97 return 0;
99 clk_err:
100 if (!IS_ERR(priv->clk))
101 clk_disable_unprepare(priv->clk);
102 return ret;
105 static int ci_hdrc_usb2_remove(struct platform_device *pdev)
107 struct ci_hdrc_usb2_priv *priv = platform_get_drvdata(pdev);
109 pm_runtime_disable(&pdev->dev);
110 ci_hdrc_remove_device(priv->ci_pdev);
111 clk_disable_unprepare(priv->clk);
113 return 0;
116 static struct platform_driver ci_hdrc_usb2_driver = {
117 .probe = ci_hdrc_usb2_probe,
118 .remove = ci_hdrc_usb2_remove,
119 .driver = {
120 .name = "chipidea-usb2",
121 .of_match_table = of_match_ptr(ci_hdrc_usb2_of_match),
124 module_platform_driver(ci_hdrc_usb2_driver);
126 MODULE_DESCRIPTION("ChipIdea HDRC USB2 binding for ci13xxx");
127 MODULE_AUTHOR("Antoine Tenart <antoine.tenart@free-electrons.com>");
128 MODULE_LICENSE("GPL");