]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/include/usbcan.h
reference count for device opens added (helps while asynchronous remove
[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 #include <linux/wait.h>
19
20 #include "../include/kthread.h"
21
22 /* our private defines. if this grows any larger, use your own .h file */
23 #define MAX_TRANSFER            (PAGE_SIZE - 512)
24 /* MAX_TRANSFER is chosen so that the VM is not stressed by
25    allocations > PAGE_SIZE and the number of packets in a page
26    is an integer 512 is the largest possible packet on EHCI */
27 #define WRITES_IN_FLIGHT        8
28 /* arbitrarily chosen */
29
30 /* Define these values to match your devices */
31 #define USBCAN_VENDOR_ID        0x1669
32 #define USBCAN_PRODUCT_ID       0x1011
33
34 #define RESET_ADDR 0x0
35
36 /*
37  * IO_RANGE is the io-memory range that gets reserved, please adjust according
38  * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
39  * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
40  */
41 #define IO_RANGE 0x100
42
43
44 int usbcan_request_io(struct candevice_t *candev);
45 int usbcan_release_io(struct candevice_t *candev);
46 int usbcan_reset(struct candevice_t *candev);
47 int usbcan_init_hw_data(struct candevice_t *candev);
48 int usbcan_init_chip_data(struct candevice_t *candev, int chipnr);
49 int usbcan_init_obj_data(struct canchip_t *chip, int objnr);
50 void usbcan_write_register(unsigned data, unsigned long address);
51 unsigned usbcan_read_register(unsigned long address);
52 int usbcan_program_irq(struct candevice_t *candev);
53 int usbcan_register(struct hwspecops_t *hwspecops);
54
55 int usbcan_chip_config(struct canchip_t *chip);
56 int usbcan_extended_mask(struct canchip_t *chip, unsigned long code, unsigned long mask);
57 int usbcan_baud_rate(struct canchip_t *chip, int rate, int clock, int sjw,
58                 int sampl_pt, int flags);
59 int usbcan_pre_read_config(struct canchip_t *chip, struct msgobj_t *obj);
60 int usbcan_pre_write_config(struct canchip_t *chip, struct msgobj_t *obj,
61                 struct canmsg_t *msg);
62 int usbcan_send_msg(struct canchip_t *chip, struct msgobj_t *obj,
63                 struct canmsg_t *msg);
64 int usbcan_fill_chipspecops(struct canchip_t *chip);
65 int usbcan_irq_handler(int irq, struct canchip_t *chip);
66
67 int usbcan_init(void);
68 void usbcan_exit(void);
69
70 int usbcan_kthread(void *data);
71 int usbcan_chip_queue_status(struct canchip_t *chip);
72
73 #ifdef CONFIG_OC_LINCAN_DETAILED_ERRORS
74
75 // static const char *sja1000_ecc_errc_str[]={
76 //      "bit error",
77 //      "form error",
78 //      "stuff error",
79 //      "other type of error"
80 // };
81 //
82 // static const char *sja1000_ecc_seg_str[]={
83 //      "?0?",
84 //      "?1?",
85 //      "ID.28 to ID.21",
86 //      "start of frame",
87 //      "bit SRTR",
88 //      "bit IDE",
89 //      "ID.20 to ID.18",
90 //      "ID.17 to ID.13",
91 //      "CRC sequence",
92 //      "reserved bit 0",
93 //      "data field",
94 //      "data length code",
95 //      "bit RTR",
96 //      "reserved bit 1",
97 //      "ID.4 to ID.0",
98 //      "ID.12 to ID.5",
99 //      "?16?"
100 //      "active error flag",
101 //      "intermission",
102 //      "tolerate dominant bits",
103 //      "?20?",
104 //      "?21?",
105 //      "passive error flag",
106 //      "error delimiter",
107 //      "CRC delimiter",
108 //      "acknowledge slot",
109 //      "end of frame",
110 //      "acknowledge delimiter",
111 //      "overload flag",
112 //      "?29?",
113 //      "?30?",
114 //      "?31?"
115 // };
116
117 #endif /*CONFIG_OC_LINCAN_DETAILED_ERRORS*/
118
119 struct usbcan_usb;
120
121 #define USBCAN_TOT_RX_URBS 8
122 #define USBCAN_TOT_TX_URBS 8
123
124 #define USBCAN_TRANSFER_SIZE 16
125
126 struct usbcan_message {
127         struct urb      *u;
128         struct usbcan_usb *dev;
129         u8      msg[USBCAN_TRANSFER_SIZE];
130         struct canque_edge_t *qedge;
131         struct canque_slot_t *slot;
132         struct list_head list_node;
133         volatile long   flags;
134 };
135
136 #define USBCAN_MESSAGE_FREE                             (1)
137 #define USBCAN_MESSAGE_URB_PENDING                      (2)
138 #define USBCAN_MESSAGE_TERMINATE                        (3)
139 #define USBCAN_MESSAGE_ERROR                            (4)
140 #define USBCAN_MESSAGE_DATA_OK                          (5)
141 #define USBCAN_MESSAGE_TYPE_RX                          (6)
142 #define USBCAN_MESSAGE_TYPE_TX                          (7)
143
144 /* Structure to hold all of our device specific stuff */
145 struct usbcan_usb {
146         struct usb_device       *udev;                  /* the usb device for this device */
147         struct usb_interface    *interface;             /* the interface for this device */
148         unsigned char           *bulk_in_buffer;        /* the buffer to receive data */
149         size_t                  bulk_in_size;           /* the size of the receive buffer */
150         u8                      bulk_in_endpointAddr;   /* the address of the bulk in endpoint */
151         u8                      bulk_out_endpointAddr;  /* the address of the bulk out endpoint */
152         struct mutex            io_mutex;               /* synchronize I/O with disconnect */
153
154         struct list_head        rx_pend_list;           /* URBs waiting for data receive */
155         struct list_head        rx_ready_list;          /* URBs with valid received data */
156         struct list_head        tx_idle_list;           /* URBs prepared to hold Tx messages */
157         struct list_head        tx_pend_list;           /* URBs holding Tx messages in progress */
158         struct list_head        tx_ready_list;          /* URBs with yet confirmed Tx messages */
159
160         spinlock_t              list_lock;                      /* list lock */
161
162         struct task_struct *comthread;                  /* usb communication kernel thread  */
163         wait_queue_head_t queue;
164
165         struct canchip_t *chip;
166         volatile long flags;
167 };
168
169 #define USBCAN_DATA_OK                          (1)
170 #define USBCAN_DATA_RX                          (2)
171 #define USBCAN_DATA_TX                          (3)
172 #define USBCAN_TERMINATE                        (4)
173 #define USBCAN_ERROR                                    (5)
174 #define USBCAN_TX_PENDING                       (6)
175 #define USBCAN_THREAD_RUNNING   (7)
176 #define USBCAN_FREE_TX_URB              (8)
177
178 #define USBCAN_VENDOR_BAUD_RATE_SET     (1)
179 #define USBCAN_VENDOR_BAUD_RATE_STATUS  (2)
180 #define USBCAN_VENDOR_SET_BTREGS        (3)
181 #define USBCAN_VENDOR_CHECK_TX_STAT     (4)
182 #define USBCAN_VENDOR_START_CHIP        (5)
183 #define USBCAN_VENDOR_STOP_CHIP (6)
184 #define USBCAN_VENDOR_EXT_MASK_SET      (7)
185 #define USBCAN_VENDOR_EXT_MASK_STATUS   (8)
186
187 struct usbcan_devs {
188         struct usbcan_usb **devs;
189         int     count;
190         struct candevice_t *candev;
191         struct usb_device *udev;
192 };
193
194
195 #endif /*USBCAN_H*/