From patchwork Mon Jul 11 12:11:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "jeffrey.lin" X-Patchwork-Id: 9223407 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9452960760 for ; Mon, 11 Jul 2016 12:12:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8217027C38 for ; Mon, 11 Jul 2016 12:12:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 72FCF27CEA; Mon, 11 Jul 2016 12:12:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46F3827C38 for ; Mon, 11 Jul 2016 12:12:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752525AbcGKMMY (ORCPT ); Mon, 11 Jul 2016 08:12:24 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:33925 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752062AbcGKMMX (ORCPT ); Mon, 11 Jul 2016 08:12:23 -0400 Received: by mail-pf0-f196.google.com with SMTP id g202so2618826pfb.1; Mon, 11 Jul 2016 05:12:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=IvcsHkoKnLG5ds+uaQCEfGlKdCiGukF4OY67Vtgf7jo=; b=xfZKQF6YzoNs+gSgGNepjiwhuKlkz6fKOUJuSj70CtJSm89ejfXG48b36Ps3/d9Qsr JpEtJNZaQXVIWX0qou8zYuvQocp9r5q3jkY0dI6C+1X8UybXaSvr/6hVKSSy3P3YYfSM p04YDzZPu1zP+BzFG368bXkeBvKdr1zhJ/TbX+e0/q4zaJP10f6X6yviuFf/HFm53GD6 Wc3iWzVwj1MfHjsUNLEk7HUHBt+Zmf/d1qGnzbw1hQeCJXNCh+wg/EGb6jsZaw1G2yiA VKmfkmGQC0oAFcC1mH5M+qIEC6wlPkvOsn5vpi/AUozmWHjCREZyTV50+ESRc3pQX0AT b0jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=IvcsHkoKnLG5ds+uaQCEfGlKdCiGukF4OY67Vtgf7jo=; b=ddQ3w0loopTKmOPY0pGKQaRF5TP1xWffN2bSobVgHU+io3ri6CePHWCYSPNaFYttHf xDnNPTDdKRKZiFzHbWXTLXcPMxK0D9D9ZblUzRAfFmQpoN9+OGPM+LoRRlCVo9EiIMKd Eqn7j2pkpH94CCEK/UYA0lBohrF74Ia37h8Aozw4TWn88wizkxuz8sZ34IeGoU3xoYAB IWEbwIOVetdDmPH/L3vwFIQLueZQGUHgjJJ4C+rvG/Y+NmavooKIOb0R2sd34RCGskUk 2iULYD2nwNwbfF7wGy0YAj92+XUiFIRg8rPAj+1XsyS9QZjT6NOXXpYPFH65k4uPznyY A/2A== X-Gm-Message-State: ALyK8tLzvWI4NNeQ9eD8SGmYdQrOW2sy+f4ZoMyrDxtnsVYvjnc0TSIKxhPjaxyzjgNSWg== X-Received: by 10.98.9.68 with SMTP id e65mr34492181pfd.121.1468239142774; Mon, 11 Jul 2016 05:12:22 -0700 (PDT) Received: from localhost.localdomain (39-8-21-84.adsl.fetnet.net. [39.8.21.84]) by smtp.gmail.com with ESMTPSA id n80sm6420743pfi.19.2016.07.11.05.12.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Jul 2016 05:12:21 -0700 (PDT) From: "jeffrey.lin" X-Google-Original-From: "jeffrey.lin" To: dmitry.torokhov@gmail.com, rydberg@euromail.se, groeck@chromium.org, robh@kernel.org Cc: jeffrey.lin@rad-ic.com, ealin.chiu@rad-ic.com, jason.yeh@rad-ic.com, KP.li@rad-ic.com, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org Subject: [PATCH] [v1.1] driver: input :touchscreen : add Raydium crc touch function Date: Mon, 11 Jul 2016 05:11:55 -0700 Message-Id: <1468239115-54712-1-git-send-email-jeffrey.lin@rad-ic.com> X-Mailer: git-send-email 2.1.2 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP add checksum for touch report points. Signed-off-by: jeffrey.lin --- drivers/input/touchscreen/raydium_i2c_ts.c | 68 +++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/drivers/input/touchscreen/raydium_i2c_ts.c b/drivers/input/touchscreen/raydium_i2c_ts.c index f3076d9..877d708 100644 --- a/drivers/input/touchscreen/raydium_i2c_ts.c +++ b/drivers/input/touchscreen/raydium_i2c_ts.c @@ -70,6 +70,8 @@ #define RM_CONTACT_WIDTH_X_POS 6 #define RM_CONTACT_WIDTH_Y_POS 7 +#define RM_CONTACT_CRC_SIZE 2 + /* Bootloader relative info */ #define RM_BL_WRT_CMD_SIZE 3 /* bl flash wrt cmd size */ #define RM_BL_WRT_PKG_SIZE 32 /* bl wrt pkg size */ @@ -137,6 +139,7 @@ struct raydium_data { u32 data_bank_addr; u8 report_size; u8 contact_size; + u8 pkg_size; enum raydium_boot_mode boot_mode; @@ -280,12 +283,14 @@ static int raydium_i2c_query_ts_info(struct raydium_data *ts) * then the size changed (due to firmware update?) and keep * old size instead. */ - if (ts->report_data && ts->report_size != data_info.pkg_size) + if (ts->report_data && ts->pkg_size != data_info.pkg_size) dev_warn(&client->dev, "report size changes, was: %d, new: %d\n", - ts->report_size, data_info.pkg_size); - else - ts->report_size = data_info.pkg_size; + ts->pkg_size, data_info.pkg_size); + else { + ts->pkg_size = data_info.pkg_size; + ts->report_size = ts->pkg_size - RM_CONTACT_CRC_SIZE; + } ts->contact_size = data_info.tp_info_size; ts->data_bank_addr = le32_to_cpu(data_info.data_bank_addr); @@ -612,6 +617,17 @@ static int raydium_i2c_fw_write_page(struct i2c_client *client, return error; } +static u16 raydium_calc_chksum(const u8 *buf, u16 len) +{ + u16 checksum = 0; + u16 i; + + for (i = 0; i < len; i++) + checksum += buf[i]; + + return checksum; +} + static int raydium_i2c_do_update_firmware(struct raydium_data *ts, const struct firmware *fw) { @@ -724,9 +740,7 @@ static int raydium_i2c_do_update_firmware(struct raydium_data *ts, return error; } - fw_checksum = 0; - for (i = 0; i < fw->size; i++) - fw_checksum += fw->data[i]; + fw_checksum = raydium_calc_chksum(fw->data, fw->size); error = raydium_i2c_write_checksum(client, fw->size, fw_checksum); if (error) @@ -780,15 +794,6 @@ out_enable_irq: static void raydium_mt_event(struct raydium_data *ts) { int i; - int error; - - error = raydium_i2c_read_message(ts->client, ts->data_bank_addr, - ts->report_data, ts->report_size); - if (error) { - dev_err(&ts->client->dev, "%s: failed to read data: %d\n", - __func__, error); - return; - } for (i = 0; i < ts->report_size / ts->contact_size; i++) { u8 *contact = &ts->report_data[ts->contact_size * i]; @@ -796,9 +801,10 @@ static void raydium_mt_event(struct raydium_data *ts) u8 wx, wy; input_mt_slot(ts->input, i); - input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, state); + input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, + state == 0x01); - if (!state) + if (state != 0x01) continue; input_report_abs(ts->input, ABS_MT_POSITION_X, @@ -819,12 +825,32 @@ static void raydium_mt_event(struct raydium_data *ts) input_sync(ts->input); } +static void raydium_i2c_event(struct raydium_data *ts) +{ + u16 fw_crc; + u16 calc_crc = raydium_calc_chksum(ts->report_data, ts->report_size); + + fw_crc = get_unaligned_le16(&ts->report_data[ts->report_size]); + + if (unlikely(fw_crc != calc_crc)) + dev_warn(&ts->client->dev, + "%s: invalid packet crc %04x &. %04x\n", + __func__, calc_crc, fw_crc); + else + raydium_mt_event(ts); +} + static irqreturn_t raydium_i2c_irq(int irq, void *_dev) { struct raydium_data *ts = _dev; + int error; - if (ts->boot_mode != RAYDIUM_TS_BLDR) - raydium_mt_event(ts); + if (ts->boot_mode == RAYDIUM_TS_MAIN) { + error = raydium_i2c_read_message(ts->client, ts->data_bank_addr, + ts->report_data, ts->pkg_size); + if (!error) + raydium_i2c_event(ts); + } return IRQ_HANDLED; } @@ -1050,7 +1076,7 @@ static int raydium_i2c_probe(struct i2c_client *client, } ts->report_data = devm_kmalloc(&client->dev, - ts->report_size, GFP_KERNEL); + ts->pkg_size, GFP_KERNEL); if (!ts->report_data) return -ENOMEM;