📄 isp116x-hcd.c
字号:
/* * ISP116x HCD (Host Controller Driver) for u-boot. * * Copyright (C) 2006-2007 Rodolfo Giometti <giometti@linux.it> * Copyright (C) 2006-2007 Eurotech S.p.A. <info@eurotech.it> * * 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 * * * Derived in part from the SL811 HCD driver "u-boot/drivers/sl811_usb.c" * (original copyright message follows): * * (C) Copyright 2004 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * * This code is based on linux driver for sl811hs chip, source at * drivers/usb/host/sl811.c: * * SL811 Host Controller Interface driver for USB. * * Copyright (c) 2003/06, Courage Co., Ltd. * * Based on: * 1.uhci.c by Linus Torvalds, Johannes Erdfelt, Randy Dunlap, * Georg Acher, Deti Fliegl, Thomas Sailer, Roman Weissgaerber, * Adam Richter, Gregory P. Smith; * 2.Original SL811 driver (hc_sl811.o) by Pei Liu <pbl@cypress.com> * 3.Rewrited as sl811.o by Yin Aihua <yinah:couragetech.com.cn> * * [[GNU/GPL disclaimer]] * * and in part from AU1x00 OHCI HCD driver "u-boot/cpu/mips/au1x00_usb_ohci.c" * (original copyright message follows): * * URB OHCI HCD (Host Controller Driver) for USB on the AU1x00. * * (C) Copyright 2003 * Gary Jennejohn, DENX Software Engineering <gj@denx.de> * * [[GNU/GPL disclaimer]] * * Note: Part of this code has been derived from linux */#include <common.h>#ifdef CONFIG_USB_ISP116X_HCD#include <asm/io.h>#include <usb.h>#include <malloc.h>#include <linux/list.h>/* * ISP116x chips require certain delays between accesses to its * registers. The following timing options exist. * * 1. Configure your memory controller (the best) * 2. Use ndelay (easiest, poorest). For that, enable the following macro. * * Value is in microseconds. */#ifdef ISP116X_HCD_USE_UDELAY#define UDELAY 1#endif/* * On some (slowly?) machines an extra delay after data packing into * controller's FIFOs is required, * otherwise you may get the following * error: * * uboot> usb start * (Re)start USB... * USB: scanning bus for devices... isp116x: isp116x_submit_job: CTL:TIMEOUT * isp116x: isp116x_submit_job: ****** FIFO not ready! ****** * * USB device not responding, giving up (status=4) * isp116x: isp116x_submit_job: ****** FIFO not empty! ****** * isp116x: isp116x_submit_job: ****** FIFO not empty! ****** * isp116x: isp116x_submit_job: ****** FIFO not empty! ****** * 3 USB Device(s) found * scanning bus for storage devices... 0 Storage Device(s) found * * Value is in milliseconds. */#ifdef ISP116X_HCD_USE_EXTRA_DELAY#define EXTRA_DELAY 2#endif/* * Enable the following defines if you wish enable debugging messages. */#undef DEBUG /* enable debugging messages */#undef TRACE /* enable tracing code */#undef VERBOSE /* verbose debugging messages */#include "isp116x.h"#define DRIVER_VERSION "08 Jan 2007"static const char hcd_name[] = "isp116x-hcd";struct isp116x isp116x_dev;struct isp116x_platform_data isp116x_board;static int got_rhsc; /* root hub status change */struct usb_device *devgone; /* device which was disconnected */static int rh_devnum; /* address of Root Hub endpoint *//* ------------------------------------------------------------------------- */#define ALIGN(x,a) (((x)+(a)-1UL)&~((a)-1UL))#define min_t(type,x,y) \ ({ type __x = (x); type __y = (y); __x < __y ? __x : __y; })/* ------------------------------------------------------------------------- */static int isp116x_reset(struct isp116x *isp116x);/* --- Debugging functions ------------------------------------------------- */#define isp116x_show_reg(d, r) { \ if ((r) < 0x20) { \ DBG("%-12s[%02x]: %08x", #r, \ r, isp116x_read_reg32(d, r)); \ } else { \ DBG("%-12s[%02x]: %04x", #r, \ r, isp116x_read_reg16(d, r)); \ } \}#define isp116x_show_regs(d) { \ isp116x_show_reg(d, HCREVISION); \ isp116x_show_reg(d, HCCONTROL); \ isp116x_show_reg(d, HCCMDSTAT); \ isp116x_show_reg(d, HCINTSTAT); \ isp116x_show_reg(d, HCINTENB); \ isp116x_show_reg(d, HCFMINTVL); \ isp116x_show_reg(d, HCFMREM); \ isp116x_show_reg(d, HCFMNUM); \ isp116x_show_reg(d, HCLSTHRESH); \ isp116x_show_reg(d, HCRHDESCA); \ isp116x_show_reg(d, HCRHDESCB); \ isp116x_show_reg(d, HCRHSTATUS); \ isp116x_show_reg(d, HCRHPORT1); \ isp116x_show_reg(d, HCRHPORT2); \ isp116x_show_reg(d, HCHWCFG); \ isp116x_show_reg(d, HCDMACFG); \ isp116x_show_reg(d, HCXFERCTR); \ isp116x_show_reg(d, HCuPINT); \ isp116x_show_reg(d, HCuPINTENB); \ isp116x_show_reg(d, HCCHIPID); \ isp116x_show_reg(d, HCSCRATCH); \ isp116x_show_reg(d, HCITLBUFLEN); \ isp116x_show_reg(d, HCATLBUFLEN); \ isp116x_show_reg(d, HCBUFSTAT); \ isp116x_show_reg(d, HCRDITL0LEN); \ isp116x_show_reg(d, HCRDITL1LEN); \}#if defined(TRACE)static int isp116x_get_current_frame_number(struct usb_device *usb_dev){ struct isp116x *isp116x = &isp116x_dev; return isp116x_read_reg32(isp116x, HCFMNUM);}static void dump_msg(struct usb_device *dev, unsigned long pipe, void *buffer, int len, char *str){#if defined(VERBOSE) int i;#endif DBG("%s URB:[%4x] dev:%2d,ep:%2d-%c,type:%s,len:%d stat:%#lx", str, isp116x_get_current_frame_number(dev), usb_pipedevice(pipe), usb_pipeendpoint(pipe), usb_pipeout(pipe) ? 'O' : 'I', usb_pipetype(pipe) < 2 ? (usb_pipeint(pipe) ? "INTR" : "ISOC") : (usb_pipecontrol(pipe) ? "CTRL" : "BULK"), len, dev->status);#if defined(VERBOSE) if (len > 0 && buffer) { printf(__FILE__ ": data(%d):", len); for (i = 0; i < 16 && i < len; i++) printf(" %02x", ((__u8 *) buffer)[i]); printf("%s\n", i < len ? "..." : ""); }#endif}#define PTD_DIR_STR(ptd) ({char __c; \ switch(PTD_GET_DIR(ptd)){ \ case 0: __c = 's'; break; \ case 1: __c = 'o'; break; \ default: __c = 'i'; break; \ }; __c;})/* Dump PTD info. The code documents the format perfectly, right :)*/static inline void dump_ptd(struct ptd *ptd){#if defined(VERBOSE) int k;#endif DBG("PTD(ext) : cc:%x %d%c%d %d,%d,%d t:%x %x%x%x", PTD_GET_CC(ptd), PTD_GET_FA(ptd), PTD_DIR_STR(ptd), PTD_GET_EP(ptd), PTD_GET_COUNT(ptd), PTD_GET_LEN(ptd), PTD_GET_MPS(ptd), PTD_GET_TOGGLE(ptd), PTD_GET_ACTIVE(ptd), PTD_GET_SPD(ptd), PTD_GET_LAST(ptd));#if defined(VERBOSE) printf("isp116x: %s: PTD(byte): ", __FUNCTION__); for (k = 0; k < sizeof(struct ptd); ++k) printf("%02x ", ((u8 *) ptd)[k]); printf("\n");#endif}static inline void dump_ptd_data(struct ptd *ptd, u8 * buf, int type){#if defined(VERBOSE) int k; if (type == 0 /* 0ut data */ ) { printf("isp116x: %s: out data: ", __FUNCTION__); for (k = 0; k < PTD_GET_LEN(ptd); ++k) printf("%02x ", ((u8 *) buf)[k]); printf("\n"); } if (type == 1 /* 1n data */ ) { printf("isp116x: %s: in data: ", __FUNCTION__); for (k = 0; k < PTD_GET_COUNT(ptd); ++k) printf("%02x ", ((u8 *) buf)[k]); printf("\n"); } if (PTD_GET_LAST(ptd)) DBG("--- last PTD ---");#endif}#else#define dump_msg(dev, pipe, buffer, len, str) do { } while (0)#define dump_pkt(dev, pipe, buffer, len, setup, str, small) do {} while (0)#define dump_ptd(ptd) do {} while (0)#define dump_ptd_data(ptd, buf, type) do {} while (0)#endif/* --- Virtual Root Hub ---------------------------------------------------- *//* Device descriptor */static __u8 root_hub_dev_des[] = { 0x12, /* __u8 bLength; */ 0x01, /* __u8 bDescriptorType; Device */ 0x10, /* __u16 bcdUSB; v1.1 */ 0x01, 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */ 0x00, /* __u8 bDeviceSubClass; */ 0x00, /* __u8 bDeviceProtocol; */ 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */ 0x00, /* __u16 idVendor; */ 0x00, 0x00, /* __u16 idProduct; */ 0x00, 0x00, /* __u16 bcdDevice; */ 0x00, 0x00, /* __u8 iManufacturer; */ 0x01, /* __u8 iProduct; */ 0x00, /* __u8 iSerialNumber; */ 0x01 /* __u8 bNumConfigurations; */};/* Configuration descriptor */static __u8 root_hub_config_des[] = { 0x09, /* __u8 bLength; */ 0x02, /* __u8 bDescriptorType; Configuration */ 0x19, /* __u16 wTotalLength; */ 0x00, 0x01, /* __u8 bNumInterfaces; */ 0x01, /* __u8 bConfigurationValue; */ 0x00, /* __u8 iConfiguration; */ 0x40, /* __u8 bmAttributes; Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup, 4..0: resvd */ 0x00, /* __u8 MaxPower; */ /* interface */ 0x09, /* __u8 if_bLength; */ 0x04, /* __u8 if_bDescriptorType; Interface */ 0x00, /* __u8 if_bInterfaceNumber; */ 0x00, /* __u8 if_bAlternateSetting; */ 0x01, /* __u8 if_bNumEndpoints; */ 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */ 0x00, /* __u8 if_bInterfaceSubClass; */ 0x00, /* __u8 if_bInterfaceProtocol; */ 0x00, /* __u8 if_iInterface; */ /* endpoint */ 0x07, /* __u8 ep_bLength; */ 0x05, /* __u8 ep_bDescriptorType; Endpoint */ 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */ 0x03, /* __u8 ep_bmAttributes; Interrupt */ 0x00, /* __u16 ep_wMaxPacketSize; ((MAX_ROOT_PORTS + 1) / 8 */ 0x02, 0xff /* __u8 ep_bInterval; 255 ms */};static unsigned char root_hub_str_index0[] = { 0x04, /* __u8 bLength; */ 0x03, /* __u8 bDescriptorType; String-descriptor */ 0x09, /* __u8 lang ID */ 0x04, /* __u8 lang ID */};static unsigned char root_hub_str_index1[] = { 0x22, /* __u8 bLength; */ 0x03, /* __u8 bDescriptorType; String-descriptor */ 'I', /* __u8 Unicode */ 0, /* __u8 Unicode */ 'S', /* __u8 Unicode */ 0, /* __u8 Unicode */ 'P', /* __u8 Unicode */ 0, /* __u8 Unicode */ '1', /* __u8 Unicode */ 0, /* __u8 Unicode */ '1', /* __u8 Unicode */ 0, /* __u8 Unicode */ '6', /* __u8 Unicode */ 0, /* __u8 Unicode */ 'x', /* __u8 Unicode */ 0, /* __u8 Unicode */ ' ', /* __u8 Unicode */ 0, /* __u8 Unicode */ 'R', /* __u8 Unicode */ 0, /* __u8 Unicode */ 'o', /* __u8 Unicode */ 0, /* __u8 Unicode */ 'o', /* __u8 Unicode */ 0, /* __u8 Unicode */ 't', /* __u8 Unicode */ 0, /* __u8 Unicode */ ' ', /* __u8 Unicode */ 0, /* __u8 Unicode */ 'H', /* __u8 Unicode */ 0, /* __u8 Unicode */ 'u', /* __u8 Unicode */ 0, /* __u8 Unicode */ 'b', /* __u8 Unicode */ 0, /* __u8 Unicode */};/* * Hub class-specific descriptor is constructed dynamically *//* --- Virtual root hub management functions ------------------------------- */static int rh_check_port_status(struct isp116x *isp116x){ u32 temp, ndp, i; int res; res = -1; temp = isp116x_read_reg32(isp116x, HCRHSTATUS); ndp = (temp & RH_A_NDP); for (i = 0; i < ndp; i++) { temp = isp116x_read_reg32(isp116x, HCRHPORT1 + i); /* check for a device disconnect */ if (((temp & (RH_PS_PESC | RH_PS_CSC)) == (RH_PS_PESC | RH_PS_CSC)) && ((temp & RH_PS_CCS) == 0)) { res = i; break; } } return res;}/* --- HC management functions --------------------------------------------- *//* Write len bytes to fifo, pad till 32-bit boundary */static void write_ptddata_to_fifo(struct isp116x *isp116x, void *buf, int len){ u8 *dp = (u8 *) buf; u16 *dp2 = (u16 *) buf; u16 w; int quot = len % 4; if ((unsigned long)dp2 & 1) { /* not aligned */ for (; len > 1; len -= 2) { w = *dp++; w |= *dp++ << 8; isp116x_raw_write_data16(isp116x, w); } if (len) isp116x_write_data16(isp116x, (u16) * dp); } else { /* aligned */ for (; len > 1; len -= 2) isp116x_raw_write_data16(isp116x, *dp2++); if (len) isp116x_write_data16(isp116x, 0xff & *((u8 *) dp2)); } if (quot == 1 || quot == 2) isp116x_raw_write_data16(isp116x, 0);}/* Read len bytes from fifo and then read till 32-bit boundary */static void read_ptddata_from_fifo(struct isp116x *isp116x, void *buf, int len){ u8 *dp = (u8 *) buf; u16 *dp2 = (u16 *) buf; u16 w; int quot = len % 4; if ((unsigned long)dp2 & 1) { /* not aligned */ for (; len > 1; len -= 2) { w = isp116x_raw_read_data16(isp116x); *dp++ = w & 0xff; *dp++ = (w >> 8) & 0xff; } if (len) *dp = 0xff & isp116x_read_data16(isp116x); } else { /* aligned */ for (; len > 1; len -= 2) *dp2++ = isp116x_raw_read_data16(isp116x); if (len) *(u8 *) dp2 = 0xff & isp116x_read_data16(isp116x); } if (quot == 1 || quot == 2) isp116x_raw_read_data16(isp116x);}/* Write PTD's and data for scheduled transfers into the fifo ram. * Fifo must be empty and ready */static void pack_fifo(struct isp116x *isp116x, struct usb_device *dev, unsigned long pipe, struct ptd *ptd, int n, void *data, int len){ int buflen = n * sizeof(struct ptd) + len; int i, done; DBG("--- pack buffer %p - %d bytes (fifo %d) ---", data, len, buflen); isp116x_write_reg16(isp116x, HCuPINT, HCuPINT_AIIEOT); isp116x_write_reg16(isp116x, HCXFERCTR, buflen); isp116x_write_addr(isp116x, HCATLPORT | ISP116x_WRITE_OFFSET); done = 0; for (i = 0; i < n; i++) { DBG("i=%d - done=%d - len=%d", i, done, PTD_GET_LEN(&ptd[i])); dump_ptd(&ptd[i]); isp116x_write_data16(isp116x, ptd[i].count); isp116x_write_data16(isp116x, ptd[i].mps); isp116x_write_data16(isp116x, ptd[i].len); isp116x_write_data16(isp116x, ptd[i].faddr);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -