Merge tag '5.9-rc-smb3-fixes-part2' of git://git.samba.org/sfrench/cifs-2.6
[linux/fpc-iii.git] / drivers / usb / chipidea / ci_hdrc_usb2.c
blob89e1d82d739b1618429b02e5967890f4ee672306
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 const struct ci_hdrc_platform_data ci_zynq_pdata = {
32 .capoffset = DEF_CAPOFFSET,
35 static const struct ci_hdrc_platform_data ci_zevio_pdata = {
36 .capoffset = DEF_CAPOFFSET,
37 .flags = CI_HDRC_REGS_SHARED | CI_HDRC_FORCE_FULLSPEED,
40 static const struct of_device_id ci_hdrc_usb2_of_match[] = {
41 { .compatible = "chipidea,usb2" },
42 { .compatible = "xlnx,zynq-usb-2.20a", .data = &ci_zynq_pdata },
43 { .compatible = "lsi,zevio-usb", .data = &ci_zevio_pdata },
44 { }
46 MODULE_DEVICE_TABLE(of, ci_hdrc_usb2_of_match);
48 static int ci_hdrc_usb2_probe(struct platform_device *pdev)
50 struct device *dev = &pdev->dev;
51 struct ci_hdrc_usb2_priv *priv;
52 struct ci_hdrc_platform_data *ci_pdata = dev_get_platdata(dev);
53 int ret;
54 const struct of_device_id *match;
56 if (!ci_pdata) {
57 ci_pdata = devm_kmalloc(dev, sizeof(*ci_pdata), GFP_KERNEL);
58 if (!ci_pdata)
59 return -ENOMEM;
60 *ci_pdata = ci_default_pdata; /* struct copy */
63 match = of_match_device(ci_hdrc_usb2_of_match, &pdev->dev);
64 if (match && match->data) {
65 /* struct copy */
66 *ci_pdata = *(struct ci_hdrc_platform_data *)match->data;
69 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
70 if (!priv)
71 return -ENOMEM;
73 priv->clk = devm_clk_get_optional(dev, NULL);
74 if (IS_ERR(priv->clk))
75 return PTR_ERR(priv->clk);
77 ret = clk_prepare_enable(priv->clk);
78 if (ret) {
79 dev_err(dev, "failed to enable the clock: %d\n", ret);
80 return ret;
83 ci_pdata->name = dev_name(dev);
85 priv->ci_pdev = ci_hdrc_add_device(dev, pdev->resource,
86 pdev->num_resources, ci_pdata);
87 if (IS_ERR(priv->ci_pdev)) {
88 ret = PTR_ERR(priv->ci_pdev);
89 if (ret != -EPROBE_DEFER)
90 dev_err(dev,
91 "failed to register ci_hdrc platform device: %d\n",
92 ret);
93 goto clk_err;
96 platform_set_drvdata(pdev, priv);
98 pm_runtime_no_callbacks(dev);
99 pm_runtime_enable(dev);
101 return 0;
103 clk_err:
104 clk_disable_unprepare(priv->clk);
105 return ret;
108 static int ci_hdrc_usb2_remove(struct platform_device *pdev)
110 struct ci_hdrc_usb2_priv *priv = platform_get_drvdata(pdev);
112 pm_runtime_disable(&pdev->dev);
113 ci_hdrc_remove_device(priv->ci_pdev);
114 clk_disable_unprepare(priv->clk);
116 return 0;
119 static struct platform_driver ci_hdrc_usb2_driver = {
120 .probe = ci_hdrc_usb2_probe,
121 .remove = ci_hdrc_usb2_remove,
122 .driver = {
123 .name = "chipidea-usb2",
124 .of_match_table = of_match_ptr(ci_hdrc_usb2_of_match),
127 module_platform_driver(ci_hdrc_usb2_driver);
129 MODULE_DESCRIPTION("ChipIdea HDRC USB2 binding for ci13xxx");
130 MODULE_AUTHOR("Antoine Tenart <antoine.tenart@free-electrons.com>");
131 MODULE_LICENSE("GPL");