Title: [8946] trunk/drivers/input/touchscreen: [#6066] AD7160 Linux Driver Support:
Revision
8946
Author
hennerich
Date
2010-06-25 05:12:30 -0400 (Fri, 25 Jun 2010)

Log Message

[#6066] AD7160 Linux Driver Support:

- Use device dev_xxx instead of printk facility.

- Return -EBUSY:
        1) The interface is already bound/probed
        2) The device is already opened

Modified Paths

Diff

Modified: trunk/drivers/input/touchscreen/ad7160-i2c.c (8945 => 8946)


--- trunk/drivers/input/touchscreen/ad7160-i2c.c	2010-06-25 05:55:16 UTC (rev 8945)
+++ trunk/drivers/input/touchscreen/ad7160-i2c.c	2010-06-25 09:12:30 UTC (rev 8946)
@@ -139,10 +139,9 @@
 		return ret;
 
 	ret = ad7160_probe_raw(&client->dev, &bdata, AD7160_DEVID, BUS_I2C);
-	if (ret < 0) {
+
+	if (ret < 0)
 		dev_err(&client->dev, "failed to add raw data interface\n");
-		ad7160_remove(&client->dev);
-	}
 
 	return ret;
 }

Modified: trunk/drivers/input/touchscreen/ad7160-raw.c (8945 => 8946)


--- trunk/drivers/input/touchscreen/ad7160-raw.c	2010-06-25 05:55:16 UTC (rev 8945)
+++ trunk/drivers/input/touchscreen/ad7160-raw.c	2010-06-25 09:12:30 UTC (rev 8946)
@@ -17,6 +17,8 @@
 #include <linux/err.h>
 #include <linux/kfifo.h>
 #include <linux/slab.h>
+#include <linux/device.h>
+#include <linux/i2c.h>
 
 #include <asm/uaccess.h>
 #include <asm/system.h>
@@ -31,9 +33,11 @@
 #define AFE_MTL_CDCVAL0		0x40051B80
 #define MAX_NUM_MTL_CDC		182
 
+#define AD7160_RAW_FIFO_DEPTH	10
 #define AD7160_RAW_JUNK_SIZE	((MAX_NUM_SLF_CDC + MAX_NUM_MTL_CDC) * sizeof(unsigned int))
-#define AD7160_RAW_FIFO_SIZE	(10 * AD7160_RAW_JUNK_SIZE)
 
+#define AD7160_RAW_FIFO_SIZE	(AD7160_RAW_FIFO_DEPTH * AD7160_RAW_JUNK_SIZE)
+
 #define MAX_I2C_READNUM		63	/* Some I2C adaptors limitation */
 
 /* NOTE:
@@ -44,6 +48,7 @@
 
 static struct ad7160_raw_device {
 	struct ad7160_bus_data	bdata;
+	struct device *dev;
 	struct mutex lock;
 	struct kfifo fifo;
 	spinlock_t fifo_lock;
@@ -97,13 +102,14 @@
 			AD7160_RAW_JUNK_SIZE);
 
 	if (ret != AD7160_RAW_JUNK_SIZE) {
-		printk(KERN_ERR "FIFO Buffer Overflow: failed to put %lu bytes,"
-		 "fifo reached %d\n Resetting FIFO\n",
-		 AD7160_RAW_JUNK_SIZE - ret,
-		 kfifo_len(&ad7160_raw_device.fifo));
+		dev_warn(ad7160_raw_device.dev,
+			"FIFO Buffer Overflow: failed to put %lu bytes,"
+			"fifo reached %d\n Resetting FIFO\n",
+			AD7160_RAW_JUNK_SIZE - ret,
+			kfifo_len(&ad7160_raw_device.fifo));
 
-		 kfifo_reset(&ad7160_raw_device.fifo);
-		 kfifo_in(&ad7160_raw_device.fifo,
+		kfifo_reset(&ad7160_raw_device.fifo);
+		kfifo_in(&ad7160_raw_device.fifo,	/* try again */
 			&ad7160_raw_device.buffer[0],
 			AD7160_RAW_JUNK_SIZE);
 	}
@@ -132,6 +138,11 @@
 static int ad7160_raw_misc_open(struct inode *inode, struct file *file)
 {
 	mutex_lock(&ad7160_raw_device.lock);
+	if (ad7160_raw_device.open) {
+		mutex_unlock(&ad7160_raw_device.lock);
+		return -EBUSY;
+	}
+
 	/* Flush input queue on open */
 	kfifo_reset(&ad7160_raw_device.fifo);
 	ad7160_raw_device.open = true;
@@ -259,16 +270,19 @@
 {
 	int error;
 
+	if (ad7160_raw_device.dev)
+		return -EBUSY;
+
 	spin_lock_init(&ad7160_raw_device.fifo_lock);
 	error = kfifo_alloc(&ad7160_raw_device.fifo, AD7160_RAW_FIFO_SIZE, GFP_KERNEL);
 	if (error) {
-		printk(KERN_ERR "ad7160_raw: kfifo_alloc failed\n");
+		dev_err(dev, "ad7160_raw: kfifo_alloc failed\n");
 		return error;
 	}
 
 	ad7160_raw_device.buffer = kzalloc(AD7160_RAW_JUNK_SIZE, GFP_KERNEL);
 	if (ad7160_raw_device.buffer == NULL) {
-		printk(KERN_ERR "ad7160_raw: buffer alloc failed\n");
+		dev_err(dev, "ad7160_raw: buffer alloc failed\n");
 		goto err_kfifo_free;
 	}
 
@@ -276,10 +290,11 @@
 	mutex_init(&ad7160_raw_device.lock);
 
 	ad7160_raw_device.bdata = *bdata;
+	ad7160_raw_device.dev = dev;
 
 	error = misc_register(&ad7160_raw_misc_device);
 	if (error) {
-		printk(KERN_ERR "ad7160_raw: misc_register failed\n");
+		dev_err(dev, "ad7160_raw: misc_register failed\n");
 		goto err_free_buffer;
 	}
 
@@ -289,6 +304,7 @@
 	kfree(ad7160_raw_device.buffer);
  err_kfifo_free:
 	kfifo_free(&ad7160_raw_device.fifo);
+	ad7160_raw_device.dev = NULL;
 
 	return error;
 }
@@ -298,6 +314,7 @@
 	misc_deregister(&ad7160_raw_misc_device);
 	kfifo_free(&ad7160_raw_device.fifo);
 	kfree(ad7160_raw_device.buffer);
+	ad7160_raw_device.dev = NULL;
 
 	return 0;
 }
_______________________________________________
Linux-kernel-commits mailing list
[email protected]
https://blackfin.uclinux.org/mailman/listinfo/linux-kernel-commits

Reply via email to