From patchwork Thu Oct 20 19:59:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Franklin Cooper X-Patchwork-Id: 9387507 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 C803B60487 for ; Thu, 20 Oct 2016 20:01:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B411D29B73 for ; Thu, 20 Oct 2016 20:01:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A898829BA0; Thu, 20 Oct 2016 20:01:43 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable 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 5175C29B73 for ; Thu, 20 Oct 2016 20:01:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932921AbcJTUAI (ORCPT ); Thu, 20 Oct 2016 16:00:08 -0400 Received: from comal.ext.ti.com ([198.47.26.152]:55016 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751742AbcJTUAH (ORCPT ); Thu, 20 Oct 2016 16:00:07 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id u9KJxqhg004146; Thu, 20 Oct 2016 14:59:52 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id u9KJxq7M029083; Thu, 20 Oct 2016 14:59:52 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.294.0; Thu, 20 Oct 2016 14:59:51 -0500 Received: from dbdmail01.india.ti.com (dbdmail01.india.ti.com [172.24.162.206]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id u9KJxo3k022564; Thu, 20 Oct 2016 14:59:51 -0500 Received: from udb0273011.am.dhcp.ti.com (udb0273011.am.dhcp.ti.com [128.247.83.33]) by dbdmail01.india.ti.com (8.14.3/8.14.3/SuSE Linux 0.8) with ESMTP id u9KJxfax011145; Fri, 21 Oct 2016 01:29:47 +0530 From: Franklin S Cooper Jr To: , , , , , , , , , , CC: Franklin S Cooper Jr Subject: [PATCH 1/4] Input: goodix - Restructure cfg checksum function Date: Thu, 20 Oct 2016 14:59:14 -0500 Message-ID: <20161020195917.20051-2-fcooper@ti.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20161020195917.20051-1-fcooper@ti.com> References: <20161020195917.20051-1-fcooper@ti.com> MIME-Version: 1.0 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 Split generation of checksum into is own function. Currently it is used only to determine if the checksum for the user provided configuration file is valid or not. However, support to dynamically alter the configuration file will be supported and needs a way to calculate the updated file's checksum. Therefore, by splitting calculating checksum into its own function the code can be reused. Signed-off-by: Franklin S Cooper Jr Reviewed-by: Bastien Nocera --- drivers/input/touchscreen/goodix.c | 42 +++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/drivers/input/touchscreen/goodix.c b/drivers/input/touchscreen/goodix.c index e9d50bc..a43c8ca 100644 --- a/drivers/input/touchscreen/goodix.c +++ b/drivers/input/touchscreen/goodix.c @@ -305,35 +305,45 @@ static int goodix_request_irq(struct goodix_ts_data *ts) ts->irq_flags, ts->client->name, ts); } +static int goodix_calculate_checksum(size_t size, const u8 *data) +{ + int i, raw_cfg_len; + u8 check_sum = 0; + + raw_cfg_len = size - 2; + for (i = 0; i < raw_cfg_len; i++) + check_sum += data[i]; + check_sum = (~check_sum) + 1; + + return check_sum; +} /** * goodix_check_cfg - Checks if config fw is valid * * @ts: goodix_ts_data pointer * @cfg: firmware config data */ -static int goodix_check_cfg(struct goodix_ts_data *ts, - const struct firmware *cfg) +static int goodix_check_cfg(struct goodix_ts_data *ts, size_t size, + const u8 *data) { - int i, raw_cfg_len; + int raw_cfg_len; u8 check_sum = 0; - if (cfg->size > GOODIX_CONFIG_MAX_LENGTH) { + if (size > GOODIX_CONFIG_MAX_LENGTH) { dev_err(&ts->client->dev, "The length of the config fw is not correct"); return -EINVAL; } - raw_cfg_len = cfg->size - 2; - for (i = 0; i < raw_cfg_len; i++) - check_sum += cfg->data[i]; - check_sum = (~check_sum) + 1; - if (check_sum != cfg->data[raw_cfg_len]) { + raw_cfg_len = size - 2; + check_sum = goodix_calculate_checksum(size, data); + if (check_sum != data[raw_cfg_len]) { dev_err(&ts->client->dev, "The checksum of the config fw is not correct"); return -EINVAL; } - if (cfg->data[raw_cfg_len + 1] != 1) { + if (data[raw_cfg_len + 1] != 1) { dev_err(&ts->client->dev, "Config fw must have Config_Fresh register set"); return -EINVAL; @@ -348,17 +358,17 @@ static int goodix_check_cfg(struct goodix_ts_data *ts, * @ts: goodix_ts_data pointer * @cfg: config firmware to write to device */ -static int goodix_send_cfg(struct goodix_ts_data *ts, - const struct firmware *cfg) +static int goodix_send_cfg(struct goodix_ts_data *ts, size_t size, + const u8 *data) { int error; - error = goodix_check_cfg(ts, cfg); + error = goodix_check_cfg(ts, size, data); if (error) return error; - error = goodix_i2c_write(ts->client, GOODIX_REG_CONFIG_DATA, cfg->data, - cfg->size); + error = goodix_i2c_write(ts->client, GOODIX_REG_CONFIG_DATA, data, + size); if (error) { dev_err(&ts->client->dev, "Failed to write config data: %d", error); @@ -670,7 +680,7 @@ static void goodix_config_cb(const struct firmware *cfg, void *ctx) if (cfg) { /* send device configuration to the firmware */ - error = goodix_send_cfg(ts, cfg); + error = goodix_send_cfg(ts, cfg->size, cfg->data); if (error) goto err_release_cfg; }