首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

linux 2.6下编译usb驱动和arm板进行数据通信

linux 2.6下编译usb驱动和arm板进行数据通信

linux 2.6下编译usb驱动和arm板进行数据通信

文件原型drivers/usb/misc/usblcd.c

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include <asm/uaccess.h>
#include <linux/usb.h>

#define DRIVER_VERSION "USBLCD Driver Version 1.05"

#define USBLCD_MINOR        144

#define IOCTL_GET_HARD_VERSION    1
#define IOCTL_GET_DRV_VERSION    2


static struct usb_device_id id_table [] = {
    { .idVendor = 0x10D2, .match_flags = USB_DEVICE_ID_MATCH_VENDOR, },
    { .idVendor = 0x8086, .match_flags = USB_DEVICE_ID_MATCH_VENDOR, },//gliethttp_20080527添加自己的vid
    { .idVendor = 0x1286, .match_flags = USB_DEVICE_ID_MATCH_VENDOR, },//gliethttp_20080527添加自己的vid
    { },
};
MODULE_DEVICE_TABLE (usb, id_table);


struct usb_lcd {
    struct usb_device *    udev;            /* init: probe_lcd */
    struct usb_interface *  interface;        /* the interface for this device */
    unsigned char *         bulk_in_buffer;        /* the buffer to receive data */
    size_t            bulk_in_size;        /* the size of the receive buffer */
    __u8            bulk_in_endpointAddr;    /* the address of the bulk in endpoint */
    __u8            bulk_out_endpointAddr;    /* the address of the bulk out endpoint */
    struct kref        kref;
    struct semaphore    limit_sem;        /* to stop writes at full throttle from
                             * using up all RAM */

};
#define to_lcd_dev(d) container_of(d, struct usb_lcd, kref)

#define USB_LCD_CONCURRENT_WRITES    1   //gliethttp_20080527同时允许1个task控制写函数,其他task将阻塞

static struct usb_driver lcd_driver;
static DEFINE_MUTEX(usb_lcd_open_mutex);


static void lcd_delete(struct kref *kref)
{
    struct usb_lcd *dev = to_lcd_dev(kref);

    usb_put_dev(dev->udev);
    kfree (dev->bulk_in_buffer);
    kfree (dev);
}


static int lcd_open(struct inode *inode, struct file *file)
{
    struct usb_lcd *dev;
    struct usb_interface *interface;
    int subminor;
    int retval = 0;

    subminor = iminor(inode);

    mutex_lock(&usb_lcd_open_mutex);
    interface = usb_find_interface(&lcd_driver, subminor);
    if (!interface) {
        err ("USBLCD: %s - error, can't find device for minor %d",
             __FUNCTION__, subminor);
        retval = -ENODEV;
        goto exit;
    }

    dev = usb_get_intfdata(interface);
    if (!dev) {
        retval = -ENODEV;
        goto exit;
    }

    /* increment our usage count for the device */
    kref_get(&dev->kref);

    /* save our object in the file's private structure */
    file->private_data = dev;

exit:
    mutex_unlock(&usb_lcd_open_mutex);
    return retval;
}



继承事业,薪火相传
返回列表