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