Skip to contentSkip to conversation

Common code for TSC 2101 and 2102

PATCH In review andrzej zaborowski 4 participants 17 messages Jun 4, 2007 – Sep 23, 2007

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

Hi,
here's a proposition of a common driver for TSC 2101 and 2102 based
on the previous 2102 code - the difference between the two chips' registers turns out to be minimal, not considering the audio part. 2101 provides a superset of 2102 functionality for the most part.

I will appreciate if anyone with a board using a TSC2101 could test how this works for them, and even more if they can fix the parts that possibly don't work. The part that needs to go into the board file is similar to that in arch/arm/mach-omap1/board-palmte.c. Audio is not expected to work, but touchscreen and hwmon parts work for me.

I've put the sensors code back in drivers/hwmon to conform with the convention that options like CONFIG_HWMON don't affect code outside drivers/hwmon and for general consistency. As an experiment I use a workqueue this time.

Cheers,
Andrzej

From 54b60e8e33d288c5fa9644fe9f48cdb8582173f0 Mon Sep 17 00:00:00 2001
From: Andrzej Zaborowski <[email protected]>
Date: Mon, 4 Jun 2007 16:14:01 +0200
Subject: [PATCH] TSC210x driver using the SPI framework.

This is a rework of the TSC2102 driver from linux-omap-2.6 taking TSC2101 into account with the goal of using only a single driver.

---
 drivers/hwmon/Kconfig                  |   12 +
 drivers/hwmon/Makefile                 |    1 +
 drivers/hwmon/tsc210x_sensors.c        |  256 +++++++
 drivers/input/touchscreen/Kconfig      |   14 +
 drivers/input/touchscreen/Makefile     |    1 +
 drivers/input/touchscreen/tsc210x_ts.c |  153 ++++
 drivers/spi/Kconfig                    |   14 +-
 drivers/spi/Makefile                   |    1 +
 drivers/spi/tsc210x.c                  | 1181 ++++++++++++++++++++++++++++++++
 include/linux/spi/tsc210x.h            |  224 ++++++
 10 files changed, 1856 insertions(+), 1 deletions(-)
drivers/hwmon/Kconfig +12 -0
index 4d1cb5b..35ba068 100644
@@ -642,6 +642,18 @@ config SENSORS_APPLESMC
 	  Say Y here if you have an applicable laptop and want to experience
 	  the awesome power of applesmc.
 
+config SENSORS_TSC210X
+	tristate "TI TSC2101/2102 battery & temperature sensors"
+	depends on HWMON && SPI_MASTER
+	select SPI_TSC210X
+	help
+	  Say Y if your board has a TSC210X chip and you want to
+	  have its battery state, auxiliary input and/or temperature
+	  sensors exported through hwmon.
+
+	  This driver can also be built as a module.  In this case
+	  the module will be called tsc210x_sensors.
+
 config HWMON_DEBUG_CHIP
 	bool "Hardware Monitoring Chip debugging messages"
 	default n
drivers/hwmon/Makefile +1 -0
index cfaf338..b436e10 100644
@@ -58,6 +58,7 @@ obj-$(CONFIG_SENSORS_VT1211)	+= vt1211.o
 obj-$(CONFIG_SENSORS_VT8231)	+= vt8231.o
 obj-$(CONFIG_SENSORS_W83627EHF)	+= w83627ehf.o
 obj-$(CONFIG_SENSORS_W83L785TS)	+= w83l785ts.o
+obj-$(CONFIG_SENSORS_TSC210X)	+= tsc210x_sensors.o
 
 ifeq ($(CONFIG_HWMON_DEBUG_CHIP),y)
 EXTRA_CFLAGS += -DDEBUG
drivers/hwmon/tsc210x_sensors.c new file +256 -0

256 lines not on this page · raw message

drivers/input/touchscreen/Kconfig +14 -0
index 58fe796..f51d0e1 100644
@@ -164,6 +164,20 @@ config TOUCHSCREEN_UCB1400
 	  To compile this driver as a module, choose M here: the
 	  module will be called ucb1400_ts.
 
+config TOUCHSCREEN_TSC210X
+	tristate "TSC 2101/2102 based touchscreens"
+	depends on SPI_MASTER
+	select SPI_TSC210X
+	help
+	  Say Y here if you have a touchscreen interface using a
+	  TI TSC 210x controller, and your board-specific initialisation
+	  code includes that in its table of SPI devices.
+
+	  If unsure, say N (but it's safe to say "Y").
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called tsc210x_ts.
+
 config TOUCHSCREEN_TSC2301
 	tristate "TSC2301 touchscreen support"
 	depends on SPI_TSC2301
drivers/input/touchscreen/Makefile +1 -0
index 5489b7e..e1eb7e6 100644
@@ -19,5 +19,6 @@ obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN)	+= touchwin.o
 obj-$(CONFIG_TOUCHSCREEN_UCB1400)	+= ucb1400_ts.o
 obj-$(CONFIG_TOUCHSCREEN_TSC2102)	+= tsc2102_ts.o
 obj-$(CONFIG_TOUCHSCREEN_OMAP)	+= omap/
+obj-$(CONFIG_TOUCHSCREEN_TSC210X)	+= tsc210x_ts.o
 obj-$(CONFIG_TOUCHSCREEN_TSC2301)	+= tsc2301_ts.o
 obj-$(CONFIG_TOUCHSCREEN_TSC2046)	+= tsc2046_ts.o
drivers/input/touchscreen/tsc210x_ts.c new file +153 -0

153 lines not on this page · raw message

drivers/spi/Kconfig +13 -1
index 6fd6a47..dfe8018 100644
@@ -197,7 +197,19 @@ config SPI_TSC2102
        ---help---
          Say Y here if you want support for the TSC2102 chip.  It
 	 will be needed for the touchscreen driver on some boards.
-	 
+
+config SPI_TSC210X
+	depends on SPI_MASTER && EXPERIMENTAL
+	tristate "TSC2101/TSC2102 chips support"
+	help
+	  Say Y here if you want support for the TSC210x chips.  It
+	  will be needed for the touchscreen driver on some boards.
+
+	  Note that the device has to be present in the board's SPI
+	  devices table for this driver to load.  This driver doesn't
+	  automatically enable touchscreen, sensors or audio
+	  functionality - enable these in their respective menus.
+
 config SPI_TSC2301
 	tristate "TSC2301 driver"
 	depends on SPI_MASTER
drivers/spi/Makefile +1 -0
index bbb3ca9..f5dabed 100644
@@ -31,6 +31,7 @@ obj-$(CONFIG_SPI_AT25)		+= at25.o
 obj-$(CONFIG_SPI_SPIDEV)	+= spidev.o
 obj-$(CONFIG_SPI_TSC2101)	+= tsc2101.o
 obj-$(CONFIG_SPI_TSC2102)	+= tsc2102.o
+obj-$(CONFIG_SPI_TSC210X)	+= tsc210x.o
 obj-$(CONFIG_SPI_TSC2301)	+= tsc2301.o
 tsc2301-objs			:= tsc2301-core.o
 tsc2301-$(CONFIG_SPI_TSC2301_AUDIO)	+= tsc2301-mixer.o
drivers/spi/tsc210x.c new file +1181 -0

1,181 lines not on this page · raw message

include/linux/spi/tsc210x.h new file +224 -0

224 lines not on this page · raw message

Signature · 1 line
1.4.4.3
#1 lore raw

Hi All,

Quoted 5 lines · andrzej zaborowski

Hi,
here's a proposition of a common driver for TSC 2101 and 2102 based
on the previous 2102 code - the difference between the two chips' registers turns out to be minimal, not considering the audio part. 2101 provides a superset of 2102 functionality for the most part.

Anybody on list who can review this approach. We need to get this thing sorted out and have alsa-audio ASoC support on 2420 H4 and finally in mainline.

Quoted 6 lines

I will appreciate if anyone with a board using a TSC2101 could test how this works for them, and even more if they can fix the parts that possibly don't work. The part that needs to go into the board file is similar to that in arch/arm/mach-omap1/board-palmte.c. Audio is not expected to work, but touchscreen and hwmon parts work for me.

I will try to review this patch, and not sure when I can test it touchscreen part on H4.

Signature · 1 line
--Trilok Soni
#2 lore raw

Hi Andrej,

Quoted 14 lines · Trilok Soni

Hi All,

Quoted 5 lines · andrzej zaborowski

Hi,
here's a proposition of a common driver for TSC 2101 and 2102 based
on the previous 2102 code - the difference between the two chips' registers turns out to be minimal, not considering the audio part. 2101 provides a superset of 2102 functionality for the most part.

Anybody on list who can review this approach. We need to get this thing sorted out and have alsa-audio ASoC support on 2420 H4 and finally in mainline.

Quoted 1 line
Quoted 8 lines
Quoted 5 lines

I will appreciate if anyone with a board using a TSC2101 could test how this works for them, and even more if they can fix the parts that possibly don't work. The part that needs to go into the board file is similar to that in arch/arm/mach-omap1/board-palmte.c. Audio is not expected to work, but touchscreen and hwmon parts work for me.

I will try to review this patch, and not sure when I can test it touchscreen part on H4.

First cut output of checkpatch, if everyone agrees on your approach, you can add changes suggested below:

spinlock_t definition without comment
#102: FILE: drivers/hwmon/tsc210x_sensors.c:41:
+ spinlock_t apm_lock;

no space before that '++' (ctx:WxO)
#815: FILE: drivers/spi/tsc210x.c:260:

+                       (*transfer)->rx_buf = data ++;
                                                  ^

printk() should include KERN_ facility level
#852: FILE: drivers/spi/tsc210x.c:297:
+ printk("TSC210x: data in");

need consistent spacing around '|' (ctx:WxV)
#956: FILE: drivers/spi/tsc210x.c:401:
+ if (dev->status & (TSC210X_PS_DAV | TSC210X_T1_DAV |TSC210X_T2_DAV))

                                                          ^

#if 0 -- if this code redundant remove it
#1308: FILE: drivers/spi/tsc210x.c:753:
+#if 0

printk() should include KERN_ facility level
#1704: FILE: drivers/spi/tsc210x.c:1149:
+ printk(banner);

EXPORT_SYMBOL(foo); should immediately follow its function/variable #1729: FILE: drivers/spi/tsc210x.c:1174:
+EXPORT_SYMBOL(tsc210x_read_sync);

EXPORT_SYMBOL(foo); should immediately follow its function/variable #1730: FILE: drivers/spi/tsc210x.c:1175:
+EXPORT_SYMBOL(tsc210x_reads_sync);

EXPORT_SYMBOL(foo); should immediately follow its function/variable #1731: FILE: drivers/spi/tsc210x.c:1176:
+EXPORT_SYMBOL(tsc210x_write_sync);

EXPORT_SYMBOL(foo); should immediately follow its function/variable #1732: FILE: drivers/spi/tsc210x.c:1177:
+EXPORT_SYMBOL(tsc210x_keyclick);

do not add new typedefs
#1796: FILE: include/linux/spi/tsc210x.h:54:
+typedef void (*tsc210x_touch_t)(void *context, int touching);

do not add new typedefs
#1797: FILE: include/linux/spi/tsc210x.h:55:
+typedef void (*tsc210x_coords_t)(void *context, int x, int y, int z1, int z2);

do not add new typedefs
#1798: FILE: include/linux/spi/tsc210x.h:56:
+typedef void (*tsc210x_ports_t)(void *context, int bat[], int aux[]);

do not add new typedefs
#1799: FILE: include/linux/spi/tsc210x.h:57:
+typedef void (*tsc210x_temp_t)(void *context, int temp);

Missing Signed-off-by: line(s)
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

Signature · 1 line
--Trilok Soni
#3 lore raw

Hi,
thanks for this review.

After GUADEC 07, I should have access to a Palm Tungsten T3 and should be able to test the TSC2101 in it. Using ASOC is also on my TODO list for a long time, but unfortunately that's also for after GUADEC.

Quoted 23 lines · Trilok Soni

Hi Andrej,

Quoted 20 lines · Trilok Soni

Hi All,

Quoted 5 lines · andrzej zaborowski

Hi,
here's a proposition of a common driver for TSC 2101 and 2102 based
on the previous 2102 code - the difference between the two chips' registers turns out to be minimal, not considering the audio part. 2101 provides a superset of 2102 functionality for the most part.

Anybody on list who can review this approach. We need to get this thing sorted out and have alsa-audio ASoC support on 2420 H4 and finally in mainline.

Quoted 6 lines

I will appreciate if anyone with a board using a TSC2101 could test how this works for them, and even more if they can fix the parts that possibly don't work. The part that needs to go into the board file is similar to that in arch/arm/mach-omap1/board-palmte.c. Audio is not expected to work, but touchscreen and hwmon parts work for me.

Quoted 5 lines
Quoted 2 lines

I will try to review this patch, and not sure when I can test it touchscreen part on H4.

First cut output of checkpatch, if everyone agrees on your approach, you can add changes suggested below:

Uh, should have done that myself before sending, sorry.

Quoted 51 lines

spinlock_t definition without comment
#102: FILE: drivers/hwmon/tsc210x_sensors.c:41:
+ spinlock_t apm_lock;

no space before that '++' (ctx:WxO)
#815: FILE: drivers/spi/tsc210x.c:260:

+                       (*transfer)->rx_buf = data ++;
                                                   ^

printk() should include KERN_ facility level
#852: FILE: drivers/spi/tsc210x.c:297:
+ printk("TSC210x: data in");

need consistent spacing around '|' (ctx:WxV)
#956: FILE: drivers/spi/tsc210x.c:401:
+ if (dev->status & (TSC210X_PS_DAV | TSC210X_T1_DAV |TSC210X_T2_DAV))

                                                           ^

#if 0 -- if this code redundant remove it
#1308: FILE: drivers/spi/tsc210x.c:753:
+#if 0

printk() should include KERN_ facility level
#1704: FILE: drivers/spi/tsc210x.c:1149:
+ printk(banner);

EXPORT_SYMBOL(foo); should immediately follow its function/variable #1729: FILE: drivers/spi/tsc210x.c:1174:
+EXPORT_SYMBOL(tsc210x_read_sync);

EXPORT_SYMBOL(foo); should immediately follow its function/variable #1730: FILE: drivers/spi/tsc210x.c:1175:
+EXPORT_SYMBOL(tsc210x_reads_sync);

EXPORT_SYMBOL(foo); should immediately follow its function/variable #1731: FILE: drivers/spi/tsc210x.c:1176:
+EXPORT_SYMBOL(tsc210x_write_sync);

EXPORT_SYMBOL(foo); should immediately follow its function/variable #1732: FILE: drivers/spi/tsc210x.c:1177:
+EXPORT_SYMBOL(tsc210x_keyclick);

do not add new typedefs
#1796: FILE: include/linux/spi/tsc210x.h:54:
+typedef void (*tsc210x_touch_t)(void *context, int touching);

do not add new typedefs
#1797: FILE: include/linux/spi/tsc210x.h:55:
+typedef void (*tsc210x_coords_t)(void *context, int x, int y, int z1, int z2);

Quoted 7 lines

do not add new typedefs
#1798: FILE: include/linux/spi/tsc210x.h:56:
+typedef void (*tsc210x_ports_t)(void *context, int bat[], int aux[]);

do not add new typedefs
#1799: FILE: include/linux/spi/tsc210x.h:57:
+typedef void (*tsc210x_temp_t)(void *context, int temp);

I wonder what is used instead.

Quoted 9 lines

Missing Signed-off-by: line(s)
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

--
--Trilok Soni

Cheers,
Andrew

#4 lore raw
Quoted 12 lines · andrzej zaborowski
Quoted 12 lines

do not add new typedefs
#1796: FILE: include/linux/spi/tsc210x.h:54:
+typedef void (*tsc210x_touch_t)(void *context, int touching);

do not add new typedefs
#1797: FILE: include/linux/spi/tsc210x.h:55:
+typedef void (*tsc210x_coords_t)(void *context, int x, int y, int z1, int z2);

do not add new typedefs
#1798: FILE: include/linux/spi/tsc210x.h:56:
+typedef void (*tsc210x_ports_t)(void *context, int bat[], int aux[]);

Quoted 5 lines
Quoted 3 lines

do not add new typedefs
#1799: FILE: include/linux/spi/tsc210x.h:57:
+typedef void (*tsc210x_temp_t)(void *context, int temp);

I wonder what is used instead.

I think the "no new typedefs" rule gets relaxed for function call prototypes. But to answer your question: it's usually more clear to just put the function prototype into the relevant type declarator than to define a new type.

- Dave

maintainer
#5 lore raw
Quoted 20 lines · David Brownell
Quoted 12 lines · andrzej zaborowski
Quoted 12 lines

do not add new typedefs
#1796: FILE: include/linux/spi/tsc210x.h:54:
+typedef void (*tsc210x_touch_t)(void *context, int touching);

do not add new typedefs
#1797: FILE: include/linux/spi/tsc210x.h:55:
+typedef void (*tsc210x_coords_t)(void *context, int x, int y, int z1, int z2);

do not add new typedefs
#1798: FILE: include/linux/spi/tsc210x.h:56:
+typedef void (*tsc210x_ports_t)(void *context, int bat[], int aux[]);

Quoted 5 lines
Quoted 3 lines

do not add new typedefs
#1799: FILE: include/linux/spi/tsc210x.h:57:
+typedef void (*tsc210x_temp_t)(void *context, int temp);

I wonder what is used instead.

Quoted 4 lines

I think the "no new typedefs" rule gets relaxed for function call prototypes. But to answer your question: it's usually more clear to just put the function prototype into the relevant type declarator than to define a new type.

I'll be pushing Andrzej's patch today.

Tony

#6 lore raw
Quoted 1 line · Tony Lindgren

I'll be pushing Andrzej's patch today.

I saw it ... it was after I've finally started to dig out from under my pile of patches going upstream, and even fired up an OMAP build again! :)

Glad to see this. Now I'll have to actually take more of a real look at it. Presumably I'll have a few updates, and then will feel it's time to start pushing three patches upstream from this big one:

- drivers/spi/tsc210x.c core, which I can handle;
- drivers/hwmon/tsc210x_sensors.c, through hwmon;
- drivers/input/touchscreen/tsc210x_ts.c, through input;
- ... and later sound/soc/.../something.c, TBD.

I figure an initial upstream merge should included one or both of { touchscreen, hwmon } in addition to the core. Hitting 2.6.24-early should be possible.

- Dave

maintainer
#7 lore raw
Quoted 6 lines · David Brownell
Quoted 1 line · Tony Lindgren

I'll be pushing Andrzej's patch today.

I saw it ... it was after I've finally started to dig out from under my pile of patches going upstream, and even fired up an OMAP build again! :)

Cool :)

Quoted 5 lines

Glad to see this. Now I'll have to actually take more of a real look at it. Presumably I'll have a few updates, and then will feel it's time to start pushing three patches upstream from this big one:

Quoted 8 lines

- drivers/spi/tsc210x.c core, which I can handle;
- drivers/hwmon/tsc210x_sensors.c, through hwmon;
- drivers/input/touchscreen/tsc210x_ts.c, through input;
- ... and later sound/soc/.../something.c, TBD.

I figure an initial upstream merge should included one or both of { touchscreen, hwmon } in addition to the core. Hitting 2.6.24-early should be possible.

Great!

Tony

#8 lore raw
Quoted 9 lines · Tony Lindgren
Quoted 6 lines · David Brownell
Quoted 1 line · Tony Lindgren

I'll be pushing Andrzej's patch today.

I saw it ... it was after I've finally started to dig out from under my pile of patches going upstream, and even fired up an OMAP build again! :)

Cool :)

Following this will be several patches, two related to this driver:

- H4 board support, using TSC2101 (not TSC2102)
- A biggish tsc210x cleanup patch, with some bugfixes

The main thing I'd call a bug in the tsc210x code is the hwmon support not reporting milliVolts. Easily enough solved after passing some more info down the hwmon code via platform_data: actual VREF, chip type, precision.

For boards using external VREF, that value should be in the tsc210x chip platform data. (And Andrzej, I'm curious why you settled on VREF=1.25V vs 2.50V ... not that it's necessarily an issue, just "why". A comment in the code might be good.)

Somewhat related, I think the TSC setup code should likely hold off until it can fetch calibration data from EEPROM or somesuch ... temperature readings are not all that useful until that data is available. Alternatively, do like I did in ads7846: punt it all to userspace, just provide the raw milliVolt readings and expect someone else to compute temperature.

I only did really basic touchscreen testing, to verify that data came out of /dev/input/event1. Not to check that it was "good" data. I suspect there's some work yet to be done there.

- Dave

#9 lore raw

Hi, sorry for late reply, I'm just catching up with email now.

Quoted 5 lines · David Brownell

Following this will be several patches, two related to this driver:

- H4 board support, using TSC2101 (not TSC2102)
- A biggish tsc210x cleanup patch, with some bugfixes

Thanks for this work.

Quoted 6 lines

For boards using external VREF, that value should be in the tsc210x chip platform data. (And Andrzej, I'm curious why you settled on VREF=1.25V vs 2.50V ... not that it's necessarily an issue, just "why". A comment in the code might be good.)

Oh, I'm afraid I left it to be made configurable by the first person who needs VREF of 2.5V, out of laziness. I settled on 1.25V specifically because that's what PalmOS (the OS that ships with Palm Tungsten E) uses. The device is a consumer PDA and I have no schematics or even multimeter access to the chips, and likely I wouldn't know how to use it if I had.

Quoted 8 lines

Somewhat related, I think the TSC setup code should likely hold off until it can fetch calibration data from EEPROM or somesuch ... temperature readings are not all that useful until that data is available. Alternatively, do like I did in ads7846: punt it all to userspace, just provide the raw milliVolt readings and expect someone else to compute temperature.

The board setup code can defer the TSC setup by registering the tsc210x device only after all information is available to fill in the pdata struct.

Regards

#10 lore raw

PATCH 1/1 tsc210x cleanup

In reply to Tony Lindgren

This is mostly cleanup of the tsc210x patch, but some bugs were fixed so now it works on tsc2101 too. Also, a few issues are now noted in the code:

Tool-reported:
- Address checkpatch.pl issues in the original patch
- And also "sparse" issues

Previously wrong:
- Cope with CONFIG_SOUND_MODULE
- Register accessor routines will now return error codes
- ... many callers now abort cleanly after errors
- Don't depend on seeing only a rev #1 tsc2102 chip!
- Add missing EXPORT_SYMBOL declarations

Style issues:
- BUG_ON() is strongly to be avoided
- So are macros that capture variables
- And needless casting from void pointers
- And type punning
- Use dev_*() for messaging where practical
- Use u16 not uint16_t, etc
- Various other whitespace issues
- Avoid __FUNCTION__
- Single-lines for file-top comments; no whole paths

Object code size and Other cleanup:
- Compile most strings out unless -DDEBUG is configured (saving space)
- Move some code into exit sections (then it may well vanish, saving space)
- Add some header comments

Open issues:
- Hwmon needs to know VREF and the chip type, and to scale its values
- Upstream push should exclude audio until some version is working
- Audio will needs to export symbols to modules, too
- Lots of the I/O calls (especially audio) still don't handle errors
- How could board init code get board-specific temp calibration data?

Also the Kconfig is more open-ended; tsc210x might in the future include the tsc2100 and tsc2111, it doesn't need to be limited to tsc2101 and tsc2102.

---
 drivers/hwmon/Kconfig                  |    4 
 drivers/hwmon/tsc210x_sensors.c        |  140 ++++++++----
 drivers/input/touchscreen/Kconfig      |    4 
 drivers/input/touchscreen/tsc210x_ts.c |   65 +++--
 drivers/spi/Kconfig                    |   13 -
 drivers/spi/tsc210x.c                  |  366 +++++++++++++++++++--------------
 include/linux/spi/tsc210x.h            |   33 +-
 7 files changed, 381 insertions(+), 244 deletions(-)
drivers/hwmon/Kconfig +2 -2
@@ -685,11 +685,11 @@ config SENSORS_APPLESMC
 	  the awesome power of applesmc.
 
 config SENSORS_TSC210X
-	tristate "TI TSC2101/2102 battery & temperature sensors"
+	tristate "TI TSC210x battery & temperature sensors"
 	depends on HWMON && SPI_MASTER
 	select SPI_TSC210X
 	help
-	  Say Y if your board has a TSC210X chip and you want to
+	  Say Y if your board has a TSC210x chip and you want to
 	  have its battery state, auxiliary input and/or temperature
 	  sensors exported through hwmon.
 
drivers/hwmon/tsc210x_sensors.c +90 -50

260 lines not on this page · raw message

drivers/input/touchscreen/Kconfig +2 -2
@@ -193,12 +193,12 @@ config TOUCHSCREEN_TSC2102
 	  module will be called tsc2102_ts.
 
 config TOUCHSCREEN_TSC210X
-	tristate "TSC 2101/2102 based touchscreens"
+	tristate "TI TSC210x based touchscreens"
 	depends on SPI_MASTER
 	select SPI_TSC210X
 	help
 	  Say Y here if you have a touchscreen interface using a
-	  TI TSC 210x controller, and your board-specific initialisation
+	  TI TSC210x controller, and your board-specific initialisation
 	  code includes that in its table of SPI devices.
 
 	  If unsure, say N (but it's safe to say "Y").
drivers/input/touchscreen/tsc210x_ts.c +36 -29

127 lines not on this page · raw message

drivers/spi/Kconfig +10 -3
@@ -229,10 +229,17 @@ config SPI_TSC2102
 
 config SPI_TSC210X
 	depends on SPI_MASTER && EXPERIMENTAL
-	tristate "TSC2101/TSC2102 chips support"
+	tristate "TI TSC210x (TSC2101/TSC2102) support"
 	help
-	  Say Y here if you want support for the TSC210x chips.  It
-	  will be needed for the touchscreen driver on some boards.
+	  Say Y here if you want support for the TSC210x chips.  Some
+	  boards use these for touchscreen and audio support.
+
+	  These are members of a family of highly integrated PDA analog
+	  interface circuit.  They include a 12-bit ADC used for battery,
+	  temperature, touchscreen, and other sensors.  They also have
+	  an audio DAC and amplifier, and in some models an audio ADC.
+	  The audio support is highly chip-specific, but most of the
+	  sensor support works the same.
 
 	  Note that the device has to be present in the board's SPI
 	  devices table for this driver to load.  This driver doesn't
drivers/spi/tsc210x.c +221 -145

799 lines not on this page · raw message

include/linux/spi/tsc210x.h +20 -13
@@ -24,15 +24,16 @@
 #define __LINUX_SPI_TSC210X_H
 
 struct apm_power_info;
+
 struct tsc210x_config {
 	int use_internal;	/* Use internal reference voltage */
-	uint32_t monitor;	/* What inputs are relevant */
+	u32 monitor;		/* What inputs are wired on this board */
 	int temp_at25c[2];	/* Thermometer calibration data */
 	void (*apm_report)(struct apm_power_info *info, int battery[]);
 				/* Report status to APM based on battery[] */
 	void *alsa_config;	/* .platform_data for the ALSA device */
-	const char *mclk;	/* Optional: bclk name */
-	const char *bclk;	/* Optional: mclk name */
+	const char *mclk;	/* Optional: mclk name */
+	const char *bclk;	/* Optional: bclk name */
 };
 
 #define TSC_BAT1	(1 << 0)
@@ -45,16 +46,25 @@ struct tsc210x_config {
 #define TSC_VBAT	TSC_BAT1
 
 struct tsc210x_dev;
-extern u16 tsc210x_read_sync(struct tsc210x_dev *dev, int page, u8 address);
-extern void tsc210x_reads_sync(struct tsc210x_dev *dev, int page,
+
+/* Drivers for tsc210x components like touchscreen, sensor, and audio
+ * are packaged as platform drivers which can issue synchronous register
+ * acceses, and may also register a callback to process their particular
+ * type of data when that data is automatically sampled.  The platform
+ * device is a child of the TSC spi device.
+ */
+
+extern int tsc210x_read_sync(struct tsc210x_dev *dev, int page, u8 address);
+extern int tsc210x_reads_sync(struct tsc210x_dev *dev, int page,
 		u8 startaddress, u16 *data, int numregs);
-extern void tsc210x_write_sync(struct tsc210x_dev *dev, int page,
+extern int tsc210x_write_sync(struct tsc210x_dev *dev, int page,
 		u8 address, u16 data);
 
 typedef void (*tsc210x_touch_t)(void *context, int touching);
 typedef void (*tsc210x_coords_t)(void *context, int x, int y, int z1, int z2);
 typedef void (*tsc210x_ports_t)(void *context, int bat[], int aux[]);
 typedef void (*tsc210x_temp_t)(void *context, int temp);
+
 extern int tsc210x_touch_cb(struct device *dev,
 		tsc210x_touch_t handler, void *context);
 extern int tsc210x_coords_cb(struct device *dev,
@@ -66,13 +76,10 @@ extern int tsc210x_temp1_cb(struct devic
 extern int tsc210x_temp2_cb(struct device *dev,
 		tsc210x_temp_t handler, void *context);
 
-#ifdef CONFIG_SOUND
-extern void tsc210x_set_dac_volume(struct device *dev,
-		uint8_t left_ch, uint8_t right_ch);
-extern void tsc210x_set_dac_mute(struct device *dev,
-		int left_ch, int right_ch);
-extern void tsc210x_get_dac_mute(struct device *dev,
-		int *left_ch, int *right_ch);
+#if defined(CONFIG_SOUND) || defined(CONFIG_SOUND_MODULE)
+extern void tsc210x_set_dac_volume(struct device *dev, u8 left, u8 right);
+extern void tsc210x_set_dac_mute(struct device *dev, int left, int right);
+extern void tsc210x_get_dac_mute(struct device *dev, int *left, int *right);
 extern void tsc210x_dac_power(struct device *dev, int on);
 extern int tsc210x_set_rate(struct device *dev, int rate);
 extern void tsc210x_set_i2s_master(struct device *dev, int state);
maintainer
#11 lore raw

Re: [patch 2.6.23-rc2-omap1] tsc210x cleanup

Quoted 37 lines · David Brownell

This is mostly cleanup of the tsc210x patch, but some bugs were fixed so now it works on tsc2101 too. Also, a few issues are now noted in the code:

Tool-reported:
- Address checkpatch.pl issues in the original patch
- And also "sparse" issues

Previously wrong:
- Cope with CONFIG_SOUND_MODULE
- Register accessor routines will now return error codes
- ... many callers now abort cleanly after errors
- Don't depend on seeing only a rev #1 tsc2102 chip!
- Add missing EXPORT_SYMBOL declarations

Style issues:
- BUG_ON() is strongly to be avoided
- So are macros that capture variables
- And needless casting from void pointers
- And type punning
- Use dev_*() for messaging where practical
- Use u16 not uint16_t, etc
- Various other whitespace issues
- Avoid __FUNCTION__
- Single-lines for file-top comments; no whole paths

Object code size and Other cleanup:
- Compile most strings out unless -DDEBUG is configured (saving space)
- Move some code into exit sections (then it may well vanish, saving space)
- Add some header comments

Open issues:
- Hwmon needs to know VREF and the chip type, and to scale its values
- Upstream push should exclude audio until some version is working
- Audio will needs to export symbols to modules, too
- Lots of the I/O calls (especially audio) still don't handle errors
- How could board init code get board-specific temp calibration data?

Quoted 2 lines

Also the Kconfig is more open-ended; tsc210x might in the future include the tsc2100 and tsc2111, it doesn't need to be limited to tsc2101 and tsc2102.

Pushing today.

Tony

#12 lore raw

PATCH 1/1 H4 support for tsc210x

In reply to Tony Lindgren

H4 board support now lists its tsc210x touchscreen/sensor/codec chip.

arch/arm/mach-omap2/board-h4.c +51 -0
@@ -22,6 +22,8 @@
 #include <linux/err.h>
 #include <linux/clk.h>
 #include <linux/i2c.h>
+#include <linux/spi/spi.h>
+#include <linux/spi/tsc210x.h>
 
 #include <asm/hardware.h>
 #include <asm/mach-types.h>
@@ -418,6 +420,33 @@ static struct omap_usb_config h4_usb_con
 #endif
 };
 
+/* ----------------------------------------------------------------------- */
+
+static struct tsc210x_config tsc_platform_data = {
+	.use_internal		= 1,
+	.monitor		= TSC_VBAT | TSC_TEMP,
+	/* REVISIT temp calibration data -- board-specific; from EEPROM? */
+	.mclk			= "sys_clkout",
+};
+
+static struct spi_board_info h4_spi_board_info[] __initdata = {
+	{
+		.modalias	= "tsc2101",
+		.bus_num	= 1,
+		.chip_select	= 0,
+		.mode		= SPI_MODE_1,
+		.irq		= OMAP_GPIO_IRQ(93),
+		.max_speed_hz	= 16000000,
+		.platform_data	= &tsc_platform_data,
+	},
+
+	/* nCS1 -- to lcd board, but unused
+	 * nCS2 -- to WLAN/miniPCI
+	 */
+};
+
+/* ----------------------------------------------------------------------- */
+
 static struct omap_board_config_kernel h4_config[] __initdata = {
 	{ OMAP_TAG_UART,	&h4_uart_config },
 	{ OMAP_TAG_MMC,		&h4_mmc_config },
@@ -550,6 +579,28 @@ static void __init omap_h4_init(void)
 	tusb_evm_setup();
 #endif
 
+	/* defaults seem ok for:
+	 * omap_cfg_reg(U18_24XX_SPI1_SCK);
+	 * omap_cfg_reg(V20_24XX_SPI1_MOSI);
+	 * omap_cfg_reg(T18_24XX_SPI1_MISO);
+	 * omap_cfg_reg(U19_24XX_SPI1_NCS0);
+	 */
+
+	/* TSC2101 */
+	omap_cfg_reg(P20_24XX_GPIO93);
+	gpio_request(93, "tsc_irq");
+	gpio_direction_input(93);
+
+	omap_cfg_reg(W14_24XX_SYS_CLKOUT);	/* mclk */
+	/* defaults seem ok for:
+	 * omap_cfg_reg(Y15_EAC_AC_SCLK);	// bclk
+	 * omap_cfg_reg(R14_EAC_AC_FS);
+	 * omap_cfg_reg(V15_EAC_AC_DOUT);
+	 * omap_cfg_reg(W15_EAC_AC_DIN);
+	 */
+
+	spi_register_board_info(h4_spi_board_info,
+				ARRAY_SIZE(h4_spi_board_info));
 }
 
 static int gpio_exp_init(void)
#13 lore raw

Re: [patch 2.6.23-rc2-omap1] H4 support for tsc210x

Note that the new tsc210x code needs work yet before it's ready to handle an H2, even just for the LCD support ... maybe it's too ambitious to think of getting it upstream in 2.6.23-early.

- Dave

maintainer
#14 lore raw

Re: [patch 2.6.23-rc2-omap1] H4 support for tsc210x

Quoted 3 lines · David Brownell

Note that the new tsc210x code needs work yet before it's ready to handle an H2, even just for the LCD support ... maybe it's too ambitious to think of getting it upstream in 2.6.23-early.

Pushing today anyways.

Tony

#15 lore raw
In reply to Trilok Soni
Quoted 9 lines · Trilok Soni

Hi All,

Quoted 5 lines · andrzej zaborowski

Hi,
here's a proposition of a common driver for TSC 2101 and 2102 based
on the previous 2102 code - the difference between the two chips' registers turns out to be minimal, not considering the audio part. 2101 provides a superset of 2102 functionality for the most part.

Quoted 3 lines

Anybody on list who can review this approach. We need to get this thing sorted out and have alsa-audio ASoC support on 2420 H4 and finally in mainline.

ISTR my first reaction was positive ... but I've had other things ahead of it in my review-and-test queue. They're nearly done.

Quoted 13 lines
Quoted 5 lines

I will appreciate if anyone with a board using a TSC2101 could test how this works for them, and even more if they can fix the parts that possibly don't work. The part that needs to go into the board file is similar to that in arch/arm/mach-omap1/board-palmte.c. Audio is not expected to work, but touchscreen and hwmon parts work for me.

I will try to review this patch, and not sure when I can test it touchscreen part on H4.

Signature · 1 line
--Trilok Soni
#16 lore raw
In reply to andrzej zaborowski

When I built this:

ERROR: "tsc210x_coords_cb" [drivers/input/touchscreen/tsc210x_ts.ko] undefined!
ERROR: "tsc210x_touch_cb" [drivers/input/touchscreen/tsc210x_ts.ko] undefined!
ERROR: "tsc210x_temp2_cb" [drivers/hwmon/tsc210x_sensors.ko] undefined!
ERROR: "tsc210x_temp1_cb" [drivers/hwmon/tsc210x_sensors.ko] undefined!
ERROR: "tsc210x_ports_cb" [drivers/hwmon/tsc210x_sensors.ko] undefined!

with

CONFIG_TOUCHSCREEN_TSC210X=m
CONFIG_SPI_TSC210X=m
CONFIG_SENSORS_TSC210X=m

Same with SPI_TSC210X=y ... problem went away when everything was statically linked.