Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 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> |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 21 | #include <linux/clk.h> |
Felipe Balbi | d720f05 | 2012-07-19 14:01:10 +0300 | [diff] [blame] | 22 | #include <linux/usb/otg.h> |
| 23 | #include <linux/usb/nop-usb-xceiv.h> |
Vivek Gautam | accefdd | 2012-11-03 18:00:27 +0530 | [diff] [blame] | 24 | #include <linux/of.h> |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 25 | |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 26 | struct dwc3_exynos { |
| 27 | struct platform_device *dwc3; |
Felipe Balbi | d720f05 | 2012-07-19 14:01:10 +0300 | [diff] [blame] | 28 | struct platform_device *usb2_phy; |
| 29 | struct platform_device *usb3_phy; |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 30 | struct device *dev; |
| 31 | |
| 32 | struct clk *clk; |
| 33 | }; |
| 34 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 35 | static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos) |
Felipe Balbi | d720f05 | 2012-07-19 14:01:10 +0300 | [diff] [blame] | 36 | { |
| 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 Gautam | b0e45dd | 2013-01-25 16:52:01 +0530 | [diff] [blame] | 43 | pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO); |
Felipe Balbi | d720f05 | 2012-07-19 14:01:10 +0300 | [diff] [blame] | 44 | 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 Gautam | b0e45dd | 2013-01-25 16:52:01 +0530 | [diff] [blame] | 54 | pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO); |
Felipe Balbi | d720f05 | 2012-07-19 14:01:10 +0300 | [diff] [blame] | 55 | 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 | |
| 77 | err3: |
| 78 | platform_device_del(exynos->usb2_phy); |
| 79 | |
| 80 | err2: |
| 81 | platform_device_put(exynos->usb3_phy); |
| 82 | |
| 83 | err1: |
| 84 | platform_device_put(exynos->usb2_phy); |
| 85 | |
| 86 | return ret; |
| 87 | } |
| 88 | |
Vivek Gautam | accefdd | 2012-11-03 18:00:27 +0530 | [diff] [blame] | 89 | static u64 dwc3_exynos_dma_mask = DMA_BIT_MASK(32); |
| 90 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 91 | static int dwc3_exynos_probe(struct platform_device *pdev) |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 92 | { |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 93 | struct platform_device *dwc3; |
| 94 | struct dwc3_exynos *exynos; |
| 95 | struct clk *clk; |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 96 | struct device *dev = &pdev->dev; |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 97 | |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 98 | int ret = -ENOMEM; |
| 99 | |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 100 | exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL); |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 101 | if (!exynos) { |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 102 | dev_err(dev, "not enough memory\n"); |
| 103 | return -ENOMEM; |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 104 | } |
| 105 | |
Vivek Gautam | accefdd | 2012-11-03 18:00:27 +0530 | [diff] [blame] | 106 | /* |
| 107 | * Right now device-tree probed devices don't get dma_mask set. |
| 108 | * Since shared usb code relies on it, set it here for now. |
| 109 | * Once we move to full device tree support this will vanish off. |
| 110 | */ |
| 111 | if (!pdev->dev.dma_mask) |
| 112 | pdev->dev.dma_mask = &dwc3_exynos_dma_mask; |
| 113 | |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 114 | platform_set_drvdata(pdev, exynos); |
| 115 | |
Felipe Balbi | d720f05 | 2012-07-19 14:01:10 +0300 | [diff] [blame] | 116 | ret = dwc3_exynos_register_phys(exynos); |
| 117 | if (ret) { |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 118 | dev_err(dev, "couldn't register PHYs\n"); |
| 119 | return ret; |
Felipe Balbi | d720f05 | 2012-07-19 14:01:10 +0300 | [diff] [blame] | 120 | } |
| 121 | |
Sebastian Andrzej Siewior | 124dafd | 2012-10-29 18:09:53 +0100 | [diff] [blame] | 122 | dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO); |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 123 | if (!dwc3) { |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 124 | dev_err(dev, "couldn't allocate dwc3 device\n"); |
| 125 | return -ENOMEM; |
| 126 | } |
| 127 | |
| 128 | clk = devm_clk_get(dev, "usbdrd30"); |
| 129 | if (IS_ERR(clk)) { |
| 130 | dev_err(dev, "couldn't get clock\n"); |
| 131 | ret = -EINVAL; |
Sebastian Andrzej Siewior | 124dafd | 2012-10-29 18:09:53 +0100 | [diff] [blame] | 132 | goto err1; |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 133 | } |
| 134 | |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 135 | dma_set_coherent_mask(&dwc3->dev, dev->coherent_dma_mask); |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 136 | |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 137 | dwc3->dev.parent = dev; |
| 138 | dwc3->dev.dma_mask = dev->dma_mask; |
| 139 | dwc3->dev.dma_parms = dev->dma_parms; |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 140 | exynos->dwc3 = dwc3; |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 141 | exynos->dev = dev; |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 142 | exynos->clk = clk; |
| 143 | |
| 144 | clk_enable(exynos->clk); |
| 145 | |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 146 | ret = platform_device_add_resources(dwc3, pdev->resource, |
| 147 | pdev->num_resources); |
| 148 | if (ret) { |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 149 | dev_err(dev, "couldn't add resources to dwc3 device\n"); |
| 150 | goto err2; |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | ret = platform_device_add(dwc3); |
| 154 | if (ret) { |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 155 | dev_err(dev, "failed to register dwc3 device\n"); |
| 156 | goto err2; |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | return 0; |
| 160 | |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 161 | err2: |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 162 | clk_disable(clk); |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 163 | err1: |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 164 | platform_device_put(dwc3); |
| 165 | |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 166 | return ret; |
| 167 | } |
| 168 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 169 | static int dwc3_exynos_remove(struct platform_device *pdev) |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 170 | { |
| 171 | struct dwc3_exynos *exynos = platform_get_drvdata(pdev); |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 172 | |
| 173 | platform_device_unregister(exynos->dwc3); |
Felipe Balbi | d720f05 | 2012-07-19 14:01:10 +0300 | [diff] [blame] | 174 | platform_device_unregister(exynos->usb2_phy); |
| 175 | platform_device_unregister(exynos->usb3_phy); |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 176 | |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 177 | clk_disable(exynos->clk); |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 178 | |
| 179 | return 0; |
| 180 | } |
| 181 | |
Vivek Gautam | accefdd | 2012-11-03 18:00:27 +0530 | [diff] [blame] | 182 | #ifdef CONFIG_OF |
| 183 | static const struct of_device_id exynos_dwc3_match[] = { |
Vivek Gautam | fe29db8 | 2013-01-24 19:15:30 +0530 | [diff] [blame] | 184 | { .compatible = "samsung,exynos5250-dwusb3" }, |
Vivek Gautam | accefdd | 2012-11-03 18:00:27 +0530 | [diff] [blame] | 185 | {}, |
| 186 | }; |
| 187 | MODULE_DEVICE_TABLE(of, exynos_dwc3_match); |
| 188 | #endif |
| 189 | |
Vikas Sajjan | 0646caf | 2012-10-16 15:15:38 +0530 | [diff] [blame^] | 190 | #ifdef CONFIG_PM |
| 191 | static int dwc3_exynos_suspend(struct device *dev) |
| 192 | { |
| 193 | struct dwc3_exynos *exynos = dev_get_drvdata(dev); |
| 194 | |
| 195 | clk_disable(exynos->clk); |
| 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | static int dwc3_exynos_resume(struct device *dev) |
| 201 | { |
| 202 | struct dwc3_exynos *exynos = dev_get_drvdata(dev); |
| 203 | |
| 204 | clk_enable(exynos->clk); |
| 205 | |
| 206 | /* runtime set active to reflect active state. */ |
| 207 | pm_runtime_disable(dev); |
| 208 | pm_runtime_set_active(dev); |
| 209 | pm_runtime_enable(dev); |
| 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | static const struct dev_pm_ops dwc3_exynos_dev_pm_ops = { |
| 215 | SET_SYSTEM_SLEEP_PM_OPS(dwc3_exynos_suspend, dwc3_exynos_resume) |
| 216 | }; |
| 217 | |
| 218 | #define DEV_PM_OPS (&dwc3_exynos_dev_pm_ops) |
| 219 | #else |
| 220 | #define DEV_PM_OPS NULL |
| 221 | #endif /* CONFIG_PM */ |
| 222 | |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 223 | static struct platform_driver dwc3_exynos_driver = { |
| 224 | .probe = dwc3_exynos_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 225 | .remove = dwc3_exynos_remove, |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 226 | .driver = { |
| 227 | .name = "exynos-dwc3", |
Vivek Gautam | accefdd | 2012-11-03 18:00:27 +0530 | [diff] [blame] | 228 | .of_match_table = of_match_ptr(exynos_dwc3_match), |
Vikas Sajjan | 0646caf | 2012-10-16 15:15:38 +0530 | [diff] [blame^] | 229 | .pm = DEV_PM_OPS, |
Anton Tikhomirov | d28a9689 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 230 | }, |
| 231 | }; |
| 232 | |
| 233 | module_platform_driver(dwc3_exynos_driver); |
| 234 | |
| 235 | MODULE_ALIAS("platform:exynos-dwc3"); |
| 236 | MODULE_AUTHOR("Anton Tikhomirov <av.tikhomirov@samsung.com>"); |
| 237 | MODULE_LICENSE("GPL"); |
| 238 | MODULE_DESCRIPTION("DesignWare USB3 EXYNOS Glue Layer"); |