From patchwork Thu Sep 19 08:38:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 2910241 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1D0EE9F1E1 for ; Thu, 19 Sep 2013 08:38:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9E4E520413 for ; Thu, 19 Sep 2013 08:38:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 74D7B20412 for ; Thu, 19 Sep 2013 08:38:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752021Ab3ISIit (ORCPT ); Thu, 19 Sep 2013 04:38:49 -0400 Received: from mail-pd0-f174.google.com ([209.85.192.174]:61059 "EHLO mail-pd0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751902Ab3ISIiq (ORCPT ); Thu, 19 Sep 2013 04:38:46 -0400 Received: by mail-pd0-f174.google.com with SMTP id y13so8096496pdi.5 for ; Thu, 19 Sep 2013 01:38:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=lYorzWbsJjXVE9S07riC4d3ze0dGB+WH6eNAX9a8Oj0=; b=EUqSVF1K2s6WZhwJqBx5zLPNJpwl5yDTyJ3EtaAPOT47uxD33JsvVNTFJDg1nr6WUJ hKKunjhrl12gruocBKpx0aHLEuLW/C3bVHSFqgeiCQ7b+p8u+ETbUgGafSiAqImwTIAu GvTs8k/FdLSN0FFokZhhFE36HGcQm7jMQILABSoZsfb1maKYGAEkj8MK1zb4jqmnCl2H /YQqdz8Z2lpah3N/fhYqqQM7NYN5GBiO44ZFaSDGLCKyezdFGokgsbegsVDiTckYZclf vQh+0Sjiowi1z7gxFjz8SkjxhrT/Nj00L0fqqHZNI4Tmeru/RDR2f1bilpbZECSq7NyJ xV3A== X-Received: by 10.66.132.69 with SMTP id os5mr1313139pab.114.1379579926014; Thu, 19 Sep 2013 01:38:46 -0700 (PDT) Received: from localhost.localdomain ([101.44.39.104]) by mx.google.com with ESMTPSA id im2sm7712750pbd.31.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 19 Sep 2013 01:38:45 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: dmitry.torokhov@gmail.com, dtor@mail.ru Cc: linux-input@vger.kernel.org, workgroup.linux@csr.com, Lisai Wang , Qipan Li , Barry Song Subject: [PATCH] input: touchscreen: add driver for Pixcir Tango C series capacitive touchscreen Date: Thu, 19 Sep 2013 16:38:31 +0800 Message-Id: <1379579911-9763-1-git-send-email-Baohua.Song@csr.com> X-Mailer: git-send-email 1.8.2.3 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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 From: Lisai Wang Pixcir Tango C series touchscreen support true multi-touch for 5 fingers. this patch adds a driver for it. Signed-off-by: Lisai Wang Signed-off-by: Qipan Li Signed-off-by: Barry Song --- drivers/input/touchscreen/Kconfig | 10 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/pixcir_tangoc_ts.c | 242 ++++++++++++++++++++++++++ 3 files changed, 253 insertions(+), 0 deletions(-) create mode 100644 drivers/input/touchscreen/pixcir_tangoc_ts.c diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index e09ec67..2b80df6 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig @@ -919,4 +919,14 @@ config TOUCHSCREEN_TPS6507X To compile this driver as a module, choose M here: the module will be called tps6507x_ts. +config TOUCHSCREEN_TANGOC + tristate "PIXCIR TANGOC touchscreen" + depends on I2C + help + Say Y here if you support PIXCIR TangoC touchscreen + controller + + If unsure, Say N. + To compile this driver as a module, choose M here. + endif diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index f5216c1..ef73c06 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile @@ -75,3 +75,4 @@ obj-$(CONFIG_TOUCHSCREEN_WM97XX_MAINSTONE) += mainstone-wm97xx.o obj-$(CONFIG_TOUCHSCREEN_WM97XX_ZYLONITE) += zylonite-wm97xx.o obj-$(CONFIG_TOUCHSCREEN_W90X900) += w90p910_ts.o obj-$(CONFIG_TOUCHSCREEN_TPS6507X) += tps6507x-ts.o +obj-$(CONFIG_TOUCHSCREEN_TANGOC) += pixcir_tangoc_ts.o diff --git a/drivers/input/touchscreen/pixcir_tangoc_ts.c b/drivers/input/touchscreen/pixcir_tangoc_ts.c new file mode 100644 index 0000000..8274917 --- /dev/null +++ b/drivers/input/touchscreen/pixcir_tangoc_ts.c @@ -0,0 +1,242 @@ +/* +* Pixcir Tango C series 5 points touch controller Driver +* +* Copyright (c) 2013 Cambridge Silicon Radio Limited, a CSR plc group company. +* +* Licensed under GPLv2 or later. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define TOUCHSCREEN_MINX 0 +#define TOUCHSCREEN_MAXX 1024 +#define TOUCHSCREEN_MINY 0 +#define TOUCHSCREEN_MAXY 600 +#define TOUCH_MAJOR_MAX 50 +#define WIDTH_MAJOR_MAX 15 +#define TRACKING_ID_MAX 5 + +struct pixcir_ts_point_data { + u16 posx; /* x coordinate */ + u16 posy; /* y coordinate */ + u8 id; /* finger ID */ +} __packed; + +struct pixcir_ts_touch_data { + u16 touch_fingers; + struct pixcir_ts_point_data point[5]; +} __packed; + +struct pixcir_ts_data { + struct i2c_client *client; + struct input_dev *input_dev; + unsigned int touch_pin; + struct pixcir_ts_touch_data touch_data; +}; + +/*Report the touch position*/ +static void pixcir_ts_report_event(struct pixcir_ts_data *ts) +{ + int ret, i; + int fingers; + u8 addr; + + addr = 0; + ret = i2c_master_send(ts->client, &addr, sizeof(addr)); + if (ret != sizeof(addr)) { + dev_err(&ts->client->dev, + "pixcir_ts:Unable to reset pixcir_ts!\n"); + return; + } + + ret = i2c_master_recv(ts->client, (char *)&ts->touch_data, + sizeof(struct pixcir_ts_touch_data)); + if (ret != sizeof(struct pixcir_ts_touch_data)) { + dev_err(&ts->client->dev, + "pixcir_ts:Unable get the touch info\n"); + return; + } + + fingers = ts->touch_data.touch_fingers & 0x07; + if (fingers > 0) { + for (i = 0; i < fingers; i++) { + /*Get the touch position*/ + input_report_abs(ts->input_dev, ABS_MT_POSITION_X, + ts->touch_data.point[i].posx); + input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, + ts->touch_data.point[i].posy); + + input_report_key(ts->input_dev, ABS_MT_TRACKING_ID, + ts->touch_data.point[i].id); + input_report_abs(ts->input_dev, + ABS_MT_TOUCH_MAJOR, TOUCH_MAJOR_MAX); + input_report_abs(ts->input_dev, + ABS_MT_WIDTH_MAJOR, WIDTH_MAJOR_MAX); + input_mt_sync(ts->input_dev); + } + } else + input_mt_sync(ts->input_dev); + + input_sync(ts->input_dev); +} + +static irqreturn_t pixcir_ts_irq_handler(int irq, void *dev_id) +{ + struct pixcir_ts_data *ts = dev_id; + + pixcir_ts_report_event(ts); + + return IRQ_HANDLED; +} + +#ifdef CONFIG_PM_SLEEP +static int pixcir_ts_suspend(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + + if (device_may_wakeup(&client->dev)) + enable_irq_wake(client->irq); + + return 0; +} + +static int pixcir_ts_resume(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + + if (device_may_wakeup(&client->dev)) + disable_irq_wake(client->irq); + + return 0; +} + +static SIMPLE_DEV_PM_OPS(pixcir_dev_pm_ops, + pixcir_ts_suspend, pixcir_ts_resume); +#endif + +static int pixcir_ts_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct pixcir_ts_data *ts; + struct input_dev *input_dev; + struct device_node *np = client->dev.of_node; + u8 tmp = 0; + int ret; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) + return -ENODEV; + + ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL); + if (!ts) + return -ENOMEM; + ts->client = client; + i2c_set_clientdata(client, ts); + + ts->touch_pin = of_get_named_gpio(np, "touch-gpio", 0); + if (!gpio_is_valid(ts->touch_pin)) { + dev_err(&client->dev, "invalid touch_pin supplied\n"); + return -EINVAL; + } + client->irq = gpio_to_irq(ts->touch_pin); + + input_dev = input_allocate_device(); + if (!input_dev) { + ret = -ENOMEM; + goto err_free_mem; + } + + /* if the client exists, this i2c transfer should be ok */ + ret = i2c_master_send(ts->client, &tmp, 1); + if (ret != 1) + goto err_free_mem; + + i2c_set_clientdata(client, ts); + input_set_drvdata(input_dev, ts); + input_dev->name = "tangoc-touchscreen"; + input_dev->id.bustype = BUS_I2C; + input_dev->dev.parent = &client->dev; + set_bit(EV_SYN, input_dev->evbit); + set_bit(EV_ABS, input_dev->evbit); + set_bit(ABS_MT_TOUCH_MAJOR, input_dev->absbit); + set_bit(ABS_MT_WIDTH_MAJOR, input_dev->absbit); + set_bit(ABS_MT_POSITION_X, input_dev->absbit); + set_bit(ABS_MT_POSITION_Y, input_dev->absbit); + set_bit(ABS_MT_TRACKING_ID, input_dev->absbit); + set_bit(INPUT_PROP_DIRECT, input_dev->propbit); + input_set_abs_params(input_dev, ABS_MT_POSITION_X, + TOUCHSCREEN_MINX, TOUCHSCREEN_MAXX, 0, 0); + input_set_abs_params(input_dev, ABS_MT_POSITION_Y, + TOUCHSCREEN_MINY, TOUCHSCREEN_MAXY, 0, 0); + input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, + 0, TOUCH_MAJOR_MAX, 0, 0); + input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, + 0, WIDTH_MAJOR_MAX, 0, 0); + input_set_abs_params(input_dev, ABS_MT_TRACKING_ID, + 0, TRACKING_ID_MAX, 0, 0); + + ret = devm_request_threaded_irq(&client->dev, + client->irq, + NULL, pixcir_ts_irq_handler, + IRQF_ONESHOT | IRQF_TRIGGER_FALLING, + client->name, ts); + if (ret) { + dev_err(&client->dev, "\nFailed to register interrupt\n"); + goto err_free_mem; + } + + ts->input_dev = input_dev; + ret = input_register_device(ts->input_dev); + if (ret) { + dev_err(&client->dev, "Unable to register %s input device\n", + input_dev->name); + goto err_free_mem; + } + device_init_wakeup(&client->dev, 1); + + return 0; + +err_free_mem: + input_free_device(input_dev); + return ret; +} + +static int pixcir_ts_remove(struct i2c_client *client) +{ + struct pixcir_ts_data *ts = i2c_get_clientdata(client); + device_init_wakeup(&client->dev, 0); + input_unregister_device(ts->input_dev); + return 0; +} + +static const struct i2c_device_id pixcir_ts_id[] = { + { "tangoc-ts", 0 }, + { } +}; + +MODULE_DEVICE_TABLE(i2c, pixcir_ts_id); + +static struct i2c_driver pixcir_ts_driver = { + .driver = { + .name = "tangoc-ts", + .owner = THIS_MODULE, +#ifdef CONFIG_PM_SLEEP + .pm = &pixcir_dev_pm_ops, +#endif + }, + .id_table = pixcir_ts_id, + .probe = pixcir_ts_probe, + .remove = pixcir_ts_remove, +}; + +module_i2c_driver(pixcir_ts_driver); + +MODULE_AUTHOR("Lisai Wang , Guoying Zhang "); +MODULE_DESCRIPTION("PIXCIR-TangoC 5 points touch controller Driver"); +MODULE_LICENSE("GPL v2");