input: cyapa: instruction of cyapa patches
Subsystems (2)
v13 cover input: cyapa: instruction of cyapa patches
V13 patches have below updates, details of other updates see history list:
1) Remove all debugfs interface, including read_fw and raw_data interfaces.
2) This patches are made based linux next-20141208.
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.
The new design cyapa driver contains:cyapa.c - the core of the re-design, supply interfaces and functions to system and read trackpad devices.cyapa.h - header file including macros and data structure definitions. cyapa_gen3.c - functions support for gen3 trackpad devices, cyapa_gen5.c - functions support for gen5 trackpad devices.
Beside this introduction patch, it has 12 patches listed as below. For these patches, each one is patched based on previous one.
patch 1/12: re-design cyapa driver with core functions and interface to support multi-type trackpad devices.
patch 2/12: add gen5 trackpad device basic functions supported into the re-design cyapa driver.
patch 3/12: add power management interfaces supported for the deivce.
patch 4/12: add runtime power management interfaces supported for the device.
patch 5/12: add sysfs interfaces supported in the cyapa driver. Including read firmware version, get production ID, read baseline, re-calibrate trackpad baselines and do trackpad firmware update.
patch 6/12: add gen3 trackpad device's firmware update function supported.
patch 7/12: add gen3 trackpad device's read baseline function supported.
patch 8/12: add gen3 trackpad device's force re-calibrate function supported.
patch 9/12: add gen5 trackpad device's firmware update function supported.
patch 10/12: add gen5 trackpad device's read baseline function supported.
patch 11/12: add gen5 trackpad device's force re-calibrate function.
patch 12/12: add acpi device id supported.
History patch series modifications list:
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 hander 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 hander 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.
PATCH v13 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/Makefile | 3 +- drivers/input/mouse/cyapa.c | 1050 ++++++++++++++------------------------ drivers/input/mouse/cyapa.h | 316 ++++++++++++ drivers/input/mouse/cyapa_gen3.c | 793 ++++++++++++++++++++++++++++ 4 files changed, 1498 insertions(+), 664 deletions(-) create mode 100644 drivers/input/mouse/cyapa.h create mode 100644 drivers/input/mouse/cyapa_gen3.c
drivers/input/mouse/Makefile +2 -1
@@ -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 +387 -663
1,254 lines not on this page · raw message
drivers/input/mouse/cyapa.h new file +316 -0
316 lines not on this page · raw message
drivers/input/mouse/cyapa_gen3.c new file +793 -0
793 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v13 2/12 input: cyapa: add gen5 trackpad device basic functions support
In reply to Dudley DuBased 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 | 1660 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 1675 insertions(+), 1 deletion(-) create mode 100644 drivers/input/mouse/cyapa_gen5.c
drivers/input/mouse/Makefile +1 -1
@@ -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
@@ -164,6 +164,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
@@ -247,6 +255,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 ;
@@ -483,6 +494,8 @@ static int cyapa_initialize(struct cyapa *cyapa)if (cyapa_gen3_ops.initialize) error = cyapa_gen3_ops.initialize (cyapa); +if (!error && cyapa_gen5_ops.initialize) + error = cyapa_gen5_ops.initialize (cyapa);if (error)return error;
drivers/input/mouse/cyapa.h +1 -0
@@ -312,5 +312,6 @@ u16 cyapa_pwr_cmd_to_sleep_time(u8 pwr_mode);extern const char unique_str[];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 +1660 -0
1,660 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v13 3/12 input: cyapa: add power management interfaces supported for the device
In reply to Dudley DuAdd 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 | 111 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+)
drivers/input/mouse/cyapa.c +111 -0
@@ -582,6 +582,96 @@ 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); + +if (!count) +dev_err (dev,"invalid suspend scanrate ms parameters\n" ); +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); +} +#endif /* CONFIG_PM_SLEEP */ +static int cyapa_probe (struct i2c_client *client,const struct i2c_device_id *dev_id) {
@@ -621,6 +711,27 @@ static int cyapa_probe(struct i2c_client *client,return error; } +#ifdef CONFIG_PM_SLEEP +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; + } + } +#endif /* CONFIG_PM_SLEEP */ + error = devm_request_threaded_irq(dev, client->irq, NULL, cyapa_irq, IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
Signature · 1 line
1.9.1
PATCH v13 4/12 input: cyapa: add runtime power management interfaces supported for the device
In reply to Dudley DuAdd 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 | 171 +++++++++++++++++++++++++++++++++++++++++++- drivers/input/mouse/cyapa.h | 4 ++ 2 files changed, 174 insertions(+), 1 deletion(-)
drivers/input/mouse/cyapa.c +170 -1
@@ -23,6 +23,7 @@#include <linux/mutex.h> #include <linux/slab.h> #include <linux/uaccess.h> +#include <linux/pm_runtime.h> #include "cyapa.h"
@@ -334,6 +335,8 @@ static int cyapa_open(struct input_dev *input) }enable_irq (client->irq); +pm_runtime_set_active (&client->dev); +pm_runtime_enable (&client->dev); out:mutex_unlock (&cyapa->state_sync_lock);return error;
@@ -347,8 +350,10 @@ static void cyapa_close(struct input_dev *input)mutex_lock (&cyapa->state_sync_lock);disable_irq (client->irq); +pm_runtime_disable (&client->dev);if (!CYAPA_BOOTLOADER (cyapa) && cyapa->ops->set_power_mode) cyapa->ops->set_power_mode (cyapa,PWR_MODE_OFF ,0 ); +pm_runtime_set_suspended (&client->dev);mutex_unlock (&cyapa->state_sync_lock); }
@@ -549,6 +554,7 @@ static irqreturn_t cyapa_irq(int irq, void *dev_id)struct device *dev = &cyapa->client->dev;bool cont; +pm_runtime_get_sync (dev);if (device_may_wakeup (dev))pm_wakeup_event (dev,0 );
@@ -579,6 +585,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 ; }
@@ -672,6 +680,116 @@ static void cyapa_remove_power_wakeup_group(void *data) }#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 ; +} +#endif /* CONFIG_PM_RUNTIME */ +static int cyapa_probe (struct i2c_client *client,const struct i2c_device_id *dev_id) {
@@ -732,6 +850,14 @@ static int cyapa_probe(struct i2c_client *client, }#endif /* CONFIG_PM_SLEEP */ +#ifdef CONFIG_PM_RUNTIME + error =cyapa_start_runtime (cyapa); +if (error) { +dev_err (dev,"failed to start pm_runtime: %d\n" , error); +return error; + } +#endif /* CONFIG_PM_RUNTIME */ + error = devm_request_threaded_irq(dev, client->irq, NULL, cyapa_irq, IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
@@ -772,6 +898,7 @@ static int __maybe_unused cyapa_suspend(struct device *dev)if (error)return error; +pm_runtime_disable (dev);disable_irq (client->irq);/*
@@ -788,6 +915,8 @@ static int __maybe_unused cyapa_suspend(struct device *dev) error); } +pm_runtime_set_suspended (dev); +if (device_may_wakeup (dev)) cyapa->irq_wake = (enable_irq_wake (client->irq) ==0 );
@@ -808,17 +937,57 @@ static int __maybe_unused cyapa_resume(struct device *dev) cyapa->irq_wake = false; } +pm_runtime_set_active (dev); + error =cyapa_reinitialize (cyapa);if (error)dev_warn (dev,"failed to reinitialize TP device: %d\n" , error);enable_irq (client->irq); +pm_runtime_enable (dev); +mutex_unlock (&cyapa->state_sync_lock);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; + +if (!CYAPA_BOOTLOADER (cyapa) && cyapa->ops->set_power_mode) { + 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; + +if (!CYAPA_BOOTLOADER (cyapa) && cyapa->ops->set_power_mode) { + 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 ; +} +#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
@@ -262,6 +262,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
PATCH v13 5/12 input: cyapa: add sysfs interfaces supported in the cyapa driver
In reply to Dudley DuAdd 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 | 327 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 327 insertions(+)
drivers/input/mouse/cyapa.c +327 -0
@@ -32,6 +32,8 @@#define CYAPA_ADAPTER_FUNC_SMBUS 2#define CYAPA_ADAPTER_FUNC_BOTH 3 +#define CYAPA_FW_NAME "cyapa.bin" +const char unique_str[] ="CYTRA" ;static int cyapa_reinitialize (struct cyapa *cyapa);
@@ -449,6 +451,29 @@ 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) { +if (!CYAPA_BOOTLOADER (cyapa) && cyapa->ops->set_power_mode) + cyapa->ops->set_power_mode (cyapa, +PWR_MODE_FULL_ACTIVE ,0 ); +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) { +disable_irq (cyapa->client->irq); +if (!CYAPA_BOOTLOADER (cyapa) && cyapa->ops->set_power_mode) + cyapa->ops->set_power_mode (cyapa,PWR_MODE_OFF ,0 ); + } +} +/* * cyapa_sleep_time_to_pwr_cmd and cyapa_pwr_cmd_to_sleep_time *
@@ -790,6 +815,295 @@ static int cyapa_start_runtime(struct cyapa *cyapa) }#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; + } + +if (cyapa->ops->check_fw) { + error = cyapa->ops->check_fw (cyapa, fw); +if (error) { +dev_err (dev,"Invalid CYAPA firmware image: %s\n" , + fw_name); + goto done; + } + }else { +dev_err (dev,"No valid device ops->check_fw handler set.\n" ); + error = -ENODEV ; + 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); + +if (cyapa->ops->bl_enter) { + error = cyapa->ops->bl_enter (cyapa); +if (error) { +dev_err (dev,"bl_enter failed, %d\n" , error); + goto err_detect; + } + } + +if (cyapa->ops->bl_activate) { + error = cyapa->ops->bl_activate (cyapa); +if (error) { +dev_err (dev,"bl_activate failed, %d\n" , error); + goto err_detect; + } + } + +if (cyapa->ops->bl_initiate) { + error = cyapa->ops->bl_initiate (cyapa, fw); +if (error) { +dev_err (dev,"bl_initiate failed, %d\n" , error); + goto err_detect; + } + } + +if (cyapa->ops->update_fw) { + error = cyapa->ops->update_fw (cyapa, fw); +if (error) { +dev_err (dev,"update_fw failed, %d\n" , error); + goto err_detect; + } + } + +if (cyapa->ops->bl_verify_app_integrity) { + error = cyapa->ops->bl_verify_app_integrity (cyapa); +if (error) { +dev_err (dev,"bl_verify_app_integrity 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[64 ]; +int ret, error; + +if (count >64 ) { +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->operational = false; + 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->ops->calibrate_store) { +dev_err (dev,"Calibrate operation not supported.\n" ); + error = -ENOTSUPP ; + }else { +cyapa_enable_irq_for_cmd (cyapa); + error = cyapa->ops->calibrate_store (dev, attr, buf, count); +cyapa_disable_irq_for_cmd (cyapa); + } + +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->ops->show_baseline) { +dev_err (dev,"Calibrate operation not supported.\n" ); + error = -ENOTSUPP ; + }else { +cyapa_enable_irq_for_cmd (cyapa); + error = cyapa->ops->show_baseline (dev, attr, buf); +cyapa_disable_irq_for_cmd (cyapa); + } + +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) {
@@ -829,6 +1143,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; + } +#ifdef CONFIG_PM_SLEEP if (device_can_wakeup (dev)) { error = sysfs_merge_group(&client->dev.kobj,
Signature · 1 line
1.9.1
PATCH v13 6/12 input: cyapa: add gen3 trackpad device firmware update function support
In reply to Dudley DuAdd 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 | 284 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 284 insertions(+)
drivers/input/mouse/cyapa_gen3.c +284 -0
@@ -416,6 +416,72 @@ 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. +* +* Also, if device was unregister device from input core. Device will +* re-register after it is detected following resumption of operational mode. +* +* 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; + + 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->state =CYAPA_STATE_NO_DEVICE ; + error =cyapa_write_byte (cyapa,CYAPA_CMD_SOFT_RESET ,0x01 ); +if (error) +return -EIO ; + +usleep_range (25000 ,50000 ); + error =cyapa_poll_state (cyapa,500 ); +if (error) +return error; +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;
@@ -476,6 +542,218 @@ static int cyapa_gen3_bl_exit(struct cyapa *cyapa)return 0 ; } +/* Used in gen3 bootloader commands. */ +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; +u8 cmd[78 ]; +u8 status[BL_STATUS_SIZE ]; +/* Programming for one block can take about 100ms. */ +int tries =11 ; +u8 bl_status, bl_error; + +/* Set write command and security key bytes. */ + cmd[0 ] =0xff ; + cmd[1 ] =0x39 ; + cmd[2 ] =0x00 ; + cmd[3 ] =0x01 ; + cmd[4 ] =0x02 ; + cmd[5 ] =0x03 ; + cmd[6 ] =0x04 ; + cmd[7 ] =0x05 ; + cmd[8 ] =0x06 ; + cmd[9 ] =0x07 ; + cmd[10 ] = block >>8 ; + cmd[11 ] = block; +memcpy (&cmd[12 ], data,CYAPA_FW_BLOCK_SIZE ); + cmd[76 ] =cyapa_gen3_csum (data,CYAPA_FW_BLOCK_SIZE ); + cmd[77 ] =cyapa_gen3_csum (cmd,sizeof (cmd) -1 ); + + ret =cyapa_gen3_write_buffer (cyapa, cmd,sizeof (cmd)); +if (ret) +return ret; + +/* Wait for write to finish */ +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 *
@@ -783,6 +1061,12 @@ static int cyapa_gen3_irq_handler(struct cyapa *cyapa) }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, + .state_parse = cyapa_gen3_state_parse, .operational_check = cyapa_gen3_do_operational_check,
Signature · 1 line
1.9.1
PATCH v13 7/12 input: cyapa: add gen3 trackpad device read baseline function support
In reply to Dudley DuAdd 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 | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+)
drivers/input/mouse/cyapa_gen3.c +71 -0
@@ -754,6 +754,75 @@ 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 =3 ; +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; + } + +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 *
@@ -1067,6 +1136,8 @@ const struct cyapa_dev_ops cyapa_gen3_ops = { .update_fw = cyapa_gen3_do_fw_update, .bl_deactivate = cyapa_gen3_bl_deactivate, + .show_baseline = cyapa_gen3_show_baseline, + .state_parse = cyapa_gen3_state_parse, .operational_check = cyapa_gen3_do_operational_check,
Signature · 1 line
1.9.1
PATCH v13 8/12 input: cyapa: add gen3 trackpad device force re-calibrate function support
In reply to Dudley DuAdd 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 | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+)
drivers/input/mouse/cyapa_gen3.c +58 -0
@@ -754,6 +754,63 @@ 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 =20 ;/* max recalibration timeout 2s. */ +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; + } + +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) {
@@ -1137,6 +1194,7 @@ const struct cyapa_dev_ops cyapa_gen3_ops = { .bl_deactivate = cyapa_gen3_bl_deactivate, .show_baseline = cyapa_gen3_show_baseline, + .calibrate_store = cyapa_gen3_do_calibrate, .state_parse = cyapa_gen3_state_parse, .operational_check = cyapa_gen3_do_operational_check,
Signature · 1 line
1.9.1
PATCH v13 9/12 input: cyapa: add gen5 trackpad device firmware update function support
In reply to Dudley DuAdd 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 | 2 +- drivers/input/mouse/cyapa_gen5.c | 290 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 291 insertions(+), 1 deletion(-)
drivers/input/mouse/Kconfig +1 -1
@@ -205,7 +205,7 @@ config MOUSE_BCM5974 config MOUSE_CYAPA tristate "Cypress APA I2C Trackpad support" - depends on I2C + depends on I2C && 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 +290 -0
314 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH v13 09/12] input: cyapa: add gen5 trackpad device firmware update function support
Dudley,
drivers/input/mouse/cyapa_gen5.c
Quoted 24 lines · Dudley Du
Add firmware image update function supported for gen5 trackpad device, it can be used through sysfs
update_fwinterface.
TEST=test on Chromebooks.Signed-off-by Dudley Du <[email protected]>--- drivers/input/mouse/Kconfig | 2 +- drivers/input/mouse/cyapa_gen5.c | 290 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 291 insertions(+), 1 deletion(-)drivers/input/mouse/Kconfig +1
-1@@ -205,7 +205,7 @@ config MOUSE_BCM5974 config MOUSE_CYAPA tristate "Cypress APA I2C Trackpad support" - depends on I2C + depends on I2C && 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 +0
-0
My initial config had MOUSE_CYAPA=m and CRC_ITU_T=n.
I did a 'make oldconfig', no questions were asked, but it removed MOUSE_CYAPA since CRC_ITU_T wasn't enabled. Since the cyapa modules were removed the touchpad no longer works. Not a very good upgrade path :-( To fix this I have to manually enable MOUSE_CYAPA and CRC_ITU_T to get it working again.
[...]
Signature · 1 line
- Jeremiah Mahler
Re: [PATCH v13 09/12] input: cyapa: add gen5 trackpad device firmware update function support
Dudley,
Quoted 19 lines · Jeremiah Mahler
Dudley,
Quoted 16 lines · Dudley Du
Add firmware image update function supported for gen5 trackpad device, it can be used through sysfs
update_fwinterface.
TEST=test on Chromebooks.Signed-off-by Dudley Du <[email protected]>--- drivers/input/mouse/Kconfig | 2 +- drivers/input/mouse/cyapa_gen5.c | 290 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 291 insertions(+), 1 deletion(-)drivers/input/mouse/Kconfig +0
-0@@ -205,7 +205,7 @@ config MOUSE_BCM5974
Quoted 4 lines
drivers/input/mouse/Kconfig config MOUSE_BCM5974 · line 208
Quoted 4 lines
drivers/input/mouse/Kconfig +1
-1config MOUSE_CYAPA tristate "Cypress APA I2C Trackpad support" - depends on I2C + depends on I2C && CRC_ITU_T
If this line is instead changed to:
+ depends on I2C
+ select CRC_ITU_T
It will upgrade correctly during make oldconfig without removing MOUSE_CYAPA.
And it looks like several other Kconfig files do it this way already.
linux-next$ grep -r CRC_ITU_T $(find ./ -name Kconfig)
Quoted 16 lines
drivers/input/mouse/cyapa_gen5.c
Quoted 4 lines
drivers/input/mouse/Kconfig +0
-0help 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 +0
-0My initial config had MOUSE_CYAPA=m and CRC_ITU_T=n.
I did a 'make oldconfig', no questions were asked, but it removedMOUSE_CYAPAsinceCRC_ITU_Twasn't enabled. Since the cyapa modules were removed the touchpad no longer works. Not a very good upgrade path :-( To fix this I have to manually enableMOUSE_CYAPAandCRC_ITU_Tto get it working again.[...]
Signature · 1 line
- Jeremiah Mahler
Signature · 1 line
- Jeremiah Mahler
RE: [PATCH v13 09/12] input: cyapa: add gen5 trackpad device firmware update function support
Jeremiah,
Thank you very much for the solution. I will aplly it to my local patches immediately.
Do you think it is required to re-submit the patch set right now?
Thanks,
Dudley
Quoted 66 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Jeremiah Mahler
Sent: 2014?12?10? 16:55
To: Dudley Du
Cc: [email protected]; [email protected]
Subject: Re: [PATCH v13 09/12] input: cyapa: add gen5 trackpad device firmware update function supportDudley,
Quoted 11 lines · Jeremiah Mahler
Dudley,
Quoted 8 lines · Dudley Du
Add firmware image update function supported for gen5 trackpad device, it can be used through sysfs
update_fwinterface.
TEST=test on Chromebooks.Signed-off-by Dudley Du <[email protected]>--- drivers/input/mouse/Kconfig | 2 +- drivers/input/mouse/cyapa_gen5.c | 290+++++++++++++++++++++++++++++++++++++++
Quoted 8 lines
Quoted 8 lines
2 files changed, 291 insertions(+), 1 deletion(-)drivers/input/mouse/Kconfig +0
-0@@ -205,7 +205,7 @@ config MOUSE_BCM5974Quoted 4 lines
drivers/input/mouse/Kconfig config MOUSE_BCM5974 · line 208
Quoted 4 lines
drivers/input/mouse/Kconfig +1
-1config MOUSE_CYAPA tristate "Cypress APA I2C Trackpad support" -depends on I2C +depends on I2C && CRC_ITU_TIf this line is instead changed to:
(quoted diff) +2
-0+ depends on I2C + select CRC_ITU_TIt will upgrade correctly during make oldconfig without removing
MOUSE_CYAPA.And it looks like several other
Kconfigfiles do it this way already.linux-next$ grep -r CRC_ITU_T $(find ./ -name Kconfig)Quoted 4 lines
Review
Quoted 4 lines
drivers/input/mouse/Kconfig +0
-0help This driver adds support for Cypress All Points Addressable (APA) I2C Trackpads, including the ones used in 2012 Samsung Chromebooks.(quoted diff) +0
-0
b/drivers/input/mouse/cyapa_gen5.cQuoted 8 lines
My initial config had MOUSE_CYAPA=m and CRC_ITU_T=n.
I did a 'make oldconfig', no questions were asked, but it removedMOUSE_CYAPAsinceCRC_ITU_Twasn't enabled. Since the cyapa modules were removed the touchpad no longer works. Not a very good upgrade path :-( To fix this I have to manually enableMOUSE_CYAPAandCRC_ITU_Tto get it working again.Quoted 4 lines
[...]
--
- Jeremiah Mahler
Quoted 6 lines
--
- Jeremiah Mahler
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
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.
Re: [PATCH v13 09/12] input: cyapa: add gen5 trackpad device firmware update function support
Dudley,
Quoted 6 lines · Dudley Du
Jeremiah,
Thank you very much for the solution. I will aplly it to my local patches immediately.
Do you think it is required to re-submit the patch set right now?
I think you could if you want to or you could wait to see if any others provide more feedback. It is up to you.
Quoted 13 lines
Thanks,
DudleyQuoted 10 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Jeremiah Mahler
Sent: 2014?12?10? 16:55
To: Dudley Du
Cc: [email protected]; [email protected]
Subject: Re: [PATCH v13 09/12] input: cyapa: add gen5 trackpad device firmware update function supportDudley,
[...]
Signature · 1 line
- Jeremiah Mahler
PATCH v13 10/12 input: cyapa: add gen5 trackpad device read baseline function support
In reply to Dudley DuAdd 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 | 621 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 623 insertions(+)
drivers/input/mouse/cyapa.h +2 -0
@@ -285,6 +285,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 algined_electrodes_rx;/* 4 aligned */ int max_z;/*
drivers/input/mouse/cyapa_gen5.c +621 -0
633 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH v13 10/12] input: cyapa: add gen5 trackpad device read baseline function support
Dudley,
Quoted 6 lines · Dudley Du
Add read baseline function supported for gen5 trackpad device, it can be used through sysfs baseline interface. TEST=test on Chromebooks.
Signed-off-by Dudley Du <[email protected]>---
[...]
drivers/input/mouse/cyapa_gen5.c static int cyapa_gen5_set_power_mode(struct cyapa *cyapa, · line 1543
Quoted 11 lines
drivers/input/mouse/cyapa_gen5.c +8
-0return 0 ; } +static int cyapa_gen5_resume_scanning (struct cyapa *cyapa) +{ +u8 cmd[7 ] = {0x04 ,0x00 ,0x05 ,0x00 ,0x2f ,0x00 ,0x04 }; +u8 resp_data[6 ]; +int resp_len; +int error; + +/* Try to dump all bufferred data before doing command. */
^^^^^^^^^ buffered
And there are three more below.
Quoted 40 lines
drivers/input/mouse/cyapa_gen5.c +40
-0+cyapa_empty_pip_output_data (cyapa,NULL ,NULL ,NULL ); + + resp_len =6 ; + error =cyapa_i2c_pip_cmd_irq_sync (cyapa, + cmd,7 , + resp_data, &resp_len, +500 , cyapa_gen5_sort_tsg_pip_app_resp_data, true); +if (error || !VALID_CMD_RESP_HEADER (resp_data,0x04 )) +return -EINVAL ; + +/* Try to dump all bufferred data when resuming scanning. */ +cyapa_empty_pip_output_data (cyapa,NULL ,NULL ,NULL ); + +return 0 ; +} + +static int cyapa_gen5_suspend_scanning (struct cyapa *cyapa) +{ +u8 cmd[7 ] = {0x04 ,0x00 ,0x05 ,0x00 ,0x2f ,0x00 ,0x03 }; +u8 resp_data[6 ]; +int resp_len; +int error; + +/* Try to dump all bufferred data before doing command. */ +cyapa_empty_pip_output_data (cyapa,NULL ,NULL ,NULL ); + + resp_len =6 ; + error =cyapa_i2c_pip_cmd_irq_sync (cyapa, + cmd,7 , + resp_data, &resp_len, +500 , cyapa_gen5_sort_tsg_pip_app_resp_data, true); +if (error || !VALID_CMD_RESP_HEADER (resp_data,0x03 )) +return -EINVAL ; + +/* Try to dump all bufferred data when suspending scanning. */ +cyapa_empty_pip_output_data (cyapa,NULL ,NULL ,NULL ); + +return 0 ; +} +
[...]
Signature · 1 line
- Jeremiah Mahler
PATCH v13 11/12 input: cyapa: add gen5 trackpad device force re-calibrate function support
In reply to Dudley DuAdd 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
@@ -1581,6 +1581,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) +{ +u8 cmd[8 ]; +u8 resp_data[6 ]; +int resp_len; +int error; + +/* Try to dump all bufferred data before doing command. */ +cyapa_empty_pip_output_data (cyapa,NULL ,NULL ,NULL ); + + cmd[0 ] =0x04 ; + cmd[1 ] =0x00 ; + cmd[2 ] =0x06 ; + cmd[3 ] =0x00 ; + cmd[4 ] =GEN5_APP_CMD_REPORT_ID ; + cmd[5 ] =0x00 ; + cmd[6 ] =GEN5_CMD_CALIBRATE ; + cmd[7 ] = 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 two_complement_to_s32 (s32 value,int num_bits) {if (value >> (num_bits -1 ))
@@ -2558,6 +2622,7 @@ const struct cyapa_dev_ops cyapa_gen5_ops = { .update_fw = cyapa_gen5_do_fw_update, .show_baseline = cyapa_gen5_show_baseline, + .calibrate_store = cyapa_gen5_do_calibrate, .initialize = cyapa_gen5_initialize,
Signature · 1 line
1.9.1
Re: [PATCH v13 11/12] input: cyapa: add gen5 trackpad device force re-calibrate function support
Dudley,
Quoted 16 lines · Dudley Du
Add force re-calibrate function supported for gen5 trackpad device, it can be used through sysfs calibrate interface. TEST=test on Chromebooks.
Signed-off-by Dudley Du <[email protected]>--- drivers/input/mouse/cyapa_gen5.c | 65 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+)drivers/input/mouse/cyapa_gen5.c +0
-0@@ -1581,6 +1581,70 @@ static int cyapa_gen5_suspend_scanning(struct cyapa *cyapa)return 0 ; }
drivers/input/mouse/cyapa_gen5.c static int cyapa_gen5_suspend_scanning(struct cyapa *cyapa) · line 1592
Quoted 10 lines
drivers/input/mouse/cyapa_gen5.c +9
-0+static int cyapa_gen5_calibrate_pwcs (struct cyapa *cyapa, +u8 calibrate_sensing_mode_type) +{ +u8 cmd[8 ]; +u8 resp_data[6 ]; +int resp_len; +int error; + +/* Try to dump all bufferred data before doing command. */
^^^^^^^^^ buffered
[...]
Signature · 1 line
- Jeremiah Mahler
PATCH v13 12/12 input: cyapa: add acpi device id supported
In reply to Dudley DuAdd acpi device tree supported.
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
@@ -24,6 +24,7 @@#include <linux/slab.h> #include <linux/uaccess.h> #include <linux/pm_runtime.h> +#include <linux/acpi.h> #include "cyapa.h"
@@ -1322,11 +1323,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
Dudley, all,
Quoted 4 lines · Dudley Du
V13 patches have below updates, details of other updates see history list:
1) Remove all debugfs interface, includingread_fwandraw_datainterfaces.
2) This patches are made based linux next-20141208.
[...]
I tested this patch set on an Acer C720 and other than the minor problems I pointed out in other emails (CONFIG_CYAPA, spelling) it seems to work fine and there are no obvious problems.
Signature · 1 line
- Jeremiah Mahler
Jeremiah,
Thank you very much for your review, comments and test. I will correct the spelling issues in next submit version.
Thanks,
Dudley
Quoted 22 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Jeremiah Mahler
Sent: 2014?12?10? 12:10
To: Dudley Du
Cc: [email protected]; [email protected]; [email protected]; David Solda; [email protected]; [email protected]
Subject: Re: [PATCH v13 00/12] input: cyapa: instruction of cyapa patchesDudley, all,
Quoted 4 lines · Dudley Du
V13 patches have below updates, details of other updates see history list:
1) Remove all debugfs interface, includingread_fwandraw_datainterfaces.
2) This patches are made based linux next-20141208.[...]
I tested this patch set on an Acer C720 and other than the minor problems I pointed out in other emails (
CONFIG_CYAPA, spelling) it seems to work fine and there are no obvious problems.
Quoted 8 lines
Reviewed-by Jeremiah Mahler <[email protected]>--
- Jeremiah Mahler
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
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.