perf python: Do not force closing original perf descriptor in evlist.get_pollfd()
[linux/fpc-iii.git] / drivers / usb / chipidea / ci_hdrc_usb2.c
blobc044fba463e43fa6016720838c44e5171a2a8b81
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2014 Marvell Technology Group Ltd.
5 * Antoine Tenart <antoine.tenart@free-electrons.com>
6 */
8 #include <linux/clk.h>
9 #include <linux/dma-mapping.h>
10 #include <linux/module.h>
11 #include <linux/of.h>
12 #include <linux/of_platform.h>
13 #include <linux/phy/phy.h>
14 #include <linux/platform_device.h>
15 #include <linux/usb/chipidea.h>
16 #include <linux/usb/hcd.h>
17 #include <linux/usb/ulpi.h>
19 #include "ci.h"
21 struct ci_hdrc_usb2_priv {
22 struct platform_device *ci_pdev;
23 struct clk *clk;
26 static const struct ci_hdrc_platform_data ci_default_pdata = {
27 .capoffset = DEF_CAPOFFSET,
28 .flags = CI_HDRC_DISABLE_STREAMING,
31 static struct ci_hdrc_platform_data ci_zynq_pdata = {
32 .capoffset = DEF_CAPOFFSET,
35 static const struct of_device_id ci_hdrc_usb2_of_match[] = {
36 { .compatible = "chipidea,usb2"},
37 { .compatible = "xlnx,zynq-usb-2.20a", .data = &ci_zynq_pdata},
38 { }
40 MODULE_DEVICE_TABLE(of, ci_hdrc_usb2_of_match);
42 static int ci_hdrc_usb2_probe(struct platform_device *pdev)
44 struct device *dev = &pdev->dev;
45 struct ci_hdrc_usb2_priv *priv;
46 struct ci_hdrc_platform_data *ci_pdata = dev_get_platdata(dev);
47 int ret;
48 const struct of_device_id *match;
50 if (!ci_pdata) {
51 ci_pdata = devm_kmalloc(dev, sizeof(*ci_pdata), GFP_KERNEL);
52 if (!ci_pdata)
53 return -ENOMEM;
54 *ci_pdata = ci_default_pdata; /* struct copy */
57 match = of_match_device(ci_hdrc_usb2_of_match, &pdev->dev);
58 if (match && match->data) {
59 /* struct copy */
60 *ci_pdata = *(struct ci_hdrc_platform_data *)match->data;
63 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
64 if (!priv)
65 return -ENOMEM;
67 priv->clk = devm_clk_get(dev, NULL);
68 if (!IS_ERR(priv->clk)) {
69 ret = clk_prepare_enable(priv->clk);
70 if (ret) {
71 dev_err(dev, "failed to enable the clock: %d\n", ret);
72 return ret;
76 ci_pdata->name = dev_name(dev);
78 priv->ci_pdev = ci_hdrc_add_device(dev, pdev->resource,
79 pdev->num_resources, ci_pdata);
80 if (IS_ERR(priv->ci_pdev)) {
81 ret = PTR_ERR(priv->ci_pdev);
82 if (ret != -EPROBE_DEFER)
83 dev_err(dev,
84 "failed to register ci_hdrc platform device: %d\n",
85 ret);
86 goto clk_err;
89 platform_set_drvdata(pdev, priv);
91 pm_runtime_no_callbacks(dev);
92 pm_runtime_enable(dev);
94 return 0;
96 clk_err:
97 if (!IS_ERR(priv->clk))
98 clk_disable_unprepare(priv->clk);
99 return ret;
102 static int ci_hdrc_usb2_remove(struct platform_device *pdev)
104 struct ci_hdrc_usb2_priv *priv = platform_get_drvdata(pdev);
106 pm_runtime_disable(&pdev->dev);
107 ci_hdrc_remove_device(priv->ci_pdev);
108 clk_disable_unprepare(priv->clk);
110 return 0;
113 static struct platform_driver ci_hdrc_usb2_driver = {
114 .probe = ci_hdrc_usb2_probe,
115 .remove = ci_hdrc_usb2_remove,
116 .driver = {
117 .name = "chipidea-usb2",
118 .of_match_table = of_match_ptr(ci_hdrc_usb2_of_match),
121 module_platform_driver(ci_hdrc_usb2_driver);
123 MODULE_DESCRIPTION("ChipIdea HDRC USB2 binding for ci13xxx");
124 MODULE_AUTHOR("Antoine Tenart <antoine.tenart@free-electrons.com>");
125 MODULE_LICENSE("GPL");