David Lopo | aa69a80 | 2008-11-17 14:14:51 -0800 | [diff] [blame] | 1 | /* |
| 2 | * ci13xxx_udc.h - structures, registers, and macros MIPS USB IP core |
| 3 | * |
| 4 | * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved. |
| 5 | * |
| 6 | * Author: David Lopo |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * Description: MIPS USB IP core family device controller |
| 13 | * Structures, registers and logging macros |
| 14 | */ |
| 15 | |
| 16 | #ifndef _CI13XXX_h_ |
| 17 | #define _CI13XXX_h_ |
| 18 | |
| 19 | /****************************************************************************** |
| 20 | * DEFINE |
| 21 | *****************************************************************************/ |
Artem Leonenko | 0a313c4 | 2010-12-14 23:47:06 -0800 | [diff] [blame] | 22 | #define CI13XXX_PAGE_SIZE 4096ul /* page size for TD's */ |
Pavankumar Kondeti | ca9cfea | 2011-01-11 09:19:22 +0530 | [diff] [blame] | 23 | #define ENDPT_MAX (32) |
David Lopo | aa69a80 | 2008-11-17 14:14:51 -0800 | [diff] [blame] | 24 | #define CTRL_PAYLOAD_MAX (64) |
| 25 | #define RX (0) /* similar to USB_DIR_OUT but can be used as an index */ |
| 26 | #define TX (1) /* similar to USB_DIR_IN but can be used as an index */ |
| 27 | |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 28 | /* UDC private data: |
| 29 | * 16MSb - Vendor ID | 16 LSb Vendor private data |
| 30 | */ |
| 31 | #define CI13XX_REQ_VENDOR_ID(id) (id & 0xFFFF0000UL) |
| 32 | |
Ido Shayevitz | d1cb16c | 2012-03-28 18:57:47 +0200 | [diff] [blame^] | 33 | #define MSM_ETD_TYPE BIT(1) |
| 34 | #define MSM_EP_PIPE_ID_RESET_VAL 0x1F001F |
Ofir Cohen | a1c2a87 | 2011-12-14 10:26:34 +0200 | [diff] [blame] | 35 | |
David Lopo | aa69a80 | 2008-11-17 14:14:51 -0800 | [diff] [blame] | 36 | /****************************************************************************** |
| 37 | * STRUCTURES |
| 38 | *****************************************************************************/ |
| 39 | /* DMA layout of transfer descriptors */ |
| 40 | struct ci13xxx_td { |
| 41 | /* 0 */ |
| 42 | u32 next; |
| 43 | #define TD_TERMINATE BIT(0) |
Pavankumar Kondeti | 0e6ca19 | 2011-02-18 17:43:16 +0530 | [diff] [blame] | 44 | #define TD_ADDR_MASK (0xFFFFFFEUL << 5) |
David Lopo | aa69a80 | 2008-11-17 14:14:51 -0800 | [diff] [blame] | 45 | /* 1 */ |
| 46 | u32 token; |
| 47 | #define TD_STATUS (0x00FFUL << 0) |
| 48 | #define TD_STATUS_TR_ERR BIT(3) |
| 49 | #define TD_STATUS_DT_ERR BIT(5) |
| 50 | #define TD_STATUS_HALTED BIT(6) |
| 51 | #define TD_STATUS_ACTIVE BIT(7) |
| 52 | #define TD_MULTO (0x0003UL << 10) |
| 53 | #define TD_IOC BIT(15) |
| 54 | #define TD_TOTAL_BYTES (0x7FFFUL << 16) |
| 55 | /* 2 */ |
| 56 | u32 page[5]; |
| 57 | #define TD_CURR_OFFSET (0x0FFFUL << 0) |
| 58 | #define TD_FRAME_NUM (0x07FFUL << 0) |
| 59 | #define TD_RESERVED_MASK (0x0FFFUL << 0) |
| 60 | } __attribute__ ((packed)); |
| 61 | |
| 62 | /* DMA layout of queue heads */ |
| 63 | struct ci13xxx_qh { |
| 64 | /* 0 */ |
| 65 | u32 cap; |
| 66 | #define QH_IOS BIT(15) |
| 67 | #define QH_MAX_PKT (0x07FFUL << 16) |
| 68 | #define QH_ZLT BIT(29) |
| 69 | #define QH_MULT (0x0003UL << 30) |
| 70 | /* 1 */ |
| 71 | u32 curr; |
| 72 | /* 2 - 8 */ |
| 73 | struct ci13xxx_td td; |
| 74 | /* 9 */ |
| 75 | u32 RESERVED; |
| 76 | struct usb_ctrlrequest setup; |
| 77 | } __attribute__ ((packed)); |
| 78 | |
| 79 | /* Extension of usb_request */ |
| 80 | struct ci13xxx_req { |
| 81 | struct usb_request req; |
| 82 | unsigned map; |
| 83 | struct list_head queue; |
| 84 | struct ci13xxx_td *ptr; |
| 85 | dma_addr_t dma; |
Pavankumar Kondeti | 0e6ca19 | 2011-02-18 17:43:16 +0530 | [diff] [blame] | 86 | struct ci13xxx_td *zptr; |
| 87 | dma_addr_t zdma; |
David Lopo | aa69a80 | 2008-11-17 14:14:51 -0800 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | /* Extension of usb_ep */ |
| 91 | struct ci13xxx_ep { |
| 92 | struct usb_ep ep; |
David Brown | ac5d154 | 2012-02-06 10:37:22 -0800 | [diff] [blame] | 93 | const struct usb_endpoint_descriptor *desc; |
David Lopo | aa69a80 | 2008-11-17 14:14:51 -0800 | [diff] [blame] | 94 | u8 dir; |
| 95 | u8 num; |
| 96 | u8 type; |
| 97 | char name[16]; |
| 98 | struct { |
| 99 | struct list_head queue; |
| 100 | struct ci13xxx_qh *ptr; |
| 101 | dma_addr_t dma; |
Pavankumar Kondeti | ca9cfea | 2011-01-11 09:19:22 +0530 | [diff] [blame] | 102 | } qh; |
David Lopo | aa69a80 | 2008-11-17 14:14:51 -0800 | [diff] [blame] | 103 | int wedge; |
| 104 | |
| 105 | /* global resources */ |
| 106 | spinlock_t *lock; |
| 107 | struct device *device; |
| 108 | struct dma_pool *td_pool; |
Anji jonnala | 6fb918c | 2011-10-21 17:54:21 +0530 | [diff] [blame] | 109 | unsigned long dTD_update_fail_count; |
David Lopo | aa69a80 | 2008-11-17 14:14:51 -0800 | [diff] [blame] | 110 | }; |
| 111 | |
Pavankumar Kondeti | f01ef57 | 2010-12-07 17:54:02 +0530 | [diff] [blame] | 112 | struct ci13xxx; |
| 113 | struct ci13xxx_udc_driver { |
| 114 | const char *name; |
| 115 | unsigned long flags; |
| 116 | #define CI13XXX_REGS_SHARED BIT(0) |
| 117 | #define CI13XXX_REQUIRE_TRANSCEIVER BIT(1) |
| 118 | #define CI13XXX_PULLUP_ON_VBUS BIT(2) |
| 119 | #define CI13XXX_DISABLE_STREAMING BIT(3) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 120 | #define CI13XXX_ZERO_ITC BIT(4) |
Vijayavardhan Vennapusa | d450cb0 | 2012-02-25 14:35:26 +0530 | [diff] [blame] | 121 | #define CI13XXX_IS_OTG BIT(5) |
Pavankumar Kondeti | f01ef57 | 2010-12-07 17:54:02 +0530 | [diff] [blame] | 122 | |
| 123 | #define CI13XXX_CONTROLLER_RESET_EVENT 0 |
Ofir Cohen | 06789f1 | 2012-01-16 09:43:13 +0200 | [diff] [blame] | 124 | #define CI13XXX_CONTROLLER_CONNECT_EVENT 1 |
Ofir Cohen | dca06cb | 2012-03-08 16:37:45 +0200 | [diff] [blame] | 125 | #define CI13XXX_CONTROLLER_SUSPEND_EVENT 2 |
Pavankumar Kondeti | f01ef57 | 2010-12-07 17:54:02 +0530 | [diff] [blame] | 126 | void (*notify_event) (struct ci13xxx *udc, unsigned event); |
| 127 | }; |
| 128 | |
David Lopo | aa69a80 | 2008-11-17 14:14:51 -0800 | [diff] [blame] | 129 | /* CI13XXX UDC descriptor & global resources */ |
| 130 | struct ci13xxx { |
| 131 | spinlock_t *lock; /* ctrl register bank access */ |
Pavankumar Kondeti | f01ef57 | 2010-12-07 17:54:02 +0530 | [diff] [blame] | 132 | void __iomem *regs; /* registers address space */ |
David Lopo | aa69a80 | 2008-11-17 14:14:51 -0800 | [diff] [blame] | 133 | |
| 134 | struct dma_pool *qh_pool; /* DMA pool for queue heads */ |
| 135 | struct dma_pool *td_pool; /* DMA pool for transfer descs */ |
Pavankumar Kondeti | ca9cfea | 2011-01-11 09:19:22 +0530 | [diff] [blame] | 136 | struct usb_request *status; /* ep0 status request */ |
David Lopo | aa69a80 | 2008-11-17 14:14:51 -0800 | [diff] [blame] | 137 | |
| 138 | struct usb_gadget gadget; /* USB slave device */ |
| 139 | struct ci13xxx_ep ci13xxx_ep[ENDPT_MAX]; /* extended endpts */ |
Pavankumar Kondeti | ca9cfea | 2011-01-11 09:19:22 +0530 | [diff] [blame] | 140 | u32 ep0_dir; /* ep0 direction */ |
| 141 | #define ep0out ci13xxx_ep[0] |
| 142 | #define ep0in ci13xxx_ep[16] |
Pavankumar Kondeti | e2b61c1 | 2011-02-18 17:43:17 +0530 | [diff] [blame] | 143 | u8 remote_wakeup; /* Is remote wakeup feature |
| 144 | enabled by the host? */ |
| 145 | u8 suspended; /* suspended by the host */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 146 | u8 configured; /* is device configured */ |
Pavankumar Kondeti | 541cace | 2011-02-18 17:43:18 +0530 | [diff] [blame] | 147 | u8 test_mode; /* the selected test mode */ |
David Lopo | aa69a80 | 2008-11-17 14:14:51 -0800 | [diff] [blame] | 148 | |
| 149 | struct usb_gadget_driver *driver; /* 3rd party gadget driver */ |
Pavankumar Kondeti | f01ef57 | 2010-12-07 17:54:02 +0530 | [diff] [blame] | 150 | struct ci13xxx_udc_driver *udc_driver; /* device controller driver */ |
| 151 | int vbus_active; /* is VBUS active */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 152 | int softconnect; /* is pull-up enable allowed */ |
Pavankumar Kondeti | f01ef57 | 2010-12-07 17:54:02 +0530 | [diff] [blame] | 153 | struct otg_transceiver *transceiver; /* Transceiver struct */ |
Anji jonnala | 6fb918c | 2011-10-21 17:54:21 +0530 | [diff] [blame] | 154 | unsigned long dTD_update_fail_count; |
David Lopo | aa69a80 | 2008-11-17 14:14:51 -0800 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | /****************************************************************************** |
| 158 | * REGISTERS |
| 159 | *****************************************************************************/ |
| 160 | /* register size */ |
| 161 | #define REG_BITS (32) |
| 162 | |
| 163 | /* HCCPARAMS */ |
| 164 | #define HCCPARAMS_LEN BIT(17) |
| 165 | |
| 166 | /* DCCPARAMS */ |
| 167 | #define DCCPARAMS_DEN (0x1F << 0) |
| 168 | #define DCCPARAMS_DC BIT(7) |
| 169 | |
| 170 | /* TESTMODE */ |
| 171 | #define TESTMODE_FORCE BIT(0) |
| 172 | |
| 173 | /* USBCMD */ |
| 174 | #define USBCMD_RS BIT(0) |
| 175 | #define USBCMD_RST BIT(1) |
| 176 | #define USBCMD_SUTW BIT(13) |
Pavankumar Kondeti | 0e6ca19 | 2011-02-18 17:43:16 +0530 | [diff] [blame] | 177 | #define USBCMD_ATDTW BIT(14) |
David Lopo | aa69a80 | 2008-11-17 14:14:51 -0800 | [diff] [blame] | 178 | |
| 179 | /* USBSTS & USBINTR */ |
| 180 | #define USBi_UI BIT(0) |
| 181 | #define USBi_UEI BIT(1) |
| 182 | #define USBi_PCI BIT(2) |
| 183 | #define USBi_URI BIT(6) |
| 184 | #define USBi_SLI BIT(8) |
| 185 | |
| 186 | /* DEVICEADDR */ |
| 187 | #define DEVICEADDR_USBADRA BIT(24) |
| 188 | #define DEVICEADDR_USBADR (0x7FUL << 25) |
| 189 | |
| 190 | /* PORTSC */ |
Pavankumar Kondeti | e2b61c1 | 2011-02-18 17:43:17 +0530 | [diff] [blame] | 191 | #define PORTSC_FPR BIT(6) |
David Lopo | aa69a80 | 2008-11-17 14:14:51 -0800 | [diff] [blame] | 192 | #define PORTSC_SUSP BIT(7) |
| 193 | #define PORTSC_HSP BIT(9) |
| 194 | #define PORTSC_PTC (0x0FUL << 16) |
| 195 | |
| 196 | /* DEVLC */ |
| 197 | #define DEVLC_PSPD (0x03UL << 25) |
| 198 | #define DEVLC_PSPD_HS (0x02UL << 25) |
| 199 | |
| 200 | /* USBMODE */ |
| 201 | #define USBMODE_CM (0x03UL << 0) |
| 202 | #define USBMODE_CM_IDLE (0x00UL << 0) |
| 203 | #define USBMODE_CM_DEVICE (0x02UL << 0) |
| 204 | #define USBMODE_CM_HOST (0x03UL << 0) |
| 205 | #define USBMODE_SLOM BIT(3) |
Pavankumar Kondeti | f01ef57 | 2010-12-07 17:54:02 +0530 | [diff] [blame] | 206 | #define USBMODE_SDIS BIT(4) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 207 | #define USBCMD_ITC(n) (n << 16) /* n = 0, 1, 2, 4, 8, 16, 32, 64 */ |
| 208 | #define USBCMD_ITC_MASK (0xFF << 16) |
David Lopo | aa69a80 | 2008-11-17 14:14:51 -0800 | [diff] [blame] | 209 | |
| 210 | /* ENDPTCTRL */ |
| 211 | #define ENDPTCTRL_RXS BIT(0) |
| 212 | #define ENDPTCTRL_RXT (0x03UL << 2) |
| 213 | #define ENDPTCTRL_RXR BIT(6) /* reserved for port 0 */ |
| 214 | #define ENDPTCTRL_RXE BIT(7) |
| 215 | #define ENDPTCTRL_TXS BIT(16) |
| 216 | #define ENDPTCTRL_TXT (0x03UL << 18) |
| 217 | #define ENDPTCTRL_TXR BIT(22) /* reserved for port 0 */ |
| 218 | #define ENDPTCTRL_TXE BIT(23) |
| 219 | |
| 220 | /****************************************************************************** |
| 221 | * LOGGING |
| 222 | *****************************************************************************/ |
| 223 | #define ci13xxx_printk(level, format, args...) \ |
| 224 | do { \ |
| 225 | if (_udc == NULL) \ |
| 226 | printk(level "[%s] " format "\n", __func__, ## args); \ |
| 227 | else \ |
| 228 | dev_printk(level, _udc->gadget.dev.parent, \ |
| 229 | "[%s] " format "\n", __func__, ## args); \ |
| 230 | } while (0) |
| 231 | |
Ofir Cohen | 06789f1 | 2012-01-16 09:43:13 +0200 | [diff] [blame] | 232 | #ifndef err |
David Lopo | aa69a80 | 2008-11-17 14:14:51 -0800 | [diff] [blame] | 233 | #define err(format, args...) ci13xxx_printk(KERN_ERR, format, ## args) |
Ofir Cohen | 06789f1 | 2012-01-16 09:43:13 +0200 | [diff] [blame] | 234 | #endif |
| 235 | |
David Lopo | aa69a80 | 2008-11-17 14:14:51 -0800 | [diff] [blame] | 236 | #define warn(format, args...) ci13xxx_printk(KERN_WARNING, format, ## args) |
| 237 | #define info(format, args...) ci13xxx_printk(KERN_INFO, format, ## args) |
| 238 | |
| 239 | #ifdef TRACE |
| 240 | #define trace(format, args...) ci13xxx_printk(KERN_DEBUG, format, ## args) |
| 241 | #define dbg_trace(format, args...) dev_dbg(dev, format, ##args) |
| 242 | #else |
| 243 | #define trace(format, args...) do {} while (0) |
| 244 | #define dbg_trace(format, args...) do {} while (0) |
| 245 | #endif |
| 246 | |
| 247 | #endif /* _CI13XXX_h_ */ |