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