uss820dci.h revision 190749
1240116Smarcel/* $FreeBSD: head/sys/dev/usb/controller/uss820dci.h 190749 2009-04-05 21:24:15Z piso $ */ 2240116Smarcel/*- 3240116Smarcel * Copyright (c) 2007 Hans Petter Selasky <hselasky@FreeBSD.org> 4240116Smarcel * All rights reserved. 5240116Smarcel * 6240116Smarcel * Redistribution and use in source and binary forms, with or without 7240116Smarcel * modification, are permitted provided that the following conditions 8240116Smarcel * are met: 9240116Smarcel * 1. Redistributions of source code must retain the above copyright 10240116Smarcel * notice, this list of conditions and the following disclaimer. 11240116Smarcel * 2. Redistributions in binary form must reproduce the above copyright 12240116Smarcel * notice, this list of conditions and the following disclaimer in the 13240116Smarcel * documentation and/or other materials provided with the distribution. 14240116Smarcel * 15240116Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16240116Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17240116Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18240116Smarcel * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19240116Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20240116Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21240116Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22240116Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23240116Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24240116Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25240116Smarcel * SUCH DAMAGE. 26275988Sngie */ 27275988Sngie 28240116Smarcel#ifndef _USS820_DCI_H_ 29240116Smarcel#define _USS820_DCI_H_ 30240116Smarcel 31240116Smarcel#define USS820_MAX_DEVICES (USB_MIN_DEVICES + 1) 32275988Sngie 33275988Sngie#define USS820_EP_MAX 8 /* maximum number of endpoints */ 34240116Smarcel 35240116Smarcel#define USS820_TXDAT 0x00 /* Transmit FIFO data */ 36240116Smarcel 37240116Smarcel#define USS820_TXCNTL 0x01 /* Transmit FIFO byte count low */ 38240116Smarcel#define USS820_TXCNTL_MASK 0xFF 39275988Sngie 40275988Sngie#define USS820_TXCNTH 0x02 /* Transmit FIFO byte count high */ 41275988Sngie#define USS820_TXCNTH_MASK 0x03 42240116Smarcel#define USS820_TXCNTH_UNUSED 0xFC 43240116Smarcel 44240116Smarcel#define USS820_TXCON 0x03 /* USB transmit FIFO control */ 45240116Smarcel#define USS820_TXCON_REVRP 0x01 46240116Smarcel#define USS820_TXCON_ADVRM 0x02 47240116Smarcel#define USS820_TXCON_ATM 0x04 /* Automatic Transmit Management */ 48240116Smarcel#define USS820_TXCON_TXISO 0x08 /* Transmit Isochronous Data */ 49240116Smarcel#define USS820_TXCON_UNUSED 0x10 50240116Smarcel#define USS820_TXCON_FFSZ_16_64 0x00 51240116Smarcel#define USS820_TXCON_FFSZ_64_256 0x20 52240116Smarcel#define USS820_TXCON_FFSZ_8_512 0x40 53240116Smarcel#define USS820_TXCON_FFSZ_32_1024 0x60 54240116Smarcel#define USS820_TXCON_FFSZ_MASK 0x60 55240116Smarcel#define USS820_TXCON_TXCLR 0x80 /* Transmit FIFO clear */ 56240116Smarcel 57240116Smarcel#define USS820_TXFLG 0x04 /* Transmit FIFO flag (Read Only) */ 58240116Smarcel#define USS820_TXFLG_TXOVF 0x01 /* TX overrun */ 59240116Smarcel#define USS820_TXFLG_TXURF 0x02 /* TX underrun */ 60240116Smarcel#define USS820_TXFLG_TXFULL 0x04 /* TX full */ 61260029Sjmmv#define USS820_TXFLG_TXEMP 0x08 /* TX empty */ 62240116Smarcel#define USS820_TXFLG_UNUSED 0x30 63240116Smarcel#define USS820_TXFLG_TXFIF0 0x40 64240116Smarcel#define USS820_TXFLG_TXFIF1 0x80 65240116Smarcel 66240116Smarcel#define USS820_RXDAT 0x05 /* Receive FIFO data */ 67240116Smarcel 68240116Smarcel#define USS820_RXCNTL 0x06 /* Receive FIFO byte count low */ 69240116Smarcel#define USS820_RXCNTL_MASK 0xFF 70240116Smarcel 71240116Smarcel#define USS820_RXCNTH 0x07 /* Receive FIFO byte count high */ 72240116Smarcel#define USS820_RXCNTH_MASK 0x03 73240116Smarcel#define USS820_RXCNTH_UNUSED 0xFC 74240116Smarcel 75240116Smarcel#define USS820_RXCON 0x08 /* Receive FIFO control */ 76240116Smarcel#define USS820_RXCON_REVWP 0x01 77240116Smarcel#define USS820_RXCON_ADVWM 0x02 78240116Smarcel#define USS820_RXCON_ARM 0x04 /* Auto Receive Management */ 79240116Smarcel#define USS820_RXCON_RXISO 0x08 /* Receive Isochronous Data */ 80240116Smarcel#define USS820_RXCON_RXFFRC 0x10 /* FIFO Read Complete */ 81240116Smarcel#define USS820_RXCON_FFSZ_16_64 0x00 82240116Smarcel#define USS820_RXCON_FFSZ_64_256 0x20 83240116Smarcel#define USS820_RXCON_FFSZ_8_512 0x40 84240116Smarcel#define USS820_RXCON_FFSZ_32_1024 0x60 85240116Smarcel#define USS820_RXCON_RXCLR 0x80 /* Receive FIFO clear */ 86240116Smarcel 87240116Smarcel#define USS820_RXFLG 0x09 /* Receive FIFO flag (Read Only) */ 88240116Smarcel#define USS820_RXFLG_RXOVF 0x01 /* RX overflow */ 89240116Smarcel#define USS820_RXFLG_RXURF 0x02 /* RX underflow */ 90240116Smarcel#define USS820_RXFLG_RXFULL 0x04 /* RX full */ 91240116Smarcel#define USS820_RXFLG_RXEMP 0x08 /* RX empty */ 92240116Smarcel#define USS820_RXFLG_RXFLUSH 0x10 /* RX flush */ 93240116Smarcel#define USS820_RXFLG_UNUSED 0x20 94240116Smarcel#define USS820_RXFLG_RXFIF0 0x40 95240116Smarcel#define USS820_RXFLG_RXFIF1 0x80 96240116Smarcel 97240116Smarcel#define USS820_EPINDEX 0x0a /* Endpoint index selection */ 98240116Smarcel#define USS820_EPINDEX_MASK 0x07 99240116Smarcel#define USS820_EPINDEX_UNUSED 0xF8 100240116Smarcel 101240116Smarcel#define USS820_EPCON 0x0b /* Endpoint control */ 102240116Smarcel#define USS820_EPCON_TXEPEN 0x01 /* Transmit Endpoint Enable */ 103240116Smarcel#define USS820_EPCON_TXOE 0x02 /* Transmit Output Enable */ 104240116Smarcel#define USS820_EPCON_RXEPEN 0x04 /* Receive Endpoint Enable */ 105240116Smarcel#define USS820_EPCON_RXIE 0x08 /* Receive Input Enable */ 106240116Smarcel#define USS820_EPCON_RXSPM 0x10 /* Receive Single-Packet Mode */ 107240116Smarcel#define USS820_EPCON_CTLEP 0x20 /* Control Endpoint */ 108240116Smarcel#define USS820_EPCON_TXSTL 0x40 /* Stall Transmit Endpoint */ 109240116Smarcel#define USS820_EPCON_RXSTL 0x80 /* Stall Receive Endpoint */ 110240116Smarcel 111240116Smarcel#define USS820_TXSTAT 0x0c /* Transmit status */ 112240116Smarcel#define USS820_TXSTAT_TXACK 0x01 /* Transmit Acknowledge */ 113240116Smarcel#define USS820_TXSTAT_TXERR 0x02 /* Transmit Error */ 114240116Smarcel#define USS820_TXSTAT_TXVOID 0x04 /* Transmit Void */ 115240116Smarcel#define USS820_TXSTAT_TXSOVW 0x08 /* Transmit Data Sequence Overwrite 116240116Smarcel * Bit */ 117240116Smarcel#define USS820_TXSTAT_TXFLUSH 0x10 /* Transmit FIFO Packet Flushed */ 118240116Smarcel#define USS820_TXSTAT_TXNAKE 0x20 /* Transmit NAK Mode Enable */ 119240116Smarcel#define USS820_TXSTAT_TXDSAM 0x40 /* Transmit Data-Set-Available Mode */ 120240116Smarcel#define USS820_TXSTAT_TXSEQ 0x80 /* Transmitter Current Sequence Bit */ 121240116Smarcel 122240116Smarcel#define USS820_RXSTAT 0x0d /* Receive status */ 123240116Smarcel#define USS820_RXSTAT_RXACK 0x01 /* Receive Acknowledge */ 124240116Smarcel#define USS820_RXSTAT_RXERR 0x02 /* Receive Error */ 125240116Smarcel#define USS820_RXSTAT_RXVOID 0x04 /* Receive Void */ 126240116Smarcel#define USS820_RXSTAT_RXSOVW 0x08 /* Receive Data Sequence Overwrite Bit */ 127240116Smarcel#define USS820_RXSTAT_EDOVW 0x10 /* End Overwrite Flag */ 128240116Smarcel#define USS820_RXSTAT_STOVW 0x20 /* Start Overwrite Flag */ 129240116Smarcel#define USS820_RXSTAT_RXSETUP 0x40 /* Received SETUP token */ 130240116Smarcel#define USS820_RXSTAT_RXSEQ 0x80 /* Receiver Endpoint Sequence Bit */ 131240116Smarcel 132240116Smarcel#define USS820_SOFL 0x0e /* Start Of Frame counter low */ 133240116Smarcel#define USS820_SOFL_MASK 0xFF 134240116Smarcel 135240116Smarcel#define USS820_SOFH 0x0f /* Start Of Frame counter high */ 136240116Smarcel#define USS820_SOFH_MASK 0x07 137240116Smarcel#define USS820_SOFH_SOFDIS 0x08 /* SOF Pin Output Disable */ 138240116Smarcel#define USS820_SOFH_FTLOCK 0x10 /* Frame Timer Lock */ 139240116Smarcel#define USS820_SOFH_SOFIE 0x20 /* SOF Interrupt Enable */ 140240116Smarcel#define USS820_SOFH_ASOF 0x40 /* Any Start of Frame */ 141240116Smarcel#define USS820_SOFH_SOFACK 0x80 /* SOF Token Received Without Error */ 142240116Smarcel 143240116Smarcel#define USS820_FADDR 0x10 /* Function Address */ 144240116Smarcel#define USS820_FADDR_MASK 0x7F 145240116Smarcel#define USS820_FADDR_UNUSED 0x80 146240116Smarcel 147240116Smarcel#define USS820_SCR 0x11 /* System Control */ 148240116Smarcel#define USS820_SCR_UNUSED 0x01 149240116Smarcel#define USS820_SCR_T_IRQ 0x02 /* Global Interrupt Enable */ 150240116Smarcel#define USS820_SCR_IRQLVL 0x04 /* Interrupt Mode */ 151240116Smarcel#define USS820_SCR_SRESET 0x08 /* Software reset */ 152240116Smarcel#define USS820_SCR_IE_RESET 0x10 /* Enable Reset Interrupt */ 153240116Smarcel#define USS820_SCR_IE_SUSP 0x20 /* Enable Suspend Interrupt */ 154240116Smarcel#define USS820_SCR_RWUPE 0x40 /* Enable Remote Wake-Up Feature */ 155240116Smarcel#define USS820_SCR_IRQPOL 0x80 /* IRQ polarity */ 156240116Smarcel 157240116Smarcel#define USS820_SSR 0x12 /* System Status */ 158240116Smarcel#define USS820_SSR_RESET 0x01 /* Reset Condition Detected on USB 159240116Smarcel * cable */ 160240116Smarcel#define USS820_SSR_SUSPEND 0x02 /* Suspend Detected */ 161240116Smarcel#define USS820_SSR_RESUME 0x04 /* Resume Detected */ 162240116Smarcel#define USS820_SSR_SUSPDIS 0x08 /* Suspend Disable */ 163240116Smarcel#define USS820_SSR_SUSPPO 0x10 /* Suspend Power Off */ 164240116Smarcel#define USS820_SSR_UNUSED 0xE0 165240116Smarcel 166240116Smarcel#define USS820_UNK0 0x13 /* Unknown */ 167240116Smarcel#define USS820_UNK0_UNUSED 0xFF 168240116Smarcel 169240116Smarcel#define USS820_SBI 0x14 /* Serial bus interrupt low */ 170240116Smarcel#define USS820_SBI_FTXD0 0x01 /* Function Transmit Done, EP 0 */ 171240116Smarcel#define USS820_SBI_FRXD0 0x02 /* Function Receive Done, EP 0 */ 172240116Smarcel#define USS820_SBI_FTXD1 0x04 173240116Smarcel#define USS820_SBI_FRXD1 0x08 174240116Smarcel#define USS820_SBI_FTXD2 0x10 175240116Smarcel#define USS820_SBI_FRXD2 0x20 176240116Smarcel#define USS820_SBI_FTXD3 0x40 177240116Smarcel#define USS820_SBI_FRXD3 0x80 178240116Smarcel 179240116Smarcel#define USS820_SBI1 0x15 /* Serial bus interrupt high */ 180240116Smarcel#define USS820_SBI1_FTXD4 0x01 181240116Smarcel#define USS820_SBI1_FRXD4 0x02 182240116Smarcel#define USS820_SBI1_FTXD5 0x04 183240116Smarcel#define USS820_SBI1_FRXD5 0x08 184240116Smarcel#define USS820_SBI1_FTXD6 0x10 185240116Smarcel#define USS820_SBI1_FRXD6 0x20 186240116Smarcel#define USS820_SBI1_FTXD7 0x40 187240116Smarcel#define USS820_SBI1_FRXD7 0x80 188240116Smarcel 189240116Smarcel#define USS820_SBIE 0x16 /* Serial bus interrupt enable low */ 190240116Smarcel#define USS820_SBIE_FTXIE0 0x01 191240116Smarcel#define USS820_SBIE_FRXIE0 0x02 192240116Smarcel#define USS820_SBIE_FTXIE1 0x04 193240116Smarcel#define USS820_SBIE_FRXIE1 0x08 194240116Smarcel#define USS820_SBIE_FTXIE2 0x10 195240116Smarcel#define USS820_SBIE_FRXIE2 0x20 196240116Smarcel#define USS820_SBIE_FTXIE3 0x40 197240116Smarcel#define USS820_SBIE_FRXIE3 0x80 198240116Smarcel 199240116Smarcel#define USS820_SBIE1 0x17 /* Serial bus interrupt enable high */ 200240116Smarcel#define USS820_SBIE1_FTXIE4 0x01 201240116Smarcel#define USS820_SBIE1_FRXIE4 0x02 202240116Smarcel#define USS820_SBIE1_FTXIE5 0x04 203240116Smarcel#define USS820_SBIE1_FRXIE5 0x08 204240116Smarcel#define USS820_SBIE1_FTXIE6 0x10 205240116Smarcel#define USS820_SBIE1_FRXIE6 0x20 206240116Smarcel#define USS820_SBIE1_FTXIE7 0x40 207240116Smarcel#define USS820_SBIE1_FRXIE7 0x80 208240116Smarcel 209240116Smarcel#define USS820_REV 0x18 /* Hardware revision */ 210240116Smarcel#define USS820_REV_MIN 0x0F 211240116Smarcel#define USS820_REV_MAJ 0xF0 212240116Smarcel 213240116Smarcel#define USS820_LOCK 0x19 /* Suspend power-off locking */ 214240116Smarcel#define USS820_LOCK_UNLOCKED 0x01 215240116Smarcel#define USS820_LOCK_UNUSED 0xFE 216240116Smarcel 217240116Smarcel#define USS820_PEND 0x1a /* Pend hardware status update */ 218240116Smarcel#define USS820_PEND_PEND 0x01 219240116Smarcel#define USS820_PEND_UNUSED 0xFE 220240116Smarcel 221240116Smarcel#define USS820_SCRATCH 0x1b /* Scratch firmware information */ 222240116Smarcel#define USS820_SCRATCH_MASK 0x7F 223240116Smarcel#define USS820_SCRATCH_IE_RESUME 0x80 /* Enable Resume Interrupt */ 224240116Smarcel 225240116Smarcel#define USS820_MCSR 0x1c /* Miscellaneous control and status */ 226240116Smarcel#define USS820_MCSR_DPEN 0x01 /* DPLS Pull-Up Enable */ 227240116Smarcel#define USS820_MCSR_SUSPLOE 0x02 /* Suspend Lock Out Enable */ 228240116Smarcel#define USS820_MCSR_BDFEAT 0x04 /* Board Feature Enable */ 229240116Smarcel#define USS820_MCSR_FEAT 0x08 /* Feature Enable */ 230240116Smarcel#define USS820_MCSR_PKGID 0x10 /* Package Identification */ 231240116Smarcel#define USS820_MCSR_SUSPS 0x20 /* Suspend Status */ 232240116Smarcel#define USS820_MCSR_INIT 0x40 /* Device Initialized */ 233240116Smarcel#define USS820_MCSR_RWUPR 0x80 /* Remote Wakeup-Up Remember */ 234240116Smarcel 235240116Smarcel#define USS820_DSAV 0x1d /* Data set available low (Read Only) */ 236240116Smarcel#define USS820_DSAV_TXAV0 0x01 237240116Smarcel#define USS820_DSAV_RXAV0 0x02 238240116Smarcel#define USS820_DSAV_TXAV1 0x04 239240116Smarcel#define USS820_DSAV_RXAV1 0x08 240240116Smarcel#define USS820_DSAV_TXAV2 0x10 241240116Smarcel#define USS820_DSAV_RXAV2 0x20 242240116Smarcel#define USS820_DSAV_TXAV3 0x40 243240116Smarcel#define USS820_DSAV_RXAV3 0x80 244240116Smarcel 245240116Smarcel#define USS820_DSAV1 0x1e /* Data set available high */ 246240116Smarcel#define USS820_DSAV1_TXAV4 0x01 247240116Smarcel#define USS820_DSAV1_RXAV4 0x02 248240116Smarcel#define USS820_DSAV1_TXAV5 0x04 249240116Smarcel#define USS820_DSAV1_RXAV5 0x08 250240116Smarcel#define USS820_DSAV1_TXAV6 0x10 251240116Smarcel#define USS820_DSAV1_RXAV6 0x20 252240116Smarcel#define USS820_DSAV1_TXAV7 0x40 253240116Smarcel#define USS820_DSAV1_RXAV7 0x80 254240116Smarcel 255240116Smarcel#define USS820_UNK1 0x1f /* Unknown */ 256240116Smarcel#define USS820_UNK1_UNKNOWN 0xFF 257240116Smarcel 258240116Smarcel#define USS820_GET_REG(sc,reg) \ 259240116Smarcel ((reg) << (sc)->sc_reg_shift) 260240116Smarcel 261240116Smarcel#define USS820_READ_1(sc, reg) \ 262240116Smarcel bus_space_read_1((sc)->sc_io_tag, (sc)->sc_io_hdl, \ 263240116Smarcel USS820_GET_REG(sc,reg)) 264240116Smarcel 265240116Smarcel#define USS820_WRITE_1(sc, reg, data) \ 266240116Smarcel bus_space_write_1((sc)->sc_io_tag, (sc)->sc_io_hdl, \ 267240116Smarcel USS820_GET_REG(sc,reg), data) 268240116Smarcel 269240116Smarcelstruct uss820dci_td; 270240116Smarcel 271240116Smarceltypedef uint8_t (uss820dci_cmd_t)(struct uss820dci_td *td); 272240116Smarcel 273240116Smarcelstruct uss820dci_td { 274275988Sngie bus_space_tag_t io_tag; 275 bus_space_handle_t io_hdl; 276 struct uss820dci_td *obj_next; 277 uss820dci_cmd_t *func; 278 struct usb2_page_cache *pc; 279 uint32_t offset; 280 uint32_t remainder; 281 uint16_t max_packet_size; 282 uint8_t rx_stat_reg; 283 uint8_t tx_stat_reg; 284 uint8_t rx_flag_reg; 285 uint8_t tx_flag_reg; 286 uint8_t rx_fifo_reg; 287 uint8_t tx_fifo_reg; 288 uint8_t rx_count_low_reg; 289 uint8_t rx_count_high_reg; 290 uint8_t tx_count_low_reg; 291 uint8_t tx_count_high_reg; 292 uint8_t rx_cntl_reg; 293 uint8_t tx_cntl_reg; 294 uint8_t ep_reg; 295 uint8_t pend_reg; 296 uint8_t ep_index; 297 uint8_t error:1; 298 uint8_t alt_next:1; 299 uint8_t short_pkt:1; 300 uint8_t support_multi_buffer:1; 301 uint8_t did_stall:1; 302}; 303 304struct uss820_std_temp { 305 uss820dci_cmd_t *func; 306 struct usb2_page_cache *pc; 307 struct uss820dci_td *td; 308 struct uss820dci_td *td_next; 309 uint32_t len; 310 uint32_t offset; 311 uint16_t max_frame_size; 312 uint8_t short_pkt; 313 /* 314 * short_pkt = 0: transfer should be short terminated 315 * short_pkt = 1: transfer should not be short terminated 316 */ 317 uint8_t setup_alt_next; 318}; 319 320struct uss820dci_config_desc { 321 struct usb2_config_descriptor confd; 322 struct usb2_interface_descriptor ifcd; 323 struct usb2_endpoint_descriptor endpd; 324} __packed; 325 326union uss820_hub_temp { 327 uWord wValue; 328 struct usb2_port_status ps; 329}; 330 331struct uss820_flags { 332 uint8_t change_connect:1; 333 uint8_t change_suspend:1; 334 uint8_t status_suspend:1; /* set if suspended */ 335 uint8_t status_vbus:1; /* set if present */ 336 uint8_t status_bus_reset:1; /* set if reset complete */ 337 uint8_t clocks_off:1; 338 uint8_t port_powered:1; 339 uint8_t port_enabled:1; 340 uint8_t d_pulled_up:1; 341 uint8_t mcsr_feat:1; 342}; 343 344struct uss820dci_softc { 345 struct usb2_bus sc_bus; 346 union uss820_hub_temp sc_hub_temp; 347 LIST_HEAD(, usb2_xfer) sc_interrupt_list_head; 348 349 struct usb2_device *sc_devices[USS820_MAX_DEVICES]; 350 struct resource *sc_io_res; 351 struct resource *sc_irq_res; 352 void *sc_intr_hdl; 353 bus_size_t sc_io_size; 354 bus_space_tag_t sc_io_tag; 355 bus_space_handle_t sc_io_hdl; 356 357 uint8_t sc_rt_addr; /* root HUB address */ 358 uint8_t sc_dv_addr; /* device address */ 359 uint8_t sc_conf; /* root HUB config */ 360 uint8_t sc_reg_shift; 361 362 uint8_t sc_hub_idata[1]; 363 364 struct uss820_flags sc_flags; 365}; 366 367/* prototypes */ 368 369usb2_error_t uss820dci_init(struct uss820dci_softc *sc); 370void uss820dci_uninit(struct uss820dci_softc *sc); 371void uss820dci_suspend(struct uss820dci_softc *sc); 372void uss820dci_resume(struct uss820dci_softc *sc); 373void uss820dci_interrupt(struct uss820dci_softc *sc); 374 375#endif /* _USS820_DCI_H_ */ 376