]> rtime.felk.cvut.cz Git - lincan.git/commitdiff
Merge: Committed updated support for MPL AG PIP5, PIP6, PIP7, PIP8
authorppisa <pisa@cmp.felk.cvut.cz>
Wed, 19 Jan 2005 18:45:00 +0000 (19:45 +0100)
committerppisa <pisa@cmp.felk.cvut.cz>
Wed, 19 Jan 2005 18:45:00 +0000 (19:45 +0100)
Merge commit 'remotes/sf-ocera-lincan/master'

lincan/README
lincan/include/pip.h
lincan/src/boardlist.c
lincan/src/i82527.c
lincan/src/pip.c

index 162b9be1d39778a7b99d335c0d6a06284648772b..7245651fc4ed73a1c4325beb922b6d7f5438bf84 100644 (file)
@@ -198,8 +198,10 @@ Examples: # insmod can.o hw=pip5 irq=4 io=0x8000
           # insmod can.o hw=virtual io=0
 
 The hw argument can be one of:
-- pip5, for the pip5 computer by MPL
-- pip6, for the pip6 computer by MPL
+- pip5, for the PIP5 computer by MPL
+- pip6, for the PIP6 computer by MPL
+- pip7, for the PIP7 computer by MPL
+- pip8, for the PIP8 computer by MPL
 - pccan-q, for the PCcan-Q ISA card by KVASER
 - pccan-f, for the PCcan-F ISA card by KVASER
 - pccan-s, for the PCcan-S ISA card by KVASER
index bcec26b3d518b7bea5de83901390a1e283edc6a6..5feddfe5ae937d46c5a65bafa8655e0f00d2b007 100644 (file)
@@ -5,15 +5,17 @@
  * email:pisa@cmp.felk.cvut.cz
  * This software is released under the GPL-License.
  * Version lincan-0.3  17 Jun 2004
+ * Modified for PIP5,PIP6,PIP7 and PIP8
+ * Stefan Peter, MPL AG, info@mpl.ch
  */
 
-int pip5_request_io(struct candevice_t *candev);
-int pip5_release_io(struct candevice_t *candev);
-int pip5_reset(struct candevice_t *candev); 
-int pip5_init_hw_data(struct candevice_t *candev);
-int pip5_init_chip_data(struct candevice_t *candev, int chipnr);
-int pip5_init_obj_data(struct canchip_t *chip, int objnr);
-void pip5_write_register(unsigned data, unsigned long address);
-unsigned pip5_read_register(unsigned long address);
-int pip5_program_irq(struct candevice_t *candev);
+int pip_request_io(struct candevice_t *candev);
+int pip_release_io(struct candevice_t *candev);
+int pip_reset(struct candevice_t *candev); 
+int pip_init_hw_data(struct candevice_t *candev);
+int pip_init_chip_data(struct candevice_t *candev, int chipnr);
+int pip_init_obj_data(struct canchip_t *chip, int objnr);
+void pip_write_register(unsigned data, unsigned long address);
+unsigned pip_read_register(unsigned long address);
+int pip_program_irq(struct candevice_t *candev);
 
index 19a03d79e614f739b4be0ce957680965c67e2334..217a3e907a32cc74275e3338dfb4b8dd8c7bb699 100644 (file)
@@ -13,8 +13,7 @@
 extern int template_register(struct hwspecops_t *hwspecops);
 extern int virtual_register(struct hwspecops_t *hwspecops);
 extern int oscar_register(struct hwspecops_t *hwspecops);
-extern int pip5_register(struct hwspecops_t *hwspecops);
-extern int pip6_register(struct hwspecops_t *hwspecops);
+extern int pip_register(struct hwspecops_t *hwspecops);
 extern int m437_register(struct hwspecops_t *hwspecops);
 extern int smartcan_register(struct hwspecops_t *hwspecops);
 extern int pccanf_register(struct hwspecops_t *hwspecops);
@@ -49,8 +48,10 @@ const struct boardtype_t can_boardtypes[]={
        {"oscar", oscar_register, 1},
     #endif
     #ifdef CONFIG_OC_LINCAN_CARD_pip
-       {"pip5", pip5_register, 1},
-       {"pip6", pip6_register, 1},
+       {"pip5", pip_register, 1},
+       {"pip6", pip_register, 1},
+       {"pip7", pip_register, 1},
+       {"pip8", pip_register, 1},
     #endif
     #ifdef CONFIG_OC_LINCAN_CARD_smartcan
        {"smartcan", smartcan_register, 1},
index fb232f380725269d2fc8e0b224d6df92ea3a420e..4ffad1766310500512a0739b581fd56c2db0c56d 100644 (file)
@@ -635,6 +635,7 @@ int i82527_irq_handler(int irq, struct canchip_t *chip)
 
                if(!loop_cnt--) {
                        CANMSG("i82527_irq_handler IRQ %d stuck\n",irq);
+                       CANMSG("i82527_irq_register 0x%x\n",irq_register);
                        return CANCHIP_IRQ_STUCK;
                }
                
index 1f3418ebca01bda3e3034226c2111d626dba7e6d..f0a04de451439ffedb7486260db7ccf52bb7acbe 100644 (file)
  * Written by Arnaud Westenberg email:arnaud@wanadoo.nl
  * Rewritten for new CAN queues by Pavel Pisa - OCERA team member
  * email:pisa@cmp.felk.cvut.cz
+ * Adapted for actual PIP5 Version and PIP7 and PIP8 by
+ * Stefan Peter, MPL AG, Switzerland
+ * email:support@mpl.ch
  * This software is released under the GPL-License.
  * Version lincan-0.3  17 Jun 2004
- */ 
+ */
+/* This is the CAN driver for the PIP5,PIP6,PIP7 and PIP8 
+ * Packaged Industrial PCs of MPL AG, Switzerland. 
+ */
+
 
 #include "../include/can.h"
 #include "../include/can_sysdep.h"
 #include "../include/main.h"
 #include "../include/pip.h"
 #include "../include/i82527.h"
-
-int pip5_request_io(struct candevice_t *candev)
-{
-       if (candev->io_addr != 0x8000) {
-               CANMSG("Invalid base io address\n");
-               CANMSG("The PIP5 uses a fixed base address of 0x8000,\n");
-               CANMSG("please consult your user manual.\n");
-               return -ENODEV;
-       }
-       if (!can_request_io_region(candev->io_addr,0x100,DEVICE_NAME)) {
-               CANMSG("Unable to open port: 0x%lx\n",candev->io_addr);
-               return -ENODEV;
-       }
-       else if(!can_request_io_region(candev->io_addr+0x102,0x01,DEVICE_NAME)) {
-               can_release_io_region(candev->io_addr,0x100);
-               CANMSG("Unable to open port: 0x%lx\n",candev->io_addr+0x102);
-               return -ENODEV;
-       }
-       else {
-               DEBUGMSG("Registered IO-memory: 0x%lx - 0x%lx\n", candev->io_addr, candev->io_addr + 0x100 - 1);
-               DEBUGMSG("Registered IO-memory: 0x%lx\n", candev->io_addr+0x102);
-       }
-       return 0;
-}
-
-int pip6_request_io(struct candevice_t *candev)
+/* PIP Specific Extension registers */
+#define PIP_CANRES_REG 0x804   /* CAN Resources */
+#define PIP_CANCTRL_REG (PIP_CANRES_REG+1)     /* CAN Control */
+/* Interrupt maps for the various PIP variants, see user manual */
+#define PIP5_IRQ_MAP 0x4F6D
+#define PIP6_IRQ_MAP 0xDEF8
+#define PIP7_IRQ_MAP 0x3768
+#define PIP8_IRQ_MAP 0x3768
+
+int pip_request_io(struct candevice_t *candev)
 {
-       if ( (candev->io_addr != 0x1000)&&(candev->io_addr != 0x8000)&&(candev->io_addr != 0xe000)) {
+       if ((candev->io_addr != 0x1000) && (candev->io_addr != 0x8000)
+           && (candev->io_addr != 0xe000)) {
                CANMSG("Invalid base io address\n");
-               CANMSG("Valid values for the PIP6 are: 0x1000, 0x8000 or 0xe000\n");
+               CANMSG
+                   ("Valid values for the PIP are: 0x1000, 0x8000 or 0xe000\n");
                CANMSG("Please consult your user manual.\n");
                return -ENODEV;
        }
-       if (!can_request_io_region(candev->io_addr,0x100, DEVICE_NAME)) {
-               CANMSG("Unable to open port: 0x%lx\n",candev->io_addr);
+       if (!can_request_io_region(candev->io_addr, 0x100, DEVICE_NAME)) {
+               CANMSG("Unable to open port: 0x%lx\n", candev->io_addr);
                return -ENODEV;
-       }
-       else if (!can_request_io_region(0x804,0x02,DEVICE_NAME)) {
-               can_release_io_region(candev->io_addr,0x100);
-               CANMSG("Unable to open port: 0x%x\n", 0x804);
+       } else
+           if (!can_request_io_region(PIP_CANRES_REG, 0x02, DEVICE_NAME))
+       {
+               can_release_io_region(candev->io_addr, 0x100);
+               CANMSG("Unable to open port: 0x%x\n", PIP_CANRES_REG);
                return -ENODEV;
-       }
-       else {
-               DEBUGMSG("Registered IO-memory: 0x%lx - 0x%lx\n", candev->io_addr, candev->io_addr + 0x100 -1);
-               DEBUGMSG("Registered IO-memory : 0x%x - 0x%x\n",0x804,0x805);
+       } else {
+               DEBUGMSG("Registered IO-memory: 0x%lx - 0x%lx\n",
+                        candev->io_addr, candev->io_addr + 0x100 - 1);
+               DEBUGMSG("Registered IO-memory : 0x%x - 0x%x\n",
+                        PIP_CANRES_REG, PIP_CANCTRL_REG);
        }
        return 0;
 }
 
-int pip5_release_io(struct candevice_t *candev)
+int pip_release_io(struct candevice_t *candev)
 {
-       can_release_io_region(candev->io_addr,0x100);
-       can_release_io_region(candev->io_addr+0x102,0x01);
-
-       return 0;
-}
-
-int pip6_release_io(struct candevice_t *candev)
-{
-       can_release_io_region(candev->io_addr,0x100);
-       can_release_io_region(0x804,0x02);
+       can_release_io_region(candev->io_addr, 0x100);
+       can_release_io_region(PIP_CANRES_REG, 0x02);
 
        return 0;
 }
 
 int pip_reset(struct candevice_t *candev)
 {
-       int i=0, res_value=0;
+       int i = 0;
 
        DEBUGMSG("Resetting %s hardware ...\n", candev->hwname);
-       if (!strcmp(candev->hwname,"pip5"))
-               res_value = 0xcf;
-       else
-               res_value = 0x01;
        while (i < 1000000) {
                i++;
-               outb(res_value,candev->res_addr);
+               outb(0x01, candev->res_addr);
        }
-       outb(0x0,candev->res_addr);
+       outb(0x0, candev->res_addr);
 
        /* Check hardware reset status */
-       i=0;
-       while ( (inb(candev->io_addr+iCPU) & iCPU_RST) && (i<=15)) {
+       i = 0;
+       while ((inb(candev->io_addr + iCPU) & iCPU_RST) && (i <= 15)) {
                udelay(20000);
                i++;
        }
-       if (i>=15) {
+       if (i >= 15) {
                CANMSG("Reset status timeout!\n");
                CANMSG("Please check your hardware.\n");
                return -ENODEV;
-       }
-       else
+       } else
                DEBUGMSG("Chip0 reset status ok.\n");
-       
+
 
        return 0;
 }
 
-int pip_init_hw_data(struct candevice_t *candev) 
+int pip_init_hw_data(struct candevice_t *candev)
 {
-       if (!strcmp(candev->hwname,"pip5"))
-               candev->res_addr=candev->io_addr+0x102;
-       else
-               candev->res_addr=0x805;
-       candev->nr_82527_chips=1;
-       candev->nr_sja1000_chips=0;
-       candev->nr_all_chips=1;
+       candev->res_addr = PIP_CANCTRL_REG;
+       candev->nr_82527_chips = 1;
+       candev->nr_sja1000_chips = 0;
+       candev->nr_all_chips = 1;
        candev->flags |= CANDEV_PROGRAMMABLE_IRQ;
 
        return 0;
@@ -127,12 +106,9 @@ int pip_init_hw_data(struct candevice_t *candev)
 int pip_init_chip_data(struct candevice_t *candev, int chipnr)
 {
        i82527_fill_chipspecops(candev->chip[chipnr]);
-       candev->chip[chipnr]->chip_base_addr=candev->io_addr;
+       candev->chip[chipnr]->chip_base_addr = candev->io_addr;
        candev->chip[chipnr]->clock = 16000000;
-       if (!strcmp(candev->hwname,"pip5"))
-               candev->chip[chipnr]->int_cpu_reg = iCPU_DSC;
-       else
-               candev->chip[chipnr]->int_cpu_reg = 0x0;
+       candev->chip[chipnr]->int_cpu_reg = 0;
        candev->chip[chipnr]->int_clk_reg = iCLK_SL1;
        candev->chip[chipnr]->int_bus_reg = iBUS_CBY;
        candev->chip[chipnr]->sja_cdr_reg = 0;
@@ -143,63 +119,77 @@ int pip_init_chip_data(struct candevice_t *candev, int chipnr)
 
 int pip_init_obj_data(struct canchip_t *chip, int objnr)
 {
-       chip->msgobj[objnr]->obj_base_addr=chip->chip_base_addr+(objnr+1)*0x10;
-       
+       chip->msgobj[objnr]->obj_base_addr =
+           chip->chip_base_addr + (objnr + 1) * 0x10;
+
        return 0;
 }
 
-int pip5_program_irq(struct candevice_t *candev)
+int pip_program_irq(struct candevice_t *candev)
 {
+       unsigned int irq_mask;
+       unsigned char can_addr = 0, can_reg = 0;
+       DEBUGMSG("pip_program_irq\n");
+       /* Reset can controller */
        outb(0x01, candev->res_addr);
-       switch (candev->chip[0]->chip_irq) {
-               case  3: { outb(0x03, candev->res_addr); break; }
-               case  4: { outb(0x05, candev->res_addr); break; }
-               case  5: { outb(0x07, candev->res_addr); break; }
-               case 10: { outb(0x09, candev->res_addr); break; }
-               case 11: { outb(0x0c, candev->res_addr); break; }
-               case 15: { outb(0x0d, candev->res_addr); break; }
-               default: {
-               CANMSG("Supplied interrupt is not supported by the hardware\n");
-               CANMSG("Please consult your user manual.\n");
+       if (strcmp(candev->hwname, "pip5") == 0) {
+               irq_mask = PIP5_IRQ_MAP;
+       } else if (strcmp(candev->hwname, "pip6") == 0) {
+               irq_mask = PIP6_IRQ_MAP;
+       } else if (strcmp(candev->hwname, "pip7") == 0) {
+               irq_mask = PIP7_IRQ_MAP;
+       } else if (strcmp(candev->hwname, "pip8") == 0) {
+               irq_mask = PIP8_IRQ_MAP;
+       } else {
+               CANMSG("Unsupported PIP specified.\n");
                return -ENODEV;
-               }
        }
-       outb(0x00, candev->res_addr);
-
-       return 0;
-}
-
-int pip6_program_irq(struct candevice_t *candev)
-{
-       unsigned char can_int = 0, can_addr = 0;
-
-       can_int = candev->chip[0]->chip_irq;
-       if ((can_int != 3) && (can_int != 4) && (can_int != 5) && (can_int != 6)
-               && (can_int != 7) && (can_int != 9) && (can_int != 10) && 
-               (can_int != 11) && (can_int != 12) && (can_int != 14) && 
-               (can_int != 15)) {
-               CANMSG("Invalid interrupt number\n");
-               CANMSG("Valid interrupt numbers for the PIP6: 3,4,5,6,7,9,10,11,12,14 or 15\n");
-               CANMSG("Please consult your user manual.\n");
+       if ((candev->chip[0]->chip_irq < 1)
+           || (candev->chip[0]->chip_irq > 15)) {
+               CANMSG("Interrupt specified does not exist.\n");
                return -ENODEV;
        }
-       switch (candev->io_addr) {
-               case 0x1000: { can_addr = 0x01; break; }
-               case 0x8000: { can_addr = 0x02; break; }
-               case 0xe000: { can_addr = 0x03; break; }
-               default: {
-               CANMSG("Supplied io address is not valid, please check your manual\n");
+       if (((0x01 << (candev->chip[0]->chip_irq - 1)) & irq_mask) == 0) {
+               CANMSG("Invalid Interrupt specified %d\n",
+                      candev->chip[0]->chip_irq);
                return -ENODEV;
+       }
+
+       /* set the IRQ routing of the board accordingly */
+       switch (candev->io_addr) {
+       case 0x1000:{
+                       can_addr = 0x01;
+                       break;
+               }
+       case 0x8000:{
+                       can_addr = 0x02;
+                       break;
+               }
+       case 0xe000:{
+                       can_addr = 0x03;
+                       break;
+               }
+       default:{
+                       CANMSG
+                           ("Supplied io address is not valid, please check your manual\n");
+                       return -ENODEV;
                }
        }
-       outb( (can_int<<4)|can_addr, 0x804);
+       can_reg = inb(PIP_CANRES_REG);
+       DEBUGMSG("PIP_CANRES was 0x%x\n", can_reg);
+       can_reg = (candev->chip[0]->chip_irq << 4) | can_addr;
+       DEBUGMSG("Setting PIP_CANRES_REG to 0x%x\n", can_reg);
+       outb((candev->chip[0]->chip_irq << 4) | can_addr, PIP_CANRES_REG);
+       /* re-enable the chip */
+       outb(0x00, candev->res_addr);
 
        return 0;
 }
 
+
 void pip_write_register(unsigned data, unsigned long address)
 {
-       outb(data,address);
+       outb(data, address);
 }
 
 unsigned pip_read_register(unsigned long address)
@@ -208,30 +198,16 @@ unsigned pip_read_register(unsigned long address)
 }
 
 /* !!! Don't change these functions !!! */
-int pip5_register(struct hwspecops_t *hwspecops)
-{
-       hwspecops->request_io = pip5_request_io;
-       hwspecops->release_io = pip5_release_io;
-       hwspecops->reset = pip_reset;
-       hwspecops->init_hw_data = pip_init_hw_data;
-       hwspecops->init_chip_data = pip_init_chip_data;
-       hwspecops->init_obj_data = pip_init_obj_data;
-       hwspecops->write_register = pip_write_register;
-       hwspecops->read_register = pip_read_register;
-       hwspecops->program_irq = pip5_program_irq;
-       return 0;
-}
-
-int pip6_register(struct hwspecops_t *hwspecops)
+int pip_register(struct hwspecops_t *hwspecops)
 {
-       hwspecops->request_io = pip6_request_io;
-       hwspecops->release_io = pip6_release_io;
+       hwspecops->request_io = pip_request_io;
+       hwspecops->release_io = pip_release_io;
        hwspecops->reset = pip_reset;
        hwspecops->init_hw_data = pip_init_hw_data;
        hwspecops->init_chip_data = pip_init_chip_data;
        hwspecops->init_obj_data = pip_init_obj_data;
        hwspecops->write_register = pip_write_register;
        hwspecops->read_register = pip_read_register;
-       hwspecops->program_irq = pip6_program_irq;
+       hwspecops->program_irq = pip_program_irq;
        return 0;
 }