2 * Linux CAN-bus device driver.
3 * Written by Arnaud Westenberg email:arnaud@wanadoo.nl
4 * This software is released under the GPL-License.
5 * Version 0.7 6 Aug 2001
9 #include <linux/module.h>
11 #include <linux/autoconf.h>
12 #if defined (CONFIG_MODVERSIONS) && !defined (MODVERSIONS)
16 #if defined (MODVERSIONS)
17 #include <linux/modversions.h>
20 #include <linux/version.h>
21 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
22 #include <linux/malloc.h>
24 #include <linux/slab.h>
28 #include ".supported_cards.h"
30 #include "../include/main.h"
31 #include "../include/setup.h"
32 #include "../include/pip.h"
33 #include "../include/pccan.h"
34 #include "../include/smartcan.h"
35 #include "../include/pc-i03.h"
36 #include "../include/pcm3680.h"
37 #include "../include/m437.h"
38 #include "../include/template.h"
39 #include "../include/i82527.h"
40 #include "../include/aim104.h"
41 #include "../include/pcccan.h"
43 extern int sja1000_register(struct chipspecops_t *chipspecops);
44 extern int sja1000p_register(struct chipspecops_t *chipspecops);
45 extern int i82527_register(struct chipspecops_t *chipspecops);
46 extern int template_register(struct hwspecops_t *hwspecops);
47 extern int pip5_register(struct hwspecops_t *hwspecops);
48 extern int pip6_register(struct hwspecops_t *hwspecops);
49 extern int smartcan_register(struct hwspecops_t *hwspecops);
50 extern int pccanf_register(struct hwspecops_t *hwspecops);
51 extern int pccand_register(struct hwspecops_t *hwspecops);
52 extern int pccanq_register(struct hwspecops_t *hwspecops);
53 extern int nsi_register(struct hwspecops_t *hwspecops);
54 extern int cc104_register(struct hwspecops_t *hwspecops);
55 extern int pci03_register(struct hwspecops_t *hwspecops);
56 extern int pcm3680_register(struct hwspecops_t *hwspecops);
57 extern int aim104_register(struct hwspecops_t *hwspecops);
58 extern int pcccan_register(struct hwspecops_t *hwspecops);
59 extern int ssv_register(struct hwspecops_t *hwspecops);
60 extern int bfadcan_register(struct hwspecops_t *hwspecops);
61 extern int pikronisa_register(struct hwspecops_t *hwspecops);
63 int init_device_struct(int card);
64 int init_hwspecops(int card);
65 int init_chip_struct(int card);
66 int init_obj_struct(int card, int chip);
67 int init_chipspecops(int card, int chipnr);
69 int add_mem_to_list(void *address_p)
71 struct mem_addr *mem_new;
74 DEBUGMSG("add_mem_to_list %p, mem_head=%p\n",address_p, mem_head);
78 mem_new=(struct mem_addr *)kmalloc(sizeof(struct mem_addr),GFP_KERNEL);
79 if (mem_new == NULL) {
80 CANMSG("Memory list error.\n");
83 mem_new->next=mem_head;
84 mem_new->address=address_p;
90 int del_mem_from_list(void *address_p)
92 struct mem_addr *mem_search=NULL;
93 struct mem_addr *mem_delete=NULL;
96 DEBUGMSG("del_mem_from_list %p, mem_head=%p\n", address_p, mem_head);
99 if(mem_head == NULL) {
100 CANMSG("del_mem_from_list: mem_head == NULL address_p=%p!\n",
105 mem_search = mem_head;
107 if (mem_head->address == address_p) {
108 kfree(mem_head->address);
109 mem_head=mem_head->next;
113 while (mem_search->next->address != address_p)
114 mem_search=mem_search->next;
115 kfree(mem_search->next->address);
116 mem_delete=mem_search->next;
117 mem_search->next=mem_search->next->next;
124 int del_mem_list(void)
126 struct mem_addr *mem_old;
129 DEBUGMSG("del_mem_list, mem_head=%p\n", mem_head);
132 if(mem_head == NULL) {
133 CANMSG("del_mem_list: mem_head == NULL!\n");
137 while (mem_head->next != NULL) {
139 kfree(mem_old->address);
140 mem_head=mem_old->next;
147 /* The function init_hw_struct is used to initialize the hardware structure. */
148 int init_hw_struct(void)
152 hardware_p->nr_boards=0;
153 while ( (hw[i] != NULL) & (i < MAX_HW_CARDS) ) {
154 hardware_p->nr_boards++;
156 if (init_device_struct(i)) {
157 CANMSG("Error initializing candevice_t structures.\n");
166 /* The function init_device_struct is used to initialize a single device
169 int init_device_struct(int card)
171 hardware_p->candevice[card]=(struct candevice_t *)kmalloc(sizeof(struct candevice_t),GFP_KERNEL);
172 if (hardware_p->candevice[card]==NULL)
175 if ( add_mem_to_list(hardware_p->candevice[card]) )
178 candevices_p[card]=hardware_p->candevice[card];
180 hardware_p->candevice[card]->hwname=hw[card];
181 hardware_p->candevice[card]->io_addr=io[card];
183 hardware_p->candevice[card]->hwspecops=(struct hwspecops_t *)kmalloc(sizeof(struct hwspecops_t),GFP_KERNEL);
184 if (hardware_p->candevice[card]->hwspecops==NULL)
187 if ( add_mem_to_list(hardware_p->candevice[card]->hwspecops) )
190 if (init_hwspecops(card))
193 if (candevices_p[card]->hwspecops->init_hw_data(card))
196 if (init_chip_struct(card))
202 /* The function init_chip_struct is used to initialize all chip_t structures
203 * on one hardware board.
205 int init_chip_struct(int card)
207 static int irq_count=0;
210 /* Alocate and initialize the chip structures */
211 for (i=0; i < candevices_p[card]->nr_82527_chips+candevices_p[card]->nr_sja1000_chips; i++) {
212 candevices_p[card]->chip[i]=(struct chip_t *)kmalloc(sizeof(struct chip_t),GFP_KERNEL);
213 if (candevices_p[card]->chip[i]==NULL)
216 if ( add_mem_to_list(candevices_p[card]->chip[i]) )
219 candevices_p[card]->chip[i]->chipspecops=(struct chipspecops_t *)kmalloc(sizeof(struct chipspecops_t),GFP_KERNEL);
220 if (candevices_p[card]->chip[i]->chipspecops==NULL)
223 if ( add_mem_to_list(candevices_p[card]->chip[i]->chipspecops) )
226 chips_p[irq_count]=candevices_p[card]->chip[i];
227 candevices_p[card]->chip[i]->hostdevice=candevices_p[card];
228 candevices_p[card]->chip[i]->chip_irq=irq[irq_count];
229 candevices_p[card]->chip[i]->flags=0x0;
231 candevices_p[card]->hwspecops->init_chip_data(card,i);
233 if (init_chipspecops(card,i))
236 init_obj_struct(card, irq_count);
244 int init_obj_struct(int card, int chip)
246 static int obj_count=0;
247 int i=0,max_objects=0;
249 if (!strcmp(chips_p[chip]->chip_type,"i82527"))
253 for (i=0; i<max_objects; i++) {
254 chips_p[chip]->msgobj[i]=(struct msgobj_t *)kmalloc(sizeof(struct msgobj_t),GFP_KERNEL);
255 if (chips_p[chip]->msgobj[i] == NULL)
258 if ( add_mem_to_list(chips_p[chip]->msgobj[i]) )
261 chips_p[chip]->msgobj[i]->fifo=(struct canfifo_t *)kmalloc(sizeof(struct canfifo_t),GFP_KERNEL);
262 if (chips_p[chip]->msgobj[i]->fifo == NULL)
265 if ( add_mem_to_list(chips_p[chip]->msgobj[i]->fifo) )
268 if (minor[0] == -1) {
269 objects_p[obj_count]=chips_p[chip]->msgobj[i];
270 objects_p[obj_count]->hostchip=chips_p[chip];
271 objects_p[obj_count]->object=i+1;
272 objects_p[obj_count]->minor=obj_count;
275 objects_p[minor[chip]+i]=chips_p[chip]->msgobj[i];
276 objects_p[minor[chip]+i]->hostchip=chips_p[chip];
277 objects_p[minor[chip]+i]->object=i+1;
278 objects_p[minor[chip]+i]->minor=minor[chip]+i;
281 chips_p[chip]->msgobj[i]->flags = 0x0;
283 candevices_p[card]->hwspecops->init_obj_data(chip,i);
291 int init_hwspecops(int card)
293 #ifdef ENABLE_CARD_template
294 if (!strcmp(candevices_p[card]->hwname,"template")) {
295 template_register(candevices_p[card]->hwspecops);
298 #ifdef ENABLE_CARD_pip
299 if (!strcmp(candevices_p[card]->hwname,"pip5")) {
300 pip5_register(candevices_p[card]->hwspecops);
302 else if (!strcmp(candevices_p[card]->hwname,"pip6")) {
303 pip6_register(candevices_p[card]->hwspecops);
306 #ifdef ENABLE_CARD_smartcan
307 if (!strcmp(candevices_p[card]->hwname,"smartcan")) {
308 smartcan_register(candevices_p[card]->hwspecops);
311 #ifdef ENABLE_CARD_nsi
312 if (!strcmp(candevices_p[card]->hwname,"nsican")) {
313 nsi_register(candevices_p[card]->hwspecops);
316 #ifdef ENABLE_CARD_cc_can104
317 if (!strcmp(candevices_p[card]->hwname,"cc104")) {
318 cc104_register(candevices_p[card]->hwspecops);
321 #ifdef ENABLE_CARD_aim104
322 if (!strcmp(candevices_p[card]->hwname,"aim104")) {
323 aim104_register(candevices_p[card]->hwspecops);
326 #ifdef ENABLE_CARD_pc_i03
327 if (!strcmp(candevices_p[card]->hwname,"pc-i03")) {
328 pci03_register(candevices_p[card]->hwspecops);
331 #ifdef ENABLE_CARD_pcm3680
332 if (!strcmp(candevices_p[card]->hwname,"pcm3680")) {
333 pcm3680_register(candevices_p[card]->hwspecops);
336 #ifdef ENABLE_CARD_pccan
337 if (!strcmp(candevices_p[card]->hwname,"pccan-f") |
338 !strcmp(candevices_p[card]->hwname,"pccan-s") ) {
339 pccanf_register(candevices_p[card]->hwspecops);
341 if (!strcmp(candevices_p[card]->hwname,"pccan-d")) {
342 pccand_register(candevices_p[card]->hwspecops);
344 if (!strcmp(candevices_p[card]->hwname,"pccan-q")) {
345 pccanq_register(candevices_p[card]->hwspecops);
348 #ifdef ENABLE_CARD_m437
349 if (!strcmp(candevices_p[card]->hwname,"m437")) {
350 m437_register(candevices_p[card]->hwspecops);
353 #ifdef ENABLE_CARD_pcccan
354 if (!strcmp(candevices_p[card]->hwname,"pcccan")) {
355 pcccan_register(candevices_p[card]->hwspecops);
358 #ifdef ENABLE_CARD_ssv
359 if (!strcmp(candevices_p[card]->hwname,"ssv")) {
360 ssv_register(candevices_p[card]->hwspecops);
363 #ifdef ENABLE_CARD_bfadcan
364 if (!strcmp(candevices_p[card]->hwname,"bfadcan")) {
365 bfadcan_register(candevices_p[card]->hwspecops);
368 #ifdef ENABLE_CARD_pikronisa
369 if (!strcmp(candevices_p[card]->hwname,"pikronisa")) {
370 pikronisa_register(candevices_p[card]->hwspecops);
376 int init_chipspecops(int card, int chipnr)
378 if (!strcmp(candevices_p[card]->chip[chipnr]->chip_type,"i82527")) {
379 i82527_register(candevices_p[card]->chip[chipnr]->chipspecops);
381 if (!strcmp(candevices_p[card]->chip[chipnr]->chip_type,"sja1000")) {
382 sja1000_register(candevices_p[card]->chip[chipnr]->chipspecops);
384 if (!strcmp(candevices_p[card]->chip[chipnr]->chip_type,"sja1000p")) {
385 sja1000p_register(candevices_p[card]->chip[chipnr]->chipspecops);