diff -ruNpa pehcd/hal/hal_intf.h /home/b/uni/fyp/fyp-svn/DriversM6/usb/pehcd/hal/hal_intf.h
--- pehcd/hal/hal_intf.h	2006-05-19 16:43:49.000000000 +0800
+++ /home/b/uni/fyp/fyp-svn/DriversM6/usb/pehcd/hal/hal_intf.h	2006-09-04 19:26:26.000000000 +0800
@@ -100,7 +100,7 @@ typedef struct _isp1761_id {
 
 typedef struct isp1761_dev {
     /*added for pci device*/
-    struct pci_dev *pcidev;
+    struct device *dev;
     struct  isp1761_driver *driver; /* which driver has allocated this device */
     void            *driver_data;   /* data private to the host controller driver */
     void            *otg_driver_data; /*data private for otg controler*/
@@ -153,7 +153,7 @@ int     phci_enumerate_otg_port(struct i
 
 int     isp1761_register_driver(struct isp1761_driver *drv);
 void    isp1761_unregister_driver(struct isp1761_driver *drv);
-int     isp1761_request_irq(void(*handler)(struct isp1761_dev* dev,void* isr_data),
+int     isp1761_request_irq(void(*handler)(struct isp1761_dev* dev,void* isr_data,struct pt_regs*),
         struct isp1761_dev* dev, void* isr_data);
 void    isp1761_free_irq(struct isp1761_dev* dev,void* isr_data);
 
diff -ruNpa pehcd/hal/hal_pxa.c /home/b/uni/fyp/fyp-svn/DriversM6/usb/pehcd/hal/hal_pxa.c
--- pehcd/hal/hal_pxa.c	1970-01-01 08:00:00.000000000 +0800
+++ /home/b/uni/fyp/fyp-svn/DriversM6/usb/pehcd/hal/hal_pxa.c	2006-09-06 10:36:37.000000000 +0800
@@ -0,0 +1,1012 @@
+/************************************************************
+ * Philips ISP176x Hardware Abstraction Layer code file
+ *
+ * (c) 2002 Koninklijke Philips Electronics N.V. All rights reserved. <usb.linux@philips.com>
+ *
+ * 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
+ *
+ * File Name: hal_x86.c
+ *
+ * Refering linux kernel version 2.6.9
+ *
+ * History:
+ *
+ * Date                Author                  Comments
+ * ---------------------------------------------------------------------
+ * Nov 29 2005        Prabhakar Kalasani      Initial Creation     
+ *
+ **********************************************************************
+ */
+
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/delay.h>
+#include <linux/ioport.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+#include <linux/smp_lock.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/timer.h>
+#include <linux/list.h>
+#include <linux/interrupt.h>  
+#include <linux/usb.h>
+#include <linux/poll.h>
+#include <linux/platform_device.h>
+#include <linux/vmalloc.h>
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/system.h>
+#include <asm/unaligned.h>
+#include <asm/dma.h>
+
+/*--------------------------------------------------------------*
+ *               linux system include files
+ *--------------------------------------------------------------*/
+#include "hal_x86.h" // We can use the x86 headers for now.
+#include "../hal/hal_intf.h"
+#include "../hal/isp1761.h"
+
+/*--------------------------------------------------------------*
+ *               Local variable Definitions
+ *--------------------------------------------------------------*/
+struct isp1761_dev              isp1761_loc_dev[ISP1761_LAST_DEV];
+static  struct isp1761_hal      hal_data;
+static struct platform_device *s_pdev;
+int      iolength = 0;
+static   __u32            isp1761_base = 0;
+
+/*--------------------------------------------------------------*
+ *               Local # Definitions
+ *--------------------------------------------------------------*/
+#define         isp1761_driver_name     "1761-m6"
+#define         ISP1761_IO_EXTENT ((1 << 17)-1) // 17 address bits used.
+#define         ISP1761_REGSET_LEN   0xffff
+
+#undef CONFIG_PM /* PM no workie yet. */
+
+/*--------------------------------------------------------------*
+ *               Local Function 
+ *--------------------------------------------------------------*/
+
+static int __devexit isp1761_remove (struct platform_device *pdev);
+static int __devinit isp1761_probe (struct platform_device *pdev);
+#ifdef CONFIG_PM
+static int isp1761_pci_suspend (struct pci_dev *dev, __u32 state);
+static int isp1761_pci_resume (struct pci_dev *dev);
+#endif
+static irqreturn_t  isp1761_pci_isr (int irq, void *dev_id, struct pt_regs *regs);
+
+
+/*--------------------------------------------------------------*
+ *              ISP 1761 interrupt locking functions
+ *--------------------------------------------------------------*/
+int             isp1761_hw_lock = 0;
+int             isp1761_hw_isr = 0;
+
+void isp1761_disable_interrupt(int      irq) {
+    /* DUMMY functions
+     * Not used */
+    disable_irq(irq);
+    return;
+}
+void isp1761_enable_interrupt(int       irq) {
+    /* DUMMY functions
+     * Not used */
+    enable_irq(irq);
+    return;
+}
+
+/*--------------------------------------------------------------*
+ *               ISP1761 Interrupt Service Routine
+ *--------------------------------------------------------------*/
+/*Interrupt Service Routine for device controller*/
+irqreturn_t isp1761_pci_dc_isr(int irq, void *data, struct pt_regs *r)
+{
+    struct isp1761_dev *dev;
+    dev = &isp1761_loc_dev[ISP1761_DC];
+
+    hal_entry("%s: Entered\n",__FUNCTION__);
+    /*not ready yet*/
+    if(dev->active == 0)
+    {
+        printk("isp1761_pci_dc_isr: dev->active is NULL \n");
+        return IRQ_NONE;
+    }
+
+    /* Get the source of interrupts for Device Controller
+     * Device Controller interrupts are cleared by the driver
+     * during processing
+     */
+
+    /*unblock the device interrupt*/
+
+    isp1761_reg_write32(dev, DEV_UNLOCK_REGISTER, 0xaa37);
+    dev->int_reg = isp1761_reg_read32(dev, DEV_INTERRUPT_REGISTER, dev->int_reg);
+    hal_int("isp1761_pci_dc_isr:INTERRUPT_REGISTER 0x%x\n",dev->int_reg);
+    /*clear the interrupt source*/
+    isp1761_reg_write32(dev, 0x218, dev->int_reg);
+    dev->int_reg &= 0x03fffdb9;
+    if(dev->int_reg)
+        dev->handler(dev, dev->isr_data,r);
+    hal_entry("%s: Exit\n",__FUNCTION__);
+    return IRQ_HANDLED;
+}
+
+/* Interrupt Service Routine of isp1761                                   
+ * Reads the source of interrupt and calls the corresponding driver's ISR.
+ * Before calling the driver's ISR clears the source of interrupt.
+ * The drivers can get the source of interrupt from the dev->int_reg field
+ */
+irqreturn_t     isp1761_pci_isr(int irq, void *__data, struct pt_regs *r) 
+{
+    __u32               irq_mask = 0;
+    struct isp1761_dev  *dev;
+    hal_entry("%s: Entered\n",__FUNCTION__);
+    /* Process the Host Controller Driver */
+    dev = &isp1761_loc_dev[ISP1761_HC];
+    /* Get the source of interrupts for Host Controller*/
+    dev->int_reg = isp1761_reg_read32(dev, HC_INTERRUPT_REG,dev->int_reg);
+    isp1761_reg_write32(dev,HC_INTERRUPT_REG,dev->int_reg);
+    irq_mask = isp1761_reg_read32(dev, HC_INTENABLE_REG,irq_mask);
+
+    dev->int_reg &= irq_mask; /*shared irq ??*/
+    /*call the Host Isr if any valid(minus otg)interrupt is present*/
+    if(dev->int_reg & ~HC_OTG_INTERRUPT)                
+        dev->handler(dev,dev->isr_data,r);
+#ifdef OTG
+#ifndef MSEC_INT_BASED
+    mdelay(1);
+#endif
+    /*process otg interrupt if there is any*/
+    if(dev->int_reg & HC_OTG_INTERRUPT){
+        u32     otg_int;        
+#ifndef MSEC_INT_BASED
+        mdelay(1);
+#endif
+        otg_int = (dev->int_reg & HC_OTG_INTERRUPT);
+        /* Process OTG controller Driver 
+         * Since OTG is part of  HC interrupt register, 
+         * the interrupt source will be HC interrupt Register
+         * */
+        dev = &isp1761_loc_dev[ISP1761_OTG];
+        /* Read the source of  OTG_INT and clear the
+           interrupt source */
+        dev->int_reg = otg_int; 
+        dev->handler(dev, dev->isr_data,r);
+    }   
+#endif
+    hal_entry("%s: Exit\n",__FUNCTION__);
+    return IRQ_HANDLED;
+} /* End of isp1362_pci_isr */
+
+/*--------------------------------------------------------------*
+ *               PCI Driver Interface Functions
+ *--------------------------------------------------------------*/
+
+/* Pci driver interface functions */
+static struct platform_driver isp1761_platform_driver = {
+probe:         isp1761_probe,
+remove:        isp1761_remove,
+driver:        { .name = "isp1761" }
+};
+
+
+/*--------------------------------------------------------------*
+ *               ISP1761 Read write routine 
+ *--------------------------------------------------------------*/
+
+/* Write a 32 bit Register of isp1761 */
+void isp1761_reg_write32(struct isp1761_dev *dev,__u16 reg,__u32 data)
+{ 
+    /* Write the 32bit to the register address given to us*/
+    writel(data,dev->baseaddress+reg);
+    //printk("Wrote to 0x%08x value 0x%08x\n", isp1761_base + reg, data);
+}
+
+
+/* Read a 32 bit Register of isp1761 */
+__u32 isp1761_reg_read32(struct isp1761_dev *dev,__u16 reg,__u32 data)
+{ 
+
+    data = readl(dev->baseaddress + reg);
+    //printk("Read from 0x%08x is 0x%08x\n", isp1761_base + reg, data);
+    return data;
+}
+
+
+/* Read a 16 bit Register of isp1761 */
+__u16 isp1761_reg_read16(struct isp1761_dev *dev,__u16 reg,__u16 data)
+{ 
+    data = readw(dev->baseaddress+reg);
+    return data;
+}
+
+/* Write a 16 bit Register of isp1761 */
+void isp1761_reg_write16(struct isp1761_dev *dev,__u16 reg,__u16 data)
+{ 
+    //printk("Wrote to 0x%08x value 0x%04x\n", isp1761_base + reg, data);
+    writew(data,dev->baseaddress+reg);
+
+}
+
+/*--------------------------------------------------------------*
+ *  
+ * Module dtatils: isp1761_mem_read
+ *
+ * Memory read using PIO method.
+ *
+ *  Input: struct isp1761_driver *drv  -->  Driver structure.
+ *                      __u32 start_add     --> Starting address of memory 
+ *              __u32 end_add     ---> End address 
+ *              
+ *              __u32 * buffer      --> Buffer pointer.
+ *              __u32 length       ---> Length 
+ *              __u16 dir          ---> Direction ( Inc or Dec)
+ *                      
+ *  Output     int Length  ----> Number of bytes read 
+ *
+ *  Called by: system function 
+ * 
+ * 
+ *--------------------------------------------------------------*/
+/* Memory read function PIO */
+
+int     
+isp1761_mem_read(struct isp1761_dev *dev, __u32 start_add, 
+        __u32 end_add, __u32 * buffer, __u32 length, __u16 dir)
+{
+    u8 *temp_base_mem = 0;      
+    u8 *one = (u8 *) buffer;
+    u16 *two = (u16 *) buffer;
+    int a = (int)length;
+    u32 w;
+    temp_base_mem= (dev->baseaddress + start_add);
+    /*initialize the Register 0x33C-used to manage Multiple threads */
+    writel(start_add,dev->baseaddress+0x33c);
+
+last:
+    w = readl(temp_base_mem);
+    if(a == 1){
+        *one=(u8)w;
+        return 0;
+    }
+    if(a == 2){
+        *two=(u16)w;
+        return 0;
+    }   
+
+
+    if(a == 3){
+        *two=(u16)w;
+        two += 1;
+        w >>= 16;
+        *two = (u8)(w);
+        return 0;
+
+    }
+
+
+    while(a>0){
+        *buffer = w;
+        temp_base_mem = temp_base_mem+4;
+        start_add +=4;
+        a -= 4;
+        if(a == 0)
+            break;
+        if(a < 4){
+            buffer += 1;
+            one = (u8 *)buffer;
+            two = (u16 *)buffer;
+            goto last;
+        }
+        buffer += 1;
+        w = readl(temp_base_mem); 
+    }
+    return ((a < 0) || (a == 0))?0:(-1);
+
+}
+
+/*--------------------------------------------------------------*
+ *  
+ * Module dtatils: isp1761_mem_write
+ *
+ * Memory write using PIO method.
+ *
+ *  Input: struct isp1761_driver *drv  -->  Driver structure.
+ *                      __u32 start_add     --> Starting address of memory 
+ *              __u32 end_add     ---> End address 
+ *              
+ *              __u32 * buffer      --> Buffer pointer.
+ *              __u32 length       ---> Length 
+ *              __u16 dir          ---> Direction ( Inc or Dec)
+ *                      
+ *  Output     int Length  ----> Number of bytes read 
+ *
+ *  Called by: system function 
+ * 
+ * 
+ *--------------------------------------------------------------*/
+
+/* Memory read function IO */
+int     
+isp1761_mem_write(struct isp1761_dev *dev, 
+        __u32 start_add, __u32 end_add, 
+        __u32 * buffer, __u32 length,
+        __u16 dir)
+{
+    u8 *temp_base_mem = 0;
+    int a = length;
+    //u8 *temp = (u8*)buffer;
+    u8 one      =(u8 )(*buffer);
+    u16 two     =(u16 )(*buffer);       
+    temp_base_mem = (dev->baseaddress + start_add);
+
+    if(a == 1){
+        writeb(one,temp_base_mem);
+        return 0;
+    }
+    if(a == 2){
+        writew(two,temp_base_mem);
+        return 0;
+    }
+
+    while(a>0){         
+        writel(*buffer, temp_base_mem);
+        temp_base_mem = temp_base_mem+4;
+        start_add +=4;
+        a -=4;
+        if(a <= 0)
+            break;
+        buffer += 1;
+
+    }
+    return ((a < 0) || (a == 0))?0:(-1);
+
+}
+/*--------------------------------------------------------------*
+ *  
+ * Module dtatils: isp1761_check_mem_region
+ *
+ *  Check the memory region for Memory Mapping 
+ *  Check with the system about the availability of the region,
+ *  and returns success, if available.
+ *
+ *  Input: struct isp1761_driver *drv  --> Driver structure.
+ *  
+ *  Output result  
+ *         
+ *
+ *  Called by: system function 
+ * 
+ * 
+ *--------------------------------------------------------------*/
+
+int isp1761_check_mem_region(struct isp1761_dev *dev)
+{
+    int ret;
+    ret=check_mem_region(dev->start, dev->length);
+    return ret;
+}/* End of isp1761_check_mem_region */
+
+/*--------------------------------------------------------------*
+ *  
+ * Module dtatils: isp1761_request_mem_region
+ isp1761_release_mem_region
+ isp1761_get_mem_params
+
+ *
+ *  If the check returns Success, we can request the region for 
+ *  Memory mapping of our chip memory
+ *
+ *  Input: struct isp1761_driver *drv  --> Driver structure.
+ *  
+ *  Output result  
+ *         
+ *
+ *  Called by: system function 
+ * 
+ * 
+ *--------------------------------------------------------------*/
+
+struct resource* isp1761_request_mem_region(struct isp1761_dev *dev)
+{
+    dev->mem_res = request_mem_region(dev->start, dev->length, "Isp1761_device");
+    return dev->mem_res;
+}/* End of isp1761_request_mem_region */
+
+/* Release an already acquired memory region.
+   It should be done at the rmmod of the module */
+void isp1761_release_mem_region(struct isp1761_dev* dev)
+{
+    release_mem_region (dev->start, dev->length);
+}
+
+/* Get the start address and length of Mapped Memory */ 
+void isp1761_get_mem_params(struct isp1761_dev *dev,struct isp1761_driver *drv)
+{
+    dev->start  =isp1761_loc_dev[drv->index].start;
+    dev->length =isp1761_loc_dev[drv->index].length;
+}/* End of isp1761_get_mem_params*/
+
+
+/*--------------------------------------------------------------*
+ *  
+ * Module dtatils: isp1761_request_irq
+ *
+ * This function registers the ISR of driver with this driver.
+ * Since there is only one interrupt line, when the first driver
+ * is registerd, will call the system function request_irq. The PLX
+ * bridge needs enabling of interrupt in the interrupt control register to 
+ * pass the local interrupts to the PCI (cpu).
+ * For later registrations will just update the variables. On ISR, this driver
+ * will look for registered handlers and calls the corresponding driver's
+ * ISR "handler" function with "isr_data" as parameter.
+ *
+ *  Input: struct 
+ *              (void (*handler)(struct isp1761_dev *, void *)-->handler.
+ *               isp1761_driver *drv  --> Driver structure.
+ *  Output result 
+ *         0= complete 
+ *         1= error.
+ *
+ *  Called by: system function module_init 
+ * 
+ * 
+ *--------------------------------------------------------------*/
+
+int isp1761_request_irq(void (*handler)(struct isp1761_dev *, void *, struct pt_regs *),
+        struct isp1761_dev *dev, void *isr_data) 
+{
+    int result = 0;
+    hal_entry("%s: Entered\n",__FUNCTION__);
+    hal_int("isp1761_request_irq: dev->index %x\n",dev->index);
+    if(dev->index == ISP1761_DC){
+        result = request_irq(dev->irq, isp1761_pci_dc_isr,
+                SA_SHIRQ,
+                dev->name,
+                isr_data);
+    }else {
+        result= request_irq(dev->irq,isp1761_pci_isr,
+                SA_SHIRQ,
+                dev->name,
+                isr_data);
+    }
+
+    /*Interrupt handler routine*/
+    dev->handler = handler;
+    dev->isr_data = isr_data;
+    hal_int("isp1761_request_irq: dev->handler %s\n",dev->handler);
+    hal_int("isp1761_request_irq: dev->isr_data %x\n",dev->isr_data);
+    hal_entry("%s: Exit\n",__FUNCTION__);
+    return result;
+} /* End of isp1761_request_irq */
+
+/*--------------------------------------------------------------*
+ *  
+ * Module dtatils: isp1761_free_irq
+ *
+ * This function de-registers the ISR of driver with this driver.
+ * Since there is only one interrupt line, when the last driver
+ * is de-registerd, will call the system function free_irq. The PLX
+ * bridge needs disabling of interrupt in the interrupt control register to 
+ * block the local interrupts to the PCI (cpu).
+ *
+ *  Input: struct 
+ *              (void (*handler)(struct isp1761_dev *, void *)-->handler.
+ *               isp1761_driver *drv  --> Driver structure.
+ *  Output result 
+ *         0= complete 
+ *         1= error.
+ *
+ *  Called by: system function module_init 
+ * 
+ * 
+ *--------------------------------------------------------------*/
+
+void isp1761_free_irq(struct isp1761_dev *dev, void *isr_data)
+{
+    hal_int(("isp1761_free_irq(dev=%p,isr_data=%p)\n",dev,isr_data));
+    free_irq(dev->irq,isr_data);
+} /* isp1761_free_irq */
+
+
+
+/* Allocate Fragmented kernel Memory */
+void* isp_1761_kmalloc(size_t size,int flags)
+{
+    void* ret;
+    ret =kmalloc(size,flags);
+    return ret;
+}
+
+/* Free the memory allocated by kmalloc */
+void isp_1761_kfree(const void* objp)
+{
+    kfree(objp);
+}
+
+/* Allocate Contiguous kernel Memory */
+void* isp_1761_vmalloc(__u32 size, __u16 flags, pgprot_t prot)
+{
+    void* ret;
+    ret = __vmalloc(size, flags, prot);
+    return ret;
+}
+
+/* Free the memory allocated by vmalloc */
+void isp_1761_vfree(const void* objp)
+{
+    kfree(objp);
+}
+
+
+
+/*--------------------------------------------------------------*
+ *  
+ * Module dtatils: isp1761_register_driver
+ *
+ * This function is used by top driver (OTG, HCD, DCD) to register
+ * their communication functions (probe, remove, suspend, resume) using
+ * the drv data structure.
+ * This function will call the probe function of the driver if the ISP1761
+ * corresponding to the driver is enabled
+ *
+ *  Input: struct isp1761_driver *drv  --> Driver structure.
+ *  Output result 
+ *         0= complete 
+ *         1= error.
+ *
+ *  Called by: system function module_init 
+ * 
+ * 
+ *--------------------------------------------------------------*/
+
+int     isp1761_register_driver(struct isp1761_driver *drv) 
+{
+    struct isp1761_dev  *dev;
+    int result;
+    isp1761_id *id;
+
+    hal_entry("%s: Entered\n",__FUNCTION__);
+    info("isp1761_register_driver(drv=%p) \n",drv);
+
+    if(!drv) return -EINVAL;
+    dev = &isp1761_loc_dev[drv->index];
+    if(drv->index == ISP1761_DC){/*FIX for device*/
+        result = drv->probe(dev,drv->id);
+    }else{              
+        id = drv->id;
+        if(dev->active) result = drv->probe(dev,id);
+        else    result = -ENODEV;
+    }
+
+    if(result >= 0 ) {
+        printk(KERN_INFO __FILE__ ": Registered Driver %s\n",
+                drv->name);
+        dev->driver = drv;
+    }
+    hal_entry("%s: Exit\n",__FUNCTION__);
+    return result;
+} /* End of isp1761_register_driver */
+
+
+/*--------------------------------------------------------------*
+ *  
+ * Module dtatils: isp1761_unregister_driver
+ *
+ * This function is used by top driver (OTG, HCD, DCD) to de-register
+ * their communication functions (probe, remove, suspend, resume) using
+ * the drv data structure.
+ * This function will check whether the driver is registered or not and
+ * call the remove function of the driver if registered
+ *
+ *  Input: struct isp1761_driver *drv  --> Driver structure.
+ *  Output result 
+ *         0= complete 
+ *         1= error.
+ *
+ *  Called by: system function module_init 
+ * 
+ * 
+ *--------------------------------------------------------------*/
+
+
+void    isp1761_unregister_driver(struct isp1761_driver *drv)
+{
+    struct isp1761_dev  *dev;
+    hal_entry("%s: Entered\n",__FUNCTION__);
+
+    info("isp1761_unregister_driver(drv=%p)\n",drv);
+    dev = &isp1761_loc_dev[drv->index];
+    if(dev->driver == drv) {
+        /* driver registered is same as the requestig driver */
+        drv->remove(dev);
+        dev->driver = NULL;
+        info(": De-registered Driver %s\n",
+                drv->name);
+        return;
+    }
+    hal_entry("%s: Exit\n",__FUNCTION__);
+} /* End of isp1761_unregister_driver */
+
+
+/*--------------------------------------------------------------*
+ *               ISP1761 PCI driver interface routine.
+ *--------------------------------------------------------------*/
+
+
+/*--------------------------------------------------------------*
+ *
+ *  Module dtatils: isp1761_module_init
+ *
+ *  This  is the module initialization function. It registers to 
+ *  PCI driver for a PLX PCI bridge device. And also resets the
+ *  internal data structures before registering to PCI driver.
+ *
+ *  Input: void 
+ *  Output result 
+ *         0= complete 
+ *         1= error.
+ *
+ *  Called by: system function module_init 
+ * 
+ * 
+ * 
+ -------------------------------------------------------------------*/
+static int __init isp1761_module_init (void) 
+{
+    int result = 0;
+    hal_entry("%s: Entered\n",__FUNCTION__);
+
+    memset(isp1761_loc_dev,0,sizeof(isp1761_loc_dev));
+
+    result = platform_driver_register(&isp1761_platform_driver);
+
+    hal_entry("%s: Exit\n",__FUNCTION__);
+    return result;
+}
+
+/*--------------------------------------------------------------*
+ *
+ *  Module dtatils: isp1761_module_cleanup
+ *
+ * This  is the module cleanup function. It de-registers from 
+ * PCI driver and resets the internal data structures.
+ *
+ *  Input: void 
+ *  Output void
+ *
+ *  Called by: system function module_cleanup 
+ * 
+ * 
+ * 
+ --------------------------------------------------------------*/
+
+static void __exit isp1761_module_cleanup (void) 
+{
+    printk("Hal Module Cleanup\n");
+    platform_driver_unregister(&isp1761_platform_driver);
+    memset(isp1761_loc_dev,0,sizeof(isp1761_loc_dev));
+} 
+
+
+/*--------------------------------------------------------------*
+ *
+ *  Module dtatils: isp1761_probe
+ *
+ * PCI probe function of ISP1761
+ * This function is called from PCI Driver as an initialization function
+ * when it founds the PCI device. This functions initializes the information
+ * for the 3 Controllers with the assigned resources and tests the register
+ * access to these controllers and do a software reset and makes them ready
+ * for the drivers to play with them.
+ *
+ *  Input: 
+ *              struct pci_dev *dev                     ----> PCI Devie data structure 
+ *      const struct pci_device_id *id  ----> PCI Device ID 
+ *  Output void
+ *
+ *  Called by: system function module_cleanup 
+ * 
+ * 
+ * 
+ --------------------------------------------------------------**/
+
+    static int __devinit
+isp1761_probe (struct platform_device *pdev)
+{
+    __u32       reg_data = 0;
+    struct isp1761_dev  *loc_dev;
+    struct resource *res;
+    void *address = 0;
+    int length = ISP1761_IO_EXTENT;
+    int status = 0;
+    hal_entry("%s: Entered\n",__FUNCTION__);
+
+    res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "isp1761-regs");
+    if (!res)
+	    res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+    if (!res)
+	    return -ENODEV;
+
+    isp1761_base = res->start;
+    hal_init(("isp1761 pci base address = %x\n", isp1761_base));
+
+    /* Get the Host Controller IO and INT resources
+     */
+    loc_dev = &(isp1761_loc_dev[ISP1761_HC]);
+    loc_dev->dev = &pdev->dev;
+    loc_dev->irq = platform_get_irq(pdev, 0);
+    loc_dev->io_base = isp1761_base;
+    loc_dev->start   =  isp1761_base;
+    loc_dev->length  = ISP1761_REGSET_LEN;
+    loc_dev->io_len = ISP1761_REGSET_LEN; /*64K*/
+    loc_dev->index = ISP1761_HC;/*zero*/
+
+    loc_dev->io_len = length; 
+    if(check_mem_region(loc_dev->io_base,length)<0){
+        err("host controller already in use\n");
+        return -EBUSY;
+    }
+    if(!request_mem_region(loc_dev->io_base, length,isp1761_driver_name)){
+        err("host controller already in use\n");
+        return -EBUSY;
+
+    }
+
+    /*map available memory*/
+    address = ioremap_nocache(isp1761_base,length);
+    if(address == NULL){
+        err("memory map problem\n");
+        release_mem_region(loc_dev->io_base,length);
+        return -ENOMEM;
+    } 
+
+    loc_dev->baseaddress = (u8*)address;
+    //loc_dev->dmabase = (u8*)iobase;
+
+    hal_init(("isp1761 HC MEM Base= %p irq = %d\n", 
+                loc_dev->baseaddress,loc_dev->irq));
+#ifdef ISP1761_DEVICE   
+
+    /*initialize device controller framework*/  
+    loc_dev = &(isp1761_loc_dev[ISP1761_DC]);
+    loc_dev->dev = &pdev->dev;
+    loc_dev->irq = platform_get_irq(pdev, 0);
+    loc_dev->io_base = isp1761_base;
+    loc_dev->start   = isp1761_base;
+    loc_dev->length  = ISP1761_REGSET_LEN;
+    loc_dev->io_len = ISP1761_REGSET_LEN;
+    loc_dev->index = ISP1761_DC;
+    loc_dev->baseaddress = address;
+    loc_dev->active = 1;
+    memcpy(loc_dev->name,"isp1761_dev",11);
+    loc_dev->name[12] = '\0';
+
+
+    {
+        u32 chipid = 0;
+        chipid = readl(address + 0x270);
+        info("pid %04x, vid %04x\n", (chipid & 0xffff), (chipid >> 16));
+    }   
+    hal_init(("isp1761 DC MEM Base= %lx irq = %d\n", 
+                loc_dev->io_base,loc_dev->irq));
+    /* Get the OTG Controller IO and INT resources
+     * OTG controller resources are same as Host Controller resources
+     */
+    loc_dev = &(isp1761_loc_dev[ISP1761_OTG]);
+    loc_dev->dev = &pdev->dev;
+    loc_dev->irq = platform_get_irq(pdev, 0);
+    loc_dev->io_base = isp1761_base;
+    loc_dev->start   =  isp1761_base;
+    loc_dev->length  = ISP1761_REGSET_LEN;     
+    loc_dev->io_len = ISP1761_REGSET_LEN;
+    loc_dev->index = ISP1761_OTG; 
+    loc_dev->baseaddress = address; /*having the same address as of host*/
+    loc_dev->active = 1;
+    memcpy(loc_dev->name,"isp1761_otg",11);
+    loc_dev->name[12] = '\0';
+
+    hal_init(("isp1761 OTG MEM Base= %lx irq = %x\n", 
+                loc_dev->io_base,loc_dev->irq));
+
+#endif
+
+    /* Try to check whether we can access Scratch Register of
+     * Host Controller or not.
+     */
+
+#if 1 // CUSTOM STUFF - 16-bit mode
+    isp1761_reg_write32(loc_dev, HC_HW_MODE_REG, 2);
+#endif
+
+    loc_dev = &(isp1761_loc_dev[ISP1761_HC]);
+    isp1761_reg_write16(loc_dev, HC_SCRATCH_REG, 0xFACE);
+    udelay(100);
+    reg_data = isp1761_reg_read16(loc_dev, HC_SCRATCH_REG,reg_data);
+
+    /* Host Controller presence is detected by writing to scratch register
+     * and reading back and checking the contents are same or not
+     */
+    if(reg_data != 0xFACE) {
+        err("%s scratch register mismatch %x",
+                isp1761_driver_name,reg_data);
+        status = -ENODEV;
+        goto clean;
+    }
+
+    memcpy(loc_dev->name, isp1761_driver_name, sizeof(isp1761_driver_name));
+    loc_dev->name[sizeof(isp1761_driver_name)] = 0;
+    loc_dev->active = 1;
+
+    info("controller address %p\n", &pdev->dev);
+
+    s_pdev = pdev;
+    hal_data.irq_usage = 0;
+    hal_entry("%s: Exit\n",__FUNCTION__);
+    return 0;
+
+clean:
+    release_mem_region(loc_dev->io_base, loc_dev->io_len);
+    iounmap(loc_dev->baseaddress);
+    hal_entry("%s: Exit\n",__FUNCTION__);
+    return status;
+} /* End of isp1761_probe */
+
+
+/*--------------------------------------------------------------*
+ *
+ *  Module dtatils: isp1761_remove
+ *
+ * PCI cleanup function of ISP1761
+ * This function is called from PCI Driver as an removal function
+ * in the absence of PCI device or a de-registration of driver.
+ * This functions checks the registerd drivers (HCD, DCD, OTG) and calls
+ * the corresponding removal functions. Also initializes the local variables
+ * to zero.
+ *
+ *  Input: 
+ *              struct pci_dev *dev                     ----> PCI Devie data structure 
+ *    
+ *  Output void
+ *
+ *  Called by: system function module_cleanup 
+ * 
+ * 
+ * 
+ --------------------------------------------------------------*/
+static int __devexit
+isp1761_remove (struct platform_device *pdev)
+{
+    struct isp1761_dev  *loc_dev;
+    hal_init(("isp1761_remove(dev=%p)\n",pdev));
+    /*Lets handle the host first*/
+    loc_dev  = &isp1761_loc_dev[ISP1761_HC];
+    /*free the memory occupied by host*/
+    release_mem_region(loc_dev->io_base, loc_dev->io_len);      
+    /*unmap the occupied memory resources*/
+    iounmap(loc_dev->baseaddress);
+    s_pdev = NULL;
+    return 0;
+} /* End of isp1761_remove */
+
+/*--------------------------------------------------------------*
+ *
+ *  Module dtatils: isp1761_pci_suspend
+ *
+ * PCI suspend function of ISP1761
+ * This function is called from PCI Driver.
+ * This functions checks the registerd drivers (HCD, DCD, OTG) and calls
+ * the corresponding suspend functions if present. 
+ *  Input: 
+ *              struct pci_dev *dev                     ----> PCI Devie data structure 
+ *    
+ *  Output void
+ *
+ *  Called by: system function 
+ * 
+ * 
+ * 
+ --------------------------------------------------------------*/
+
+#ifdef CONFIG_PM
+static int isp1761_pci_suspend (struct pci_dev *dev, __u32 state) 
+{
+    struct isp1761_dev  *loc_dev;
+    int                 index;
+
+    hal_init(("isp1761_pci_suspend(dev=%p, state = %x)\n",dev, state));
+
+
+    loc_dev = (struct isp1761_dev *)pci_get_drvdata(dev);
+
+    /* For each controller check whether driver is registerd
+     * or not. If registerd call the suspend function if it is
+     * present
+     */
+    for(index=ISP1761_1ST_DEV;index<ISP1761_LAST_DEV;(index++,loc_dev++)) {
+        if(loc_dev->driver && loc_dev->driver->suspend) {
+            loc_dev->driver->suspend(loc_dev);
+        }
+    }
+
+    return 0;
+} /* End of isp1761_pci_suspend */
+#endif
+
+
+/*--------------------------------------------------------------*
+ *
+ *  Module dtatils: isp1761_pci_suspend
+ *
+ *  PCI resume function of ISP1761
+ * This function is called from PCI Driver.
+ * This functions checks the registerd drivers (HCD, DCD, OTG) and calls
+ * the corresponding resume functions if present.  
+ *  Input: 
+ *              struct pci_dev *dev                     ----> PCI Devie data structure 
+ *    
+ *  Output void
+ *
+ *  Called by: system function
+ * 
+ * 
+ --------------------------------------------------------------*/
+#ifdef CONFIG_PM
+static int isp1761_pci_resume (struct pci_dev *dev)
+{
+    struct isp1761_dev  *loc_dev;
+    int                 index;
+    hal_init(("isp1362_pci_resume(dev=%p)\n",dev));
+    loc_dev = (struct isp1761_dev *)pci_get_drvdata(dev);
+
+    /* For each controller check whether driver is registerd
+     * or not. If registerd call the resume function if it is
+     * present
+     */
+    for(index=ISP1761_1ST_DEV;index<ISP1761_LAST_DEV;(index++,loc_dev++)) {
+        if(loc_dev->driver && loc_dev->driver->resume) {
+            loc_dev->driver->resume(loc_dev);
+        }
+    }
+
+    return 0;
+
+} /* End of isp1362_pci_resume */
+#endif
+
+
+
+EXPORT_SYMBOL(isp1761_reg_write16);
+EXPORT_SYMBOL(isp1761_reg_read16);
+EXPORT_SYMBOL(isp1761_reg_read32);
+EXPORT_SYMBOL(isp1761_reg_write32);
+EXPORT_SYMBOL(isp1761_request_irq);
+EXPORT_SYMBOL(isp1761_mem_read);
+EXPORT_SYMBOL(isp1761_mem_write);
+EXPORT_SYMBOL(isp1761_free_irq);
+EXPORT_SYMBOL(isp1761_register_driver);
+EXPORT_SYMBOL(isp1761_unregister_driver);
+
+MODULE_AUTHOR (DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE ("GPL");
+
+module_init (isp1761_module_init);
+module_exit (isp1761_module_cleanup);
+
+
diff -ruNpa pehcd/hal/isp1761.h /home/b/uni/fyp/fyp-svn/DriversM6/usb/pehcd/hal/isp1761.h
--- pehcd/hal/isp1761.h	2006-05-19 16:56:12.000000000 +0800
+++ /home/b/uni/fyp/fyp-svn/DriversM6/usb/pehcd/hal/isp1761.h	2006-09-04 19:49:13.000000000 +0800
@@ -120,9 +120,9 @@ do \
 /*Debug for Interrupt , Registers , Device Enable/Disable and some other info */
 #undef DEV_DEBUG_LEVEL3
 #ifdef DEV_DEBUG_LEVEL3
-#define dev_info(format,arg...) printk(format, ##arg)
+#define dev_inform(format,arg...) printk(format, ##arg)
 #else
-#define dev_info(format,arg...) do {} while (0)
+#define dev_inform(format,arg...) do {} while (0)
 #endif
 
 /*Debug for Tranffer flow , Enumeration and Packet info */
diff -ruNpa pehcd/host/itdptd.c /home/b/uni/fyp/fyp-svn/DriversM6/usb/pehcd/host/itdptd.c
--- pehcd/host/itdptd.c	2006-05-19 16:45:54.000000000 +0800
+++ /home/b/uni/fyp/fyp-svn/DriversM6/usb/pehcd/host/itdptd.c	2006-09-04 21:42:04.000000000 +0800
@@ -646,17 +646,18 @@ void phcd_iso_itd_free_list( phci_hcd *h
  *  - Allocating and initializing Payload and PTD memory
  */
 unsigned long phcd_submit_iso( phci_hcd *hcd,
+	struct usb_host_endpoint *ep,
         struct urb *urb,
         unsigned long *status
         )
 {
     struct _periodic_list *periodic_list;
-    struct _hcd_dev *dev;
+    struct hcd_dev *dev;
     struct ehci_qh *qhead;
     struct ehci_itd *itd, *prev_itd;
     struct list_head *itd_list;
 
-    unsigned long ep_num, ep_in, max_pkt, mult;
+    unsigned long ep_in, max_pkt, mult;
     unsigned long bus_time, high_speed, start_frame;
     unsigned long flags, packets;
 
@@ -665,8 +666,7 @@ unsigned long phcd_submit_iso( phci_hcd 
     /* Local variable initialization */
     high_speed = 0;
     periodic_list = &hcd->periodic_list[0];
-    dev = (struct _hcd_dev *)urb->dev->hcpriv;
-    ep_num = usb_pipeendpoint(urb->pipe);
+    dev = (struct hcd_dev *)urb->dev->bus->hcpriv;
     urb->hcpriv = (void *) 0;
     prev_itd = (struct ehci_itd *) 0;
     itd = (struct ehci_itd *) 0;
@@ -674,14 +674,11 @@ unsigned long phcd_submit_iso( phci_hcd 
 
     ep_in = usb_pipein(urb->pipe);
 
-    if(ep_in)
-        ep_num |= 0x10;
-
     /* 
      * Take the endpoint, if there is still no memory allocated
      * for it allocate some and indicate this is for ISO.
      */
-    qhead  = (struct ehci_qh *)dev->ep[ep_num];
+    qhead  = ep->hcpriv;
     if(!qhead)
     {
         /* 
@@ -695,7 +692,7 @@ unsigned long phcd_submit_iso( phci_hcd 
             return -ENOMEM;
         }
         qhead->type = TD_PTD_BUFF_TYPE_ISTL;
-        dev->ep[ep_num] = qhead;
+        ep->hcpriv = qhead;
     } /* if(!qhead) */
 
     /* 
diff -ruNpa pehcd/host/pehci.c /home/b/uni/fyp/fyp-svn/DriversM6/usb/pehcd/host/pehci.c
--- pehcd/host/pehci.c	2006-05-19 16:46:32.000000000 +0800
+++ /home/b/uni/fyp/fyp-svn/DriversM6/usb/pehcd/host/pehci.c	2006-09-06 10:19:28.000000000 +0800
@@ -80,6 +80,7 @@ extern void * phcd_iso_itd_to_ptd( phci_
         );
 
 extern  unsigned long phcd_submit_iso( phci_hcd *hcd,
+	struct usb_host_endpoint *ep,
         struct urb *urb,
         unsigned long *status
         );
@@ -205,7 +206,7 @@ pehci_hcd_td_ptd_submit_urb(phci_hcd *hc
 
     spin_lock_irqsave(&hcd->lock, flags);
     ptd_map_buff = &td_ptd_map_buff[bufftype];
-    qha = hcd->qha;
+    qha = &hcd->qha;
     switch(bufftype){
         case TD_PTD_BUFF_TYPE_ATL:
             skipmap = isp1761_reg_read32(hcd->dev, hcd->regs.atltdskipmap, skipmap);
@@ -588,7 +589,7 @@ loadtd:
             switch(PTD_PID(qha->td_info2)){
                 case OUT_PID:
                 case SETUP_PID:
-                    isp1761_mem_write(hcd->dev,(u32)mem_addr->phy_addr,0,(le32_to_cpu(qtd->hw_buf[0])),length,0);
+                    isp1761_mem_write(hcd->dev,(u32)mem_addr->phy_addr,0,(void*)(le32_to_cpu(qtd->hw_buf[0])),length,0);
                     break;
             }
 
@@ -723,7 +724,7 @@ pehci_hcd_qtd_schedule(phci_hcd *hcd,str
         switch(PTD_PID(qha->td_info2)){
             case OUT_PID:
             case SETUP_PID:
-                isp1761_mem_write(hcd->dev, (u32)mem_addr->phy_addr, 0,(le32_to_cpu(qtd->hw_buf[0])),length,0);
+                isp1761_mem_write(hcd->dev, (u32)mem_addr->phy_addr, 0,(void*)(le32_to_cpu(qtd->hw_buf[0])),length,0);
                 break;
         }
 
@@ -863,7 +864,7 @@ void phcd_iso_handler(phci_hcd *hcd, str
     frame_num = 0;
     schedule = FALSE;
     remove = FALSE;     
-    iso_ptd = hcd->isotd;
+    iso_ptd = &hcd->isotd;
     last_map = 0;
 
     /* Check if there are any ITDs scheduled  for processing */
@@ -1378,7 +1379,7 @@ pehci_hcd_intl_worker(phci_hcd *hcd,stru
     struct urb *urb;
     struct ehci_qtd *qtd = 0;
     struct ehci_qh *qh = 0;
-    struct _isp1761_qhint *qhint = hcd->qhint;
+    struct _isp1761_qhint *qhint = &hcd->qhint;
     td_ptd_map_t                *td_ptd_map;
     td_ptd_map_buff_t   *ptd_map_buff;
     struct isp1761_mem_addr *mem_addr = 0;
@@ -1537,7 +1538,7 @@ copylength:
             case IN_PID:
                 if(length && (length <= MAX_PTD_BUFFER_SIZE))
                     /*do read only when there is somedata*/
-                    isp1761_mem_read(hcd->dev,(u32)mem_addr->phy_addr,0,(le32_to_cpu(qtd->hw_buf[0])),length,0);
+                    isp1761_mem_read(hcd->dev,(u32)mem_addr->phy_addr,0,(void*)(le32_to_cpu(qtd->hw_buf[0])),length,0);
             case OUT_PID:
                 urb->actual_length += length;
                 qh->hw_current = qtd->hw_next;
@@ -1950,7 +1951,7 @@ copylength:
             qh->ping = 0;
             /*do read only when there is some data*/
             if(length && (length <= HC_ATL_PL_SIZE)){
-                isp1761_mem_read(hcd->dev,(u32)mem_addr->phy_addr,0,(le32_to_cpu(qtd->hw_buf[0])),length,0);
+                isp1761_mem_read(hcd->dev,(u32)mem_addr->phy_addr,0,(void*)(le32_to_cpu(qtd->hw_buf[0])),length,0);
             }
 
         case OUT_PID:
@@ -2145,7 +2146,7 @@ pehci_hcd_start_controller(phci_hcd *hcd
     command &=0;
     command  =  isp1761_reg_read32(hcd->dev,hcd->regs.command,command);
     /*should be in operation in 1000 usecs*/
-    if((retval = pehci_hcd_handshake(hcd,hcd->regs.command, CMD_RUN, CMD_RUN,1000))){
+    if((retval = pehci_hcd_handshake(hcd,hcd->regs.command, CMD_RUN, CMD_RUN,100000))){
         err("Host is not up(CMD_RUN) in 1000 usecs\n");
         return retval;
     }
@@ -2187,7 +2188,7 @@ pehci_hcd_enable_interrupts(phci_hcd *hc
     /*enable the global interrupt*/
     temp &=0;
     temp = isp1761_reg_read32(hcd->dev, hcd->regs.hwmodecontrol, temp);
-    temp |= 0x101;/*enable the global interrupt*/
+    temp |= 0x003;/*enable the global interrupt*/
     isp1761_reg_write32(hcd->dev, hcd->regs.hwmodecontrol, temp);
     /*maximum rate is one msec*/
     /*enable the atl interrupts OR and AND mask*/
@@ -2270,15 +2271,6 @@ pehci_hcd_init_reg(phci_hcd *hcd)
     pehci_entry("-- %s: Exit\n",__FUNCTION__);
 }
 
-static void pehci_hcd_pci_release(struct usb_bus *bus)
-{
-    struct usb_hcd *hcd = bus->hcpriv;
-    pehci_info("release pci bus\n");
-    if (hcd)
-        hcd->driver->hcd_free(hcd);
-}
-
-
 /*---------------------------------------------------
  *  Interrupt request function
  -----------------------------------------------------*/
@@ -2320,26 +2312,28 @@ pehci_hcd_irq1(struct usb_hcd *hcd, stru
 
 /*isr routine*/
     irqreturn_t
-pehci_hcd_irq(struct isp1761_dev *dev, void *__irq_data, struct pt_regs *regs) 
+pehci_hcd_irq(struct usb_hcd *usb_hcd, struct pt_regs *regs) //struct isp1761_dev *dev, void *__irq_data, struct pt_regs *regs) 
 {
+    struct isp1761_dev *dev;
     int work = 0;
     phci_hcd    *pehci_hcd;
     u32 intr = 0;
 
-    struct usb_hcd *usb_hcd = (struct usb_hcd *)__irq_data;
     if(!(usb_hcd->state & USB_STATE_READY)){
-        info("interrupt handler state not ready yet\n");
+        //info("interrupt handler state not ready yet\n");
         return IRQ_NONE;
+	//return IRQ_HANDLED;
     }
 
     /*our host*/        
     pehci_hcd = usb_hcd_to_pehci_hcd(usb_hcd);
+    dev = pehci_hcd->dev;
     intr = dev->int_reg;
     if(atomic_read(&pehci_hcd->nuofsofs)){
         return IRQ_HANDLED;     
     }
     atomic_inc(&pehci_hcd->nuofsofs);
-    usb_hcd->saw_irq = 1;               
+    set_bit(HCD_FLAG_SAW_IRQ, &usb_hcd->flags);
 #ifdef MSEC_INT_BASED
     work = 1;
 #else
@@ -2380,21 +2374,25 @@ pehci_hcd_reset(
     /*reset the host controller */
     temp &= 0;
     temp |= 1;
-    isp1761_reg_write32(hcd->dev,hcd->regs.reset, temp);
+    isp1761_reg_write32(hcd->dev,HC_RESET_REG, temp);
+    mdelay(50);
 
     /*reset the ehci controller registers*/
     temp = 0;
     temp |= (1<<1);
-    isp1761_reg_write32(hcd->dev,hcd->regs.reset, temp);
+    isp1761_reg_write32(hcd->dev,HC_RESET_REG, temp);
+
+    isp1761_reg_write32(hcd->dev,HC_HW_MODE_REG, 2); // 16-bit data bus. falling edge intr
+    isp1761_reg_write32(hcd->dev,0x374, 0x00800018); // Configure port 1 as HC
 
     /*read the command register */
-    command = isp1761_reg_read32(hcd->dev,hcd->regs.command,command);
+    command = isp1761_reg_read32(hcd->dev,HC_USBCMD_REG,command);
 
     command |= CMD_RESET;
     /*write back and wait for, 250 msec */
-    isp1761_reg_write32(hcd->dev,hcd->regs.command,command);
+    isp1761_reg_write32(hcd->dev,HC_USBCMD_REG,command);
     /*wait for maximum 250 msecs*/
-    return pehci_hcd_handshake(hcd,hcd->regs.command, CMD_RESET,0, 250 * 1000);
+    return pehci_hcd_handshake(hcd,HC_USBCMD_REG, CMD_RESET,0, 250 * 1000);
 }
 
 
@@ -2405,8 +2403,6 @@ pehci_hcd_reset(
 pehci_hcd_start(struct usb_hcd  *usb_hcd)
 
 {
-    struct usb_device   *udev;
-    struct usb_bus              *bus;
     int                 retval;
     int          count = 0;
     phci_hcd            *pehci_hcd = NULL;
@@ -2466,33 +2462,14 @@ pehci_hcd_start(struct usb_hcd  *usb_hcd
     /*set the state of the host to ready,
      * start processing interrupts
      * */
-    usb_hcd->state =  USB_STATE_READY;
-    pehci_hcd->state = USB_STATE_READY;
+    usb_hcd->state =  HC_STATE_RUNNING;
+    pehci_hcd->state = HC_STATE_RUNNING;
 
     /*initialize root hub timer*/
     init_timer(&pehci_hcd->rh_timer);
     /*initialize watchdog*/
     init_timer(&pehci_hcd->watchdog);
 
-    /*take the usb_bus*/
-    bus = &usb_hcd->self;
-    /*create the root hub*/
-    bus->root_hub = udev = usb_alloc_dev (NULL, bus,0);
-    if(!udev)
-        return -ENODEV;
-
-     /*root hub is high speed*/
-    udev->speed = USB_SPEED_HIGH;
-
-    pehci_info("enumerate the hub \n");
-    /*enumerate root hub, should never fail*/
-    if(usb_register_root_hub(udev, usb_hcd->self.controller) != 0){
-        err("can not enumerate the hub\n");
-        usb_put_dev (udev);
-        bus->root_hub = 0;
-        return -ENODEV;
-
-    }
     pehci_entry("-- %s: Exit\n",__FUNCTION__);
     return 0;
 }
@@ -2523,51 +2500,9 @@ pehci_hcd_stop(struct usb_hcd *usb_hcd)
     return;
 }
 
-/*allocate the host controller*/
-    static struct usb_hcd *
-pehci_hcd_alloc(void)
-{
-    phci_hcd *hcd;
-    hcd = (phci_hcd *)kmalloc(sizeof(phci_hcd), GFP_KERNEL);
-    if(!hcd)
-        return 0;
-    memset(hcd, 0, sizeof(phci_hcd));
-    hcd->qha = (isp1761_qha *)kmalloc(sizeof(isp1761_qha), GFP_KERNEL);
-    if(!hcd->qha)
-        return 0;
-    hcd->qhint = (isp1761_qhint *)kmalloc(sizeof(isp1761_qhint), GFP_KERNEL);
-    if(!hcd->qhint)
-        return 0;
-    hcd->isotd = (isp1761_isoptd *) kmalloc( sizeof(isp1761_isoptd), GFP_KERNEL);
-    if(!hcd->isotd){
-        kfree(hcd->qhint);
-        kfree(hcd->qha);
-        return 0;
-    }
-
-    /*initialize our device list on this host*/
-    INIT_LIST_HEAD(&hcd->dev_list);
-
-    return &hcd->usb_hcd;
-}
-
-/*free host controller*/
-    static void
-pehci_hcd_free(struct usb_hcd *usb_hcd)
-{
-    phci_hcd  *pehci_hcd = usb_hcd_to_pehci_hcd(usb_hcd);
-    if(pehci_hcd){
-        kfree(pehci_hcd->qha);
-        kfree(pehci_hcd->qhint);
-        kfree(pehci_hcd->isotd);
-        kfree(pehci_hcd);
-        pehci_hcd = 0;
-    }
-}
-
 /*submit urb , other than root hub*/
     static int
-pehci_hcd_urb_enqueue(struct usb_hcd *usb_hcd,struct urb *urb,int mem_flags)
+pehci_hcd_urb_enqueue(struct usb_hcd *usb_hcd,struct usb_host_endpoint *ep,struct urb *urb,gfp_t mem_flags)
 {
 
     struct list_head    qtd_list;
@@ -2580,7 +2515,6 @@ pehci_hcd_urb_enqueue(struct usb_hcd *us
     INIT_LIST_HEAD(&qtd_list);
     urb->transfer_flags &= ~EHCI_STATE_UNLINK;
 
-
     temp = usb_pipetype(urb->pipe);
     max = usb_maxpacket (urb->dev, urb->pipe, !usb_pipein(urb->pipe));
 
@@ -2672,7 +2606,7 @@ pehci_hcd_urb_enqueue(struct usb_hcd *us
             phci_hcd_make_qtd(pehci_hcd, &qtd_list,urb, &status);
             if(status < 0)
                 return status;
-            qh = phci_hcd_submit_interrupt(pehci_hcd,&qtd_list, urb, &status);
+            qh = phci_hcd_submit_interrupt(pehci_hcd,ep,&qtd_list, urb, &status);
             if(status < 0)
                 return status;
             break;
@@ -2683,7 +2617,7 @@ pehci_hcd_urb_enqueue(struct usb_hcd *us
             if(status < 0)
                 return status;
 
-            qh = phci_hcd_submit_async(pehci_hcd, &qtd_list, urb, &status);
+            qh = phci_hcd_submit_async(pehci_hcd, ep, &qtd_list, urb, &status);
             if(status < 0)
                 return status;
             break;
@@ -2693,7 +2627,7 @@ pehci_hcd_urb_enqueue(struct usb_hcd *us
                     (long) urb->transfer_buffer);
             iso_dbg(ISO_DBG_DATA,"[pehci_hcd_urb_enqueue]: URB Buffer Length: %d\n", 
                     (long) urb->transfer_buffer_length);
-            phcd_submit_iso(pehci_hcd, urb, (unsigned long *) &status);
+            phcd_submit_iso(pehci_hcd, ep, urb, (unsigned long *) &status);
 
             return status;
 
@@ -2863,10 +2797,9 @@ pehci_hcd_urb_dequeue(struct usb_hcd  *u
 /* bulk qh holds the data toggle */
 
     static void
-pehci_hcd_endpoint_disable (struct usb_hcd *usb_hcd, struct hcd_dev *dev, int ep)
+pehci_hcd_endpoint_disable (struct usb_hcd *usb_hcd, struct usb_host_endpoint *ep)//struct hcd_dev *dev, int ep)
 {
     phci_hcd            *ehci = usb_hcd_to_pehci_hcd (usb_hcd);
-    int                 epnum;
     unsigned long               flags;
     struct ehci_qh              *qh;
 
@@ -2874,23 +2807,18 @@ pehci_hcd_endpoint_disable (struct usb_h
     /* ASSERT:  any requests/urbs are being unlinked */
     /* ASSERT:  nobody can be submitting urbs for this any more */
 
-    epnum = ep & USB_ENDPOINT_NUMBER_MASK;
-    if (epnum != 0 && (ep & USB_DIR_IN))
-        epnum |= 0x10;
-
-
     spin_lock_irqsave (&ehci->lock, flags);
-    qh = (struct ehci_qh *) dev->ep [epnum];
+    qh = ep->hcpriv;
     if (!qh){
         goto done;
     }else {
         /*i will complete whatever left on this endpoint*/
         pehci_complete_device_removal(ehci,qh);
-        dev->ep [epnum] = NULL;
+	ep->hcpriv = NULL;
         goto done;
     }
 done:
-    dev->ep[epnum] = NULL;
+    ep->hcpriv = NULL;
     spin_unlock_irqrestore (&ehci->lock, flags);
     pehci_entry("-- %s: Exit\n",__FUNCTION__);
     return;
@@ -3164,6 +3092,10 @@ error:
 
 static const struct hc_driver pehci_driver = {
     .description =              hcd_name,
+    .product_desc = "PHILIPS ISP1761",
+    .hcd_priv_size = sizeof(phci_hcd) - sizeof(struct usb_hcd),
+
+    .irq = pehci_hcd_irq,
 
     /*
      * generic hardware linkage
@@ -3178,12 +3110,6 @@ static const struct hc_driver pehci_driv
     .stop =                     pehci_hcd_stop,
 
     /*
-     * memory lifecycle (except per-request)
-     */
-    .hcd_alloc =                pehci_hcd_alloc,
-    .hcd_free =                 pehci_hcd_free,
-
-    /*
      * managing i/o requests and associated device resources
      */
     .urb_enqueue =              pehci_hcd_urb_enqueue,
@@ -3206,26 +3132,17 @@ static const struct hc_driver pehci_driv
     int 
 pehci_hcd_probe(struct isp1761_dev *tmp_1761_dev , isp1761_id *ids )
 {
-    struct hc_driver        *driver;
-    struct pci_dev *dev = tmp_1761_dev->pcidev;
     struct usb_hcd          *usb_hcd;
     phci_hcd                *pehci_hcd;
+    struct device *dev = tmp_1761_dev->dev;
 
-    void            *base = 0;
-    int             retval = 0,status =0;
-    char            buf [8], *bufp = buf;
-
-    u32             intcsr;
+    int             status =0;
 
     pehci_entry("++ %s: Entered\n",__FUNCTION__);
     if (usb_disabled())
         return -ENODEV;
 
-    if (!ids || !(driver =(struct hc_driver *) ids->driver_info))
-        return -EINVAL;
-
-
-    usb_hcd = driver->hcd_alloc ();
+    usb_hcd = usb_create_hcd(&pehci_driver, dev, "platform");
     if (usb_hcd == NULL){
         status = -ENOMEM;
         goto clean;
@@ -3243,60 +3160,7 @@ pehci_hcd_probe(struct isp1761_dev *tmp_
     /*lets keep our host here*/
     tmp_1761_dev->driver_data = usb_hcd;
 
-    usb_hcd->region = 3;
-    usb_hcd->driver = driver;
-    usb_hcd->description = driver->description;
-    usb_hcd->self.bus_name = pci_name(dev);
-    usb_hcd->product_desc = "PHILIPS ISP1761";
-    usb_hcd->self.controller = &dev->dev;
-
-    if ((retval = hcd_buffer_create (usb_hcd)) != 0) {
-        driver->hcd_free (usb_hcd);
-        goto clean;
-    }
-
-    dev_info (usb_hcd->self.controller, "%s\n", usb_hcd->product_desc);
-
-    usb_hcd->state = USB_STATE_HALT;
-    status = isp1761_request_irq(pehci_hcd_irq,tmp_1761_dev,usb_hcd);
-
-    if (status != 0) {
-        dev_err (usb_hcd->self.controller,"request interrupt %s failed\n", bufp);
-        driver->hcd_free(usb_hcd);
-        goto clean;
-    }
-
-    /*enable the interrupts from PLX to PCI*/
-    /*CONFIGURE PCI/PLX interrupt*/
-    intcsr = readl(pehci_hcd->plxiobase+0x68);
-    intcsr |= 0x900;
-    writel(intcsr,pehci_hcd->plxiobase+0x68);
-
-    usb_hcd->irq = dev->irq;
-
-
-    sprintf (buf, "%d", dev->irq);
-
-    dev_info (usb_hcd->self.controller, "irq %s, %s %p\n", bufp,
-            (driver->flags & HCD_MEMORY) ? "pci mem" : "io base",
-            base);
-
-    usb_bus_init (&usb_hcd->self);
-    usb_hcd->self.op = &usb_hcd_operations;
-    usb_hcd->self.hcpriv = (void *) usb_hcd;
-    usb_hcd->self.release = &pehci_hcd_pci_release;
-    init_timer (&usb_hcd->rh_timer);
-    usb_hcd->self.controller->dma_mask = 0;
-
-    INIT_LIST_HEAD (&usb_hcd->dev_list);
-
-    usb_register_bus (&usb_hcd->self);
-    if ((status = driver->start (usb_hcd)) < 0) {
-        dev_err (usb_hcd->self.controller, "init error %d\n", retval);
-        free_irq(dev->irq,usb_hcd);
-        driver->hcd_free(usb_hcd);
-        goto clean;
-    }
+    status = usb_add_hcd(usb_hcd, tmp_1761_dev->irq, SA_INTERRUPT | SA_SHIRQ);
     pehci_entry("-- %s: Exit\n",__FUNCTION__);
     return status;
 
@@ -3312,55 +3176,16 @@ pehci_hcd_remove(struct isp1761_dev *tmp
 {
 
     struct usb_hcd          *usb_hcd;
-    struct pci_dev *dev = tmp_1761_dev->pcidev;
 
     phci_hcd *hcd = NULL;
-    u32 temp;
     usb_hcd = (struct usb_hcd *)tmp_1761_dev->driver_data;
     if (!usb_hcd)
         return;
 
     hcd = usb_hcd_to_pehci_hcd(usb_hcd);
-    pehci_entry("++ %s: Entered\n",__FUNCTION__);
 
-    if (in_interrupt ())
-        BUG ();
+    usb_remove_hcd(usb_hcd);
 
-    if (HCD_IS_RUNNING (usb_hcd->state)){
-        pehci_info("host is running\n");
-        usb_hcd->state = USB_STATE_QUIESCING;
-    }
-    usb_disconnect (&usb_hcd->self.root_hub);
-
-    usb_hcd->driver->stop (usb_hcd);
-    hcd_buffer_destroy (usb_hcd);
-
-    /*disable global interrupt*/
-    temp &=0;
-    isp1761_reg_write32(hcd->dev, hcd->regs.hwmodecontrol, temp);
-
-    /*disable individual interrupts*/
-    temp &= ~INTR_ENABLE_MASK;
-    isp1761_reg_write32(hcd->dev,hcd->regs.interruptenable, temp);
-
-    usb_hcd->state = USB_STATE_HALT;
-
-    isp1761_free_irq(tmp_1761_dev,usb_hcd);
-
-    /*let the interrupt source stabilise*/
-    mdelay(10);
-    /*no more processing of any interrupt or request*/
-    hcd->state = USB_STATE_HALT;
-
-    /*put host controller into
-     * non-functional state
-     * */
-    temp &=0;
-    temp |= ~CMD_RUN;
-    isp1761_reg_write32(hcd->dev, hcd->regs.command, temp);
-
-    usb_deregister_bus (&usb_hcd->self);
-    pehci_entry("-- %s: Exit\n",__FUNCTION__);
     return;
 }
 
@@ -3390,7 +3215,7 @@ static int  __init pehci_module_init(voi
     if(!result)
         info("Host Driver has been Registered");
     else
-        err("Host Driver has not been Registered with errors : %x",result);
+        err("Host Driver has not been Registered with errors : %d",result);
     return result;
 
 }
diff -ruNpa pehcd/host/pehci.h /home/b/uni/fyp/fyp-svn/DriversM6/usb/pehcd/host/pehci.h
--- pehcd/host/pehci.h	2006-05-19 16:46:48.000000000 +0800
+++ /home/b/uni/fyp/fyp-svn/DriversM6/usb/pehcd/host/pehci.h	2006-09-06 10:11:39.000000000 +0800
@@ -415,12 +415,12 @@ struct _phci_driver;
 struct _isp1761_hcd;
 #define EHCI_MAX_ROOT_PORTS 1
 
-#include "../../core/hcd.h"
+#include "../drivers/usb/core/hcd.h"
 
 /*host controller*/
 typedef struct _phci_hcd {
-    spinlock_t  lock;
     struct usb_hcd       usb_hcd;
+    spinlock_t  lock;
     /* async schedule support */
     struct ehci_qh              *async;
     struct ehci_qh              *reclaim;
@@ -448,9 +448,9 @@ typedef struct _phci_hcd {
     int                         state;/*state of the host controller*/
     unsigned long       reset_done[EHCI_MAX_ROOT_PORTS];
     ehci_regs   regs;
-    struct _isp1761_qha *qha;
-    struct _isp1761_qhint *qhint;
-    struct _isp1761_isoptd *isotd;
+    struct _isp1761_qha qha;
+    struct _isp1761_qhint qhint;
+    struct _isp1761_isoptd isotd;
     struct tasklet_struct tasklet;
     /*this timer is going to run every 20 msec*/
     struct timer_list   watchdog;
@@ -459,10 +459,9 @@ typedef struct _phci_hcd {
 }phci_hcd,*pphci_hcd;
 
 /*usb_device->hcpriv, points to this structure*/
-typedef struct _hcd_dev{
+typedef struct hcd_dev{
     struct list_head        dev_list;
     struct list_head        urb_list;
-    void                    *ep[32];
 }hcd_dev;
 
 #define usb_hcd_to_pehci_hcd(hcd)   container_of(hcd, struct _phci_hcd, usb_hcd)
diff -ruNpa pehcd/host/qtdptd.c /home/b/uni/fyp/fyp-svn/DriversM6/usb/pehcd/host/qtdptd.c
--- pehcd/host/qtdptd.c	2006-05-19 16:46:41.000000000 +0800
+++ /home/b/uni/fyp/fyp-svn/DriversM6/usb/pehcd/host/qtdptd.c	2006-09-04 21:45:07.000000000 +0800
@@ -751,13 +751,14 @@ phci_hcd_clear_toggle (struct usb_device
 struct ehci_qh * 
 phci_hcd_qh_append_tds (
         phci_hcd                *hcd, 
+	struct usb_host_endpoint *ep,
         struct urb              *urb,
         struct list_head        *qtd_list,
-        int                     epnum,
         void                    **ptr,
         int               *status
         )
 {
+    int epnum;
     struct ehci_qh              *qh = 0;
     struct ehci_qtd *qtd = list_entry(qtd_list->next, struct ehci_qtd, qtd_list);
     td_ptd_map_buff_t   *ptd_map_buff;
@@ -767,6 +768,7 @@ phci_hcd_qh_append_tds (
 
     pehci_entry("++ %s: Entered\n",__FUNCTION__);   
 
+    epnum = ep->desc.bEndpointAddress;
     qh = (struct ehci_qh *) *ptr;
     if(likely(qh != 0)){
         u32     hw_next = QTD_NEXT (qtd->qtd_dma);
@@ -834,6 +836,7 @@ phci_hcd_qh_append_tds (
 struct ehci_qh * 
 phci_hcd_submit_async(
         phci_hcd *hcd, 
+	struct usb_host_endpoint *ep,
         struct list_head *qtd_list, 
         struct urb *urb,
         int *status)
@@ -841,8 +844,8 @@ phci_hcd_submit_async(
 
 {
     struct ehci_qtd             *qtd;
-    struct _hcd_dev             *dev;
-    int                 epnum;
+    struct hcd_dev             *dev;
+    int                         epnum;
     unsigned long               flags;
     struct ehci_qh              *qh = 0;
 
@@ -850,7 +853,7 @@ phci_hcd_submit_async(
 
 
     qtd = list_entry (qtd_list->next, struct ehci_qtd, qtd_list);
-    dev = (struct _hcd_dev *)urb->dev->hcpriv;
+    dev = (struct hcd_dev *)urb->dev->bus->hcpriv;
     epnum = usb_pipeendpoint (urb->pipe);
     if (usb_pipein (urb->pipe) && !usb_pipecontrol (urb->pipe))
         epnum |= 0x10;
@@ -873,7 +876,7 @@ phci_hcd_submit_async(
 
     spin_lock_irqsave (&hcd->lock, flags);
     spin_lock(&hcd_data_lock);
-    qh = phci_hcd_qh_append_tds (hcd, urb, qtd_list, epnum, &dev->ep[epnum],status);
+    qh = phci_hcd_qh_append_tds (hcd, ep, urb, qtd_list, &ep->hcpriv,status);
     if(!qh  || *status < 0)
         goto cleanup;
     /* Control/bulk operations through TTs don't need scheduling,
@@ -1004,13 +1007,14 @@ done:
 struct ehci_qh *
 phci_hcd_submit_interrupt(
         phci_hcd *hcd, 
+	struct usb_host_endpoint *ep,
         struct list_head *qtd_list, 
         struct urb *urb,
         int *status)
 {
 
     struct ehci_qtd             *qtd;
-    struct _hcd_dev             *dev;
+    struct hcd_dev             *dev;
     int                 epnum;
     unsigned long               flags;
     struct ehci_qh              *qh = 0;
@@ -1018,16 +1022,14 @@ phci_hcd_submit_interrupt(
 
 
     qtd = list_entry (qtd_list->next, struct ehci_qtd, qtd_list);
-    dev = (struct _hcd_dev *)urb->dev->hcpriv;
-    epnum = usb_pipeendpoint (urb->pipe);
-    if (usb_pipein (urb->pipe))
-        epnum |= 0x10;
+    dev = (struct hcd_dev *)urb->dev->bus->hcpriv;
+    epnum = ep->desc.bEndpointAddress;
 
     pehci_entry("++ %s, enter\n", __FUNCTION__);    
 
 
     /*check for more than one urb queued for this endpoint*/
-    qh = (struct ehci_qh *)dev->ep[epnum];
+    qh = ep->hcpriv;
 
     spin_lock_irqsave (&hcd->lock, flags);
     if(unlikely(qh != 0)){
@@ -1064,7 +1066,7 @@ phci_hcd_submit_interrupt(
             *status = -ENOMEM;
             goto done;
         }
-        dev->ep[epnum] = qh;
+        ep->hcpriv = qh;
     }
 
     if (likely (qh != 0)) {
diff -ruNpa pehcd/Makefile /home/b/uni/fyp/fyp-svn/DriversM6/usb/pehcd/Makefile
--- pehcd/Makefile	2006-06-29 17:48:58.000000000 +0800
+++ /home/b/uni/fyp/fyp-svn/DriversM6/usb/pehcd/Makefile	2006-09-06 10:44:34.000000000 +0800
@@ -1,11 +1,17 @@
+PWD       := $(shell pwd)
 TOPDIR=$(shell pwd)
 TARGET=hal host
-KERNEL_DIR=/usr/src/linux-2.6.9
+#KERNEL_DIR=/usr/src/linux-2.6.9
+KERNEL_DIR= /mnt/gumstix/gumstix-buildroot-new/build_arm_nofpu/linux-2.6.17gum
+CROSS_COMPILE=/mnt/gumstix/gumstix-buildroot-new/build_arm_nofpu/staging_dir/bin/arm-linux-uclibc-
 export $(KERNEL_DIR)
+export $(CROSS_COMPILE)
 
 all:
-	for i in $(TARGET); do make -C $(KERNEL_DIR) SUBDIRS=$(TOPDIR)/$$i modules 2>> warn.log; done 
+	make -C $(KERNEL_DIR) M=$(PWD)/hal ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) modules
+	make -C $(KERNEL_DIR) M=$(PWD)/host ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) modules
 	for i in $(TARGET); do cp -f $(TOPDIR)/$$i/*.ko $(TOPDIR)/objs; done
+
 clean:
 	for i in $(TARGET); do make -C $(TOPDIR)/$$i SUBDIRS=$(TOPDIR)/$$i clean; done
 	rm -rf $(TOPDIR)/objs/hal_x86.ko $(TOPDIR)/objs/pehci.ko 

