Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751693AbbH1JHj (ORCPT ); Fri, 28 Aug 2015 05:07:39 -0400 Received: from mail-bn1on0139.outbound.protection.outlook.com ([157.56.110.139]:59967 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751367AbbH1JHe (ORCPT ); Fri, 28 Aug 2015 05:07:34 -0400 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none;freescale.mail.onmicrosoft.com; dmarc=none action=none header.from=freescale.com; From: Haibo Chen To: , , , , , , , CC: , , , , , Subject: [PATCH v3 1/5] input: touchscreen: add imx6ul_tsc driver support Date: Fri, 28 Aug 2015 17:09:32 +0800 Message-ID: <1440752976-9094-2-git-send-email-haibo.chen@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1440752976-9094-1-git-send-email-haibo.chen@freescale.com> References: <1440752976-9094-1-git-send-email-haibo.chen@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11FD011;1:1/7+rH7rTfmUTq2UhmNYvS4eLMLbZx7d0Ck0RqoWNT1EGxsbp9J4hDi+qqSZ+9zLWdpKE+yrVWHot+3WOI490gFQkG0dUbtLut7jtUgiPH0XxtM8dFjhC8GdmyTHiGPj7Ii/PsZ8fvh1VhCO1NyZNQy8mMTF0giBy2Z2shp/ZOK045wEnjotqkbBMz03pXvikxzQa9NXwAtb2DrrpiIjUiEYd3greKQAn3wXL1dc5S3rz1CrQdAMTFVkzl4W/44yzFWT0/ZYtuMfdYIRc2IhQylaQ34KOMtQ5k/TWe8EFkmD3NS52TT6G47qnGms5gFd3pxPGmM/H/nEeD8ad6SB5Hjg9xuj3kq7/c2J4MwHS7gas6MnoAydRyXX2Feials+MEEjYgYT+HoAcpHO1Pt2Xw== X-Forefront-Antispam-Report: CIP:192.88.158.2;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(3050300001)(339900001)(189002)(199003)(4001540100001)(47776003)(575784001)(92566002)(229853001)(5001770100001)(2950100001)(5001830100001)(81156007)(19580405001)(2201001)(77096005)(86362001)(76176999)(6806004)(19580395003)(97736004)(50986999)(5003940100001)(87936001)(104016003)(68736005)(33646002)(46102003)(48376002)(107886002)(5001860100001)(50226001)(189998001)(36756003)(77156002)(5007970100001)(50466002)(105606002)(85426001)(5001960100002)(62966003)(69596002)(106466001)(64706001)(2004002)(4001430100001);DIR:OUT;SFP:1102;SCL:1;SRVR:BLUPR03MB1377;H:az84smr01.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB1377;2:HZ9a8FXGXF47ZIOZYjQgiMamv7SbZafl/lx1/GAMgAuWJlpAPNZXuBNJq0qBCFbS+sDZeFQAOUcxG1JlSWVafORXpqJaheYVk09cMI85lkhYaMCtvVqdgoyIYt38vWycqd6i/EUyBx+/QUja+F/QXpH/OKQmTh1ob9oAMIrMUBY=;3:/54qgXjtSfF/1hS3JuGPrVW50XkUs7dZ8s+Xjxmmy/FWlVpn5zaiMy0jGOIMqUJZVeINppaTPwCo9ElOFCfewKHtfhx49fUJ0l013vd5Lgq6sH1P5r0ShfITJAEQZ0o8seVXf74FzdB6SD/OACVoXtGtQnSzz2a87QV3KwK1NVvzXShgdrRdU3BD6g2jFQhNev/lTvVEH/AjM42DygOvUKuyjed3QW+L8mS37hxBr1U=;25:4cO6r+CAU6JBdmAMX8jAmURPDpovh3edv5mnH0Z/u/SRtiaZe4DKI5Q6zgKZ24TS1lQpEhXG4ThMe8jIGkrdNCmQBTDxMFuzWjBqFDuTT5hFLPfequntM9i315cfGoDNZ6yhwyYSxVZsfoQJH3A5ZG0+KpY3fIAn4+GnT0TwaOEjiJtXKlhiiHfOr6cz+pZqL/IOR+3yoRWKpkRiYlU8i+1URK7FLLy19WuXnx1YpoKiegm/0VoarKWb30t3kgwcQ2XeKSbtgSeZMcWD9RPp6g== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB1377; X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB1377;20:w9q9c6ZaSqyFfZoEVCR+4TmzleNMqdWyer7syL1KhYoNyyAQOmO6kVDLqTiTatUEwXKTz5YXTf8BrfZ2JJLuvH1ziCPv55MtUMxSj0AUzW8fiid2lr+9Pcwj8QxoDxjxvdKOGK7ah3A3e6esQAb3A3dNfWhj/kYiefqqG2iwiqWhG+pve/Xqt/d68h9/WFX49z8Qkz5cNKrffj357bIH5gJuNvI8h+KmGZFIouNciJtF7tAxMR8ccyiS23juMP2hr3UKGbZLrXAqa9aRugvs/t5ixpwet1skjnh83aJBvM5SCK0brcSkPixZi2TeXlHuE4/VxjV6MfjzFuH/7i/YQzB/hUl/RBUu4yHBuJwghsI=;4:i/h9+t3Styvrbunx8ZEaYF90+GaAhKpHgM8xJagCjYf9zsviz2+mNcHw9pjgDhF+JamFfjFC2gmo3Vx7e7hCilEJJe2a0ubgvIL0RUpbLek9omWmyIf4QiVt8kOoM0uZr7LrZRNIucGSsTyUO0EUXkvJr5inSfjQScFcVIv/7kWLIm9qKPnsvzdZFGF3sq8g+cfxu22gv4uxLNrIyq7UKraMWCYJHVhaqyEeaUqrClml50JFnTME6zNdgimdat5h5mJbHkMdleTznAEzLfBJqyogAC65s2XX657lsCSJbU4G0dgpUqCo41KsiOzwt8aJ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(8121501046)(3002001);SRVR:BLUPR03MB1377;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB1377; X-Forefront-PRVS: 0682FC00E8 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BLUPR03MB1377;23:1VAopLMYENkotXh921aLvXIGtqJq12mq235MgmLaI?= =?us-ascii?Q?qCliKWN31lLR6Y8ZhkWbKzYbVRyxUNzDqWlbHqmJ6I6c+ZwFCjFMvaVYxWna?= =?us-ascii?Q?LKkmkNUdDv1kMrwXaEVlmAEmC0dB/fFXh5y9NfBRzj9BSkEPJpYsdaR8Z8kl?= =?us-ascii?Q?W7HmA+P1g4GJwDuRX90zahSooMTpCAnixQFOYBxSTRC3SXTGnBuapnYPoC8x?= =?us-ascii?Q?XND1Pp+GIoj8YE7jNx+lQbaeDNOMwf7khSk/FeTSF7UgWCUKKJuDeuu8g6Eo?= =?us-ascii?Q?YA2koV/F8Sac8g/kGgFA+pl1CessSee2ZBqd/fL7alGLgrqbbbDSI6a/kEQk?= =?us-ascii?Q?T/Y52JqNXNlZZGShSPkaN9F8nI+ekVNwi2LjhOynOmv/O+8PtUGSPYTREUc4?= =?us-ascii?Q?cBlICnBAqEGqWu8c7MQkf3L6yyg5Tny0UEm6ru/ctBOuyd1taHpUjTMV0xz3?= =?us-ascii?Q?53ge8+mp9NpIIFDFKoHk2dy6wpx9eilfj6KddneM2l9htJYtzgmVWqHM/MgW?= =?us-ascii?Q?X5u2105C3N7CWb2ozmE94AYyeIYvkJflzbs6C5loccLKTHPD7sMBuqkbEXZh?= =?us-ascii?Q?kfmHKtsuznQC3eiD20RYLveE0JS2jI+waleYp13NlhwL1tc+hdg4RfgWJs4E?= =?us-ascii?Q?/q0S65oJV0k68NidpUgXu8/PlWmREOz7fmr/KkzksMl2Ly12xWOlr7ckorDi?= =?us-ascii?Q?oTkD6W8w3Tpm9u9w484Kq5l1K2Jixv+n+Mts1lVISjQepGG5qNNgKnAptICe?= =?us-ascii?Q?hQSYzhMLcyBJa+/8cCSyarbKj1bNXHaZ9g7NSGOy7XNgroH/p94hwWZTRoLP?= =?us-ascii?Q?7dSkMvMD9e+micqvHBE3uhXSfS9lGOVCl6cZ37HRSgn76o83UHB+d7CFsezu?= =?us-ascii?Q?QLLDg33NFyt9kGiQsZ1O4YOSeUFwNs4XPEQ6doT4LOSpD6O320Q/Yk3VYc4s?= =?us-ascii?Q?pqrjzH1efCQAIVImam/ZZjpUj2CXAsQ2xa4uCSFFPz6kEZ66JPLP5O6keYz0?= =?us-ascii?Q?KMDxtLpYiiJpQpxfuovOn3c4/w9MWusmuVGnekkVZxscFZMrJSWobLAO3Do1?= =?us-ascii?Q?vSA0PyderJtXNc2xPr6B0AaD8Jo5BMAX4Pddd/IODhc31bWJXu8Z89s9OXdz?= =?us-ascii?Q?2AsOWb+zaD7P05zuUs1d+u78EA9FslBrrhnU9hvOm4WRbsTXfMvDgyAKZkch?= =?us-ascii?Q?Qm/M9Wp77tCA8CjA3th+gCohDur0lpOqugBHpDvhMkuHe97DS4Jhvvqq44TD?= =?us-ascii?Q?+3KuWuHMBkk4QkiqOGKUAoVmM/DCLjxyjrqljtTAvUDUBEJ/RT1Moi1keFhz?= =?us-ascii?B?QT09?= X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB1377;5:Gl0MT9a2s8JBws74AyWFJ3wdzytuNQQDyiWYgQWN3e3v+olABW3mq376TdqCpqP4+wKNwfBUyfEU1iY+1AjmG4AK2oK7f5S0sYJrryd9Oo6wF2m9EmQaBWGP+myJpoFtDX4GYqlcaVkhhIDTrj896A==;24:8Md/p5NFsnhOHKkKLwm5i9gjrDMst5joTDFCJCcZbwZZfJJPTspb4uLGecdzHjV/LgcE2H5qmmG8yqcVm6RiJgp6Runik7HRxmTcRswzDUc=;20:nRTLascse5E7vQSCErjLcOC4V9QUh/bcDx0jt73r4vJp3xxl4dwQfT/tdOQ4ziMPUhIhiyvRGYO5fYi0E0HCUQ== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Aug 2015 09:07:31.9176 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.158.2];Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR03MB1377 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 16220 Lines: 584 Freescale i.MX6UL contains a internal touchscreen controller, this patch add a driver to support this controller. Signed-off-by: Haibo Chen --- drivers/input/touchscreen/Kconfig | 12 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/imx6ul_tsc.c | 524 +++++++++++++++++++++++++++++++++ 3 files changed, 537 insertions(+) create mode 100644 drivers/input/touchscreen/imx6ul_tsc.c diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 059edeb..50a42b8 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig @@ -479,6 +479,18 @@ config TOUCHSCREEN_MTOUCH To compile this driver as a module, choose M here: the module will be called mtouch. +config TOUCHSCREEN_IMX6UL_TSC + tristate "Freescale i.MX6UL touchscreen controller" + depends on (OF && GPIOLIB) || COMPILE_TEST + help + Say Y here if you have a Freescale i.MX6UL, and want to + use the internal touchscreen controller. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + moduel will be called imx6ul_tsc. + config TOUCHSCREEN_INEXIO tristate "iNexio serial touchscreens" select SERIO diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index c85aae2..9379b32 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile @@ -38,6 +38,7 @@ obj-$(CONFIG_TOUCHSCREEN_EGALAX) += egalax_ts.o obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o obj-$(CONFIG_TOUCHSCREEN_GOODIX) += goodix.o obj-$(CONFIG_TOUCHSCREEN_ILI210X) += ili210x.o +obj-$(CONFIG_TOUCHSCREEN_IMX6UL_TSC) += imx6ul_tsc.o obj-$(CONFIG_TOUCHSCREEN_INEXIO) += inexio.o obj-$(CONFIG_TOUCHSCREEN_INTEL_MID) += intel-mid-touch.o obj-$(CONFIG_TOUCHSCREEN_IPROC) += bcm_iproc_tsc.o diff --git a/drivers/input/touchscreen/imx6ul_tsc.c b/drivers/input/touchscreen/imx6ul_tsc.c new file mode 100644 index 0000000..fe1d3d9 --- /dev/null +++ b/drivers/input/touchscreen/imx6ul_tsc.c @@ -0,0 +1,524 @@ +/* + * Freescale i.MX6UL touchscreen controller driver + * + * Copyright (C) 2015 Freescale Semiconductor, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* ADC configuration registers field define */ +#define ADC_AIEN (0x1 << 7) +#define ADC_CONV_DISABLE 0x1F +#define ADC_CAL (0x1 << 7) +#define ADC_CALF 0x2 +#define ADC_12BIT_MODE (0x2 << 2) +#define ADC_IPG_CLK 0x00 +#define ADC_CLK_DIV_8 (0x03 << 5) +#define ADC_SHORT_SAMPLE_MODE (0x0 << 4) +#define ADC_HARDWARE_TRIGGER (0x1 << 13) +#define SELECT_CHANNEL_4 0x04 +#define SELECT_CHANNEL_1 0x01 +#define DISABLE_CONVERSION_INT (0x0 << 7) + +/* ADC registers */ +#define REG_ADC_HC0 0x00 +#define REG_ADC_HC1 0x04 +#define REG_ADC_HC2 0x08 +#define REG_ADC_HC3 0x0C +#define REG_ADC_HC4 0x10 +#define REG_ADC_HS 0x14 +#define REG_ADC_R0 0x18 +#define REG_ADC_CFG 0x2C +#define REG_ADC_GC 0x30 +#define REG_ADC_GS 0x34 + +#define ADC_TIMEOUT msecs_to_jiffies(100) + +/* TSC registers */ +#define REG_TSC_BASIC_SETING 0x00 +#define REG_TSC_PRE_CHARGE_TIME 0x10 +#define REG_TSC_FLOW_CONTROL 0x20 +#define REG_TSC_MEASURE_VALUE 0x30 +#define REG_TSC_INT_EN 0x40 +#define REG_TSC_INT_SIG_EN 0x50 +#define REG_TSC_INT_STATUS 0x60 +#define REG_TSC_DEBUG_MODE 0x70 +#define REG_TSC_DEBUG_MODE2 0x80 + +/* TSC configuration registers field define */ +#define DETECT_4_WIRE_MODE (0x0 << 4) +#define AUTO_MEASURE 0x1 +#define MEASURE_SIGNAL 0x1 +#define DETECT_SIGNAL (0x1 << 4) +#define VALID_SIGNAL (0x1 << 8) +#define MEASURE_INT_EN 0x1 +#define MEASURE_SIG_EN 0x1 +#define VALID_SIG_EN (0x1 << 8) +#define DE_GLITCH_2 (0x2 << 29) +#define START_SENSE (0x1 << 12) +#define TSC_DISABLE (0x1 << 16) +#define DETECT_MODE 0x2 + +struct imx6ul_tsc { + struct device *dev; + struct input_dev *input; + void __iomem *tsc_regs; + void __iomem *adc_regs; + struct clk *tsc_clk; + struct clk *adc_clk; + struct gpio_desc *xnur_gpio; + + int measure_delay_time; + int pre_charge_time; + + struct completion completion; +}; + +/* + * TSC module need ADC to get the measure value. So + * before config TSC, we should initialize ADC module. + */ +static void imx6ul_adc_init(struct imx6ul_tsc *tsc) +{ + int adc_hc = 0; + int adc_gc; + int adc_gs; + int adc_cfg; + int timeout; + + reinit_completion(&tsc->completion); + + adc_cfg = readl(tsc->adc_regs + REG_ADC_CFG); + adc_cfg |= ADC_12BIT_MODE | ADC_IPG_CLK; + adc_cfg |= ADC_CLK_DIV_8 | ADC_SHORT_SAMPLE_MODE; + adc_cfg &= ~ADC_HARDWARE_TRIGGER; + writel(adc_cfg, tsc->adc_regs + REG_ADC_CFG); + + /* enable calibration interrupt */ + adc_hc |= ADC_AIEN; + adc_hc |= ADC_CONV_DISABLE; + writel(adc_hc, tsc->adc_regs + REG_ADC_HC0); + + /* start ADC calibration */ + adc_gc = readl(tsc->adc_regs + REG_ADC_GC); + adc_gc |= ADC_CAL; + writel(adc_gc, tsc->adc_regs + REG_ADC_GC); + + timeout = wait_for_completion_timeout + (&tsc->completion, ADC_TIMEOUT); + if (timeout == 0) + dev_err(tsc->dev, "Timeout for adc calibration\n"); + + adc_gs = readl(tsc->adc_regs + REG_ADC_GS); + if (adc_gs & ADC_CALF) + dev_err(tsc->dev, "ADC calibration failed\n"); + + /* TSC need the ADC work in hardware trigger */ + adc_cfg = readl(tsc->adc_regs + REG_ADC_CFG); + adc_cfg |= ADC_HARDWARE_TRIGGER; + writel(adc_cfg, tsc->adc_regs + REG_ADC_CFG); +} + +/* + * This is a TSC workaround. Currently TSC misconnect two + * ADC channels, this function remap channel configure for + * hardware trigger. + */ +static void imx6ul_tsc_channel_config(struct imx6ul_tsc *tsc) +{ + int adc_hc0, adc_hc1, adc_hc2, adc_hc3, adc_hc4; + + adc_hc0 = DISABLE_CONVERSION_INT; + writel(adc_hc0, tsc->adc_regs + REG_ADC_HC0); + + adc_hc1 = DISABLE_CONVERSION_INT | SELECT_CHANNEL_4; + writel(adc_hc1, tsc->adc_regs + REG_ADC_HC1); + + adc_hc2 = DISABLE_CONVERSION_INT; + writel(adc_hc2, tsc->adc_regs + REG_ADC_HC2); + + adc_hc3 = DISABLE_CONVERSION_INT | SELECT_CHANNEL_1; + writel(adc_hc3, tsc->adc_regs + REG_ADC_HC3); + + adc_hc4 = DISABLE_CONVERSION_INT; + writel(adc_hc4, tsc->adc_regs + REG_ADC_HC4); +} + +/* + * TSC setting, confige the pre-charge time and measure delay time. + * different touch screen may need different pre-charge time and + * measure delay time. + */ +static void imx6ul_tsc_set(struct imx6ul_tsc *tsc) +{ + int basic_setting = 0; + int start; + + basic_setting |= tsc->measure_delay_time << 8; + basic_setting |= DETECT_4_WIRE_MODE | AUTO_MEASURE; + writel(basic_setting, tsc->tsc_regs + REG_TSC_BASIC_SETING); + + writel(DE_GLITCH_2, tsc->tsc_regs + REG_TSC_DEBUG_MODE2); + + writel(tsc->pre_charge_time, tsc->tsc_regs + REG_TSC_PRE_CHARGE_TIME); + writel(MEASURE_INT_EN, tsc->tsc_regs + REG_TSC_INT_EN); + writel(MEASURE_SIG_EN | VALID_SIG_EN, + tsc->tsc_regs + REG_TSC_INT_SIG_EN); + + /* start sense detection */ + start = readl(tsc->tsc_regs + REG_TSC_FLOW_CONTROL); + start |= START_SENSE; + start &= ~TSC_DISABLE; + writel(start, tsc->tsc_regs + REG_TSC_FLOW_CONTROL); +} + +static void imx6ul_tsc_init(struct imx6ul_tsc *tsc) +{ + imx6ul_adc_init(tsc); + imx6ul_tsc_channel_config(tsc); + imx6ul_tsc_set(tsc); +} + +static void imx6ul_tsc_disable(struct imx6ul_tsc *tsc) +{ + int tsc_flow; + int adc_cfg; + + /* TSC controller enters to idle status */ + tsc_flow = readl(tsc->tsc_regs + REG_TSC_FLOW_CONTROL); + tsc_flow |= TSC_DISABLE; + writel(tsc_flow, tsc->tsc_regs + REG_TSC_FLOW_CONTROL); + + /* ADC controller enters to stop mode */ + adc_cfg = readl(tsc->adc_regs + REG_ADC_HC0); + adc_cfg |= ADC_CONV_DISABLE; + writel(adc_cfg, tsc->adc_regs + REG_ADC_HC0); +} + +static irqreturn_t tsc_irq_fn(int irq, void *dev_id) +{ + struct imx6ul_tsc *tsc = (struct imx6ul_tsc *)dev_id; + int status; + int value; + int x, y; + int debug_mode2; + int state_machine; + int start; + unsigned long timeout; + bool touch; + + status = readl(tsc->tsc_regs + REG_TSC_INT_STATUS); + + /* write 1 to clear the bit measure-signal */ + writel(MEASURE_SIGNAL | DETECT_SIGNAL, + tsc->tsc_regs + REG_TSC_INT_STATUS); + + /* It's a HW self-clean bit. Set this bit and start sense detection */ + start = readl(tsc->tsc_regs + REG_TSC_FLOW_CONTROL); + start |= START_SENSE; + writel(start, tsc->tsc_regs + REG_TSC_FLOW_CONTROL); + + if (status & MEASURE_SIGNAL) { + value = readl(tsc->tsc_regs + REG_TSC_MEASURE_VALUE); + x = (value >> 16) & 0x0fff; + y = value & 0x0fff; + + /* + * Delay some time(max 2ms), wait the pre-charge done. + * After the pre-change mode, TSC go into detect mode. + * And in detect mode, we can get the xnur gpio value. + * If xnur is high, this means the touch screen still + * be touched. If xnur is low, this means finger leave + * the touch screen. + */ + timeout = jiffies + HZ/500; + do { + if (time_after(jiffies, timeout)) { + touch = true; + goto report_touch; + } + usleep_range(200, 400); + debug_mode2 = readl(tsc->tsc_regs + REG_TSC_DEBUG_MODE2); + state_machine = (debug_mode2 >> 20) & 0x7; + } while (state_machine != DETECT_MODE); + usleep_range(200, 400); + + touch = gpiod_get_value_cansleep(tsc->xnur_gpio); +report_touch: + if (touch) { + input_report_key(tsc->input, BTN_TOUCH, 1); + input_report_abs(tsc->input, ABS_X, x); + input_report_abs(tsc->input, ABS_Y, y); + } else { + input_report_key(tsc->input, BTN_TOUCH, 0); + } + + input_sync(tsc->input); + } + + return IRQ_HANDLED; +} + +static irqreturn_t adc_irq_fn(int irq, void *dev_id) +{ + struct imx6ul_tsc *tsc = dev_id; + int coco; + int value; + + coco = readl(tsc->adc_regs + REG_ADC_HS); + if (coco & 0x01) { + value = readl(tsc->adc_regs + REG_ADC_R0); + complete(&tsc->completion); + } + + return IRQ_HANDLED; +} + +static int imx6ul_tsc_open(struct input_dev *input_dev) +{ + struct imx6ul_tsc *tsc = input_get_drvdata(input_dev); + int err; + + err = clk_prepare_enable(tsc->adc_clk); + if (err) { + dev_err(tsc->dev, + "Could not prepare or enable the adc clock: %d\n", + err); + return err; + } + + err = clk_prepare_enable(tsc->tsc_clk); + if (err) { + dev_err(tsc->dev, + "Could not prepare or enable the tsc clock: %d\n", + err); + clk_disable_unprepare(tsc->adc_clk); + return err; + } + + imx6ul_tsc_init(tsc); + + return 0; +} + +static void imx6ul_tsc_close(struct input_dev *input_dev) +{ + struct imx6ul_tsc *tsc = input_get_drvdata(input_dev); + + imx6ul_tsc_disable(tsc); + + clk_disable_unprepare(tsc->tsc_clk); + clk_disable_unprepare(tsc->adc_clk); +} + +static int imx6ul_tsc_probe(struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + struct imx6ul_tsc *tsc; + struct input_dev *input_dev; + struct resource *tsc_mem; + struct resource *adc_mem; + int err; + int tsc_irq; + int adc_irq; + + tsc = devm_kzalloc(&pdev->dev, sizeof(struct imx6ul_tsc), GFP_KERNEL); + if (!tsc) + return -ENOMEM; + + input_dev = devm_input_allocate_device(&pdev->dev); + if (!input_dev) + return -ENOMEM; + + input_dev->name = "iMX6UL TouchScreen Controller"; + input_dev->id.bustype = BUS_HOST; + + input_dev->open = imx6ul_tsc_open; + input_dev->close = imx6ul_tsc_close; + + input_set_capability(input_dev, EV_KEY, BTN_TOUCH); + input_set_abs_params(input_dev, ABS_X, 0, 0xFFF, 0, 0); + input_set_abs_params(input_dev, ABS_Y, 0, 0xFFF, 0, 0); + + input_set_drvdata(input_dev, tsc); + + tsc->dev = &pdev->dev; + tsc->input = input_dev; + init_completion(&tsc->completion); + + tsc->xnur_gpio = devm_gpiod_get(&pdev->dev, "xnur", GPIOD_IN); + if (IS_ERR(tsc->xnur_gpio)) { + err = PTR_ERR(tsc->xnur_gpio); + dev_err(&pdev->dev, + "failed to request GPIO tsc_X- (xnur): %d\n", err); + return err; + } + + tsc_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); + tsc->tsc_regs = devm_ioremap_resource(&pdev->dev, tsc_mem); + if (IS_ERR(tsc->tsc_regs)) { + err = PTR_ERR(tsc->tsc_regs); + dev_err(&pdev->dev, "failed to remap tsc memory: %d\n", err); + return err; + } + + adc_mem = platform_get_resource(pdev, IORESOURCE_MEM, 1); + tsc->adc_regs = devm_ioremap_resource(&pdev->dev, adc_mem); + if (IS_ERR(tsc->adc_regs)) { + err = PTR_ERR(tsc->adc_regs); + dev_err(&pdev->dev, "failed to remap adc memory: %d\n", err); + return err; + } + + tsc->tsc_clk = devm_clk_get(&pdev->dev, "tsc"); + if (IS_ERR(tsc->tsc_clk)) { + err = PTR_ERR(tsc->tsc_clk); + dev_err(&pdev->dev, "failed getting tsc clock: %d\n", err); + return err; + } + + tsc->adc_clk = devm_clk_get(&pdev->dev, "adc"); + if (IS_ERR(tsc->adc_clk)) { + err = PTR_ERR(tsc->adc_clk); + dev_err(&pdev->dev, "failed getting adc clock: %d\n", err); + return err; + } + + tsc_irq = platform_get_irq(pdev, 0); + if (tsc_irq < 0) { + dev_err(&pdev->dev, "no tsc irq resource?\n"); + return tsc_irq; + } + + adc_irq = platform_get_irq(pdev, 1); + if (adc_irq <= 0) { + dev_err(&pdev->dev, "no adc irq resource?\n"); + return adc_irq; + } + + err = devm_request_threaded_irq(tsc->dev, tsc_irq, + NULL, tsc_irq_fn, IRQF_ONESHOT, + dev_name(&pdev->dev), tsc); + if (err) { + dev_err(&pdev->dev, + "failed requesting tsc irq %d: %d\n", + tsc_irq, err); + return err; + } + + err = devm_request_irq(tsc->dev, adc_irq, adc_irq_fn, 0, + dev_name(&pdev->dev), tsc); + if (err) { + dev_err(&pdev->dev, + "failed requesting adc irq %d: %d\n", + adc_irq, err); + return err; + } + + err = of_property_read_u32(np, "measure-delay-time", + &tsc->measure_delay_time); + if (err) + tsc->measure_delay_time = 0xffff; + + err = of_property_read_u32(np, "pre-charge-time", + &tsc->pre_charge_time); + if (err) + tsc->pre_charge_time = 0xfff; + + err = input_register_device(tsc->input); + if (err) { + dev_err(&pdev->dev, + "failed to register input device: %d\n", err); + return err; + } + + platform_set_drvdata(pdev, tsc); + return 0; +} + +static int __maybe_unused imx6ul_tsc_suspend(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct imx6ul_tsc *tsc = platform_get_drvdata(pdev); + struct input_dev *input_dev = tsc->input; + + mutex_lock(&input_dev->mutex); + + if (input_dev->users) { + imx6ul_tsc_disable(tsc); + + clk_disable_unprepare(tsc->tsc_clk); + clk_disable_unprepare(tsc->adc_clk); + } + + mutex_unlock(&input_dev->mutex); + + return 0; +} + +static int __maybe_unused imx6ul_tsc_resume(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct imx6ul_tsc *tsc = platform_get_drvdata(pdev); + struct input_dev *input_dev = tsc->input; + int retval = 0; + + mutex_lock(&input_dev->mutex); + + if (input_dev->users) { + retval = clk_prepare_enable(tsc->adc_clk); + if (retval) + goto out; + + retval = clk_prepare_enable(tsc->tsc_clk); + if (retval) { + clk_disable_unprepare(tsc->adc_clk); + goto out; + } + + imx6ul_tsc_init(tsc); + } + +out: + mutex_unlock(&input_dev->mutex); + return retval; +} + +static SIMPLE_DEV_PM_OPS(imx6ul_tsc_pm_ops, + imx6ul_tsc_suspend, imx6ul_tsc_resume); + +static const struct of_device_id imx6ul_tsc_match[] = { + { .compatible = "fsl,imx6ul-tsc", }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, imx6ul_tsc_match); + +static struct platform_driver imx6ul_tsc_driver = { + .driver = { + .name = "imx6ul-tsc", + .of_match_table = imx6ul_tsc_match, + .pm = &imx6ul_tsc_pm_ops, + }, + .probe = imx6ul_tsc_probe, +}; +module_platform_driver(imx6ul_tsc_driver); + +MODULE_AUTHOR("Haibo Chen "); +MODULE_DESCRIPTION("Freescale i.MX6UL Touchscreen controller driver"); +MODULE_LICENSE("GPL v2"); -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/