Anton Tikhomirov | d28a968 | 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 | d28a968 | 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 | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 25 | |
| 26 | #include "core.h" |
| 27 | |
| 28 | struct dwc3_exynos { |
| 29 | struct platform_device *dwc3; |
Felipe Balbi | d720f05 | 2012-07-19 14:01:10 +0300 | [diff] [blame] | 30 | struct platform_device *usb2_phy; |
| 31 | struct platform_device *usb3_phy; |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 32 | struct device *dev; |
| 33 | |
| 34 | struct clk *clk; |
| 35 | }; |
| 36 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 37 | static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos) |
Felipe Balbi | d720f05 | 2012-07-19 14:01:10 +0300 | [diff] [blame] | 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 | |
| 79 | err3: |
| 80 | platform_device_del(exynos->usb2_phy); |
| 81 | |
| 82 | err2: |
| 83 | platform_device_put(exynos->usb3_phy); |
| 84 | |
| 85 | err1: |
| 86 | platform_device_put(exynos->usb2_phy); |
| 87 | |
| 88 | return ret; |
| 89 | } |
| 90 | |
Vivek Gautam | accefdd | 2012-11-03 18:00:27 +0530 | [diff] [blame] | 91 | static u64 dwc3_exynos_dma_mask = DMA_BIT_MASK(32); |
| 92 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 93 | static int dwc3_exynos_probe(struct platform_device *pdev) |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 94 | { |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 95 | struct platform_device *dwc3; |
| 96 | struct dwc3_exynos *exynos; |
| 97 | struct clk *clk; |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 98 | struct device *dev = &pdev->dev; |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 99 | |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 100 | int ret = -ENOMEM; |
| 101 | |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 102 | exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL); |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 103 | if (!exynos) { |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 104 | dev_err(dev, "not enough memory\n"); |
| 105 | return -ENOMEM; |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 106 | } |
| 107 | |
Vivek Gautam | accefdd | 2012-11-03 18:00:27 +0530 | [diff] [blame] | 108 | /* |
| 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 Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 116 | platform_set_drvdata(pdev, exynos); |
| 117 | |
Felipe Balbi | d720f05 | 2012-07-19 14:01:10 +0300 | [diff] [blame] | 118 | ret = dwc3_exynos_register_phys(exynos); |
| 119 | if (ret) { |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 120 | dev_err(dev, "couldn't register PHYs\n"); |
| 121 | return ret; |
Felipe Balbi | d720f05 | 2012-07-19 14:01:10 +0300 | [diff] [blame] | 122 | } |
| 123 | |
Sebastian Andrzej Siewior | 124dafd | 2012-10-29 18:09:53 +0100 | [diff] [blame] | 124 | dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO); |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 125 | if (!dwc3) { |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 126 | dev_err(dev, "couldn't allocate dwc3 device\n"); |
| 127 | return -ENOMEM; |
| 128 | } |
| 129 | |
| 130 | clk = devm_clk_get(dev, "usbdrd30"); |
| 131 | if (IS_ERR(clk)) { |
| 132 | dev_err(dev, "couldn't get clock\n"); |
| 133 | ret = -EINVAL; |
Sebastian Andrzej Siewior | 124dafd | 2012-10-29 18:09:53 +0100 | [diff] [blame] | 134 | goto err1; |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 135 | } |
| 136 | |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 137 | dma_set_coherent_mask(&dwc3->dev, dev->coherent_dma_mask); |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 138 | |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 139 | dwc3->dev.parent = dev; |
| 140 | dwc3->dev.dma_mask = dev->dma_mask; |
| 141 | dwc3->dev.dma_parms = dev->dma_parms; |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 142 | exynos->dwc3 = dwc3; |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 143 | exynos->dev = dev; |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 144 | exynos->clk = clk; |
| 145 | |
| 146 | clk_enable(exynos->clk); |
| 147 | |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 148 | ret = platform_device_add_resources(dwc3, pdev->resource, |
| 149 | pdev->num_resources); |
| 150 | if (ret) { |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 151 | dev_err(dev, "couldn't add resources to dwc3 device\n"); |
| 152 | goto err2; |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | ret = platform_device_add(dwc3); |
| 156 | if (ret) { |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 157 | dev_err(dev, "failed to register dwc3 device\n"); |
| 158 | goto err2; |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | return 0; |
| 162 | |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 163 | err2: |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 164 | clk_disable(clk); |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 165 | err1: |
Jingoo Han | 20b97dc | 2012-11-13 11:20:49 +0900 | [diff] [blame] | 166 | platform_device_put(dwc3); |
| 167 | |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 168 | return ret; |
| 169 | } |
| 170 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 171 | static int dwc3_exynos_remove(struct platform_device *pdev) |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 172 | { |
| 173 | struct dwc3_exynos *exynos = platform_get_drvdata(pdev); |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 174 | |
| 175 | platform_device_unregister(exynos->dwc3); |
Felipe Balbi | d720f05 | 2012-07-19 14:01:10 +0300 | [diff] [blame] | 176 | platform_device_unregister(exynos->usb2_phy); |
| 177 | platform_device_unregister(exynos->usb3_phy); |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 178 | |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 179 | clk_disable(exynos->clk); |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 180 | |
| 181 | return 0; |
| 182 | } |
| 183 | |
Vivek Gautam | accefdd | 2012-11-03 18:00:27 +0530 | [diff] [blame] | 184 | #ifdef CONFIG_OF |
| 185 | static const struct of_device_id exynos_dwc3_match[] = { |
| 186 | { .compatible = "samsung,exynos-dwc3" }, |
| 187 | {}, |
| 188 | }; |
| 189 | MODULE_DEVICE_TABLE(of, exynos_dwc3_match); |
| 190 | #endif |
| 191 | |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 192 | static struct platform_driver dwc3_exynos_driver = { |
| 193 | .probe = dwc3_exynos_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 194 | .remove = dwc3_exynos_remove, |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 195 | .driver = { |
| 196 | .name = "exynos-dwc3", |
Vivek Gautam | accefdd | 2012-11-03 18:00:27 +0530 | [diff] [blame] | 197 | .of_match_table = of_match_ptr(exynos_dwc3_match), |
Anton Tikhomirov | d28a968 | 2012-02-15 17:04:56 +0900 | [diff] [blame] | 198 | }, |
| 199 | }; |
| 200 | |
| 201 | module_platform_driver(dwc3_exynos_driver); |
| 202 | |
| 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"); |