From patchwork Mon Nov 3 08:33:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dudley Du X-Patchwork-Id: 5214911 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 1F2BD9F295 for ; Mon, 3 Nov 2014 08:38:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 34E2F20166 for ; Mon, 3 Nov 2014 08:38:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 26D562015E for ; Mon, 3 Nov 2014 08:38:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752384AbaKCIhd (ORCPT ); Mon, 3 Nov 2014 03:37:33 -0500 Received: from mail-pd0-f180.google.com ([209.85.192.180]:57782 "EHLO mail-pd0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752378AbaKCIha (ORCPT ); Mon, 3 Nov 2014 03:37:30 -0500 Received: by mail-pd0-f180.google.com with SMTP id ft15so10992555pdb.25 for ; Mon, 03 Nov 2014 00:37:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lraztWouw726kRIyD24Q3IJ6noA/EdmlC+1DPyadpmQ=; b=iAzVqOfSQ9G/xJZJMu9kkNrgUVM5MMGJ1qj4FExcwPyyYg9UJVrTG2te6C/4c4WcvV AZhiyeLGVe+G6e8Ynu7Mkp7pgA6V4ON+KZyhBo8pHTHmki4fDExFYg900qjn1nXqgSL1 NnWmyajGasjzIUaYkiX1um6/dDlhkBQ2Bo9eOIAkKIHteTQ0wEigdYRgO0jxaeuQH7Y7 pSZgJ8/xWYyuefppafDzVvL2in5OYxPvCwG3L7bqvWhti1agY98UpnlOb/I+QCi+lNaR CkQiOxs6Z3xcLoW/TA4bJcucpjXDaqedhcWkzmNRZETvNxJwoFIsoZq64aeLIy01neht WWGQ== X-Received: by 10.68.248.40 with SMTP id yj8mr41666690pbc.58.1415003850062; Mon, 03 Nov 2014 00:37:30 -0800 (PST) Received: from localhost ([140.207.206.26]) by mx.google.com with ESMTPSA id nb4sm16475681pdb.86.2014.11.03.00.37.26 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 03 Nov 2014 00:37:28 -0800 (PST) From: Dudley Du X-Google-Original-From: Dudley Du To: dmitry.torokhov@gmail.com, rydberg@euromail.se Cc: Dudley Du , bleung@google.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v9 18/18] input: cyapa: add gen5 trackpad device read raw data function support Date: Mon, 3 Nov 2014 16:33:10 +0800 Message-Id: <1415003590-30485-19-git-send-email-dudl@cypress.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1415003590-30485-1-git-send-email-dudl@cypress.com> References: <1415003590-30485-1-git-send-email-dudl@cypress.com> 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=unavailable 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 Add read raw data function supported for gen5 trackpad device, it can be used through debugfs raw_data interface. TEST=test on Chromebooks. Signed-off-by: Dudley Du --- drivers/input/mouse/cyapa_gen5.c | 109 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/drivers/input/mouse/cyapa_gen5.c b/drivers/input/mouse/cyapa_gen5.c index 35334dc..bbc2e20 100644 --- a/drivers/input/mouse/cyapa_gen5.c +++ b/drivers/input/mouse/cyapa_gen5.c @@ -2350,6 +2350,114 @@ resume_scanning: return ret + err; } +static int cyapa_gen5_read_raw_data(struct cyapa *cyapa) +{ + int ret, err; + int raw_cap_mutual_max, raw_cap_mutual_min, raw_cap_mutual_ave; + int raw_cap_self_max, raw_cap_self_min, raw_cap_self_ave; + int offset; + int data_size, max, min, ave; + ktime_t time_mono; + + offset = 0; + if (!cyapa->tp_raw_data) { + if (cyapa->state != CYAPA_STATE_GEN5_APP || + !cyapa->electrodes_x || !cyapa->electrodes_y) + return -EINVAL; + + cyapa->tp_raw_data_size = sizeof(s32) * (cyapa->electrodes_x * + cyapa->electrodes_y + cyapa->electrodes_x + + cyapa->electrodes_y) + GEN5_RAW_DATA_HEAD_SIZE; + /* + * This buffer will be hold after used until the driver is + * unloaded, the purpose of it is to improve the performace + * to avoid frequently allocate and release the buffer. + */ + cyapa->tp_raw_data = devm_kzalloc(&cyapa->client->dev, + cyapa->tp_raw_data_size, GFP_KERNEL); + if (!cyapa->tp_raw_data) + return -ENOMEM; + } + + /* + * 1. Suspend Scanning. + * + * After suspend scanning, the raw data will not be updated, + * so the time of the raw data is before scanning suspended. + */ + time_mono = ktime_get(); + ret = cyapa_gen5_suspend_scanning(cyapa); + if (ret) + return ret; + + /* 2. Get the correct electrodes_rx number. */ + if (cyapa->electrodes_rx == 0) { + /* + * Through the read global idac interface to get the Rx number. + * this value is useful to the raw data map. + */ + data_size = 0; + err = cyapa_gen5_read_idac_data(cyapa, + GEN5_CMD_RETRIEVE_DATA_STRUCTURE, + GEN5_RETRIEVE_MUTUAL_PWC_DATA, + &data_size, &max, &min, &ave); + if (err || cyapa->electrodes_rx == 0) + goto resume_scanning; + } + + /* 3. Execuate panel scan. It must be executed before read data. */ + err = cyapa_gen5_execute_panel_scan(cyapa); + if (err) + goto resume_scanning; + + /* 4. Retrieve panel scan, mutual cap raw data. */ + offset = GEN5_RAW_DATA_HEAD_SIZE; + err = cyapa_gen5_read_panel_scan_raw_data(cyapa, + GEN5_CMD_RETRIEVE_PANEL_SCAN, + GEN5_PANEL_SCAN_MUTUAL_DIFFCOUNT, + cyapa->electrodes_x * cyapa->electrodes_y, + &raw_cap_mutual_max, &raw_cap_mutual_min, + &raw_cap_mutual_ave, + cyapa->tp_raw_data + offset); + if (err) + goto resume_scanning; + + offset += sizeof(s32) * cyapa->electrodes_x * cyapa->electrodes_y; + + /* 5. Retrieve panel scan, self cap raw data. */ + err = cyapa_gen5_read_panel_scan_raw_data(cyapa, + GEN5_CMD_RETRIEVE_PANEL_SCAN, + GEN5_PANEL_SCAN_SELF_DIFFCOUNT, + cyapa->electrodes_x + cyapa->electrodes_y, + &raw_cap_self_max, &raw_cap_self_min, + &raw_cap_self_ave, + cyapa->tp_raw_data + offset); + if (err) + goto resume_scanning; + + offset += sizeof(s32) * (cyapa->electrodes_x + cyapa->electrodes_y); + +resume_scanning: + /* 6. Resume Scanning*/ + ret = cyapa_gen5_resume_scanning(cyapa); + if (ret || err) + return ret ? ret : err; + + *((struct timeval *)&cyapa->tp_raw_data[0]) = + ktime_to_timeval(time_mono); + cyapa->tp_raw_data[16] = (u8)cyapa->electrodes_x; + cyapa->tp_raw_data[17] = (u8)cyapa->electrodes_y; + cyapa->tp_raw_data[18] = (u8)cyapa->x_origin; + cyapa->tp_raw_data[19] = (u8)cyapa->y_origin; + cyapa->tp_raw_data[20] = (u8)sizeof(s32); + cyapa->tp_raw_data[21] = (u8)sizeof(s32); + cyapa->tp_raw_data[22] = (u8)cyapa->electrodes_rx; + cyapa->tp_raw_data[23] = 0; /* Reserved. */ + + cyapa->tp_raw_data_size = offset; + return 0; +} + static bool cyapa_gen5_sort_system_info_data(struct cyapa *cyapa, u8 *buf, int len) { @@ -2762,6 +2870,7 @@ const struct cyapa_dev_ops cyapa_gen5_ops = { .calibrate_store = cyapa_gen5_do_calibrate, .read_fw = cyapa_gen5_read_fw, + .read_raw_data = cyapa_gen5_read_raw_data, .initialize = cyapa_gen5_initialize,