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
10 #include <linux/autoconf.h>
11 #if defined (CONFIG_MODVERSIONS) && !defined (MODVERSIONS)
15 #include <linux/module.h>
17 #if defined (MODVERSIONS)
18 #include <linux/modversions.h>
21 #include <linux/kernel.h>
23 #include <linux/wrapper.h>
24 #include <linux/sched.h>
25 #include <linux/poll.h>
26 #include <linux/version.h>
27 #include <linux/autoconf.h>
28 #include <linux/interrupt.h>
30 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,0))
31 #include <asm/spinlock.h>
33 #include <linux/spinlock.h>
36 #if !defined (__GENKSYMS__)
37 #if (defined (MODVERSIONS) && !defined(NOVER))
38 #include <linux/modversions.h>
39 /*#include "../include/main.ver"*/
43 #ifdef CONFIG_DEVFS_FS
44 #include <linux/miscdevice.h>
47 #include "../include/main.h"
48 #include "../include/modparms.h"
49 #include "../include/setup.h"
50 #include "../include/proc.h"
51 #include "../include/open.h"
52 #include "../include/close.h"
53 #include "../include/read.h"
54 #include "../include/select.h"
55 #include "../include/irq.h"
56 #include "../include/ioctl.h"
57 #include "../include/write.h"
61 /* Module parameters, some must be supplied at module loading time */
63 MODULE_PARM(major,"1i");
64 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};
65 /*MODULE_PARM(minor, "1-" __MODULE_STRING(MAX_TOT_CHIPS)"i");*/
66 MODULE_PARM(minor, "1-" __MODULE_STRING(MAX_TOT_CHIPS_STR)"i");
68 MODULE_PARM(extended,"1i");
70 MODULE_PARM(pelican,"1i");
72 MODULE_PARM(baudrate,"1i");
73 char *hw[MAX_HW_CARDS]={NULL,};
74 MODULE_PARM(hw, "1-" __MODULE_STRING(MAX_HW_CARDS)"s");
75 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};
76 MODULE_PARM(irq, "1-" __MODULE_STRING(MAX_IRQ)"i");
77 unsigned long io[MAX_HW_CARDS]={-1,-1,-1,-1,-1,-1,-1,-1};
78 MODULE_PARM(io, "1-" __MODULE_STRING(MAX_HW_CARDS)"i");
80 MODULE_PARM(stdmask, "1i");
82 MODULE_PARM(extmask, "1i");
84 MODULE_PARM(mo15mask, "1i");
86 /* Other module attributes */
87 #ifdef MODULE_SUPPORTED_DEVICE
88 MODULE_SUPPORTED_DEVICE("can");
91 MODULE_LICENSE("GPL");
93 #ifdef MODULE_DESCRIPTION
94 MODULE_DESCRIPTION("Universal Linux CAN-bus device driver");
97 /* Global structures, used to describe the installed hardware. */
98 struct canhardware_t canhardware;
99 struct canhardware_t *hardware_p=&canhardware;
100 struct candevice_t *candevices_p[MAX_HW_CARDS];
101 struct chip_t *chips_p[MAX_TOT_CHIPS];
102 struct msgobj_t *objects_p[MAX_TOT_MSGOBJS];
103 #ifdef CONFIG_DEVFS_FS
104 devfs_handle_t devfs_handles[MAX_TOT_MSGOBJS];
107 /* Pointers to dynamically allocated memory are maintained in a linked list
108 * to ease memory deallocation.
110 struct mem_addr *mem_head=NULL;
112 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,0))
113 struct file_operations can_fops=
128 struct file_operations can_fops=
140 EXPORT_SYMBOL(can_fops);
142 int init_module(void)
146 if (parse_mod_parms())
149 if (init_hw_struct())
156 res=register_chrdev(major,DEVICE_NAME, &can_fops);
158 CANMSG("Error registering driver.\n");
162 for (i=0; i<hardware_p->nr_boards; i++) {
163 if (candevices_p[i]->hwspecops->request_io(candevices_p[i]->io_addr))
167 for (i=0; i<hardware_p->nr_boards; i++) {
168 if (candevices_p[i]->hwspecops->reset(i))
172 spin_lock_init(&hardware_p->rtr_lock);
173 hardware_p->rtr_queue=NULL;
176 while ( (chips_p[i] != NULL) && (i < MAX_TOT_CHIPS) ) {
177 if (!strcmp(chips_p[i]->chip_type,"i82527")) {
178 if (request_irq(chips_p[i]->chip_irq,i82527_irq_handler,SA_SHIRQ,DEVICE_NAME,chips_p[i]))
179 goto interrupt_error;
181 DEBUGMSG("Registered interrupt %d\n",chips_p[i]->chip_irq);
183 if (!strcmp(chips_p[i]->chip_type,"sja1000p") ||
184 !strcmp(chips_p[i]->chip_type,"sja1000")) {
185 if (request_irq(chips_p[i]->chip_irq,
186 chips_p[i]->chipspecops->irq_handler,SA_SHIRQ,DEVICE_NAME,chips_p[i]))
187 goto interrupt_error;
189 DEBUGMSG("Registered interrupt %d\n",chips_p[i]->chip_irq);
194 for (i=0; i<hardware_p->nr_boards; i++) {
195 if (candevices_p[i]->flags & PROGRAMMABLE_IRQ)
196 if (candevices_p[i]->hwspecops->program_irq(i))
197 goto interrupt_error;
200 #ifdef CONFIG_PROC_FS
201 if (can_init_procdir())
205 #ifdef CONFIG_DEVFS_FS
209 for(i=0;i<MAX_TOT_MSGOBJS;i++) {
210 if(!objects_p[i]) continue;
211 dev_minor=objects_p[i]->minor;
212 sprintf (dev_name, "can%d", dev_minor);
213 devfs_handles[i]=devfs_register(NULL, dev_name,
214 DEVFS_FL_DEFAULT, major, dev_minor,
215 S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
216 &can_fops, (void*)objects_p[i]);
222 #ifdef CONFIG_PROC_FS
224 CANMSG("Error registering /proc entry.\n");
229 CANMSG("Error registering interrupt line.\n");
236 for (i=0; i<hardware_p->nr_boards; i++)
237 candevices_p[i]->hwspecops->release_io(candevices_p[i]->io_addr);
241 res=unregister_chrdev(major,DEVICE_NAME);
243 CANMSG("Error unloading CAN driver, error: %d\n",res);
245 CANMSG("Successfully unloaded CAN driver.\n");
250 void cleanup_module(void)
254 #ifdef CONFIG_PROC_FS
255 if (can_delete_procdir())
256 CANMSG("Error unregistering /proc/can entry.\n");
259 #ifdef CONFIG_DEVFS_FS
260 for(i=0;i<MAX_TOT_MSGOBJS;i++) {
262 devfs_unregister(devfs_handles[i]);
266 while ( (chips_p[i] != NULL) & (i < MAX_TOT_CHIPS) ) {
267 free_irq(chips_p[i]->chip_irq, chips_p[i]);
271 for (i=0; i<hardware_p->nr_boards; i++)
272 candevices_p[i]->hwspecops->release_io(candevices_p[i]->io_addr);
274 if ( del_mem_list() )
275 CANMSG("Error deallocating memory\n");
277 res=unregister_chrdev(major,DEVICE_NAME);
279 CANMSG("Error unregistering CAN driver, error: %d\n",res);