From patchwork Wed Nov 19 08:37:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dudley Du X-Patchwork-Id: 5335441 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 2BC019F2ED for ; Wed, 19 Nov 2014 08:43:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 538D3200FE for ; Wed, 19 Nov 2014 08:43:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 75C87200F0 for ; Wed, 19 Nov 2014 08:43:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932262AbaKSIkr (ORCPT ); Wed, 19 Nov 2014 03:40:47 -0500 Received: from mail-pd0-f176.google.com ([209.85.192.176]:63664 "EHLO mail-pd0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932259AbaKSIkp (ORCPT ); Wed, 19 Nov 2014 03:40:45 -0500 Received: by mail-pd0-f176.google.com with SMTP id y10so143447pdj.7 for ; Wed, 19 Nov 2014 00:40:45 -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=Qp9zXSAEEqVTCadKfjtF32ZwsSeQuHxUzFsRgKCOLDI=; b=c2nudF88YnC+dg71BjkRlgoCqeA4RDm7/ZlL2r/QWr/dWUo5vDN2+0U3d600ciiKJv SdBFz1q6iiI9UQ8LCrr7g8Z+JxTJ6beVXTHL9SfmaG2NYgZoN0KbWbT5VG/J6IRrrRVN 8aqMq70ZHYOxZ52oXzk/387hxNsD+O6lFbaX4P1+amPpd2YevC8VdFvpmxPaAJfroCe4 b/ouifkZguuoESownKnjvdXNtHzCv625c2NHRuGkoL53zlZRXGw5Ih+fsXD2F8lbpFl6 2BLQD3MvLZSdPuYZS5Ksm/IaFY0hoEWSaMurzQcsvDw+ERBtJyrya4fNy9Vrv+d03eXh uUrg== X-Received: by 10.66.218.131 with SMTP id pg3mr17673290pac.143.1416386445043; Wed, 19 Nov 2014 00:40:45 -0800 (PST) Received: from localhost ([140.207.206.26]) by mx.google.com with ESMTPSA id r15sm1106793pdn.23.2014.11.19.00.40.15 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 19 Nov 2014 00:40:44 -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 09/19] input: cyapa: add gen3 trackpad device read baseline function support Date: Wed, 19 Nov 2014 16:37:41 +0800 Message-Id: <1416386271-28167-10-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 read baseline function supported for gen3 trackpad device, it can be used through sysfs baseline interface. TEST=test on Chromebooks. Signed-off-by: Dudley Du --- drivers/input/mouse/cyapa_gen3.c | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/drivers/input/mouse/cyapa_gen3.c b/drivers/input/mouse/cyapa_gen3.c index fc1b781..bc2be93 100644 --- a/drivers/input/mouse/cyapa_gen3.c +++ b/drivers/input/mouse/cyapa_gen3.c @@ -754,6 +754,75 @@ static int cyapa_gen3_do_fw_update(struct cyapa *cyapa, return 0; } +static ssize_t cyapa_gen3_show_baseline(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct cyapa *cyapa = dev_get_drvdata(dev); + int max_baseline, min_baseline; + int tries = 3; + int ret; + + ret = cyapa_read_byte(cyapa, CYAPA_CMD_DEV_STATUS); + if (ret < 0) { + dev_err(dev, "Error reading dev status. err = %d\n", ret); + goto out; + } + if ((ret & CYAPA_DEV_NORMAL) != CYAPA_DEV_NORMAL) { + dev_warn(dev, "Trackpad device is busy. device state = 0x%x\n", + ret); + ret = -EAGAIN; + goto out; + } + + ret = cyapa_write_byte(cyapa, CYAPA_CMD_SOFT_RESET, + OP_REPORT_BASELINE_MASK); + if (ret < 0) { + dev_err(dev, "Failed to send report baseline command. %d\n", + ret); + goto out; + } + + do { + usleep_range(10000, 20000); + + ret = cyapa_read_byte(cyapa, CYAPA_CMD_DEV_STATUS); + if (ret < 0) { + dev_err(dev, "Error reading dev status. err = %d\n", + ret); + goto out; + } + if ((ret & CYAPA_DEV_NORMAL) == CYAPA_DEV_NORMAL) + break; + } while (--tries); + + if (tries == 0) { + dev_err(dev, "Device timed out going to Normal state.\n"); + ret = -ETIMEDOUT; + goto out; + } + + ret = cyapa_read_byte(cyapa, CYAPA_CMD_MAX_BASELINE); + if (ret < 0) { + dev_err(dev, "Failed to read max baseline. err = %d\n", ret); + goto out; + } + max_baseline = ret; + + ret = cyapa_read_byte(cyapa, CYAPA_CMD_MIN_BASELINE); + if (ret < 0) { + dev_err(dev, "Failed to read min baseline. err = %d\n", ret); + goto out; + } + min_baseline = ret; + + dev_dbg(dev, "Baseline report successful. Max: %d Min: %d\n", + max_baseline, min_baseline); + ret = scnprintf(buf, PAGE_SIZE, "%d %d\n", max_baseline, min_baseline); + +out: + return ret; +} + /* * cyapa_get_wait_time_for_pwr_cmd * @@ -1066,6 +1135,8 @@ const struct cyapa_dev_ops cyapa_gen3_ops = { .update_fw = cyapa_gen3_do_fw_update, .bl_deactivate = cyapa_gen3_bl_deactivate, + .show_baseline = cyapa_gen3_show_baseline, + .state_parse = cyapa_gen3_state_parse, .operational_check = cyapa_gen3_do_operational_check,