From patchwork Tue Aug 30 12:27:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Ferre X-Patchwork-Id: 9305369 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 645A160756 for ; Tue, 30 Aug 2016 12:33:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55D5628BC7 for ; Tue, 30 Aug 2016 12:33:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4ACC828BCC; Tue, 30 Aug 2016 12:33:48 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5158B28BC7 for ; Tue, 30 Aug 2016 12:33:46 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1beiD2-0002MP-Jh; Tue, 30 Aug 2016 12:32:08 +0000 Received: from exsmtp03.microchip.com ([198.175.253.49] helo=email.microchip.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bei7s-0004ow-MJ for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2016 12:26:51 +0000 Received: from tenerife.corp.atmel.com (10.10.76.4) by chn-sv-exch03.mchp-main.com (10.10.76.49) with Microsoft SMTP Server id 14.3.181.6; Tue, 30 Aug 2016 05:26:24 -0700 From: Nicolas Ferre To: Cristian Birsan , Ludovic Desroches Subject: [PATCH] iio: adc: at91: Add support for Touchscreen Switches Closure Time Date: Tue, 30 Aug 2016 14:27:01 +0200 Message-ID: <20160830122701.19385-1-nicolas.ferre@atmel.com> X-Mailer: git-send-email 2.9.0 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAC+NgFnrLosTGxcLF5cOiW1h9NNzg4e/t3xgtOqasYrK492kbo8XXJmOLadPfMTuwBDBEsWbmJeVXJLBmvLy2m7HgokhFw6QDrA2MFwS6GLk4hATWMUrcmXaCuYuRk4NNQFfi7IQnbCC2iECaxM/3j5lAipgFLjBKvPm1CKxIWCBI4sOBf+wgNouAqkRb+1GwBl4BG4lXXTfBaiQE5CQazt9nhogLSpyc+YQFxGYWkJA4+OIFWFxIQEWi730/O0R9oMT6hVeYIGwniaVXNrBA2HYSh6dfhKqxl+heup0RpubD77dQtrbE9lf7WCFsHYltB/uhem0l9syYCDXTXeLBo+VQtq/ErIcNUDVREhv2vWafwCg2C8mps5CcuoCRaRWjdHJGnm5xmW5qRXKGgbFebnJGgW5uYmaeXnJ+7iZGSFQY7mDc9MDvEKMkB5OSKO/U+CPhQnxJ+SmVGYnFGfFFpTmpxYcYJTh4lER4154GyvEWFyTmFmemw6RkODiUJHiFQFKCRanpqRVpmTklqUUQ6VOMklLivAdPASUFQPoySvPgcpcYRaWEeev2AuV4ClKLcjNLIOK3GIU5HjIJseTl56VKAZ3IAAQajK8YxTkYlYR59UAW8WTmlcCd8AroOiag6wruHAa5riQRISXVwCi6+8z2mzmbLsx+qnHjmUZVLv/vr7VfN96/2b4i3SXfaq7deZ4cN8PbuQmW9gKFS/b3thbuDjlzdntq1crdz6/aGVQklGyW41WpPrBAleM1g+/059WrXzxVEZt+tu72GgH955Xz606aemVJpk2U+71CYuVcZ7uKldzSqfEXehtnbSlc5vj8wBclluKMREMt5qLiRAAh9nkAAAMAAA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160830_052649_018933_4AFAEF39 X-CRM114-Status: GOOD ( 11.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-iio@vger.kernel.org, Nicolas Ferre , Alexandre Belloni , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On newer components compatible with the at91sam9x5, the Touchscreen Switches Closure Time or TSSCTIM value of the Touchscreen Mode Register is not filled at all. On some hardware, having no time indicated for it may lead to incoherent values and jitter. We fix this time to 10us as it is usually difficult to retrieve impedance values from LCD manufacturers. Signed-off-by: Nicolas Ferre --- drivers/iio/adc/at91_adc.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c index 0438c68015e8..bbdac07f4aaa 100644 --- a/drivers/iio/adc/at91_adc.c +++ b/drivers/iio/adc/at91_adc.c @@ -113,6 +113,7 @@ #define AT91_ADC_TSMR_TSAV (3 << 4) /* Averages samples */ #define AT91_ADC_TSMR_TSAV_(x) ((x) << 4) #define AT91_ADC_TSMR_SCTIM (0x0f << 16) /* Switch closure time */ +#define AT91_ADC_TSMR_SCTIM_(x) ((x) << 16) #define AT91_ADC_TSMR_PENDBC (0x0f << 28) /* Pen Debounce time */ #define AT91_ADC_TSMR_PENDBC_(x) ((x) << 28) #define AT91_ADC_TSMR_NOTSDMA (1 << 22) /* No Touchscreen DMA */ @@ -150,6 +151,7 @@ #define MAX_RLPOS_BITS 10 #define TOUCH_SAMPLE_PERIOD_US_RL 10000 /* 10ms, the SoC can't keep up with 2ms */ #define TOUCH_SHTIM 0xa +#define TOUCH_SCTIM_US 10 /* 10us for the Touchscreen Switches Closure Time */ /** * struct at91_adc_reg_desc - Various informations relative to registers @@ -1001,7 +1003,9 @@ static void atmel_ts_close(struct input_dev *dev) static int at91_ts_hw_init(struct at91_adc_state *st, u32 adc_clk_khz) { + struct iio_dev *idev = iio_priv_to_dev(st); u32 reg = 0; + u32 tssctim = 0; int i = 0; /* a Pen Detect Debounce Time is necessary for the ADC Touch to avoid @@ -1034,11 +1038,20 @@ static int at91_ts_hw_init(struct at91_adc_state *st, u32 adc_clk_khz) return 0; } + /* Touchscreen Switches Closure time needed for allowing the value to + * stabilize. + * Switch Closure Time = (TSSCTIM * 4) ADCClock periods + */ + tssctim = DIV_ROUND_UP(TOUCH_SCTIM_US * adc_clk_khz / 1000, 4); + dev_dbg(&idev->dev, "adc_clk at: %d KHz, tssctim at: %d\n", + adc_clk_khz, tssctim); + if (st->touchscreen_type == ATMEL_ADC_TOUCHSCREEN_4WIRE) reg = AT91_ADC_TSMR_TSMODE_4WIRE_PRESS; else reg = AT91_ADC_TSMR_TSMODE_5WIRE; + reg |= AT91_ADC_TSMR_SCTIM_(tssctim) & AT91_ADC_TSMR_SCTIM; reg |= AT91_ADC_TSMR_TSAV_(st->caps->ts_filter_average) & AT91_ADC_TSMR_TSAV; reg |= AT91_ADC_TSMR_PENDBC_(st->ts_pendbc) & AT91_ADC_TSMR_PENDBC;