]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/modparms.c
Merge branch 'master' into can-usb1
[lincan.git] / lincan / src / modparms.c
1 /**************************************************************************/
2 /* File: modparms.c - driver module parameters parsing                    */
3 /*                                                                        */
4 /* LinCAN - (Not only) Linux CAN bus driver                               */
5 /* Copyright (C) 2002-2009 DCE FEE CTU Prague <http://dce.felk.cvut.cz>   */
6 /* Copyright (C) 2002-2009 Pavel Pisa <pisa@cmp.felk.cvut.cz>             */
7 /* Funded by OCERA and FRESCOR IST projects                               */
8 /* Based on CAN driver code by Arnaud Westenberg <arnaud@wanadoo.nl>      */
9 /*                                                                        */
10 /* LinCAN is free software; you can redistribute it and/or modify it      */
11 /* under terms of the GNU General Public License as published by the      */
12 /* Free Software Foundation; either version 2, or (at your option) any    */
13 /* later version.  LinCAN is distributed in the hope that it will be      */
14 /* useful, but WITHOUT ANY WARRANTY; without even the implied warranty    */
15 /* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU    */
16 /* General Public License for more details. You should have received a    */
17 /* copy of the GNU General Public License along with LinCAN; see file     */
18 /* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,  */
19 /* Cambridge, MA 02139, USA.                                              */
20 /*                                                                        */
21 /* To allow use of LinCAN in the compact embedded systems firmware        */
22 /* and RT-executives (RTEMS for example), main authors agree with next    */
23 /* special exception:                                                     */
24 /*                                                                        */
25 /* Including LinCAN header files in a file, instantiating LinCAN generics */
26 /* or templates, or linking other files with LinCAN objects to produce    */
27 /* an application image/executable, does not by itself cause the          */
28 /* resulting application image/executable to be covered by                */
29 /* the GNU General Public License.                                        */
30 /* This exception does not however invalidate any other reasons           */
31 /* why the executable file might be covered by the GNU Public License.    */
32 /* Publication of enhanced or derived LinCAN files is required although.  */
33 /**************************************************************************/
34
35
36 #include "../include/can.h"
37 #include "../include/can_sysdep.h"
38 #include "../include/main.h"
39 #include "../include/modparms.h"
40
41 int parse_mod_parms(void)
42 {
43         int i=0,j=0,irq_needed=0,irq_supplied=0,io_needed=0,io_supplied=0,minor_needed=0,minor_supplied=0;
44         const struct boardtype_t *brp;
45
46         if ( (hw[0] == NULL) | (io[0] == -1) ) {
47                 //CANMSG("You must supply your type of hardware, interrupt numbers and io address.\n");
48                 CANMSG("Autodetection works only for USB devices, supply your type of hardware for PCI devices \n");
49                 CANMSG("Example: # insmod lincan.ko hw=pip5 irq=4 io=0x8000\n");
50                 //return -ENODEV;
51         }
52
53         while ( (hw[i] != NULL) && (i < MAX_HW_CARDS) ) {
54                 brp = boardtype_find(hw[i]);
55                 if(!brp) {
56                         CANMSG("Sorry, hardware \"%s\" is currently not supported.\n",hw[i]);
57                         return -EINVAL;
58                 }
59                 irq_needed += brp->irqnum;
60                 i++;
61         }
62
63         /* Check wether the supplied number of io addresses is correct. */
64         io_needed=i;
65         while ( (io[io_supplied] != -1) & (io_supplied<MAX_HW_CARDS) )
66                 io_supplied++;
67         if (io_needed != io_supplied) {
68                 CANMSG("Invalid number of io addresses.\n");
69                 CANMSG("Supplied hardware needs %d io address(es).\n",io_needed);
70                 return -EINVAL;
71         }
72
73         /* Check wether the supplied number of irq's is correct. */
74         while ( (irq[irq_supplied] != -1) & (irq_supplied<MAX_IRQ) )
75                 irq_supplied++;
76         while ( (hw[j] != NULL) && (j<MAX_HW_CARDS) ) {
77                 if (!strcmp(hw[j],"template"))
78                         irq_needed = irq_supplied;
79                 j++;
80         }
81         if (irq_needed != irq_supplied) {
82                 CANMSG("Invalid number of interrupts.\n");
83                 CANMSG("Supplied harware needs %d irq number(s).\n",irq_needed);
84                 return -EINVAL;
85         }
86
87         /* In case minor numbers were assigned check wether the correct number
88          * of minor numbers was supplied.
89          */
90         if (minor[0] != -1) {
91                 minor_needed=irq_needed;
92                 while ((minor[minor_supplied] != -1) & (minor_supplied<MAX_IRQ))
93                         minor_supplied++;
94                 if (minor_supplied != minor_needed) {
95                         CANMSG("Invalid number of minor numbers.\n");
96                         CANMSG("Supplied hardware needs %d minor number(s).\n",minor_needed);
97                         return -EINVAL;
98                 }
99         }
100
101         return 0;
102 }
103 /* list_hw is used when debugging is on to show the hardware layout */
104 int list_hw(void)
105 {
106         int i=0,j=0,k=0;
107
108         DEBUGMSG("Number of boards : %d\n",hardware_p->nr_boards);
109
110         while ( (hw[i] != NULL) & (i<=MAX_HW_CARDS-1) ) {
111                 printk(KERN_ERR "\n");
112                 DEBUGMSG("Hardware         : %s\n",hardware_p->candevice[i]->hwname);
113                 DEBUGMSG("IO address       : 0x%lx\n",hardware_p->candevice[i]->io_addr);
114                 DEBUGMSG("Nr. all chips    : %d\n",hardware_p->candevice[i]->nr_all_chips);
115                 DEBUGMSG("Nr. of i82527    : %d\n",hardware_p->candevice[i]->nr_82527_chips);
116                 DEBUGMSG("Nr. of sja1000   : %d\n",hardware_p->candevice[i]->nr_sja1000_chips);
117                 for (j=0; j<hardware_p->candevice[i]->nr_all_chips; j++) {
118                         DEBUGMSG("Chip%d type       : %s\n", j+1, hardware_p->candevice[i]->chip[j]->chip_type);
119                         DEBUGMSG("Chip base        : 0x%lx\n",hardware_p->candevice[i]->chip[j]->chip_base_addr);
120                         DEBUGMSG("Interrupt        : %d\n",hardware_p->candevice[i]->chip[j]->chip_irq);
121
122
123                         for (k=0; k<hardware_p->candevice[i]->chip[j]->max_objects; k++)
124                                 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);
125
126                 }
127                 i++;
128         }
129         return 0;
130 }