LinCAN driver updated to work on Real-Time Preemption enabled kernel.
authorppisa <ppisa>
Sun, 6 Nov 2005 00:20:47 +0000 (00:20 +0000)
committerppisa <ppisa>
Sun, 6 Nov 2005 00:20:47 +0000 (00:20 +0000)
Code tested on SJA1000 controller on the ARM based system
with Linux kernel 2.6.14 and Ingo Molnar's 2.6.14-rt5 patch.

lincan/include/can_sysdep.h
lincan/src/bfadcan.c
lincan/src/c_can.c
lincan/src/msmcan.c
lincan/src/nsi.c
lincan/src/pcan_dongle.c
lincan/src/pcccan.c
lincan/src/pimx1.c
lincan/src/smartcan.c
lincan/src/ssv.c

index 3966e8f..5a3b86c 100644 (file)
 #define can_spin_unlock_irqrestore spin_unlock_irqrestore
 #define can_spin_lock_init         spin_lock_init
 
+#ifndef DEFINE_SPINLOCK
+#define CAN_DEFINE_SPINLOCK(x)     can_spinlock_t x = SPIN_LOCK_UNLOCKED
+#else /*DEFINE_SPINLOCK*/
+#define CAN_DEFINE_SPINLOCK        DEFINE_SPINLOCK
+#endif /*DEFINE_SPINLOCK*/
+
 #if defined(CONFIG_PREEMPT) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
 #define can_preempt_disable        preempt_disable
 #define can_preempt_enable         preempt_enable
 #define can_spin_unlock_irqrestore rtl_spin_unlock_irqrestore
 #define can_spin_lock_init         rtl_spin_lock_init
 
+#define CAN_DEFINE_SPINLOCK(x)     can_spinlock_t x = SPIN_LOCK_UNLOCKED
+
 #define can_preempt_disable()      do { } while (0)
 #define can_preempt_enable()       do { } while (0)
 
index 78c7660..f6d831b 100644 (file)
@@ -28,7 +28,7 @@ MODULE_PARM(clock_freq,"i");
 
 /* cli and sti are not allowed in 2.5.5x SMP kernels */
 #ifdef WINDOWED_ACCESS
-static can_spinlock_t bfadcan_win_lock=SPIN_LOCK_UNLOCKED;
+static CAN_DEFINE_SPINLOCK(bfadcan_win_lock);
 #endif
 
 /*
index ed3991c..9929467 100644 (file)
 extern int stdmask;
 extern int extmask;
 
-can_spinlock_t c_can_spwlock = SPIN_LOCK_UNLOCKED;     // Spin lock for write operations
-can_spinlock_t c_can_sprlock = SPIN_LOCK_UNLOCKED;     // Spin lock for read operations
-can_spinlock_t c_can_if1lock = SPIN_LOCK_UNLOCKED;     // spin lock for the if1 register
-can_spinlock_t c_can_if2lock = SPIN_LOCK_UNLOCKED;     // spin lcok for the if2 register
+CAN_DEFINE_SPINLOCK(c_can_spwlock);    // Spin lock for write operations
+CAN_DEFINE_SPINLOCK(c_can_sprlock);    // Spin lock for read operations
+CAN_DEFINE_SPINLOCK(c_can_if1lock);    // spin lock for the if1 register
+CAN_DEFINE_SPINLOCK(c_can_if2lock);    // spin lcok for the if2 register
 
 /**
  * c_can_enable_configuration - enable chip configuration mode
index 230e786..9851b5f 100644 (file)
@@ -13,7 +13,7 @@
 #include "../include/msmcan.h"
 #include "../include/i82527.h"
 
-static can_spinlock_t msmcan_port_lock=SPIN_LOCK_UNLOCKED;
+static CAN_DEFINE_SPINLOCK(msmcan_port_lock);
 
 /* IO_RANGE is the io-memory range that gets reserved, please adjust according
  * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
index 777850b..ce9c591 100644 (file)
@@ -16,7 +16,7 @@
 int nsican_irq=-1;
 unsigned long nsican_base=0x0;
 
-static can_spinlock_t nsican_port_lock=SPIN_LOCK_UNLOCKED;
+static CAN_DEFINE_SPINLOCK(nsican_port_lock);
 
 /* IO_RANGE is the io-memory range that gets reserved, please adjust according
  * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
index 6bd3496..ce94186 100644 (file)
@@ -109,7 +109,7 @@ typedef void (*PARPORT_IRQ_HANLDER)(int, void *, struct pt_regs *);
 
 /****************************************************************************/
 // GLOBALS
-spinlock_t pcan_lock = SPIN_LOCK_UNLOCKED;
+CAN_DEFINE_SPINLOCK(pcan_lock);
 
 /****************************************************************************/
 // LOCALS
@@ -158,14 +158,9 @@ static u8 pcan_dongle_sp_readreg(struct DONGLE_PORT *dng, u8 port) // read a reg
   u16 _PC_ = _PB_ + 1;
   u8  b0, b1 ;
   u8  irqEnable = inb(_PC_) & 0x10; // don't influence irqEnable
-  unsigned long flags;
+  can_spin_irqflags_t flags;
 
-  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
-  save_flags(flags);
-  cli();
-  #else
-  spin_lock_irqsave(&pcan_lock, flags);
-  #endif
+  can_spin_lock_irqsave(&pcan_lock, flags);
 
   outb((0x0B ^ 0x0D) | irqEnable, _PC_);
   outb((port & 0x1F) | 0x80,      _PA_);
@@ -175,11 +170,7 @@ static u8 pcan_dongle_sp_readreg(struct DONGLE_PORT *dng, u8 port) // read a reg
   b0=nibble_decode[inb(_PB_)>>3];
   outb((0x0B ^ 0x0D) | irqEnable, _PC_);
 
-  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
-  restore_flags(flags);
-  #else
-  spin_unlock_irqrestore(&pcan_lock, flags);
-  #endif
+  can_spin_unlock_irqrestore(&pcan_lock, flags);
 
   return  (b1 << 4) | b0 ;
 }
@@ -189,14 +180,9 @@ static void pcan_dongle_writereg(struct DONGLE_PORT *dng, u8 port, u8 data) // w
   u16 _PA_ = (u16)dng->dwPort;
   u16 _PC_ = _PA_ + 2;
   u8  irqEnable = inb(_PC_) & 0x10; // don't influence irqEnable
-  unsigned long flags;
+  can_spin_irqflags_t flags;
 
-  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
-  save_flags(flags);
-  cli();
-  #else
-  spin_lock_irqsave(&pcan_lock, flags);
-  #endif
+  can_spin_lock_irqsave(&pcan_lock, flags);
 
   outb((0x0B ^ 0x0D) | irqEnable, _PC_);
   outb(port & 0x1F,               _PA_);
@@ -204,11 +190,7 @@ static void pcan_dongle_writereg(struct DONGLE_PORT *dng, u8 port, u8 data) // w
   outb(data,                      _PA_);
   outb((0x0B ^ 0x0D) | irqEnable, _PC_);
 
-  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
-  restore_flags(flags);
-  #else
-  spin_unlock_irqrestore(&pcan_lock, flags);
-  #endif
+  can_spin_unlock_irqrestore(&pcan_lock, flags);
 }
 
 // functions for EPP port
@@ -218,14 +200,9 @@ static u8 pcan_dongle_epp_readreg(struct DONGLE_PORT *dng, u8 port) // read a re
   u16 _PC_ = _PA_ + 2;
   u8  wert;
   u8  irqEnable = inb(_PC_) & 0x10; // don't influence irqEnable
-  unsigned long flags;
+  can_spin_irqflags_t flags;
 
-  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
-  save_flags(flags);
-  cli();
-  #else
-  spin_lock_irqsave(&pcan_lock, flags);
-  #endif
+  can_spin_lock_irqsave(&pcan_lock, flags);
 
   outb((0x0B ^ 0x0F) | irqEnable, _PC_);
   outb((port & 0x1F) | 0x80,      _PA_);
@@ -233,11 +210,7 @@ static u8 pcan_dongle_epp_readreg(struct DONGLE_PORT *dng, u8 port) // read a re
   wert = inb(_PA_);
   outb((0x0B ^ 0x0F) | irqEnable, _PC_);
 
-  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18)
-  restore_flags(flags);
-  #else
-  spin_unlock_irqrestore(&pcan_lock, flags);
-  #endif
+  can_spin_unlock_irqrestore(&pcan_lock, flags);
 
   return wert;
 }
index a6b3ad0..b568912 100644 (file)
@@ -20,7 +20,7 @@
 int pcccan_irq=-1;
 unsigned long pcccan_base=0x0;
 
-static can_spinlock_t pcccan_port_lock=SPIN_LOCK_UNLOCKED;
+static CAN_DEFINE_SPINLOCK(pcccan_port_lock);
 
 /*
  * IO_RANGE is the io-memory range that gets reserved, please adjust according
index 8486882..a24ddd8 100644 (file)
@@ -11,6 +11,9 @@
 #include "../include/can_sysdep.h"
 #include "../include/main.h"
 #include "../include/sja1000p.h"
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14))
+#include <linux/irq.h>
+#endif /* <2.6.14 */
 #include <asm/arch/hardware.h>
 #include <asm/arch/imx-regs.h>
 
@@ -29,7 +32,7 @@
 #define NR_82527 0
 #define NR_SJA1000 1
 
-static can_spinlock_t pimx1_setup_hardware_lock=SPIN_LOCK_UNLOCKED;
+static CAN_DEFINE_SPINLOCK(pimx1_setup_hardware_lock);
 
 int pimx1_setup_hardware(struct candevice_t *candev)
 {
@@ -40,10 +43,17 @@ int pimx1_setup_hardware(struct candevice_t *candev)
        EIM_CS1U = 0x00000902;
        EIM_CS1L = 0x82820903;
        imx_gpio_mode(PA21_PF_A0);
+
+    #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14))
        /* Setup IRQ port as input */
+       imx_gpio_mode(GPIO_PORTB | GPIO_GIUS | GPIO_IN  | GPIO_PUEN | 17);
+       /* Setup SJA1000 reset as output */
+       imx_gpio_mode(GPIO_PORTB | GPIO_GIUS | GPIO_OUT | GPIO_DR | 15);
+    #else /* <2.6.14 */
        imx_gpio_mode(GPIO_PORTB | GPIO_IN | GPIO_PUEN | GPIO_GPIO | 17);
-       /* Setup SJA1000 reset as ourput */
        imx_gpio_mode(GPIO_PORTB | GPIO_OUT | GPIO_GPIO | 15);
+    #endif /* <2.6.14 */
+
        DR(1) |= 1<<15;
        can_spin_unlock_irqrestore(&pimx1_setup_hardware_lock,flags);
 
@@ -86,7 +96,8 @@ int pimx1_request_io(struct candevice_t *candev)
                return -ENODEV;
        }
        can_base_addr_fixup(candev, remap_addr);
-       CANMSG("Registered IO-memory: 0x%lx - 0x%lx\n", candev->io_addr, candev->io_addr + PIMX1_CAN_IO_RANGE - 1);
+       CANMSG("Registered IO-memory: 0x%lx - 0x%lx (VMA 0x%lx)\n", 
+               candev->io_addr, candev->io_addr + PIMX1_CAN_IO_RANGE - 1, (long)remap_addr);
        return 0;
 }
 
@@ -124,7 +135,7 @@ int pimx1_release_io(struct candevice_t *candev)
  */
 void pimx1_write_register(unsigned data, unsigned long address)
 {
-       /*DEBUGMSG("pimx1_write_register: addr=0x%lx data=0x%x",
+       /*DEBUGMSG("pimx1_write_register: addr=0x%lx data=0x%x\n",
                address,data);*/
        writeb(data,address);
 }
index eddd13d..a7a990d 100644 (file)
@@ -16,7 +16,7 @@
 int smartcan_irq=-1;
 unsigned long smartcan_base=0x0;
 
-static can_spinlock_t smartcan_port_lock=SPIN_LOCK_UNLOCKED;
+static CAN_DEFINE_SPINLOCK(smartcan_port_lock);
 
 int smartcan_request_io(struct candevice_t *candev)
 {
index 3cd003d..45aef4b 100644 (file)
@@ -14,7 +14,7 @@
 int ssvcan_irq[2]={-1,-1};
 unsigned long ssvcan_base=0x0;
 
-static can_spinlock_t ssv_port_lock=SPIN_LOCK_UNLOCKED;
+static CAN_DEFINE_SPINLOCK(ssv_port_lock);
 
 /* IO_RANGE is the io-memory range that gets reserved, please adjust according
  * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or