From patchwork Wed Dec 3 09:30:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dudley Du X-Patchwork-Id: 5428581 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4AD58BEEA8 for ; Wed, 3 Dec 2014 09:37:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 78A70201D3 for ; Wed, 3 Dec 2014 09:36:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0F81A201CE for ; Wed, 3 Dec 2014 09:36:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751986AbaLCJdj (ORCPT ); Wed, 3 Dec 2014 04:33:39 -0500 Received: from mail-pa0-f41.google.com ([209.85.220.41]:46027 "EHLO mail-pa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751925AbaLCJdg (ORCPT ); Wed, 3 Dec 2014 04:33:36 -0500 Received: by mail-pa0-f41.google.com with SMTP id rd3so15457457pab.28 for ; Wed, 03 Dec 2014 01:33:35 -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=VO8TksaV37Dx8ZSca7h4YF/rq5nVYsEKTfsF+FCaJwI=; b=pwDUwVViemg2StliXehbctXAdgiOwuMYoDQP4mgX7sC9LShCpj5y0HYm8OuLnddDgj 0m8gzWGtk6rFkkcb95OLPoNWCdHy/iC/TpAerlzSpNcaGtW0T4Xqc/jZezE73WfZYLEV qsf3KiQ9lWvUpNhl2CSJnecVK2PEhujk9xs/g0SG5w8SZ64VSn9F7IY2iCxoPkR4TZcH a+mbpxp39m5Uysg/OqUaEPjBmqLzYhGblGP2nUsPbeCZUaIavQ9orPaciANvD9zN1iTd br6VVu3108g0It+y5G1JvcRO0QZpF2foP7Ajxzdg2WBeh62b3ek1LrYhZFbr0Wo8gibh /Kcg== X-Received: by 10.68.201.201 with SMTP id kc9mr13542504pbc.149.1417599215888; Wed, 03 Dec 2014 01:33:35 -0800 (PST) Received: from localhost ([140.207.206.26]) by mx.google.com with ESMTPSA id j10sm22549074pdr.92.2014.12.03.01.33.32 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 03 Dec 2014 01:33:34 -0800 (PST) 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 v12 13/19] input: cyapa: add gen5 trackpad device force re-calibrate function support Date: Wed, 3 Dec 2014 17:30:19 +0800 Message-Id: <1417599025-21681-14-git-send-email-dudley.dulixin@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1417599025-21681-1-git-send-email-dudley.dulixin@gmail.com> References: <1417599025-21681-1-git-send-email-dudley.dulixin@gmail.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=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, 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 force re-calibrate function supported for gen5 trackpad device, it can be used through sysfs calibrate interface. TEST=test on Chromebooks. Signed-off-by: Dudley Du --- drivers/input/mouse/cyapa_gen5.c | 65 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/drivers/input/mouse/cyapa_gen5.c b/drivers/input/mouse/cyapa_gen5.c index ad123ae..9d45941 100644 --- a/drivers/input/mouse/cyapa_gen5.c +++ b/drivers/input/mouse/cyapa_gen5.c @@ -1580,6 +1580,70 @@ static int cyapa_gen5_suspend_scanning(struct cyapa *cyapa) return 0; } +static int cyapa_gen5_calibrate_pwcs(struct cyapa *cyapa, + u8 calibrate_sensing_mode_type) +{ + u8 cmd[8]; + u8 resp_data[6]; + int resp_len; + int error; + + /* Try to dump all bufferred data before doing command. */ + cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL); + + cmd[0] = 0x04; + cmd[1] = 0x00; + cmd[2] = 0x06; + cmd[3] = 0x00; + cmd[4] = GEN5_APP_CMD_REPORT_ID; + cmd[5] = 0x00; + cmd[6] = GEN5_CMD_CALIBRATE; + cmd[7] = calibrate_sensing_mode_type; + resp_len = sizeof(resp_data); + error = cyapa_i2c_pip_cmd_irq_sync(cyapa, + cmd, sizeof(cmd), + resp_data, &resp_len, + 5000, cyapa_gen5_sort_tsg_pip_app_resp_data, true); + if (error || !VALID_CMD_RESP_HEADER(resp_data, GEN5_CMD_CALIBRATE) || + !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5])) + return error < 0 ? error : -EAGAIN; + + return 0; +} + +static ssize_t cyapa_gen5_do_calibrate(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct cyapa *cyapa = dev_get_drvdata(dev); + int error, calibrate_error; + + /* 1. Suspend Scanning*/ + error = cyapa_gen5_suspend_scanning(cyapa); + if (error) + return error; + + /* 2. Do mutual capacitance fine calibrate. */ + calibrate_error = cyapa_gen5_calibrate_pwcs(cyapa, + CYAPA_SENSING_MODE_MUTUAL_CAP_FINE); + if (calibrate_error) + goto resume_scanning; + + /* 3. Do self capacitance calibrate. */ + calibrate_error = cyapa_gen5_calibrate_pwcs(cyapa, + CYAPA_SENSING_MODE_SELF_CAP); + if (calibrate_error) + goto resume_scanning; + +resume_scanning: + /* 4. Resume Scanning*/ + error = cyapa_gen5_resume_scanning(cyapa); + if (error || calibrate_error) + return error ? error : calibrate_error; + + return count; +} + static s32 two_complement_to_s32(s32 value, int num_bits) { if (value >> (num_bits - 1)) @@ -2557,6 +2621,7 @@ const struct cyapa_dev_ops cyapa_gen5_ops = { .update_fw = cyapa_gen5_do_fw_update, .show_baseline = cyapa_gen5_show_baseline, + .calibrate_store = cyapa_gen5_do_calibrate, .initialize = cyapa_gen5_initialize,