📄 vivi_usb_drv.h
字号:
/* * Driver for USB of VIVI (linux-2.4.20-8) * * Copyright (C) 2006, thisway.diy@163.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., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include <linux/module.h>#include <linux/kernel.h>#include <linux/errno.h>#include <asm/uaccess.h>#include <linux/init.h>#include <linux/slab.h>#include <linux/delay.h>#include <linux/ioctl.h>#include <linux/sched.h>#include <linux/smp_lock.h>#include <linux/devfs_fs_kernel.h>// #define DEBUG#define DRIVER_VERSION "0.0.1"#define DRIVER_DESC "USB for VIVI Driver, thisway.diy@163.com"#include <linux/usb.h>static __s32 vendor=-1, product=-1, read_timeout=0;MODULE_AUTHOR("thisway.diy@163.com");MODULE_DESCRIPTION(DRIVER_DESC" "DRIVER_VERSION);MODULE_LICENSE("GPL");MODULE_PARM(vendor, "i");MODULE_PARM_DESC(vendor, "User specified USB idVendor");MODULE_PARM(product, "i");MODULE_PARM_DESC(product, "User specified USB idProduct");MODULE_PARM(read_timeout, "i");MODULE_PARM_DESC(read_timeout, "User specified read timeout in seconds");/* WARNING: These DATA_DUMP's can produce a lot of data. Caveat Emptor. */// #define RD_DATA_DUMP /* Enable to dump data - limited to 24 bytes */// #define WR_DATA_DUMP /* DEBUG does not have to be defined. */static struct usb_device_id vivi_s3c2410_device_ids [] = { /* SAMSUNG S3C2410 */ { USB_DEVICE(0x5345, 0x1234) }, /* usb of vivi for s3c2410 */ { } /* Terminating entry */};MODULE_DEVICE_TABLE (usb, vivi_s3c2410_device_ids);#define IS_EP_BULK(ep) ((ep).bmAttributes == USB_ENDPOINT_XFER_BULK ? 1 : 0)#define IS_EP_BULK_IN(ep) (IS_EP_BULK(ep) && ((ep).bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN)#define IS_EP_BULK_OUT(ep) (IS_EP_BULK(ep) && ((ep).bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT)#define IS_EP_INTR(ep) ((ep).bmAttributes == USB_ENDPOINT_XFER_INT ? 1 : 0)#define USB_VIVI_MINOR(X) MINOR((X)->i_rdev) - VIVI_BASE_MNR#ifdef DEBUG#define VIVI_DEBUG(X) X#else#define VIVI_DEBUG(X)#endif#define IBUF_SIZE 4096#define OBUF_SIZE 32768/* read_vivi_s3c2410 timeouts -- RD_NAK_TIMEOUT * RD_EXPIRE = Number of seconds */#define RD_NAK_TIMEOUT (10*HZ) /* Default number of X seconds to wait */#define RD_EXPIRE 12 /* Number of attempts to wait X seconds *//* add by thisway * some kernel doesn't define this struct devrequest */typedef struct { __u8 requesttype; __u8 request; __u16 value; __u16 index; __u16 length;} usb_devrequest __attribute__ ((packed));/* read vendor and product IDs from the vivi_s3c2410 */#define VIVI_IOCTL_VENDOR _IOR('U', 0x20, int)#define VIVI_IOCTL_PRODUCT _IOR('U', 0x21, int)/* send/recv a control message to the vivi_s3c2410 */#define VIVI_IOCTL_CTRLMSG _IOWR('U', 0x22, usb_devrequest )#define VIVI_MAX_MNR 16 /* We're allocated 16 minors */#define VIVI_BASE_MNR 128 /* USB for VIVI start at minor 48 */static DECLARE_MUTEX (vivi_mutex); /* Initializes to unlocked */struct vivi_usb_data { struct usb_device *vivi_dev; devfs_handle_t devfs; /* devfs device */ struct urb vivi_irq; unsigned int ifnum; /* Interface number of the USB device */ kdev_t vivi_minor; /* Scanner minor - used in disconnect() */ unsigned char button; /* Front panel buffer */ char isopen; /* Not zero if the device is open */ char present; /* Not zero if device is present */ char *obuf, *ibuf; /* transfer buffers */ char bulk_in_ep, bulk_out_ep, intr_ep; /* Endpoint assignments */ wait_queue_head_t rd_wait_q; /* read timeouts */ struct semaphore sem; /* lock to prevent concurrent reads or writes */ unsigned int rd_nak_timeout; /* Seconds to wait before read() timeout. */};extern devfs_handle_t usb_devfs_handle;static struct vivi_usb_data *p_vivi_table[VIVI_MAX_MNR] = { NULL, /* ... */};static struct usb_driver vivi_s3c2410_driver;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -