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