Wolfson Open Source eNews

Using AUXADC with the WM97xx touchscreen drivers

The touchscreen interface provided by some WM97xx devices use an ADC which is also available as an auxiliary ADC, frequently used for battery monitoring. When the touchscreen is in use access to the auxiliary ADC must be coordinated with the touchscreen driver. This article outlines the mechanism provided for this by the standard touchscreen drivers.

Client device

When the touchscreen driver is registered it registers a platform device called wm97xx-battery, setting the platform data for the device to a pointer to a struct wm97xx. This pointer can be passed to a function wm97xx_read_aux_adc():

   #define TS_COMP1                0x0
   #define TS_COMP2                0x1
   #define TS_BMON                 0x2
   #define TS_WIPER                0x3

   int wm97xx_read_aux_adc(struct wm97xx *wm, u16 adcsel);

which returns the current ADC reading.

Access is also provided to the GPIO lines of the chip - see linux/wm97xx.h and linux/input/touchscreen/wm97xx-ts.c for details of these features. In new designs it may be more convenient to use CPU GPIOs due to more rapid and flexible access.

A minimal example of a driver showing how to set this up is included at the end of this article.

Integrating with other drivers

If it is not possible to use the wm97xx-battery device alone (eg, if you wish to instantiate your from some other bit of hardware it also interfaces to) the recommended approach is to provide a trivial wm97xx-battery driver which exports an interface allowing your real driver to obtain the object (eg, by storing it in a static).

If access to information from the auxiliary ADC is required at all times, even when the touchscreen driver is not available, then the approach taken by the battery driver used by the tosa platform is probably the best one available. The patches for this are not currently integrated but can be found in the OpenEmbedded codebase. This is not recommended and if possible the system should be redesigned to remove this requirement.

A minimal battery driver

This driver simply prints out the reading from the battery monitor input when probed, demonstrating the interface provided by the WM97xx touchscreen driver.

#include <linux/wm97xx.h>

static int mainstone_wm97xx_probe(struct platform_device *pdev)
	struct wm97xx *wm = platform_get_drvdata(pdev);

	printk(KERN_INFO "AUX ADC reading: %d\n",
		wm97xx_read_aux_adc(wm, TS_BMON));

	return 0;

static int mainstone_wm97xx_remove(struct platform_device *pdev)
	struct wm97xx *wm = platform_get_drvdata(pdev);
	return 0;

static struct platform_driver sample_wm97xx_driver = {
	.probe = sample_wm97xx_probe,
	.remove = sample_wm97xx_remove,
	.driver = {
		.name = "wm97xx-battery",

static int __init sample_wm97xx_init(void)
	return platform_driver_register(&sample_wm97xx_driver);

static void __exit sample_wm97xx_exit(void)

Copyright Wolfson Microelectronics 2006-8