From patchwork Mon May 19 08:24: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: 30365 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f69.google.com (mail-yh0-f69.google.com [209.85.213.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D3635203AB for ; Mon, 19 May 2014 08:24:57 +0000 (UTC) Received: by mail-yh0-f69.google.com with SMTP id i57sf32058537yha.8 for ; Mon, 19 May 2014 01:24:57 -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=YRDHrku2dFUSJn3JnfBXALOObSSf26DMERyEpjSyS8s=; b=KGrQya121WAkOQ8NSsUD7gUSchCXLASlh1HkQVUThOKMIwU1RcEP0cPDMyaNbW1JhZ xfNyy9r997nydSssqe5LHU8Ke4A+Ee9HA3WQwT07oVm/Sg6Bv6IfAaSlwQCchSWNJn0P Y5Lxi04sA8ClpL+aXGvkVZ8T2dIef38AwIFbnFaSP/NOEgKzPEyrw5Jk9z+b3/sFDG+6 r+BtjOMnNd5XTUUm16x73o+dd+5wC+Bg6Fq3fKxQe0QhdVnqL0W4KdL5uVb+aaTIX5Ni oK7OSx/ZaZh9QwwbxsUAEVf0yrjOywodycUgKxCiFK9C8W0aohBc4bNEWbq8KhrJKPp/ K0Pw== X-Gm-Message-State: ALoCoQmkP/ASBa5EQzdPXoWX1kmh4OJL9mDAoFUCQuDZUQcaK/zkx5R+eYje/6xoPyAQHF79xON2 X-Received: by 10.58.43.170 with SMTP id x10mr7871504vel.36.1400487897621; Mon, 19 May 2014 01:24:57 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.36.14 with SMTP id o14ls1582246qgo.63.gmail; Mon, 19 May 2014 01:24:57 -0700 (PDT) X-Received: by 10.224.95.73 with SMTP id c9mr45840736qan.68.1400487897524; Mon, 19 May 2014 01:24:57 -0700 (PDT) Received: from mail-qc0-f178.google.com (mail-qc0-f178.google.com [209.85.216.178]) by mx.google.com with ESMTPS id 2si8251184qah.21.2014.05.19.01.24.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 19 May 2014 01:24:57 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.216.178 as permitted sender) client-ip=209.85.216.178; Received: by mail-qc0-f178.google.com with SMTP id l6so8315783qcy.37 for ; Mon, 19 May 2014 01:24:57 -0700 (PDT) X-Received: by 10.229.239.4 with SMTP id ku4mr47235945qcb.17.1400487897394; Mon, 19 May 2014 01:24:57 -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 s7csp208010qda; Mon, 19 May 2014 01:24:56 -0700 (PDT) X-Received: by 10.66.119.136 with SMTP id ku8mr41273319pab.121.1400487896361; Mon, 19 May 2014 01:24:56 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id wt1si9187472pbc.118.2014.05.19.01.24.55; Mon, 19 May 2014 01:24:55 -0700 (PDT) Received-SPF: none (google.com: devicetree-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 S1753317AbaESIYy (ORCPT + 8 others); Mon, 19 May 2014 04:24:54 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:56027 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753310AbaESIYx (ORCPT ); Mon, 19 May 2014 04:24:53 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id s4J8OoBP000646; Mon, 19 May 2014 03:24:50 -0500 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id s4J8OnKs025779; Mon, 19 May 2014 03:24:50 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.174.1; Mon, 19 May 2014 03:24:49 -0500 Received: from [192.168.2.6] (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s4J8OkYu019579; Mon, 19 May 2014 03:24:47 -0500 Message-ID: <5379BFCE.9050107@ti.com> Date: Mon, 19 May 2014 11:24: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 4/7] Input: pixcir_i2c_ts: Use Type-B Multi-Touch protocol References: <1399374372-29123-1-git-send-email-rogerq@ti.com> <1399374372-29123-5-git-send-email-rogerq@ti.com> In-Reply-To: <1399374372-29123-5-git-send-email-rogerq@ti.com> Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@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.178 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 Switch to using the Type-B Multi-Touch protocol. Reviewed-by: Henrik Rydberg Signed-off-by: Roger Quadros --- drivers/input/touchscreen/pixcir_i2c_ts.c | 125 ++++++++++++++++++++++-------- 1 file changed, 94 insertions(+), 31 deletions(-) diff --git a/drivers/input/touchscreen/pixcir_i2c_ts.c b/drivers/input/touchscreen/pixcir_i2c_ts.c index 8a7da61..627d2f5 100644 --- a/drivers/input/touchscreen/pixcir_i2c_ts.c +++ b/drivers/input/touchscreen/pixcir_i2c_ts.c @@ -23,9 +23,12 @@ #include #include #include +#include #include #include +#define PIXCIR_MAX_SLOTS 2 + struct pixcir_i2c_ts_data { struct i2c_client *client; struct input_dev *input; @@ -33,12 +36,25 @@ struct pixcir_i2c_ts_data { bool running; }; -static void pixcir_ts_poscheck(struct pixcir_i2c_ts_data *data) +struct pixcir_touch { + int x; + int y; +}; + +struct pixcir_report_data { + int num_touches; + struct pixcir_touch touches[PIXCIR_MAX_SLOTS]; +}; + +static void pixcir_ts_parse(struct pixcir_i2c_ts_data *tsdata, + struct pixcir_report_data *report) { - struct pixcir_i2c_ts_data *tsdata = data; u8 rdbuf[10], wrbuf[1] = { 0 }; + u8 *bufptr; u8 touch; - int ret; + int ret, i; + + memset(report, 0, sizeof(struct pixcir_report_data)); ret = i2c_master_send(tsdata->client, wrbuf, sizeof(wrbuf)); if (ret != sizeof(wrbuf)) { @@ -56,45 +72,85 @@ static void pixcir_ts_poscheck(struct pixcir_i2c_ts_data *data) return; } - touch = rdbuf[0]; - if (touch) { - u16 posx1 = (rdbuf[3] << 8) | rdbuf[2]; - u16 posy1 = (rdbuf[5] << 8) | rdbuf[4]; - u16 posx2 = (rdbuf[7] << 8) | rdbuf[6]; - u16 posy2 = (rdbuf[9] << 8) | rdbuf[8]; - - input_report_key(tsdata->input, BTN_TOUCH, 1); - input_report_abs(tsdata->input, ABS_X, posx1); - input_report_abs(tsdata->input, ABS_Y, posy1); - - input_report_abs(tsdata->input, ABS_MT_POSITION_X, posx1); - input_report_abs(tsdata->input, ABS_MT_POSITION_Y, posy1); - input_mt_sync(tsdata->input); - - if (touch == 2) { - input_report_abs(tsdata->input, - ABS_MT_POSITION_X, posx2); - input_report_abs(tsdata->input, - ABS_MT_POSITION_Y, posy2); - input_mt_sync(tsdata->input); - } - } else { - input_report_key(tsdata->input, BTN_TOUCH, 0); + touch = rdbuf[0] & 0x7; + if (touch > PIXCIR_MAX_SLOTS) + touch = PIXCIR_MAX_SLOTS; + + report->num_touches = touch; + bufptr = &rdbuf[2]; + + for (i = 0; i < touch; i++) { + report->touches[i].x = (bufptr[1] << 8) | bufptr[0]; + report->touches[i].y = (bufptr[3] << 8) | bufptr[2]; + + bufptr = bufptr + 4; } +} + +static void pixcir_ts_report(struct pixcir_i2c_ts_data *ts, + struct pixcir_report_data *report) +{ + struct input_mt_pos pos[PIXCIR_MAX_SLOTS]; + int slots[PIXCIR_MAX_SLOTS]; + struct pixcir_touch *touch; + int n, i, slot; + struct device *dev = &ts->client->dev; - input_sync(tsdata->input); + 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; + } + + input_mt_assign_slots(ts->input, slots, pos, n); + + for (i = 0; i < n; i++) { + touch = &report->touches[i]; + slot = slots[i]; + + input_mt_slot(ts->input, slot); + input_mt_report_slot_state(ts->input, + MT_TOOL_FINGER, true); + + input_event(ts->input, EV_ABS, ABS_MT_POSITION_X, touch->x); + input_event(ts->input, EV_ABS, ABS_MT_POSITION_Y, touch->y); + + dev_dbg(dev, "%d: slot %d, x %d, y %d\n", + i, slot, touch->x, touch->y); + } + + input_mt_sync_frame(ts->input); + input_sync(ts->input); } 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; + struct pixcir_report_data report; while (tsdata->running) { - pixcir_ts_poscheck(tsdata); - - if (gpio_get_value(pdata->gpio_attb)) + /* parse packet */ + pixcir_ts_parse(tsdata, &report); + + /* report it */ + pixcir_ts_report(tsdata, &report); + + if (gpio_get_value(pdata->gpio_attb)) { + if (report.num_touches) { + /* + * Last report with no finger up? + * Do it now then. + */ + input_mt_sync_frame(tsdata->input); + input_sync(tsdata->input); + } break; + } msleep(20); } @@ -333,6 +389,13 @@ 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, + INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED); + if (error) { + dev_err(dev, "Error initializing Multi-Touch slots\n"); + return error; + } + input_set_drvdata(input, tsdata); error = devm_gpio_request_one(dev, pdata->gpio_attb,