]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/include/usbcan.h
2d580fb3424ddde470f5f62edd6ff2df1a6be672
[lincan.git] / lincan / include / usbcan.h
1 /* usbcan.h
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
6  */
7
8 #ifndef USBCAN_H
9 #define USBCAN_H
10
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>
18
19 #include "../include/kthread.h"
20
21 /* our private defines. if this grows any larger, use your own .h file */
22 #define MAX_TRANSFER            (PAGE_SIZE - 512)
23 /* MAX_TRANSFER is chosen so that the VM is not stressed by
24    allocations > PAGE_SIZE and the number of packets in a page
25    is an integer 512 is the largest possible packet on EHCI */
26 #define WRITES_IN_FLIGHT        8
27 /* arbitrarily chosen */
28
29 /* Define these values to match your devices */
30 #define USBCAN_VENDOR_ID        0xDEAD
31 #define USBCAN_PRODUCT_ID       0x1001
32
33 #define RESET_ADDR 0x0
34
35 /*
36  * IO_RANGE is the io-memory range that gets reserved, please adjust according
37  * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
38  * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
39  */
40 #define IO_RANGE 0x100
41
42
43 int usbcan_request_io(struct candevice_t *candev);
44 int usbcan_release_io(struct candevice_t *candev);
45 int usbcan_reset(struct candevice_t *candev);
46 int usbcan_init_hw_data(struct candevice_t *candev);
47 int usbcan_init_chip_data(struct candevice_t *candev, int chipnr);
48 int usbcan_init_obj_data(struct canchip_t *chip, int objnr);
49 void usbcan_write_register(unsigned data, unsigned long address);
50 unsigned usbcan_read_register(unsigned long address);
51 int usbcan_program_irq(struct candevice_t *candev);
52 int usbcan_register(struct hwspecops_t *hwspecops);
53
54 int usbcan_chip_config(struct canchip_t *chip);
55 int usbcan_extended_mask(struct canchip_t *chip, unsigned long code, unsigned long mask);
56 int usbcan_baud_rate(struct canchip_t *chip, int rate, int clock, int sjw,
57                 int sampl_pt, int flags);
58 int usbcan_pre_read_config(struct canchip_t *chip, struct msgobj_t *obj);
59 int usbcan_pre_write_config(struct canchip_t *chip, struct msgobj_t *obj,
60                 struct canmsg_t *msg);
61 int usbcan_send_msg(struct canchip_t *chip, struct msgobj_t *obj,
62                 struct canmsg_t *msg);
63 int usbcan_fill_chipspecops(struct canchip_t *chip);
64 int usbcan_irq_handler(int irq, struct canchip_t *chip);
65
66 int usbcan_init(void);
67 void usbcan_exit(void);
68
69 void usbcan_read_kthread(kthread_t *kthread);
70 int usbcan_chip_queue_status(struct canchip_t *chip);
71
72 #ifdef CONFIG_OC_LINCAN_DETAILED_ERRORS
73
74 static const char *sja1000_ecc_errc_str[]={
75         "bit error",
76         "form error",
77         "stuff error",
78         "other type of error"
79 };
80
81 static const char *sja1000_ecc_seg_str[]={
82         "?0?",
83         "?1?",
84         "ID.28 to ID.21",
85         "start of frame",
86         "bit SRTR",
87         "bit IDE",
88         "ID.20 to ID.18",
89         "ID.17 to ID.13",
90         "CRC sequence",
91         "reserved bit 0",
92         "data field",
93         "data length code",
94         "bit RTR",
95         "reserved bit 1",
96         "ID.4 to ID.0",
97         "ID.12 to ID.5",
98         "?16?"
99         "active error flag",
100         "intermission",
101         "tolerate dominant bits",
102         "?20?",
103         "?21?",
104         "passive error flag",
105         "error delimiter",
106         "CRC delimiter",
107         "acknowledge slot",
108         "end of frame",
109         "acknowledge delimiter",
110         "overload flag",
111         "?29?",
112         "?30?",
113         "?31?"
114 };
115
116 #endif /*CONFIG_OC_LINCAN_DETAILED_ERRORS*/
117
118 /* CAN message over usb */
119 struct usbcan_canmsg_t{
120         __u8 chip_id;
121         __u16 flags;
122         __u8 id[4];
123         __u8 length;
124         __u8 data[8];
125 };
126
127 /* Structure to hold all of our device specific stuff */
128 struct usbcan_usb {
129         struct usb_device       *udev;                  /* the usb device for this device */
130         struct usb_interface    *interface;             /* the interface for this device */
131         struct semaphore        limit_sem;              /* limiting the number of writes in progress */
132         struct usb_anchor       submitted;              /* in case we need to retract our submissions */
133         unsigned char           *bulk_in_buffer;        /* the buffer to receive data */
134         unsigned char           *ctl_in_buffer; /* the buffer to receive data */
135         size_t                  bulk_in_size;           /* the size of the receive buffer */
136         size_t                  ctl_in_size;            /* the size of the receive buffer */
137         __u8                    ctl_in_endpointAddr;    /* the address of the bulk in endpoint */
138         __u8                    ctl_out_endpointAddr;   /* the address of the bulk in endpoint */
139         __u8                    bulk_in_endpointAddr;   /* the address of the bulk in endpoint */
140         __u8                    bulk_out_endpointAddr;  /* the address of the bulk out endpoint */
141         int                     errors;                 /* the last request tanked */
142         int                     open_count;             /* count the number of openers */
143         spinlock_t              err_lock;               /* lock for errors */
144         struct mutex            io_mutex;               /* synchronize I/O with disconnect */
145         struct urb              *rcv;
146 /*      uchar8_t        rcv_msg[16];
147         uchar8_t        tx_msg[16];*/
148         __u8    rcv_msg[16];
149         __u8    tx_msg[16];
150         kthread_t  rcvthread;                      /* usb receive kernel thread  */
151
152         struct candevice_t *candev;
153         long flags;
154 };
155
156 #define USBCAN_DATA_READ                (1)
157 #define USBCAN_TERMINATE                (2)
158 #define USBCAN_ERROR                            (3)
159 #define USBCAN_TX_PENDING               (4)
160
161 #define USBCAN_VENDOR_BAUD_RATE_SET     (1)
162 #define USBCAN_VENDOR_BAUD_RATE_STATUS  (2)
163 #define USBCAN_VENDOR_SET_BTREGS        (3)
164 #define USBCAN_VENDOR_CHECK_TX_STAT     (4)
165 #define USBCAN_VENDOR_START_CHIP        (5)
166 #define USBCAN_VENDOR_STOP_CHIP (6)
167 #define USBCAN_VENDOR_EXT_MASK_SET      (7)
168 #define USBCAN_VENDOR_EXT_MASK_STATUS   (8)
169
170
171 #endif /*USBCAN_H*/