1/** 2 * \brief this file contains general declarations for the USB 3 */ 4 5/* Copyright (c) 2007-2013 ETH Zurich. 6 * All rights reserved. 7 * 8 * This file is distributed under the terms in the attached LICENSE file. 9 * If you do not find this file, copies can be found by writing to: 10 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group. 11 */ 12 13#ifndef LIBUSB_USB_H_ 14#define LIBUSB_USB_H_ 15 16#include <stdio.h> 17#include <usb/usb_error.h> 18#include <usb/usb_descriptor.h> 19 20#include <barrelfish/deferred.h> 21 22/// definition for the USB 23#define USB_MANAGER_SERVICE "usb_manager_service_name" 24 25/** 26 * enumeration of the differente USB modes. 27 * Currently only the HOST mode is supported 28 */ 29typedef enum usb_mode { 30 USB_MODE_HOST, 31 USB_MODE_DEVICE, 32 USB_MODE_DUAL 33} usb_mode_t; 34#define USB_MODE_MAX (USB_MODE_DUAL+1) 35 36 37/** 38 * The USB device speed enumeration describes all possible USB speed 39 * settings for a device. 40 */ 41typedef enum usb_speed { 42 USB_SPEED_VARIABLE, 43 USB_SPEED_LOW, 44 USB_SPEED_FULL, 45 USB_SPEED_HIGH, 46 USB_SPEED_SUPER, 47} usb_speed_t; 48 49#define USB_SPEED_MAX (USB_SPEED_SUPER+1) 50 51/// typedef for the host controller versions 52typedef enum usb_hc_version { 53 USB_UHCI=0x0100, 54 USB_OHCI=0x0110, 55 USB_EHCI=0x0200, 56 USB_XHCI=0x0300 57} usb_hc_version_t; 58 59/// typedef for the different USB revisions 60typedef enum usb_revision { 61 USB_REV_UNKNOWN, 62 USB_REV_PRE_1_0, 63 USB_REV_1_0, 64 USB_REV_1_1, 65 USB_REV_2_0, 66 USB_REV_2_5, 67 USB_REV_3_0 68} usb_revision_t; 69 70/// typedef for the different usb transfer / endpoint types 71typedef enum usb_type { 72 USB_TYPE_CTRL = 0, 73 USB_TYPE_ISOC, 74 USB_TYPE_BULK, 75 USB_TYPE_INTR 76} usb_type_t; 77 78 79/// typedef for the different power modes of an usb device 80typedef enum usb_power { 81 USB_POWER_MODE_OFF = 0, 82 USB_POWER_MODE_ON = 1, 83 USB_POWER_MODE_SAVE = 2, 84 USB_POWER_MODE_SUSPEND = 3, 85 USB_POWER_MODE_RESUME = 4 86} usb_power_t; 87 88/// the maximum power consumption in mA 89#define USB_POWER_MAX 500 90 91/// the minimum power requirements in mA 92#define USB_POWER_MIN 100 93 94/// the USB physical address type 95typedef volatile uintptr_t usb_paddr_t; 96 97/// definition for the default configuration value 98#define USB_CONFIGURATION_DEFAULT 1 99 100/// definition if the USB 101#define USB_CONFIGURATION_UNCONFIGURED 0xFF 102 103/// generic usb status 104struct usb_status { 105 uint16_t wStatus; 106}; 107typedef struct usb_status usb_status_t; 108 109#define USB_STATUS_SELF_POWERED 0x0001; 110#define USB_STATUS_REMOTE_WAKEUP 0x0002; 111#define USB_STATUS_EP_HALT 0x0001; 112 113/* 114 * Specific delays 115 */ 116#define USB_DELAY_PORT_RESET 10 117#define USB_DELAY_PORT_ROOT_RESET 50 118#define USB_DELAY_PORT_RECOVERY 10 119#define USB_DELAY_PORT_POWERUP 100 120#define USB_DELAY_PORT_RESUME 20 121#define USB_DELAY_SET_ADDRESS 2 122#define USB_DELAY_RESUME 100 123#define USB_DELAY_WAIT 10 124#define USB_DELAY_RECOVERY 10 125 126/* 127 * debug message control 128 */ 129 130#define USB_DEBUG(x...) debug_printf(x) 131//#define USB_DEBUG(x...) 132 133//#define USB_DEBUG_XFER(x...) USB_DEBUG(x) 134#define USB_DEBUG_XFER(x...) 135 136#define USB_DEBUG_HC(x...) USB_DEBUG(x) 137//#define USB_DEBUG_HC(x...) 138 139//#define USB_DEBUG_XFER_HC(x...) USB_DEBUG(x) 140#define USB_DEBUG_XFER_HC(x...) 141 142//#define USB_DEBUG_REQ(x...) USB_DEBUG(x) 143#define USB_DEBUG_REQ(x...) 144 145//#define USB_DEBUG_DEV(x...) USB_DEBUG(x) 146#define USB_DEBUG_DEV(x...) 147 148//#define USB_DEBUG_TR_ENTER USB_DEBUG(">> %s()\n", __func__) 149#define USB_DEBUG_TR_ENTER 150 151//#define USB_DEBUG_TR_RETURN USB_DEBUG("<< %s() return\n", __func__) 152#define USB_DEBUG_TR_RETURN 153 154#define USB_DEBUG_TR(x...) USB_DEBUG(x) 155 156#define USB_DEBUG_DRIVER(x...) USB_DEBUG(x) 157//#define USB_DEBUG_DRIVER(x...) 158 159//#define USB_DEBUG_MEM(x...) USB_DEBUG(x) 160#define USB_DEBUG_MEM(x...) 161 162#define USB_DEBUG_IDC(x...) 163//#define USB_DEBUG_IDC(x...) USB_DEBUG(x) 164 165//#define USB_DEBUG_HID(x...) debug_printf(x) 166#define USB_DEBUG_HID(x...) 167 168/* 169 * Wait a specific amount of milliseconds. This is a replacement for the USB_WAIT macro. 170 * 171 * \param ms Milliseconds to wait 172 * 173 * \return the error value from barrelfish_usleep 174 */ 175static inline errval_t lib_usb_wait(uint32_t ms) { 176 return barrelfish_usleep(1000 * ms); 177} 178 179typedef void (*lib_usb_callback)(void *st, usb_error_t err); 180 181usb_error_t usb_lib_init(uint16_t init_config, lib_usb_callback cb, void* st); 182 183#endif 184