Modified: branches/2008R1/drivers/input/touchscreen/ad7877.c (4177 => 4178)
--- branches/2008R1/drivers/input/touchscreen/ad7877.c 2008-01-30 14:56:05 UTC (rev 4177)
+++ branches/2008R1/drivers/input/touchscreen/ad7877.c 2008-01-30 15:02:46 UTC (rev 4178)
@@ -3,17 +3,15 @@
*
* Based on: ads7846.c
*
- * Copyright (C) 2006 Michael Hennerich, Analog Devices Inc.
+ * Copyright (C) 2006-2008 Michael Hennerich, Analog Devices Inc.
*
* Author: Michael Hennerich, Analog Devices Inc.
*
* Created: Nov, 10th 2006
* Description: AD7877 based touchscreen, sensor (ADCs), DAC and GPIO driver
*
- * Rev: $Id$
*
* Modified:
- * Copyright 2004-2007 Analog Devices Inc.
*
* Bugs: Enter bugs at http://blackfin.uclinux.org/
*
@@ -53,16 +51,10 @@
#include <linux/input.h>
#include <linux/interrupt.h>
#include <linux/slab.h>
-#include <linux/kthread.h>
#include <linux/spi/spi.h>
#include <linux/spi/ad7877.h>
-#include <linux/freezer.h>
#include <asm/irq.h>
-#ifdef CONFIG_BLACKFIN
-#include <asm/blackfin.h>
-#endif
-
#define TS_PEN_UP_TIMEOUT msecs_to_jiffies(50)
/*--------------------------------------------------------------------------*/
@@ -128,7 +120,6 @@
AD7877_SEQ_TEMP1 = 8,
AD7877_SEQ_TEMP2 = 9,
AD7877_SEQ_Z1 = 10,
-
AD7877_NR_SENSE = 11,
};
@@ -223,9 +214,6 @@
static int gpio3;
-static struct task_struct *ad7877_task;
-static DECLARE_WAIT_QUEUE_HEAD(ad7877_wait);
-
static void ad7877_enable(struct ad7877 *ts);
static void ad7877_disable(struct ad7877 *ts);
@@ -443,14 +431,15 @@
i = simple_strtoul(buf, &endp, 10);
- if (i) {
+ if (i)
ts->gpio3=1;
- } else {
+ else
ts->gpio3=0;
- }
- ad7877_write(dev, AD7877_REG_EXTWRITE, AD7877_EXTW_GPIO_DATA | (ts->gpio4 << 4) | (ts->gpio3 << 5));
+ ad7877_write(dev, AD7877_REG_EXTWRITE, AD7877_EXTW_GPIO_DATA |
+ (ts->gpio4 << 4) | (ts->gpio3 << 5));
+
return count;
}
@@ -474,14 +463,15 @@
i = simple_strtoul(buf, &endp, 10);
- if (i) {
+ if (i)
ts->gpio4=1;
- } else {
+ else
ts->gpio4=0;
- }
- ad7877_write(dev, AD7877_REG_EXTWRITE, AD7877_EXTW_GPIO_DATA | (ts->gpio4 << 4) | (ts->gpio3 << 5));
+ ad7877_write(dev, AD7877_REG_EXTWRITE, AD7877_EXTW_GPIO_DATA |
+ (ts->gpio4 << 4) | (ts->gpio3 << 5));
+
return count;
}
@@ -575,6 +565,7 @@
{
struct ad7877 *ts = handle;
unsigned long flags;
+ int status;
spin_lock_irqsave(&ts->lock, flags);
@@ -586,47 +577,39 @@
ts->intr_flag = 1;
- wake_up_interruptible(&ad7877_wait);
-
spin_unlock_irqrestore(&ts->lock, flags);
+ status = spi_async(ts->spi, &ts->msg);
+
+ if (status)
+ dev_err(&ts->spi->dev, "spi_sync --> %d\n", status);
+
return IRQ_HANDLED;
}
-static int ad7877_thread(void *_ts)
+static void ad7877_callback(void *_ts)
{
struct ad7877 *ts = _ts;
- int status;
unsigned long flags;
- do {
- wait_event_interruptible(ad7877_wait, kthread_should_stop() || (ts->intr_flag!=0));
+ if (ts->intr_flag) {
- if(ts->intr_flag) {
- status = spi_sync(ts->spi, &ts->msg);
- if (status)
- dev_err(&ts->spi->dev, "spi_sync --> %d\n", status);
+ ad7877_rx(ts);
- ad7877_rx(ts);
+ spin_lock_irqsave(&ts->lock, flags);
- spin_lock_irqsave(&ts->lock, flags);
+ ts->intr_flag = 0;
+ ts->pending = 0;
- ts->intr_flag = 0;
- ts->pending = 0;
-
- if (!device_suspended(&ts->spi->dev)) {
- ts->irq_disabled = 0;
- enable_irq(ts->spi->irq);
- mod_timer(&ts->timer, jiffies + TS_PEN_UP_TIMEOUT);
- }
-
- spin_unlock_irqrestore(&ts->lock, flags);
+ if (!device_suspended(&ts->spi->dev)) {
+ ts->irq_disabled = 0;
+ enable_irq(ts->spi->irq);
+ mod_timer(&ts->timer, jiffies + TS_PEN_UP_TIMEOUT);
}
- try_to_freeze();
- } while (!kthread_should_stop());
- printk(KERN_DEBUG "ad7877: ktsd kthread exiting\n");
- return 0;
+
+ spin_unlock_irqrestore(&ts->lock, flags);
+ }
}
@@ -701,16 +684,19 @@
static inline void ad7877_setup_ts_def_msg(struct spi_device *spi, struct ad7877 *ts)
{
struct spi_message *m;
- u16 i;
+ int i;
- ts->cmd_crtl2 = AD7877_WRITEADD(AD7877_REG_CTRL2) | AD7877_POL(ts->stopacq_polarity) |\
- AD7877_AVG(ts->averaging) | AD7877_PM(1) |\
- AD7877_TMR(ts->pen_down_acc_interval) | AD7877_ACQ(ts->acquisition_time) |\
+ ts->cmd_crtl2 = AD7877_WRITEADD(AD7877_REG_CTRL2) |
+ AD7877_POL(ts->stopacq_polarity) |
+ AD7877_AVG(ts->averaging) | AD7877_PM(1) |
+ AD7877_TMR(ts->pen_down_acc_interval) |
+ AD7877_ACQ(ts->acquisition_time) |
AD7877_FCD(ts->first_conversion_delay);
ad7877_write((struct device *) spi, AD7877_REG_CTRL2, ts->cmd_crtl2);
- ts->cmd_crtl1 = AD7877_WRITEADD(AD7877_REG_CTRL1) | AD7877_READADD(AD7877_REG_XPLUS-1) |\
+ ts->cmd_crtl1 = AD7877_WRITEADD(AD7877_REG_CTRL1) |
+ AD7877_READADD(AD7877_REG_XPLUS-1) |
AD7877_MODE_SEQ1 | AD7877_DFR;
ad7877_write((struct device *) spi, AD7877_REG_CTRL1, ts->cmd_crtl1);
@@ -721,6 +707,9 @@
spi_message_init(m);
+ m->complete = ad7877_callback;
+ m->context = ts;
+
ts->xfer[0].tx_buf = &ts->cmd_crtl1;
ts->xfer[0].len = 2;
@@ -819,19 +808,21 @@
verify = ad7877_read((struct device *) spi, AD7877_REG_SEQ1);
if (verify != AD7877_MM_SEQUENCE){
- printk(KERN_ERR "%s: Failed to probe %s\n", spi->dev.bus_id, input_dev->name);
+ printk(KERN_ERR "%s: Failed to probe %s\n", spi->dev.bus_id,
+ input_dev->name);
err = -ENODEV;
goto err_free_mem;
}
- if(gpio3)
- ad7877_write((struct device *) spi, AD7877_REG_EXTWRITE, AD7877_EXTW_GPIO_3_CONF);
+ if (gpio3)
+ ad7877_write((struct device *) spi, AD7877_REG_EXTWRITE,
+ AD7877_EXTW_GPIO_3_CONF);
ad7877_setup_ts_def_msg(spi, ts);
/* Request AD7877 /DAV GPIO interrupt */
- if (request_irq(spi->irq, ad7877_irq, IRQF_TRIGGER_LOW,
+ if (request_irq(spi->irq, ad7877_irq, IRQF_TRIGGER_LOW | IRQF_SAMPLE_RANDOM,
spi->dev.driver->name, ts)) {
dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq);
err = -EBUSY;
@@ -844,7 +835,7 @@
if (err)
goto err_remove_attr;
- if(gpio3)
+ if (gpio3)
err = device_create_file(&spi->dev, &dev_attr_gpio3);
else
err = device_create_file(&spi->dev, &dev_attr_aux3);
@@ -854,28 +845,20 @@
err = input_register_device(input_dev);
if (err)
- goto err_remove_attr;
+ goto err_idev;
ts->intr_flag = 0;
- ad7877_task = kthread_run(ad7877_thread, ts, "ad7877_ktsd");
-
- if (IS_ERR(ad7877_task)) {
- printk(KERN_ERR "ts: Failed to start ad7877_task\n");
- goto err_unregister_idev;
- }
-
return 0;
-err_unregister_idev:
- input_unregister_device(input_dev);
+err_idev:
input_dev = NULL; /* so we don't try to free it later */
err_remove_attr:
sysfs_remove_group(&spi->dev.kobj, &ad7877_attr_group);
- if(gpio3)
+ if (gpio3)
device_remove_file(&spi->dev, &dev_attr_gpio3);
else
device_remove_file(&spi->dev, &dev_attr_aux3);
@@ -895,11 +878,9 @@
ad7877_suspend(spi, PMSG_SUSPEND);
- kthread_stop(ad7877_task);
-
sysfs_remove_group(&spi->dev.kobj, &ad7877_attr_group);
- if(gpio3)
+ if (gpio3)
device_remove_file(&spi->dev, &dev_attr_gpio3);
else
device_remove_file(&spi->dev, &dev_attr_aux3);