Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/usb/gadget/pxa2xx_udc.h |
| 3 | * Intel PXA2xx on-chip full speed USB device controller |
| 4 | * |
| 5 | * Copyright (C) 2003 Robert Schwebel <r.schwebel@pengutronix.de>, Pengutronix |
| 6 | * Copyright (C) 2003 David Brownell |
| 7 | * |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #ifndef __LINUX_USB_GADGET_PXA2XX_H |
| 25 | #define __LINUX_USB_GADGET_PXA2XX_H |
| 26 | |
| 27 | #include <linux/types.h> |
| 28 | |
| 29 | /*-------------------------------------------------------------------------*/ |
| 30 | |
| 31 | /* pxa2xx has this (move to include/asm-arm/arch-pxa/pxa-regs.h) */ |
| 32 | #define UFNRH_SIR (1 << 7) /* SOF interrupt request */ |
| 33 | #define UFNRH_SIM (1 << 6) /* SOF interrupt mask */ |
| 34 | #define UFNRH_IPE14 (1 << 5) /* ISO packet error, ep14 */ |
| 35 | #define UFNRH_IPE9 (1 << 4) /* ISO packet error, ep9 */ |
| 36 | #define UFNRH_IPE4 (1 << 3) /* ISO packet error, ep4 */ |
| 37 | |
| 38 | /* pxa255 has this (move to include/asm-arm/arch-pxa/pxa-regs.h) */ |
| 39 | #define UDCCFR UDC_RES2 /* UDC Control Function Register */ |
| 40 | #define UDCCFR_AREN (1 << 7) /* ACK response enable (now) */ |
| 41 | #define UDCCFR_ACM (1 << 2) /* ACK control mode (wait for AREN) */ |
| 42 | |
| 43 | /* latest pxa255 errata define new "must be one" bits in UDCCFR */ |
| 44 | #define UDCCFR_MB1 (0xff & ~(UDCCFR_AREN|UDCCFR_ACM)) |
| 45 | |
| 46 | /*-------------------------------------------------------------------------*/ |
| 47 | |
| 48 | struct pxa2xx_udc; |
| 49 | |
| 50 | struct pxa2xx_ep { |
| 51 | struct usb_ep ep; |
| 52 | struct pxa2xx_udc *dev; |
| 53 | |
| 54 | const struct usb_endpoint_descriptor *desc; |
| 55 | struct list_head queue; |
| 56 | unsigned long pio_irqs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | unsigned short fifo_size; |
| 59 | u8 bEndpointAddress; |
| 60 | u8 bmAttributes; |
| 61 | |
| 62 | unsigned stopped : 1; |
| 63 | unsigned dma_fixup : 1; |
David Brownell | ad8c623 | 2007-06-30 06:30:04 -0700 | [diff] [blame] | 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | /* UDCCS = UDC Control/Status for this EP |
| 66 | * UBCR = UDC Byte Count Remaining (contents of OUT fifo) |
| 67 | * UDDR = UDC Endpoint Data Register (the fifo) |
| 68 | * DRCM = DMA Request Channel Map |
| 69 | */ |
Ian Campbell | 63a4b52 | 2005-10-28 15:26:42 +0100 | [diff] [blame] | 70 | volatile u32 *reg_udccs; |
| 71 | volatile u32 *reg_ubcr; |
| 72 | volatile u32 *reg_uddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | struct pxa2xx_request { |
| 76 | struct usb_request req; |
| 77 | struct list_head queue; |
| 78 | }; |
| 79 | |
David Brownell | ad8c623 | 2007-06-30 06:30:04 -0700 | [diff] [blame] | 80 | enum ep0_state { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | EP0_IDLE, |
| 82 | EP0_IN_DATA_PHASE, |
| 83 | EP0_OUT_DATA_PHASE, |
| 84 | EP0_END_XFER, |
| 85 | EP0_STALL, |
| 86 | }; |
| 87 | |
| 88 | #define EP0_FIFO_SIZE ((unsigned)16) |
| 89 | #define BULK_FIFO_SIZE ((unsigned)64) |
| 90 | #define ISO_FIFO_SIZE ((unsigned)256) |
| 91 | #define INT_FIFO_SIZE ((unsigned)8) |
| 92 | |
| 93 | struct udc_stats { |
| 94 | struct ep0stats { |
| 95 | unsigned long ops; |
| 96 | unsigned long bytes; |
| 97 | } read, write; |
| 98 | unsigned long irqs; |
| 99 | }; |
| 100 | |
| 101 | #ifdef CONFIG_USB_PXA2XX_SMALL |
| 102 | /* when memory's tight, SMALL config saves code+data. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | #define PXA_UDC_NUM_ENDPOINTS 3 |
| 104 | #endif |
| 105 | |
| 106 | #ifndef PXA_UDC_NUM_ENDPOINTS |
| 107 | #define PXA_UDC_NUM_ENDPOINTS 16 |
| 108 | #endif |
| 109 | |
| 110 | struct pxa2xx_udc { |
| 111 | struct usb_gadget gadget; |
| 112 | struct usb_gadget_driver *driver; |
| 113 | |
| 114 | enum ep0_state ep0state; |
| 115 | struct udc_stats stats; |
| 116 | unsigned got_irq : 1, |
| 117 | vbus : 1, |
| 118 | pullup : 1, |
| 119 | has_cfr : 1, |
| 120 | req_pending : 1, |
| 121 | req_std : 1, |
| 122 | req_config : 1; |
| 123 | |
| 124 | #define start_watchdog(dev) mod_timer(&dev->timer, jiffies + (HZ/200)) |
| 125 | struct timer_list timer; |
| 126 | |
| 127 | struct device *dev; |
| 128 | struct pxa2xx_udc_mach_info *mach; |
| 129 | u64 dma_mask; |
| 130 | struct pxa2xx_ep ep [PXA_UDC_NUM_ENDPOINTS]; |
| 131 | }; |
| 132 | |
| 133 | /*-------------------------------------------------------------------------*/ |
| 134 | |
| 135 | #ifdef CONFIG_ARCH_LUBBOCK |
| 136 | #include <asm/arch/lubbock.h> |
| 137 | /* lubbock can also report usb connect/disconnect irqs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | #endif |
| 139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | static struct pxa2xx_udc *the_controller; |
| 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | /*-------------------------------------------------------------------------*/ |
| 143 | |
| 144 | /* |
| 145 | * Debugging support vanishes in non-debug builds. DBG_NORMAL should be |
| 146 | * mostly silent during normal use/testing, with no timing side-effects. |
| 147 | */ |
| 148 | #define DBG_NORMAL 1 /* error paths, device state transitions */ |
| 149 | #define DBG_VERBOSE 2 /* add some success path trace info */ |
| 150 | #define DBG_NOISY 3 /* ... even more: request level */ |
| 151 | #define DBG_VERY_NOISY 4 /* ... even more: packet level */ |
| 152 | |
| 153 | #ifdef DEBUG |
| 154 | |
| 155 | static const char *state_name[] = { |
| 156 | "EP0_IDLE", |
| 157 | "EP0_IN_DATA_PHASE", "EP0_OUT_DATA_PHASE", |
| 158 | "EP0_END_XFER", "EP0_STALL" |
| 159 | }; |
| 160 | |
| 161 | #define DMSG(stuff...) printk(KERN_DEBUG "udc: " stuff) |
| 162 | |
| 163 | #ifdef VERBOSE |
| 164 | # define UDC_DEBUG DBG_VERBOSE |
| 165 | #else |
| 166 | # define UDC_DEBUG DBG_NORMAL |
| 167 | #endif |
| 168 | |
David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 169 | static void __maybe_unused |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | dump_udccr(const char *label) |
| 171 | { |
| 172 | u32 udccr = UDCCR; |
| 173 | DMSG("%s %02X =%s%s%s%s%s%s%s%s\n", |
| 174 | label, udccr, |
| 175 | (udccr & UDCCR_REM) ? " rem" : "", |
| 176 | (udccr & UDCCR_RSTIR) ? " rstir" : "", |
| 177 | (udccr & UDCCR_SRM) ? " srm" : "", |
| 178 | (udccr & UDCCR_SUSIR) ? " susir" : "", |
| 179 | (udccr & UDCCR_RESIR) ? " resir" : "", |
| 180 | (udccr & UDCCR_RSM) ? " rsm" : "", |
| 181 | (udccr & UDCCR_UDA) ? " uda" : "", |
| 182 | (udccr & UDCCR_UDE) ? " ude" : ""); |
| 183 | } |
| 184 | |
David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 185 | static void __maybe_unused |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | dump_udccs0(const char *label) |
| 187 | { |
| 188 | u32 udccs0 = UDCCS0; |
| 189 | |
| 190 | DMSG("%s %s %02X =%s%s%s%s%s%s%s%s\n", |
| 191 | label, state_name[the_controller->ep0state], udccs0, |
| 192 | (udccs0 & UDCCS0_SA) ? " sa" : "", |
| 193 | (udccs0 & UDCCS0_RNE) ? " rne" : "", |
| 194 | (udccs0 & UDCCS0_FST) ? " fst" : "", |
| 195 | (udccs0 & UDCCS0_SST) ? " sst" : "", |
| 196 | (udccs0 & UDCCS0_DRWF) ? " dwrf" : "", |
| 197 | (udccs0 & UDCCS0_FTF) ? " ftf" : "", |
| 198 | (udccs0 & UDCCS0_IPR) ? " ipr" : "", |
| 199 | (udccs0 & UDCCS0_OPR) ? " opr" : ""); |
| 200 | } |
| 201 | |
David Rientjes | 8234509 | 2007-05-11 14:39:44 -0700 | [diff] [blame] | 202 | static void __maybe_unused |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | dump_state(struct pxa2xx_udc *dev) |
| 204 | { |
| 205 | u32 tmp; |
| 206 | unsigned i; |
| 207 | |
| 208 | DMSG("%s %s, uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n", |
| 209 | is_usb_connected() ? "host " : "disconnected", |
| 210 | state_name[dev->ep0state], |
| 211 | UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL); |
| 212 | dump_udccr("udccr"); |
| 213 | if (dev->has_cfr) { |
| 214 | tmp = UDCCFR; |
| 215 | DMSG("udccfr %02X =%s%s\n", tmp, |
| 216 | (tmp & UDCCFR_AREN) ? " aren" : "", |
| 217 | (tmp & UDCCFR_ACM) ? " acm" : ""); |
| 218 | } |
| 219 | |
| 220 | if (!dev->driver) { |
| 221 | DMSG("no gadget driver bound\n"); |
| 222 | return; |
| 223 | } else |
| 224 | DMSG("ep0 driver '%s'\n", dev->driver->driver.name); |
| 225 | |
| 226 | if (!is_usb_connected()) |
| 227 | return; |
| 228 | |
| 229 | dump_udccs0 ("udccs0"); |
| 230 | DMSG("ep0 IN %lu/%lu, OUT %lu/%lu\n", |
| 231 | dev->stats.write.bytes, dev->stats.write.ops, |
| 232 | dev->stats.read.bytes, dev->stats.read.ops); |
| 233 | |
| 234 | for (i = 1; i < PXA_UDC_NUM_ENDPOINTS; i++) { |
| 235 | if (dev->ep [i].desc == 0) |
| 236 | continue; |
| 237 | DMSG ("udccs%d = %02x\n", i, *dev->ep->reg_udccs); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | #else |
| 242 | |
| 243 | #define DMSG(stuff...) do{}while(0) |
| 244 | |
| 245 | #define dump_udccr(x) do{}while(0) |
| 246 | #define dump_udccs0(x) do{}while(0) |
| 247 | #define dump_state(x) do{}while(0) |
| 248 | |
| 249 | #define UDC_DEBUG ((unsigned)0) |
| 250 | |
| 251 | #endif |
| 252 | |
| 253 | #define DBG(lvl, stuff...) do{if ((lvl) <= UDC_DEBUG) DMSG(stuff);}while(0) |
| 254 | |
| 255 | #define WARN(stuff...) printk(KERN_WARNING "udc: " stuff) |
| 256 | #define INFO(stuff...) printk(KERN_INFO "udc: " stuff) |
| 257 | |
| 258 | |
| 259 | #endif /* __LINUX_USB_GADGET_PXA2XX_H */ |