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 | * |
| 9 | * Redistribution and use in source and binary forms, with or without |
| 10 | * modification, are permitted provided that the following conditions |
| 11 | * are met: |
| 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions, and the following disclaimer, |
| 14 | * without modification. |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in the |
| 17 | * documentation and/or other materials provided with the distribution. |
| 18 | * 3. The names of the above-listed copyright holders may not be used |
| 19 | * to endorse or promote products derived from this software without |
| 20 | * specific prior written permission. |
| 21 | * |
| 22 | * ALTERNATIVELY, this software may be distributed under the terms of the |
| 23 | * GNU General Public License ("GPL") version 2, as published by the Free |
| 24 | * Software Foundation. |
| 25 | * |
| 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 27 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 28 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 29 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 30 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 31 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 32 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 33 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 34 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 35 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 36 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 37 | */ |
| 38 | |
Felipe Balbi | a72e658 | 2011-09-05 13:37:28 +0300 | [diff] [blame] | 39 | #include <linux/module.h> |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 40 | #include <linux/kernel.h> |
| 41 | #include <linux/slab.h> |
| 42 | #include <linux/interrupt.h> |
| 43 | #include <linux/spinlock.h> |
| 44 | #include <linux/platform_device.h> |
Felipe Balbi | 9962444 | 2011-09-01 22:26:25 +0300 | [diff] [blame] | 45 | #include <linux/platform_data/dwc3-omap.h> |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 46 | #include <linux/usb/dwc3-omap.h> |
Kishon Vijay Abraham I | af310e9 | 2013-01-25 08:30:47 +0530 | [diff] [blame] | 47 | #include <linux/pm_runtime.h> |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 48 | #include <linux/dma-mapping.h> |
| 49 | #include <linux/ioport.h> |
| 50 | #include <linux/io.h> |
Felipe Balbi | 45b3cd4a | 2012-01-25 11:07:03 +0200 | [diff] [blame] | 51 | #include <linux/of.h> |
Kishon Vijay Abraham I | b4bfe6a | 2013-01-25 08:30:46 +0530 | [diff] [blame] | 52 | #include <linux/of_platform.h> |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 53 | |
Felipe Balbi | a418cc4 | 2012-07-19 13:56:07 +0300 | [diff] [blame] | 54 | #include <linux/usb/otg.h> |
Felipe Balbi | a418cc4 | 2012-07-19 13:56:07 +0300 | [diff] [blame] | 55 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 56 | /* |
| 57 | * All these registers belong to OMAP's Wrapper around the |
| 58 | * DesignWare USB3 Core. |
| 59 | */ |
| 60 | |
| 61 | #define USBOTGSS_REVISION 0x0000 |
| 62 | #define USBOTGSS_SYSCONFIG 0x0010 |
| 63 | #define USBOTGSS_IRQ_EOI 0x0020 |
| 64 | #define USBOTGSS_IRQSTATUS_RAW_0 0x0024 |
| 65 | #define USBOTGSS_IRQSTATUS_0 0x0028 |
| 66 | #define USBOTGSS_IRQENABLE_SET_0 0x002c |
| 67 | #define USBOTGSS_IRQENABLE_CLR_0 0x0030 |
| 68 | #define USBOTGSS_IRQSTATUS_RAW_1 0x0034 |
| 69 | #define USBOTGSS_IRQSTATUS_1 0x0038 |
| 70 | #define USBOTGSS_IRQENABLE_SET_1 0x003c |
| 71 | #define USBOTGSS_IRQENABLE_CLR_1 0x0040 |
| 72 | #define USBOTGSS_UTMI_OTG_CTRL 0x0080 |
| 73 | #define USBOTGSS_UTMI_OTG_STATUS 0x0084 |
| 74 | #define USBOTGSS_MMRAM_OFFSET 0x0100 |
| 75 | #define USBOTGSS_FLADJ 0x0104 |
| 76 | #define USBOTGSS_DEBUG_CFG 0x0108 |
| 77 | #define USBOTGSS_DEBUG_DATA 0x010c |
| 78 | |
| 79 | /* SYSCONFIG REGISTER */ |
| 80 | #define USBOTGSS_SYSCONFIG_DMADISABLE (1 << 16) |
Felipe Balbi | 4b5faa7a | 2011-09-06 10:56:51 +0300 | [diff] [blame] | 81 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 82 | /* IRQ_EOI REGISTER */ |
| 83 | #define USBOTGSS_IRQ_EOI_LINE_NUMBER (1 << 0) |
| 84 | |
| 85 | /* IRQS0 BITS */ |
| 86 | #define USBOTGSS_IRQO_COREIRQ_ST (1 << 0) |
| 87 | |
| 88 | /* IRQ1 BITS */ |
| 89 | #define USBOTGSS_IRQ1_DMADISABLECLR (1 << 17) |
| 90 | #define USBOTGSS_IRQ1_OEVT (1 << 16) |
| 91 | #define USBOTGSS_IRQ1_DRVVBUS_RISE (1 << 13) |
| 92 | #define USBOTGSS_IRQ1_CHRGVBUS_RISE (1 << 12) |
| 93 | #define USBOTGSS_IRQ1_DISCHRGVBUS_RISE (1 << 11) |
| 94 | #define USBOTGSS_IRQ1_IDPULLUP_RISE (1 << 8) |
| 95 | #define USBOTGSS_IRQ1_DRVVBUS_FALL (1 << 5) |
| 96 | #define USBOTGSS_IRQ1_CHRGVBUS_FALL (1 << 4) |
| 97 | #define USBOTGSS_IRQ1_DISCHRGVBUS_FALL (1 << 3) |
| 98 | #define USBOTGSS_IRQ1_IDPULLUP_FALL (1 << 0) |
| 99 | |
| 100 | /* UTMI_OTG_CTRL REGISTER */ |
| 101 | #define USBOTGSS_UTMI_OTG_CTRL_DRVVBUS (1 << 5) |
| 102 | #define USBOTGSS_UTMI_OTG_CTRL_CHRGVBUS (1 << 4) |
| 103 | #define USBOTGSS_UTMI_OTG_CTRL_DISCHRGVBUS (1 << 3) |
| 104 | #define USBOTGSS_UTMI_OTG_CTRL_IDPULLUP (1 << 0) |
| 105 | |
| 106 | /* UTMI_OTG_STATUS REGISTER */ |
| 107 | #define USBOTGSS_UTMI_OTG_STATUS_SW_MODE (1 << 31) |
| 108 | #define USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT (1 << 9) |
| 109 | #define USBOTGSS_UTMI_OTG_STATUS_TXBITSTUFFENABLE (1 << 8) |
| 110 | #define USBOTGSS_UTMI_OTG_STATUS_IDDIG (1 << 4) |
| 111 | #define USBOTGSS_UTMI_OTG_STATUS_SESSEND (1 << 3) |
| 112 | #define USBOTGSS_UTMI_OTG_STATUS_SESSVALID (1 << 2) |
| 113 | #define USBOTGSS_UTMI_OTG_STATUS_VBUSVALID (1 << 1) |
| 114 | |
| 115 | struct dwc3_omap { |
| 116 | /* device lock */ |
| 117 | spinlock_t lock; |
| 118 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 119 | struct device *dev; |
| 120 | |
| 121 | int irq; |
| 122 | void __iomem *base; |
| 123 | |
Felipe Balbi | f3e117f | 2013-02-11 11:12:02 +0200 | [diff] [blame] | 124 | u32 utmi_otg_status; |
| 125 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 126 | u32 dma_status:1; |
| 127 | }; |
| 128 | |
Felipe Balbi | a33bb21 | 2013-03-14 16:00:58 +0200 | [diff] [blame] | 129 | static struct dwc3_omap *_omap; |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 130 | |
Ido Shayevitz | ab5e59d | 2012-04-24 14:18:38 +0300 | [diff] [blame] | 131 | static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset) |
| 132 | { |
| 133 | return readl(base + offset); |
| 134 | } |
| 135 | |
| 136 | static inline void dwc3_omap_writel(void __iomem *base, u32 offset, u32 value) |
| 137 | { |
| 138 | writel(value, base + offset); |
| 139 | } |
| 140 | |
Kishon Vijay Abraham I | 2ba7943 | 2013-03-07 18:51:44 +0530 | [diff] [blame] | 141 | int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status) |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 142 | { |
| 143 | u32 val; |
| 144 | struct dwc3_omap *omap = _omap; |
| 145 | |
Kishon Vijay Abraham I | 2ba7943 | 2013-03-07 18:51:44 +0530 | [diff] [blame] | 146 | if (!omap) |
| 147 | return -EPROBE_DEFER; |
| 148 | |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 149 | switch (status) { |
| 150 | case OMAP_DWC3_ID_GROUND: |
| 151 | dev_dbg(omap->dev, "ID GND\n"); |
| 152 | |
| 153 | val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); |
| 154 | val &= ~(USBOTGSS_UTMI_OTG_STATUS_IDDIG |
| 155 | | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID |
| 156 | | USBOTGSS_UTMI_OTG_STATUS_SESSEND); |
| 157 | val |= USBOTGSS_UTMI_OTG_STATUS_SESSVALID |
| 158 | | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT; |
| 159 | dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val); |
| 160 | break; |
| 161 | |
| 162 | case OMAP_DWC3_VBUS_VALID: |
| 163 | dev_dbg(omap->dev, "VBUS Connect\n"); |
| 164 | |
| 165 | val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); |
| 166 | val &= ~USBOTGSS_UTMI_OTG_STATUS_SESSEND; |
| 167 | val |= USBOTGSS_UTMI_OTG_STATUS_IDDIG |
| 168 | | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID |
| 169 | | USBOTGSS_UTMI_OTG_STATUS_SESSVALID |
| 170 | | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT; |
| 171 | dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val); |
| 172 | break; |
| 173 | |
| 174 | case OMAP_DWC3_ID_FLOAT: |
| 175 | case OMAP_DWC3_VBUS_OFF: |
| 176 | dev_dbg(omap->dev, "VBUS Disconnect\n"); |
| 177 | |
| 178 | val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); |
| 179 | val &= ~(USBOTGSS_UTMI_OTG_STATUS_SESSVALID |
| 180 | | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID |
| 181 | | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT); |
| 182 | val |= USBOTGSS_UTMI_OTG_STATUS_SESSEND |
| 183 | | USBOTGSS_UTMI_OTG_STATUS_IDDIG; |
| 184 | dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val); |
| 185 | break; |
| 186 | |
| 187 | default: |
| 188 | dev_dbg(omap->dev, "ID float\n"); |
| 189 | } |
| 190 | |
Kishon Vijay Abraham I | 2ba7943 | 2013-03-07 18:51:44 +0530 | [diff] [blame] | 191 | return 0; |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 192 | } |
| 193 | EXPORT_SYMBOL_GPL(dwc3_omap_mailbox); |
| 194 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 195 | static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap) |
| 196 | { |
| 197 | struct dwc3_omap *omap = _omap; |
| 198 | u32 reg; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 199 | |
| 200 | spin_lock(&omap->lock); |
| 201 | |
Ido Shayevitz | ab5e59d | 2012-04-24 14:18:38 +0300 | [diff] [blame] | 202 | reg = dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_1); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 203 | |
| 204 | if (reg & USBOTGSS_IRQ1_DMADISABLECLR) { |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 205 | dev_dbg(omap->dev, "DMA Disable was Cleared\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 206 | omap->dma_status = false; |
| 207 | } |
| 208 | |
| 209 | if (reg & USBOTGSS_IRQ1_OEVT) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 210 | dev_dbg(omap->dev, "OTG Event\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 211 | |
Felipe Balbi | 42077b0 | 2011-09-06 12:00:39 +0300 | [diff] [blame] | 212 | if (reg & USBOTGSS_IRQ1_DRVVBUS_RISE) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 213 | dev_dbg(omap->dev, "DRVVBUS Rise\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 214 | |
Felipe Balbi | 42077b0 | 2011-09-06 12:00:39 +0300 | [diff] [blame] | 215 | if (reg & USBOTGSS_IRQ1_CHRGVBUS_RISE) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 216 | dev_dbg(omap->dev, "CHRGVBUS Rise\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 217 | |
Felipe Balbi | 42077b0 | 2011-09-06 12:00:39 +0300 | [diff] [blame] | 218 | if (reg & USBOTGSS_IRQ1_DISCHRGVBUS_RISE) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 219 | dev_dbg(omap->dev, "DISCHRGVBUS Rise\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 220 | |
Felipe Balbi | 42077b0 | 2011-09-06 12:00:39 +0300 | [diff] [blame] | 221 | if (reg & USBOTGSS_IRQ1_IDPULLUP_RISE) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 222 | dev_dbg(omap->dev, "IDPULLUP Rise\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 223 | |
Felipe Balbi | 42077b0 | 2011-09-06 12:00:39 +0300 | [diff] [blame] | 224 | if (reg & USBOTGSS_IRQ1_DRVVBUS_FALL) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 225 | dev_dbg(omap->dev, "DRVVBUS Fall\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 226 | |
Felipe Balbi | 42077b0 | 2011-09-06 12:00:39 +0300 | [diff] [blame] | 227 | if (reg & USBOTGSS_IRQ1_CHRGVBUS_FALL) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 228 | dev_dbg(omap->dev, "CHRGVBUS Fall\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 229 | |
Felipe Balbi | 42077b0 | 2011-09-06 12:00:39 +0300 | [diff] [blame] | 230 | if (reg & USBOTGSS_IRQ1_DISCHRGVBUS_FALL) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 231 | dev_dbg(omap->dev, "DISCHRGVBUS Fall\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 232 | |
Felipe Balbi | 42077b0 | 2011-09-06 12:00:39 +0300 | [diff] [blame] | 233 | if (reg & USBOTGSS_IRQ1_IDPULLUP_FALL) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 234 | dev_dbg(omap->dev, "IDPULLUP Fall\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 235 | |
Ido Shayevitz | ab5e59d | 2012-04-24 14:18:38 +0300 | [diff] [blame] | 236 | dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_1, reg); |
Felipe Balbi | 42077b0 | 2011-09-06 12:00:39 +0300 | [diff] [blame] | 237 | |
Ido Shayevitz | ab5e59d | 2012-04-24 14:18:38 +0300 | [diff] [blame] | 238 | reg = dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_0); |
| 239 | dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_0, reg); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 240 | |
| 241 | spin_unlock(&omap->lock); |
| 242 | |
| 243 | return IRQ_HANDLED; |
| 244 | } |
| 245 | |
Kishon Vijay Abraham I | 94c6a43 | 2013-01-25 08:30:45 +0530 | [diff] [blame] | 246 | static int dwc3_omap_remove_core(struct device *dev, void *c) |
| 247 | { |
| 248 | struct platform_device *pdev = to_platform_device(dev); |
| 249 | |
| 250 | platform_device_unregister(pdev); |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame] | 255 | static void dwc3_omap_enable_irqs(struct dwc3_omap *omap) |
| 256 | { |
| 257 | u32 reg; |
| 258 | |
| 259 | /* enable all IRQs */ |
| 260 | reg = USBOTGSS_IRQO_COREIRQ_ST; |
| 261 | dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, reg); |
| 262 | |
| 263 | reg = (USBOTGSS_IRQ1_OEVT | |
| 264 | USBOTGSS_IRQ1_DRVVBUS_RISE | |
| 265 | USBOTGSS_IRQ1_CHRGVBUS_RISE | |
| 266 | USBOTGSS_IRQ1_DISCHRGVBUS_RISE | |
| 267 | USBOTGSS_IRQ1_IDPULLUP_RISE | |
| 268 | USBOTGSS_IRQ1_DRVVBUS_FALL | |
| 269 | USBOTGSS_IRQ1_CHRGVBUS_FALL | |
| 270 | USBOTGSS_IRQ1_DISCHRGVBUS_FALL | |
| 271 | USBOTGSS_IRQ1_IDPULLUP_FALL); |
| 272 | |
| 273 | dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, reg); |
| 274 | } |
| 275 | |
| 276 | static void dwc3_omap_disable_irqs(struct dwc3_omap *omap) |
| 277 | { |
| 278 | /* disable all IRQs */ |
| 279 | dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, 0x00); |
| 280 | dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, 0x00); |
| 281 | } |
| 282 | |
Kishon Vijay Abraham I | ddff14f | 2013-03-07 18:51:43 +0530 | [diff] [blame] | 283 | static u64 dwc3_omap_dma_mask = DMA_BIT_MASK(32); |
| 284 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 285 | static int dwc3_omap_probe(struct platform_device *pdev) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 286 | { |
Felipe Balbi | 45b3cd4a | 2012-01-25 11:07:03 +0200 | [diff] [blame] | 287 | struct device_node *node = pdev->dev.of_node; |
| 288 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 289 | struct dwc3_omap *omap; |
| 290 | struct resource *res; |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 291 | struct device *dev = &pdev->dev; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 292 | |
| 293 | int ret = -ENOMEM; |
| 294 | int irq; |
| 295 | |
Kishon Vijay Abraham I | e36a0c8 | 2013-02-26 20:03:27 +0530 | [diff] [blame] | 296 | int utmi_mode = 0; |
| 297 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 298 | u32 reg; |
| 299 | |
| 300 | void __iomem *base; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 301 | |
Kishon Vijay Abraham I | 4495afc | 2013-02-26 20:03:28 +0530 | [diff] [blame] | 302 | if (!node) { |
| 303 | dev_err(dev, "device node not found\n"); |
| 304 | return -EINVAL; |
| 305 | } |
| 306 | |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 307 | omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 308 | if (!omap) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 309 | dev_err(dev, "not enough memory\n"); |
| 310 | return -ENOMEM; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | platform_set_drvdata(pdev, omap); |
| 314 | |
Kishon Vijay Abraham I | e36a0c8 | 2013-02-26 20:03:27 +0530 | [diff] [blame] | 315 | irq = platform_get_irq(pdev, 0); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 316 | if (irq < 0) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 317 | dev_err(dev, "missing IRQ resource\n"); |
| 318 | return -EINVAL; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 319 | } |
| 320 | |
Kishon Vijay Abraham I | e36a0c8 | 2013-02-26 20:03:27 +0530 | [diff] [blame] | 321 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 322 | if (!res) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 323 | dev_err(dev, "missing memory base resource\n"); |
| 324 | return -EINVAL; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 325 | } |
| 326 | |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 327 | base = devm_ioremap_nocache(dev, res->start, resource_size(res)); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 328 | if (!base) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 329 | dev_err(dev, "ioremap failed\n"); |
| 330 | return -ENOMEM; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 331 | } |
| 332 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 333 | spin_lock_init(&omap->lock); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 334 | |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 335 | omap->dev = dev; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 336 | omap->irq = irq; |
| 337 | omap->base = base; |
Kishon Vijay Abraham I | ddff14f | 2013-03-07 18:51:43 +0530 | [diff] [blame] | 338 | dev->dma_mask = &dwc3_omap_dma_mask; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 339 | |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 340 | /* |
| 341 | * REVISIT if we ever have two instances of the wrapper, we will be |
| 342 | * in big trouble |
| 343 | */ |
| 344 | _omap = omap; |
| 345 | |
Kishon Vijay Abraham I | af310e9 | 2013-01-25 08:30:47 +0530 | [diff] [blame] | 346 | pm_runtime_enable(dev); |
| 347 | ret = pm_runtime_get_sync(dev); |
| 348 | if (ret < 0) { |
| 349 | 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^] | 350 | goto err0; |
Kishon Vijay Abraham I | af310e9 | 2013-01-25 08:30:47 +0530 | [diff] [blame] | 351 | } |
| 352 | |
Ido Shayevitz | ab5e59d | 2012-04-24 14:18:38 +0300 | [diff] [blame] | 353 | reg = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); |
Felipe Balbi | 9962444 | 2011-09-01 22:26:25 +0300 | [diff] [blame] | 354 | |
Kishon Vijay Abraham I | 4495afc | 2013-02-26 20:03:28 +0530 | [diff] [blame] | 355 | of_property_read_u32(node, "utmi-mode", &utmi_mode); |
Kishon Vijay Abraham I | e36a0c8 | 2013-02-26 20:03:27 +0530 | [diff] [blame] | 356 | |
| 357 | switch (utmi_mode) { |
| 358 | case DWC3_OMAP_UTMI_MODE_SW: |
| 359 | reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE; |
| 360 | break; |
| 361 | case DWC3_OMAP_UTMI_MODE_HW: |
| 362 | reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE; |
| 363 | break; |
| 364 | default: |
| 365 | dev_dbg(dev, "UNKNOWN utmi mode %d\n", utmi_mode); |
Felipe Balbi | 9962444 | 2011-09-01 22:26:25 +0300 | [diff] [blame] | 366 | } |
| 367 | |
Ido Shayevitz | ab5e59d | 2012-04-24 14:18:38 +0300 | [diff] [blame] | 368 | dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, reg); |
Felipe Balbi | 9962444 | 2011-09-01 22:26:25 +0300 | [diff] [blame] | 369 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 370 | /* check the DMA Status */ |
Ido Shayevitz | ab5e59d | 2012-04-24 14:18:38 +0300 | [diff] [blame] | 371 | reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 372 | omap->dma_status = !!(reg & USBOTGSS_SYSCONFIG_DMADISABLE); |
| 373 | |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 374 | ret = devm_request_irq(dev, omap->irq, dwc3_omap_interrupt, 0, |
Felipe Balbi | dd17a6b | 2011-09-06 10:57:41 +0300 | [diff] [blame] | 375 | "dwc3-omap", omap); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 376 | if (ret) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 377 | dev_err(dev, "failed to request IRQ #%d --> %d\n", |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 378 | omap->irq, ret); |
Kishon Vijay Abraham I | 594daba | 2013-06-03 21:43:39 +0530 | [diff] [blame^] | 379 | goto err1; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 380 | } |
| 381 | |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame] | 382 | dwc3_omap_enable_irqs(omap); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 383 | |
Kishon Vijay Abraham I | 4495afc | 2013-02-26 20:03:28 +0530 | [diff] [blame] | 384 | ret = of_platform_populate(node, NULL, NULL, dev); |
| 385 | if (ret) { |
| 386 | dev_err(&pdev->dev, "failed to create dwc3 core\n"); |
Kishon Vijay Abraham I | 594daba | 2013-06-03 21:43:39 +0530 | [diff] [blame^] | 387 | goto err2; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | return 0; |
Kishon Vijay Abraham I | 594daba | 2013-06-03 21:43:39 +0530 | [diff] [blame^] | 391 | |
| 392 | err2: |
| 393 | dwc3_omap_disable_irqs(omap); |
| 394 | |
| 395 | err1: |
| 396 | pm_runtime_put_sync(dev); |
| 397 | |
| 398 | err0: |
| 399 | pm_runtime_disable(dev); |
| 400 | |
| 401 | return ret; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 402 | } |
| 403 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 404 | static int dwc3_omap_remove(struct platform_device *pdev) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 405 | { |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame] | 406 | struct dwc3_omap *omap = platform_get_drvdata(pdev); |
| 407 | |
| 408 | dwc3_omap_disable_irqs(omap); |
Kishon Vijay Abraham I | af310e9 | 2013-01-25 08:30:47 +0530 | [diff] [blame] | 409 | pm_runtime_put_sync(&pdev->dev); |
| 410 | pm_runtime_disable(&pdev->dev); |
Kishon Vijay Abraham I | 94c6a43 | 2013-01-25 08:30:45 +0530 | [diff] [blame] | 411 | device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core); |
| 412 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 413 | return 0; |
| 414 | } |
| 415 | |
Felipe Balbi | 2c2dc89 | 2013-02-11 10:31:15 +0200 | [diff] [blame] | 416 | static const struct of_device_id of_dwc3_match[] = { |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 417 | { |
Kishon Vijay Abraham I | e36a0c8 | 2013-02-26 20:03:27 +0530 | [diff] [blame] | 418 | .compatible = "ti,dwc3" |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 419 | }, |
| 420 | { }, |
| 421 | }; |
Felipe Balbi | 2c2dc89 | 2013-02-11 10:31:15 +0200 | [diff] [blame] | 422 | MODULE_DEVICE_TABLE(of, of_dwc3_match); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 423 | |
Jingoo Han | 19fda7c | 2013-03-26 01:52:48 +0000 | [diff] [blame] | 424 | #ifdef CONFIG_PM_SLEEP |
Felipe Balbi | f3e117f | 2013-02-11 11:12:02 +0200 | [diff] [blame] | 425 | static int dwc3_omap_prepare(struct device *dev) |
| 426 | { |
| 427 | struct dwc3_omap *omap = dev_get_drvdata(dev); |
| 428 | |
| 429 | dwc3_omap_disable_irqs(omap); |
| 430 | |
| 431 | return 0; |
| 432 | } |
| 433 | |
| 434 | static void dwc3_omap_complete(struct device *dev) |
| 435 | { |
| 436 | struct dwc3_omap *omap = dev_get_drvdata(dev); |
| 437 | |
| 438 | dwc3_omap_enable_irqs(omap); |
| 439 | } |
| 440 | |
| 441 | static int dwc3_omap_suspend(struct device *dev) |
| 442 | { |
| 443 | struct dwc3_omap *omap = dev_get_drvdata(dev); |
| 444 | |
| 445 | omap->utmi_otg_status = dwc3_omap_readl(omap->base, |
| 446 | USBOTGSS_UTMI_OTG_STATUS); |
| 447 | |
| 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | static int dwc3_omap_resume(struct device *dev) |
| 452 | { |
| 453 | struct dwc3_omap *omap = dev_get_drvdata(dev); |
| 454 | |
| 455 | dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, |
| 456 | omap->utmi_otg_status); |
| 457 | |
| 458 | pm_runtime_disable(dev); |
| 459 | pm_runtime_set_active(dev); |
| 460 | pm_runtime_enable(dev); |
| 461 | |
| 462 | return 0; |
| 463 | } |
| 464 | |
| 465 | static const struct dev_pm_ops dwc3_omap_dev_pm_ops = { |
| 466 | .prepare = dwc3_omap_prepare, |
| 467 | .complete = dwc3_omap_complete, |
| 468 | |
| 469 | SET_SYSTEM_SLEEP_PM_OPS(dwc3_omap_suspend, dwc3_omap_resume) |
| 470 | }; |
| 471 | |
| 472 | #define DEV_PM_OPS (&dwc3_omap_dev_pm_ops) |
| 473 | #else |
| 474 | #define DEV_PM_OPS NULL |
Jingoo Han | 19fda7c | 2013-03-26 01:52:48 +0000 | [diff] [blame] | 475 | #endif /* CONFIG_PM_SLEEP */ |
Felipe Balbi | f3e117f | 2013-02-11 11:12:02 +0200 | [diff] [blame] | 476 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 477 | static struct platform_driver dwc3_omap_driver = { |
| 478 | .probe = dwc3_omap_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 479 | .remove = dwc3_omap_remove, |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 480 | .driver = { |
| 481 | .name = "omap-dwc3", |
Felipe Balbi | 2c2dc89 | 2013-02-11 10:31:15 +0200 | [diff] [blame] | 482 | .of_match_table = of_dwc3_match, |
Felipe Balbi | f3e117f | 2013-02-11 11:12:02 +0200 | [diff] [blame] | 483 | .pm = DEV_PM_OPS, |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 484 | }, |
| 485 | }; |
| 486 | |
Axel Lin | cc27c96 | 2011-11-27 20:16:27 +0800 | [diff] [blame] | 487 | module_platform_driver(dwc3_omap_driver); |
| 488 | |
Sebastian Andrzej Siewior | 7ae4fc4 | 2011-10-19 19:39:50 +0200 | [diff] [blame] | 489 | MODULE_ALIAS("platform:omap-dwc3"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 490 | MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); |
| 491 | MODULE_LICENSE("Dual BSD/GPL"); |
| 492 | MODULE_DESCRIPTION("DesignWare USB3 OMAP Glue Layer"); |