From patchwork Wed Nov 19 08:37:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dudley Du X-Patchwork-Id: 5335401 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 234CAC11AC for ; Wed, 19 Nov 2014 08:43:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 47D8F200FE for ; Wed, 19 Nov 2014 08:43:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5BC5E200F0 for ; Wed, 19 Nov 2014 08:43:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754748AbaKSIl2 (ORCPT ); Wed, 19 Nov 2014 03:41:28 -0500 Received: from mail-pd0-f180.google.com ([209.85.192.180]:41517 "EHLO mail-pd0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754704AbaKSIl0 (ORCPT ); Wed, 19 Nov 2014 03:41:26 -0500 Received: by mail-pd0-f180.google.com with SMTP id p10so130102pdj.25 for ; Wed, 19 Nov 2014 00:41:26 -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=uFlvHuBenq0kEF9myXb+HkiQKLwbboWGmM0YrHYaHdE=; b=GzUHKC1yWC73qk3MgKSIzUOKdnfmkqMfmQ3cPD6SyA1sm6SMQIPoswCYw394YHsHsZ 7eEGS2gSmbZviTxGj2jUfG5gNDigAPDar6aVnTEhrXFyKZN8PPh49ILVm3000xit29lf 15B/Y9vVAH39rGM/t3BZil+fmemuPcXUND40Plpbi3xBvwgledC+iibccYRco+YAbDOf qlGtxT62ZAaNBsajK3en9uEa1ROTsyDoQvjXXDIixCAt8LLWvYRiBNOP/5fpF0suWmf9 YpNVouHRcM6WBHJLbVxmqFvyPKC88jFb6Xk9A+9vOKEZJsE96uwiOOsFxuRozk4kPWvp XCPA== X-Received: by 10.68.204.8 with SMTP id ku8mr44099421pbc.103.1416386486085; Wed, 19 Nov 2014 00:41:26 -0800 (PST) Received: from localhost ([140.207.206.26]) by mx.google.com with ESMTPSA id pz6sm1166527pbb.77.2014.11.19.00.41.22 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 19 Nov 2014 00:41:24 -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 v11 13/19] input: cyapa: add gen5 trackpad device force re-calibrate function support Date: Wed, 19 Nov 2014 16:37:45 +0800 Message-Id: <1416386271-28167-14-git-send-email-dudley.dulixin@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1416386271-28167-1-git-send-email-dudley.dulixin@gmail.com> References: <1416386271-28167-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 b401b2a..51bdf06 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)) @@ -2556,6 +2620,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,