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