From: ppisa Date: Sat, 5 Nov 2005 23:20:00 +0000 (+0100) Subject: Merge: LinCAN driver updated to work on Real-Time Preemption enabled kernel. X-Git-Tag: CLT_COMM_CAN_usb_can1_kriz_bp~41 X-Git-Url: http://rtime.felk.cvut.cz/gitweb/lincan.git/commitdiff_plain/f4eab9f1647cee07d82160bd62f5f26db0734fbc?hp=a4d92e712bfccc8f574f9d80a2ab04a439ca9b8b Merge: LinCAN driver updated to work on Real-Time Preemption enabled kernel. Merge commit 'remotes/sf-ocera-lincan/master' --- diff --git a/lincan/include/can_sysdep.h b/lincan/include/can_sysdep.h index 3966e8f..5a3b86c 100644 --- a/lincan/include/can_sysdep.h +++ b/lincan/include/can_sysdep.h @@ -161,6 +161,12 @@ #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 @@ -187,6 +193,8 @@ #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) diff --git a/lincan/src/bfadcan.c b/lincan/src/bfadcan.c index 78c7660..f6d831b 100644 --- a/lincan/src/bfadcan.c +++ b/lincan/src/bfadcan.c @@ -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 /* diff --git a/lincan/src/c_can.c b/lincan/src/c_can.c index ed3991c..9929467 100644 --- a/lincan/src/c_can.c +++ b/lincan/src/c_can.c @@ -19,10 +19,10 @@ 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 diff --git a/lincan/src/msmcan.c b/lincan/src/msmcan.c index 230e786..9851b5f 100644 --- a/lincan/src/msmcan.c +++ b/lincan/src/msmcan.c @@ -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 diff --git a/lincan/src/nsi.c b/lincan/src/nsi.c index 777850b..ce9c591 100644 --- a/lincan/src/nsi.c +++ b/lincan/src/nsi.c @@ -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 diff --git a/lincan/src/pcan_dongle.c b/lincan/src/pcan_dongle.c index 6bd3496..ce94186 100644 --- a/lincan/src/pcan_dongle.c +++ b/lincan/src/pcan_dongle.c @@ -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; } diff --git a/lincan/src/pcccan.c b/lincan/src/pcccan.c index a6b3ad0..b568912 100644 --- a/lincan/src/pcccan.c +++ b/lincan/src/pcccan.c @@ -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 diff --git a/lincan/src/pimx1.c b/lincan/src/pimx1.c index 8486882..a24ddd8 100644 --- a/lincan/src/pimx1.c +++ b/lincan/src/pimx1.c @@ -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 +#endif /* <2.6.14 */ #include #include @@ -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); } diff --git a/lincan/src/smartcan.c b/lincan/src/smartcan.c index eddd13d..a7a990d 100644 --- a/lincan/src/smartcan.c +++ b/lincan/src/smartcan.c @@ -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) { diff --git a/lincan/src/ssv.c b/lincan/src/ssv.c index 3cd003d..45aef4b 100644 --- a/lincan/src/ssv.c +++ b/lincan/src/ssv.c @@ -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