Chinaunix首页 | 论坛 | 博客
  • 博客访问: 260850
  • 博文数量: 49
  • 博客积分: 1684
  • 博客等级: 上尉
  • 技术积分: 458
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-09 22:45
文章分类

全部博文(49)

文章存档

2023年(1)

2021年(2)

2018年(2)

2017年(7)

2016年(2)

2015年(6)

2014年(13)

2013年(7)

2012年(7)

2011年(1)

2010年(1)

分类: LINUX

2014-09-06 16:29:37

主要作用是何2410上的usb device对接,然后往2410上读写数据的

这个是PC上linux下的驱动代码:

点击(此处)折叠或打开

  1. /*
  2.  * USB led driver - 0.1
  3.  *
  4.  * Copyright (C) 2001-2004 Alex Woo (lelee1949@163.com)
  5.  *
  6.  *    This program is free software; you can redistribute it and/or
  7.  *    modify it under the terms of the GNU General Public License as
  8.  *    published by the Free Software Foundation, version 0.1.
  9.  *
  10.  * This driver is based on the 2.6.3 version of drivers/usb/usb-usbdeton.c
  11.  * just be written to light the led to test the firmware of
  12.  * s3c2410 usb device controller.
  13.  *
  14.  */

  15. #include <linux/kernel.h>
  16. #include <linux/errno.h>
  17. #include <linux/init.h>
  18. #include <linux/slab.h>
  19. #include <linux/module.h>
  20. #include <linux/kref.h>
  21. #include <asm/uaccess.h>
  22. #include <linux/usb.h>
  23. #include <linux/mutex.h>

  24. #include <linux/types.h>
  25. #include <linux/miscdevice.h>
  26. #include <linux/ioport.h>
  27. #include <linux/fcntl.h>
  28. #include <asm/io.h>
  29. //#include <mach/regs-gpio.h>
  30. #include <linux/device.h> /* creat_class() */
  31. #include <linux/cdev.h>
  32. //#include <mach/regs-gpio.h>




  33. /* Define these values to match your devices */
  34. #define USBD_2410_VENDOR_ID    0x5345
  35. #define USBD_2410_PRODUCT_ID    0x1234

  36. /* table of devices that work with this driver */
  37. static struct usb_device_id usbd_2410_table [] = {
  38.     { USB_DEVICE(USBD_2410_VENDOR_ID, USBD_2410_PRODUCT_ID) },
  39.     { }                    /* Terminating entry */
  40. };
  41. MODULE_DEVICE_TABLE(usb, usbd_2410_table);


  42. /* Get a minor range for your devices from the usb maintainer */
  43. //#define USB_SKEL_MINOR_BASE    192
  44. //#define USBD2410_MAJOR 0//不使用USB的主设备号,申请动态分配一个主设备号,字符设备
  45. #define    usbd2410_major 0
  46. int        usbd2410_devno;
  47. /* our private defines. if this grows any larger, use your own .h file */
  48. #define MAX_TRANSFER        (PAGE_SIZE - 512)
  49. /* MAX_TRANSFER is chosen so that the VM is not stressed by
  50.    allocations > PAGE_SIZE and the number of packets in a page
  51.    is an integer 512 is the largest possible packet on EHCI */
  52. #define WRITES_IN_FLIGHT    8
  53. /* arbitrarily chosen */

  54. struct class *usbled_class;

  55. /* Structure to hold all of our device specific stuff */
  56. struct usbd_2410 {
  57.     struct usb_device    *udev;            /* the usb device for this device */
  58.                         //看看程序中udev都用来作什么用,
  59.                         //如果是一个普通的USB接口的字符设备,usb_device有木有必要!!!
  60.     struct usb_interface    *interface;        /* the interface for this device */
  61.     struct semaphore    limit_sem;        /* limiting the number of writes in progress */
  62.     struct usb_anchor    submitted;        /* in case we need to retract our submissions */
  63.     unsigned char *bulk_in_buffer;    /* the buffer to receive data */
  64.     size_t            bulk_in_size;        /* the size of the receive buffer */
  65.     __u8            bulk_in_endpointAddr;    /* the address of the bulk in endpoint */
  66.     __u8            bulk_out_endpointAddr;    /* the address of the bulk out endpoint */
  67.     int            errors;            /* the last request tanked */
  68.     int            open_count;        /* count the number of openers */
  69.     spinlock_t        err_lock;        /* lock for errors */
  70.     struct kref        kref;
  71.     struct mutex        io_mutex;        /* synchronize I/O with disconnect */

  72.     //added by lelee for led
  73.     struct cdev led_dev;
  74.     unsigned int led_value;
  75. };
  76. #define to_usbd_dev(d) container_of(d, struct usbd_2410, kref)

  77. static struct usb_driver usbd_driver;
  78. static void usbd_draw_down(struct usbd_2410 *dev);

  79. static void usbd_delete(struct kref *kref)
  80. {
  81.     struct usbd_2410 *dev = to_usbd_dev(kref);

  82.     usb_put_dev(dev->udev);
  83.     kfree(dev->bulk_in_buffer);
  84.     kfree(dev);
  85. }

  86. static int usbd_open(struct inode *inode, struct file *file)
  87. {
  88.     struct usbd_2410 *dev;
  89.     struct usb_interface *interface;
  90.     int subminor;
  91.     int retval = 0;

  92.     subminor = iminor(inode);

  93.     interface = usb_find_interface(&usbd_driver, subminor);
  94.     if (!interface) {
  95.         err ("%s - error, can't find device for minor %d",
  96.          __func__, subminor);
  97.         retval = -ENODEV;
  98.         goto exit;
  99.     }

  100.     dev = usb_get_intfdata(interface);
  101.     if (!dev) {
  102.         retval = -ENODEV;
  103.         goto exit;
  104.     }

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

  107.     /* lock the device to allow correctly handling errors
  108.      * in resumption */
  109.     mutex_lock(&dev->io_mutex);

  110.     if (!dev->open_count++) {
  111.         retval = usb_autopm_get_interface(interface);
  112.             if (retval) {
  113.                 dev->open_count--;
  114.                 mutex_unlock(&dev->io_mutex);
  115.                 kref_put(&dev->kref, usbd_delete);
  116.                 goto exit;
  117.             }
  118.     } /* else { //uncomment this block if you want exclusive open
  119.         retval = -EBUSY;
  120.         dev->open_count--;
  121.         mutex_unlock(&dev->io_mutex);
  122.         kref_put(&dev->kref, usbd_delete);
  123.         goto exit;
  124.     } */
  125.     /* prevent the device from being autosuspended */

  126.     /* save our object in the file's private structure */
  127.     file->private_data = dev;
  128.     mutex_unlock(&dev->io_mutex);

  129. exit:
  130.     return retval;
  131. }

  132. static int usbd_release(struct inode *inode, struct file *file)
  133. {
  134.     struct usbd_2410 *dev;

  135.     dev = (struct usbd_2410 *)file->private_data;
  136.     if (dev == NULL)
  137.         return -ENODEV;

  138.     /* allow the device to be autosuspended */
  139.     mutex_lock(&dev->io_mutex);
  140.     if (!--dev->open_count && dev->interface)
  141.         usb_autopm_put_interface(dev->interface);
  142.     mutex_unlock(&dev->io_mutex);

  143.     /* decrement the count on our device */
  144.     kref_put(&dev->kref, usbd_delete);
  145.     return 0;
  146. }

  147. static int usbd_flush(struct file *file, fl_owner_t id)
  148. {
  149.     struct usbd_2410 *dev;
  150.     int res;

  151.     dev = (struct usbd_2410 *)file->private_data;
  152.     if (dev == NULL)
  153.         return -ENODEV;

  154.     /* wait for io to stop */
  155.     mutex_lock(&dev->io_mutex);
  156.     usbd_draw_down(dev);

  157.     /* read out errors, leave subsequent opens a clean slate */
  158.     spin_lock_irq(&dev->err_lock);
  159.     res = dev->errors ? (dev->errors == -EPIPE ? -EPIPE : -EIO) : 0;
  160.     dev->errors = 0;
  161.     spin_unlock_irq(&dev->err_lock);

  162.     mutex_unlock(&dev->io_mutex);

  163.     return res;
  164. }

  165. static ssize_t usbd_read(struct file *file, char *buffer, size_t count, loff_t *ppos)
  166. {
  167.     struct usbd_2410 *dev;
  168.     int retval;
  169.     int bytes_read;

  170.     dev = (struct usbd_2410 *)file->private_data;

  171.     mutex_lock(&dev->io_mutex);
  172.     if (!dev->interface) {        /* disconnect() was called */
  173.         retval = -ENODEV;
  174.         goto exit;
  175.     }

  176.     /* do a blocking bulk read to get data from the device */
  177.     retval = usb_bulk_msg(dev->udev,
  178.              usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr),
  179.              dev->bulk_in_buffer,
  180.              min(dev->bulk_in_size, count),
  181.              &bytes_read, 10000);

  182.     /* if the read was successful, copy the data to userspace */
  183.     if (!retval) {
  184.         if (copy_to_user(buffer, dev->bulk_in_buffer, bytes_read))
  185.             retval = -EFAULT;
  186.         else
  187.             retval = bytes_read;
  188.     }

  189. exit:
  190.     mutex_unlock(&dev->io_mutex);
  191.     return retval;
  192. }

  193. static void usbd_write_bulk_callback(struct urb *urb)
  194. {
  195.     struct usbd_2410 *dev;

  196.     dev = urb->context;

  197.     /* sync/async unlink faults aren't errors */
  198.     if (urb->status) {
  199.         if(!(urb->status == -ENOENT ||
  200.          urb->status == -ECONNRESET ||
  201.          urb->status == -ESHUTDOWN))
  202.             err("%s - nonzero write bulk status received: %d",
  203.              __func__, urb->status);

  204.         spin_lock(&dev->err_lock);
  205.         dev->errors = urb->status;
  206.         spin_unlock(&dev->err_lock);
  207.     }

  208.     /* free up our allocated buffer */
  209.     usb_buffer_free(urb->dev, urb->transfer_buffer_length,
  210.             urb->transfer_buffer, urb->transfer_dma);
  211.     up(&dev->limit_sem);
  212. }

  213. static ssize_t usbd_write(struct file *file, const char *user_buffer, size_t count, loff_t *ppos)
  214. {
  215.     struct usbd_2410 *dev;
  216.     int retval = 0;
  217.     struct urb *urb = NULL;
  218.     char *buf = NULL;
  219.     size_t writesize = min(count, (size_t)MAX_TRANSFER);
  220.     printk(KERN_ALERT"the num of bytes to usbd_write is:%u\n", count);
  221.     printk(KERN_ALERT"the num of bytes been sent to usbd2410 is:%u\n", writesize);


  222.     dev = (struct usbd_2410 *)file->private_data;

  223.     /* verify that we actually have some data to write */
  224.     if (count == 0)
  225.         goto exit;

  226.     /* limit the number of URBs in flight to stop a user from using up all RAM */
  227.     if (down_interruptible(&dev->limit_sem)) {
  228.         retval = -ERESTARTSYS;
  229.         goto exit;
  230.     }

  231.     spin_lock_irq(&dev->err_lock);
  232.     if ((retval = dev->errors) < 0) {
  233.         /* any error is reported once */
  234.         dev->errors = 0;
  235.         /* to preserve notifications about reset */
  236.         retval = (retval == -EPIPE) ? retval : -EIO;
  237.     }
  238.     spin_unlock_irq(&dev->err_lock);
  239.     if (retval < 0)
  240.         goto error;

  241.     /* create a urb, and a buffer for it, and copy the data to the urb */
  242.     urb = usb_alloc_urb(0, GFP_KERNEL);
  243.     if (!urb) {
  244.         retval = -ENOMEM;
  245.         goto error;
  246.     }

  247.     buf = usb_buffer_alloc(dev->udev, writesize, GFP_KERNEL, &urb->transfer_dma);
  248.     if (!buf) {
  249.         retval = -ENOMEM;
  250.         goto error;
  251.     }

  252.     if (copy_from_user(buf, user_buffer, writesize)) {
  253.         retval = -EFAULT;
  254.         goto error;
  255.     }
  256.     //
  257.     printk(KERN_ALERT"The user_buffer's data is %u,%u,%u\n", user_buffer[0],user_buffer[1],user_buffer[2]);
  258.     printk(KERN_ALERT"The kernel_buff's data is %u,%u,%u\n", buf[0],buf[1],buf[2]);


  259.     /* this lock makes sure we don't submit URBs to gone devices */
  260.     mutex_lock(&dev->io_mutex);
  261.     if (!dev->interface) {        /* disconnect() was called */
  262.         mutex_unlock(&dev->io_mutex);
  263.         retval = -ENODEV;
  264.         goto error;
  265.     }

  266.     /* initialize the urb properly */
  267.     usb_fill_bulk_urb(urb, dev->udev,
  268.              usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr),
  269.              buf, writesize, usbd_write_bulk_callback, dev);
  270.     urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  271.     usb_anchor_urb(urb, &dev->submitted);

  272.     printk(KERN_ALERT"----------after fill urb----------\n" );

  273.     printk(KERN_ALERT"The user_buffer's data is %u,%u,%u", user_buffer[0],user_buffer[1],user_buffer[2]);
  274.     printk(KERN_ALERT"The kernel_buff's data is %u,%u,%u", buf[0],buf[1],buf[2]);



  275.     /* send the data out the bulk port */
  276.     retval = usb_submit_urb(urb, GFP_KERNEL);


  277.     printk(KERN_ALERT"=================after submit the urb===============\n");

  278.     printk(KERN_ALERT"The user_buffer's data is %u,%u,%u\n", user_buffer[0],user_buffer[1],user_buffer[2]);
  279.     printk(KERN_ALERT"The kernel_buff's data is %u,%u,%u\n", buf[0],buf[1],buf[2]);



  280.     mutex_unlock(&dev->io_mutex);
  281.     if (retval) {
  282.         err("%s - failed submitting write urb, error %d", __func__, retval);
  283.         goto error_unanchor;
  284.     }

  285.     /* release our reference to this urb, the USB core will eventually free it entirely */
  286.     usb_free_urb(urb);


  287.     return writesize;

  288. error_unanchor:
  289.     usb_unanchor_urb(urb);
  290. error:
  291.     if (urb) {
  292.         usb_buffer_free(dev->udev, writesize, buf, urb->transfer_dma);
  293.         usb_free_urb(urb);
  294.     }
  295.     up(&dev->limit_sem);

  296. exit:
  297.     return retval;
  298. }

  299. static const struct file_operations usbd_fops = {
  300.     .owner =    THIS_MODULE,
  301.     .read =        usbd_read,
  302.     .write =    usbd_write,
  303.     .open =        usbd_open,
  304.     .release =    usbd_release,
  305.     .flush =    usbd_flush,
  306. };

  307. /*
  308.  * usb class driver info in order to get a minor number from the usb core,
  309.  * and to have the device registered with the driver core
  310.  */
  311. /*
  312. static struct usb_class_driver usbd_class = {
  313.     .name =        "usbd%d",
  314.     .fops =        &usbd_fops,
  315.     .minor_base =    USB_SKEL_MINOR_BASE,//lelee
  316. };
  317. */


  318. static int usbd_probe(struct usb_interface *interface, const struct usb_device_id *id)
  319. {
  320.     struct usbd_2410 *dev;
  321.     struct usb_host_interface *iface_desc;
  322.     struct usb_endpoint_descriptor *endpoint;
  323.     size_t buffer_size;
  324.     int i;
  325.     int retval = -ENOMEM;

  326.     /* allocate memory for our device state and initialize it */
  327.     dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  328.     if (!dev) {
  329.         err("Out of memory");
  330.         goto error;
  331.     }
  332.     kref_init(&dev->kref);
  333.     sema_init(&dev->limit_sem, WRITES_IN_FLIGHT);
  334.     mutex_init(&dev->io_mutex);
  335.     spin_lock_init(&dev->err_lock);
  336.     init_usb_anchor(&dev->submitted);

  337.     dev->udev = usb_get_dev(interface_to_usbdev(interface));//usb_get_dev()就是为了看看usb_device->dev(device结构)是否为空
  338.     dev->interface = interface;

  339.     /* set up the endpoint information */
  340.     /* use only the first bulk-in and bulk-out endpoints */
  341.     iface_desc = interface->cur_altsetting;
  342.     for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
  343.         endpoint = &iface_desc->endpoint[i].desc;

  344.         if (!dev->bulk_in_endpointAddr &&
  345.          usb_endpoint_is_bulk_in(endpoint)) {
  346.             /* we found a bulk in endpoint */
  347.             buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
  348.             dev->bulk_in_size = buffer_size;
  349.             dev->bulk_in_endpointAddr = endpoint->bEndpointAddress;
  350.             dev->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
  351.             if (!dev->bulk_in_buffer) {
  352.                 err("Could not allocate bulk_in_buffer");
  353.                 goto error;
  354.             }
  355.         }

  356.         if (!dev->bulk_out_endpointAddr &&
  357.          usb_endpoint_is_bulk_out(endpoint)) {
  358.             /* we found a bulk out endpoint */
  359.             dev->bulk_out_endpointAddr = endpoint->bEndpointAddress;
  360.         }
  361.     }
  362.     if (!(dev->bulk_in_endpointAddr && dev->bulk_out_endpointAddr)) {
  363.         err("Could not find both bulk-in and bulk-out endpoints");
  364.         goto error;
  365.     }

  366.     /* save our data pointer in this interface device */
  367.     usb_set_intfdata(interface, dev);
  368. //看看usb_serial的设备注册里边,需不需要设置接口!!!lelee001

  369.     
  370.     /*
  371.      * we can register the device now, as it is ready /
  372.     retval = usb_register_dev(interface, &usbd_class);
  373.     //设备注册,此处需要改成字符设备的注册,调用cdev_add!!!lelee002
  374.     if (retval) {
  375.         // something prevented us from registering this driver
  376.         err("Not able to get a minor for this device.");
  377.         usb_set_intfdata(interface, NULL);
  378.         goto error;
  379.     }
  380.     */
  381.     //led作为字符设备的注册
  382.     //led作为字符设备的注册
  383.     //led作为字符设备的注册
  384.     //led作为字符设备的注册
  385.     //led作为字符设备的注册
  386.     //led作为字符设备的注册
  387.     //led作为字符设备的注册
  388.     //led作为字符设备的注册
  389.     //led作为字符设备的注册
  390.     //led作为字符设备的注册
  391.     int usbd_major;
  392.     dev_t devnumb = MKDEV(usbd2410_major, 0);

  393.     if(usbd2410_major)
  394.         retval = register_chrdev_region(devnumb, 1, "USB-LED");
  395.     else
  396.     {
  397.         retval = alloc_chrdev_region(&devnumb, 0, 1, "USB-LED");
  398.         usbd_major = MAJOR(devnumb);
  399.         usbd2410_devno = MKDEV(usbd_major,0);//生成设备号,以备驱动模块退出注销时使用
  400.     }
  401.     if(retval<0)
  402.         goto err_devno;

  403.     memset(&dev->led_dev, 0, sizeof(struct cdev));//将dev结构(struct usbd_2410)中的struct cdev led_dev区域清零
  404.     cdev_init(&dev->led_dev, &usbd_fops);
  405.     dev->led_dev.owner = THIS_MODULE;
  406.     dev->led_dev.ops = &usbd_fops;

  407.     retval = cdev_add(&dev->led_dev, usbd2410_devno, 1);
  408.     if(retval)
  409.         printk(KERN_NOTICE"Error %d adding LED %d ", retval, 0);

  410.     usbled_class = class_create(THIS_MODULE, "USB-LED");
  411.     if(IS_ERR(usbled_class))
  412.     {
  413.         printk(KERN_NOTICE"failed to create usbled_class!!!-lelee");
  414.         return -1;//fuck the mumu!!!直接返回吧,分配的内存什么的,不用去管了,反正那又没出错
  415.     }

  416.     device_create(usbled_class, NULL, devnumb, NULL, "USB-LED");

  417.     //led作为字符设备的注册
  418.     //led作为字符设备的注册
  419.     //led作为字符设备的注册
  420.     //led作为字符设备的注册
  421.     //led作为字符设备的注册
  422.     //led作为字符设备的注册
  423.     //led作为字符设备的注册
  424.     //led作为字符设备的注册
  425.     //led作为字符设备的注册
  426.     //led作为字符设备的注册

  427.     /* let the user know what node this device is now attached to */
  428.     info("USB Skeleton device now attached to USBSkel-%d", interface->minor);
  429.     return 0;

  430. //////////////////////////////////////////////////////////////////////////////////////
  431. err_devno:
  432.     kref_put(&dev->kref, usbd_delete);
  433.     return retval;//返回错误号

  434. error:
  435.     if (dev)
  436.         /* this frees allocated memory */
  437.         kref_put(&dev->kref, usbd_delete);
  438.     return retval;
  439. //////////////////////////////////////////////////////////////////////////////////////
  440. }

  441. static void usbd_disconnect(struct usb_interface *interface)
  442. {
  443.     struct usbd_2410 *dev;
  444.     int minor = interface->minor;

  445.     dev = usb_get_intfdata(interface);//在此之前,应该是已经将open里边打开的那个usbd_2410类型的dev结构赋给interface->dev->driver_data了,然后可以由此再获得他,所以后面的注销完全可以由该dev来获取已注册的cdev类型的led_dev结构
  446.     usb_set_intfdata(interface, NULL);

  447.     /* give back our minor */
  448.     //usb_deregister_dev(interface, &usbd_class);
  449.     //注销我们的字符设备,应用程序里边根据设备文件是否存在来判断USB是否已经插入
  450.     cdev_del(&dev->led_dev);//此处的dev是打开函数中赋予private的那个dev么?如果不是,应该其中不包含led_dev
  451.     unregister_chrdev_region(MKDEV(usbd2410_major, 0), 1);
  452.     device_destroy(usbled_class, usbd2410_devno);
  453.     class_destroy(usbled_class);
  454.     //注销完毕,每次USB设备拔出以后,驱动就将已注册的字符设备也注销;
  455.     //当系统检测到USB设备插入或者再次插入的时候,再重新注册一次字符设备
  456.     //-----++++-----++++-----
  457.     //OK啦,至此,USB接口的字符型设备的驱动完美啦
  458.     //-----++++-----++++-----



  459.     /* prevent more I/O from starting */
  460.     mutex_lock(&dev->io_mutex);
  461.     dev->interface = NULL;
  462.     mutex_unlock(&dev->io_mutex);

  463.     usb_kill_anchored_urbs(&dev->submitted);

  464.     /* decrement our usage count */
  465.     kref_put(&dev->kref, usbd_delete);

  466.     info("USB Skeleton #%d now disconnected", minor);
  467. }

  468. static void usbd_draw_down(struct usbd_2410 *dev)
  469. {
  470.     int time;

  471.     time = usb_wait_anchor_empty_timeout(&dev->submitted, 1000);
  472.     if (!time)
  473.         usb_kill_anchored_urbs(&dev->submitted);
  474. }

  475. static int usbd_suspend(struct usb_interface *intf, pm_message_t message)
  476. {
  477.     struct usbd_2410 *dev = usb_get_intfdata(intf);

  478.     if (!dev)
  479.         return 0;
  480.     usbd_draw_down(dev);
  481.     return 0;
  482. }

  483. static int usbd_resume (struct usb_interface *intf)
  484. {
  485.     return 0;
  486. }

  487. static int usbd_pre_reset(struct usb_interface *intf)
  488. {
  489.     struct usbd_2410 *dev = usb_get_intfdata(intf);

  490.     mutex_lock(&dev->io_mutex);
  491.     usbd_draw_down(dev);

  492.     return 0;
  493. }

  494. static int usbd_post_reset(struct usb_interface *intf)
  495. {
  496.     struct usbd_2410 *dev = usb_get_intfdata(intf);

  497.     /* we are sure no URBs are active - no locking needed */
  498.     dev->errors = -EPIPE;
  499.     mutex_unlock(&dev->io_mutex);

  500.     return 0;
  501. }

  502. static struct usb_driver usbd_driver = {
  503.     .name =        "usbd_2410",
  504.     .probe =    usbd_probe,
  505.     .disconnect =    usbd_disconnect,
  506.     .suspend =    usbd_suspend,
  507.     .resume =    usbd_resume,
  508.     .pre_reset =    usbd_pre_reset,
  509.     .post_reset =    usbd_post_reset,
  510.     .id_table =    usbd_2410_table,
  511.     .supports_autosuspend = 1,
  512. };

  513. static int __init usbd_2410_init(void)
  514. {
  515.     int result;

  516.     /* register this driver with the USB subsystem */
  517.     result = usb_register(&usbd_driver);
  518.     if (result)
  519.         err("usb_register failed. Error number %d", result);

  520.     return result;
  521. }

  522. static void __exit usbd_2410_exit(void)
  523. {
  524.     /* deregister this driver with the USB subsystem */
  525.     usb_deregister(&usbd_driver);
  526. }

  527. module_init(usbd_2410_init);
  528. module_exit(usbd_2410_exit);

  529. MODULE_LICENSE("GPL");
这个当时是练手USB驱动做的,记得当时有一个《linux那些事之我是USB》的读书活动,刚好那阵子在研究USB,当时已经把USB协议基本研究透了,刚好又赶上那个读书活动,于是申请了书,回来一通饱读,然后就跃跃欲试要搞linux驱动,然后发现那本书还真的是挺有用。于是很快程序就基本调通了,后来发现居然能当一个很顺手的小工具,每次需要验证什么东东,在PC上通过USB发数据到2410上,然后2410上加载哥命令解析的操作,然后就可以控制2410干各种想干的事情了。主要是因为当时2410裸奔的一些程序没做好,后来想想,其实完全可以通过串口发同样的命令,哈哈

2410上的固件代码当时记得是移植的三爽的代码,然后做了一些修改

阅读(1177) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~