From patchwork Wed Dec 24 07:03:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vignesh Raghavendra X-Patchwork-Id: 5536761 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D9712BEEA8 for ; Wed, 24 Dec 2014 07:09:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EB679201B9 for ; Wed, 24 Dec 2014 07:09:40 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 062C7200F2 for ; Wed, 24 Dec 2014 07:09:40 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Y3g2K-0004r3-1t; Wed, 24 Dec 2014 07:07:12 +0000 Received: from devils.ext.ti.com ([198.47.26.153]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Y3g1N-0004FU-Ll for linux-arm-kernel@lists.infradead.org; Wed, 24 Dec 2014 07:06:14 +0000 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id sBO75JN9020231; Wed, 24 Dec 2014 01:05:19 -0600 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id sBO75JBT027122; Wed, 24 Dec 2014 01:05:19 -0600 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.3.174.1; Wed, 24 Dec 2014 01:05:18 -0600 Received: from uda0132425.apr.dhcp.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id sBO74Mhp005006; Wed, 24 Dec 2014 01:05:11 -0600 From: Vignesh R To: Jonathan Cameron , Hartmut Knaack , Dmitry Torokhov , Lee Jones , Sebastian Andrzej Siewior Subject: [PATCH v5 6/6] input: touchscreen: ti_am335x_tsc: Replace delta filtering with median filtering Date: Wed, 24 Dec 2014 12:33:39 +0530 Message-ID: <1419404619-10744-7-git-send-email-vigneshr@ti.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1419404619-10744-1-git-send-email-vigneshr@ti.com> References: <1419404619-10744-1-git-send-email-vigneshr@ti.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141223_230613_921979_FDD8A9E2 X-CRM114-Status: GOOD ( 18.39 ) X-Spam-Score: -5.0 (-----) Cc: Mark Rutland , Vignesh R , Wolfram Sang , linux-iio@vger.kernel.org, Paul Gortmaker , Peter Meerwald , Lars-Peter Clausen , Russell King , Jan Kardell , Tony Lindgren , linux-input@vger.kernel.org, Sanjeev Sharma , devicetree@vger.kernel.org, Brad Griffis , Pawel Moll , Ian Campbell , Rob Herring , linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Samuel Ortiz , linux-kernel@vger.kernel.org, Felipe Balbi , Benoit Cousson , Kumar Gala X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Previously, delta filtering was applied TSC co-ordinate readouts before reporting a single value to user space. This patch replaces delta filtering with median filtering. Median filtering sorts co-ordinate readouts, drops min and max values, and reports the average of remaining values. This method is more sensible than delta filering. Median filtering is applied only if number of readouts is greater than 3 else just average of co-ordinate readouts is reported. Signed-off-by: Vignesh R --- drivers/input/touchscreen/ti_am335x_tsc.c | 91 +++++++++++++++++-------------- 1 file changed, 51 insertions(+), 40 deletions(-) diff --git a/drivers/input/touchscreen/ti_am335x_tsc.c b/drivers/input/touchscreen/ti_am335x_tsc.c index 9cb8b4a01dca..504b85db6425 100644 --- a/drivers/input/touchscreen/ti_am335x_tsc.c +++ b/drivers/input/touchscreen/ti_am335x_tsc.c @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -204,56 +205,61 @@ static void titsc_step_config(struct titsc *ts_dev) am335x_tsc_se_set_cache(ts_dev->mfd_tscadc, ts_dev->step_mask); } +static int titsc_cmp_coord(const void *a, const void *b) +{ + return *(int *)a - *(int *)b; +} + static void titsc_read_coordinates(struct titsc *ts_dev, u32 *x, u32 *y, u32 *z1, u32 *z2) { - unsigned int fifocount = titsc_readl(ts_dev, REG_FIFO0CNT); - unsigned int prev_val_x = ~0, prev_val_y = ~0; - unsigned int prev_diff_x = ~0, prev_diff_y = ~0; - unsigned int read, diff; - unsigned int i, channel; + unsigned int yvals[7], xvals[7]; + unsigned int i, xsum = 0, ysum = 0; unsigned int creads = ts_dev->coordinate_readouts; - unsigned int first_step = TOTAL_STEPS - (creads * 2 + 2); - *z1 = *z2 = 0; - if (fifocount % (creads * 2 + 2)) - fifocount -= fifocount % (creads * 2 + 2); - /* - * Delta filter is used to remove large variations in sampled - * values from ADC. The filter tries to predict where the next - * coordinate could be. This is done by taking a previous - * coordinate and subtracting it form current one. Further the - * algorithm compares the difference with that of a present value, - * if true the value is reported to the sub system. - */ - for (i = 0; i < fifocount; i++) { - read = titsc_readl(ts_dev, REG_FIFO0); - - channel = (read & 0xf0000) >> 16; - read &= 0xfff; - if (channel > first_step + creads + 2) { - diff = abs(read - prev_val_x); - if (diff < prev_diff_x) { - prev_diff_x = diff; - *x = read; - } - prev_val_x = read; + for (i = 0; i < creads; i++) { + yvals[i] = titsc_readl(ts_dev, REG_FIFO0); + yvals[i] &= 0xfff; + } - } else if (channel == first_step + creads + 1) { - *z1 = read; + *z1 = titsc_readl(ts_dev, REG_FIFO0); + *z1 &= 0xfff; + *z2 = titsc_readl(ts_dev, REG_FIFO0); + *z2 &= 0xfff; - } else if (channel == first_step + creads + 2) { - *z2 = read; + for (i = 0; i < creads; i++) { + xvals[i] = titsc_readl(ts_dev, REG_FIFO0); + xvals[i] &= 0xfff; + } - } else if (channel > first_step) { - diff = abs(read - prev_val_y); - if (diff < prev_diff_y) { - prev_diff_y = diff; - *y = read; - } - prev_val_y = read; + /* + * If co-ordinates readouts is less than 4 then + * report the average. In case of 4 or more + * readouts, sort the co-ordinate samples, drop + * min and max values and report the average of + * remaining values. + */ + if (creads <= 3) { + for (i = 0; i < creads; i++) { + ysum += yvals[i]; + xsum += xvals[i]; } + ysum /= creads; + xsum /= creads; + } else { + sort(yvals, creads, sizeof(unsigned int), + titsc_cmp_coord, NULL); + sort(xvals, creads, sizeof(unsigned int), + titsc_cmp_coord, NULL); + for (i = 1; i < creads - 1; i++) { + ysum += yvals[i]; + xsum += xvals[i]; + } + ysum /= creads - 2; + xsum /= creads - 2; } + *y = ysum; + *x = xsum; } static irqreturn_t titsc_irq(int irq, void *dev) @@ -369,6 +375,11 @@ static int titsc_parse_dt(struct platform_device *pdev, if (err < 0) return err; + if (ts_dev->coordinate_readouts <= 0) { + dev_warn(&pdev->dev, "invalid co-ordinate readouts, resetting it to 5\n"); + ts_dev->coordinate_readouts = 5; + } + err = of_property_read_u32(node, "ti,charge-delay", &ts_dev->charge_delay); /*