]> rtime.felk.cvut.cz Git - lincan.git/blob - embedded/app/usbcan/ul_usb1.c
hw side seems complete,
[lincan.git] / embedded / app / usbcan / ul_usb1.c
1 /* ul_usb1.c
2  * Linux CAN-bus device driver.
3  * Written by Jan Kriz email:johen@post.cz
4  * This software is released under the GPL-License.
5  * Version lincan-0.3  17 Jun 2004
6  *
7  * Based on
8  *      USB Skeleton driver - 2.2
9  *
10  * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
11  *
12  *      This program is free software; you can redistribute it and/or
13  *      modify it under the terms of the GNU General Public License as
14  *      published by the Free Software Foundation, version 2.
15  *
16  * This driver is based on the 2.6.3 version of drivers/usb/usb-skeleton.c
17  * but has been rewritten to be easier to read and use.
18  *
19  */
20
21 #include "./can/ul_usb1.h"
22 #include "./can/can.h"
23 #include "./can/can_sysdep.h"
24 #include "./can/main.h"
25 #include "./can/devcommon.h"
26 #include "./can/setup.h"
27 // #include "./can/finish.h"
28 #include "./can/i82527.h"
29 //#include "../include/sja1000.h"
30 #include "./can/sja1000p.h"
31
32 #include "./can/errno.h"
33
34 /* Get a minor range for your devices from the usb maintainer */
35 #define USB_SKEL_MINOR_BASE     192
36
37 #define CAN_OP_MASK 0x80
38 #define CAN_OP_READ 0x80
39 #define CAN_OP_WRITE 0x00
40
41
42         /* our private defines. if this grows any larger, use your own .h file */
43 #define MAX_TRANSFER            (PAGE_SIZE - 512)
44 /* MAX_TRANSFER is chosen so that the VM is not stressed by
45    allocations > PAGE_SIZE and the number of packets in a page
46    is an integer 512 is the largest possible packet on EHCI */
47 #define WRITES_IN_FLIGHT        8
48 /* arbitrarily chosen */
49
50 /* Define these values to match your devices */
51 #define USB_SKEL_VENDOR_ID      0xDEAD
52 #define USB_SKEL_PRODUCT_ID     0x1001
53
54 /* table of devices that work with this driver */
55 // static struct usb_device_id ul_usb1_table [] = {
56 //      { USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) },
57 //      { }                                     /* Terminating entry */
58 // };
59 // MODULE_DEVICE_TABLE(usb, ul_usb1_table);
60
61 // extern struct file_operations can_fops;
62
63 // struct ul_usb1_combo {
64 //      struct usb_ul_usb1 * dev;
65 //      struct urb * urb;
66 // };
67
68 /*
69  * IO_RANGE is the io-memory range that gets reserved, please adjust according
70  * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
71  * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
72  */
73 #define IO_RANGE 0x100
74
75 /* Structure to hold all of our device specific stuff */
76 // struct usb_ul_usb1 {
77 //      struct usb_device       *udev;                  /* the usb device for this device */
78 //      struct usb_interface    *interface;             /* the interface for this device */
79 //      struct semaphore        limit_sem;              /* limiting the number of writes in progress */
80 //      struct usb_anchor       submitted;              /* in case we need to retract our submissions */
81 //      unsigned char           *bulk_in_buffer;        /* the buffer to receive data */
82 //      size_t                  bulk_in_size;           /* the size of the receive buffer */
83 //      unsigned char           *int_in_buffer; /* the buffer to receive data */
84 //      size_t                  int_in_size;            /* the size of the receive buffer */
85 //      __u8                    bulk_in_endpointAddr;   /* the address of the bulk in endpoint */
86 //      __u8                    bulk_out_endpointAddr;  /* the address of the bulk out endpoint */
87 //      __u8                    int_in_endpointAddr;    /* the address of the interrupt in endpoint */
88 //      int                             int_in_interval;
89 //      int                     errors;                 /* the last request tanked */
90 //      int                     open_count;             /* count the number of openers */
91 //      spinlock_t              err_lock;               /* lock for errors */
92 //      struct mutex            io_mutex;               /* synchronize I/O with disconnect */
93 //      struct urb              *irq;
94 //      struct candevice_t              *candev;
95 // };
96 //
97 // static struct usb_driver ul_usb1_driver;
98
99 /** ul_usb1_request_io
100  * ul_usb1_request_io: - reserve io or memory range for can board
101  * @candev: pointer to candevice/board which asks for io. Field @io_addr
102  *      of @candev is used in most cases to define start of the range
103  *
104  * The function ul_usb1_request_io() is used to reserve the io-memory. If your
105  * hardware uses a dedicated memory range as hardware control registers you
106  * will have to add the code to reserve this memory as well.
107  * %IO_RANGE is the io-memory range that gets reserved, please adjust according
108  * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
109  * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
110  * Return Value: The function returns zero on success or %-ENODEV on failure
111  * File: src/ul_usb1.c
112  */
113 int ul_usb1_request_io(struct candevice_t *candev)
114 {
115 //      ((struct usb_ul_usb1*)candev->sysdevptr.anydev)->candev=candev;
116         return 0;
117 }
118
119 /** ul_usb1_release_io
120  * ul_usb1_release_io - free reserved io memory range
121  * @candev: pointer to candevice/board which releases io
122  *
123  * The function ul_usb1_release_io() is used to free reserved io-memory.
124  * In case you have reserved more io memory, don't forget to free it here.
125  * IO_RANGE is the io-memory range that gets released, please adjust according
126  * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
127  * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
128  * Return Value: The function always returns zero
129  * File: src/ul_usb1.c
130  */
131 int ul_usb1_release_io(struct candevice_t *candev)
132 {
133 /*      struct usb_ul_usb1 *dev;
134         if (candev->sysdevptr.anydev){
135                 dev=(struct usb_ul_usb1*) candev->sysdevptr.anydev;
136                 usb_put_dev(dev->udev);
137                 usb_kill_urb(dev->irq);
138                 usb_free_urb(dev->irq);
139                 kfree(dev->bulk_in_buffer);
140                 kfree(dev->int_in_buffer);
141                 if (dev->candev){
142                         dev->candev->sysdevptr.anydev=NULL;
143                         //cleanup_usbdev(dev->candev);
144                 }
145                 kfree(dev);
146         }*/
147         return 0;
148 }
149
150 /** ul_usb1_reset
151  * ul_usb1_reset - hardware reset routine
152  * @candev: Pointer to candevice/board structure
153  *
154  * The function ul_usb1_reset() is used to give a hardware reset. This is
155  * rather hardware specific so I haven't included example code. Don't forget to
156  * check the reset status of the chip before returning.
157  * Return Value: The function returns zero on success or %-ENODEV on failure
158  * File: src/ul_usb1.c
159  */
160 int ul_usb1_reset(struct candevice_t *candev)
161 {
162         return 0;
163 }
164
165 #define RESET_ADDR 0x0
166 #define NR_82527 0
167 #define NR_SJA1000 1
168
169 /** ul_usb1_init_hw_data
170  * ul_usb1_init_hw_data - Initialize hardware cards
171  * @candev: Pointer to candevice/board structure
172  *
173  * The function ul_usb1_init_hw_data() is used to initialize the hardware
174  * structure containing information about the installed CAN-board.
175  * %RESET_ADDR represents the io-address of the hardware reset register.
176  * %NR_82527 represents the number of Intel 82527 chips on the board.
177  * %NR_SJA1000 represents the number of Philips sja1000 chips on the board.
178  * The flags entry can currently only be %CANDEV_PROGRAMMABLE_IRQ to indicate that
179  * the hardware uses programmable interrupts.
180  * Return Value: The function always returns zero
181  * File: src/ul_usb1.c
182  */
183 int ul_usb1_init_hw_data(struct candevice_t *candev)
184 {
185         candev->res_addr=RESET_ADDR;
186         candev->nr_82527_chips=NR_82527;
187         candev->nr_sja1000_chips=NR_SJA1000;
188         candev->nr_all_chips=NR_82527+NR_SJA1000;
189         //candev->flags |= CANDEV_PROGRAMMABLE_IRQ;
190
191         return 0;
192 }
193
194 /** ul_usb1_init_chip_data
195  * ul_usb1_init_chip_data - Initialize chips
196  * @candev: Pointer to candevice/board structure
197  * @chipnr: Number of the CAN chip on the hardware card
198  *
199  * The function ul_usb1_init_chip_data() is used to initialize the hardware
200  * structure containing information about the CAN chips.
201  * %CHIP_TYPE represents the type of CAN chip. %CHIP_TYPE can be "i82527" or
202  * "sja1000".
203  * The @chip_base_addr entry represents the start of the 'official' memory map
204  * of the installed chip. It's likely that this is the same as the @io_addr
205  * argument supplied at module loading time.
206  * The @clock entry holds the chip clock value in Hz.
207  * The entry @sja_cdr_reg holds hardware specific options for the Clock Divider
208  * register. Options defined in the %sja1000.h file:
209  * %sjaCDR_CLKOUT_MASK, %sjaCDR_CLK_OFF, %sjaCDR_RXINPEN, %sjaCDR_CBP, %sjaCDR_PELICAN
210  * The entry @sja_ocr_reg holds hardware specific options for the Output Control
211  * register. Options defined in the %sja1000.h file:
212  * %sjaOCR_MODE_BIPHASE, %sjaOCR_MODE_TEST, %sjaOCR_MODE_NORMAL, %sjaOCR_MODE_CLOCK,
213  * %sjaOCR_TX0_LH, %sjaOCR_TX1_ZZ.
214  * The entry @int_clk_reg holds hardware specific options for the Clock Out
215  * register. Options defined in the %i82527.h file:
216  * %iCLK_CD0, %iCLK_CD1, %iCLK_CD2, %iCLK_CD3, %iCLK_SL0, %iCLK_SL1.
217  * The entry @int_bus_reg holds hardware specific options for the Bus
218  * Configuration register. Options defined in the %i82527.h file:
219  * %iBUS_DR0, %iBUS_DR1, %iBUS_DT1, %iBUS_POL, %iBUS_CBY.
220  * The entry @int_cpu_reg holds hardware specific options for the cpu interface
221  * register. Options defined in the %i82527.h file:
222  * %iCPU_CEN, %iCPU_MUX, %iCPU_SLP, %iCPU_PWD, %iCPU_DMC, %iCPU_DSC, %iCPU_RST.
223  * Return Value: The function always returns zero
224  * File: src/ul_usb1.c
225  */
226 int ul_usb1_init_chip_data(struct candevice_t *candev, int chipnr)
227 {
228         /*i82527_fill_chipspecops(candev->chip[chipnr]);*/
229         /*sja1000_fill_chipspecops(candev->chip[chipnr]);*/
230         sja1000p_fill_chipspecops(candev->chip[chipnr]);
231
232         candev->chip[chipnr]->flags|= CHIP_IRQ_CUSTOM;
233
234         candev->chip[chipnr]->chip_base_addr=0;
235         candev->chip[chipnr]->clock = 24000000;
236         candev->chip[chipnr]->int_cpu_reg = iCPU_DSC;
237         candev->chip[chipnr]->int_clk_reg = iCLK_SL1;
238         candev->chip[chipnr]->int_bus_reg = iBUS_CBY;
239         candev->chip[chipnr]->sja_cdr_reg = sjaCDR_CBP | sjaCDR_CLK_OFF;
240         candev->chip[chipnr]->sja_ocr_reg = sjaOCR_MODE_NORMAL |
241                                                                 sjaOCR_TX0_LH;
242
243         return 0;
244 }
245
246 /** ul_usb1_init_obj_data
247  * ul_usb1_init_obj_data - Initialize message buffers
248  * @chip: Pointer to chip specific structure
249  * @objnr: Number of the message buffer
250  *
251  * The function ul_usb1_init_obj_data() is used to initialize the hardware
252  * structure containing information about the different message objects on the
253  * CAN chip. In case of the sja1000 there's only one message object but on the
254  * i82527 chip there are 15.
255  * The code below is for a i82527 chip and initializes the object base addresses
256  * The entry @obj_base_addr represents the first memory address of the message
257  * object. In case of the sja1000 @obj_base_addr is taken the same as the chips
258  * base address.
259  * Unless the hardware uses a segmented memory map, flags can be set zero.
260  * Return Value: The function always returns zero
261  * File: src/ul_usb1.c
262  */
263 int ul_usb1_init_obj_data(struct canchip_t *chip, int objnr)
264 {
265         chip->msgobj[objnr]->obj_base_addr=chip->chip_base_addr+(objnr+1)*0x10;
266
267         return 0;
268 }
269
270 /** ul_usb1_program_irq
271  * ul_usb1_program_irq - program interrupts
272  * @candev: Pointer to candevice/board structure
273  *
274  * The function ul_usb1_program_irq() is used for hardware that uses
275  * programmable interrupts. If your hardware doesn't use programmable interrupts
276  * you should not set the @candevices_t->flags entry to %CANDEV_PROGRAMMABLE_IRQ and
277  * leave this function unedited. Again this function is hardware specific so
278  * there's no example code.
279  * Return value: The function returns zero on success or %-ENODEV on failure
280  * File: src/ul_usb1.c
281  */
282 int ul_usb1_program_irq(struct candevice_t *candev)
283 {
284         return 0;
285 }
286
287 /** ul_usb1_write_register
288  * ul_usb1_write_register - Low level write register routine
289  * @data: data to be written
290  * @address: memory address to write to
291  *
292  * The function ul_usb1_write_register() is used to write to hardware registers
293  * on the CAN chip. You should only have to edit this function if your hardware
294  * uses some specific write process.
295  * Return Value: The function does not return a value
296  * File: src/ul_usb1.c
297  */
298 void ul_usb1_write_register(unsigned data, unsigned long address)
299 {
300         IO1DIR|=0x00FF0000; // Port as output to send data
301         IO1CLR=0x00FF0000; // Clear all data on port
302         // Init
303         SET_OUT_PIN(IO0,P0_SJA1000_RD_PIN);     // Stays high on write
304         SET_OUT_PIN(IO0,P0_SJA1000_WR_PIN); // Stays high on address write
305         SET_OUT_PIN(IO0,P0_SJA1000_CS_PIN); // Sets output buffers to third state
306         for (slowdown=0;slowdown<SJA1000_SCLK;slowdown++);
307         //SET_OUT_PIN(IO0,P0_SJA1000_ALE_PIN); // Start command
308
309         // Set memory address
310         IO1SET=__val2mfld(0x00FF0000,address&0xFF); // Shift data to SJA pins and output them
311         for (slowdown=0;slowdown<SJA1000_SCLK;slowdown++);
312         //CLR_OUT_PIN(IO0,P0_SJA1000_ALE_PIN); // Makes address active
313         CLR_OUT_PIN(IO0,P0_SJA1000_CS_PIN);
314         for (slowdown=0;slowdown<SJA1000_SCLK;slowdown++);
315
316         // Setting data
317         CLR_OUT_PIN(IO0,P0_SJA1000_WR_PIN);
318
319         IO1CLR=0x00FF0000;
320         IO1SET=__val2mfld(0x00FF0000,data&0xFF);
321         for (slowdown=0;slowdown<SJA1000_SCLK;slowdown++);
322         SET_OUT_PIN(IO0,P0_SJA1000_WR_PIN); // Data should be accepted by now
323         SET_OUT_PIN(IO0,P0_SJA1000_CS_PIN);
324         for (slowdown=0;slowdown<SJA1000_SCLK;slowdown++);
325
326 //      struct usb_ul_usb1 *dev;
327 //      int retval;
328 //      int bytes_transferred;
329 //      unsigned char buffer[2];
330 //      buffer[0]=((unsigned char)address & ~CAN_OP_MASK)+CAN_OP_WRITE;
331 //      buffer[1]=(unsigned char)data;
332 //
333 //      dev = (struct usb_ul_usb1 *)candev->sysdevptr.anydev;
334
335 //      mutex_lock(&dev->io_mutex);
336 //      if (!dev) {             /* disconnect() was called */
337 //              CANMSG("Sending %lu:%X : ERR No device\n",address,(uint8_t)data);
338 //              retval = -ENODEV;
339 //              goto exit;
340 //      }
341 //      if (!dev->interface) {          /* disconnect() was called */
342 //              CANMSG("Sending %lu:%X : ERR No interface\n",address,(uint8_t)data);
343 //              retval = -ENODEV;
344 //              goto exit;
345 //      }
346
347         /* do a blocking bulk write to send data to the device */
348 /*      retval = usb_bulk_msg(dev->udev,
349                               usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr),
350                               buffer,
351                               2,
352                               &bytes_transferred, 10000);
353         CANMSG("Sending %lu:%X : retval %d, transferred %d bytes\n",address,(uint8_t)data,retval,bytes_transferred);
354
355 exit:
356         mutex_unlock(&dev->io_mutex);*/
357 }
358
359 /** ul_usb1_read_register
360  * ul_usb1_read_register - Low level read register routine
361  * @address: memory address to read from
362  *
363  * The function ul_usb1_read_register() is used to read from hardware registers
364  * on the CAN chip. You should only have to edit this function if your hardware
365  * uses some specific read process.
366  * Return Value: The function returns the value stored in @address
367  * File: src/ul_usb1.c
368  */
369 unsigned ul_usb1_read_register(unsigned long address)
370 {
371         unsigned data;
372         IO1DIR|=0x00FF0000; // Port as output to set address
373         IO1CLR=0x00FF0000; // Clear all data
374         // Init
375         SET_OUT_PIN(IO0,P0_SJA1000_WR_PIN); // Stays high on read
376         SET_OUT_PIN(IO0,P0_SJA1000_RD_PIN); // Stays high while entering address
377         SET_OUT_PIN(IO0,P0_SJA1000_CS_PIN);
378         for (slowdown=0;slowdown<SJA1000_SCLK;slowdown++);
379         //SET_OUT_PIN(IO0,P0_SJA1000_ALE_PIN);
380
381         // Request memory address
382         IO1SET=__val2mfld(0x00FF0000,address&0xFF);
383         for (slowdown=0;slowdown<SJA1000_SCLK;slowdown++);
384         //CLR_OUT_PIN(IO0,P0_SJA1000_ALE_PIN);
385         CLR_OUT_PIN(IO0,P0_SJA1000_CS_PIN);
386
387         // Get data
388
389         IO1DIR&=~0x00FF0000; // Sets port as input
390         CLR_OUT_PIN(IO0,P0_SJA1000_RD_PIN);
391         for (slowdown=0;slowdown<SJA1000_SCLK;slowdown++);
392         data=__mfld2val(0x00FF0000,IO1PIN);
393         SET_OUT_PIN(IO0,P0_SJA1000_RD_PIN);
394         SET_OUT_PIN(IO0,P0_SJA1000_CS_PIN);
395         for (slowdown=0;slowdown<SJA1000_SCLK;slowdown++);
396         return data;
397
398 //      struct usb_ul_usb1 *dev;
399 //      int retval;
400 //      int bytes_transferred;
401 //      unsigned char buffer[2];
402 //      buffer[0]=((unsigned char)address & ~CAN_OP_MASK)+CAN_OP_READ;
403 //      buffer[1]=0x00;
404 //
405 //      dev = (struct usb_ul_usb1 *)candev->sysdevptr.anydev;
406
407 //      mutex_lock(&dev->io_mutex);
408 //      if (!dev) {             /* disconnect() was called */
409 //              retval = -ENODEV;
410 //              goto exit;
411 //      }
412 //      if (!dev->interface) {          /* disconnect() was called */
413 //              retval = -ENODEV;
414 //              goto exit;
415 //      }
416
417         /* do a blocking bulk write to send data to the device */
418 /*      retval = usb_bulk_msg(dev->udev,
419                               usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr),
420                               buffer,
421                               2,
422                               &bytes_transferred, 10000);
423
424         CANMSG("Requested: %ld : retval %d, transferred %d bytes\n",address,retval,bytes_transferred);
425         if ((retval)||(bytes_transferred!=2)){
426                 retval = -EFAULT;
427                 goto exit;
428         }
429 */
430         /* do a blocking bulk read to get data from the device */
431 //      retval = usb_bulk_msg(dev->udev,
432 //                            usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr),
433 //                            dev->bulk_in_buffer,
434 //                            dev->bulk_in_size,
435 //                            &bytes_transferred, 10000);
436
437         /* if the read was successful, copy the data to userspace */
438 /*      CANMSG("Received %d bytes : %u:%X\n",bytes_transferred,(dev->bulk_in_buffer[0] & 0x7F),dev->bulk_in_buffer[1]);
439         if (!retval) {
440                 if (bytes_transferred!=2)
441                         retval = -EFAULT;
442                 else
443                         retval = dev->bulk_in_buffer[1];
444         }
445
446 exit:
447         mutex_unlock(&dev->io_mutex);
448         return retval;*/
449 }
450
451 /* !!! Don't change this function !!! */
452 int ul_usb1_register(struct hwspecops_t *hwspecops)
453 {
454         hwspecops->request_io = ul_usb1_request_io;
455         hwspecops->release_io = ul_usb1_release_io;
456         hwspecops->reset = ul_usb1_reset;
457         hwspecops->init_hw_data = ul_usb1_init_hw_data;
458         hwspecops->init_chip_data = ul_usb1_init_chip_data;
459         hwspecops->init_obj_data = ul_usb1_init_obj_data;
460         hwspecops->write_register = ul_usb1_write_register;
461         hwspecops->read_register = ul_usb1_read_register;
462         hwspecops->program_irq = ul_usb1_program_irq;
463         return 0;
464 }
465
466
467
468
469 /* --------------------------------------------------------------------------------------------------- */
470
471
472 // static void ul_usb1_irq(struct urb *urb)
473 // {
474 //      struct usb_ul_usb1 *dev = urb->context;
475 //      struct ul_usb1_combo devc;
476 //      int retval;
477 //
478 //      CANMSG("Interrupt poll\n");
479 //
480 //      switch (urb->status) {
481 //      case 0:
482 //              /* success */
483 //              break;
484 //      case -ECONNRESET:
485 //      case -ENOENT:
486 //      case -ESHUTDOWN:
487 //              /* this urb is terminated, clean up */
488 //              CANMSG("%s - urb shutting down with status: %d\n", __FUNCTION__, urb->status);
489 //              return;
490 //      default:
491 //              CANMSG("%s - nonzero urb status received: %d\n", __FUNCTION__, urb->status);
492 //              goto exit;
493 //      }
494 //
495 //      devc.dev = dev;
496 //      devc.urb = urb;
497 //
498 //      dev->candev->chip[0]->chipspecops->irq_handler(0,dev->candev->chip[0]);
499 //      CANMSG("Interrupt caught\n");
500 //
501 //  exit:
502 //      retval = usb_submit_urb (urb, GFP_ATOMIC);
503 //      if (retval)
504 //              CANMSG("%s - usb_submit_urb failed with result %d\n",
505 //                   __FUNCTION__, retval);
506 // }
507
508 // static void ul_usb1_delete(struct usb_ul_usb1 *dev)
509 // {
510 //      usb_put_dev(dev->udev);
511 //      usb_kill_urb(dev->irq);
512 //      usb_free_urb(dev->irq);
513 //      kfree(dev->bulk_in_buffer);
514 //      kfree(dev->int_in_buffer);
515 //      if (dev->candev){
516 //              dev->candev->sysdevptr.anydev=NULL;
517 //              cleanup_usbdev(dev->candev);
518 //      }
519 //      kfree(dev);
520 // }
521
522 // static int ul_usb1_probe(struct usb_interface *interface, const struct usb_device_id *id)
523 // {
524 //      struct usb_ul_usb1 *dev;
525 //      struct usb_host_interface *iface_desc;
526 //      struct usb_endpoint_descriptor *endpoint;
527 //      struct candevice_t *candev;
528 //      size_t buffer_size;
529 //      int i;
530 //      int retval = -ENOMEM;
531 //
532 //      /* allocate memory for our device state and initialize it */
533 //      dev = kzalloc(sizeof(*dev), GFP_KERNEL);
534 //      if (!dev) {
535 //              err("Out of memory");
536 //              goto error;
537 //      }
538 //      sema_init(&dev->limit_sem, WRITES_IN_FLIGHT);
539 //      mutex_init(&dev->io_mutex);
540 //      spin_lock_init(&dev->err_lock);
541 //      init_usb_anchor(&dev->submitted);
542 //
543 // //   dev->udev = usb_get_dev(interface_to_usbdev(interface));
544 //      dev->udev = interface_to_usbdev(interface);
545 //      dev->interface = interface;
546 //
547 //      /* set up the endpoint information */
548 //      /* use only the first bulk-in and bulk-out endpoints */
549 //      iface_desc = interface->cur_altsetting;
550 //      for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
551 //              endpoint = &iface_desc->endpoint[i].desc;
552 //
553 //              if (!dev->bulk_in_endpointAddr &&
554 //                  usb_endpoint_is_bulk_in(endpoint)) {
555 //                      /* we found a bulk in endpoint */
556 //                      buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
557 //                      dev->bulk_in_size = buffer_size;
558 //                      dev->bulk_in_endpointAddr = endpoint->bEndpointAddress;
559 //                      dev->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
560 //                      if (!dev->bulk_in_buffer) {
561 //                              err("Could not allocate bulk_in_buffer");
562 //                              goto error;
563 //                      }
564 //              }
565 //
566 //              if (!dev->bulk_out_endpointAddr &&
567 //                  usb_endpoint_is_bulk_out(endpoint)) {
568 //                      /* we found a bulk out endpoint */
569 //                              dev->bulk_out_endpointAddr = endpoint->bEndpointAddress;
570 //              }
571 //
572 //              if (!dev->int_in_endpointAddr &&
573 //                  usb_endpoint_is_int_in(endpoint)) {
574 //                      /* we found an interrupt in endpoint */
575 //                      buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
576 //                      dev->int_in_size = buffer_size;
577 //                      dev->int_in_endpointAddr = endpoint->bEndpointAddress;
578 //                      dev->int_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
579 //                      dev->int_in_interval = endpoint->bInterval;
580 //                      if (!dev->int_in_buffer) {
581 //                              err("Could not allocate int_in_buffer");
582 //                              goto error;
583 //                      }
584 //              }
585 //      }
586 //      if (!(dev->bulk_in_endpointAddr && dev->bulk_out_endpointAddr && dev->int_in_endpointAddr)) {
587 //              err("Could not find all bulk-in, bulk-out and interrupt endpoints");
588 //              goto error;
589 //      }
590 //
591 //      /* save our data pointer in this interface device */
592 //      usb_set_intfdata(interface, dev);
593 //
594 //      if (main_init_done==1)
595 //              register_usbdev("ul_usb1",(void *) dev);
596 //      else {
597 //              mutex_lock(&usbdev_reg_mutex);
598 //              if (main_init_done==1)
599 //                      register_usbdev("ul_usb1",(void *) dev);
600 //              else {
601 //                      for (i=0;i<MAX_HW_CARDS;i++){
602 //                              if (usbregq[i]==NULL){
603 //                                      usbregq[i]=(struct usbdev_reg_query *)can_checked_malloc(sizeof(struct usbdev_reg_query));
604 //                                      if (!usbregq[i]){
605 //                                              CANMSG("Error allocating usbdev_reg_query");
606 //                                              mutex_unlock(&usbdev_reg_mutex);
607 //                                              goto error;
608 //                                      }
609 //                                      sprintf (usbregq[i]->hwname,"ul_usb1");
610 //                                      usbregq[i]->anydev=(void *) dev;
611 //                                      break;
612 //                              }
613 //                      }
614 //                      if (i==MAX_HW_CARDS){
615 //                              CANMSG("No free space to register new card");
616 //                              mutex_unlock(&usbdev_reg_mutex);
617 //                              goto error;
618 //                      }
619 //              }
620 //              mutex_unlock(&usbdev_reg_mutex);
621 //      }
622 //
623 //      dev->irq = usb_alloc_urb(0, GFP_KERNEL);
624 //      if (!dev->irq){
625 //              CANMSG("Error allocating usb urb\n");
626 //              goto error;
627 //      }
628 //      dev->irq->dev = dev->udev;
629 //      usb_fill_int_urb(dev->irq, dev->udev,
630 //                       usb_rcvintpipe(dev->udev, dev->int_in_endpointAddr),
631 //                       dev->int_in_buffer, dev->int_in_size,
632 //                       ul_usb1_irq, dev, dev->int_in_interval);
633 // /*   usb_fill_bulk_urb(dev->irq, dev->udev,
634 //                       usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr),
635 //                       dev->int_in_buffer, dev->int_in_size,
636 //                       ul_usb1_irq, dev);*/
637 //
638 // /*   dev->irq->transfer_dma = wacom->data_dma;
639 //      dev->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;*/
640 //      retval=usb_submit_urb(dev->irq, GFP_KERNEL);
641 //      if (retval){
642 //              CANMSG("INT URB %d\n",retval);
643 //              return -EIO;
644 //      }else
645 //              CANMSG("INT URB SUCCCESS\n");
646 //
647 //      /* let the user know what node this device is now attached to */
648 //      info("USB Skeleton device now attached");
649 //      return 0;
650 //
651 // error:
652 //              ul_usb1_delete(dev);
653 //      return retval;
654 // }
655
656 // static void ul_usb1_disconnect(struct usb_interface *interface)
657 // {
658 //      struct usb_ul_usb1 *dev;
659 //      int minor = interface->minor;
660 //
661 //      dev = usb_get_intfdata(interface);
662 //      usb_set_intfdata(interface, NULL);
663 //
664 //      /* prevent more I/O from starting */
665 //      mutex_lock(&dev->io_mutex);
666 //      dev->interface = NULL;
667 //      mutex_unlock(&dev->io_mutex);
668 //
669 //      //usb_kill_anchored_urbs(&dev->submitted);
670 //
671 //      ul_usb1_delete(dev);
672 //
673 //      info("USB Skeleton now disconnected");
674 // }
675
676 // static struct usb_driver ul_usb1_driver = {
677 //      .name =         "ul_usb1-can",
678 //      .id_table = ul_usb1_table,
679 //      .probe =        ul_usb1_probe,
680 //      .disconnect =   ul_usb1_disconnect,
681 //      .id_table =     ul_usb1_table,
682 // };
683
684 // int ul_usb1_init(void){
685 //      return usb_register(&ul_usb1_driver);
686 // }
687 //
688 // void ul_usb1_exit(void){
689 //      usb_deregister(&ul_usb1_driver);
690 // }