blob: 8ce9d7fd6cfc30051462373d3c8d1f2b681dfcb3 [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>
Vivek Gautamadcf20d2013-03-14 18:09:49 +053025#include <linux/of_platform.h>
Anton Tikhomirovd28a9682012-02-15 17:04:56 +090026
Anton Tikhomirovd28a9682012-02-15 17:04:56 +090027struct dwc3_exynos {
Felipe Balbid720f052012-07-19 14:01:10 +030028 struct platform_device *usb2_phy;
29 struct platform_device *usb3_phy;
Anton Tikhomirovd28a9682012-02-15 17:04:56 +090030 struct device *dev;
31
32 struct clk *clk;
33};
34
Bill Pemberton41ac7b32012-11-19 13:21:48 -050035static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos)
Felipe Balbid720f052012-07-19 14:01:10 +030036{
37 struct nop_usb_xceiv_platform_data pdata;
38 struct platform_device *pdev;
39 int ret;
40
41 memset(&pdata, 0x00, sizeof(pdata));
42
Vivek Gautamb0e45dd2013-01-25 16:52:01 +053043 pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO);
Felipe Balbid720f052012-07-19 14:01:10 +030044 if (!pdev)
45 return -ENOMEM;
46
47 exynos->usb2_phy = pdev;
48 pdata.type = USB_PHY_TYPE_USB2;
49
50 ret = platform_device_add_data(exynos->usb2_phy, &pdata, sizeof(pdata));
51 if (ret)
52 goto err1;
53
Vivek Gautamb0e45dd2013-01-25 16:52:01 +053054 pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO);
Felipe Balbid720f052012-07-19 14:01:10 +030055 if (!pdev) {
56 ret = -ENOMEM;
57 goto err1;
58 }
59
60 exynos->usb3_phy = pdev;
61 pdata.type = USB_PHY_TYPE_USB3;
62
63 ret = platform_device_add_data(exynos->usb3_phy, &pdata, sizeof(pdata));
64 if (ret)
65 goto err2;
66
67 ret = platform_device_add(exynos->usb2_phy);
68 if (ret)
69 goto err2;
70
71 ret = platform_device_add(exynos->usb3_phy);
72 if (ret)
73 goto err3;
74
75 return 0;
76
77err3:
78 platform_device_del(exynos->usb2_phy);
79
80err2:
81 platform_device_put(exynos->usb3_phy);
82
83err1:
84 platform_device_put(exynos->usb2_phy);
85
86 return ret;
87}
88
Vivek Gautamadcf20d2013-03-14 18:09:49 +053089static int dwc3_exynos_remove_child(struct device *dev, void *unused)
90{
91 struct platform_device *pdev = to_platform_device(dev);
92
93 platform_device_unregister(pdev);
94
95 return 0;
96}
97
Bill Pemberton41ac7b32012-11-19 13:21:48 -050098static int dwc3_exynos_probe(struct platform_device *pdev)
Anton Tikhomirovd28a9682012-02-15 17:04:56 +090099{
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900100 struct dwc3_exynos *exynos;
101 struct clk *clk;
Jingoo Han20b97dc2012-11-13 11:20:49 +0900102 struct device *dev = &pdev->dev;
Vivek Gautamadcf20d2013-03-14 18:09:49 +0530103 struct device_node *node = dev->of_node;
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900104
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900105 int ret = -ENOMEM;
106
Jingoo Han20b97dc2012-11-13 11:20:49 +0900107 exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900108 if (!exynos) {
Jingoo Han20b97dc2012-11-13 11:20:49 +0900109 dev_err(dev, "not enough memory\n");
Vivek Gautamadcf20d2013-03-14 18:09:49 +0530110 goto err1;
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900111 }
112
Vivek Gautamaccefdd2012-11-03 18:00:27 +0530113 /*
114 * Right now device-tree probed devices don't get dma_mask set.
115 * Since shared usb code relies on it, set it here for now.
116 * Once we move to full device tree support this will vanish off.
117 */
Vivek Gautamadcf20d2013-03-14 18:09:49 +0530118 if (!dev->dma_mask)
Stephen Warren3b9561e2013-05-07 16:53:52 -0600119 dev->dma_mask = &dev->coherent_dma_mask;
120 if (!dev->coherent_dma_mask)
121 dev->coherent_dma_mask = DMA_BIT_MASK(32);
Vivek Gautamaccefdd2012-11-03 18:00:27 +0530122
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900123 platform_set_drvdata(pdev, exynos);
124
Felipe Balbid720f052012-07-19 14:01:10 +0300125 ret = dwc3_exynos_register_phys(exynos);
126 if (ret) {
Jingoo Han20b97dc2012-11-13 11:20:49 +0900127 dev_err(dev, "couldn't register PHYs\n");
Vivek Gautamadcf20d2013-03-14 18:09:49 +0530128 goto err1;
Jingoo Han20b97dc2012-11-13 11:20:49 +0900129 }
130
131 clk = devm_clk_get(dev, "usbdrd30");
132 if (IS_ERR(clk)) {
133 dev_err(dev, "couldn't get clock\n");
134 ret = -EINVAL;
Sebastian Andrzej Siewior124dafd2012-10-29 18:09:53 +0100135 goto err1;
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900136 }
137
Jingoo Han20b97dc2012-11-13 11:20:49 +0900138 exynos->dev = dev;
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900139 exynos->clk = clk;
140
Vivek Gautamddb51472013-03-14 16:14:58 +0530141 clk_prepare_enable(exynos->clk);
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900142
Vivek Gautamadcf20d2013-03-14 18:09:49 +0530143 if (node) {
144 ret = of_platform_populate(node, NULL, NULL, dev);
145 if (ret) {
146 dev_err(dev, "failed to add dwc3 core\n");
147 goto err2;
148 }
149 } else {
150 dev_err(dev, "no device node, failed to add dwc3 core\n");
151 ret = -ENODEV;
Jingoo Han20b97dc2012-11-13 11:20:49 +0900152 goto err2;
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900153 }
154
155 return 0;
156
Jingoo Han20b97dc2012-11-13 11:20:49 +0900157err2:
Vivek Gautamddb51472013-03-14 16:14:58 +0530158 clk_disable_unprepare(clk);
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900159err1:
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900160 return ret;
161}
162
Bill Pembertonfb4e98a2012-11-19 13:26:20 -0500163static int dwc3_exynos_remove(struct platform_device *pdev)
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900164{
165 struct dwc3_exynos *exynos = platform_get_drvdata(pdev);
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900166
Peter Chen022d0542013-05-24 14:30:16 +0800167 device_for_each_child(&pdev->dev, NULL, dwc3_exynos_remove_child);
Felipe Balbid720f052012-07-19 14:01:10 +0300168 platform_device_unregister(exynos->usb2_phy);
169 platform_device_unregister(exynos->usb3_phy);
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900170
Vivek Gautamddb51472013-03-14 16:14:58 +0530171 clk_disable_unprepare(exynos->clk);
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900172
173 return 0;
174}
175
Vivek Gautamaccefdd2012-11-03 18:00:27 +0530176#ifdef CONFIG_OF
177static const struct of_device_id exynos_dwc3_match[] = {
Vivek Gautamfe29db82013-01-24 19:15:30 +0530178 { .compatible = "samsung,exynos5250-dwusb3" },
Vivek Gautamaccefdd2012-11-03 18:00:27 +0530179 {},
180};
181MODULE_DEVICE_TABLE(of, exynos_dwc3_match);
182#endif
183
Jingoo Han19fda7c2013-03-26 01:52:48 +0000184#ifdef CONFIG_PM_SLEEP
Vikas Sajjan0646caf2012-10-16 15:15:38 +0530185static int dwc3_exynos_suspend(struct device *dev)
186{
187 struct dwc3_exynos *exynos = dev_get_drvdata(dev);
188
189 clk_disable(exynos->clk);
190
191 return 0;
192}
193
194static int dwc3_exynos_resume(struct device *dev)
195{
196 struct dwc3_exynos *exynos = dev_get_drvdata(dev);
197
198 clk_enable(exynos->clk);
199
200 /* runtime set active to reflect active state. */
201 pm_runtime_disable(dev);
202 pm_runtime_set_active(dev);
203 pm_runtime_enable(dev);
204
205 return 0;
206}
207
208static const struct dev_pm_ops dwc3_exynos_dev_pm_ops = {
209 SET_SYSTEM_SLEEP_PM_OPS(dwc3_exynos_suspend, dwc3_exynos_resume)
210};
211
212#define DEV_PM_OPS (&dwc3_exynos_dev_pm_ops)
213#else
214#define DEV_PM_OPS NULL
Jingoo Han19fda7c2013-03-26 01:52:48 +0000215#endif /* CONFIG_PM_SLEEP */
Vikas Sajjan0646caf2012-10-16 15:15:38 +0530216
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900217static struct platform_driver dwc3_exynos_driver = {
218 .probe = dwc3_exynos_probe,
Bill Pemberton76904172012-11-19 13:21:08 -0500219 .remove = dwc3_exynos_remove,
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900220 .driver = {
221 .name = "exynos-dwc3",
Vivek Gautamaccefdd2012-11-03 18:00:27 +0530222 .of_match_table = of_match_ptr(exynos_dwc3_match),
Vikas Sajjan0646caf2012-10-16 15:15:38 +0530223 .pm = DEV_PM_OPS,
Anton Tikhomirovd28a9682012-02-15 17:04:56 +0900224 },
225};
226
227module_platform_driver(dwc3_exynos_driver);
228
229MODULE_ALIAS("platform:exynos-dwc3");
230MODULE_AUTHOR("Anton Tikhomirov <av.tikhomirov@samsung.com>");
231MODULE_LICENSE("GPL");
232MODULE_DESCRIPTION("DesignWare USB3 EXYNOS Glue Layer");