]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/modparms.c
The original version of Arnaud Westenberg Linux CAN-bus driver
[lincan.git] / lincan / src / modparms.c
1 /* mod_parms.c
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
6  */
7
8
9 #include <linux/autoconf.h>
10 #if defined (CONFIG_MODVERSIONS) && !defined (MODVERSIONS)
11 #define MODVERSIONS
12 #endif
13
14 #if defined (MODVERSIONS)
15 #include <linux/modversions.h>
16 #endif
17
18 #include "../.support"
19 #ifndef PIP
20 #define PIP 0
21 #endif
22 #ifndef SMARTCAN
23 #define SMARTCAN 0
24 #endif
25 #ifndef PCCAN
26 #define PCCAN 0
27 #endif
28 #ifndef NSI
29 #define NSI 0
30 #endif
31 #ifndef CC104
32 #define CC104 0
33 #endif
34 #ifndef AIM104
35 #define AIM104 0
36 #endif
37 #ifndef PCI03
38 #define PCI03 0
39 #endif
40 #ifndef PCM3680
41 #define PCM3680 0
42 #endif
43 #ifndef M437
44 #define M437 0
45 #endif
46 #ifndef PCCCAN
47 #define PCCCAN 0
48 #endif
49 #ifndef SSV
50 #define SSV 0
51 #endif
52 #ifndef TEMPLATE
53 #define TEMPLATE 0
54 #endif
55
56 #include <linux/string.h>
57 #include <linux/fs.h>
58
59 #include "../include/main.h"
60 #include "../include/modparms.h"
61
62 int parse_mod_parms(void)
63 {
64         int i=0,j=0,irq_needed=0,irq_supplied=0,io_needed=0,io_supplied=0,minor_needed=0,minor_supplied=0;
65
66         if ( (hw[0] == NULL) | (irq[0] == -1) | (io[0] == -1) ) {
67                 CANMSG("You must supply your type of hardware, interrupt numbers and io address.\n");
68                 CANMSG("Example: # insmod can.o hw=pip5 irq=4 io=0x8000\n");
69                 return -ENODEV;
70         }
71
72         while ( (hw[i] != NULL) && (i < MAX_HW_CARDS) ) {
73                 if ( !strcmp(hw[i],"pip5") && PIP )
74                         irq_needed++;
75                 else if (!strcmp(hw[i],"pip6") && PIP)
76                         irq_needed++;
77                 else if (!strcmp(hw[i],"smartcan") && SMARTCAN)
78                         irq_needed++;
79                 else if (!strcmp(hw[i],"pccan-q") && PCCAN)
80                         irq_needed=irq_needed+4;
81                 else if (!strcmp(hw[i],"pccan-f") && PCCAN)
82                         irq_needed++;
83                 else if (!strcmp(hw[i],"pccan-s") && PCCAN)
84                         irq_needed++;
85                 else if (!strcmp(hw[i],"pccan-d") && PCCAN)
86                         irq_needed=irq_needed+2;
87                 else if (!strcmp(hw[i],"nsican") && NSI)
88                         irq_needed++;
89                 else if (!strcmp(hw[i],"cc104") && CC104)
90                         irq_needed++;
91                 else if (!strcmp(hw[i],"aim104") && AIM104)
92                         irq_needed++;
93                 else if (!strcmp(hw[i],"pc-i03") && PCI03)
94                         irq_needed++;
95                 else if (!strcmp(hw[i],"pcm3680") && PCM3680)
96                         irq_needed=irq_needed+2;
97                 else if (!strcmp(hw[i],"m437") && M437)
98                         irq_needed++;
99                 else if (!strcmp(hw[i],"pcccan") && PCCCAN)
100                         irq_needed++;
101                 else if (!strcmp(hw[i],"ssv") && SSV)
102                         irq_needed=irq_needed+2;
103                 else if (!strcmp(hw[i],"template") && TEMPLATE);
104                 else {
105                         CANMSG("Sorry, hardware \"%s\" is currently not supported.\n",hw[i]);
106                         return -EINVAL;
107                 }
108                 i++;
109         }
110
111         /* Check wether the supplied number of io addresses is correct. */
112         io_needed=i;
113         while ( (io[io_supplied] != -1) & (io_supplied<MAX_HW_CARDS) ) 
114                 io_supplied++;
115         if (io_needed != io_supplied) {
116                 CANMSG("Invalid number of io addresses.\n");
117                 CANMSG("Supplied hardware needs %d io address(es).\n",io_needed);
118                 return -EINVAL;
119         }
120
121         /* Check wether the supplied number of irq's is correct. */
122         while ( (irq[irq_supplied] != -1) & (irq_supplied<MAX_IRQ) )
123                 irq_supplied++;
124         while ( (hw[j] != NULL) && (j<MAX_HW_CARDS) ) {
125                 if (!strcmp(hw[j],"template") && TEMPLATE)
126                         irq_needed = irq_supplied;
127                 j++;
128         }
129         if (irq_needed != irq_supplied) {
130                 CANMSG("Invalid number of interrupts.\n");
131                 CANMSG("Supplied harware needs %d irq number(s).\n",irq_needed);
132                 return -EINVAL;
133         }
134
135         /* In case minor numbers were assigned check wether the correct number
136          * of minor numbers was supplied.
137          */
138         if (minor[0] != -1) {
139                 minor_needed=irq_needed;
140                 while ((minor[minor_supplied] != -1) & (minor_supplied<MAX_IRQ))
141                         minor_supplied++; 
142                 if (minor_supplied != minor_needed) {
143                         CANMSG("Invalid number of minor numbers.\n");
144                         CANMSG("Supplied hardware needs %d minor number(s).\n",minor_needed);
145                         return -EINVAL;
146                 }
147         }
148
149         return 0;
150 }
151 /* list_hw is used when debugging is on to show the hardware layout */
152 int list_hw(void)
153 {
154         int i=0,j=0,k=0;
155
156         DEBUGMSG("Number of boards : %d\n",hardware_p->nr_boards);
157
158         while ( (hw[i] != NULL) & (i<=MAX_HW_CARDS-1) ) {
159                 printk(KERN_ERR "\n");
160                 DEBUGMSG("Hardware         : %s\n",hardware_p->candevice[i]->hwname);
161                 DEBUGMSG("IO address       : 0x%lx\n",hardware_p->candevice[i]->io_addr);
162                 DEBUGMSG("Nr. of i82527    : %d\n",hardware_p->candevice[i]->nr_82527_chips);
163                 DEBUGMSG("Nr. of sja1000   : %d\n",hardware_p->candevice[i]->nr_sja1000_chips);
164                 for (j=0; j<hardware_p->candevice[i]->nr_82527_chips+hardware_p->candevice[i]->nr_sja1000_chips; j++) {
165                         DEBUGMSG("Chip%d type       : %s\n", j+1, hardware_p->candevice[i]->chip[j]->chip_type);
166                         DEBUGMSG("Chip base        : 0x%lx\n",hardware_p->candevice[i]->chip[j]->chip_base_addr);
167                         DEBUGMSG("Interrupt        : %d\n",hardware_p->candevice[i]->chip[j]->chip_irq);
168
169
170                         if (!strcmp(hardware_p->candevice[i]->chip[j]->chip_type,"i82527")) {
171                                 for (k=0; k<15; k++)
172                                         DEBUGMSG("Obj%d: minor: %d base: 0x%lx\n",k,hardware_p->candevice[i]->chip[j]->msgobj[k]->minor,hardware_p->candevice[i]->chip[j]->msgobj[k]->obj_base_addr);
173                         }
174
175                         if (!strcmp(hardware_p->candevice[i]->chip[j]->chip_type,"sja1000")) {
176                                 for (k=0; k<1; k++)
177                                         DEBUGMSG("Obj%d: minor: %d base: 0x%lx\n",k,hardware_p->candevice[i]->chip[j]->msgobj[k]->minor,hardware_p->candevice[i]->chip[j]->msgobj[k]->obj_base_addr);
178                         } 
179
180
181                 }
182                 i++;
183         }
184         return 0;
185 }