From: Dudley Du <dudley.dulixin@gmail.com>
To: dmitry.torokhov@gmail.com, rydberg@euromail.se
Cc: Dudley Du <dudl@cypress.com>,
bleung@google.com, linux-input@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v9 16/18] input: cyapa: add gen5 trackpad device read firmware image function support
Date: Mon, 3 Nov 2014 16:33:08 +0800 [thread overview]
Message-ID: <1415003590-30485-17-git-send-email-dudl@cypress.com> (raw)
In-Reply-To: <1415003590-30485-1-git-send-email-dudl@cypress.com>
Add read firmware image function supported for gen5 trackpad device,
it can be used through debugfs read_fw interface.
TEST=test on Chromebooks.
Signed-off-by: Dudley Du <dudl@cypress.com>
---
drivers/input/mouse/cyapa_gen5.c | 154 +++++++++++++++++++++++++++++++++++++++
1 file changed, 154 insertions(+)
diff --git a/drivers/input/mouse/cyapa_gen5.c b/drivers/input/mouse/cyapa_gen5.c
index 7e7de12..35334dc 100644
--- a/drivers/input/mouse/cyapa_gen5.c
+++ b/drivers/input/mouse/cyapa_gen5.c
@@ -1213,6 +1213,153 @@ static int cyapa_gen5_write_fw_block(struct cyapa *cyapa,
return 0;
}
+static int cyapa_gen5_read_fw_bytes(struct cyapa *cyapa, u16 row_num, u8 *data)
+{
+ int ret;
+ u8 cmd[16];
+ size_t cmd_len;
+ u8 resp_data[CYAPA_TSG_FW_ROW_SIZE / 2 + GEN5_MIN_BL_RESP_LENGTH];
+ int resp_len;
+ u16 offset;
+ u16 cmd_crc;
+ struct cyapa_tsg_bin_image_data_record *fw_img_record;
+
+ fw_img_record = (struct cyapa_tsg_bin_image_data_record *)data;
+
+ cmd[0] = 0x04; /* Register address */
+ cmd[1] = 0x00;
+ cmd[2] = 0x0e;
+ cmd[3] = 0x00;
+ cmd[4] = 0x40; /* Report id 40h */
+ cmd[5] = 0x00;
+ cmd[6] = GEN5_SOP_KEY;
+ cmd[7] = 0x3d; /* Read application image command code */
+ cmd[8] = 0x03;
+ cmd[9] = 0x00;
+ offset = row_num * CYAPA_TSG_FW_ROW_SIZE -
+ CYAPA_TSG_START_OF_APPLICATION;
+ put_unaligned_le16(offset, &cmd[10]);
+ cmd[12] = CYAPA_TSG_IMG_READ_SIZE;
+ cmd_crc = crc_itu_t(0xffff, &cmd[6], 7);
+ put_unaligned_le16(cmd_crc, &cmd[13]); /* CRC[15:0] */
+ cmd[15] = GEN5_EOP_KEY; /* EOP = 17h */
+ cmd_len = 16;
+
+ resp_len = CYAPA_TSG_IMG_READ_SIZE + GEN5_MIN_BL_RESP_LENGTH;
+ ret = cyapa_i2c_pip_cmd_irq_sync(cyapa,
+ cmd, cmd_len,
+ resp_data, &resp_len,
+ 50, cyapa_gen5_sort_tsg_pip_bl_resp_data, true);
+ if (resp_len != (CYAPA_TSG_IMG_READ_SIZE + GEN5_MIN_BL_RESP_LENGTH) ||
+ ret || resp_data[2] != GEN5_BL_RESP_REPORT_ID ||
+ !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5]))
+ return (ret < 0) ? ret : -EAGAIN;
+
+ /* Copy first 64 bytes in the row. */
+ memcpy(&fw_img_record->record_data[0], &resp_data[8],
+ CYAPA_TSG_IMG_READ_SIZE);
+
+ if (row_num == CYAPA_TSG_IMG_APP_INTEGRITY_ROW_NUM) {
+ /* Last row's rest 64 bytes are bootloader metadata,
+ * it's not allowed to be read out, will respond with error. */
+ memset(&fw_img_record->record_data[CYAPA_TSG_IMG_READ_SIZE],
+ 0, CYAPA_TSG_IMG_READ_SIZE);
+ goto skip_last_row;
+ }
+
+ /* Read next 64 bytes in the row. */
+ offset = offset + CYAPA_TSG_IMG_READ_SIZE;
+ put_unaligned_le16(offset, &cmd[10]);
+ cmd_crc = crc_itu_t(0xffff, &cmd[6], 7);
+ put_unaligned_le16(cmd_crc, &cmd[13]); /* CRC[15:0] */
+ ret = cyapa_i2c_pip_cmd_irq_sync(cyapa,
+ cmd, cmd_len,
+ resp_data, &resp_len,
+ 500, cyapa_gen5_sort_tsg_pip_bl_resp_data, true);
+ if (resp_len != (CYAPA_TSG_IMG_READ_SIZE + GEN5_MIN_BL_RESP_LENGTH) ||
+ ret || resp_data[2] != GEN5_BL_RESP_REPORT_ID ||
+ !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5]))
+ return (ret < 0) ? ret : -EAGAIN;
+
+ /* Copy last 64 bytes in the row. */
+ memcpy(&fw_img_record->record_data[CYAPA_TSG_IMG_READ_SIZE],
+ &resp_data[8], CYAPA_TSG_IMG_READ_SIZE);
+
+skip_last_row:
+ fw_img_record->flash_array_id = 0;
+ put_unaligned_be16(row_num, &fw_img_record->row_number);
+ put_unaligned_be16(CYAPA_TSG_FW_ROW_SIZE, &fw_img_record->record_len);
+
+ return 0;
+}
+
+static int cyapa_gen5_read_fw(struct cyapa *cyapa)
+{
+ int ret;
+ int fw_img_head_size;
+ int fw_img_record_size;
+ int fw_img_size;
+ int row_index;
+ int array_index;
+ u32 img_start;
+ u16 img_len;
+ u16 img_start_row;
+ u16 img_end_row;
+ struct cyapa_tsg_bin_image_data_record app_integrity;
+ u8 *record_data;
+
+ ret = cyapa_gen5_bl_enter(cyapa);
+ if (ret)
+ return ret;
+
+ cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
+
+ fw_img_head_size = sizeof(struct cyapa_tsg_bin_image_head);
+ fw_img_record_size = sizeof(struct cyapa_tsg_bin_image_data_record);
+
+ /* Read app integrity block data. */
+ row_index = CYAPA_TSG_IMG_APP_INTEGRITY_ROW_NUM;
+ ret = cyapa_gen5_read_fw_bytes(cyapa, row_index, (u8 *)&app_integrity);
+ if (ret)
+ return ret;
+ img_start = get_unaligned_le32(&app_integrity.record_data[16]);
+ img_len = get_unaligned_le16(&app_integrity.record_data[20]);
+ if ((img_start + img_len) % CYAPA_TSG_FW_ROW_SIZE)
+ return -EINVAL;
+ img_start_row = img_start / CYAPA_TSG_FW_ROW_SIZE;
+ img_end_row = (img_start + img_len) / CYAPA_TSG_FW_ROW_SIZE - 1;
+
+ /* Allocate memory for image. */
+ fw_img_size = fw_img_head_size +
+ (img_end_row - img_start_row + 2) * fw_img_record_size;
+ cyapa->fw_image = cyapa->fw_image ? cyapa->fw_image :
+ devm_kzalloc(&cyapa->client->dev, fw_img_size, GFP_KERNEL);
+ if (!cyapa->fw_image)
+ return -ENOMEM;
+
+ /* Set image head data. */
+ memcpy(cyapa->fw_image, &cyapa->fw_img_head, fw_img_head_size);
+
+ /* Read image blocks. */
+ for (row_index = img_start_row, array_index = 0;
+ row_index <= img_end_row;
+ row_index++, array_index++) {
+ record_data = &cyapa->fw_image[fw_img_head_size +
+ array_index * fw_img_record_size];
+ ret = cyapa_gen5_read_fw_bytes(cyapa, row_index, record_data);
+ if (ret)
+ return ret;
+ }
+
+ /* Append last app integrity block data. */
+ record_data = &cyapa->fw_image[fw_img_head_size +
+ array_index * fw_img_record_size];
+ memcpy(record_data, &app_integrity, fw_img_record_size);
+
+ cyapa->fw_image_size = fw_img_size;
+ return 0;
+}
+
static int cyapa_gen5_do_fw_update(struct cyapa *cyapa,
const struct firmware *fw)
{
@@ -2276,6 +2423,11 @@ static int cyapa_gen5_get_query_data(struct cyapa *cyapa)
if (ret || resp_len < sizeof(resp_data))
return ret;
+ cyapa->fw_img_head.head_size =
+ sizeof(struct cyapa_tsg_bin_image_head) - 1;
+ memcpy(&cyapa->fw_img_head.ttda_driver_major_version,
+ &resp_data[5], cyapa->fw_img_head.head_size);
+
product_family = get_unaligned_le16(&resp_data[7]);
if ((product_family & GEN5_PRODUCT_FAMILY_MASK) !=
GEN5_PRODUCT_FAMILY_TRACKPAD)
@@ -2609,6 +2761,8 @@ const struct cyapa_dev_ops cyapa_gen5_ops = {
.show_baseline = cyapa_gen5_show_baseline,
.calibrate_store = cyapa_gen5_do_calibrate,
+ .read_fw = cyapa_gen5_read_fw,
+
.initialize = cyapa_gen5_initialize,
.state_parse = cyapa_gen5_state_parse,
--
1.9.1
next prev parent reply other threads:[~2014-11-03 8:33 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-03 8:32 [PATCH v9 01/18] input: cyapa: instruction of cyapa patches Dudley Du
2014-11-03 8:32 ` [PATCH v9 01/18] input: cyapa: add device resource management infrastructure support Dudley Du
2014-11-09 21:25 ` Dmitry Torokhov
2014-11-10 2:48 ` Dudley Du
2014-11-10 3:30 ` Dmitry Torokhov
2014-11-03 8:32 ` [PATCH v9 02/18] input: cyapa: re-design driver to support multi-trackpad in one driver Dudley Du
2014-11-10 8:18 ` Dmitry Torokhov
2014-11-10 11:04 ` Dudley Du
2014-11-03 8:32 ` [PATCH v9 03/18] input: cyapa: add gen3 trackpad device basic functions support Dudley Du
2014-11-10 8:30 ` Dmitry Torokhov
2014-11-10 11:05 ` Dudley Du
2014-11-03 8:32 ` [PATCH v9 04/18] input: cyapa: add gen5 " Dudley Du
2014-11-03 8:32 ` [PATCH v9 05/18] input: cyapa: add power management interfaces supported for the device Dudley Du
2014-11-10 8:38 ` Dmitry Torokhov
2014-11-10 11:05 ` Dudley Du
2014-11-03 8:32 ` [PATCH v9 06/18] input: cyapa: add runtime " Dudley Du
2014-11-03 8:32 ` [PATCH v9 07/18] input: cyapa: add sysfs interfaces supported in the cyapa driver Dudley Du
2014-11-03 8:33 ` [PATCH v9 08/18] input: cyapa: add gen3 trackpad device firmware update function support Dudley Du
2014-11-03 8:33 ` [PATCH v9 09/18] input: cyapa: add gen3 trackpad device read baseline " Dudley Du
2014-11-03 8:33 ` [PATCH v9 10/18] input: cyapa: add gen3 trackpad device force re-calibrate " Dudley Du
2014-11-03 8:33 ` [PATCH v9 11/18] input: cyapa: add gen5 trackpad device firmware update " Dudley Du
2014-11-03 8:33 ` [PATCH v9 12/18] input: cyapa: add gen5 trackpad device read baseline " Dudley Du
2014-11-03 8:33 ` [PATCH v9 13/18] input: cyapa: add gen5 trackpad device force re-calibrate " Dudley Du
2014-11-03 8:33 ` [PATCH v9 14/18] input: cyapa: add read firmware image debugfs interface support Dudley Du
2014-11-03 8:33 ` [PATCH v9 15/18] input: cyapa: add gen3 trackpad device read firmware image function support Dudley Du
2014-11-10 8:39 ` Dmitry Torokhov
2014-11-10 11:05 ` Dudley Du
2014-12-04 17:46 ` Dmitry Torokhov
2014-12-05 1:43 ` Dudley Du
2014-11-03 8:33 ` Dudley Du [this message]
2014-11-03 8:33 ` [PATCH v9 17/18] input: cyapa: add read sensors raw data debugfs interface support Dudley Du
2014-11-03 8:33 ` [PATCH v9 18/18] input: cyapa: add gen5 trackpad device read raw data function support 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=1415003590-30485-17-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=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).