]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/pcan_dongle.c
LinCAN sources go through big white-space cleanup.
[lincan.git] / lincan / src / pcan_dongle.c
index 386725b23123ca6dbe385ec3f3ae58d0bacb9d51..7757efbddf73f97f1d59295290c2c5dbce72de8f 100644 (file)
@@ -291,7 +291,7 @@ static int pcan_dongle_probe(struct DONGLE_PORT *dng) // probe for type
   struct parport *p;
 
   DEBUGMSG("%s: pcan_dongle_probe() - PARPORT_SUBSYSTEM\n", DEVICE_NAME);
   struct parport *p;
 
   DEBUGMSG("%s: pcan_dongle_probe() - PARPORT_SUBSYSTEM\n", DEVICE_NAME);
-  
+
   // probe does not probe for the sja1000 device here - this is done at sja1000_open()
   p = parport_find_base(dng->dwPort);
   if (!p)
   // probe does not probe for the sja1000 device here - this is done at sja1000_open()
   p = parport_find_base(dng->dwPort);
   if (!p)
@@ -301,14 +301,14 @@ static int pcan_dongle_probe(struct DONGLE_PORT *dng) // probe for type
   }
   else
   {
   }
   else
   {
-       dng->pardev = parport_register_device(p, "can", NULL, NULL, 
+       dng->pardev = parport_register_device(p, "can", NULL, NULL,
                           (PARPORT_IRQ_HANLDER)dng->chip->chipspecops->irq_handler,
                          0, (void *)dng->chip);
                           (PARPORT_IRQ_HANLDER)dng->chip->chipspecops->irq_handler,
                          0, (void *)dng->chip);
-       
+
 //    DEBUGMSG("datos IRQ: irq_handler=0x%x p=0x%x dng->chip=0x%x dng->pardev->port->irq=0x%x irq_handler2=0x%x\n",
 //             dng->chip->chipspecops->irq_handler,
 //             p,dng->chip,dng->pardev->port->irq, &sja1000p_irq_handler);
 //    DEBUGMSG("datos IRQ: irq_handler=0x%x p=0x%x dng->chip=0x%x dng->pardev->port->irq=0x%x irq_handler2=0x%x\n",
 //             dng->chip->chipspecops->irq_handler,
 //             p,dng->chip,dng->pardev->port->irq, &sja1000p_irq_handler);
-                                     
+
     if (!dng->pardev)
     {
       DEBUGMSG("found no parport device\n");
     if (!dng->pardev)
     {
       DEBUGMSG("found no parport device\n");
@@ -316,7 +316,7 @@ static int pcan_dongle_probe(struct DONGLE_PORT *dng) // probe for type
     }
 
   }
     }
 
   }
-  
+
   return 0;
 }
 
   return 0;
 }
 
@@ -325,11 +325,11 @@ static int pcan_dongle_open(struct DONGLE_PORT *dng)
 {
   int result = 0;
   u16 wPort;
 {
   int result = 0;
   u16 wPort;
-  
+
   DEBUGMSG("%s: pcan_dongle_open()\n", DEVICE_NAME);
   DEBUGMSG("%s: pcan_dongle_open()\n", DEVICE_NAME);
-  
+
   result = parport_claim(dng->pardev);
   result = parport_claim(dng->pardev);
-  
+
   if (!result)
   {
     if (dng->pardev->port->irq == PARPORT_IRQ_NONE)
   if (!result)
   {
     if (dng->pardev->port->irq == PARPORT_IRQ_NONE)
@@ -339,25 +339,25 @@ static int pcan_dongle_open(struct DONGLE_PORT *dng)
     }
   }
   else
     }
   }
   else
-   DEBUGMSG(KERN_ERR "%s: can't claim parport.\n", DEVICE_NAME);       
-  
+   DEBUGMSG(KERN_ERR "%s: can't claim parport.\n", DEVICE_NAME);
+
   // save port state
   if (!result)
    {
       wPort    = (u16)dng->dwPort;
   // save port state
   if (!result)
    {
       wPort    = (u16)dng->dwPort;
-         
+
      // save old port contents
      dng->ucOldDataContent     = can_inb(wPort);
      dng->ucOldControlContent  = can_inb(wPort + 2);
      // save old port contents
      dng->ucOldDataContent     = can_inb(wPort);
      dng->ucOldControlContent  = can_inb(wPort + 2);
-         
+
      // switch to epp mode if possible
      if (dng->wType == HW_DONGLE_SJA_EPP)
      // switch to epp mode if possible
      if (dng->wType == HW_DONGLE_SJA_EPP)
-        setECR(dng); 
-  
+        setECR(dng);
+
     // enable irqs
     _parport_enable_irq(dng); // parport_enable_irq(dng->pardev->port); not working since 2.4.18
     // enable irqs
     _parport_enable_irq(dng); // parport_enable_irq(dng->pardev->port); not working since 2.4.18
-  }    
-       
+  }
+
   return result;
 }
 
   return result;
 }
 
@@ -366,84 +366,84 @@ static int pcan_dongle_release(struct DONGLE_PORT *dng)
   u16 wPort = (u16)dng->dwPort;
 
   DEBUGMSG("%s: pcan_dongle_release()\n", DEVICE_NAME);
   u16 wPort = (u16)dng->dwPort;
 
   DEBUGMSG("%s: pcan_dongle_release()\n", DEVICE_NAME);
-  
+
   // disable irqs
   _parport_disable_irq(dng); // parport_disable_irq(dng->pardev->port); not working since 2.4.18
 
   if (dng->wType == HW_DONGLE_SJA_EPP)
     restoreECR(dng);
   // disable irqs
   _parport_disable_irq(dng); // parport_disable_irq(dng->pardev->port); not working since 2.4.18
 
   if (dng->wType == HW_DONGLE_SJA_EPP)
     restoreECR(dng);
-    
+
   // restore port state
   can_outb(dng->ucOldDataContent, wPort);
   can_outb(dng->ucOldControlContent, wPort + 2);
   // restore port state
   can_outb(dng->ucOldDataContent, wPort);
   can_outb(dng->ucOldControlContent, wPort + 2);
-      
+
   parport_release(dng->pardev);
   parport_release(dng->pardev);
-  
+
   return 0;
 }
 
 int  pcan_dongle_init(struct DONGLE_PORT *dng, u32 dwPort, u16 wIrq, char *type)
 {
   int err;
   return 0;
 }
 
 int  pcan_dongle_init(struct DONGLE_PORT *dng, u32 dwPort, u16 wIrq, char *type)
 {
   int err;
-  
+
   DEBUGMSG("%s: pcan_dongle_init(), dng_devices = %d\n", DEVICE_NAME, dng_devices);
   DEBUGMSG("%s: pcan_dongle_init(), dng_devices = %d\n", DEVICE_NAME, dng_devices);
-  
+
   dng->type = type;
 
   dng->wType = (!strncmp(dongle_type, "sp", 4)) ? HW_DONGLE_SJA : HW_DONGLE_SJA_EPP;
   dng->type = type;
 
   dng->wType = (!strncmp(dongle_type, "sp", 4)) ? HW_DONGLE_SJA : HW_DONGLE_SJA_EPP;
-  
-  // set this before any instructions, fill struct pcandev, part 1 
-  dng->wInitStep   = 0;  
-        
+
+  // set this before any instructions, fill struct pcandev, part 1
+  dng->wInitStep   = 0;
+
   // fill struct pcandev, 1st check if a default is set
   if (!dwPort)
   {
     // there's no default available
     if (dng_devices >= DNG_DEFAULT_COUNT)
       return -ENODEV;
   // fill struct pcandev, 1st check if a default is set
   if (!dwPort)
   {
     // there's no default available
     if (dng_devices >= DNG_DEFAULT_COUNT)
       return -ENODEV;
-    
+
     dng->dwPort = dng_ports[dng_devices];
   }
   else
     dng->dwPort = dwPort;
     dng->dwPort = dng_ports[dng_devices];
   }
   else
     dng->dwPort = dwPort;
-  
+
   if (!wIrq)
   {
     if (dng_devices >= DNG_DEFAULT_COUNT)
       return -ENODEV;
   if (!wIrq)
   {
     if (dng_devices >= DNG_DEFAULT_COUNT)
       return -ENODEV;
-    
-    dng->wIrq   = dng_irqs[dng_devices];    
+
+    dng->wIrq   = dng_irqs[dng_devices];
   }
   else
   }
   else
-    dng->wIrq   = wIrq;    
-  
+    dng->wIrq   = wIrq;
+
   if (dng->wType == HW_DONGLE_SJA)
     {
   if (dng->wType == HW_DONGLE_SJA)
     {
-          dng->nMinor        = PCAN_DNG_SP_MINOR_BASE + sp_devices; 
+          dng->nMinor        = PCAN_DNG_SP_MINOR_BASE + sp_devices;
           dng->wEcr = 0; // set to anything
     }
   else
     {
           dng->wEcr = 0; // set to anything
     }
   else
     {
-           dng->nMinor        = PCAN_DNG_EPP_MINOR_BASE + epp_devices;  
+           dng->nMinor        = PCAN_DNG_EPP_MINOR_BASE + epp_devices;
            dng->wEcr = (u16)dng->dwPort + 0x402;
     }
            dng->wEcr = (u16)dng->dwPort + 0x402;
     }
-         
-       // is the device really available?              
+
+       // is the device really available?
   if ((err = pcan_dongle_probe(dng)) < 0)
     return err;
   if ((err = pcan_dongle_probe(dng)) < 0)
     return err;
-  
+
   if (dng->wType == HW_DONGLE_SJA)
     sp_devices++;
   else
     epp_devices++;
   if (dng->wType == HW_DONGLE_SJA)
     sp_devices++;
   else
     epp_devices++;
-         
+
   dng_devices = sp_devices + epp_devices;
   dng_devices = sp_devices + epp_devices;
-  
+
   dng->wInitStep = 3;
 
   dng->wInitStep = 3;
 
-  DEBUGMSG(KERN_INFO "%s: %s device minor %d prepared (io=0x%04x,irq=%d)\n", DEVICE_NAME, 
+  DEBUGMSG(KERN_INFO "%s: %s device minor %d prepared (io=0x%04x,irq=%d)\n", DEVICE_NAME,
                                dng->type, dng->nMinor, dng->dwPort, dng->wIrq);
                                dng->type, dng->nMinor, dng->dwPort, dng->wIrq);
-       
+
   return 0;
 }
 
   return 0;
 }
 
@@ -457,7 +457,7 @@ int  pcan_dongle_init(struct DONGLE_PORT *dng, u32 dwPort, u16 wIrq, char *type)
  *
  * The function template_request_io() is used to reserve the io-memory. If your
  * hardware uses a dedicated memory range as hardware control registers you
  *
  * The function template_request_io() is used to reserve the io-memory. If your
  * hardware uses a dedicated memory range as hardware control registers you
- * will have to add the code to reserve this memory as well. 
+ * will have to add the code to reserve this memory as well.
  * %IO_RANGE is the io-memory range that gets reserved, please adjust according
  * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
  * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
  * %IO_RANGE is the io-memory range that gets reserved, please adjust according
  * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
  * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
@@ -491,7 +491,7 @@ int pcan_dongle_release_io(struct candevice_t *candev)
 {
        /* release I/O port */
        pcan_dongle_release(&dongle_port);
 {
        /* release I/O port */
        pcan_dongle_release(&dongle_port);
-       
+
        pcan_dongle_cleanup(&dongle_port);
 
        return 0;
        pcan_dongle_cleanup(&dongle_port);
 
        return 0;
@@ -501,8 +501,8 @@ int pcan_dongle_release_io(struct candevice_t *candev)
  * template_reset - hardware reset routine
  * @candev: Pointer to candevice/board structure
  *
  * template_reset - hardware reset routine
  * @candev: Pointer to candevice/board structure
  *
- * The function template_reset() is used to give a hardware reset. This is 
- * rather hardware specific so I haven't included example code. Don't forget to 
+ * The function template_reset() is used to give a hardware reset. This is
+ * rather hardware specific so I haven't included example code. Don't forget to
  * check the reset status of the chip before returning.
  * Return Value: The function returns zero on success or %-ENODEV on failure
  * File: src/template.c
  * check the reset status of the chip before returning.
  * Return Value: The function returns zero on success or %-ENODEV on failure
  * File: src/template.c
@@ -513,14 +513,14 @@ int pcan_dongle_reset(struct candevice_t *candev)
        struct canchip_t *chip;
        int chipnr;
        unsigned cdr;
        struct canchip_t *chip;
        int chipnr;
        unsigned cdr;
-       
+
        DEBUGMSG("Resetting pcan_dongle hardware ...\n");
        for(chipnr=0;chipnr<candev->nr_sja1000_chips;chipnr++) {
                chip=candev->chip[chipnr];
 
          pcan_dongle_write_register(sjaMOD_RM, chip->chip_base_addr+SJAMOD);
          udelay(1000);
        DEBUGMSG("Resetting pcan_dongle hardware ...\n");
        for(chipnr=0;chipnr<candev->nr_sja1000_chips;chipnr++) {
                chip=candev->chip[chipnr];
 
          pcan_dongle_write_register(sjaMOD_RM, chip->chip_base_addr+SJAMOD);
          udelay(1000);
-       
+
          cdr=pcan_dongle_read_register(chip->chip_base_addr+SJACDR);
          pcan_dongle_write_register(cdr|sjaCDR_PELICAN, chip->chip_base_addr+SJACDR);
 
          cdr=pcan_dongle_read_register(chip->chip_base_addr+SJACDR);
          pcan_dongle_write_register(cdr|sjaCDR_PELICAN, chip->chip_base_addr+SJACDR);
 
@@ -564,7 +564,7 @@ int pcan_dongle_reset(struct candevice_t *candev)
  * Return Value: The function always returns zero
  * File: src/template.c
  */
  * Return Value: The function always returns zero
  * File: src/template.c
  */
-int pcan_dongle_init_hw_data(struct candevice_t *candev) 
+int pcan_dongle_init_hw_data(struct candevice_t *candev)
 {
        candev->res_addr=RESET_ADDR;
        candev->nr_82527_chips=NR_82527;
 {
        candev->res_addr=RESET_ADDR;
        candev->nr_82527_chips=NR_82527;
@@ -600,7 +600,7 @@ int pcan_dongle_init_hw_data(struct candevice_t *candev)
  * The entry @int_clk_reg holds hardware specific options for the Clock Out
  * register. Options defined in the %i82527.h file:
  * %iCLK_CD0, %iCLK_CD1, %iCLK_CD2, %iCLK_CD3, %iCLK_SL0, %iCLK_SL1.
  * The entry @int_clk_reg holds hardware specific options for the Clock Out
  * register. Options defined in the %i82527.h file:
  * %iCLK_CD0, %iCLK_CD1, %iCLK_CD2, %iCLK_CD3, %iCLK_SL0, %iCLK_SL1.
- * The entry @int_bus_reg holds hardware specific options for the Bus 
+ * The entry @int_bus_reg holds hardware specific options for the Bus
  * Configuration register. Options defined in the %i82527.h file:
  * %iBUS_DR0, %iBUS_DR1, %iBUS_DT1, %iBUS_POL, %iBUS_CBY.
  * Return Value: The function always returns zero
  * Configuration register. Options defined in the %i82527.h file:
  * %iBUS_DR0, %iBUS_DR1, %iBUS_DT1, %iBUS_POL, %iBUS_CBY.
  * Return Value: The function always returns zero
@@ -622,8 +622,8 @@ int pcan_dongle_init_chip_data(struct candevice_t *candev, int chipnr)
        candev->chip[chipnr]->sja_cdr_reg = sjaCDR_CBP | sjaCDR_CLK_OFF;
        candev->chip[chipnr]->sja_ocr_reg = sjaOCR_MODE_NORMAL | sjaOCR_TX0_LH;
 
        candev->chip[chipnr]->sja_cdr_reg = sjaCDR_CBP | sjaCDR_CLK_OFF;
        candev->chip[chipnr]->sja_ocr_reg = sjaOCR_MODE_NORMAL | sjaOCR_TX0_LH;
 
-       candev->chip[chipnr]->flags |= CHIP_IRQ_CUSTOM;  // I don't want setup call request_irq 
-                                     // I'm going to do it through parport_register_device 
+       candev->chip[chipnr]->flags |= CHIP_IRQ_CUSTOM;  // I don't want setup call request_irq
+                                     // I'm going to do it through parport_register_device
 
      }
 
 
      }
 
@@ -640,7 +640,7 @@ int pcan_dongle_init_chip_data(struct candevice_t *candev, int chipnr)
  * CAN chip. In case of the sja1000 there's only one message object but on the
  * i82527 chip there are 15.
  * The code below is for a i82527 chip and initializes the object base addresses
  * CAN chip. In case of the sja1000 there's only one message object but on the
  * i82527 chip there are 15.
  * The code below is for a i82527 chip and initializes the object base addresses
- * The entry @obj_base_addr represents the first memory address of the message 
+ * The entry @obj_base_addr represents the first memory address of the message
  * object. In case of the sja1000 @obj_base_addr is taken the same as the chips
  * base address.
  * Unless the hardware uses a segmented memory map, flags can be set zero.
  * object. In case of the sja1000 @obj_base_addr is taken the same as the chips
  * base address.
  * Unless the hardware uses a segmented memory map, flags can be set zero.
@@ -651,7 +651,7 @@ int pcan_dongle_init_obj_data(struct canchip_t *chip, int objnr)
 {
        chip->msgobj[objnr]->obj_base_addr=chip->chip_base_addr;
        chip->msgobj[objnr]->obj_flags=0;
 {
        chip->msgobj[objnr]->obj_base_addr=chip->chip_base_addr;
        chip->msgobj[objnr]->obj_flags=0;
-       
+
        return 0;
 }
 
        return 0;
 }
 
@@ -659,10 +659,10 @@ int pcan_dongle_init_obj_data(struct canchip_t *chip, int objnr)
  * template_program_irq - program interrupts
  * @candev: Pointer to candevice/board structure
  *
  * template_program_irq - program interrupts
  * @candev: Pointer to candevice/board structure
  *
- * The function template_program_irq() is used for hardware that uses 
+ * The function template_program_irq() is used for hardware that uses
  * programmable interrupts. If your hardware doesn't use programmable interrupts
  * programmable interrupts. If your hardware doesn't use programmable interrupts
- * you should not set the @candevices_t->flags entry to %CANDEV_PROGRAMMABLE_IRQ and 
- * leave this function unedited. Again this function is hardware specific so 
+ * you should not set the @candevices_t->flags entry to %CANDEV_PROGRAMMABLE_IRQ and
+ * leave this function unedited. Again this function is hardware specific so
  * there's no example code.
  * Return value: The function returns zero on success or %-ENODEV on failure
  * File: src/template.c
  * there's no example code.
  * Return value: The function returns zero on success or %-ENODEV on failure
  * File: src/template.c
@@ -713,10 +713,10 @@ unsigned pcan_dongle_read_register(can_ioptr_t address)
    u8 val;
 
   address -= dongle_port.chip->chip_base_addr;  // it's in mutiplexed mode
    u8 val;
 
   address -= dongle_port.chip->chip_base_addr;  // it's in mutiplexed mode
-       
+
   if (dongle_port.wType == HW_DONGLE_SJA)
      val = pcan_dongle_sp_readreg(&dongle_port, (u8) address); // functions for SP port
   if (dongle_port.wType == HW_DONGLE_SJA)
      val = pcan_dongle_sp_readreg(&dongle_port, (u8) address); // functions for SP port
-  else 
+  else
      val = pcan_dongle_epp_readreg(&dongle_port, (u8) address); // functions for EPP port
 
 //  DEBUGMSG("Read Reg at: 0x%lx data 0x%x \n", address, val);
      val = pcan_dongle_epp_readreg(&dongle_port, (u8) address); // functions for EPP port
 
 //  DEBUGMSG("Read Reg at: 0x%lx data 0x%x \n", address, val);