Skip to contentSkip to conversation

input: cyapa: instruction of cyapa patches

PATCH In review Dudley Du 4 participants 28 messages Jan 16, 2015 – Jan 19, 2015

Subsystems (2)
lore
Share & tools
lore

Dudley Du

author
#0 lore raw

v18 cover input: cyapa: instruction of cyapa patches

V18 patches have below updates, details of other updates see history list:
1) Fix 'cyapa_runtime_suspend' undeclared compiling issue in latest kernel-next source code. Verified on next-20150114 with make C=1.
2) Optimize enter bootloader failed for some chipset takes longer time issue.

This patch series is aimed to re-design the cyapa driver to support old gen3 trackpad devices and new gen5 trackpad devices in one cyapa driver, it's for easily productions support based on customers' requirements. And add sysfs functions and interfaces supported that required by users and customers.

Since the earlier gen3 and the latest gen5 trackpad devices using two different chipsets, and have different protocols and interfaces, so if supported these two type trackpad devices in two different drivers, then it will be difficult to manage productions and later firmware updates. e.g.: It will cause customer don't know which one trackpad device firmware image to use and update when it has been used and integrated
in same one productions, so here we support these two trackpad devices in same on driver.

Dudley Du (12):
input: cyapa: re-design driver to support multi-trackpad in one driver
input: cyapa: add gen5 trackpad device basic functions support
input: cyapa: add power management interfaces support for the device
input: cyapa: add runtime power management interfaces support for the
device
input: cyapa: add sysfs interfaces support in the cyapa driver
input: cyapa: add gen3 trackpad device firmware update function
support
input: cyapa: add gen3 trackpad device read baseline function support
input: cyapa: add gen3 trackpad device force re-calibrate function
support
input: cyapa: add gen5 trackpad device firmware update function
support
input: cyapa: add gen5 trackpad device read baseline function support
input: cyapa: add gen5 trackpad device force re-calibrate function
support
input: cyapa: add acpi device id support

 drivers/input/mouse/Kconfig      |   11 +-
 drivers/input/mouse/Makefile     |    3 +-
 drivers/input/mouse/cyapa.c      | 1711 ++++++++++++++---------
 drivers/input/mouse/cyapa.h      |  303 +++++
 drivers/input/mouse/cyapa_gen3.c | 1247 +++++++++++++++++
 drivers/input/mouse/cyapa_gen5.c | 2774 ++++++++++++++++++++++++++++++++++++++
 6 files changed, 5378 insertions(+), 671 deletions(-)
 create mode 100644 drivers/input/mouse/cyapa.h
 create mode 100644 drivers/input/mouse/cyapa_gen3.c
 create mode 100644 drivers/input/mouse/cyapa_gen5.c

History patch series modifications list:
V17 patches have below main updates compared with v16 patches:
1) Fix kernel oops when system booting up with finger on TP.
2) Remove unnecessary error log that may to system.
3) Slipt out pm sleep code into cyapa_prepare_wakeup_controls(), remove #indefs in function body of CONFIG_PM_SLEEP and CONFIG_PM_RUNTIME.
4) Supply stubs to cyapa_gen3_ops and cyapa_gen5_ops data structure to avoid checking for presence of various methods in ops.
5) Changing CYAPA_BOOTLOADER() and CYAPA_OPERATIONAL() macros to static inline functions as cyapa_is_bootloader_mode() and cyapa_is_operational_mode().
6) Remove touching runtime suspend state during system calling cyapa_suspend().
7) Change to enable runtime PM until make sure device is out of bootloader.
8) Change to return -EAGAIN when bootloader is busy.
9) Correct word spell issue and code styles.

V16 patches have below main updates compared with v15 patches:
1) Fix all miss-spelling and space issue.
2) Rename variables and functions with much more clearer names.
3) Initialize and document tries near where it will be used.
4) Modify cmd buffer to struct for more descriptive way.

V15 patches have below main updates compared with v14 patches:
1) Fix all warning errors of sparse tool when running with "make C=1".
2) Change variable name "unique_str" to "product_id" for clearer meanings.
3) Update cyapa_i2c_write function to return error directly when length > 31.

V14 patches have below main updates compared with v13 patches:
1) Correct 9 miss spelling issues of "bufferred" to "buffered".
2) Fix the upgrade issue of removing MOUSE_CYAPA config when make oldconfig by replase "depends on I2C && CRC_ITU_T" with
"depends on I2C"
"select CRC_ITU_T"
in patch 9.

V13 patches have below main updates compared with v12 patches:
1) Remove all debugfs interface, including read_fw and raw_data interfaces.
2) This patches are made based linux next-20141208.

V12 patches have below main updates compared with v11 patches:
1) Add check that when TP is detected but not operational, do not exit driver immediately, but wait and export the update_fw interface for recovering.
2) Re-arrange the function codes, remove unnesseary protype definitions in the header file.

V11 patches have below main updates compared with v10 patches:
1) Add add acpi device id supported for old gen3 and new gen5 trackpad devices.
2) Fix the unable to update firmware issue when cyapa_open is not called which means the irq for firwmare update process is not enabled. This fix by checking if the irq is enabled, if not then enable irq before start to do firmware update.

V10 patches have below main updates compared with v9 patches:
1) Modify code to following kernel code style.
e.g.: correct to use error as return name when there is only error path, and fix the checkpatch.sh wanting in the driver.
2) Remove cyapa_remove method and use input open and close interface to following device resouse management infrastructure.
3) Modify cyapa_detect method to return tristate issue to make the return value much more consistent and clear.
4) Use platform supplied functions as possible instead of driver specific rewritten version.

V9 patches have below updates compared with v8 patches:
1) Removed all async thread stuff from the driver.
2) Split driver into 18 patches for each function change one patch.

V8 patches have below updates compared with v7 patches:
1) [PATCH v8 01/13] - Remove the async thread for device detect in probe routine, now the device detect process is completely done within the device probe routine.
2) [PATCH v8 01/13] - Split the irq cmd handler function to separated function cyapa_default_irq_cmd_handler() and set it to interface cyapa_default_ops.irq_cmd_handler.
3) [PATCH v8 06/13] - Add cyapa->gen check in cyapa_gen3_irq_cmd_handler() to avoid miss-enter when device protocol is still in detecting.

V7 patches have below updates compared with v6 patches:
1) [PATCH v7 01/13] - Split the irq cmd handler function to separated function cyapa_default_irq_cmd_handler() and set it to interface cyapa_default_ops.irq_cmd_handler.
2) [PATCH v7 06/13] - Add cyapa->gen check in cyapa_gen3_irq_cmd_handler() to avoid miss-enter when device protocol is still in detecting.

V6 patches have below updates compared with v5 patches:
1) Remove patch 14 of the lid filtering from the cyapa driver.

V5 patches have below updates compared with v4 patches:
1) Uses get_device()/put_device() instead of kobject_get()/kobject_put();
2) Fix memories freed before debugfs entries issue;
3) Make cyapa_debugs_root valid in driver module level
in module_init()/moudle_exit() ;
4) Fix i2c_transfer() may return partial transfer issues.
5) Add cyapa->removed flag to avoid detecting thread may still running when driver module is removed.
6) Fix the meanings of some comments and return error code not clear issue.

author
#1 lore raw

PATCH v18 1/12 input: cyapa: re-design driver to support multi-trackpad in one driver

In order to support multiple different chipsets and communication protocols trackpad devices in one cyapa driver, the new cyapa driver is re-designed with one cyapa driver core and multiple device specific functions component. The cyapa driver core is contained in this patch, it supplies basic functions that working with kernel and input subsystem, and also supplies the interfaces that the specific devices' component can connect and work together with as one driver.
TEST=test on Chromebooks.

---
 drivers/input/mouse/Kconfig      |   10 -
 drivers/input/mouse/Makefile     |    3 +-
 drivers/input/mouse/cyapa.c      | 1076 +++++++++++++++-----------------------
 drivers/input/mouse/cyapa.h      |  296 +++++++++++
 drivers/input/mouse/cyapa_gen3.c |  807 ++++++++++++++++++++++++++++
 5 files changed, 1516 insertions(+), 676 deletions(-)
 create mode 100644 drivers/input/mouse/cyapa.h
 create mode 100644 drivers/input/mouse/cyapa_gen3.c
drivers/input/mouse/Kconfig +0 -10
index 2541bfa..d8b46b0 100644
@@ -146,16 +146,6 @@ config MOUSE_PS2_OLPC
 
 	  If unsure, say N.
 
-config MOUSE_PS2_FOCALTECH
-	bool "FocalTech PS/2 mouse protocol extension" if EXPERT
-	default y
-	depends on MOUSE_PS2
-	help
-	  Say Y here if you have a FocalTech PS/2 TouchPad connected to
-	  your system.
-
-	  If unsure, say Y.
-
 config MOUSE_SERIAL
 	tristate "Serial mouse"
 	select SERIO
drivers/input/mouse/Makefile +2 -1
index 560003d..8bd950d 100644
@@ -8,7 +8,7 @@ obj-$(CONFIG_MOUSE_AMIGA)		+= amimouse.o
 obj-$(CONFIG_MOUSE_APPLETOUCH)		+= appletouch.o
 obj-$(CONFIG_MOUSE_ATARI)		+= atarimouse.o
 obj-$(CONFIG_MOUSE_BCM5974)		+= bcm5974.o
-obj-$(CONFIG_MOUSE_CYAPA)		+= cyapa.o
+obj-$(CONFIG_MOUSE_CYAPA)		+= cyapatp.o
 obj-$(CONFIG_MOUSE_ELAN_I2C)		+= elan_i2c.o
 obj-$(CONFIG_MOUSE_GPIO)		+= gpio_mouse.o
 obj-$(CONFIG_MOUSE_INPORT)		+= inport.o
@@ -24,6 +24,7 @@ obj-$(CONFIG_MOUSE_SYNAPTICS_I2C)	+= synaptics_i2c.o
 obj-$(CONFIG_MOUSE_SYNAPTICS_USB)	+= synaptics_usb.o
 obj-$(CONFIG_MOUSE_VSXXXAA)		+= vsxxxaa.o
 
+cyapatp-objs := cyapa.o cyapa_gen3.o
 psmouse-objs := psmouse-base.o synaptics.o focaltech.o
 
 psmouse-$(CONFIG_MOUSE_PS2_ALPS)	+= alps.o
drivers/input/mouse/cyapa.c +411 -665

1,280 lines not on this page · raw message

drivers/input/mouse/cyapa.h new file +296 -0

296 lines not on this page · raw message

drivers/input/mouse/cyapa_gen3.c new file +807 -0

807 lines not on this page · raw message

Signature · 1 line
1.9.1
maintainer
#2 lore raw

Re: [PATCH v18 01/12] input: cyapa: re-design driver to support multi-trackpad in one driver

Hi Dudley,

Quoted 28 lines · Dudley Du

In order to support multiple different chipsets and communication protocols trackpad devices in one cyapa driver, the new cyapa driver is re-designed with one cyapa driver core and multiple device specific functions component. The cyapa driver core is contained in this patch, it supplies basic functions that working with kernel and input subsystem, and also supplies the interfaces that the specific devices' component can connect and work together with as one driver.
TEST=test on Chromebooks.

---
 drivers/input/mouse/Kconfig      |   10 -
 drivers/input/mouse/Makefile     |    3 +-
 drivers/input/mouse/cyapa.c      | 1076 +++++++++++++++-----------------------
 drivers/input/mouse/cyapa.h      |  296 +++++++++++
 drivers/input/mouse/cyapa_gen3.c |  807 ++++++++++++++++++++++++++++
 5 files changed, 1516 insertions(+), 676 deletions(-)
 create mode 100644 drivers/input/mouse/cyapa.h
 create mode 100644 drivers/input/mouse/cyapa_gen3.c
drivers/input/mouse/Kconfig +0 -0
index 2541bfa..d8b46b0 100644
@@ -146,16 +146,6 @@ config MOUSE_PS2_OLPC
 
 	  If unsure, say N.
 

drivers/input/mouse/Kconfig config MOUSE_PS2_OLPC · line 158

Quoted 10 lines
drivers/input/mouse/Kconfig +0 -10
-config MOUSE_PS2_FOCALTECH
-	bool "FocalTech PS/2 mouse protocol extension" if EXPERT
-	default y
-	depends on MOUSE_PS2
-	help
-	  Say Y here if you have a FocalTech PS/2 TouchPad connected to
-	  your system.
-
-	  If unsure, say Y.
-

Hmm, I wonder why you do not like Focaltech ;) I fixed it up locally, no need to resubmit.

Thanks.

Signature · 1 line
Dmitry
author
#3 lore raw

RE: [PATCH v18 01/12] input: cyapa: re-design driver to support multi-trackpad in one driver

Quoted 42 lines

-----Original Message-----
From: Dmitry Torokhov [mailto:[email protected]]
Sent: 2015?1?18? 16:27
To: Dudley Du
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v18 01/12] input: cyapa: re-design driver to support multi-trackpad in one driver

Hi Dudley,

Quoted 28 lines · Dudley Du

In order to support multiple different chipsets and communication protocols trackpad devices in one cyapa driver, the new cyapa driver is re-designed with one cyapa driver core and multiple device specific functions component. The cyapa driver core is contained in this patch, it supplies basic functions that working with kernel and input subsystem, and also supplies the interfaces that the specific devices' component can connect and work together with as one driver.
TEST=test on Chromebooks.

---
 drivers/input/mouse/Kconfig      |   10 -
 drivers/input/mouse/Makefile     |    3 +-
 drivers/input/mouse/cyapa.c      | 1076 +++++++++++++++-----------------------
 drivers/input/mouse/cyapa.h      |  296 +++++++++++
 drivers/input/mouse/cyapa_gen3.c |  807 ++++++++++++++++++++++++++++
 5 files changed, 1516 insertions(+), 676 deletions(-)
 create mode 100644 drivers/input/mouse/cyapa.h
 create mode 100644 drivers/input/mouse/cyapa_gen3.c
drivers/input/mouse/Kconfig +0 -0
index 2541bfa..d8b46b0 100644
@@ -146,16 +146,6 @@ config MOUSE_PS2_OLPC
 
   If unsure, say N.
 
Quoted 13 lines

drivers/input/mouse/Kconfig config MOUSE_PS2_OLPC · line 158

Quoted 10 lines
drivers/input/mouse/Kconfig +0 -10
-config MOUSE_PS2_FOCALTECH
-bool "FocalTech PS/2 mouse protocol extension" if EXPERT
-default y
-depends on MOUSE_PS2
-help
-  Say Y here if you have a FocalTech PS/2 TouchPad connected to
-  your system.
-
-  If unsure, say Y.
-

Hmm, I wonder why you do not like Focaltech ;) I fixed it up locally, no need to resubmit.

Sorry, it should be my mistook to do the merge.
I don't want to remove the Focaltech.
I will correct it locally.

Quoted 5 lines

Thanks.

--
Dmitry

This message and any attachments may contain Cypress (or its subsidiaries) confidential information. If it has been received in error, please advise the sender and immediately delete this message.

author
#4 lore raw

PATCH v18 2/12 input: cyapa: add gen5 trackpad device basic functions support

In reply to Dudley Du

Based on the cyapa core, add the gen5 trackpad device's basic functions supported, so gen5 trackpad device can work with kernel input system. And also based on the state parse interface, the cyapa driver can automatically determine the attached is gen3 or gen5 protocol trackpad device, then set the correct protocol to work with the attached trackpad device.
TEST=test on Chromebooks.

---
 drivers/input/mouse/Makefile     |    2 +-
 drivers/input/mouse/cyapa.c      |   13 +
 drivers/input/mouse/cyapa.h      |    1 +
 drivers/input/mouse/cyapa_gen5.c | 1678 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 1693 insertions(+), 1 deletion(-)
 create mode 100644 drivers/input/mouse/cyapa_gen5.c
drivers/input/mouse/Makefile +1 -1
index 8bd950d..8a9c98e 100644
@@ -24,7 +24,7 @@ obj-$(CONFIG_MOUSE_SYNAPTICS_I2C)	+= synaptics_i2c.o
 obj-$(CONFIG_MOUSE_SYNAPTICS_USB)	+= synaptics_usb.o
 obj-$(CONFIG_MOUSE_VSXXXAA)		+= vsxxxaa.o
 
-cyapatp-objs := cyapa.o cyapa_gen3.o
+cyapatp-objs := cyapa.o cyapa_gen3.o cyapa_gen5.o
 psmouse-objs := psmouse-base.o synaptics.o focaltech.o
 
 psmouse-$(CONFIG_MOUSE_PS2_ALPS)	+= alps.o
drivers/input/mouse/cyapa.c +13 -0
index 36c6433..fa4d501 100644
@@ -184,6 +184,14 @@ static int cyapa_get_state(struct cyapa *cyapa)
 			if (!error)
 				goto out_detected;
 		}
+		if ((cyapa->gen == CYAPA_GEN_UNKNOWN ||
+				cyapa->gen == CYAPA_GEN5) &&
+			!smbus && even_addr) {
+			error = cyapa_gen5_ops.state_parse(cyapa,
+					status, BL_STATUS_SIZE);
+			if (!error)
+				goto out_detected;
+		}
 
 		/*
 		 * Write 0x00 0x00 to trackpad device to force update its
@@ -272,6 +280,9 @@ static int cyapa_check_is_operational(struct cyapa *cyapa)
 		return error;
 
 	switch (cyapa->gen) {
+	case CYAPA_GEN5:
+		cyapa->ops = &cyapa_gen5_ops;
+		break;
 	case CYAPA_GEN3:
 		cyapa->ops = &cyapa_gen3_ops;
 		break;
@@ -506,6 +517,8 @@ static int cyapa_initialize(struct cyapa *cyapa)
 
 	/* ops.initialize() is aimed to prepare for module communications. */
 	error = cyapa_gen3_ops.initialize(cyapa);
+	if (!error)
+		error = cyapa_gen5_ops.initialize(cyapa);
 	if (error)
 		return error;
 
drivers/input/mouse/cyapa.h +1 -0
index aab19b7..481a60d 100644
@@ -292,5 +292,6 @@ u16 cyapa_pwr_cmd_to_sleep_time(u8 pwr_mode);
 
 extern const char product_id[];
 extern const struct cyapa_dev_ops cyapa_gen3_ops;
+extern const struct cyapa_dev_ops cyapa_gen5_ops;
 
 #endif
drivers/input/mouse/cyapa_gen5.c new file +1678 -0

1,678 lines not on this page · raw message

Signature · 1 line
1.9.1
author
#5 lore raw

PATCH v18 3/12 input: cyapa: add power management interfaces support for the device

In reply to Dudley Du

Add suspend_scanrate_ms power management interfaces in device's power group, so users or applications can control the power management strategy of trackpad device as their requirements. TEST=test on Chromebooks.

---
 drivers/input/mouse/cyapa.c | 127 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 127 insertions(+)
drivers/input/mouse/cyapa.c +127 -0
index fa4d501..eb0e515 100644
@@ -604,6 +604,127 @@ out:
 	return IRQ_HANDLED;
 }
 
+/*
+ **************************************************************
+ * sysfs interface
+ **************************************************************
+*/
+#ifdef CONFIG_PM_SLEEP
+static ssize_t cyapa_show_suspend_scanrate(struct device *dev,
+					   struct device_attribute *attr,
+					   char *buf)
+{
+	struct cyapa *cyapa = dev_get_drvdata(dev);
+	u8 pwr_cmd = cyapa->suspend_power_mode;
+	u16 sleep_time;
+	int len;
+	int error;
+
+	error = mutex_lock_interruptible(&cyapa->state_sync_lock);
+	if (error)
+		return error;
+	pwr_cmd = cyapa->suspend_power_mode;
+	sleep_time = cyapa->suspend_sleep_time;
+	mutex_unlock(&cyapa->state_sync_lock);
+
+	if (pwr_cmd == PWR_MODE_BTN_ONLY) {
+		len = scnprintf(buf, PAGE_SIZE, "%s\n", BTN_ONLY_MODE_NAME);
+	} else if (pwr_cmd == PWR_MODE_OFF) {
+		len = scnprintf(buf, PAGE_SIZE, "%s\n", OFF_MODE_NAME);
+	} else {
+		if (cyapa->gen == CYAPA_GEN3)
+			sleep_time = cyapa_pwr_cmd_to_sleep_time(pwr_cmd);
+		len = scnprintf(buf, PAGE_SIZE, "%u\n", sleep_time);
+	}
+
+	return len;
+}
+
+static ssize_t cyapa_update_suspend_scanrate(struct device *dev,
+					     struct device_attribute *attr,
+					     const char *buf, size_t count)
+{
+	struct cyapa *cyapa = dev_get_drvdata(dev);
+	u16 sleep_time;
+	int error;
+
+	error = mutex_lock_interruptible(&cyapa->state_sync_lock);
+	if (error)
+		return error;
+
+	if (sysfs_streq(buf, BTN_ONLY_MODE_NAME)) {
+		cyapa->suspend_power_mode = PWR_MODE_BTN_ONLY;
+	} else if (sysfs_streq(buf, OFF_MODE_NAME)) {
+		cyapa->suspend_power_mode = PWR_MODE_OFF;
+	} else if (!kstrtou16(buf, 10, &sleep_time)) {
+		cyapa->suspend_sleep_time = max_t(u16, sleep_time, 1000);
+		cyapa->suspend_power_mode =
+			cyapa_sleep_time_to_pwr_cmd(cyapa->suspend_sleep_time);
+	} else {
+		count = 0;
+	}
+
+	mutex_unlock(&cyapa->state_sync_lock);
+
+	return count ? count : -EINVAL;
+}
+
+static DEVICE_ATTR(suspend_scanrate_ms, S_IRUGO|S_IWUSR,
+		   cyapa_show_suspend_scanrate,
+		   cyapa_update_suspend_scanrate);
+
+static struct attribute *cyapa_power_wakeup_entries[] = {
+	&dev_attr_suspend_scanrate_ms.attr,
+	NULL,
+};
+
+static const struct attribute_group cyapa_power_wakeup_group = {
+	.name = power_group_name,
+	.attrs = cyapa_power_wakeup_entries,
+};
+
+static void cyapa_remove_power_wakeup_group(void *data)
+{
+	struct cyapa *cyapa = data;
+
+	sysfs_unmerge_group(&cyapa->client->dev.kobj,
+				&cyapa_power_wakeup_group);
+}
+
+static int cyapa_prepare_wakeup_controls(struct cyapa *cyapa)
+{
+	struct i2c_client *client = cyapa->client;
+	struct device *dev = &client->dev;
+	int error;
+
+	if (device_can_wakeup(dev)) {
+		error = sysfs_merge_group(&client->dev.kobj,
+					&cyapa_power_wakeup_group);
+		if (error) {
+			dev_err(dev, "failed to add power wakeup group: %d\n",
+				error);
+			return error;
+		}
+
+		error = devm_add_action(dev,
+				cyapa_remove_power_wakeup_group, cyapa);
+		if (error) {
+			cyapa_remove_power_wakeup_group(cyapa);
+			dev_err(dev, "failed to add power cleanup action: %d\n",
+				error);
+			return error;
+		}
+	}
+
+	return 0;
+}
+#else
+static inline int cyapa_prepare_wakeup_controls(struct cyapa *cyapa)
+{
+	return 0;
+}
+#endif /* CONFIG_PM_SLEEP */
+
 static int cyapa_probe(struct i2c_client *client,
 		       const struct i2c_device_id *dev_id)
 {
@@ -643,6 +764,12 @@ static int cyapa_probe(struct i2c_client *client,
 		return error;
 	}
 
+	error = cyapa_prepare_wakeup_controls(cyapa);
+	if (error) {
+		dev_err(dev, "failed to prepare wakeup controls: %d\n", error);
+		return error;
+	}
+
 	error = devm_request_threaded_irq(dev, client->irq,
 					  NULL, cyapa_irq,
 					  IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
Signature · 1 line
1.9.1
author
#6 lore raw

PATCH v18 4/12 input: cyapa: add runtime power management interfaces support for the device

In reply to Dudley Du

Add runtime_suspend_scanrate_ms power management interfaces in device's power group, so users or applications can control the runtime power management strategy of trackpad device as their requirements. TEST=test on Chromebooks.

---
 drivers/input/mouse/cyapa.c | 184 +++++++++++++++++++++++++++++++++++++++++++-
 drivers/input/mouse/cyapa.h |   4 +
 2 files changed, 187 insertions(+), 1 deletion(-)
drivers/input/mouse/cyapa.c +183 -1
index eb0e515..43fa0cb 100644
@@ -23,6 +23,7 @@
 #include <linux/mutex.h>
 #include <linux/slab.h>
 #include <linux/uaccess.h>
+#include <linux/pm_runtime.h>
 #include "cyapa.h"
 
 
@@ -357,6 +358,10 @@ static int cyapa_open(struct input_dev *input)
 	}
 
 	enable_irq(client->irq);
+	if (!pm_runtime_enabled(&client->dev)) {
+		pm_runtime_set_active(&client->dev);
+		pm_runtime_enable(&client->dev);
+	}
 out:
 	mutex_unlock(&cyapa->state_sync_lock);
 	return error;
@@ -370,6 +375,10 @@ static void cyapa_close(struct input_dev *input)
 	mutex_lock(&cyapa->state_sync_lock);
 
 	disable_irq(client->irq);
+	if (pm_runtime_enabled(&client->dev))
+		pm_runtime_disable(&client->dev);
+	pm_runtime_set_suspended(&client->dev);
+
 	if (cyapa->operational)
 		cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0);
 
@@ -539,6 +548,9 @@ static int cyapa_reinitialize(struct cyapa *cyapa)
 	struct input_dev *input = cyapa->input;
 	int error;
 
+	if (pm_runtime_enabled(dev))
+		pm_runtime_disable(dev);
+
 	/* Avoid command failures when TP was in OFF state. */
 	if (cyapa->operational)
 		cyapa->ops->set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE, 0);
@@ -561,6 +573,13 @@ out:
 		/* Reset to power OFF state to save power when no user open. */
 		if (cyapa->operational)
 			cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0);
+	} else if (!error && cyapa->operational) {
+		/*
+		 * Make sure only enable runtime PM when device is
+		 * in operational mode and input->users > 0.
+		 */
+		pm_runtime_set_active(dev);
+		pm_runtime_enable(dev);
 	}
 
 	return error;
@@ -571,6 +590,7 @@ static irqreturn_t cyapa_irq(int irq, void *dev_id)
 	struct cyapa *cyapa = dev_id;
 	struct device *dev = &cyapa->client->dev;
 
+	pm_runtime_get_sync(dev);
 	if (device_may_wakeup(dev))
 		pm_wakeup_event(dev, 0);
 
@@ -601,6 +621,8 @@ static irqreturn_t cyapa_irq(int irq, void *dev_id)
 	}
 
 out:
+	pm_runtime_mark_last_busy(dev);
+	pm_runtime_put_sync_autosuspend(dev);
 	return IRQ_HANDLED;
 }
 
@@ -725,6 +747,118 @@ static inline int cyapa_prepare_wakeup_controls(struct cyapa *cyapa)
 }
 #endif /* CONFIG_PM_SLEEP */
 
+#ifdef CONFIG_PM_RUNTIME
+static ssize_t cyapa_show_rt_suspend_scanrate(struct device *dev,
+					      struct device_attribute *attr,
+					      char *buf)
+{
+	struct cyapa *cyapa = dev_get_drvdata(dev);
+	u8 pwr_cmd;
+	u16 sleep_time;
+	int error;
+
+	error = mutex_lock_interruptible(&cyapa->state_sync_lock);
+	if (error)
+		return error;
+	pwr_cmd = cyapa->runtime_suspend_power_mode;
+	sleep_time = cyapa->runtime_suspend_sleep_time;
+	mutex_unlock(&cyapa->state_sync_lock);
+
+	if (cyapa->gen == CYAPA_GEN3)
+		return scnprintf(buf, PAGE_SIZE, "%u\n",
+			cyapa_pwr_cmd_to_sleep_time(pwr_cmd));
+	return scnprintf(buf, PAGE_SIZE, "%u\n", sleep_time);
+}
+
+static ssize_t cyapa_update_rt_suspend_scanrate(struct device *dev,
+						struct device_attribute *attr,
+						const char *buf, size_t count)
+{
+	struct cyapa *cyapa = dev_get_drvdata(dev);
+	u16 time;
+	int error;
+
+	if (buf == NULL || count == 0 || kstrtou16(buf, 10, &time)) {
+		dev_err(dev, "invalid runtime suspend scanrate ms parameter\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * When the suspend scanrate is changed, pm_runtime_get to resume
+	 * a potentially suspended device, update to the new pwr_cmd
+	 * and then pm_runtime_put to suspend into the new power mode.
+	 */
+	pm_runtime_get_sync(dev);
+	error = mutex_lock_interruptible(&cyapa->state_sync_lock);
+	if (error)
+		return error;
+	cyapa->runtime_suspend_sleep_time = max_t(u16, time, 1000);
+	cyapa->runtime_suspend_power_mode =
+		cyapa_sleep_time_to_pwr_cmd(cyapa->runtime_suspend_sleep_time);
+	mutex_unlock(&cyapa->state_sync_lock);
+	pm_runtime_put_sync_autosuspend(dev);
+
+	return count;
+}
+
+static DEVICE_ATTR(runtime_suspend_scanrate_ms, S_IRUGO|S_IWUSR,
+		   cyapa_show_rt_suspend_scanrate,
+		   cyapa_update_rt_suspend_scanrate);
+
+static struct attribute *cyapa_power_runtime_entries[] = {
+	&dev_attr_runtime_suspend_scanrate_ms.attr,
+	NULL,
+};
+
+static const struct attribute_group cyapa_power_runtime_group = {
+	.name = power_group_name,
+	.attrs = cyapa_power_runtime_entries,
+};
+
+static void cyapa_remove_power_runtime_group(void *data)
+{
+	struct cyapa *cyapa = data;
+
+	sysfs_unmerge_group(&cyapa->client->dev.kobj,
+				&cyapa_power_runtime_group);
+}
+
+static int cyapa_start_runtime(struct cyapa *cyapa)
+{
+	struct device *dev = &cyapa->client->dev;
+	int error;
+
+	cyapa->runtime_suspend_power_mode = PWR_MODE_IDLE;
+	cyapa->runtime_suspend_sleep_time =
+		cyapa_pwr_cmd_to_sleep_time(cyapa->runtime_suspend_power_mode);
+
+	error = sysfs_merge_group(&dev->kobj, &cyapa_power_runtime_group);
+	if (error) {
+		dev_err(dev,
+			"failed to create power runtime group: %d\n", error);
+		return error;
+	}
+
+	error = devm_add_action(dev, cyapa_remove_power_runtime_group, cyapa);
+	if (error) {
+		cyapa_remove_power_runtime_group(cyapa);
+		dev_err(dev,
+			"failed to add power runtime cleanup action: %d\n",
+			error);
+		return error;
+	}
+
+	/* runtime is enabled until device is operational and opened. */
+	pm_runtime_set_suspended(dev);
+	pm_runtime_use_autosuspend(dev);
+	pm_runtime_set_autosuspend_delay(dev, AUTOSUSPEND_DELAY);
+
+	return 0;
+}
+#else
+static inline int cyapa_start_runtime(struct cyapa *cyapa) { return 0; }
+#endif /* CONFIG_PM_RUNTIME */
+
 static int cyapa_probe(struct i2c_client *client,
 		       const struct i2c_device_id *dev_id)
 {
@@ -770,6 +904,12 @@ static int cyapa_probe(struct i2c_client *client,
 		return error;
 	}
 
+	error = cyapa_start_runtime(cyapa);
+	if (error) {
+		dev_err(dev, "failed to start pm_runtime: %d\n", error);
+		return error;
+	}
+
 	error = devm_request_threaded_irq(dev, client->irq,
 					  NULL, cyapa_irq,
 					  IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
@@ -810,6 +950,13 @@ static int __maybe_unused cyapa_suspend(struct device *dev)
 	if (error)
 		return error;
 
+	/*
+	 * Runtime PM is enable only when device is in operational mode and
+	 * users in use, so need check it before disable it to
+	 * avoid unbalance warning.
+	 */
+	if (pm_runtime_enabled(dev))
+		pm_runtime_disable(dev);
 	disable_irq(client->irq);
 
 	/*
@@ -846,6 +993,7 @@ static int __maybe_unused cyapa_resume(struct device *dev)
 		cyapa->irq_wake = false;
 	}
 
+	/* Update device states and runtime PM states. */
 	error = cyapa_reinitialize(cyapa);
 	if (error)
 		dev_warn(dev, "failed to reinitialize TP device: %d\n", error);
@@ -856,7 +1004,41 @@ static int __maybe_unused cyapa_resume(struct device *dev)
 	return 0;
 }
 
-static SIMPLE_DEV_PM_OPS(cyapa_pm_ops, cyapa_suspend, cyapa_resume);
+#ifdef CONFIG_PM_RUNTIME
+static int cyapa_runtime_suspend(struct device *dev)
+{
+	struct cyapa *cyapa = dev_get_drvdata(dev);
+	int error;
+
+	error = cyapa->ops->set_power_mode(cyapa,
+			cyapa->runtime_suspend_power_mode,
+			cyapa->runtime_suspend_sleep_time);
+	if (error)
+		dev_warn(dev, "runtime suspend failed: %d\n", error);
+
+	return 0;
+}
+
+static int cyapa_runtime_resume(struct device *dev)
+{
+	struct cyapa *cyapa = dev_get_drvdata(dev);
+	int error;
+
+	error = cyapa->ops->set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE, 0);
+	if (error)
+		dev_warn(dev, "runtime resume failed: %d\n", error);
+
+	return 0;
+}
+#else
+static inline int cyapa_runtime_suspend(struct device *dev) { return 0; }
+static inline int cyapa_runtime_resume(struct device *dev) { return 0; }
+#endif /* CONFIG_PM_RUNTIME */
+
+static const struct dev_pm_ops cyapa_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(cyapa_suspend, cyapa_resume)
+	SET_RUNTIME_PM_OPS(cyapa_runtime_suspend, cyapa_runtime_resume, NULL)
+};
 
 static const struct i2c_device_id cyapa_id_table[] = {
 	{ "cyapa", 0 },
drivers/input/mouse/cyapa.h +4 -0
index 481a60d..f5a2c22 100644
@@ -242,6 +242,10 @@ struct cyapa {
 	/* power mode settings */
 	u8 suspend_power_mode;
 	u16 suspend_sleep_time;
+#ifdef CONFIG_PM_RUNTIME
+	u8 runtime_suspend_power_mode;
+	u16 runtime_suspend_sleep_time;
+#endif /* CONFIG_PM_RUNTIME */
 	u8 dev_pwr_mode;
 	u16 dev_sleep_time;
 
Signature · 1 line
1.9.1
maintainer
#7 lore raw

Re: [PATCH v18 04/12] input: cyapa: add runtime power management interfaces support for the device

Hi Dudley,

drivers/input/mouse/cyapa.c static inline int cyapa_prepare_wakeup_controls(struct cyapa *cyapa) · line 753

Quoted 4 lines · Dudley Du
drivers/input/mouse/cyapa.c +4 -0
+#ifdef CONFIG_PM_RUNTIME
+static ssize_t cyapa_show_rt_suspend_scanrate(struct device *dev,
+					      struct device_attribute *attr,
+					      char *buf)

The runtime PM was switched to just CONFIG_PM in mainline and CONFIG_PM_RUNTIME was dropped. I adjusted the patch accordingly.

...

drivers/input/mouse/cyapa.c static int __maybe_unused cyapa_resume(struct device *dev) · line 1008

Quoted 3 lines
drivers/input/mouse/cyapa.c +2 -1
-static SIMPLE_DEV_PM_OPS(cyapa_pm_ops, cyapa_suspend, cyapa_resume);
+#ifdef CONFIG_PM_RUNTIME
+static int cyapa_runtime_suspend(struct device *dev)

I switched both cyapa_runtme_suspend and resume to __maybe_unused and dropped #ifdef guards.

Thanks.

Signature · 1 line
Dmitry
author
#8 lore raw

RE: [PATCH v18 04/12] input: cyapa: add runtime power management interfaces support for the device

Quoted 15 lines

-----Original Message-----
From: Dmitry Torokhov [mailto:[email protected]]
Sent: 2015?1?18? 16:32
To: Dudley Du
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v18 04/12] input: cyapa: add runtime power management interfaces support for the device

Hi Dudley,

On Fri, Jan 16, 2015 at 02:34:07PM +0800, Dudley Du wrote:

Quoted 7 lines

drivers/input/mouse/cyapa.c static inline int cyapa_prepare_wakeup_controls(struct cyapa *cyapa) · line 753

Quoted 4 lines
drivers/input/mouse/cyapa.c +4 -0
+#ifdef CONFIG_PM_RUNTIME
+static ssize_t cyapa_show_rt_suspend_scanrate(struct device *dev,
+      struct device_attribute *attr,
+      char *buf)

The runtime PM was switched to just CONFIG_PM in mainline and CONFIG_PM_RUNTIME was dropped. I adjusted the patch accordingly.

Thanks, I will update my knowledge.;)

Quoted 10 lines

...

drivers/input/mouse/cyapa.c static int __maybe_unused cyapa_resume(struct device *dev) · line 1008

Quoted 3 lines
drivers/input/mouse/cyapa.c +2 -1
-static SIMPLE_DEV_PM_OPS(cyapa_pm_ops, cyapa_suspend, cyapa_resume);
+#ifdef CONFIG_PM_RUNTIME
+static int cyapa_runtime_suspend(struct device *dev)

I switched both cyapa_runtme_suspend and resume to __maybe_unused and dropped #ifdef guards.

Quoted 4 lines

Thanks.

--
Dmitry

This message and any attachments may contain Cypress (or its subsidiaries) confidential information. If it has been received in error, please advise the sender and immediately delete this message.

author
#9 lore raw

PATCH v18 5/12 input: cyapa: add sysfs interfaces support in the cyapa driver

In reply to Dudley Du

Add device's basic control and features supported in cyapa driver through sysfs file system interfaces. These interfaces are commonly used in pre- and after production, for trackpad device state checking, managing and firmware image updating.
These interfaces including mode, firmware_version and product_id interfaces for reading firmware version and trackpad device product id values, and including update_fw interface to command firmware image update process. Also including baseline and calibrate interfaces for reading and checking trackpad device's sensors states. TEST=test on Chromebooks.

---
 drivers/input/mouse/cyapa.c | 310 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 310 insertions(+)
drivers/input/mouse/cyapa.c +310 -0
index 43fa0cb..5f9b24a 100644
@@ -32,6 +32,8 @@
 #define CYAPA_ADAPTER_FUNC_SMBUS  2
 #define CYAPA_ADAPTER_FUNC_BOTH   3
 
+#define CYAPA_FW_NAME		"cyapa.bin"
+
 const char product_id[] = "CYTRA";
 
 static int cyapa_reinitialize(struct cyapa *cyapa);
@@ -476,6 +478,38 @@ static int cyapa_create_input_dev(struct cyapa *cyapa)
 	return 0;
 }
 
+static void cyapa_enable_irq_for_cmd(struct cyapa *cyapa)
+{
+	struct input_dev *input = cyapa->input;
+
+	if (!input || !input->users) {
+		/*
+		 * When input is NULL, TP must be in deep sleep mode.
+		 * In this mode, later non-power I2C command will always failed
+		 * if not bring it out of deep sleep mode firstly,
+		 * so must command TP to active mode here.
+		 */
+		if (!input || cyapa->operational)
+			cyapa->ops->set_power_mode(cyapa,
+				PWR_MODE_FULL_ACTIVE, 0);
+		/* Gen3 always using polling mode for command. */
+		if (cyapa->gen >= CYAPA_GEN5)
+			enable_irq(cyapa->client->irq);
+	}
+}
+
+static void cyapa_disable_irq_for_cmd(struct cyapa *cyapa)
+{
+	struct input_dev *input = cyapa->input;
+
+	if (!input || !input->users) {
+		if (cyapa->gen >= CYAPA_GEN5)
+			disable_irq(cyapa->client->irq);
+		if (!input || cyapa->operational)
+			cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0);
+	}
+}
+
 /*
  * cyapa_sleep_time_to_pwr_cmd and cyapa_pwr_cmd_to_sleep_time
  *
@@ -859,6 +893,269 @@ static int cyapa_start_runtime(struct cyapa *cyapa)
 static inline int cyapa_start_runtime(struct cyapa *cyapa) { return 0; }
 #endif /* CONFIG_PM_RUNTIME */
 
+static ssize_t cyapa_show_fm_ver(struct device *dev,
+				 struct device_attribute *attr, char *buf)
+{
+	int error;
+	struct cyapa *cyapa = dev_get_drvdata(dev);
+
+	error = mutex_lock_interruptible(&cyapa->state_sync_lock);
+	if (error)
+		return error;
+	error = scnprintf(buf, PAGE_SIZE, "%d.%d\n", cyapa->fw_maj_ver,
+			 cyapa->fw_min_ver);
+	mutex_unlock(&cyapa->state_sync_lock);
+	return error;
+}
+
+static ssize_t cyapa_show_product_id(struct device *dev,
+				     struct device_attribute *attr, char *buf)
+{
+	struct cyapa *cyapa = dev_get_drvdata(dev);
+	int size;
+	int error;
+
+	error = mutex_lock_interruptible(&cyapa->state_sync_lock);
+	if (error)
+		return error;
+	size = scnprintf(buf, PAGE_SIZE, "%s\n", cyapa->product_id);
+	mutex_unlock(&cyapa->state_sync_lock);
+	return size;
+}
+
+static int cyapa_firmware(struct cyapa *cyapa, const char *fw_name)
+{
+	struct device *dev = &cyapa->client->dev;
+	const struct firmware *fw;
+	int error;
+
+	error = request_firmware(&fw, fw_name, dev);
+	if (error) {
+		dev_err(dev, "Could not load firmware from %s: %d\n",
+			fw_name, error);
+		return error;
+	}
+
+	error = cyapa->ops->check_fw(cyapa, fw);
+	if (error) {
+		dev_err(dev, "Invalid CYAPA firmware image: %s\n",
+				fw_name);
+		goto done;
+	}
+
+	/*
+	 * Resume the potentially suspended device because doing FW
+	 * update on a device not in the FULL mode has a chance to
+	 * fail.
+	 */
+	pm_runtime_get_sync(dev);
+
+	/* Require IRQ support for firmware update commands. */
+	cyapa_enable_irq_for_cmd(cyapa);
+
+	error = cyapa->ops->bl_enter(cyapa);
+	if (error) {
+		dev_err(dev, "bl_enter failed, %d\n", error);
+		goto err_detect;
+	}
+
+	error = cyapa->ops->bl_activate(cyapa);
+	if (error) {
+		dev_err(dev, "bl_activate failed, %d\n", error);
+		goto err_detect;
+	}
+
+	error = cyapa->ops->bl_initiate(cyapa, fw);
+	if (error) {
+		dev_err(dev, "bl_initiate failed, %d\n", error);
+		goto err_detect;
+	}
+
+	error = cyapa->ops->update_fw(cyapa, fw);
+	if (error) {
+		dev_err(dev, "update_fw failed, %d\n", error);
+		goto err_detect;
+	}
+
+err_detect:
+	cyapa_disable_irq_for_cmd(cyapa);
+	pm_runtime_put_noidle(dev);
+
+done:
+	release_firmware(fw);
+	return error;
+}
+
+static ssize_t cyapa_update_fw_store(struct device *dev,
+				     struct device_attribute *attr,
+				     const char *buf, size_t count)
+{
+	struct cyapa *cyapa = dev_get_drvdata(dev);
+	char fw_name[NAME_MAX];
+	int ret, error;
+
+	if (count > NAME_MAX) {
+		dev_err(dev, "File name too long\n");
+		return -EINVAL;
+	}
+
+	memcpy(fw_name, buf, count);
+	if (fw_name[count - 1] == '\n')
+		fw_name[count - 1] = '\0';
+	else
+		fw_name[count] = '\0';
+
+	if (cyapa->input) {
+		/*
+		 * Force the input device to be registered after the firmware
+		 * image is updated, so if the corresponding parameters updated
+		 * in the new firmware image can taken effect immediately.
+		 */
+		input_unregister_device(cyapa->input);
+		cyapa->input = NULL;
+	}
+
+	error = mutex_lock_interruptible(&cyapa->state_sync_lock);
+	if (error) {
+		/*
+		 * Whatever, do reinitialize to try to recover TP state to
+		 * previous state just as it entered fw update entrance.
+		 */
+		cyapa_reinitialize(cyapa);
+		return error;
+	}
+
+	error = cyapa_firmware(cyapa, fw_name);
+	if (error)
+		dev_err(dev, "firmware update failed: %d\n", error);
+	else
+		dev_dbg(dev, "firmware update successfully done.\n");
+
+	/*
+	 * Redetect trackpad device states because firmware update process
+	 * will reset trackpad device into bootloader mode.
+	 */
+	ret = cyapa_reinitialize(cyapa);
+	if (ret) {
+		dev_err(dev, "failed to redetect after updated: %d\n", ret);
+		error = error ? error : ret;
+	}
+
+	mutex_unlock(&cyapa->state_sync_lock);
+
+	return error ? error : count;
+}
+
+static ssize_t cyapa_calibrate_store(struct device *dev,
+				     struct device_attribute *attr,
+				     const char *buf, size_t count)
+{
+	struct cyapa *cyapa = dev_get_drvdata(dev);
+	int error;
+
+	error = mutex_lock_interruptible(&cyapa->state_sync_lock);
+	if (error)
+		return error;
+
+	if (cyapa->operational) {
+		cyapa_enable_irq_for_cmd(cyapa);
+		error = cyapa->ops->calibrate_store(dev, attr, buf, count);
+		cyapa_disable_irq_for_cmd(cyapa);
+	} else {
+		error = -EBUSY;  /* Still running in bootloader mode. */
+	}
+
+	mutex_unlock(&cyapa->state_sync_lock);
+	return error < 0 ? error : count;
+}
+
+static ssize_t cyapa_show_baseline(struct device *dev,
+				   struct device_attribute *attr, char *buf)
+{
+	struct cyapa *cyapa = dev_get_drvdata(dev);
+	ssize_t error;
+
+	error = mutex_lock_interruptible(&cyapa->state_sync_lock);
+	if (error)
+		return error;
+
+	if (cyapa->operational) {
+		cyapa_enable_irq_for_cmd(cyapa);
+		error = cyapa->ops->show_baseline(dev, attr, buf);
+		cyapa_disable_irq_for_cmd(cyapa);
+	} else {
+		error = -EBUSY;  /* Still running in bootloader mode. */
+	}
+
+	mutex_unlock(&cyapa->state_sync_lock);
+	return error;
+}
+
+static char *cyapa_state_to_string(struct cyapa *cyapa)
+{
+	switch (cyapa->state) {
+	case CYAPA_STATE_BL_BUSY:
+		return "bootloader busy";
+	case CYAPA_STATE_BL_IDLE:
+		return "bootloader idle";
+	case CYAPA_STATE_BL_ACTIVE:
+		return "bootloader active";
+	case CYAPA_STATE_GEN5_BL:
+		return "bootloader";
+	case CYAPA_STATE_OP:
+	case CYAPA_STATE_GEN5_APP:
+		return "operational";  /* Normal valid state. */
+	default:
+		return "invalid mode";
+	}
+}
+
+static ssize_t cyapa_show_mode(struct device *dev,
+				   struct device_attribute *attr, char *buf)
+{
+	struct cyapa *cyapa = dev_get_drvdata(dev);
+	int size;
+	int error;
+
+	error = mutex_lock_interruptible(&cyapa->state_sync_lock);
+	if (error)
+		return error;
+
+	size = scnprintf(buf, PAGE_SIZE, "gen%d %s\n",
+			cyapa->gen, cyapa_state_to_string(cyapa));
+
+	mutex_unlock(&cyapa->state_sync_lock);
+	return size;
+}
+
+static DEVICE_ATTR(firmware_version, S_IRUGO, cyapa_show_fm_ver, NULL);
+static DEVICE_ATTR(product_id, S_IRUGO, cyapa_show_product_id, NULL);
+static DEVICE_ATTR(update_fw, S_IWUSR, NULL, cyapa_update_fw_store);
+static DEVICE_ATTR(baseline, S_IRUGO, cyapa_show_baseline, NULL);
+static DEVICE_ATTR(calibrate, S_IWUSR, NULL, cyapa_calibrate_store);
+static DEVICE_ATTR(mode, S_IRUGO, cyapa_show_mode, NULL);
+
+static struct attribute *cyapa_sysfs_entries[] = {
+	&dev_attr_firmware_version.attr,
+	&dev_attr_product_id.attr,
+	&dev_attr_update_fw.attr,
+	&dev_attr_baseline.attr,
+	&dev_attr_calibrate.attr,
+	&dev_attr_mode.attr,
+	NULL,
+};
+
+static const struct attribute_group cyapa_sysfs_group = {
+	.attrs = cyapa_sysfs_entries,
+};
+
+static void cyapa_remove_sysfs_group(void *data)
+{
+	struct cyapa *cyapa = data;
+
+	sysfs_remove_group(&cyapa->client->dev.kobj, &cyapa_sysfs_group);
+}
+
 static int cyapa_probe(struct i2c_client *client,
 		       const struct i2c_device_id *dev_id)
 {
@@ -898,6 +1195,19 @@ static int cyapa_probe(struct i2c_client *client,
 		return error;
 	}
 
+	error = sysfs_create_group(&client->dev.kobj, &cyapa_sysfs_group);
+	if (error) {
+		dev_err(dev, "failed to create sysfs entries: %d\n", error);
+		return error;
+	}
+
+	error = devm_add_action(dev, cyapa_remove_sysfs_group, cyapa);
+	if (error) {
+		cyapa_remove_sysfs_group(cyapa);
+		dev_err(dev, "failed to add sysfs cleanup action: %d\n", error);
+		return error;
+	}
+
 	error = cyapa_prepare_wakeup_controls(cyapa);
 	if (error) {
 		dev_err(dev, "failed to prepare wakeup controls: %d\n", error);
Signature · 1 line
1.9.1
author
#10 lore raw

PATCH v18 6/12 input: cyapa: add gen3 trackpad device firmware update function support

In reply to Dudley Du

Add firmware image update function supported for gen3 trackpad device, it can be used through sysfs update_fw interface.
TEST=test on Chromebooks.

---
 drivers/input/mouse/cyapa_gen3.c | 309 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 309 insertions(+)
drivers/input/mouse/cyapa_gen3.c +309 -0
index 1b62c7d..214d45a 100644
@@ -20,6 +20,7 @@
 #include <linux/input/mt.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/unaligned/access_ok.h>
 #include "cyapa.h"
 
 
@@ -115,6 +116,18 @@ struct cyapa_reg_data {
 	struct cyapa_touch touches[5];
 } __packed;
 
+struct gen3_write_block_cmd {
+	u8 checksum_seed;  /* Always be 0xff */
+	u8 cmd_code;       /* command code: 0x39 */
+	u8 key[8];         /* 8-byte security key */
+	__be16 block_num;
+	u8 block_data[CYAPA_FW_BLOCK_SIZE];
+	u8 block_checksum;  /* Calculated using bytes 12 - 75 */
+	u8 cmd_checksum;    /* Calculated using bytes 0-76 */
+} __packed;
+
+static const u8 security_key[] = {
+		0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
 static const u8 bl_activate[] = { 0x00, 0xff, 0x38, 0x00, 0x01, 0x02, 0x03,
 		0x04, 0x05, 0x06, 0x07 };
 static const u8 bl_deactivate[] = { 0x00, 0xff, 0x3b, 0x00, 0x01, 0x02, 0x03,
@@ -423,6 +436,87 @@ static int cyapa_gen3_state_parse(struct cyapa *cyapa, u8 *reg_data, int len)
 	return -EAGAIN;
 }
 
+/*
+ * Enter bootloader by soft resetting the device.
+ *
+ * If device is already in the bootloader, the function just returns.
+ * Otherwise, reset the device; after reset, device enters bootloader idle
+ * state immediately.
+ *
+ * Returns:
+ *   0        on success
+ *   -EAGAIN  device was reset, but is not now in bootloader idle state
+ *   < 0      if the device never responds within the timeout
+ */
+static int cyapa_gen3_bl_enter(struct cyapa *cyapa)
+{
+	int error;
+	int waiting_time;
+
+	error = cyapa_poll_state(cyapa, 500);
+	if (error)
+		return error;
+	if (cyapa->state == CYAPA_STATE_BL_IDLE) {
+		/* Already in BL_IDLE. Skipping reset. */
+		return 0;
+	}
+
+	if (cyapa->state != CYAPA_STATE_OP)
+		return -EAGAIN;
+
+	cyapa->operational = false;
+	cyapa->state = CYAPA_STATE_NO_DEVICE;
+	error = cyapa_write_byte(cyapa, CYAPA_CMD_SOFT_RESET, 0x01);
+	if (error)
+		return -EIO;
+
+	usleep_range(25000, 50000);
+	waiting_time = 2000;  /* For some shipset, max waiting time is 1~2s. */
+	do {
+		error = cyapa_poll_state(cyapa, 500);
+		if (error) {
+			if (error == -ETIMEDOUT) {
+				waiting_time -= 500;
+				continue;
+			}
+			return error;
+		}
+
+		if ((cyapa->state == CYAPA_STATE_BL_IDLE) &&
+			!(cyapa->status[REG_BL_STATUS] & BL_STATUS_WATCHDOG))
+			break;
+
+		msleep(100);
+		waiting_time -= 100;
+	} while (waiting_time > 0);
+
+	if ((cyapa->state != CYAPA_STATE_BL_IDLE) ||
+		(cyapa->status[REG_BL_STATUS] & BL_STATUS_WATCHDOG))
+		return -EAGAIN;
+
+	return 0;
+}
+
+static int cyapa_gen3_bl_activate(struct cyapa *cyapa)
+{
+	int error;
+
+	error = cyapa_i2c_reg_write_block(cyapa, 0, sizeof(bl_activate),
+					bl_activate);
+	if (error)
+		return error;
+
+	/* Wait for bootloader to activate; takes between 2 and 12 seconds */
+	msleep(2000);
+	error = cyapa_poll_state(cyapa, 11000);
+	if (error)
+		return error;
+	if (cyapa->state != CYAPA_STATE_BL_ACTIVE)
+		return -EAGAIN;
+
+	return 0;
+}
+
 static int cyapa_gen3_bl_deactivate(struct cyapa *cyapa)
 {
 	int error;
@@ -483,6 +577,212 @@ static int cyapa_gen3_bl_exit(struct cyapa *cyapa)
 	return 0;
 }
 
+static u16 cyapa_gen3_csum(const u8 *buf, size_t count)
+{
+	int i;
+	u16 csum = 0;
+
+	for (i = 0; i < count; i++)
+		csum += buf[i];
+
+	return csum;
+}
+
+/*
+ * Verify the integrity of a CYAPA firmware image file.
+ *
+ * The firmware image file is 30848 bytes, composed of 482 64-byte blocks.
+ *
+ * The first 2 blocks are the firmware header.
+ * The next 480 blocks are the firmware image.
+ *
+ * The first two bytes of the header hold the header checksum, computed by
+ * summing the other 126 bytes of the header.
+ * The last two bytes of the header hold the firmware image checksum, computed
+ * by summing the 30720 bytes of the image modulo 0xffff.
+ *
+ * Both checksums are stored little-endian.
+ */
+static int cyapa_gen3_check_fw(struct cyapa *cyapa, const struct firmware *fw)
+{
+	struct device *dev = &cyapa->client->dev;
+	u16 csum;
+	u16 csum_expected;
+
+	/* Firmware must match exact 30848 bytes = 482 64-byte blocks. */
+	if (fw->size != CYAPA_FW_SIZE) {
+		dev_err(dev, "invalid firmware size = %zu, expected %u.\n",
+			fw->size, CYAPA_FW_SIZE);
+		return -EINVAL;
+	}
+
+	/* Verify header block */
+	csum_expected = (fw->data[0] << 8) | fw->data[1];
+	csum = cyapa_gen3_csum(&fw->data[2], CYAPA_FW_HDR_SIZE - 2);
+	if (csum != csum_expected) {
+		dev_err(dev, "%s %04x, expected: %04x\n",
+			"invalid firmware header checksum = ",
+			csum, csum_expected);
+		return -EINVAL;
+	}
+
+	/* Verify firmware image */
+	csum_expected = (fw->data[CYAPA_FW_HDR_SIZE - 2] << 8) |
+			 fw->data[CYAPA_FW_HDR_SIZE - 1];
+	csum = cyapa_gen3_csum(&fw->data[CYAPA_FW_HDR_SIZE],
+			CYAPA_FW_DATA_SIZE);
+	if (csum != csum_expected) {
+		dev_err(dev, "%s %04x, expected: %04x\n",
+			"invalid firmware header checksum = ",
+			csum, csum_expected);
+		return -EINVAL;
+	}
+	return 0;
+}
+
+/*
+ * Write a |len| byte long buffer |buf| to the device, by chopping it up into a
+ * sequence of smaller |CYAPA_CMD_LEN|-length write commands.
+ *
+ * The data bytes for a write command are prepended with the 1-byte offset
+ * of the data relative to the start of |buf|.
+ */
+static int cyapa_gen3_write_buffer(struct cyapa *cyapa,
+		const u8 *buf, size_t len)
+{
+	int error;
+	size_t i;
+	unsigned char cmd[CYAPA_CMD_LEN + 1];
+	size_t cmd_len;
+
+	for (i = 0; i < len; i += CYAPA_CMD_LEN) {
+		const u8 *payload = &buf[i];
+
+		cmd_len = (len - i >= CYAPA_CMD_LEN) ? CYAPA_CMD_LEN : len - i;
+		cmd[0] = i;
+		memcpy(&cmd[1], payload, cmd_len);
+
+		error = cyapa_i2c_reg_write_block(cyapa, 0, cmd_len + 1, cmd);
+		if (error)
+			return error;
+	}
+	return 0;
+}
+
+/*
+ * A firmware block write command writes 64 bytes of data to a single flash
+ * page in the device.  The 78-byte block write command has the format:
+ *   <0xff> <CMD> <Key> <Start> <Data> <Data-Checksum> <CMD Checksum>
+ *
+ *  <0xff>  - every command starts with 0xff
+ *  <CMD>   - the write command value is 0x39
+ *  <Key>   - write commands include an 8-byte key: { 00 01 02 03 04 05 06 07 }
+ *  <Block> - Memory Block number (address / 64) (16-bit, big-endian)
+ *  <Data>  - 64 bytes of firmware image data
+ *  <Data Checksum> - sum of 64 <Data> bytes, modulo 0xff
+ *  <CMD Checksum> - sum of 77 bytes, from 0xff to <Data Checksum>
+ *
+ * Each write command is split into 5 i2c write transactions of up to 16 bytes.
+ * Each transaction starts with an i2c register offset: (00, 10, 20, 30, 40).
+ */
+static int cyapa_gen3_write_fw_block(struct cyapa *cyapa,
+		u16 block, const u8 *data)
+{
+	int ret;
+	struct gen3_write_block_cmd write_block_cmd;
+	u8 status[BL_STATUS_SIZE];
+	int tries;
+	u8 bl_status, bl_error;
+
+	/* Set write command and security key bytes. */
+	write_block_cmd.checksum_seed = GEN3_BL_CMD_CHECKSUM_SEED;
+	write_block_cmd.cmd_code = GEN3_BL_CMD_WRITE_BLOCK;
+	memcpy(write_block_cmd.key, security_key, sizeof(security_key));
+	put_unaligned_be16(block, &write_block_cmd.block_num);
+	memcpy(write_block_cmd.block_data, data, CYAPA_FW_BLOCK_SIZE);
+	write_block_cmd.block_checksum = cyapa_gen3_csum(
+			write_block_cmd.block_data, CYAPA_FW_BLOCK_SIZE);
+	write_block_cmd.cmd_checksum = cyapa_gen3_csum((u8 *)&write_block_cmd,
+			sizeof(write_block_cmd) - 1);
+
+	ret = cyapa_gen3_write_buffer(cyapa, (u8 *)&write_block_cmd,
+			sizeof(write_block_cmd));
+	if (ret)
+		return ret;
+
+	/* Wait for write to finish */
+	tries = 11;  /* Programming for one block can take about 100ms. */
+	do {
+		usleep_range(10000, 20000);
+
+		/* Check block write command result status. */
+		ret = cyapa_i2c_reg_read_block(cyapa, BL_HEAD_OFFSET,
+					       BL_STATUS_SIZE, status);
+		if (ret != BL_STATUS_SIZE)
+			return (ret < 0) ? ret : -EIO;
+	} while ((status[REG_BL_STATUS] & BL_STATUS_BUSY) && --tries);
+
+	/* Ignore WATCHDOG bit and reserved bits. */
+	bl_status = status[REG_BL_STATUS] & ~BL_STATUS_REV_MASK;
+	bl_error = status[REG_BL_ERROR] & ~BL_ERROR_RESERVED;
+
+	if (bl_status & BL_STATUS_BUSY)
+		ret = -ETIMEDOUT;
+	else if (bl_status != BL_STATUS_RUNNING ||
+		bl_error != BL_ERROR_BOOTLOADING)
+		ret = -EIO;
+	else
+		ret = 0;
+
+	return ret;
+}
+
+static int cyapa_gen3_write_blocks(struct cyapa *cyapa,
+		size_t start_block, size_t block_count,
+		const u8 *image_data)
+{
+	int error;
+	int i;
+
+	for (i = 0; i < block_count; i++) {
+		size_t block = start_block + i;
+		size_t addr = i * CYAPA_FW_BLOCK_SIZE;
+		const u8 *data = &image_data[addr];
+
+		error = cyapa_gen3_write_fw_block(cyapa, block, data);
+		if (error)
+			return error;
+	}
+	return 0;
+}
+
+static int cyapa_gen3_do_fw_update(struct cyapa *cyapa,
+		const struct firmware *fw)
+{
+	struct device *dev = &cyapa->client->dev;
+	int error;
+
+	/* First write data, starting at byte 128 of fw->data */
+	error = cyapa_gen3_write_blocks(cyapa,
+		CYAPA_FW_DATA_BLOCK_START, CYAPA_FW_DATA_BLOCK_COUNT,
+		&fw->data[CYAPA_FW_HDR_BLOCK_COUNT * CYAPA_FW_BLOCK_SIZE]);
+	if (error) {
+		dev_err(dev, "FW update aborted, write image: %d\n", error);
+		return error;
+	}
+
+	/* Then write checksum */
+	error = cyapa_gen3_write_blocks(cyapa,
+		CYAPA_FW_HDR_BLOCK_START, CYAPA_FW_HDR_BLOCK_COUNT,
+		&fw->data[0]);
+	if (error) {
+		dev_err(dev, "FW update aborted, write checksum: %d\n", error);
+		return error;
+	}
+
+	return 0;
+}
+
 /*
  * cyapa_get_wait_time_for_pwr_cmd
  *
@@ -791,10 +1091,19 @@ static int cyapa_gen3_irq_handler(struct cyapa *cyapa)
 }
 
 static int cyapa_gen3_initialize(struct cyapa *cyapa) { return 0; }
+static int cyapa_gen3_bl_initiate(struct cyapa *cyapa,
+		const struct firmware *fw) { return 0; }
 static int cyapa_gen3_empty_output_data(struct cyapa *cyapa,
 		u8 *buf, int *len, cb_sort func) { return 0; }
 
 const struct cyapa_dev_ops cyapa_gen3_ops = {
+	.check_fw = cyapa_gen3_check_fw,
+	.bl_enter = cyapa_gen3_bl_enter,
+	.bl_activate = cyapa_gen3_bl_activate,
+	.update_fw = cyapa_gen3_do_fw_update,
+	.bl_deactivate = cyapa_gen3_bl_deactivate,
+	.bl_initiate = cyapa_gen3_bl_initiate,
+
 	.initialize = cyapa_gen3_initialize,
 
 	.state_parse = cyapa_gen3_state_parse,
Signature · 1 line
1.9.1
author
#11 lore raw

PATCH v18 7/12 input: cyapa: add gen3 trackpad device read baseline function support

In reply to Dudley Du

Add read baseline function supported for gen3 trackpad device, it can be used through sysfs baseline interface. TEST=test on Chromebooks.

---
 drivers/input/mouse/cyapa_gen3.c | 72 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)
drivers/input/mouse/cyapa_gen3.c +72 -0
index 214d45a..6e04e4b 100644
@@ -783,6 +783,76 @@ static int cyapa_gen3_do_fw_update(struct cyapa *cyapa,
 	return 0;
 }
 
+static ssize_t cyapa_gen3_show_baseline(struct device *dev,
+				   struct device_attribute *attr, char *buf)
+{
+	struct cyapa *cyapa = dev_get_drvdata(dev);
+	int max_baseline, min_baseline;
+	int tries;
+	int ret;
+
+	ret = cyapa_read_byte(cyapa, CYAPA_CMD_DEV_STATUS);
+	if (ret < 0) {
+		dev_err(dev, "Error reading dev status. err = %d\n", ret);
+		goto out;
+	}
+	if ((ret & CYAPA_DEV_NORMAL) != CYAPA_DEV_NORMAL) {
+		dev_warn(dev, "Trackpad device is busy. device state = 0x%x\n",
+			 ret);
+		ret = -EAGAIN;
+		goto out;
+	}
+
+	ret = cyapa_write_byte(cyapa, CYAPA_CMD_SOFT_RESET,
+			       OP_REPORT_BASELINE_MASK);
+	if (ret < 0) {
+		dev_err(dev, "Failed to send report baseline command. %d\n",
+			ret);
+		goto out;
+	}
+
+	tries = 3;  /* Try for 30 to 60 ms */
+	do {
+		usleep_range(10000, 20000);
+
+		ret = cyapa_read_byte(cyapa, CYAPA_CMD_DEV_STATUS);
+		if (ret < 0) {
+			dev_err(dev, "Error reading dev status. err = %d\n",
+				ret);
+			goto out;
+		}
+		if ((ret & CYAPA_DEV_NORMAL) == CYAPA_DEV_NORMAL)
+			break;
+	} while (--tries);
+
+	if (tries == 0) {
+		dev_err(dev, "Device timed out going to Normal state.\n");
+		ret = -ETIMEDOUT;
+		goto out;
+	}
+
+	ret = cyapa_read_byte(cyapa, CYAPA_CMD_MAX_BASELINE);
+	if (ret < 0) {
+		dev_err(dev, "Failed to read max baseline. err = %d\n", ret);
+		goto out;
+	}
+	max_baseline = ret;
+
+	ret = cyapa_read_byte(cyapa, CYAPA_CMD_MIN_BASELINE);
+	if (ret < 0) {
+		dev_err(dev, "Failed to read min baseline. err = %d\n", ret);
+		goto out;
+	}
+	min_baseline = ret;
+
+	dev_dbg(dev, "Baseline report successful. Max: %d Min: %d\n",
+		max_baseline, min_baseline);
+	ret = scnprintf(buf, PAGE_SIZE, "%d %d\n", max_baseline, min_baseline);
+
+out:
+	return ret;
+}
+
 /*
  * cyapa_get_wait_time_for_pwr_cmd
  *
@@ -1104,6 +1174,8 @@ const struct cyapa_dev_ops cyapa_gen3_ops = {
 	.bl_deactivate = cyapa_gen3_bl_deactivate,
 	.bl_initiate = cyapa_gen3_bl_initiate,
 
+	.show_baseline = cyapa_gen3_show_baseline,
+
 	.initialize = cyapa_gen3_initialize,
 
 	.state_parse = cyapa_gen3_state_parse,
Signature · 1 line
1.9.1
author
#12 lore raw

PATCH v18 8/12 input: cyapa: add gen3 trackpad device force re-calibrate function support

In reply to Dudley Du

Add force re-calibrate function supported for gen3 trackpad device, it can be used through sysfs calibrate interface. TEST=test on Chromebooks.

---
 drivers/input/mouse/cyapa_gen3.c | 59 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
drivers/input/mouse/cyapa_gen3.c +59 -0
index 6e04e4b..77e9d70 100644
@@ -783,6 +783,64 @@ static int cyapa_gen3_do_fw_update(struct cyapa *cyapa,
 	return 0;
 }
 
+static ssize_t cyapa_gen3_do_calibrate(struct device *dev,
+				     struct device_attribute *attr,
+				     const char *buf, size_t count)
+{
+	struct cyapa *cyapa = dev_get_drvdata(dev);
+	int tries;
+	int ret;
+
+	ret = cyapa_read_byte(cyapa, CYAPA_CMD_DEV_STATUS);
+	if (ret < 0) {
+		dev_err(dev, "Error reading dev status: %d\n", ret);
+		goto out;
+	}
+	if ((ret & CYAPA_DEV_NORMAL) != CYAPA_DEV_NORMAL) {
+		dev_warn(dev, "Trackpad device is busy, device state: 0x%02x\n",
+			 ret);
+		ret = -EAGAIN;
+		goto out;
+	}
+
+	ret = cyapa_write_byte(cyapa, CYAPA_CMD_SOFT_RESET,
+			       OP_RECALIBRATION_MASK);
+	if (ret < 0) {
+		dev_err(dev, "Failed to send calibrate command: %d\n",
+			ret);
+		goto out;
+	}
+
+	tries = 20;  /* max recalibration timeout 2s. */
+	do {
+		/*
+		 * For this recalibration, the max time will not exceed 2s.
+		 * The average time is approximately 500 - 700 ms, and we
+		 * will check the status every 100 - 200ms.
+		 */
+		usleep_range(100000, 200000);
+
+		ret = cyapa_read_byte(cyapa, CYAPA_CMD_DEV_STATUS);
+		if (ret < 0) {
+			dev_err(dev, "Error reading dev status: %d\n",
+				ret);
+			goto out;
+		}
+		if ((ret & CYAPA_DEV_NORMAL) == CYAPA_DEV_NORMAL)
+			break;
+	} while (--tries);
+
+	if (tries == 0) {
+		dev_err(dev, "Failed to calibrate. Timeout.\n");
+		ret = -ETIMEDOUT;
+		goto out;
+	}
+	dev_dbg(dev, "Calibration successful.\n");
+
+out:
+	return ret < 0 ? ret : count;
+}
+
 static ssize_t cyapa_gen3_show_baseline(struct device *dev,
 				   struct device_attribute *attr, char *buf)
 {
@@ -1175,6 +1233,7 @@ const struct cyapa_dev_ops cyapa_gen3_ops = {
 	.bl_initiate = cyapa_gen3_bl_initiate,
 
 	.show_baseline = cyapa_gen3_show_baseline,
+	.calibrate_store = cyapa_gen3_do_calibrate,
 
 	.initialize = cyapa_gen3_initialize,
 
Signature · 1 line
1.9.1
author
#13 lore raw

PATCH v18 9/12 input: cyapa: add gen5 trackpad device firmware update function support

In reply to Dudley Du

Add firmware image update function supported for gen5 trackpad device, it can be used through sysfs update_fw interface.
TEST=test on Chromebooks.

---
 drivers/input/mouse/Kconfig      |   1 +
 drivers/input/mouse/cyapa_gen5.c | 391 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 392 insertions(+)
drivers/input/mouse/Kconfig +1 -0
index d8b46b0..728490e 100644
@@ -206,6 +206,7 @@ config MOUSE_BCM5974
 config MOUSE_CYAPA
 	tristate "Cypress APA I2C Trackpad support"
 	depends on I2C
+	select CRC_ITU_T
 	help
 	  This driver adds support for Cypress All Points Addressable (APA)
 	  I2C Trackpads, including the ones used in 2012 Samsung Chromebooks.
drivers/input/mouse/cyapa_gen5.c +391 -0

434 lines not on this page · raw message

Signature · 1 line
1.9.1
maintainer
#14 lore raw

Re: [PATCH v18 09/12] input: cyapa: add gen5 trackpad device firmware update function support

drivers/input/mouse/cyapa_gen5.c static int cyapa_gen5_bl_exit(struct cyapa *cyapa) · line 1209

Quoted 6 lines · Dudley Du
drivers/input/mouse/cyapa_gen5.c +6 -0
+	/* APP_INTEGRITY row is always the last row block,
+	 * and the row id must be 0x01ff */
+	row_num = get_unaligned_be16(
+			&image->records[flash_records_count - 1].row_number);
+	if (image->records[flash_records_count - 1].flash_array_id != 0x00 &&
+			row_num != 0x01ff) {

By the way, shouldn't this be "or" and not "and"?

drivers/input/mouse/cyapa_gen5.c static int cyapa_gen5_bl_exit(struct cyapa *cyapa) · line 1212

Quoted 3 lines
drivers/input/mouse/cyapa_gen5.c +3 -0
+		dev_err(dev, "%s: invalid app_integrity data.\n", __func__);
+		return -EINVAL;
+	}

Thanks.

Signature · 1 line
Dmitry
author
#15 lore raw

RE: [PATCH v18 09/12] input: cyapa: add gen5 trackpad device firmware update function support

Quoted 12 lines

-----Original Message-----
From: Dmitry Torokhov [mailto:[email protected]]
Sent: 2015?1?19? 8:27
To: Dudley Du
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v18 09/12] input: cyapa: add gen5 trackpad device firmware update function support

On Fri, Jan 16, 2015 at 02:34:12PM +0800, Dudley Du wrote:

Quoted 8 lines

drivers/input/mouse/cyapa_gen5.c static int cyapa_gen5_bl_exit(struct cyapa *cyapa) · line 1209

Quoted 6 lines
drivers/input/mouse/cyapa_gen5.c +6 -0
+/* APP_INTEGRITY row is always the last row block,
+ * and the row id must be 0x01ff */
+row_num = get_unaligned_be16(
+&image->records[flash_records_count - 1].row_number);
+if (image->records[flash_records_count - 1].flash_array_id != 0x00 &&
+row_num != 0x01ff) {

By the way, shouldn't this be "or" and not "and"?

It should or, thanks for the correction.

Quoted 9 lines

drivers/input/mouse/cyapa_gen5.c static int cyapa_gen5_bl_exit(struct cyapa *cyapa) · line 1212

Quoted 4 lines
drivers/input/mouse/cyapa_gen5.c +3 -0
+dev_err(dev, "%s: invalid app_integrity data.\n", __func__);
+return -EINVAL;
+}

Thanks.

--
Dmitry

This message and any attachments may contain Cypress (or its subsidiaries) confidential information. If it has been received in error, please advise the sender and immediately delete this message.

author
#16 lore raw

PATCH v18 10/12 input: cyapa: add gen5 trackpad device read baseline function support

In reply to Dudley Du

Add read baseline function supported for gen5 trackpad device, it can be used through sysfs baseline interface. TEST=test on Chromebooks.

---
 drivers/input/mouse/cyapa.h      |   2 +
 drivers/input/mouse/cyapa_gen5.c | 640 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 642 insertions(+)
drivers/input/mouse/cyapa.h +2 -0
index f5a2c22..fb3b863 100644
@@ -265,6 +265,8 @@ struct cyapa {
 	u8 y_origin;  /* Y Axis Origin: 0 = top; 1 = bottom. */
 	int electrodes_x;  /* Number of electrodes on the X Axis*/
 	int electrodes_y;  /* Number of electrodes on the Y Axis*/
+	int electrodes_rx;  /* Number of Rx electrodes */
+	int aligned_electrodes_rx;  /* 4 aligned */
 	int max_z;
 
 	/*
drivers/input/mouse/cyapa_gen5.c +640 -0

658 lines not on this page · raw message

Signature · 1 line
1.9.1
author
#17 lore raw

PATCH v18 11/12 input: cyapa: add gen5 trackpad device force re-calibrate function support

In reply to Dudley Du

Add force re-calibrate function supported for gen5 trackpad device, it can be used through sysfs calibrate interface. TEST=test on Chromebooks.

---
 drivers/input/mouse/cyapa_gen5.c | 65 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
drivers/input/mouse/cyapa_gen5.c +65 -0
index 7c6e339..ced2a2c 100644
@@ -1715,6 +1715,70 @@ static int cyapa_gen5_suspend_scanning(struct cyapa *cyapa)
 	return 0;
 }
 
+static int cyapa_gen5_calibrate_pwcs(struct cyapa *cyapa,
+		u8 calibrate_sensing_mode_type)
+{
+	struct gen5_app_cmd_head *app_cmd_head;
+	u8 cmd[8];
+	u8 resp_data[6];
+	int resp_len;
+	int error;
+
+	/* Try to dump all buffered data before doing command. */
+	cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
+
+	memset(cmd, 0, sizeof(cmd));
+	app_cmd_head = (struct gen5_app_cmd_head *)cmd;
+	put_unaligned_le16(GEN5_OUTPUT_REPORT_ADDR, &app_cmd_head->addr);
+	put_unaligned_le16(sizeof(cmd) - 2, &app_cmd_head->length);
+	app_cmd_head->report_id = GEN5_APP_CMD_REPORT_ID;
+	app_cmd_head->cmd_code = GEN5_CMD_CALIBRATE;
+	app_cmd_head->parameter_data[0] = calibrate_sensing_mode_type;
+	resp_len = sizeof(resp_data);
+	error = cyapa_i2c_pip_cmd_irq_sync(cyapa,
+			cmd, sizeof(cmd),
+			resp_data, &resp_len,
+			5000, cyapa_gen5_sort_tsg_pip_app_resp_data, true);
+	if (error || !VALID_CMD_RESP_HEADER(resp_data, GEN5_CMD_CALIBRATE) ||
+			!GEN5_CMD_COMPLETE_SUCCESS(resp_data[5]))
+		return error < 0 ? error : -EAGAIN;
+
+	return 0;
+}
+
+static ssize_t cyapa_gen5_do_calibrate(struct device *dev,
+				     struct device_attribute *attr,
+				     const char *buf, size_t count)
+{
+	struct cyapa *cyapa = dev_get_drvdata(dev);
+	int error, calibrate_error;
+
+	/* 1. Suspend Scanning*/
+	error = cyapa_gen5_suspend_scanning(cyapa);
+	if (error)
+		return error;
+
+	/* 2. Do mutual capacitance fine calibrate. */
+	calibrate_error = cyapa_gen5_calibrate_pwcs(cyapa,
+				CYAPA_SENSING_MODE_MUTUAL_CAP_FINE);
+	if (calibrate_error)
+		goto resume_scanning;
+
+	/* 3. Do self capacitance calibrate. */
+	calibrate_error = cyapa_gen5_calibrate_pwcs(cyapa,
+				CYAPA_SENSING_MODE_SELF_CAP);
+	if (calibrate_error)
+		goto resume_scanning;
+
+resume_scanning:
+	/* 4. Resume Scanning*/
+	error = cyapa_gen5_resume_scanning(cyapa);
+	if (error || calibrate_error)
+		return error ? error : calibrate_error;
+
+	return count;
+}
+
 static s32 twos_complement_to_s32(s32 value, int num_bits)
 {
 	if (value >> (num_bits - 1))
@@ -2696,6 +2760,7 @@ const struct cyapa_dev_ops cyapa_gen5_ops = {
 	.bl_deactivate = cyapa_gen5_bl_deactivate,
 
 	.show_baseline = cyapa_gen5_show_baseline,
+	.calibrate_store = cyapa_gen5_do_calibrate,
 
 	.initialize = cyapa_gen5_initialize,
 
Signature · 1 line
1.9.1
author
#18 lore raw

PATCH v18 12/12 input: cyapa: add acpi device id support

In reply to Dudley Du

Add acpi device tree support.
acpi device id "CYAP0000" is for old gen3 trackpad devices. acpi device id "CYAP0001" is for new gen5 trackpad devices. TEST=test on Chromebooks.

---
 drivers/input/mouse/cyapa.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/input/mouse/cyapa.c +13 -0
index 5f9b24a..9dc9f65 100644
@@ -24,6 +24,7 @@
 #include <linux/slab.h>
 #include <linux/uaccess.h>
 #include <linux/pm_runtime.h>
+#include <linux/acpi.h>
 #include "cyapa.h"
 
 
@@ -1356,11 +1357,23 @@ static const struct i2c_device_id cyapa_id_table[] = {
 };
 MODULE_DEVICE_TABLE(i2c, cyapa_id_table);
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id cyapa_acpi_id[] = {
+	{ "CYAP0000", 0 },  /* Gen3 trackpad with 0x67 I2C address. */
+	{ "CYAP0001", 0 },  /* Gen5 trackpad with 0x24 I2C address. */
+	{ }
+};
+MODULE_DEVICE_TABLE(acpi, cyapa_acpi_id);
+#endif
+
 static struct i2c_driver cyapa_driver = {
 	.driver = {
 		.name = "cyapa",
 		.owner = THIS_MODULE,
 		.pm = &cyapa_pm_ops,
+#ifdef CONFIG_ACPI
+		.acpi_match_table = ACPI_PTR(cyapa_acpi_id),
+#endif
 	},
 
 	.probe = cyapa_probe,
Signature · 1 line
1.9.1
maintainer
#19 lore raw

Re: [PATCH v18 12/12] input: cyapa: add acpi device id support

Quoted 32 lines · Dudley Du

Add acpi device tree support.
acpi device id "CYAP0000" is for old gen3 trackpad devices. acpi device id "CYAP0001" is for new gen5 trackpad devices. TEST=test on Chromebooks.

---
 drivers/input/mouse/cyapa.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/input/mouse/cyapa.c +7 -0
index 5f9b24a..9dc9f65 100644
@@ -24,6 +24,7 @@
 #include <linux/slab.h>
 #include <linux/uaccess.h>
 #include <linux/pm_runtime.h>
+#include <linux/acpi.h>
 #include "cyapa.h"
 
 
@@ -1356,11 +1357,23 @@ static const struct i2c_device_id cyapa_id_table[] = {
 };
 MODULE_DEVICE_TABLE(i2c, cyapa_id_table);
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id cyapa_acpi_id[] = {
+	{ "CYAP0000", 0 },  /* Gen3 trackpad with 0x67 I2C address. */
+	{ "CYAP0001", 0 },  /* Gen5 trackpad with 0x24 I2C address. */
+	{ }
+};

drivers/input/mouse/cyapa.c static const struct i2c_device_id cyapa_id_table[] = { · line 1375

Quoted 10 lines
drivers/input/mouse/cyapa.c +5 -0
+MODULE_DEVICE_TABLE(acpi, cyapa_acpi_id);
+#endif
+
 static struct i2c_driver cyapa_driver = {
 	.driver = {
 		.name = "cyapa",
 		.owner = THIS_MODULE,
 		.pm = &cyapa_pm_ops,
+#ifdef CONFIG_ACPI
+		.acpi_match_table = ACPI_PTR(cyapa_acpi_id),

I do not think you should guard it with CONFIG_ACPI, so I dropped it.

Quoted 7 lines
drivers/input/mouse/cyapa.c +1 -0
+#endif
 	},
 
 	.probe = cyapa_probe,
Signature · 1 line
1.9.1

Thanks.

Signature · 1 line
Dmitry
author
#20 lore raw

RE: [PATCH v18 12/12] input: cyapa: add acpi device id support

Quoted 47 lines

-----Original Message-----
From: Dmitry Torokhov [mailto:[email protected]]
Sent: 2015?1?18? 16:28
To: Dudley Du
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v18 12/12] input: cyapa: add acpi device id support

Quoted 36 lines · Dudley Du

Add acpi device tree support.
acpi device id "CYAP0000" is for old gen3 trackpad devices. acpi device id "CYAP0001" is for new gen5 trackpad devices. TEST=test on Chromebooks.

---
 drivers/input/mouse/cyapa.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/input/mouse/cyapa.c +10 -0
index 5f9b24a..9dc9f65 100644
@@ -24,6 +24,7 @@
 #include <linux/slab.h>
 #include <linux/uaccess.h>
 #include <linux/pm_runtime.h>
+#include <linux/acpi.h>
 #include "cyapa.h"
 
 
@@ -1356,11 +1357,23 @@ static const struct i2c_device_id cyapa_id_table[] = {
 };
 MODULE_DEVICE_TABLE(i2c, cyapa_id_table);
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id cyapa_acpi_id[] = {
+{ "CYAP0000", 0 },  /* Gen3 trackpad with 0x67 I2C address. */
+{ "CYAP0001", 0 },  /* Gen5 trackpad with 0x24 I2C address. */
+{ }
+};
+MODULE_DEVICE_TABLE(acpi, cyapa_acpi_id);
+#endif
+
 static struct i2c_driver cyapa_driver = {
Quoted 8 lines

drivers/input/mouse/cyapa.c static const struct i2c_device_id cyapa_id_table[] = { · line 1375

Quoted 6 lines
drivers/input/mouse/cyapa.c +2 -0
 .driver = {
 .name = "cyapa",
 .owner = THIS_MODULE,
 .pm = &cyapa_pm_ops,
+#ifdef CONFIG_ACPI
+.acpi_match_table = ACPI_PTR(cyapa_acpi_id),

I do not think you should guard it with CONFIG_ACPI, so I dropped it.

Thanks.

Quoted 9 lines
Quoted 8 lines
drivers/input/mouse/cyapa.c +1 -1
+#endif
 },
 
 .probe = cyapa_probe,
--

1.9.1

Quoted 4 lines

Thanks.

--
Dmitry

This message and any attachments may contain Cypress (or its subsidiaries) confidential information. If it has been received in error, please advise the sender and immediately delete this message.

#21 lore raw
In reply to Dudley Du

Dudley,

Your patch series applies without issue but unfortunately I could not test them because I ran in to a bug created by someone elses patch (not yours) [1].

[1]: https://lkml.org/lkml/2015/1/17/24

Once that issue gets resolved I would be happy to test your patch series.

Quoted 4 lines · Dudley Du

V18 patches have below updates, details of other updates see history list:
1) Fix 'cyapa_runtime_suspend' undeclared compiling issue in latest kernel-next source code. Verified on next-20150114 with make C=1.
2) Optimize enter bootloader failed for some chipset takes longer time issue.

[...]

Signature · 1 line
- Jeremiah Mahler
Tested-by
#22 lore raw

Dudley,

Quoted 11 lines · Jeremiah Mahler

Dudley,

Your patch series applies without issue but unfortunately I could not test them because I ran in to a bug created by someone elses patch (not yours) [1].

[1]: https://lkml.org/lkml/2015/1/17/24

Once that issue gets resolved I would be happy to test your patch series.

If I go back to linux-next 20150112 I can avoid the drm/i915 bug. Then, with this patch series applied, everything works well. Suspend/resume work, and the touchpad operates as expected.

Signature · 1 line
- Jeremiah Mahler
maintainer
#23 lore raw
Quoted 15 lines · Jeremiah Mahler

Dudley,

Quoted 11 lines · Jeremiah Mahler

Dudley,

Your patch series applies without issue but unfortunately I could not test them because I ran in to a bug created by someone elses patch (not yours) [1].

[1]: https://lkml.org/lkml/2015/1/17/24

Once that issue gets resolved I would be happy to test your patch series.

Quoted 5 lines

If I go back to linux-next 20150112 I can avoid the drm/i915 bug. Then, with this patch series applied, everything works well. Suspend/resume work, and the touchpad operates as expected.

OK, I believe that the code is in good shape now, so I queued all patches for 3.20 (currently in my 'next' branch and should show in linux-next soon). Any subsequent improvements to the code should be relative to this series.

Jeremiah, thank you for testing the patches; Dudley thank you for your patience with the process.

Thanks.

Signature · 1 line
Dmitry
author
#24 lore raw

Dmitry,

Thank you very much.

Thanks,
Dudley

Quoted 34 lines

-----Original Message-----
From: Dmitry Torokhov [mailto:[email protected]]
Sent: 2015?1?18? 16:35
To: Jeremiah Mahler; Dudley Du; [email protected]; [email protected]; David Solda; [email protected]; [email protected]
Subject: Re: [PATCH v18 00/12] input: cyapa: instruction of cyapa patches

Quoted 15 lines · Jeremiah Mahler

Dudley,

Quoted 11 lines · Jeremiah Mahler

Dudley,

Your patch series applies without issue but unfortunately I could not test them because I ran in to a bug created by someone elses patch (not yours) [1].

[1]: https://lkml.org/lkml/2015/1/17/24

Once that issue gets resolved I would be happy to test your patch series.

Quoted 5 lines

If I go back to linux-next 20150112 I can avoid the drm/i915 bug. Then, with this patch series applied, everything works well. Suspend/resume work, and the touchpad operates as expected.

OK, I believe that the code is in good shape now, so I queued all patches for 3.20 (currently in my 'next' branch and should show in linux-next soon). Any subsequent improvements to the code should be relative to this series.

Quoted 7 lines

Jeremiah, thank you for testing the patches; Dudley thank you for your patience with the process.

Thanks.

--
Dmitry

This message and any attachments may contain Cypress (or its subsidiaries) confidential information. If it has been received in error, please advise the sender and immediately delete this message.

#25 lore raw
In reply to Jeremiah Mahler

Can we just reverse the prior change that caused the bug, or are you saying that the owner of the prior patch has to fix it?

Dave

Quoted 18 lines · Jeremiah Mahler

Dudley,

Your patch series applies without issue but unfortunately I could not test them because I ran in to a bug created by someone elses patch (not yours) [1].

[1]: https://lkml.org/lkml/2015/1/17/24

Once that issue gets resolved I would be happy to test your patch series.

Quoted 5 lines · Dudley Du

V18 patches have below updates, details of other updates see history list:
1) Fix 'cyapa_runtime_suspend' undeclared compiling issue in latest kernel-next source code. Verified on next-20150114 with make C=1.
2) Optimize enter bootloader failed for some chipset takes longer time issue.

Quoted 4 lines

[...]

--
- Jeremiah Mahler

This message and any attachments may contain Cypress (or its subsidiaries) confidential information. If it has been received in error, please advise the sender and immediately delete this message.

#26 lore raw

Dave,

Quoted 4 lines · David Solda

Can we just reverse the prior change that caused the bug, or are you saying that the owner of the prior patch has to fix it?

Dave

I tried to revert the patch but it didn't do so cleanly.

git revert ea2c67bb4aff

So I just reverted back to next-20150112.

  git reset --hard next-20150112

I hope the owner of the prior patch responds promptly and fixes their bug. But for the time being the cyapa patch series works when that other bug is avoided.

If you have any suggestions, let me know.

Signature · 1 line
- Jeremiah Mahler
author
#27 lore raw

Jeremiah,

Thanks.
If there is something that I could do, please let me know.

Thanks,
Dudley

Quoted 25 lines

-----Original Message-----
From: Jeremiah Mahler [mailto:[email protected]]
Sent: 2015?1?18? 6:46
To: David Solda
Cc: Dudley Du; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v18 00/12] input: cyapa: instruction of cyapa patches

Dave,

Quoted 1 line · David Solda

Can we just reverse the prior change that caused the bug, or are you saying that

the owner of the prior patch has to fix it?

Quoted 3 lines

Dave

I tried to revert the patch but it didn't do so cleanly.

git revert ea2c67bb4aff

So I just reverted back to next-20150112.

  git reset --hard next-20150112
Quoted 8 lines

I hope the owner of the prior patch responds promptly and fixes their bug. But for the time being the cyapa patch series works when that other bug is avoided.

If you have any suggestions, let me know.

--
- Jeremiah Mahler

This message and any attachments may contain Cypress (or its subsidiaries) confidential information. If it has been received in error, please advise the sender and immediately delete this message.