2 * dwc3-exynos.c - Samsung EXYNOS DWC3 Specific Glue layer
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com
7 * Author: Anton Tikhomirov <av.tikhomirov@samsung.com>
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.
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>
29 struct platform_device *dwc3;
30 struct platform_device *usb2_phy;
31 struct platform_device *usb3_phy;
37 static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos)
39 struct nop_usb_xceiv_platform_data pdata;
40 struct platform_device *pdev;
43 memset(&pdata, 0x00, sizeof(pdata));
45 pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO);
49 exynos->usb2_phy = pdev;
50 pdata.type = USB_PHY_TYPE_USB2;
52 ret = platform_device_add_data(exynos->usb2_phy, &pdata, sizeof(pdata));
56 pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO);
62 exynos->usb3_phy = pdev;
63 pdata.type = USB_PHY_TYPE_USB3;
65 ret = platform_device_add_data(exynos->usb3_phy, &pdata, sizeof(pdata));
69 ret = platform_device_add(exynos->usb2_phy);
73 ret = platform_device_add(exynos->usb3_phy);
80 platform_device_del(exynos->usb2_phy);
83 platform_device_put(exynos->usb3_phy);
86 platform_device_put(exynos->usb2_phy);
91 static u64 dwc3_exynos_dma_mask = DMA_BIT_MASK(32);
93 static int dwc3_exynos_probe(struct platform_device *pdev)
95 struct platform_device *dwc3;
96 struct dwc3_exynos *exynos;
98 struct device *dev = &pdev->dev;
102 exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
104 dev_err(dev, "not enough memory\n");
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.
113 if (!pdev->dev.dma_mask)
114 pdev->dev.dma_mask = &dwc3_exynos_dma_mask;
116 platform_set_drvdata(pdev, exynos);
118 ret = dwc3_exynos_register_phys(exynos);
120 dev_err(dev, "couldn't register PHYs\n");
124 dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
126 dev_err(dev, "couldn't allocate dwc3 device\n");
130 clk = devm_clk_get(dev, "usbdrd30");
132 dev_err(dev, "couldn't get clock\n");
137 dma_set_coherent_mask(&dwc3->dev, dev->coherent_dma_mask);
139 dwc3->dev.parent = dev;
140 dwc3->dev.dma_mask = dev->dma_mask;
141 dwc3->dev.dma_parms = dev->dma_parms;
146 clk_enable(exynos->clk);
148 ret = platform_device_add_resources(dwc3, pdev->resource,
149 pdev->num_resources);
151 dev_err(dev, "couldn't add resources to dwc3 device\n");
155 ret = platform_device_add(dwc3);
157 dev_err(dev, "failed to register dwc3 device\n");
166 platform_device_put(dwc3);
171 static int dwc3_exynos_remove(struct platform_device *pdev)
173 struct dwc3_exynos *exynos = platform_get_drvdata(pdev);
175 platform_device_unregister(exynos->dwc3);
176 platform_device_unregister(exynos->usb2_phy);
177 platform_device_unregister(exynos->usb3_phy);
179 clk_disable(exynos->clk);
185 static const struct of_device_id exynos_dwc3_match[] = {
186 { .compatible = "samsung,exynos5250-dwusb3" },
189 MODULE_DEVICE_TABLE(of, exynos_dwc3_match);
192 static struct platform_driver dwc3_exynos_driver = {
193 .probe = dwc3_exynos_probe,
194 .remove = dwc3_exynos_remove,
196 .name = "exynos-dwc3",
197 .of_match_table = of_match_ptr(exynos_dwc3_match),
201 module_platform_driver(dwc3_exynos_driver);
203 MODULE_ALIAS("platform:exynos-dwc3");
204 MODULE_AUTHOR("Anton Tikhomirov <av.tikhomirov@samsung.com>");
205 MODULE_LICENSE("GPL");
206 MODULE_DESCRIPTION("DesignWare USB3 EXYNOS Glue Layer");