/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
Frodo Looijaard <frodol@dds.nl> */
-#include <linux/config.h>
#include <linux/kernel.h>
#include <linux/ioport.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/init.h>
+#include <linux/wait.h>
#include <asm/irq.h>
#include <asm/io.h>
static struct iic_ite gpi;
static wait_queue_head_t iic_wait;
static int iic_pending;
+static spinlock_t lock;
/* ----- local functions ---------------------------------------------- */
* IIC controller interrupts.
*/
static void iic_ite_waitforpin(void) {
-
+ DEFINE_WAIT(wait);
int timeout = 2;
+ unsigned long flags;
/* If interrupts are enabled (which they are), then put the process to
* sleep. This process will be awakened by two events -- either the
* of time and return.
*/
if (gpi.iic_irq > 0) {
- cli();
+ spin_lock_irqsave(&lock, flags);
if (iic_pending == 0) {
- interruptible_sleep_on_timeout(&iic_wait, timeout*HZ );
- } else
+ spin_unlock_irqrestore(&lock, flags);
+ prepare_to_wait(&iic_wait, &wait, TASK_INTERRUPTIBLE);
+ if (schedule_timeout(timeout*HZ)) {
+ spin_lock_irqsave(&lock, flags);
+ if (iic_pending == 1) {
+ iic_pending = 0;
+ }
+ spin_unlock_irqrestore(&lock, flags);
+ }
+ finish_wait(&iic_wait, &wait);
+ } else {
iic_pending = 0;
- sti();
+ spin_unlock_irqrestore(&lock, flags);
+ }
} else {
udelay(100);
}
}
-static void iic_ite_handler(int this_irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t iic_ite_handler(int this_irq, void *dev_id,
+ struct pt_regs *regs)
{
-
- iic_pending = 1;
+ spin_lock(&lock);
+ iic_pending = 1;
+ spin_unlock(&lock);
+
+ wake_up_interruptible(&iic_wait);
- wake_up_interruptible(&iic_wait);
+ return IRQ_HANDLED;
}
iic_ite_data.data = (void *)piic;
init_waitqueue_head(&iic_wait);
+ spin_lock_init(&lock);
if (iic_hw_resrc_init() == 0) {
if (i2c_iic_add_bus(&iic_ite_ops) < 0)
return -ENODEV;