From patchwork Tue Dec 9 09:11:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dudley Du X-Patchwork-Id: 5461221 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 24857BEEA8 for ; Tue, 9 Dec 2014 09:17:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 62A7F2012B for ; Tue, 9 Dec 2014 09:17:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 865E1200CA for ; Tue, 9 Dec 2014 09:17:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932323AbaLIJOh (ORCPT ); Tue, 9 Dec 2014 04:14:37 -0500 Received: from mail-pd0-f169.google.com ([209.85.192.169]:46394 "EHLO mail-pd0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932300AbaLIJOf (ORCPT ); Tue, 9 Dec 2014 04:14:35 -0500 Received: by mail-pd0-f169.google.com with SMTP id z10so183205pdj.28 for ; Tue, 09 Dec 2014 01:14: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=2PoBJG5+jk5YmdqTOVih6COzA3Q7FdE1OlbP6yCzcNQ=; b=s0s15Nya49+zCstVhhw4elJ6AhSntdlHmrR02jn6Vkqiaf6JKWQsLW/cr0hos/rLiC yX+TSb7tyHIY+p+Qyxv9aFr5NMOpTzxCyGsqnlkLrffade1i8bVU+EY/6b06q73sBCw3 b7YFS5J8o3Q8S5/qoWTf0i3lz7gy6Wxp4uMrPd8/cVY5RbhjYu0GVYr9mF4roM0OdgeL iIqdK4vssZh35vc6Q9UcAYsf/tO9m3fpE9pBYw5lEPiYmhQ4lzaZYa8tdJg0CyLiXRzW +LzVob6TamsfrFxR7m3laJOTkueF256t/ibM3R2HFbvlhMQXWml65UkD13Bog/iaG3io NTXw== X-Received: by 10.66.157.196 with SMTP id wo4mr3511137pab.156.1418116475517; Tue, 09 Dec 2014 01:14:35 -0800 (PST) Received: from localhost ([140.207.206.26]) by mx.google.com with ESMTPSA id pb6sm902030pbb.13.2014.12.09.01.14.31 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 09 Dec 2014 01:14: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 v13 11/12] input: cyapa: add gen5 trackpad device force re-calibrate function support Date: Tue, 9 Dec 2014 17:11:43 +0800 Message-Id: <1418116304-11392-12-git-send-email-dudley.dulixin@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1418116304-11392-1-git-send-email-dudley.dulixin@gmail.com> References: <1418116304-11392-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 5bebee1..7d96904 100644 --- a/drivers/input/mouse/cyapa_gen5.c +++ b/drivers/input/mouse/cyapa_gen5.c @@ -1581,6 +1581,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)) @@ -2558,6 +2622,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,