102ac6454SAndrew Thompson /*- 2*b61a5730SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3718cf2ccSPedro F. Giffuni * 402ac6454SAndrew Thompson * Copyright (c) 1998 The NetBSD Foundation, Inc. 502ac6454SAndrew Thompson * All rights reserved. 602ac6454SAndrew Thompson * 702ac6454SAndrew Thompson * This code is derived from software contributed to The NetBSD Foundation 802ac6454SAndrew Thompson * by Lennart Augustsson (lennart@augustsson.net) at 902ac6454SAndrew Thompson * Carlstedt Research & Technology. 1002ac6454SAndrew Thompson * 1102ac6454SAndrew Thompson * Redistribution and use in source and binary forms, with or without 1202ac6454SAndrew Thompson * modification, are permitted provided that the following conditions 1302ac6454SAndrew Thompson * are met: 1402ac6454SAndrew Thompson * 1. Redistributions of source code must retain the above copyright 1502ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer. 1602ac6454SAndrew Thompson * 2. Redistributions in binary form must reproduce the above copyright 1702ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer in the 1802ac6454SAndrew Thompson * documentation and/or other materials provided with the distribution. 1902ac6454SAndrew Thompson * 2002ac6454SAndrew Thompson * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2102ac6454SAndrew Thompson * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2202ac6454SAndrew Thompson * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2302ac6454SAndrew Thompson * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2402ac6454SAndrew Thompson * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2502ac6454SAndrew Thompson * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2602ac6454SAndrew Thompson * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2702ac6454SAndrew Thompson * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2802ac6454SAndrew Thompson * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2902ac6454SAndrew Thompson * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3002ac6454SAndrew Thompson * POSSIBILITY OF SUCH DAMAGE. 3102ac6454SAndrew Thompson */ 3202ac6454SAndrew Thompson 3302ac6454SAndrew Thompson #ifndef _OHCI_H_ 3402ac6454SAndrew Thompson #define _OHCI_H_ 3502ac6454SAndrew Thompson 36ab42e8b2SAndrew Thompson #define OHCI_MAX_DEVICES MIN(USB_MAX_DEVICES, 128) 3702ac6454SAndrew Thompson 3802ac6454SAndrew Thompson #define OHCI_NO_INTRS 32 3902ac6454SAndrew Thompson #define OHCI_HCCA_SIZE 256 4002ac6454SAndrew Thompson 4102ac6454SAndrew Thompson /* Structures alignment (bytes) */ 4202ac6454SAndrew Thompson #define OHCI_HCCA_ALIGN 256 4302ac6454SAndrew Thompson #define OHCI_ED_ALIGN 16 4402ac6454SAndrew Thompson #define OHCI_TD_ALIGN 16 4502ac6454SAndrew Thompson #define OHCI_ITD_ALIGN 32 4602ac6454SAndrew Thompson 4702ac6454SAndrew Thompson #define OHCI_PAGE_SIZE 0x1000 4802ac6454SAndrew Thompson #define OHCI_PAGE(x) ((x) &~ 0xfff) 4902ac6454SAndrew Thompson #define OHCI_PAGE_OFFSET(x) ((x) & 0xfff) 5002ac6454SAndrew Thompson #define OHCI_PAGE_MASK(x) ((x) & 0xfff) 5102ac6454SAndrew Thompson 5202ac6454SAndrew Thompson #if ((USB_PAGE_SIZE < OHCI_ED_ALIGN) || (OHCI_ED_ALIGN == 0) || \ 5302ac6454SAndrew Thompson (USB_PAGE_SIZE < OHCI_TD_ALIGN) || (OHCI_TD_ALIGN == 0) || \ 5402ac6454SAndrew Thompson (USB_PAGE_SIZE < OHCI_ITD_ALIGN) || (OHCI_ITD_ALIGN == 0) || \ 5502ac6454SAndrew Thompson (USB_PAGE_SIZE < OHCI_PAGE_SIZE) || (OHCI_PAGE_SIZE == 0)) 5602ac6454SAndrew Thompson #error "Invalid USB page size!" 5702ac6454SAndrew Thompson #endif 5802ac6454SAndrew Thompson 5902ac6454SAndrew Thompson #define OHCI_VIRTUAL_FRAMELIST_COUNT 128/* dummy */ 6002ac6454SAndrew Thompson 6102ac6454SAndrew Thompson #if (OHCI_VIRTUAL_FRAMELIST_COUNT < USB_MAX_FS_ISOC_FRAMES_PER_XFER) 6202ac6454SAndrew Thompson #error "maximum number of full-speed isochronous frames is higher than supported!" 6302ac6454SAndrew Thompson #endif 6402ac6454SAndrew Thompson 6502ac6454SAndrew Thompson struct ohci_hcca { 6602ac6454SAndrew Thompson volatile uint32_t hcca_interrupt_table[OHCI_NO_INTRS]; 6702ac6454SAndrew Thompson volatile uint32_t hcca_frame_number; 6802ac6454SAndrew Thompson volatile uint32_t hcca_done_head; 6902ac6454SAndrew Thompson #define OHCI_DONE_INTRS 1 7002ac6454SAndrew Thompson } __aligned(OHCI_HCCA_ALIGN); 7102ac6454SAndrew Thompson 7202ac6454SAndrew Thompson typedef struct ohci_hcca ohci_hcca_t; 7302ac6454SAndrew Thompson 7402ac6454SAndrew Thompson struct ohci_ed { 7502ac6454SAndrew Thompson volatile uint32_t ed_flags; 7602ac6454SAndrew Thompson #define OHCI_ED_GET_FA(s) ((s) & 0x7f) 7702ac6454SAndrew Thompson #define OHCI_ED_ADDRMASK 0x0000007f 7802ac6454SAndrew Thompson #define OHCI_ED_SET_FA(s) (s) 7902ac6454SAndrew Thompson #define OHCI_ED_GET_EN(s) (((s) >> 7) & 0xf) 8002ac6454SAndrew Thompson #define OHCI_ED_SET_EN(s) ((s) << 7) 8102ac6454SAndrew Thompson #define OHCI_ED_DIR_MASK 0x00001800 8202ac6454SAndrew Thompson #define OHCI_ED_DIR_TD 0x00000000 8302ac6454SAndrew Thompson #define OHCI_ED_DIR_OUT 0x00000800 8402ac6454SAndrew Thompson #define OHCI_ED_DIR_IN 0x00001000 8502ac6454SAndrew Thompson #define OHCI_ED_SPEED 0x00002000 8602ac6454SAndrew Thompson #define OHCI_ED_SKIP 0x00004000 8702ac6454SAndrew Thompson #define OHCI_ED_FORMAT_GEN 0x00000000 8802ac6454SAndrew Thompson #define OHCI_ED_FORMAT_ISO 0x00008000 8902ac6454SAndrew Thompson #define OHCI_ED_GET_MAXP(s) (((s) >> 16) & 0x07ff) 9002ac6454SAndrew Thompson #define OHCI_ED_SET_MAXP(s) ((s) << 16) 9102ac6454SAndrew Thompson #define OHCI_ED_MAXPMASK (0x7ff << 16) 9202ac6454SAndrew Thompson volatile uint32_t ed_tailp; 9302ac6454SAndrew Thompson volatile uint32_t ed_headp; 9402ac6454SAndrew Thompson #define OHCI_HALTED 0x00000001 9502ac6454SAndrew Thompson #define OHCI_TOGGLECARRY 0x00000002 9602ac6454SAndrew Thompson #define OHCI_HEADMASK 0xfffffffc 9702ac6454SAndrew Thompson volatile uint32_t ed_next; 9802ac6454SAndrew Thompson /* 9902ac6454SAndrew Thompson * Extra information needed: 10002ac6454SAndrew Thompson */ 10102ac6454SAndrew Thompson struct ohci_ed *next; 10202ac6454SAndrew Thompson struct ohci_ed *prev; 10302ac6454SAndrew Thompson struct ohci_ed *obj_next; 104760bc48eSAndrew Thompson struct usb_page_cache *page_cache; 10502ac6454SAndrew Thompson uint32_t ed_self; 10602ac6454SAndrew Thompson } __aligned(OHCI_ED_ALIGN); 10702ac6454SAndrew Thompson 10802ac6454SAndrew Thompson typedef struct ohci_ed ohci_ed_t; 10902ac6454SAndrew Thompson 11002ac6454SAndrew Thompson struct ohci_td { 11102ac6454SAndrew Thompson volatile uint32_t td_flags; 11202ac6454SAndrew Thompson #define OHCI_TD_R 0x00040000 /* Buffer Rounding */ 11302ac6454SAndrew Thompson #define OHCI_TD_DP_MASK 0x00180000 /* Direction / PID */ 11402ac6454SAndrew Thompson #define OHCI_TD_SETUP 0x00000000 11502ac6454SAndrew Thompson #define OHCI_TD_OUT 0x00080000 11602ac6454SAndrew Thompson #define OHCI_TD_IN 0x00100000 11702ac6454SAndrew Thompson #define OHCI_TD_GET_DI(x) (((x) >> 21) & 7) /* Delay Interrupt */ 11802ac6454SAndrew Thompson #define OHCI_TD_SET_DI(x) ((x) << 21) 11902ac6454SAndrew Thompson #define OHCI_TD_NOINTR 0x00e00000 12002ac6454SAndrew Thompson #define OHCI_TD_INTR_MASK 0x00e00000 12102ac6454SAndrew Thompson #define OHCI_TD_TOGGLE_CARRY 0x00000000 12202ac6454SAndrew Thompson #define OHCI_TD_TOGGLE_0 0x02000000 12302ac6454SAndrew Thompson #define OHCI_TD_TOGGLE_1 0x03000000 12402ac6454SAndrew Thompson #define OHCI_TD_TOGGLE_MASK 0x03000000 12502ac6454SAndrew Thompson #define OHCI_TD_GET_EC(x) (((x) >> 26) & 3) /* Error Count */ 12602ac6454SAndrew Thompson #define OHCI_TD_GET_CC(x) ((x) >> 28) /* Condition Code */ 12702ac6454SAndrew Thompson #define OHCI_TD_SET_CC(x) ((x) << 28) 12802ac6454SAndrew Thompson #define OHCI_TD_NOCC 0xf0000000 12902ac6454SAndrew Thompson volatile uint32_t td_cbp; /* Current Buffer Pointer */ 13002ac6454SAndrew Thompson volatile uint32_t td_next; /* Next TD */ 13102ac6454SAndrew Thompson #define OHCI_TD_NEXT_END 0 13202ac6454SAndrew Thompson volatile uint32_t td_be; /* Buffer End */ 13302ac6454SAndrew Thompson /* 13402ac6454SAndrew Thompson * Extra information needed: 13502ac6454SAndrew Thompson */ 13602ac6454SAndrew Thompson struct ohci_td *obj_next; 13702ac6454SAndrew Thompson struct ohci_td *alt_next; 138760bc48eSAndrew Thompson struct usb_page_cache *page_cache; 13902ac6454SAndrew Thompson uint32_t td_self; 14002ac6454SAndrew Thompson uint16_t len; 14102ac6454SAndrew Thompson } __aligned(OHCI_TD_ALIGN); 14202ac6454SAndrew Thompson 14302ac6454SAndrew Thompson typedef struct ohci_td ohci_td_t; 14402ac6454SAndrew Thompson 14502ac6454SAndrew Thompson struct ohci_itd { 14602ac6454SAndrew Thompson volatile uint32_t itd_flags; 14702ac6454SAndrew Thompson #define OHCI_ITD_GET_SF(x) ((x) & 0x0000ffff) 14802ac6454SAndrew Thompson #define OHCI_ITD_SET_SF(x) ((x) & 0xffff) 14902ac6454SAndrew Thompson #define OHCI_ITD_GET_DI(x) (((x) >> 21) & 7) /* Delay Interrupt */ 15002ac6454SAndrew Thompson #define OHCI_ITD_SET_DI(x) ((x) << 21) 15102ac6454SAndrew Thompson #define OHCI_ITD_NOINTR 0x00e00000 15202ac6454SAndrew Thompson #define OHCI_ITD_GET_FC(x) ((((x) >> 24) & 7)+1) /* Frame Count */ 15302ac6454SAndrew Thompson #define OHCI_ITD_SET_FC(x) (((x)-1) << 24) 15402ac6454SAndrew Thompson #define OHCI_ITD_GET_CC(x) ((x) >> 28) /* Condition Code */ 15502ac6454SAndrew Thompson #define OHCI_ITD_NOCC 0xf0000000 15602ac6454SAndrew Thompson #define OHCI_ITD_NOFFSET 8 15702ac6454SAndrew Thompson volatile uint32_t itd_bp0; /* Buffer Page 0 */ 15802ac6454SAndrew Thompson volatile uint32_t itd_next; /* Next ITD */ 15902ac6454SAndrew Thompson volatile uint32_t itd_be; /* Buffer End */ 16002ac6454SAndrew Thompson volatile uint16_t itd_offset[OHCI_ITD_NOFFSET]; /* Buffer offsets and 16102ac6454SAndrew Thompson * Status */ 16202ac6454SAndrew Thompson #define OHCI_ITD_PAGE_SELECT 0x00001000 16302ac6454SAndrew Thompson #define OHCI_ITD_MK_OFFS(len) (0xe000 | ((len) & 0x1fff)) 16402ac6454SAndrew Thompson #define OHCI_ITD_PSW_LENGTH(x) ((x) & 0xfff) /* Transfer length */ 16502ac6454SAndrew Thompson #define OHCI_ITD_PSW_GET_CC(x) ((x) >> 12) /* Condition Code */ 16602ac6454SAndrew Thompson /* 16702ac6454SAndrew Thompson * Extra information needed: 16802ac6454SAndrew Thompson */ 16902ac6454SAndrew Thompson struct ohci_itd *obj_next; 170760bc48eSAndrew Thompson struct usb_page_cache *page_cache; 17102ac6454SAndrew Thompson uint32_t itd_self; 17202ac6454SAndrew Thompson uint8_t frames; 17302ac6454SAndrew Thompson } __aligned(OHCI_ITD_ALIGN); 17402ac6454SAndrew Thompson 17502ac6454SAndrew Thompson typedef struct ohci_itd ohci_itd_t; 17602ac6454SAndrew Thompson 17702ac6454SAndrew Thompson #define OHCI_CC_NO_ERROR 0 17802ac6454SAndrew Thompson #define OHCI_CC_CRC 1 17902ac6454SAndrew Thompson #define OHCI_CC_BIT_STUFFING 2 18002ac6454SAndrew Thompson #define OHCI_CC_DATA_TOGGLE_MISMATCH 3 18102ac6454SAndrew Thompson #define OHCI_CC_STALL 4 18202ac6454SAndrew Thompson #define OHCI_CC_DEVICE_NOT_RESPONDING 5 18302ac6454SAndrew Thompson #define OHCI_CC_PID_CHECK_FAILURE 6 18402ac6454SAndrew Thompson #define OHCI_CC_UNEXPECTED_PID 7 18502ac6454SAndrew Thompson #define OHCI_CC_DATA_OVERRUN 8 18602ac6454SAndrew Thompson #define OHCI_CC_DATA_UNDERRUN 9 18702ac6454SAndrew Thompson #define OHCI_CC_BUFFER_OVERRUN 12 18802ac6454SAndrew Thompson #define OHCI_CC_BUFFER_UNDERRUN 13 18902ac6454SAndrew Thompson #define OHCI_CC_NOT_ACCESSED 15 19002ac6454SAndrew Thompson 19102ac6454SAndrew Thompson /* Some delay needed when changing certain registers. */ 19202ac6454SAndrew Thompson #define OHCI_ENABLE_POWER_DELAY 5 19302ac6454SAndrew Thompson #define OHCI_READ_DESC_DELAY 5 19402ac6454SAndrew Thompson 19502ac6454SAndrew Thompson #define OHCI_NO_EDS (2*OHCI_NO_INTRS) 19602ac6454SAndrew Thompson 19702ac6454SAndrew Thompson struct ohci_hw_softc { 198760bc48eSAndrew Thompson struct usb_page_cache hcca_pc; 199760bc48eSAndrew Thompson struct usb_page_cache ctrl_start_pc; 200760bc48eSAndrew Thompson struct usb_page_cache bulk_start_pc; 201760bc48eSAndrew Thompson struct usb_page_cache isoc_start_pc; 202760bc48eSAndrew Thompson struct usb_page_cache intr_start_pc[OHCI_NO_EDS]; 20302ac6454SAndrew Thompson 204760bc48eSAndrew Thompson struct usb_page hcca_pg; 205760bc48eSAndrew Thompson struct usb_page ctrl_start_pg; 206760bc48eSAndrew Thompson struct usb_page bulk_start_pg; 207760bc48eSAndrew Thompson struct usb_page isoc_start_pg; 208760bc48eSAndrew Thompson struct usb_page intr_start_pg[OHCI_NO_EDS]; 20902ac6454SAndrew Thompson }; 21002ac6454SAndrew Thompson 21102ac6454SAndrew Thompson struct ohci_config_desc { 212760bc48eSAndrew Thompson struct usb_config_descriptor confd; 213760bc48eSAndrew Thompson struct usb_interface_descriptor ifcd; 214760bc48eSAndrew Thompson struct usb_endpoint_descriptor endpd; 21502ac6454SAndrew Thompson } __packed; 21602ac6454SAndrew Thompson 21702ac6454SAndrew Thompson union ohci_hub_desc { 218760bc48eSAndrew Thompson struct usb_status stat; 219760bc48eSAndrew Thompson struct usb_port_status ps; 220760bc48eSAndrew Thompson struct usb_hub_descriptor hubd; 22102ac6454SAndrew Thompson uint8_t temp[128]; 22202ac6454SAndrew Thompson }; 22302ac6454SAndrew Thompson 22402ac6454SAndrew Thompson typedef struct ohci_softc { 22502ac6454SAndrew Thompson struct ohci_hw_softc sc_hw; 226760bc48eSAndrew Thompson struct usb_bus sc_bus; /* base device */ 227760bc48eSAndrew Thompson struct usb_callout sc_tmo_rhsc; 22802ac6454SAndrew Thompson union ohci_hub_desc sc_hub_desc; 22902ac6454SAndrew Thompson 230760bc48eSAndrew Thompson struct usb_device *sc_devices[OHCI_MAX_DEVICES]; 23102ac6454SAndrew Thompson struct resource *sc_io_res; 23202ac6454SAndrew Thompson struct resource *sc_irq_res; 23302ac6454SAndrew Thompson struct ohci_hcca *sc_hcca_p; 23402ac6454SAndrew Thompson struct ohci_ed *sc_ctrl_p_last; 23502ac6454SAndrew Thompson struct ohci_ed *sc_bulk_p_last; 23602ac6454SAndrew Thompson struct ohci_ed *sc_isoc_p_last; 23702ac6454SAndrew Thompson struct ohci_ed *sc_intr_p_last[OHCI_NO_EDS]; 23802ac6454SAndrew Thompson void *sc_intr_hdl; 23902ac6454SAndrew Thompson device_t sc_dev; 24002ac6454SAndrew Thompson bus_size_t sc_io_size; 24102ac6454SAndrew Thompson bus_space_tag_t sc_io_tag; 24202ac6454SAndrew Thompson bus_space_handle_t sc_io_hdl; 24302ac6454SAndrew Thompson 24402ac6454SAndrew Thompson uint32_t sc_eintrs; /* enabled interrupts */ 24502ac6454SAndrew Thompson 24602ac6454SAndrew Thompson uint16_t sc_intr_stat[OHCI_NO_EDS]; 24702ac6454SAndrew Thompson uint16_t sc_id_vendor; 24802ac6454SAndrew Thompson 24902ac6454SAndrew Thompson uint8_t sc_noport; 25002ac6454SAndrew Thompson uint8_t sc_addr; /* device address */ 25102ac6454SAndrew Thompson uint8_t sc_conf; /* device configuration */ 25202ac6454SAndrew Thompson uint8_t sc_hub_idata[32]; 25302ac6454SAndrew Thompson 25402ac6454SAndrew Thompson char sc_vendor[16]; 25502ac6454SAndrew Thompson 25602ac6454SAndrew Thompson } ohci_softc_t; 25702ac6454SAndrew Thompson 258e0a69b51SAndrew Thompson usb_bus_mem_cb_t ohci_iterate_hw_softc; 25902ac6454SAndrew Thompson 260e0a69b51SAndrew Thompson usb_error_t ohci_init(ohci_softc_t *sc); 26102ac6454SAndrew Thompson void ohci_detach(struct ohci_softc *sc); 26202ac6454SAndrew Thompson void ohci_interrupt(ohci_softc_t *sc); 26302ac6454SAndrew Thompson 26402ac6454SAndrew Thompson #endif /* _OHCI_H_ */ 265