예제 #1
0
/*****************************************************************
 *
 * Function Name: hc_alloc_hci
 *
 * This function allocates all data structure and store in the 
 * private data structure. 
 *
 * Input:  hci = data structure for the host controller
 *
 * Return value  : 0 
 *                
 *****************************************************************/
static hci_t *__devinit hc_alloc_hci (void)
{
	hci_t *hci;
	hcipriv_t *hp;
	portstat_t *ps;
	struct usb_bus *bus;

	DBGFUNC ("Enter hc_alloc_hci\n");
	hci = (hci_t *) kmalloc (sizeof (hci_t), GFP_KERNEL);
	if (!hci)
		return NULL;

	memset (hci, 0, sizeof (hci_t));

	hp = &hci->hp;

	hp->irq = -1;
	hp->hcport = -1;

	/* setup root hub port status */

	ps = (portstat_t *) kmalloc (sizeof (portstat_t), GFP_KERNEL);

	if (!ps)
		return NULL;
	ps->portStatus = PORT_STAT_DEFAULT;
	ps->portChange = PORT_CHANGE_DEFAULT;
	hp->RHportStatus = ps;

	hci->nakCnt = 0;
	hci->last_packet_nak = 0;

	hci->a_td_array.len = 0;
	hci->i_td_array[0].len = 0;
	hci->i_td_array[1].len = 0;
	hci->td_array = &hci->a_td_array;
	hci->active_urbs = 0;
	hci->active_trans = 0;
	INIT_LIST_HEAD (&hci->hci_hcd_list);
	list_add (&hci->hci_hcd_list, &hci_hcd_list);
	init_waitqueue_head (&hci->waitq);

	INIT_LIST_HEAD (&hci->ctrl_list);
	INIT_LIST_HEAD (&hci->bulk_list);
	INIT_LIST_HEAD (&hci->iso_list);
	INIT_LIST_HEAD (&hci->intr_list);
	INIT_LIST_HEAD (&hci->del_list);

	bus = usb_alloc_bus (&hci_device_operations);
	if (!bus) {
		kfree (hci);
		kfree (ps);
		return NULL;
	}

	hci->bus = bus;
	bus->hcpriv = (void *) hci;

	return hci;
}
예제 #2
0
파일: tusb.c 프로젝트: 1587/ltp
/*
 * test_find_usbdev
 *	using our driver, attempt to find
 *	a usb device that our driver can use,
 *	and set the pointers in our test interface
 *	structure to the device pointer so that
 *	it can be used future test calls
 */
static int test_find_usbdev()
{
	struct usb_device *udev =
	    (struct usb_device *)kmalloc(sizeof(struct usb_device), GFP_KERNEL);
	struct usb_bus *bus =
	    (struct usb_bus *)kmalloc(sizeof(struct usb_bus), GFP_KERNEL);

	/* Zero out the ltp_usb */
	memset(&ltp_usb, 0, sizeof(tusb_user_t));

	ltp_usb.bus = bus;
	ltp_usb.dev = udev;

	/* allocate the usb_bus pointer */
#if 0
	bus = usb_alloc_bus(&test_device_operations);
	if (!bus) {
		printk("tusb: Did not allocate a bus\n");
		return 1;
	} else {
		printk("tusb: Allocated a bus pointer\n");
		memcpy(ltp_usb.bus, bus, sizeof(struct usb_bus));
		printk("test1\n");
	}

	/* allocate the usb_device pointer */
	udev = usb_alloc_dev(NULL, bus);
	if (udev) {
		printk("tusb: Found a usb device pointer\n");
		memcpy(ltp_usb.dev, udev, sizeof(struct usb_device));
	} else {
		printk("tusb: Failed find usb device pointer\n");
		return 1;
	}

	/* connect the new device and setup pointers */
	usb_connect(udev);
	usb_new_device(udev);
#endif

	return 0;
}
예제 #3
0
int usb_hcd_amba_probe (struct amba_device *dev, void *vid)
{
	int			retval = 0;
	char			buf [8], *bufp = buf;
	struct usb_bus		*bus = NULL;
	struct usb_hcd 		*hcd = NULL;
	void 			*device_base = NULL;
	struct amba_id *id 	= (struct amba_id *)vid;
	struct hc_driver	*driver = (struct hc_driver *)id->data;

#if defined (CONFIG_USB_EHCI_PNX0106) && defined (GPIO_USB_POWER_FAULT)
	init_timer (&timer_check_usb_power_fault);
	timer_check_usb_power_fault.function = check_usb_power_fault_func;
	timer_check_usb_power_fault.data = 0;
#endif
	proc_vbus_init();

	usb2ip_init (dev);

	if (driver->flags & HCD_MEMORY) {	// EHCI, OHCI
		/* map the address (already requested by amba_device) */
		device_base = ioremap_nocache( dev->res.start, dev->res.end - dev->res.start + 1 ) ;
		if ( !device_base ) {
			printk( KERN_ERR "%s: failed to remap the amba registers\n", __FUNCTION__) ;
			return -1 ;
		}
	} else {
		printk (KERN_ERR "%s: tried to allocate i/o memory for UHCI\n", __FUNCTION__);
	}


	hcd = driver->hcd_alloc ();
	if (hcd == NULL) {
		printk(KERN_DEBUG "%s: hcd alloc fail\n", __FUNCTION__);
		retval = -ENOMEM;
clean_1:
		if (driver->flags & HCD_MEMORY) {
			iounmap (device_base);
			device_base = 0;
		}
		printk(KERN_DEBUG "hcd-amba::init usb_amba fail, %d\n", retval);
		goto done;
	}
	// hcd zeroed everything
	hcd->regs = device_base;

	//amba_set_drvdata (dev, hcd);
	hcd->pdev = dev;
	hcd->driver = driver;
	hcd->description = driver->description;

	if (hcd->product_desc == NULL)
		hcd->product_desc = "USB EHCI 1.0 Host Controller (amba)";

	hcd->state = USB_STATE_HALT;

#ifndef __sparc__
	sprintf (buf, "%d", dev->irq[0]);
#else
	bufp = __irq_itoa(dev->irq[0]);
#endif

	/* request the irq (there should be one) */
	retval = request_irq (dev->irq[0], hcd_irq, 0/*SA_SHIRQ*/, "usb_ehci", hcd);
	if (retval) {
		printk(KERN_ERR	"hcd-amba.c :: request interrupt %s failed\n", bufp);
		retval = -EBUSY;
		goto clean_1;
	}
	hcd->irq = dev->irq[0];

	bus = usb_alloc_bus (&hcd_operations);
	if (bus == NULL) {
		printk(KERN_ERR "usb_alloc_bus fail\n");
		retval = -ENOMEM;
		free_irq (dev->irq, hcd);
		goto clean_1;
	}

	hcd->bus = bus;
	strcpy(dev->slot_name, "1");
	bus->bus_name = dev->slot_name;
	bus->hcpriv = (void *) hcd;

	INIT_LIST_HEAD (&hcd->dev_list);
	INIT_LIST_HEAD (&hcd->hcd_list);

	down (&hcd_list_lock);
	list_add (&hcd->hcd_list, &hcd_list);
	up (&hcd_list_lock);

	usb_register_bus (bus);

	if ((retval = driver->start (hcd)) < 0)
		usb_hcd_amba_remove (dev);

done:
	return retval;
}