Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line | 
|---|---|---|---|
| 6 | f9daq | 1 | /************************************************************************\ | 
        
| 2 | ##                                                                      ## | 
        ||
| 3 | ##  Creation Date: 19 Mar 2007                                          ## | 
        ||
| 4 | ##  Last Update:   19 Mar 2007                                          ## | 
        ||
| 5 | ##  Author:       XInstruments                                          ## | 
        ||
| 6 | ##                                                                      ## | 
        ||
| 7 | ##  Desc: Driver main module header.                                    ## | 
        ||
| 8 | ##                                                                      ## | 
        ||
| 9 | \************************************************************************/ | 
        ||
| 10 | |||
| 11 | |||
| 12 | #include        <linux/usb.h> | 
        ||
| 13 | |||
| 14 | |||
| 15 | #define         USMC_DEV_NAME           "8SMC-USB1h" | 
        ||
| 16 | #define         USMC_PRODUCT_ID         0x0230 | 
        ||
| 17 | #define         USMC_VENDOR_ID          0x10c4 | 
        ||
| 18 | #define         USB_USMC_MINOR_BASE     192             // Get a minor range for your devices from the usb maintainer | 
        ||
| 19 | #define         WRITES_IN_FLIGHT        8 | 
        ||
| 20 | #define         USMC_SUCCESS            0 | 
        ||
| 21 | |||
| 22 | |||
| 23 | |||
| 24 | |||
| 25 | // Connect/Disconnect: | 
        ||
| 26 | static int usmc_probe ( struct usb_interface * interface,  | 
        ||
| 27 | const struct usb_device_id * id );  | 
        ||
| 28 | static void usmc_disconnect ( struct usb_interface * interface );  | 
        ||
| 29 | // File operations: | 
        ||
| 30 | static long usmc_ioctl ( struct file * file, unsigned int ioctl_num, unsigned long ioctl_param );  | 
        ||
| 31 | static int usmc_open ( struct inode * inode, struct file * file );  | 
        ||
| 32 | static int usmc_release ( struct inode * inode, struct file * file );  | 
        ||
| 33 | // Util functions: | 
        ||
| 34 | static void usmc_delete ( struct kref * kref );  | 
        ||
| 35 | |||
| 36 | |||
| 37 | static struct usb_device_id usmc_table [] = {  | 
        ||
| 38 | { USB_DEVICE ( USMC_VENDOR_ID, USMC_PRODUCT_ID ) },  | 
        ||
| 39 | {} // Terminating element.  | 
        ||
| 40 | };  | 
        ||
| 41 | |||
| 42 | |||
| 43 | static struct usb_driver usmc_driver = {  | 
        ||
| 44 | .name = USMC_DEV_NAME,  | 
        ||
| 45 | .probe = usmc_probe,  | 
        ||
| 46 | .disconnect = usmc_disconnect,  | 
        ||
| 47 | .id_table = usmc_table  | 
        ||
| 48 | };  | 
        ||
| 49 | |||
| 50 | |||
| 51 | /* Structure to hold all of our device specific stuff */ | 
        ||
| 52 | struct usb_usmc | 
        ||
| 53 | { | 
        ||
| 54 | struct usb_device * udev; /* the usb device for this device */  | 
        ||
| 55 | struct usb_interface * interface; /* the interface for this device */  | 
        ||
| 56 | struct semaphore limit_sem; /* limiting the number of writes in progress */  | 
        ||
| 57 | //      unsigned char        * bulk_in_buffer;          /* the buffer to receive data */ | 
        ||
| 58 | //      size_t                 bulk_in_size;            /* the size of the receive buffer */ | 
        ||
| 59 | //      __u8                   bulk_in_endpointAddr;    /* the address of the bulk in endpoint */ | 
        ||
| 60 | //      __u8                   bulk_out_endpointAddr;   /* the address of the bulk out endpoint */ | 
        ||
| 61 | struct kref kref;  | 
        ||
| 62 | };  | 
        ||
| 63 | |||
| 64 | #define to_usmc_dev(d) container_of(d, struct usb_usmc, kref) | 
        ||
| 65 | |||
| 66 | |||
| 67 | static struct file_operations usmc_fops = {  | 
        ||
| 68 | .owner = THIS_MODULE,  | 
        ||
| 69 | /*      .read    = usmc_read, | 
        ||
| 70 |         .write   = usmc_write,*/ | 
        ||
| 71 | .open = usmc_open,  | 
        ||
| 72 | .release = usmc_release,  | 
        ||
| 73 | .unlocked_ioctl = usmc_ioctl  | 
        ||
| 74 | };  | 
        ||
| 75 | |||
| 76 | /* | 
        ||
| 77 | struct file_operations { | 
        ||
| 78 |         struct module *owner; | 
        ||
| 79 |         loff_t (*llseek) (struct file *, loff_t, int); | 
        ||
| 80 |         ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); | 
        ||
| 81 |         ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); | 
        ||
| 82 |         ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t); | 
        ||
| 83 |         ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t); | 
        ||
| 84 |         int (*readdir) (struct file *, void *, filldir_t); | 
        ||
| 85 |         unsigned int (*poll) (struct file *, struct poll_table_struct *); | 
        ||
| 86 |         long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); | 
        ||
| 87 |    ..... | 
        ||
| 88 | */ | 
        ||
| 89 | |||
| 90 | |||
| 91 | /* | 
        ||
| 92 |  * usb class driver info in order to get a minor number from the usb core, | 
        ||
| 93 |  * and to have the device registered with the driver core | 
        ||
| 94 |  */ | 
        ||
| 95 | static struct usb_class_driver usmc_class = {  | 
        ||
| 96 | .name = "usmc%d",  | 
        ||
| 97 | .fops = &usmc_fops,  | 
        ||
| 98 | .minor_base = USB_USMC_MINOR_BASE  | 
        ||
| 99 | };  |