From patchwork Tue Mar 12 08:21:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Jander X-Patchwork-Id: 10848731 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 782621575 for ; Tue, 12 Mar 2019 08:28:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6495929573 for ; Tue, 12 Mar 2019 08:28:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55FEA2956D; Tue, 12 Mar 2019 08:28:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8B362956D for ; Tue, 12 Mar 2019 08:28:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726844AbfCLI2w (ORCPT ); Tue, 12 Mar 2019 04:28:52 -0400 Received: from protonic.xs4all.nl ([83.163.252.89]:46382 "EHLO protonic.nl" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727089AbfCLI2v (ORCPT ); Tue, 12 Mar 2019 04:28:51 -0400 Received: from erd988.prtnl (erd988.prtnl [192.168.224.30]) by sparta (Postfix) with ESMTP id 7EAEB44A00CB; Tue, 12 Mar 2019 09:23:23 +0100 (CET) From: David Jander To: Dmitry Torokhov , linux-input@vger.kernel.org Cc: Greg KH , Mark Brown , Imre Deak , David Jander Subject: [PATCH 0/2] [RFC] input: touchscreen: ads7846.c: re-write Date: Tue, 12 Mar 2019 09:21:43 +0100 Message-Id: <20190312082145.8906-1-david@protonic.nl> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is a near complete re-write of the ads7846 touchscreen driver, fixing many issues the current implementation has. Unfortunately due to the nature of the problems, separate patches addressing the individual issues would have been too big of a task and not really practical. For instance re-implementing the sampling code while keeping the filter code would already require a lot changes to the filtering code in order to work with the new way of sampling, only to throw everything away in the next patch. The only patch that is separate, and that can be used without the rest is the addition of device-tree parameters to allow for inversion of X/Y axes. Here is a summary of all the issues with the current code that are addressed in the second patch: - Excessive CPU usage. The new driver has almost 100x lower CPU usage in some cases. This was due to the fact that the original driver submits a chain of many small SPI transfers that cause a lot of context switching in the SPI work-queue. All touchscreen measurements can be done in a single SPI transfer using the 16 clocks-per-conversion timing mode described in the data-sheets. The driver also relied on spi_transfer->delay_usecs, which in worst-case can busy-wait, and in best case introduces a few more context switches. The new driver implementes settling-delays by inserting dummy samples into the SPI transfer. Since the SPI transfer is handled by hardware (either DMA or FIFOs), the CPU is freed even further. While this can increse the SPI traffic a bit on the SPI bus, in practice that bit of extra bandwidth that was available before could not have been used due to system latency anyway. - Unreadable filter code. The filtering code was implemented in a quirky and hard to follow manner, due to the way the samples get extracted one by one from the chain of SPI messages. The new code extracts all data from X, Y and pressure at once and delivers the complete set of samples to the filter. This way the filter knows what X, Y or pressure data is respectively. - Potential integer overflow in the pressure calculation, resulting in fake high-pressure touches on bigger touch-panels, where the x-plate resistance is higher (800-1000 Ohm or more). - Each time a HWMON measurement is done from one of the temperature or aux inputs of the chip while the screen is touched, a pen-up and pen-down event was generated. This is now solved by using the lock also in the interrupt thread. - Improved filter performance: Mark samples that signify a big displacement as suspects and wait for the next sample to decide if it is valid (fast slide) or not. Moving average of up to 4 deemed-good samples. Also on bad touch-panels, the pen contact can be glitchy. There is a new filter parameter to enable a separate touch contact glitch filter. Due to the new filter architecture, the DT layout needed to change. This patch is an RFC, so no changes have been made yet to the affected device-trees. These will be done before the final version of this patch. David Jander (2): input: touchscreen: ads7846.c: Add support for invert_x/y in dt input: touchscreen: ads7846.c: Re-write sampling and filtering functions .../bindings/input/touchscreen/ads7846.txt | 34 +- drivers/input/touchscreen/ads7846.c | 874 +++++++----------- include/linux/spi/ads7846.h | 29 +- 3 files changed, 386 insertions(+), 551 deletions(-)