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 |
Bin Liu | 2283219 | 2015-03-24 15:08:49 -0500 | [diff] [blame] | 68 | #define USBOTGSS_UTMI_OTG_STATUS 0x0080 |
| 69 | #define USBOTGSS_UTMI_OTG_CTRL 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 | |
| 80 | /* SYSCONFIG REGISTER */ |
| 81 | #define USBOTGSS_SYSCONFIG_DMADISABLE (1 << 16) |
Felipe Balbi | 4b5faa7a | 2011-09-06 10:56:51 +0300 | [diff] [blame] | 82 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 83 | /* IRQ_EOI REGISTER */ |
| 84 | #define USBOTGSS_IRQ_EOI_LINE_NUMBER (1 << 0) |
| 85 | |
| 86 | /* IRQS0 BITS */ |
| 87 | #define USBOTGSS_IRQO_COREIRQ_ST (1 << 0) |
| 88 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 89 | /* IRQMISC BITS */ |
| 90 | #define USBOTGSS_IRQMISC_DMADISABLECLR (1 << 17) |
| 91 | #define USBOTGSS_IRQMISC_OEVT (1 << 16) |
| 92 | #define USBOTGSS_IRQMISC_DRVVBUS_RISE (1 << 13) |
| 93 | #define USBOTGSS_IRQMISC_CHRGVBUS_RISE (1 << 12) |
| 94 | #define USBOTGSS_IRQMISC_DISCHRGVBUS_RISE (1 << 11) |
| 95 | #define USBOTGSS_IRQMISC_IDPULLUP_RISE (1 << 8) |
| 96 | #define USBOTGSS_IRQMISC_DRVVBUS_FALL (1 << 5) |
| 97 | #define USBOTGSS_IRQMISC_CHRGVBUS_FALL (1 << 4) |
| 98 | #define USBOTGSS_IRQMISC_DISCHRGVBUS_FALL (1 << 3) |
| 99 | #define USBOTGSS_IRQMISC_IDPULLUP_FALL (1 << 0) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 100 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 101 | /* UTMI_OTG_STATUS REGISTER */ |
Bin Liu | 2283219 | 2015-03-24 15:08:49 -0500 | [diff] [blame] | 102 | #define USBOTGSS_UTMI_OTG_STATUS_DRVVBUS (1 << 5) |
| 103 | #define USBOTGSS_UTMI_OTG_STATUS_CHRGVBUS (1 << 4) |
| 104 | #define USBOTGSS_UTMI_OTG_STATUS_DISCHRGVBUS (1 << 3) |
| 105 | #define USBOTGSS_UTMI_OTG_STATUS_IDPULLUP (1 << 0) |
| 106 | |
| 107 | /* UTMI_OTG_CTRL REGISTER */ |
| 108 | #define USBOTGSS_UTMI_OTG_CTRL_SW_MODE (1 << 31) |
| 109 | #define USBOTGSS_UTMI_OTG_CTRL_POWERPRESENT (1 << 9) |
| 110 | #define USBOTGSS_UTMI_OTG_CTRL_TXBITSTUFFENABLE (1 << 8) |
| 111 | #define USBOTGSS_UTMI_OTG_CTRL_IDDIG (1 << 4) |
| 112 | #define USBOTGSS_UTMI_OTG_CTRL_SESSEND (1 << 3) |
| 113 | #define USBOTGSS_UTMI_OTG_CTRL_SESSVALID (1 << 2) |
| 114 | #define USBOTGSS_UTMI_OTG_CTRL_VBUSVALID (1 << 1) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 115 | |
| 116 | struct dwc3_omap { |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 117 | struct device *dev; |
| 118 | |
| 119 | int irq; |
| 120 | void __iomem *base; |
| 121 | |
Bin Liu | 2283219 | 2015-03-24 15:08:49 -0500 | [diff] [blame] | 122 | u32 utmi_otg_ctrl; |
George Cherian | 1e2a064 | 2013-06-12 14:53:45 +0530 | [diff] [blame] | 123 | u32 utmi_otg_offset; |
| 124 | u32 irqmisc_offset; |
| 125 | u32 irq_eoi_offset; |
| 126 | u32 debug_offset; |
| 127 | u32 irq0_offset; |
Felipe Balbi | f3e117f | 2013-02-11 11:12:02 +0200 | [diff] [blame] | 128 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 129 | u32 dma_status:1; |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 130 | |
| 131 | struct extcon_specific_cable_nb extcon_vbus_dev; |
| 132 | struct extcon_specific_cable_nb extcon_id_dev; |
| 133 | struct notifier_block vbus_nb; |
| 134 | struct notifier_block id_nb; |
| 135 | |
| 136 | struct regulator *vbus_reg; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 137 | }; |
| 138 | |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 139 | enum omap_dwc3_vbus_id_status { |
| 140 | OMAP_DWC3_ID_FLOAT, |
| 141 | OMAP_DWC3_ID_GROUND, |
| 142 | OMAP_DWC3_VBUS_OFF, |
| 143 | OMAP_DWC3_VBUS_VALID, |
| 144 | }; |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 145 | |
Ido Shayevitz | ab5e59d | 2012-04-24 14:18:38 +0300 | [diff] [blame] | 146 | static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset) |
| 147 | { |
| 148 | return readl(base + offset); |
| 149 | } |
| 150 | |
| 151 | static inline void dwc3_omap_writel(void __iomem *base, u32 offset, u32 value) |
| 152 | { |
| 153 | writel(value, base + offset); |
| 154 | } |
| 155 | |
Bin Liu | 2283219 | 2015-03-24 15:08:49 -0500 | [diff] [blame] | 156 | static u32 dwc3_omap_read_utmi_ctrl(struct dwc3_omap *omap) |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 157 | { |
Bin Liu | 2283219 | 2015-03-24 15:08:49 -0500 | [diff] [blame] | 158 | return dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_CTRL + |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 159 | omap->utmi_otg_offset); |
| 160 | } |
| 161 | |
Bin Liu | 2283219 | 2015-03-24 15:08:49 -0500 | [diff] [blame] | 162 | static void dwc3_omap_write_utmi_ctrl(struct dwc3_omap *omap, u32 value) |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 163 | { |
Bin Liu | 2283219 | 2015-03-24 15:08:49 -0500 | [diff] [blame] | 164 | dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_CTRL + |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 165 | omap->utmi_otg_offset, value); |
| 166 | |
| 167 | } |
| 168 | |
| 169 | static u32 dwc3_omap_read_irq0_status(struct dwc3_omap *omap) |
| 170 | { |
| 171 | return dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_0 - |
| 172 | omap->irq0_offset); |
| 173 | } |
| 174 | |
| 175 | static void dwc3_omap_write_irq0_status(struct dwc3_omap *omap, u32 value) |
| 176 | { |
| 177 | dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_0 - |
| 178 | omap->irq0_offset, value); |
| 179 | |
| 180 | } |
| 181 | |
| 182 | static u32 dwc3_omap_read_irqmisc_status(struct dwc3_omap *omap) |
| 183 | { |
| 184 | return dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_MISC + |
| 185 | omap->irqmisc_offset); |
| 186 | } |
| 187 | |
| 188 | static void dwc3_omap_write_irqmisc_status(struct dwc3_omap *omap, u32 value) |
| 189 | { |
| 190 | dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_MISC + |
| 191 | omap->irqmisc_offset, value); |
| 192 | |
| 193 | } |
| 194 | |
| 195 | static void dwc3_omap_write_irqmisc_set(struct dwc3_omap *omap, u32 value) |
| 196 | { |
| 197 | dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_MISC + |
| 198 | omap->irqmisc_offset, value); |
| 199 | |
| 200 | } |
| 201 | |
| 202 | static void dwc3_omap_write_irq0_set(struct dwc3_omap *omap, u32 value) |
| 203 | { |
| 204 | dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0 - |
| 205 | omap->irq0_offset, value); |
| 206 | } |
| 207 | |
George Cherian | 96e5d31 | 2015-02-13 10:13:24 +0530 | [diff] [blame] | 208 | static void dwc3_omap_write_irqmisc_clr(struct dwc3_omap *omap, u32 value) |
| 209 | { |
| 210 | dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_CLR_MISC + |
| 211 | omap->irqmisc_offset, value); |
| 212 | } |
| 213 | |
| 214 | static void dwc3_omap_write_irq0_clr(struct dwc3_omap *omap, u32 value) |
| 215 | { |
| 216 | dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_CLR_0 - |
| 217 | omap->irq0_offset, value); |
| 218 | } |
| 219 | |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 220 | static void dwc3_omap_set_mailbox(struct dwc3_omap *omap, |
| 221 | enum omap_dwc3_vbus_id_status status) |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 222 | { |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 223 | int ret; |
| 224 | u32 val; |
Kishon Vijay Abraham I | 2ba7943 | 2013-03-07 18:51:44 +0530 | [diff] [blame] | 225 | |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 226 | switch (status) { |
| 227 | case OMAP_DWC3_ID_GROUND: |
| 228 | dev_dbg(omap->dev, "ID GND\n"); |
| 229 | |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 230 | if (omap->vbus_reg) { |
| 231 | ret = regulator_enable(omap->vbus_reg); |
| 232 | if (ret) { |
| 233 | dev_dbg(omap->dev, "regulator enable failed\n"); |
| 234 | return; |
| 235 | } |
| 236 | } |
| 237 | |
Bin Liu | 2283219 | 2015-03-24 15:08:49 -0500 | [diff] [blame] | 238 | val = dwc3_omap_read_utmi_ctrl(omap); |
| 239 | val &= ~(USBOTGSS_UTMI_OTG_CTRL_IDDIG |
| 240 | | USBOTGSS_UTMI_OTG_CTRL_VBUSVALID |
| 241 | | USBOTGSS_UTMI_OTG_CTRL_SESSEND); |
| 242 | val |= USBOTGSS_UTMI_OTG_CTRL_SESSVALID |
| 243 | | USBOTGSS_UTMI_OTG_CTRL_POWERPRESENT; |
| 244 | dwc3_omap_write_utmi_ctrl(omap, val); |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 245 | break; |
| 246 | |
| 247 | case OMAP_DWC3_VBUS_VALID: |
| 248 | dev_dbg(omap->dev, "VBUS Connect\n"); |
| 249 | |
Bin Liu | 2283219 | 2015-03-24 15:08:49 -0500 | [diff] [blame] | 250 | val = dwc3_omap_read_utmi_ctrl(omap); |
| 251 | val &= ~USBOTGSS_UTMI_OTG_CTRL_SESSEND; |
| 252 | val |= USBOTGSS_UTMI_OTG_CTRL_IDDIG |
| 253 | | USBOTGSS_UTMI_OTG_CTRL_VBUSVALID |
| 254 | | USBOTGSS_UTMI_OTG_CTRL_SESSVALID |
| 255 | | USBOTGSS_UTMI_OTG_CTRL_POWERPRESENT; |
| 256 | dwc3_omap_write_utmi_ctrl(omap, val); |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 257 | break; |
| 258 | |
| 259 | case OMAP_DWC3_ID_FLOAT: |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 260 | if (omap->vbus_reg) |
| 261 | regulator_disable(omap->vbus_reg); |
| 262 | |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 263 | case OMAP_DWC3_VBUS_OFF: |
| 264 | dev_dbg(omap->dev, "VBUS Disconnect\n"); |
| 265 | |
Bin Liu | 2283219 | 2015-03-24 15:08:49 -0500 | [diff] [blame] | 266 | val = dwc3_omap_read_utmi_ctrl(omap); |
| 267 | val &= ~(USBOTGSS_UTMI_OTG_CTRL_SESSVALID |
| 268 | | USBOTGSS_UTMI_OTG_CTRL_VBUSVALID |
| 269 | | USBOTGSS_UTMI_OTG_CTRL_POWERPRESENT); |
| 270 | val |= USBOTGSS_UTMI_OTG_CTRL_SESSEND |
| 271 | | USBOTGSS_UTMI_OTG_CTRL_IDDIG; |
| 272 | dwc3_omap_write_utmi_ctrl(omap, val); |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 273 | break; |
| 274 | |
| 275 | default: |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 276 | dev_dbg(omap->dev, "invalid state\n"); |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 277 | } |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 278 | } |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 279 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 280 | static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap) |
| 281 | { |
| 282 | struct dwc3_omap *omap = _omap; |
| 283 | u32 reg; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 284 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 285 | reg = dwc3_omap_read_irqmisc_status(omap); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 286 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 287 | if (reg & USBOTGSS_IRQMISC_DMADISABLECLR) { |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 288 | dev_dbg(omap->dev, "DMA Disable was Cleared\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 289 | omap->dma_status = false; |
| 290 | } |
| 291 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 292 | if (reg & USBOTGSS_IRQMISC_OEVT) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 293 | dev_dbg(omap->dev, "OTG Event\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 294 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 295 | if (reg & USBOTGSS_IRQMISC_DRVVBUS_RISE) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 296 | dev_dbg(omap->dev, "DRVVBUS Rise\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 297 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 298 | if (reg & USBOTGSS_IRQMISC_CHRGVBUS_RISE) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 299 | dev_dbg(omap->dev, "CHRGVBUS Rise\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 300 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 301 | if (reg & USBOTGSS_IRQMISC_DISCHRGVBUS_RISE) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 302 | dev_dbg(omap->dev, "DISCHRGVBUS Rise\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 303 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 304 | if (reg & USBOTGSS_IRQMISC_IDPULLUP_RISE) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 305 | dev_dbg(omap->dev, "IDPULLUP Rise\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 306 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 307 | if (reg & USBOTGSS_IRQMISC_DRVVBUS_FALL) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 308 | dev_dbg(omap->dev, "DRVVBUS Fall\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 309 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 310 | if (reg & USBOTGSS_IRQMISC_CHRGVBUS_FALL) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 311 | dev_dbg(omap->dev, "CHRGVBUS Fall\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 312 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 313 | if (reg & USBOTGSS_IRQMISC_DISCHRGVBUS_FALL) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 314 | dev_dbg(omap->dev, "DISCHRGVBUS Fall\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 315 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 316 | if (reg & USBOTGSS_IRQMISC_IDPULLUP_FALL) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 317 | dev_dbg(omap->dev, "IDPULLUP Fall\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 318 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 319 | dwc3_omap_write_irqmisc_status(omap, reg); |
Felipe Balbi | 42077b0 | 2011-09-06 12:00:39 +0300 | [diff] [blame] | 320 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 321 | reg = dwc3_omap_read_irq0_status(omap); |
| 322 | |
| 323 | dwc3_omap_write_irq0_status(omap, reg); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 324 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 325 | return IRQ_HANDLED; |
| 326 | } |
| 327 | |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame] | 328 | static void dwc3_omap_enable_irqs(struct dwc3_omap *omap) |
| 329 | { |
| 330 | u32 reg; |
| 331 | |
| 332 | /* enable all IRQs */ |
| 333 | reg = USBOTGSS_IRQO_COREIRQ_ST; |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 334 | dwc3_omap_write_irq0_set(omap, reg); |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame] | 335 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 336 | reg = (USBOTGSS_IRQMISC_OEVT | |
| 337 | USBOTGSS_IRQMISC_DRVVBUS_RISE | |
| 338 | USBOTGSS_IRQMISC_CHRGVBUS_RISE | |
| 339 | USBOTGSS_IRQMISC_DISCHRGVBUS_RISE | |
| 340 | USBOTGSS_IRQMISC_IDPULLUP_RISE | |
| 341 | USBOTGSS_IRQMISC_DRVVBUS_FALL | |
| 342 | USBOTGSS_IRQMISC_CHRGVBUS_FALL | |
| 343 | USBOTGSS_IRQMISC_DISCHRGVBUS_FALL | |
| 344 | USBOTGSS_IRQMISC_IDPULLUP_FALL); |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame] | 345 | |
George Cherian | b1fd6cb | 2013-06-12 14:53:47 +0530 | [diff] [blame] | 346 | dwc3_omap_write_irqmisc_set(omap, reg); |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | static void dwc3_omap_disable_irqs(struct dwc3_omap *omap) |
| 350 | { |
George Cherian | 96e5d31 | 2015-02-13 10:13:24 +0530 | [diff] [blame] | 351 | u32 reg; |
| 352 | |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame] | 353 | /* disable all IRQs */ |
George Cherian | 96e5d31 | 2015-02-13 10:13:24 +0530 | [diff] [blame] | 354 | reg = USBOTGSS_IRQO_COREIRQ_ST; |
| 355 | dwc3_omap_write_irq0_clr(omap, reg); |
| 356 | |
| 357 | reg = (USBOTGSS_IRQMISC_OEVT | |
| 358 | USBOTGSS_IRQMISC_DRVVBUS_RISE | |
| 359 | USBOTGSS_IRQMISC_CHRGVBUS_RISE | |
| 360 | USBOTGSS_IRQMISC_DISCHRGVBUS_RISE | |
| 361 | USBOTGSS_IRQMISC_IDPULLUP_RISE | |
| 362 | USBOTGSS_IRQMISC_DRVVBUS_FALL | |
| 363 | USBOTGSS_IRQMISC_CHRGVBUS_FALL | |
| 364 | USBOTGSS_IRQMISC_DISCHRGVBUS_FALL | |
| 365 | USBOTGSS_IRQMISC_IDPULLUP_FALL); |
| 366 | |
| 367 | dwc3_omap_write_irqmisc_clr(omap, reg); |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame] | 368 | } |
| 369 | |
Kishon Vijay Abraham I | ddff14f | 2013-03-07 18:51:43 +0530 | [diff] [blame] | 370 | static u64 dwc3_omap_dma_mask = DMA_BIT_MASK(32); |
| 371 | |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 372 | static int dwc3_omap_id_notifier(struct notifier_block *nb, |
| 373 | unsigned long event, void *ptr) |
| 374 | { |
| 375 | struct dwc3_omap *omap = container_of(nb, struct dwc3_omap, id_nb); |
| 376 | |
| 377 | if (event) |
| 378 | dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND); |
| 379 | else |
| 380 | dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_FLOAT); |
| 381 | |
| 382 | return NOTIFY_DONE; |
| 383 | } |
| 384 | |
| 385 | static int dwc3_omap_vbus_notifier(struct notifier_block *nb, |
| 386 | unsigned long event, void *ptr) |
| 387 | { |
| 388 | struct dwc3_omap *omap = container_of(nb, struct dwc3_omap, vbus_nb); |
| 389 | |
| 390 | if (event) |
| 391 | dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID); |
| 392 | else |
| 393 | dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_OFF); |
| 394 | |
| 395 | return NOTIFY_DONE; |
| 396 | } |
| 397 | |
George Cherian | 30fef1a | 2014-07-16 18:37:06 +0530 | [diff] [blame] | 398 | static void dwc3_omap_map_offset(struct dwc3_omap *omap) |
| 399 | { |
| 400 | struct device_node *node = omap->dev->of_node; |
| 401 | |
| 402 | /* |
| 403 | * Differentiate between OMAP5 and AM437x. |
| 404 | * |
| 405 | * For OMAP5(ES2.0) and AM437x wrapper revision is same, even |
| 406 | * though there are changes in wrapper register offsets. |
| 407 | * |
| 408 | * Using dt compatible to differentiate AM437x. |
| 409 | */ |
| 410 | if (of_device_is_compatible(node, "ti,am437x-dwc3")) { |
| 411 | omap->irq_eoi_offset = USBOTGSS_EOI_OFFSET; |
| 412 | omap->irq0_offset = USBOTGSS_IRQ0_OFFSET; |
| 413 | omap->irqmisc_offset = USBOTGSS_IRQMISC_OFFSET; |
| 414 | omap->utmi_otg_offset = USBOTGSS_UTMI_OTG_OFFSET; |
| 415 | omap->debug_offset = USBOTGSS_DEBUG_OFFSET; |
| 416 | } |
| 417 | } |
| 418 | |
George Cherian | d2f0cf89 | 2014-07-16 18:37:07 +0530 | [diff] [blame] | 419 | static void dwc3_omap_set_utmi_mode(struct dwc3_omap *omap) |
| 420 | { |
| 421 | u32 reg; |
| 422 | struct device_node *node = omap->dev->of_node; |
| 423 | int utmi_mode = 0; |
| 424 | |
Bin Liu | 2283219 | 2015-03-24 15:08:49 -0500 | [diff] [blame] | 425 | reg = dwc3_omap_read_utmi_ctrl(omap); |
George Cherian | d2f0cf89 | 2014-07-16 18:37:07 +0530 | [diff] [blame] | 426 | |
| 427 | of_property_read_u32(node, "utmi-mode", &utmi_mode); |
| 428 | |
| 429 | switch (utmi_mode) { |
| 430 | case DWC3_OMAP_UTMI_MODE_SW: |
Bin Liu | 2283219 | 2015-03-24 15:08:49 -0500 | [diff] [blame] | 431 | reg |= USBOTGSS_UTMI_OTG_CTRL_SW_MODE; |
George Cherian | d2f0cf89 | 2014-07-16 18:37:07 +0530 | [diff] [blame] | 432 | break; |
| 433 | case DWC3_OMAP_UTMI_MODE_HW: |
Bin Liu | 2283219 | 2015-03-24 15:08:49 -0500 | [diff] [blame] | 434 | reg &= ~USBOTGSS_UTMI_OTG_CTRL_SW_MODE; |
George Cherian | d2f0cf89 | 2014-07-16 18:37:07 +0530 | [diff] [blame] | 435 | break; |
| 436 | default: |
| 437 | dev_dbg(omap->dev, "UNKNOWN utmi mode %d\n", utmi_mode); |
| 438 | } |
| 439 | |
Bin Liu | 2283219 | 2015-03-24 15:08:49 -0500 | [diff] [blame] | 440 | dwc3_omap_write_utmi_ctrl(omap, reg); |
George Cherian | d2f0cf89 | 2014-07-16 18:37:07 +0530 | [diff] [blame] | 441 | } |
| 442 | |
George Cherian | 025b431 | 2014-07-16 18:37:08 +0530 | [diff] [blame] | 443 | static int dwc3_omap_extcon_register(struct dwc3_omap *omap) |
| 444 | { |
Dan Carpenter | 788b0bc4 | 2014-07-31 18:30:51 +0300 | [diff] [blame] | 445 | int ret; |
George Cherian | 025b431 | 2014-07-16 18:37:08 +0530 | [diff] [blame] | 446 | struct device_node *node = omap->dev->of_node; |
| 447 | struct extcon_dev *edev; |
| 448 | |
| 449 | if (of_property_read_bool(node, "extcon")) { |
| 450 | edev = extcon_get_edev_by_phandle(omap->dev, 0); |
| 451 | if (IS_ERR(edev)) { |
| 452 | dev_vdbg(omap->dev, "couldn't get extcon device\n"); |
| 453 | return -EPROBE_DEFER; |
| 454 | } |
| 455 | |
| 456 | omap->vbus_nb.notifier_call = dwc3_omap_vbus_notifier; |
| 457 | ret = extcon_register_interest(&omap->extcon_vbus_dev, |
| 458 | edev->name, "USB", |
| 459 | &omap->vbus_nb); |
| 460 | if (ret < 0) |
| 461 | dev_vdbg(omap->dev, "failed to register notifier for USB\n"); |
| 462 | |
| 463 | omap->id_nb.notifier_call = dwc3_omap_id_notifier; |
| 464 | ret = extcon_register_interest(&omap->extcon_id_dev, |
| 465 | edev->name, "USB-HOST", |
| 466 | &omap->id_nb); |
| 467 | if (ret < 0) |
| 468 | dev_vdbg(omap->dev, "failed to register notifier for USB-HOST\n"); |
| 469 | |
| 470 | if (extcon_get_cable_state(edev, "USB") == true) |
| 471 | dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID); |
| 472 | if (extcon_get_cable_state(edev, "USB-HOST") == true) |
| 473 | dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND); |
| 474 | } |
| 475 | |
| 476 | return 0; |
| 477 | } |
| 478 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 479 | static int dwc3_omap_probe(struct platform_device *pdev) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 480 | { |
Felipe Balbi | 45b3cd4a | 2012-01-25 11:07:03 +0200 | [diff] [blame] | 481 | struct device_node *node = pdev->dev.of_node; |
| 482 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 483 | struct dwc3_omap *omap; |
| 484 | struct resource *res; |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 485 | struct device *dev = &pdev->dev; |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 486 | struct regulator *vbus_reg = NULL; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 487 | |
Andy Shevchenko | b09e99e | 2014-05-15 15:53:32 +0300 | [diff] [blame] | 488 | int ret; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 489 | int irq; |
| 490 | |
| 491 | u32 reg; |
| 492 | |
| 493 | void __iomem *base; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 494 | |
Kishon Vijay Abraham I | 4495afc | 2013-02-26 20:03:28 +0530 | [diff] [blame] | 495 | if (!node) { |
| 496 | dev_err(dev, "device node not found\n"); |
| 497 | return -EINVAL; |
| 498 | } |
| 499 | |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 500 | omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL); |
Jingoo Han | 734d5a5 | 2014-07-17 12:45:11 +0900 | [diff] [blame] | 501 | if (!omap) |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 502 | return -ENOMEM; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 503 | |
| 504 | platform_set_drvdata(pdev, omap); |
| 505 | |
Kishon Vijay Abraham I | e36a0c8 | 2013-02-26 20:03:27 +0530 | [diff] [blame] | 506 | irq = platform_get_irq(pdev, 0); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 507 | if (irq < 0) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 508 | dev_err(dev, "missing IRQ resource\n"); |
| 509 | return -EINVAL; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 510 | } |
| 511 | |
Kishon Vijay Abraham I | e36a0c8 | 2013-02-26 20:03:27 +0530 | [diff] [blame] | 512 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Felipe Balbi | 8bbcd17 | 2013-07-12 15:33:35 +0300 | [diff] [blame] | 513 | base = devm_ioremap_resource(dev, res); |
| 514 | if (IS_ERR(base)) |
| 515 | return PTR_ERR(base); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 516 | |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 517 | if (of_property_read_bool(node, "vbus-supply")) { |
| 518 | vbus_reg = devm_regulator_get(dev, "vbus"); |
| 519 | if (IS_ERR(vbus_reg)) { |
| 520 | dev_err(dev, "vbus init failed\n"); |
| 521 | return PTR_ERR(vbus_reg); |
| 522 | } |
| 523 | } |
| 524 | |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 525 | omap->dev = dev; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 526 | omap->irq = irq; |
| 527 | omap->base = base; |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 528 | omap->vbus_reg = vbus_reg; |
Kishon Vijay Abraham I | ddff14f | 2013-03-07 18:51:43 +0530 | [diff] [blame] | 529 | dev->dma_mask = &dwc3_omap_dma_mask; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 530 | |
Kishon Vijay Abraham I | af310e9 | 2013-01-25 08:30:47 +0530 | [diff] [blame] | 531 | pm_runtime_enable(dev); |
| 532 | ret = pm_runtime_get_sync(dev); |
| 533 | if (ret < 0) { |
| 534 | 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] | 535 | goto err0; |
Kishon Vijay Abraham I | af310e9 | 2013-01-25 08:30:47 +0530 | [diff] [blame] | 536 | } |
| 537 | |
George Cherian | 30fef1a | 2014-07-16 18:37:06 +0530 | [diff] [blame] | 538 | dwc3_omap_map_offset(omap); |
George Cherian | d2f0cf89 | 2014-07-16 18:37:07 +0530 | [diff] [blame] | 539 | dwc3_omap_set_utmi_mode(omap); |
Felipe Balbi | 9962444 | 2011-09-01 22:26:25 +0300 | [diff] [blame] | 540 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 541 | /* check the DMA Status */ |
Ido Shayevitz | ab5e59d | 2012-04-24 14:18:38 +0300 | [diff] [blame] | 542 | reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 543 | omap->dma_status = !!(reg & USBOTGSS_SYSCONFIG_DMADISABLE); |
| 544 | |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 545 | ret = devm_request_irq(dev, omap->irq, dwc3_omap_interrupt, 0, |
Felipe Balbi | dd17a6b | 2011-09-06 10:57:41 +0300 | [diff] [blame] | 546 | "dwc3-omap", omap); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 547 | if (ret) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 548 | dev_err(dev, "failed to request IRQ #%d --> %d\n", |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 549 | omap->irq, ret); |
Kishon Vijay Abraham I | 594daba | 2013-06-03 21:43:39 +0530 | [diff] [blame] | 550 | goto err1; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 551 | } |
| 552 | |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame] | 553 | dwc3_omap_enable_irqs(omap); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 554 | |
George Cherian | 025b431 | 2014-07-16 18:37:08 +0530 | [diff] [blame] | 555 | ret = dwc3_omap_extcon_register(omap); |
| 556 | if (ret < 0) |
| 557 | goto err2; |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 558 | |
Kishon Vijay Abraham I | 4495afc | 2013-02-26 20:03:28 +0530 | [diff] [blame] | 559 | ret = of_platform_populate(node, NULL, NULL, dev); |
| 560 | if (ret) { |
| 561 | dev_err(&pdev->dev, "failed to create dwc3 core\n"); |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 562 | goto err3; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | return 0; |
Kishon Vijay Abraham I | 594daba | 2013-06-03 21:43:39 +0530 | [diff] [blame] | 566 | |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 567 | err3: |
| 568 | if (omap->extcon_vbus_dev.edev) |
| 569 | extcon_unregister_interest(&omap->extcon_vbus_dev); |
| 570 | if (omap->extcon_id_dev.edev) |
| 571 | extcon_unregister_interest(&omap->extcon_id_dev); |
| 572 | |
Kishon Vijay Abraham I | 594daba | 2013-06-03 21:43:39 +0530 | [diff] [blame] | 573 | err2: |
| 574 | dwc3_omap_disable_irqs(omap); |
| 575 | |
| 576 | err1: |
| 577 | pm_runtime_put_sync(dev); |
| 578 | |
| 579 | err0: |
| 580 | pm_runtime_disable(dev); |
| 581 | |
| 582 | return ret; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 583 | } |
| 584 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 585 | static int dwc3_omap_remove(struct platform_device *pdev) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 586 | { |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame] | 587 | struct dwc3_omap *omap = platform_get_drvdata(pdev); |
| 588 | |
Kishon Vijay Abraham I | 8061ad7 | 2013-07-08 09:54:43 +0900 | [diff] [blame] | 589 | if (omap->extcon_vbus_dev.edev) |
| 590 | extcon_unregister_interest(&omap->extcon_vbus_dev); |
| 591 | if (omap->extcon_id_dev.edev) |
| 592 | extcon_unregister_interest(&omap->extcon_id_dev); |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame] | 593 | dwc3_omap_disable_irqs(omap); |
Felipe Balbi | 3d0184d | 2014-09-02 14:12:26 -0500 | [diff] [blame] | 594 | of_platform_depopulate(omap->dev); |
Kishon Vijay Abraham I | af310e9 | 2013-01-25 08:30:47 +0530 | [diff] [blame] | 595 | pm_runtime_put_sync(&pdev->dev); |
| 596 | pm_runtime_disable(&pdev->dev); |
Kishon Vijay Abraham I | 94c6a43 | 2013-01-25 08:30:45 +0530 | [diff] [blame] | 597 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 598 | return 0; |
| 599 | } |
| 600 | |
Felipe Balbi | 2c2dc89 | 2013-02-11 10:31:15 +0200 | [diff] [blame] | 601 | static const struct of_device_id of_dwc3_match[] = { |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 602 | { |
Kishon Vijay Abraham I | e36a0c8 | 2013-02-26 20:03:27 +0530 | [diff] [blame] | 603 | .compatible = "ti,dwc3" |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 604 | }, |
George Cherian | ff7307b | 2013-06-12 14:53:46 +0530 | [diff] [blame] | 605 | { |
| 606 | .compatible = "ti,am437x-dwc3" |
| 607 | }, |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 608 | { }, |
| 609 | }; |
Felipe Balbi | 2c2dc89 | 2013-02-11 10:31:15 +0200 | [diff] [blame] | 610 | MODULE_DEVICE_TABLE(of, of_dwc3_match); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 611 | |
Jingoo Han | 19fda7c | 2013-03-26 01:52:48 +0000 | [diff] [blame] | 612 | #ifdef CONFIG_PM_SLEEP |
Felipe Balbi | f3e117f | 2013-02-11 11:12:02 +0200 | [diff] [blame] | 613 | static int dwc3_omap_suspend(struct device *dev) |
| 614 | { |
| 615 | struct dwc3_omap *omap = dev_get_drvdata(dev); |
| 616 | |
Bin Liu | 2283219 | 2015-03-24 15:08:49 -0500 | [diff] [blame] | 617 | omap->utmi_otg_ctrl = dwc3_omap_read_utmi_ctrl(omap); |
George Cherian | 7ee2566 | 2013-12-17 18:47:54 +0530 | [diff] [blame] | 618 | dwc3_omap_disable_irqs(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 | |
Bin Liu | 2283219 | 2015-03-24 15:08:49 -0500 | [diff] [blame] | 627 | dwc3_omap_write_utmi_ctrl(omap, omap->utmi_otg_ctrl); |
George Cherian | 7ee2566 | 2013-12-17 18:47:54 +0530 | [diff] [blame] | 628 | dwc3_omap_enable_irqs(omap); |
Felipe Balbi | f3e117f | 2013-02-11 11:12:02 +0200 | [diff] [blame] | 629 | |
| 630 | pm_runtime_disable(dev); |
| 631 | pm_runtime_set_active(dev); |
| 632 | pm_runtime_enable(dev); |
| 633 | |
| 634 | return 0; |
| 635 | } |
| 636 | |
| 637 | static const struct dev_pm_ops dwc3_omap_dev_pm_ops = { |
Felipe Balbi | f3e117f | 2013-02-11 11:12:02 +0200 | [diff] [blame] | 638 | |
| 639 | SET_SYSTEM_SLEEP_PM_OPS(dwc3_omap_suspend, dwc3_omap_resume) |
| 640 | }; |
| 641 | |
| 642 | #define DEV_PM_OPS (&dwc3_omap_dev_pm_ops) |
| 643 | #else |
| 644 | #define DEV_PM_OPS NULL |
Jingoo Han | 19fda7c | 2013-03-26 01:52:48 +0000 | [diff] [blame] | 645 | #endif /* CONFIG_PM_SLEEP */ |
Felipe Balbi | f3e117f | 2013-02-11 11:12:02 +0200 | [diff] [blame] | 646 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 647 | static struct platform_driver dwc3_omap_driver = { |
| 648 | .probe = dwc3_omap_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 649 | .remove = dwc3_omap_remove, |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 650 | .driver = { |
| 651 | .name = "omap-dwc3", |
Felipe Balbi | 2c2dc89 | 2013-02-11 10:31:15 +0200 | [diff] [blame] | 652 | .of_match_table = of_dwc3_match, |
Felipe Balbi | f3e117f | 2013-02-11 11:12:02 +0200 | [diff] [blame] | 653 | .pm = DEV_PM_OPS, |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 654 | }, |
| 655 | }; |
| 656 | |
Axel Lin | cc27c96 | 2011-11-27 20:16:27 +0800 | [diff] [blame] | 657 | module_platform_driver(dwc3_omap_driver); |
| 658 | |
Sebastian Andrzej Siewior | 7ae4fc4 | 2011-10-19 19:39:50 +0200 | [diff] [blame] | 659 | MODULE_ALIAS("platform:omap-dwc3"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 660 | MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); |
Felipe Balbi | 5945f78 | 2013-06-30 14:15:11 +0300 | [diff] [blame] | 661 | MODULE_LICENSE("GPL v2"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 662 | MODULE_DESCRIPTION("DesignWare USB3 OMAP Glue Layer"); |