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> |
Kishon Vijay Abraham I | 9955a783 | 2015-12-21 14:24:13 +0530 | [diff] [blame] | 32 | #include <linux/mfd/syscon.h> |
| 33 | #include <linux/regmap.h> |
Roger Quadros | 478b6c7 | 2013-10-03 18:12:32 +0300 | [diff] [blame] | 34 | #include <linux/of_platform.h> |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 35 | |
Austin Beam | 7e47240 | 2014-03-06 18:11:53 +0530 | [diff] [blame] | 36 | #define USB2PHY_DISCON_BYP_LATCH (1 << 31) |
| 37 | #define USB2PHY_ANA_CONFIG1 0x4c |
| 38 | |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 39 | /** |
| 40 | * omap_usb2_set_comparator - links the comparator present in the sytem with |
| 41 | * this phy |
| 42 | * @comparator - the companion phy(comparator) for this phy |
| 43 | * |
| 44 | * The phy companion driver should call this API passing the phy_companion |
| 45 | * filled with set_vbus and start_srp to be used by usb phy. |
| 46 | * |
| 47 | * For use by phy companion driver |
| 48 | */ |
| 49 | int omap_usb2_set_comparator(struct phy_companion *comparator) |
| 50 | { |
| 51 | struct omap_usb *phy; |
| 52 | struct usb_phy *x = usb_get_phy(USB_PHY_TYPE_USB2); |
| 53 | |
| 54 | if (IS_ERR(x)) |
| 55 | return -ENODEV; |
| 56 | |
| 57 | phy = phy_to_omapusb(x); |
| 58 | phy->comparator = comparator; |
| 59 | return 0; |
| 60 | } |
| 61 | EXPORT_SYMBOL_GPL(omap_usb2_set_comparator); |
| 62 | |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 63 | static int omap_usb_set_vbus(struct usb_otg *otg, bool enabled) |
| 64 | { |
Antoine Tenart | 19c1eac | 2014-10-30 18:41:14 +0100 | [diff] [blame] | 65 | struct omap_usb *phy = phy_to_omapusb(otg->usb_phy); |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 66 | |
| 67 | if (!phy->comparator) |
| 68 | return -ENODEV; |
| 69 | |
| 70 | return phy->comparator->set_vbus(phy->comparator, enabled); |
| 71 | } |
| 72 | |
| 73 | static int omap_usb_start_srp(struct usb_otg *otg) |
| 74 | { |
Antoine Tenart | 19c1eac | 2014-10-30 18:41:14 +0100 | [diff] [blame] | 75 | struct omap_usb *phy = phy_to_omapusb(otg->usb_phy); |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 76 | |
| 77 | if (!phy->comparator) |
| 78 | return -ENODEV; |
| 79 | |
| 80 | return phy->comparator->start_srp(phy->comparator); |
| 81 | } |
| 82 | |
| 83 | static int omap_usb_set_host(struct usb_otg *otg, struct usb_bus *host) |
| 84 | { |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 85 | otg->host = host; |
| 86 | if (!host) |
Antoine Tenart | e47d925 | 2014-10-30 18:41:13 +0100 | [diff] [blame] | 87 | otg->state = OTG_STATE_UNDEFINED; |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | static int omap_usb_set_peripheral(struct usb_otg *otg, |
| 93 | struct usb_gadget *gadget) |
| 94 | { |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 95 | otg->gadget = gadget; |
| 96 | if (!gadget) |
Antoine Tenart | e47d925 | 2014-10-30 18:41:13 +0100 | [diff] [blame] | 97 | otg->state = OTG_STATE_UNDEFINED; |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
Kishon Vijay Abraham I | 9955a783 | 2015-12-21 14:24:13 +0530 | [diff] [blame] | 102 | static int omap_usb_phy_power(struct omap_usb *phy, int on) |
| 103 | { |
| 104 | u32 val; |
| 105 | int ret; |
| 106 | |
| 107 | if (!phy->syscon_phy_power) { |
| 108 | omap_control_phy_power(phy->control_dev, on); |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | if (on) |
| 113 | val = phy->power_on; |
| 114 | else |
| 115 | val = phy->power_off; |
| 116 | |
| 117 | ret = regmap_update_bits(phy->syscon_phy_power, phy->power_reg, |
| 118 | phy->mask, val); |
| 119 | return ret; |
| 120 | } |
| 121 | |
Kishon Vijay Abraham I | 5d93d1e | 2013-09-27 11:53:26 +0530 | [diff] [blame] | 122 | static int omap_usb_power_off(struct phy *x) |
| 123 | { |
| 124 | struct omap_usb *phy = phy_get_drvdata(x); |
| 125 | |
Kishon Vijay Abraham I | 9955a783 | 2015-12-21 14:24:13 +0530 | [diff] [blame] | 126 | return omap_usb_phy_power(phy, false); |
Kishon Vijay Abraham I | 5d93d1e | 2013-09-27 11:53:26 +0530 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | static int omap_usb_power_on(struct phy *x) |
| 130 | { |
| 131 | struct omap_usb *phy = phy_get_drvdata(x); |
| 132 | |
Kishon Vijay Abraham I | 9955a783 | 2015-12-21 14:24:13 +0530 | [diff] [blame] | 133 | return omap_usb_phy_power(phy, true); |
Kishon Vijay Abraham I | 5d93d1e | 2013-09-27 11:53:26 +0530 | [diff] [blame] | 134 | } |
| 135 | |
Sekhar Nori | 80fc666 | 2016-08-23 11:57:39 +0300 | [diff] [blame] | 136 | static int omap_usb2_disable_clocks(struct omap_usb *phy) |
| 137 | { |
| 138 | clk_disable(phy->wkupclk); |
| 139 | if (!IS_ERR(phy->optclk)) |
| 140 | clk_disable(phy->optclk); |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | static int omap_usb2_enable_clocks(struct omap_usb *phy) |
| 146 | { |
| 147 | int ret; |
| 148 | |
| 149 | ret = clk_enable(phy->wkupclk); |
| 150 | if (ret < 0) { |
| 151 | dev_err(phy->dev, "Failed to enable wkupclk %d\n", ret); |
| 152 | goto err0; |
| 153 | } |
| 154 | |
| 155 | if (!IS_ERR(phy->optclk)) { |
| 156 | ret = clk_enable(phy->optclk); |
| 157 | if (ret < 0) { |
| 158 | dev_err(phy->dev, "Failed to enable optclk %d\n", ret); |
| 159 | goto err1; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | return 0; |
| 164 | |
| 165 | err1: |
| 166 | clk_disable(phy->wkupclk); |
| 167 | |
| 168 | err0: |
| 169 | return ret; |
| 170 | } |
| 171 | |
Austin Beam | 7e47240 | 2014-03-06 18:11:53 +0530 | [diff] [blame] | 172 | static int omap_usb_init(struct phy *x) |
| 173 | { |
| 174 | struct omap_usb *phy = phy_get_drvdata(x); |
| 175 | u32 val; |
| 176 | |
Sekhar Nori | 80fc666 | 2016-08-23 11:57:39 +0300 | [diff] [blame] | 177 | omap_usb2_enable_clocks(phy); |
| 178 | |
Austin Beam | 7e47240 | 2014-03-06 18:11:53 +0530 | [diff] [blame] | 179 | if (phy->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) { |
| 180 | /* |
| 181 | * |
| 182 | * Reduce the sensitivity of internal PHY by enabling the |
| 183 | * DISCON_BYP_LATCH of the USB2PHY_ANA_CONFIG1 register. This |
| 184 | * resolves issues with certain devices which can otherwise |
| 185 | * be prone to false disconnects. |
| 186 | * |
| 187 | */ |
| 188 | val = omap_usb_readl(phy->phy_base, USB2PHY_ANA_CONFIG1); |
| 189 | val |= USB2PHY_DISCON_BYP_LATCH; |
| 190 | omap_usb_writel(phy->phy_base, USB2PHY_ANA_CONFIG1, val); |
| 191 | } |
| 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | |
Sekhar Nori | 80fc666 | 2016-08-23 11:57:39 +0300 | [diff] [blame] | 196 | static int omap_usb_exit(struct phy *x) |
| 197 | { |
| 198 | struct omap_usb *phy = phy_get_drvdata(x); |
| 199 | |
| 200 | return omap_usb2_disable_clocks(phy); |
| 201 | } |
| 202 | |
Axel Lin | 4a9e5ca | 2015-07-15 15:33:51 +0800 | [diff] [blame] | 203 | static const struct phy_ops ops = { |
Austin Beam | 7e47240 | 2014-03-06 18:11:53 +0530 | [diff] [blame] | 204 | .init = omap_usb_init, |
Sekhar Nori | 80fc666 | 2016-08-23 11:57:39 +0300 | [diff] [blame] | 205 | .exit = omap_usb_exit, |
Kishon Vijay Abraham I | 5d93d1e | 2013-09-27 11:53:26 +0530 | [diff] [blame] | 206 | .power_on = omap_usb_power_on, |
| 207 | .power_off = omap_usb_power_off, |
| 208 | .owner = THIS_MODULE, |
| 209 | }; |
| 210 | |
George Cherian | 09a0168 | 2014-03-06 18:11:52 +0530 | [diff] [blame] | 211 | static const struct usb_phy_data omap_usb2_data = { |
| 212 | .label = "omap_usb2", |
| 213 | .flags = OMAP_USB2_HAS_START_SRP | OMAP_USB2_HAS_SET_VBUS, |
Kishon Vijay Abraham I | 9955a783 | 2015-12-21 14:24:13 +0530 | [diff] [blame] | 214 | .mask = OMAP_DEV_PHY_PD, |
| 215 | .power_off = OMAP_DEV_PHY_PD, |
George Cherian | 09a0168 | 2014-03-06 18:11:52 +0530 | [diff] [blame] | 216 | }; |
| 217 | |
George Cherian | db68e80 | 2014-03-06 18:11:54 +0530 | [diff] [blame] | 218 | static const struct usb_phy_data omap5_usb2_data = { |
| 219 | .label = "omap5_usb2", |
| 220 | .flags = 0, |
Kishon Vijay Abraham I | 9955a783 | 2015-12-21 14:24:13 +0530 | [diff] [blame] | 221 | .mask = OMAP_DEV_PHY_PD, |
| 222 | .power_off = OMAP_DEV_PHY_PD, |
George Cherian | db68e80 | 2014-03-06 18:11:54 +0530 | [diff] [blame] | 223 | }; |
| 224 | |
Austin Beam | 7e47240 | 2014-03-06 18:11:53 +0530 | [diff] [blame] | 225 | static const struct usb_phy_data dra7x_usb2_data = { |
| 226 | .label = "dra7x_usb2", |
| 227 | .flags = OMAP_USB2_CALIBRATE_FALSE_DISCONNECT, |
Kishon Vijay Abraham I | 9955a783 | 2015-12-21 14:24:13 +0530 | [diff] [blame] | 228 | .mask = OMAP_DEV_PHY_PD, |
| 229 | .power_off = OMAP_DEV_PHY_PD, |
| 230 | }; |
| 231 | |
| 232 | static const struct usb_phy_data dra7x_usb2_phy2_data = { |
| 233 | .label = "dra7x_usb2_phy2", |
| 234 | .flags = OMAP_USB2_CALIBRATE_FALSE_DISCONNECT, |
| 235 | .mask = OMAP_USB2_PHY_PD, |
| 236 | .power_off = OMAP_USB2_PHY_PD, |
Austin Beam | 7e47240 | 2014-03-06 18:11:53 +0530 | [diff] [blame] | 237 | }; |
| 238 | |
George Cherian | 09a0168 | 2014-03-06 18:11:52 +0530 | [diff] [blame] | 239 | static const struct usb_phy_data am437x_usb2_data = { |
| 240 | .label = "am437x_usb2", |
| 241 | .flags = 0, |
Kishon Vijay Abraham I | 9955a783 | 2015-12-21 14:24:13 +0530 | [diff] [blame] | 242 | .mask = AM437X_USB2_PHY_PD | AM437X_USB2_OTG_PD | |
| 243 | AM437X_USB2_OTGVDET_EN | AM437X_USB2_OTGSESSEND_EN, |
| 244 | .power_on = AM437X_USB2_OTGVDET_EN | AM437X_USB2_OTGSESSEND_EN, |
| 245 | .power_off = AM437X_USB2_PHY_PD | AM437X_USB2_OTG_PD, |
George Cherian | 09a0168 | 2014-03-06 18:11:52 +0530 | [diff] [blame] | 246 | }; |
| 247 | |
| 248 | static const struct of_device_id omap_usb2_id_table[] = { |
| 249 | { |
| 250 | .compatible = "ti,omap-usb2", |
| 251 | .data = &omap_usb2_data, |
| 252 | }, |
| 253 | { |
George Cherian | db68e80 | 2014-03-06 18:11:54 +0530 | [diff] [blame] | 254 | .compatible = "ti,omap5-usb2", |
| 255 | .data = &omap5_usb2_data, |
| 256 | }, |
| 257 | { |
Austin Beam | 7e47240 | 2014-03-06 18:11:53 +0530 | [diff] [blame] | 258 | .compatible = "ti,dra7x-usb2", |
| 259 | .data = &dra7x_usb2_data, |
| 260 | }, |
| 261 | { |
Kishon Vijay Abraham I | 9955a783 | 2015-12-21 14:24:13 +0530 | [diff] [blame] | 262 | .compatible = "ti,dra7x-usb2-phy2", |
| 263 | .data = &dra7x_usb2_phy2_data, |
| 264 | }, |
| 265 | { |
George Cherian | 09a0168 | 2014-03-06 18:11:52 +0530 | [diff] [blame] | 266 | .compatible = "ti,am437x-usb2", |
| 267 | .data = &am437x_usb2_data, |
| 268 | }, |
| 269 | {}, |
| 270 | }; |
| 271 | MODULE_DEVICE_TABLE(of, omap_usb2_id_table); |
George Cherian | 09a0168 | 2014-03-06 18:11:52 +0530 | [diff] [blame] | 272 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 273 | static int omap_usb2_probe(struct platform_device *pdev) |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 274 | { |
Roger Quadros | 478b6c7 | 2013-10-03 18:12:32 +0300 | [diff] [blame] | 275 | struct omap_usb *phy; |
| 276 | struct phy *generic_phy; |
Austin Beam | 7e47240 | 2014-03-06 18:11:53 +0530 | [diff] [blame] | 277 | struct resource *res; |
Roger Quadros | 478b6c7 | 2013-10-03 18:12:32 +0300 | [diff] [blame] | 278 | struct phy_provider *phy_provider; |
| 279 | struct usb_otg *otg; |
| 280 | struct device_node *node = pdev->dev.of_node; |
| 281 | struct device_node *control_node; |
| 282 | struct platform_device *control_pdev; |
George Cherian | 09a0168 | 2014-03-06 18:11:52 +0530 | [diff] [blame] | 283 | const struct of_device_id *of_id; |
| 284 | struct usb_phy_data *phy_data; |
Roger Quadros | 478b6c7 | 2013-10-03 18:12:32 +0300 | [diff] [blame] | 285 | |
Axel Lin | 52a4a72 | 2015-03-05 18:20:07 +0800 | [diff] [blame] | 286 | of_id = of_match_device(omap_usb2_id_table, &pdev->dev); |
George Cherian | 09a0168 | 2014-03-06 18:11:52 +0530 | [diff] [blame] | 287 | |
| 288 | if (!of_id) |
Roger Quadros | 478b6c7 | 2013-10-03 18:12:32 +0300 | [diff] [blame] | 289 | return -EINVAL; |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 290 | |
George Cherian | 09a0168 | 2014-03-06 18:11:52 +0530 | [diff] [blame] | 291 | phy_data = (struct usb_phy_data *)of_id->data; |
| 292 | |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 293 | phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); |
Peter Griffin | 0b68253 | 2014-08-15 13:40:10 +0100 | [diff] [blame] | 294 | if (!phy) |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 295 | return -ENOMEM; |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 296 | |
| 297 | otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL); |
Peter Griffin | 0b68253 | 2014-08-15 13:40:10 +0100 | [diff] [blame] | 298 | if (!otg) |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 299 | return -ENOMEM; |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 300 | |
| 301 | phy->dev = &pdev->dev; |
| 302 | |
| 303 | phy->phy.dev = phy->dev; |
George Cherian | 09a0168 | 2014-03-06 18:11:52 +0530 | [diff] [blame] | 304 | phy->phy.label = phy_data->label; |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 305 | phy->phy.otg = otg; |
Kishon Vijay Abraham I | c11747f | 2013-01-25 08:03:24 +0530 | [diff] [blame] | 306 | phy->phy.type = USB_PHY_TYPE_USB2; |
Kishon Vijay Abraham I | 9955a783 | 2015-12-21 14:24:13 +0530 | [diff] [blame] | 307 | phy->mask = phy_data->mask; |
| 308 | phy->power_on = phy_data->power_on; |
| 309 | phy->power_off = phy_data->power_off; |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 310 | |
Austin Beam | 7e47240 | 2014-03-06 18:11:53 +0530 | [diff] [blame] | 311 | if (phy_data->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) { |
| 312 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 313 | phy->phy_base = devm_ioremap_resource(&pdev->dev, res); |
Himangi Saraogi | 3df9fcd | 2014-07-10 11:55:00 +0530 | [diff] [blame] | 314 | if (IS_ERR(phy->phy_base)) |
| 315 | return PTR_ERR(phy->phy_base); |
Austin Beam | 7e47240 | 2014-03-06 18:11:53 +0530 | [diff] [blame] | 316 | phy->flags |= OMAP_USB2_CALIBRATE_FALSE_DISCONNECT; |
| 317 | } |
| 318 | |
Kishon Vijay Abraham I | 9955a783 | 2015-12-21 14:24:13 +0530 | [diff] [blame] | 319 | phy->syscon_phy_power = syscon_regmap_lookup_by_phandle(node, |
| 320 | "syscon-phy-power"); |
| 321 | if (IS_ERR(phy->syscon_phy_power)) { |
| 322 | dev_dbg(&pdev->dev, |
| 323 | "can't get syscon-phy-power, using control device\n"); |
| 324 | phy->syscon_phy_power = NULL; |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 325 | |
Kishon Vijay Abraham I | 9955a783 | 2015-12-21 14:24:13 +0530 | [diff] [blame] | 326 | control_node = of_parse_phandle(node, "ctrl-module", 0); |
| 327 | if (!control_node) { |
| 328 | dev_err(&pdev->dev, |
| 329 | "Failed to get control device phandle\n"); |
| 330 | return -EINVAL; |
| 331 | } |
Roger Quadros | 478b6c7 | 2013-10-03 18:12:32 +0300 | [diff] [blame] | 332 | |
Kishon Vijay Abraham I | 9955a783 | 2015-12-21 14:24:13 +0530 | [diff] [blame] | 333 | control_pdev = of_find_device_by_node(control_node); |
| 334 | if (!control_pdev) { |
| 335 | dev_err(&pdev->dev, "Failed to get control device\n"); |
| 336 | return -EINVAL; |
| 337 | } |
| 338 | phy->control_dev = &control_pdev->dev; |
| 339 | } else { |
| 340 | if (of_property_read_u32_index(node, |
| 341 | "syscon-phy-power", 1, |
| 342 | &phy->power_reg)) { |
| 343 | dev_err(&pdev->dev, |
| 344 | "couldn't get power reg. offset\n"); |
| 345 | return -EINVAL; |
| 346 | } |
| 347 | } |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 348 | |
| 349 | otg->set_host = omap_usb_set_host; |
| 350 | otg->set_peripheral = omap_usb_set_peripheral; |
George Cherian | 09a0168 | 2014-03-06 18:11:52 +0530 | [diff] [blame] | 351 | if (phy_data->flags & OMAP_USB2_HAS_SET_VBUS) |
| 352 | otg->set_vbus = omap_usb_set_vbus; |
| 353 | if (phy_data->flags & OMAP_USB2_HAS_START_SRP) |
| 354 | otg->start_srp = omap_usb_start_srp; |
Antoine Tenart | 19c1eac | 2014-10-30 18:41:14 +0100 | [diff] [blame] | 355 | otg->usb_phy = &phy->phy; |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 356 | |
Kishon Vijay Abraham I | 5d93d1e | 2013-09-27 11:53:26 +0530 | [diff] [blame] | 357 | platform_set_drvdata(pdev, phy); |
Oussama Ghorbel | f20531a | 2014-11-04 11:47:06 +0530 | [diff] [blame] | 358 | pm_runtime_enable(phy->dev); |
Kishon Vijay Abraham I | 5d93d1e | 2013-09-27 11:53:26 +0530 | [diff] [blame] | 359 | |
Heikki Krogerus | dbc9863 | 2014-11-19 17:28:21 +0200 | [diff] [blame] | 360 | generic_phy = devm_phy_create(phy->dev, NULL, &ops); |
Oussama Ghorbel | f20531a | 2014-11-04 11:47:06 +0530 | [diff] [blame] | 361 | if (IS_ERR(generic_phy)) { |
| 362 | pm_runtime_disable(phy->dev); |
Kishon Vijay Abraham I | 5d93d1e | 2013-09-27 11:53:26 +0530 | [diff] [blame] | 363 | return PTR_ERR(generic_phy); |
Oussama Ghorbel | f20531a | 2014-11-04 11:47:06 +0530 | [diff] [blame] | 364 | } |
Kishon Vijay Abraham I | 5d93d1e | 2013-09-27 11:53:26 +0530 | [diff] [blame] | 365 | |
| 366 | phy_set_drvdata(generic_phy, phy); |
Kishon Vijay Abraham I | 86c574e | 2015-12-21 14:24:12 +0530 | [diff] [blame] | 367 | omap_usb_power_off(generic_phy); |
Kishon Vijay Abraham I | 5d93d1e | 2013-09-27 11:53:26 +0530 | [diff] [blame] | 368 | |
Kishon Vijay Abraham I | 64fe189 | 2014-02-17 14:29:25 +0530 | [diff] [blame] | 369 | phy_provider = devm_of_phy_provider_register(phy->dev, |
| 370 | of_phy_simple_xlate); |
Roger Quadros | eb82a3d | 2014-07-10 11:55:03 +0530 | [diff] [blame] | 371 | if (IS_ERR(phy_provider)) { |
| 372 | pm_runtime_disable(phy->dev); |
Kishon Vijay Abraham I | 64fe189 | 2014-02-17 14:29:25 +0530 | [diff] [blame] | 373 | return PTR_ERR(phy_provider); |
Roger Quadros | eb82a3d | 2014-07-10 11:55:03 +0530 | [diff] [blame] | 374 | } |
Kishon Vijay Abraham I | 64fe189 | 2014-02-17 14:29:25 +0530 | [diff] [blame] | 375 | |
Roger Quadros | 9f1d8ed | 2014-05-05 12:54:40 +0300 | [diff] [blame] | 376 | phy->wkupclk = devm_clk_get(phy->dev, "wkupclk"); |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 377 | if (IS_ERR(phy->wkupclk)) { |
Roger Quadros | 9f1d8ed | 2014-05-05 12:54:40 +0300 | [diff] [blame] | 378 | dev_warn(&pdev->dev, "unable to get wkupclk, trying old name\n"); |
| 379 | phy->wkupclk = devm_clk_get(phy->dev, "usb_phy_cm_clk32k"); |
| 380 | if (IS_ERR(phy->wkupclk)) { |
| 381 | dev_err(&pdev->dev, "unable to get usb_phy_cm_clk32k\n"); |
Kishon Vijay Abraham I | 4581f79 | 2015-05-04 22:07:33 +0530 | [diff] [blame] | 382 | pm_runtime_disable(phy->dev); |
Roger Quadros | 9f1d8ed | 2014-05-05 12:54:40 +0300 | [diff] [blame] | 383 | return PTR_ERR(phy->wkupclk); |
| 384 | } else { |
| 385 | dev_warn(&pdev->dev, |
| 386 | "found usb_phy_cm_clk32k, please fix DTS\n"); |
| 387 | } |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 388 | } |
| 389 | clk_prepare(phy->wkupclk); |
| 390 | |
Roger Quadros | 9f1d8ed | 2014-05-05 12:54:40 +0300 | [diff] [blame] | 391 | phy->optclk = devm_clk_get(phy->dev, "refclk"); |
| 392 | if (IS_ERR(phy->optclk)) { |
| 393 | dev_dbg(&pdev->dev, "unable to get refclk, trying old name\n"); |
| 394 | phy->optclk = devm_clk_get(phy->dev, "usb_otg_ss_refclk960m"); |
| 395 | if (IS_ERR(phy->optclk)) { |
| 396 | dev_dbg(&pdev->dev, |
| 397 | "unable to get usb_otg_ss_refclk960m\n"); |
| 398 | } else { |
| 399 | dev_warn(&pdev->dev, |
| 400 | "found usb_otg_ss_refclk960m, please fix DTS\n"); |
| 401 | } |
Roger Quadros | 9f1d8ed | 2014-05-05 12:54:40 +0300 | [diff] [blame] | 402 | } |
Kishon Vijay Abraham I | 0c4c8bb | 2013-01-25 08:21:49 +0530 | [diff] [blame] | 403 | |
Axel Lin | b1ff323 | 2015-03-11 09:41:34 +0800 | [diff] [blame] | 404 | if (!IS_ERR(phy->optclk)) |
| 405 | clk_prepare(phy->optclk); |
| 406 | |
Kishon Vijay Abraham I | c11747f | 2013-01-25 08:03:24 +0530 | [diff] [blame] | 407 | usb_add_phy_dev(&phy->phy); |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 408 | |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 409 | return 0; |
| 410 | } |
| 411 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 412 | static int omap_usb2_remove(struct platform_device *pdev) |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 413 | { |
| 414 | struct omap_usb *phy = platform_get_drvdata(pdev); |
| 415 | |
| 416 | clk_unprepare(phy->wkupclk); |
Kishon Vijay Abraham I | 0c4c8bb | 2013-01-25 08:21:49 +0530 | [diff] [blame] | 417 | if (!IS_ERR(phy->optclk)) |
| 418 | clk_unprepare(phy->optclk); |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 419 | usb_remove_phy(&phy->phy); |
Roger Quadros | eb82a3d | 2014-07-10 11:55:03 +0530 | [diff] [blame] | 420 | pm_runtime_disable(phy->dev); |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 421 | |
| 422 | return 0; |
| 423 | } |
| 424 | |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 425 | static struct platform_driver omap_usb2_driver = { |
| 426 | .probe = omap_usb2_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 427 | .remove = omap_usb2_remove, |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 428 | .driver = { |
| 429 | .name = "omap-usb2", |
Axel Lin | 52a4a72 | 2015-03-05 18:20:07 +0800 | [diff] [blame] | 430 | .of_match_table = omap_usb2_id_table, |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 431 | }, |
| 432 | }; |
| 433 | |
| 434 | module_platform_driver(omap_usb2_driver); |
| 435 | |
Axel Lin | dd64ad38 | 2015-03-07 00:01:21 +0800 | [diff] [blame] | 436 | MODULE_ALIAS("platform:omap_usb2"); |
Kishon Vijay Abraham I | 657b306 | 2012-09-06 20:27:06 +0530 | [diff] [blame] | 437 | MODULE_AUTHOR("Texas Instruments Inc."); |
| 438 | MODULE_DESCRIPTION("OMAP USB2 phy driver"); |
| 439 | MODULE_LICENSE("GPL v2"); |