blob: 6471d786b3cfffad3401dedaab29cfa1396347e3 [file] [log] [blame]
Anton Tikhomirovd28a9682012-02-15 17:04:56 +09001/**
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>
Anton Tikhomirovd28a9682012-02-15 17:04:56 +090021#include <linux/clk.h>
Felipe Balbid720f052012-07-19 14:01:10 +030022#include <linux/usb/otg.h>
23#include <linux/usb/nop-usb-xceiv.h>
Vivek Gautamaccefdd2012-11-03 18:00:27 +053024#include <linux/of.h>
Anton Tikhomirovd28a9682012-02-15 17:04:56 +090025
26#include "core.h"
27
28struct dwc3_exynos {
29 struct platform_device *dwc3;
Felipe Balbid720f052012-07-19 14:01:10 +030030 struct platform_device *usb2_phy;
31 struct platform_device *usb3_phy;
Anton Tikhomirovd28a9682012-02-15 17:04:56 +090032 struct device *dev;
33
34 struct clk *clk;
35};
36
Felipe Balbid720f052012-07-19 14:01:10 +030037static int __devinit dwc3_exynos_register_phys(struct dwc3_exynos *exynos)
38{
39 struct nop_usb_xceiv_platform_data pdata;
40 struct platform_device *pdev;
41 int ret;
42
43 memset(&pdata, 0x00, sizeof(pdata));
44
45 pdev = platform_device_alloc("nop_usb_xceiv", 0);
46 if (!pdev)
47 return -ENOMEM;
48
49 exynos->usb2_phy = pdev;
50 pdata.type = USB_PHY_TYPE_USB2;
51
52 ret = platform_device_add_data(exynos->usb2_phy, &pdata, sizeof(pdata));
53 if (ret)
54 goto err1;
55
56 pdev = platform_device_alloc("nop_usb_xceiv", 1);
57 if (!pdev) {
58 ret = -ENOMEM;
59 goto err1;
60 }
61
62 exynos->usb3_phy = pdev;
63 pdata.type = USB_PHY_TYPE_USB3;
64
65 ret = platform_device_add_data(exynos->usb3_phy, &pdata, sizeof(pdata));
66 if (ret)
67 goto err2;
68
69 ret = platform_device_add(exynos->usb2_phy);
70 if (ret)
71 goto err2;
72
73 ret = platform_device_add(exynos->usb3_phy);
74 if (ret)
75 goto err3;
76
77 return 0;
78
79err3:
80 platform_device_del(exynos->usb2_phy);
81
82err2:
83 platform_device_put(exynos->usb3_phy);
84
85err1:
86 platform_device_put(exynos->usb2_phy);
87
88 return ret;
89}
90
Vivek Gautamaccefdd2012-11-03 18:00:27 +053091static u64 dwc3_exynos_dma_mask = DMA_BIT_MASK(32);
92
Anton Tikhomirovd28a9682012-02-15 17:04:56 +090093static int __devinit dwc3_exynos_probe(struct platform_device *pdev)
94{
95 struct dwc3_exynos_data *pdata = pdev->dev.platform_data;
96 struct platform_device *dwc3;
97 struct dwc3_exynos *exynos;
98 struct clk *clk;
99
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900100 int ret = -ENOMEM;
101
102 exynos = kzalloc(sizeof(*exynos), GFP_KERNEL);
103 if (!exynos) {
104 dev_err(&pdev->dev, "not enough memory\n");
105 goto err0;
106 }
107
Vivek Gautamaccefdd2012-11-03 18:00:27 +0530108 /*
109 * Right now device-tree probed devices don't get dma_mask set.
110 * Since shared usb code relies on it, set it here for now.
111 * Once we move to full device tree support this will vanish off.
112 */
113 if (!pdev->dev.dma_mask)
114 pdev->dev.dma_mask = &dwc3_exynos_dma_mask;
115
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900116 platform_set_drvdata(pdev, exynos);
117
Felipe Balbid720f052012-07-19 14:01:10 +0300118 ret = dwc3_exynos_register_phys(exynos);
119 if (ret) {
120 dev_err(&pdev->dev, "couldn't register PHYs\n");
121 goto err1;
122 }
123
Sebastian Andrzej Siewior124dafd2012-10-29 18:09:53 +0100124 dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900125 if (!dwc3) {
126 dev_err(&pdev->dev, "couldn't allocate dwc3 device\n");
Sebastian Andrzej Siewior124dafd2012-10-29 18:09:53 +0100127 goto err1;
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900128 }
129
130 clk = clk_get(&pdev->dev, "usbdrd30");
131 if (IS_ERR(clk)) {
132 dev_err(&pdev->dev, "couldn't get clock\n");
133 ret = -EINVAL;
134 goto err3;
135 }
136
137 dma_set_coherent_mask(&dwc3->dev, pdev->dev.coherent_dma_mask);
138
139 dwc3->dev.parent = &pdev->dev;
140 dwc3->dev.dma_mask = pdev->dev.dma_mask;
141 dwc3->dev.dma_parms = pdev->dev.dma_parms;
142 exynos->dwc3 = dwc3;
143 exynos->dev = &pdev->dev;
144 exynos->clk = clk;
145
146 clk_enable(exynos->clk);
147
148 /* PHY initialization */
149 if (!pdata) {
150 dev_dbg(&pdev->dev, "missing platform data\n");
151 } else {
152 if (pdata->phy_init)
153 pdata->phy_init(pdev, pdata->phy_type);
154 }
155
156 ret = platform_device_add_resources(dwc3, pdev->resource,
157 pdev->num_resources);
158 if (ret) {
159 dev_err(&pdev->dev, "couldn't add resources to dwc3 device\n");
160 goto err4;
161 }
162
163 ret = platform_device_add(dwc3);
164 if (ret) {
165 dev_err(&pdev->dev, "failed to register dwc3 device\n");
166 goto err4;
167 }
168
169 return 0;
170
171err4:
172 if (pdata && pdata->phy_exit)
173 pdata->phy_exit(pdev, pdata->phy_type);
174
175 clk_disable(clk);
176 clk_put(clk);
177err3:
178 platform_device_put(dwc3);
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900179err1:
180 kfree(exynos);
181err0:
182 return ret;
183}
184
185static int __devexit dwc3_exynos_remove(struct platform_device *pdev)
186{
187 struct dwc3_exynos *exynos = platform_get_drvdata(pdev);
188 struct dwc3_exynos_data *pdata = pdev->dev.platform_data;
189
190 platform_device_unregister(exynos->dwc3);
Felipe Balbid720f052012-07-19 14:01:10 +0300191 platform_device_unregister(exynos->usb2_phy);
192 platform_device_unregister(exynos->usb3_phy);
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900193
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900194 if (pdata && pdata->phy_exit)
195 pdata->phy_exit(pdev, pdata->phy_type);
196
197 clk_disable(exynos->clk);
198 clk_put(exynos->clk);
199
200 kfree(exynos);
201
202 return 0;
203}
204
Vivek Gautamaccefdd2012-11-03 18:00:27 +0530205#ifdef CONFIG_OF
206static const struct of_device_id exynos_dwc3_match[] = {
207 { .compatible = "samsung,exynos-dwc3" },
208 {},
209};
210MODULE_DEVICE_TABLE(of, exynos_dwc3_match);
211#endif
212
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900213static struct platform_driver dwc3_exynos_driver = {
214 .probe = dwc3_exynos_probe,
215 .remove = __devexit_p(dwc3_exynos_remove),
216 .driver = {
217 .name = "exynos-dwc3",
Vivek Gautamaccefdd2012-11-03 18:00:27 +0530218 .of_match_table = of_match_ptr(exynos_dwc3_match),
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900219 },
220};
221
222module_platform_driver(dwc3_exynos_driver);
223
224MODULE_ALIAS("platform:exynos-dwc3");
225MODULE_AUTHOR("Anton Tikhomirov <av.tikhomirov@samsung.com>");
226MODULE_LICENSE("GPL");
227MODULE_DESCRIPTION("DesignWare USB3 EXYNOS Glue Layer");