From patchwork Mon May 19 08:26:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 30366 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f197.google.com (mail-ig0-f197.google.com [209.85.213.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 645C3203AB for ; Mon, 19 May 2014 08:27:22 +0000 (UTC) Received: by mail-ig0-f197.google.com with SMTP id hn18sf10876441igb.4 for ; Mon, 19 May 2014 01:27:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:date:from:user-agent :mime-version:to:cc:subject:references:in-reply-to:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe :content-type:content-transfer-encoding; bh=R/olpzL27/IL427i2LycSa2iKH8uZXjwZDXEP9KQOUE=; b=NNBax119ywCRgxJjmzStmrTPsNqUVxI60NpK8w2DhZmYJbWRFhi8AJu7azcBgeVwHT 8l7zztDUew8s2WVPV1tlbABXC1VIslyuNKxb48zUYN6IPoVpsthWnacJwiy26h2cRflR Pig74jIUHVlYdVacSfwh4k+s7XeEMuEnDtm/mRYsQP3Ilm2SRr/TCOhF9uhZMdtNIDxA g0ppR+9Zh8gUi8iuUF0BIiXM1ZPvalprP4MZGiUDdTpGj7LF0h9M2OonPdXFLS1V8p33 +C2mvckilIgEcOXI4oAe8H9IfRndCsrZ5ooHwSQp685u0mBXAvx29zi2XKxLzMReT7Rm 3HFg== X-Gm-Message-State: ALoCoQnNgg3fYNRdOY6NdJCR8Ikl7jeiWRSGK+PYZc4ovbI0HNYsSaxp+J5Bqmy+Wk/87HHCELrj X-Received: by 10.50.32.4 with SMTP id e4mr6519633igi.7.1400488041893; Mon, 19 May 2014 01:27:21 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.34.233 with SMTP id l96ls1497443qgl.90.gmail; Mon, 19 May 2014 01:27:21 -0700 (PDT) X-Received: by 10.224.25.133 with SMTP id z5mr45135557qab.97.1400488041761; Mon, 19 May 2014 01:27:21 -0700 (PDT) Received: from mail-qc0-f177.google.com (mail-qc0-f177.google.com [209.85.216.177]) by mx.google.com with ESMTPS id 2si8219003qah.251.2014.05.19.01.27.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 19 May 2014 01:27:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.216.177 as permitted sender) client-ip=209.85.216.177; Received: by mail-qc0-f177.google.com with SMTP id i17so8306126qcy.22 for ; Mon, 19 May 2014 01:27:21 -0700 (PDT) X-Received: by 10.140.48.161 with SMTP id o30mr45495845qga.68.1400488041650; Mon, 19 May 2014 01:27:21 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.96.8.167 with SMTP id s7csp208177qda; Mon, 19 May 2014 01:27:21 -0700 (PDT) X-Received: by 10.66.146.105 with SMTP id tb9mr9064193pab.157.1400488040812; Mon, 19 May 2014 01:27:20 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id go2si9171289pbc.435.2014.05.19.01.27.20; Mon, 19 May 2014 01:27:20 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753607AbaESI1H (ORCPT + 27 others); Mon, 19 May 2014 04:27:07 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:56134 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751334AbaESI1F (ORCPT ); Mon, 19 May 2014 04:27:05 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id s4J8QolQ001921; Mon, 19 May 2014 03:26:50 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s4J8QobV028356; Mon, 19 May 2014 03:26:50 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.174.1; Mon, 19 May 2014 03:26:50 -0500 Received: from [192.168.2.6] (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s4J8QlJB009950; Mon, 19 May 2014 03:26:47 -0500 Message-ID: <5379C046.5070900@ti.com> Date: Mon, 19 May 2014 11:26:46 +0300 From: Roger Quadros User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: CC: , , , , , , , , Roger Quadros Subject: [PATCH v6 5/7] Input: pixcir_i2c_ts: support upto 5 fingers and hardware provided tracking IDs References: <1399374372-29123-1-git-send-email-rogerq@ti.com> <1399374372-29123-6-git-send-email-rogerq@ti.com> In-Reply-To: <1399374372-29123-6-git-send-email-rogerq@ti.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: rogerq@ti.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.216.177 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Roger Quadros Some variants of the Pixcir touch controller support upto 5 simultaneous fingers and hardware tracking IDs. Prepare the driver for that. Signed-off-by: Roger Quadros --- drivers/input/touchscreen/pixcir_i2c_ts.c | 74 ++++++++++++++++++++++++------- include/linux/input/pixcir_ts.h | 12 +++++ 2 files changed, 69 insertions(+), 17 deletions(-) diff --git a/drivers/input/touchscreen/pixcir_i2c_ts.c b/drivers/input/touchscreen/pixcir_i2c_ts.c index 627d2f5..8107965 100644 --- a/drivers/input/touchscreen/pixcir_i2c_ts.c +++ b/drivers/input/touchscreen/pixcir_i2c_ts.c @@ -27,18 +27,20 @@ #include #include -#define PIXCIR_MAX_SLOTS 2 +#define PIXCIR_MAX_SLOTS 5 /* Max fingers supported by driver */ struct pixcir_i2c_ts_data { struct i2c_client *client; struct input_dev *input; - const struct pixcir_ts_platform_data *chip; + const struct pixcir_ts_platform_data *pdata; bool running; + int max_fingers; /* Max fingers supported in this instance */ }; struct pixcir_touch { int x; int y; + int id; }; struct pixcir_report_data { @@ -49,13 +51,21 @@ struct pixcir_report_data { static void pixcir_ts_parse(struct pixcir_i2c_ts_data *tsdata, struct pixcir_report_data *report) { - u8 rdbuf[10], wrbuf[1] = { 0 }; + u8 rdbuf[2 + PIXCIR_MAX_SLOTS * 5]; + u8 wrbuf[1] = { 0 }; u8 *bufptr; u8 touch; int ret, i; + int readsize; + const struct pixcir_i2c_chip_data *chip = &tsdata->pdata->chip; memset(report, 0, sizeof(struct pixcir_report_data)); + i = chip->has_hw_ids ? 1 : 0; + readsize = 2 + tsdata->max_fingers * (4 + i); + if (readsize > sizeof(rdbuf)) + readsize = sizeof(rdbuf); + ret = i2c_master_send(tsdata->client, wrbuf, sizeof(wrbuf)); if (ret != sizeof(wrbuf)) { dev_err(&tsdata->client->dev, @@ -64,7 +74,7 @@ static void pixcir_ts_parse(struct pixcir_i2c_ts_data *tsdata, return; } - ret = i2c_master_recv(tsdata->client, rdbuf, sizeof(rdbuf)); + ret = i2c_master_recv(tsdata->client, rdbuf, readsize); if (ret != sizeof(rdbuf)) { dev_err(&tsdata->client->dev, "%s: i2c_master_recv failed(), ret=%d\n", @@ -73,8 +83,8 @@ static void pixcir_ts_parse(struct pixcir_i2c_ts_data *tsdata, } touch = rdbuf[0] & 0x7; - if (touch > PIXCIR_MAX_SLOTS) - touch = PIXCIR_MAX_SLOTS; + if (touch > tsdata->max_fingers) + touch = tsdata->max_fingers; report->num_touches = touch; bufptr = &rdbuf[2]; @@ -83,7 +93,12 @@ static void pixcir_ts_parse(struct pixcir_i2c_ts_data *tsdata, report->touches[i].x = (bufptr[1] << 8) | bufptr[0]; report->touches[i].y = (bufptr[3] << 8) | bufptr[2]; - bufptr = bufptr + 4; + if (chip->has_hw_ids) { + report->touches[i].id = bufptr[4]; + bufptr = bufptr + 5; + } else { + bufptr = bufptr + 4; + } } } @@ -95,22 +110,35 @@ static void pixcir_ts_report(struct pixcir_i2c_ts_data *ts, struct pixcir_touch *touch; int n, i, slot; struct device *dev = &ts->client->dev; + const struct pixcir_i2c_chip_data *chip = &ts->pdata->chip; n = report->num_touches; if (n > PIXCIR_MAX_SLOTS) n = PIXCIR_MAX_SLOTS; - for (i = 0; i < n; i++) { - touch = &report->touches[i]; - pos[i].x = touch->x; - pos[i].y = touch->y; - } + if (!chip->has_hw_ids) { + for (i = 0; i < n; i++) { + touch = &report->touches[i]; + pos[i].x = touch->x; + pos[i].y = touch->y; + } - input_mt_assign_slots(ts->input, slots, pos, n); + input_mt_assign_slots(ts->input, slots, pos, n); + } for (i = 0; i < n; i++) { touch = &report->touches[i]; - slot = slots[i]; + + if (chip->has_hw_ids) { + slot = input_mt_get_slot_by_key(ts->input, touch->id); + if (slot < 0) { + dev_dbg(dev, "no free slot for id 0x%x\n", + touch->id); + continue; + } + } else { + slot = slots[i]; + } input_mt_slot(ts->input, slot); input_mt_report_slot_state(ts->input, @@ -130,7 +158,7 @@ static void pixcir_ts_report(struct pixcir_i2c_ts_data *ts, static irqreturn_t pixcir_ts_isr(int irq, void *dev_id) { struct pixcir_i2c_ts_data *tsdata = dev_id; - const struct pixcir_ts_platform_data *pdata = tsdata->chip; + const struct pixcir_ts_platform_data *pdata = tsdata->pdata; struct pixcir_report_data report; while (tsdata->running) { @@ -359,6 +387,11 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client, dev_err(dev, "Invalid gpio_attb in pdata\n"); return -EINVAL; } + + if (pdata->chip.max_fingers <= 0) { + dev_err(dev, "Invalid max_fingers in pdata\n"); + return -EINVAL; + } } tsdata = devm_kzalloc(dev, sizeof(*tsdata), GFP_KERNEL); @@ -373,7 +406,7 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client, tsdata->client = client; tsdata->input = input; - tsdata->chip = pdata; + tsdata->pdata = pdata; input->name = client->name; input->id.bustype = BUS_I2C; @@ -389,7 +422,14 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client, input_set_abs_params(input, ABS_MT_POSITION_X, 0, pdata->x_max, 0, 0); input_set_abs_params(input, ABS_MT_POSITION_Y, 0, pdata->y_max, 0, 0); - error = input_mt_init_slots(input, PIXCIR_MAX_SLOTS, + tsdata->max_fingers = tsdata->pdata->chip.max_fingers; + if (tsdata->max_fingers > PIXCIR_MAX_SLOTS) { + tsdata->max_fingers = PIXCIR_MAX_SLOTS; + dev_info(dev, "Limiting maximum fingers to %d\n", + tsdata->max_fingers); + } + + error = input_mt_init_slots(input, tsdata->max_fingers, INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED); if (error) { dev_err(dev, "Error initializing Multi-Touch slots\n"); diff --git a/include/linux/input/pixcir_ts.h b/include/linux/input/pixcir_ts.h index 160cf35..7bae83b 100644 --- a/include/linux/input/pixcir_ts.h +++ b/include/linux/input/pixcir_ts.h @@ -43,10 +43,22 @@ enum pixcir_int_mode { #define PIXCIR_INT_ENABLE (1UL << 3) #define PIXCIR_INT_POL_HIGH (1UL << 2) +/** + * struct pixcir_irc_chip_data - chip related data + * @max_fingers: Max number of fingers reported simultaneously by h/w + * @has_hw_ids: Hardware supports finger tracking IDs + * + */ +struct pixcir_i2c_chip_data { + u8 max_fingers; + bool has_hw_ids; +}; + struct pixcir_ts_platform_data { int x_max; int y_max; int gpio_attb; /* GPIO connected to ATTB line */ + struct pixcir_i2c_chip_data chip; }; #endif