Skip to content

input: touchscreen: edt-ft5x06: Suppress bogus data on startup - #5645

Merged
njhollinghurst merged 1 commit into
rpi-6.1.yfrom
ft5x06-filter
Oct 12, 2023
Merged

njhollinghurst merged 1 commit into
rpi-6.1.yfrom
ft5x06-filter

Conversation

@njhollinghurst

Copy link
Copy Markdown
Contributor

When polled without the use of IRQ, FT5x06 registers may hold undefined data. Filter out the initial static state (allowing a few transient zeroes which may occur around 700ms after reset).

@njhollinghurst

Copy link
Copy Markdown
Contributor Author

Not pretty, but it seems to do the trick. (We could avoid special handling for "transient zeroes" either by slowing down the reset by another 400ms or delaying the initial polling timer by 400ms.)

What I'm not doing right now is checking for duplicated IDs, because the bad state is not "guaranteed" to have any. But duplicated IDs are bad news generally as they can lead to input event spamming.

@6by9 6by9 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the one comment, that looks reasonable.

Comment thread drivers/input/touchscreen/edt-ft5x06.c Resolved
@njhollinghurst

Copy link
Copy Markdown
Contributor Author

Now I think I still need to do some more testing for the "transient zeros" effect, to see whether or not we need to delay the first polling interval by 400ms or whatever (it's a bit shocking that reset seems to take so long).

If we do that, the code change could be a little simpler.

Comment thread drivers/input/touchscreen/edt-ft5x06.c Outdated
/* When polling FT5x06 without IRQ: initial register
* contents could be stale or undefined; ignore them
* until something changes or num_points becomes 0.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the comment, now that you're delaying and don't see the awkward drop to 0 points, can't we now just filter until num_points to hits 0?

@njhollinghurst njhollinghurst Oct 12, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EDITED. I previously had a largely bogus objection about pre-existing touches.

However there is worse case, which is that it could change from the undefined data to the first real touch (which could occur after an arbitrarily long delay) without num_points ever dropping to zero.

So I think the workaround really does need to do a memcmp to detect the first change.

@njhollinghurst njhollinghurst Oct 12, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can probably simplify by detecting change to num_points only. The risk is that if the bogus data had exactly one point, we would miss the first touch.

@pelwell pelwell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love the fact that this relies on both 0 and UINT_MAX being illegal TD_STATUS values, especially when there are no comments or named constants to make that clear, but if that is indeed the case then I can live with this.

Comment thread drivers/input/touchscreen/edt-ft5x06.c Outdated
timer_setup(&tsdata->timer, edt_ft5x06_ts_irq_poll_timer, 0);
tsdata->timer.expires = jiffies +
msecs_to_jiffies(POLL_INTERVAL_MS);
msecs_to_jiffies(FIRST_POLL_DELAY_MS);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous indentation looks better.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was emacs' default for linux style - but I've just noticed that checkpatch allows both (surprisingly). I can increase it again.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either that or push jiffies onto the next line

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a signed integer and -1 be a nicer way to represent "uninitialized"? Actual values are u8, and u8->int casting is presumably uncontroversial.

To anticipate another potential question: we deliberately do include the "reserved" upper nybble in the test, because it does help to discriminate between bogus and real touch data.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since init_td_status is a signed int, and the rdbuf values are u8s, making the magic values negative is clearer and guaranteed to work.

When polled without the use of IRQ, FT5x06 registers may return
undefined initial data, causing unwanted touches or event spamming.
A simple way to filter this out is to suppress touches until the
TD_STATUS register changes for the first time.

Increase the delay before first polling to 300ms, to avoid
transient I2C read flakiness that seems to occur after reset.

Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>
@pelwell

pelwell commented Oct 12, 2023

Copy link
Copy Markdown
Contributor

With the latest change you are still relying on the first TD_STATUS value not being 0 - is that guaranteed to be the case?

@njhollinghurst

njhollinghurst commented Oct 12, 2023 •

Copy link
Copy Markdown
Contributor Author

With the latest change you are still relying on the first TD_STATUS value not being 0 - is that guaranteed to be the case?

Functionally, we don't rely on this: even if we chose some other bit pattern to represent the no-filtering state, a first value of TD_STATUS==0 would imply num_points==0 and would put it into that state.

0 is a benign value that we don't need to filter, and indeed is what we'd like the first TD_STATUS to have been, so it felt natural to use it for that. It's also the simplest value to test for (silly micro-optimization!)

@pelwell

pelwell commented Oct 12, 2023

Copy link
Copy Markdown
Contributor

a first value of TD_STATUS==0 would imply num_points==0

Is a reviewer supposed to know that? Anyway, I don't object.

@njhollinghurst
njhollinghurst merged commit dd802fc into rpi-6.1.y Oct 12, 2023
@njhollinghurst
njhollinghurst deleted the ft5x06-filter branch October 12, 2023 16:21
@njhollinghurst

njhollinghurst commented Oct 16, 2023 •

Copy link
Copy Markdown
Contributor Author

Sorry... I am having second thoughts about the fix above It's possible to get into a state where the first touch is ignored. This can happen either if the initial data happened to have TD_STATUS == 0x01, which I have never observed; or quite reproducibly by the following steps:

  • Hold one finger on the touchscreen
  • Reboot
  • Release finger as soon as the Plymouth splash appears (TS is held in reset at this point)
  • Now the next touch will be ignored.

To fix it I may need to revert the simplification which looked at TD_STATUS only, and go back to comparing the entire buffer.

The safer-but-more-complicated version is sitting on branch ft5x06-filter2. I won't PR it for now.

njhollinghurst added a commit that referenced this pull request Oct 16, 2023
This is a refinement which replaces or should be squashed with
commit dd802fc from PR #5645
and the new commit message should be the following:

When polled without the use of IRQ, FT5x06 registers may return
undefined initial data, causing unwanted touches or event spamming.
To avoid this, whenever the initial number of touches is non-zero,
discard all touches until something changes.

Increase the delay before first polling to 300ms, to avoid
transient I2C read flakiness that seems to occur after reset.

Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>
popcornmix added a commit to raspberrypi/firmware that referenced this pull request Oct 17, 2023
kernel: drivers: media: rp1_cfe: Fix link validate test for pixel format
See: raspberrypi/linux#5657

kernel: drm/vc4: Correct address offset for planes with src_[xy] offsets
See: raspberrypi/linux#5654

kernel: input: touchscreen: edt-ft5x06: Suppress bogus data on startup
See: raspberrypi/linux#5645

kernel: vc_mem: Add the DMA memcpy support from bcm2708_fb
See: raspberrypi/linux#5651

kernel: dts: bcm2712: Set default I2C baudrates to 100kHz
See: raspberrypi/linux#5653

kernel: MCP23017: allow specification of the i2c bus
See: raspberrypi/linux#5650

kernel: Revert: bcm2708_fb: Hack out dma support
See: raspberrypi/linux#5648

firmware: config: Add [pi5] to config.txt on 2711 and earlier platforms

userland: bcm_host: Update kms/fkms check for pi5
popcornmix added a commit to raspberrypi/rpi-firmware that referenced this pull request Oct 17, 2023
kernel: drivers: media: rp1_cfe: Fix link validate test for pixel format
See: raspberrypi/linux#5657

kernel: drm/vc4: Correct address offset for planes with src_[xy] offsets
See: raspberrypi/linux#5654

kernel: input: touchscreen: edt-ft5x06: Suppress bogus data on startup
See: raspberrypi/linux#5645

kernel: vc_mem: Add the DMA memcpy support from bcm2708_fb
See: raspberrypi/linux#5651

kernel: dts: bcm2712: Set default I2C baudrates to 100kHz
See: raspberrypi/linux#5653

kernel: MCP23017: allow specification of the i2c bus
See: raspberrypi/linux#5650

kernel: Revert: bcm2708_fb: Hack out dma support
See: raspberrypi/linux#5648

firmware: config: Add [pi5] to config.txt on 2711 and earlier platforms

userland: bcm_host: Update kms/fkms check for pi5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants