Sonoff NSPanel Pro 120: Touch Panel

Sonoff NSPanel Pro 120: Touch Panel

In this post, let's get the touchscreen working. But first, let's review the extracted .dts file to see what devices are connected to the i2c1 bus.

i2c @ff190000 {
    compatible = "rockchip,rk3399-i2c";
    reg = < 0x00 0xff190000 0x00 0x1000 > ;
    clocks = < 0x02 0x1e 0x02 0x14f > ;
    clock - names = "i2c\0pclk";
    interrupts = < 0x00 0x08 0x04 > ;
    pinctrl - names = "default";
    pinctrl - 0 = < 0x69 > ;
    #address - cells = < 0x01 > ;
    #size - cells = < 0x00 > ;
    status = "okay";
    clock - frequency = < 0x61a80 > ;
    phandle = < 0x100 > ;

    chsc5xxx @2e {
        compatible = "chipsemi,chsc_cap_touch";
        reg = < 0x2e > ;
        chipsemi, int - gpio = < 0x5e 0x0d 0x08 > ;
        chipsemi, rst - gpio = < 0x5e 0x0c 0x00 > ;
        status = "okay";
    };

    smatek @3C {
        compatible = "smatek,tp";
        status = "okay";
        reg = < 0x3c > ;
        phandle = < 0x101 > ;
    };
};

The first node, chsc5xxx@2e, is definitely the Chipsemi CHSC5448A capacitive touch panel controller (with i2c address 0x2E). The other node, smatek@3C, could initially be assumed to be a touch panel as well, but it turned out not to be. I’ll write a separate article to examine the existing driver for the Smatek device and reverse-engineer kernel for its functionality.

Unfortunately, I failed to find the full datasheet. What’s available online is essentially a brief version that lacks even the I2C register maps, making it impossible to write a kernel driver. This is far from ideal, and it leaves me wondering why manufacturers keep their datasheets secret for their products. Anyway, I was fortunate enough to have a good friend from China who managed to obtain the kernel drivers for this chip directly from the manufacturer. I will share them at the end of this article, so please be patient.

The chct_touch kernel driver structure:

We see the Kconfig and Makefile files, which we need to link to our kernel. Let’s place the touch panel kernel driver in kernel/drivers/input/touchscreen/chct_touch. The Kconfig file is a text file that defines configuration options, which you can configure through menuconfig. To link the Kconfig file, simply add the folowing line to the higher-level Kconfig file (this is part of a chained structure and will include it as an option):

source "drivers/input/touchscreen/chct_touch/Kconfig"

Run make menuconfig and let’s find our new options under Device Drivers -> Input Device Support -> Touchscreens .

Nice! It should be enabled by default, so let’s just save the configuration to the .config file, which will then be used to compile the kernel. Select Save and exit.

The only thing left is to include the chct_touch folder in the upper-level Makefile so that it will be included in the compilation. Simply add the following line to the upper-level Makefile:

obj-$(CONFIG_TOUCHSCREEN_CHCT_TOUCH) += chct_touch/

So, in order for the kernel to recognize that it should link the kernel driver with the DTS node, let’s add it to the DTS. Note that the INT and RST pin values were taken from the extracted .dts file in the original firmware. Additionally, I have disabled other I2C nodes since we don’t have the corresponding hardware.

&i2c1 {
	status = "okay";
	chsc5xxx@2e {
		compatible = "chipsemi,chsc_cap_touch";
		reg = <0x2e>;
		chipsemi,int-gpio = <&gpio0 RK_PB5 IRQ_TYPE_LEVEL_LOW>;
		chipsemi,rst-gpio = <&gpio0 RK_PB4 GPIO_ACTIVE_HIGH>;
		status = "okay";
	};

	sensor@f {
		status = "disabled";
	};

	gt1x@14 {
		status = "disabled";
	};

	sensor@4c {
		status = "disabled";
	};
};

I believe we are ready to compile the updated kernel and upload it to the panel. I encountered a few errors during the compilation of the driver, but I fixed them, so the driver is now fully compatible with the 5.10 kernel. You should see the CHSC logs in the boot kernel log:

💽
The Touch Panel Kernel driver for CHSC5XXX could be found here

Great! We already have the display and touchscreen up and running. Let’s focus on Wi-Fi and Bluetooth functionality in the next articles.