usb_controller.h revision 213435
1184610Salfred/* $FreeBSD: head/sys/dev/usb/usb_controller.h 213435 2010-10-04 23:18:05Z hselasky $ */ 2184610Salfred/*- 3184610Salfred * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 4184610Salfred * 5184610Salfred * Redistribution and use in source and binary forms, with or without 6184610Salfred * modification, are permitted provided that the following conditions 7184610Salfred * are met: 8184610Salfred * 1. Redistributions of source code must retain the above copyright 9184610Salfred * notice, this list of conditions and the following disclaimer. 10184610Salfred * 2. Redistributions in binary form must reproduce the above copyright 11184610Salfred * notice, this list of conditions and the following disclaimer in the 12184610Salfred * documentation and/or other materials provided with the distribution. 13184610Salfred * 14184610Salfred * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15184610Salfred * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16184610Salfred * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17184610Salfred * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18184610Salfred * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19184610Salfred * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20184610Salfred * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21184610Salfred * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22184610Salfred * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23184610Salfred * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24184610Salfred * SUCH DAMAGE. 25184610Salfred */ 26184610Salfred 27194230Sthompsa#ifndef _USB_CONTROLLER_H_ 28194230Sthompsa#define _USB_CONTROLLER_H_ 29184610Salfred 30184610Salfred/* defines */ 31184610Salfred 32184610Salfred#define USB_BUS_DMA_TAG_MAX 8 33184610Salfred 34190754Sthompsa/* structure prototypes */ 35184610Salfred 36192984Sthompsastruct usb_bus; 37192984Sthompsastruct usb_page; 38193644Sthompsastruct usb_endpoint; 39192984Sthompsastruct usb_page_cache; 40192984Sthompsastruct usb_setup_params; 41192984Sthompsastruct usb_hw_ep_profile; 42192984Sthompsastruct usb_fs_isoc_schedule; 43192984Sthompsastruct usb_config_descriptor; 44192984Sthompsastruct usb_endpoint_descriptor; 45184610Salfred 46184610Salfred/* typedefs */ 47184610Salfred 48193074Sthompsatypedef void (usb_bus_mem_sub_cb_t)(struct usb_bus *bus, struct usb_page_cache *pc, struct usb_page *pg, usb_size_t size, usb_size_t align); 49193045Sthompsatypedef void (usb_bus_mem_cb_t)(struct usb_bus *bus, usb_bus_mem_sub_cb_t *scb); 50184610Salfred 51184610Salfred/* 52184610Salfred * The following structure is used to define all the USB BUS 53184610Salfred * callbacks. 54184610Salfred */ 55192984Sthompsastruct usb_bus_methods { 56184610Salfred 57184610Salfred /* USB Device and Host mode - Mandatory */ 58184610Salfred 59193045Sthompsa usb_handle_req_t *roothub_exec; 60191402Sthompsa 61193644Sthompsa void (*endpoint_init) (struct usb_device *, 62193644Sthompsa struct usb_endpoint_descriptor *, struct usb_endpoint *); 63192984Sthompsa void (*xfer_setup) (struct usb_setup_params *); 64192984Sthompsa void (*xfer_unsetup) (struct usb_xfer *); 65212134Sthompsa void (*get_dma_delay) (struct usb_device *, uint32_t *); 66192984Sthompsa void (*device_suspend) (struct usb_device *); 67192984Sthompsa void (*device_resume) (struct usb_device *); 68192984Sthompsa void (*set_hw_power) (struct usb_bus *); 69191402Sthompsa 70186730Salfred /* 71186730Salfred * The following flag is set if one or more control transfers are 72186730Salfred * active: 73186730Salfred */ 74186730Salfred#define USB_HW_POWER_CONTROL 0x01 75186730Salfred /* 76186730Salfred * The following flag is set if one or more bulk transfers are 77186730Salfred * active: 78186730Salfred */ 79186730Salfred#define USB_HW_POWER_BULK 0x02 80186730Salfred /* 81186730Salfred * The following flag is set if one or more interrupt transfers are 82186730Salfred * active: 83186730Salfred */ 84186730Salfred#define USB_HW_POWER_INTERRUPT 0x04 85186730Salfred /* 86186730Salfred * The following flag is set if one or more isochronous transfers 87186730Salfred * are active: 88186730Salfred */ 89186730Salfred#define USB_HW_POWER_ISOC 0x08 90187730Sthompsa /* 91187730Sthompsa * The following flag is set if one or more non-root-HUB devices 92187730Sthompsa * are present on the given USB bus: 93187730Sthompsa */ 94187730Sthompsa#define USB_HW_POWER_NON_ROOT_HUB 0x10 95184610Salfred 96184610Salfred /* USB Device mode only - Mandatory */ 97184610Salfred 98192984Sthompsa void (*get_hw_ep_profile) (struct usb_device *udev, const struct usb_hw_ep_profile **ppf, uint8_t ep_addr); 99195121Sthompsa void (*set_stall) (struct usb_device *udev, struct usb_xfer *xfer, struct usb_endpoint *ep, uint8_t *did_stall); 100213435Shselasky 101213435Shselasky /* USB Device mode mandatory. USB Host mode optional. */ 102213435Shselasky 103193644Sthompsa void (*clear_stall) (struct usb_device *udev, struct usb_endpoint *ep); 104184610Salfred 105195960Salfred /* Optional transfer polling support */ 106195960Salfred 107195960Salfred void (*xfer_poll) (struct usb_bus *); 108212135Sthompsa 109212135Sthompsa /* Optional fixed power mode support */ 110212135Sthompsa 111212135Sthompsa void (*get_power_mode) (struct usb_device *udev, int8_t *pmode); 112213435Shselasky 113213435Shselasky /* Optional endpoint uninit */ 114213435Shselasky 115213435Shselasky void (*endpoint_uninit) (struct usb_device *, struct usb_endpoint *); 116213435Shselasky 117213435Shselasky /* Optional device init */ 118213435Shselasky 119213435Shselasky usb_error_t (*device_init) (struct usb_device *); 120213435Shselasky 121213435Shselasky /* Optional device uninit */ 122213435Shselasky 123213435Shselasky void (*device_uninit) (struct usb_device *); 124213435Shselasky 125213435Shselasky /* Optional for device and host mode */ 126213435Shselasky 127213435Shselasky void (*start_dma_delay) (struct usb_xfer *); 128213435Shselasky 129213435Shselasky void (*device_state_change) (struct usb_device *); 130213435Shselasky 131213435Shselasky /* Optional for host mode */ 132213435Shselasky 133213435Shselasky usb_error_t (*set_address) (struct usb_device *, struct mtx *, uint16_t); 134184610Salfred}; 135184610Salfred 136184610Salfred/* 137184610Salfred * The following structure is used to define all the USB pipe 138184610Salfred * callbacks. 139184610Salfred */ 140192984Sthompsastruct usb_pipe_methods { 141184610Salfred 142184610Salfred /* Mandatory USB Device and Host mode callbacks: */ 143184610Salfred 144194677Sthompsa void (*open)(struct usb_xfer *); 145194677Sthompsa void (*close)(struct usb_xfer *); 146184610Salfred 147194677Sthompsa void (*enter)(struct usb_xfer *); 148194677Sthompsa void (*start)(struct usb_xfer *); 149184610Salfred 150184610Salfred /* Optional */ 151184610Salfred 152184610Salfred void *info; 153184610Salfred}; 154184610Salfred 155184610Salfred/* 156184610Salfred * The following structure keeps information about what a hardware USB 157184610Salfred * endpoint supports. 158184610Salfred */ 159192984Sthompsastruct usb_hw_ep_profile { 160184610Salfred uint16_t max_in_frame_size; /* IN-token direction */ 161184610Salfred uint16_t max_out_frame_size; /* OUT-token direction */ 162184610Salfred uint8_t is_simplex:1; 163184610Salfred uint8_t support_multi_buffer:1; 164184610Salfred uint8_t support_bulk:1; 165184610Salfred uint8_t support_control:1; 166184610Salfred uint8_t support_interrupt:1; 167184610Salfred uint8_t support_isochronous:1; 168184610Salfred uint8_t support_in:1; /* IN-token is supported */ 169184610Salfred uint8_t support_out:1; /* OUT-token is supported */ 170184610Salfred}; 171184610Salfred 172184610Salfred/* 173184610Salfred * The following structure is used when trying to allocate hardware 174184610Salfred * endpoints for an USB configuration in USB device side mode. 175184610Salfred */ 176192984Sthompsastruct usb_hw_ep_scratch_sub { 177192984Sthompsa const struct usb_hw_ep_profile *pf; 178184610Salfred uint16_t max_frame_size; 179184610Salfred uint8_t hw_endpoint_out; 180184610Salfred uint8_t hw_endpoint_in; 181184610Salfred uint8_t needs_ep_type; 182184610Salfred uint8_t needs_in:1; 183184610Salfred uint8_t needs_out:1; 184184610Salfred}; 185184610Salfred 186184610Salfred/* 187184610Salfred * The following structure is used when trying to allocate hardware 188184610Salfred * endpoints for an USB configuration in USB device side mode. 189184610Salfred */ 190192984Sthompsastruct usb_hw_ep_scratch { 191192984Sthompsa struct usb_hw_ep_scratch_sub ep[USB_EP_MAX]; 192192984Sthompsa struct usb_hw_ep_scratch_sub *ep_max; 193192984Sthompsa struct usb_config_descriptor *cd; 194192984Sthompsa struct usb_device *udev; 195192984Sthompsa struct usb_bus_methods *methods; 196184610Salfred uint8_t bmOutAlloc[(USB_EP_MAX + 15) / 16]; 197184610Salfred uint8_t bmInAlloc[(USB_EP_MAX + 15) / 16]; 198184610Salfred}; 199184610Salfred 200184610Salfred/* 201184610Salfred * The following structure is used when generating USB descriptors 202184610Salfred * from USB templates. 203184610Salfred */ 204192984Sthompsastruct usb_temp_setup { 205184610Salfred void *buf; 206193074Sthompsa usb_size_t size; 207192500Sthompsa enum usb_dev_speed usb_speed; 208184610Salfred uint8_t self_powered; 209184610Salfred uint8_t bNumEndpoints; 210184610Salfred uint8_t bInterfaceNumber; 211184610Salfred uint8_t bAlternateSetting; 212184610Salfred uint8_t bConfigurationValue; 213193045Sthompsa usb_error_t err; 214184610Salfred}; 215184610Salfred 216184610Salfred/* prototypes */ 217184610Salfred 218194228Sthompsavoid usb_bus_mem_flush_all(struct usb_bus *bus, usb_bus_mem_cb_t *cb); 219194228Sthompsauint8_t usb_bus_mem_alloc_all(struct usb_bus *bus, bus_dma_tag_t dmat, usb_bus_mem_cb_t *cb); 220194228Sthompsavoid usb_bus_mem_free_all(struct usb_bus *bus, usb_bus_mem_cb_t *cb); 221194228Sthompsauint16_t usb_isoc_time_expand(struct usb_bus *bus, uint16_t isoc_time_curr); 222194228Sthompsauint16_t usbd_fs_isoc_schedule_isoc_time_expand(struct usb_device *udev, struct usb_fs_isoc_schedule **pp_start, struct usb_fs_isoc_schedule **pp_end, uint16_t isoc_time); 223194228Sthompsauint8_t usbd_fs_isoc_schedule_alloc(struct usb_fs_isoc_schedule *fss, uint8_t *pstart, uint16_t len); 224184610Salfred 225194230Sthompsa#endif /* _USB_CONTROLLER_H_ */ 226