1184610Salfred/* $FreeBSD$ */ 2184610Salfred/*- 3184610Salfred * Copyright (c) 2001 The NetBSD Foundation, Inc. 4184610Salfred * All rights reserved. 5184610Salfred * 6184610Salfred * This code is derived from software contributed to The NetBSD Foundation 7184610Salfred * by Lennart Augustsson (lennart@augustsson.net). 8184610Salfred * 9184610Salfred * Redistribution and use in source and binary forms, with or without 10184610Salfred * modification, are permitted provided that the following conditions 11184610Salfred * are met: 12184610Salfred * 1. Redistributions of source code must retain the above copyright 13184610Salfred * notice, this list of conditions and the following disclaimer. 14184610Salfred * 2. Redistributions in binary form must reproduce the above copyright 15184610Salfred * notice, this list of conditions and the following disclaimer in the 16184610Salfred * documentation and/or other materials provided with the distribution. 17184610Salfred * 18184610Salfred * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19184610Salfred * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20184610Salfred * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21184610Salfred * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22184610Salfred * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23184610Salfred * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24184610Salfred * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25184610Salfred * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26184610Salfred * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27184610Salfred * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28184610Salfred * POSSIBILITY OF SUCH DAMAGE. 29184610Salfred */ 30184610Salfred 31184610Salfred#ifndef _EHCI_H_ 32184610Salfred#define _EHCI_H_ 33184610Salfred 34190174Sthompsa#define EHCI_MAX_DEVICES MIN(USB_MAX_DEVICES, 128) 35187170Sthompsa 36184610Salfred/* 37184610Salfred * Alignment NOTE: structures must be aligned so that the hardware can index 38184610Salfred * without performing addition. 39184610Salfred */ 40184610Salfred#define EHCI_FRAMELIST_ALIGN 0x1000 /* bytes */ 41184610Salfred#define EHCI_FRAMELIST_COUNT 1024 /* units */ 42184610Salfred#define EHCI_VIRTUAL_FRAMELIST_COUNT 128 /* units */ 43184610Salfred 44184610Salfred#if ((8*EHCI_VIRTUAL_FRAMELIST_COUNT) < USB_MAX_HS_ISOC_FRAMES_PER_XFER) 45184610Salfred#error "maximum number of high-speed isochronous frames is higher than supported!" 46184610Salfred#endif 47184610Salfred 48184610Salfred#if (EHCI_VIRTUAL_FRAMELIST_COUNT < USB_MAX_FS_ISOC_FRAMES_PER_XFER) 49184610Salfred#error "maximum number of full-speed isochronous frames is higher than supported!" 50184610Salfred#endif 51184610Salfred 52184610Salfred/* Link types */ 53184610Salfred#define EHCI_LINK_TERMINATE 0x00000001 54184610Salfred#define EHCI_LINK_TYPE(x) ((x) & 0x00000006) 55184610Salfred#define EHCI_LINK_ITD 0x0 56184610Salfred#define EHCI_LINK_QH 0x2 57184610Salfred#define EHCI_LINK_SITD 0x4 58184610Salfred#define EHCI_LINK_FSTN 0x6 59184610Salfred#define EHCI_LINK_ADDR(x) ((x) &~ 0x1f) 60184610Salfred 61184610Salfred/* Structures alignment (bytes) */ 62184610Salfred#define EHCI_ITD_ALIGN 128 63184610Salfred#define EHCI_SITD_ALIGN 64 64184610Salfred#define EHCI_QTD_ALIGN 64 65184610Salfred#define EHCI_QH_ALIGN 128 66184610Salfred#define EHCI_FSTN_ALIGN 32 67184610Salfred/* Data buffers are divided into one or more pages */ 68184610Salfred#define EHCI_PAGE_SIZE 0x1000 69184610Salfred#if ((USB_PAGE_SIZE < EHCI_PAGE_SIZE) || (EHCI_PAGE_SIZE == 0) || \ 70184610Salfred (USB_PAGE_SIZE < EHCI_ITD_ALIGN) || (EHCI_ITD_ALIGN == 0) || \ 71184610Salfred (USB_PAGE_SIZE < EHCI_SITD_ALIGN) || (EHCI_SITD_ALIGN == 0) || \ 72184610Salfred (USB_PAGE_SIZE < EHCI_QTD_ALIGN) || (EHCI_QTD_ALIGN == 0) || \ 73184610Salfred (USB_PAGE_SIZE < EHCI_QH_ALIGN) || (EHCI_QH_ALIGN == 0) || \ 74184610Salfred (USB_PAGE_SIZE < EHCI_FSTN_ALIGN) || (EHCI_FSTN_ALIGN == 0)) 75184610Salfred#error "Invalid USB page size!" 76184610Salfred#endif 77184610Salfred 78184610Salfred 79184610Salfred/* 80184610Salfred * Isochronous Transfer Descriptor. This descriptor is used for high speed 81184610Salfred * transfers only. 82184610Salfred */ 83184610Salfredstruct ehci_itd { 84184610Salfred volatile uint32_t itd_next; 85184610Salfred volatile uint32_t itd_status[8]; 86184610Salfred#define EHCI_ITD_SET_LEN(x) ((x) << 16) 87184610Salfred#define EHCI_ITD_GET_LEN(x) (((x) >> 16) & 0xFFF) 88184610Salfred#define EHCI_ITD_IOC (1 << 15) 89184610Salfred#define EHCI_ITD_SET_PG(x) ((x) << 12) 90184610Salfred#define EHCI_ITD_GET_PG(x) (((x) >> 12) & 0x7) 91184610Salfred#define EHCI_ITD_SET_OFFS(x) (x) 92184610Salfred#define EHCI_ITD_GET_OFFS(x) (((x) >> 0) & 0xFFF) 93184610Salfred#define EHCI_ITD_ACTIVE (1 << 31) 94184610Salfred#define EHCI_ITD_DATABUFERR (1 << 30) 95184610Salfred#define EHCI_ITD_BABBLE (1 << 29) 96184610Salfred#define EHCI_ITD_XACTERR (1 << 28) 97184610Salfred volatile uint32_t itd_bp[7]; 98184610Salfred /* itd_bp[0] */ 99184610Salfred#define EHCI_ITD_SET_ADDR(x) (x) 100184610Salfred#define EHCI_ITD_GET_ADDR(x) (((x) >> 0) & 0x7F) 101184610Salfred#define EHCI_ITD_SET_ENDPT(x) ((x) << 8) 102184610Salfred#define EHCI_ITD_GET_ENDPT(x) (((x) >> 8) & 0xF) 103184610Salfred /* itd_bp[1] */ 104184610Salfred#define EHCI_ITD_SET_DIR_IN (1 << 11) 105184610Salfred#define EHCI_ITD_SET_DIR_OUT (0 << 11) 106184610Salfred#define EHCI_ITD_SET_MPL(x) (x) 107184610Salfred#define EHCI_ITD_GET_MPL(x) (((x) >> 0) & 0x7FF) 108184610Salfred volatile uint32_t itd_bp_hi[7]; 109184610Salfred/* 110184610Salfred * Extra information needed: 111184610Salfred */ 112184610Salfred uint32_t itd_self; 113184610Salfred struct ehci_itd *next; 114184610Salfred struct ehci_itd *prev; 115184610Salfred struct ehci_itd *obj_next; 116192984Sthompsa struct usb_page_cache *page_cache; 117184610Salfred} __aligned(EHCI_ITD_ALIGN); 118184610Salfred 119184610Salfredtypedef struct ehci_itd ehci_itd_t; 120184610Salfred 121184610Salfred/* 122184610Salfred * Split Transaction Isochronous Transfer Descriptor. This descriptor is used 123184610Salfred * for full speed transfers only. 124184610Salfred */ 125184610Salfredstruct ehci_sitd { 126184610Salfred volatile uint32_t sitd_next; 127184610Salfred volatile uint32_t sitd_portaddr; 128184610Salfred#define EHCI_SITD_SET_DIR_OUT (0 << 31) 129184610Salfred#define EHCI_SITD_SET_DIR_IN (1 << 31) 130184610Salfred#define EHCI_SITD_SET_ADDR(x) (x) 131184610Salfred#define EHCI_SITD_GET_ADDR(x) ((x) & 0x7F) 132184610Salfred#define EHCI_SITD_SET_ENDPT(x) ((x) << 8) 133184610Salfred#define EHCI_SITD_GET_ENDPT(x) (((x) >> 8) & 0xF) 134184610Salfred#define EHCI_SITD_GET_DIR(x) ((x) >> 31) 135184610Salfred#define EHCI_SITD_SET_PORT(x) ((x) << 24) 136184610Salfred#define EHCI_SITD_GET_PORT(x) (((x) >> 24) & 0x7F) 137184610Salfred#define EHCI_SITD_SET_HUBA(x) ((x) << 16) 138184610Salfred#define EHCI_SITD_GET_HUBA(x) (((x) >> 16) & 0x7F) 139184610Salfred volatile uint32_t sitd_mask; 140184610Salfred#define EHCI_SITD_SET_SMASK(x) (x) 141184610Salfred#define EHCI_SITD_SET_CMASK(x) ((x) << 8) 142184610Salfred volatile uint32_t sitd_status; 143184610Salfred#define EHCI_SITD_COMPLETE_SPLIT (1<<1) 144184610Salfred#define EHCI_SITD_START_SPLIT (0<<1) 145184610Salfred#define EHCI_SITD_MISSED_MICRO_FRAME (1<<2) 146184610Salfred#define EHCI_SITD_XACTERR (1<<3) 147184610Salfred#define EHCI_SITD_BABBLE (1<<4) 148184610Salfred#define EHCI_SITD_DATABUFERR (1<<5) 149184610Salfred#define EHCI_SITD_ERROR (1<<6) 150184610Salfred#define EHCI_SITD_ACTIVE (1<<7) 151184610Salfred#define EHCI_SITD_IOC (1<<31) 152184610Salfred#define EHCI_SITD_SET_LEN(len) ((len)<<16) 153184610Salfred#define EHCI_SITD_GET_LEN(x) (((x)>>16) & 0x3FF) 154184610Salfred volatile uint32_t sitd_bp[2]; 155184610Salfred volatile uint32_t sitd_back; 156184610Salfred volatile uint32_t sitd_bp_hi[2]; 157184610Salfred/* 158184610Salfred * Extra information needed: 159184610Salfred */ 160184610Salfred uint32_t sitd_self; 161184610Salfred struct ehci_sitd *next; 162184610Salfred struct ehci_sitd *prev; 163184610Salfred struct ehci_sitd *obj_next; 164192984Sthompsa struct usb_page_cache *page_cache; 165184610Salfred} __aligned(EHCI_SITD_ALIGN); 166184610Salfred 167184610Salfredtypedef struct ehci_sitd ehci_sitd_t; 168184610Salfred 169184610Salfred/* Queue Element Transfer Descriptor */ 170184610Salfredstruct ehci_qtd { 171184610Salfred volatile uint32_t qtd_next; 172184610Salfred volatile uint32_t qtd_altnext; 173184610Salfred volatile uint32_t qtd_status; 174184610Salfred#define EHCI_QTD_GET_STATUS(x) (((x) >> 0) & 0xff) 175184610Salfred#define EHCI_QTD_SET_STATUS(x) ((x) << 0) 176184610Salfred#define EHCI_QTD_ACTIVE 0x80 177184610Salfred#define EHCI_QTD_HALTED 0x40 178184610Salfred#define EHCI_QTD_BUFERR 0x20 179184610Salfred#define EHCI_QTD_BABBLE 0x10 180184610Salfred#define EHCI_QTD_XACTERR 0x08 181184610Salfred#define EHCI_QTD_MISSEDMICRO 0x04 182184610Salfred#define EHCI_QTD_SPLITXSTATE 0x02 183184610Salfred#define EHCI_QTD_PINGSTATE 0x01 184184610Salfred#define EHCI_QTD_STATERRS 0x74 185184610Salfred#define EHCI_QTD_GET_PID(x) (((x) >> 8) & 0x3) 186184610Salfred#define EHCI_QTD_SET_PID(x) ((x) << 8) 187184610Salfred#define EHCI_QTD_PID_OUT 0x0 188184610Salfred#define EHCI_QTD_PID_IN 0x1 189184610Salfred#define EHCI_QTD_PID_SETUP 0x2 190184610Salfred#define EHCI_QTD_GET_CERR(x) (((x) >> 10) & 0x3) 191184610Salfred#define EHCI_QTD_SET_CERR(x) ((x) << 10) 192184610Salfred#define EHCI_QTD_GET_C_PAGE(x) (((x) >> 12) & 0x7) 193184610Salfred#define EHCI_QTD_SET_C_PAGE(x) ((x) << 12) 194184610Salfred#define EHCI_QTD_GET_IOC(x) (((x) >> 15) & 0x1) 195184610Salfred#define EHCI_QTD_IOC 0x00008000 196184610Salfred#define EHCI_QTD_GET_BYTES(x) (((x) >> 16) & 0x7fff) 197184610Salfred#define EHCI_QTD_SET_BYTES(x) ((x) << 16) 198184610Salfred#define EHCI_QTD_GET_TOGGLE(x) (((x) >> 31) & 0x1) 199184610Salfred#define EHCI_QTD_SET_TOGGLE(x) ((x) << 31) 200184610Salfred#define EHCI_QTD_TOGGLE_MASK 0x80000000 201184610Salfred#define EHCI_QTD_NBUFFERS 5 202184610Salfred#define EHCI_QTD_PAYLOAD_MAX ((EHCI_QTD_NBUFFERS-1)*EHCI_PAGE_SIZE) 203184610Salfred volatile uint32_t qtd_buffer[EHCI_QTD_NBUFFERS]; 204184610Salfred volatile uint32_t qtd_buffer_hi[EHCI_QTD_NBUFFERS]; 205184610Salfred/* 206184610Salfred * Extra information needed: 207184610Salfred */ 208184610Salfred struct ehci_qtd *alt_next; 209184610Salfred struct ehci_qtd *obj_next; 210192984Sthompsa struct usb_page_cache *page_cache; 211184610Salfred uint32_t qtd_self; 212184610Salfred uint16_t len; 213184610Salfred} __aligned(EHCI_QTD_ALIGN); 214184610Salfred 215184610Salfredtypedef struct ehci_qtd ehci_qtd_t; 216184610Salfred 217184610Salfred/* Queue Head Sub Structure */ 218184610Salfredstruct ehci_qh_sub { 219184610Salfred volatile uint32_t qtd_next; 220184610Salfred volatile uint32_t qtd_altnext; 221184610Salfred volatile uint32_t qtd_status; 222184610Salfred volatile uint32_t qtd_buffer[EHCI_QTD_NBUFFERS]; 223184610Salfred volatile uint32_t qtd_buffer_hi[EHCI_QTD_NBUFFERS]; 224184610Salfred} __aligned(4); 225184610Salfred 226184610Salfred/* Queue Head */ 227184610Salfredstruct ehci_qh { 228184610Salfred volatile uint32_t qh_link; 229184610Salfred volatile uint32_t qh_endp; 230184610Salfred#define EHCI_QH_GET_ADDR(x) (((x) >> 0) & 0x7f) /* endpoint addr */ 231184610Salfred#define EHCI_QH_SET_ADDR(x) (x) 232184610Salfred#define EHCI_QH_ADDRMASK 0x0000007f 233184610Salfred#define EHCI_QH_GET_INACT(x) (((x) >> 7) & 0x01) /* inactivate on next */ 234184610Salfred#define EHCI_QH_INACT 0x00000080 235184610Salfred#define EHCI_QH_GET_ENDPT(x) (((x) >> 8) & 0x0f) /* endpoint no */ 236184610Salfred#define EHCI_QH_SET_ENDPT(x) ((x) << 8) 237184610Salfred#define EHCI_QH_GET_EPS(x) (((x) >> 12) & 0x03) /* endpoint speed */ 238184610Salfred#define EHCI_QH_SET_EPS(x) ((x) << 12) 239184610Salfred#define EHCI_QH_SPEED_FULL 0x0 240184610Salfred#define EHCI_QH_SPEED_LOW 0x1 241184610Salfred#define EHCI_QH_SPEED_HIGH 0x2 242184610Salfred#define EHCI_QH_GET_DTC(x) (((x) >> 14) & 0x01) /* data toggle control */ 243184610Salfred#define EHCI_QH_DTC 0x00004000 244184610Salfred#define EHCI_QH_GET_HRECL(x) (((x) >> 15) & 0x01) /* head of reclamation */ 245184610Salfred#define EHCI_QH_HRECL 0x00008000 246184610Salfred#define EHCI_QH_GET_MPL(x) (((x) >> 16) & 0x7ff) /* max packet len */ 247184610Salfred#define EHCI_QH_SET_MPL(x) ((x) << 16) 248184610Salfred#define EHCI_QH_MPLMASK 0x07ff0000 249184610Salfred#define EHCI_QH_GET_CTL(x) (((x) >> 27) & 0x01) /* control endpoint */ 250184610Salfred#define EHCI_QH_CTL 0x08000000 251184610Salfred#define EHCI_QH_GET_NRL(x) (((x) >> 28) & 0x0f) /* NAK reload */ 252184610Salfred#define EHCI_QH_SET_NRL(x) ((x) << 28) 253184610Salfred volatile uint32_t qh_endphub; 254184610Salfred#define EHCI_QH_GET_SMASK(x) (((x) >> 0) & 0xff) /* intr sched mask */ 255184610Salfred#define EHCI_QH_SET_SMASK(x) ((x) << 0) 256184610Salfred#define EHCI_QH_GET_CMASK(x) (((x) >> 8) & 0xff) /* split completion mask */ 257184610Salfred#define EHCI_QH_SET_CMASK(x) ((x) << 8) 258184610Salfred#define EHCI_QH_GET_HUBA(x) (((x) >> 16) & 0x7f) /* hub address */ 259184610Salfred#define EHCI_QH_SET_HUBA(x) ((x) << 16) 260184610Salfred#define EHCI_QH_GET_PORT(x) (((x) >> 23) & 0x7f) /* hub port */ 261184610Salfred#define EHCI_QH_SET_PORT(x) ((x) << 23) 262184610Salfred#define EHCI_QH_GET_MULT(x) (((x) >> 30) & 0x03) /* pipe multiplier */ 263184610Salfred#define EHCI_QH_SET_MULT(x) ((x) << 30) 264184610Salfred volatile uint32_t qh_curqtd; 265184610Salfred struct ehci_qh_sub qh_qtd; 266184610Salfred/* 267184610Salfred * Extra information needed: 268184610Salfred */ 269184610Salfred struct ehci_qh *next; 270184610Salfred struct ehci_qh *prev; 271184610Salfred struct ehci_qh *obj_next; 272192984Sthompsa struct usb_page_cache *page_cache; 273184610Salfred uint32_t qh_self; 274184610Salfred} __aligned(EHCI_QH_ALIGN); 275184610Salfred 276184610Salfredtypedef struct ehci_qh ehci_qh_t; 277184610Salfred 278184610Salfred/* Periodic Frame Span Traversal Node */ 279184610Salfredstruct ehci_fstn { 280184610Salfred volatile uint32_t fstn_link; 281184610Salfred volatile uint32_t fstn_back; 282184610Salfred} __aligned(EHCI_FSTN_ALIGN); 283184610Salfred 284184610Salfredtypedef struct ehci_fstn ehci_fstn_t; 285184610Salfred 286184610Salfredstruct ehci_hw_softc { 287192984Sthompsa struct usb_page_cache pframes_pc; 288213869Shselasky struct usb_page_cache terminate_pc; 289192984Sthompsa struct usb_page_cache async_start_pc; 290192984Sthompsa struct usb_page_cache intr_start_pc[EHCI_VIRTUAL_FRAMELIST_COUNT]; 291192984Sthompsa struct usb_page_cache isoc_hs_start_pc[EHCI_VIRTUAL_FRAMELIST_COUNT]; 292192984Sthompsa struct usb_page_cache isoc_fs_start_pc[EHCI_VIRTUAL_FRAMELIST_COUNT]; 293184610Salfred 294192984Sthompsa struct usb_page pframes_pg; 295213869Shselasky struct usb_page terminate_pg; 296192984Sthompsa struct usb_page async_start_pg; 297192984Sthompsa struct usb_page intr_start_pg[EHCI_VIRTUAL_FRAMELIST_COUNT]; 298192984Sthompsa struct usb_page isoc_hs_start_pg[EHCI_VIRTUAL_FRAMELIST_COUNT]; 299192984Sthompsa struct usb_page isoc_fs_start_pg[EHCI_VIRTUAL_FRAMELIST_COUNT]; 300184610Salfred}; 301184610Salfred 302184610Salfredstruct ehci_config_desc { 303192984Sthompsa struct usb_config_descriptor confd; 304192984Sthompsa struct usb_interface_descriptor ifcd; 305192984Sthompsa struct usb_endpoint_descriptor endpd; 306184610Salfred} __packed; 307184610Salfred 308184610Salfredunion ehci_hub_desc { 309192984Sthompsa struct usb_status stat; 310192984Sthompsa struct usb_port_status ps; 311192984Sthompsa struct usb_hub_descriptor hubd; 312184610Salfred uint8_t temp[128]; 313184610Salfred}; 314184610Salfred 315184610Salfredtypedef struct ehci_softc { 316184610Salfred struct ehci_hw_softc sc_hw; 317192984Sthompsa struct usb_bus sc_bus; /* base device */ 318192984Sthompsa struct usb_callout sc_tmo_pcd; 319199058Sthompsa struct usb_callout sc_tmo_poll; 320184610Salfred union ehci_hub_desc sc_hub_desc; 321184610Salfred 322192984Sthompsa struct usb_device *sc_devices[EHCI_MAX_DEVICES]; 323184610Salfred struct resource *sc_io_res; 324184610Salfred struct resource *sc_irq_res; 325184610Salfred struct ehci_qh *sc_async_p_last; 326184610Salfred struct ehci_qh *sc_intr_p_last[EHCI_VIRTUAL_FRAMELIST_COUNT]; 327184610Salfred struct ehci_sitd *sc_isoc_fs_p_last[EHCI_VIRTUAL_FRAMELIST_COUNT]; 328184610Salfred struct ehci_itd *sc_isoc_hs_p_last[EHCI_VIRTUAL_FRAMELIST_COUNT]; 329184610Salfred void *sc_intr_hdl; 330184610Salfred bus_size_t sc_io_size; 331184610Salfred bus_space_tag_t sc_io_tag; 332184610Salfred bus_space_handle_t sc_io_hdl; 333184610Salfred 334213869Shselasky uint32_t sc_terminate_self; /* TD short packet termination pointer */ 335184610Salfred uint32_t sc_eintrs; 336184610Salfred 337184610Salfred uint16_t sc_intr_stat[EHCI_VIRTUAL_FRAMELIST_COUNT]; 338184610Salfred uint16_t sc_id_vendor; /* vendor ID for root hub */ 339185087Salfred uint16_t sc_flags; /* chip specific flags */ 340186730Salfred#define EHCI_SCFLG_SETMODE 0x0001 /* set bridge mode again after init */ 341186730Salfred#define EHCI_SCFLG_FORCESPEED 0x0002 /* force speed */ 342186730Salfred#define EHCI_SCFLG_NORESTERM 0x0004 /* don't terminate reset sequence */ 343186730Salfred#define EHCI_SCFLG_BIGEDESC 0x0008 /* big-endian byte order descriptors */ 344186730Salfred#define EHCI_SCFLG_BIGEMMIO 0x0010 /* big-endian byte order MMIO */ 345186730Salfred#define EHCI_SCFLG_TT 0x0020 /* transaction translator present */ 346199058Sthompsa#define EHCI_SCFLG_LOSTINTRBUG 0x0040 /* workaround for VIA / ATI chipsets */ 347203693Sthompsa#define EHCI_SCFLG_IAADBUG 0x0080 /* workaround for nVidia chipsets */ 348242523Smarcel#define EHCI_SCFLG_DONTRESET 0x0100 /* don't reset ctrl. in ehci_init() */ 349242523Smarcel#define EHCI_SCFLG_DONEINIT 0x1000 /* ehci_init() has been called. */ 350184610Salfred 351184610Salfred uint8_t sc_offs; /* offset to operational registers */ 352184610Salfred uint8_t sc_doorbell_disable; /* set on doorbell failure */ 353184610Salfred uint8_t sc_noport; 354184610Salfred uint8_t sc_addr; /* device address */ 355184610Salfred uint8_t sc_conf; /* device configuration */ 356184610Salfred uint8_t sc_isreset; 357184610Salfred uint8_t sc_hub_idata[8]; 358184610Salfred 359184610Salfred char sc_vendor[16]; /* vendor string for root hub */ 360184610Salfred 361184610Salfred} ehci_softc_t; 362184610Salfred 363184610Salfred#define EREAD1(sc, a) bus_space_read_1((sc)->sc_io_tag, (sc)->sc_io_hdl, (a)) 364184610Salfred#define EREAD2(sc, a) bus_space_read_2((sc)->sc_io_tag, (sc)->sc_io_hdl, (a)) 365184610Salfred#define EREAD4(sc, a) bus_space_read_4((sc)->sc_io_tag, (sc)->sc_io_hdl, (a)) 366184610Salfred#define EWRITE1(sc, a, x) \ 367184610Salfred bus_space_write_1((sc)->sc_io_tag, (sc)->sc_io_hdl, (a), (x)) 368184610Salfred#define EWRITE2(sc, a, x) \ 369184610Salfred bus_space_write_2((sc)->sc_io_tag, (sc)->sc_io_hdl, (a), (x)) 370184610Salfred#define EWRITE4(sc, a, x) \ 371184610Salfred bus_space_write_4((sc)->sc_io_tag, (sc)->sc_io_hdl, (a), (x)) 372184610Salfred#define EOREAD1(sc, a) \ 373184610Salfred bus_space_read_1((sc)->sc_io_tag, (sc)->sc_io_hdl, (sc)->sc_offs+(a)) 374184610Salfred#define EOREAD2(sc, a) \ 375184610Salfred bus_space_read_2((sc)->sc_io_tag, (sc)->sc_io_hdl, (sc)->sc_offs+(a)) 376184610Salfred#define EOREAD4(sc, a) \ 377184610Salfred bus_space_read_4((sc)->sc_io_tag, (sc)->sc_io_hdl, (sc)->sc_offs+(a)) 378184610Salfred#define EOWRITE1(sc, a, x) \ 379184610Salfred bus_space_write_1((sc)->sc_io_tag, (sc)->sc_io_hdl, (sc)->sc_offs+(a), (x)) 380184610Salfred#define EOWRITE2(sc, a, x) \ 381184610Salfred bus_space_write_2((sc)->sc_io_tag, (sc)->sc_io_hdl, (sc)->sc_offs+(a), (x)) 382184610Salfred#define EOWRITE4(sc, a, x) \ 383184610Salfred bus_space_write_4((sc)->sc_io_tag, (sc)->sc_io_hdl, (sc)->sc_offs+(a), (x)) 384184610Salfred 385189496Sthompsa#ifdef USB_EHCI_BIG_ENDIAN_DESC 386189496Sthompsa/* 387189496Sthompsa * Handle byte order conversion between host and ``host controller''. 388189496Sthompsa * Typically the latter is little-endian but some controllers require 389189496Sthompsa * big-endian in which case we may need to manually swap. 390189496Sthompsa */ 391189496Sthompsastatic __inline uint32_t 392189496Sthompsahtohc32(const struct ehci_softc *sc, const uint32_t v) 393189496Sthompsa{ 394189496Sthompsa return sc->sc_flags & EHCI_SCFLG_BIGEDESC ? htobe32(v) : htole32(v); 395189496Sthompsa} 396189496Sthompsa 397189496Sthompsastatic __inline uint16_t 398189496Sthompsahtohc16(const struct ehci_softc *sc, const uint16_t v) 399189496Sthompsa{ 400189496Sthompsa return sc->sc_flags & EHCI_SCFLG_BIGEDESC ? htobe16(v) : htole16(v); 401189496Sthompsa} 402189496Sthompsa 403189496Sthompsastatic __inline uint32_t 404189496Sthompsahc32toh(const struct ehci_softc *sc, const uint32_t v) 405189496Sthompsa{ 406189496Sthompsa return sc->sc_flags & EHCI_SCFLG_BIGEDESC ? be32toh(v) : le32toh(v); 407189496Sthompsa} 408189496Sthompsa 409189496Sthompsastatic __inline uint16_t 410189496Sthompsahc16toh(const struct ehci_softc *sc, const uint16_t v) 411189496Sthompsa{ 412189496Sthompsa return sc->sc_flags & EHCI_SCFLG_BIGEDESC ? be16toh(v) : le16toh(v); 413189496Sthompsa} 414189496Sthompsa#else 415189496Sthompsa/* 416189496Sthompsa * Normal little-endian only conversion routines. 417189496Sthompsa */ 418189496Sthompsastatic __inline uint32_t 419189496Sthompsahtohc32(const struct ehci_softc *sc, const uint32_t v) 420189496Sthompsa{ 421189496Sthompsa return htole32(v); 422189496Sthompsa} 423189496Sthompsa 424189496Sthompsastatic __inline uint16_t 425189496Sthompsahtohc16(const struct ehci_softc *sc, const uint16_t v) 426189496Sthompsa{ 427189496Sthompsa return htole16(v); 428189496Sthompsa} 429189496Sthompsa 430189496Sthompsastatic __inline uint32_t 431189496Sthompsahc32toh(const struct ehci_softc *sc, const uint32_t v) 432189496Sthompsa{ 433189496Sthompsa return le32toh(v); 434189496Sthompsa} 435189496Sthompsa 436189496Sthompsastatic __inline uint16_t 437189496Sthompsahc16toh(const struct ehci_softc *sc, const uint16_t v) 438189496Sthompsa{ 439189496Sthompsa return le16toh(v); 440189496Sthompsa} 441189496Sthompsa#endif 442189496Sthompsa 443193045Sthompsausb_bus_mem_cb_t ehci_iterate_hw_softc; 444184610Salfred 445193045Sthompsausb_error_t ehci_reset(ehci_softc_t *sc); 446193045Sthompsausb_error_t ehci_init(ehci_softc_t *sc); 447184610Salfredvoid ehci_detach(struct ehci_softc *sc); 448184610Salfredvoid ehci_interrupt(ehci_softc_t *sc); 449184610Salfred 450184610Salfred#endif /* _EHCI_H_ */ 451