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 | |
| 124 | void *context; |
| 125 | u32 resource_size; |
| 126 | |
| 127 | u32 dma_status:1; |
| 128 | }; |
| 129 | |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 130 | struct dwc3_omap *_omap; |
| 131 | |
Ido Shayevitz | ab5e59d | 2012-04-24 14:18:38 +0300 | [diff] [blame] | 132 | static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset) |
| 133 | { |
| 134 | return readl(base + offset); |
| 135 | } |
| 136 | |
| 137 | static inline void dwc3_omap_writel(void __iomem *base, u32 offset, u32 value) |
| 138 | { |
| 139 | writel(value, base + offset); |
| 140 | } |
| 141 | |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 142 | void dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status) |
| 143 | { |
| 144 | u32 val; |
| 145 | struct dwc3_omap *omap = _omap; |
| 146 | |
| 147 | switch (status) { |
| 148 | case OMAP_DWC3_ID_GROUND: |
| 149 | dev_dbg(omap->dev, "ID GND\n"); |
| 150 | |
| 151 | val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); |
| 152 | val &= ~(USBOTGSS_UTMI_OTG_STATUS_IDDIG |
| 153 | | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID |
| 154 | | USBOTGSS_UTMI_OTG_STATUS_SESSEND); |
| 155 | val |= USBOTGSS_UTMI_OTG_STATUS_SESSVALID |
| 156 | | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT; |
| 157 | dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val); |
| 158 | break; |
| 159 | |
| 160 | case OMAP_DWC3_VBUS_VALID: |
| 161 | dev_dbg(omap->dev, "VBUS Connect\n"); |
| 162 | |
| 163 | val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); |
| 164 | val &= ~USBOTGSS_UTMI_OTG_STATUS_SESSEND; |
| 165 | val |= USBOTGSS_UTMI_OTG_STATUS_IDDIG |
| 166 | | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID |
| 167 | | USBOTGSS_UTMI_OTG_STATUS_SESSVALID |
| 168 | | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT; |
| 169 | dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val); |
| 170 | break; |
| 171 | |
| 172 | case OMAP_DWC3_ID_FLOAT: |
| 173 | case OMAP_DWC3_VBUS_OFF: |
| 174 | dev_dbg(omap->dev, "VBUS Disconnect\n"); |
| 175 | |
| 176 | val = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); |
| 177 | val &= ~(USBOTGSS_UTMI_OTG_STATUS_SESSVALID |
| 178 | | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID |
| 179 | | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT); |
| 180 | val |= USBOTGSS_UTMI_OTG_STATUS_SESSEND |
| 181 | | USBOTGSS_UTMI_OTG_STATUS_IDDIG; |
| 182 | dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, val); |
| 183 | break; |
| 184 | |
| 185 | default: |
| 186 | dev_dbg(omap->dev, "ID float\n"); |
| 187 | } |
| 188 | |
| 189 | return; |
| 190 | } |
| 191 | EXPORT_SYMBOL_GPL(dwc3_omap_mailbox); |
| 192 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 193 | static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap) |
| 194 | { |
| 195 | struct dwc3_omap *omap = _omap; |
| 196 | u32 reg; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 197 | |
| 198 | spin_lock(&omap->lock); |
| 199 | |
Ido Shayevitz | ab5e59d | 2012-04-24 14:18:38 +0300 | [diff] [blame] | 200 | reg = dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_1); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 201 | |
| 202 | if (reg & USBOTGSS_IRQ1_DMADISABLECLR) { |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 203 | dev_dbg(omap->dev, "DMA Disable was Cleared\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 204 | omap->dma_status = false; |
| 205 | } |
| 206 | |
| 207 | if (reg & USBOTGSS_IRQ1_OEVT) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 208 | dev_dbg(omap->dev, "OTG Event\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 209 | |
Felipe Balbi | 42077b0 | 2011-09-06 12:00:39 +0300 | [diff] [blame] | 210 | if (reg & USBOTGSS_IRQ1_DRVVBUS_RISE) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 211 | dev_dbg(omap->dev, "DRVVBUS Rise\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 212 | |
Felipe Balbi | 42077b0 | 2011-09-06 12:00:39 +0300 | [diff] [blame] | 213 | if (reg & USBOTGSS_IRQ1_CHRGVBUS_RISE) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 214 | dev_dbg(omap->dev, "CHRGVBUS Rise\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 215 | |
Felipe Balbi | 42077b0 | 2011-09-06 12:00:39 +0300 | [diff] [blame] | 216 | if (reg & USBOTGSS_IRQ1_DISCHRGVBUS_RISE) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 217 | dev_dbg(omap->dev, "DISCHRGVBUS Rise\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 218 | |
Felipe Balbi | 42077b0 | 2011-09-06 12:00:39 +0300 | [diff] [blame] | 219 | if (reg & USBOTGSS_IRQ1_IDPULLUP_RISE) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 220 | dev_dbg(omap->dev, "IDPULLUP Rise\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 221 | |
Felipe Balbi | 42077b0 | 2011-09-06 12:00:39 +0300 | [diff] [blame] | 222 | if (reg & USBOTGSS_IRQ1_DRVVBUS_FALL) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 223 | dev_dbg(omap->dev, "DRVVBUS Fall\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 224 | |
Felipe Balbi | 42077b0 | 2011-09-06 12:00:39 +0300 | [diff] [blame] | 225 | if (reg & USBOTGSS_IRQ1_CHRGVBUS_FALL) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 226 | dev_dbg(omap->dev, "CHRGVBUS Fall\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 227 | |
Felipe Balbi | 42077b0 | 2011-09-06 12:00:39 +0300 | [diff] [blame] | 228 | if (reg & USBOTGSS_IRQ1_DISCHRGVBUS_FALL) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 229 | dev_dbg(omap->dev, "DISCHRGVBUS Fall\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 230 | |
Felipe Balbi | 42077b0 | 2011-09-06 12:00:39 +0300 | [diff] [blame] | 231 | if (reg & USBOTGSS_IRQ1_IDPULLUP_FALL) |
Felipe Balbi | ccba3bc | 2011-09-01 14:46:16 +0300 | [diff] [blame] | 232 | dev_dbg(omap->dev, "IDPULLUP Fall\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 233 | |
Ido Shayevitz | ab5e59d | 2012-04-24 14:18:38 +0300 | [diff] [blame] | 234 | dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_1, reg); |
Felipe Balbi | 42077b0 | 2011-09-06 12:00:39 +0300 | [diff] [blame] | 235 | |
Ido Shayevitz | ab5e59d | 2012-04-24 14:18:38 +0300 | [diff] [blame] | 236 | reg = dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_0); |
| 237 | dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_0, reg); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 238 | |
| 239 | spin_unlock(&omap->lock); |
| 240 | |
| 241 | return IRQ_HANDLED; |
| 242 | } |
| 243 | |
Kishon Vijay Abraham I | 94c6a43 | 2013-01-25 08:30:45 +0530 | [diff] [blame] | 244 | static int dwc3_omap_remove_core(struct device *dev, void *c) |
| 245 | { |
| 246 | struct platform_device *pdev = to_platform_device(dev); |
| 247 | |
| 248 | platform_device_unregister(pdev); |
| 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame^] | 253 | static void dwc3_omap_enable_irqs(struct dwc3_omap *omap) |
| 254 | { |
| 255 | u32 reg; |
| 256 | |
| 257 | /* enable all IRQs */ |
| 258 | reg = USBOTGSS_IRQO_COREIRQ_ST; |
| 259 | dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, reg); |
| 260 | |
| 261 | reg = (USBOTGSS_IRQ1_OEVT | |
| 262 | USBOTGSS_IRQ1_DRVVBUS_RISE | |
| 263 | USBOTGSS_IRQ1_CHRGVBUS_RISE | |
| 264 | USBOTGSS_IRQ1_DISCHRGVBUS_RISE | |
| 265 | USBOTGSS_IRQ1_IDPULLUP_RISE | |
| 266 | USBOTGSS_IRQ1_DRVVBUS_FALL | |
| 267 | USBOTGSS_IRQ1_CHRGVBUS_FALL | |
| 268 | USBOTGSS_IRQ1_DISCHRGVBUS_FALL | |
| 269 | USBOTGSS_IRQ1_IDPULLUP_FALL); |
| 270 | |
| 271 | dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, reg); |
| 272 | } |
| 273 | |
| 274 | static void dwc3_omap_disable_irqs(struct dwc3_omap *omap) |
| 275 | { |
| 276 | /* disable all IRQs */ |
| 277 | dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, 0x00); |
| 278 | dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, 0x00); |
| 279 | } |
| 280 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 281 | static int dwc3_omap_probe(struct platform_device *pdev) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 282 | { |
Felipe Balbi | 45b3cd4a | 2012-01-25 11:07:03 +0200 | [diff] [blame] | 283 | struct device_node *node = pdev->dev.of_node; |
| 284 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 285 | struct dwc3_omap *omap; |
| 286 | struct resource *res; |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 287 | struct device *dev = &pdev->dev; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 288 | |
| 289 | int ret = -ENOMEM; |
| 290 | int irq; |
| 291 | |
Kishon Vijay Abraham I | e36a0c8 | 2013-02-26 20:03:27 +0530 | [diff] [blame] | 292 | int utmi_mode = 0; |
| 293 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 294 | u32 reg; |
| 295 | |
| 296 | void __iomem *base; |
| 297 | void *context; |
| 298 | |
Kishon Vijay Abraham I | 4495afc | 2013-02-26 20:03:28 +0530 | [diff] [blame] | 299 | if (!node) { |
| 300 | dev_err(dev, "device node not found\n"); |
| 301 | return -EINVAL; |
| 302 | } |
| 303 | |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 304 | omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 305 | if (!omap) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 306 | dev_err(dev, "not enough memory\n"); |
| 307 | return -ENOMEM; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | platform_set_drvdata(pdev, omap); |
| 311 | |
Kishon Vijay Abraham I | e36a0c8 | 2013-02-26 20:03:27 +0530 | [diff] [blame] | 312 | irq = platform_get_irq(pdev, 0); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 313 | if (irq < 0) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 314 | dev_err(dev, "missing IRQ resource\n"); |
| 315 | return -EINVAL; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 316 | } |
| 317 | |
Kishon Vijay Abraham I | e36a0c8 | 2013-02-26 20:03:27 +0530 | [diff] [blame] | 318 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 319 | if (!res) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 320 | dev_err(dev, "missing memory base resource\n"); |
| 321 | return -EINVAL; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 322 | } |
| 323 | |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 324 | base = devm_ioremap_nocache(dev, res->start, resource_size(res)); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 325 | if (!base) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 326 | dev_err(dev, "ioremap failed\n"); |
| 327 | return -ENOMEM; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 328 | } |
| 329 | |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 330 | context = devm_kzalloc(dev, resource_size(res), GFP_KERNEL); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 331 | if (!context) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 332 | dev_err(dev, "couldn't allocate dwc3 context memory\n"); |
Kishon Vijay Abraham I | b4bfe6a | 2013-01-25 08:30:46 +0530 | [diff] [blame] | 333 | return -ENOMEM; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | spin_lock_init(&omap->lock); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 337 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 338 | omap->resource_size = resource_size(res); |
| 339 | omap->context = context; |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 340 | omap->dev = dev; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 341 | omap->irq = irq; |
| 342 | omap->base = base; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 343 | |
Kishon Vijay Abraham I | 7e41bba | 2013-01-25 08:30:49 +0530 | [diff] [blame] | 344 | /* |
| 345 | * REVISIT if we ever have two instances of the wrapper, we will be |
| 346 | * in big trouble |
| 347 | */ |
| 348 | _omap = omap; |
| 349 | |
Kishon Vijay Abraham I | af310e9 | 2013-01-25 08:30:47 +0530 | [diff] [blame] | 350 | pm_runtime_enable(dev); |
| 351 | ret = pm_runtime_get_sync(dev); |
| 352 | if (ret < 0) { |
| 353 | dev_err(dev, "get_sync failed with err %d\n", ret); |
| 354 | return ret; |
| 355 | } |
| 356 | |
Ido Shayevitz | ab5e59d | 2012-04-24 14:18:38 +0300 | [diff] [blame] | 357 | reg = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); |
Felipe Balbi | 9962444 | 2011-09-01 22:26:25 +0300 | [diff] [blame] | 358 | |
Kishon Vijay Abraham I | 4495afc | 2013-02-26 20:03:28 +0530 | [diff] [blame] | 359 | of_property_read_u32(node, "utmi-mode", &utmi_mode); |
Kishon Vijay Abraham I | e36a0c8 | 2013-02-26 20:03:27 +0530 | [diff] [blame] | 360 | |
| 361 | switch (utmi_mode) { |
| 362 | case DWC3_OMAP_UTMI_MODE_SW: |
| 363 | reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE; |
| 364 | break; |
| 365 | case DWC3_OMAP_UTMI_MODE_HW: |
| 366 | reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE; |
| 367 | break; |
| 368 | default: |
| 369 | dev_dbg(dev, "UNKNOWN utmi mode %d\n", utmi_mode); |
Felipe Balbi | 9962444 | 2011-09-01 22:26:25 +0300 | [diff] [blame] | 370 | } |
| 371 | |
Ido Shayevitz | ab5e59d | 2012-04-24 14:18:38 +0300 | [diff] [blame] | 372 | dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, reg); |
Felipe Balbi | 9962444 | 2011-09-01 22:26:25 +0300 | [diff] [blame] | 373 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 374 | /* check the DMA Status */ |
Ido Shayevitz | ab5e59d | 2012-04-24 14:18:38 +0300 | [diff] [blame] | 375 | reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 376 | omap->dma_status = !!(reg & USBOTGSS_SYSCONFIG_DMADISABLE); |
| 377 | |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 378 | ret = devm_request_irq(dev, omap->irq, dwc3_omap_interrupt, 0, |
Felipe Balbi | dd17a6b | 2011-09-06 10:57:41 +0300 | [diff] [blame] | 379 | "dwc3-omap", omap); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 380 | if (ret) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 381 | dev_err(dev, "failed to request IRQ #%d --> %d\n", |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 382 | omap->irq, ret); |
Kishon Vijay Abraham I | b4bfe6a | 2013-01-25 08:30:46 +0530 | [diff] [blame] | 383 | return ret; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 384 | } |
| 385 | |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame^] | 386 | dwc3_omap_enable_irqs(omap); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 387 | |
Kishon Vijay Abraham I | 4495afc | 2013-02-26 20:03:28 +0530 | [diff] [blame] | 388 | ret = of_platform_populate(node, NULL, NULL, dev); |
| 389 | if (ret) { |
| 390 | dev_err(&pdev->dev, "failed to create dwc3 core\n"); |
| 391 | return ret; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | return 0; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 395 | } |
| 396 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 397 | static int dwc3_omap_remove(struct platform_device *pdev) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 398 | { |
Felipe Balbi | 9a4b5da | 2013-02-11 11:03:59 +0200 | [diff] [blame^] | 399 | struct dwc3_omap *omap = platform_get_drvdata(pdev); |
| 400 | |
| 401 | dwc3_omap_disable_irqs(omap); |
Kishon Vijay Abraham I | af310e9 | 2013-01-25 08:30:47 +0530 | [diff] [blame] | 402 | pm_runtime_put_sync(&pdev->dev); |
| 403 | pm_runtime_disable(&pdev->dev); |
Kishon Vijay Abraham I | 94c6a43 | 2013-01-25 08:30:45 +0530 | [diff] [blame] | 404 | device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core); |
| 405 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 406 | return 0; |
| 407 | } |
| 408 | |
Felipe Balbi | 2c2dc89 | 2013-02-11 10:31:15 +0200 | [diff] [blame] | 409 | static const struct of_device_id of_dwc3_match[] = { |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 410 | { |
Kishon Vijay Abraham I | e36a0c8 | 2013-02-26 20:03:27 +0530 | [diff] [blame] | 411 | .compatible = "ti,dwc3" |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 412 | }, |
| 413 | { }, |
| 414 | }; |
Felipe Balbi | 2c2dc89 | 2013-02-11 10:31:15 +0200 | [diff] [blame] | 415 | MODULE_DEVICE_TABLE(of, of_dwc3_match); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 416 | |
| 417 | static struct platform_driver dwc3_omap_driver = { |
| 418 | .probe = dwc3_omap_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 419 | .remove = dwc3_omap_remove, |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 420 | .driver = { |
| 421 | .name = "omap-dwc3", |
Felipe Balbi | 2c2dc89 | 2013-02-11 10:31:15 +0200 | [diff] [blame] | 422 | .of_match_table = of_dwc3_match, |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 423 | }, |
| 424 | }; |
| 425 | |
Axel Lin | cc27c96 | 2011-11-27 20:16:27 +0800 | [diff] [blame] | 426 | module_platform_driver(dwc3_omap_driver); |
| 427 | |
Sebastian Andrzej Siewior | 7ae4fc4 | 2011-10-19 19:39:50 +0200 | [diff] [blame] | 428 | MODULE_ALIAS("platform:omap-dwc3"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 429 | MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); |
| 430 | MODULE_LICENSE("Dual BSD/GPL"); |
| 431 | MODULE_DESCRIPTION("DesignWare USB3 OMAP Glue Layer"); |