usb: dwc3: remove custom unique id handling
[linux-block.git] / drivers / usb / dwc3 / dwc3-exynos.c
1 /**
2  * dwc3-exynos.c - Samsung EXYNOS DWC3 Specific Glue layer
3  *
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5  *              http://www.samsung.com
6  *
7  * Author: Anton Tikhomirov <av.tikhomirov@samsung.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  */
14
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/slab.h>
18 #include <linux/platform_device.h>
19 #include <linux/platform_data/dwc3-exynos.h>
20 #include <linux/dma-mapping.h>
21 #include <linux/clk.h>
22 #include <linux/usb/otg.h>
23 #include <linux/usb/nop-usb-xceiv.h>
24
25 #include "core.h"
26
27 struct dwc3_exynos {
28         struct platform_device  *dwc3;
29         struct platform_device  *usb2_phy;
30         struct platform_device  *usb3_phy;
31         struct device           *dev;
32
33         struct clk              *clk;
34 };
35
36 static int __devinit dwc3_exynos_register_phys(struct dwc3_exynos *exynos)
37 {
38         struct nop_usb_xceiv_platform_data pdata;
39         struct platform_device  *pdev;
40         int                     ret;
41
42         memset(&pdata, 0x00, sizeof(pdata));
43
44         pdev = platform_device_alloc("nop_usb_xceiv", 0);
45         if (!pdev)
46                 return -ENOMEM;
47
48         exynos->usb2_phy = pdev;
49         pdata.type = USB_PHY_TYPE_USB2;
50
51         ret = platform_device_add_data(exynos->usb2_phy, &pdata, sizeof(pdata));
52         if (ret)
53                 goto err1;
54
55         pdev = platform_device_alloc("nop_usb_xceiv", 1);
56         if (!pdev) {
57                 ret = -ENOMEM;
58                 goto err1;
59         }
60
61         exynos->usb3_phy = pdev;
62         pdata.type = USB_PHY_TYPE_USB3;
63
64         ret = platform_device_add_data(exynos->usb3_phy, &pdata, sizeof(pdata));
65         if (ret)
66                 goto err2;
67
68         ret = platform_device_add(exynos->usb2_phy);
69         if (ret)
70                 goto err2;
71
72         ret = platform_device_add(exynos->usb3_phy);
73         if (ret)
74                 goto err3;
75
76         return 0;
77
78 err3:
79         platform_device_del(exynos->usb2_phy);
80
81 err2:
82         platform_device_put(exynos->usb3_phy);
83
84 err1:
85         platform_device_put(exynos->usb2_phy);
86
87         return ret;
88 }
89
90 static int __devinit dwc3_exynos_probe(struct platform_device *pdev)
91 {
92         struct dwc3_exynos_data *pdata = pdev->dev.platform_data;
93         struct platform_device  *dwc3;
94         struct dwc3_exynos      *exynos;
95         struct clk              *clk;
96
97         int                     ret = -ENOMEM;
98
99         exynos = kzalloc(sizeof(*exynos), GFP_KERNEL);
100         if (!exynos) {
101                 dev_err(&pdev->dev, "not enough memory\n");
102                 goto err0;
103         }
104
105         platform_set_drvdata(pdev, exynos);
106
107         ret = dwc3_exynos_register_phys(exynos);
108         if (ret) {
109                 dev_err(&pdev->dev, "couldn't register PHYs\n");
110                 goto err1;
111         }
112
113         dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
114         if (!dwc3) {
115                 dev_err(&pdev->dev, "couldn't allocate dwc3 device\n");
116                 goto err1;
117         }
118
119         clk = clk_get(&pdev->dev, "usbdrd30");
120         if (IS_ERR(clk)) {
121                 dev_err(&pdev->dev, "couldn't get clock\n");
122                 ret = -EINVAL;
123                 goto err3;
124         }
125
126         dma_set_coherent_mask(&dwc3->dev, pdev->dev.coherent_dma_mask);
127
128         dwc3->dev.parent = &pdev->dev;
129         dwc3->dev.dma_mask = pdev->dev.dma_mask;
130         dwc3->dev.dma_parms = pdev->dev.dma_parms;
131         exynos->dwc3    = dwc3;
132         exynos->dev     = &pdev->dev;
133         exynos->clk     = clk;
134
135         clk_enable(exynos->clk);
136
137         /* PHY initialization */
138         if (!pdata) {
139                 dev_dbg(&pdev->dev, "missing platform data\n");
140         } else {
141                 if (pdata->phy_init)
142                         pdata->phy_init(pdev, pdata->phy_type);
143         }
144
145         ret = platform_device_add_resources(dwc3, pdev->resource,
146                         pdev->num_resources);
147         if (ret) {
148                 dev_err(&pdev->dev, "couldn't add resources to dwc3 device\n");
149                 goto err4;
150         }
151
152         ret = platform_device_add(dwc3);
153         if (ret) {
154                 dev_err(&pdev->dev, "failed to register dwc3 device\n");
155                 goto err4;
156         }
157
158         return 0;
159
160 err4:
161         if (pdata && pdata->phy_exit)
162                 pdata->phy_exit(pdev, pdata->phy_type);
163
164         clk_disable(clk);
165         clk_put(clk);
166 err3:
167         platform_device_put(dwc3);
168 err1:
169         kfree(exynos);
170 err0:
171         return ret;
172 }
173
174 static int __devexit dwc3_exynos_remove(struct platform_device *pdev)
175 {
176         struct dwc3_exynos      *exynos = platform_get_drvdata(pdev);
177         struct dwc3_exynos_data *pdata = pdev->dev.platform_data;
178
179         platform_device_unregister(exynos->dwc3);
180         platform_device_unregister(exynos->usb2_phy);
181         platform_device_unregister(exynos->usb3_phy);
182
183         if (pdata && pdata->phy_exit)
184                 pdata->phy_exit(pdev, pdata->phy_type);
185
186         clk_disable(exynos->clk);
187         clk_put(exynos->clk);
188
189         kfree(exynos);
190
191         return 0;
192 }
193
194 static struct platform_driver dwc3_exynos_driver = {
195         .probe          = dwc3_exynos_probe,
196         .remove         = __devexit_p(dwc3_exynos_remove),
197         .driver         = {
198                 .name   = "exynos-dwc3",
199         },
200 };
201
202 module_platform_driver(dwc3_exynos_driver);
203
204 MODULE_ALIAS("platform:exynos-dwc3");
205 MODULE_AUTHOR("Anton Tikhomirov <av.tikhomirov@samsung.com>");
206 MODULE_LICENSE("GPL");
207 MODULE_DESCRIPTION("DesignWare USB3 EXYNOS Glue Layer");