Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 1 | /* |
| 2 | * omap-usb2.c - USB PHY, talking to musb controller in OMAP. |
| 3 | * |
| 4 | * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * Author: Kishon Vijay Abraham I <kishon@ti.com> |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/slab.h> |
| 22 | #include <linux/of.h> |
| 23 | #include <linux/io.h> |
Kishon Vijay Abraham I | 6284be2 | 2014-03-03 17:08:14 +0530 | [diff] [blame] | 24 | #include <linux/phy/omap_usb.h> |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 25 | #include <linux/usb/phy_companion.h> |
| 26 | #include <linux/clk.h> |
| 27 | #include <linux/err.h> |
| 28 | #include <linux/pm_runtime.h> |
| 29 | #include <linux/delay.h> |
Kishon Vijay Abraham I | 14da699 | 2014-03-06 16:38:37 +0200 | [diff] [blame] | 30 | #include <linux/phy/omap_control_phy.h> |
Kishon Vijay Abraham I | 5d93d1e | 2013-09-27 11:53:26 +0530 | [diff] [blame] | 31 | #include <linux/phy/phy.h> |
Roger Quadros | 478b6c7 | 2013-10-03 18:12:32 +0300 | [diff] [blame] | 32 | #include <linux/of_platform.h> |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 33 | |
Austin Beam | 7e47240 | 2014-03-06 18:11:53 +0530 | [diff] [blame] | 34 | #define USB2PHY_DISCON_BYP_LATCH (1 << 31) |
| 35 | #define USB2PHY_ANA_CONFIG1 0x4c |
| 36 | |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 37 | /** |
| 38 | * omap_usb2_set_comparator - links the comparator present in the sytem with |
| 39 | * this phy |
| 40 | * @comparator - the companion phy(comparator) for this phy |
| 41 | * |
| 42 | * The phy companion driver should call this API passing the phy_companion |
| 43 | * filled with set_vbus and start_srp to be used by usb phy. |
| 44 | * |
| 45 | * For use by phy companion driver |
| 46 | */ |
| 47 | int omap_usb2_set_comparator(struct phy_companion *comparator) |
| 48 | { |
| 49 | struct omap_usb *phy; |
| 50 | struct usb_phy *x = usb_get_phy(USB_PHY_TYPE_USB2); |
| 51 | |
| 52 | if (IS_ERR(x)) |
| 53 | return -ENODEV; |
| 54 | |
| 55 | phy = phy_to_omapusb(x); |
| 56 | phy->comparator = comparator; |
| 57 | return 0; |
| 58 | } |
| 59 | EXPORT_SYMBOL_GPL(omap_usb2_set_comparator); |
| 60 | |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 61 | static int omap_usb_set_vbus(struct usb_otg *otg, bool enabled) |
| 62 | { |
Antoine Tenart | 19c1eac | 2014-10-30 18:41:14 +0100 | [diff] [blame] | 63 | struct omap_usb *phy = phy_to_omapusb(otg->usb_phy); |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 64 | |
| 65 | if (!phy->comparator) |
| 66 | return -ENODEV; |
| 67 | |
| 68 | return phy->comparator->set_vbus(phy->comparator, enabled); |
| 69 | } |
| 70 | |
| 71 | static int omap_usb_start_srp(struct usb_otg *otg) |
| 72 | { |
Antoine Tenart | 19c1eac | 2014-10-30 18:41:14 +0100 | [diff] [blame] | 73 | struct omap_usb *phy = phy_to_omapusb(otg->usb_phy); |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 74 | |
| 75 | if (!phy->comparator) |
| 76 | return -ENODEV; |
| 77 | |
| 78 | return phy->comparator->start_srp(phy->comparator); |
| 79 | } |
| 80 | |
| 81 | static int omap_usb_set_host(struct usb_otg *otg, struct usb_bus *host) |
| 82 | { |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 83 | otg->host = host; |
| 84 | if (!host) |
Antoine Tenart | e47d925 | 2014-10-30 18:41:13 +0100 | [diff] [blame] | 85 | otg->state = OTG_STATE_UNDEFINED; |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | static int omap_usb_set_peripheral(struct usb_otg *otg, |
| 91 | struct usb_gadget *gadget) |
| 92 | { |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 93 | otg->gadget = gadget; |
| 94 | if (!gadget) |
Antoine Tenart | e47d925 | 2014-10-30 18:41:13 +0100 | [diff] [blame] | 95 | otg->state = OTG_STATE_UNDEFINED; |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
Kishon Vijay Abraham I | 5d93d1e | 2013-09-27 11:53:26 +0530 | [diff] [blame] | 100 | static int omap_usb_power_off(struct phy *x) |
| 101 | { |
| 102 | struct omap_usb *phy = phy_get_drvdata(x); |
| 103 | |
Kishon Vijay Abraham I | 14da699 | 2014-03-06 16:38:37 +0200 | [diff] [blame] | 104 | omap_control_phy_power(phy->control_dev, 0); |
Kishon Vijay Abraham I | 5d93d1e | 2013-09-27 11:53:26 +0530 | [diff] [blame] | 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | static int omap_usb_power_on(struct phy *x) |
| 110 | { |
| 111 | struct omap_usb *phy = phy_get_drvdata(x); |
| 112 | |
Kishon Vijay Abraham I | 14da699 | 2014-03-06 16:38:37 +0200 | [diff] [blame] | 113 | omap_control_phy_power(phy->control_dev, 1); |
Kishon Vijay Abraham I | 5d93d1e | 2013-09-27 11:53:26 +0530 | [diff] [blame] | 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
Austin Beam | 7e47240 | 2014-03-06 18:11:53 +0530 | [diff] [blame] | 118 | static int omap_usb_init(struct phy *x) |
| 119 | { |
| 120 | struct omap_usb *phy = phy_get_drvdata(x); |
| 121 | u32 val; |
| 122 | |
| 123 | if (phy->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) { |
| 124 | /* |
| 125 | * |
| 126 | * Reduce the sensitivity of internal PHY by enabling the |
| 127 | * DISCON_BYP_LATCH of the USB2PHY_ANA_CONFIG1 register. This |
| 128 | * resolves issues with certain devices which can otherwise |
| 129 | * be prone to false disconnects. |
| 130 | * |
| 131 | */ |
| 132 | val = omap_usb_readl(phy->phy_base, USB2PHY_ANA_CONFIG1); |
| 133 | val |= USB2PHY_DISCON_BYP_LATCH; |
| 134 | omap_usb_writel(phy->phy_base, USB2PHY_ANA_CONFIG1, val); |
| 135 | } |
| 136 | |
| 137 | return 0; |
| 138 | } |
| 139 | |
Kishon Vijay Abraham I | 5d93d1e | 2013-09-27 11:53:26 +0530 | [diff] [blame] | 140 | static struct phy_ops ops = { |
Austin Beam | 7e47240 | 2014-03-06 18:11:53 +0530 | [diff] [blame] | 141 | .init = omap_usb_init, |
Kishon Vijay Abraham I | 5d93d1e | 2013-09-27 11:53:26 +0530 | [diff] [blame] | 142 | .power_on = omap_usb_power_on, |
| 143 | .power_off = omap_usb_power_off, |
| 144 | .owner = THIS_MODULE, |
| 145 | }; |
| 146 | |
George Cherian | 09a0168 | 2014-03-06 18:11:52 +0530 | [diff] [blame] | 147 | static const struct usb_phy_data omap_usb2_data = { |
| 148 | .label = "omap_usb2", |
| 149 | .flags = OMAP_USB2_HAS_START_SRP | OMAP_USB2_HAS_SET_VBUS, |
| 150 | }; |
| 151 | |
George Cherian | db68e80 | 2014-03-06 18:11:54 +0530 | [diff] [blame] | 152 | static const struct usb_phy_data omap5_usb2_data = { |
| 153 | .label = "omap5_usb2", |
| 154 | .flags = 0, |
| 155 | }; |
| 156 | |
Austin Beam | 7e47240 | 2014-03-06 18:11:53 +0530 | [diff] [blame] | 157 | static const struct usb_phy_data dra7x_usb2_data = { |
| 158 | .label = "dra7x_usb2", |
| 159 | .flags = OMAP_USB2_CALIBRATE_FALSE_DISCONNECT, |
| 160 | }; |
| 161 | |
George Cherian | 09a0168 | 2014-03-06 18:11:52 +0530 | [diff] [blame] | 162 | static const struct usb_phy_data am437x_usb2_data = { |
| 163 | .label = "am437x_usb2", |
| 164 | .flags = 0, |
| 165 | }; |
| 166 | |
| 167 | static const struct of_device_id omap_usb2_id_table[] = { |
| 168 | { |
| 169 | .compatible = "ti,omap-usb2", |
| 170 | .data = &omap_usb2_data, |
| 171 | }, |
| 172 | { |
George Cherian | db68e80 | 2014-03-06 18:11:54 +0530 | [diff] [blame] | 173 | .compatible = "ti,omap5-usb2", |
| 174 | .data = &omap5_usb2_data, |
| 175 | }, |
| 176 | { |
Austin Beam | 7e47240 | 2014-03-06 18:11:53 +0530 | [diff] [blame] | 177 | .compatible = "ti,dra7x-usb2", |
| 178 | .data = &dra7x_usb2_data, |
| 179 | }, |
| 180 | { |
George Cherian | 09a0168 | 2014-03-06 18:11:52 +0530 | [diff] [blame] | 181 | .compatible = "ti,am437x-usb2", |
| 182 | .data = &am437x_usb2_data, |
| 183 | }, |
| 184 | {}, |
| 185 | }; |
| 186 | MODULE_DEVICE_TABLE(of, omap_usb2_id_table); |
George Cherian | 09a0168 | 2014-03-06 18:11:52 +0530 | [diff] [blame] | 187 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 188 | static int omap_usb2_probe(struct platform_device *pdev) |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 189 | { |
Roger Quadros | 478b6c7 | 2013-10-03 18:12:32 +0300 | [diff] [blame] | 190 | struct omap_usb *phy; |
| 191 | struct phy *generic_phy; |
Austin Beam | 7e47240 | 2014-03-06 18:11:53 +0530 | [diff] [blame] | 192 | struct resource *res; |
Roger Quadros | 478b6c7 | 2013-10-03 18:12:32 +0300 | [diff] [blame] | 193 | struct phy_provider *phy_provider; |
| 194 | struct usb_otg *otg; |
| 195 | struct device_node *node = pdev->dev.of_node; |
| 196 | struct device_node *control_node; |
| 197 | struct platform_device *control_pdev; |
George Cherian | 09a0168 | 2014-03-06 18:11:52 +0530 | [diff] [blame] | 198 | const struct of_device_id *of_id; |
| 199 | struct usb_phy_data *phy_data; |
Roger Quadros | 478b6c7 | 2013-10-03 18:12:32 +0300 | [diff] [blame] | 200 | |
Axel Lin | 52a4a72 | 2015-03-05 18:20:07 +0800 | [diff] [blame] | 201 | of_id = of_match_device(omap_usb2_id_table, &pdev->dev); |
George Cherian | 09a0168 | 2014-03-06 18:11:52 +0530 | [diff] [blame] | 202 | |
| 203 | if (!of_id) |
Roger Quadros | 478b6c7 | 2013-10-03 18:12:32 +0300 | [diff] [blame] | 204 | return -EINVAL; |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 205 | |
George Cherian | 09a0168 | 2014-03-06 18:11:52 +0530 | [diff] [blame] | 206 | phy_data = (struct usb_phy_data *)of_id->data; |
| 207 | |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 208 | phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); |
Peter Griffin | 0b68253 | 2014-08-15 13:40:10 +0100 | [diff] [blame] | 209 | if (!phy) |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 210 | return -ENOMEM; |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 211 | |
| 212 | otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL); |
Peter Griffin | 0b68253 | 2014-08-15 13:40:10 +0100 | [diff] [blame] | 213 | if (!otg) |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 214 | return -ENOMEM; |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 215 | |
| 216 | phy->dev = &pdev->dev; |
| 217 | |
| 218 | phy->phy.dev = phy->dev; |
George Cherian | 09a0168 | 2014-03-06 18:11:52 +0530 | [diff] [blame] | 219 | phy->phy.label = phy_data->label; |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 220 | phy->phy.otg = otg; |
Kishon Vijay Abraham I | c11747f | 2013-01-25 08:03:24 +0530 | [diff] [blame] | 221 | phy->phy.type = USB_PHY_TYPE_USB2; |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 222 | |
Austin Beam | 7e47240 | 2014-03-06 18:11:53 +0530 | [diff] [blame] | 223 | if (phy_data->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) { |
| 224 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 225 | phy->phy_base = devm_ioremap_resource(&pdev->dev, res); |
Himangi Saraogi | 3df9fcd | 2014-07-10 11:55:00 +0530 | [diff] [blame] | 226 | if (IS_ERR(phy->phy_base)) |
| 227 | return PTR_ERR(phy->phy_base); |
Austin Beam | 7e47240 | 2014-03-06 18:11:53 +0530 | [diff] [blame] | 228 | phy->flags |= OMAP_USB2_CALIBRATE_FALSE_DISCONNECT; |
| 229 | } |
| 230 | |
Roger Quadros | 478b6c7 | 2013-10-03 18:12:32 +0300 | [diff] [blame] | 231 | control_node = of_parse_phandle(node, "ctrl-module", 0); |
| 232 | if (!control_node) { |
| 233 | dev_err(&pdev->dev, "Failed to get control device phandle\n"); |
| 234 | return -EINVAL; |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 235 | } |
| 236 | |
Roger Quadros | 478b6c7 | 2013-10-03 18:12:32 +0300 | [diff] [blame] | 237 | control_pdev = of_find_device_by_node(control_node); |
| 238 | if (!control_pdev) { |
| 239 | dev_err(&pdev->dev, "Failed to get control device\n"); |
| 240 | return -EINVAL; |
| 241 | } |
| 242 | |
| 243 | phy->control_dev = &control_pdev->dev; |
Kishon Vijay Abraham I | 14da699 | 2014-03-06 16:38:37 +0200 | [diff] [blame] | 244 | omap_control_phy_power(phy->control_dev, 0); |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 245 | |
| 246 | otg->set_host = omap_usb_set_host; |
| 247 | otg->set_peripheral = omap_usb_set_peripheral; |
George Cherian | 09a0168 | 2014-03-06 18:11:52 +0530 | [diff] [blame] | 248 | if (phy_data->flags & OMAP_USB2_HAS_SET_VBUS) |
| 249 | otg->set_vbus = omap_usb_set_vbus; |
| 250 | if (phy_data->flags & OMAP_USB2_HAS_START_SRP) |
| 251 | otg->start_srp = omap_usb_start_srp; |
Antoine Tenart | 19c1eac | 2014-10-30 18:41:14 +0100 | [diff] [blame] | 252 | otg->usb_phy = &phy->phy; |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 253 | |
Kishon Vijay Abraham I | 5d93d1e | 2013-09-27 11:53:26 +0530 | [diff] [blame] | 254 | platform_set_drvdata(pdev, phy); |
Oussama Ghorbel | f20531a | 2014-11-04 11:47:06 +0530 | [diff] [blame] | 255 | pm_runtime_enable(phy->dev); |
Kishon Vijay Abraham I | 5d93d1e | 2013-09-27 11:53:26 +0530 | [diff] [blame] | 256 | |
Heikki Krogerus | dbc9863 | 2014-11-19 17:28:21 +0200 | [diff] [blame] | 257 | generic_phy = devm_phy_create(phy->dev, NULL, &ops); |
Oussama Ghorbel | f20531a | 2014-11-04 11:47:06 +0530 | [diff] [blame] | 258 | if (IS_ERR(generic_phy)) { |
| 259 | pm_runtime_disable(phy->dev); |
Kishon Vijay Abraham I | 5d93d1e | 2013-09-27 11:53:26 +0530 | [diff] [blame] | 260 | return PTR_ERR(generic_phy); |
Oussama Ghorbel | f20531a | 2014-11-04 11:47:06 +0530 | [diff] [blame] | 261 | } |
Kishon Vijay Abraham I | 5d93d1e | 2013-09-27 11:53:26 +0530 | [diff] [blame] | 262 | |
| 263 | phy_set_drvdata(generic_phy, phy); |
| 264 | |
Kishon Vijay Abraham I | 64fe189 | 2014-02-17 14:29:25 +0530 | [diff] [blame] | 265 | phy_provider = devm_of_phy_provider_register(phy->dev, |
| 266 | of_phy_simple_xlate); |
Roger Quadros | eb82a3d | 2014-07-10 11:55:03 +0530 | [diff] [blame] | 267 | if (IS_ERR(phy_provider)) { |
| 268 | pm_runtime_disable(phy->dev); |
Kishon Vijay Abraham I | 64fe189 | 2014-02-17 14:29:25 +0530 | [diff] [blame] | 269 | return PTR_ERR(phy_provider); |
Roger Quadros | eb82a3d | 2014-07-10 11:55:03 +0530 | [diff] [blame] | 270 | } |
Kishon Vijay Abraham I | 64fe189 | 2014-02-17 14:29:25 +0530 | [diff] [blame] | 271 | |
Roger Quadros | 9f1d8ed | 2014-05-05 12:54:40 +0300 | [diff] [blame] | 272 | phy->wkupclk = devm_clk_get(phy->dev, "wkupclk"); |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 273 | if (IS_ERR(phy->wkupclk)) { |
Roger Quadros | 9f1d8ed | 2014-05-05 12:54:40 +0300 | [diff] [blame] | 274 | dev_warn(&pdev->dev, "unable to get wkupclk, trying old name\n"); |
| 275 | phy->wkupclk = devm_clk_get(phy->dev, "usb_phy_cm_clk32k"); |
| 276 | if (IS_ERR(phy->wkupclk)) { |
| 277 | dev_err(&pdev->dev, "unable to get usb_phy_cm_clk32k\n"); |
| 278 | return PTR_ERR(phy->wkupclk); |
| 279 | } else { |
| 280 | dev_warn(&pdev->dev, |
| 281 | "found usb_phy_cm_clk32k, please fix DTS\n"); |
| 282 | } |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 283 | } |
| 284 | clk_prepare(phy->wkupclk); |
| 285 | |
Roger Quadros | 9f1d8ed | 2014-05-05 12:54:40 +0300 | [diff] [blame] | 286 | phy->optclk = devm_clk_get(phy->dev, "refclk"); |
| 287 | if (IS_ERR(phy->optclk)) { |
| 288 | dev_dbg(&pdev->dev, "unable to get refclk, trying old name\n"); |
| 289 | phy->optclk = devm_clk_get(phy->dev, "usb_otg_ss_refclk960m"); |
| 290 | if (IS_ERR(phy->optclk)) { |
| 291 | dev_dbg(&pdev->dev, |
| 292 | "unable to get usb_otg_ss_refclk960m\n"); |
| 293 | } else { |
| 294 | dev_warn(&pdev->dev, |
| 295 | "found usb_otg_ss_refclk960m, please fix DTS\n"); |
| 296 | } |
Roger Quadros | 9f1d8ed | 2014-05-05 12:54:40 +0300 | [diff] [blame] | 297 | } |
Kishon Vijay Abraham I | 0c4c8bb | 2013-01-25 08:21:49 +0530 | [diff] [blame] | 298 | |
Axel Lin | b1ff323 | 2015-03-11 09:41:34 +0800 | [diff] [blame] | 299 | if (!IS_ERR(phy->optclk)) |
| 300 | clk_prepare(phy->optclk); |
| 301 | |
Kishon Vijay Abraham I | c11747f | 2013-01-25 08:03:24 +0530 | [diff] [blame] | 302 | usb_add_phy_dev(&phy->phy); |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 303 | |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 304 | return 0; |
| 305 | } |
| 306 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 307 | static int omap_usb2_remove(struct platform_device *pdev) |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 308 | { |
| 309 | struct omap_usb *phy = platform_get_drvdata(pdev); |
| 310 | |
| 311 | clk_unprepare(phy->wkupclk); |
Kishon Vijay Abraham I | 0c4c8bb | 2013-01-25 08:21:49 +0530 | [diff] [blame] | 312 | if (!IS_ERR(phy->optclk)) |
| 313 | clk_unprepare(phy->optclk); |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 314 | usb_remove_phy(&phy->phy); |
Roger Quadros | eb82a3d | 2014-07-10 11:55:03 +0530 | [diff] [blame] | 315 | pm_runtime_disable(phy->dev); |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
Rafael J. Wysocki | 7ba3705 | 2014-12-13 00:42:12 +0100 | [diff] [blame] | 320 | #ifdef CONFIG_PM |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 321 | |
| 322 | static int omap_usb2_runtime_suspend(struct device *dev) |
| 323 | { |
| 324 | struct platform_device *pdev = to_platform_device(dev); |
| 325 | struct omap_usb *phy = platform_get_drvdata(pdev); |
| 326 | |
| 327 | clk_disable(phy->wkupclk); |
Kishon Vijay Abraham I | 0c4c8bb | 2013-01-25 08:21:49 +0530 | [diff] [blame] | 328 | if (!IS_ERR(phy->optclk)) |
| 329 | clk_disable(phy->optclk); |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 330 | |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | static int omap_usb2_runtime_resume(struct device *dev) |
| 335 | { |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 336 | struct platform_device *pdev = to_platform_device(dev); |
| 337 | struct omap_usb *phy = platform_get_drvdata(pdev); |
Dan Carpenter | 0f82768 | 2013-08-21 11:41:22 +0300 | [diff] [blame] | 338 | int ret; |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 339 | |
| 340 | ret = clk_enable(phy->wkupclk); |
Kishon Vijay Abraham I | 0c4c8bb | 2013-01-25 08:21:49 +0530 | [diff] [blame] | 341 | if (ret < 0) { |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 342 | dev_err(phy->dev, "Failed to enable wkupclk %d\n", ret); |
Kishon Vijay Abraham I | 0c4c8bb | 2013-01-25 08:21:49 +0530 | [diff] [blame] | 343 | goto err0; |
| 344 | } |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 345 | |
Kishon Vijay Abraham I | 0c4c8bb | 2013-01-25 08:21:49 +0530 | [diff] [blame] | 346 | if (!IS_ERR(phy->optclk)) { |
| 347 | ret = clk_enable(phy->optclk); |
| 348 | if (ret < 0) { |
| 349 | dev_err(phy->dev, "Failed to enable optclk %d\n", ret); |
| 350 | goto err1; |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | return 0; |
| 355 | |
| 356 | err1: |
| 357 | clk_disable(phy->wkupclk); |
| 358 | |
| 359 | err0: |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 360 | return ret; |
| 361 | } |
| 362 | |
| 363 | static const struct dev_pm_ops omap_usb2_pm_ops = { |
| 364 | SET_RUNTIME_PM_OPS(omap_usb2_runtime_suspend, omap_usb2_runtime_resume, |
| 365 | NULL) |
| 366 | }; |
| 367 | |
| 368 | #define DEV_PM_OPS (&omap_usb2_pm_ops) |
| 369 | #else |
| 370 | #define DEV_PM_OPS NULL |
| 371 | #endif |
| 372 | |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 373 | static struct platform_driver omap_usb2_driver = { |
| 374 | .probe = omap_usb2_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 375 | .remove = omap_usb2_remove, |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 376 | .driver = { |
| 377 | .name = "omap-usb2", |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 378 | .pm = DEV_PM_OPS, |
Axel Lin | 52a4a72 | 2015-03-05 18:20:07 +0800 | [diff] [blame] | 379 | .of_match_table = omap_usb2_id_table, |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 380 | }, |
| 381 | }; |
| 382 | |
| 383 | module_platform_driver(omap_usb2_driver); |
| 384 | |
Axel Lin | dd64ad38 | 2015-03-07 00:01:21 +0800 | [diff] [blame] | 385 | MODULE_ALIAS("platform:omap_usb2"); |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 386 | MODULE_AUTHOR("Texas Instruments Inc."); |
| 387 | MODULE_DESCRIPTION("OMAP USB2 phy driver"); |
| 388 | MODULE_LICENSE("GPL v2"); |