1184610Salfred/* $FreeBSD: releng/11.0/sys/dev/usb/usb_controller.h 259023 2013-12-06 08:42:41Z 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_endpoint_descriptor; 44184610Salfred 45184610Salfred/* typedefs */ 46184610Salfred 47193074Sthompsatypedef 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); 48193045Sthompsatypedef void (usb_bus_mem_cb_t)(struct usb_bus *bus, usb_bus_mem_sub_cb_t *scb); 49184610Salfred 50184610Salfred/* 51184610Salfred * The following structure is used to define all the USB BUS 52184610Salfred * callbacks. 53184610Salfred */ 54192984Sthompsastruct usb_bus_methods { 55184610Salfred 56184610Salfred /* USB Device and Host mode - Mandatory */ 57184610Salfred 58193045Sthompsa usb_handle_req_t *roothub_exec; 59191402Sthompsa 60193644Sthompsa void (*endpoint_init) (struct usb_device *, 61193644Sthompsa struct usb_endpoint_descriptor *, struct usb_endpoint *); 62192984Sthompsa void (*xfer_setup) (struct usb_setup_params *); 63192984Sthompsa void (*xfer_unsetup) (struct usb_xfer *); 64212134Sthompsa void (*get_dma_delay) (struct usb_device *, uint32_t *); 65192984Sthompsa void (*device_suspend) (struct usb_device *); 66192984Sthompsa void (*device_resume) (struct usb_device *); 67192984Sthompsa void (*set_hw_power) (struct usb_bus *); 68228483Shselasky void (*set_hw_power_sleep) (struct usb_bus *, uint32_t); 69186730Salfred /* 70186730Salfred * The following flag is set if one or more control transfers are 71186730Salfred * active: 72186730Salfred */ 73186730Salfred#define USB_HW_POWER_CONTROL 0x01 74186730Salfred /* 75186730Salfred * The following flag is set if one or more bulk transfers are 76186730Salfred * active: 77186730Salfred */ 78186730Salfred#define USB_HW_POWER_BULK 0x02 79186730Salfred /* 80186730Salfred * The following flag is set if one or more interrupt transfers are 81186730Salfred * active: 82186730Salfred */ 83186730Salfred#define USB_HW_POWER_INTERRUPT 0x04 84186730Salfred /* 85186730Salfred * The following flag is set if one or more isochronous transfers 86186730Salfred * are active: 87186730Salfred */ 88186730Salfred#define USB_HW_POWER_ISOC 0x08 89187730Sthompsa /* 90187730Sthompsa * The following flag is set if one or more non-root-HUB devices 91187730Sthompsa * are present on the given USB bus: 92187730Sthompsa */ 93187730Sthompsa#define USB_HW_POWER_NON_ROOT_HUB 0x10 94228483Shselasky /* 95228483Shselasky * The following flag is set if we are suspending 96228483Shselasky */ 97228483Shselasky#define USB_HW_POWER_SUSPEND 0x20 98228483Shselasky /* 99228483Shselasky * The following flag is set if we are resuming 100228483Shselasky */ 101228483Shselasky#define USB_HW_POWER_RESUME 0x40 102228483Shselasky /* 103228483Shselasky * The following flag is set if we are shutting down 104228483Shselasky */ 105228483Shselasky#define USB_HW_POWER_SHUTDOWN 0x60 106184610Salfred 107184610Salfred /* USB Device mode only - Mandatory */ 108184610Salfred 109192984Sthompsa void (*get_hw_ep_profile) (struct usb_device *udev, const struct usb_hw_ep_profile **ppf, uint8_t ep_addr); 110239214Shselasky void (*xfer_stall) (struct usb_xfer *xfer); 111239214Shselasky void (*set_stall) (struct usb_device *udev, struct usb_endpoint *ep, uint8_t *did_stall); 112213435Shselasky 113213435Shselasky /* USB Device mode mandatory. USB Host mode optional. */ 114213435Shselasky 115193644Sthompsa void (*clear_stall) (struct usb_device *udev, struct usb_endpoint *ep); 116184610Salfred 117195960Salfred /* Optional transfer polling support */ 118195960Salfred 119195960Salfred void (*xfer_poll) (struct usb_bus *); 120212135Sthompsa 121212135Sthompsa /* Optional fixed power mode support */ 122212135Sthompsa 123212135Sthompsa void (*get_power_mode) (struct usb_device *udev, int8_t *pmode); 124213435Shselasky 125213435Shselasky /* Optional endpoint uninit */ 126213435Shselasky 127213435Shselasky void (*endpoint_uninit) (struct usb_device *, struct usb_endpoint *); 128213435Shselasky 129213435Shselasky /* Optional device init */ 130213435Shselasky 131213435Shselasky usb_error_t (*device_init) (struct usb_device *); 132213435Shselasky 133213435Shselasky /* Optional device uninit */ 134213435Shselasky 135213435Shselasky void (*device_uninit) (struct usb_device *); 136213435Shselasky 137213435Shselasky /* Optional for device and host mode */ 138213435Shselasky 139213435Shselasky void (*start_dma_delay) (struct usb_xfer *); 140213435Shselasky 141213435Shselasky void (*device_state_change) (struct usb_device *); 142213435Shselasky 143213435Shselasky /* Optional for host mode */ 144213435Shselasky 145213435Shselasky usb_error_t (*set_address) (struct usb_device *, struct mtx *, uint16_t); 146239214Shselasky 147239214Shselasky /* Optional for device and host mode */ 148239214Shselasky 149239214Shselasky usb_error_t (*set_endpoint_mode) (struct usb_device *, struct usb_endpoint *, uint8_t); 150184610Salfred}; 151184610Salfred 152184610Salfred/* 153184610Salfred * The following structure is used to define all the USB pipe 154184610Salfred * callbacks. 155184610Salfred */ 156192984Sthompsastruct usb_pipe_methods { 157184610Salfred 158184610Salfred /* Mandatory USB Device and Host mode callbacks: */ 159184610Salfred 160194677Sthompsa void (*open)(struct usb_xfer *); 161194677Sthompsa void (*close)(struct usb_xfer *); 162184610Salfred 163194677Sthompsa void (*enter)(struct usb_xfer *); 164194677Sthompsa void (*start)(struct usb_xfer *); 165184610Salfred 166184610Salfred /* Optional */ 167184610Salfred 168184610Salfred void *info; 169184610Salfred}; 170184610Salfred 171184610Salfred/* 172184610Salfred * The following structure keeps information about what a hardware USB 173184610Salfred * endpoint supports. 174184610Salfred */ 175192984Sthompsastruct usb_hw_ep_profile { 176184610Salfred uint16_t max_in_frame_size; /* IN-token direction */ 177184610Salfred uint16_t max_out_frame_size; /* OUT-token direction */ 178184610Salfred uint8_t is_simplex:1; 179184610Salfred uint8_t support_multi_buffer:1; 180184610Salfred uint8_t support_bulk:1; 181184610Salfred uint8_t support_control:1; 182184610Salfred uint8_t support_interrupt:1; 183184610Salfred uint8_t support_isochronous:1; 184184610Salfred uint8_t support_in:1; /* IN-token is supported */ 185184610Salfred uint8_t support_out:1; /* OUT-token is supported */ 186184610Salfred}; 187184610Salfred 188184610Salfred/* prototypes */ 189184610Salfred 190194228Sthompsavoid usb_bus_mem_flush_all(struct usb_bus *bus, usb_bus_mem_cb_t *cb); 191194228Sthompsauint8_t usb_bus_mem_alloc_all(struct usb_bus *bus, bus_dma_tag_t dmat, usb_bus_mem_cb_t *cb); 192194228Sthompsavoid usb_bus_mem_free_all(struct usb_bus *bus, usb_bus_mem_cb_t *cb); 193194228Sthompsauint16_t usb_isoc_time_expand(struct usb_bus *bus, uint16_t isoc_time_curr); 194259023Shselaskyvoid usb_bus_reset_async_locked(struct usb_bus *bus); 195234803Shselasky#if USB_HAVE_TT_SUPPORT 196234803Shselaskyuint8_t usbd_fs_isoc_schedule_alloc_slot(struct usb_xfer *isoc_xfer, uint16_t isoc_time); 197234803Shselasky#endif 198184610Salfred 199194230Sthompsa#endif /* _USB_CONTROLLER_H_ */ 200