From: Franklin S Cooper Jr <fcooper@ti.com>
To: <dmitry.torokhov@gmail.com>, <robh+dt@kernel.org>,
<hadess@hadess.net>, <octavian.purdila@intel.com>,
<irina.tirdea@intel.com>, <merker@debian.org>,
<linux-input@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <nsekhar@ti.com>, <nm@ti.com>
Cc: Franklin S Cooper Jr <fcooper@ti.com>
Subject: [PATCH 1/4] Input: goodix - Restructure cfg checksum function
Date: Thu, 20 Oct 2016 14:59:14 -0500 [thread overview]
Message-ID: <20161020195917.20051-2-fcooper@ti.com> (raw)
In-Reply-To: <20161020195917.20051-1-fcooper@ti.com>
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 <fcooper@ti.com>
---
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;
}
--
2.10.0
next prev parent reply other threads:[~2016-10-20 20:00 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-20 19:59 [PATCH 0/4] Input: goodix - Support dynamic reconfiguration Franklin S Cooper Jr
2016-10-20 19:59 ` Franklin S Cooper Jr [this message]
2016-10-27 10:32 ` [PATCH 1/4] Input: goodix - Restructure cfg checksum function Bastien Nocera
2016-10-20 19:59 ` [PATCH 2/4] Input: goodix - Allow tweaking of configuration file dynamically Franklin S Cooper Jr
2016-10-27 10:33 ` Bastien Nocera
2016-10-27 16:58 ` Franklin S Cooper Jr
2016-10-27 17:41 ` Bastien Nocera
2016-10-20 19:59 ` [PATCH 3/4] Input: goodix - Tweak configuration to use passed in touchscreen resolution Franklin S Cooper Jr
2016-10-26 23:10 ` Rob Herring
2016-10-27 10:34 ` Bastien Nocera
2016-10-27 17:03 ` Franklin S Cooper Jr
2016-10-20 19:59 ` [PATCH 4/4] Input: goodix - Support interchanging x and y coordinates in hardware Franklin S Cooper Jr
2016-10-26 23:18 ` Rob Herring
2016-10-27 10:34 ` Bastien Nocera
2016-10-27 17:42 ` Franklin S Cooper Jr
2016-10-28 0:08 ` Bastien Nocera
2016-10-27 17:54 ` Franklin S Cooper Jr
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161020195917.20051-2-fcooper@ti.com \
--to=fcooper@ti.com \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=hadess@hadess.net \
--cc=irina.tirdea@intel.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=merker@debian.org \
--cc=nm@ti.com \
--cc=nsekhar@ti.com \
--cc=octavian.purdila@intel.com \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®