From patchwork Wed Apr 30 12:36:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 29416 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f200.google.com (mail-ie0-f200.google.com [209.85.223.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EE242206A5 for ; Wed, 30 Apr 2014 12:37:01 +0000 (UTC) Received: by mail-ie0-f200.google.com with SMTP id lx4sf8380132iec.11 for ; Wed, 30 Apr 2014 05:37:01 -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:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=1uy3ib0KDn3HruPMOaRlNNkDo8E07sQuNhTATAhR7AU=; b=JH/S2ZcqeZu+b0wa+HnfwBqDadD40EgxVUB/nWY3PyuQAt0MdWFldK0Yfw9QODIDWZ 0CD4smYfP/gVotTfuleVcbWY7cCBBo0SoxHOarPimxKQVBj86a981j48N9ByGyIwNPVj jdn61uM/XD7cKyYCaUpr1vs460nWHcDkF70sCEcal0yWzzT9aTkBHr7ugtvReH8p3R7l atZpNa6Qx8mHCPwsnODTsr0D3n/HfpiWMQ+uGClzp1C9Vc8v0o0SLpt7BHTN9ILFeNEl pTMtv0G23DoqnhB0xVrqIKR08fMEeyb+SXW44fD5kyyFUiQv4XGHO+JMpWlcPqGqJ/OA 9vIw== X-Gm-Message-State: ALoCoQnTwv+KT55VLSW5DcxR2epjpeu2o5HXbA6U1VJHEzQbKiQ4GVn1FWRFeiIQS16Ck9jH2Vsk X-Received: by 10.43.126.2 with SMTP id gu2mr2089711icc.0.1398861420143; Wed, 30 Apr 2014 05:37:00 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.32.203 with SMTP id h69ls584609qgh.56.gmail; Wed, 30 Apr 2014 05:37:00 -0700 (PDT) X-Received: by 10.58.187.78 with SMTP id fq14mr3808223vec.9.1398861419971; Wed, 30 Apr 2014 05:36:59 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id tz5si5271405vdc.43.2014.04.30.05.36.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Apr 2014 05:36:59 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id hr9so2107697vcb.1 for ; Wed, 30 Apr 2014 05:36:59 -0700 (PDT) X-Received: by 10.58.122.164 with SMTP id lt4mr3852324veb.2.1398861419869; Wed, 30 Apr 2014 05:36:59 -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.220.221.72 with SMTP id ib8csp275349vcb; Wed, 30 Apr 2014 05:36:59 -0700 (PDT) X-Received: by 10.67.1.202 with SMTP id bi10mr8280721pad.68.1398861419092; Wed, 30 Apr 2014 05:36:59 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fd9si16857279pad.347.2014.04.30.05.36.58; Wed, 30 Apr 2014 05:36:58 -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 S933675AbaD3Mgy (ORCPT + 9 others); Wed, 30 Apr 2014 08:36:54 -0400 Received: from bear.ext.ti.com ([192.94.94.41]:52563 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933624AbaD3Mgw (ORCPT ); Wed, 30 Apr 2014 08:36:52 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id s3UCao6G006554; Wed, 30 Apr 2014 07:36:50 -0500 Received: from DLEE70.ent.ti.com (dlemailx.itg.ti.com [157.170.170.113]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s3UCaoce006101; Wed, 30 Apr 2014 07:36:50 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.174.1; Wed, 30 Apr 2014 07:36:50 -0500 Received: from localhost.localdomain (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s3UCaZTE018190; Wed, 30 Apr 2014 07:36:47 -0500 From: Roger Quadros To: CC: , , , , , , , , Roger Quadros Subject: [PATCH v3 4/7] Input: pixcir_i2c_ts: Use Type-B Multi-Touch protocol Date: Wed, 30 Apr 2014 15:36:29 +0300 Message-ID: <1398861392-8959-5-git-send-email-rogerq@ti.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1398861392-8959-1-git-send-email-rogerq@ti.com> References: <1398861392-8959-1-git-send-email-rogerq@ti.com> MIME-Version: 1.0 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=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) 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: , Switch to using the Type-B Multi-Touch protocol. 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 106096f..6127606 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 exiting; }; -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->exiting) { - 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); } @@ -337,6 +393,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,