Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1 | /** |
| 2 | * dwc3-omap.c - OMAP Specific Glue layer |
| 3 | * |
| 4 | * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 5 | * |
| 6 | * Authors: Felipe Balbi <balbi@ti.com>, |
| 7 | * Sebastian Andrzej Siewior <bigeasy@linutronix.de> |
| 8 | * |
Felipe Balbi | 5945f78 | 2013-06-30 14:15:11 +0300 | [diff] [blame] | 9 | * This program is free software: you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 of |
| 11 | * the License as published by the Free Software Foundation. |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 12 | * |
Felipe Balbi | 5945f78 | 2013-06-30 14:15:11 +0300 | [diff] [blame] | 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 17 | */ |
| 18 | |
Felipe Balbi | a72e658 | 2011-09-05 13:37:28 +0300 | [diff] [blame] | 19 | #include <linux/module.h> |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 20 | #include <linux/kernel.h> |
| 21 | #include <linux/slab.h> |
| 22 | #include <linux/interrupt.h> |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 23 | #include <linux/platform_device.h> |
Felipe Balbi | 9962444 | 2011-09-01 22:26:25 +0300 | [diff] [blame] | 24 | #include <linux/platform_data/dwc3-omap.h> |
Kishon Vijay Abraham I | af310e9 | 2013-01-25 08:30:47 +0530 | [diff] [blame] | 25 | #include <linux/pm_runtime.h> |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 26 | #include <linux/dma-mapping.h> |
| 27 | #include <linux/ioport.h> |
| 28 | #include <linux/io.h> |
Felipe Balbi | 45b3cd4a | 2012-01-25 11:07:03 +0200 | [diff] [blame] | 29 | #include <linux/of.h> |
Kishon Vijay Abraham I | b4bfe6a | 2013-01-25 08:30:46 +0530 | [diff] [blame] | 30 | #include <linux/of_platform.h> |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 31 | #include <linux/extcon.h> |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 32 | #include <linux/regulator/consumer.h> |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 33 | |
Felipe Balbi | a418cc4 | 2012-07-19 13:56:07 +0300 | [diff] [blame] | 34 | #include <linux/usb/otg.h> |
Felipe Balbi | a418cc4 | 2012-07-19 13:56:07 +0300 | [diff] [blame] | 35 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 36 | /* |
| 37 | * All these registers belong to OMAP's Wrapper around the |
| 38 | * DesignWare USB3 Core. |
| 39 | */ |
| 40 | |
| 41 | #define USBOTGSS_REVISION 0x0000 |
| 42 | #define USBOTGSS_SYSCONFIG 0x0010 |
| 43 | #define USBOTGSS_IRQ_EOI 0x0020 |
George Cherian | ff7307b | 2013-06-12 14:53:46 +0530 | [diff] [blame] | 44 | #define USBOTGSS_EOI_OFFSET 0x0008 |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 45 | #define USBOTGSS_IRQSTATUS_RAW_0 0x0024 |
| 46 | #define USBOTGSS_IRQSTATUS_0 0x0028 |
| 47 | #define USBOTGSS_IRQENABLE_SET_0 0x002c |
| 48 | #define USBOTGSS_IRQENABLE_CLR_0 0x0030 |
George Cherian | ff7307b | 2013-06-12 14:53:46 +0530 | [diff] [blame] | 49 | #define USBOTGSS_IRQ0_OFFSET 0x0004 |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 50 | #define USBOTGSS_IRQSTATUS_RAW_1 0x0030 |
| 51 | #define USBOTGSS_IRQSTATUS_1 0x0034 |
| 52 | #define USBOTGSS_IRQENABLE_SET_1 0x0038 |
| 53 | #define USBOTGSS_IRQENABLE_CLR_1 0x003c |
| 54 | #define USBOTGSS_IRQSTATUS_RAW_2 0x0040 |
| 55 | #define USBOTGSS_IRQSTATUS_2 0x0044 |
| 56 | #define USBOTGSS_IRQENABLE_SET_2 0x0048 |
| 57 | #define USBOTGSS_IRQENABLE_CLR_2 0x004c |
| 58 | #define USBOTGSS_IRQSTATUS_RAW_3 0x0050 |
| 59 | #define USBOTGSS_IRQSTATUS_3 0x0054 |
| 60 | #define USBOTGSS_IRQENABLE_SET_3 0x0058 |
| 61 | #define USBOTGSS_IRQENABLE_CLR_3 0x005c |
George Cherian | ff7307b | 2013-06-12 14:53:46 +0530 | [diff] [blame] | 62 | #define USBOTGSS_IRQSTATUS_EOI_MISC 0x0030 |
| 63 | #define USBOTGSS_IRQSTATUS_RAW_MISC 0x0034 |
| 64 | #define USBOTGSS_IRQSTATUS_MISC 0x0038 |
| 65 | #define USBOTGSS_IRQENABLE_SET_MISC 0x003c |
| 66 | #define USBOTGSS_IRQENABLE_CLR_MISC 0x0040 |
| 67 | #define USBOTGSS_IRQMISC_OFFSET 0x03fc |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 68 | #define USBOTGSS_UTMI_OTG_CTRL 0x0080 |
| 69 | #define USBOTGSS_UTMI_OTG_STATUS 0x0084 |
George Cherian | ff7307b | 2013-06-12 14:53:46 +0530 | [diff] [blame] | 70 | #define USBOTGSS_UTMI_OTG_OFFSET 0x0480 |
| 71 | #define USBOTGSS_TXFIFO_DEPTH 0x0508 |
| 72 | #define USBOTGSS_RXFIFO_DEPTH 0x050c |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 73 | #define USBOTGSS_MMRAM_OFFSET 0x0100 |
| 74 | #define USBOTGSS_FLADJ 0x0104 |
| 75 | #define USBOTGSS_DEBUG_CFG 0x0108 |
| 76 | #define USBOTGSS_DEBUG_DATA 0x010c |
George Cherian | ff7307b | 2013-06-12 14:53:46 +0530 | [diff] [blame] | 77 | #define USBOTGSS_DEV_EBC_EN 0x0110 |
| 78 | #define USBOTGSS_DEBUG_OFFSET 0x0600 |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 79 | |
George Cherian | ff7307b | 2013-06-12 14:53:46 +0530 | [diff] [blame] | 80 | /* REVISION REGISTER */ |
| 81 | #define USBOTGSS_REVISION_XMAJOR(reg) ((reg >> 8) & 0x7) |
| 82 | #define USBOTGSS_REVISION_XMAJOR1 1 |
| 83 | #define USBOTGSS_REVISION_XMAJOR2 2 |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 84 | /* SYSCONFIG REGISTER */ |
| 85 | #define USBOTGSS_SYSCONFIG_DMADISABLE (1 << 16) |
Felipe Balbi | 4b5faa7a | 2011-09-06 10:56:51 +0300 | [diff] [blame] | 86 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 87 | /* IRQ_EOI REGISTER */ |
| 88 | #define USBOTGSS_IRQ_EOI_LINE_NUMBER (1 << 0) |
| 89 | |
| 90 | /* IRQS0 BITS */ |
| 91 | #define USBOTGSS_IRQO_COREIRQ_ST (1 << 0) |
| 92 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 93 | /* IRQMISC BITS */ |
| 94 | #define USBOTGSS_IRQMISC_DMADISABLECLR (1 << 17) |
| 95 | #define USBOTGSS_IRQMISC_OEVT (1 << 16) |
| 96 | #define USBOTGSS_IRQMISC_DRVVBUS_RISE (1 << 13) |
| 97 | #define USBOTGSS_IRQMISC_CHRGVBUS_RISE (1 << 12) |
| 98 | #define USBOTGSS_IRQMISC_DISCHRGVBUS_RISE (1 << 11) |
| 99 | #define USBOTGSS_IRQMISC_IDPULLUP_RISE (1 << 8) |
| 100 | #define USBOTGSS_IRQMISC_DRVVBUS_FALL (1 << 5) |
| 101 | #define USBOTGSS_IRQMISC_CHRGVBUS_FALL (1 << 4) |
| 102 | #define USBOTGSS_IRQMISC_DISCHRGVBUS_FALL (1 << 3) |
| 103 | #define USBOTGSS_IRQMISC_IDPULLUP_FALL (1 << 0) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 104 | |
| 105 | /* UTMI_OTG_CTRL REGISTER */ |
| 106 | #define USBOTGSS_UTMI_OTG_CTRL_DRVVBUS (1 << 5) |
| 107 | #define USBOTGSS_UTMI_OTG_CTRL_CHRGVBUS (1 << 4) |
| 108 | #define USBOTGSS_UTMI_OTG_CTRL_DISCHRGVBUS (1 << 3) |
| 109 | #define USBOTGSS_UTMI_OTG_CTRL_IDPULLUP (1 << 0) |
| 110 | |
| 111 | /* UTMI_OTG_STATUS REGISTER */ |
| 112 | #define USBOTGSS_UTMI_OTG_STATUS_SW_MODE (1 << 31) |
| 113 | #define USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT (1 << 9) |
| 114 | #define USBOTGSS_UTMI_OTG_STATUS_TXBITSTUFFENABLE (1 << 8) |
| 115 | #define USBOTGSS_UTMI_OTG_STATUS_IDDIG (1 << 4) |
| 116 | #define USBOTGSS_UTMI_OTG_STATUS_SESSEND (1 << 3) |
| 117 | #define USBOTGSS_UTMI_OTG_STATUS_SESSVALID (1 << 2) |
| 118 | #define USBOTGSS_UTMI_OTG_STATUS_VBUSVALID (1 << 1) |
| 119 | |
| 120 | struct dwc3_omap { |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 121 | struct device *dev; |
| 122 | |
| 123 | int irq; |
| 124 | void __iomem *base; |
| 125 | |
Felipe Balbi | f3e117f | 2013-02-11 11:12:02 +0200 | [diff] [blame] | 126 | u32 utmi_otg_status; |
George Cherian | 1e2a064 | 2013-06-12 14:53:45 +0530 | [diff] [blame] | 127 | u32 utmi_otg_offset; |
| 128 | u32 irqmisc_offset; |
| 129 | u32 irq_eoi_offset; |
| 130 | u32 debug_offset; |
| 131 | u32 irq0_offset; |
| 132 | u32 revision; |
Felipe Balbi | f3e117f | 2013-02-11 11:12:02 +0200 | [diff] [blame] | 133 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 134 | u32 dma_status:1; |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 135 | |
| 136 | struct extcon_specific_cable_nb extcon_vbus_dev; |
| 137 | struct extcon_specific_cable_nb extcon_id_dev; |
| 138 | struct notifier_block vbus_nb; |
| 139 | struct notifier_block id_nb; |
| 140 | |
| 141 | struct regulator *vbus_reg; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 142 | }; |
| 143 | |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 144 | enum omap_dwc3_vbus_id_status { |
| 145 | OMAP_DWC3_ID_FLOAT, |
| 146 | OMAP_DWC3_ID_GROUND, |
| 147 | OMAP_DWC3_VBUS_OFF, |
| 148 | OMAP_DWC3_VBUS_VALID, |
| 149 | }; |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 150 | |
Ido Shayevitz | ab5e59d | 2012-04-24 14:18:38 +0300 | [diff] [blame] | 151 | static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset) |
| 152 | { |
| 153 | return readl(base + offset); |
| 154 | } |
| 155 | |
| 156 | static inline void dwc3_omap_writel(void __iomem *base, u32 offset, u32 value) |
| 157 | { |
| 158 | writel(value, base + offset); |
| 159 | } |
| 160 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 161 | static u32 dwc3_omap_read_utmi_status(struct dwc3_omap *omap) |
| 162 | { |
| 163 | return dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS + |
| 164 | omap->utmi_otg_offset); |
| 165 | } |
| 166 | |
| 167 | static void dwc3_omap_write_utmi_status(struct dwc3_omap *omap, u32 value) |
| 168 | { |
| 169 | dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS + |
| 170 | omap->utmi_otg_offset, value); |
| 171 | |
| 172 | } |
| 173 | |
| 174 | static u32 dwc3_omap_read_irq0_status(struct dwc3_omap *omap) |
| 175 | { |
| 176 | return dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_0 - |
| 177 | omap->irq0_offset); |
| 178 | } |
| 179 | |
| 180 | static void dwc3_omap_write_irq0_status(struct dwc3_omap *omap, u32 value) |
| 181 | { |
| 182 | dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_0 - |
| 183 | omap->irq0_offset, value); |
| 184 | |
| 185 | } |
| 186 | |
| 187 | static u32 dwc3_omap_read_irqmisc_status(struct dwc3_omap *omap) |
| 188 | { |
| 189 | return dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_MISC + |
| 190 | omap->irqmisc_offset); |
| 191 | } |
| 192 | |
| 193 | static void dwc3_omap_write_irqmisc_status(struct dwc3_omap *omap, u32 value) |
| 194 | { |
| 195 | dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_MISC + |
| 196 | omap->irqmisc_offset, value); |
| 197 | |
| 198 | } |
| 199 | |
| 200 | static void dwc3_omap_write_irqmisc_set(struct dwc3_omap *omap, u32 value) |
| 201 | { |
| 202 | dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_MISC + |
| 203 | omap->irqmisc_offset, value); |
| 204 | |
| 205 | } |
| 206 | |
| 207 | static void dwc3_omap_write_irq0_set(struct dwc3_omap *omap, u32 value) |
| 208 | { |
| 209 | dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0 - |
| 210 | omap->irq0_offset, value); |
| 211 | } |
| 212 | |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 213 | static void dwc3_omap_set_mailbox(struct dwc3_omap *omap, |
| 214 | enum omap_dwc3_vbus_id_status status) |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 215 | { |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 216 | int ret; |
| 217 | u32 val; |
Kishon Vijay Abraham I | 2ba7943 | 2013-03-07 18:51:44 +0530 | [diff] [blame] | 218 | |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 219 | switch (status) { |
| 220 | case OMAP_DWC3_ID_GROUND: |
| 221 | dev_dbg(omap->dev, "ID GND\n"); |
| 222 | |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 223 | if (omap->vbus_reg) { |
| 224 | ret = regulator_enable(omap->vbus_reg); |
| 225 | if (ret) { |
| 226 | dev_dbg(omap->dev, "regulator enable failed\n"); |
| 227 | return; |
| 228 | } |
| 229 | } |
| 230 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 231 | val = dwc3_omap_read_utmi_status(omap); |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 232 | val &= ~(USBOTGSS_UTMI_OTG_STATUS_IDDIG |
| 233 | | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID |
| 234 | | USBOTGSS_UTMI_OTG_STATUS_SESSEND); |
| 235 | val |= USBOTGSS_UTMI_OTG_STATUS_SESSVALID |
| 236 | | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT; |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 237 | dwc3_omap_write_utmi_status(omap, val); |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 238 | break; |
| 239 | |
| 240 | case OMAP_DWC3_VBUS_VALID: |
| 241 | dev_dbg(omap->dev, "VBUS Connect\n"); |
| 242 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 243 | val = dwc3_omap_read_utmi_status(omap); |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 244 | val &= ~USBOTGSS_UTMI_OTG_STATUS_SESSEND; |
| 245 | val |= USBOTGSS_UTMI_OTG_STATUS_IDDIG |
| 246 | | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID |
| 247 | | USBOTGSS_UTMI_OTG_STATUS_SESSVALID |
| 248 | | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT; |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 249 | dwc3_omap_write_utmi_status(omap, val); |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 250 | break; |
| 251 | |
| 252 | case OMAP_DWC3_ID_FLOAT: |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 253 | if (omap->vbus_reg) |
| 254 | regulator_disable(omap->vbus_reg); |
| 255 | |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 256 | case OMAP_DWC3_VBUS_OFF: |
| 257 | dev_dbg(omap->dev, "VBUS Disconnect\n"); |
| 258 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 259 | val = dwc3_omap_read_utmi_status(omap); |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 260 | val &= ~(USBOTGSS_UTMI_OTG_STATUS_SESSVALID |
| 261 | | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID |
| 262 | | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT); |
| 263 | val |= USBOTGSS_UTMI_OTG_STATUS_SESSEND |
| 264 | | USBOTGSS_UTMI_OTG_STATUS_IDDIG; |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 265 | dwc3_omap_write_utmi_status(omap, val); |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 266 | break; |
| 267 | |
| 268 | default: |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 269 | dev_dbg(omap->dev, "invalid state\n"); |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 270 | } |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 271 | } |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 272 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 273 | static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap) |
| 274 | { |
| 275 | struct dwc3_omap *omap = _omap; |
| 276 | u32 reg; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 277 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 278 | reg = dwc3_omap_read_irqmisc_status(omap); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 279 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 280 | if (reg & USBOTGSS_IRQMISC_DMADISABLECLR) { |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 281 | dev_dbg(omap->dev, "DMA Disable was Cleared\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 282 | omap->dma_status = false; |
| 283 | } |
| 284 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 285 | if (reg & USBOTGSS_IRQMISC_OEVT) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 286 | dev_dbg(omap->dev, "OTG Event\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 287 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 288 | if (reg & USBOTGSS_IRQMISC_DRVVBUS_RISE) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 289 | dev_dbg(omap->dev, "DRVVBUS Rise\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 290 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 291 | if (reg & USBOTGSS_IRQMISC_CHRGVBUS_RISE) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 292 | dev_dbg(omap->dev, "CHRGVBUS Rise\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 293 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 294 | if (reg & USBOTGSS_IRQMISC_DISCHRGVBUS_RISE) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 295 | dev_dbg(omap->dev, "DISCHRGVBUS Rise\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 296 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 297 | if (reg & USBOTGSS_IRQMISC_IDPULLUP_RISE) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 298 | dev_dbg(omap->dev, "IDPULLUP Rise\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 299 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 300 | if (reg & USBOTGSS_IRQMISC_DRVVBUS_FALL) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 301 | dev_dbg(omap->dev, "DRVVBUS Fall\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 302 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 303 | if (reg & USBOTGSS_IRQMISC_CHRGVBUS_FALL) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 304 | dev_dbg(omap->dev, "CHRGVBUS Fall\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 305 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 306 | if (reg & USBOTGSS_IRQMISC_DISCHRGVBUS_FALL) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 307 | dev_dbg(omap->dev, "DISCHRGVBUS Fall\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 308 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 309 | if (reg & USBOTGSS_IRQMISC_IDPULLUP_FALL) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 310 | dev_dbg(omap->dev, "IDPULLUP Fall\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 311 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 312 | dwc3_omap_write_irqmisc_status(omap, reg); |
Felipe Balbi | 42077b0 | 2011-09-06 12:00:39 +0300 | [diff] [blame] | 313 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 314 | reg = dwc3_omap_read_irq0_status(omap); |
| 315 | |
| 316 | dwc3_omap_write_irq0_status(omap, reg); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 317 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 318 | return IRQ_HANDLED; |
| 319 | } |
| 320 | |
Kishon Vijay Abraham I | 94c6a43 | 2013-01-25 08:30:45 +0530 | [diff] [blame] | 321 | static int dwc3_omap_remove_core(struct device *dev, void *c) |
| 322 | { |
| 323 | struct platform_device *pdev = to_platform_device(dev); |
| 324 | |
| 325 | platform_device_unregister(pdev); |
| 326 | |
| 327 | return 0; |
| 328 | } |
| 329 | |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame] | 330 | static void dwc3_omap_enable_irqs(struct dwc3_omap *omap) |
| 331 | { |
| 332 | u32 reg; |
| 333 | |
| 334 | /* enable all IRQs */ |
| 335 | reg = USBOTGSS_IRQO_COREIRQ_ST; |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 336 | dwc3_omap_write_irq0_set(omap, reg); |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame] | 337 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 338 | reg = (USBOTGSS_IRQMISC_OEVT | |
| 339 | USBOTGSS_IRQMISC_DRVVBUS_RISE | |
| 340 | USBOTGSS_IRQMISC_CHRGVBUS_RISE | |
| 341 | USBOTGSS_IRQMISC_DISCHRGVBUS_RISE | |
| 342 | USBOTGSS_IRQMISC_IDPULLUP_RISE | |
| 343 | USBOTGSS_IRQMISC_DRVVBUS_FALL | |
| 344 | USBOTGSS_IRQMISC_CHRGVBUS_FALL | |
| 345 | USBOTGSS_IRQMISC_DISCHRGVBUS_FALL | |
| 346 | USBOTGSS_IRQMISC_IDPULLUP_FALL); |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame] | 347 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 348 | dwc3_omap_write_irqmisc_set(omap, reg); |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | static void dwc3_omap_disable_irqs(struct dwc3_omap *omap) |
| 352 | { |
| 353 | /* disable all IRQs */ |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 354 | dwc3_omap_write_irqmisc_set(omap, 0x00); |
| 355 | dwc3_omap_write_irq0_set(omap, 0x00); |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame] | 356 | } |
| 357 | |
Kishon Vijay Abraham I | ddff14f | 2013-03-07 18:51:43 +0530 | [diff] [blame] | 358 | static u64 dwc3_omap_dma_mask = DMA_BIT_MASK(32); |
| 359 | |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 360 | static int dwc3_omap_id_notifier(struct notifier_block *nb, |
| 361 | unsigned long event, void *ptr) |
| 362 | { |
| 363 | struct dwc3_omap *omap = container_of(nb, struct dwc3_omap, id_nb); |
| 364 | |
| 365 | if (event) |
| 366 | dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND); |
| 367 | else |
| 368 | dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_FLOAT); |
| 369 | |
| 370 | return NOTIFY_DONE; |
| 371 | } |
| 372 | |
| 373 | static int dwc3_omap_vbus_notifier(struct notifier_block *nb, |
| 374 | unsigned long event, void *ptr) |
| 375 | { |
| 376 | struct dwc3_omap *omap = container_of(nb, struct dwc3_omap, vbus_nb); |
| 377 | |
| 378 | if (event) |
| 379 | dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID); |
| 380 | else |
| 381 | dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_OFF); |
| 382 | |
| 383 | return NOTIFY_DONE; |
| 384 | } |
| 385 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 386 | static int dwc3_omap_probe(struct platform_device *pdev) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 387 | { |
Felipe Balbi | 45b3cd4a | 2012-01-25 11:07:03 +0200 | [diff] [blame] | 388 | struct device_node *node = pdev->dev.of_node; |
| 389 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 390 | struct dwc3_omap *omap; |
| 391 | struct resource *res; |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 392 | struct device *dev = &pdev->dev; |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 393 | struct extcon_dev *edev; |
| 394 | struct regulator *vbus_reg = NULL; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 395 | |
| 396 | int ret = -ENOMEM; |
| 397 | int irq; |
| 398 | |
Kishon Vijay Abraham I | e36a0c8 | 2013-02-26 20:03:27 +0530 | [diff] [blame] | 399 | int utmi_mode = 0; |
George Cherian | ff7307b | 2013-06-12 14:53:46 +0530 | [diff] [blame] | 400 | int x_major; |
Kishon Vijay Abraham I | e36a0c8 | 2013-02-26 20:03:27 +0530 | [diff] [blame] | 401 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 402 | u32 reg; |
| 403 | |
| 404 | void __iomem *base; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 405 | |
Kishon Vijay Abraham I | 4495afc | 2013-02-26 20:03:28 +0530 | [diff] [blame] | 406 | if (!node) { |
| 407 | dev_err(dev, "device node not found\n"); |
| 408 | return -EINVAL; |
| 409 | } |
| 410 | |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 411 | omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 412 | if (!omap) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 413 | dev_err(dev, "not enough memory\n"); |
| 414 | return -ENOMEM; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | platform_set_drvdata(pdev, omap); |
| 418 | |
Kishon Vijay Abraham I | e36a0c8 | 2013-02-26 20:03:27 +0530 | [diff] [blame] | 419 | irq = platform_get_irq(pdev, 0); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 420 | if (irq < 0) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 421 | dev_err(dev, "missing IRQ resource\n"); |
| 422 | return -EINVAL; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 423 | } |
| 424 | |
Kishon Vijay Abraham I | e36a0c8 | 2013-02-26 20:03:27 +0530 | [diff] [blame] | 425 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Felipe Balbi | 8bbcd17 | 2013-07-12 15:33:35 +0300 | [diff] [blame] | 426 | base = devm_ioremap_resource(dev, res); |
| 427 | if (IS_ERR(base)) |
| 428 | return PTR_ERR(base); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 429 | |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 430 | if (of_property_read_bool(node, "vbus-supply")) { |
| 431 | vbus_reg = devm_regulator_get(dev, "vbus"); |
| 432 | if (IS_ERR(vbus_reg)) { |
| 433 | dev_err(dev, "vbus init failed\n"); |
| 434 | return PTR_ERR(vbus_reg); |
| 435 | } |
| 436 | } |
| 437 | |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 438 | omap->dev = dev; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 439 | omap->irq = irq; |
| 440 | omap->base = base; |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 441 | omap->vbus_reg = vbus_reg; |
Kishon Vijay Abraham I | ddff14f | 2013-03-07 18:51:43 +0530 | [diff] [blame] | 442 | dev->dma_mask = &dwc3_omap_dma_mask; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 443 | |
Kishon Vijay Abraham I | af310e9 | 2013-01-25 08:30:47 +0530 | [diff] [blame] | 444 | pm_runtime_enable(dev); |
| 445 | ret = pm_runtime_get_sync(dev); |
| 446 | if (ret < 0) { |
| 447 | dev_err(dev, "get_sync failed with err %d\n", ret); |
Kishon Vijay Abraham I | 594daba | 2013-06-03 21:43:39 +0530 | [diff] [blame] | 448 | goto err0; |
Kishon Vijay Abraham I | af310e9 | 2013-01-25 08:30:47 +0530 | [diff] [blame] | 449 | } |
| 450 | |
George Cherian | ff7307b | 2013-06-12 14:53:46 +0530 | [diff] [blame] | 451 | reg = dwc3_omap_readl(omap->base, USBOTGSS_REVISION); |
| 452 | omap->revision = reg; |
| 453 | x_major = USBOTGSS_REVISION_XMAJOR(reg); |
| 454 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 455 | /* Differentiate between OMAP5 and AM437x */ |
George Cherian | ff7307b | 2013-06-12 14:53:46 +0530 | [diff] [blame] | 456 | switch (x_major) { |
| 457 | case USBOTGSS_REVISION_XMAJOR1: |
| 458 | case USBOTGSS_REVISION_XMAJOR2: |
| 459 | omap->irq_eoi_offset = 0; |
| 460 | omap->irq0_offset = 0; |
| 461 | omap->irqmisc_offset = 0; |
| 462 | omap->utmi_otg_offset = 0; |
| 463 | omap->debug_offset = 0; |
| 464 | break; |
| 465 | default: |
| 466 | /* Default to the latest revision */ |
| 467 | omap->irq_eoi_offset = USBOTGSS_EOI_OFFSET; |
| 468 | omap->irq0_offset = USBOTGSS_IRQ0_OFFSET; |
| 469 | omap->irqmisc_offset = USBOTGSS_IRQMISC_OFFSET; |
| 470 | omap->utmi_otg_offset = USBOTGSS_UTMI_OTG_OFFSET; |
| 471 | omap->debug_offset = USBOTGSS_DEBUG_OFFSET; |
| 472 | break; |
| 473 | } |
| 474 | |
| 475 | /* For OMAP5(ES2.0) and AM437x x_major is 2 even though there are |
| 476 | * changes in wrapper registers, Using dt compatible for aegis |
| 477 | */ |
| 478 | |
| 479 | if (of_device_is_compatible(node, "ti,am437x-dwc3")) { |
| 480 | omap->irq_eoi_offset = USBOTGSS_EOI_OFFSET; |
| 481 | omap->irq0_offset = USBOTGSS_IRQ0_OFFSET; |
| 482 | omap->irqmisc_offset = USBOTGSS_IRQMISC_OFFSET; |
| 483 | omap->utmi_otg_offset = USBOTGSS_UTMI_OTG_OFFSET; |
| 484 | omap->debug_offset = USBOTGSS_DEBUG_OFFSET; |
| 485 | } |
| 486 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 487 | reg = dwc3_omap_read_utmi_status(omap); |
Felipe Balbi | 9962444 | 2011-09-01 22:26:25 +0300 | [diff] [blame] | 488 | |
Kishon Vijay Abraham I | 4495afc | 2013-02-26 20:03:28 +0530 | [diff] [blame] | 489 | of_property_read_u32(node, "utmi-mode", &utmi_mode); |
Kishon Vijay Abraham I | e36a0c8 | 2013-02-26 20:03:27 +0530 | [diff] [blame] | 490 | |
| 491 | switch (utmi_mode) { |
| 492 | case DWC3_OMAP_UTMI_MODE_SW: |
| 493 | reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE; |
| 494 | break; |
| 495 | case DWC3_OMAP_UTMI_MODE_HW: |
| 496 | reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE; |
| 497 | break; |
| 498 | default: |
| 499 | dev_dbg(dev, "UNKNOWN utmi mode %d\n", utmi_mode); |
Felipe Balbi | 9962444 | 2011-09-01 22:26:25 +0300 | [diff] [blame] | 500 | } |
| 501 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 502 | dwc3_omap_write_utmi_status(omap, reg); |
Felipe Balbi | 9962444 | 2011-09-01 22:26:25 +0300 | [diff] [blame] | 503 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 504 | /* check the DMA Status */ |
Ido Shayevitz | ab5e59d | 2012-04-24 14:18:38 +0300 | [diff] [blame] | 505 | reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 506 | omap->dma_status = !!(reg & USBOTGSS_SYSCONFIG_DMADISABLE); |
| 507 | |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 508 | ret = devm_request_irq(dev, omap->irq, dwc3_omap_interrupt, 0, |
Felipe Balbi | dd17a6b | 2011-09-06 10:57:41 +0300 | [diff] [blame] | 509 | "dwc3-omap", omap); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 510 | if (ret) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 511 | dev_err(dev, "failed to request IRQ #%d --> %d\n", |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 512 | omap->irq, ret); |
Kishon Vijay Abraham I | 594daba | 2013-06-03 21:43:39 +0530 | [diff] [blame] | 513 | goto err1; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 514 | } |
| 515 | |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame] | 516 | dwc3_omap_enable_irqs(omap); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 517 | |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 518 | if (of_property_read_bool(node, "extcon")) { |
Chanwoo Choi | 1ad94ff | 2014-03-18 19:55:46 +0900 | [diff] [blame] | 519 | edev = extcon_get_edev_by_phandle(dev, 0); |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 520 | if (IS_ERR(edev)) { |
| 521 | dev_vdbg(dev, "couldn't get extcon device\n"); |
George Cherian | e0a6104 | 2013-09-25 11:59:43 +0530 | [diff] [blame] | 522 | ret = -EPROBE_DEFER; |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 523 | goto err2; |
| 524 | } |
| 525 | |
| 526 | omap->vbus_nb.notifier_call = dwc3_omap_vbus_notifier; |
| 527 | ret = extcon_register_interest(&omap->extcon_vbus_dev, |
| 528 | edev->name, "USB", &omap->vbus_nb); |
| 529 | if (ret < 0) |
| 530 | dev_vdbg(dev, "failed to register notifier for USB\n"); |
| 531 | omap->id_nb.notifier_call = dwc3_omap_id_notifier; |
| 532 | ret = extcon_register_interest(&omap->extcon_id_dev, edev->name, |
| 533 | "USB-HOST", &omap->id_nb); |
| 534 | if (ret < 0) |
| 535 | dev_vdbg(dev, |
| 536 | "failed to register notifier for USB-HOST\n"); |
| 537 | |
| 538 | if (extcon_get_cable_state(edev, "USB") == true) |
| 539 | dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID); |
| 540 | if (extcon_get_cable_state(edev, "USB-HOST") == true) |
| 541 | dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND); |
| 542 | } |
| 543 | |
Kishon Vijay Abraham I | 4495afc | 2013-02-26 20:03:28 +0530 | [diff] [blame] | 544 | ret = of_platform_populate(node, NULL, NULL, dev); |
| 545 | if (ret) { |
| 546 | dev_err(&pdev->dev, "failed to create dwc3 core\n"); |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 547 | goto err3; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | return 0; |
Kishon Vijay Abraham I | 594daba | 2013-06-03 21:43:39 +0530 | [diff] [blame] | 551 | |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 552 | err3: |
| 553 | if (omap->extcon_vbus_dev.edev) |
| 554 | extcon_unregister_interest(&omap->extcon_vbus_dev); |
| 555 | if (omap->extcon_id_dev.edev) |
| 556 | extcon_unregister_interest(&omap->extcon_id_dev); |
| 557 | |
Kishon Vijay Abraham I | 594daba | 2013-06-03 21:43:39 +0530 | [diff] [blame] | 558 | err2: |
| 559 | dwc3_omap_disable_irqs(omap); |
| 560 | |
| 561 | err1: |
| 562 | pm_runtime_put_sync(dev); |
| 563 | |
| 564 | err0: |
| 565 | pm_runtime_disable(dev); |
| 566 | |
| 567 | return ret; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 568 | } |
| 569 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 570 | static int dwc3_omap_remove(struct platform_device *pdev) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 571 | { |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame] | 572 | struct dwc3_omap *omap = platform_get_drvdata(pdev); |
| 573 | |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 574 | if (omap->extcon_vbus_dev.edev) |
| 575 | extcon_unregister_interest(&omap->extcon_vbus_dev); |
| 576 | if (omap->extcon_id_dev.edev) |
| 577 | extcon_unregister_interest(&omap->extcon_id_dev); |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame] | 578 | dwc3_omap_disable_irqs(omap); |
Kishon Vijay Abraham I | af310e9 | 2013-01-25 08:30:47 +0530 | [diff] [blame] | 579 | pm_runtime_put_sync(&pdev->dev); |
| 580 | pm_runtime_disable(&pdev->dev); |
Kishon Vijay Abraham I | 94c6a43 | 2013-01-25 08:30:45 +0530 | [diff] [blame] | 581 | device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core); |
| 582 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 583 | return 0; |
| 584 | } |
| 585 | |
Felipe Balbi | 2c2dc89 | 2013-02-11 10:31:15 +0200 | [diff] [blame] | 586 | static const struct of_device_id of_dwc3_match[] = { |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 587 | { |
Kishon Vijay Abraham I | e36a0c8 | 2013-02-26 20:03:27 +0530 | [diff] [blame] | 588 | .compatible = "ti,dwc3" |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 589 | }, |
George Cherian | ff7307b | 2013-06-12 14:53:46 +0530 | [diff] [blame] | 590 | { |
| 591 | .compatible = "ti,am437x-dwc3" |
| 592 | }, |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 593 | { }, |
| 594 | }; |
Felipe Balbi | 2c2dc89 | 2013-02-11 10:31:15 +0200 | [diff] [blame] | 595 | MODULE_DEVICE_TABLE(of, of_dwc3_match); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 596 | |
Jingoo Han | 19fda7c | 2013-03-26 01:52:48 +0000 | [diff] [blame] | 597 | #ifdef CONFIG_PM_SLEEP |
Felipe Balbi | f3e117f | 2013-02-11 11:12:02 +0200 | [diff] [blame] | 598 | static int dwc3_omap_prepare(struct device *dev) |
| 599 | { |
| 600 | struct dwc3_omap *omap = dev_get_drvdata(dev); |
| 601 | |
| 602 | dwc3_omap_disable_irqs(omap); |
| 603 | |
| 604 | return 0; |
| 605 | } |
| 606 | |
| 607 | static void dwc3_omap_complete(struct device *dev) |
| 608 | { |
| 609 | struct dwc3_omap *omap = dev_get_drvdata(dev); |
| 610 | |
| 611 | dwc3_omap_enable_irqs(omap); |
| 612 | } |
| 613 | |
| 614 | static int dwc3_omap_suspend(struct device *dev) |
| 615 | { |
| 616 | struct dwc3_omap *omap = dev_get_drvdata(dev); |
| 617 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 618 | omap->utmi_otg_status = dwc3_omap_read_utmi_status(omap); |
Felipe Balbi | f3e117f | 2013-02-11 11:12:02 +0200 | [diff] [blame] | 619 | |
| 620 | return 0; |
| 621 | } |
| 622 | |
| 623 | static int dwc3_omap_resume(struct device *dev) |
| 624 | { |
| 625 | struct dwc3_omap *omap = dev_get_drvdata(dev); |
| 626 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 627 | dwc3_omap_write_utmi_status(omap, omap->utmi_otg_status); |
Felipe Balbi | f3e117f | 2013-02-11 11:12:02 +0200 | [diff] [blame] | 628 | |
| 629 | pm_runtime_disable(dev); |
| 630 | pm_runtime_set_active(dev); |
| 631 | pm_runtime_enable(dev); |
| 632 | |
| 633 | return 0; |
| 634 | } |
| 635 | |
| 636 | static const struct dev_pm_ops dwc3_omap_dev_pm_ops = { |
| 637 | .prepare = dwc3_omap_prepare, |
| 638 | .complete = dwc3_omap_complete, |
| 639 | |
| 640 | SET_SYSTEM_SLEEP_PM_OPS(dwc3_omap_suspend, dwc3_omap_resume) |
| 641 | }; |
| 642 | |
| 643 | #define DEV_PM_OPS (&dwc3_omap_dev_pm_ops) |
| 644 | #else |
| 645 | #define DEV_PM_OPS NULL |
Jingoo Han | 19fda7c | 2013-03-26 01:52:48 +0000 | [diff] [blame] | 646 | #endif /* CONFIG_PM_SLEEP */ |
Felipe Balbi | f3e117f | 2013-02-11 11:12:02 +0200 | [diff] [blame] | 647 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 648 | static struct platform_driver dwc3_omap_driver = { |
| 649 | .probe = dwc3_omap_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 650 | .remove = dwc3_omap_remove, |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 651 | .driver = { |
| 652 | .name = "omap-dwc3", |
Felipe Balbi | 2c2dc89 | 2013-02-11 10:31:15 +0200 | [diff] [blame] | 653 | .of_match_table = of_dwc3_match, |
Felipe Balbi | f3e117f | 2013-02-11 11:12:02 +0200 | [diff] [blame] | 654 | .pm = DEV_PM_OPS, |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 655 | }, |
| 656 | }; |
| 657 | |
Axel Lin | cc27c96 | 2011-11-27 20:16:27 +0800 | [diff] [blame] | 658 | module_platform_driver(dwc3_omap_driver); |
| 659 | |
Sebastian Andrzej Siewior | 7ae4fc4 | 2011-10-19 19:39:50 +0200 | [diff] [blame] | 660 | MODULE_ALIAS("platform:omap-dwc3"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 661 | MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); |
Felipe Balbi | 5945f78 | 2013-06-30 14:15:11 +0300 | [diff] [blame] | 662 | MODULE_LICENSE("GPL v2"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 663 | MODULE_DESCRIPTION("DesignWare USB3 OMAP Glue Layer"); |