]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/modparms.c
1608bd2d080b8af3009f55c692fd4028561383da
[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 <linux/string.h>
14 #include <linux/fs.h>
15
16 #include "../include/main.h"
17 #include "../include/modparms.h"
18
19 int parse_mod_parms(void)
20 {
21         int i=0,j=0,irq_needed=0,irq_supplied=0,io_needed=0,io_supplied=0,minor_needed=0,minor_supplied=0;
22         const struct boardtype_t *brp;
23
24         if ( (hw[0] == NULL) | (io[0] == -1) ) {
25                 CANMSG("You must supply your type of hardware, interrupt numbers and io address.\n");
26                 CANMSG("Example: # insmod can.o hw=pip5 irq=4 io=0x8000\n");
27                 return -ENODEV;
28         }
29
30         while ( (hw[i] != NULL) && (i < MAX_HW_CARDS) ) {
31                 brp = boardtype_find(hw[i]);
32                 if(!brp) {
33                         CANMSG("Sorry, hardware \"%s\" is currently not supported.\n",hw[i]);
34                         return -EINVAL;
35                 }
36                 irq_needed += brp->irqnum;
37                 i++;
38         }
39
40         /* Check wether the supplied number of io addresses is correct. */
41         io_needed=i;
42         while ( (io[io_supplied] != -1) & (io_supplied<MAX_HW_CARDS) ) 
43                 io_supplied++;
44         if (io_needed != io_supplied) {
45                 CANMSG("Invalid number of io addresses.\n");
46                 CANMSG("Supplied hardware needs %d io address(es).\n",io_needed);
47                 return -EINVAL;
48         }
49
50         /* Check wether the supplied number of irq's is correct. */
51         while ( (irq[irq_supplied] != -1) & (irq_supplied<MAX_IRQ) )
52                 irq_supplied++;
53         while ( (hw[j] != NULL) && (j<MAX_HW_CARDS) ) {
54                 if (!strcmp(hw[j],"template"))
55                         irq_needed = irq_supplied;
56                 j++;
57         }
58         if (irq_needed != irq_supplied) {
59                 CANMSG("Invalid number of interrupts.\n");
60                 CANMSG("Supplied harware needs %d irq number(s).\n",irq_needed);
61                 return -EINVAL;
62         }
63
64         /* In case minor numbers were assigned check wether the correct number
65          * of minor numbers was supplied.
66          */
67         if (minor[0] != -1) {
68                 minor_needed=irq_needed;
69                 while ((minor[minor_supplied] != -1) & (minor_supplied<MAX_IRQ))
70                         minor_supplied++; 
71                 if (minor_supplied != minor_needed) {
72                         CANMSG("Invalid number of minor numbers.\n");
73                         CANMSG("Supplied hardware needs %d minor number(s).\n",minor_needed);
74                         return -EINVAL;
75                 }
76         }
77
78         return 0;
79 }
80 /* list_hw is used when debugging is on to show the hardware layout */
81 int list_hw(void)
82 {
83         int i=0,j=0,k=0;
84
85         DEBUGMSG("Number of boards : %d\n",hardware_p->nr_boards);
86
87         while ( (hw[i] != NULL) & (i<=MAX_HW_CARDS-1) ) {
88                 printk(KERN_ERR "\n");
89                 DEBUGMSG("Hardware         : %s\n",hardware_p->candevice[i]->hwname);
90                 DEBUGMSG("IO address       : 0x%lx\n",hardware_p->candevice[i]->io_addr);
91                 DEBUGMSG("Nr. all chips    : %d\n",hardware_p->candevice[i]->nr_all_chips);
92                 DEBUGMSG("Nr. of i82527    : %d\n",hardware_p->candevice[i]->nr_82527_chips);
93                 DEBUGMSG("Nr. of sja1000   : %d\n",hardware_p->candevice[i]->nr_sja1000_chips);
94                 for (j=0; j<hardware_p->candevice[i]->nr_all_chips; j++) {
95                         DEBUGMSG("Chip%d type       : %s\n", j+1, hardware_p->candevice[i]->chip[j]->chip_type);
96                         DEBUGMSG("Chip base        : 0x%lx\n",hardware_p->candevice[i]->chip[j]->chip_base_addr);
97                         DEBUGMSG("Interrupt        : %d\n",hardware_p->candevice[i]->chip[j]->chip_irq);
98
99
100                         for (k=0; k<hardware_p->candevice[i]->chip[j]->max_objects; k++)
101                                 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);
102
103                 }
104                 i++;
105         }
106         return 0;
107 }