public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] SPI: tsc2xxx core
@ 2007-08-14 19:12 Ragner Magalhaes
  2007-08-14 19:12 ` [PATCH 2/4] SPI: tsc2301 support for " Ragner Magalhaes
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Ragner Magalhaes @ 2007-08-14 19:12 UTC (permalink / raw)
  To: david-b; +Cc: linux-omap-open-source

From: Ragner Magalhaes <ragner.magalhaes@indt.org.br>

This is the start to build tsc2xxx core with all sharable routines
between tsc2101, tsc2102, tsc2301 ... and more later tsc2100, tsc2111, etc.

Signed-off-by: Ragner Magalhaes <ragner.magalhaes@indt.org.br>
---

 drivers/spi/Kconfig         |    4 +
 drivers/spi/Makefile        |    1 
 drivers/spi/tsc2xxx.c       |  227 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/spi/tsc2xxx.h |   40 ++++++++
 4 files changed, 272 insertions(+), 0 deletions(-)

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 4f43b97..e612fc7 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -212,6 +212,10 @@ config SPI_AT25
 	  This driver can also be built as a module.  If so, the module
 	  will be called at25.
 
+config SPI_TSC2XXX
+	tristate
+	default n
+
 config SPI_TSC2101
        depends on SPI_MASTER
        tristate "TSC2101 chip support"
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index 78d02bd..05fc03e 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -33,6 +33,7 @@ obj-$(CONFIG_SPI_XILINX)		+= xilinx_spi.o
 obj-$(CONFIG_SPI_AT25)		+= at25.o
 obj-$(CONFIG_SPI_SPIDEV)	+= spidev.o
 obj-$(CONFIG_SPI_TLE62X0)	+= tle62x0.o
+obj-$(CONFIG_SPI_TSC2XXX)	+= tsc2xxx.o
 obj-$(CONFIG_SPI_TSC2101)	+= tsc2101.o
 obj-$(CONFIG_SPI_TSC2102)	+= tsc2102.o
 obj-$(CONFIG_SPI_TSC210X)	+= tsc210x.o
diff --git a/drivers/spi/tsc2xxx.c b/drivers/spi/tsc2xxx.c
new file mode 100644
index 0000000..14d46d8
--- /dev/null
+++ b/drivers/spi/tsc2xxx.c
@@ -0,0 +1,227 @@
+/*
+ * drivers/spi/tsc2xxx.c
+ *
+ * Copyright (C) 2007, Ragner Magalhaes <ragner.magalhaes@indt.org.br>
+ *
+ * TSC2xxx core.
+ *
+ * Sharable core routines (tsc2101, tsc2102 and tsc2301).
+ *
+ * Licensed under the GPLv2 only.
+ */
+
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/spi/spi.h>
+#include <linux/spi/tsc2xxx.h>
+
+u16 tsc2xxx_read_sync(struct spi_device *spi, u32 reg)
+{
+	struct spi_transfer t[2];
+	struct spi_message m;
+	u16 data 	= 0;
+	u16 cmd 	= 0x8000 | reg;
+
+	memset(t, 0, sizeof(t));
+	spi_message_init(&m);
+	m.spi = spi;
+
+	t[0].tx_buf = &cmd;
+	t[0].rx_buf = NULL;
+	t[0].len = 2;
+	spi_message_add_tail(&t[0], &m);
+
+	t[1].tx_buf = NULL;
+	t[1].rx_buf = &data;
+	t[1].len = 2;
+	spi_message_add_tail(&t[1], &m);
+
+	spi_sync(m.spi, &m);
+
+	return data;
+}
+EXPORT_SYMBOL(tsc2xxx_read_sync);
+
+int tsc2xxx_write_sync(struct spi_device *spi, u32 reg, u16 val)
+{
+	struct spi_transfer t[2];
+	struct spi_message m;
+	u16 data 	= val;
+	u16 cmd 	= reg;
+
+	memset(t, 0, sizeof(t));
+	spi_message_init(&m);
+	m.spi = spi;
+
+	t[0].tx_buf = &cmd;
+	t[0].rx_buf = NULL;
+	t[0].len = 2;
+	spi_message_add_tail(&t[0], &m);
+
+	t[1].tx_buf = &data;
+	t[1].rx_buf = NULL;
+	t[1].len = 2;
+	spi_message_add_tail(&t[1], &m);
+
+	spi_sync(m.spi, &m);
+
+	spi_sync(m.spi, &m);
+
+	return (m.status);
+}
+EXPORT_SYMBOL(tsc2xxx_write_sync);
+
+u16 tsc2xxx_read_async(struct spi_device *spi, u32 reg,
+		void (*complete)(void *context))
+{
+	struct spi_transfer t[2];
+	struct spi_message m;
+	u16 data 	= 0;
+	u16 cmd 	= 0x8000 | reg;
+
+	memset(t, 0, sizeof(t));
+	spi_message_init(&m);
+	m.spi = spi;
+
+	m.complete = complete;
+	m.context = spi_get_drvdata(spi);
+
+	t[0].tx_buf = &cmd;
+	t[0].rx_buf = NULL;
+	t[0].len = 2;
+	spi_message_add_tail(&t[0], &m);
+
+	t[1].tx_buf = NULL;
+	t[1].rx_buf = &data;
+	t[1].len = 2;
+	spi_message_add_tail(&t[1], &m);
+
+	spi_async(m.spi, &m);
+
+	return data;
+}
+EXPORT_SYMBOL(tsc2xxx_read_async);
+
+int tsc2xxx_write_async(struct spi_device *spi, u32 reg, u16 val,
+		void (*complete)(void *context))
+{
+	struct spi_transfer t[2];
+	struct spi_message m;
+	u16 data 	= val;
+	u16 cmd 	= reg;
+
+	memset(t, 0, sizeof(t));
+	spi_message_init(&m);
+	m.spi = spi;
+
+	m.complete = complete;
+	m.context = spi_get_drvdata(spi);
+
+	t[0].tx_buf = &cmd;
+	t[0].rx_buf = NULL;
+	t[0].len = 2;
+	spi_message_add_tail(&t[0], &m);
+
+	t[1].tx_buf = &data;
+	t[1].rx_buf = NULL;
+	t[1].len = 2;
+	spi_message_add_tail(&t[1], &m);
+
+	spi_async(m.spi, &m);
+
+	return (m.status);
+}
+EXPORT_SYMBOL(tsc2xxx_write_async);
+
+#ifdef DEBUG
+
+static inline void dump_rx_buf(struct spi_device *spi, u16 *buf, u32 len)
+{
+	struct device *dev = &spi->dev;
+	u32 i;
+	for (i = 0; i < len; i++)
+		dev_dbg(dev, "rx_buf[%d]: %04x\n", i, buf[i]);
+}
+
+#else
+
+static inline void dump_rx_buf(struct spi_device *spi, u16 *buf, u32 len)
+{}
+
+#endif /* DUMP_MSG */
+
+int tsc2xxx_read_buf_sync(struct spi_device *spi, u32 reg, u16 *buf, u32 len)
+{
+	struct spi_transfer t[2];
+	struct spi_message m;
+	u16 cmd 	= 0x8000 | reg;
+
+	memset(t, 0, sizeof(t));
+	spi_message_init(&m);
+	m.spi = spi;
+
+	t[0].tx_buf = &cmd;
+	t[0].rx_buf = NULL;
+	t[0].len = 2;
+	spi_message_add_tail(&t[0], &m);
+
+	t[1].tx_buf = NULL;
+	t[1].rx_buf = buf;
+	t[1].len = 2 * len;
+	spi_message_add_tail(&t[1], &m);
+
+	spi_sync(m.spi, &m);
+
+	dump_rx_buf(spi, buf, len);
+
+	return (m.status);
+}
+EXPORT_SYMBOL(tsc2xxx_read_buf_sync);
+
+int tsc2xxx_read_buf_async(struct spi_device *spi, u32 reg, u16 *buf, u32 len,
+		void (*complete)(void *context))
+{
+	struct spi_transfer t[2];
+	struct spi_message m;
+	u16 cmd 	= 0x8000 | reg;
+
+	memset(t, 0, sizeof(t));
+	spi_message_init(&m);
+	m.spi = spi;
+
+	m.complete = complete;
+	m.context = spi_get_drvdata(spi);
+
+	t[0].tx_buf = &cmd;
+	t[0].rx_buf = NULL;
+	t[0].len = 2;
+	spi_message_add_tail(&t[0], &m);
+
+	t[1].tx_buf = NULL;
+	t[1].rx_buf = buf;
+	t[1].len = 2 * len;
+	spi_message_add_tail(&t[1], &m);
+
+	spi_sync(m.spi, &m);
+
+	dump_rx_buf(spi, buf, len);
+
+	return (m.status);
+}
+EXPORT_SYMBOL(tsc2xxx_read_buf_async);
+
+static int __init tsc2xxx_init(void)
+{
+	return 0;
+}
+
+static void __exit tsc2xxx_exit(void)
+{
+}
+
+module_init(tsc2xxx_init)
+module_exit(tsc2xxx_exit)
+
+MODULE_AUTHOR("Ragner Magalhaes");
+MODULE_DESCRIPTION("TSC2xxx family sharable routines.");
+MODULE_LICENSE("GPL v2");
diff --git a/include/linux/spi/tsc2xxx.h b/include/linux/spi/tsc2xxx.h
new file mode 100644
index 0000000..ddfc68c
--- /dev/null
+++ b/include/linux/spi/tsc2xxx.h
@@ -0,0 +1,40 @@
+/*
+ * include/linux/spi/tsc2xxx.h
+ *
+ * Copyright (C) 2007, Ragner Magalhaes <ragner.magalhaes@indt.org.br>
+ *
+ * TSC2xxx core.
+ *
+ * Sharable core routines (tsc2101, tsc2102 and tsc2301).
+ *
+ * Licensed under the GPLv2 only.
+ */
+
+#ifndef _LINUX_SPI_TSC2XXX_H
+#define _LINUX_SPI_TSC2XXX_H
+
+struct tsc210x_spi_req {
+	struct spi_device *dev;
+	u16 command;
+	u16 data;
+	struct spi_message message;
+};
+
+#define TSC2XXX_REG(page, addr)  (((page) << 11) | ((addr) << 5))
+#define TSC2XXX_REG_TO_PAGE(reg) (((reg) >> 11) & 0x03)
+#define TSC2XXX_REG_TO_ADDR(reg) (((reg) >> 5)  & 0x1f)
+
+extern u16 tsc2xxx_read_sync(struct spi_device *spi, u32 reg);
+extern int tsc2xxx_write_sync(struct spi_device *spi, u32 reg, u16 val);
+
+extern u16 tsc2xxx_read_async(struct spi_device *spi, u32 reg,
+		void (*complete)(void *context));
+extern int tsc2xxx_write_async(struct spi_device *spi, u32 reg, u16 val,
+		void (*complete)(void *context));
+
+extern int tsc2xxx_read_buf_sync(struct spi_device *spi, u32 reg, u16 *buf,
+		u32 len);
+extern int tsc2xxx_read_buf_async(struct spi_device *spi, u32 reg, u16 *buf,
+		u32 len, void (*complete)(void *context));
+
+#endif /* _LINUX_SPI_TSC2XXX_H */

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/4] SPI: tsc2301 support for tsc2xxx core
  2007-08-14 19:12 [PATCH 1/4] SPI: tsc2xxx core Ragner Magalhaes
@ 2007-08-14 19:12 ` Ragner Magalhaes
  2007-08-14 19:12 ` [PATCH 3/4] SPI: tsc2101 " Ragner Magalhaes
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Ragner Magalhaes @ 2007-08-14 19:12 UTC (permalink / raw)
  To: david-b; +Cc: linux-omap-open-source

From: Ragner Magalhaes <ragner.magalhaes@indt.org.br>

Add support for tsc2xxx core api

Signed-off-by: Ragner Magalhaes <ragner.magalhaes@indt.org.br>
---

 drivers/spi/Kconfig         |    1 
 drivers/spi/tsc2301-core.c  |   94 ++++---------------------------------------
 include/linux/spi/tsc2301.h |   50 +++++++++++------------
 3 files changed, 32 insertions(+), 113 deletions(-)

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index e612fc7..ceab02e 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -246,6 +246,7 @@ config SPI_TSC210X
 config SPI_TSC2301
 	tristate "TSC2301 driver"
 	depends on SPI_MASTER
+	select SPI_TSC2XXX
 	help
 	  Say Y here if you have a TSC2301 chip connected to an SPI
 	  bus on your board.
diff --git a/drivers/spi/tsc2301-core.c b/drivers/spi/tsc2301-core.c
index 500c3dc..f686287 100644
--- a/drivers/spi/tsc2301-core.c
+++ b/drivers/spi/tsc2301-core.c
@@ -23,62 +23,13 @@
 #include <linux/device.h>
 #include <linux/delay.h>
 #include <linux/spi/spi.h>
+#include <linux/spi/tsc2xxx.h>
 #include <linux/spi/tsc2301.h>
 
 #ifdef CONFIG_ARCH_OMAP
 #include <asm/arch/gpio.h>
 #endif
 
-u16 tsc2301_read_reg(struct tsc2301 *tsc, int reg)
-{
-	struct spi_transfer t[2];
-	struct spi_message m;
-	u16 data = 0, cmd;
-
-	cmd = reg;
-	cmd |= 0x8000;
-
-	memset(t, 0, sizeof(t));
-	spi_message_init(&m);
-	m.spi = tsc->spi;
-
-	t[0].tx_buf = &cmd;
-	t[0].rx_buf = NULL;
-	t[0].len = 2;
-	spi_message_add_tail(&t[0], &m);
-
-	t[1].tx_buf = NULL;
-	t[1].rx_buf = &data;
-	t[1].len = 2;
-	spi_message_add_tail(&t[1], &m);
-
-	spi_sync(m.spi, &m);
-
-	return data;
-}
-
-void tsc2301_write_reg(struct tsc2301 *tsc, int reg, u16 val)
-{
-	struct spi_transfer t;
-	struct spi_message m;
-	u16 data[2];
-
-	/* Now we prepare the command for transferring */
-	data[0] = reg;
-	data[1] = val;
-
-	spi_message_init(&m);
-	m.spi = tsc->spi;
-
-	memset(&t, 0, sizeof(t));
-	t.tx_buf = data;
-	t.rx_buf = NULL;
-	t.len = 4;
-	spi_message_add_tail(&t, &m);
-
-	spi_sync(m.spi, &m);
-}
-
 void tsc2301_write_kbc(struct tsc2301 *tsc, int val)
 {
 	u16 w;
@@ -86,7 +37,7 @@ void tsc2301_write_kbc(struct tsc2301 *tsc, int val)
 	w = tsc->config2_shadow;
 	w &= ~(0x03 << 14);
 	w |= (val & 0x03) << 14;
-	tsc2301_write_reg(tsc, TSC2301_REG_CONFIG2, w);
+	tsc2xxx_write_sync(tsc->spi, TSC2301_REG_CONFIG2, w);
 	tsc->config2_shadow = w;
 }
 
@@ -100,39 +51,10 @@ void tsc2301_write_pll(struct tsc2301 *tsc,
 	w |= (pll_n & 0x0f) | ((pll_a & 0x0f) << 4) | ((pll_pdc & 0x0f) << 8);
 	w |= pct_e ? (1 << 12) : 0;
 	w |= pll_o ? (1 << 13) : 0;
-	tsc2301_write_reg(tsc, TSC2301_REG_CONFIG2, w);
+	tsc2xxx_write_sync(tsc->spi, TSC2301_REG_CONFIG2, w);
 	tsc->config2_shadow = w;
 }
 
-void tsc2301_read_buf(struct tsc2301 *tsc, int reg, u16 *rx_buf, int len)
-{
-	struct spi_transfer t[2];
-	struct spi_message m;
-	u16 cmd, i;
-
-	cmd = reg;
-	cmd |= 0x8000;
-
-	spi_message_init(&m);
-	m.spi = tsc->spi;
-
-	memset(t, 0, sizeof(t));
-	t[0].tx_buf = &cmd;
-	t[0].rx_buf = NULL;
-	t[0].len = 2;
-	spi_message_add_tail(&t[0], &m);
-
-	t[1].tx_buf = NULL;
-	t[1].rx_buf = rx_buf;
-	t[1].len = 2 * len;
-	spi_message_add_tail(&t[1], &m);
-
-	spi_sync(m.spi, &m);
-
-	for (i = 0; i < len; i++)
-		printk(KERN_DEBUG "rx_buf[%d]: %04x\n", i, rx_buf[i]);
-}
-
 static int __devinit tsc2301_probe(struct spi_device *spi)
 {
 	struct tsc2301			*tsc;
@@ -179,17 +101,17 @@ static int __devinit tsc2301_probe(struct spi_device *spi)
 	spi_setup(spi);
 
 	/* Soft reset */
-	tsc2301_write_reg(tsc, TSC2301_REG_RESET, 0xbb00);
+	tsc2xxx_write_sync(tsc->spi, TSC2301_REG_RESET, 0xbb00);
 	msleep(1);
 
-	w = tsc2301_read_reg(tsc, TSC2301_REG_ADC);
+	w = tsc2xxx_read_sync(tsc->spi, TSC2301_REG_ADC);
 	if (!(w & (1 << 14))) {
 		dev_err(&spi->dev, "invalid ADC reg value: %04x\n", w);
 		r = -ENODEV;
 		goto err1;
 	}
 
-	w = tsc2301_read_reg(tsc, TSC2301_REG_DAC);
+	w = tsc2xxx_read_sync(tsc->spi, TSC2301_REG_DAC);
 	if (!(w & (1 << 15))) {
 		dev_err(&spi->dev, "invalid DAC reg value: %04x\n", w);
 		r = -ENODEV;
@@ -197,11 +119,11 @@ static int __devinit tsc2301_probe(struct spi_device *spi)
 	}
 
 	/* Stop keypad scanning */
-	tsc2301_write_reg(tsc, TSC2301_REG_KEY, 0x4000);
+	tsc2xxx_write_sync(tsc->spi, TSC2301_REG_KEY, 0x4000);
 
 	/* We have to cache this for read-modify-write, since we can't
 	 * read back BIT15 */
-	w = tsc2301_read_reg(tsc, TSC2301_REG_CONFIG2);
+	w = tsc2xxx_read_sync(tsc->spi, TSC2301_REG_CONFIG2);
 	/* By default BIT15 is set */
 	w |= 1 << 15;
 	tsc->config2_shadow = w;
diff --git a/include/linux/spi/tsc2301.h b/include/linux/spi/tsc2301.h
index 059cc58..186485c 100644
--- a/include/linux/spi/tsc2301.h
+++ b/include/linux/spi/tsc2301.h
@@ -83,33 +83,29 @@ struct tsc2301 {
 
 #define TSC2301_HZ	33000000
 
-#define TSC2301_REG(page, addr)  (((page) << 11) | ((addr) << 5))
-#define TSC2301_REG_TO_PAGE(reg) (((reg) >> 11) & 0x03)
-#define TSC2301_REG_TO_ADDR(reg) (((reg) >> 5)  & 0x1f)
-
-#define TSC2301_REG_X		TSC2301_REG(0, 0)
-#define TSC2301_REG_Y		TSC2301_REG(0, 1)
-#define TSC2301_REG_Z1		TSC2301_REG(0, 2)
-#define TSC2301_REG_Z2		TSC2301_REG(0, 3)
-#define TSC2301_REG_KPDATA	TSC2301_REG(0, 4)
-#define TSC2301_REG_ADC		TSC2301_REG(1, 0)
-#define TSC2301_REG_KEY		TSC2301_REG(1, 1)
-#define TSC2301_REG_DAC		TSC2301_REG(1, 2)
-#define TSC2301_REG_REF		TSC2301_REG(1, 3)
-#define TSC2301_REG_RESET	TSC2301_REG(1, 4)
-#define TSC2301_REG_CONFIG	TSC2301_REG(1, 5)
-#define TSC2301_REG_CONFIG2	TSC2301_REG(1, 6)
-#define TSC2301_REG_KPMASK	TSC2301_REG(1, 16)
-#define TSC2301_REG_AUDCNTL	TSC2301_REG(2, 0)
-#define TSC2301_REG_ADCVOL	TSC2301_REG(2, 1)
-#define TSC2301_REG_DACVOL	TSC2301_REG(2, 2)
-#define TSC2301_REG_BPVOL	TSC2301_REG(2, 3)
-#define TSC2301_REG_KEYCTL	TSC2301_REG(2, 4)
-#define TSC2301_REG_PD_MISC	TSC2301_REG(2, 5)
-#define TSC2301_REG_GPIO	TSC2301_REG(2, 6)
-#define TSC2301_REG_ADCLKCFG	TSC2301_REG(2, 27)
-
-#define TSC2301_REG_PD_MISC_APD		(1 << 15)
+#define TSC2301_REG_X		TSC2XXX_REG(0, 0)
+#define TSC2301_REG_Y		TSC2XXX_REG(0, 1)
+#define TSC2301_REG_Z1		TSC2XXX_REG(0, 2)
+#define TSC2301_REG_Z2		TSC2XXX_REG(0, 3)
+#define TSC2301_REG_KPDATA	TSC2XXX_REG(0, 4)
+#define TSC2301_REG_ADC 	TSC2XXX_REG(1, 0)
+#define TSC2301_REG_KEY 	TSC2XXX_REG(1, 1)
+#define TSC2301_REG_DAC 	TSC2XXX_REG(1, 2)
+#define TSC2301_REG_REF 	TSC2XXX_REG(1, 3)
+#define TSC2301_REG_RESET	TSC2XXX_REG(1, 4)
+#define TSC2301_REG_CONFIG	TSC2XXX_REG(1, 5)
+#define TSC2301_REG_CONFIG2	TSC2XXX_REG(1, 6)
+#define TSC2301_REG_KPMASK	TSC2XXX_REG(1, 16)
+#define TSC2301_REG_AUDCNTL	TSC2XXX_REG(2, 0)
+#define TSC2301_REG_ADCVOL	TSC2XXX_REG(2, 1)
+#define TSC2301_REG_DACVOL	TSC2XXX_REG(2, 2)
+#define TSC2301_REG_BPVOL	TSC2XXX_REG(2, 3)
+#define TSC2301_REG_KEYCTL	TSC2XXX_REG(2, 4)
+#define TSC2301_REG_PD_MISC	TSC2XXX_REG(2, 5)
+#define TSC2301_REG_GPIO	TSC2XXX_REG(2, 6)
+#define TSC2301_REG_ADCLKCFG	TSC2XXX_REG(2, 27)
+
+#define TSC2301_REG_PD_MISC_APD 	(1 << 15)
 #define TSC2301_REG_PD_MISC_AVPD	(1 << 14)
 #define TSC2301_REG_PD_MISC_ABPD	(1 << 13)
 #define TSC2301_REG_PD_MISC_HAPD	(1 << 12)

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/4] SPI: tsc2101 support for tsc2xxx core
  2007-08-14 19:12 [PATCH 1/4] SPI: tsc2xxx core Ragner Magalhaes
  2007-08-14 19:12 ` [PATCH 2/4] SPI: tsc2301 support for " Ragner Magalhaes
@ 2007-08-14 19:12 ` Ragner Magalhaes
  2007-08-14 19:13 ` [PATCH 4/4] SPI: tsc2102 " Ragner Magalhaes
  2007-08-14 20:12 ` [PATCH 1/4] SPI: " David Brownell
  3 siblings, 0 replies; 7+ messages in thread
From: Ragner Magalhaes @ 2007-08-14 19:12 UTC (permalink / raw)
  To: david-b; +Cc: linux-omap-open-source

From: Ragner Magalhaes <ragner.magalhaes@indt.org.br>

Add support for tsc2xxx core api

Signed-off-by: Ragner Magalhaes <ragner.magalhaes@indt.org.br>
---

 arch/arm/mach-omap1/board-h2.c |    1 
 drivers/spi/Kconfig            |    5 +-
 drivers/spi/tsc2101.c          |   94 ++++------------------------------------
 drivers/video/omap/lcd_h2.c    |   10 +++-
 include/linux/spi/tsc2101.h    |   10 ++--
 5 files changed, 26 insertions(+), 94 deletions(-)

diff --git a/arch/arm/mach-omap1/board-h2.c b/arch/arm/mach-omap1/board-h2.c
index d2214ad..67b9f01 100644
--- a/arch/arm/mach-omap1/board-h2.c
+++ b/arch/arm/mach-omap1/board-h2.c
@@ -29,6 +29,7 @@
 #include <linux/input.h>
 #include <linux/workqueue.h>
 #include <linux/spi/spi.h>
+#include <linux/spi/tsc2xxx.h>
 #include <linux/spi/tsc2101.h>
 #include <linux/clk.h>
 
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index ceab02e..a4b112a 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -217,8 +217,9 @@ config SPI_TSC2XXX
 	default n
 
 config SPI_TSC2101
-       depends on SPI_MASTER
-       tristate "TSC2101 chip support"
+	depends on SPI_MASTER
+	tristate "TSC2101 chip support"
+	select SPI_TSC2XXX
        ---help---
          Say Y here if you want support for the TSC2101 chip.
 	 At the moment it provides basic register read / write interface
diff --git a/drivers/spi/tsc2101.c b/drivers/spi/tsc2101.c
index 71702e2..b044b4c 100644
--- a/drivers/spi/tsc2101.c
+++ b/drivers/spi/tsc2101.c
@@ -22,6 +22,7 @@
 #include <linux/clk.h>
 #include <linux/device.h>
 #include <linux/spi/spi.h>
+#include <linux/spi/tsc2xxx.h>
 #include <linux/spi/tsc2101.h>
 
 struct tsc2101_device {
@@ -76,99 +77,22 @@ void tsc2101_disable_mclk(struct spi_device *spi)
 }
 EXPORT_SYMBOL(tsc2101_disable_mclk);
 
-int tsc2101_write_sync(struct spi_device *spi, int page, u8 address, u16 data)
+int tsc2101_write_sync(struct spi_device *spi, u32 reg, u16 data)
 {
-	struct tsc2101_device *tsc2101;
-	struct spi_message *m;
-	struct spi_transfer *t;
-	int ret;
-
-	tsc2101 = spi_get_drvdata(spi);
-
-	mutex_lock(&tsc2101->mutex);
-	if (spi->dev.power.power_state.event != PM_EVENT_ON) {
-		mutex_unlock(&tsc2101->mutex);
-		return -ENODEV;
-	}
-
-	m = &tsc2101->message;
-	spi_message_init(m);
-	t = &tsc2101->transfer[0];
-	memset(t, 0, sizeof(tsc2101->transfer));
-
-	/* Address */
-	tsc2101->command = (page << 11) | (address << 5);
-	t->tx_buf = &tsc2101->command;
-	t->len = 2;
-	spi_message_add_tail(t, m);
-
-	/* Data */
-	t++;
-	t->tx_buf = &data;
-	t->len = 2;
-	spi_message_add_tail(t, m);
-
-	ret = spi_sync(spi, m);
-	if (!ret)
-		ret = tsc2101->message.status;
-	mutex_unlock(&tsc2101->mutex);
-
-	return ret;
+	return tsc2xxx_write_sync(spi, reg, data);
 }
 EXPORT_SYMBOL(tsc2101_write_sync);
 
-int tsc2101_reads_sync(struct spi_device *spi,
-		       int page, u8 startaddress, u16 *data, int numregs)
+int tsc2101_reads_sync(struct spi_device *spi, u32 reg, u16 *data,
+		int numregs)
 {
-	struct tsc2101_device *tsc2101;
-	struct spi_message *m;
-	struct spi_transfer *t;
-	int ret;
-
-	tsc2101 = spi_get_drvdata(spi);
-
-	mutex_lock(&tsc2101->mutex);
-	if (spi->dev.power.power_state.event != PM_EVENT_ON) {
-		mutex_unlock(&tsc2101->mutex);
-		return -ENODEV;
-	}
-
-	m = &tsc2101->message;
-	spi_message_init(m);
-	t = &tsc2101->transfer[0];
-	memset(t, 0, sizeof(tsc2101->transfer));
-
-	/* Address */
-	tsc2101->command = 0x8000 | (page << 11) | (startaddress << 5);
-	t->tx_buf = &tsc2101->command;
-	t->len = 2;
-	spi_message_add_tail(t, m);
-
-	/* Data */
-	t++;
-	t->rx_buf = data;
-	t->len = numregs << 1;
-	spi_message_add_tail(t, m);
-
-	ret = spi_sync(spi, m);
-	if (!ret)
-		ret = tsc2101->message.status;
-
-	mutex_unlock(&tsc2101->mutex);
-
-	return ret;
+	return tsc2xxx_read_buf_sync(spi, reg, data, numregs);
 }
 EXPORT_SYMBOL(tsc2101_reads_sync);
 
-int tsc2101_read_sync(struct spi_device *spi, int page, u8 address)
+u16 tsc2101_read_sync(struct spi_device *spi, u32 reg)
 {
-	int err;
-	u16 val;
-
-	err = tsc2101_reads_sync(spi, page, address, &val, 1);
-	if (err)
-		return err;
-	return val;
+	return tsc2xxx_read_sync(spi, reg);
 }
 EXPORT_SYMBOL(tsc2101_read_sync);
 
@@ -244,7 +168,7 @@ static int tsc2101_probe(struct spi_device *spi)
 		goto err;
 	}
 
-	w = tsc2101_read_sync(spi, 1, 0);
+	w = tsc2101_read_sync(spi, TSC2XXX_REG(1, 0));
 	if (!(w & (1 << 14))) {
 		dev_err(&spi->dev, "invalid ADC register value %04x\n", w);
 		goto err;
diff --git a/drivers/video/omap/lcd_h2.c b/drivers/video/omap/lcd_h2.c
index 7d16b57..fa419eb 100644
--- a/drivers/video/omap/lcd_h2.c
+++ b/drivers/video/omap/lcd_h2.c
@@ -21,6 +21,8 @@
 
 #include <linux/module.h>
 #include <linux/platform_device.h>
+#include <linux/spi/spi.h>
+#include <linux/spi/tsc2xxx.h>
 #include <linux/spi/tsc2101.h>
 
 #include <asm/arch/mux.h>
@@ -48,7 +50,8 @@ static int h2_panel_enable(struct lcd_panel *panel)
 	 * Assert LCD_EN, BKLIGHT_EN pins on LCD panel
 	 * page2, GPIO config reg, GPIO(0,1) to out and asserted
 	 */
-	r = tsc2101_write_sync(h2_panel_dev.tsc2101_dev, 2, 0x23, 0xcc00);
+	r = tsc2101_write_sync(h2_panel_dev.tsc2101_dev,
+					TSC2XXX_REG(2, 0x23), 0xcc00);
 	if (r < 0)
 		dev_err(&h2_panel_dev.lcd_dev->dev,
 			"failed to enable LCD panel\n");
@@ -58,11 +61,14 @@ static int h2_panel_enable(struct lcd_panel *panel)
 
 static void h2_panel_disable(struct lcd_panel *panel)
 {
+	int r;
 	/*
 	 * Deassert LCD_EN and BKLIGHT_EN pins on LCD panel
 	 * page2, GPIO config reg, GPIO(0,1) to out and deasserted
 	 */
-	if (tsc2101_write_sync(h2_panel_dev.tsc2101_dev, 2, 0x23, 0x8800))
+	r = tsc2101_write_sync(h2_panel_dev.tsc2101_dev,
+					TSC2XXX_REG(2, 0x23), 0x8800);
+	if (r < 0)
 		dev_err(&h2_panel_dev.lcd_dev->dev,
 			"failed to disable LCD panel\n");
 }
diff --git a/include/linux/spi/tsc2101.h b/include/linux/spi/tsc2101.h
index 01e6d23..af8815f 100644
--- a/include/linux/spi/tsc2101.h
+++ b/include/linux/spi/tsc2101.h
@@ -30,11 +30,11 @@ struct tsc2101_platform_data {
 	void	(*disable_mclk)(struct spi_device *spi);
 };
 
-extern int tsc2101_read_sync(struct spi_device *spi, int page, u8 address);
-extern int tsc2101_reads_sync(struct spi_device *spi, int page,
-			       u8 startaddress, u16 * data, int numregs);
-extern int tsc2101_write_sync(struct spi_device *spi, int page, u8 address,
-			       u16 data);
+extern u16 tsc2101_read_sync(struct spi_device *spi, u32 reg);
+extern int tsc2101_reads_sync(struct spi_device *spi, u32 reg,
+		u16 *data, int numregs);
+extern int tsc2101_write_sync(struct spi_device *spi, u32 reg,
+		u16 data);
 
 extern int tsc2101_enable_mclk(struct spi_device *spi);
 extern void tsc2101_disable_mclk(struct spi_device *spi);

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/4] SPI: tsc2102 support for tsc2xxx core
  2007-08-14 19:12 [PATCH 1/4] SPI: tsc2xxx core Ragner Magalhaes
  2007-08-14 19:12 ` [PATCH 2/4] SPI: tsc2301 support for " Ragner Magalhaes
  2007-08-14 19:12 ` [PATCH 3/4] SPI: tsc2101 " Ragner Magalhaes
@ 2007-08-14 19:13 ` Ragner Magalhaes
  2007-08-14 20:12 ` [PATCH 1/4] SPI: " David Brownell
  3 siblings, 0 replies; 7+ messages in thread
From: Ragner Magalhaes @ 2007-08-14 19:13 UTC (permalink / raw)
  To: david-b; +Cc: linux-omap-open-source

From: Ragner Magalhaes <ragner.magalhaes@indt.org.br>

Add support for tsc2xxx core api

Signed-off-by: Ragner Magalhaes <ragner.magalhaes@indt.org.br>
---

 drivers/spi/Kconfig         |    5 -
 drivers/spi/tsc2102.c       |  343 +++++++++++++------------------------------
 include/linux/spi/tsc2102.h |   95 ++++++------
 3 files changed, 150 insertions(+), 293 deletions(-)

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index a4b112a..54483f6 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -226,8 +226,9 @@ config SPI_TSC2101
 	 as well as a way to enable the MCLK clock.
 	 
 config SPI_TSC2102
-       depends on SPI_MASTER
-       tristate "TSC2102 codec support"
+	depends on SPI_MASTER
+	tristate "TSC2102 codec support"
+	select SPI_TSC2XXX
        ---help---
          Say Y here if you want support for the TSC2102 chip.  It
 	 will be needed for the touchscreen driver on some boards.
diff --git a/drivers/spi/tsc2102.c b/drivers/spi/tsc2102.c
index 59171ca..865fe6c 100644
--- a/drivers/spi/tsc2102.c
+++ b/drivers/spi/tsc2102.c
@@ -30,6 +30,7 @@
 #include <linux/interrupt.h>
 #include <linux/clk.h>
 #include <linux/spi/spi.h>
+#include <linux/spi/tsc2xxx.h>
 #include <linux/spi/tsc2102.h>
 #include <linux/err.h>
 #include <linux/hwmon.h>
@@ -76,14 +77,6 @@
 
 #define CS_CHANGE(val)			0
 
-struct tsc2102_spi_req {
-	struct spi_device *dev;
-	uint16_t command;
-	uint16_t data;
-	struct spi_transfer *transfer;
-	struct spi_message message;
-};
-
 struct tsc2102_dev {
 	struct tsc2102_config *pdata;
 	spinlock_t lock, lock_sync;
@@ -104,12 +97,6 @@ struct tsc2102_dev {
 	unsigned int mode_msecs;	/* Interval for .mode_timer */
 
 	struct spi_device *spi;
-	struct spi_transfer *transfers;
-	struct tsc2102_spi_req req_adc;
-	struct tsc2102_spi_req req_status;
-	struct tsc2102_spi_req req_pressure;
-	struct tsc2102_spi_req req_stopadc;
-	struct tsc2102_spi_req req_mode;
 
 	int bat[2], aux[1], temp[2];
 	struct class_device *hwmondev;
@@ -123,168 +110,41 @@ MODULE_PARM_DESC(touch_check_msecs, "Pen-up polling interval in msecs");
 module_param_named(sensor_scan_msecs, tsc.mode_msecs, uint, 0);
 MODULE_PARM_DESC(sensor_scan_msecs, "Temperature & battery scan interval");
 
-void tsc2102_write_sync(int page, u8 address, u16 data)
+int tsc2102_write_sync(struct spi_device *spi, u32 reg, u16 data)
 {
-	static struct tsc2102_spi_req req;
-	static struct spi_transfer transfer[2];
-	int ret;
-
-	spi_message_init(&req.message);
-	req.transfer = transfer;
-
-	/* Address */
-	req.command = (page << 11) | (address << 5);
-	req.transfer[0].tx_buf = &req.command;
-	req.transfer[0].rx_buf = 0;
-	req.transfer[0].len = 2;
-	spi_message_add_tail(&req.transfer[0], &req.message);
-
-	/* Data */
-	req.transfer[1].tx_buf = &data;
-	req.transfer[1].rx_buf = 0;
-	req.transfer[1].len = 2;
-	req.transfer[1].cs_change = CS_CHANGE(1);
-	spi_message_add_tail(&req.transfer[1], &req.message);
-
-	ret = spi_sync(tsc.spi, &req.message);
-	if (!ret && req.message.status)
-		ret = req.message.status;
-
-	if (ret)
-		printk(KERN_ERR "%s: error %i in SPI request\n",
-				__FUNCTION__, ret);
+	return tsc2xxx_write_sync(tsc.spi, reg, data);
 }
 
-void tsc2102_reads_sync(int page, u8 startaddress, u16 *data, int numregs)
+int tsc2102_reads_sync(struct spi_device *spi, u32 reg,
+		u16 *data, int numregs)
 {
-	static struct tsc2102_spi_req req;
-	static struct spi_transfer transfer[6];
-	int ret, i, j;
-
-	BUG_ON(numregs + 1 > ARRAY_SIZE(transfer));
-
-	spi_message_init(&req.message);
-	req.transfer = transfer;
-	i = 0;
-	j = 0;
-
-	/* Address */
-	req.command = 0x8000 | (page << 11) | (startaddress << 5);
-	req.transfer[i].tx_buf = &req.command;
-	req.transfer[i].rx_buf = 0;
-	req.transfer[i].len = 2;
-	spi_message_add_tail(&req.transfer[i ++], &req.message);
-
-	/* Data */
-	while (j < numregs) {
-		req.transfer[i].tx_buf = 0;
-		req.transfer[i].rx_buf = &data[j ++];
-		req.transfer[i].len = 2;
-		req.transfer[i].cs_change = CS_CHANGE(j == numregs);
-		spi_message_add_tail(&req.transfer[i ++], &req.message);
-	}
-
-	ret = spi_sync(tsc.spi, &req.message);
-	if (!ret && req.message.status)
-		ret = req.message.status;
-
-	if (ret)
-		printk(KERN_ERR "%s: error %i in SPI request\n",
-				__FUNCTION__, ret);
+	return tsc2xxx_read_buf_sync(spi, reg, data, numregs);
 }
 
-u16 tsc2102_read_sync(int page, u8 address)
-{
-	u16 ret;
-	tsc2102_reads_sync(page, address, &ret, 1);
-	return ret;
-}
-
-static void tsc2102_write_async(
-		struct tsc2102_spi_req *spi, int page, u8 address, u16 data,
-		void (*complete)(struct tsc2102_dev *context))
+u16 tsc2102_read_sync(struct spi_device *spi, u32 reg)
 {
-	int ret;
-
-	spi_message_init(&spi->message);
-	spi->message.complete = (void (*)(void *)) complete;
-	spi->message.context = &tsc;
-
-	/* Address */
-	spi->command = (page << 11) | (address << 5);
-	spi->transfer[0].tx_buf = &spi->command;
-	spi->transfer[0].rx_buf = 0;
-	spi->transfer[0].len = 2;
-	spi_message_add_tail(&spi->transfer[0], &spi->message);
-
-	/* Data */
-	spi->data = data;
-	spi->transfer[1].tx_buf = &spi->data;
-	spi->transfer[1].rx_buf = 0;
-	spi->transfer[1].len = 2;
-	spi->transfer[1].cs_change = CS_CHANGE(1);
-	spi_message_add_tail(&spi->transfer[1], &spi->message);
-
-	ret = spi_async(spi->dev, &spi->message);
-	if (ret)
-		printk(KERN_ERR "%s: error %i in SPI request\n",
-				__FUNCTION__, ret);
+	return tsc2xxx_read_sync(spi, reg);
 }
 
-static void tsc2102_reads_async(struct tsc2102_spi_req *spi,
-		int page, u8 startaddress, u16 *data, int numregs,
-		void (*complete)(struct tsc2102_dev *context))
+static int tsc2102_write_async( struct spi_device *spi, u32 reg,
+		u16 data, void (*complete)(struct tsc2102_dev *context))
 {
-	int ret, i, j;
-
-	spi_message_init(&spi->message);
-	spi->message.complete = (void (*)(void *)) complete;
-	spi->message.context = &tsc;
-	i = 0;
-	j = 0;
-
-	/* Address */
-	spi->command = 0x8000 | (page << 11) | (startaddress << 5);
-	spi->transfer[i].tx_buf = &spi->command;
-	spi->transfer[i].rx_buf = 0;
-	spi->transfer[i].len = 2;
-	spi_message_add_tail(&spi->transfer[i ++], &spi->message);
-
-	/* Data */
-	while (j < numregs) {
-		spi->transfer[i].tx_buf = 0;
-		spi->transfer[i].rx_buf = &data[j ++];
-		spi->transfer[i].len = 2;
-		spi->transfer[i].cs_change = CS_CHANGE(j == numregs);
-		spi_message_add_tail(&spi->transfer[i ++], &spi->message);
-	}
-
-	ret = spi_async(spi->dev, &spi->message);
-	if (ret)
-		printk(KERN_ERR "%s: error %i in SPI request\n",
-				__FUNCTION__, ret);
+	return tsc2xxx_write_async(spi, reg, data,
+			(void (*)(void *)) complete);
 }
 
-static void tsc2102_read_async(struct tsc2102_spi_req *spi,
-		int page, u8 address, u16 *ret,
+static int tsc2102_reads_async(struct spi_device *spi, u32 reg,
+		u16 *data, int numregs,
 		void (*complete)(struct tsc2102_dev *context))
 {
-	tsc2102_reads_async(spi, page, address, ret, 1, complete);
+	return tsc2xxx_read_buf_async(spi, reg, data, numregs,
+			(void (*)(void *)) complete);
 }
 
-static void tsc2102_request_alloc(struct tsc2102_dev *dev,
-		struct tsc2102_spi_req *spi, int direction, int numregs,
-		struct spi_transfer **buffer)
+static u16 tsc2102_read_async(struct spi_device *spi, u32 reg,
+		u16 *ret, void (*complete)(struct tsc2102_dev *context))
 {
-	spi->dev = dev->spi;
-
-	if (direction == 1)	/* Write */
-		numregs = 2;
-	else			/* Read */
-		numregs += 1;
-
-	spi->transfer = *buffer;
-	*buffer += numregs;
+	return tsc2xxx_read_async(spi, reg, (void (*)(void *)) complete);
 }
 
 #define tsc2102_cb_register_func(cb, cb_t)	\
@@ -315,7 +175,7 @@ tsc2102_cb_register_func(temp2_cb, tsc2102_temp_t)
 #ifdef DEBUG
 static void tsc2102_print_dav(void)
 {
-	u16 status = tsc2102_read_sync(TSC2102_TS_STATUS_CTRL);
+	u16 status = tsc2102_read_sync(tsc.spi, TSC2102_TS_STATUS_CTRL);
 	if (status & 0x0fff)
 		printk("TSC2102: data in");
 	if (status & 0x0400)
@@ -352,33 +212,29 @@ static void tsc2102_complete_dummy(struct tsc2102_dev *dev)
 static inline void tsc2102_touchscreen_mode(struct tsc2102_dev *dev)
 {
 	/* Scan X, Y, Z1, Z2, chip controlled, 12-bit, 16 samples, 500 usec */
-	tsc2102_write_async(&dev->req_mode,
-			TSC2102_TS_ADC_CTRL, TSC2102_ADC_TS_CONTROL,
-			tsc2102_complete_dummy);
+	tsc2102_write_async(dev->spi, TSC2102_TS_ADC_CTRL,
+			TSC2102_ADC_TS_CONTROL, tsc2102_complete_dummy);
 }
 
 static inline void tsc2102_portscan_mode(struct tsc2102_dev *dev)
 {
 	/* Scan BAT1, BAT2, AUX, 12-bit, 16 samples, 500 usec */
-	tsc2102_write_async(&dev->req_mode,
-			TSC2102_TS_ADC_CTRL, TSC2102_ADC_SCAN_CONTROL,
-			tsc2102_complete_dummy);
+	tsc2102_write_async(dev->spi, TSC2102_TS_ADC_CTRL,
+			TSC2102_ADC_SCAN_CONTROL, tsc2102_complete_dummy);
 }
 
 static inline void tsc2102_temp1_mode(struct tsc2102_dev *dev)
 {
 	/* Scan TEMP1, 12-bit, 16 samples, 500 usec */
-	tsc2102_write_async(&dev->req_mode,
-			TSC2102_TS_ADC_CTRL, TSC2102_ADC_T1_CONTROL,
-			tsc2102_complete_dummy);
+	tsc2102_write_async(dev->spi, TSC2102_TS_ADC_CTRL,
+			TSC2102_ADC_T1_CONTROL, tsc2102_complete_dummy);
 }
 
 static inline void tsc2102_temp2_mode(struct tsc2102_dev *dev)
 {
 	/* Scan TEMP2, 12-bit, 16 samples, 500 usec */
-	tsc2102_write_async(&dev->req_mode,
-			TSC2102_TS_ADC_CTRL, TSC2102_ADC_T2_CONTROL,
-			tsc2102_complete_dummy);
+	tsc2102_write_async(dev->spi, TSC2102_TS_ADC_CTRL,
+			TSC2102_ADC_T2_CONTROL, tsc2102_complete_dummy);
 }
 
 static void tsc2102_mode(struct tsc2102_dev *dev)
@@ -407,9 +263,8 @@ static void tsc2102_mode(struct tsc2102_dev *dev)
 static void tsc2102_new_mode(struct tsc2102_dev *dev)
 {
 	/* Abort current conversion if any */
-	tsc2102_write_async(&dev->req_stopadc,
-			TSC2102_TS_ADC_CTRL, TSC2102_ADC_ADST,
-			tsc2102_complete_dummy);
+	tsc2102_write_async(dev->spi, TSC2102_TS_ADC_CTRL,
+			TSC2102_ADC_ADST, tsc2102_complete_dummy);
 
 	dev->state ++;
 	tsc2102_mode(dev);
@@ -487,7 +342,7 @@ static void tsc2102_status_report(struct tsc2102_dev *dev)
 	 * so that the ADC can move on to a new conversion.
 	 */
 	if (dev->status & TSC2102_TS_DAV) {
-		tsc2102_reads_async(&dev->req_adc, TSC2102_TS_X,
+		tsc2102_reads_async(dev->spi, TSC2102_TS_X,
 				dev->adc_data, 4, tsc2102_data_report);
 		if (!dev->pendown) {
 			dev->pendown = 1;
@@ -500,17 +355,17 @@ static void tsc2102_status_report(struct tsc2102_dev *dev)
 	}
 
 	if (dev->status & TSC2102_PS_DAV) {
-		tsc2102_reads_async(&dev->req_adc, TSC2102_TS_BAT1,
+		tsc2102_reads_async(dev->spi, TSC2102_TS_BAT1,
 				dev->adc_data, 3, tsc2102_data_report);
 	}
 
 	if (dev->status & TSC2102_T1_DAV) {
-		tsc2102_read_async(&dev->req_adc, TSC2102_TS_TEMP1,
+		tsc2102_read_async(dev->spi, TSC2102_TS_TEMP1,
 				dev->adc_data, tsc2102_data_report);
 	}
 
 	if (dev->status & TSC2102_T2_DAV) {
-		tsc2102_read_async(&dev->req_adc, TSC2102_TS_TEMP2,
+		tsc2102_read_async(dev->spi, TSC2102_TS_TEMP2,
 				dev->adc_data, tsc2102_data_report);
 	}
 
@@ -526,7 +381,7 @@ static void tsc2102_status_report(struct tsc2102_dev *dev)
 
 static void tsc2102_check_status(struct tsc2102_dev *dev)
 {
-	tsc2102_read_async(&dev->req_status, TSC2102_TS_STATUS_CTRL,
+	tsc2102_read_async(dev->spi, TSC2102_TS_STATUS_CTRL,
 			&dev->status, tsc2102_status_report);
 }
 
@@ -579,7 +434,7 @@ static void tsc2102_pressure(unsigned long data)
 
 	BUG_ON(!dev->pendown);
 
-	tsc2102_read_async(&dev->req_pressure, TSC2102_TS_ADC_CTRL,
+	tsc2102_read_async(dev->spi, TSC2102_TS_ADC_CTRL,
 			&dev->adc_status, tsc2102_pressure_report);
 }
 
@@ -599,12 +454,12 @@ void tsc2102_set_volume(uint8_t left_ch, uint8_t right_ch)
 
 	spin_lock(&tsc.lock_sync);
 
-	val = tsc2102_read_sync(TSC2102_DAC_GAIN_CTRL);
+	val = tsc2102_read_sync(tsc.spi, TSC2102_DAC_GAIN_CTRL);
 
 	val &= 0x8080;	/* Preserve mute-bits */
 	val |= (left_ch << 8) | right_ch;
 
-	tsc2102_write_sync(TSC2102_DAC_GAIN_CTRL, val);
+	tsc2102_write_sync(tsc.spi, TSC2102_DAC_GAIN_CTRL, val);
 
 	spin_unlock(&tsc.lock_sync);
 }
@@ -615,12 +470,12 @@ void tsc2102_set_mute(int left_ch, int right_ch)
 	u16 val;
 	spin_lock(&tsc.lock_sync);
 
-	val = tsc2102_read_sync(TSC2102_DAC_GAIN_CTRL);
+	val = tsc2102_read_sync(tsc.spi, TSC2102_DAC_GAIN_CTRL);
 
 	val &= 0x7f7f;	/* Preserve volume settings */
 	val |= (left_ch << 15) | (right_ch << 7);
 
-	tsc2102_write_sync(TSC2102_DAC_GAIN_CTRL, val);
+	tsc2102_write_sync(tsc.spi, TSC2102_DAC_GAIN_CTRL, val);
 
 	spin_unlock(&tsc.lock_sync);
 }
@@ -631,7 +486,7 @@ void tsc2102_get_mute(int *left_ch, int *right_ch)
 	u16 val;
 	spin_lock(&tsc.lock_sync);
 
-	val = tsc2102_read_sync(TSC2102_DAC_GAIN_CTRL);
+	val = tsc2102_read_sync(tsc.spi, TSC2102_DAC_GAIN_CTRL);
 
 	spin_unlock(&tsc.lock_sync);
 
@@ -643,14 +498,14 @@ void tsc2102_set_deemphasis(int enable)
 {
 	u16 val;
 	spin_lock(&tsc.lock_sync);
-	val = tsc2102_read_sync(TSC2102_DAC_POWER_CTRL);
+	val = tsc2102_read_sync(tsc.spi, TSC2102_DAC_POWER_CTRL);
 
 	if (enable)
 		val &= ~TSC2102_DEEMPF;
 	else
 		val |= TSC2102_DEEMPF;
 
-	tsc2102_write_sync(TSC2102_DAC_POWER_CTRL, val);
+	tsc2102_write_sync(tsc.spi, TSC2102_DAC_POWER_CTRL, val);
 	spin_unlock(&tsc.lock_sync);
 }
 EXPORT_SYMBOL_GPL(tsc2102_set_deemphasis);
@@ -659,14 +514,14 @@ void tsc2102_set_bassboost(int enable)
 {
 	u16 val;
 	spin_lock(&tsc.lock_sync);
-	val = tsc2102_read_sync(TSC2102_DAC_POWER_CTRL);
+	val = tsc2102_read_sync(tsc.spi, TSC2102_DAC_POWER_CTRL);
 
 	if (enable)
 		val &= ~TSC2102_BASSBC;
 	else
 		val |= TSC2102_BASSBC;
 
-	tsc2102_write_sync(TSC2102_DAC_POWER_CTRL, val);
+	tsc2102_write_sync(tsc.spi, TSC2102_DAC_POWER_CTRL, val);
 	spin_unlock(&tsc.lock_sync);
 }
 EXPORT_SYMBOL_GPL(tsc2102_set_bassboost);
@@ -716,20 +571,27 @@ int tsc2102_set_rate(int rate)
 
 	spin_lock(&tsc.lock_sync);
 
-	tsc2102_write_sync(TSC2102_AUDIO1_CTRL, tsc2102_rates[i].divisor);
+	tsc2102_write_sync(tsc.spi, TSC2102_AUDIO1_CTRL,
+			tsc2102_rates[i].divisor);
 
-	val = tsc2102_read_sync(TSC2102_AUDIO3_CTRL);
+	val = tsc2102_read_sync(tsc.spi, TSC2102_AUDIO3_CTRL);
 
 	if (tsc2102_rates[i].fs_44k) {
-		tsc2102_write_sync(TSC2102_AUDIO3_CTRL, val | TSC2102_FS44K);
+		tsc2102_write_sync(tsc.spi, TSC2102_AUDIO3_CTRL,
+				val | TSC2102_FS44K);
 		/* Enable Phase-locked-loop, set up clock dividers */
-		tsc2102_write_sync(TSC2102_PLL1_CTRL, TSC2102_PLL1_44K);
-		tsc2102_write_sync(TSC2102_PLL2_CTRL, TSC2102_PLL2_44K);
+		tsc2102_write_sync(tsc.spi, TSC2102_PLL1_CTRL,
+				TSC2102_PLL1_44K);
+		tsc2102_write_sync(tsc.spi, TSC2102_PLL2_CTRL,
+				TSC2102_PLL2_44K);
 	} else {
-		tsc2102_write_sync(TSC2102_AUDIO3_CTRL, val & ~TSC2102_FS44K);
+		tsc2102_write_sync(tsc.spi, TSC2102_AUDIO3_CTRL,
+				val & ~TSC2102_FS44K);
 		/* Enable Phase-locked-loop, set up clock dividers */
-		tsc2102_write_sync(TSC2102_PLL1_CTRL, TSC2102_PLL1_48K);
-		tsc2102_write_sync(TSC2102_PLL2_CTRL, TSC2102_PLL2_48K);
+		tsc2102_write_sync(tsc.spi, TSC2102_PLL1_CTRL,
+				TSC2102_PLL1_48K);
+		tsc2102_write_sync(tsc.spi, TSC2102_PLL2_CTRL,
+				TSC2102_PLL2_48K);
 	}
 
 	spin_unlock(&tsc.lock_sync);
@@ -746,24 +608,30 @@ void tsc2102_dac_power(int state)
 
 	if (state) {
 		/* 16-bit words, DSP mode, sample at Fsref */
-		tsc2102_write_sync(TSC2102_AUDIO1_CTRL, 0x0100);
+		tsc2102_write_sync(tsc.spi, TSC2102_AUDIO1_CTRL, 0x0100);
 		/* Keyclicks off, soft-stepping at normal rate */
-		tsc2102_write_sync(TSC2102_AUDIO2_CTRL, TSC2102_KEYCLICK_OFF);
+		tsc2102_write_sync(tsc.spi, TSC2102_AUDIO2_CTRL,
+				TSC2102_KEYCLICK_OFF);
 		/* 44.1 kHz Fsref, continuous transfer mode, master DAC */
-		tsc2102_write_sync(TSC2102_AUDIO3_CTRL, 0x2800);
+		tsc2102_write_sync(tsc.spi, TSC2102_AUDIO3_CTRL, 0x2800);
 		/* Soft-stepping enabled */
-		tsc2102_write_sync(TSC2102_AUDIO4_CTRL, 0x0000);
+		tsc2102_write_sync(tsc.spi, TSC2102_AUDIO4_CTRL, 0x0000);
 
 		/* PLL generates 44.1 kHz */
-		tsc2102_write_sync(TSC2102_PLL1_CTRL, TSC2102_PLL1_44K);
-		tsc2102_write_sync(TSC2102_PLL2_CTRL, TSC2102_PLL2_44K);
+		tsc2102_write_sync(tsc.spi, TSC2102_PLL1_CTRL,
+				TSC2102_PLL1_44K);
+		tsc2102_write_sync(tsc.spi, TSC2102_PLL2_CTRL,
+				TSC2102_PLL2_44K);
 
 		/* Codec & DAC power up, virtual ground disabled */
-		tsc2102_write_sync(TSC2102_DAC_POWER_CTRL, TSC2102_DAC_ON);
+		tsc2102_write_sync(tsc.spi, TSC2102_DAC_POWER_CTRL,
+				TSC2102_DAC_ON);
 	} else {
 		/* All off */
-		tsc2102_write_sync(TSC2102_AUDIO4_CTRL, TSC2102_KEYCLICK_OFF);
-		tsc2102_write_sync(TSC2102_PLL1_CTRL, TSC2102_PLL1_OFF);
+		tsc2102_write_sync(tsc.spi, TSC2102_AUDIO4_CTRL,
+				TSC2102_KEYCLICK_OFF);
+		tsc2102_write_sync(tsc.spi, TSC2102_PLL1_CTRL,
+				TSC2102_PLL1_OFF);
 	}
 
 	spin_unlock(&tsc.lock_sync);
@@ -775,12 +643,14 @@ void tsc2102_set_i2s_master(int state)
 	uint16_t val;
 	spin_lock(&tsc.lock_sync);
 
-	val = tsc2102_read_sync(TSC2102_AUDIO3_CTRL);
+	val = tsc2102_read_sync(tsc.spi, TSC2102_AUDIO3_CTRL);
 
 	if (state)
-		tsc2102_write_sync(TSC2102_AUDIO3_CTRL, val | TSC2102_SLVMS);
+		tsc2102_write_sync(tsc.spi, TSC2102_AUDIO3_CTRL,
+				val | TSC2102_SLVMS);
 	else
-		tsc2102_write_sync(TSC2102_AUDIO3_CTRL, val & ~TSC2102_SLVMS);
+		tsc2102_write_sync(tsc.spi, TSC2102_AUDIO3_CTRL,
+				val & ~TSC2102_SLVMS);
 
 	spin_unlock(&tsc.lock_sync);
 }
@@ -791,19 +661,23 @@ EXPORT_SYMBOL_GPL(tsc2102_set_i2s_master);
 static int tsc2102_configure(struct tsc2102_dev *dev)
 {
 	/* Reset the chip */
-	tsc2102_write_sync(TSC2102_TS_RESET_CTRL, TSC2102_RESET);
+	tsc2102_write_sync(tsc.spi, TSC2102_TS_RESET_CTRL, TSC2102_RESET);
 
 	/* Reference mode, 100 usec delay, 1.25 V reference */
 	if (dev->pdata->use_internal)
-		tsc2102_write_sync(TSC2102_TS_REF_CTRL, TSC2102_ADC_INT_REF);
+		tsc2102_write_sync(tsc.spi, TSC2102_TS_REF_CTRL,
+				TSC2102_ADC_INT_REF);
 	else
-		tsc2102_write_sync(TSC2102_TS_REF_CTRL, TSC2102_ADC_EXT_REF);
+		tsc2102_write_sync(tsc.spi, TSC2102_TS_REF_CTRL,
+				TSC2102_ADC_EXT_REF);
 
 	/* 84 usec precharge time, 32 usec sense time */
-	tsc2102_write_sync(TSC2102_TS_CONFIG_CTRL, TSC2102_CONFIG_TIMES);
+	tsc2102_write_sync(tsc.spi, TSC2102_TS_CONFIG_CTRL,
+			TSC2102_CONFIG_TIMES);
 
 	/* PINT/DAV acts as DAV */
-	tsc2102_write_sync(TSC2102_TS_STATUS_CTRL, TSC2102_ADC_DAV);
+	tsc2102_write_sync(tsc.spi, TSC2102_TS_STATUS_CTRL,
+			TSC2102_ADC_DAV);
 
 	tsc2102_mode(dev);
 	mod_timer(&dev->mode_timer, jiffies +
@@ -816,7 +690,7 @@ static int tsc2102_configure(struct tsc2102_dev *dev)
  */
 int tsc2102_get_revision(void)
 {
-	return tsc2102_read_sync(TSC2102_AUDIO3_CTRL) & 7;
+	return tsc2102_read_sync(tsc.spi, TSC2102_AUDIO3_CTRL) & 7;
 }
 
 /*
@@ -834,7 +708,7 @@ void tsc2102_keyclick(int amplitude, int freq, int length)
 {
 	u16 val;
 	spin_lock(&tsc.lock_sync);
-	val = tsc2102_read_sync(TSC2102_AUDIO2_CTRL);
+	val = tsc2102_read_sync(tsc.spi, TSC2102_AUDIO2_CTRL);
 	val &= 0x800f;
 
 	/* Set amplitude */
@@ -865,7 +739,7 @@ void tsc2102_keyclick(int amplitude, int freq, int length)
 	/* Enable keyclick */
 	val |= 0x8000;
 
-	tsc2102_write_sync(TSC2102_AUDIO2_CTRL, val);
+	tsc2102_write_sync(tsc.spi, TSC2102_AUDIO2_CTRL, val);
 	spin_unlock(&tsc.lock_sync);
 }
 
@@ -945,7 +819,7 @@ tsc2102_suspend(struct spi_device *spi, pm_message_t state)
 		dev->touch_cb(0);
 
 	/* Abort current conversion and power down the ADC */
-	tsc2102_write_sync(TSC2102_TS_ADC_CTRL, TSC2102_ADC_ADST);
+	tsc2102_write_sync(tsc.spi, TSC2102_TS_ADC_CTRL, TSC2102_ADC_ADST);
 
 	dev->spi->dev.power.power_state = state;
 
@@ -994,16 +868,15 @@ static struct platform_device tsc2102_alsa_device = {
 static int tsc2102_probe(struct spi_device *spi)
 {
 	struct tsc2102_config *pdata = spi->dev.platform_data;
-	struct spi_transfer *spi_buffer;
 	int err = 0;
 
 	if (!pdata) {
-		printk(KERN_ERR "TSC2102: Platform data not supplied\n");
+		dev_err(&spi->dev, "TSC2102: Platform data not supplied\n");
 		return -ENOENT;
 	}
 
 	if (!spi->irq) {
-		printk(KERN_ERR "TSC2102: Invalid irq value\n");
+		dev_err(&spi->dev, "TSC2102: Invalid irq value\n");
 		return -ENOENT;
 	}
 
@@ -1015,27 +888,13 @@ static int tsc2102_probe(struct spi_device *spi)
 	tsc.mode_msecs = 1000;
 	tsc.spi = spi;
 
-	/* Allocate enough struct spi_transfer's for all requests */
-	spi_buffer = kzalloc(sizeof(struct spi_transfer) * 16, GFP_KERNEL);
-	if (!spi_buffer) {
-		printk(KERN_ERR "TSC2102: No memory for SPI buffers\n");
-		return -ENOMEM;
-	}
-
-	tsc.transfers = spi_buffer;
-	tsc2102_request_alloc(&tsc, &tsc.req_adc, 0, 4, &spi_buffer);
-	tsc2102_request_alloc(&tsc, &tsc.req_status, 0, 1, &spi_buffer);
-	tsc2102_request_alloc(&tsc, &tsc.req_pressure, 0, 1, &spi_buffer);
-	tsc2102_request_alloc(&tsc, &tsc.req_stopadc, 1, 1, &spi_buffer);
-	tsc2102_request_alloc(&tsc, &tsc.req_mode, 1, 1, &spi_buffer);
-
 	spin_lock_init(&tsc.lock);
 	spin_lock(&tsc.lock_sync);
 
 	/* Get the BCLK - assuming the rate is at 12000000 */
 	tsc.bclk_ck = clk_get(0, "bclk");
 	if (!tsc.bclk_ck) {
-		printk(KERN_ERR "Unable to get the clock BCLK\n");
+		dev_err(&spi->dev, "Unable to get the clock BCLK\n");
 		err = -EPERM;
 		goto done;
 	}
@@ -1044,7 +903,7 @@ static int tsc2102_probe(struct spi_device *spi)
 
 	if (request_irq(spi->irq, tsc2102_handler, IRQF_SAMPLE_RANDOM |
 				IRQF_TRIGGER_FALLING, "tsc2102", &tsc)) {
-		printk(KERN_ERR "Could not allocate touchscreen IRQ!\n");
+		dev_err(&spi->dev, "Could not allocate touchscreen IRQ!\n");
 		err = -EINVAL;
 		goto err_clk;
 	}
@@ -1065,7 +924,7 @@ static int tsc2102_probe(struct spi_device *spi)
 
 	/* Now try to detect the chip, make first contact */
 	if (tsc2102_get_revision() != 0x1) {
-		printk(KERN_ERR "No TI TSC2102 chip found!\n");
+		dev_err(&spi->dev, "No TI TSC2102 chip found!\n");
 		goto err_timer;
 	}
 
@@ -1089,7 +948,7 @@ static int tsc2102_probe(struct spi_device *spi)
 #ifdef CONFIG_HWMON
 	tsc.hwmondev = hwmon_device_register(&spi->dev);
 	if (IS_ERR(tsc.hwmondev)) {
-		printk(KERN_ERR "tsc2102_hwmon: Device registration failed\n");
+		dev_err(&spi->dev, "tsc2102_hwmon: Device registration failed\n");
 		err = PTR_ERR(tsc.hwmondev);
 		goto err_alsa;
 	}
@@ -1107,7 +966,7 @@ static int tsc2102_probe(struct spi_device *spi)
 	}
 
 	if (err)
-		printk(KERN_ERR "tsc2102_hwmon: Creating one or more "
+		dev_err(&spi->dev, "tsc2102_hwmon: Creating one or more "
 				"attribute files failed\n");
 	err = 0;	/* Not fatal */
 #endif
@@ -1154,8 +1013,6 @@ static int tsc2102_remove(struct spi_device *spi)
 	del_timer(&tsc.mode_timer);
 	del_timer(&tsc.ts_timer);
 
-	kfree(tsc.transfers);
-
 #ifdef CONFIG_HWMON
 	hwmon_device_unregister(dev->hwmondev);
 #endif
diff --git a/include/linux/spi/tsc2102.h b/include/linux/spi/tsc2102.h
index be13300..4c7e3c6 100644
--- a/include/linux/spi/tsc2102.h
+++ b/include/linux/spi/tsc2102.h
@@ -38,10 +38,11 @@ struct tsc2102_config {
 #define TSC_AUX		(1 << 2)
 #define TSC_TEMP	(1 << 4)
 
-extern u16 tsc2102_read_sync(int page, u8 address);
-extern void tsc2102_reads_sync(int page, u8 startaddress, u16 *data,
-		int numregs);
-extern void tsc2102_write_sync(int page, u8 address, u16 data);
+extern u16 tsc2102_read_sync(struct spi_device *spi, u32 reg);
+extern int tsc2102_reads_sync(struct spi_device *spi, u32 reg,
+		u16 *data, int numregs);
+extern int tsc2102_write_sync(struct spi_device *spi, u32 reg,
+		u16 data);
 
 typedef void (*tsc2102_touch_t)(int touching);
 typedef void (*tsc2102_coords_t)(int x, int y, int z1, int z2);
@@ -66,55 +67,53 @@ extern void tsc2102_set_bassboost(int enable);
 
 extern void tsc2102_keyclick(int amplitude, int freq, int length);
 
-#define TSC2102_REG(pg, addr)		pg, addr
-
 /* Page 0, Touch Screen & Keypad Data registers */
-#define TSC2102_TS_X			TSC2102_REG(0, 0x00)
-#define TSC2102_TS_Y			TSC2102_REG(0, 0x01)
-#define TSC2102_TS_Z1			TSC2102_REG(0, 0x02)
-#define TSC2102_TS_Z2			TSC2102_REG(0, 0x03)
-#define TSC2102_TS_BAT1			TSC2102_REG(0, 0x05)
-#define TSC2102_TS_BAT2			TSC2102_REG(0, 0x06)
-#define TSC2102_TS_AUX			TSC2102_REG(0, 0x07)
-#define TSC2102_TS_TEMP1		TSC2102_REG(0, 0x09)
-#define TSC2102_TS_TEMP2		TSC2102_REG(0, 0x0a)
+#define TSC2102_TS_X			TSC2XXX_REG(0, 0x00)
+#define TSC2102_TS_Y			TSC2XXX_REG(0, 0x01)
+#define TSC2102_TS_Z1			TSC2XXX_REG(0, 0x02)
+#define TSC2102_TS_Z2			TSC2XXX_REG(0, 0x03)
+#define TSC2102_TS_BAT1 		TSC2XXX_REG(0, 0x05)
+#define TSC2102_TS_BAT2 		TSC2XXX_REG(0, 0x06)
+#define TSC2102_TS_AUX			TSC2XXX_REG(0, 0x07)
+#define TSC2102_TS_TEMP1		TSC2XXX_REG(0, 0x09)
+#define TSC2102_TS_TEMP2		TSC2XXX_REG(0, 0x0a)
 
 /* Page 1, Touch Screen & Keypad Control registers */
-#define TSC2102_TS_ADC_CTRL		TSC2102_REG(1, 0x00)
-#define TSC2102_TS_STATUS_CTRL		TSC2102_REG(1, 0x01)
-#define TSC2102_TS_REF_CTRL		TSC2102_REG(1, 0x03)
-#define TSC2102_TS_RESET_CTRL		TSC2102_REG(1, 0x04)
-#define TSC2102_TS_CONFIG_CTRL		TSC2102_REG(1, 0x05)
+#define TSC2102_TS_ADC_CTRL		TSC2XXX_REG(1, 0x00)
+#define TSC2102_TS_STATUS_CTRL		TSC2XXX_REG(1, 0x01)
+#define TSC2102_TS_REF_CTRL		TSC2XXX_REG(1, 0x03)
+#define TSC2102_TS_RESET_CTRL		TSC2XXX_REG(1, 0x04)
+#define TSC2102_TS_CONFIG_CTRL		TSC2XXX_REG(1, 0x05)
 
 /* Page 2, Audio Control registers */
-#define TSC2102_AUDIO1_CTRL		TSC2102_REG(2, 0x00)
-#define TSC2102_DAC_GAIN_CTRL		TSC2102_REG(2, 0x02)
-#define TSC2102_AUDIO2_CTRL		TSC2102_REG(2, 0x04)
-#define TSC2102_DAC_POWER_CTRL		TSC2102_REG(2, 0x05)
-#define TSC2102_AUDIO3_CTRL		TSC2102_REG(2, 0x06)
-#define TSC2102_LCH_BASS_BOOST_N0	TSC2102_REG(2, 0x07)
-#define TSC2102_LCH_BASS_BOOST_N1	TSC2102_REG(2, 0x08)
-#define TSC2102_LCH_BASS_BOOST_N2	TSC2102_REG(2, 0x09)
-#define TSC2102_LCH_BASS_BOOST_N3	TSC2102_REG(2, 0x0a)
-#define TSC2102_LCH_BASS_BOOST_N4	TSC2102_REG(2, 0x0b)
-#define TSC2102_LCH_BASS_BOOST_N5	TSC2102_REG(2, 0x0c)
-#define TSC2102_LCH_BASS_BOOST_D1	TSC2102_REG(2, 0x0d)
-#define TSC2102_LCH_BASS_BOOST_D2	TSC2102_REG(2, 0x0e)
-#define TSC2102_LCH_BASS_BOOST_D4	TSC2102_REG(2, 0x0f)
-#define TSC2102_LCH_BASS_BOOST_D5	TSC2102_REG(2, 0x10)
-#define TSC2102_RCH_BASS_BOOST_N0	TSC2102_REG(2, 0x11)
-#define TSC2102_RCH_BASS_BOOST_N1	TSC2102_REG(2, 0x12)
-#define TSC2102_RCH_BASS_BOOST_N2	TSC2102_REG(2, 0x13)
-#define TSC2102_RCH_BASS_BOOST_N3	TSC2102_REG(2, 0x14)
-#define TSC2102_RCH_BASS_BOOST_N4	TSC2102_REG(2, 0x15)
-#define TSC2102_RCH_BASS_BOOST_N5	TSC2102_REG(2, 0x16)
-#define TSC2102_RCH_BASS_BOOST_D1	TSC2102_REG(2, 0x17)
-#define TSC2102_RCH_BASS_BOOST_D2	TSC2102_REG(2, 0x18)
-#define TSC2102_RCH_BASS_BOOST_D4	TSC2102_REG(2, 0x19)
-#define TSC2102_RCH_BASS_BOOST_D5	TSC2102_REG(2, 0x1a)
-#define TSC2102_PLL1_CTRL		TSC2102_REG(2, 0x1b)
-#define TSC2102_PLL2_CTRL		TSC2102_REG(2, 0x1c)
-#define TSC2102_AUDIO4_CTRL		TSC2102_REG(2, 0x1d)
+#define TSC2102_AUDIO1_CTRL		TSC2XXX_REG(2, 0x00)
+#define TSC2102_DAC_GAIN_CTRL		TSC2XXX_REG(2, 0x02)
+#define TSC2102_AUDIO2_CTRL		TSC2XXX_REG(2, 0x04)
+#define TSC2102_DAC_POWER_CTRL		TSC2XXX_REG(2, 0x05)
+#define TSC2102_AUDIO3_CTRL		TSC2XXX_REG(2, 0x06)
+#define TSC2102_LCH_BASS_BOOST_N0	TSC2XXX_REG(2, 0x07)
+#define TSC2102_LCH_BASS_BOOST_N1	TSC2XXX_REG(2, 0x08)
+#define TSC2102_LCH_BASS_BOOST_N2	TSC2XXX_REG(2, 0x09)
+#define TSC2102_LCH_BASS_BOOST_N3	TSC2XXX_REG(2, 0x0a)
+#define TSC2102_LCH_BASS_BOOST_N4	TSC2XXX_REG(2, 0x0b)
+#define TSC2102_LCH_BASS_BOOST_N5	TSC2XXX_REG(2, 0x0c)
+#define TSC2102_LCH_BASS_BOOST_D1	TSC2XXX_REG(2, 0x0d)
+#define TSC2102_LCH_BASS_BOOST_D2	TSC2XXX_REG(2, 0x0e)
+#define TSC2102_LCH_BASS_BOOST_D4	TSC2XXX_REG(2, 0x0f)
+#define TSC2102_LCH_BASS_BOOST_D5	TSC2XXX_REG(2, 0x10)
+#define TSC2102_RCH_BASS_BOOST_N0	TSC2XXX_REG(2, 0x11)
+#define TSC2102_RCH_BASS_BOOST_N1	TSC2XXX_REG(2, 0x12)
+#define TSC2102_RCH_BASS_BOOST_N2	TSC2XXX_REG(2, 0x13)
+#define TSC2102_RCH_BASS_BOOST_N3	TSC2XXX_REG(2, 0x14)
+#define TSC2102_RCH_BASS_BOOST_N4	TSC2XXX_REG(2, 0x15)
+#define TSC2102_RCH_BASS_BOOST_N5	TSC2XXX_REG(2, 0x16)
+#define TSC2102_RCH_BASS_BOOST_D1	TSC2XXX_REG(2, 0x17)
+#define TSC2102_RCH_BASS_BOOST_D2	TSC2XXX_REG(2, 0x18)
+#define TSC2102_RCH_BASS_BOOST_D4	TSC2XXX_REG(2, 0x19)
+#define TSC2102_RCH_BASS_BOOST_D5	TSC2XXX_REG(2, 0x1a)
+#define TSC2102_PLL1_CTRL		TSC2XXX_REG(2, 0x1b)
+#define TSC2102_PLL2_CTRL		TSC2XXX_REG(2, 0x1c)
+#define TSC2102_AUDIO4_CTRL		TSC2XXX_REG(2, 0x1d)
 
 /* Field masks for Audio Control 1 */
 #define AC1_WLEN(ARG)			(((ARG) & 0x03) << 10)

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/4] SPI: tsc2xxx core
  2007-08-14 19:12 [PATCH 1/4] SPI: tsc2xxx core Ragner Magalhaes
                   ` (2 preceding siblings ...)
  2007-08-14 19:13 ` [PATCH 4/4] SPI: tsc2102 " Ragner Magalhaes
@ 2007-08-14 20:12 ` David Brownell
  2007-08-14 21:02   ` Ragner Magalhaes
  3 siblings, 1 reply; 7+ messages in thread
From: David Brownell @ 2007-08-14 20:12 UTC (permalink / raw)
  To: Ragner Magalhaes; +Cc: linux-omap-open-source

On Tuesday 14 August 2007, Ragner Magalhaes wrote:
> This is the start to build tsc2xxx core with all sharable routines
> between tsc2101, tsc2102, tsc2301 ... and more later tsc2100, tsc2111, etc.

I'm getting confused here.  What's the plan?  Is this an entirely
different approach from the tsc210x stuff ... and if so, why?


I took a look at the tsc2101 bits, and I'm puzzled by why the
original "int tsc2101_read_sync()" became "u16 tsc2101_read_sync()".

First, why return "int" instead of "negative erno or value"?  Not
that errors will be common, but returning "u16" means they can't
ever be reported or handled...

Second, since that just wraps tsc2xxx_read_sync(), why even bother
wrapping it?  Better to call that directly ... more efficient and
easier to understand/follow.

... and for that matter, the single-register read/write commands
seem like they'd best use spi_write_then_read(), since DMA to
stacks is unsafe and nonportable.


I certainly like the idea of having *one* core for all these TSC
chips ... with reusable bits on top.  And I know that audio will
be one of the nastier bits, so being able to reuse e.g. the H2
(and H3?) audio support right away seems like a win.  Do your
patches also give us shared tsc2101/2102 touchscreen and hwmon
support?

I just don't see how these parts are expected to fit together yet.
The patch from Andrzej seemed a bit more clear, although it did
not cover as much ground at the beginning.  I suspect you have
a plan, but it's just not yet apparent to me...

- Dave

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/4] SPI: tsc2xxx core
  2007-08-14 20:12 ` [PATCH 1/4] SPI: " David Brownell
@ 2007-08-14 21:02   ` Ragner Magalhaes
  2007-08-14 22:50     ` David Brownell
  0 siblings, 1 reply; 7+ messages in thread
From: Ragner Magalhaes @ 2007-08-14 21:02 UTC (permalink / raw)
  To: ext David Brownell; +Cc: linux-omap-open-source

ext David Brownell wrote:
> On Tuesday 14 August 2007, Ragner Magalhaes wrote:
>> This is the start to build tsc2xxx core with all sharable routines
>> between tsc2101, tsc2102, tsc2301 ... and more later tsc2100, tsc2111, etc.
> 
> I'm getting confused here.  What's the plan?  Is this an entirely
> different approach from the tsc210x stuff ... and if so, why?
I think we could to have a tsc2xxx core with all main sharable routines
by tsc2xxx family ... and Chip-specific calling this core routines ...

And "[PATCH 1/4] SPI: tsc2xxx core" could to be the start ...

> 
> 
> I took a look at the tsc2101 bits, and I'm puzzled by why the
> original "int tsc2101_read_sync()" became "u16 tsc2101_read_sync()".
> 
> First, why return "int" instead of "negative erno or value"?  Not
> that errors will be common, but returning "u16" means they can't
> ever be reported or handled...
Ok, I do not saw at the kernel's code some thing as

w = tsc2101_read_sync(spi, 1, 0);
if (w < 0) {
	dev_err(&spi->dev, "Error or invalid anything \n");
	goto err;
}

I saw ...
w = tsc2101_read_sync(spi, 1, 0);
if (!(w & (1 << 14))) {
	dev_err(&spi->dev, "Error or invalid anything \n");
	goto err;
}

I think my solution is not a mistake  about this ...

> 
> Second, since that just wraps tsc2xxx_read_sync(), why even bother
> wrapping it?  Better to call that directly ... more efficient and
> easier to understand/follow.
Ok, thanks ...
> 
> ... and for that matter, the single-register read/write commands
> seem like they'd best use spi_write_then_read(), since DMA to
> stacks is unsafe and nonportable.
> 
> 
> I certainly like the idea of having *one* core for all these TSC
> chips ... with reusable bits on top.  And I know that audio will
> be one of the nastier bits, so being able to reuse e.g. the H2
> (and H3?) audio support right away seems like a win.  Do your
> patches also give us shared tsc2101/2102 touchscreen and hwmon
> support?

> 
> I just don't see how these parts are expected to fit together yet.
> The patch from Andrzej seemed a bit more clear, although it did
> not cover as much ground at the beginning.  I suspect you have
> a plan, but it's just not yet apparent to me...
> 
> - Dave
Ok, David
Thanks for yours comments ...
I go to continue working about this ... to find a better solution ..

> 
> 


-- 
Ragner Magalhaes

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/4] SPI: tsc2xxx core
  2007-08-14 21:02   ` Ragner Magalhaes
@ 2007-08-14 22:50     ` David Brownell
  0 siblings, 0 replies; 7+ messages in thread
From: David Brownell @ 2007-08-14 22:50 UTC (permalink / raw)
  To: Ragner Magalhaes; +Cc: linux-omap-open-source

On Tuesday 14 August 2007, Ragner Magalhaes wrote:
> ext David Brownell wrote:
> > On Tuesday 14 August 2007, Ragner Magalhaes wrote:
> >> This is the start to build tsc2xxx core with all sharable routines
> >> between tsc2101, tsc2102, tsc2301 ... and more later tsc2100, tsc2111, etc.
> > 
> > I'm getting confused here.  What's the plan?  Is this an entirely
> > different approach from the tsc210x stuff ... and if so, why?
>
> I think we could to have a tsc2xxx core with all main sharable routines
> by tsc2xxx family ... and Chip-specific calling this core routines ...
> 
> And "[PATCH 1/4] SPI: tsc2xxx core" could to be the start ...

Yes, but we also want other sharable code too.  In most cases it
seems that the touchscreen and sensor code is sharable -- modulo
the "what sensors are valid on this system" issue -- and the audio
code isn't.  Plus tsc2301 has keypad support, etc.


> > I took a look at the tsc2101 bits, and I'm puzzled by why the
> > original "int tsc2101_read_sync()" became "u16 tsc2101_read_sync()".
> > 
> > First, why return "int" instead of "negative erno or value"?  Not
> > that errors will be common, but returning "u16" means they can't
> > ever be reported or handled...
> Ok, I do not saw at the kernel's code some thing as
> 
> w = tsc2101_read_sync(spi, 1, 0);
> if (w < 0) {
> 	dev_err(&spi->dev, "Error or invalid anything \n");
> 	goto err;
> }
> 
> I saw ...
> w = tsc2101_read_sync(spi, 1, 0);
> if (!(w & (1 << 14))) {
> 	dev_err(&spi->dev, "Error or invalid anything \n");
> 	goto err;
> }
> 
> I think my solution is not a mistake  about this ...

But, did yoou see the patch I posted yesterday?  It fixes that.
I had a similar patch for the old tsc2101 code too.
 
 
> > I just don't see how these parts are expected to fit together yet.
> > The patch from Andrzej seemed a bit more clear, although it did
> > not cover as much ground at the beginning.  I suspect you have
> > a plan, but it's just not yet apparent to me...
> > 
> > - Dave
>
> Ok, David
> Thanks for yours comments ...
> I go to continue working about this ... to find a better solution ..

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-08-14 22:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-14 19:12 [PATCH 1/4] SPI: tsc2xxx core Ragner Magalhaes
2007-08-14 19:12 ` [PATCH 2/4] SPI: tsc2301 support for " Ragner Magalhaes
2007-08-14 19:12 ` [PATCH 3/4] SPI: tsc2101 " Ragner Magalhaes
2007-08-14 19:13 ` [PATCH 4/4] SPI: tsc2102 " Ragner Magalhaes
2007-08-14 20:12 ` [PATCH 1/4] SPI: " David Brownell
2007-08-14 21:02   ` Ragner Magalhaes
2007-08-14 22:50     ` David Brownell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox