From: Dudley Du <dudley.dulixin@gmail.com>
To: dmitry.torokhov@gmail.com, rydberg@euromail.se
Cc: Dudley Du <dudl@cypress.com>,
bleung@google.com, patrikf@google.com,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 09/13] input: cyapa: add gen3 trackpad device read firmware image function support
Date: Wed, 15 Oct 2014 15:19:23 +0800 [thread overview]
Message-ID: <1413357567-26177-10-git-send-email-dudl@cypress.com> (raw)
In-Reply-To: <1413357567-26177-1-git-send-email-dudl@cypress.com>
Add read firmware image function supported for gen3 trackpad device,
which its function is supplied through cyapa core read_fw interface.
TEST=test on Chromebooks.
Signed-off-by: Dudley Du <dudl@cypress.com>
---
drivers/input/mouse/cyapa_gen3.c | 74 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 74 insertions(+)
diff --git a/drivers/input/mouse/cyapa_gen3.c b/drivers/input/mouse/cyapa_gen3.c
index c92da08..1f862d3 100644
--- a/drivers/input/mouse/cyapa_gen3.c
+++ b/drivers/input/mouse/cyapa_gen3.c
@@ -710,6 +710,36 @@ static int cyapa_gen3_write_fw_block(struct cyapa *cyapa,
return ret;
}
+/*
+ * A firmware block read command reads 16 bytes of data from flash starting
+ * from a given address. The 12-byte block read command has the format:
+ * <0xff> <CMD> <Key> <Addr>
+ *
+ * <0xff> - every command starts with 0xff
+ * <CMD> - the read command value is 0x3c
+ * <Key> - read commands include an 8-byte key: { 00 01 02 03 04 05 06 07 }
+ * <Addr> - Memory address (16-bit, big-endian)
+ *
+ * The command is followed by an i2c block read to read the 16 bytes of data.
+ */
+static int cyapa_gen3_read_fw_bytes(struct cyapa *cyapa, u16 addr, u8 *data)
+{
+ int ret;
+ u8 cmd[] = { 0xff, 0x3c, 0x00, 0x01, 0x02, 0x03, 0x04,
+ 0x05, 0x06, 0x07, addr >> 8, addr };
+
+ ret = cyapa_gen3_write_buffer(cyapa, cmd, sizeof(cmd));
+ if (ret)
+ return ret;
+
+ /* Read data buffer starting from offset 16 */
+ ret = cyapa_i2c_reg_read_block(cyapa, 16, CYAPA_FW_READ_SIZE, data);
+ if (ret != CYAPA_FW_READ_SIZE)
+ return (ret < 0) ? ret : -EIO;
+
+ return 0;
+}
+
static int cyapa_gen3_write_blocks(struct cyapa *cyapa,
size_t start_block, size_t block_count,
const u8 *image_data)
@@ -756,6 +786,48 @@ static int cyapa_gen3_do_fw_update(struct cyapa *cyapa,
return 0;
}
+/*
+ * Read the entire firmware image into ->fw_image.
+ * If the ->fw_image has already been allocated, then this function
+ * doesn't do anything and just returns 0.
+ * If an error occurs while reading the image, ->fw_image is freed, and
+ * the error is returned.
+ *
+ * The firmware is a fixed size (CYAPA_FW_SIZE), and is read out in
+ * fixed length (CYAPA_FW_READ_SIZE) chunks.
+ */
+static int cyapa_gen3_read_fw(struct cyapa *cyapa)
+{
+ int ret;
+ int addr;
+
+ ret = cyapa_gen3_bl_enter(cyapa);
+ if (ret)
+ goto err;
+
+ cyapa->fw_image = devm_kzalloc(&cyapa->client->dev,
+ CYAPA_FW_SIZE, GFP_KERNEL);
+ if (!cyapa->fw_image) {
+ ret = -ENOMEM;
+ goto err;
+ }
+
+ for (addr = 0; addr < CYAPA_FW_SIZE; addr += CYAPA_FW_READ_SIZE) {
+ ret = cyapa_gen3_read_fw_bytes(cyapa, CYAPA_FW_HDR_START + addr,
+ &cyapa->fw_image[addr]);
+ if (ret) {
+ devm_kfree(&cyapa->client->dev, cyapa->fw_image);
+ cyapa->fw_image = NULL;
+ break;
+ }
+ }
+
+err:
+ if (cyapa->fw_image)
+ cyapa->fw_image_size = CYAPA_FW_SIZE;
+ return ret;
+}
+
static ssize_t cyapa_gen3_do_calibrate(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
@@ -1206,6 +1278,8 @@ const struct cyapa_dev_ops cyapa_gen3_ops = {
.show_baseline = cyapa_gen3_show_baseline,
.calibrate_store = cyapa_gen3_do_calibrate,
+ .read_fw = cyapa_gen3_read_fw,
+
.state_parse = cyapa_gen3_state_parse,
.operational_check = cyapa_gen3_do_operational_check,
--
1.9.1
next prev parent reply other threads:[~2014-10-15 7:19 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-15 7:19 [PATCH 00/13] input: cyapa: intruction of cyapa patches Dudley Du
2014-10-15 7:19 ` [PATCH 01/13] input: cyapa: re-architecture driver to support multi-trackpads in one driver Dudley Du
2014-10-15 7:19 ` [PATCH 02/13] input: cyapa: add cyapa driver power management interfaces support Dudley Du
2014-10-15 7:19 ` [PATCH 03/13] input: cyapa: add cyapa driver runtime " Dudley Du
2014-10-15 7:19 ` [PATCH 04/13] input: cyapa: add cyapa key function interfaces in sysfs system Dudley Du
2014-10-15 7:19 ` [PATCH 05/13] input: cyapa: add read firmware image and raw data interfaces in debugfs system Dudley Du
2014-10-15 7:19 ` [PATCH 06/13] input: cyapa: add gen3 trackpad device basic functions support Dudley Du
2014-10-15 7:19 ` [PATCH 07/13] input: cyapa: add gen3 trackpad device firmware update function support Dudley Du
2014-10-15 7:19 ` [PATCH 08/13] input: cyapa: add gen3 trackpad device baseline and calibrate functions support Dudley Du
2014-10-15 7:19 ` Dudley Du [this message]
2014-10-15 7:19 ` [PATCH 10/13] input: cyapa: add gen5 trackpad device basic " Dudley Du
2014-10-15 7:19 ` [PATCH 11/13] input: cyapa: add gen5 trackpad device firmware update function support Dudley Du
2014-10-15 7:19 ` [PATCH 12/13] input: cyapa: add gen5 trackpad device baseline and calibrate functions support Dudley Du
2014-10-15 7:19 ` [PATCH 13/13] input: cyapa: add gen5 trackpad device read firmware image and raw data " Dudley Du
2014-10-15 7:37 ` [PATCH 00/13] input: cyapa: intruction of cyapa patches Dudley Du
2014-10-20 1:15 ` Dudley Du
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=1413357567-26177-10-git-send-email-dudl@cypress.com \
--to=dudley.dulixin@gmail.com \
--cc=bleung@google.com \
--cc=dmitry.torokhov@gmail.com \
--cc=dudl@cypress.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=patrikf@google.com \
--cc=rydberg@euromail.se \
/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;
as well as URLs for NNTP newsgroup(s).