Adding USB code to base

This commit is contained in:
Ørn E. Hansen
2013-04-20 22:14:30 +00:00
parent 5769bc31ac
commit 234d7f278a
8 changed files with 4995 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
#ifndef _CONFIG_H_
#define _CONFIG_H_
/* DEBUG */
#define DEBUG
/* DBUG */
#define DBUG
/* PCI XBIOS */
#undef PCI_XBIOS /* faster by cookie */
/* NETWORK */
#ifdef COLDFIRE
#define NETWORK
#define ETHERNET_PORT 0 /* FEC channel */
#undef TEST_NETWORK
#undef DEBUG_PRINT
#define LWIP
#define WEB_LIGHT
#undef FTP_SERVER
#define ERRNO
#define MCD_PROGQUERY
#undef MCD_DEBUG
#ifdef MCF5445X /* target untested */
#ifndef LWIP
#undef NETWORK /* to do */
#endif /* LWIP */
#endif /* MCF5445X */
/* XBIOS */
#define TOS_ATARI_LOGO /* defined for use TOS4.04 logo */
/* BDOS */
#define NEWCODE
#endif /* COLDFIRE */
/* fVDI */
#define FVDI_STRUCT_2006
/* NVDI */
#define PATCH_NVDI
/* VDI */
#undef TOS_TABLES /* defined for use TOS4.04 index tables */
/* X86 emulator */
#undef DEBUG_X86EMU
#undef DEBUG_X86EMU_PCI
#define __BIG_ENDIAN__
#define NO_LONG_LONG
/* Radeon */
#define DEFAULT_MONITOR_LAYOUT ""
#define ATI_LOGO
#define CONFIG_FB_RADEON_I2C
#define CONFIG_FB_MODE_HELPERS
#undef RADEON_TILING /* normally faster but tile 16 x 16 is not compatible with accel.c read_pixel, blit/expand_area and writes on screen frame buffer */
#ifndef COLDFIRE
#define RADEON_RENDER
#endif
#undef RADEON_THEATRE /* unfinished */
#define RADEON_DIRECT_ACCESS /* MMIO access faster but don't check endian - little -> big conversion !!! */
/* Radeon VIDIX */
#undef VIDIX_FILTER
#undef VIDIX_ENABLE_BM /* unfinished */
/* RTC M5485EVB */
#undef USE_RTC
/* LynxEM M5485EVB */
#ifdef COLDFIRE
#ifndef MCF5445X
#ifndef MCF547X
#undef CONFIG_VIDEO_SMI_LYNXEM
#endif
#endif
#endif /* COLDFIRE */
/* XBIOS Setscreen */
#define MAX_WIDTH_EMU_MONO 1024
#define MAX_HEIGHT_EMU_MONO 768
/* AC97 */
#define SOUND_AC97
/* USB */
#undef USB_DEVICE /* Coldfire USB device */
#define USB_BUFFER_SIZE 0x10000
#define CONFIG_USB_OHCI /* PCI USB 1.1 */
#define CONFIG_USB_EHCI /* PCI USB 2.0 */
#undef CONFIG_EHCI_DCACHE
#define CONFIG_SYS_OHCI_SWAP_REG_ACCESS
#define CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS 15
#define CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS 15
#if defined(COLDFIRE) && !defined(MCF547X)
#undef CONFIG_USB_INTERRUPT_POLLING
#else
#define CONFIG_USB_INTERRUPT_POLLING
#endif /* COLDFIRE */
#undef CONFIG_LEGACY_USB_INIT_SEQ
#define CONFIG_USB_KEYBOARD
#define CONFIG_USB_MOUSE
#define CONFIG_USB_STORAGE
#ifdef COLDFIRE
#define CONFIG_USB_MEM_NO_CACHE
#endif /* COLDFIRE */
#endif /* _CONFIG_H_ */

View File

@@ -0,0 +1,207 @@
/*-
* Copyright (c) 2007-2008, Juniper Networks, Inc.
* Copyright (c) 2008, Michael Trimarchi <trimarchimichael@yahoo.it>
* All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation version 2 of
* the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#ifndef USB_EHCI_H
#define USB_EHCI_H
#if !defined(CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS)
#define CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS 2
#endif
/* (shifted) direction/type/recipient from the USB 2.0 spec, table 9.2 */
#define DeviceRequest \
((USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE) << 8)
#define DeviceOutRequest \
((USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE) << 8)
#define InterfaceRequest \
((USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_INTERFACE) << 8)
#define EndpointRequest \
((USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_INTERFACE) << 8)
#define EndpointOutRequest \
((USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_INTERFACE) << 8)
/*
* Register Space.
*/
struct ehci_hccr {
uint32_t cr_capbase;
#define HC_LENGTH(p) (((p) >> 0) & 0x00ff)
#define HC_VERSION(p) (((p) >> 16) & 0xffff)
uint32_t cr_hcsparams;
#define HCS_PPC(p) ((p) & (1 << 4))
#define HCS_INDICATOR(p) ((p) & (1 << 16)) /* Port indicators */
#define HCS_N_PORTS(p) (((p) >> 0) & 0xf)
uint32_t cr_hccparams;
uint8_t cr_hcsp_portrt[8];
} __attribute__ ((packed));
struct ehci_hcor {
uint32_t or_usbcmd;
#define CMD_PARK (1 << 11) /* enable "park" */
#define CMD_PARK_CNT(c) (((c) >> 8) & 3) /* how many transfers to park */
#define CMD_ASE (1 << 5) /* async schedule enable */
#define CMD_LRESET (1 << 7) /* partial reset */
#define CMD_IAAD (1 << 5) /* "doorbell" interrupt */
#define CMD_PSE (1 << 4) /* periodic schedule enable */
#define CMD_RESET (1 << 1) /* reset HC not bus */
#define CMD_RUN (1 << 0) /* start/stop HC */
uint32_t or_usbsts;
#define STD_ASS (1 << 15)
#define STS_PSSTAT (1 << 14)
#define STS_RECL ( 1 << 13)
#define STS_HALT (1 << 12)
#define STS_IAA (1 << 5)
#define STS_HSE (1 << 4)
#define STS_FLR (1 << 3)
#define STS_PCD (1 << 2)
#define STS_USBERRINT (1 << 1)
#define STS_USBINT (1 << 0)
uint32_t or_usbintr;
#define INTR_IAAE (1 << 5)
#define INTR_HSEE (1 << 4)
#define INTR_FLRE (1 << 3)
#define INTR_PCDE (1 << 2)
#define INTR_USBERRINTE (1 << 1)
#define INTR_USBINTE (1 << 0)
uint32_t or_frindex;
uint32_t or_ctrldssegment;
uint32_t or_periodiclistbase;
uint32_t or_asynclistaddr;
uint32_t _reserved_[9];
uint32_t or_configflag;
#define FLAG_CF (1 << 0) /* true: we'll support "high speed" */
uint32_t or_portsc[CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS];
uint32_t or_systune;
} __attribute__ ((packed));
#define USBMODE 0x68 /* USB Device mode */
#define USBMODE_SDIS (1 << 3) /* Stream disable */
#define USBMODE_BE (1 << 2) /* BE/LE endiannes select */
#define USBMODE_CM_HC (3 << 0) /* host controller mode */
#define USBMODE_CM_IDLE (0 << 0) /* idle state */
/* Interface descriptor */
struct usb_linux_interface_descriptor {
unsigned char bLength;
unsigned char bDescriptorType;
unsigned char bInterfaceNumber;
unsigned char bAlternateSetting;
unsigned char bNumEndpoints;
unsigned char bInterfaceClass;
unsigned char bInterfaceSubClass;
unsigned char bInterfaceProtocol;
unsigned char iInterface;
} __attribute__ ((packed));
/* Configuration descriptor information.. */
struct usb_linux_config_descriptor {
unsigned char bLength;
unsigned char bDescriptorType;
unsigned short wTotalLength;
unsigned char bNumInterfaces;
unsigned char bConfigurationValue;
unsigned char iConfiguration;
unsigned char bmAttributes;
unsigned char MaxPower;
} __attribute__ ((packed));
#if defined CONFIG_EHCI_DESC_BIG_ENDIAN
#define ehci_readl(x) (*((volatile u32 *)(x)))
#define ehci_writel(a, b) (*((volatile u32 *)(a)) = ((volatile u32)b))
#else
#define ehci_readl(x) cpu_to_le32((*((volatile u32 *)(x))))
#define ehci_writel(a, b) (*((volatile u32 *)(a)) = cpu_to_le32(((volatile u32)b)))
#endif
#if defined CONFIG_EHCI_MMIO_BIG_ENDIAN
#define hc32_to_cpu(x) be32_to_cpu((x))
#define cpu_to_hc32(x) cpu_to_be32((x))
#else
#define hc32_to_cpu(x) le32_to_cpu((x))
#define cpu_to_hc32(x) cpu_to_le32((x))
#endif
#define EHCI_PS_WKOC_E (1 << 22) /* RW wake on over current */
#define EHCI_PS_WKDSCNNT_E (1 << 21) /* RW wake on disconnect */
#define EHCI_PS_WKCNNT_E (1 << 20) /* RW wake on connect */
#define EHCI_PS_PO (1 << 13) /* RW port owner */
#define EHCI_PS_PP (1 << 12) /* RW,RO port power */
#define EHCI_PS_LS (3 << 10) /* RO line status */
#define EHCI_PS_PR (1 << 8) /* RW port reset */
#define EHCI_PS_SUSP (1 << 7) /* RW suspend */
#define EHCI_PS_FPR (1 << 6) /* RW force port resume */
#define EHCI_PS_OCC (1 << 5) /* RWC over current change */
#define EHCI_PS_OCA (1 << 4) /* RO over current active */
#define EHCI_PS_PEC (1 << 3) /* RWC port enable change */
#define EHCI_PS_PE (1 << 2) /* RW port enable */
#define EHCI_PS_CSC (1 << 1) /* RWC connect status change */
#define EHCI_PS_CS (1 << 0) /* RO connect status */
#define EHCI_PS_CLEAR (EHCI_PS_OCC | EHCI_PS_PEC | EHCI_PS_CSC)
#define EHCI_PS_IS_LOWSPEED(x) (((x) & EHCI_PS_LS) == (1 << 10))
/*
* Schedule Interface Space.
*
* IMPORTANT: Software must ensure that no interface data structure
* reachable by the EHCI host controller spans a 4K page boundary!
*
* Periodic transfers (i.e. isochronous and interrupt transfers) are
* not supported.
*/
/* Queue Element Transfer Descriptor (qTD). */
struct qTD {
uint32_t qt_next;
#define QT_NEXT_TERMINATE 1
uint32_t qt_altnext;
uint32_t qt_token;
uint32_t qt_buffer[5];
};
/* Queue Head (QH). */
struct QH {
uint32_t qh_link;
#define QH_LINK_TERMINATE 1
#define QH_LINK_TYPE_ITD 0
#define QH_LINK_TYPE_QH 2
#define QH_LINK_TYPE_SITD 4
#define QH_LINK_TYPE_FSTN 6
uint32_t qh_endpt1;
uint32_t qh_endpt2;
uint32_t qh_curtd;
struct qTD qh_overlay;
/*
* Add dummy fill value to make the size of this struct
* aligned to 32 bytes
*/
uint8_t fill[16];
};
/* Low level init functions */
int ehci_hcd_init(void);
int ehci_hcd_stop(void);
#endif /* USB_EHCI_H */

View File

@@ -0,0 +1,165 @@
#ifndef MOD_DEVICETABLE_H
#define MOD_DEVICETABLE_H
#define PCI_ANY_ID (~0)
struct pci_device_id {
unsigned long vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
unsigned long subvendor, subdevice; /* Subsystem ID's or PCI_ANY_ID */
unsigned long class, class_mask; /* (class,subclass,prog-if) triplet */
unsigned long driver_data; /* Data private to the driver */
};
#define IEEE1394_MATCH_VENDOR_ID 0x0001
#define IEEE1394_MATCH_MODEL_ID 0x0002
#define IEEE1394_MATCH_SPECIFIER_ID 0x0004
#define IEEE1394_MATCH_VERSION 0x0008
struct ieee1394_device_id {
unsigned long match_flags;
unsigned long vendor_id;
unsigned long model_id;
unsigned long specifier_id;
unsigned long version;
unsigned long driver_data;
};
/*
* Device table entry for "new style" table-driven USB drivers.
* User mode code can read these tables to choose which modules to load.
* Declare the table as a MODULE_DEVICE_TABLE.
*
* A probe() parameter will point to a matching entry from this table.
* Use the driver_info field for each match to hold information tied
* to that match: device quirks, etc.
*
* Terminate the driver's table with an all-zeroes entry.
* Use the flag values to control which fields are compared.
*/
/**
* struct usb_device_id - identifies USB devices for probing and hotplugging
* @match_flags: Bit mask controlling of the other fields are used to match
* against new devices. Any field except for driver_info may be used,
* although some only make sense in conjunction with other fields.
* This is usually set by a USB_DEVICE_*() macro, which sets all
* other fields in this structure except for driver_info.
* @idVendor: USB vendor ID for a device; numbers are assigned
* by the USB forum to its members.
* @idProduct: Vendor-assigned product ID.
* @bcdDevice_lo: Low end of range of vendor-assigned product version numbers.
* This is also used to identify individual product versions, for
* a range consisting of a single device.
* @bcdDevice_hi: High end of version number range. The range of product
* versions is inclusive.
* @bDeviceClass: Class of device; numbers are assigned
* by the USB forum. Products may choose to implement classes,
* or be vendor-specific. Device classes specify behavior of all
* the interfaces on a devices.
* @bDeviceSubClass: Subclass of device; associated with bDeviceClass.
* @bDeviceProtocol: Protocol of device; associated with bDeviceClass.
* @bInterfaceClass: Class of interface; numbers are assigned
* by the USB forum. Products may choose to implement classes,
* or be vendor-specific. Interface classes specify behavior only
* of a given interface; other interfaces may support other classes.
* @bInterfaceSubClass: Subclass of interface; associated with bInterfaceClass.
* @bInterfaceProtocol: Protocol of interface; associated with bInterfaceClass.
* @driver_info: Holds information used by the driver. Usually it holds
* a pointer to a descriptor understood by the driver, or perhaps
* device flags.
*
* In most cases, drivers will create a table of device IDs by using
* USB_DEVICE(), or similar macros designed for that purpose.
* They will then export it to userspace using MODULE_DEVICE_TABLE(),
* and provide it to the USB core through their usb_driver structure.
*
* See the usb_match_id() function for information about how matches are
* performed. Briefly, you will normally use one of several macros to help
* construct these entries. Each entry you provide will either identify
* one or more specific products, or will identify a class of products
* which have agreed to behave the same. You should put the more specific
* matches towards the beginning of your table, so that driver_info can
* record quirks of specific products.
*/
struct usb_device_id {
/* which fields to match against? */
unsigned short match_flags;
/* Used for product specific matches; range is inclusive */
unsigned short idVendor;
unsigned short idProduct;
unsigned short bcdDevice_lo;
unsigned short bcdDevice_hi;
/* Used for device class matches */
unsigned char bDeviceClass;
unsigned char bDeviceSubClass;
unsigned char bDeviceProtocol;
/* Used for interface class matches */
unsigned char bInterfaceClass;
unsigned char bInterfaceSubClass;
unsigned char bInterfaceProtocol;
/* not matched against */
unsigned long driver_info;
};
/* Some useful macros to use to create struct usb_device_id */
#define USB_DEVICE_ID_MATCH_VENDOR 0x0001
#define USB_DEVICE_ID_MATCH_PRODUCT 0x0002
#define USB_DEVICE_ID_MATCH_DEV_LO 0x0004
#define USB_DEVICE_ID_MATCH_DEV_HI 0x0008
#define USB_DEVICE_ID_MATCH_DEV_CLASS 0x0010
#define USB_DEVICE_ID_MATCH_DEV_SUBCLASS 0x0020
#define USB_DEVICE_ID_MATCH_DEV_PROTOCOL 0x0040
#define USB_DEVICE_ID_MATCH_INT_CLASS 0x0080
#define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
#define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
/* s390 CCW devices */
struct ccw_device_id {
unsigned short match_flags; /* which fields to match against */
unsigned short cu_type; /* control unit type */
unsigned short dev_type; /* device type */
unsigned char cu_model; /* control unit model */
unsigned char dev_model; /* device model */
unsigned long driver_info;
};
#define CCW_DEVICE_ID_MATCH_CU_TYPE 0x01
#define CCW_DEVICE_ID_MATCH_CU_MODEL 0x02
#define CCW_DEVICE_ID_MATCH_DEVICE_TYPE 0x04
#define CCW_DEVICE_ID_MATCH_DEVICE_MODEL 0x08
#define PNP_ID_LEN 8
#define PNP_MAX_DEVICES 8
struct pnp_device_id {
unsigned char id[PNP_ID_LEN];
unsigned long driver_data;
};
struct pnp_card_device_id {
unsigned char id[PNP_ID_LEN];
unsigned long driver_data;
struct {
unsigned char id[PNP_ID_LEN];
} devs[PNP_MAX_DEVICES];
};
#define SERIO_ANY 0xff
struct serio_device_id {
unsigned char type;
unsigned char extra;
unsigned char id;
unsigned char proto;
};
#endif /* MOD_DEVICETABLE_H */

View File

@@ -0,0 +1,480 @@
/*
* URB OHCI HCD (Host Controller Driver) for USB.
*
* (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
* (C) Copyright 2000-2001 David Brownell <dbrownell@users.sourceforge.net>
*
* usb-ohci.h
*/
static int cc_to_error[16] = {
/* mapping of the OHCI CC status to error codes */
/* No Error */ 0,
/* CRC Error */ USB_ST_CRC_ERR,
/* Bit Stuff */ USB_ST_BIT_ERR,
/* Data Togg */ USB_ST_CRC_ERR,
/* Stall */ USB_ST_STALLED,
/* DevNotResp */ -1,
/* PIDCheck */ USB_ST_BIT_ERR,
/* UnExpPID */ USB_ST_BIT_ERR,
/* DataOver */ USB_ST_BUF_ERR,
/* DataUnder */ USB_ST_BUF_ERR,
/* reservd */ -1,
/* reservd */ -1,
/* BufferOver */ USB_ST_BUF_ERR,
/* BuffUnder */ USB_ST_BUF_ERR,
/* Not Access */ -1,
/* Not Access */ -1
};
static const char *cc_to_string[16] = {
"No Error",
"CRC: Last data packet from endpoint contained a CRC error.",
"BITSTUFFING:\r\nLast data packet from endpoint contained a bit stuffing violation",
"DATATOGGLEMISMATCH:\r\n Last packet from endpoint had data toggle PID\r\n" \
"that did not match the expected value.",
"STALL: TD was moved to the Done Queue because the endpoint returned a STALL PID",
"DEVICENOTRESPONDING:\r\nDevice did not respond to token (IN) or did\r\n" \
"not provide a handshake (OUT)",
"PIDCHECKFAILURE:\r\nCheck bits on PID from endpoint failed on data PID\r\n"\
"(IN) or handshake (OUT)",
"UNEXPECTEDPID:\r\nReceive PID was not valid when encountered or PID\r\n" \
"value is not defined.",
"DATAOVERRUN:\r\nThe amount of data returned by the endpoint exceeded\r\n" \
"either the size of the maximum data packet allowed\r\n" \
"from the endpoint (found in MaximumPacketSize field\r\n" \
"of ED) or the remaining buffer size.",
"DATAUNDERRUN:\r\nThe endpoint returned less than MaximumPacketSize\r\n" \
"and that amount was not sufficient to fill the\r\n" \
"specified buffer",
"reserved1",
"reserved2",
"BUFFEROVERRUN:\r\nDuring an IN, HC received data from endpoint faster\r\n" \
"than it could be written to system memory",
"BUFFERUNDERRUN:\r\nDuring an OUT, HC could not retrieve data from\r\n" \
"system memory fast enough to keep up with data USB data rate.",
"NOT ACCESSED:\r\nThis code is set by software before the TD is placed\r\n" \
"on a list to be processed by the HC.(1)",
"NOT ACCESSED:\r\nThis code is set by software before the TD is placed\r\n" \
"on a list to be processed by the HC.(2)",
};
/* ED States */
#define ED_NEW 0x00
#define ED_UNLINK 0x01
#define ED_OPER 0x02
#define ED_DEL 0x04
#define ED_URB_DEL 0x08
/* usb_ohci_ed */
struct ed {
__u32 hwINFO;
__u32 hwTailP;
__u32 hwHeadP;
__u32 hwNextED;
struct ed *ed_prev;
__u8 int_period;
__u8 int_branch;
__u8 int_load;
__u8 int_interval;
__u8 state;
__u8 type;
__u16 last_iso;
struct ed *ed_rm_list;
struct usb_device *usb_dev;
void *purb;
__u32 unused[2];
} __attribute__((aligned(16)));
typedef struct ed ed_t;
/* TD info field */
#define TD_CC 0xf0000000
#define TD_CC_GET(td_p) ((td_p >>28) & 0x0f)
#define TD_CC_SET(td_p, cc) (td_p) = ((td_p) & 0x0fffffff) | (((cc) & 0x0f) << 28)
#define TD_EC 0x0C000000
#define TD_T 0x03000000
#define TD_T_DATA0 0x02000000
#define TD_T_DATA1 0x03000000
#define TD_T_TOGGLE 0x00000000
#define TD_R 0x00040000
#define TD_DI 0x00E00000
#define TD_DI_SET(X) (((X) & 0x07)<< 21)
#define TD_DP 0x00180000
#define TD_DP_SETUP 0x00000000
#define TD_DP_IN 0x00100000
#define TD_DP_OUT 0x00080000
#define TD_ISO 0x00010000
#define TD_DEL 0x00020000
/* CC Codes */
#define TD_CC_NOERROR 0x00
#define TD_CC_CRC 0x01
#define TD_CC_BITSTUFFING 0x02
#define TD_CC_DATATOGGLEM 0x03
#define TD_CC_STALL 0x04
#define TD_DEVNOTRESP 0x05
#define TD_PIDCHECKFAIL 0x06
#define TD_UNEXPECTEDPID 0x07
#define TD_DATAOVERRUN 0x08
#define TD_DATAUNDERRUN 0x09
#define TD_BUFFEROVERRUN 0x0C
#define TD_BUFFERUNDERRUN 0x0D
#define TD_NOTACCESSED 0x0F
#define MAXPSW 1
struct td {
__u32 hwINFO;
__u32 hwCBP; /* Current Buffer Pointer */
__u32 hwNextTD; /* Next TD Pointer */
__u32 hwBE; /* Memory Buffer End Pointer */
__u16 hwPSW[MAXPSW];
__u8 unused;
__u8 index;
struct ed *ed;
struct td *next_dl_td;
struct usb_device *usb_dev;
int transfer_len;
__u32 data;
__u32 unused2[2];
} __attribute__((aligned(32)));
typedef struct td td_t;
#define OHCI_ED_SKIP (1 << 14)
/*
* The HCCA (Host Controller Communications Area) is a 256 byte
* structure defined in the OHCI spec. that the host controller is
* told the base address of. It must be 256-byte aligned.
*/
#define NUM_INTS 32 /* part of the OHCI standard */
struct ohci_hcca {
__u32 int_table[NUM_INTS]; /* Interrupt ED table */
#if defined(CONFIG_MPC5200)
__u16 pad1; /* set to 0 on each frame_no change */
__u16 frame_no; /* current frame number */
#else
__u16 frame_no; /* current frame number */
__u16 pad1; /* set to 0 on each frame_no change */
#endif
__u32 done_head; /* info returned for an interrupt */
u8 reserved_for_hc[116];
} __attribute__((aligned(256)));
/*
* Maximum number of root hub ports.
*/
#ifndef CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS
# error "CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS undefined!"
#endif
/*
* This is the structure of the OHCI controller's memory mapped I/O
* region. This is Memory Mapped I/O. You must use the readl() and
* writel() macros defined in asm/io.h to access these!!
*/
struct ohci_regs {
/* control and status registers */
__u32 revision;
__u32 control;
__u32 cmdstatus;
__u32 intrstatus;
__u32 intrenable;
__u32 intrdisable;
/* memory pointers */
__u32 hcca;
__u32 ed_periodcurrent;
__u32 ed_controlhead;
__u32 ed_controlcurrent;
__u32 ed_bulkhead;
__u32 ed_bulkcurrent;
__u32 donehead;
/* frame counters */
__u32 fminterval;
__u32 fmremaining;
__u32 fmnumber;
__u32 periodicstart;
__u32 lsthresh;
/* Root hub ports */
struct ohci_roothub_regs {
__u32 a;
__u32 b;
__u32 status;
__u32 portstatus[CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS];
} roothub;
} __attribute__((aligned(32)));
/* Some EHCI controls */
#define EHCI_USBCMD_OFF 0x20
#define EHCI_USBCMD_HCRESET (1 << 1)
/* OHCI CONTROL AND STATUS REGISTER MASKS */
/*
* HcControl (control) register masks
*/
#define OHCI_CTRL_CBSR (3 << 0) /* control/bulk service ratio */
#define OHCI_CTRL_PLE (1 << 2) /* periodic list enable */
#define OHCI_CTRL_IE (1 << 3) /* isochronous enable */
#define OHCI_CTRL_CLE (1 << 4) /* control list enable */
#define OHCI_CTRL_BLE (1 << 5) /* bulk list enable */
#define OHCI_CTRL_HCFS (3 << 6) /* host controller functional state */
#define OHCI_CTRL_IR (1 << 8) /* interrupt routing */
#define OHCI_CTRL_RWC (1 << 9) /* remote wakeup connected */
#define OHCI_CTRL_RWE (1 << 10) /* remote wakeup enable */
/* pre-shifted values for HCFS */
# define OHCI_USB_RESET (0 << 6)
# define OHCI_USB_RESUME (1 << 6)
# define OHCI_USB_OPER (2 << 6)
# define OHCI_USB_SUSPEND (3 << 6)
/*
* HcCommandStatus (cmdstatus) register masks
*/
#define OHCI_HCR (1 << 0) /* host controller reset */
#define OHCI_CLF (1 << 1) /* control list filled */
#define OHCI_BLF (1 << 2) /* bulk list filled */
#define OHCI_OCR (1 << 3) /* ownership change request */
#define OHCI_SOC (3 << 16) /* scheduling overrun count */
/*
* masks used with interrupt registers:
* HcInterruptStatus (intrstatus)
* HcInterruptEnable (intrenable)
* HcInterruptDisable (intrdisable)
*/
#define OHCI_INTR_SO (1 << 0) /* scheduling overrun */
#define OHCI_INTR_WDH (1 << 1) /* writeback of done_head */
#define OHCI_INTR_SF (1 << 2) /* start frame */
#define OHCI_INTR_RD (1 << 3) /* resume detect */
#define OHCI_INTR_UE (1 << 4) /* unrecoverable error */
#define OHCI_INTR_FNO (1 << 5) /* frame number overflow */
#define OHCI_INTR_RHSC (1 << 6) /* root hub status change */
#define OHCI_INTR_OC (1 << 30) /* ownership change */
#define OHCI_INTR_MIE (1 << 31) /* master interrupt enable */
/* Virtual Root HUB */
struct virt_root_hub {
int devnum; /* Address of Root Hub endpoint */
void *dev; /* was urb */
void *int_addr;
int send;
int interval;
};
/* USB HUB CONSTANTS (not OHCI-specific; see hub.h) */
/* destination of request */
#define RH_INTERFACE 0x01
#define RH_ENDPOINT 0x02
#define RH_OTHER 0x03
#define RH_CLASS 0x20
#define RH_VENDOR 0x40
/* Requests: bRequest << 8 | bmRequestType */
#define RH_GET_STATUS 0x0080
#define RH_CLEAR_FEATURE 0x0100
#define RH_SET_FEATURE 0x0300
#define RH_SET_ADDRESS 0x0500
#define RH_GET_DESCRIPTOR 0x0680
#define RH_SET_DESCRIPTOR 0x0700
#define RH_GET_CONFIGURATION 0x0880
#define RH_SET_CONFIGURATION 0x0900
#define RH_GET_STATE 0x0280
#define RH_GET_INTERFACE 0x0A80
#define RH_SET_INTERFACE 0x0B00
#define RH_SYNC_FRAME 0x0C80
/* Our Vendor Specific Request */
#define RH_SET_EP 0x2000
/* Hub port features */
#define RH_PORT_CONNECTION 0x00
#define RH_PORT_ENABLE 0x01
#define RH_PORT_SUSPEND 0x02
#define RH_PORT_OVER_CURRENT 0x03
#define RH_PORT_RESET 0x04
#define RH_PORT_POWER 0x08
#define RH_PORT_LOW_SPEED 0x09
#define RH_C_PORT_CONNECTION 0x10
#define RH_C_PORT_ENABLE 0x11
#define RH_C_PORT_SUSPEND 0x12
#define RH_C_PORT_OVER_CURRENT 0x13
#define RH_C_PORT_RESET 0x14
/* Hub features */
#define RH_C_HUB_LOCAL_POWER 0x00
#define RH_C_HUB_OVER_CURRENT 0x01
#define RH_DEVICE_REMOTE_WAKEUP 0x00
#define RH_ENDPOINT_STALL 0x01
#define RH_ACK 0x01
#define RH_REQ_ERR -1
#define RH_NACK 0x00
/* OHCI ROOT HUB REGISTER MASKS */
/* roothub.portstatus [i] bits */
#define RH_PS_CCS 0x00000001 /* current connect status */
#define RH_PS_PES 0x00000002 /* port enable status*/
#define RH_PS_PSS 0x00000004 /* port suspend status */
#define RH_PS_POCI 0x00000008 /* port over current indicator */
#define RH_PS_PRS 0x00000010 /* port reset status */
#define RH_PS_PPS 0x00000100 /* port power status */
#define RH_PS_LSDA 0x00000200 /* low speed device attached */
#define RH_PS_CSC 0x00010000 /* connect status change */
#define RH_PS_PESC 0x00020000 /* port enable status change */
#define RH_PS_PSSC 0x00040000 /* port suspend status change */
#define RH_PS_OCIC 0x00080000 /* over current indicator change */
#define RH_PS_PRSC 0x00100000 /* port reset status change */
/* roothub.status bits */
#define RH_HS_LPS 0x00000001 /* local power status */
#define RH_HS_OCI 0x00000002 /* over current indicator */
#define RH_HS_DRWE 0x00008000 /* device remote wakeup enable */
#define RH_HS_LPSC 0x00010000 /* local power status change */
#define RH_HS_OCIC 0x00020000 /* over current indicator change */
#define RH_HS_CRWE 0x80000000 /* clear remote wakeup enable */
/* roothub.b masks */
#define RH_B_DR 0x0000ffff /* device removable flags */
#define RH_B_PPCM 0xffff0000 /* port power control mask */
/* roothub.a masks */
#define RH_A_NDP (0xff << 0) /* number of downstream ports */
#define RH_A_PSM (1 << 8) /* power switching mode */
#define RH_A_NPS (1 << 9) /* no power switching */
#define RH_A_DT (1 << 10) /* device type (mbz) */
#define RH_A_OCPM (1 << 11) /* over current protection mode */
#define RH_A_NOCP (1 << 12) /* no over current protection */
#define RH_A_POTPGT (0xff << 24) /* power on to power good time */
/* urb */
#define N_URB_TD 48
typedef struct
{
ed_t *ed;
__u16 length; /* number of tds associated with this request */
__u16 td_cnt; /* number of tds already serviced */
struct usb_device *dev;
int state;
unsigned long pipe;
void *transfer_buffer;
int transfer_buffer_length;
int interval;
int actual_length;
int finished;
td_t *td[N_URB_TD]; /* list pointer to all corresponding TDs associated with this request */
} urb_priv_t;
#define URB_DEL 1
#define NUM_EDS 8 /* num of preallocated endpoint descriptors */
struct ohci_device {
ed_t ed[NUM_EDS];
int ed_cnt;
};
/*
* This is the full ohci controller description
*
* Note how the "proper" USB information is just
* a subset of what the full implementation needs. (Linus)
*/
typedef struct ohci {
/* ------- common part -------- */
long handle; /* PCI BIOS */
const struct pci_device_id *ent;
int usbnum;
/* ---- end of common part ---- */
int big_endian; /* PCI BIOS */
int controller;
struct ohci_hcca *hcca_unaligned;
struct ohci_hcca *hcca; /* hcca */
td_t *td_unaligned;
struct ohci_device *ohci_dev_unaligned;
/* this allocates EDs for all possible endpoints */
struct ohci_device *ohci_dev;
int irq_enabled;
int stat_irq;
int irq;
int disabled; /* e.g. got a UE, we're hung */
int sleeping;
#define OHCI_FLAGS_NEC 0x80000000
unsigned long flags; /* for HC bugs */
unsigned long offset;
unsigned long dma_offset;
struct ohci_regs *regs; /* OHCI controller's memory */
int ohci_int_load[32]; /* load of the 32 Interrupt Chains (for load balancing)*/
ed_t *ed_rm_list[2]; /* lists of all endpoints to be removed */
ed_t *ed_bulktail; /* last endpoint of bulk list */
ed_t *ed_controltail; /* last endpoint of control list */
int intrstatus;
__u32 hc_control; /* copy of the hc control reg */
struct virt_root_hub rh;
const char *slot_name;
/* device which was disconnected */
struct usb_device *devgone;
} ohci_t;
/* hcd */
/* endpoint */
static int ep_link(ohci_t * ohci, ed_t * ed);
static int ep_unlink(ohci_t * ohci, ed_t * ed);
static ed_t * ep_add_ed(ohci_t * ohci, struct usb_device * usb_dev, unsigned long pipe, int interval, int load);
/*-------------------------------------------------------------------------*/
/* we need more TDs than EDs */
#define NUM_TD 64
/* pointers to aligned storage */
td_t *ptd;
/* TDs ... */
static inline struct td *td_alloc(struct usb_device *usb_dev)
{
int i;
struct td *td;
td = NULL;
for(i = 0; i < NUM_TD; i++)
{
if(ptd[i].usb_dev == NULL)
{
td = &ptd[i];
td->usb_dev = usb_dev;
break;
}
}
return td;
}
static inline void ed_free(struct ed *ed)
{
ed->usb_dev = NULL;
}

View File

@@ -0,0 +1,209 @@
/*
* (C) Copyright 2001
* Denis Peter, MPL AG Switzerland
*
* See file CREDITS for list of people who contributed to this
* project.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*/
#ifndef _SCSI_H
#define _SCSI_H
typedef struct SCSI_cmd_block{
unsigned char cmd[16]; /* command */
unsigned char sense_buf[64]; /* for request sense */
unsigned char status; /* SCSI Status */
unsigned char target; /* Target ID */
unsigned char lun; /* Target LUN */
unsigned char cmdlen; /* command len */
unsigned long datalen; /* Total data length */
unsigned char * pdata; /* pointer to data */
unsigned char msgout[12]; /* Messge out buffer (NOT USED) */
unsigned char msgin[12]; /* Message in buffer */
unsigned char sensecmdlen; /* Sense command len */
unsigned long sensedatalen; /* Sense data len */
unsigned char sensecmd[6]; /* Sense command */
unsigned long contr_stat; /* Controller Status */
unsigned long trans_bytes; /* tranfered bytes */
unsigned int priv;
}ccb;
/*-----------------------------------------------------------
**
** SCSI constants.
**
**-----------------------------------------------------------
*/
/*
** Messages
*/
#define M_COMPLETE (0x00)
#define M_EXTENDED (0x01)
#define M_SAVE_DP (0x02)
#define M_RESTORE_DP (0x03)
#define M_DISCONNECT (0x04)
#define M_ID_ERROR (0x05)
#define M_ABORT (0x06)
#define M_REJECT (0x07)
#define M_NOOP (0x08)
#define M_PARITY (0x09)
#define M_LCOMPLETE (0x0a)
#define M_FCOMPLETE (0x0b)
#define M_RESET (0x0c)
#define M_ABORT_TAG (0x0d)
#define M_CLEAR_QUEUE (0x0e)
#define M_INIT_REC (0x0f)
#define M_REL_REC (0x10)
#define M_TERMINATE (0x11)
#define M_SIMPLE_TAG (0x20)
#define M_HEAD_TAG (0x21)
#define M_ORDERED_TAG (0x22)
#define M_IGN_RESIDUE (0x23)
#define M_IDENTIFY (0x80)
#define M_X_MODIFY_DP (0x00)
#define M_X_SYNC_REQ (0x01)
#define M_X_WIDE_REQ (0x03)
#define M_X_PPR_REQ (0x04)
/*
** Status
*/
#define S_GOOD (0x00)
#define S_CHECK_COND (0x02)
#define S_COND_MET (0x04)
#define S_BUSY (0x08)
#define S_INT (0x10)
#define S_INT_COND_MET (0x14)
#define S_CONFLICT (0x18)
#define S_TERMINATED (0x20)
#define S_QUEUE_FULL (0x28)
#define S_ILLEGAL (0xff)
#define S_SENSE (0x80)
/*
* Sense_keys
*/
#define SENSE_NO_SENSE 0x0
#define SENSE_RECOVERED_ERROR 0x1
#define SENSE_NOT_READY 0x2
#define SENSE_MEDIUM_ERROR 0x3
#define SENSE_HARDWARE_ERROR 0x4
#define SENSE_ILLEGAL_REQUEST 0x5
#define SENSE_UNIT_ATTENTION 0x6
#define SENSE_DATA_PROTECT 0x7
#define SENSE_BLANK_CHECK 0x8
#define SENSE_VENDOR_SPECIFIC 0x9
#define SENSE_COPY_ABORTED 0xA
#define SENSE_ABORTED_COMMAND 0xB
#define SENSE_VOLUME_OVERFLOW 0xD
#define SENSE_MISCOMPARE 0xE
#define SCSI_CHANGE_DEF 0x40 /* Change Definition (Optional) */
#define SCSI_COMPARE 0x39 /* Compare (O) */
#define SCSI_COPY 0x18 /* Copy (O) */
#define SCSI_COP_VERIFY 0x3A /* Copy and Verify (O) */
#define SCSI_INQUIRY 0x12 /* Inquiry (MANDATORY) */
#define SCSI_LOG_SELECT 0x4C /* Log Select (O) */
#define SCSI_LOG_SENSE 0x4D /* Log Sense (O) */
#define SCSI_MODE_SEL6 0x15 /* Mode Select 6-byte (Device Specific) */
#define SCSI_MODE_SEL10 0x55 /* Mode Select 10-byte (Device Specific) */
#define SCSI_MODE_SEN6 0x1A /* Mode Sense 6-byte (Device Specific) */
#define SCSI_MODE_SEN10 0x5A /* Mode Sense 10-byte (Device Specific) */
#define SCSI_READ_BUFF 0x3C /* Read Buffer (O) */
#define SCSI_REQ_SENSE 0x03 /* Request Sense (MANDATORY) */
#define SCSI_SEND_DIAG 0x1D /* Send Diagnostic (O) */
#define SCSI_TST_U_RDY 0x00 /* Test Unit Ready (MANDATORY) */
#define SCSI_WRITE_BUFF 0x3B /* Write Buffer (O) */
/***************************************************************************
* %%% Commands Unique to Direct Access Devices %%%
***************************************************************************/
#define SCSI_COMPARE 0x39 /* Compare (O) */
#define SCSI_FORMAT 0x04 /* Format Unit (MANDATORY) */
#define SCSI_LCK_UN_CAC 0x36 /* Lock Unlock Cache (O) */
#define SCSI_PREFETCH 0x34 /* Prefetch (O) */
#define SCSI_MED_REMOVL 0x1E /* Prevent/Allow medium Removal (O) */
#define SCSI_READ6 0x08 /* Read 6-byte (MANDATORY) */
#define SCSI_READ10 0x28 /* Read 10-byte (MANDATORY) */
#define SCSI_RD_CAPAC 0x25 /* Read Capacity (MANDATORY) */
#define SCSI_RD_DEFECT 0x37 /* Read Defect Data (O) */
#define SCSI_READ_LONG 0x3E /* Read Long (O) */
#define SCSI_REASS_BLK 0x07 /* Reassign Blocks (O) */
#define SCSI_RCV_DIAG 0x1C /* Receive Diagnostic Results (O) */
#define SCSI_RELEASE 0x17 /* Release Unit (MANDATORY) */
#define SCSI_REZERO 0x01 /* Rezero Unit (O) */
#define SCSI_SRCH_DAT_E 0x31 /* Search Data Equal (O) */
#define SCSI_SRCH_DAT_H 0x30 /* Search Data High (O) */
#define SCSI_SRCH_DAT_L 0x32 /* Search Data Low (O) */
#define SCSI_SEEK6 0x0B /* Seek 6-Byte (O) */
#define SCSI_SEEK10 0x2B /* Seek 10-Byte (O) */
#define SCSI_SEND_DIAG 0x1D /* Send Diagnostics (MANDATORY) */
#define SCSI_SET_LIMIT 0x33 /* Set Limits (O) */
#define SCSI_START_STP 0x1B /* Start/Stop Unit (O) */
#define SCSI_SYNC_CACHE 0x35 /* Synchronize Cache (O) */
#define SCSI_VERIFY 0x2F /* Verify (O) */
#define SCSI_WRITE6 0x0A /* Write 6-Byte (MANDATORY) */
#define SCSI_WRITE10 0x2A /* Write 10-Byte (MANDATORY) */
#define SCSI_WRT_VERIFY 0x2E /* Write and Verify (O) */
#define SCSI_WRITE_LONG 0x3F /* Write Long (O) */
#define SCSI_WRITE_SAME 0x41 /* Write Same (O) */
#if 0
/****************************************************************************
* decleration of functions which have to reside in the LowLevel Part Driver
*/
void scsi_print_error(ccb *pccb);
int scsi_exec(ccb *pccb);
void scsi_bus_reset(void);
void scsi_low_level_init(int busdevfunc);
/***************************************************************************
* functions residing inside cmd_scsi.c
*/
void scsi_init(void);
#endif
#define SCSI_IDENTIFY 0xC0 /* not used */
/* Hardware errors */
#define SCSI_SEL_TIME_OUT 0x00000101 /* Selection time out */
#define SCSI_HNS_TIME_OUT 0x00000102 /* Handshake */
#define SCSI_MA_TIME_OUT 0x00000103 /* Phase error */
#define SCSI_UNEXP_DIS 0x00000104 /* unexpected disconnect */
#define SCSI_INT_STATE 0x00010000 /* unknown Interrupt number is stored in 16 LSB */
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#endif /* _SCSI_H */

View File

@@ -0,0 +1,514 @@
/*
* (C) Copyright 2001
* Denis Peter, MPL AG Switzerland
*
* Most of this source has been derived from the Linux USB
* project.
*
* See file CREDITS for list of people who contributed to this
* project.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*/
#include "config.h"
#include <stdarg.h>
#include "usb.h"
#undef RESET_START_STOP_CMDS
#undef CONFIG_USB_STORAGE
#if defined(CONFIG_USB_UHCI) || defined(CONFIG_USB_OHCI) || defined(CONFIG_USB_EHCI)
#ifdef CONFIG_USB_STORAGE
extern int usb_stor_curr_dev; /* current device */
#endif
#if defined(COLDFIRE) && defined(NETWORK) && defined(LWIP)
extern long pxCurrentTCB, tid_TOS;
// #define info(format, arg...) do { if(pxCurrentTCB == tid_TOS) kprint(format, ## arg); else board_printf(format, ## arg); } while(0)
#else
#define info(format, arg...) kprint(format, ## arg)
#endif
#if defined(COLDFIRE) && defined(NETWORK) && defined(LWIP)
typedef struct
{
int dest;
void (*func)(char);
char *loc;
} PRINTK_INFO;
#define DEST_CONSOLE (1)
#define DEST_STRING (2)
extern int printk(PRINTK_INFO *info, const char *fmt, va_list ap);
static void info(const char *const fmt, ...)
{
va_list ap;
PRINTK_INFO info;
static char buf[1024];
info.dest = DEST_STRING;
info.loc = buf;
va_start(ap, fmt);
printk(&info, fmt, ap);
*info.loc = '\0';
if(pxCurrentTCB == tid_TOS)
kprint(buf);
else
board_printf(buf);
va_end(ap);
}
#endif /* defined(COLDFIRE) && defined(NETWORK) && defined(LWIP) */
/* some display routines (info command) */
char *usb_get_class_desc(unsigned char dclass)
{
switch (dclass)
{
case USB_CLASS_PER_INTERFACE: return "See Interface";
case USB_CLASS_AUDIO: return "Audio";
case USB_CLASS_COMM: return "Communication";
case USB_CLASS_HID: return "Human Interface";
case USB_CLASS_PRINTER: return "Printer";
case USB_CLASS_MASS_STORAGE: return "Mass Storage";
case USB_CLASS_HUB: return "Hub";
case USB_CLASS_DATA: return "CDC Data";
case USB_CLASS_VENDOR_SPEC: return "Vendor specific";
default: return "";
}
}
void usb_display_class_sub(unsigned char dclass, unsigned char subclass, unsigned char proto)
{
switch(dclass)
{
case USB_CLASS_PER_INTERFACE:
info("See Interface");
break;
case USB_CLASS_HID:
info("Human Interface, Subclass: ");
switch(subclass)
{
case USB_SUB_HID_NONE: info("None"); break;
case USB_SUB_HID_BOOT:
info("Boot ");
switch(proto)
{
case USB_PROT_HID_NONE: info("None"); break;
case USB_PROT_HID_KEYBOARD: info("Keyboard"); break;
case USB_PROT_HID_MOUSE: info("Mouse"); break;
default: info("reserved"); break;
}
break;
default: info("reserved"); break;
}
break;
case USB_CLASS_MASS_STORAGE:
info("Mass Storage, ");
switch(subclass)
{
case US_SC_RBC: info("RBC "); break;
case US_SC_8020: info("SFF-8020i (ATAPI)"); break;
case US_SC_QIC: info("QIC-157 (Tape)"); break;
case US_SC_UFI: info("UFI"); break;
case US_SC_8070: info("SFF-8070"); break;
case US_SC_SCSI: info("Transp. SCSI"); break;
default: info("reserved"); break;
}
info(", ");
switch (proto)
{
case US_PR_CB: info("Command/Bulk"); break;
case US_PR_CBI: info("Command/Bulk/Int"); break;
case US_PR_BULK: info("Bulk only"); break;
default: info("reserved"); break;
}
break;
default: info("%s", usb_get_class_desc(dclass)); break;
}
}
void usb_display_string(struct usb_device *dev, int index)
{
char buffer[256];
if(index != 0)
{
if(usb_string(dev, index, &buffer[0], 256) > 0)
info("String: \"%s\"", buffer);
}
}
void usb_display_desc(struct usb_device *dev)
{
if(dev->descriptor.bDescriptorType == USB_DT_DEVICE)
{
info("%d: %s, USB Revision %x.%x\r\n", dev->devnum, usb_get_class_desc(dev->config.if_desc[0].bInterfaceClass), (dev->descriptor.bcdUSB>>8) & 0xff, dev->descriptor.bcdUSB & 0xff);
if(strlen(dev->mf) || strlen(dev->prod) || strlen(dev->serial))
info(" - %s %s %s\r\n", dev->mf, dev->prod, dev->serial);
if(dev->descriptor.bDeviceClass)
{
info(" - Class: ");
usb_display_class_sub(dev->descriptor.bDeviceClass, dev->descriptor.bDeviceSubClass, dev->descriptor.bDeviceProtocol);
info("\r\n");
}
else
info(" - Class: (from Interface) %s\r\n", usb_get_class_desc(dev->config.if_desc[0].bInterfaceClass));
info(" - PacketSize: %d Configurations: %d\r\n",
dev->descriptor.bMaxPacketSize0,
dev->descriptor.bNumConfigurations);
info(" - Vendor: 0x%04x Product 0x%04x Version %d.%d\r\n", dev->descriptor.idVendor, dev->descriptor.idProduct, (dev->descriptor.bcdDevice>>8) & 0xff, dev->descriptor.bcdDevice & 0xff);
}
}
void usb_display_conf_desc(struct usb_config_descriptor *config, struct usb_device *dev)
{
info(" Configuration: %d\r\n", config->bConfigurationValue);
info(" - Interfaces: %d %s%s%dmA\r\n", config->bNumInterfaces, (config->bmAttributes & 0x40) ? "Self Powered " : "Bus Powered ", (config->bmAttributes & 0x20) ? "Remote Wakeup " : "", config->MaxPower*2);
if(config->iConfiguration)
{
info(" - ");
usb_display_string(dev, config->iConfiguration);
info("\r\n");
}
}
void usb_display_if_desc(struct usb_interface_descriptor *ifdesc, struct usb_device *dev)
{
info(" Interface: %d\r\n", ifdesc->bInterfaceNumber);
info(" - Alternate Setting %d, Endpoints: %d\r\n", ifdesc->bAlternateSetting, ifdesc->bNumEndpoints);
info(" - Class ");
usb_display_class_sub(ifdesc->bInterfaceClass, ifdesc->bInterfaceSubClass, ifdesc->bInterfaceProtocol);
info("\r\n");
if(ifdesc->iInterface)
{
info(" - ");
usb_display_string(dev, ifdesc->iInterface);
info("\r\n");
}
}
void usb_display_ep_desc(struct usb_endpoint_descriptor *epdesc)
{
info(" - Endpoint %d %s ", epdesc->bEndpointAddress & 0xf, (epdesc->bEndpointAddress & 0x80) ? "In" : "Out");
switch((epdesc->bmAttributes & 0x03))
{
case 0: info("Control"); break;
case 1: info("Isochronous"); break;
case 2: info("Bulk"); break;
case 3: info("Interrupt"); break;
}
info(" MaxPacket %d", epdesc->wMaxPacketSize);
if((epdesc->bmAttributes & 0x03) == 0x3)
info(" Interval %dms", epdesc->bInterval);
info("\r\n");
}
/* main routine to diasplay the configs, interfaces and endpoints */
void usb_display_config(struct usb_device *dev)
{
struct usb_config_descriptor *config;
struct usb_interface_descriptor *ifdesc;
struct usb_endpoint_descriptor *epdesc;
int i, ii;
config = &dev->config;
usb_display_conf_desc(config, dev);
for(i = 0; i < config->no_of_if; i++)
{
ifdesc = &config->if_desc[i];
usb_display_if_desc(ifdesc, dev);
for(ii = 0; ii < ifdesc->no_of_ep; ii++)
{
epdesc = &ifdesc->ep_desc[ii];
usb_display_ep_desc(epdesc);
}
}
info("\r\n");
}
static inline char *portspeed(int speed)
{
if(speed == USB_SPEED_HIGH)
return "480 Mb/s";
else if(speed == USB_SPEED_LOW)
return "1.5 Mb/s";
else
return "12 Mb/s";
}
/* shows the device tree recursively */
void usb_show_tree_graph(struct usb_device *dev, char *pre)
{
int i, index;
int has_child, last_child, port;
index = strlen(pre);
info(" %s", pre);
/* check if the device has connected children */
has_child = 0;
for(i = 0; i < dev->maxchild; i++)
{
if(dev->children[i] != NULL)
has_child = 1;
}
/* check if we are the last one */
last_child = 1;
if(dev->parent != NULL)
{
for(i = 0; i < dev->parent->maxchild; i++)
{
/* search for children */
if(dev->parent->children[i] == dev)
{
/* found our pointer, see if we have a little sister */
port = i;
while(i++ < dev->parent->maxchild)
{
if(dev->parent->children[i] != NULL)
{
/* found a sister */
last_child = 0;
break;
} /* if */
} /* while */
} /* device found */
} /* for all children of the parent */
info("\b+-");
/* correct last child */
if(last_child)
pre[index-1] = ' ';
} /* if not root hub */
else
info(" ");
info("%d ", dev->devnum);
pre[index++] = ' ';
pre[index++] = has_child ? '|' : ' ';
pre[index] = 0;
info(" %s (%s, %dmA)\r\n", usb_get_class_desc(dev->config.if_desc[0].bInterfaceClass), portspeed(dev->speed), dev->config.MaxPower * 2);
if(strlen(dev->mf) || strlen(dev->prod) || strlen(dev->serial))
info(" %s %s %s %s\r\n", pre, dev->mf, dev->prod, dev->serial);
info(" %s\r\n", pre);
if(dev->maxchild > 0)
{
for(i = 0; i < dev->maxchild; i++)
{
if(dev->children[i] != NULL)
{
usb_show_tree_graph(dev->children[i], pre);
pre[index] = 0;
}
}
}
}
/* main routine for the tree command */
void usb_show_tree(struct usb_device *dev)
{
char preamble[32];
memset(preamble, 0, 32);
usb_show_tree_graph(dev, &preamble[0]);
}
/******************************************************************************
* usb command intepreter
*/
int uif_cmd_usb(int argc, char **argv)
{
int i;
struct usb_device *dev = NULL;
#ifdef CONFIG_USB_STORAGE
block_dev_desc_t *stor_dev;
#endif
#ifdef RESET_START_STOP_CMDS
extern char usb_started;
if((strncmp(argv[1], "reset", 5) == 0) || (strncmp(argv[1], "start", 5) == 0))
{
usb_stop();
info("(Re)start USB...\r\n");
i = usb_init(0, NULL);
#ifdef CONFIG_USB_STORAGE
/* try to recognize storage devices immediately */
if(i >= 0)
usb_stor_curr_dev = usb_stor_scan();
#endif /* CONFIG_USB_STORAGE */
return 0;
}
if(strncmp(argv[1], "stop", 4) == 0)
{
#ifdef CONFIG_USB_KEYBOARD
if(argc == 2)
{
if(usb_kbd_deregister() != 0)
{
info("USB not stopped: usbkbd still using USB\r\n");
return 1;
}
}
else /* forced stop, switch console in to serial */
usb_kbd_deregister();
#endif /* CONFIG_USB_KEYBOARD */
info("stopping USB..\r\n");
usb_stop();
return 0;
}
if(!usb_started)
{
info("USB is stopped. Please issue 'usb start' first.\r\n");
return 1;
}
#endif /* RESET_START_STOP_CMDS */
if(strncmp(argv[1], "tree", 4) == 0)
{
info("\r\nUSB Device Tree:\r\n");
for(i = 0; i < USB_MAX_BUS; i++)
{
struct usb_device *dev = usb_get_dev_index(0, i);
if(dev == NULL)
break;
info(" USB controller %d:\r\n", i);
usb_show_tree(dev);
}
return 0;
}
if(strncmp(argv[1], "inf", 3) == 0)
{
int b, d;
if(argc == 2)
{
for(b = 0; b < USB_MAX_BUS; b++)
{
for(d = 0; d < USB_MAX_DEVICE; d++)
{
dev = usb_get_dev_index(d, b);
if(dev == NULL)
break;
if(!d)
info("USB controller %d:\r\n\n", b);
usb_display_desc(dev);
usb_display_config(dev);
}
}
return 0;
}
else
{
int d;
i = strtoul(argv[2], NULL, 16);
info("config for device %d\r\n", i);
for(d = 0; d < USB_MAX_DEVICE; d++)
{
dev = usb_get_dev_index(d, 0);
if(dev == NULL)
break;
if(dev->devnum == i)
break;
}
if(dev == NULL)
{
info("*** NO Device avaiable ***\r\n");
return 0;
}
else
{
usb_display_desc(dev);
usb_display_config(dev);
}
}
return 0;
}
#ifdef CONFIG_USB_STORAGE
if(strncmp(argv[1], "stor", 4) == 0)
return usb_stor_info();
if(strcmp(argv[1], "read") == 0)
{
if(usb_stor_curr_dev < 0)
{
info("no current device selected\r\n");
return 1;
}
if(argc == 5)
{
unsigned long addr = strtoul(argv[2], NULL, 16);
unsigned long blk = strtoul(argv[3], NULL, 16);
unsigned long cnt = strtoul(argv[4], NULL, 16);
unsigned long n;
info("\r\nUSB read: device %d block # %ld, count %ld ... ", usb_stor_curr_dev, blk, cnt);
stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
n = stor_dev->block_read(usb_stor_curr_dev, blk, cnt, (unsigned long *)addr);
info("%ld blocks read: %s\r\n", n, (n == cnt) ? "OK" : "ERROR");
if(n == cnt)
return 0;
return 1;
}
}
if(strncmp(argv[1], "dev", 3) == 0)
{
if(argc == 3)
{
int dev = (int)strtoul(argv[2], NULL, 10);
info("\r\nUSB device %d: ", dev);
if(dev >= USB_MAX_STOR_DEV)
{
info("unknown device\r\n");
return 1;
}
info("\r\n Device %d: ", dev);
stor_dev = usb_stor_get_dev(dev);
dev_print(stor_dev);
if(stor_dev->type == DEV_TYPE_UNKNOWN)
return 1;
usb_stor_curr_dev = dev;
info("... is now current device\r\n");
return 0;
}
else
{
info("\r\nUSB device %d: ", usb_stor_curr_dev);
stor_dev = usb_stor_get_dev(usb_stor_curr_dev);
dev_print(stor_dev);
if(stor_dev->type == DEV_TYPE_UNKNOWN)
return 1;
return 0;
}
return 0;
}
info(
#ifdef RESET_START_STOP_CMDS
"usb reset - reset (rescan) USB controller\r\n"
"usb stop [f] - stop USB [f]=force stop\r\n"
#endif
"usb tree - show USB device tree\r\n"
"usb info [dev] - show available USB devices\r\n"
"usb storage - show details of USB storage devices\r\n"
"usb dev [dev] - show or set current USB storage device\r\n"
"usb read addr blk# cnt - read `cnt' blocks starting at block `blk#'\r\n"
" to memory address `addr'\r\n");
#else /* !CONFIG_USB_STORAGE */
info(
#ifdef RESET_START_STOP_CMDS
"usb reset - reset (rescan) USB controller\r\n"
"usb stop [f] - stop USB [f]=force stop\r\n"
#endif
"usb tree - show USB device tree\r\n"
"usb info [dev] - show available USB devices\r\n");
#endif /* CONFIG_USB_STORAGE */
return 1;
}
#endif /* CONFIG_USB_UHCI || CONFIG_USB_OHCI || CONFIG_USB_EHCI */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff