From patchwork Thu Jun 27 12:49:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Dyer X-Patchwork-Id: 2792981 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 EED759F3A0 for ; Thu, 27 Jun 2013 12:57:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C82502032D for ; Thu, 27 Jun 2013 12:57:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F1F3E20328 for ; Thu, 27 Jun 2013 12:57:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753920Ab3F0M4z (ORCPT ); Thu, 27 Jun 2013 08:56:55 -0400 Received: from kdh-gw.itdev.co.uk ([89.21.227.133]:62414 "EHLO hermes.kdh.itdev.co.uk" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753580Ab3F0Mur (ORCPT ); Thu, 27 Jun 2013 08:50:47 -0400 Received: from localhost.localdomain (andromeda.kdh.itdev.co.uk [192.168.1.19]) by hermes.kdh.itdev.co.uk (Postfix) with ESMTP id 6FC1785AFE; Thu, 27 Jun 2013 13:50:46 +0100 (BST) From: Nick Dyer To: Dmitry Torokhov Cc: Daniel Kurtz , Henrik Rydberg , Joonyoung Shim , Alan Bowens , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Meerwald , Benson Leung , Olof Johansson , Nick Dyer Subject: [PATCH 32/51] Input: atmel_mxt_ts - Decode T6 status messages Date: Thu, 27 Jun 2013 13:49:07 +0100 Message-Id: <1372337366-9286-33-git-send-email-nick.dyer@itdev.co.uk> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1372337366-9286-1-git-send-email-nick.dyer@itdev.co.uk> References: <1372337366-9286-1-git-send-email-nick.dyer@itdev.co.uk> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 By storing the previous T6 status byte we can detect reset completion more correctly, and multiple debug output of the same status can be suppressed (for example CFGERR). Signed-off-by: Nick Dyer Acked-by: Benson Leung --- drivers/input/touchscreen/atmel_mxt_ts.c | 60 ++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 688eab3..3890ed5 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -91,6 +91,11 @@ /* Define for T6 status byte */ #define MXT_T6_STATUS_RESET (1 << 7) +#define MXT_T6_STATUS_OFL (1 << 6) +#define MXT_T6_STATUS_SIGERR (1 << 5) +#define MXT_T6_STATUS_CAL (1 << 4) +#define MXT_T6_STATUS_CFGERR (1 << 3) +#define MXT_T6_STATUS_COMSERR (1 << 2) /* MXT_GEN_POWER_T7 field */ struct t7_config { @@ -246,6 +251,7 @@ struct mxt_data { u8 bootloader_addr; struct t7_config t7_cfg; u8 *msg_buf; + u8 t6_status; /* Cached parameters from object table */ u8 T5_msg_size; @@ -629,6 +635,39 @@ mxt_get_object(struct mxt_data *data, u8 type) return NULL; } +static void mxt_proc_t6_messages(struct mxt_data *data, u8 *msg) +{ + struct device *dev = &data->client->dev; + u8 status = msg[1]; + u32 crc = msg[2] | (msg[3] << 8) | (msg[4] << 16); + + if (crc != data->config_crc) { + data->config_crc = crc; + dev_dbg(dev, "T6 Config Checksum: 0x%06X\n", crc); + complete(&data->crc_completion); + } + + /* Detect transition out of reset */ + if ((data->t6_status & MXT_T6_STATUS_RESET) && + !(status & MXT_T6_STATUS_RESET)) + complete(&data->reset_completion); + + /* Output debug if status has changed */ + if (status != data->t6_status) + dev_dbg(dev, "T6 Status 0x%02X%s%s%s%s%s%s%s\n", + status, + (status == 0) ? " OK" : "", + (status & MXT_T6_STATUS_RESET) ? " RESET" : "", + (status & MXT_T6_STATUS_OFL) ? " OFL" : "", + (status & MXT_T6_STATUS_SIGERR) ? " SIGERR" : "", + (status & MXT_T6_STATUS_CAL) ? " CAL" : "", + (status & MXT_T6_STATUS_CFGERR) ? " CFGERR" : "", + (status & MXT_T6_STATUS_COMSERR) ? " COMSERR" : ""); + + /* Save current status */ + data->t6_status = status; +} + static int mxt_read_message(struct mxt_data *data, u8 *message) { struct mxt_object *object; @@ -735,11 +774,6 @@ static void mxt_input_touchevent(struct mxt_data *data, u8 *message) } } -static u16 mxt_extract_T6_csum(const u8 *csum) -{ - return csum[0] | (csum[1] << 8) | (csum[2] << 16); -} - static bool mxt_is_T9_message(struct mxt_data *data, u8 *msg) { u8 id = msg[0]; @@ -749,11 +783,9 @@ static bool mxt_is_T9_message(struct mxt_data *data, u8 *msg) static irqreturn_t mxt_process_messages_until_invalid(struct mxt_data *data) { u8 *message = &data->msg_buf[0]; - const u8 *payload = &data->msg_buf[1]; struct device *dev = &data->client->dev; u8 reportid; bool update_input = false; - u32 crc; do { if (mxt_read_message(data, message)) { @@ -764,19 +796,7 @@ static irqreturn_t mxt_process_messages_until_invalid(struct mxt_data *data) reportid = message[0]; if (reportid == data->T6_reportid) { - u8 status = payload[0]; - - crc = mxt_extract_T6_csum(&payload[1]); - if (crc != data->config_crc) { - data->config_crc = crc; - complete(&data->crc_completion); - } - - dev_dbg(dev, "Status: %02x Config Checksum: %06x\n", - status, data->config_crc); - - if (status & MXT_T6_STATUS_RESET) - complete(&data->reset_completion); + mxt_proc_t6_messages(data, message); } else if (mxt_is_T9_message(data, message)) { mxt_input_touchevent(data, message); update_input = true;