Ejemplo n.º 1
0
/*!
 * generic_cl_modinit() - module init
 *
 * This is called by the Linux kernel; either when the module is loaded
 * if compiled as a module, or during the system intialization if the
 * driver is linked into the kernel.
 *
 * This function will parse module parameters if required and then register
 * the generic driver with the USB Device software.
 *
 */
static int generic_cl_modinit (void)
{
        #if !defined(OTG_C99)
        /*! function_ops - operations table for the USB Device Core
         */
        ZERO(generic_function_ops);
        generic_function_ops.device_request=generic_cl_device_request;          /*! called for each received device request */

        /*! class_driver - USB Device Core function driver definition
         */
        ZERO(generic_class_driver);
        generic_class_driver.driver.name = "generic-class";                            /*! driver name */
        generic_class_driver.driver.fops = &generic_function_ops;                             /*! operations table */
        #endif /* defined(OTG_C99) */

        GCLASS = otg_trace_obtain_tag(NULL, "generic-cf");

        // register as usb function driver
        TRACE_MSG0(GCLASS, "REGISTER CLASS");
        THROW_IF (usbd_register_class_function (&generic_class_driver, "generic-class", NULL), error);

        TRACE_MSG0(GCLASS, "REGISTER FINISHED");

        CATCH(error) {
                generic_cl_modexit();
                return -EINVAL;
        }
        return 0;
}
Ejemplo n.º 2
0
/*! 
 * mouse_cf_modinit() - module init
 *
 * This is called by the Linux kernel; either when the module is loaded
 * if compiled as a module, or during the system intialization if the 
 * driver is linked into the kernel.
 *
 * This function will parse module parameters if required and then register
 * the mouse driver with the USB Device software.
 *
 */
static int mouse_cf_modinit (void)
{
        int i;
        printk (KERN_INFO "%s: vendor_id: %04x product_id: %04x\n", __FUNCTION__, vendor_id, product_id);

        #if !defined(OTG_C99)
        mouse_cf_global_init();
        mouse_cf_ops_init();
        #endif /* defined(OTG_C99) */
        
        MOUSE = otg_trace_obtain_tag();
        TRACE_MSG2(MOUSE, "vendor_id: %04x product_id: %04x",vendor_id, product_id);

        //if (vendor_id) 
        //        mouse_composite_driver.idVendor = cpu_to_le16(vendor_id);
        //if (product_id) 
        //        mouse_composite_driver.idProduct = cpu_to_le16(product_id);


        // register as usb function driver
	TRACE_MSG0(MOUSE, "REGISTER COMPOSITE");

        THROW_IF (usbd_register_composite_function (&mouse_composite_driver, 
                                        "mouse-random-cf", NULL, mouse_arg_list, NULL), error);

	TRACE_MSG0(MOUSE, "REGISTER FINISHED");

        CATCH(error) {
                otg_trace_invalidate_tag(MOUSE);
                return -EINVAL;
        }
        return 0;
}
Ejemplo n.º 3
0
/* pcd_ocd_modinit - linux module initialization
 *
 * This needs to initialize the ocd, pcd and tcd drivers.  
 *
 * Specifically for each driver:
 *
 * 	obtain tag
 * 	pass ops table address to state machine and get instance address
 * 	call ops.mod_init
 *
 * Note that we automatically provide a default tcd_init if
 * none is set.
 */
static int pcd_ocd_modinit (void)
{
        printk(KERN_INFO"%s\n", __FUNCTION__);

        #if !defined(OTG_C99)
        pcd_global_init();
        #endif /* !defined(OTG_C99) */

        UNLESS(pcd_ops.pcd_init_func) pcd_ops.pcd_init_func = pcd_init_func;
        PCD = otg_trace_obtain_tag();
        THROW_UNLESS(pcd_instance = otg_set_pcd_ops(&pcd_ops), error);
        THROW_IF((pcd_ops.mod_init) ? pcd_ops.mod_init() : 0, error);

        OCD = otg_trace_obtain_tag();
        THROW_UNLESS(ocd_instance = otg_set_ocd_ops(&ocd_ops), error);
        THROW_IF((ocd_ops.mod_init) ? ocd_ops.mod_init() : 0, error);

        CATCH(error) {
                pcd_ocd_modexit();
                return -EINVAL;
        }
        return 0;
}
Ejemplo n.º 4
0
/*! acm_l26_modinit - module init
 *
 * This is called immediately after the module is loaded or during
 * the kernel driver initialization if linked into the kernel.
 *
 */
static int acm_l26_modinit (void)
{
        BOOL tty_l26 = FALSE, tty_if = FALSE;
        int minor_numbers=1;
        /* register tty  and usb interface function drivers
         */
        TTY = otg_trace_obtain_tag();
        THROW_UNLESS(tty_l26 = BOOLEAN(!tty_l26_init(ACM_DRIVER_PROCFS_NAME, ACM_TTY_MINORS)), error);
        THROW_UNLESS(tty_if = BOOLEAN(!tty_if_init()), error);

        CATCH(error) {
                if (tty_l26) tty_l26_exit();
                if (tty_if) tty_if_exit();
                otg_trace_invalidate_tag(TTY);
                return -EINVAL;
        }
        return 0;
}
Ejemplo n.º 5
0
/*! mcpc_l26_modinit - module init
 *
 * This is called immediately after the module is loaded or during
 * the kernel driver initialization if linked into the kernel.
 *
 */
STATIC int mcpc_l26_modinit (void)
{
    BOOL tty_l26 = FALSE, dun_if = FALSE, obex_if = FALSE, atcom_if = FALSE;

    TTY = otg_trace_obtain_tag();
    THROW_UNLESS (tty_l26 = BOOLEAN(!tty_l26_init("mcpc_if", 6)), error);
    THROW_UNLESS (tty_l26 = BOOLEAN(!dun_if_init()), error);
    THROW_UNLESS (tty_l26 = BOOLEAN(!obex_if_init()), error);
    THROW_UNLESS (tty_l26 = BOOLEAN(!atcom_if_init()), error);
    CATCH(error) {
        printk(KERN_ERR"%s: ERROR\n", __FUNCTION__);
        if (tty_l26) tty_l26_exit();
        if (dun_if) dun_if_exit();
        if (obex_if) obex_if_exit();
        if (atcom_if) atcom_if_exit();
        otg_trace_invalidate_tag(TTY);
        return -EINVAL;
    }
    return 0;
}
Ejemplo n.º 6
0
/*!
 * inteltest_cl_device_request - called to process a request to endpoint or interface
 * @param function
 * @param request
 * @return non-zero for failure, will cause endpoint zero stall
 */
static int inteltest_cl_device_request (struct usbd_function_instance *function, struct usbd_device_request *request)
{
        struct usbd_urb *urb;
        u16 wLength = le16_to_cpu(request->wLength);


        TRACE_MSG5(GCLASS, "bmRequestType: %02x bRequest: %02x wValue: %04x wIndex: %04x wLength: %04x",
                        request->bmRequestType, request->bRequest, request->wValue,
                        request->wIndex, request->wLength);

        /* XXX it should be this, need to verify
         */
        RETURN_EINVAL_UNLESS(USB_REQ_RECIPIENT_DEVICE == (request->bmRequestType & USB_REQ_RECIPIENT_MASK));

        switch (ctrl->bRequest) {
        switch (request->bmRequestType & USB_REQ_DIRECTION_MASK) {
        case USB_REQ_DEVICE2HOST:

                switch (request->bRequest) {
                case 0x5c:      /* read test */
                        RETURN_EINVAL_UNLESS((urb = usbd_alloc_urb_ep0 (function, wLength, NULL)));
                        RETURN_ZERO_UNLESS(rc || usbd_start_in_urb(urb));
                        break;
                }
                break;

        case USB_REQ_HOST2DEVICE:

                switch (request->bRequest) {
                case 0x5b:      /* write test */
                        RETURN_EINVAL_UNLESS((urb = usbd_alloc_urb_ep0 (function, wLength, NULL)));
                        RETURN_ZERO_UNLESS(rc || usbd_start_out_urb(urb));
                        break;
                }
                break;
        }

        return -EINVAL;
}
/* ********************************************************************************************* */
#if !defined(OTG_C99)
/*! function_ops - operations table for the USB Device Core
 */
static struct usbd_function_operations inteltest_function_ops;

/*! inteltest_class_driver - USB Device Core function driver definition
 */
struct usbd_class_driver inteltest_class_driver;

#else /* defined(OTG_C99) */
/*! function_ops - operations table for the USB Device Core
 */
static struct usbd_function_operations inteltest_function_ops = {
        .device_request = inteltest_cl_device_request,           /*!< called for each received device request */
};

/*! inteltest_class_driver - USB Device Core function driver definition
 */
struct usbd_class_driver inteltest_class_driver = {
        .driver.name = "inteltest-class",                            /*!< driver name */
        .driver.fops = &inteltest_function_ops,                             /*!< operations table */
};
#endif /* defined(OTG_C99) */


/* USB Module init/exit ***************************************************** */

//#if OTG_EPILOGUE
/*!
 * inteltest_cl_modexit() - module init
 *
 * This is called by the Linux kernel; when the module is being unloaded
 * if compiled as a module. This function is never called if the
 * driver is linked into the kernel.
 * @return none
 */
static void inteltest_cl_modexit (void)
{
        usbd_deregister_class_function (&inteltest_class_driver);
        otg_trace_invalidate_tag(GCLASS);
}

module_exit (inteltest_cl_modexit);
//#endif

/*!
 * inteltest_cl_modinit() - module init
 *
 * This is called by the Linux kernel; either when the module is loaded
 * if compiled as a module, or during the system intialization if the
 * driver is linked into the kernel.
 *
 * This function will parse module parameters if required and then register
 * the inteltest driver with the USB Device software.
 *
 */
static int inteltest_cl_modinit (void)
{
        #if !defined(OTG_C99)
        /*! function_ops - operations table for the USB Device Core
         */
        ZERO(inteltest_function_ops);
        inteltest_function_ops.device_request=inteltest_cl_device_request;          /*! called for each received device request */

        /*! class_driver - USB Device Core function driver definition
         */
        ZERO(inteltest_class_driver);
        inteltest_class_driver.driver.name = "inteltest-class";                            /*! driver name */
        inteltest_class_driver.driver.fops = &inteltest_function_ops;                             /*! operations table */
        #endif /* defined(OTG_C99) */

        GCLASS = otg_trace_obtain_tag(NULL, "inteltest-cf");

        // register as usb function driver
        TRACE_MSG0(GCLASS, "REGISTER CLASS");
        THROW_IF (usbd_register_class_function (&inteltest_class_driver, "inteltest-class", NULL), error);

        TRACE_MSG0(GCLASS, "REGISTER FINISHED");

        CATCH(error) {
                inteltest_cl_modexit();
                return -EINVAL;
        }
        return 0;
}
Ejemplo n.º 7
0
/*! 
 * generic_cf_modinit() - module init
 *
 * This is called by the Linux kernel; either when the module is loaded
 * if compiled as a module, or during the system intialization if the 
 * driver is linked into the kernel.
 *
 * This function will parse module parameters if required and then register
 * the generic driver with the USB Device software.
 *
 */
static int generic_cf_modinit (void)
{
        int i;

        #if !defined(OTG_C99)
        //generic_cf_global_init();
        #endif /* defined(OTG_C99) */


        GENERIC = otg_trace_obtain_tag();

        i = MODPARM(idVendor);

        printk (KERN_INFO "Model ID is %s",MODPARM(iProduct));

#if 0
        TRACE_MSG4(GENERIC, "config_name: \"%s\" load_all: %d class_name: \"%s\" interface_names: \"%s\"",
                        MODPARM(config_name) ? MODPARM(config_name) : "", 
                        MODPARM(load_all), 
                        MODPARM(class_name) ? MODPARM(class_name) : "", 
                        MODPARM(interface_names) ? MODPARM(interface_names) : "");
#else

        TRACE_MSG5(GENERIC, "config_name: \"%s\" load_all: %d class_name: \"%s\" interface_names: \"%s\" Serial: \"%s\"",
                        generic_config_name(), 
                        MODPARM(load_all), 
                        MODPARM(class_name) ? MODPARM(class_name) : "", 
                        MODPARM(interface_names) ? MODPARM(interface_names) : "",
			MODPARM(iSerialNumber) ? MODPARM(iSerialNumber) : "");

#endif

        /* load config or configs
         */
        
        if (preset_config_name()  || MODPARM(load_all)) {

		if (preset_config_name()){
                        MODPARM(load_all) = 0;
		}

                printk (KERN_INFO "%s: config_name: \"%s\" load_all: %d\n", 
                                __FUNCTION__, generic_config_name() , MODPARM(load_all));

                /* search for named config
                 */
                for (i = 0; ; i++) {
                        struct generic_config *config = generic_configs + i;
                        BREAK_UNLESS(config->interface_names);
                        printk(KERN_INFO"%s: checking[%d] \"%s\"\n", __FUNCTION__, i, config->composite_driver.driver.name);

			if (MODPARM(iSerialNumber) && strlen(MODPARM(iSerialNumber)) &&
                            /* For the moment, we will only use serial number for msc and mtp.  I suggest we come up with a more generic
                               way to determine if a function driver needs to use the serial number. (for instance another function member. */
                            ( ( !strcmp(config->composite_driver.driver.name, "mtp")) || !strcmp(config->composite_driver.driver.name, "msc")) ){
                              config->device_description.iSerialNumber = MODPARM(iSerialNumber);
			}

                        config->device_description.iProduct = MODPARM(iProduct);

                        generic_cf_register(config, generic_config_name());
                        //printk(KERN_INFO"%s: loaded  %s\n", __FUNCTION__, config->composite_driver.driver.name);
                }
        }
        else {
                struct generic_config *config = &generic_config;

                //printk (KERN_INFO "%s: idVendor: %04x idProduct: %04x\n", __FUNCTION__, MODPARM(idVendor), MODPARM(idProduct));
                //printk (KERN_INFO "%s: class_name: \"%s\" _interface_names: \"%s\"\n", 
                //                __FUNCTION__, MODPARM(class_name), MODPARM(interface_names));

                if (MODPARM(driver_name) && strlen(MODPARM(driver_name)))
                        config->composite_driver.driver.name = MODPARM(driver_name);

                if (MODPARM(class_name) && strlen(MODPARM(class_name)))
                        config->class_name = MODPARM(class_name);

                if (MODPARM(interface_names) && strlen(MODPARM(interface_names)))
                        config->interface_names = MODPARM(interface_names);

                if (MODPARM(iConfiguration) && strlen(MODPARM(iConfiguration)))
                        config->configuration_description.iConfiguration = MODPARM(iConfiguration);

                if (MODPARM(bDeviceClass))
                        config->device_description.bDeviceClass = MODPARM(bDeviceClass);

                if (MODPARM(bDeviceSubClass))
                        config->device_description.bDeviceSubClass = MODPARM(bDeviceSubClass);

                if (MODPARM(bDeviceProtocol))
                        config->device_description.bDeviceProtocol = MODPARM(bDeviceProtocol);

                if (MODPARM(idVendor)) 
                        config->device_description.idVendor = MODPARM(idVendor);
                else
                        config->device_description.idVendor = CONFIG_OTG_GENERIC_VENDORID;

                if (MODPARM(idProduct))
                        config->device_description.idProduct = MODPARM(idProduct);
                else
                        config->device_description.idProduct = CONFIG_OTG_GENERIC_PRODUCTID;

                if (MODPARM(bcdDevice))
                        config->device_description.bcdDevice = MODPARM(bcdDevice);
                else
                        config->device_description.bcdDevice = CONFIG_OTG_GENERIC_BCDDEVICE;

                if (MODPARM(iManufacturer) && strlen(MODPARM(iManufacturer)))
                        config->device_description.iManufacturer = MODPARM(iManufacturer);
                else
                        config->device_description.iManufacturer = CONFIG_OTG_GENERIC_MANUFACTURER;

                if (MODPARM(iProduct) && strlen(MODPARM(iProduct)))
                        config->device_description.iProduct = MODPARM(iProduct);
                else
                        config->device_description.iProduct = CONFIG_OTG_GENERIC_PRODUCT_NAME;

                if (MODPARM(iSerialNumber) && strlen(MODPARM(iSerialNumber))){
                        config->device_description.iSerialNumber = MODPARM(iSerialNumber);
		}
                if (MODPARM(interface_names))
                        config->interface_names = MODPARM(interface_names);

                generic_cf_register(config, NULL);
        }
        return 0;
}
Ejemplo n.º 8
0
/*!
 * zasevb_modinit() - linux module initialization
 *
 * This needs to initialize the hcd, pcd and tcd drivers. This includes tcd and possibly hcd
 * for some architectures.
 *
 */
static int zasevb_modinit (void)
{
        struct otg_instance *otg = NULL;

        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
        struct clk *clk = clk_get(NULL, "usb_clk");
        clk_enable(clk);
        clk_put(clk);
        #endif

        THROW_UNLESS((otg = otg_create()), error);

        mxc_pcd_ops_init();
        #if !defined(OTG_C99)
        pcd_global_init();
        fs_ocd_global_init();
        zasevb_tcd_global_init();
        fs_pcd_global_init();
        #endif /* !defined(OTG_C99) */

        ZAS = otg_trace_obtain_tag(otg, "zas");

        mxc_procfs_init();

        TRACE_MSG0(ZAS, "1. ZAS");

        #if 0
        /* ZAS EVB Platform setup
         */
        TRACE_MSG4(ZAS, "BCTRL Version: %04x Status: %04x 1: %04x 2: %04x",
                        readw(PBC_BASE_ADDRESS ),
                        readw(PBC_BASE_ADDRESS + PBC_BSTAT),
                        readw(PBC_BASE_ADDRESS + PBC_BCTRL1_SET),
                        readw(PBC_BASE_ADDRESS + PBC_BCTRL2_SET));

        #endif

        /* ZAS EVB Clock setup
         */

#if defined(CONFIG_ARCH_ARGONPLUS) || defined(CONFIG_ARCH_ARGONLV)
#define ZASEVB_MULTIPLIER       12
#define ZASEVB_DIVISOR          775             // ~10.
#else
#define ZASEVB_MULTIPLIER       12
#define ZASEVB_DIVISOR 155
#endif

        TRACE_MSG0(ZAS, "2. Setup GPT");

        THROW_UNLESS(ocd_instance = otg_set_ocd_ops(otg, &ocd_ops), error);
        REMOVE_OCD = ocd_instance->TAG;
        // XXX THROW_IF((ocd_ops.mod_init ? ocd_ops.mod_init() : 0), error);

        #if defined(CONFIG_OTG_GPTR)
        mxc_gptcr_mod_init(ZASEVB_DIVISOR, ZASEVB_MULTIPLIER);
        #endif /* defined(CONFIG_OTG_GPTR) */

        #if defined(CONFIG_OTG_HRT)
        mxc_hrt_mod_init(otg, ZASEVB_DIVISOR, ZASEVB_MULTIPLIER);
        #endif /* defined(CONFIG_OTG_GPTR) */


        #if !defined(CONFIG_USB_HOST)
        TRACE_MSG0(ZAS, "3. PCD");
        THROW_UNLESS(REMOVE_pcd_instance = otg_set_pcd_ops(otg, &pcd_ops), error);
        REMOVE_PCD = REMOVE_pcd_instance->TAG;
        // XXX THROW_IF((pcd_ops.mod_init ? pcd_ops.mod_init() : 0), error);
        #else /* !defined(CONFIG_USB_HOST) */
        printk(KERN_INFO"%s: PCD DRIVER N/A\n", __FUNCTION__);
        #endif /* !defined(CONFIG_USB_HOST) */


        TRACE_MSG0(ZAS, "4. TCD");
        THROW_UNLESS(REMOVE_tcd_instance = otg_set_tcd_ops(otg, &tcd_ops), error);
        REMOVE_TCD = REMOVE_tcd_instance->TAG;
        // XXX THROW_IF((tcd_ops.mod_init ? tcd_ops.mod_init() : 0), error);
#ifdef OTG_USE_I2C
        TRACE_MSG0(ZAS, "0. I2C");
        i2c_mod_init(otg);
#endif


        #if defined(CONFIG_OTG_USB_HOST) || defined(CONFIG_OTG_USB_PERIPHERAL_OR_HOST)|| defined(CONFIG_OTG_DEVICE)
        TRACE_MSG0(ZAS, "5. Host");
        THROW_UNLESS(hcd_instance = otg_set_hcd_ops(otg, &hcd_ops), error);
        HCD = hcd_instance->TAG;
        // XXX THROW_IF((hcd_ops.mod_init) ? hcd_ops.mod_init() : 0, error);
        #else /* defined(CONFIG_OTG_USB_HOST) || defined(CONFIG_OTG_USB_PERIPHERAL_OR_HOST)|| defined(CONFIG_OTG_DEVICE) */
        printk(KERN_INFO"%s: HCD DRIVER N/A\n", __FUNCTION__);
        #endif /* defined(CONFIG_OTG_USB_HOST) || defined(CONFIG_OTG_USB_PERIPHERAL_OR_HOST)|| defined(CONFIG_OTG_DEVICE) */



        TRACE_MSG0(ZAS, "6. Init & check");
        THROW_IF((ocd_ops.mod_init ? ocd_ops.mod_init(otg) : 0), error);

        #if !defined(CONFIG_USB_HOST)
        THROW_IF((pcd_ops.mod_init ? pcd_ops.mod_init(otg) : 0), error);
        #endif /* !defined(CONFIG_USB_HOST) */

        THROW_IF((tcd_ops.mod_init ? tcd_ops.mod_init(otg) : 0), error);

        #if defined(CONFIG_OTG_USB_HOST) || defined(CONFIG_OTG_USB_PERIPHERAL_OR_HOST)|| defined(CONFIG_OTG_DEVICE)
        THROW_IF((hcd_ops.mod_init) ? hcd_ops.mod_init(otg) : 0, error);
        #endif /* defined(CONFIG_OTG_USB_HOST) || defined(CONFIG_OTG_USB_PERIPHERAL_OR_HOST)|| defined(CONFIG_OTG_DEVICE) */

        THROW_UNLESS(ocd_instance && (otg = ocd_instance->otg), error);


        TRACE_MSG0(ZAS, "7. otg_init");
        if (MODPARM(serial_number_str) && strlen(MODPARM(serial_number_str))) {

                TRACE_MSG1(ZAS, "serial_number_str: %s", MODPARM(serial_number_str));
                otg_serial_number (otg, MODPARM(serial_number_str));
        }
        otg_init(otg);

        return 0;

        CATCH(error) {
                //zasevb_modexit();
                return -EINVAL;
        }

        return 0;
}
Ejemplo n.º 9
0
/*!
 * otg_pci_probe() - otg pci probe function
 *
 * Get the standard PCI resources allocated.
 *
 */
int __devinit otg_pci_probe (struct pci_dev *pci_dev, const struct pci_device_id *id, struct otg_pci_driver *otg_pci_driver)
{

        struct otg_driver       *otg_driver;
        struct otg_dev          *otg_dev = NULL;
        int                     enabled = 0;
        int                     irq = 0;
        int                     region;

        u8                      latency, limit;


        /* allocate otg_dev structure and fill in standard fields */
        THROW_UNLESS((otg_dev = kmalloc(sizeof(struct otg_dev), SLAB_KERNEL)), error);

        memset(otg_dev, 0, sizeof(struct otg_dev));
        otg_dev->PCI = otg_trace_obtain_tag();


        //printk(KERN_INFO"%s: PCI %d\n", __FUNCTION__, otg_dev->PCI); 
        //TRACE_MSG0(otg_dev->PCI, "TEST");

        THROW_UNLESS((enabled = !pci_enable_device(pci_dev)), error);

        otg_dev->otg_pci_driver = otg_pci_driver;
        otg_dev->pci_regions = otg_pci_driver->pci_regions;
        pci_set_drvdata(pci_dev, otg_dev);
        printk(KERN_INFO"%s: pci_dev: %x otg_dev: %x drv_data: %x\n", __FUNCTION__, pci_dev, otg_dev, pci_get_drvdata(pci_dev)); 

        for (region = 0; region < DEVICE_COUNT_RESOURCE; region++) {
                unsigned long           resource_start;
                unsigned long           resource_len;
                TRACE_MSG5(otg_dev->PCI, "[%2d] flags: %08x start: %08x end: %08x len: %08x", region,
                                pci_resource_flags(pci_dev, region),
                                pci_resource_start(pci_dev, region),
                                pci_resource_end(pci_dev, region),
                                pci_resource_len(pci_dev, region)
                                ); 

                CONTINUE_UNLESS(otg_dev->pci_regions & (1 << region));

                resource_start = pci_resource_start(pci_dev, region);
                resource_len = pci_resource_len(pci_dev, region);

                TRACE_MSG5(otg_dev->PCI, "pci_dev: %x otg_dev: %x start: %lx len: %lx name: %s", 
                                pci_dev, otg_dev, resource_start, resource_len, otg_pci_driver->name); 

                THROW_UNLESS(request_mem_region(resource_start, resource_len, otg_pci_driver->name), error);
                THROW_UNLESS((otg_dev->regs[region] = ioremap_nocache(resource_start, resource_len)), error);
                TRACE_MSG2(otg_dev->PCI, "regs[%d] %x", region, otg_dev->regs[region]);
        }

        THROW_UNLESS((irq = !request_irq(pci_dev->irq, otg_pci_isr, SA_SHIRQ, otg_pci_driver->name, pci_dev)), error);
        TRACE_MSG1(otg_dev->PCI, "irq: %d", pci_dev->irq);

        /* bad pci latencies can contribute to overruns  - but where ?? */
        pci_read_config_byte (pci_dev, PCI_LATENCY_TIMER, &latency);
        pci_read_config_byte (pci_dev, PCI_MAX_LAT, &limit);
        TRACE_MSG2(otg_dev->PCI, "latency: %02x limit: %02x", latency, limit);

        if (latency && /* limit &&*/ (limit < latency)) {

                pci_write_config_byte (pci_dev, PCI_LATENCY_TIMER, limit);
                pci_read_config_byte (pci_dev, PCI_LATENCY_TIMER, &latency);
                TRACE_MSG2(otg_dev->PCI, "latency: %02x limit: %02x", latency, limit);
        }



	/* XXX lock? */
        otg_dev->id = otg_get_id(pci_dev);
        TRACE_MSG1(otg_dev->PCI, "id: %d", otg_dev->id); 
        if (otg_devs) {
                TRACE_MSG2(otg_dev->PCI, "otg_devs: %x new: %x", otg_devs, otg_dev); 
                otg_dev->next = otg_devs;
        }
        otg_devs = otg_dev;

        return 0;

        CATCH(error) {

                printk(KERN_INFO"%s: FAILED\n", __FUNCTION__); 
                pci_set_drvdata(pci_dev, NULL);

                if (irq) free_irq(pci_dev->irq, otg_dev);

                otg_pci_free_dev(pci_dev, otg_dev);

                if (otg_dev) kfree(otg_dev);

                if (enabled) pci_disable_device(pci_dev);
                
                return -EINVAL;
        }
}