Greg Kroah-Hartman | 5fd54ac | 2017-11-03 11:28:30 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 2 | /* |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 3 | * SAMSUNG EXYNOS USB HOST EHCI Controller |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2011 Samsung Electronics Co.Ltd |
| 6 | * Author: Jingoo Han <jg1.han@samsung.com> |
| 7 | * Author: Joonyoung Shim <jy0922.shim@samsung.com> |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/clk.h> |
Manjunath Goudar | 7edb3da | 2013-04-02 18:24:01 +0200 | [diff] [blame] | 11 | #include <linux/dma-mapping.h> |
| 12 | #include <linux/io.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/module.h> |
Vivek Gautam | 2c026e2 | 2012-07-16 11:25:37 +0530 | [diff] [blame] | 15 | #include <linux/of.h> |
Vivek Gautam | fd81d59 | 2012-07-17 10:10:50 +0530 | [diff] [blame] | 16 | #include <linux/of_gpio.h> |
Kamil Debski | 1c17675 | 2014-05-05 10:32:28 +0530 | [diff] [blame] | 17 | #include <linux/phy/phy.h> |
Manjunath Goudar | 7edb3da | 2013-04-02 18:24:01 +0200 | [diff] [blame] | 18 | #include <linux/platform_device.h> |
Manjunath Goudar | 7edb3da | 2013-04-02 18:24:01 +0200 | [diff] [blame] | 19 | #include <linux/usb.h> |
| 20 | #include <linux/usb/hcd.h> |
Manjunath Goudar | 7edb3da | 2013-04-02 18:24:01 +0200 | [diff] [blame] | 21 | |
| 22 | #include "ehci.h" |
| 23 | |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 24 | #define DRIVER_DESC "EHCI EXYNOS driver" |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 25 | |
Jingoo Han | 88555a6 | 2012-03-05 10:40:14 +0900 | [diff] [blame] | 26 | #define EHCI_INSNREG00(base) (base + 0x90) |
| 27 | #define EHCI_INSNREG00_ENA_INCR16 (0x1 << 25) |
| 28 | #define EHCI_INSNREG00_ENA_INCR8 (0x1 << 24) |
| 29 | #define EHCI_INSNREG00_ENA_INCR4 (0x1 << 23) |
| 30 | #define EHCI_INSNREG00_ENA_INCRX_ALIGN (0x1 << 22) |
| 31 | #define EHCI_INSNREG00_ENABLE_DMA_BURST \ |
| 32 | (EHCI_INSNREG00_ENA_INCR16 | EHCI_INSNREG00_ENA_INCR8 | \ |
| 33 | EHCI_INSNREG00_ENA_INCR4 | EHCI_INSNREG00_ENA_INCRX_ALIGN) |
| 34 | |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 35 | static const char hcd_name[] = "ehci-exynos"; |
| 36 | static struct hc_driver __read_mostly exynos_ehci_hc_driver; |
Manjunath Goudar | 7edb3da | 2013-04-02 18:24:01 +0200 | [diff] [blame] | 37 | |
Kamil Debski | 1c17675 | 2014-05-05 10:32:28 +0530 | [diff] [blame] | 38 | #define PHY_NUMBER 3 |
| 39 | |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 40 | struct exynos_ehci_hcd { |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 41 | struct clk *clk; |
Vivek Gautam | 46c1cda | 2014-09-29 11:54:14 +0530 | [diff] [blame] | 42 | struct phy *phy[PHY_NUMBER]; |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 43 | }; |
| 44 | |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 45 | #define to_exynos_ehci(hcd) (struct exynos_ehci_hcd *)(hcd_to_ehci(hcd)->priv) |
Vivek Gautam | d233c19 | 2013-01-22 18:30:42 +0530 | [diff] [blame] | 46 | |
Kamil Debski | 1c17675 | 2014-05-05 10:32:28 +0530 | [diff] [blame] | 47 | static int exynos_ehci_get_phy(struct device *dev, |
| 48 | struct exynos_ehci_hcd *exynos_ehci) |
| 49 | { |
| 50 | struct device_node *child; |
| 51 | struct phy *phy; |
| 52 | int phy_number; |
Vivek Gautam | 46c1cda | 2014-09-29 11:54:14 +0530 | [diff] [blame] | 53 | int ret; |
Kamil Debski | 1c17675 | 2014-05-05 10:32:28 +0530 | [diff] [blame] | 54 | |
Vivek Gautam | 46c1cda | 2014-09-29 11:54:14 +0530 | [diff] [blame] | 55 | /* Get PHYs for the controller */ |
Kamil Debski | 1c17675 | 2014-05-05 10:32:28 +0530 | [diff] [blame] | 56 | for_each_available_child_of_node(dev->of_node, child) { |
| 57 | ret = of_property_read_u32(child, "reg", &phy_number); |
| 58 | if (ret) { |
| 59 | dev_err(dev, "Failed to parse device tree\n"); |
| 60 | of_node_put(child); |
| 61 | return ret; |
| 62 | } |
| 63 | |
| 64 | if (phy_number >= PHY_NUMBER) { |
| 65 | dev_err(dev, "Invalid number of PHYs\n"); |
| 66 | of_node_put(child); |
| 67 | return -EINVAL; |
| 68 | } |
| 69 | |
Sachin Kamat | 14ad5a9 | 2014-06-06 14:13:45 +0530 | [diff] [blame] | 70 | phy = devm_of_phy_get(dev, child, NULL); |
Vivek Gautam | 46c1cda | 2014-09-29 11:54:14 +0530 | [diff] [blame] | 71 | exynos_ehci->phy[phy_number] = phy; |
Vivek Gautam | 46c1cda | 2014-09-29 11:54:14 +0530 | [diff] [blame] | 72 | if (IS_ERR(phy)) { |
| 73 | ret = PTR_ERR(phy); |
| 74 | if (ret == -EPROBE_DEFER) { |
Krzysztof Kozlowski | 3f6026b | 2017-01-07 10:41:40 +0200 | [diff] [blame] | 75 | of_node_put(child); |
Vivek Gautam | 46c1cda | 2014-09-29 11:54:14 +0530 | [diff] [blame] | 76 | return ret; |
| 77 | } else if (ret != -ENOSYS && ret != -ENODEV) { |
| 78 | dev_err(dev, |
| 79 | "Error retrieving usb2 phy: %d\n", ret); |
Krzysztof Kozlowski | 3f6026b | 2017-01-07 10:41:40 +0200 | [diff] [blame] | 80 | of_node_put(child); |
Vivek Gautam | 46c1cda | 2014-09-29 11:54:14 +0530 | [diff] [blame] | 81 | return ret; |
| 82 | } |
| 83 | } |
Vivek Gautam | 2f7f41c | 2014-08-05 16:09:08 +0530 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | return 0; |
Kamil Debski | 1c17675 | 2014-05-05 10:32:28 +0530 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | static int exynos_ehci_phy_enable(struct device *dev) |
| 90 | { |
| 91 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 92 | struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); |
| 93 | int i; |
| 94 | int ret = 0; |
| 95 | |
Kamil Debski | 1c17675 | 2014-05-05 10:32:28 +0530 | [diff] [blame] | 96 | for (i = 0; ret == 0 && i < PHY_NUMBER; i++) |
Vivek Gautam | 46c1cda | 2014-09-29 11:54:14 +0530 | [diff] [blame] | 97 | if (!IS_ERR(exynos_ehci->phy[i])) |
| 98 | ret = phy_power_on(exynos_ehci->phy[i]); |
Kamil Debski | 1c17675 | 2014-05-05 10:32:28 +0530 | [diff] [blame] | 99 | if (ret) |
| 100 | for (i--; i >= 0; i--) |
Vivek Gautam | 46c1cda | 2014-09-29 11:54:14 +0530 | [diff] [blame] | 101 | if (!IS_ERR(exynos_ehci->phy[i])) |
| 102 | phy_power_off(exynos_ehci->phy[i]); |
Kamil Debski | 1c17675 | 2014-05-05 10:32:28 +0530 | [diff] [blame] | 103 | |
| 104 | return ret; |
| 105 | } |
| 106 | |
| 107 | static void exynos_ehci_phy_disable(struct device *dev) |
| 108 | { |
| 109 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 110 | struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); |
| 111 | int i; |
| 112 | |
Kamil Debski | 1c17675 | 2014-05-05 10:32:28 +0530 | [diff] [blame] | 113 | for (i = 0; i < PHY_NUMBER; i++) |
Vivek Gautam | 46c1cda | 2014-09-29 11:54:14 +0530 | [diff] [blame] | 114 | if (!IS_ERR(exynos_ehci->phy[i])) |
| 115 | phy_power_off(exynos_ehci->phy[i]); |
Kamil Debski | 1c17675 | 2014-05-05 10:32:28 +0530 | [diff] [blame] | 116 | } |
| 117 | |
Vivek Gautam | 91a9677 | 2014-05-05 10:34:25 +0530 | [diff] [blame] | 118 | static void exynos_setup_vbus_gpio(struct device *dev) |
Vivek Gautam | fd81d59 | 2012-07-17 10:10:50 +0530 | [diff] [blame] | 119 | { |
| 120 | int err; |
| 121 | int gpio; |
| 122 | |
Doug Anderson | 3f3b55b | 2013-03-14 20:15:37 -0700 | [diff] [blame] | 123 | if (!dev->of_node) |
Vivek Gautam | fd81d59 | 2012-07-17 10:10:50 +0530 | [diff] [blame] | 124 | return; |
| 125 | |
Doug Anderson | 3f3b55b | 2013-03-14 20:15:37 -0700 | [diff] [blame] | 126 | gpio = of_get_named_gpio(dev->of_node, "samsung,vbus-gpio", 0); |
Vivek Gautam | fd81d59 | 2012-07-17 10:10:50 +0530 | [diff] [blame] | 127 | if (!gpio_is_valid(gpio)) |
| 128 | return; |
| 129 | |
Doug Anderson | 3f3b55b | 2013-03-14 20:15:37 -0700 | [diff] [blame] | 130 | err = devm_gpio_request_one(dev, gpio, GPIOF_OUT_INIT_HIGH, |
| 131 | "ehci_vbus_gpio"); |
Vivek Gautam | fd81d59 | 2012-07-17 10:10:50 +0530 | [diff] [blame] | 132 | if (err) |
Doug Anderson | 3f3b55b | 2013-03-14 20:15:37 -0700 | [diff] [blame] | 133 | dev_err(dev, "can't request ehci vbus gpio %d", gpio); |
Vivek Gautam | fd81d59 | 2012-07-17 10:10:50 +0530 | [diff] [blame] | 134 | } |
| 135 | |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 136 | static int exynos_ehci_probe(struct platform_device *pdev) |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 137 | { |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 138 | struct exynos_ehci_hcd *exynos_ehci; |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 139 | struct usb_hcd *hcd; |
| 140 | struct ehci_hcd *ehci; |
| 141 | struct resource *res; |
| 142 | int irq; |
| 143 | int err; |
| 144 | |
Vivek Gautam | 2c026e2 | 2012-07-16 11:25:37 +0530 | [diff] [blame] | 145 | /* |
| 146 | * Right now device-tree probed devices don't get dma_mask set. |
| 147 | * Since shared usb code relies on it, set it here for now. |
| 148 | * Once we move to full device tree support this will vanish off. |
| 149 | */ |
Linus Torvalds | 8ceafbf | 2013-11-14 07:55:21 +0900 | [diff] [blame] | 150 | err = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 151 | if (err) |
| 152 | return err; |
Vivek Gautam | 2c026e2 | 2012-07-16 11:25:37 +0530 | [diff] [blame] | 153 | |
Vivek Gautam | 91a9677 | 2014-05-05 10:34:25 +0530 | [diff] [blame] | 154 | exynos_setup_vbus_gpio(&pdev->dev); |
Vivek Gautam | fd81d59 | 2012-07-17 10:10:50 +0530 | [diff] [blame] | 155 | |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 156 | hcd = usb_create_hcd(&exynos_ehci_hc_driver, |
Manjunath Goudar | 7edb3da | 2013-04-02 18:24:01 +0200 | [diff] [blame] | 157 | &pdev->dev, dev_name(&pdev->dev)); |
| 158 | if (!hcd) { |
| 159 | dev_err(&pdev->dev, "Unable to create HCD\n"); |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 160 | return -ENOMEM; |
Manjunath Goudar | 7edb3da | 2013-04-02 18:24:01 +0200 | [diff] [blame] | 161 | } |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 162 | exynos_ehci = to_exynos_ehci(hcd); |
Thomas Abraham | e6b0166f | 2013-05-27 18:42:12 +0900 | [diff] [blame] | 163 | |
| 164 | if (of_device_is_compatible(pdev->dev.of_node, |
Jingoo Han | 57ae160 | 2013-10-10 16:41:19 +0900 | [diff] [blame] | 165 | "samsung,exynos5440-ehci")) |
Thomas Abraham | e6b0166f | 2013-05-27 18:42:12 +0900 | [diff] [blame] | 166 | goto skip_phy; |
Thomas Abraham | e6b0166f | 2013-05-27 18:42:12 +0900 | [diff] [blame] | 167 | |
Kamil Debski | 1c17675 | 2014-05-05 10:32:28 +0530 | [diff] [blame] | 168 | err = exynos_ehci_get_phy(&pdev->dev, exynos_ehci); |
| 169 | if (err) |
| 170 | goto fail_clk; |
Vivek Gautam | d233c19 | 2013-01-22 18:30:42 +0530 | [diff] [blame] | 171 | |
Thomas Abraham | e6b0166f | 2013-05-27 18:42:12 +0900 | [diff] [blame] | 172 | skip_phy: |
| 173 | |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 174 | exynos_ehci->clk = devm_clk_get(&pdev->dev, "usbhost"); |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 175 | |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 176 | if (IS_ERR(exynos_ehci->clk)) { |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 177 | dev_err(&pdev->dev, "Failed to get usbhost clock\n"); |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 178 | err = PTR_ERR(exynos_ehci->clk); |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 179 | goto fail_clk; |
| 180 | } |
| 181 | |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 182 | err = clk_prepare_enable(exynos_ehci->clk); |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 183 | if (err) |
Julia Lawall | 63fd0ae | 2012-07-30 16:43:44 +0200 | [diff] [blame] | 184 | goto fail_clk; |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 185 | |
| 186 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Vivek Gautam | 4e24bde | 2014-05-10 17:30:05 +0530 | [diff] [blame] | 187 | hcd->regs = devm_ioremap_resource(&pdev->dev, res); |
| 188 | if (IS_ERR(hcd->regs)) { |
| 189 | err = PTR_ERR(hcd->regs); |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 190 | goto fail_io; |
| 191 | } |
| 192 | |
Varka Bhadram | 35df647 | 2014-11-04 07:51:33 +0530 | [diff] [blame] | 193 | hcd->rsrc_start = res->start; |
| 194 | hcd->rsrc_len = resource_size(res); |
| 195 | |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 196 | irq = platform_get_irq(pdev, 0); |
| 197 | if (!irq) { |
| 198 | dev_err(&pdev->dev, "Failed to get IRQ\n"); |
| 199 | err = -ENODEV; |
Jingoo Han | 9cb0756 | 2012-06-28 16:29:46 +0900 | [diff] [blame] | 200 | goto fail_io; |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 201 | } |
| 202 | |
Kamil Debski | 1c17675 | 2014-05-05 10:32:28 +0530 | [diff] [blame] | 203 | err = exynos_ehci_phy_enable(&pdev->dev); |
| 204 | if (err) { |
| 205 | dev_err(&pdev->dev, "Failed to enable USB phy\n"); |
| 206 | goto fail_io; |
| 207 | } |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 208 | |
| 209 | ehci = hcd_to_ehci(hcd); |
| 210 | ehci->caps = hcd->regs; |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 211 | |
Jingoo Han | 88555a6 | 2012-03-05 10:40:14 +0900 | [diff] [blame] | 212 | /* DMA burst Enable */ |
| 213 | writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs)); |
| 214 | |
Yong Zhang | b5dd18d | 2011-09-07 16:10:52 +0800 | [diff] [blame] | 215 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 216 | if (err) { |
| 217 | dev_err(&pdev->dev, "Failed to add USB HCD\n"); |
Vivek Gautam | d233c19 | 2013-01-22 18:30:42 +0530 | [diff] [blame] | 218 | goto fail_add_hcd; |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 219 | } |
Peter Chen | 3c9740a | 2013-11-05 10:46:02 +0800 | [diff] [blame] | 220 | device_wakeup_enable(hcd->self.controller); |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 221 | |
Vivek Gautam | bbcd85a | 2013-04-09 18:42:11 +0530 | [diff] [blame] | 222 | platform_set_drvdata(pdev, hcd); |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 223 | |
| 224 | return 0; |
| 225 | |
Vivek Gautam | d233c19 | 2013-01-22 18:30:42 +0530 | [diff] [blame] | 226 | fail_add_hcd: |
Kamil Debski | 1c17675 | 2014-05-05 10:32:28 +0530 | [diff] [blame] | 227 | exynos_ehci_phy_disable(&pdev->dev); |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 228 | fail_io: |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 229 | clk_disable_unprepare(exynos_ehci->clk); |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 230 | fail_clk: |
| 231 | usb_put_hcd(hcd); |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 232 | return err; |
| 233 | } |
| 234 | |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 235 | static int exynos_ehci_remove(struct platform_device *pdev) |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 236 | { |
Manjunath Goudar | 7edb3da | 2013-04-02 18:24:01 +0200 | [diff] [blame] | 237 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 238 | struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 239 | |
| 240 | usb_remove_hcd(hcd); |
| 241 | |
Kamil Debski | 1c17675 | 2014-05-05 10:32:28 +0530 | [diff] [blame] | 242 | exynos_ehci_phy_disable(&pdev->dev); |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 243 | |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 244 | clk_disable_unprepare(exynos_ehci->clk); |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 245 | |
| 246 | usb_put_hcd(hcd); |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 247 | |
| 248 | return 0; |
| 249 | } |
| 250 | |
Jingoo Han | 1acb30e | 2011-05-20 20:48:33 +0900 | [diff] [blame] | 251 | #ifdef CONFIG_PM |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 252 | static int exynos_ehci_suspend(struct device *dev) |
Jingoo Han | 1acb30e | 2011-05-20 20:48:33 +0900 | [diff] [blame] | 253 | { |
Manjunath Goudar | 7edb3da | 2013-04-02 18:24:01 +0200 | [diff] [blame] | 254 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 255 | struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); |
Manjunath Goudar | 7edb3da | 2013-04-02 18:24:01 +0200 | [diff] [blame] | 256 | |
Alan Stern | c5cf921 | 2012-06-28 11:19:02 -0400 | [diff] [blame] | 257 | bool do_wakeup = device_may_wakeup(dev); |
Alan Stern | c5cf921 | 2012-06-28 11:19:02 -0400 | [diff] [blame] | 258 | int rc; |
Jingoo Han | 1acb30e | 2011-05-20 20:48:33 +0900 | [diff] [blame] | 259 | |
Alan Stern | c5cf921 | 2012-06-28 11:19:02 -0400 | [diff] [blame] | 260 | rc = ehci_suspend(hcd, do_wakeup); |
Vivek Gautam | d721751 | 2014-04-10 15:58:01 +0530 | [diff] [blame] | 261 | if (rc) |
| 262 | return rc; |
Jingoo Han | 1acb30e | 2011-05-20 20:48:33 +0900 | [diff] [blame] | 263 | |
Kamil Debski | 1c17675 | 2014-05-05 10:32:28 +0530 | [diff] [blame] | 264 | exynos_ehci_phy_disable(dev); |
Jingoo Han | 1acb30e | 2011-05-20 20:48:33 +0900 | [diff] [blame] | 265 | |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 266 | clk_disable_unprepare(exynos_ehci->clk); |
Jingoo Han | 8b4fc8c | 2012-04-13 11:06:36 +0900 | [diff] [blame] | 267 | |
Jingoo Han | 1acb30e | 2011-05-20 20:48:33 +0900 | [diff] [blame] | 268 | return rc; |
| 269 | } |
| 270 | |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 271 | static int exynos_ehci_resume(struct device *dev) |
Jingoo Han | 1acb30e | 2011-05-20 20:48:33 +0900 | [diff] [blame] | 272 | { |
Manjunath Goudar | 7edb3da | 2013-04-02 18:24:01 +0200 | [diff] [blame] | 273 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 274 | struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); |
Kamil Debski | 1c17675 | 2014-05-05 10:32:28 +0530 | [diff] [blame] | 275 | int ret; |
Jingoo Han | 1acb30e | 2011-05-20 20:48:33 +0900 | [diff] [blame] | 276 | |
Arvind Yadav | 264ffb1 | 2017-06-12 16:45:14 +0530 | [diff] [blame] | 277 | ret = clk_prepare_enable(exynos_ehci->clk); |
| 278 | if (ret) |
| 279 | return ret; |
Jingoo Han | 8b4fc8c | 2012-04-13 11:06:36 +0900 | [diff] [blame] | 280 | |
Kamil Debski | 1c17675 | 2014-05-05 10:32:28 +0530 | [diff] [blame] | 281 | ret = exynos_ehci_phy_enable(dev); |
| 282 | if (ret) { |
| 283 | dev_err(dev, "Failed to enable USB phy\n"); |
| 284 | clk_disable_unprepare(exynos_ehci->clk); |
| 285 | return ret; |
| 286 | } |
Jingoo Han | 1acb30e | 2011-05-20 20:48:33 +0900 | [diff] [blame] | 287 | |
Jingoo Han | 88555a6 | 2012-03-05 10:40:14 +0900 | [diff] [blame] | 288 | /* DMA burst Enable */ |
| 289 | writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs)); |
| 290 | |
Alan Stern | c5cf921 | 2012-06-28 11:19:02 -0400 | [diff] [blame] | 291 | ehci_resume(hcd, false); |
Jingoo Han | 1acb30e | 2011-05-20 20:48:33 +0900 | [diff] [blame] | 292 | return 0; |
| 293 | } |
| 294 | #else |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 295 | #define exynos_ehci_suspend NULL |
| 296 | #define exynos_ehci_resume NULL |
Jingoo Han | 1acb30e | 2011-05-20 20:48:33 +0900 | [diff] [blame] | 297 | #endif |
| 298 | |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 299 | static const struct dev_pm_ops exynos_ehci_pm_ops = { |
| 300 | .suspend = exynos_ehci_suspend, |
| 301 | .resume = exynos_ehci_resume, |
Jingoo Han | 1acb30e | 2011-05-20 20:48:33 +0900 | [diff] [blame] | 302 | }; |
| 303 | |
Vivek Gautam | 2c026e2 | 2012-07-16 11:25:37 +0530 | [diff] [blame] | 304 | #ifdef CONFIG_OF |
| 305 | static const struct of_device_id exynos_ehci_match[] = { |
Vivek Gautam | 6e24777 | 2013-01-24 19:15:29 +0530 | [diff] [blame] | 306 | { .compatible = "samsung,exynos4210-ehci" }, |
Thomas Abraham | e6b0166f | 2013-05-27 18:42:12 +0900 | [diff] [blame] | 307 | { .compatible = "samsung,exynos5440-ehci" }, |
Vivek Gautam | 2c026e2 | 2012-07-16 11:25:37 +0530 | [diff] [blame] | 308 | {}, |
| 309 | }; |
| 310 | MODULE_DEVICE_TABLE(of, exynos_ehci_match); |
| 311 | #endif |
| 312 | |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 313 | static struct platform_driver exynos_ehci_driver = { |
| 314 | .probe = exynos_ehci_probe, |
| 315 | .remove = exynos_ehci_remove, |
Roger Quadros | aaf6b52 | 2013-07-22 15:04:50 +0300 | [diff] [blame] | 316 | .shutdown = usb_hcd_platform_shutdown, |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 317 | .driver = { |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 318 | .name = "exynos-ehci", |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 319 | .pm = &exynos_ehci_pm_ops, |
Vivek Gautam | 2c026e2 | 2012-07-16 11:25:37 +0530 | [diff] [blame] | 320 | .of_match_table = of_match_ptr(exynos_ehci_match), |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 321 | } |
| 322 | }; |
Nicolas Pitre | edc8c54 | 2016-04-27 13:28:32 -0400 | [diff] [blame] | 323 | static const struct ehci_driver_overrides exynos_overrides __initconst = { |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 324 | .extra_priv_size = sizeof(struct exynos_ehci_hcd), |
Manjunath Goudar | 7edb3da | 2013-04-02 18:24:01 +0200 | [diff] [blame] | 325 | }; |
Joonyoung Shim | 1bcc5aa | 2011-04-08 14:08:50 +0900 | [diff] [blame] | 326 | |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 327 | static int __init ehci_exynos_init(void) |
Manjunath Goudar | 7edb3da | 2013-04-02 18:24:01 +0200 | [diff] [blame] | 328 | { |
| 329 | if (usb_disabled()) |
| 330 | return -ENODEV; |
| 331 | |
| 332 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 333 | ehci_init_driver(&exynos_ehci_hc_driver, &exynos_overrides); |
| 334 | return platform_driver_register(&exynos_ehci_driver); |
Manjunath Goudar | 7edb3da | 2013-04-02 18:24:01 +0200 | [diff] [blame] | 335 | } |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 336 | module_init(ehci_exynos_init); |
Manjunath Goudar | 7edb3da | 2013-04-02 18:24:01 +0200 | [diff] [blame] | 337 | |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 338 | static void __exit ehci_exynos_cleanup(void) |
Manjunath Goudar | 7edb3da | 2013-04-02 18:24:01 +0200 | [diff] [blame] | 339 | { |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 340 | platform_driver_unregister(&exynos_ehci_driver); |
Manjunath Goudar | 7edb3da | 2013-04-02 18:24:01 +0200 | [diff] [blame] | 341 | } |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 342 | module_exit(ehci_exynos_cleanup); |
Manjunath Goudar | 7edb3da | 2013-04-02 18:24:01 +0200 | [diff] [blame] | 343 | |
| 344 | MODULE_DESCRIPTION(DRIVER_DESC); |
Jingoo Han | 29824c16 | 2013-10-10 16:42:47 +0900 | [diff] [blame] | 345 | MODULE_ALIAS("platform:exynos-ehci"); |
Manjunath Goudar | 7edb3da | 2013-04-02 18:24:01 +0200 | [diff] [blame] | 346 | MODULE_AUTHOR("Jingoo Han"); |
| 347 | MODULE_AUTHOR("Joonyoung Shim"); |
| 348 | MODULE_LICENSE("GPL v2"); |