⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbd-bus.c

📁 Linux2.4.20针对三星公司的s3c2440内核基础上的一些设备驱动代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * linux/drivers/usbd/usbd-bus.c - USB Device Prototype * * Copyright (c) 2000, 2001, 2002 Lineo * Copyright (c) 2001 Hewlett Packard * * By:  *      Stuart Lynne <sl@lineo.com>,  *      Tom Rushworth <tbr@lineo.com>,  *      Bruce Balden <balden@lineo.com> * * Changes copyright (c) 2003 MontaVista Software, Inc. * * 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., 675 Mass Ave, Cambridge, MA 02139, USA. * */#include <linux/config.h>#define USBD_CONFIG_NOWAIT_DEREGISTER_DEVICE 1#include <linux/module.h>#include <linux/init.h>#include <linux/kernel.h>#include <linux/list.h>#include <asm/uaccess.h>#include <linux/netdevice.h>#include <linux/skbuff.h>#include <linux/etherdevice.h>#include <net/arp.h>#include <linux/rtnetlink.h>#include <linux/smp_lock.h>#include <linux/ctype.h>#include <linux/timer.h>#include <linux/string.h>#include <linux/atmdev.h>#include <linux/pkt_sched.h>#include "usbd.h"#include "usbd-debug.h"#include "usbd-func.h"#include "usbd-bus.h"#include "usbd-inline.h"extern int usb_devices;extern struct usb_function_driver ep0_driver;extern int registered_functions;extern struct list_head function_drivers;extern struct list_head devices;static __inline__ struct usb_function_driver *list_entry_func (const struct list_head *le){	return list_entry (le, struct usb_function_driver, drivers);}static __inline__ struct usb_device_instance *list_entry_device (const struct list_head *le){	return list_entry (le, struct usb_device_instance, devices);}// Debug stuff - dbgflg_usbdbi_init must be defined in the main part of the bus driver (e.g. *_bi/init.c)int dbgflg_usbdbi_init;EXPORT_SYMBOL(dbgflg_usbdbi_init);#define dbg_init(lvl,fmt,args...) dbgPRINT(dbgflg_usbdbi_init,lvl,fmt,##args)extern int registered_functions;extern int registered_devices;/** * usbd_fill_rcv - fill the rx recyle queue with empty urbs * @endpoint: * * Fill the recycle queue so that receive has some empty urbs to use. */EXPORT_SYMBOL(usbd_fill_rcv);void usbd_fill_rcv (struct usb_device_instance *device, struct usb_endpoint_instance *endpoint,		    int num){	int i;	unsigned buffersize;	dbg_init (1, "endpoint: %d", endpoint->endpoint_address);	if (endpoint->rcv_packetSize) {		// we need to allocate URBs with enough room for the endpoints transfersize plus one rounded 		// up to the next packetsize		buffersize =		    ((endpoint->rcv_transferSize +		      endpoint->rcv_packetSize) / endpoint->rcv_packetSize) *		    endpoint->rcv_packetSize;		dbg_init (1, "endpoint: %d packetSize: %d transferSize: %d buffersize: %d",			  endpoint->endpoint_address, endpoint->rcv_packetSize,			  endpoint->rcv_transferSize, buffersize);                // XXX should we do this here?                usbd_flush_rcv(endpoint);		for (i = 0; i < num; i++) {			usbd_recycle_urb (usbd_alloc_urb					  (device, device->function_instance_array,					   endpoint->endpoint_address, buffersize));		}	} else {		dbg_init (0, "endpoint: %d packetSize is Zero!", endpoint->endpoint_address);	}}/** * usbd_flush_rcv - flush rcv * @endpoint: * * Iterate across the rx list and dispose of any urbs. */EXPORT_SYMBOL(usbd_flush_rcv);void usbd_flush_rcv (struct usb_endpoint_instance *endpoint){	struct urb *rcv_urb = NULL;	unsigned long flags;        dbg_init (1, "endpoint: %d", endpoint->endpoint_address);	if (endpoint) {		local_irq_save (flags);		if ((rcv_urb = endpoint->rcv_urb)) {			endpoint->rcv_urb = NULL;			usbd_dealloc_urb (rcv_urb);		}		while ((rcv_urb = first_urb_detached (&endpoint->rdy))) {			usbd_dealloc_urb (rcv_urb);		}		local_irq_restore (flags);	}}/** * usbd_flush_tx - flush tx urbs from endpoint * @endpoint: * * Iterate across the tx list and cancel any outstanding urbs. */EXPORT_SYMBOL(usbd_flush_tx);void usbd_flush_tx (struct usb_endpoint_instance *endpoint){	struct urb *send_urb = NULL;	unsigned long flags;	if (endpoint) {		local_irq_save (flags);		if ((send_urb = endpoint->tx_urb)) {			endpoint->tx_urb = NULL;			usbd_urb_sent_irq (send_urb, SEND_FINISHED_ERROR);		}		while ((send_urb = first_urb_detached (&endpoint->tx))) {			usbd_urb_sent_irq (send_urb, SEND_FINISHED_ERROR);		}		local_irq_restore (flags);	}}/** * usbd_flush_ep - flush urbs from endpoint * @endpoint: * * Iterate across the approrpiate tx or rcv list and cancel any outstanding urbs. */EXPORT_SYMBOL(usbd_flush_ep);void usbd_flush_ep (struct usb_endpoint_instance *endpoint){	if (endpoint) {		if (endpoint->endpoint_address & 0x7f) {			usbd_flush_tx (endpoint);		} else {			usbd_flush_rcv (endpoint);		}	}}/** * usbd_device_bh -  * @data: * * Bottom half handler to process sent or received urbs. */void usbd_device_bh (void *data){        struct usb_device_instance *device;        if ((device = data)) {                int i;                for (i = 0; i < device->bus->driver->max_endpoints; i++) {                        struct usb_endpoint_instance *endpoint = device->bus->endpoint_array + i;                        // process received urbs                        if (endpoint->endpoint_address                                        && (endpoint->endpoint_address & USB_REQ_DIRECTION_MASK) ==                                        USB_REQ_HOST2DEVICE) {                                struct urb *urb;                                while ((urb = first_urb_detached (&endpoint->rcv))) {                                        if (!urb->function_instance ||                                                         !urb->function_instance->function_driver->ops->recv_urb)                                         {                                                dbg_init (0, "usbd_device_bh: no recv_urb function");                                                usbd_recycle_urb (urb);                                        }                                         else if (urb->function_instance->function_driver->ops->recv_urb (urb)) {                                                // XXX printk(KERN_ERR"usbd_device_bh: recv_urb failed\n");                                                usbd_recycle_urb (urb);                                        }                                }                        }                        // process sent urbs                        if (endpoint->endpoint_address                                        && (endpoint->endpoint_address & USB_REQ_DIRECTION_MASK) ==                                        USB_REQ_DEVICE2HOST) {                                struct urb *urb;                                while ((urb = first_urb_detached (&endpoint->done))) {                                        if (!urb->function_instance ||                                                         !urb->function_instance->function_driver->ops->urb_sent ||                                                         urb->function_instance->function_driver->ops->urb_sent                                                         (urb, urb-> status)                                           )                                        {                                                dbg_init (0, "usbd_device_bh: no urb_sent function");                                                usbd_dealloc_urb (urb);                                        }                                }                        }                }#if defined(CONFIG_SA1100_COLLIE) && defined(CONFIG_PM)                {                        // Please clear autoPowerCancel flag during the transmission and  the reception.                        // XXX XXX extern                         int autoPowerCancel;                        autoPowerCancel = 0;	// Auto Power Off Cancel                }#endif#if defined(CONFIG_SA1110_CALYPSO) && defined(CONFIG_PM)                // Shouldn't need to make this atomic, all we need is a change indicator                device->usbd_rxtx_timestamp = jiffies;#endif                if (device->status == USBD_CLOSING) {                        device->device_bh.data = NULL;                }        }        else {                dbg_init (0, "usbd_device_bh: device NULL");        }}EXPORT_SYMBOL(usbd_device_bh);/** * usbd_function_bh -  * @data: * * Bottom half handler to process events for functions. */void usbd_function_bh (void *data){	// Process control (ep0) events for the function layer.	struct usb_device_instance *device;        if ((device = data)) {		// Pick up endpoint 0.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -