tried to fix PCI - sometimes all three USB controllers are detected, sometimes not, sometimes there is even a PCI bus hang

This commit is contained in:
Markus Fröschle
2014-10-03 07:29:42 +00:00
parent b3ef74342e
commit b1c2026746
9 changed files with 5581 additions and 5548 deletions

View File

@@ -32,19 +32,19 @@ NATIVECC=gcc
INCLUDE=-Iinclude INCLUDE=-Iinclude
CFLAGS=-mcpu=5474 \ CFLAGS=-mcpu=5474 \
-Wall \ -Wall \
-g3 \ -g \
-fomit-frame-pointer \ -fomit-frame-pointer \
-ffreestanding \ -ffreestanding \
-fleading-underscore \ -fleading-underscore \
-Wa,--register-prefix-optional -Wa,--register-prefix-optional
CFLAGS_OPTIMIZED = -mcpu=5474 \ CFLAGS_OPTIMIZED = -mcpu=5474 \
-Wall \ -Wall \
-g3 \
-O2 \ -O2 \
-fomit-frame-pointer \ -fomit-frame-pointer \
-ffreestanding \ -ffreestanding \
-fleading-underscore \ -fleading-underscore \
-Wa,--register-prefix-optional -Wa,--register-prefix-optional
LDFLAGS=-g
TRGTDIRS= ./firebee ./m5484lite ./m54455 TRGTDIRS= ./firebee ./m5484lite ./m54455
OBJDIRS=$(patsubst %, %/objs,$(TRGTDIRS)) OBJDIRS=$(patsubst %, %/objs,$(TRGTDIRS))
@@ -271,7 +271,7 @@ endif
$(1)_MAPFILE_RAM=$(1)/$$(basename $$(RAM_EXEC)).map $(1)_MAPFILE_RAM=$(1)/$$(basename $$(RAM_EXEC)).map
$(1)/$$(RAM_EXEC): $(1)/$(LIBBAS) $(LDCSRC) $(1)/$$(RAM_EXEC): $(1)/$(LIBBAS) $(LDCSRC)
$(CPP) $(INCLUDE) -DCOMPILE_RAM -DOBJDIR=$(1)/objs -P -DFORMAT_ELF=$(FORMAT_ELF) -D$$(MACHINE) $(LDCSRC) -o $(1)/$$(LDRFILE) $(CPP) $(INCLUDE) -DCOMPILE_RAM -DOBJDIR=$(1)/objs -P -DFORMAT_ELF=$(FORMAT_ELF) -D$$(MACHINE) $(LDCSRC) -o $(1)/$$(LDRFILE)
$(LD) -g --oformat $$(FORMAT) -Map $$($(1)_MAPFILE_RAM) --cref -T $(1)/$$(LDRFILE) -o $$@ $(LD) $(LDFLAGS) --oformat $$(FORMAT) -Map $$($(1)_MAPFILE_RAM) --cref -T $(1)/$$(LDRFILE) -o $$@
ifeq ($(COMPILE_ELF),Y) ifeq ($(COMPILE_ELF),Y)
$(OBJCOPY) -O srec $$@ $$(basename $$@).s19 $(OBJCOPY) -O srec $$@ $$(basename $$@).s19
else else

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -27,7 +27,7 @@
#error "unknown machine!" #error "unknown machine!"
#endif #endif
#define DBG_DM //#define DBG_DM
#ifdef DBG_DM #ifdef DBG_DM
#define dbg(fmt, args...) xprintf(fmt, ##args) #define dbg(fmt, args...) xprintf(fmt, ##args)
#else #else
@@ -44,10 +44,10 @@ extern uint8_t driver_mem_buffer[DRIVER_MEM_BUFFER_SIZE]; /* defined in linker c
MD MD
{ {
MD *m_link; MD *m_link;
long m_start; long m_start;
long m_length; long m_length;
void *m_own; void *m_own;
}; };
/* MPB - Memory Partition Block */ /* MPB - Memory Partition Block */
@@ -56,9 +56,9 @@ MD
MPB MPB
{ {
MD *mp_mfl; MD *mp_mfl;
MD *mp_mal; MD *mp_mal;
MD *mp_rover; MD *mp_rover;
}; };
#define MAXMD 256 #define MAXMD 256
@@ -68,273 +68,273 @@ static MPB pmd;
static void *xmgetblk(void) static void *xmgetblk(void)
{ {
int i; int i;
for (i = 0; i < MAXMD; i++) for (i = 0; i < MAXMD; i++)
{ {
if (tab_md[i].m_own == NULL) if (tab_md[i].m_own == NULL)
{ {
tab_md[i].m_own = (void*)1L; tab_md[i].m_own = (void*)1L;
return(&tab_md[i]); return(&tab_md[i]);
} }
} }
return NULL; return NULL;
} }
static void xmfreblk(void *m) static void xmfreblk(void *m)
{ {
int i = (int)(((long) m - (long) tab_md) / sizeof(MD)); int i = (int)(((long) m - (long) tab_md) / sizeof(MD));
if ((i > 0) && (i < MAXMD)) if ((i > 0) && (i < MAXMD))
{ {
tab_md[i].m_own = NULL; tab_md[i].m_own = NULL;
} }
} }
static MD *ffit(long amount, MPB *mp) static MD *ffit(long amount, MPB *mp)
{ {
MD *p, *q, *p1; /* free list is composed of MD's */ MD *p, *q, *p1; /* free list is composed of MD's */
int maxflg; int maxflg;
long maxval; long maxval;
if (amount != -1) if (amount != -1)
{ {
amount += 15; /* 16 bytes alignment */ amount += 15; /* 16 bytes alignment */
amount &= 0xFFFFFFF0; amount &= 0xFFFFFFF0;
} }
if ((q = mp->mp_rover) == 0) /* get rotating pointer */ if ((q = mp->mp_rover) == 0) /* get rotating pointer */
{ {
return 0; return 0;
} }
maxval = 0; maxval = 0;
maxflg = ((amount == -1) ? true : false) ; maxflg = ((amount == -1) ? true : false) ;
p = q->m_link; /* start with next MD */ p = q->m_link; /* start with next MD */
do /* search the list for an MD with enough space */ do /* search the list for an MD with enough space */
{ {
if (p == 0) if (p == 0)
{ {
/* at end of list, wrap back to start */ /* at end of list, wrap back to start */
q = (MD *) &mp->mp_mfl; /* q => mfl field */ q = (MD *) &mp->mp_mfl; /* q => mfl field */
p = q->m_link; /* p => 1st MD */ p = q->m_link; /* p => 1st MD */
} }
if ((!maxflg) && (p->m_length >= amount)) if ((!maxflg) && (p->m_length >= amount))
{ {
/* big enough */ /* big enough */
if (p->m_length == amount) if (p->m_length == amount)
{ {
q->m_link = p->m_link; /* take the whole thing */ q->m_link = p->m_link; /* take the whole thing */
} }
else else
{ {
/* /*
* break it up - 1st allocate a new * break it up - 1st allocate a new
* MD to describe the remainder * MD to describe the remainder
*/ */
p1 = xmgetblk(); p1 = xmgetblk();
if (p1 == NULL) if (p1 == NULL)
{ {
return(NULL); return(NULL);
} }
/* init new MD */ /* init new MD */
p1->m_length = p->m_length - amount; p1->m_length = p->m_length - amount;
p1->m_start = p->m_start + amount; p1->m_start = p->m_start + amount;
p1->m_link = p->m_link; p1->m_link = p->m_link;
p->m_length = amount; /* adjust allocated block */ p->m_length = amount; /* adjust allocated block */
q->m_link = p1; q->m_link = p1;
} }
/* link allocate block into allocated list, /* link allocate block into allocated list,
mark owner of block, & adjust rover */ mark owner of block, & adjust rover */
p->m_link = mp->mp_mal; p->m_link = mp->mp_mal;
mp->mp_mal = p; mp->mp_mal = p;
mp->mp_rover = (q == (MD *) &mp->mp_mfl ? q->m_link : q); mp->mp_rover = (q == (MD *) &mp->mp_mfl ? q->m_link : q);
return(p); /* got some */ return(p); /* got some */
} }
else if (p->m_length > maxval) else if (p->m_length > maxval)
maxval = p->m_length; maxval = p->m_length;
p = ( q=p )->m_link; p = ( q=p )->m_link;
} while(q != mp->mp_rover); } while(q != mp->mp_rover);
/* /*
* return either the max, or 0 (error) * return either the max, or 0 (error)
*/ */
if (maxflg) if (maxflg)
{ {
maxval -= 15; /* 16 bytes alignment */ maxval -= 15; /* 16 bytes alignment */
if (maxval < 0) if (maxval < 0)
{ {
maxval = 0; maxval = 0;
} }
else else
{ {
maxval &= 0xFFFFFFF0; maxval &= 0xFFFFFFF0;
} }
} }
return(maxflg ? (MD *) maxval : 0); return(maxflg ? (MD *) maxval : 0);
} }
static void freeit(MD *m, MPB *mp) static void freeit(MD *m, MPB *mp)
{ {
MD *p, *q; MD *p, *q;
q = 0; q = 0;
for (p = mp->mp_mfl; p ; p = (q = p) -> m_link) for (p = mp->mp_mfl; p ; p = (q = p) -> m_link)
{ {
if (m->m_start <= p->m_start) if (m->m_start <= p->m_start)
{ {
break; break;
} }
} }
m->m_link = p; m->m_link = p;
if (q) if (q)
{ {
q->m_link = m; q->m_link = m;
} }
else else
{ {
mp->mp_mfl = m; mp->mp_mfl = m;
} }
if (!mp->mp_rover) if (!mp->mp_rover)
{ {
mp->mp_rover = m; mp->mp_rover = m;
} }
if (p) if (p)
{ {
if (m->m_start + m->m_length == p->m_start) if (m->m_start + m->m_length == p->m_start)
{ {
/* join to higher neighbor */ /* join to higher neighbor */
m->m_length += p->m_length; m->m_length += p->m_length;
m->m_link = p->m_link; m->m_link = p->m_link;
if (p == mp->mp_rover) if (p == mp->mp_rover)
{ {
mp->mp_rover = m; mp->mp_rover = m;
} }
xmfreblk(p); xmfreblk(p);
} }
} }
if (q) if (q)
{ {
if (q->m_start + q->m_length == m->m_start) if (q->m_start + q->m_length == m->m_start)
{ {
/* join to lower neighbor */ /* join to lower neighbor */
q->m_length += m->m_length; q->m_length += m->m_length;
q->m_link = m->m_link; q->m_link = m->m_link;
if (m == mp->mp_rover) if (m == mp->mp_rover)
{ {
mp->mp_rover = q; mp->mp_rover = q;
} }
xmfreblk(m); xmfreblk(m);
} }
} }
} }
int32_t driver_mem_free(void *addr) int32_t driver_mem_free(void *addr)
{ {
int level; int level;
MD *p, **q; MD *p, **q;
MPB *mpb; MPB *mpb;
mpb = &pmd; mpb = &pmd;
level = set_ipl(7); level = set_ipl(7);
for(p = *(q = &mpb->mp_mal); p; p = *(q = &p->m_link)) for(p = *(q = &mpb->mp_mal); p; p = *(q = &p->m_link))
{ {
if ((long) addr == p->m_start) if ((long) addr == p->m_start)
{ {
break; break;
} }
} }
if (!p) if (!p)
{ {
set_ipl(level); set_ipl(level);
return(-1); return(-1);
} }
*q = p->m_link; *q = p->m_link;
freeit(p, mpb); freeit(p, mpb);
set_ipl(level); set_ipl(level);
dbg("%s: driver_mem_free(0x%08X)\r\n", __FUNCTION__, addr); dbg("%s: driver_mem_free(0x%08X)\r\n", __FUNCTION__, addr);
return(0); return(0);
} }
void *driver_mem_alloc(uint32_t amount) void *driver_mem_alloc(uint32_t amount)
{ {
void *ret = NULL; void *ret = NULL;
int level; int level;
MD *m; MD *m;
if (amount == -1L) if (amount == -1L)
{ {
return (void *) ffit(-1L, &pmd); return (void *) ffit(-1L, &pmd);
} }
if (amount <= 0 ) if (amount <= 0 )
{ {
return(0); return(0);
} }
if ((amount & 1)) if ((amount & 1))
{ {
amount++; amount++;
} }
level = set_ipl(7); level = set_ipl(7);
m = ffit(amount, &pmd); m = ffit(amount, &pmd);
if (m != NULL) if (m != NULL)
{ {
ret = (void *) m->m_start; ret = (void *) m->m_start;
} }
set_ipl(level); set_ipl(level);
dbg("%s: driver_mem_alloc(%d) = 0x%08X\r\n", __FUNCTION__, amount, ret); dbg("%s: driver_mem_alloc(%d) = 0x%08X\r\n", __FUNCTION__, amount, ret);
return ret; return ret;
} }
static int use_count = 0; static int use_count = 0;
int driver_mem_init(void) int driver_mem_init(void)
{ {
if (use_count == 0) if (use_count == 0)
{ {
dbg("%s: initialise driver_mem_buffer[] at %p, size 0x%x\r\n", __FUNCTION__, driver_mem_buffer, DRIVER_MEM_BUFFER_SIZE); dbg("%s: initialise driver_mem_buffer[] at %p, size 0x%x\r\n", __FUNCTION__, driver_mem_buffer, DRIVER_MEM_BUFFER_SIZE);
memset(driver_mem_buffer, 0, DRIVER_MEM_BUFFER_SIZE); memset(driver_mem_buffer, 0, DRIVER_MEM_BUFFER_SIZE);
pmd.mp_mfl = pmd.mp_rover = &tab_md[0]; pmd.mp_mfl = pmd.mp_rover = &tab_md[0];
tab_md[0].m_link = (MD *) NULL; tab_md[0].m_link = (MD *) NULL;
tab_md[0].m_start = ((long) driver_mem_buffer + 15) & ~15; tab_md[0].m_start = ((long) driver_mem_buffer + 15) & ~15;
tab_md[0].m_length = DRIVER_MEM_BUFFER_SIZE; tab_md[0].m_length = DRIVER_MEM_BUFFER_SIZE;
tab_md[0].m_own = (void *) 1L; tab_md[0].m_own = (void *) 1L;
pmd.mp_mal = (MD *) NULL; pmd.mp_mal = (MD *) NULL;
memset(driver_mem_buffer, 0, tab_md[0].m_length); memset(driver_mem_buffer, 0, tab_md[0].m_length);
dbg("%s: uncached driver memory buffer at 0x%08X size %d\r\n", __FUNCTION__, tab_md[0].m_start, tab_md[0].m_length); dbg("%s: uncached driver memory buffer at 0x%08X size %d\r\n", __FUNCTION__, tab_md[0].m_start, tab_md[0].m_length);
} }
use_count++; use_count++;
dbg("%s: driver_mem now has a use count of %d\r\n", __FUNCTION__, use_count); dbg("%s: driver_mem now has a use count of %d\r\n", __FUNCTION__, use_count);
return 0; return 0;
} }
void driver_mem_release(void) void driver_mem_release(void)
{ {
if (use_count-- == 0) if (use_count-- == 0)
{ {
#ifndef CONFIG_USB_MEM_NO_CACHE #ifndef CONFIG_USB_MEM_NO_CACHE
#ifdef USE_RADEON_MEMORY #ifdef USE_RADEON_MEMORY
if (driver_mem_buffer == (void *) offscren_reserved()) if (driver_mem_buffer == (void *) offscren_reserved())
return; return;
#endif #endif
#endif #endif
} }
dbg("%s: driver_mem use count now %d\r\n", __FUNCTION__, use_count); dbg("%s: driver_mem use count now %d\r\n", __FUNCTION__, use_count);
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -26,7 +26,7 @@
#include "exceptions.h" #include "exceptions.h"
#include "driver_mem.h" #include "driver_mem.h"
//#define DEBUG_USBMOUSE #define DEBUG_USBMOUSE
#ifdef DEBUG_USBMOUSE #ifdef DEBUG_USBMOUSE
#define dbg(format, arg...) do { xprintf("DEBUG: %s(): " format, __FUNCTION__, ##arg); } while (0) #define dbg(format, arg...) do { xprintf("DEBUG: %s(): " format, __FUNCTION__, ##arg); } while (0)
#else #else
@@ -48,65 +48,67 @@ static int usb_mouse_probe(struct usb_device *dev, unsigned int ifnum);
/* deregistering the mouse */ /* deregistering the mouse */
int usb_mouse_deregister(struct usb_device *dev) int usb_mouse_deregister(struct usb_device *dev)
{ {
dev->irq_handle = NULL; dev->irq_handle = NULL;
if (new != NULL) if (new != NULL)
{ {
driver_mem_free(new); driver_mem_free(new);
new = NULL; new = NULL;
} }
mouse_installed = 0; mouse_installed = 0;
dbg("USB MOUSE deregister\r\n"); dbg("USB MOUSE deregister\r\n");
return 1; return 1;
} }
/* registering the mouse */ /* registering the mouse */
int usb_mouse_register(struct usb_device *dev) int usb_mouse_register(struct usb_device *dev)
{ {
if (!mouse_installed && (dev->devnum != -1) && (usb_mouse_probe(dev, 0) == 1)) if (!mouse_installed && (dev->devnum != -1) && (usb_mouse_probe(dev, 0) == 1))
{ {
/* Ok, we found a mouse */ /* Ok, we found a mouse */
dbg("USB MOUSE found (USB: %d, devnum: %d)\r\n", dev->usbnum, dev->devnum); dbg("USB MOUSE found (USB: %d, devnum: %d)\r\n", dev->usbnum, dev->devnum);
mouse_installed = 1; mouse_installed = 1;
dev->deregister = usb_mouse_deregister; dev->deregister = usb_mouse_deregister;
return 1; return 1;
} }
/* no USB Mouse found */ /* no USB Mouse found */
return -1; return -1;
} }
/* search for mouse and register it if found */ /* search for mouse and register it if found */
int drv_usb_mouse_init(void) int drv_usb_mouse_init(void)
{ {
int i; int i;
int j; int j;
/* /*
* check if mouse is already initialized * check if mouse is already initialized
*/ */
if (mouse_installed) if (mouse_installed)
{ {
xprintf("USB mouse already initialized\r\n"); xprintf("USB mouse already initialized\r\n");
return -1; return -1;
} }
/* scan all USB Devices */ /* scan all USB Devices */
for (j = 0; j < USB_MAX_BUS; j++) for (j = 0; j < USB_MAX_BUS; j++)
{ {
for (i = 0; i < USB_MAX_DEVICE; i++) for (i = 0; i < USB_MAX_DEVICE; i++)
{ {
struct usb_device *dev = usb_get_dev_index(i, j); /* get device */ struct usb_device *dev = usb_get_dev_index(i, j); /* get device */
if (dev == NULL) if (dev == NULL)
break; {
break;
}
xprintf("Try to register usb device %d,%d as mouse\r\n", i, j); xprintf("Try to register usb device %d,%d as mouse\r\n", i, j);
if (usb_mouse_register(dev) > 0) if (usb_mouse_register(dev) > 0)
return 1; return 1;
} }
} }
/* no USB Mouse found */ /* no USB Mouse found */
return -1; return -1;
} }
/************************************************************************** /**************************************************************************
@@ -114,184 +116,184 @@ int drv_usb_mouse_init(void)
*/ */
static void usb_kbd_send_code(unsigned char code) static void usb_kbd_send_code(unsigned char code)
{ {
dbg("FIXME: usb_kbd_send_code 0x%x not implemented\r\n", code); dbg("FIXME: usb_kbd_send_code 0x%x not implemented\r\n", code);
} }
/* Interrupt service routine */ /* Interrupt service routine */
static int usb_mouse_irq(struct usb_device *dev) static int usb_mouse_irq(struct usb_device *dev)
{ {
#ifdef CONFIG_USB_INTERRUPT_POLLING #ifdef CONFIG_USB_INTERRUPT_POLLING
int level; int level;
#endif #endif
int i, change = 0; int i, change = 0;
if ((dev->irq_status != 0) || (dev->irq_act_len < 3) || (dev->irq_act_len > 8)) if ((dev->irq_status != 0) || (dev->irq_act_len < 3) || (dev->irq_act_len > 8))
{ {
dbg("USB MOUSE error %lX, len %d\r\n", dev->irq_status, dev->irq_act_len); dbg("USB MOUSE error %lX, len %d\r\n", dev->irq_status, dev->irq_act_len);
return 1; return 1;
} }
for (i = 0; i < dev->irq_act_len; i++) for (i = 0; i < dev->irq_act_len; i++)
{ {
if (new[i] != old[i]) if (new[i] != old[i])
{ {
change = 1; change = 1;
break; break;
} }
} }
if (change) if (change)
{ {
char wheel = 0, buttons, old_buttons; char wheel = 0, buttons, old_buttons;
dbg("USB MOUSE len:%d %02X %02X %02X %02X %02X %02X\r\n", dev->irq_act_len, new[0], new[1], new[2], new[3], new[4], new[5]); dbg("USB MOUSE len:%d %02X %02X %02X %02X %02X %02X\r\n", dev->irq_act_len, new[0], new[1], new[2], new[3], new[4], new[5]);
#ifdef CONFIG_USB_INTERRUPT_POLLING #ifdef CONFIG_USB_INTERRUPT_POLLING
level = set_ipl(7); /* mask interrupts */ level = set_ipl(7); /* mask interrupts */
#endif #endif
if ((dev->irq_act_len >= 6) && (new[0] == 1)) /* report-ID */ if ((dev->irq_act_len >= 6) && (new[0] == 1)) /* report-ID */
{ {
buttons = new[1]; buttons = new[1];
old_buttons = old[1]; old_buttons = old[1];
new[0] = ((new[1] & 1) << 1) + ((new[1] & 2) >> 1) + 0xF8; new[0] = ((new[1] & 1) << 1) + ((new[1] & 2) >> 1) + 0xF8;
new[1] = new[2]; new[1] = new[2];
new[2] = new[3]; new[2] = new[3];
wheel = new[4]; wheel = new[4];
} }
else /* boot report */ else /* boot report */
{ {
buttons = new[0]; buttons = new[0];
old_buttons = old[0]; old_buttons = old[0];
new[0] = ((new[0] & 1) << 1) + ((new[0] & 2) >> 1) + 0xF8; new[0] = ((new[0] & 1) << 1) + ((new[0] & 2) >> 1) + 0xF8;
if (dev->irq_act_len >= 3) if (dev->irq_act_len >= 3)
wheel = new[3]; wheel = new[3];
} }
if ((buttons ^ old_buttons) & 4) /* 3rd button */ if ((buttons ^ old_buttons) & 4) /* 3rd button */
{ {
if (buttons & 4) if (buttons & 4)
{ {
usb_kbd_send_code(0x72); /* ENTER */ usb_kbd_send_code(0x72); /* ENTER */
usb_kbd_send_code(0xF2); usb_kbd_send_code(0xF2);
} }
} }
if (wheel != 0) /* actually like Eiffel */ if (wheel != 0) /* actually like Eiffel */
{ {
#define REPEAT_WHEEL 3 #define REPEAT_WHEEL 3
int i; int i;
if (wheel > 0) if (wheel > 0)
{ {
for (i = 0; i < REPEAT_WHEEL; i++) for (i = 0; i < REPEAT_WHEEL; i++)
{ {
usb_kbd_send_code(0x48); /* UP */ usb_kbd_send_code(0x48); /* UP */
usb_kbd_send_code(0xC8); usb_kbd_send_code(0xC8);
} }
} }
else else
{ {
for (i = 0; i < REPEAT_WHEEL; i++) for (i = 0; i < REPEAT_WHEEL; i++)
{ {
usb_kbd_send_code(0x50); /* DOWN */ usb_kbd_send_code(0x50); /* DOWN */
usb_kbd_send_code(0xD0); usb_kbd_send_code(0xD0);
} }
} }
} }
xprintf("FIXME: call_mousevec(new, mousevec) not implemented\r\n"); xprintf("FIXME: call_mousevec(new, mousevec) not implemented\r\n");
//if(mousevec != NULL) //if(mousevec != NULL)
//call_mousevec(new, mousevec); //call_mousevec(new, mousevec);
#ifdef CONFIG_USB_INTERRUPT_POLLING #ifdef CONFIG_USB_INTERRUPT_POLLING
set_ipl(level); set_ipl(level);
#endif #endif
old[0] = new[0]; old[0] = new[0];
old[1] = new[1]; old[1] = new[1];
old[2] = new[2]; old[2] = new[2];
old[3] = new[3]; old[3] = new[3];
old[4] = new[4]; old[4] = new[4];
old[5] = new[5]; old[5] = new[5];
} }
return 1; /* install IRQ Handler again */ return 1; /* install IRQ Handler again */
} }
/* probes the USB device dev for mouse type */ /* probes the USB device dev for mouse type */
static int usb_mouse_probe(struct usb_device *dev, unsigned int ifnum) static int usb_mouse_probe(struct usb_device *dev, unsigned int ifnum)
{ {
struct usb_interface_descriptor *iface; struct usb_interface_descriptor *iface;
struct usb_endpoint_descriptor *ep; struct usb_endpoint_descriptor *ep;
int pipe; int pipe;
int maxp; int maxp;
if (dev->descriptor.bNumConfigurations != 1) if (dev->descriptor.bNumConfigurations != 1)
{ {
dbg("dev->descriptor.bNumConfigurations != 1\r\n"); dbg("dev->descriptor.bNumConfigurations != 1\r\n");
return 0; return 0;
} }
iface = &dev->config.if_desc[ifnum]; iface = &dev->config.if_desc[ifnum];
if (iface->bInterfaceClass != USB_CLASS_HID) if (iface->bInterfaceClass != USB_CLASS_HID)
{ {
dbg("iface->bInterfaceClass != USB_CLASS_HID (%d instead)\r\n", iface->bInterfaceClass); dbg("iface->bInterfaceClass != USB_CLASS_HID (%d instead)\r\n", iface->bInterfaceClass);
return 0; return 0;
} }
if (iface->bInterfaceSubClass != USB_SUB_HID_BOOT) if (iface->bInterfaceSubClass != USB_SUB_HID_BOOT)
{ {
dbg("iface->bInterfaceSubClass != USB_SUB_HID_BOOT (%d instead)\r\n", iface->bInterfaceSubClass); dbg("iface->bInterfaceSubClass != USB_SUB_HID_BOOT (%d instead)\r\n", iface->bInterfaceSubClass);
return 0; return 0;
} }
if (iface->bInterfaceProtocol != USB_PROT_HID_MOUSE) if (iface->bInterfaceProtocol != USB_PROT_HID_MOUSE)
{ {
dbg("iface->bInterfaceProtocol != USB_PROT_HID_MOUSE (%d)\r\n", iface->bInterfaceProtocol); dbg("iface->bInterfaceProtocol != USB_PROT_HID_MOUSE (%d)\r\n", iface->bInterfaceProtocol);
return 0; return 0;
} }
if (iface->bNumEndpoints != 1) if (iface->bNumEndpoints != 1)
{ {
dbg("iface->bNumEndpoints != 1\r\n"); dbg("iface->bNumEndpoints != 1\r\n");
return 0; return 0;
} }
ep = &iface->ep_desc[0]; ep = &iface->ep_desc[0];
if (!(ep->bEndpointAddress & 0x80)) if (!(ep->bEndpointAddress & 0x80))
{ {
dbg("! ep->bEndpointAddress & 0x80\r\n"); dbg("! ep->bEndpointAddress & 0x80\r\n");
return 0; return 0;
} }
if ((ep->bmAttributes & 3) != 3) if ((ep->bmAttributes & 3) != 3)
{ {
dbg("ep->bmAttributes & 3 != 3\r\n"); dbg("ep->bmAttributes & 3 != 3\r\n");
return 0; return 0;
} }
new = (unsigned char *) driver_mem_alloc(8); new = (unsigned char *) driver_mem_alloc(8);
if (new == NULL) if (new == NULL)
{ {
dbg("new == NULL\r\n"); dbg("new == NULL\r\n");
return 0; return 0;
} }
dbg("USB MOUSE found set protocol...\r\n"); dbg("USB MOUSE found set protocol...\r\n");
/* ok, we found a USB Mouse, install it */ /* ok, we found a USB Mouse, install it */
pipe = usb_rcvintpipe(dev, ep->bEndpointAddress); pipe = usb_rcvintpipe(dev, ep->bEndpointAddress);
maxp = usb_maxpacket(dev, pipe); maxp = usb_maxpacket(dev, pipe);
// if(maxp < 6) // if(maxp < 6)
// usb_set_protocol(dev, iface->bInterfaceNumber, 0); /* boot */ // usb_set_protocol(dev, iface->bInterfaceNumber, 0); /* boot */
// else // else
usb_set_protocol(dev, iface->bInterfaceNumber, 1); /* report */ usb_set_protocol(dev, iface->bInterfaceNumber, 1); /* report */
dbg("USB MOUSE found set idle...\r\n"); dbg("USB MOUSE found set idle...\r\n");
usb_set_idle(dev, iface->bInterfaceNumber, 0, 0); /* report infinite */ usb_set_idle(dev, iface->bInterfaceNumber, 0, 0); /* report infinite */
memset(&new[0], 0, 8); memset(&new[0], 0, 8);
memset(&old[0], 0, 8); memset(&old[0], 0, 8);
dev->irq_handle = usb_mouse_irq; dev->irq_handle = usb_mouse_irq;
dbg("USB MOUSE enable interrupt pipe (maxp: %d)...\r\n", maxp); dbg("USB MOUSE enable interrupt pipe (maxp: %d)...\r\n", maxp);
usb_submit_int_msg(dev, pipe, &new[0], maxp > 8 ? 8 : maxp, ep->bInterval); usb_submit_int_msg(dev, pipe, &new[0], maxp > 8 ? 8 : maxp, ep->bInterval);
return 1; return 1;
} }