input: cyapa: instruction of cyapa patches
Subsystems (2)
v12 cover input: cyapa: instruction of cyapa patches
V12 patches have below main updates compared with v10 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.
This patch set 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 18 patches listed as below. For these patches each one is patched based on previous one.
patch 1/19: modify code to following kernel code style.
patch 2/19: add device resource management infrastructure support.
patch 3/19: re-design cyapa driver with core functions and interface to support multi-type trackpad devices.
patch 4/19: add gen5 trackpad device basic functions supported into the re-design cyapa driver.
patch 5/19: add power management interfaces supported for the deivce.
patch 6/19: add runtime power management interfaces supported for the device.
patch 7/19: 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 8/19: add gen3 trackpad device's firmware update function supported.
patch 9/19: add gen3 trackpad device's read baseline function supported.
patch 10/19: add gen3 trackpad device's force re-calibrate function supported.
patch 11/19: add gen5 trackpad device's firmware update function supported.
patch 12/19: add gen5 trackpad device's read baseline function supported.
patch 13/19: add gen5 trackpad device's force re-calibrate function.
patch 14/19: add read firmware image debugfs interface supported in the cyapa driver.
patch 15/19: add gen3 trackpad device's read firmware image function supported.
patch 16/19: add gen5 trackpad device's read firmware image function supported.
patch 17/19: add read trackpad device's sensors' raw data debugfs interface supported in the cyapa driver.
patch 18/19: add gen5 trackpad device's read read raw function supported.
patch 19/19: add acpi device id supported.
PATCH v12 1/19 input: cyapa: modify code to following kernel code style
This patch modified the code to fix the patch check warning issue with latest checkpatch.sh tool, and also changed the return variable name from "ret" to "error" when there is only one error path to follow code style. TEST=test on Chromebooks.
--- drivers/input/mouse/cyapa.c | 162 ++++++++++++++++++++++---------------------- 1 file changed, 80 insertions(+), 82 deletions(-)
drivers/input/mouse/cyapa.c +80 -82
@@ -6,7 +6,7 @@* Daniel Kurtz <[email protected]> * Benson Leung <[email protected]> * -* Copyright (C) 2011-2012 Cypress Semiconductor, Inc. +* Copyright (C) 2011-2014 Cypress Semiconductor, Inc. * Copyright (C) 2011-2012 Google, Inc. * * This file is subject to the terms and conditions of the GNU General Public
@@ -409,11 +409,11 @@ static ssize_t cyapa_read_block(struct cyapa *cyapa, u8 cmd_idx, u8 *values) cmd = cyapa_smbus_cmds[cmd_idx].cmd; len = cyapa_smbus_cmds[cmd_idx].len;return cyapa_smbus_read_block (cyapa, cmd, len, values); - }else { - cmd = cyapa_i2c_cmds[cmd_idx].cmd; - len = cyapa_i2c_cmds[cmd_idx].len; -return cyapa_i2c_reg_read_block (cyapa, cmd, len, values); } + + cmd = cyapa_i2c_cmds[cmd_idx].cmd; + len = cyapa_i2c_cmds[cmd_idx].len; +return cyapa_i2c_reg_read_block (cyapa, cmd, len, values); }/*
@@ -422,8 +422,8 @@ static ssize_t cyapa_read_block(struct cyapa *cyapa, u8 cmd_idx, u8 *values)*/ static int cyapa_get_state (struct cyapa *cyapa) { -int ret;u8 status[BL_STATUS_SIZE ]; +int error; cyapa->state =CYAPA_STATE_NO_DEVICE ;
@@ -433,7 +433,7 @@ static int cyapa_get_state(struct cyapa *cyapa)* If the device is in operation mode, this will be the DATA regs. * */ - ret =cyapa_i2c_reg_read_block (cyapa,BL_HEAD_OFFSET ,BL_STATUS_SIZE , + error =cyapa_i2c_reg_read_block (cyapa,BL_HEAD_OFFSET ,BL_STATUS_SIZE , status);/*
@@ -441,10 +441,10 @@ static int cyapa_get_state(struct cyapa *cyapa)* -ETIMEDOUT. In this case, try again using the smbus equivalent * command. This should return a BL_HEAD indicating CYAPA_STATE_OP. */ -if (cyapa->smbus && (ret == -ETIMEDOUT || ret == -ENXIO )) - ret =cyapa_read_block (cyapa,CYAPA_CMD_BL_STATUS , status); +if (cyapa->smbus && (error == -ETIMEDOUT || error == -ENXIO )) + error =cyapa_read_block (cyapa,CYAPA_CMD_BL_STATUS , status); -if (ret !=BL_STATUS_SIZE ) +if (error !=BL_STATUS_SIZE ) goto error;if ((status[REG_OP_STATUS ] &OP_STATUS_SRC ) ==OP_STATUS_SRC ) {
@@ -454,7 +454,7 @@ static int cyapa_get_state(struct cyapa *cyapa) cyapa->state =CYAPA_STATE_OP ;break ;default : - ret = -EAGAIN ; + error = -EAGAIN ; goto error; } }else {
@@ -468,7 +468,7 @@ static int cyapa_get_state(struct cyapa *cyapa)return 0 ; error: -return (ret <0 ) ? ret : -EAGAIN ; +return (error <0 ) ? error : -EAGAIN ; }/*
@@ -487,31 +487,31 @@ error:*/ static int cyapa_poll_state (struct cyapa *cyapa,unsigned int timeout) { -int ret; +int error;int tries = timeout /100 ; - ret =cyapa_get_state (cyapa); -while ((ret || cyapa->state >=CYAPA_STATE_BL_BUSY ) && tries--) { + error =cyapa_get_state (cyapa); +while ((error || cyapa->state >=CYAPA_STATE_BL_BUSY ) && tries--) {msleep (100 ); - ret =cyapa_get_state (cyapa); + error =cyapa_get_state (cyapa); } -return (ret == -EAGAIN || ret == -ETIMEDOUT ) ? -ETIMEDOUT : ret; +return (error == -EAGAIN || error == -ETIMEDOUT ) ? -ETIMEDOUT : error; }static int cyapa_bl_deactivate (struct cyapa *cyapa) { -int ret; +int error; - ret =cyapa_i2c_reg_write_block (cyapa,0 ,sizeof (bl_deactivate), + error =cyapa_i2c_reg_write_block (cyapa,0 ,sizeof (bl_deactivate), bl_deactivate); -if (ret <0 ) -return ret; +if (error) +return error;/* wait for bootloader to switch to idle state; should take < 100ms */ msleep (100 ); - ret =cyapa_poll_state (cyapa,500 ); -if (ret <0 ) -return ret; + error =cyapa_poll_state (cyapa,500 ); +if (error) +return error;if (cyapa->state !=CYAPA_STATE_BL_IDLE )return -EAGAIN ;return 0 ;
@@ -532,11 +532,11 @@ static int cyapa_bl_deactivate(struct cyapa *cyapa)*/ static int cyapa_bl_exit (struct cyapa *cyapa) { -int ret; +int error; - ret =cyapa_i2c_reg_write_block (cyapa,0 ,sizeof (bl_exit), bl_exit); -if (ret <0 ) -return ret; + error =cyapa_i2c_reg_write_block (cyapa,0 ,sizeof (bl_exit), bl_exit); +if (error) +return error;/* * Wait for bootloader to exit, and operation mode to start.
@@ -548,9 +548,9 @@ static int cyapa_bl_exit(struct cyapa *cyapa)* updated to new firmware, it must first calibrate its sensors, which * can take up to an additional 2 seconds. */ - ret =cyapa_poll_state (cyapa,2000 ); -if (ret <0 ) -return ret; + error =cyapa_poll_state (cyapa,2000 ); +if (error <0 ) +return error;if (cyapa->state !=CYAPA_STATE_OP )return -EAGAIN ;
@@ -637,28 +637,28 @@ static int cyapa_check_is_operational(struct cyapa *cyapa) {struct device *dev = &cyapa->client->dev;static const char unique_str[] ="CYTRA" ; -int ret; +int error; - ret =cyapa_poll_state (cyapa,2000 ); -if (ret <0 ) -return ret; + error =cyapa_poll_state (cyapa,2000 ); +if (error) +return error;switch (cyapa->state) {case CYAPA_STATE_BL_ACTIVE : - ret =cyapa_bl_deactivate (cyapa); -if (ret) -return ret; + error =cyapa_bl_deactivate (cyapa); +if (error) +return error;/* Fallthrough state */ case CYAPA_STATE_BL_IDLE : - ret =cyapa_bl_exit (cyapa); -if (ret) -return ret; + error =cyapa_bl_exit (cyapa); +if (error) +return error;/* Fallthrough state */ case CYAPA_STATE_OP : - ret =cyapa_get_query_data (cyapa); -if (ret <0 ) -return ret; + error =cyapa_get_query_data (cyapa); +if (error) +return error;/* only support firmware protocol gen3 */ if (cyapa->gen !=CYAPA_GEN3 ) {
@@ -756,15 +756,15 @@ static u8 cyapa_check_adapter_functionality(struct i2c_client *client)static int cyapa_create_input_dev (struct cyapa *cyapa) {struct device *dev = &cyapa->client->dev; -int ret;struct input_dev *input; +int error;if (!cyapa->physical_size_x || !cyapa->physical_size_y)return -EINVAL ; input = cyapa->input =input_allocate_device ();if (!input) { -dev_err (dev,"allocate memory for input device failed\n" ); +dev_err (dev,"failed to allocate memory for input device.\n" );return -ENOMEM ; }
@@ -772,14 +772,14 @@ static int cyapa_create_input_dev(struct cyapa *cyapa) input->phys = cyapa->phys; input->id.bustype =BUS_I2C ; input->id.version =1 ; - input->id.product =0 ;/* means any product in eventcomm. */ + input->id.product =0 ;/* Means any product in eventcomm. */ input->dev.parent = &cyapa->client->dev;input_set_drvdata (input, cyapa);__set_bit (EV_ABS , input->evbit); -/* finger position */ +/* Finger position */ input_set_abs_params (input,ABS_MT_POSITION_X ,0 , cyapa->max_abs_x,0 ,0 ); input_set_abs_params(input, ABS_MT_POSITION_Y, 0, cyapa->max_abs_y, 0,
@@ -801,18 +801,18 @@ static int cyapa_create_input_dev(struct cyapa *cyapa)if (cyapa->btn_capability ==CAPABILITY_LEFT_BTN_MASK )__set_bit (INPUT_PROP_BUTTONPAD , input->propbit); -/* handle pointer emulation and unused slots in core */ - ret =input_mt_init_slots (input,CYAPA_MAX_MT_SLOTS , -INPUT_MT_POINTER |INPUT_MT_DROP_UNUSED ); -if (ret) { -dev_err (dev,"allocate memory for MT slots failed, %d\n" , ret); +/* Handle pointer emulation and unused slots in core */ + error =input_mt_init_slots (input,CYAPA_MAX_MT_SLOTS , +INPUT_MT_POINTER |INPUT_MT_DROP_UNUSED ); +if (error) { +dev_err (dev,"failed to initialize MT slots, %d\n" , error); goto err_free_device; }/* Register the device in input subsystem */ - ret =input_register_device (input); -if (ret) { -dev_err (dev,"input device register failed, %d\n" , ret); + error =input_register_device (input); +if (error) { +dev_err (dev,"failed to register input device, %d\n" , error); goto err_free_device; }return 0 ;
@@ -820,16 +820,16 @@ static int cyapa_create_input_dev(struct cyapa *cyapa) err_free_device:input_free_device (input); cyapa->input =NULL ; -return ret; +return error; }static int cyapa_probe (struct i2c_client *client,const struct i2c_device_id *dev_id) { -int ret;u8 adapter_func;struct cyapa *cyapa;struct device *dev = &client->dev; +int error; adapter_func =cyapa_check_adapter_functionality (client);if (adapter_func ==CYAPA_ADAPTER_FUNC_NONE ) {
@@ -838,10 +838,8 @@ static int cyapa_probe(struct i2c_client *client, } cyapa =kzalloc (sizeof (struct cyapa ),GFP_KERNEL ); -if (!cyapa) { -dev_err (dev,"allocate memory for cyapa failed\n" ); +if (!cyapa)return -ENOMEM ; - } cyapa->gen =CYAPA_GEN3 ; cyapa->client = client;
@@ -853,33 +851,33 @@ static int cyapa_probe(struct i2c_client *client,if (adapter_func ==CYAPA_ADAPTER_FUNC_SMBUS ) cyapa->smbus = true; cyapa->state =CYAPA_STATE_NO_DEVICE ; - ret =cyapa_check_is_operational (cyapa); -if (ret) { -dev_err (dev,"device not operational, %d\n" , ret); + error =cyapa_check_is_operational (cyapa); +if (error) { +dev_err (dev,"device not operational, %d\n" , error); goto err_mem_free; } - ret =cyapa_create_input_dev (cyapa); -if (ret) { -dev_err (dev,"create input_dev instance failed, %d\n" , ret); + error =cyapa_create_input_dev (cyapa); +if (error) { +dev_err (dev,"create input_dev instance failed, %d\n" , error); goto err_mem_free; } - ret =cyapa_set_power_mode (cyapa,PWR_MODE_FULL_ACTIVE ); -if (ret) { -dev_err (dev,"set active power failed, %d\n" , ret); + error =cyapa_set_power_mode (cyapa,PWR_MODE_FULL_ACTIVE ); +if (error) { +dev_err (dev,"set active power failed, %d\n" , error); goto err_unregister_device; } cyapa->irq = client->irq; - ret =request_threaded_irq (cyapa->irq, + error =request_threaded_irq (cyapa->irq,NULL , cyapa_irq,IRQF_TRIGGER_FALLING |IRQF_ONESHOT ,"cyapa" , cyapa); -if (ret) { -dev_err (dev,"IRQ request failed: %d\n, " , ret); +if (error) { +dev_err (dev,"failed to request threaded irq: %d\n" , error); goto err_unregister_device; }
@@ -890,7 +888,7 @@ err_unregister_device: err_mem_free:kfree (cyapa); -return ret; +return error; }static int cyapa_remove (struct i2c_client *client)
@@ -908,7 +906,7 @@ static int cyapa_remove(struct i2c_client *client)#ifdef CONFIG_PM_SLEEP static int cyapa_suspend (struct device *dev) { -int ret; +int error;u8 power_mode;struct cyapa *cyapa =dev_get_drvdata (dev);
@@ -920,9 +918,9 @@ static int cyapa_suspend(struct device *dev)*/ power_mode =device_may_wakeup (dev) ?PWR_MODE_IDLE :PWR_MODE_OFF ; - ret =cyapa_set_power_mode (cyapa, power_mode); -if (ret <0 ) -dev_err (dev,"set power mode failed, %d\n" , ret); + error =cyapa_set_power_mode (cyapa, power_mode); +if (error) +dev_err (dev,"set power mode failed, %d\n" , error);if (device_may_wakeup (dev)) cyapa->irq_wake = (enable_irq_wake (cyapa->irq) ==0 );
@@ -931,15 +929,15 @@ static int cyapa_suspend(struct device *dev)static int cyapa_resume (struct device *dev) { -int ret; +int error;struct cyapa *cyapa =dev_get_drvdata (dev);if (device_may_wakeup (dev) && cyapa->irq_wake)disable_irq_wake (cyapa->irq); - ret =cyapa_set_power_mode (cyapa,PWR_MODE_FULL_ACTIVE ); -if (ret) -dev_warn (dev,"resume active power failed, %d\n" , ret); + error =cyapa_set_power_mode (cyapa,PWR_MODE_FULL_ACTIVE ); +if (error) +dev_warn (dev,"resume active power failed, %d\n" , error);enable_irq (cyapa->irq);return 0 ;
Signature · 1 line
1.9.1
Re: [PATCH v12 01/19] input: cyapa: modify code to following kernel code style
Dudley,
drivers/input/mouse/cyapa.c
Quoted 14 lines · Dudley Du
This patch modified the code to fix the patch check warning issue with latest
checkpatch.shtool, and also changed the return variable name from "ret" to "error" when there is only one error path to follow code style. TEST=test on Chromebooks.Signed-off-by Dudley Du <[email protected]>--- drivers/input/mouse/cyapa.c | 162 ++++++++++++++++++++++---------------------- 1 file changed, 80 insertions(+), 82 deletions(-)drivers/input/mouse/cyapa.c +0
-0
[...]
I was hoping to test out your patchset since the patch for the touchpad problem [1] still has not appeared in linux-next as of 20141203. Unfortunately your patchset does not apply so I can't test it. Which kernel is your work based off of?
[1]: https://lkml.org/lkml/2014/11/27/684
Signature · 1 line
- Jeremiah Mahler
RE: [PATCH v12 01/19] input: cyapa: modify code to following kernel code style
Jeremiah,
I didn't submitted this fix patch, but Dmitry has been helping apply the fix patch quickly, maybe todoay or tommorrow.
For the pathces that I made were worked based off of kernel mainline.
Thanks,
Dudley
Quoted 32 lines
-----Original Message-----
From: Jeremiah Mahler [mailto:[email protected]]
Sent: 2014?12?4? 12:58
To: Dudley Du
Cc: [email protected]; [email protected]
Subject: Re: [PATCH v12 01/19] input: cyapa: modify code to following kernel code styleDudley,
drivers/input/mouse/cyapa.c
Quoted 14 lines · Dudley Du
This patch modified the code to fix the patch check warning issue with latest
checkpatch.shtool, and also changed the return variable name from "ret" to "error" when there is only one error path to follow code style. TEST=test on Chromebooks.Signed-off-by Dudley Du <[email protected]>--- drivers/input/mouse/cyapa.c | 162 ++++++++++++++++++++++---------------------- 1 file changed, 80 insertions(+), 82 deletions(-)drivers/input/mouse/cyapa.c +0
-0[...]
I was hoping to test out your patchset since the patch for the touchpad problem [1] still has not appeared in linux-next as of 20141203. Unfortunately your patchset does not apply so I can't test it. Which kernel is your work based off of?
Quoted 4 lines
[1]: https://lkml.org/lkml/2014/11/27/684
--
- 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.
Re: [PATCH v12 01/19] input: cyapa: modify code to following kernel code style
Dudley,
Quoted 6 lines · Dudley Du
Jeremiah,
I didn't submitted this fix patch, but Dmitry has been helping apply the fix patch quickly, maybe todoay or tommorrow.
For the pathces that I made were worked based off of kernel mainline.
I'm sorry, I still can't figure out which one.
According to kernel.org, mainline is 3.18-rc7, which is similar to linux-next, but the patches won't apply.
I tried linux-stable 3.17.4 too but they won't apply to that either.
Which version are you using exactly?
Quoted 3 lines
Thanks,
Dudley
[...]
Signature · 1 line
- Jeremiah Mahler
[email protected]
maintainerRe: [PATCH v12 01/19] input: cyapa: modify code to following kernel code style
In reply to Dudley DuDudley, Jeremiah,
Quoted 3 lines · Dudley Du
Jeremiah,
I didn't submitted this fix patch, but Dmitry has been helping apply the fix patch quickly, maybe todoay or tommorrow.
The patches that I apply for the next merge window should appear first in my 'next' branch in
git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git
and then in the linux-next and eventually in mainline.
Quoted 2 lines
For the pathces that I made were worked based off of kernel mainline.
I resolved the conflicts and applied this 1/19 patch, next time you are re-posting the series could you please base them off my 'next' branch? It will help me applhy them much more easily.
Thanks!
Signature · 1 line
Dmitry
RE: [PATCH v12 01/19] input: cyapa: modify code to following kernel code style
Dmitry,
Thank you very much for the effort.
I will re-post the series based on the your updated next branch when it ready.
Thanks,
Dudley
Quoted 26 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: 2014?12?5? 1:32
To: Dudley Du
Cc: Jeremiah Mahler; [email protected]
Subject: Re: [PATCH v12 01/19] input: cyapa: modify code to following kernel code styleDudley, Jeremiah,
Quoted 3 lines · Dudley Du
Jeremiah,
I didn't submitted this fix patch, but Dmitry has been helping apply the fix patch
quickly, maybe todoay or tommorrow.
The patches that I apply for the next merge window should appear first in my 'next' branch in
git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.gitand then in the linux-next and eventually in mainline.
Quoted 2 lines
For the pathces that I made were worked based off of kernel mainline.
Quoted 8 lines
I resolved the conflicts and applied this 1/19 patch, next time you are re-posting the series could you please base them off my 'next' branch? It will help me applhy them much more easily.
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.
PATCH v12 2/19 input: cyapa: add device resource management infrastructure support
In reply to Dudley DuRemove cyapa_remove() method, add cyapa_open() and cyapa_close() methods for input interface, also modified together with driver's memory and IRQ resource allocations to support device resource management infrastructure to reduce the mistakes of resource management.
TEST=test on Chromebooks.
--- drivers/input/mouse/cyapa.c | 77 ++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 33 deletions(-)
drivers/input/mouse/cyapa.c +44 -33
@@ -753,6 +753,22 @@ static u8 cyapa_check_adapter_functionality(struct i2c_client *client)return ret; } +static int cyapa_open (struct input_dev *input) +{ +struct cyapa *cyapa =input_get_drvdata (input); +struct i2c_client *client = cyapa->client; + +enable_irq (client->irq); +return 0 ; +} + +static void cyapa_close (struct input_dev *input) +{ +struct cyapa *cyapa =input_get_drvdata (input); + +disable_irq (cyapa->client->irq); +} +static int cyapa_create_input_dev (struct cyapa *cyapa) {struct device *dev = &cyapa->client->dev;
@@ -762,7 +778,7 @@ static int cyapa_create_input_dev(struct cyapa *cyapa)if (!cyapa->physical_size_x || !cyapa->physical_size_y)return -EINVAL ; - input = cyapa->input =input_allocate_device (); + input =devm_input_allocate_device (dev);if (!input) {dev_err (dev,"failed to allocate memory for input device.\n" );return -ENOMEM ;
@@ -775,6 +791,9 @@ static int cyapa_create_input_dev(struct cyapa *cyapa) input->id.product =0 ;/* Means any product in eventcomm. */ input->dev.parent = &cyapa->client->dev; + input->open = cyapa_open; + input->close = cyapa_close; +input_set_drvdata (input, cyapa);__set_bit (EV_ABS , input->evbit);
@@ -806,21 +825,18 @@ static int cyapa_create_input_dev(struct cyapa *cyapa) INPUT_MT_POINTER | INPUT_MT_DROP_UNUSED);if (error) {dev_err (dev,"failed to initialize MT slots, %d\n" , error); - goto err_free_device; +return error; }/* Register the device in input subsystem */ error =input_register_device (input);if (error) {dev_err (dev,"failed to register input device, %d\n" , error); - goto err_free_device; +return error; } -return 0 ; -err_free_device: -input_free_device (input); - cyapa->input =NULL ; -return error; + cyapa->input = input; +return 0 ; } static int cyapa_probe(struct i2c_client *client,
@@ -837,7 +853,7 @@ static int cyapa_probe(struct i2c_client *client,return -EIO ; } - cyapa =kzalloc (sizeof (struct cyapa ),GFP_KERNEL ); + cyapa =devm_kzalloc (dev,sizeof (struct cyapa ),GFP_KERNEL );if (!cyapa)return -ENOMEM ;
@@ -854,51 +870,46 @@ static int cyapa_probe(struct i2c_client *client, error =cyapa_check_is_operational (cyapa);if (error) {dev_err (dev,"device not operational, %d\n" , error); - goto err_mem_free; - } - - error =cyapa_create_input_dev (cyapa); -if (error) { -dev_err (dev,"create input_dev instance failed, %d\n" , error); - goto err_mem_free; +return error; } error =cyapa_set_power_mode (cyapa,PWR_MODE_FULL_ACTIVE );if (error) {dev_err (dev,"set active power failed, %d\n" , error); - goto err_unregister_device; +return error; } cyapa->irq = client->irq; - error =request_threaded_irq (cyapa->irq, -NULL , - cyapa_irq, -IRQF_TRIGGER_FALLING |IRQF_ONESHOT , -"cyapa" , - cyapa); + error =devm_request_threaded_irq (dev, + cyapa->irq, +NULL , + cyapa_irq, +IRQF_TRIGGER_FALLING |IRQF_ONESHOT , +"cyapa" , + cyapa);if (error) {dev_err (dev,"failed to request threaded irq: %d\n" , error); - goto err_unregister_device; +return error; } -return 0 ; +/* Disable IRQ until the device is opened. */ +disable_irq (client->irq); -err_unregister_device: -input_unregister_device (cyapa->input); -err_mem_free: -kfree (cyapa); + error =cyapa_create_input_dev (cyapa); +if (error) { +dev_err (dev,"create input_dev instance failed, %d\n" , error); +return error; + } -return error; +return 0 ; }static int cyapa_remove (struct i2c_client *client) {struct cyapa *cyapa =i2c_get_clientdata (client); -free_irq (cyapa->irq, cyapa); -input_unregister_device (cyapa->input); +disable_irq (cyapa->irq);cyapa_set_power_mode (cyapa,PWR_MODE_OFF ); -kfree (cyapa);return 0 ; }
Signature · 1 line
1.9.1
Dmitry Torokhov
maintainerRe: [PATCH v12 02/19] input: cyapa: add device resource management infrastructure support
Quoted 7 lines · Dudley Du
Remove
cyapa_remove()method, addcyapa_open()andcyapa_close()methods for input interface, also modified together with driver's memory and IRQ resource allocations to support device resource management infrastructure to reduce the mistakes of resource management.
TEST=test on Chromebooks.Signed-off-by Dudley Du <[email protected]>
OK, so this patch (in slightly modified form) has already been applied, so you can drop it from the next respin.
Thanks.
Signature · 1 line
Dmitry
PATCH v12 3/19 input: cyapa: re-design driver to support multi-trackpad in one driver
In reply to Dudley DuIn 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 | 1063 +++++++++++++++----------------------- drivers/input/mouse/cyapa.h | 316 +++++++++++ drivers/input/mouse/cyapa_gen3.c | 792 ++++++++++++++++++++++++++++ 4 files changed, 1513 insertions(+), 661 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_GPIO) += gpio_mouse.o obj-$(CONFIG_MOUSE_INPORT) += inport.o obj-$(CONFIG_MOUSE_LOGIBM) += logibm.o
@@ -23,6 +23,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 +403 -660
1,256 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 +792 -0
792 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v12 4/19 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 | 1659 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 1674 insertions(+), 1 deletion(-) create mode 100644 drivers/input/mouse/cyapa_gen5.c
drivers/input/mouse/Makefile +1 -1
@@ -23,7 +23,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 +1659 -0
1,659 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v12 5/19 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,
Signature · 1 line
1.9.1
PATCH v12 6/19 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 | 167 ++++++++++++++++++++++++++++++++++++++++++++ drivers/input/mouse/cyapa.h | 4 ++ 2 files changed, 171 insertions(+)
drivers/input/mouse/cyapa.c +167 -0
@@ -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,
@@ -775,6 +901,7 @@ static int __maybe_unused cyapa_suspend(struct device *dev)if (error)return error; +pm_runtime_disable (dev);disable_irq (cyapa->client->irq);/*
@@ -791,6 +918,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 (cyapa->client->irq) ==0 );
@@ -811,18 +940,56 @@ 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_err (dev,"failed to reinitialize TP device: %d\n" , error);enable_irq (cyapa->client->irq); +pm_runtime_enable (dev); +mutex_unlock (&cyapa->state_sync_lock);return 0 ; } +#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_err (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_err (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[] = {
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 v12 7/19 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 v12 8/19 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 *
@@ -782,6 +1060,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 v12 9/19 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 *
@@ -1066,6 +1135,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 v12 10/19 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) {
@@ -1136,6 +1193,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 v12 11/19 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
PATCH v12 12/19 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
PATCH v12 13/19 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
@@ -1580,6 +1580,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 ))
@@ -2557,6 +2621,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
PATCH v12 14/19 input: cyapa: add read firmware image debugfs interface support
In reply to Dudley DuAdd read firmware image from trackpad device interface supported in cyapa driver through debugfs read_fw interface.
Through this interface user can read out, check and backup the firmware image of the trackpad device before any firmware update, or can use the backed image to do firmware image recovery.
TEST=test on Chromebooks.
--- drivers/input/mouse/cyapa.c | 182 +++++++++++++++++++++++++++++++++++++++++++- drivers/input/mouse/cyapa.h | 10 +++ 2 files changed, 191 insertions(+), 1 deletion(-)
drivers/input/mouse/cyapa.c +181 -1
@@ -14,6 +14,7 @@* more details. */ +#include <linux/debugfs.h> #include <linux/delay.h> #include <linux/i2c.h> #include <linux/input.h>
@@ -32,10 +33,14 @@#define CYAPA_ADAPTER_FUNC_SMBUS 2#define CYAPA_ADAPTER_FUNC_BOTH 3 +#define CYAPA_DEBUGFS_READ_FW "read_fw"#define CYAPA_FW_NAME "cyapa.bin"const char unique_str[] ="CYTRA" ; +/* Global root node of the cyapa debugfs directory. */ +static struct dentry *cyapa_debugfs_root; +static int cyapa_reinitialize (struct cyapa *cyapa);/* Returns 0 on success, else negative errno on failure. */
@@ -617,6 +622,141 @@ out:/* ************************************************************** +* debugfs interface +************************************************************** +*/ +static int cyapa_debugfs_open (struct inode *inode,struct file *file) +{ +struct cyapa *cyapa = inode->i_private; +struct device *dev = &cyapa->client->dev; +int ret, error; + +if (!cyapa) +return -ENODEV ; + + error =mutex_lock_interruptible (&cyapa->debugfs_mutex); +if (error) +return error; + +if (!get_device (dev)) { + error = -ENODEV ; + goto out; + } + + file->private_data = cyapa; + +if (cyapa->fw_image && cyapa->fw_image_size) { + error =0 ; + goto out; + } + + error =mutex_lock_interruptible (&cyapa->state_sync_lock); +if (error) + goto out; + +/* +* If firmware hasn't been read yet, read it all in one pass. +* Subsequent opens will reuse the data in this same buffer. +*/ +if (cyapa->ops->read_fw) { + cyapa->operational = false; +cyapa_enable_irq_for_cmd (cyapa); + error = cyapa->ops->read_fw (cyapa); +cyapa_disable_irq_for_cmd (cyapa); + + ret =cyapa_reinitialize (cyapa); +if (ret) { +dev_err (dev,"failed to redetect after read_fw: %d\n" , + ret); + error = error ? error : ret; + } + }else { + ret = -EPERM ; + } + +mutex_unlock (&cyapa->state_sync_lock); +out: +mutex_unlock (&cyapa->debugfs_mutex); +return error; +} + +static int cyapa_debugfs_release (struct inode *inode,struct file *file) +{ +struct cyapa *cyapa = file->private_data; +int error; + +if (!cyapa) +return 0 ; + + error =mutex_lock_interruptible (&cyapa->debugfs_mutex); +if (error) +return error; + file->private_data =NULL ; +put_device (&cyapa->client->dev); +mutex_unlock (&cyapa->debugfs_mutex); + +return 0 ; +} + +/* Return some bytes from the buffered firmware image, starting from *ppos */ +static ssize_t cyapa_debugfs_read_fw (struct file *file,char __user *buffer, +size_t count,loff_t *ppos) +{ +struct cyapa *cyapa = file->private_data; + +if (!cyapa->fw_image) +return -EINVAL ; + +if (*ppos >= cyapa->fw_image_size) +return 0 ; + +if (count + *ppos > cyapa->fw_image_size) + count = cyapa->fw_image_size - *ppos; + +if (copy_to_user (buffer, &cyapa->fw_image[*ppos], count)) +return -EFAULT ; + + *ppos += count; +return count; +} + +static const struct file_operations cyapa_read_fw_fops = { + .open = cyapa_debugfs_open, + .release = cyapa_debugfs_release, + .read = cyapa_debugfs_read_fw +}; + +static int cyapa_debugfs_init (struct cyapa *cyapa) +{ +struct device *dev = &cyapa->client->dev; + +if (!cyapa_debugfs_root) +return -ENODEV ; + + cyapa->dentry_dev =debugfs_create_dir (kobject_name (&dev->kobj), + cyapa_debugfs_root); + +if (!cyapa->dentry_dev) +return -ENODEV ; + +mutex_init (&cyapa->debugfs_mutex); + +debugfs_create_file (CYAPA_DEBUGFS_READ_FW ,S_IRUSR , cyapa->dentry_dev, + cyapa, &cyapa_read_fw_fops); + +return 0 ; +} + +static void cyapa_remove_debugfs (void *data) +{ +struct cyapa *cyapa = data; + +debugfs_remove_recursive (cyapa->dentry_dev); +mutex_destroy (&cyapa->debugfs_mutex); +} + +/* +************************************************************** * sysfs interface ************************************************************** */
@@ -1156,6 +1296,20 @@ static int cyapa_probe(struct i2c_client *client,return error; } + error =cyapa_debugfs_init (cyapa); +if (error) { +dev_err (dev,"failed to create debugfs entries: %d\n" , error); +return error; + } + + error =devm_add_action (dev, cyapa_remove_debugfs, cyapa); +if (error) { +cyapa_remove_debugfs (cyapa); +dev_err (dev,"failed to add debugfs cleanup action :%d\n" , + error); +return error; + } +#ifdef CONFIG_PM_SLEEP if (device_can_wakeup (dev)) { error = sysfs_merge_group(&client->dev.kobj,
@@ -1336,7 +1490,33 @@ static struct i2c_driver cyapa_driver = { .id_table = cyapa_id_table, }; -module_i2c_driver (cyapa_driver); +static int __init cyapa_init (void ) +{ +int error; + +/* Create a global debugfs root for all cyapa devices */ + cyapa_debugfs_root =debugfs_create_dir ("cyapa" ,NULL ); +if (cyapa_debugfs_root ==ERR_PTR (-ENODEV )) + cyapa_debugfs_root =NULL ; + + error =i2c_add_driver (&cyapa_driver); +if (error) { +pr_err ("cyapa driver register FAILED.\n" ); +return error; + } + +return 0 ; +} + +static void __exit cyapa_exit(void) +{ +debugfs_remove_recursive (cyapa_debugfs_root); + +i2c_del_driver (&cyapa_driver); +} + +module_init (cyapa_init); +module_exit (cyapa_exit);MODULE_DESCRIPTION ("Cypress APA I2C Trackpad Driver" );MODULE_AUTHOR ("Dudley Du <[email protected]>" );
drivers/input/mouse/cyapa.h +10 -0
@@ -186,6 +186,8 @@ struct cyapa_dev_ops {ssize_t (*calibrate_store)(struct device *,struct device_attribute *,const char *,size_t ); +int (*read_fw)(struct cyapa *); +int (*initialize)(struct cyapa *cyapa);int (*state_parse)(struct cyapa *cyapa,u8 *reg_status,int len);
@@ -297,6 +299,14 @@ struct cyapa {*/ struct mutex state_sync_lock; +/* Per-instance debugfs root */ +struct dentry *dentry_dev; + +/* Buffer to store firmware read using debugfs */ +struct mutex debugfs_mutex; +u8 *fw_image; +size_t fw_image_size; +const struct cyapa_dev_ops *ops;union cyapa_cmd_states cmd_states;
Signature · 1 line
1.9.1
PATCH v12 15/19 input: cyapa: add gen3 trackpad device read firmware image function support
In reply to Dudley DuAdd read firmware image function supported for gen3 trackpad device, it can be used through debugfs read_fw interface. TEST=test on Chromebooks.
--- drivers/input/mouse/cyapa_gen3.c | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)
drivers/input/mouse/cyapa_gen3.c +67 -0
@@ -708,6 +708,36 @@ static int cyapa_gen3_write_fw_block(struct cyapa *cyapa,return ret; } +/* +* A firmware block read command reads 16 bytes of data from flash starting +* from a given address. The 12-byte block read command has the format: +* <0xff> <CMD> <Key> <Addr> +* +* <0xff> - every command starts with 0xff +* <CMD> - the read command value is 0x3c +* <Key> - read commands include an 8-byte key: { 00 01 02 03 04 05 06 07 } +* <Addr> - Memory address (16-bit, big-endian) +* +* The command is followed by an i2c block read to read the 16 bytes of data. +*/ +static int cyapa_gen3_read_fw_bytes (struct cyapa *cyapa,u16 addr,u8 *data) +{ +u8 cmd[] = {0xff ,0x3c ,0x00 ,0x01 ,0x02 ,0x03 ,0x04 , +0x05 ,0x06 ,0x07 , addr >>8 , addr }; +int ret, error; + + error =cyapa_gen3_write_buffer (cyapa, cmd,sizeof (cmd)); +if (error) +return error; + +/* Read data buffer starting from offset 16 */ + ret =cyapa_i2c_reg_read_block (cyapa,16 ,CYAPA_FW_READ_SIZE , data); +if (ret !=CYAPA_FW_READ_SIZE ) +return (ret <0 ) ? ret : -EIO ; + +return 0 ; +} +static int cyapa_gen3_write_blocks (struct cyapa *cyapa,size_t start_block,size_t block_count,const u8 *image_data)
@@ -754,6 +784,41 @@ static int cyapa_gen3_do_fw_update(struct cyapa *cyapa,return 0 ; } +/* +* Read the entire firmware image into ->fw_image. +* If the ->fw_image has already been allocated, then this function +* doesn't do anything and just returns 0. +* If an error occurs while reading the image, ->fw_image is freed, and +* the error is returned. +* +* The firmware is a fixed size (CYAPA_FW_SIZE), and is read out in +* fixed length (CYAPA_FW_READ_SIZE) chunks. +*/ +static int cyapa_gen3_read_fw (struct cyapa *cyapa) +{ +int error; +int addr; + + error =cyapa_gen3_bl_enter (cyapa); +if (error) +return error; + + cyapa->fw_image = cyapa->fw_image ? cyapa->fw_image : +devm_kzalloc (&cyapa->client->dev,CYAPA_FW_SIZE ,GFP_KERNEL ); +if (!cyapa->fw_image) +return -ENOMEM ; + +for (addr =0 ; addr <CYAPA_FW_SIZE ; addr +=CYAPA_FW_READ_SIZE ) { + error =cyapa_gen3_read_fw_bytes (cyapa, +CYAPA_FW_HDR_START + addr, &cyapa->fw_image[addr]); +if (error) +return error; + } + + cyapa->fw_image_size =CYAPA_FW_SIZE ; +return 0 ; +} +static ssize_t cyapa_gen3_do_calibrate (struct device *dev,struct device_attribute *attr,const char *buf,size_t count)
@@ -1195,6 +1260,8 @@ const struct cyapa_dev_ops cyapa_gen3_ops = { .show_baseline = cyapa_gen3_show_baseline, .calibrate_store = cyapa_gen3_do_calibrate, + .read_fw = cyapa_gen3_read_fw, + .state_parse = cyapa_gen3_state_parse, .operational_check = cyapa_gen3_do_operational_check,
Signature · 1 line
1.9.1
PATCH v12 16/19 input: cyapa: add gen5 trackpad device read firmware image function support
In reply to Dudley DuAdd read firmware image function supported for gen5 trackpad device, it can be used through debugfs read_fw interface. TEST=test on Chromebooks.
--- drivers/input/mouse/cyapa.h | 1 + drivers/input/mouse/cyapa_gen5.c | 155 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+)
drivers/input/mouse/cyapa.h +1 -0
@@ -304,6 +304,7 @@ struct cyapa {/* Buffer to store firmware read using debugfs */ struct mutex debugfs_mutex; +struct cyapa_tsg_bin_image_head fw_img_head;u8 *fw_image;size_t fw_image_size;
drivers/input/mouse/cyapa_gen5.c +155 -0
173 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v12 17/19 input: cyapa: add read sensors raw data debugfs interface support
In reply to Dudley DuAdd read sensors' raw data from trackpad device interface supported in cyapa driver through debugfs raw_data interface.
Through this interface, user can read difference count map of each sensors directly from trackpad device (some customers want). And it's useful to help users to find out the root cause when there is performance gap happened. TEST=test on Chromebooks.
--- drivers/input/mouse/cyapa.c | 90 +++++++++++++++++++++++++++++++++++++++++++++ drivers/input/mouse/cyapa.h | 4 ++ 2 files changed, 94 insertions(+)
drivers/input/mouse/cyapa.c +90 -0
@@ -34,6 +34,7 @@#define CYAPA_ADAPTER_FUNC_BOTH 3#define CYAPA_DEBUGFS_READ_FW "read_fw" +#define CYAPA_DEBUGFS_RAW_DATA "raw_data"#define CYAPA_FW_NAME "cyapa.bin"const char unique_str[] ="CYTRA" ;
@@ -726,6 +727,91 @@ static const struct file_operations cyapa_read_fw_fops = { .read = cyapa_debugfs_read_fw }; +static int cyapa_debugfs_raw_data_open (struct inode *inode,struct file *file) +{ +struct cyapa *cyapa = inode->i_private; +int error; + +if (!cyapa) +return -ENODEV ; + +/* Start to be supported after Gen5 trackpad devices. */ +if (cyapa->gen <CYAPA_GEN5 ) +return -ENOTSUPP ; + + error =mutex_lock_interruptible (&cyapa->debugfs_mutex); +if (error) +return error; + +if (!get_device (&cyapa->client->dev)) { + error = -ENODEV ; + goto out; + } + + file->private_data = cyapa; + + error =mutex_lock_interruptible (&cyapa->state_sync_lock); +if (error) + goto out; + +if (cyapa->ops->read_raw_data) { +cyapa_enable_irq_for_cmd (cyapa); + error = cyapa->ops->read_raw_data (cyapa); +cyapa_disable_irq_for_cmd (cyapa); + }else { + error = -EPERM ; + } + +mutex_unlock (&cyapa->state_sync_lock); +out: +mutex_unlock (&cyapa->debugfs_mutex); +return error; +} + +static int cyapa_debugfs_raw_data_release (struct inode *inode, +struct file *file) +{ +struct cyapa *cyapa = file->private_data; +int error; + +if (!cyapa) +return 0 ; + + error =mutex_lock_interruptible (&cyapa->debugfs_mutex); +if (error) +return error; + file->private_data =NULL ; +put_device (&cyapa->client->dev); +mutex_unlock (&cyapa->debugfs_mutex); + +return 0 ; +} + +static ssize_t cyapa_debugfs_read_raw_data (struct file *file, +char __user *buffer, +size_t count,loff_t *ppos) +{ +struct cyapa *cyapa = file->private_data; + +if (*ppos >= cyapa->tp_raw_data_size) +return 0 ; + +if (count + *ppos > cyapa->tp_raw_data_size) + count = cyapa->tp_raw_data_size - *ppos; + +if (copy_to_user (buffer, &cyapa->tp_raw_data[*ppos], count)) +return -EFAULT ; + + *ppos += count; +return count; +} + +static const struct file_operations cyapa_read_raw_data_fops = { + .open = cyapa_debugfs_raw_data_open, + .release = cyapa_debugfs_raw_data_release, + .read = cyapa_debugfs_read_raw_data +}; +static int cyapa_debugfs_init (struct cyapa *cyapa) {struct device *dev = &cyapa->client->dev;
@@ -744,6 +830,10 @@ static int cyapa_debugfs_init(struct cyapa *cyapa)debugfs_create_file (CYAPA_DEBUGFS_READ_FW ,S_IRUSR , cyapa->dentry_dev, cyapa, &cyapa_read_fw_fops); +if (cyapa->gen >=CYAPA_GEN5 ) +debugfs_create_file (CYAPA_DEBUGFS_RAW_DATA ,S_IRUSR , + cyapa->dentry_dev, cyapa, &cyapa_read_raw_data_fops); +return 0 ; }
drivers/input/mouse/cyapa.h +4 -0
@@ -187,6 +187,7 @@ struct cyapa_dev_ops { struct device_attribute *, const char *, size_t);int (*read_fw)(struct cyapa *); +int (*read_raw_data)(struct cyapa *);int (*initialize)(struct cyapa *cyapa);
@@ -307,6 +308,9 @@ struct cyapa {struct cyapa_tsg_bin_image_head fw_img_head;u8 *fw_image;size_t fw_image_size; +/* Buffer to store sensors' raw data */ +u8 *tp_raw_data; +size_t tp_raw_data_size;const struct cyapa_dev_ops *ops;
Signature · 1 line
1.9.1
PATCH v12 18/19 input: cyapa: add gen5 trackpad device read raw data function support
In reply to Dudley DuAdd read raw data function supported for gen5 trackpad device, it can be used through debugfs raw_data interface. TEST=test on Chromebooks.
--- drivers/input/mouse/cyapa_gen5.c | 138 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+)
drivers/input/mouse/cyapa_gen5.c +138 -0
@@ -2363,6 +2363,143 @@ resume_scanning:return size; } +static int cyapa_gen5_read_electrodies_rx_tx (struct cyapa *cyapa) +{ +u8 cmd[7 ] = {0x04 ,0x00 ,0x05 ,0x00 ,0x2f ,0x00 ,0x71 }; +u8 resp_data[7 ]; +int resp_len; +int error; + + resp_len =sizeof (resp_data); + error =cyapa_i2c_pip_cmd_irq_sync (cyapa, + cmd,7 , + resp_data, &resp_len, +150 , cyapa_gen5_sort_tsg_pip_app_resp_data, true); +if (error || !VALID_CMD_RESP_HEADER (resp_data,0x71 ) || + !resp_data[5 ] || !resp_data[6 ]) +return -EINVAL ; + + cyapa->electrodes_rx = resp_data[6 ]; + +return 0 ; +} + +static int cyapa_gen5_read_raw_data (struct cyapa *cyapa) +{ +int raw_cap_mutual_max, raw_cap_mutual_min, raw_cap_mutual_ave; +int raw_cap_self_max, raw_cap_self_min, raw_cap_self_ave; +int offset; +int data_size, max, min, ave; +ktime_t time_mono; +int error, resume_error; + + offset =0 ; +if (!cyapa->tp_raw_data) { +if (cyapa->state !=CYAPA_STATE_GEN5_APP || + !cyapa->electrodes_x || !cyapa->electrodes_y) +return -EINVAL ; + + cyapa->tp_raw_data_size =sizeof (s32) * (cyapa->electrodes_x * + cyapa->electrodes_y + cyapa->electrodes_x + + cyapa->electrodes_y) +GEN5_RAW_DATA_HEAD_SIZE ; +/* +* This buffer will be hold after used until the driver is +* unloaded, the purpose of it is to improve the performace +* to avoid frequently allocate and release the buffer. +*/ + cyapa->tp_raw_data =devm_kzalloc (&cyapa->client->dev, + cyapa->tp_raw_data_size,GFP_KERNEL ); +if (!cyapa->tp_raw_data) +return -ENOMEM ; + } + +/* +* 1. Suspend Scanning. +* +* After suspend scanning, the raw data will not be updated, +* so the time of the raw data is before scanning suspended. +*/ + time_mono =ktime_get (); + error =cyapa_gen5_suspend_scanning (cyapa); +if (error) +return error; + +/* 2. Get the correct electrodes_rx number. */ +if (cyapa->electrodes_rx ==0 ) { + error =cyapa_gen5_read_electrodies_rx_tx (cyapa); +if (error || cyapa->electrodes_rx ==0 ) { +cyapa_empty_pip_output_data (cyapa,NULL ,NULL ,NULL ); + +/* +* Since, old firmware doesn't support the command to +* read the electrodies' Rx and Tx values, so using +* the read global idac interface to get the Rx number, +* this value is useful to analyze and +* display the raw data map in userspace. +*/ + data_size =0 ; + error =cyapa_gen5_read_idac_data (cyapa, +GEN5_CMD_RETRIEVE_DATA_STRUCTURE , +GEN5_RETRIEVE_MUTUAL_PWC_DATA , + &data_size, &max, &min, &ave); +if (error || cyapa->electrodes_rx ==0 ) + goto resume_scanning; + } + } + +/* 3. Execuate panel scan. It must be executed before read data. */ + error =cyapa_gen5_execute_panel_scan (cyapa); +if (error) + goto resume_scanning; + +/* 4. Retrieve panel scan, mutual cap raw data. */ + offset =GEN5_RAW_DATA_HEAD_SIZE ; + error =cyapa_gen5_read_panel_scan_raw_data (cyapa, +GEN5_CMD_RETRIEVE_PANEL_SCAN , +GEN5_PANEL_SCAN_MUTUAL_DIFFCOUNT , + cyapa->electrodes_x * cyapa->electrodes_y, + &raw_cap_mutual_max, &raw_cap_mutual_min, + &raw_cap_mutual_ave, + cyapa->tp_raw_data + offset); +if (error) + goto resume_scanning; + + offset +=sizeof (s32) * cyapa->electrodes_x * cyapa->electrodes_y; + +/* 5. Retrieve panel scan, self cap raw data. */ + error =cyapa_gen5_read_panel_scan_raw_data (cyapa, +GEN5_CMD_RETRIEVE_PANEL_SCAN , +GEN5_PANEL_SCAN_SELF_DIFFCOUNT , + cyapa->electrodes_x + cyapa->electrodes_y, + &raw_cap_self_max, &raw_cap_self_min, + &raw_cap_self_ave, + cyapa->tp_raw_data + offset); +if (error) + goto resume_scanning; + + offset +=sizeof (s32) * (cyapa->electrodes_x + cyapa->electrodes_y); + +resume_scanning: +/* 6. Resume Scanning*/ + resume_error =cyapa_gen5_resume_scanning (cyapa); +if (resume_error || error) +return resume_error ? resume_error : error; + + *((struct timeval *)&cyapa->tp_raw_data[0 ]) = +ktime_to_timeval (time_mono); + cyapa->tp_raw_data[16 ] = (u8 )cyapa->electrodes_x; + cyapa->tp_raw_data[17 ] = (u8 )cyapa->electrodes_y; + cyapa->tp_raw_data[18 ] = (u8 )cyapa->x_origin; + cyapa->tp_raw_data[19 ] = (u8 )cyapa->y_origin; + cyapa->tp_raw_data[20 ] = (u8 )sizeof (s32); + cyapa->tp_raw_data[21 ] = (u8 )sizeof (s32); + cyapa->tp_raw_data[22 ] = (u8 )cyapa->electrodes_rx; + cyapa->tp_raw_data[23 ] =0 ;/* Reserved. */ + + cyapa->tp_raw_data_size = offset; +return 0 ; +} +static bool cyapa_gen5_sort_system_info_data (struct cyapa *cyapa,u8 *buf,int len) {
@@ -2777,6 +2914,7 @@ const struct cyapa_dev_ops cyapa_gen5_ops = { .calibrate_store = cyapa_gen5_do_calibrate, .read_fw = cyapa_gen5_read_fw, + .read_raw_data = cyapa_gen5_read_raw_data, .initialize = cyapa_gen5_initialize,
Signature · 1 line
1.9.1
PATCH v12 19/19 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
@@ -25,6 +25,7 @@#include <linux/slab.h> #include <linux/uaccess.h> #include <linux/pm_runtime.h> +#include <linux/acpi.h> #include "cyapa.h"
@@ -1569,11 +1570,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