Touchscreen tsc2046 (ads7846): ts_calibrate and SPI issues

1,145 views
Skip to first unread message

Willem

unread,
Apr 20, 2011, 5:18:01 PM4/20/11
to Beagle Board, was...@hotmail.com
Hi,

I am trying to get an lcd adapter board's touch screen controller
(tsc2046)
working on a xM, Angstrom Linux kernel 2.6.37+. When I run
ts_calibrate, I get the 'selected device is not a
touchscreen I understand' output and 'top' shows X doing 98%
processing as soon
as I tap the touchscreen in X. I use SPI4 and GPIO 157 for the pen
interrupt and the ads7846 kernel driver.

A couple of issues I have noticed (may or may not be related to
problem):

1. XOrg.0.0.log does not show /dev/input/event1 set up for the
touchscreen, but it does show all the other input device events such
as /dev/input/event3 for the mouse and keyboard etc.

2. I have added a line of debug code to the ads7846 kernel driver to
output the
result when a reading is requested. When I tap the touchscreen, I do
not see
this debug output on the serial kernel debug output.

3. If I cat /dev/input/event1 and then tap the touchscreen, I do get
binary output, but values are rubbish.

4. If I cat /sys/devices/platform/omap2_mcspi.4/spi4.0/in0_input
it hits the ads7846 kernel debug output e.g:
[ 1669.133270] ads7846 spi4.0: RESULT:0x000006AF
1044
which looks like a sane value.

5. So it looks as if things are working fine at the kernel driver
level, but not when
a user application is trying to use the touchscreen.

6. I am not sure if the OMAP3_MUX settings are correct. From the
datasheet for the tsc2046, the data is clocked when CS0 is pulled low.

7. I am not sure if I need to turn on the voltage regulator supply for
spi4.

8. A bit puzzling is that I do not get a Hz reading on the multimeter
for the SPI4 CLK line, and only a tiny voltage (52mV) when the touch
screen is tapped.

I am bit stumped as to what to try next.

ts_calibrate: (top shows X processing 98%)
=========
xres = 480, yres = 272
selected device is not a touchscreen I understand
Took 2 samples...
Top left : X = -548100188 Y = -548100069
Took 2 samples...
Top right : X = -548100188 Y = -548100069
Took 2 samples...
Bot right : X = -548100188 Y = -548100069
Took 2 samples...
Bot left : X = -548100188 Y = -548100069
Took 2 samples...
Center : X = -548100188 Y = -548100069
-2.721680 -2.013672 2.012695
1.125000 -1.132812 1.125000
Calibration constants: -178368 -131968 131904 73728 -74240 73728 65536

tslibs installed:
=================
libts-1.0-0 - 1.0-r28.6.6
tslib-calibrate - 1.0-r28.6.6
tslib-conf - 1.0-r28.6.6
tslib-tests - 1.0-r28.6.6
xf86-input-tslib - 0.0.6-r15.1.6
xf86-input-tslib-doc - 0.0.6-r15.1.6

Environment vars:
=================
TSLIB_CONFFILE=/etc/ts.conf
TSLIB_CALIBFILE=/etc/pointercal
TSLIB_CONSOLEDEVICE=none
TSLIB_FBDEVICE=/dev/fb0
TSLIB_TSDEVICE=/dev/input/event1
TSLIB_PLUGINDIR=/usr/lib/ts

/etc/ts.conf:
module_raw input is uncommented

# ls /usr/lib/ts/
arctic2.so corgi.so h3600.so linear.so mk712.so
ucb1x00.so
collie.so dejitter.so input.so linear_h2200.so pthres.so
variance.so

/var/log/Xorg.0.0.log:
======================
(II) LoadModule: "tslib"
(II) Loading /usr/lib/xorg/modules/input/tslib_drv.so
(II) Module tslib: vendor="X.Org Foundation"
compiled for 1.7.4, module version = 0.0.1
Module class: X.Org XInput Driver
ABI class: X.Org XInput driver, version 7.0
...
...
(II) config/hal: Adding input device ADS7846 Touchscreen
(**) ADS7846 Touchscreen: always reports core events
(II) XINPUT: Adding extended input device "ADS7846 Touchscreen" (type:
TOUCHSCREEN)
xf86TslibControlProc
xf86TslibControlProc

xorg.conf:
==========
Section "InputDevice"
Identifier "touchscreen0"
Driver "tslib"
Option "Device" "/dev/input/event1"
Option "ScreenNumber" "0"
Option "Width" "480"
Option "Height" "272"
Option "Rotate" "NONE"
Option "EmulateRightButton" "0"
EndSection

Section "Module"
Load "tslib"
....
EndSection

cat /dev/input/event1 produces binary output when touchscreen is
tapped but the values seem rubbish:
0000000: 803e ae4d 2601 0900 0100 4a01 0100 0000
0000010: 803e ae4d 4501 0900 0300 0000 2009 0000
0000020: 803e ae4d 4501 0900 0300 0100 0500 0000
0000030: 803e ae4d 4501 0900 0300 1800 ea00 0000
0000040: 803e ae4d 4501 0900 0000 0000 0000 0000
0000050: 803e ae4d e3f5 0900 0300 0000 3709 0000
0000060: 803e ae4d e3f5 0900 0300 1800 cb00 0000
0000070: 803e ae4d e3f5 0900 0000 0000 0000 0000
0000080: 803e ae4d a0b4 0c00 0300 0000 4009 0000
0000090: 803e ae4d a0b4 0c00 0300 0100 0400 0000
00000a0: 803e ae4d a0b4 0c00 0300 1800 ea00 0000
00000b0: 803e ae4d bfb4 0c00 0000 0000 0000 0000
00000c0: 803e ae4d 1374 0d00 0100 4a01 0000 0000
00000d0: 803e ae4d 1374 0d00 0300 1800 0000 0000
00000e0: 803e ae4d 1374 0d00 0000 0000 0000 0000

cat /proc/interrupts number changes for GPIO ads7846 when touchscreen
is tapped

cat /proc/bus/input/devices:
I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="ADS7846 Touchscreen"
P: Phys=spi4.0/input0
S: Sysfs=/devices/platform/omap2_mcspi.4/spi4.0/input/input1
U: Uniq=
H: Handlers=mouse0 event1
B: EV=b
B: KEY=400 0 0 0 0 0 0 0 0 0 0
B: ABS=1000003

kernel debug output:
====================
Debug line "RESULT" added:
[ 3.514739] ads7846 spi4.0: touchscreen, irq 317
[ 3.519866] ads7846 spi4.0: RESULT:0x00000560
[ 3.524810] input: ADS7846 Touchscreen as /devices/platform/
omap2_mcspi.4/spi
4.0/input/input1

diff --git a/arch/arm/mach-omap2/board-omap3beagle.c b/arch/arm/mach-
omap2/board-omap3beagle.c
index d23b499..348633b 100644
--- a/arch/arm/mach-omap2/board-omap3beagle.c
+++ b/arch/arm/mach-omap2/board-omap3beagle.c
@@ -48,12 +48,17 @@
#include <plat/usb.h>
#include <plat/omap_device.h>

+#include <plat/mcspi.h>
+#include <linux/spi/spi.h>
+#include <linux/spi/ads7846.h>
+
#include "mux.h"
#include "hsmmc.h"
#include "timer-gp.h"
#include "pm.h"

#define NAND_BLOCK_SIZE SZ_128K
+#define OMAP3_BEAGLE_TS_GPIO 157

/*
* OMAP3 Beagle revision
@@ -400,6 +423,10 @@ static struct regulator_consumer_supply
beagle_vdac_supply =
static struct regulator_consumer_supply beagle_vdvi_supply =
REGULATOR_SUPPLY("vdds_dsi", "omapdss");

+/* ads7846 on SPI */
+static struct regulator_consumer_supply beagle_vio_supply =
+ REGULATOR_SUPPLY("vcc", "spi4.0");
+
static void __init beagle_display_init(void)
{
int r;
@@ -608,6 +647,21 @@ static struct regulator_init_data beagle_vpll2 =
{
.consumer_supplies = &beagle_vdvi_supply,
};
+/* VAUX4 for ads7846 and nubs */
+static struct regulator_init_data beagle_vio = {
+ .constraints = {
+ .min_uV = 1800000,
+ .max_uV = 1800000,
+ .apply_uV = true,
+ .valid_modes_mask = REGULATOR_MODE_NORMAL
+ | REGULATOR_MODE_STANDBY,
+ .valid_ops_mask = REGULATOR_CHANGE_MODE
+ | REGULATOR_CHANGE_STATUS,
+ },
+ .num_consumer_supplies = 1,
+ .consumer_supplies = &beagle_vio_supply,
+};
+
static struct twl4030_usb_data beagle_usb_data = {
.usb_mode = T2_USB_MODE_ULPI,
};
@@ -638,6 +692,7 @@ static struct twl4030_platform_data beagle_twldata
= {
.vsim = &beagle_vsim,
.vdac = &beagle_vdac,
.vpll2 = &beagle_vpll2,
+ .vio = &beagle_vio,
};

static struct i2c_board_info __initdata beagle_i2c1_boardinfo[] = {
@@ -796,6 +851,13 @@ static const struct ehci_hcd_omap_platform_data
ehci_pdata __initconst = {

#ifdef CONFIG_OMAP_MUX
static struct omap_board_mux board_mux[] __initdata = {
+ /* McSPI4 */
+ OMAP3_MUX(MCBSP1_CLKR, OMAP_MUX_MODE1 | OMAP_PIN_INPUT), /* p20
McSPI4_CLK */
+ OMAP3_MUX(MCBSP1_DX, OMAP_MUX_MODE1 | OMAP_PIN_OUTPUT), /* p12
McSPI4_SIMO */
+ OMAP3_MUX(MCBSP1_DR, OMAP_MUX_MODE1 | OMAP_PIN_INPUT), /* p18
McSPI4_SOMI */
+ OMAP3_MUX(MCBSP1_FSX, OMAP_MUX_MODE1 |OMAP_PIN_OUTPUT), /* p16
McSPI4_CS0 */
+ /* PENDOWN GPIO */
+ OMAP3_MUX(MCBSP1_FSR, OMAP_MUX_MODE4 | OMAP_PIN_INPUT), /* p22
GPIO_157 */
{ .reg_offset = OMAP_MUX_TERMINATOR },
}; #endif
@@ -812,6 +874,55 @@ static struct omap_musb_board_data
musb_board_data = {
.power = 100,
};

+static void __init ads7846_init(void)
+{
+ int gpio = OMAP3_BEAGLE_TS_GPIO;
+ int ret;
+
+ ret = gpio_request(gpio, "ads7846_pen_down");
+ if (ret < 0) {
+ printk(KERN_ERR "Failed to request GPIO %d for "
+ "ads7846 pen down IRQ\n", gpio);
+ return;
+ }
+
+ gpio_direction_input(gpio);
+}
+
+static int ads7846_get_pendown_state(void)
+{
+ return !gpio_get_value(OMAP3_BEAGLE_TS_GPIO);
+}
+
+static struct ads7846_platform_data ads7846_config = {
+ .x_max = 0x0fff,
+ .y_max = 0x0fff,
+ .x_plate_ohms = 180,
+ .pressure_max = 255,
+ .debounce_max = 10,
+ .debounce_tol = 5,
+ .debounce_rep = 1,
+ .get_pendown_state = ads7846_get_pendown_state,
+ .keep_vref_on = 1,
+ .settle_delay_usecs = 150,
+};
+
+static struct omap2_mcspi_device_config ads7846_mcspi_config = {
+ .turbo_mode = 0,
+ .single_channel = 1, /* 0: slave, 1: master */
+};
+

+static struct spi_board_info ads7846_spi_board_info[] __initdata = {
+ {
+ .modalias = "ads7846",
+ .bus_num = 4,
+ .chip_select = 0,
+ .max_speed_hz = 1500000,
+ .controller_data = &ads7846_mcspi_config,
+ .irq = OMAP_GPIO_IRQ(OMAP3_BEAGLE_TS_GPIO),
+ .platform_data = &ads7846_config,
+ }
+};
static int __init expansionboard_setup(char *str)
{
if (!str)
@@ -942,6 +1055,10 @@ static void __init omap3_beagle_init(void)
platform_device_register(&omap_vwlan_device);
}

+ spi_register_board_info(ads7846_spi_board_info,
+ ARRAY_SIZE(ads7846_spi_board_info));
+ ads7846_init();
+
usb_musb_init(&musb_board_data);
usb_ehci_init(&ehci_pdata);
omap3beagle_flash_init();



diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/
touchscreen/ads7846.c
index c775e38..ba1c9e6 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -362,6 +362,9 @@ static int ads7846_read12_ser(struct device *dev,
unsigned command)
}

kfree(req);
+
+ dev_err(&spi->dev, "RESULT:0x%08X\n", status);

+
return status;
}

Any suggestions would be appreciated,

Thanks
Willem

Willem

unread,
Apr 20, 2011, 11:52:36 PM4/20/11
to Beagle Board
I noticed I am not seeing this in the kernel debug ouput anymore:

[ 0.018157] omap2_mcspi omap2_mcspi.1: registered master spi1
[ 0.018371] omap2_mcspi omap2_mcspi.2: registered master spi2
[ 0.018585] omap2_mcspi omap2_mcspi.3: registered master spi3
[ 0.018798] omap2_mcspi omap2_mcspi.4: registered master spi4
[ 0.018859] spi spi4.0: setup: speed 1500000, sample leading edge,
clk normal
[ 0.018890] spi spi4.0: setup mode 0, 8 bits/w, 1500000 Hz max -->
0
[ 0.019042] omap2_mcspi omap2_mcspi.4: registered child spi4.0
[ 0.019592] usbcore: registered new interface driver usbfs

which originates from drivers/spi/spi.c:

/* register the device, then userspace will see it.
* registration fails if the bus ID is in use.
*/
dev_set_name(&master->dev, "spi%u", master->bus_num);
status = device_add(&master->dev);
if (status < 0)
goto done;
dev_dbg(dev, "registered master %s%s\n", dev_name(&master->dev),
dynamic ? " (dynamic)" : "");


Not sure why the registration fails (bus ID is in use?)
Thanks
Willem
Reply all
Reply to author
Forward
0 new messages