Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752311AbbG0LjR (ORCPT ); Mon, 27 Jul 2015 07:39:17 -0400 Received: from mail-bn1bbn0103.outbound.protection.outlook.com ([157.56.111.103]:62620 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751244AbbG0LjN (ORCPT ); Mon, 27 Jul 2015 07:39:13 -0400 X-Greylist: delayed 908 seconds by postgrey-1.27 at vger.kernel.org; Mon, 27 Jul 2015 07:39:12 EDT Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; vger.kernel.org; dkim=none (message not signed) header.d=none; From: Haibo Chen To: , , , , , , , , CC: , , , , , , , , , , , , , , , , , Subject: [PATCH 1/5] input: touchscreen: add imx6ul_tsc driver support Date: Mon, 27 Jul 2015 19:26:43 +0800 Message-ID: <1437996407-27266-2-git-send-email-haibo.chen@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1437996407-27266-1-git-send-email-haibo.chen@freescale.com> References: <1437996407-27266-1-git-send-email-haibo.chen@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BN1BFFO11FD018;1:pjrAGjlGr9Tpg3/OeYDqvouQvXcN8yT2Uo/hQ+gp7Z1iFXthELOWW7Xj+Ir/2nOA4+dUPDaMYashTS+QdyUL31BX0LMCZms4ui8qh/Wej59jg6go7AuGnM7sqFqwkNgDlFO4xeNzOIypWhV2UHGmG5YHZ5h5kxKZUuOZRC1WAOsPRlI4MLvlL839b13MLf8et8M9Qaz1czj/gQybbmb42Ej2/idZXMalQc1iMsYafjBeGm8W4SaOYXxNs+8bOt3c9i10fijwc+Ab4SRgckgzbgF9jrUMnM8tBoh51fHAuiDNf9WFhMH0w3vmGM4QgmVp7caHjO/mNR9pRwMZgeFKGg== X-Forefront-Antispam-Report: CIP:192.88.158.2;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(339900001)(189002)(199003)(2201001)(47776003)(92566002)(50226001)(19580395003)(76176999)(50466002)(77096005)(5001770100001)(189998001)(19580405001)(6806004)(62966003)(2950100001)(46102003)(50986999)(48376002)(106466001)(36756003)(105606002)(575784001)(77156002)(33646002)(5001960100002)(5003940100001)(87936001)(86362001)(229853001)(104016003)(85426001)(7059030);DIR:OUT;SFP:1102;SCL:1;SRVR:BLUPR03MB1379;H:az84smr01.freescale.net;FPR:;SPF:Fail;MLV:sfv;MX:1;A:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB1379;2:XVnGWPF6c5f7KwYPb6KkKJR/OHKOmOZXn31TYo+b/sGGbui87NgmOnxAsc/ZTjLoi0JsG07u++bq2tNUAtZH1jSiuZ0SNegkKaW4WQIiGDVn58kO0eizhv/45ICp1q6HE7nA2Ry0QyseeQL9/ixXwoJ+4V34uFbD60pgMoydb4I=;3:HWvQoxc/UbKELmEAc3NO6aSt1PK4uRHE+t7uw1lP9NUKrX8FYoZaMa8ICOns+eVRN4dLRJ0srYRPBXL4XjQXuszNpmjzRmkM7QHK84lO3c27qltZ1xr4VvKhn1JMKlwg6DmmQ+f7uvQytXoxMBTVeF1YV5/fCIpBPRIKSZMYVXLdm8YtbFirguf6v4bbmtQ2AtQ/rmg+Hwafv6t9dzlWEon8Li4WlQsIhFBeP4EahXs=;25:IKI75wrT5uFs9tfgM6NqErXMUyv2Vrs4fH1/2gWHW4/J7wl6hSkaHvb//uihBB4a0BOgdH0k8gep50ikvLA68ID+74S0jiEWI9G4is1/FPHI6C99kHmHGu2Yr4K4FNpjqj6VMjqdkoBtF3G4PQTnI42ZGvCI1JQtUwmJMKiycDedXyF24fThrZ6cS68OFg1tNwnWYE/RHfm/ec+hLpc2qP2n+5nGTQGNStfAQQF0DsjRzkyJcQGlsoV6i6e3NxhkirR+hDU+FiQXi79t7T3g4A== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB1379;UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB167; X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB1379;20:tebGFRiusjDmOHJnnBJpo8b7SMnbGyV3TDqFuQDi1KsAO02sPgodBOKOIAXcEfX6YjuFC+1d9S+ME6MjLZPHLhawqqvYW2l7Nn//hdw8O0e1pKzdKTyhipaAYYXP6UsK/aCG3hBXEjbaxDlHejyMAWbPECLRzQscO0P1w23WwDyJaRqHqx/t5bATnwQKRYoiQGlG9IHHwrq4wlnXKFr/5oNIMN5XN1DA2qxJ1EC2oze6HeR5Z56/mJ3GgCobq5jINVKh5HTKaA7zDLljCGz4n+w8vtDLTM+MTuIQig12gP5MvSJUhPj5Km+tqoNpeowsJbhabRTdBfO0e+fAI1cT+iIklY3I3KcAr1vla3obIko=;4:M1FkxwNX8K+B0WX/y9/5sT4lTsK+L0Ve47bAbkpQbY7JAmdK30dH+I+h3+td8ombNBVpkdZvyHBm3VJAQh9qKt/7qA8hbfdjYFxUQowdtgcthU9OqIIojFCePjarIOo8kWd3YmpmCe7OkTAJ1NCv3/wLJ55W1Uoiozlj/Fa9kD5ZDemqD4d1wxIqLvnBuL9+etSh7gV4vZzx8Cjh1H8nGCyZ/ATnHk3vjm1o41PHpXQlKPfqxLSiO/hB6ZHiKxg+Dv0dB/8isqpzE3DW1YnoHd3ZEIbtH6qdYeUx1OlhYF0= BLUPR03MB1379: X-MS-Exchange-Organization-RulesExecuted X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(3002001);SRVR:BLUPR03MB1379;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB1379; X-Forefront-PRVS: 0650714AAA X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BLUPR03MB1379;23:ghjOKlAdvKvQ9VxlSXdfUczMDF+tufql8bgml6fqQ?= =?us-ascii?Q?ncYXGxHMXiPFfX157qkezScIf9cJaskTYAMdxbJQUplqSBkSU6vVcoBNsYdA?= =?us-ascii?Q?ACn9nvsoHRwHzlLvhOYTiEye5VQLUCy5SrtyKy51rztxq98gIi4j5Uz7f3+t?= =?us-ascii?Q?xvCR0BWvyEm7AevLPRMYGTO0rWhjoC41DzZNH1UR2My9noY6uqZjaUHKCUZU?= =?us-ascii?Q?HOg1szldR1va3ydMBmaqrzUgEOHl+r8D889kmHxOBCEtfAjjVs44TLjw45cy?= =?us-ascii?Q?8d7cuvMI6xQAk3e0xb0QAqWM1Qdee1EDFk8S2TNO6EJVkoZQQ5pjAYyELH2h?= =?us-ascii?Q?30kAzWhCBvdjI6PyLycUCFzOZdsZSeurz0VcZdW8Y+3KIBkvndFCzMqtnNUQ?= =?us-ascii?Q?XEAGCtzoEhFLH53AVcFUfsGzx4tNf8oQcaxs666C5WyBQAVj9GO0LCyYXeep?= =?us-ascii?Q?Lw0csYUGY+AWgeKf6nG378e/wgZNjIsxahMu/mHToq5AlbfadYKvu0jITzhe?= =?us-ascii?Q?vMe3YtpJRLSjX4m7QrKKKwYYDjH8TJdotdHJkp6ZUaoOkEmFaEBICPus9+dg?= =?us-ascii?Q?p57f/JTTHKm+S/QswQIARlyCA2SpRIVNsuObJBBRJ5HC3CoVNvUBMmujLJMI?= =?us-ascii?Q?YSfbmjioHS3UFmscstLPs2PO6FtUhwbFyWjmDZqbE+Zv1TtixX8UawUp4VsX?= =?us-ascii?Q?73D0me5XfyjjZnfV/UTihlw1UsINk+DT27afAoj0AfeGhDACU6uhcp75dWFV?= =?us-ascii?Q?HxPA9gKPTu6O8BIGWFl39KxhkQML60Aj7bcIioS7d0WLwAcPiQXkOv4SlzNo?= =?us-ascii?Q?pbMsUKj68jY/h3igu94qkB0vXJEba83UKcgVviUFrwqXNtRwkaGmvfYl8bIn?= =?us-ascii?Q?Xpj9prKu69BsowOwA0rkWOn0et5lHlrTnJIa6NzbyrlTvEJgRnHxaaQn7L5l?= =?us-ascii?Q?5UpVI5NIBU2Blb+XjomqVjywBswWl4Yh65VaMAZew=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB1379;5:C6E6xjiYZw/aCgy3ISft4kf+hk3RxUzcwURfFfr6JdvLBp4nWayNsurF5tUwwJcQsyH8FkJyosPtYn0Em6p1nClAWuIH4B7hIuKlEhVm5Hsp+/MrYZwWcLuvgLFIrIGPpstDEMsbj77igE604llwUQ==;24:NIg2uWgqXjFfVPgy+0A8XJZ++YNKG+cvy4nWMRBfsDM6zVljihT/ky6cCpzwq94IQTWCpYZobWFrU++s7Sb7tsOq8gBh9cJ9XWSGlUBVVgQ=;20:bOW16hSoDJBbblicZ3gdte9JGQzt6H/+vJoWlonTwY6jSQlAtlxpfaAZBPzsx8iImUkLTWh/TCcngRo/JRuvrg== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2015 11:23:57.9703 (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: BLUPR03MB1379 X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB167;2:q8OmwYeiBqwKCxTBzDLAOOcWuWs3v7YG0rgA+YE3eRcC6NAiXQIFlVFl8DVw0CHl;3:deC3mNMijcIAuolue5NaxkGWBzsyQmVhoX3Xalw03prnPS/wE1aHN50r3n/kCNqvXzKgGosSGgn2x0ser9z+S51av6Dx1Oj17wNinfsC6VGfOQneSk8h9FK4keuSBypZe7BKCssc1f4nfWJmxwsMqFrHLyxM1J67rDdgpPd2VAf4Z9WPiJBu+5UxMPlJFibqRDI8LYYV4urdkYfK62/bAZjWyXjbelZ59dcUAqMCenY=;25:RHCwVhU49jStPK2gqqxLwVBd3cEnc1WhRjgBi2G6zHj1X+09zp4lmPHwXmwZZX7YZ2n+mKo2+fw4qE4pKqtek/N4V4gpvlwS+k8KQ6LRirR6Z3T6Djwq547lg7kQJ/bfyrOu+QAYiz+uWug2bJKlEElaStOWlXU8QPcekT4mR66rJZPEDI0dW89Ua0WpeOz3E1GMsSb2SQ+DW4HJAmlZjjZFUgtT7dyHcFHKKgW/vjL4x7tBouhadFBrvuDj5dn6uM5uwDY9Fy2CAQWFbrFv+Q==;23:7yFR20oQYSmZHIzDBzevvR4BWBxxFRHR6abBNkff9wCBzs0Ht12kq3qKRtupSR+CYSop+UwL0w1n2i1XReykHjPeXvOJdwZxQE1mINV6S++ImBAUTh80ufHPT4/uWdkgbBAgf+f4rBNKAolRdF1uTumWZL0gPvtxDKUkOutOHfQsuQg4fMhiA48bCMhxyvPGssb7hNI+b0IfUjKi9e0clxsBcdgYYzzkQIDz7ZS6jGqx0eaVjqkX+umocqKhwaJT X-OriginatorOrg: freescale.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 15955 Lines: 570 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 | 510 +++++++++++++++++++++++++++++++++ 3 files changed, 523 insertions(+) create mode 100644 drivers/input/touchscreen/imx6ul_tsc.c diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 5b272ba..32c300d 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 + 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..5a5a368 --- /dev/null +++ b/drivers/input/touchscreen/imx6ul_tsc.c @@ -0,0 +1,510 @@ +/* + * 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 +#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; + + int tsc_irq; + int adc_irq; + int value; + int 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; + + 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 irqreturn_t tsc_irq(int irq, void *dev_id) +{ + struct imx6ul_tsc *tsc = (struct imx6ul_tsc *)dev_id; + int status; + int x, y; + int xnur; + int debug_mode2; + int state_machine; + int start; + unsigned long timeout; + + 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) { + tsc->value = readl(tsc->tsc_regs + REG_TSC_MEASURE_VALUE); + x = (tsc->value >> 16) & 0x0fff; + y = tsc->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 low, this means the touch screen still + * be touched. If xnur is high, this means finger leave + * the touch screen. + */ + timeout = jiffies + HZ/500; + do { + if (time_after(jiffies, timeout)) { + xnur = 0; + goto touch_event; + } + 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); + + xnur = gpio_get_value(tsc->xnur_gpio); +touch_event: + if (xnur == 0) { + 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(int irq, void *dev_id) +{ + struct imx6ul_tsc *tsc = (struct imx6ul_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 const struct of_device_id imx6ul_tsc_match[] = { + { .compatible = "fsl,imx6ul-tsc", }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, imx6ul_tsc_match); + +static int imx6ul_tsc_probe(struct platform_device *pdev) +{ + struct imx6ul_tsc *tsc; + struct resource *tsc_mem; + struct resource *adc_mem; + struct input_dev *input_dev; + struct device_node *np = pdev->dev.of_node; + int err; + + tsc = kzalloc(sizeof(struct imx6ul_tsc), GFP_KERNEL); + if (!tsc) { + err = -ENOMEM; + goto err_free_mem_tsc; + } + + input_dev = input_allocate_device(); + if (!input_dev) { + err = -ENOMEM; + goto err_free_mem; + } + + tsc->dev = &pdev->dev; + + tsc->input = input_dev; + tsc->input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); + tsc->input->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); + input_set_abs_params(tsc->input, ABS_X, 0, 0xFFF, 0, 0); + input_set_abs_params(tsc->input, ABS_Y, 0, 0xFFF, 0, 0); + + tsc->input->name = "iMX6UL TouchScreen Controller"; + + tsc->xnur_gpio = of_get_named_gpio(np, "xnur-gpio", 0); + err = gpio_request_one(tsc->xnur_gpio, GPIOF_IN, "tsc_X-"); + if (err) { + dev_err(&pdev->dev, "failed to request GPIO tsc_X-\n"); + goto err_free_mem; + } + + 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)) { + dev_err(&pdev->dev, "failed to remap tsc memory\n"); + err = PTR_ERR(tsc->tsc_regs); + goto err_free_mem; + } + + 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)) { + dev_err(&pdev->dev, "failed to remap adc memory\n"); + err = PTR_ERR(tsc->adc_regs); + goto err_free_mem; + } + + tsc->tsc_clk = devm_clk_get(&pdev->dev, "tsc"); + if (IS_ERR(tsc->tsc_clk)) { + dev_err(&pdev->dev, "failed getting tsc clock\n"); + err = PTR_ERR(tsc->tsc_clk); + goto err_free_mem; + } + + tsc->adc_clk = devm_clk_get(&pdev->dev, "adc"); + if (IS_ERR(tsc->adc_clk)) { + dev_err(&pdev->dev, "failed getting adc clock\n"); + err = PTR_ERR(tsc->adc_clk); + goto err_free_mem; + } + + tsc->tsc_irq = platform_get_irq(pdev, 0); + if (tsc->tsc_irq <= 0) { + dev_err(&pdev->dev, "no tsc irq resource?\n"); + err = -EINVAL; + goto err_free_mem; + } + + tsc->adc_irq = platform_get_irq(pdev, 1); + if (tsc->adc_irq <= 0) { + dev_err(&pdev->dev, "no adc irq resource?\n"); + err = -EINVAL; + goto err_free_mem; + } + + err = devm_request_threaded_irq(tsc->dev, tsc->tsc_irq, + NULL, tsc_irq, + IRQF_TRIGGER_HIGH | IRQF_ONESHOT, + dev_name(&pdev->dev), tsc); + if (err < 0) { + dev_err(&pdev->dev, + "failed requesting tsc irq %d\n", + tsc->tsc_irq); + goto err_free_mem; + } + + err = devm_request_irq(tsc->dev, tsc->adc_irq, + adc_irq, 0, + dev_name(&pdev->dev), tsc); + if (err < 0) { + dev_err(&pdev->dev, + "failed requesting adc irq %d\n", + tsc->adc_irq); + goto err_free_mem; + } + + 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; + + init_completion(&tsc->completion); + + err = clk_prepare_enable(tsc->adc_clk); + if (err) { + dev_err(&pdev->dev, + "Could not prepare or enable the adc clock.\n"); + goto err_free_mem; + } + + err = clk_prepare_enable(tsc->tsc_clk); + if (err) { + dev_err(&pdev->dev, + "Could not prepare or enable the tsc clock.\n"); + goto error_tsc_clk_enable; + } + + err = input_register_device(tsc->input); + if (err < 0) { + dev_err(&pdev->dev, "failed to register input device\n"); + err = -EIO; + goto err_input_register; + } + + imx6ul_tsc_init(tsc); + + platform_set_drvdata(pdev, tsc); + return 0; + +err_input_register: + clk_disable_unprepare(tsc->tsc_clk); +error_tsc_clk_enable: + clk_disable_unprepare(tsc->adc_clk); +err_free_mem: + input_free_device(tsc->input); +err_free_mem_tsc: + kfree(tsc); + return err; +} + +static int imx6ul_tsc_remove(struct platform_device *pdev) +{ + struct imx6ul_tsc *tsc = platform_get_drvdata(pdev); + + clk_disable_unprepare(tsc->tsc_clk); + clk_disable_unprepare(tsc->adc_clk); + input_unregister_device(tsc->input); + kfree(tsc); + + return 0; +} + +#ifdef CONFIG_PM_SLEEP +static int imx6ul_tsc_suspend(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct imx6ul_tsc *tsc = platform_get_drvdata(pdev); + 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); + + clk_disable_unprepare(tsc->tsc_clk); + clk_disable_unprepare(tsc->adc_clk); + + return 0; +} + +static int imx6ul_tsc_resume(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct imx6ul_tsc *tsc = platform_get_drvdata(pdev); + int err; + + err = clk_prepare_enable(tsc->adc_clk); + if (err) + return err; + + err = clk_prepare_enable(tsc->tsc_clk); + if (err) + return err; + + imx6ul_tsc_init(tsc); + return 0; +} +#endif + +static SIMPLE_DEV_PM_OPS(imx6ul_tsc_pm_ops, + imx6ul_tsc_suspend, + imx6ul_tsc_resume); + +static struct platform_driver imx6ul_tsc_driver = { + .driver = { + .name = "imx6ul-tsc", + .owner = THIS_MODULE, + .of_match_table = imx6ul_tsc_match, + .pm = &imx6ul_tsc_pm_ops, + }, + .probe = imx6ul_tsc_probe, + .remove = imx6ul_tsc_remove, +}; +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/