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