Greg Kroah-Hartman | 5fd54ac | 2017-11-03 11:28:30 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 2 | /* |
| 3 | * SAMSUNG EXYNOS USB HOST OHCI Controller |
| 4 | * |
| 5 | * Copyright (C) 2011 Samsung Electronics Co.Ltd |
| 6 | * Author: Jingoo Han <jg1.han@samsung.com> |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/clk.h> |
Manjunath Goudar | 50a97e0 | 2013-09-21 16:38:38 +0530 | [diff] [blame] | 10 | #include <linux/dma-mapping.h> |
| 11 | #include <linux/io.h> |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/module.h> |
Vivek Gautam | d513893 | 2012-07-16 11:25:36 +0530 | [diff] [blame] | 14 | #include <linux/of.h> |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 15 | #include <linux/platform_device.h> |
Vivek Gautam | 7d28e54 | 2014-05-05 10:32:57 +0530 | [diff] [blame] | 16 | #include <linux/phy/phy.h> |
Manjunath Goudar | 50a97e0 | 2013-09-21 16:38:38 +0530 | [diff] [blame] | 17 | #include <linux/usb.h> |
| 18 | #include <linux/usb/hcd.h> |
Manjunath Goudar | 50a97e0 | 2013-09-21 16:38:38 +0530 | [diff] [blame] | 19 | |
| 20 | #include "ohci.h" |
| 21 | |
Krzysztof Kozlowski | dea7b20 | 2020-01-04 16:20:55 +0100 | [diff] [blame] | 22 | #define DRIVER_DESC "OHCI Exynos driver" |
Manjunath Goudar | 50a97e0 | 2013-09-21 16:38:38 +0530 | [diff] [blame] | 23 | |
| 24 | static const char hcd_name[] = "ohci-exynos"; |
| 25 | static struct hc_driver __read_mostly exynos_ohci_hc_driver; |
| 26 | |
| 27 | #define to_exynos_ohci(hcd) (struct exynos_ohci_hcd *)(hcd_to_ohci(hcd)->priv) |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 28 | |
Vivek Gautam | 7d28e54 | 2014-05-05 10:32:57 +0530 | [diff] [blame] | 29 | #define PHY_NUMBER 3 |
| 30 | |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 31 | struct exynos_ohci_hcd { |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 32 | struct clk *clk; |
Marek Szyprowski | 01d4071 | 2019-05-20 11:08:23 +0200 | [diff] [blame] | 33 | struct device_node *of_node; |
Vivek Gautam | 2db9416 | 2014-09-22 11:16:19 +0530 | [diff] [blame] | 34 | struct phy *phy[PHY_NUMBER]; |
Marek Szyprowski | 214b606 | 2019-07-26 10:14:52 +0200 | [diff] [blame] | 35 | bool legacy_phy; |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 36 | }; |
| 37 | |
Vivek Gautam | 7d28e54 | 2014-05-05 10:32:57 +0530 | [diff] [blame] | 38 | static int exynos_ohci_get_phy(struct device *dev, |
| 39 | struct exynos_ohci_hcd *exynos_ohci) |
| 40 | { |
| 41 | struct device_node *child; |
| 42 | struct phy *phy; |
Marek Szyprowski | 214b606 | 2019-07-26 10:14:52 +0200 | [diff] [blame] | 43 | int phy_number, num_phys; |
Vivek Gautam | 2db9416 | 2014-09-22 11:16:19 +0530 | [diff] [blame] | 44 | int ret; |
Vivek Gautam | 7d28e54 | 2014-05-05 10:32:57 +0530 | [diff] [blame] | 45 | |
Vivek Gautam | 2db9416 | 2014-09-22 11:16:19 +0530 | [diff] [blame] | 46 | /* Get PHYs for the controller */ |
Marek Szyprowski | 214b606 | 2019-07-26 10:14:52 +0200 | [diff] [blame] | 47 | num_phys = of_count_phandle_with_args(dev->of_node, "phys", |
| 48 | "#phy-cells"); |
| 49 | for (phy_number = 0; phy_number < num_phys; phy_number++) { |
| 50 | phy = devm_of_phy_get_by_index(dev, dev->of_node, phy_number); |
| 51 | if (IS_ERR(phy)) |
| 52 | return PTR_ERR(phy); |
| 53 | exynos_ohci->phy[phy_number] = phy; |
| 54 | } |
| 55 | if (num_phys > 0) |
| 56 | return 0; |
| 57 | |
| 58 | /* Get PHYs using legacy bindings */ |
Vivek Gautam | 7d28e54 | 2014-05-05 10:32:57 +0530 | [diff] [blame] | 59 | for_each_available_child_of_node(dev->of_node, child) { |
| 60 | ret = of_property_read_u32(child, "reg", &phy_number); |
| 61 | if (ret) { |
| 62 | dev_err(dev, "Failed to parse device tree\n"); |
| 63 | of_node_put(child); |
| 64 | return ret; |
| 65 | } |
| 66 | |
| 67 | if (phy_number >= PHY_NUMBER) { |
| 68 | dev_err(dev, "Invalid number of PHYs\n"); |
| 69 | of_node_put(child); |
| 70 | return -EINVAL; |
| 71 | } |
| 72 | |
Sachin Kamat | 473e92e | 2014-06-06 14:13:44 +0530 | [diff] [blame] | 73 | phy = devm_of_phy_get(dev, child, NULL); |
Vivek Gautam | 2db9416 | 2014-09-22 11:16:19 +0530 | [diff] [blame] | 74 | exynos_ohci->phy[phy_number] = phy; |
Vivek Gautam | 2db9416 | 2014-09-22 11:16:19 +0530 | [diff] [blame] | 75 | if (IS_ERR(phy)) { |
| 76 | ret = PTR_ERR(phy); |
| 77 | if (ret == -EPROBE_DEFER) { |
Krzysztof Kozlowski | 68bd6fc | 2017-01-07 10:41:41 +0200 | [diff] [blame] | 78 | of_node_put(child); |
Vivek Gautam | 2db9416 | 2014-09-22 11:16:19 +0530 | [diff] [blame] | 79 | return ret; |
| 80 | } else if (ret != -ENOSYS && ret != -ENODEV) { |
| 81 | dev_err(dev, |
| 82 | "Error retrieving usb2 phy: %d\n", ret); |
Krzysztof Kozlowski | 68bd6fc | 2017-01-07 10:41:41 +0200 | [diff] [blame] | 83 | of_node_put(child); |
Vivek Gautam | 2db9416 | 2014-09-22 11:16:19 +0530 | [diff] [blame] | 84 | return ret; |
| 85 | } |
| 86 | } |
Vivek Gautam | 2f7f41c | 2014-08-05 16:09:08 +0530 | [diff] [blame] | 87 | } |
| 88 | |
Marek Szyprowski | 214b606 | 2019-07-26 10:14:52 +0200 | [diff] [blame] | 89 | exynos_ohci->legacy_phy = true; |
Vivek Gautam | 2f7f41c | 2014-08-05 16:09:08 +0530 | [diff] [blame] | 90 | return 0; |
Vivek Gautam | 7d28e54 | 2014-05-05 10:32:57 +0530 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | static int exynos_ohci_phy_enable(struct device *dev) |
Vivek Gautam | ed993bf | 2013-01-22 18:30:43 +0530 | [diff] [blame] | 94 | { |
Vivek Gautam | 54969ed | 2014-05-05 10:33:42 +0530 | [diff] [blame] | 95 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Manjunath Goudar | 50a97e0 | 2013-09-21 16:38:38 +0530 | [diff] [blame] | 96 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); |
Vivek Gautam | 7d28e54 | 2014-05-05 10:32:57 +0530 | [diff] [blame] | 97 | int i; |
| 98 | int ret = 0; |
Vivek Gautam | ed993bf | 2013-01-22 18:30:43 +0530 | [diff] [blame] | 99 | |
Vivek Gautam | 7d28e54 | 2014-05-05 10:32:57 +0530 | [diff] [blame] | 100 | for (i = 0; ret == 0 && i < PHY_NUMBER; i++) |
Vivek Gautam | 2db9416 | 2014-09-22 11:16:19 +0530 | [diff] [blame] | 101 | if (!IS_ERR(exynos_ohci->phy[i])) |
| 102 | ret = phy_power_on(exynos_ohci->phy[i]); |
Vivek Gautam | 7d28e54 | 2014-05-05 10:32:57 +0530 | [diff] [blame] | 103 | if (ret) |
| 104 | for (i--; i >= 0; i--) |
Vivek Gautam | 2db9416 | 2014-09-22 11:16:19 +0530 | [diff] [blame] | 105 | if (!IS_ERR(exynos_ohci->phy[i])) |
| 106 | phy_power_off(exynos_ohci->phy[i]); |
Vivek Gautam | 7d28e54 | 2014-05-05 10:32:57 +0530 | [diff] [blame] | 107 | |
| 108 | return ret; |
Vivek Gautam | ed993bf | 2013-01-22 18:30:43 +0530 | [diff] [blame] | 109 | } |
| 110 | |
Vivek Gautam | 54969ed | 2014-05-05 10:33:42 +0530 | [diff] [blame] | 111 | static void exynos_ohci_phy_disable(struct device *dev) |
Vivek Gautam | ed993bf | 2013-01-22 18:30:43 +0530 | [diff] [blame] | 112 | { |
Vivek Gautam | 54969ed | 2014-05-05 10:33:42 +0530 | [diff] [blame] | 113 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Manjunath Goudar | 50a97e0 | 2013-09-21 16:38:38 +0530 | [diff] [blame] | 114 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); |
Vivek Gautam | 7d28e54 | 2014-05-05 10:32:57 +0530 | [diff] [blame] | 115 | int i; |
Vivek Gautam | ed993bf | 2013-01-22 18:30:43 +0530 | [diff] [blame] | 116 | |
Vivek Gautam | 7d28e54 | 2014-05-05 10:32:57 +0530 | [diff] [blame] | 117 | for (i = 0; i < PHY_NUMBER; i++) |
Vivek Gautam | 2db9416 | 2014-09-22 11:16:19 +0530 | [diff] [blame] | 118 | if (!IS_ERR(exynos_ohci->phy[i])) |
| 119 | phy_power_off(exynos_ohci->phy[i]); |
Vivek Gautam | ed993bf | 2013-01-22 18:30:43 +0530 | [diff] [blame] | 120 | } |
| 121 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 122 | static int exynos_ohci_probe(struct platform_device *pdev) |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 123 | { |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 124 | struct exynos_ohci_hcd *exynos_ohci; |
| 125 | struct usb_hcd *hcd; |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 126 | struct resource *res; |
| 127 | int irq; |
| 128 | int err; |
| 129 | |
Vivek Gautam | d513893 | 2012-07-16 11:25:36 +0530 | [diff] [blame] | 130 | /* |
| 131 | * Right now device-tree probed devices don't get dma_mask set. |
| 132 | * Since shared usb code relies on it, set it here for now. |
| 133 | * Once we move to full device tree support this will vanish off. |
| 134 | */ |
Russell King | e1fd734 | 2013-06-27 12:36:37 +0100 | [diff] [blame] | 135 | err = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
Russell King | 22d9d8e | 2013-06-10 16:28:49 +0100 | [diff] [blame] | 136 | if (err) |
| 137 | return err; |
Vivek Gautam | d513893 | 2012-07-16 11:25:36 +0530 | [diff] [blame] | 138 | |
Manjunath Goudar | 50a97e0 | 2013-09-21 16:38:38 +0530 | [diff] [blame] | 139 | hcd = usb_create_hcd(&exynos_ohci_hc_driver, |
| 140 | &pdev->dev, dev_name(&pdev->dev)); |
| 141 | if (!hcd) { |
| 142 | dev_err(&pdev->dev, "Unable to create HCD\n"); |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 143 | return -ENOMEM; |
Manjunath Goudar | 50a97e0 | 2013-09-21 16:38:38 +0530 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | exynos_ohci = to_exynos_ohci(hcd); |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 147 | |
Vivek Gautam | 7d28e54 | 2014-05-05 10:32:57 +0530 | [diff] [blame] | 148 | err = exynos_ohci_get_phy(&pdev->dev, exynos_ohci); |
| 149 | if (err) |
| 150 | goto fail_clk; |
Vivek Gautam | ed993bf | 2013-01-22 18:30:43 +0530 | [diff] [blame] | 151 | |
Jingoo Han | 60d80ad | 2012-10-04 16:11:50 +0900 | [diff] [blame] | 152 | exynos_ohci->clk = devm_clk_get(&pdev->dev, "usbhost"); |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 153 | |
| 154 | if (IS_ERR(exynos_ohci->clk)) { |
| 155 | dev_err(&pdev->dev, "Failed to get usbhost clock\n"); |
| 156 | err = PTR_ERR(exynos_ohci->clk); |
| 157 | goto fail_clk; |
| 158 | } |
| 159 | |
Thomas Abraham | c05c946 | 2012-10-03 08:41:37 +0900 | [diff] [blame] | 160 | err = clk_prepare_enable(exynos_ohci->clk); |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 161 | if (err) |
Jingoo Han | 60d80ad | 2012-10-04 16:11:50 +0900 | [diff] [blame] | 162 | goto fail_clk; |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 163 | |
| 164 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Vivek Gautam | bae00c1 | 2014-05-10 17:30:10 +0530 | [diff] [blame] | 165 | hcd->regs = devm_ioremap_resource(&pdev->dev, res); |
| 166 | if (IS_ERR(hcd->regs)) { |
| 167 | err = PTR_ERR(hcd->regs); |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 168 | goto fail_io; |
| 169 | } |
Varka Bhadram | b87a9c5 | 2014-11-04 07:51:13 +0530 | [diff] [blame] | 170 | hcd->rsrc_start = res->start; |
| 171 | hcd->rsrc_len = resource_size(res); |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 172 | |
| 173 | irq = platform_get_irq(pdev, 0); |
| 174 | if (!irq) { |
| 175 | dev_err(&pdev->dev, "Failed to get IRQ\n"); |
| 176 | err = -ENODEV; |
Jingoo Han | 390a0a7 | 2012-06-28 16:30:30 +0900 | [diff] [blame] | 177 | goto fail_io; |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 178 | } |
| 179 | |
Manjunath Goudar | 50a97e0 | 2013-09-21 16:38:38 +0530 | [diff] [blame] | 180 | platform_set_drvdata(pdev, hcd); |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 181 | |
Vivek Gautam | 7d28e54 | 2014-05-05 10:32:57 +0530 | [diff] [blame] | 182 | err = exynos_ohci_phy_enable(&pdev->dev); |
| 183 | if (err) { |
| 184 | dev_err(&pdev->dev, "Failed to enable USB phy\n"); |
| 185 | goto fail_io; |
| 186 | } |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 187 | |
Marek Szyprowski | 01d4071 | 2019-05-20 11:08:23 +0200 | [diff] [blame] | 188 | /* |
Marek Szyprowski | 214b606 | 2019-07-26 10:14:52 +0200 | [diff] [blame] | 189 | * Workaround: reset of_node pointer to avoid conflict between legacy |
| 190 | * Exynos OHCI port subnodes and generic USB device bindings |
Marek Szyprowski | 01d4071 | 2019-05-20 11:08:23 +0200 | [diff] [blame] | 191 | */ |
| 192 | exynos_ohci->of_node = pdev->dev.of_node; |
Marek Szyprowski | 214b606 | 2019-07-26 10:14:52 +0200 | [diff] [blame] | 193 | if (exynos_ohci->legacy_phy) |
| 194 | pdev->dev.of_node = NULL; |
Marek Szyprowski | 01d4071 | 2019-05-20 11:08:23 +0200 | [diff] [blame] | 195 | |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 196 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 197 | if (err) { |
| 198 | dev_err(&pdev->dev, "Failed to add USB HCD\n"); |
Vivek Gautam | ed993bf | 2013-01-22 18:30:43 +0530 | [diff] [blame] | 199 | goto fail_add_hcd; |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 200 | } |
Peter Chen | 3c9740a | 2013-11-05 10:46:02 +0800 | [diff] [blame] | 201 | device_wakeup_enable(hcd->self.controller); |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 202 | return 0; |
| 203 | |
Vivek Gautam | ed993bf | 2013-01-22 18:30:43 +0530 | [diff] [blame] | 204 | fail_add_hcd: |
Vivek Gautam | 54969ed | 2014-05-05 10:33:42 +0530 | [diff] [blame] | 205 | exynos_ohci_phy_disable(&pdev->dev); |
Marek Szyprowski | 01d4071 | 2019-05-20 11:08:23 +0200 | [diff] [blame] | 206 | pdev->dev.of_node = exynos_ohci->of_node; |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 207 | fail_io: |
Thomas Abraham | c05c946 | 2012-10-03 08:41:37 +0900 | [diff] [blame] | 208 | clk_disable_unprepare(exynos_ohci->clk); |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 209 | fail_clk: |
| 210 | usb_put_hcd(hcd); |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 211 | return err; |
| 212 | } |
| 213 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 214 | static int exynos_ohci_remove(struct platform_device *pdev) |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 215 | { |
Manjunath Goudar | 50a97e0 | 2013-09-21 16:38:38 +0530 | [diff] [blame] | 216 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 217 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 218 | |
Marek Szyprowski | 01d4071 | 2019-05-20 11:08:23 +0200 | [diff] [blame] | 219 | pdev->dev.of_node = exynos_ohci->of_node; |
| 220 | |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 221 | usb_remove_hcd(hcd); |
| 222 | |
Vivek Gautam | 54969ed | 2014-05-05 10:33:42 +0530 | [diff] [blame] | 223 | exynos_ohci_phy_disable(&pdev->dev); |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 224 | |
Thomas Abraham | c05c946 | 2012-10-03 08:41:37 +0900 | [diff] [blame] | 225 | clk_disable_unprepare(exynos_ohci->clk); |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 226 | |
| 227 | usb_put_hcd(hcd); |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 228 | |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | static void exynos_ohci_shutdown(struct platform_device *pdev) |
| 233 | { |
Manjunath Goudar | 50a97e0 | 2013-09-21 16:38:38 +0530 | [diff] [blame] | 234 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 235 | |
| 236 | if (hcd->driver->shutdown) |
| 237 | hcd->driver->shutdown(hcd); |
| 238 | } |
| 239 | |
| 240 | #ifdef CONFIG_PM |
| 241 | static int exynos_ohci_suspend(struct device *dev) |
| 242 | { |
Manjunath Goudar | 50a97e0 | 2013-09-21 16:38:38 +0530 | [diff] [blame] | 243 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 244 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); |
Majunath Goudar | 14982e3 | 2013-11-13 17:40:20 +0530 | [diff] [blame] | 245 | bool do_wakeup = device_may_wakeup(dev); |
Majunath Goudar | 14982e3 | 2013-11-13 17:40:20 +0530 | [diff] [blame] | 246 | int rc = ohci_suspend(hcd, do_wakeup); |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 247 | |
Majunath Goudar | 14982e3 | 2013-11-13 17:40:20 +0530 | [diff] [blame] | 248 | if (rc) |
| 249 | return rc; |
| 250 | |
Vivek Gautam | 54969ed | 2014-05-05 10:33:42 +0530 | [diff] [blame] | 251 | exynos_ohci_phy_disable(dev); |
Jingoo Han | e864abe | 2012-06-28 16:49:42 +0900 | [diff] [blame] | 252 | |
Thomas Abraham | c05c946 | 2012-10-03 08:41:37 +0900 | [diff] [blame] | 253 | clk_disable_unprepare(exynos_ohci->clk); |
Jingoo Han | e864abe | 2012-06-28 16:49:42 +0900 | [diff] [blame] | 254 | |
Majunath Goudar | 14982e3 | 2013-11-13 17:40:20 +0530 | [diff] [blame] | 255 | return 0; |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | static int exynos_ohci_resume(struct device *dev) |
| 259 | { |
Manjunath Goudar | 50a97e0 | 2013-09-21 16:38:38 +0530 | [diff] [blame] | 260 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 261 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); |
Vivek Gautam | 7d28e54 | 2014-05-05 10:32:57 +0530 | [diff] [blame] | 262 | int ret; |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 263 | |
Thomas Abraham | c05c946 | 2012-10-03 08:41:37 +0900 | [diff] [blame] | 264 | clk_prepare_enable(exynos_ohci->clk); |
Jingoo Han | e864abe | 2012-06-28 16:49:42 +0900 | [diff] [blame] | 265 | |
Vivek Gautam | 7d28e54 | 2014-05-05 10:32:57 +0530 | [diff] [blame] | 266 | ret = exynos_ohci_phy_enable(dev); |
| 267 | if (ret) { |
| 268 | dev_err(dev, "Failed to enable USB phy\n"); |
| 269 | clk_disable_unprepare(exynos_ohci->clk); |
| 270 | return ret; |
| 271 | } |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 272 | |
Florian Fainelli | cfa49b4 | 2012-10-08 15:11:29 +0200 | [diff] [blame] | 273 | ohci_resume(hcd, false); |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 274 | |
| 275 | return 0; |
| 276 | } |
| 277 | #else |
| 278 | #define exynos_ohci_suspend NULL |
| 279 | #define exynos_ohci_resume NULL |
| 280 | #endif |
| 281 | |
Manjunath Goudar | 50a97e0 | 2013-09-21 16:38:38 +0530 | [diff] [blame] | 282 | static const struct ohci_driver_overrides exynos_overrides __initconst = { |
| 283 | .extra_priv_size = sizeof(struct exynos_ohci_hcd), |
| 284 | }; |
| 285 | |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 286 | static const struct dev_pm_ops exynos_ohci_pm_ops = { |
| 287 | .suspend = exynos_ohci_suspend, |
| 288 | .resume = exynos_ohci_resume, |
| 289 | }; |
| 290 | |
Vivek Gautam | d513893 | 2012-07-16 11:25:36 +0530 | [diff] [blame] | 291 | #ifdef CONFIG_OF |
| 292 | static const struct of_device_id exynos_ohci_match[] = { |
Vivek Gautam | 6e24777 | 2013-01-24 19:15:29 +0530 | [diff] [blame] | 293 | { .compatible = "samsung,exynos4210-ohci" }, |
Vivek Gautam | d513893 | 2012-07-16 11:25:36 +0530 | [diff] [blame] | 294 | {}, |
| 295 | }; |
| 296 | MODULE_DEVICE_TABLE(of, exynos_ohci_match); |
| 297 | #endif |
| 298 | |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 299 | static struct platform_driver exynos_ohci_driver = { |
| 300 | .probe = exynos_ohci_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 301 | .remove = exynos_ohci_remove, |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 302 | .shutdown = exynos_ohci_shutdown, |
| 303 | .driver = { |
| 304 | .name = "exynos-ohci", |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 305 | .pm = &exynos_ohci_pm_ops, |
Vivek Gautam | d513893 | 2012-07-16 11:25:36 +0530 | [diff] [blame] | 306 | .of_match_table = of_match_ptr(exynos_ohci_match), |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 307 | } |
| 308 | }; |
Manjunath Goudar | 50a97e0 | 2013-09-21 16:38:38 +0530 | [diff] [blame] | 309 | static int __init ohci_exynos_init(void) |
| 310 | { |
| 311 | if (usb_disabled()) |
| 312 | return -ENODEV; |
| 313 | |
| 314 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); |
| 315 | ohci_init_driver(&exynos_ohci_hc_driver, &exynos_overrides); |
| 316 | return platform_driver_register(&exynos_ohci_driver); |
| 317 | } |
| 318 | module_init(ohci_exynos_init); |
| 319 | |
| 320 | static void __exit ohci_exynos_cleanup(void) |
| 321 | { |
| 322 | platform_driver_unregister(&exynos_ohci_driver); |
| 323 | } |
| 324 | module_exit(ohci_exynos_cleanup); |
Jingoo Han | 6219424 | 2011-12-23 11:20:54 +0900 | [diff] [blame] | 325 | |
| 326 | MODULE_ALIAS("platform:exynos-ohci"); |
| 327 | MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>"); |
Manjunath Goudar | 50a97e0 | 2013-09-21 16:38:38 +0530 | [diff] [blame] | 328 | MODULE_LICENSE("GPL v2"); |