2 * Linux CAN-bus device driver.
3 * Written by Arnaud Westenberg email:arnaud@wanadoo.nl
4 * Rewritten for new CAN queues by Pavel Pisa - OCERA team member
5 * email:pisa@cmp.felk.cvut.cz
6 * This software is released under the GPL-License.
7 * Version lincan-0.2 9 Jul 2003
12 #include <linux/autoconf.h>
14 #include <linux/module.h>
16 #include <linux/kernel.h>
18 #include <linux/sched.h>
19 #include <linux/poll.h>
20 #include <linux/version.h>
21 #include <linux/autoconf.h>
22 #include <linux/interrupt.h>
24 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,50))
25 #include <linux/wrapper.h>
28 #if !defined (__GENKSYMS__)
29 #if (defined (MODVERSIONS) && !defined(NOVER))
30 #include <linux/modversions.h>
31 /*#include "../include/main.ver"*/
35 /*#undef CONFIG_DEVFS_FS*/
37 #ifdef CONFIG_DEVFS_FS
38 #include <linux/devfs_fs_kernel.h>
39 #include <linux/miscdevice.h>
42 #include "../include/can.h"
43 #include "../include/can_sysdep.h"
44 #include "../include/main.h"
45 #include "../include/modparms.h"
46 #include "../include/devcommon.h"
47 #include "../include/setup.h"
48 #include "../include/proc.h"
49 #include "../include/open.h"
50 #include "../include/close.h"
51 #include "../include/read.h"
52 #include "../include/select.h"
53 #include "../include/irq.h"
54 #include "../include/ioctl.h"
55 #include "../include/write.h"
56 #include "../include/finish.h"
60 /* Module parameters, some must be supplied at module loading time */
62 MODULE_PARM(major,"1i");
63 int minor[MAX_TOT_CHIPS]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
64 /*MODULE_PARM(minor, "1-" __MODULE_STRING(MAX_TOT_CHIPS)"i");*/
65 MODULE_PARM(minor, "1-" __MODULE_STRING(MAX_TOT_CHIPS_STR)"i");
67 MODULE_PARM(extended,"1i");
69 MODULE_PARM(pelican,"1i");
70 int baudrate[MAX_TOT_CHIPS];
71 MODULE_PARM(baudrate, "1-" __MODULE_STRING(MAX_TOT_CHIPS_STR)"i");
72 char *hw[MAX_HW_CARDS]={NULL,};
73 MODULE_PARM(hw, "1-" __MODULE_STRING(MAX_HW_CARDS)"s");
74 int irq[MAX_IRQ]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
75 MODULE_PARM(irq, "1-" __MODULE_STRING(MAX_IRQ)"i");
76 unsigned long io[MAX_HW_CARDS]={-1,-1,-1,-1,-1,-1,-1,-1};
77 MODULE_PARM(io, "1-" __MODULE_STRING(MAX_HW_CARDS)"i");
79 MODULE_PARM(stdmask, "1i");
81 MODULE_PARM(extmask, "1i");
83 MODULE_PARM(mo15mask, "1i");
85 MODULE_PARM(processlocal, "1i");
87 /* Other module attributes */
88 #ifdef MODULE_SUPPORTED_DEVICE
89 MODULE_SUPPORTED_DEVICE("can");
92 MODULE_LICENSE("GPL");
94 #ifdef MODULE_DESCRIPTION
95 MODULE_DESCRIPTION("Universal Linux CAN-bus device driver");
98 /* Global structures, used to describe the installed hardware. */
99 struct canhardware_t canhardware;
100 struct canhardware_t *hardware_p=&canhardware;
101 struct chip_t *chips_p[MAX_TOT_CHIPS];
102 struct msgobj_t *objects_p[MAX_TOT_MSGOBJS];
103 #ifdef CONFIG_DEVFS_FS
104 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,60))
105 devfs_handle_t devfs_handles[MAX_TOT_MSGOBJS];
109 /* Pointers to dynamically allocated memory are maintained in a linked list
110 * to ease memory deallocation.
112 struct mem_addr *mem_head=NULL;
114 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,0))
115 struct file_operations can_fops=
130 struct file_operations can_fops=
142 EXPORT_SYMBOL(can_fops);
144 int init_module(void)
147 struct candevice_t *candev;
150 if (parse_mod_parms())
153 canqueue_kern_initialize();
155 if (init_hw_struct())
162 res=register_chrdev(major,DEVICE_NAME, &can_fops);
164 CANMSG("Error registering driver.\n");
168 for (i=0; i<hardware_p->nr_boards; i++) {
169 candev=hardware_p->candevice[i];
170 if (candev->hwspecops->request_io(candev))
172 candev->flags|=CANDEV_IO_RESERVED;
175 for (i=0; i<hardware_p->nr_boards; i++) {
176 candev=hardware_p->candevice[i];
177 if (candev->hwspecops->reset(candev))
181 spin_lock_init(&hardware_p->rtr_lock);
182 hardware_p->rtr_queue=NULL;
184 for (i=0; i<hardware_p->nr_boards; i++) {
185 candev=hardware_p->candevice[i];
186 for(j=0; j<candev->nr_all_chips; j++) {
187 if((chip=candev->chip[j])==NULL)
189 if(!chip->chipspecops->irq_handler)
192 if (request_irq(chip->chip_irq,chip->chipspecops->irq_handler,SA_SHIRQ,DEVICE_NAME,chip))
193 goto interrupt_error;
195 DEBUGMSG("Registered interrupt %d\n",chip->chip_irq);
196 chip->flags |= CHIP_IRQ_SETUP;
200 if (candev->flags & CANDEV_PROGRAMMABLE_IRQ)
201 if (candev->hwspecops->program_irq(candev))
202 goto interrupt_error;
205 #ifdef CONFIG_PROC_FS
206 if (can_init_procdir())
210 #ifdef CONFIG_DEVFS_FS
214 for(i=0;i<MAX_TOT_MSGOBJS;i++) {
215 if(!objects_p[i]) continue;
216 dev_minor=objects_p[i]->minor;
217 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,50))
218 sprintf (dev_name, "can%d", dev_minor);
219 devfs_handles[i]=devfs_register(NULL, dev_name,
220 DEVFS_FL_DEFAULT, major, dev_minor,
221 S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
222 &can_fops, (void*)objects_p[i]);
224 devfs_mk_cdev(MKDEV(major, dev_minor), S_IFCHR | S_IRUGO | S_IWUGO, "can%d", dev_minor);
231 #ifdef CONFIG_PROC_FS
233 CANMSG("Error registering /proc entry.\n");
238 CANMSG("Error registering interrupt line.\n");
245 canhardware_done(hardware_p);
247 res=unregister_chrdev(major,DEVICE_NAME);
249 CANMSG("Error unloading CAN driver, error: %d\n",res);
251 CANMSG("No CAN devices or driver setup error.\n");
256 void cleanup_module(void)
260 #ifdef CONFIG_PROC_FS
261 if (can_delete_procdir())
262 CANMSG("Error unregistering /proc/can entry.\n");
265 #ifdef CONFIG_DEVFS_FS
266 for(i=0;i<MAX_TOT_MSGOBJS;i++) {
267 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,50))
269 devfs_unregister(devfs_handles[i]);
272 if(!objects_p[i]) continue;
273 dev_minor=objects_p[i]->minor;
275 devfs_remove("can%d", dev_minor);
280 canhardware_done(hardware_p);
282 if ( can_del_mem_list() )
283 CANMSG("Error deallocating memory\n");
285 res=unregister_chrdev(major,DEVICE_NAME);
287 CANMSG("Error unregistering CAN driver, error: %d\n",res);