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 23 #include "core.h" 24 25 struct dwc3_exynos { 26 struct platform_device *dwc3; 27 struct device *dev; 28 29 struct clk *clk; 30 }; 31 32 static int __devinit dwc3_exynos_probe(struct platform_device *pdev) 33 { 34 struct dwc3_exynos_data *pdata = pdev->dev.platform_data; 35 struct platform_device *dwc3; 36 struct dwc3_exynos *exynos; 37 struct clk *clk; 38 39 int devid; 40 int ret = -ENOMEM; 41 42 exynos = kzalloc(sizeof(*exynos), GFP_KERNEL); 43 if (!exynos) { 44 dev_err(&pdev->dev, "not enough memory\n"); 45 goto err0; 46 } 47 48 platform_set_drvdata(pdev, exynos); 49 50 devid = dwc3_get_device_id(); 51 if (devid < 0) 52 goto err1; 53 54 dwc3 = platform_device_alloc("dwc3", devid); 55 if (!dwc3) { 56 dev_err(&pdev->dev, "couldn't allocate dwc3 device\n"); 57 goto err2; 58 } 59 60 clk = clk_get(&pdev->dev, "usbdrd30"); 61 if (IS_ERR(clk)) { 62 dev_err(&pdev->dev, "couldn't get clock\n"); 63 ret = -EINVAL; 64 goto err3; 65 } 66 67 dma_set_coherent_mask(&dwc3->dev, pdev->dev.coherent_dma_mask); 68 69 dwc3->dev.parent = &pdev->dev; 70 dwc3->dev.dma_mask = pdev->dev.dma_mask; 71 dwc3->dev.dma_parms = pdev->dev.dma_parms; 72 exynos->dwc3 = dwc3; 73 exynos->dev = &pdev->dev; 74 exynos->clk = clk; 75 76 clk_enable(exynos->clk); 77 78 /* PHY initialization */ 79 if (!pdata) { 80 dev_dbg(&pdev->dev, "missing platform data\n"); 81 } else { 82 if (pdata->phy_init) 83 pdata->phy_init(pdev, pdata->phy_type); 84 } 85 86 ret = platform_device_add_resources(dwc3, pdev->resource, 87 pdev->num_resources); 88 if (ret) { 89 dev_err(&pdev->dev, "couldn't add resources to dwc3 device\n"); 90 goto err4; 91 } 92 93 ret = platform_device_add(dwc3); 94 if (ret) { 95 dev_err(&pdev->dev, "failed to register dwc3 device\n"); 96 goto err4; 97 } 98 99 return 0; 100 101 err4: 102 if (pdata && pdata->phy_exit) 103 pdata->phy_exit(pdev, pdata->phy_type); 104 105 clk_disable(clk); 106 clk_put(clk); 107 err3: 108 platform_device_put(dwc3); 109 err2: 110 dwc3_put_device_id(devid); 111 err1: 112 kfree(exynos); 113 err0: 114 return ret; 115 } 116 117 static int __devexit dwc3_exynos_remove(struct platform_device *pdev) 118 { 119 struct dwc3_exynos *exynos = platform_get_drvdata(pdev); 120 struct dwc3_exynos_data *pdata = pdev->dev.platform_data; 121 122 platform_device_unregister(exynos->dwc3); 123 124 dwc3_put_device_id(exynos->dwc3->id); 125 126 if (pdata && pdata->phy_exit) 127 pdata->phy_exit(pdev, pdata->phy_type); 128 129 clk_disable(exynos->clk); 130 clk_put(exynos->clk); 131 132 kfree(exynos); 133 134 return 0; 135 } 136 137 static struct platform_driver dwc3_exynos_driver = { 138 .probe = dwc3_exynos_probe, 139 .remove = __devexit_p(dwc3_exynos_remove), 140 .driver = { 141 .name = "exynos-dwc3", 142 }, 143 }; 144 145 module_platform_driver(dwc3_exynos_driver); 146 147 MODULE_ALIAS("platform:exynos-dwc3"); 148 MODULE_AUTHOR("Anton Tikhomirov <av.tikhomirov@samsung.com>"); 149 MODULE_LICENSE("GPL"); 150 MODULE_DESCRIPTION("DesignWare USB3 EXYNOS Glue Layer"); 151