
Forlinx OKMX8MP Linux 5.4.70 Porting Guide for Resistive Touchscreen Controller TSC2007
This document provides a step-by-step guide for porting and calibrating the TSC2007 resistive touchscreen controller on the Forlinx OKMX8MP-C development board running Linux kernel 5.4.70.
- Purpose: Help developers enable and configure the TSC2007 driver so that resistive touchscreens can work properly on the OKMX8MP platform.
- Scope: Applicable to Forlinx OKMX8MP boards with Linux 5.4.70 SDK.
- Prerequisites: A working Linux build environment, basic knowledge of device tree modification, and hardware equipped with a TSC2007-based resistive touchscreen.
The TSC2007 is a low-power resistive touchscreen controller launched by Texas Instruments (TI). It adopts a 4-wire interface, integrates a 12-bit Analog-to-Digital Converter (ADC), and features an I²C communication interface, supporting a wide voltage range from 1.2V to 3.6V.
1. Porting TSC2007 to the Kernel
Modify the Device Tree.
1.1 Device Tree Path:
forlinx@ubuntu: ~/work/$ vi OK8MP-linux-sdk/OK8MP-linux-kernel/arch/arm64/boot/dts/freescale/OK8MP-C.dts
Add the TSC2007 node under the i2c3 node:
[…] &i2c3 { clock-frequency =; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_i2c3>; status = "okay"; touchscreen: tsc2007@48 { compatible = "ti,tsc2007"; reg =; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_i2c4_gt928_io>; interrupt-parent = <&gpio1>; interrupts =; gpios = <&gpio1 0 GPIO_ACTIVE_LOW>; ti,x-plate-ohms =; linux,wakeup; status = "okay"; }; fusb302: typec-portc@22 { compatible = "fcs,fusb302"; reg =; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_typec>; […]
Note: The pins used here are those of the capacitive touchscreen GT928. In practice, the actual pins should be adapted according to the reserved pins on the carrier board.
1.2 Modify OK8MP-C_defconfig to include the TSC2007 driver in the build
If the Linux 5.4.70 kernel already contains the related driver, you only need to enable it in the configuration file and build it into the kernel.
Configuration file path:
forlinx@ubuntu: ~/work/$ vi OK8MP-linux-sdk/OK8MP-linux-kernel/arch/arm64/configs/OK8MP-C_defconfig
Add the following configurations:
CONFIG_TOUCHSCREEN_TSC2007=y CONFIG_TOUCHSCREEN_TSC2007_IIO=y
1.3 Compile the source code and flash the board with the new image
2. Touchscreen Calibration
Note:
Sections 2.1 and 2.2 describe two different calibration methods.
2.1: After adding the driver in the source code and flashing, calibration is performed directly on the development board.
2.2: Calibration is added to the root filesystem source, and then flashed together with the image.
Either method can be used. If one does not work, try the other.
2.1 Resistive Touchscreen Calibration
2.1.1 Add Weston calibration support and reboot the board
Configuration file path:
root@OK8MP:~# vi /etc/xdg/weston/weston.ini
Append the following content at the end of the file:
[…] [launcher] icon=/usr/share/weston/terminal.png path=/usr/bin/weston-terminal [libinput] touchscreen_calibrator=true
2.1.2 Run the calibration command in the terminal
root@OK8MP:~# weston-touch-calibrator "DPI-1" --debug -v
Note: DPI-1 is the node seen from the modetest command. For example, an LVDS screen would be shown as "LVDS-1".
The output is as follows:
could not load cursor 'dnd-move' could not load cursor 'dnd-copy' could not load cursor 'dnd-none' Configure calibrator window to size 800x480 Down[0] (0.156738, 0.210938) Finish[0] Conv[0] (0.150000, 0.100000) Down[1] (0.814209, 0.223633) Finish[1] Conv[1] (0.850000, 0.129167) Down[2] (0.202148, 0.802246) Finish[2] Conv[2] (0.200000, 0.800000) Down[3] (0.661865, 0.752197) Finish[3] got all touches Conv[3] (0.700000, 0.750000) calibration test error: -0.010711, 0.000734 Calibration values: 1.064632 0.002799 -0.017459 0.021535 1.182161 -0.152738
2.1.3 Copy the calibration results to the calibration file
Copy:1.064632 0.002799 -0.017459 0.021535 1.182161 -0.152738
Calibration file path:
/etc/udev/rules.d/ws-calibrate.rules
(This file does not exist by default and needs to be created.)
root@OK8MP:~# vi /etc/udev/rules.d/ws-calibrate.rule
Insert the following content into the file:
SUBSYSTEM=="input", ATTRS{name}=="tsc2007", ENV{LIBINPUT_CALIBRATION_MATRIX}="1.064632 0.002799 -0.017459 0.021535 1.182161 -0.152738", ENV{ID_INPUT_KEY}="1"
Note: Use the evtest tool to check the touchscreen input node, then copy the correct ATTRS{name} value here.
2.1.4 Save and reboot
root@OK8MP:~# sync root@OK8MP:~# reboot // Either command reboot or hardware power cycle works
2.2 Post-flash Calibration at Startup
2.2.1 Create the cal.sh script under: /OK8MP-linux-sdk/OK8MP-linux-fs/rootfs/etc
forlinx@ubuntu:~/work/$ cd OK8MP-linux-sdk/OK8MP-linux-fs/rootfs/etc/ forlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-fs/rootfs/etc/$ vi cal.sh
The script is:
#!/bin/sh sleep 1 for sh in /etc/profile.d/*.sh ; do [ -r "$sh" ] && . "$sh" done CAL_FILE=/etc/udev/rules.d/ws-calibrate.rules SYS_DIR=`weston-touch-calibrator "LVDS-1" | awk -F "\"" '{print $2}'` if [ ! -e /dev/input/event1 ] ; then exit 0 fi if [ -f $CAL_FILE ] ; then exit fi while [ -z "$CAL_VALUES" ] do CAL_VALUES=`weston-touch-calibrator "LVDS-1" -v --debug $SYS_DIR|cut -c21-` echo $CAL_VALUES done echo 'SUBSYSTEM=="input", ATTRS{name}=="tsc2007", ENV{LIBINPUT_CALIBRATION_MATRIX}="'$CAL_VALUES'", ENV{ID_INPUT_KEY}="1"' > $CAL_FILE sleep 1 echo sync sync
Note: The blue-highlighted part refers to the screen node, which must match the actual display node being used.
2.2.2 Create the cal.service service under:
OK8MP-linux-sdk/OK8MP-linux-fs/rootfs/lib/systemd/system
forlinx@ubuntu:~/work/$ cd OK8MP-linux-sdk/OK8MP-linux-fs/rootfs/lib/systemd/system/ forlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-fs/rootfs/lib/systemd/system/$ vi cal.service
Service:
[Unit] Description=weston-touch-calibrator After=weston.service Requires=weston.service Before=graphical.target [Service] Type=forking ExecStart=/etc/cal.sh Restart=no TimeoutSec=5min IgnoreSIGPIPE=no KillMode=process GuessMainPID=no RemainAfterExit=yes [Install] WantedBy=multi-user.target
2.2.3 Enable the service
Create a symbolic link to set it to start automatically at boot, then go to the directory:
OK8MP-linux-fs/rootfs/lib/systemd/system/multi-user.target.wants
forlinx@ubuntu:~/work/$ cd OK8MP-linux-sdk/OK8MP-linux-fs/rootfs/lib/systemd/system/multi-user.target.wants forlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-fs/rootfs/lib/systemd/system/multi-user.target.wants/$ ln -s ../cal.service ./
2.2.4 After completing the above operations, perform a full build and flash the board using the newly generated complete image.