[SOLVED] Enable Focaltech touchscreen FT5X06

Post Reply
hunterhu
Posts: 24
Joined: Wed Nov 09, 2016 3:41 am
languages_spoken: english
ODROIDs: C0, C2, XU4
Has thanked: 1 time
Been thanked: 2 times
Contact:

[SOLVED] Enable Focaltech touchscreen FT5X06

Post by hunterhu » Tue May 12, 2020 12:35 am

Hi,

We are in the final phase of development of using c0 as our new platform. We are using FT5216 ts chip and plan to continue use it. However I have some difficulties figuring out the support for this chip in c0's kernel source odroidc-3.10.y.

It seems the Focaltech touchscreen support is located here in odroidc-3.10.y menuconfig:

Code: Select all

Device Drivers --> Amlogic Device Drivers --> Input Device Support --> Touchscreens --> FocalTech I2C Capactive touchscreen
It's help says: Say Y here if you want to use the FocalTech 5X06 capacitive panel.

The driver source is located at:

Code: Select all

drivers/amlogic/input/touchscreen/focaltech_5x06.c
According to its header ft5x06_ts.h, it support varieties of Focaltech ts chips including FT5X06 (ft5206, ft5306, ft5406), so I assume I am looking at the right driver.

Where I am stuck at is:

After I enabled the driver, the focaltech_5x06.c get built and kernel dmesg does show the init function and the driver get registered, however it is never been probed.

Code: Select all

 i2c-core: driver [ft5x06] registered
So my immediate thought is that is is missing device tree node configuration, but "it seems the focaltech_5x06.c doesn't support device tree probe with odroidc_3.10.y kernel".

Well if the focaltech_5x06.c doesn't support device tree configuration, how people suppose to use it then? or what do I miss here?

Any insights comments or pointers are greatly appreciated!

Thanks,
Hunter

User avatar
odroid
Site Admin
Posts: 34195
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean, Japanese
ODROIDs: ODROID
Has thanked: 701 times
Been thanked: 625 times
Contact:

Re: Enable Focaltech touchscreen FT5X06

Post by odroid » Tue May 12, 2020 9:51 am

Did you enable "aml_i2c" driver as a built-in module too?
https://wiki.odroid.com/odroid-c1/appli ... i2c_driver

hunterhu
Posts: 24
Joined: Wed Nov 09, 2016 3:41 am
languages_spoken: english
ODROIDs: C0, C2, XU4
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: Enable Focaltech touchscreen FT5X06

Post by hunterhu » Wed May 13, 2020 12:47 am

I did, actually, since the default Hardkernel sx865x.c ts driver is enabled and configured inside device tree node, it is being probed,

Code: Select all

[    7.962670] sx865x 2-0049: sx865x_probe()
[    7.966286]  reg:2620,clearmask=10001,setmask=10001
[    7.966300] reg:2621,clearmask=ff,set pin=98
[    7.966306] reg:2623,clearmask=7,setmask=7
[    7.966317] sx865x 2-0049: swap_xy (1)
[    7.966323] sx865x 2-0049: invert_x (0)
[    7.966334] sx865x 2-0049: invert_y (1)
[    7.966341] sx865x 2-0049: gpio pendown (98)
[    7.966348] sx865x 2-0049: gpio reset (99)
[    7.966354] sx865x 2-0049: gpio irq (96)
[    7.966517] i2c i2c-2: [aml_i2c_xfer] error ret = -5 (-EIO) token 1, master_no(2) 100K addr 0x49
[    7.976107] gpiomem-meson c1108000.gpiomem: Initialised: Registers at 0xc1108000
[    7.980143] i2c i2c-2: [aml_i2c_xfer] error ret = -5 (-EIO) token 1, master_no(2) 100K addr 0x49
[    7.993118] i2c i2c-2: [aml_i2c_xfer] error ret = -5 (-EIO) token 1, master_no(2) 100K addr 0x49
[    8.001677] i2c i2c-2: [aml_i2c_xfer] error ret = -5 (-EIO) token 1, master_no(2) 100K addr 0x49
[    8.011572] i2c i2c-2: [aml_i2c_xfer] error ret = -5 (-EIO) token 1, master_no(2) 100K addr 0x49
[    8.021345] i2c i2c-2: [aml_i2c_xfer] error ret = -5 (-EIO) token 1, master_no(2) 100K addr 0x49
[    8.031175] sx865x: probe of 2-0049 failed with error -5
But since the hardware is not there, probe failed as expected.

This is where I am lost, the ft5x06 driver get the init call

Code: Select all

1441 static int __init ft5x0x_ts_init(void)                                                                               
1442 {
1443 |   printk("==ft5x0x_ts_init==\n");
1444 |   return i2c_add_driver(&ft5x0x_ts_driver);
1445 }
but never reaches its probe call

Code: Select all

1224 static int 
1225 ft5x0x_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
1226 {
1227 |   struct ft5x0x_ts_data *ft5x0x_ts;
1228 |   struct input_dev *input_dev;
1229 |   int err = 0;
1230 |   unsigned char uc_reg_value; 
1231 
1232 |   printk("%s==%s==\n", client->name, __func__);
...
I assume because it doesn't support device tree node probe? if device tree node configuration is required in odroidc_3.10.y for any device is being probed, then this driver is useless? or there is a workaround to hard code the configurations and still use it.

Thanks,
Hunter

User avatar
odroid
Site Admin
Posts: 34195
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean, Japanese
ODROIDs: ODROID
Has thanked: 701 times
Been thanked: 625 times
Contact:

Re: Enable Focaltech touchscreen FT5X06

Post by odroid » Wed May 13, 2020 8:58 am

You might need to remove "sx865x" driver from the device tree to avoid the messages.

Anyway, I have no idea whether the focaltech_5x06 driver in Kernel 3.10 is really working one or not.
If you don't mind, try Armbian OS image with Kernel 5.4. I hope it has a working I2C driver at least.
viewtopic.php?f=114&t=26992

User avatar
tobetter
Posts: 5113
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: X, X2, U2, U3, XU3, C1
Location: Paju, South Korea
Has thanked: 161 times
Been thanked: 509 times
Contact:

Re: Enable Focaltech touchscreen FT5X06

Post by tobetter » Wed May 13, 2020 9:45 am

@hunterhu, I've looked into the driver code focaltech_5x06.c in odroidc-3.10.y branch and I think it's very outdated. It does not support device tree entry for the driver but use platform data which is used before device tree is supported in ARM Linux kernel.

Please refer to the code, g_pdata is a structure that contains the device details, therefore you must add multiple lines of code to give the hardware setup to run the driver. This is one problem. https://github.com/hardkernel/linux/blo ... 06.c#L1248

Another problem is that in order to call probe function, you need to define a device driver information and have to call such as platform_add_register with the structure data I explained abobe to be linked with i2c bus. Then the probe function will be called when i2c bus is initiated.

This is old fashion so I recommending diging the higher version of Linux kernel tree like 4.x or 5.x for focaltech_5x06 and drag it to 3.10 branch and fix the compile issue. Then you would be able to use the device tree.

hunterhu
Posts: 24
Joined: Wed Nov 09, 2016 3:41 am
languages_spoken: english
ODROIDs: C0, C2, XU4
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: Enable Focaltech touchscreen FT5X06

Post by hunterhu » Thu May 14, 2020 4:06 am

Thanks for the pointers and I am actually getting good progress but not there just yet!

I am now using a version of ft5x06.c from this Android version:

https://android.googlesource.com/kernel ... t5x06_ts.c

Getting the ft5x06.c and its header ft5x06.h, minor tweaks to make it compiled successfully in odroidc_3.10.y kernel. It does support device tree configuration, also I found this commit on how to write a device tree node for ft5x06.c driver,

http://visa.lab.asu.edu/gitlab/fstrace/ ... c22336336

Also looking the "ft5x06_parse_dt()" function inside ft5x06.c, they are matching, so far so good.

In the commit, there is an example of configuring ft5x06.c with the Android msm hammerhead-3.4 platform, I quote here:

Code: Select all

Example:
i2c@f9924000 {
ft5x06_ts@38 {
compatible = "focaltech,5x06";
reg = <0x38>;
interrupt-parent = <&msmgpio>;
interrupts = <61 0x2>;
vdd-supply = <&pm8941_l22>;
vcc_i2c-supply = <&pm8941_s3>;
focaltech,reset-gpio = <&msmgpio 60 0x00>;
focaltech,irq-gpio = <&msmgpio 61 0x00>;
focaltech,panel-coords = <0 0 480 800>;
focaltech,display-coords = <0 0 480 800>;
focaltech,button-map= <158 102 139 217>;
focaltech,family-id = <0x0a>;
};
};
Following the example, and based on c0 meson8b_odroidc.dts, I come up with my own device tree node like the following, note that GPIO 97,98 are our chosen interrupt and reset GPIO pins:

Code: Select all

304                 focaltech: ft5x06_ts@38 {                              
305                     compatible = "focaltech,5x06";                     
306                     reg = <0x38>;
307                    
308                     interrupt-parent = <&gpio>;                        
309                     interrupts = <97 0x2>;
310                    
311                     focaltech,reset-gpio = <&gpio 98 0x00>;            
312                     focaltech,irq-gpio = <&gpio 97 0x00>;
313                    
314                     focaltech,panel-coords = <0 0 272 480>;            
315                     focaltech,display-coords = <0 0 272 480>;                                                                                       
316
317                     focaltech,family-id = <0x0a>;                      
318                    
319                     //focaltech,vdd-supply = <>;                       
320                     //focaltech,vcc_i2c-supply = <>;                   
321                 }; 
Note that everything seems obvious for me except two required fields:

focaltech,vdd-supply and focaltech,vcc_i2c-supply.

I have tried this approach since aml_pm is there in meson8b_odroidc.dts,

Code: Select all

focaltech,vdd-supply = <&aml_pm>;  //in order to use &aml_pm here, I added a label for the section of aml_pm
focaltech,vcc_i2c-supply = <&aml_pm>;
In either case, I get the following kernel output, which indicates that the 2 configurations are still failing:

Code: Select all

[    1.792987] input: ft5x06_ts as /devices/i2c-2/2-0038/input/input0
[    1.799034] ft5x06_ts 2-0038: Regulator get failed vdd rc=-19
[    1.804774] ft5x06_ts 2-0038: power init failed
Error code -19 meaning "ENODEV: no such device" according to kernel header include/asm-generic/errno-base.h.

The messages are actually coming from the driver source code here:

drivers/input/touchscreen/ft5x06.c

Code: Select all

73 struct ft5x06_ts_data {                                                  
 74 |   struct i2c_client *client;                                           
 75 |   struct input_dev *input_dev;                                         
 76 |   struct ts_event event;                                               
 77 |   const struct ft5x06_ts_platform_data *pdata;                         
 78 |   struct regulator *vdd;                                                                                                                            
 79 |   struct regulator *vcc_i2c;                                           
 80 #ifdef CONFIG_HAS_EARLYSUSPEND                                           
 81 |   struct early_suspend early_suspend;                                  
 82 #endif                                                                   
 83 };   

Code: Select all

242 static int ft5x06_power_init(struct ft5x06_ts_data *data, bool on)
243 {                                                                                                                    
244 |   int rc;
245 |   if (!on)
246 |   |   goto pwr_deinit;
247 |   data->vdd = regulator_get(&data->client->dev, "vdd");
248 |   if (IS_ERR(data->vdd)) {
249 |   |   rc = PTR_ERR(data->vdd);
250 |   |   dev_err(&data->client->dev,
251 |   |   |   "Regulator get failed vdd rc=%d\n", rc);
252 |   |   return rc;
...
It is not happy about the vdd configuration after returning from regulator_get() call.

So, any ideas how to correctly set up the vdd-supply and vcc_i2c-supply fields in the device tree node on c0 platform?

Thanks for your insight,
Hunter

User avatar
tobetter
Posts: 5113
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: X, X2, U2, U3, XU3, C1
Location: Paju, South Korea
Has thanked: 161 times
Been thanked: 509 times
Contact:

Re: Enable Focaltech touchscreen FT5X06

Post by tobetter » Thu May 14, 2020 4:35 am

Code: Select all

focaltech,vdd-supply = <&aml_pm>;  //in order to use &aml_pm here, I added a label for the section of aml_pm
focaltech,vcc_i2c-supply = <&aml_pm>;
You should remove focaltech,.

hunterhu
Posts: 24
Joined: Wed Nov 09, 2016 3:41 am
languages_spoken: english
ODROIDs: C0, C2, XU4
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: Enable Focaltech touchscreen FT5X06

Post by hunterhu » Thu May 14, 2020 12:07 pm

Thanks tobetter, good catch for the mistake, it did move the issue one step forward.

After removing focaltech, the kernel messages is a bit more friendly, but still we are failing on the two power related configurations,

Code: Select all

319                     vdd-supply = <&aml_pm>;                       
320                    vcc_i2c-supply = <&aml_pm>;

Code: Select all

[    1.793972] input: ft5x06_ts as /devices/i2c-2/2-0038/input/input0
[    1.800026] ft5x06_ts 2-0038: Regulator get failed vdd rc=-517
[    1.805851] ft5x06_ts 2-0038: power init failed
[    1.874197] i2c 2-0038: Driver ft5x06_ts requests probe deferral
 
[    3.925475] input: ft5x06_ts as /devices/i2c-2/2-0038/input/input1
[    3.931626] ft5x06_ts 2-0038: Regulator get failed vdd rc=-517
[    3.937544] ft5x06_ts 2-0038: power init failed
[    3.994214] i2c 2-0038: Driver ft5x06_ts requests probe deferral
...
Note that error code 517 means, I quote
517 is the value of the linux error EPROBE_DEFER , and it just means that a device driver is telling the linux kernel to try probing a particular device later. The Linux kernel calls a driver's probe() method when it wants the driver to prepare a device for usage.
So my educated guess is that the aml_pm may not even enabled.

After checking with menuconfig, there is a "CONFIG_AML_PMU" that is N by default, and I went ahead enabled it, but the results were the same, no luck there (or aml_pm section is not intended for AML_PMU). Other than aml_pm there is no other configurations related with amlogic power related stuff.

So, after digging into the source tree, the amlogic power related code are located at here:

Code: Select all

linux/drivers/amlogic/power$ ls 
aml.dtd   aml_pmu_of_common.c  battery_parameter.c  Kconfig                  modules.builtin  pmu_mutex.o
aml_dvfs  aml_pmu_of_common.o  built-in.mod.c       Makefile                 modules.order    ricoh
aml_pmu   axp_power            built-in.o           meson_cs_dcdc_regulator  pmu_mutex.c
and the available configurations and source code are:

Code: Select all

11 ifeq ($(CONFIG_AMLOGIC_BOARD_HAS_PMU), y)
 12 ifneq ($(KBUILD_SRC),)
 13 TOP_KBUILD_SRC := $(KBUILD_SRC)/
 14 endif
 15 
 16 #obj-$(CONFIG_SMBA10XX_BATTERY)             += smba10xx_battery/
 17 #obj-$(CONFIG_BQ27x00_BATTERY)              += bq27x00_battery.o
 18 #obj-$(CONFIG_PMU_ACT8xxx)                  += act8xxx_pmu/
 19 obj-$(CONFIG_AW_AXP)                        += axp_power/
 20 #obj-$(CONFIG_CW2015)                       += cw2015/cw2015_gasgauge.o
 21 obj-$(CONFIG_AML_PMU)                       += aml_pmu/
 22 obj-$(CONFIG_RICOH_PMU)                     += ricoh/
 23 obj-$(CONFIG_UBOOT_BATTERY_PARAMETERS)      += battery_parameter.o
 24 obj-$(CONFIG_AMLOGIC_PMU_OF)                += aml_pmu_of_common.o pmu_mutex.o
 25 
 26 endif
 27 
 28 obj-$(CONFIG_MESON_CS_DCDC_REGULATOR)       += meson_cs_dcdc_regulator/
 29 obj-$(CONFIG_AML_DVFS)                      += aml_dvfs/
the ones that look interesting to me are:

Code: Select all

21 obj-$(CONFIG_AML_PMU)                       += aml_pmu/
24 obj-$(CONFIG_AMLOGIC_PMU_OF)                += aml_pmu_of_common.o pmu_mutex.o
I could be mistaken, they just catch my attention more than others.

aml_pmu/aml_pmu.c does support device tree because I find this section in it:

Code: Select all

433 #ifdef CONFIG_OF
434 static const struct of_device_id amlogic_pmu_match_id = {
435         .compatible = "amlogic_pmu",                                                                                  
436 };
437 #endif
aml_pmu_of_common.c also have the .compatible:

Code: Select all

385 static const struct of_device_id aml_pmu_dt_match[] = {
386     {
387         .compatible = "amlogic, aml_pmu_prober",                                                                      
388     },
389     {}
390 };
The compatible strings are no where to find inside meson8b_odroidc.dts, which means they will be defined and added if needed.

So now the questions are, on c0 platform, which power module should we use, aml_pmu? aml_pmu_of_common? or both?

Thanks for your insights,
Hunter

User avatar
tobetter
Posts: 5113
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: X, X2, U2, U3, XU3, C1
Location: Paju, South Korea
Has thanked: 161 times
Been thanked: 509 times
Contact:

Re: Enable Focaltech touchscreen FT5X06

Post by tobetter » Thu May 14, 2020 12:33 pm

What if vdd-supply and vcc_i2c-supply are removed?

hunterhu
Posts: 24
Joined: Wed Nov 09, 2016 3:41 am
languages_spoken: english
ODROIDs: C0, C2, XU4
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: Enable Focaltech touchscreen FT5X06

Post by hunterhu » Fri May 15, 2020 11:27 am

Hi tobetter, I have done more work. Yes, after trying out all my options, the removing vdd-supply, vcc_i2c-supply route does appear to be the most promising approach.

After removing the vdd-supply and vcc_i2c-supply fields, the driver is not happy, so I went ahead just make it happy by ignoring the power part:

Code: Select all

209 static int ft5x06_power_on(struct ft5x06_ts_data *data, bool on)                                                      
210 {
211 |   return 0;        
212 }
213 static int ft5x06_power_init(struct ft5x06_ts_data *data, bool on)
214 {
215 |   return 0;        
216 }
and a few other minor tweaks to make everything going well, now I am getting these kernel messages, a big step forward,

Code: Select all

[    1.798654] input: ft5x06_ts as /devices/i2c-2/2-0038/input/input0
[    1.961709] ft5x06_ts 2-0038: [FTS] Firmware version = 0x1
[    1.962189] ft5x06_ts 2-0038: [FTS] report rate is 100Hz.
[    1.967720] ft5x06_ts 2-0038: [FTS] touch threshold is 100.
[    1.973025] ft5x06_ts 2-0038: request irq failed
[    2.030935] ft5x06_ts: probe of 2-0038 failed with error -22
The probe function actually went almost to the end of but failed with

Code: Select all

491 |   err = request_irq(client->irq, ft5x06_ts_interrupt,
492                         pdata->irqflags, client->dev.driver->name, data);
After putting some debugging messages, I located it failed the kernel code:

Code: Select all

1422 |   if (!irq_settings_can_request(desc) ||
1423 |       WARN_ON(irq_settings_is_per_cpu_devid(desc)))                                                               
1424 |   |   return -EINVAL;
I do not quite exactly understand the failure here means what, But I did found something that directly related with meson8b_odroidc.dts.

Here is my focaltech node that related with interrupts:

Code: Select all

308                     interrupt-parent = <&gpio>;                        
309                     interrupts = <97 0x2>;
310                    
311                     focaltech,reset-gpio = <&gpio 98 0x00>;            
312                     focaltech,irq-gpio = <&gpio 97 0x00>;
OK, what is &gpio then?

Code: Select all

737         gpio:gpio{                                                                                                   
 738                 compatible = "amlogic,m8b-gpio";
 739                 dev_name = "gpio";
 740                 #gpio-cells=<2>;
 741         };
All right, here is the place I found something is not right:

According to kernel menuconfig, the amlogic gpio driver is located at:

Code: Select all

linux/drivers/amlogic/gpio$ ls 
aml.dtd  built-in.mod.c  built-in.o  gpio-amlogic.c  gpio-amlogic.o  Kconfig  Makefile  modules.builtin  modules.order
and Makefile inside linux/drivers/amlogic/gpio

Code: Select all

 4 obj-$(CONFIG_GPIO_AMLOGIC)+= gpio-amlogic.o
So I am pretty sure this is the driver that is getting built and running on c0.

However, it seems this gpio-amlogic.c driver doesn't support device tree, and the gpio node inside meson8b-odroidc.dtsb is not intended for this driver, hence the broken link and failed irq_request() call.

I could be wrong, what do you think? What could I do to make the focaltech driver device tree node work?

Thanks for your insights,
-Hunter

User avatar
tobetter
Posts: 5113
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: X, X2, U2, U3, XU3, C1
Location: Paju, South Korea
Has thanked: 161 times
Been thanked: 509 times
Contact:

Re: Enable Focaltech touchscreen FT5X06

Post by tobetter » Fri May 15, 2020 12:41 pm

I can imagine how you are difficult to make your touchscreen work...

The DTS in the kernel 3.10 is not that good as you refer to anything else, at the same time, GPIO driver from Amlogic is messy.
So this is a bit tricky, you would need to modify a lot FT5x06 driver for the interrupt as well. As you are aware, SX865X driver is provided and it also uses the interrupt for touch, copy the code from to your driver and DTB also must be modified as SX865X.
https://github.com/hardkernel/linux/blo ... 65x.c#L384

hunterhu
Posts: 24
Joined: Wed Nov 09, 2016 3:41 am
languages_spoken: english
ODROIDs: C0, C2, XU4
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: Enable Focaltech touchscreen FT5X06

Post by hunterhu » Tue May 19, 2020 6:23 am

Thanks tobetter. I did follow your suggestions and uses the interrupt handling from SX865X driver, and my FT5216 is working.

The following are my final device tree node:

Code: Select all

 304                 focaltech: ft5x06_ts@38 {                                                                            
 305                     compatible = "focaltech,5x06";
 306                     reg = <0x38>;
 307 
 308                     /* H/W Pin control setup */
 309                     gpio-pendown = "GPIOX_0";
 310                     gpio-reset = "GPIOX_1";
 311 
 312                     focaltech,panel-coords = <0 0 272 480>;
 313                     focaltech,display-coords = <0 0 272 480>;
 314 
 315                     focaltech,family-id = <0x0a>;
 316                 };
Basically what I have done is to follow the

Code: Select all

#if defined(CONFIG_MACH_MESON8B_ODROIDC)
Code block inside drivers/input/touchscreen/sx865x.c, because it looks like all the related code that are handling irq and device tree node parsing are embraced within the if define.

That concludes this thread.

Thanks again for all the help and insights from Hardkernel's fantastic engineers and support!

-Hunter
These users thanked the author hunterhu for the post (total 2):
tobetter (Tue May 19, 2020 6:41 am) • odroid (Tue May 19, 2020 9:50 am)

User avatar
tobetter
Posts: 5113
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: X, X2, U2, U3, XU3, C1
Location: Paju, South Korea
Has thanked: 161 times
Been thanked: 509 times
Contact:

Re: Enable Focaltech touchscreen FT5X06

Post by tobetter » Tue May 19, 2020 6:41 am

@hunterhu, this is a great update and thank you for sharing. :)

Post Reply

Return to “Ubuntu”

Who is online

Users browsing this forum: No registered users and 2 guests