Skip to contentSkip to conversation

Input: synaptics-rmi4 - add support for F34 V7 bootloader

PATCH In review Nick Dyer 2 participants 4 messages Dec 11, 2016 – Dec 12, 2016

Subsystems (2)
lore
Share & tools
lore

Nick Dyer

author
#0 lore raw

PATCH v9 1/1 Input: synaptics-rmi4 - add support for F34 V7 bootloader

Port firmware update code from Samsung Galaxy S7 driver into mainline framework.

This patch has been tested on Synaptics S7813.

---

Changes in v9:
- Fix strangeness introduced in conversion to proper le32_to_cpu() APIs
- Various other minor tidyups.

Changes in v8:
- Address Dmitry Torokhov review comments.

Changes in v7:
- Removed bitfields (would cause issues on big endian archs)

Changes in v6:
- Properly free irq_memory in rmi_free_function_list()
- Split out the sysfs changes for now
- Various coding style improvements to the V7 patch (now checkpatch clean)

Changes in v5:
- Improve split between for different versions (req. Bjorn Andersson)
- Address a couple of kbuild test robot issues
- Fix a bug with configuration ID on V7

Changes in v4:
- Add support for v7 bootloaders and fix numerous issues
- Add sysfs attributes for retrieving various hardware IDs
- Add a couple of debug lines to core

Changes in v3:
- Only attempt to flash on F34 V0 (later versions have different register map)

Changes in v2:
- Resolved reliability issues with locking and teardown/re-probe
- Add #ifdefs for CONFIG_RMI4_F34 in rmi_driver.c
- Slightly improve debug
- Tested by Chris Healy

 drivers/input/rmi4/Makefile     |    2 +-
 drivers/input/rmi4/rmi_driver.c |   56 +-
 drivers/input/rmi4/rmi_f34.c    |   40 +-
 drivers/input/rmi4/rmi_f34.h    |  250 ++++++-
 drivers/input/rmi4/rmi_f34v7.c  | 1384 +++++++++++++++++++++++++++++++++++++++
 include/linux/rmi.h             |    2 +-
 6 files changed, 1700 insertions(+), 34 deletions(-)
 create mode 100644 drivers/input/rmi4/rmi_f34v7.c
drivers/input/rmi4/Makefile +1 -1
index a199cbe..9aaac3d 100644
@@ -8,7 +8,7 @@ rmi_core-$(CONFIG_RMI4_F03) += rmi_f03.o
 rmi_core-$(CONFIG_RMI4_F11) += rmi_f11.o
 rmi_core-$(CONFIG_RMI4_F12) += rmi_f12.o
 rmi_core-$(CONFIG_RMI4_F30) += rmi_f30.o
-rmi_core-$(CONFIG_RMI4_F34) += rmi_f34.o
+rmi_core-$(CONFIG_RMI4_F34) += rmi_f34.o rmi_f34v7.o
 rmi_core-$(CONFIG_RMI4_F54) += rmi_f54.o
 rmi_core-$(CONFIG_RMI4_F55) += rmi_f55.o
 
drivers/input/rmi4/rmi_driver.c +33 -23

94 lines not on this page · raw message

drivers/input/rmi4/rmi_f34.c +33 -7
index 01936a4..9774dfb 100644
@@ -12,6 +12,7 @@
 #include <linux/firmware.h>
 #include <asm/unaligned.h>
 #include <asm/unaligned.h>
+#include <linux/bitops.h>
 
 #include "rmi_driver.h"
 #include "rmi_f34.h"
@@ -105,6 +106,9 @@ static int rmi_f34_attention(struct rmi_function *fn, unsigned long *irq_bits)
 	struct f34_data *f34 = dev_get_drvdata(&fn->dev);
 	int ret;
 
+	if (f34->bl_version != 5)
+		return 0;
+
 	ret = rmi_read(f34->fn->rmi_dev, f34->v5.ctrl_address, &f34->v5.status);
 	rmi_dbg(RMI_DEBUG_FN, &fn->dev, "%s: status: %#02x, ret: %d\n",
 		__func__, f34->v5.status, ret);
@@ -292,17 +296,24 @@ static int rmi_firmware_update(struct rmi_driver_data *data,
 		return -EINVAL;
 	}
 
-	/* Only version 0 currently supported */
-	if (data->f34_container->fd.function_version != 0) {
+	f34 = dev_get_drvdata(&data->f34_container->dev);
+
+	if (f34->bl_version == 7) {
+		if (data->pdt_props & HAS_BSR) {
+			dev_err(dev, "%s: LTS not supported\n", __func__);
+			return -ENODEV;
+		}
+	} else if (f34->bl_version != 5) {
 		dev_warn(dev, "F34 V%d not supported!\n",
 			 data->f34_container->fd.function_version);
 		return -ENODEV;
 	}
 
-	f34 = dev_get_drvdata(&data->f34_container->dev);
-
 	/* Enter flash mode */
-	ret = rmi_f34_enable_flash(f34);
+	if (f34->bl_version == 7)
+		ret = rmi_f34v7_start_reflash(f34, fw);
+	else
+		ret = rmi_f34_enable_flash(f34);
 	if (ret)
 		return ret;
 
@@ -319,7 +330,7 @@ static int rmi_firmware_update(struct rmi_driver_data *data,
 	if (ret)
 		return ret;
 
-	if (!data->f01_bootloader_mode || !data->f34_container) {
+	if (!data->bootloader_mode || !data->f34_container) {
 		dev_warn(dev, "%s: No F34 present or not in bootloader!\n",
 				__func__);
 		return -EINVAL;
@@ -330,7 +341,10 @@ static int rmi_firmware_update(struct rmi_driver_data *data,
 	f34 = dev_get_drvdata(&data->f34_container->dev);
 
 	/* Perform firmware update */
-	ret = rmi_f34_update_firmware(f34, fw);
+	if (f34->bl_version == 7)
+		ret = rmi_f34v7_do_reflash(f34, fw);
+	else
+		ret = rmi_f34_update_firmware(f34, fw);
 
 	dev_info(&f34->fn->dev, "Firmware update complete, status:%d\n", ret);
 
@@ -363,6 +377,9 @@ static int rmi_firmware_update(struct rmi_driver_data *data,
 	return ret;
 }
 
+static int rmi_firmware_update(struct rmi_driver_data *data,
+			       const struct firmware *fw);
+
 static ssize_t rmi_driver_update_fw_store(struct device *dev,
 					  struct device_attribute *dattr,
 					  const char *buf, size_t count)
@@ -411,6 +428,7 @@ static int rmi_f34_probe(struct rmi_function *fn)
 	struct f34_data *f34;
 	unsigned char f34_queries[9];
 	bool has_config_id;
+	u8 version = fn->fd.function_version;
 	int ret;
 
 	f34 = devm_kzalloc(&fn->dev, sizeof(struct f34_data), GFP_KERNEL);
@@ -420,6 +438,14 @@ static int rmi_f34_probe(struct rmi_function *fn)
 	f34->fn = fn;
 	dev_set_drvdata(&fn->dev, f34);
 
+	/* v5 code only supported version 0, try V7 probe */
+	if (version > 0)
+		return rmi_f34v7_probe(f34);
+	else if (version != 0)
+		return -ENODEV;
+
+	f34->bl_version = 5;
+
 	ret = rmi_read_block(fn->rmi_dev, fn->fd.query_base_addr,
 			     f34_queries, sizeof(f34_queries));
 	if (ret) {
drivers/input/rmi4/rmi_f34.h +248 -2

267 lines not on this page · raw message

drivers/input/rmi4/rmi_f34v7.c new file +1384 -0

1,384 lines not on this page · raw message

include/linux/rmi.h +1 -1
index ac910f7..64125443 100644
@@ -342,7 +342,7 @@ struct rmi_driver_data {
 
 	struct rmi_function *f01_container;
 	struct rmi_function *f34_container;
-	bool f01_bootloader_mode;
+	bool bootloader_mode;
 
 	int num_of_irq_regs;
 	int irq_count;
Signature · 1 line
2.7.4
maintainer
#1 lore raw

Hi NIck,

Review

Quoted 12 lines · Nick Dyer
(quoted diff) +12 -0
+static void rmi_f34v7_parse_img_header_10_bl_container(struct f34_data *f34,
+						       const u8 *image)
+{
+	int i;
+	int num_of_containers;
+	unsigned int addr;
+	unsigned int container_id;
+	unsigned int length;
+	const u8 *content;
+	struct container_descriptor *descriptor;
+
+	BUG_ON(f34->v7.img.bootloader.size < 4);

Killing the box because you got bad firmware is not very nice...

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	num_of_containers = (f34->v7.img.bootloader.size - 4) / 4;

Wouldn't

	num_of_containes = f34->v7.img.bootloader.size / 4 - 1;

give the same result but be less "suspicious". The variable is 'int' so for size < 4 we'll get a negative and the loop won't execute.

Review

Quoted 4 lines
(quoted diff) +4 -0
+
+	for (i = 1; i <= num_of_containers; i++) {
+		addr = get_unaligned_le32(f34->v7.img.bootloader.data + i*4);
+		descriptor = (struct container_descriptor *)(image + addr);

This casts away constness, which is not nice. DOes it still work if you apply the below on top?

Thanks!

Signature · 12 lines
Dmitry


Input: synaptics-rmi4 - misc f34v7 changes

From: Dmitry Torokhov <[email protected]>

Signed-off-by: Dmitry Torokhov <[email protected]>
---
 drivers/input/rmi4/rmi_f34.h   |    6 ++--
 drivers/input/rmi4/rmi_f34v7.c |   64 ++++++++++++++++------------------------
 2 files changed, 28 insertions(+), 42 deletions(-)
drivers/input/rmi4/rmi_f34.h +3 -3
index 12827f4..2c21056 100644
@@ -145,7 +145,7 @@ struct f34v7_data_1_5 {
 } __packed;
 
 struct block_data {
-	const u8 *data;
+	const void *data;
 	int size;
 };
 
@@ -290,8 +290,8 @@ struct f34v7_data {
 	struct physical_address phyaddr;
 	struct image_metadata img;
 
-	const u8 *config_data;
-	const u8 *image;
+	const void *config_data;
+	const void *image;
 };
 
 struct f34_data {
drivers/input/rmi4/rmi_f34v7.c +25 -39

147 lines not on this page · raw message

author Tested-by
#2 lore raw
Quoted 21 lines · Dmitry Torokhov

Review

Quoted 12 lines · Nick Dyer
(quoted diff) +12 -0
+static void rmi_f34v7_parse_img_header_10_bl_container(struct f34_data *f34,
+						       const u8 *image)
+{
+	int i;
+	int num_of_containers;
+	unsigned int addr;
+	unsigned int container_id;
+	unsigned int length;
+	const u8 *content;
+	struct container_descriptor *descriptor;
+
+	BUG_ON(f34->v7.img.bootloader.size < 4);

Killing the box because you got bad firmware is not very nice...

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	num_of_containers = (f34->v7.img.bootloader.size - 4) / 4;

Wouldn't

Quoted 4 lines
	num_of_containes = f34->v7.img.bootloader.size / 4 - 1;

give the same result but be less "suspicious". The variable is 'int' so for size < 4 we'll get a negative and the loop won't execute.

Neat!

Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+
+	for (i = 1; i <= num_of_containers; i++) {
+		addr = get_unaligned_le32(f34->v7.img.bootloader.data + i*4);
+		descriptor = (struct container_descriptor *)(image + addr);

This casts away constness, which is not nice. DOes it still work if you apply the below on top?

I've run it through a few flash cycles with no issues.

Quoted 1 line

Thanks!

Thanks for your help with this.

Quoted 14 lines
Signature · 13 lines
-- 
Dmitry


Input: synaptics-rmi4 - misc f34v7 changes

From: Dmitry Torokhov <[email protected]>

Signed-off-by: Dmitry Torokhov <[email protected]>
---
 drivers/input/rmi4/rmi_f34.h   |    6 ++--
 drivers/input/rmi4/rmi_f34v7.c |   64 ++++++++++++++++------------------------
 2 files changed, 28 insertions(+), 42 deletions(-)
maintainer
#3 lore raw
Quoted 37 lines · Nick Dyer
Quoted 21 lines · Dmitry Torokhov

Review

Quoted 12 lines · Nick Dyer
(quoted diff) +12 -0
+static void rmi_f34v7_parse_img_header_10_bl_container(struct f34_data *f34,
+						       const u8 *image)
+{
+	int i;
+	int num_of_containers;
+	unsigned int addr;
+	unsigned int container_id;
+	unsigned int length;
+	const u8 *content;
+	struct container_descriptor *descriptor;
+
+	BUG_ON(f34->v7.img.bootloader.size < 4);

Killing the box because you got bad firmware is not very nice...

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	num_of_containers = (f34->v7.img.bootloader.size - 4) / 4;

Wouldn't

Quoted 4 lines
	num_of_containes = f34->v7.img.bootloader.size / 4 - 1;

give the same result but be less "suspicious". The variable is 'int' so for size < 4 we'll get a negative and the loop won't execute.

Neat!

Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+
+	for (i = 1; i <= num_of_containers; i++) {
+		addr = get_unaligned_le32(f34->v7.img.bootloader.data + i*4);
+		descriptor = (struct container_descriptor *)(image + addr);

This casts away constness, which is not nice. DOes it still work if you apply the below on top?

Quoted 3 lines

I've run it through a few flash cycles with no issues.

Great, I'll fold and apply then. Thanks!

Signature · 1 line
Dmitry