2 * Header file for the Linux CAN-bus 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 Jul 2008
11 #include <linux/errno.h>
12 #include <linux/init.h>
13 #include <linux/slab.h>
14 #include <linux/kref.h>
15 #include <asm/uaccess.h>
16 #include <linux/usb.h>
17 #include <linux/mutex.h>
19 /* our private defines. if this grows any larger, use your own .h file */
20 #define MAX_TRANSFER (PAGE_SIZE - 512)
21 /* MAX_TRANSFER is chosen so that the VM is not stressed by
22 allocations > PAGE_SIZE and the number of packets in a page
23 is an integer 512 is the largest possible packet on EHCI */
24 #define WRITES_IN_FLIGHT 8
25 /* arbitrarily chosen */
27 /* Define these values to match your devices */
28 #define USBCAN_VENDOR_ID 0xDEAD
29 #define USBCAN_PRODUCT_ID 0x1001
31 #define RESET_ADDR 0x0
34 * IO_RANGE is the io-memory range that gets reserved, please adjust according
35 * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
36 * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
38 #define IO_RANGE 0x100
41 int usbcan_request_io(struct candevice_t *candev);
42 int usbcan_release_io(struct candevice_t *candev);
43 int usbcan_reset(struct candevice_t *candev);
44 int usbcan_init_hw_data(struct candevice_t *candev);
45 int usbcan_init_chip_data(struct candevice_t *candev, int chipnr);
46 int usbcan_init_obj_data(struct canchip_t *chip, int objnr);
47 void usbcan_write_register(unsigned data, unsigned long address);
48 unsigned usbcan_read_register(unsigned long address);
49 int usbcan_program_irq(struct candevice_t *candev);
50 int usbcan_register(struct hwspecops_t *hwspecops);
52 int usbcan_chip_config(struct canchip_t *chip);
53 int usbcan_extended_mask(struct canchip_t *chip, unsigned long code, unsigned long mask);
54 int usbcan_baud_rate(struct canchip_t *chip, int rate, int clock, int sjw,
55 int sampl_pt, int flags);
56 int usbcan_pre_read_config(struct canchip_t *chip, struct msgobj_t *obj);
57 int usbcan_pre_write_config(struct canchip_t *chip, struct msgobj_t *obj,
58 struct canmsg_t *msg);
59 int usbcan_send_msg(struct canchip_t *chip, struct msgobj_t *obj,
60 struct canmsg_t *msg);
61 int usbcan_fill_chipspecops(struct canchip_t *chip);
62 int usbcan_irq_handler(int irq, struct canchip_t *chip);
64 void usbcan_read_kthread(kthread_t *kthread);
65 int usbcan_chip_queue_status(struct canchip_t *chip);
67 int usbcan_init(void);
68 void usbcan_exit(void);
69 static int usbcan_probe(struct usb_interface *interface, const struct usb_device_id *id);
70 static void usbcan_disconnect(struct usb_interface *interface);
72 #ifdef CONFIG_OC_LINCAN_DETAILED_ERRORS
74 static const char *sja1000_ecc_errc_str[]={
81 static const char *sja1000_ecc_seg_str[]={
101 "tolerate dominant bits",
104 "passive error flag",
109 "acknowledge delimiter",
116 #endif /*CONFIG_OC_LINCAN_DETAILED_ERRORS*/
118 /* CAN message over usb */
119 struct usbcan_canmsg_t{
127 /* CAN extended mask */
128 struct usbcan_mask_t{
133 /* Structure to hold all of our device specific stuff */
135 struct usb_device *udev; /* the usb device for this device */
136 struct usb_interface *interface; /* the interface for this device */
137 struct semaphore limit_sem; /* limiting the number of writes in progress */
138 struct usb_anchor submitted; /* in case we need to retract our submissions */
139 unsigned char *bulk_in_buffer; /* the buffer to receive data */
140 unsigned char *ctl_in_buffer; /* the buffer to receive data */
141 size_t bulk_in_size; /* the size of the receive buffer */
142 size_t ctl_in_size; /* the size of the receive buffer */
143 __u8 ctl_in_endpointAddr; /* the address of the bulk in endpoint */
144 __u8 ctl_out_endpointAddr; /* the address of the bulk in endpoint */
145 __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */
146 __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */
147 int errors; /* the last request tanked */
148 int open_count; /* count the number of openers */
149 spinlock_t err_lock; /* lock for errors */
150 struct mutex io_mutex; /* synchronize I/O with disconnect */
152 struct usbcan_canmsg_t rcv_msg;
153 struct usbcan_canmsg_t tx_msg;
154 kthread_t rcvthread; /* usb receive kernel thread */
156 struct candevice_t *candev;
160 #define USBCAN_DATA_READ (1)
161 #define USBCAN_TERMINATE (2)
162 #define USBCAN_ERROR (3)
163 #define USBCAN_TX_PENDING (4)
165 #define USBCAN_VENDOR_BAUD_RATE_SET (1)
166 #define USBCAN_VENDOR_BAUD_RATE_STATUS (2)
167 #define USBCAN_VENDOR_SET_BTREGS (3)
168 #define USBCAN_VENDOR_CHECK_TX_STAT (4)
169 #define USBCAN_VENDOR_START_CHIP (5)
170 #define USBCAN_VENDOR_STOP_CHIP (6)
172 /* table of devices that work with this driver */
173 static struct usb_device_id usbcan_table [] = {
174 { USB_DEVICE(USBCAN_VENDOR_ID, USBCAN_PRODUCT_ID) },
175 { } /* Terminating entry */
177 MODULE_DEVICE_TABLE(usb, usbcan_table);
179 static struct usb_driver usbcan_driver = {
181 .id_table = usbcan_table,
182 .probe = usbcan_probe,
183 .disconnect = usbcan_disconnect,