]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/modparms.c
The original version of Arnaud Westenberg Linux CAN-bus driver
[lincan.git] / lincan / src / modparms.c
diff --git a/lincan/src/modparms.c b/lincan/src/modparms.c
new file mode 100644 (file)
index 0000000..6f9a0de
--- /dev/null
@@ -0,0 +1,185 @@
+/* mod_parms.c
+ * Linux CAN-bus device driver.
+ * Written by Arnaud Westenberg email:arnaud@wanadoo.nl
+ * This software is released under the GPL-License.
+ * Version 0.7  6 Aug 2001
+ */
+
+
+#include <linux/autoconf.h>
+#if defined (CONFIG_MODVERSIONS) && !defined (MODVERSIONS)
+#define MODVERSIONS
+#endif
+
+#if defined (MODVERSIONS)
+#include <linux/modversions.h>
+#endif
+
+#include "../.support"
+#ifndef PIP
+#define PIP 0
+#endif
+#ifndef SMARTCAN
+#define SMARTCAN 0
+#endif
+#ifndef PCCAN
+#define PCCAN 0
+#endif
+#ifndef NSI
+#define NSI 0
+#endif
+#ifndef CC104
+#define CC104 0
+#endif
+#ifndef AIM104
+#define AIM104 0
+#endif
+#ifndef PCI03
+#define PCI03 0
+#endif
+#ifndef PCM3680
+#define PCM3680 0
+#endif
+#ifndef M437
+#define M437 0
+#endif
+#ifndef PCCCAN
+#define PCCCAN 0
+#endif
+#ifndef SSV
+#define SSV 0
+#endif
+#ifndef TEMPLATE
+#define TEMPLATE 0
+#endif
+
+#include <linux/string.h>
+#include <linux/fs.h>
+
+#include "../include/main.h"
+#include "../include/modparms.h"
+
+int parse_mod_parms(void)
+{
+       int i=0,j=0,irq_needed=0,irq_supplied=0,io_needed=0,io_supplied=0,minor_needed=0,minor_supplied=0;
+
+       if ( (hw[0] == NULL) | (irq[0] == -1) | (io[0] == -1) ) {
+               CANMSG("You must supply your type of hardware, interrupt numbers and io address.\n");
+               CANMSG("Example: # insmod can.o hw=pip5 irq=4 io=0x8000\n");
+               return -ENODEV;
+       }
+
+       while ( (hw[i] != NULL) && (i < MAX_HW_CARDS) ) {
+               if ( !strcmp(hw[i],"pip5") && PIP )
+                       irq_needed++;
+               else if (!strcmp(hw[i],"pip6") && PIP)
+                       irq_needed++;
+               else if (!strcmp(hw[i],"smartcan") && SMARTCAN)
+                       irq_needed++;
+               else if (!strcmp(hw[i],"pccan-q") && PCCAN)
+                       irq_needed=irq_needed+4;
+               else if (!strcmp(hw[i],"pccan-f") && PCCAN)
+                       irq_needed++;
+               else if (!strcmp(hw[i],"pccan-s") && PCCAN)
+                       irq_needed++;
+               else if (!strcmp(hw[i],"pccan-d") && PCCAN)
+                       irq_needed=irq_needed+2;
+               else if (!strcmp(hw[i],"nsican") && NSI)
+                       irq_needed++;
+               else if (!strcmp(hw[i],"cc104") && CC104)
+                       irq_needed++;
+               else if (!strcmp(hw[i],"aim104") && AIM104)
+                       irq_needed++;
+               else if (!strcmp(hw[i],"pc-i03") && PCI03)
+                       irq_needed++;
+               else if (!strcmp(hw[i],"pcm3680") && PCM3680)
+                       irq_needed=irq_needed+2;
+               else if (!strcmp(hw[i],"m437") && M437)
+                       irq_needed++;
+               else if (!strcmp(hw[i],"pcccan") && PCCCAN)
+                       irq_needed++;
+               else if (!strcmp(hw[i],"ssv") && SSV)
+                       irq_needed=irq_needed+2;
+               else if (!strcmp(hw[i],"template") && TEMPLATE);
+               else {
+                       CANMSG("Sorry, hardware \"%s\" is currently not supported.\n",hw[i]);
+                       return -EINVAL;
+               }
+               i++;
+       }
+
+       /* Check wether the supplied number of io addresses is correct. */
+       io_needed=i;
+       while ( (io[io_supplied] != -1) & (io_supplied<MAX_HW_CARDS) ) 
+               io_supplied++;
+       if (io_needed != io_supplied) {
+               CANMSG("Invalid number of io addresses.\n");
+               CANMSG("Supplied hardware needs %d io address(es).\n",io_needed);
+               return -EINVAL;
+       }
+
+       /* Check wether the supplied number of irq's is correct. */
+       while ( (irq[irq_supplied] != -1) & (irq_supplied<MAX_IRQ) )
+               irq_supplied++;
+       while ( (hw[j] != NULL) && (j<MAX_HW_CARDS) ) {
+               if (!strcmp(hw[j],"template") && TEMPLATE)
+                       irq_needed = irq_supplied;
+               j++;
+       }
+       if (irq_needed != irq_supplied) {
+               CANMSG("Invalid number of interrupts.\n");
+               CANMSG("Supplied harware needs %d irq number(s).\n",irq_needed);
+               return -EINVAL;
+       }
+
+       /* In case minor numbers were assigned check wether the correct number
+        * of minor numbers was supplied.
+        */
+       if (minor[0] != -1) {
+               minor_needed=irq_needed;
+               while ((minor[minor_supplied] != -1) & (minor_supplied<MAX_IRQ))
+                       minor_supplied++; 
+               if (minor_supplied != minor_needed) {
+                       CANMSG("Invalid number of minor numbers.\n");
+                       CANMSG("Supplied hardware needs %d minor number(s).\n",minor_needed);
+                       return -EINVAL;
+               }
+       }
+
+       return 0;
+}
+/* list_hw is used when debugging is on to show the hardware layout */
+int list_hw(void)
+{
+       int i=0,j=0,k=0;
+
+       DEBUGMSG("Number of boards : %d\n",hardware_p->nr_boards);
+
+       while ( (hw[i] != NULL) & (i<=MAX_HW_CARDS-1) ) {
+               printk(KERN_ERR "\n");
+               DEBUGMSG("Hardware         : %s\n",hardware_p->candevice[i]->hwname);
+               DEBUGMSG("IO address       : 0x%lx\n",hardware_p->candevice[i]->io_addr);
+               DEBUGMSG("Nr. of i82527    : %d\n",hardware_p->candevice[i]->nr_82527_chips);
+               DEBUGMSG("Nr. of sja1000   : %d\n",hardware_p->candevice[i]->nr_sja1000_chips);
+               for (j=0; j<hardware_p->candevice[i]->nr_82527_chips+hardware_p->candevice[i]->nr_sja1000_chips; j++) {
+                       DEBUGMSG("Chip%d type       : %s\n", j+1, hardware_p->candevice[i]->chip[j]->chip_type);
+                       DEBUGMSG("Chip base        : 0x%lx\n",hardware_p->candevice[i]->chip[j]->chip_base_addr);
+                       DEBUGMSG("Interrupt        : %d\n",hardware_p->candevice[i]->chip[j]->chip_irq);
+
+
+                       if (!strcmp(hardware_p->candevice[i]->chip[j]->chip_type,"i82527")) {
+                               for (k=0; k<15; k++)
+                                       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);
+                       }
+
+                       if (!strcmp(hardware_p->candevice[i]->chip[j]->chip_type,"sja1000")) {
+                               for (k=0; k<1; k++)
+                                       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);
+                       } 
+
+
+               }
+               i++;
+       }
+       return 0;
+}