input: Synaptics RMI4 Touchscreen Driver
Subsystems (2)
cover input: Synaptics RMI4 Touchscreen Driver
This patch implements a driver supporting Synaptics ClearPad and other touchscreen sensors that use the RMI4 protocol, as defined here:
http://www.synaptics.com/sites/default/files/511-000136-01-Rev-E-RMI4%20Intrfacing%20Guide.pdf
as well as successor documents that haven't made their way through to publication yet.
This code supersedes the patch submitted on 2012-08-17. For all files included in this patch, we believe that all outstanding issues arising from the previous submissions have been addressed, except for looking into using irq_chip to manage chip interrupt dispatch - was passed on that mainly to limit the amount of major structural change since the previous patch. We will continue to pursue the irq_chip request, however.
Also, at the request of several maintainers, we have reduced the number of files included in this patch. Hopefully this is much less of a patch bomb (perhaps just a patch firecracker). The files provided are sufficient to fully drive an RMI4 2D sensor, handling full multifinger reporting and device and power management.
This patch is against the v3.6 tag of Linus' kernel tree, commit a0d271cbfed1dd50278c6b06bead3d00ba0a88f9. It should work fine with kernels back to 3.1.
Included in this patch are:
- full support for an RMI virtual bus as a standard kernel bus
- physical layer implementation for I2C
- device driver for general RMI4 sensor functionality
- function implementations for the following RMI4 functions:
* F01 device control
* F11 multifinger pointing
The driver supports a system having one or more RMI sensors attached to it. Most devices have just a single touch sensor, but some have more than one. An example is the Fuse concept phone, which has 4 RMI sensors in it.
Each sensor is presented as a device on the RMI logical bus (/sys/bus/rmi). Devices are named/numbered in the order they are discovered on the bus, starting with /sys/bus/rmi/devices/sensor00 for the first once, .../sensor01 for the second one, and so on.
Individual RMI functions are presented as child devices of the sensor device. For example, sensor00.fn01, sensor00.fn11, and so on. Control of an RMI function's operating parameters is implemented via sysfs or debugfs (depending on whether the parameters are used during normal operation or system development/prototyping).
The amount of feedback received on previous patches precludes addressing each item individually. However, major changes for this patch are:
- elimination of ad-hoc bus matching/binding and reliance on standard bus implementation.
- elimination of out-of-tree features such as EARLY_SUSPEND
- use of devm_kzalloc where appropriate
- partition of control parameters between sysfs and debugfs
- simplified configuration and control of debugging related features
- IRQ management consolidated in once place
We've broken this patch into 6 parts, as follows:
01 - public header files and documentation
02 - core sensor and bus implementation
03 - I2C physical layer driver
04 - Kconfigs and Makefiles
05..06 - drivers for individual RMI functions
Comments and other feedback on this driver are welcomed.
Christopher Heiny and the Synaptics RMI4 driver team
---
RFC PATCH 2/6 input/rmi4: Core files
rmi_bus.c implements the basic functionality of the RMI bus. This file is greatly simplified compared to the previous patch - we've switched from "do it yourself" device/driver binding to using device_type to distinguish between the two kinds of devices on the bus (sensor devices and function specific devices) and using the standard bus implementation to manage devices and drivers.
rmi_driver.c is a driver for the general functionality of the RMI sensor as a whole, managing those behaviors not specific to any RMI4 function. This file is also greatly simplified, mainly for the same reasons as rmi_bus.c was.
The rmi_driver.c implementation has been significantly decoupled from the F01 implementation, although it's unlikely that the dependencies on F01 can be eliminated completely. Special dependencies from F01 back to rmi_driver.c have been eliminated, though (see notes on rmi_f01.c for details).
IRQ management has been shifted from the physical layer into rmi_driver.c. This simplifies the code and eliminates a bug where unserviced IRQs would significantly impede the boot process.
One request from previously that we did not address with this patch is using irq_chip to dispatch the attention IRQs to the various functions. We felt that with the major overhaul of the bus structure, there was enough to consider with the current changes. We're currently investigating the use of irq_chip - the request hasn't been forgotten.
The header file rmi_driver.h provides definitions that are shared among the modules of the RMI implementation, but not thought to be necessary outside it.
---
drivers/input/rmi4/rmi_bus.c | 231 ++++++ drivers/input/rmi4/rmi_driver.c | 1529 +++++++++++++++++++++++++++++++++++++++ drivers/input/rmi4/rmi_driver.h | 438 +++++++++++ 3 files changed, 2198 insertions(+), 0 deletions(-)
drivers/input/rmi4/rmi_bus.c new file +231 -0
@@ -0,0 +1,231 @@ +/* +* Copyright (c) 2011, 2012 Synaptics Incorporated +* Copyright (c) 2011 Unixphere +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include <linux/kernel.h> +#include <linux/device.h> +#include <linux/kconfig.h> +#include <linux/list.h> +#include <linux/pm.h> +#include <linux/rmi.h> +#include <linux/slab.h> +#include <linux/types.h> +#ifdef CONFIG_RMI4_DEBUG +#include <linux/debugfs.h> +#endif +#include "rmi_driver.h" + +DEFINE_MUTEX (rmi_bus_mutex); + +static struct attribute *function_dev_attrs[] = { +NULL , +}; + +static struct attribute_group function_dev_attr_group = { + .attrs = function_dev_attrs, +}; + +static struct attribute_group *function_dev_attr_groups[] = { + &function_dev_attr_group, +NULL , +}; + +struct device_type rmi_function_type = { + .name ="rmi_function" , + .groups = function_dev_attr_groups, +}; +EXPORT_SYMBOL_GPL (rmi_function_type); + +static struct attribute *sensor_dev_attrs[] = { +NULL , +}; +static struct attribute_group sensor_dev_attr_group = { + .attrs = sensor_dev_attrs, +}; + +static struct attribute_group *sensor_dev_attr_groups[] = { + &sensor_dev_attr_group, +NULL , +}; + +struct device_type rmi_sensor_type = { + .name ="rmi_sensor" , + .groups = sensor_dev_attr_groups, +}; +EXPORT_SYMBOL_GPL (rmi_sensor_type); + +static atomic_t physical_device_count =ATOMIC_INIT (0 ); + +#ifdef CONFIG_RMI4_DEBUG +static struct dentry *rmi_debugfs_root; +#endif + +#ifdef CONFIG_PM +static int rmi_bus_suspend (struct device *dev) +{ +struct device_driver *driver = dev->driver; +const struct dev_pm_ops *pm; + +if (!driver) +return 0 ; + + pm = driver->pm; +if (pm && pm->suspend) +return pm->suspend (dev); +if (driver->suspend) +return driver->suspend (dev,PMSG_SUSPEND ); + +return 0 ; +} + +static int rmi_bus_resume (struct device *dev) +{ +struct device_driver *driver = dev->driver; +const struct dev_pm_ops *pm; + +if (!driver) +return 0 ; + + pm = driver->pm; +if (pm && pm->resume) +return pm->resume (dev); +if (driver->resume) +return driver->resume (dev); + +return 0 ; +} +#endif + +static SIMPLE_DEV_PM_OPS(rmi_bus_pm_ops, + rmi_bus_suspend, rmi_bus_resume); + +struct bus_type rmi_bus_type = { + .name ="rmi" , + .pm = &rmi_bus_pm_ops +}; +EXPORT_SYMBOL_GPL (rmi_bus_type); + +static void release_rmidev_device (struct device *dev) +{ +device_unregister (dev); +} + +int rmi_register_phys_device (struct rmi_phys_device *phys) +{ +struct rmi_device_platform_data *pdata = phys->dev->platform_data; +struct rmi_device *rmi_dev; + +if (!pdata) { +dev_err (phys->dev,"no platform data!\n" ); +return -EINVAL ; + } + + rmi_dev =kzalloc (sizeof (struct rmi_device ),GFP_KERNEL ); +if (!rmi_dev) +return -ENOMEM ; + + rmi_dev->phys = phys; + rmi_dev->dev.bus = &rmi_bus_type; + rmi_dev->dev.type = &rmi_sensor_type; + + rmi_dev->number =atomic_inc_return (&physical_device_count) -1 ; + rmi_dev->dev.release = release_rmidev_device; + +dev_set_name (&rmi_dev->dev,"sensor%02d" , rmi_dev->number); +dev_dbg (phys->dev,"%s: Registered %s as %s.\n" , __func__, + pdata->sensor_name,dev_name (&rmi_dev->dev)); + +if (IS_ENABLED (CONFIG_RMI4_DEBUG ) && rmi_debugfs_root) { + rmi_dev->debugfs_root =debugfs_create_dir ( +dev_name (&rmi_dev->dev), rmi_debugfs_root); +if (!rmi_dev->debugfs_root) +dev_err (&rmi_dev->dev,"Failed to create debugfs root.\n" ); + } + + phys->rmi_dev = rmi_dev; +return device_register (&rmi_dev->dev); +} +EXPORT_SYMBOL (rmi_register_phys_device); + +void rmi_unregister_phys_device (struct rmi_phys_device *phys) +{ +struct rmi_device *rmi_dev = phys->rmi_dev; + +if (IS_ENABLED (CONFIG_RMI4_DEBUG ) && rmi_dev->debugfs_root) +debugfs_remove (rmi_dev->debugfs_root); + +kfree (rmi_dev); +} +EXPORT_SYMBOL (rmi_unregister_phys_device); + +int rmi_for_each_dev (void *data,int (*func)(struct device *dev,void *data)) +{ +int retval; +mutex_lock (&rmi_bus_mutex); + retval =bus_for_each_dev (&rmi_bus_type,NULL , data, func); +mutex_unlock (&rmi_bus_mutex); +return retval; +} +EXPORT_SYMBOL_GPL (rmi_for_each_dev); + +static int __init rmi_bus_init (void ) +{ +int error; + +mutex_init (&rmi_bus_mutex); + +if (IS_ENABLED (CONFIG_RMI4_DEBUG )) { + rmi_debugfs_root =debugfs_create_dir (rmi_bus_type.name,NULL ); +if (!rmi_debugfs_root) +pr_err ("%s: Failed to create debugfs root.\n" , + __func__); +else if (IS_ERR (rmi_debugfs_root)) { +pr_err ("%s: Kernel may not contain debugfs support, code=%ld\n" , + __func__,PTR_ERR (rmi_debugfs_root)); + rmi_debugfs_root =NULL ; + } + } + + error =bus_register (&rmi_bus_type); +if (error <0 ) { +pr_err ("%s: error registering the RMI bus: %d\n" , __func__, + error); +return error; + } +pr_debug ("%s: successfully registered RMI bus.\n" , __func__); + +return 0 ; +} + +static void __exit rmi_bus_exit(void) +{ +/* We should only ever get here if all drivers are unloaded, so +* all we have to do at this point is unregister ourselves. +*/ +if (IS_ENABLED (CONFIG_RMI4_DEBUG ) && rmi_debugfs_root) +debugfs_remove (rmi_debugfs_root); +bus_unregister (&rmi_bus_type); +} + +module_init (rmi_bus_init); +module_exit (rmi_bus_exit); + +MODULE_AUTHOR ("Christopher Heiny <[email protected]" ); +MODULE_DESCRIPTION ("RMI bus" ); +MODULE_LICENSE ("GPL" ); +MODULE_VERSION (RMI_DRIVER_VERSION );
drivers/input/rmi4/rmi_driver.c new file +1529 -0
1,529 lines not on this page · raw message
drivers/input/rmi4/rmi_driver.h new file +438 -0
438 lines not on this page · raw message
RFC PATCH 3/6 input/rmi4: I2C physical interface
In reply to Christopher HeinyThe I2C physical driver is not extensively changed in terms of functionality since the previous patch. Management of the attention GPIO has been moved to rmi_driver.c (see previous email), and most of the debug related interfaces have been moved from sysfs to debugfs. Control of the debug features has been moved from compile-time to runtime switches available via debugfs.
The core I2C functionality was previously ACKed by Jean Delvare. I don't believe that portion of the code has changed much since then, but we'd appreciate a second glance at this.
---
drivers/input/rmi4/rmi_i2c.c | 455 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 455 insertions(+), 0 deletions(-)
drivers/input/rmi4/rmi_i2c.c new file +455 -0
@@ -0,0 +1,455 @@ +/* +* Copyright (c) 2011, 2012 Synaptics Incorporated +* Copyright (c) 2011 Unixphere +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include <linux/kernel.h> +#include <linux/delay.h> +#include <linux/gpio.h> +#include <linux/i2c.h> +#include <linux/interrupt.h> +#include <linux/kconfig.h> +#include <linux/lockdep.h> +#include <linux/module.h> +#include <linux/pm.h> +#include <linux/rmi.h> +#include <linux/slab.h> +#include "rmi_driver.h" + +struct rmi_i2c_data { +struct mutex page_mutex; +int page; +struct rmi_phys_device *phys; + +bool comms_debug; +#ifdef CONFIG_RMI4_DEBUG +struct dentry *debugfs_comms; +#endif +}; + +#ifdef CONFIG_RMI4_DEBUG + +#include <linux/debugfs.h> +#include <linux/uaccess.h> + +static int setup_debugfs (struct rmi_device *rmi_dev,struct rmi_i2c_data *data); +static void teardown_debugfs (struct rmi_i2c_data *data); + +struct i2c_debugfs_data { +bool done; +struct rmi_i2c_data *i2c_data; +}; + +static int debug_open (struct inode *inodep,struct file *filp) +{ +struct i2c_debugfs_data *data; + + data =kzalloc (sizeof (struct i2c_debugfs_data ),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + data->i2c_data = inodep->i_private; + filp->private_data = data; +return 0 ; +} + +static int debug_release (struct inode *inodep,struct file *filp) +{ +kfree (filp->private_data); +return 0 ; +} + +static ssize_t comms_debug_read (struct file *filp,char __user *buffer, +size_t size,loff_t *offset) { +int retval; +char local_buf[size]; +struct i2c_debugfs_data *dfs = filp->private_data; +struct rmi_i2c_data *data = dfs->i2c_data; + +if (dfs->done) +return 0 ; + + dfs->done =1 ; + + retval =snprintf (local_buf,PAGE_SIZE ,"%u\n" , data->comms_debug); + +if (retval <=0 ||copy_to_user (buffer, local_buf, retval)) +return -EFAULT ; + +return retval; +} + +static ssize_t comms_debug_write (struct file *filp,const char __user *buffer, +size_t size,loff_t *offset) { +int retval; +char local_buf[size]; +unsigned int new_value; +struct i2c_debugfs_data *dfs = filp->private_data; +struct rmi_i2c_data *data = dfs->i2c_data; + + retval =copy_from_user (local_buf, buffer, size); +if (retval) +return -EFAULT ; + + retval =sscanf (local_buf,"%u" , &new_value); +if (retval !=1 || new_value >1 ) +return -EINVAL ; + + data->comms_debug = new_value; + +return size; +} + + +static const struct file_operations comms_debug_fops = { + .owner =THIS_MODULE , + .open = debug_open, + .release = debug_release, + .read = comms_debug_read, + .write = comms_debug_write, +}; + +static int setup_debugfs (struct rmi_device *rmi_dev,struct rmi_i2c_data *data) +{ +if (!rmi_dev->debugfs_root) +return -ENODEV ; + + data->debugfs_comms =debugfs_create_file ("comms_debug" ,RMI_RW_ATTR , + rmi_dev->debugfs_root, data, &comms_debug_fops); +if (!data->debugfs_comms ||IS_ERR (data->debugfs_comms)) { +dev_warn (&rmi_dev->dev,"Failed to create debugfs comms_debug.\n" ); + data->debugfs_comms =NULL ; + } + +return 0 ; +} + +static void teardown_debugfs (struct rmi_i2c_data *data) +{ +if (data->debugfs_comms) +debugfs_remove (data->debugfs_comms); +} +#endif + +#define COMMS_DEBUG (data) (IS_ENABLED(CONFIG_RMI4_DEBUG) && data->comms_debug) + +#define RMI_PAGE_SELECT_REGISTER 0xff +#define RMI_I2C_PAGE (addr) (((addr) >> 8) & 0xff) + +static char *phys_proto_name ="i2c" ; + +/* +* rmi_set_page - Set RMI page +* @phys: The pointer to the rmi_phys_device struct +* @page: The new page address. +* +* RMI devices have 16-bit addressing, but some of the physical +* implementations (like SMBus) only have 8-bit addressing. So RMI implements +* a page address at 0xff of every page so we can reliable page addresses +* every 256 registers. +* +* The page_mutex lock must be held when this function is entered. +* +* Returns zero on success, non-zero on failure. +*/ +static int rmi_set_page (struct rmi_phys_device *phys,u8 page) +{ +struct i2c_client *client =to_i2c_client (phys->dev); +struct rmi_i2c_data *data = phys->data; +u8 txbuf[2 ] = {RMI_PAGE_SELECT_REGISTER , page}; +int retval; + +if (COMMS_DEBUG (data)) +dev_dbg (&client->dev,"writes 3 bytes: %02x %02x\n" , + txbuf[0 ], txbuf[1 ]); + phys->info.tx_count++; + phys->info.tx_bytes +=sizeof (txbuf); + retval =i2c_master_send (client, txbuf,sizeof (txbuf)); +if (retval !=sizeof (txbuf)) { + phys->info.tx_errs++; +dev_err (&client->dev, +"%s: set page failed: %d." , __func__, retval); +return (retval <0 ) ? retval : -EIO ; + } + data->page = page; +return 0 ; +} + +static int rmi_i2c_write_block (struct rmi_phys_device *phys,u16 addr,u8 *buf, +int len) +{ +struct i2c_client *client =to_i2c_client (phys->dev); +struct rmi_i2c_data *data = phys->data; +u8 txbuf[len +1 ]; +int retval; + + txbuf[0 ] = addr &0xff ; +memcpy (txbuf +1 , buf, len); + +mutex_lock (&data->page_mutex); + +if (RMI_I2C_PAGE (addr) != data->page) { + retval =rmi_set_page (phys,RMI_I2C_PAGE (addr)); +if (retval <0 ) + goto exit; + } + +if (COMMS_DEBUG (data)) { +char debug_buf[len*3 +1 ]; +int i; +int n =0 ; +char *temp = debug_buf; + +for (i =0 ; i < len; i++) { + n =sprintf (temp," %02x" , buf[i]); + temp += n; + } +dev_dbg (&client->dev,"writes %d bytes at %#06x:%s\n" , + len, addr, debug_buf); + } + + phys->info.tx_count++; + phys->info.tx_bytes +=sizeof (txbuf); + retval =i2c_master_send (client, txbuf,sizeof (txbuf)); +if (retval <0 ) + phys->info.tx_errs++; +else + retval--;/* don't count the address byte */ + +exit: +mutex_unlock (&data->page_mutex); +return retval; +} + + +static int rmi_i2c_read_block (struct rmi_phys_device *phys,u16 addr,u8 *buf, +int len) +{ +struct i2c_client *client =to_i2c_client (phys->dev); +struct rmi_i2c_data *data = phys->data; +u8 txbuf[1 ] = {addr &0xff }; +int retval; + +mutex_lock (&data->page_mutex); + +if (RMI_I2C_PAGE (addr) != data->page) { + retval =rmi_set_page (phys,RMI_I2C_PAGE (addr)); +if (retval <0 ) + goto exit; + } + +if (COMMS_DEBUG (data)) +dev_dbg (&client->dev,"writes 1 bytes: %02x\n" , txbuf[0 ]); + + phys->info.tx_count++; + phys->info.tx_bytes +=sizeof (txbuf); + retval =i2c_master_send (client, txbuf,sizeof (txbuf)); +if (retval !=sizeof (txbuf)) { + phys->info.tx_errs++; + retval = (retval <0 ) ? retval : -EIO ; + goto exit; + } + + retval =i2c_master_recv (client, buf, len); + + phys->info.rx_count++; + phys->info.rx_bytes += len; +if (retval <0 ) + phys->info.rx_errs++; +else if (COMMS_DEBUG (data)) { +char debug_buf[len*3 +1 ]; +char *temp = debug_buf; +int i; +int n =0 ; + +for (i =0 ; i < len; i++) { + n =sprintf (temp," %02x" , buf[i]); + temp += n; + } +dev_dbg (&client->dev,"read %d bytes at %#06x:%s\n" , + len, addr, debug_buf); + } + +exit: +mutex_unlock (&data->page_mutex); +return retval; +} + +static int __devinit rmi_i2c_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +struct rmi_phys_device *rmi_phys; +struct rmi_i2c_data *data; +struct rmi_device_platform_data *pdata = client->dev.platform_data; +int retval; + +if (!pdata) { +dev_err (&client->dev,"no platform data\n" ); +return -EINVAL ; + } +dev_info (&client->dev,"Probing %s at %#02x (IRQ %d).\n" , + pdata->sensor_name ? pdata->sensor_name :"-no name-" , + client->addr, pdata->attn_gpio); + +if (pdata->gpio_config) { +dev_info (&client->dev,"Configuring GPIOs.\n" ); + retval = pdata->gpio_config (pdata->gpio_data, true); +if (retval <0 ) { +dev_err (&client->dev,"Failed to configure GPIOs, code: %d.\n" , + retval); +return retval; + } +dev_info (&client->dev,"Done with GPIO configuration.\n" ); + } + + retval =i2c_check_functionality (client->adapter,I2C_FUNC_I2C ); +if (!retval) { +dev_err (&client->dev,"i2c_check_functionality error %d.\n" , + retval); +return retval; + } + + rmi_phys =kzalloc (sizeof (struct rmi_phys_device ),GFP_KERNEL ); +if (!rmi_phys) +return -ENOMEM ; + + data =kzalloc (sizeof (struct rmi_i2c_data ),GFP_KERNEL ); +if (!data) { + retval = -ENOMEM ; + goto err_phys; + } + + data->phys = rmi_phys; + + rmi_phys->data = data; + rmi_phys->dev = &client->dev; + + rmi_phys->write_block = rmi_i2c_write_block; + rmi_phys->read_block = rmi_i2c_read_block; + rmi_phys->info.proto = phys_proto_name; + +mutex_init (&data->page_mutex); + +/* Setting the page to zero will (a) make sure the PSR is in a +* known state, and (b) make sure we can talk to the device. +*/ + retval =rmi_set_page (rmi_phys,0 ); +if (retval) { +dev_err (&client->dev,"Failed to set page select to 0.\n" ); + goto err_data; + } + + retval =rmi_register_phys_device (rmi_phys); +if (retval) { +dev_err (&client->dev, +"failed to register physical driver at 0x%.2X.\n" , + client->addr); + goto err_gpio; + } +i2c_set_clientdata (client, rmi_phys); + +if (IS_ENABLED (CONFIG_RMI4_DEBUG )) + retval =setup_debugfs (rmi_phys->rmi_dev, data); + +if (IS_ENABLED (CONFIG_RMI4_DEV )) { + retval =gpio_export (pdata->attn_gpio, false); +if (retval) { +dev_warn (&client->dev, +"WARNING: Failed to export ATTN gpio!\n" ); + retval =0 ; + }else { + retval =gpio_export_link (&client->dev, +"attn" , pdata->attn_gpio); +if (retval) { +dev_warn (&client->dev, +"WARNING: Failed to symlink ATTN gpio!\n" ); + retval =0 ; + }else { +dev_info (&client->dev,"Exported ATTN GPIO %d." , + pdata->attn_gpio); + } + } + } + +dev_info (&client->dev,"registered rmi i2c driver at %#04x.\n" , + client->addr); +return 0 ; + +err_gpio: +if (pdata->gpio_config) + pdata->gpio_config (pdata->gpio_data, false); +err_data: +kfree (data); +err_phys: +kfree (rmi_phys); +return retval; +} + +static int __devexit rmi_i2c_remove(struct i2c_client *client) +{ +struct rmi_phys_device *phys =i2c_get_clientdata (client); +struct rmi_device_platform_data *pd = client->dev.platform_data; + +/* Can I remove this disable_device */ +/*disable_device(phys); */ + +if (IS_ENABLED (CONFIG_RMI4_DEBUG )) +teardown_debugfs (phys->data); + +rmi_unregister_phys_device (phys); +kfree (phys->data); +kfree (phys); + +if (pd->gpio_config) + pd->gpio_config (&pd->gpio_data, false); + +return 0 ; +} + +static const struct i2c_device_id rmi_id[] = { + {"rmi_i2c" ,0 }, + { } +}; +MODULE_DEVICE_TABLE (i2c, rmi_id); + +static struct i2c_driver rmi_i2c_driver = { + .driver = { + .owner =THIS_MODULE , + .name ="rmi_i2c" + }, + .id_table = rmi_id, + .probe = rmi_i2c_probe, + .remove =__devexit_p (rmi_i2c_remove), +}; + +static int __init rmi_i2c_init (void ) +{ +return i2c_add_driver (&rmi_i2c_driver); +} + +static void __exit rmi_i2c_exit(void) +{ +i2c_del_driver (&rmi_i2c_driver); +} + +module_init (rmi_i2c_init); +module_exit (rmi_i2c_exit); + +MODULE_AUTHOR ("Christopher Heiny <[email protected]>" ); +MODULE_DESCRIPTION ("RMI I2C driver" ); +MODULE_LICENSE ("GPL" ); +MODULE_VERSION (RMI_DRIVER_VERSION );
RFC PATCH 5/6 input/rmi4: F01 - device control
In reply to Christopher HeinyRMI Function 01 implements basic device control and power management behaviors for the RMI4 sensor. Since the last patch, we've decoupled rmi_f01.c implementation from rmi_driver.c, so rmi_f01.c acts as a standard driver module to handle F01 devices on the RMI bus.
Like other modules, a number of attributes have been moved from sysfs to debugfs, depending on their expected use.
rmi_f01.h exports definitions that we expect to be used by other functionality in the future (such as firmware reflash).
---
drivers/input/rmi4/rmi_f01.c | 1463 ++++++++++++++++++++++++++++++++++++++++++ drivers/input/rmi4/rmi_f01.h | 136 ++++ 2 files changed, 1599 insertions(+), 0 deletions(-)
drivers/input/rmi4/rmi_f01.c new file +1463 -0
@@ -0,0 +1,1463 @@ +/* +* Copyright (c) 2011-2012 Synaptics Incorporated +* Copyright (c) 2011 Unixphere +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include <linux/kernel.h> +#include <linux/debugfs.h> +#include <linux/kconfig.h> +#include <linux/rmi.h> +#include <linux/slab.h> +#include <linux/uaccess.h> +#include "rmi_driver.h" +#include "rmi_f01.h" + +/** +* @reset - set this bit to force a firmware reset of the sensor. +*/ +union f01_device_commands { +struct { +bool reset:1 ; +u8 reserved:7 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +/** +* @ctrl0 - see documentation in rmi_f01.h. +* @interrupt_enable - A mask of per-function interrupts on the touch sensor. +* @doze_interval - controls the interval between checks for finger presence +* when the touch sensor is in doze mode, in units of 10ms. +* @wakeup_threshold - controls the capacitance threshold at which the touch +* sensor will decide to wake up from that low power state. +* @doze_holdoff - controls how long the touch sensor waits after the last +* finger lifts before entering the doze state, in units of 100ms. +*/ +struct f01_device_control { +union f01_device_control_0 ctrl0; +u8 *interrupt_enable; +u8 doze_interval; +u8 wakeup_threshold; +u8 doze_holdoff; +}; + +/** +* @has_ds4_queries - if true, the query registers relating to Design Studio 4 +* features are present. +* @has_multi_phy - if true, multiple physical communications interfaces are +* supported. +* @has_guest - if true, a "guest" device is supported. +*/ +union f01_query_42 { +struct { +bool has_ds4_queries:1 ; +bool has_multi_phy:1 ; +bool has_guest:1 ; +u8 reserved:5 ; + } __attribute__((__packed__ )); +u8 regs[1 ]; +}; + +/** +* @length - the length of the remaining Query43.* register block, not +* including the first register. +* @has_package_id_query - the package ID query data will be accessible from +* inside the ProductID query registers. +* @has_packrat_query - the packrat query data will be accessible from inside +* the ProductID query registers. +* @has_reset_query - the reset pin related registers are valid. +* @has_maskrev_query - the silicon mask revision number will be reported. +* @has_i2c_control - the register F01_RMI_Ctrl6 will exist. +* @has_spi_control - the register F01_RMI_Ctrl7 will exist. +* @has_attn_control - the register F01_RMI_Ctrl8 will exist. +* @reset_enabled - the hardware reset pin functionality has been enabled +* for this device. +* @reset_polarity - If this bit reports as ‘0’, it means that the reset state +* is active low. A ‘1’ means that the reset state is active high. +* @pullup_enabled - If set, it indicates that a built-in weak pull up has +* been enabled on the Reset pin; clear means that no pull-up is present. +* @reset_pin_number - This field represents which GPIO pin number has been +* assigned the reset functionality. +*/ +union f01_ds4_queries { +struct { +u8 length:4 ; +u8 reserved_1:4 ; + +bool has_package_id_query:1 ; +bool has_packrat_query:1 ; +bool has_reset_query:1 ; +bool has_maskrev_query:1 ; +u8 reserved_2:4 ; + +bool has_i2c_control:1 ; +bool has_spi_control:1 ; +bool has_attn_control:1 ; +u8 reserved_3:5 ; + +bool reset_enabled:1 ; +bool reset_polarity:1 ; +bool pullup_enabled:1 ; +u8 reserved_4:1 ; +u8 reset_pin_number:4 ; + } __attribute__((__packed__ )); +u8 regs[4 ]; +}; + +struct f01_data { +struct f01_device_control device_control; +union f01_basic_queries basic_queries; +union f01_device_status device_status; +u8 product_id[RMI_PRODUCT_ID_LENGTH +1 ]; + +u16 interrupt_enable_addr; +u16 doze_interval_addr; +u16 wakeup_threshold_addr; +u16 doze_holdoff_addr; + +int irq_count; +int num_of_irq_regs; + +#ifdef CONFIG_PM +bool suspended; +bool old_nosleep; +#endif + +#ifdef CONFIG_RMI4_DEBUG +struct dentry *debugfs_interrupt_enable; +#endif +}; + +#ifdef CONFIG_RMI4_DEBUG +struct f01_debugfs_data { +bool done; +struct rmi_function_container *fc; +}; + +static int f01_debug_open (struct inode *inodep,struct file *filp) +{ +struct f01_debugfs_data *data; +struct rmi_function_container *fc = inodep->i_private; + + data =devm_kzalloc (&fc->dev,sizeof (struct f01_debugfs_data ), +GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + data->fc = fc; + filp->private_data = data; +return 0 ; +} + +static ssize_t interrupt_enable_read (struct file *filp,char __user *buffer, +size_t size,loff_t *offset) { +int i; +int len; +int total_len =0 ; +char local_buf[size]; +char *current_buf = local_buf; +struct f01_debugfs_data *data = filp->private_data; +struct f01_data *f01 = data->fc->data; + +if (data->done) +return 0 ; + + data->done =1 ; + +/* loop through each irq value and copy its +* string representation into buf */ +for (i =0 ; i < f01->irq_count; i++) { +int irq_reg; +int irq_shift; +int interrupt_enable; + + irq_reg = i /8 ; + irq_shift = i %8 ; + interrupt_enable = + ((f01->device_control.interrupt_enable[irq_reg] + >> irq_shift) &0x01 ); + +/* get next irq value and write it to buf */ + len =snprintf (current_buf, size - total_len, +"%u " , interrupt_enable); +/* bump up ptr to next location in buf if the +* snprintf was valid. Otherwise issue an error +* and return. */ +if (len >0 ) { + current_buf += len; + total_len += len; + }else { +dev_err (&data->fc->dev,"Failed to build interrupt_enable buffer, code = %d.\n" , + len); +return snprintf (local_buf, size,"unknown\n" ); + } + } + len =snprintf (current_buf, size - total_len,"\n" ); +if (len >0 ) + total_len += len; +else +dev_warn (&data->fc->dev,"%s: Failed to append carriage return.\n" , + __func__); + +if (copy_to_user (buffer, local_buf, total_len)) +return -EFAULT ; + +return total_len; +} + +static ssize_t interrupt_enable_write (struct file *filp, +const char __user *buffer,size_t size,loff_t *offset) { +int retval; +char buf[size]; +char *local_buf = buf; +int i; +int irq_count =0 ; +int irq_reg =0 ; +struct f01_debugfs_data *data = filp->private_data; +struct f01_data *f01 = data->fc->data; + + retval =copy_from_user (buf, buffer, size); +if (retval) +return -EFAULT ; + +for (i =0 ; i < f01->irq_count && *local_buf !=0 ; + i++, local_buf +=2 ) { +int irq_shift; +int interrupt_enable; +int result; + + irq_reg = i /8 ; + irq_shift = i %8 ; + +/* get next interrupt mapping value and store and bump up to +* point to next item in local_buf */ + result =sscanf (local_buf,"%u" , &interrupt_enable); +if ((result !=1 ) || + (interrupt_enable !=0 && interrupt_enable !=1 )) { +dev_err (&data->fc->dev,"Interrupt enable[%d] is not a valid value 0x%x.\n" , + i, interrupt_enable); +return -EINVAL ; + } +if (interrupt_enable ==0 ) { + f01->device_control.interrupt_enable[irq_reg] &= + (1 << irq_shift) ^0xFF ; + }else + f01->device_control.interrupt_enable[irq_reg] |= + (1 << irq_shift); + irq_count++; + } + +/* Make sure the irq count matches */ +if (irq_count != f01->irq_count) { +dev_err (&data->fc->dev,"Interrupt enable count of %d doesn't match device count of %d.\n" , + irq_count, f01->irq_count); +return -EINVAL ; + } + +/* write back to the control register */ + retval =rmi_write_block (data->fc->rmi_dev, f01->interrupt_enable_addr, + f01->device_control.interrupt_enable, + f01->num_of_irq_regs); +if (retval <0 ) { +dev_err (&data->fc->dev,"Could not write interrupt_enable mask to %#06x\n" , + f01->interrupt_enable_addr); +return retval; + } + +return size; +} + +static const struct file_operations interrupt_enable_fops = { + .owner =THIS_MODULE , + .open = f01_debug_open, + .read = interrupt_enable_read, + .write = interrupt_enable_write, +}; + +static int setup_debugfs (struct rmi_function_container *fc) +{ +struct f01_data *data = fc->data; + +if (!fc->debugfs_root) +return -ENODEV ; + + data->debugfs_interrupt_enable =debugfs_create_file ("interrupt_enable" , +RMI_RW_ATTR , fc->debugfs_root, fc, &interrupt_enable_fops); +if (!data->debugfs_interrupt_enable) +dev_warn (&fc->dev, +"Failed to create debugfs interrupt_enable.\n" ); + +return 0 ; +} + +static void teardown_debugfs (struct f01_data *f01) +{ +if (f01->debugfs_interrupt_enable) +debugfs_remove (f01->debugfs_interrupt_enable); +} +#endif + + +static ssize_t rmi_fn_01_productinfo_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +static ssize_t rmi_fn_01_productid_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +static ssize_t rmi_fn_01_manufacturer_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +static ssize_t rmi_fn_01_datecode_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +static ssize_t rmi_fn_01_reportrate_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +static ssize_t rmi_fn_01_reportrate_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count); + +static ssize_t rmi_fn_01_interrupt_enable_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +static ssize_t rmi_fn_01_doze_interval_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +static ssize_t rmi_fn_01_doze_interval_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count); + +static ssize_t rmi_fn_01_wakeup_threshold_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +static ssize_t rmi_fn_01_wakeup_threshold_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count); + +static ssize_t rmi_fn_01_doze_holdoff_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +static ssize_t rmi_fn_01_doze_holdoff_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count); + +static ssize_t rmi_fn_01_reset_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count); + +static ssize_t rmi_fn_01_sleepmode_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +static ssize_t rmi_fn_01_sleepmode_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count); + +static ssize_t rmi_fn_01_nosleep_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +static ssize_t rmi_fn_01_nosleep_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count); + +static ssize_t rmi_fn_01_chargerinput_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +static ssize_t rmi_fn_01_chargerinput_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count); + +static ssize_t rmi_fn_01_configured_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +static ssize_t rmi_fn_01_unconfigured_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +static ssize_t rmi_fn_01_flashprog_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +static ssize_t rmi_fn_01_statuscode_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +static int rmi_f01_alloc_memory (struct rmi_function_container *fc, +int num_of_irq_regs); + +static int rmi_f01_initialize (struct rmi_function_container *fc); + +static int rmi_f01_create_sysfs (struct rmi_function_container *fc); + +static int rmi_f01_config (struct rmi_function_container *fc); + + +static struct device_attribute fn_01_attrs[] = { +__ATTR (productinfo,RMI_RO_ATTR , + rmi_fn_01_productinfo_show, rmi_store_error), +__ATTR (productid,RMI_RO_ATTR , + rmi_fn_01_productid_show, rmi_store_error), +__ATTR (manufacturer,RMI_RO_ATTR , + rmi_fn_01_manufacturer_show, rmi_store_error), +__ATTR (datecode,RMI_RO_ATTR , + rmi_fn_01_datecode_show, rmi_store_error), + +/* control register access */ +__ATTR (sleepmode,RMI_RW_ATTR , + rmi_fn_01_sleepmode_show, rmi_fn_01_sleepmode_store), +__ATTR (nosleep,RMI_RW_ATTR , + rmi_fn_01_nosleep_show, rmi_fn_01_nosleep_store), +__ATTR (chargerinput,RMI_RW_ATTR , + rmi_fn_01_chargerinput_show, rmi_fn_01_chargerinput_store), +__ATTR (reportrate,RMI_RW_ATTR , + rmi_fn_01_reportrate_show, rmi_fn_01_reportrate_store), +/* We don't want arbitrary callers changing the interrupt enable mask, +* so it's read only. +*/ +__ATTR (interrupt_enable,RMI_RO_ATTR , + rmi_fn_01_interrupt_enable_show, rmi_store_error), +__ATTR (doze_interval,RMI_RW_ATTR , + rmi_fn_01_doze_interval_show, rmi_fn_01_doze_interval_store), +__ATTR (wakeup_threshold,RMI_RW_ATTR , + rmi_fn_01_wakeup_threshold_show, + rmi_fn_01_wakeup_threshold_store), +__ATTR (doze_holdoff,RMI_RW_ATTR , + rmi_fn_01_doze_holdoff_show, rmi_fn_01_doze_holdoff_store), + +/* We make report rate RO, since the driver uses that to look for +* resets. We don't want someone faking us out by changing that +* bit. +*/ +__ATTR (configured,RMI_RO_ATTR , + rmi_fn_01_configured_show, rmi_store_error), + +/* Command register access. */ +__ATTR (reset,RMI_WO_ATTR , + rmi_show_error, rmi_fn_01_reset_store), + +/* STatus register access. */ +__ATTR (unconfigured,RMI_RO_ATTR , + rmi_fn_01_unconfigured_show, rmi_store_error), +__ATTR (flashprog,RMI_RO_ATTR , + rmi_fn_01_flashprog_show, rmi_store_error), +__ATTR (statuscode,RMI_RO_ATTR , + rmi_fn_01_statuscode_show, rmi_store_error), +}; + +/* Utility routine to set the value of a bit field in a register. */ +int rmi_mask_and_set (struct rmi_device *rmi_dev, +u16 address, +u8 mask, +u8 set) +{ +u8 reg_contents; +int retval; + + retval =rmi_read (rmi_dev, address, ®_contents); +if (retval <0 ) +return retval; + reg_contents = (reg_contents & ~mask) | set; + retval =rmi_write (rmi_dev, address, reg_contents); +if (retval ==1 ) +return 0 ; +else if (retval ==0 ) +return -EIO ; +return retval; +} + +static ssize_t rmi_fn_01_productinfo_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct f01_data *data =NULL ; +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + +return snprintf (buf,PAGE_SIZE ,"0x%02x 0x%02x\n" , + data->basic_queries.productinfo_1, + data->basic_queries.productinfo_2); +} + +static ssize_t rmi_fn_01_productid_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct f01_data *data =NULL ; +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + +return snprintf (buf,PAGE_SIZE ,"%s\n" , data->product_id); +} + +static ssize_t rmi_fn_01_manufacturer_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct f01_data *data =NULL ; +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + +return snprintf (buf,PAGE_SIZE ,"0x%02x\n" , + data->basic_queries.manufacturer_id); +} + +static ssize_t rmi_fn_01_datecode_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct f01_data *data =NULL ; +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + +return snprintf (buf,PAGE_SIZE ,"20%02u-%02u-%02u\n" , + data->basic_queries.year, + data->basic_queries.month, + data->basic_queries.day); +} + +static ssize_t rmi_fn_01_reset_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct rmi_function_container *fc =NULL ; +unsigned int reset; +int retval =0 ; +/* Command register always reads as 0, so we can just use a local. */ +union f01_device_commands commands = {}; + + fc =to_rmi_function_container (dev); + +if (sscanf (buf,"%u" , &reset) !=1 ) +return -EINVAL ; +if (reset <0 || reset >1 ) +return -EINVAL ; + +/* Per spec, 0 has no effect, so we skip it entirely. */ +if (reset) { + commands.reset =1 ; + retval =rmi_write_block (fc->rmi_dev, fc->fd.command_base_addr, + &commands.reg,sizeof (commands.reg)); +if (retval <0 ) { +dev_err (dev,"Failed to issue reset command, code = %d." , + retval); +return retval; + } + } + +return count; +} + +static ssize_t rmi_fn_01_sleepmode_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct f01_data *data =NULL ; +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + +return snprintf (buf,PAGE_SIZE , +"%d\n" , data->device_control.ctrl0.sleep_mode); +} + +static ssize_t rmi_fn_01_sleepmode_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct f01_data *data =NULL ; +unsigned long new_value; +int retval; +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + + retval =strict_strtoul (buf,10 , &new_value); +if (retval <0 || !RMI_IS_VALID_SLEEPMODE (new_value)) { +dev_err (dev,"%s: Invalid sleep mode %s." , __func__, buf); +return -EINVAL ; + } + +dev_dbg (dev,"Setting sleep mode to %ld." , new_value); + data->device_control.ctrl0.sleep_mode = new_value; + retval =rmi_write_block (fc->rmi_dev, fc->fd.control_base_addr, + data->device_control.ctrl0.regs, +ARRAY_SIZE (data->device_control.ctrl0.regs)); +if (retval >=0 ) + retval = count; +else +dev_err (dev,"Failed to write sleep mode, code %d.\n" , retval); +return retval; +} + +static ssize_t rmi_fn_01_nosleep_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct f01_data *data =NULL ; +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + +return snprintf (buf,PAGE_SIZE ,"%d\n" , + data->device_control.ctrl0.nosleep); +} + +static ssize_t rmi_fn_01_nosleep_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct f01_data *data =NULL ; +unsigned long new_value; +int retval; +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + + retval =strict_strtoul (buf,10 , &new_value); +if (retval <0 || new_value <0 || new_value >1 ) { +dev_err (dev,"%s: Invalid nosleep bit %s." , __func__, buf); +return -EINVAL ; + } + + data->device_control.ctrl0.nosleep = new_value; + retval =rmi_write_block (fc->rmi_dev, fc->fd.control_base_addr, + data->device_control.ctrl0.regs, +ARRAY_SIZE (data->device_control.ctrl0.regs)); +if (retval >=0 ) + retval = count; +else +dev_err (dev,"Failed to write nosleep bit.\n" ); +return retval; +} + +static ssize_t rmi_fn_01_chargerinput_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct f01_data *data =NULL ; +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + +return snprintf (buf,PAGE_SIZE ,"%d\n" , + data->device_control.ctrl0.charger_input); +} + +static ssize_t rmi_fn_01_chargerinput_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct f01_data *data =NULL ; +unsigned long new_value; +int retval; +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + + retval =strict_strtoul (buf,10 , &new_value); +if (retval <0 || new_value <0 || new_value >1 ) { +dev_err (dev,"%s: Invalid chargerinput bit %s." , __func__, buf); +return -EINVAL ; + } + + data->device_control.ctrl0.charger_input = new_value; + retval =rmi_write_block (fc->rmi_dev, fc->fd.control_base_addr, + data->device_control.ctrl0.regs, +ARRAY_SIZE (data->device_control.ctrl0.regs)); +if (retval >=0 ) + retval = count; +else +dev_err (dev,"Failed to write chargerinput bit.\n" ); +return retval; +} + +static ssize_t rmi_fn_01_reportrate_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct f01_data *data =NULL ; +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + +return snprintf (buf,PAGE_SIZE ,"%d\n" , + data->device_control.ctrl0.report_rate); +} + +static ssize_t rmi_fn_01_reportrate_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct f01_data *data =NULL ; +unsigned long new_value; +int retval; +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + + retval =strict_strtoul (buf,10 , &new_value); +if (retval <0 || new_value <0 || new_value >1 ) { +dev_err (dev,"%s: Invalid reportrate bit %s." , __func__, buf); +return -EINVAL ; + } + + data->device_control.ctrl0.report_rate = new_value; + retval =rmi_write_block (fc->rmi_dev, fc->fd.control_base_addr, + data->device_control.ctrl0.regs, +ARRAY_SIZE (data->device_control.ctrl0.regs)); +if (retval >=0 ) + retval = count; +else +dev_err (dev,"Failed to write reportrate bit.\n" ); +return retval; +} + +static ssize_t rmi_fn_01_interrupt_enable_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct rmi_function_container *fc; +struct f01_data *data; +int i, len, total_len =0 ; +char *current_buf = buf; + + fc =to_rmi_function_container (dev); + data = fc->data; +/* loop through each irq value and copy its +* string representation into buf */ +for (i =0 ; i < data->irq_count; i++) { +int irq_reg; +int irq_shift; +int interrupt_enable; + + irq_reg = i /8 ; + irq_shift = i %8 ; + interrupt_enable = + ((data->device_control.interrupt_enable[irq_reg] + >> irq_shift) &0x01 ); + +/* get next irq value and write it to buf */ + len =snprintf (current_buf,PAGE_SIZE - total_len, +"%u " , interrupt_enable); +/* bump up ptr to next location in buf if the +* snprintf was valid. Otherwise issue an error +* and return. */ +if (len >0 ) { + current_buf += len; + total_len += len; + }else { +dev_err (dev,"Failed to build interrupt_enable buffer, code = %d.\n" , + len); +return snprintf (buf,PAGE_SIZE ,"unknown\n" ); + } + } + len =snprintf (current_buf,PAGE_SIZE - total_len,"\n" ); +if (len >0 ) + total_len += len; +else +dev_warn (dev,"%s: Failed to append carriage return.\n" , + __func__); +return total_len; + +} + +static ssize_t rmi_fn_01_doze_interval_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct f01_data *data =NULL ; +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + +return snprintf (buf,PAGE_SIZE ,"%d\n" , + data->device_control.doze_interval); + +} + +static ssize_t rmi_fn_01_doze_interval_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct f01_data *data =NULL ; +unsigned long new_value; +int retval; +u16 ctrl_base_addr; + +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + + retval =strict_strtoul (buf,10 , &new_value); +if (retval <0 || new_value <0 || new_value >255 ) { +dev_err (dev,"%s: Invalid doze interval %s." , __func__, buf); +return -EINVAL ; + } + + data->device_control.doze_interval = new_value; + ctrl_base_addr = fc->fd.control_base_addr +sizeof (u8) + + (sizeof (u8)*(data->num_of_irq_regs)); +dev_dbg (dev,"doze_interval store address %x, value %d" , + ctrl_base_addr, data->device_control.doze_interval); + + retval =rmi_write_block (fc->rmi_dev, data->doze_interval_addr, + &data->device_control.doze_interval, +sizeof (u8)); +if (retval >=0 ) + retval = count; +else +dev_err (dev,"Failed to write doze interval.\n" ); +return retval; + +} + +static ssize_t rmi_fn_01_wakeup_threshold_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct f01_data *data =NULL ; +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + +return snprintf (buf,PAGE_SIZE ,"%d\n" , + data->device_control.wakeup_threshold); +} + +static ssize_t rmi_fn_01_wakeup_threshold_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct f01_data *data =NULL ; +unsigned long new_value; +int retval; + +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + + retval =strict_strtoul (buf,10 , &new_value); +if (retval <0 || new_value <0 || new_value >255 ) { +dev_err (dev,"%s: Invalid wakeup threshold %s." , __func__, buf); +return -EINVAL ; + } + + data->device_control.doze_interval = new_value; + retval =rmi_write_block (fc->rmi_dev, data->wakeup_threshold_addr, + &data->device_control.wakeup_threshold, +sizeof (u8)); +if (retval >=0 ) + retval = count; +else +dev_err (dev,"Failed to write wakeup threshold.\n" ); +return retval; + +} + +static ssize_t rmi_fn_01_doze_holdoff_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct f01_data *data =NULL ; +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + +return snprintf (buf,PAGE_SIZE ,"%d\n" , + data->device_control.doze_holdoff); + +} + + +static ssize_t rmi_fn_01_doze_holdoff_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct f01_data *data =NULL ; +unsigned long new_value; +int retval; + +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + + retval =strict_strtoul (buf,10 , &new_value); +if (retval <0 || new_value <0 || new_value >255 ) { +dev_err (dev,"%s: Invalid doze holdoff %s." , __func__, buf); +return -EINVAL ; + } + + data->device_control.doze_interval = new_value; + retval =rmi_write_block (fc->rmi_dev, data->doze_holdoff_addr, + &data->device_control.doze_holdoff, +sizeof (u8)); +if (retval >=0 ) + retval = count; +else +dev_err (dev,"Failed to write doze holdoff.\n" ); +return retval; + +} + +static ssize_t rmi_fn_01_configured_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct f01_data *data =NULL ; +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + +return snprintf (buf,PAGE_SIZE ,"%d\n" , + data->device_control.ctrl0.configured); +} + +static ssize_t rmi_fn_01_unconfigured_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct f01_data *data =NULL ; +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + +return snprintf (buf,PAGE_SIZE ,"%d\n" , + data->device_status.unconfigured); +} + +static ssize_t rmi_fn_01_flashprog_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct f01_data *data =NULL ; +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + +return snprintf (buf,PAGE_SIZE ,"%d\n" , + data->device_status.flash_prog); +} + +static ssize_t rmi_fn_01_statuscode_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct f01_data *data =NULL ; +struct rmi_function_container *fc =to_rmi_function_container (dev); + + data = fc->data; + +return snprintf (buf,PAGE_SIZE ,"0x%02x\n" , + data->device_status.status_code); +} + +static int f01_device_init (struct rmi_function_container *fc) +{ +struct rmi_driver_data *driver_data = +dev_get_drvdata (&fc->rmi_dev->dev); +int error; + + error =rmi_f01_alloc_memory (fc, driver_data->num_of_irq_regs); +if (error <0 ) +return error; + + error =rmi_f01_initialize (fc); +if (error <0 ) +return error; + + error =rmi_f01_create_sysfs (fc); +if (error <0 ) +return error; + +return 0 ; +} + +static int rmi_f01_alloc_memory (struct rmi_function_container *fc, +int num_of_irq_regs) +{ +struct f01_data *f01; + + f01 =devm_kzalloc (&fc->dev,sizeof (struct f01_data ),GFP_KERNEL ); +if (!f01) { +dev_err (&fc->dev,"Failed to allocate fn_01_data.\n" ); +return -ENOMEM ; + } + + f01->device_control.interrupt_enable =devm_kzalloc (&fc->dev, +sizeof (u8)*(num_of_irq_regs), +GFP_KERNEL ); +if (!f01->device_control.interrupt_enable) { +dev_err (&fc->dev,"Failed to allocate interrupt enable.\n" ); +return -ENOMEM ; + } + fc->data = f01; + +return 0 ; +} + +static int rmi_f01_initialize (struct rmi_function_container *fc) +{ +u8 temp; +int retval; +u16 ctrl_base_addr; +struct rmi_device *rmi_dev = fc->rmi_dev; +struct rmi_driver_data *driver_data =dev_get_drvdata (&rmi_dev->dev); +struct f01_data *data = fc->data; +struct rmi_device_platform_data *pdata =to_rmi_platform_data (rmi_dev); + +/* Set the configured bit and (optionally) other important stuff +* in the device control register. */ + ctrl_base_addr = fc->fd.control_base_addr; + retval =rmi_read_block (rmi_dev, fc->fd.control_base_addr, + data->device_control.ctrl0.regs, +ARRAY_SIZE (data->device_control.ctrl0.regs)); +if (retval <0 ) { +dev_err (&fc->dev,"Failed to read F01 control.\n" ); +return retval; + } +switch (pdata->power_management.nosleep) { +case RMI_F01_NOSLEEP_DEFAULT : +break ; +case RMI_F01_NOSLEEP_OFF : + data->device_control.ctrl0.nosleep =0 ; +break ; +case RMI_F01_NOSLEEP_ON : + data->device_control.ctrl0.nosleep =1 ; +break ; + } +/* Sleep mode might be set as a hangover from a system crash or +* reboot without power cycle. If so, clear it so the sensor +* is certain to function. +*/ +if (data->device_control.ctrl0.sleep_mode !=RMI_SLEEP_MODE_NORMAL ) { +dev_warn (&fc->dev, +"WARNING: Non-zero sleep mode found. Clearing...\n" ); + data->device_control.ctrl0.sleep_mode =RMI_SLEEP_MODE_NORMAL ; + } + + data->device_control.ctrl0.configured =1 ; + retval =rmi_write_block (rmi_dev, fc->fd.control_base_addr, + data->device_control.ctrl0.regs, +ARRAY_SIZE (data->device_control.ctrl0.regs)); +if (retval <0 ) { +dev_err (&fc->dev,"Failed to write F01 control.\n" ); +return retval; + } + + data->irq_count = driver_data->irq_count; + data->num_of_irq_regs = driver_data->num_of_irq_regs; + ctrl_base_addr +=sizeof (union f01_device_control_0 ); + + data->interrupt_enable_addr = ctrl_base_addr; + retval =rmi_read_block (rmi_dev, ctrl_base_addr, + data->device_control.interrupt_enable, +sizeof (u8)*(driver_data->num_of_irq_regs)); +if (retval <0 ) { +dev_err (&fc->dev,"Failed to read F01 control interrupt enable register.\n" ); + goto error_exit; + } + ctrl_base_addr += driver_data->num_of_irq_regs; + +/* dummy read in order to clear irqs */ + retval =rmi_read (rmi_dev, fc->fd.data_base_addr +1 , &temp); +if (retval <0 ) { +dev_err (&fc->dev,"Failed to read Interrupt Status.\n" ); +return retval; + } + + retval =rmi_read_block (rmi_dev, fc->fd.query_base_addr, + data->basic_queries.regs, +sizeof (data->basic_queries.regs)); +if (retval <0 ) { +dev_err (&fc->dev,"Failed to read device query registers.\n" ); +return retval; + } + + retval =rmi_read_block (rmi_dev, + fc->fd.query_base_addr +sizeof (data->basic_queries.regs), + data->product_id,RMI_PRODUCT_ID_LENGTH ); +if (retval <0 ) { +dev_err (&fc->dev,"Failed to read product ID.\n" ); +return retval; + } + data->product_id[RMI_PRODUCT_ID_LENGTH ] ='\0' ; +dev_info (&fc->dev,"found RMI device, manufacturer: %s, product: %s\n" , + data->basic_queries.manufacturer_id ==1 ? +"synaptics" :"unknown" , + data->product_id); + +/* read control register */ +if (data->basic_queries.has_adjustable_doze) { + data->doze_interval_addr = ctrl_base_addr; + ctrl_base_addr++; + +if (pdata->power_management.doze_interval) { + data->device_control.doze_interval = + pdata->power_management.doze_interval; + retval =rmi_write (rmi_dev, data->doze_interval_addr, + data->device_control.doze_interval); +if (retval <0 ) { +dev_err (&fc->dev,"Failed to configure F01 doze interval register.\n" ); + goto error_exit; + } + }else { + retval =rmi_read (rmi_dev, data->doze_interval_addr, + &data->device_control.doze_interval); +if (retval <0 ) { +dev_err (&fc->dev,"Failed to read F01 doze interval register.\n" ); + goto error_exit; + } + } + + data->wakeup_threshold_addr = ctrl_base_addr; + ctrl_base_addr++; + +if (pdata->power_management.wakeup_threshold) { + data->device_control.wakeup_threshold = + pdata->power_management.wakeup_threshold; + retval =rmi_write (rmi_dev, data->wakeup_threshold_addr, + data->device_control.wakeup_threshold); +if (retval <0 ) { +dev_err (&fc->dev,"Failed to configure F01 wakeup threshold register.\n" ); + goto error_exit; + } + }else { + retval =rmi_read (rmi_dev, data->wakeup_threshold_addr, + &data->device_control.wakeup_threshold); +if (retval <0 ) { +dev_err (&fc->dev,"Failed to read F01 wakeup threshold register.\n" ); + goto error_exit; + } + } + } + +if (data->basic_queries.has_adjustable_doze_holdoff) { + data->doze_holdoff_addr = ctrl_base_addr; + ctrl_base_addr++; + +if (pdata->power_management.doze_holdoff) { + data->device_control.doze_holdoff = + pdata->power_management.doze_holdoff; + retval =rmi_write (rmi_dev, data->doze_holdoff_addr, + data->device_control.doze_holdoff); +if (retval <0 ) { +dev_err (&fc->dev,"Failed to configure F01 doze holdoff register.\n" ); + goto error_exit; + } + }else { + retval =rmi_read (rmi_dev, data->doze_holdoff_addr, + &data->device_control.doze_holdoff); +if (retval <0 ) { +dev_err (&fc->dev,"Failed to read F01 doze holdoff register.\n" ); + goto error_exit; + } + } + } + + retval =rmi_read_block (rmi_dev, fc->fd.data_base_addr, + data->device_status.regs,ARRAY_SIZE (data->device_status.regs)); +if (retval <0 ) { +dev_err (&fc->dev,"Failed to read device status.\n" ); + goto error_exit; + } + +if (data->device_status.unconfigured) { +dev_err (&fc->dev,"Device reset during configuration process, status: %#02x!\n" , + data->device_status.status_code); + retval = -EINVAL ; + goto error_exit; + } + +if (IS_ENABLED (CONFIG_RMI4_DEBUG )) { + retval =setup_debugfs (fc); +if (retval <0 ) +dev_warn (&fc->dev,"Failed to setup debugfs. Code: %d.\n" , + retval); + } + +return retval; + + error_exit: +kfree (data); +return retval; +} + +static int rmi_f01_create_sysfs (struct rmi_function_container *fc) +{ +int attr_count =0 ; +int retval =0 ; +struct f01_data *data = fc->data; + +dev_dbg (&fc->dev,"Creating sysfs files." ); +for (attr_count =0 ; attr_count <ARRAY_SIZE (fn_01_attrs); + attr_count++) { +if (!strcmp ("doze_interval" , fn_01_attrs[attr_count].attr.name) + && !data->basic_queries.has_lts) { +continue ; + } +if (!strcmp ("wakeup_threshold" , + fn_01_attrs[attr_count].attr.name) + && !data->basic_queries.has_adjustable_doze) { +continue ; + } +if (!strcmp ("doze_holdoff" , fn_01_attrs[attr_count].attr.name) + && !data->basic_queries.has_adjustable_doze_holdoff) { +continue ; + } + retval =sysfs_create_file (&fc->dev.kobj, + &fn_01_attrs[attr_count].attr); +if (retval <0 ) { +dev_err (&fc->dev,"Failed to create sysfs file for %s." , + fn_01_attrs[attr_count].attr.name); + goto err_remove_sysfs; + } + } + +return 0 ; + +err_remove_sysfs: +for (attr_count--; attr_count >=0 ; attr_count--) +sysfs_remove_file (&fc->dev.kobj, + &fn_01_attrs[attr_count].attr); + +return retval; +} + +static int rmi_f01_config (struct rmi_function_container *fc) +{ +struct f01_data *data = fc->data; +int retval; + + retval =rmi_write_block (fc->rmi_dev, fc->fd.control_base_addr, + data->device_control.ctrl0.regs, +ARRAY_SIZE (data->device_control.ctrl0.regs)); +if (retval <0 ) { +dev_err (&fc->dev,"Failed to write device_control.reg.\n" ); +return retval; + } + + retval =rmi_write_block (fc->rmi_dev, data->interrupt_enable_addr, + data->device_control.interrupt_enable, +sizeof (u8)*(data->num_of_irq_regs)); + +if (retval <0 ) { +dev_err (&fc->dev,"Failed to write interrupt enable.\n" ); +return retval; + } +if (data->basic_queries.has_lts) { + retval =rmi_write_block (fc->rmi_dev, data->doze_interval_addr, + &data->device_control.doze_interval, +sizeof (u8)); +if (retval <0 ) { +dev_err (&fc->dev,"Failed to write doze interval.\n" ); +return retval; + } + } + +if (data->basic_queries.has_adjustable_doze) { + retval =rmi_write_block ( + fc->rmi_dev, data->wakeup_threshold_addr, + &data->device_control.wakeup_threshold, +sizeof (u8)); +if (retval <0 ) { +dev_err (&fc->dev,"Failed to write wakeup threshold.\n" ); +return retval; + } + } + +if (data->basic_queries.has_adjustable_doze_holdoff) { + retval =rmi_write_block (fc->rmi_dev, data->doze_holdoff_addr, + &data->device_control.doze_holdoff, +sizeof (u8)); +if (retval <0 ) { +dev_err (&fc->dev,"Failed to write doze holdoff.\n" ); +return retval; + } + } +return 0 ; +} + +#ifdef CONFIG_PM +static int rmi_f01_suspend (struct rmi_function_container *fc) +{ +struct rmi_device *rmi_dev = fc->rmi_dev; +struct rmi_driver_data *driver_data =dev_get_drvdata (&rmi_dev->dev); +struct f01_data *data = driver_data->f01_container->data; +int retval =0 ; + +if (data->suspended) +return 0 ; + + data->old_nosleep = data->device_control.ctrl0.nosleep; + data->device_control.ctrl0.nosleep =0 ; + data->device_control.ctrl0.sleep_mode =RMI_SLEEP_MODE_SENSOR_SLEEP ; + + retval =rmi_write_block (rmi_dev, + driver_data->f01_container->fd.control_base_addr, + data->device_control.ctrl0.regs, +ARRAY_SIZE (data->device_control.ctrl0.regs)); +if (retval <0 ) { +dev_err (&fc->dev,"Failed to write sleep mode. Code: %d.\n" , + retval); + data->device_control.ctrl0.nosleep = data->old_nosleep; + data->device_control.ctrl0.sleep_mode =RMI_SLEEP_MODE_NORMAL ; + }else { + data->suspended = true; + retval =0 ; + } + +return retval; +} + +static int rmi_f01_resume (struct rmi_function_container *fc) +{ +struct rmi_device *rmi_dev = fc->rmi_dev; +struct rmi_driver_data *driver_data =dev_get_drvdata (&rmi_dev->dev); +struct f01_data *data = driver_data->f01_container->data; +int retval =0 ; + +if (!data->suspended) +return 0 ; + + data->device_control.ctrl0.nosleep = data->old_nosleep; + data->device_control.ctrl0.sleep_mode =RMI_SLEEP_MODE_NORMAL ; + + retval =rmi_write_block (rmi_dev, + driver_data->f01_container->fd.control_base_addr, + data->device_control.ctrl0.regs, +ARRAY_SIZE (data->device_control.ctrl0.regs)); +if (retval <0 ) +dev_err (&fc->dev, +"Failed to restore normal operation. Code: %d.\n" , + retval); +else { + data->suspended = false; + retval =0 ; + } + +return retval; +} +#endif /* CONFIG_PM */ + +static int f01_remove_device (struct device *dev) +{ +int attr_count; +struct rmi_function_container *fc =to_rmi_function_container (dev); + +if (IS_ENABLED (CONFIG_RMI4_DEBUG )) +teardown_debugfs (fc->data); + +for (attr_count =0 ; attr_count <ARRAY_SIZE (fn_01_attrs); + attr_count++) { +sysfs_remove_file (&fc->dev.kobj, &fn_01_attrs[attr_count].attr); + } +return 0 ; +} + +static int rmi_f01_attention (struct rmi_function_container *fc,u8 *irq_bits) +{ +struct rmi_device *rmi_dev = fc->rmi_dev; +struct f01_data *data = fc->data; +int retval; + + retval =rmi_read_block (rmi_dev, fc->fd.data_base_addr, + data->device_status.regs,ARRAY_SIZE (data->device_status.regs)); +if (retval <0 ) { +dev_err (&fc->dev,"Failed to read device status, code: %d.\n" , + retval); +return retval; + } +if (data->device_status.unconfigured) { +dev_warn (&fc->dev,"Device reset detected.\n" ); + retval = rmi_dev->driver->reset_handler (rmi_dev); +if (retval <0 ) +return retval; + } +return 0 ; +} + +static int f01_probe (struct device *dev); + +static struct rmi_function_handler function_handler = { + .driver = { + .owner =THIS_MODULE , + .name ="rmi_f01" , + .bus = &rmi_bus_type, + .probe = f01_probe, + .remove = f01_remove_device, + }, + .func =0x01 , + .config = rmi_f01_config, + .attention = rmi_f01_attention, + +#ifdef CONFIG_PM + .suspend = rmi_f01_suspend, + .resume = rmi_f01_resume, +#endif /* CONFIG_PM */ +}; + +static __devinit int f01_probe (struct device *dev) +{ +struct rmi_function_container *fc; + +if (dev->type != &rmi_function_type) { +dev_dbg (dev,"Not a function device.\n" ); +return 1 ; + } + fc =to_rmi_function_container (dev); +if (fc->fd.function_number != function_handler.func) { +dev_dbg (dev,"Device is F%02X, not F%02X.\n" , + fc->fd.function_number, function_handler.func); +return 1 ; + } + +dev_dbg (dev,"Yay! It is F01!\n" ); +return f01_device_init (fc); +} + +static int __init rmi_f01_module_init (void ) +{ +int error; + + error =driver_register (&function_handler.driver); +if (error <0 ) { +pr_err ("%s: register failed!\n" , __func__); +return error; + } + +return 0 ; +} + +static void __exit rmi_f01_module_exit(void) +{ +driver_unregister (&function_handler.driver); +} + +module_init (rmi_f01_module_init); +module_exit (rmi_f01_module_exit); + +MODULE_AUTHOR ("Christopher Heiny <[email protected]>" ); +MODULE_DESCRIPTION ("RMI F01 module" ); +MODULE_LICENSE ("GPL" ); +MODULE_VERSION (RMI_DRIVER_VERSION );
drivers/input/rmi4/rmi_f01.h new file +136 -0
136 lines not on this page · raw message
RFC PATCH 6/6 input/rmi4: F11 - 2D touch interface
In reply to Christopher Heinyrmi_f11.c is a driver for 2D touch sensors. It has been updated to support the MT-B specification, partition control attributes between debugfs and sysfs, and to use the standard bus model for loading/unloading.
---
drivers/input/rmi4/rmi_f11.c | 2727 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 2727 insertions(+), 0 deletions(-)
drivers/input/rmi4/rmi_f11.c new file +2727 -0
@@ -0,0 +1,2727 @@ +/* +* Copyright (c) 2011,2012 Synaptics Incorporated +* Copyright (c) 2011 Unixphere +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#define FUNCTION_DATA f11_data +#define FNUM 11 + +#include <linux/kernel.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/input.h> +#include <linux/input/mt.h> +#include <linux/kconfig.h> +#include <linux/rmi.h> +#include <linux/slab.h> +#include "rmi_driver.h" + +#ifdef CONFIG_RMI4_DEBUG +#include <linux/debugfs.h> +#include <linux/fs.h> +#include <linux/uaccess.h> +#endif + +#define F11_MAX_NUM_OF_SENSORS 8 +#define F11_MAX_NUM_OF_FINGERS 10 +#define F11_MAX_NUM_OF_TOUCH_SHAPES 16 + +#define F11_REL_POS_MIN -128 +#define F11_REL_POS_MAX 127 + +#define FINGER_STATE_MASK 0x03 +#define GET_FINGER_STATE (f_states, i) \ + ((f_states[i / 4] >> (2 * (i % 4))) & FINGER_STATE_MASK) + +#define F11_CTRL_SENSOR_MAX_X_POS_OFFSET 6 +#define F11_CTRL_SENSOR_MAX_Y_POS_OFFSET 8 + +#define F11_CEIL (x, y) (((x) + ((y)-1)) / (y)) +#define INBOX (x, y, box) (x >= box.x && x < (box.x + box.width) \ + && y >= box.y && y < (box.y + box.height)) + +#define DEFAULT_XY_MAX 9999 +#define DEFAULT_MAX_ABS_MT_PRESSURE 255 +#define DEFAULT_MAX_ABS_MT_TOUCH 15 +#define DEFAULT_MAX_ABS_MT_ORIENTATION 1 +#define DEFAULT_MIN_ABS_MT_TRACKING_ID 1 +#define DEFAULT_MAX_ABS_MT_TRACKING_ID 10 +#define MAX_NAME_LENGTH 256 + +static ssize_t f11_relreport_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +static ssize_t f11_relreport_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count); + +static ssize_t f11_maxPos_show (struct device *dev, +struct device_attribute *attr,char *buf); + +static ssize_t f11_rezero_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count); + +static void rmi_f11_free_memory (struct rmi_function_container *fc); + +static int rmi_f11_initialize (struct rmi_function_container *fc); + +static int rmi_f11_create_sysfs (struct rmi_function_container *fc); + +static int rmi_f11_config (struct rmi_function_container *fc); + +static int rmi_f11_register_devices (struct rmi_function_container *fc); + +static void rmi_f11_free_devices (struct rmi_function_container *fc); + +static void f11_set_abs_params (struct rmi_function_container *fc,int index); + +static struct device_attribute attrs[] = { +__ATTR (relreport,RMI_RW_ATTR , f11_relreport_show, f11_relreport_store), +__ATTR (maxPos,RMI_RO_ATTR , f11_maxPos_show, rmi_store_error), +__ATTR (rezero,RMI_WO_ATTR , rmi_show_error, f11_rezero_store) +}; + +/** +* @rezero - writing 1 to this will cause the sensor to calibrate to the +* current capacitive state. +*/ +union f11_2d_commands { +struct { +bool rezero:1 ; +u8 reserved:7 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +/** +* @nbr_of_sensors - the number of 2D sensors on the touch device. +* @has_query9 - indicates the F11_2D_Query9 register exists. +* @has_query11 - indicates the F11_2D_Query11 register exists. +* @has_z_tuning - if set, the sensor supports Z tuning and registers +* F11_2D_Ctrl29 through F11_2D_Ctrl33 exist. +* @has_pos_interpolation_tuning - TBD +* @has_w_tuning - the sensor supports Wx and Wy scaling and registers +* F11_2D_Ctrl36 through F11_2D_Ctrl39 exist. +* @has_pitch_info - the X and Y pitches of the sensor electrodes can be +* configured and registers F11_2D_Ctrl40 and F11_2D_Ctrl41 exist. +* @has_default_finger_width - the default finger width settings for the +* sensor can be configured and registers F11_2D_Ctrl42 through F11_2D_Ctrl44 +* exist. +* @has_segmentation_aggressiveness - the sensor’s ability to distinguish +* multiple objects close together can be configured and register F11_2D_Ctrl45 +* exists. +* @has_tx_rw_clip - the inactive outside borders of the sensor can be +* configured and registers F11_2D_Ctrl46 through F11_2D_Ctrl49 exist. +* @has_drumming_correction - the sensor can be configured to distinguish +* between a fast flick and a quick drumming movement and registers +* F11_2D_Ctrl50 and F11_2D_Ctrl51 exist. +*/ +struct f11_2d_device_query { +union { +struct { +u8 nbr_of_sensors:3 ; +bool has_query9:1 ; +bool has_query11:1 ; +u8 reserved:3 ; + } __attribute__((__packed__ )); +u8 f11_2d_query0; + }; + +union { +struct { +bool has_z_tuning:1 ; +bool has_pos_interpolation_tuning:1 ; +bool has_w_tuning:1 ; +bool has_pitch_info:1 ; +bool has_default_finger_width:1 ; +bool has_segmentation_aggressiveness:1 ; +bool has_tx_rw_clip:1 ; +bool has_drumming_correction:1 ; + } __attribute__((__packed__ )); +u8 f11_2d_query11; + }; +}; + +/** +* @has_pen - detection of a stylus is supported and registers F11_2D_Ctrl20 +* and F11_2D_Ctrl21 exist. +* @has_proximity - detection of fingers near the sensor is supported and +* registers F11_2D_Ctrl22 through F11_2D_Ctrl26 exist. +* @has_palm_det_sensitivity - the sensor supports the palm detect sensitivity +* feature and register F11_2D_Ctrl27 exists. +* @has_two_pen_thresholds - is has_pen is also set, then F11_2D_Ctrl35 exists. +* @has_contact_geometry - the sensor supports the use of contact geometry to +* map absolute X and Y target positions and registers F11_2D_Data18.* through +* F11_2D_Data27 exist. +*/ +union f11_2d_query9 { +struct { +bool has_pen:1 ; +bool has_proximity:1 ; +bool has_palm_det_sensitivity:1 ; +bool has_suppress_on_palm_detect:1 ; +bool has_two_pen_thresholds:1 ; +bool has_contact_geometry:1 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +/** +* @number_of_fingers - describes the maximum number of fingers the 2-D sensor +* supports. +* @has_rel - the sensor supports relative motion reporting. +* @has_abs - the sensor supports absolute poition reporting. +* @has_gestures - the sensor supports gesture reporting. +* @has_sensitivity_adjust - the sensor supports a global sensitivity +* adjustment. +* @configurable - the sensor supports various configuration options. +* @num_of_x_electrodes - the maximum number of electrodes the 2-D sensor +* supports on the X axis. +* @num_of_y_electrodes - the maximum number of electrodes the 2-D sensor +* supports on the Y axis. +* @max_electrodes - the total number of X and Y electrodes that may be +* configured. +* @abs_data_size - describes the format of data reported by the absolute +* data source. Only one format (the kind used here) is supported at this +* time. +* @has_anchored_finger - then the sensor supports the high-precision second +* finger tracking provided by the manual tracking and motion sensitivity +* options. +* @has_adjust_hyst - the difference between the finger release threshold and +* the touch threshold. +* @has_dribble - the sensor supports the generation of dribble interrupts, +* which may be enabled or disabled with the dribble control bit. +* @f11_2d_query6 - reserved. +* @has_single_tap - a basic single-tap gesture is supported. +* @has_tap_n_hold - tap-and-hold gesture is supported. +* @has_double_tap - double-tap gesture is supported. +* @has_early_tap - early tap is supported and reported as soon as the finger +* lifts for any tap event that could be interpreted as either a single tap +* or as the first tap of a double-tap or tap-and-hold gesture. +* @has_flick - flick detection is supported. +* @has_press - press gesture reporting is supported. +* @has_pinch - pinch gesture detection is supported. +* @has_palm_det - the 2-D sensor notifies the host whenever a large conductive +* object such as a palm or a cheek touches the 2-D sensor. +* @has_rotate - rotation gesture detection is supported. +* @has_touch_shapes - TouchShapes are supported. A TouchShape is a fixed +* rectangular area on the sensor that behaves like a capacitive button. +* @has_scroll_zones - scrolling areas near the sensor edges are supported. +* @has_individual_scroll_zones - if 1, then 4 scroll zones are supported; +* if 0, then only two are supported. +* @has_multi_finger_scroll - the multifinger_scrolling bit will be set when +* more than one finger is involved in a scrolling action. +* @nbr_touch_shapes - the total number of touch shapes supported. +*/ +struct f11_2d_sensor_query { +union { +struct { +/* query1 */ +u8 number_of_fingers:3 ; +bool has_rel:1 ; +bool has_abs:1 ; +bool has_gestures:1 ; +bool has_sensitivity_adjust:1 ; +bool configurable:1 ; +/* query2 */ +u8 num_of_x_electrodes:7 ; +u8 reserved_1:1 ; +/* query3 */ +u8 num_of_y_electrodes:7 ; +u8 reserved_2:1 ; +/* query4 */ +u8 max_electrodes:7 ; +u8 reserved_3:1 ; + } __attribute__((__packed__ )); +u8 f11_2d_query1__4[4 ]; + }; + +union { +struct { +u8 abs_data_size:3 ; +bool has_anchored_finger:1 ; +bool has_adj_hyst:1 ; +bool has_dribble:1 ; +u8 reserved_4:2 ; + } __attribute__((__packed__ )); +u8 f11_2d_query5; + }; + +u8 f11_2d_query6; + +union { +struct { +bool has_single_tap:1 ; +bool has_tap_n_hold:1 ; +bool has_double_tap:1 ; +bool has_early_tap:1 ; +bool has_flick:1 ; +bool has_press:1 ; +bool has_pinch:1 ; +bool padding:1 ; + +bool has_palm_det:1 ; +bool has_rotate:1 ; +bool has_touch_shapes:1 ; +bool has_scroll_zones:1 ; +bool has_individual_scroll_zones:1 ; +bool has_multi_finger_scroll:1 ; + } __attribute__((__packed__ )); +u8 f11_2d_query7__8[2 ]; + }; + +union f11_2d_query9 query9; + +union { +struct { +u8 nbr_touch_shapes:5 ; + } __attribute__((__packed__ )); +u8 f11_2d_query10; + }; +}; + +/** +* @reporting_mode - controls how often finger position data is reported. +* @abs_pos_filt - when set, enables various noise and jitter filtering +* algorithms for absolute reports. +* @rel_pos_filt - when set, enables various noise and jitter filtering +* algorithms for relative reports. +* @rel_ballistics - enables ballistics processing for the relative finger +* motion on the 2-D sensor. +* @dribble - enables the dribbling feature. +* @report_beyond_clip - when this is set, fingers outside the active area +* specified by the x_clip and y_clip registers will be reported, but with +* reported finger position clipped to the edge of the active area. +* @palm_detect_thresh - the threshold at which a wide finger is considered a +* palm. A value of 0 inhibits palm detection. +* @motion_sensitivity - specifies the threshold an anchored finger must move +* before it is considered no longer anchored. High values mean more +* sensitivity. +* @man_track_en - for anchored finger tracking, whether the host (1) or the +* device (0) determines which finger is the tracked finger. +* @man_tracked_finger - when man_track_en is 1, specifies whether finger 0 or +* finger 1 is the tracked finger. +* @delta_x_threshold - 2-D position update interrupts are inhibited unless +* the finger moves more than a certain threshold distance along the X axis. +* @delta_y_threshold - 2-D position update interrupts are inhibited unless +* the finger moves more than a certain threshold distance along the Y axis. +* @velocity - When rel_ballistics is set, this register defines the +* velocity ballistic parameter applied to all relative motion events. +* @acceleration - When rel_ballistics is set, this register defines the +* acceleration ballistic parameter applied to all relative motion events. +* @sensor_max_x_pos - the maximum X coordinate reported by the sensor. +* @sensor_max_y_pos - the maximum Y coordinate reported by the sensor. +*/ +union f11_2d_ctrl0_9 { +struct { +/* F11_2D_Ctrl0 */ +u8 reporting_mode:3 ; +bool abs_pos_filt:1 ; +bool rel_pos_filt:1 ; +bool rel_ballistics:1 ; +bool dribble:1 ; +bool report_beyond_clip:1 ; +/* F11_2D_Ctrl1 */ +u8 palm_detect_thres:4 ; +u8 motion_sensitivity:2 ; +bool man_track_en:1 ; +bool man_tracked_finger:1 ; +/* F11_2D_Ctrl2 and 3 */ +u8 delta_x_threshold:8 ; +u8 delta_y_threshold:8 ; +/* F11_2D_Ctrl4 and 5 */ +u8 velocity:8 ; +u8 acceleration:8 ; +/* F11_2D_Ctrl6 thru 9 */ +u16 sensor_max_x_pos:12 ; +u8 ctrl7_reserved:4 ; +u16 sensor_max_y_pos:12 ; +u8 ctrl9_reserved:4 ; + } __attribute__((__packed__ )); +struct { +u8 regs[10 ]; +u16 address; + } __attribute__((__packed__ )); +}; + +/** +* @single_tap_int_enable - enable tap gesture recognition. +* @tap_n_hold_int_enable - enable tap-and-hold gesture recognition. +* @double_tap_int_enable - enable double-tap gesture recognition. +* @early_tap_int_enable - enable early tap notification. +* @flick_int_enable - enable flick detection. +* @press_int_enable - enable press gesture recognition. +* @pinch_int_enable - enable pinch detection. +*/ +union f11_2d_ctrl10 { +struct { +bool single_tap_int_enable:1 ; +bool tap_n_hold_int_enable:1 ; +bool double_tap_int_enable:1 ; +bool early_tap_int_enable:1 ; +bool flick_int_enable:1 ; +bool press_int_enable:1 ; +bool pinch_int_enable:1 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +/** +* @palm_detect_int_enable - enable palm detection feature. +* @rotate_int_enable - enable rotate gesture detection. +* @touch_shape_int_enable - enable the TouchShape feature. +* @scroll_zone_int_enable - enable scroll zone reporting. +* @multi_finger_scroll_int_enable - enable the multfinger scroll feature. +*/ +union f11_2d_ctrl11 { +struct { +bool palm_detect_int_enable:1 ; +bool rotate_int_enable:1 ; +bool touch_shape_int_enable:1 ; +bool scroll_zone_int_enable:1 ; +bool multi_finger_scroll_int_enable:1 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +union f11_2d_ctrl12 { +struct { +u8 sensor_map:7 ; +bool xy_sel:1 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +/** +* @sens_adjustment - allows a host to alter the overall sensitivity of a +* 2-D sensor. A positive value in this register will make the sensor more +* sensitive than the factory defaults, and a negative value will make it +* less sensitive. +* @hyst_adjustment - increase the touch/no-touch hysteresis by 2 Z-units for +* each one unit increment in this setting. +*/ +union f11_2d_ctrl14 { +struct { +s8 sens_adjustment:5 ; +u8 hyst_adjustment:3 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +/** +* @max_tap_time - the maximum duration of a tap, in 10-millisecond units. +*/ +union f11_2d_ctrl15 { +struct { +u8 max_tap_time:8 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +/** +* @min_press_time - The minimum duration required for stationary finger(s) to +* generate a press gesture, in 10-millisecond units. +*/ +union f11_2d_ctrl16 { +struct { +u8 min_press_time:8 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +/** +* @max_tap_distance - Determines the maximum finger movement allowed during +* a tap, in 0.1-millimeter units. +*/ +union f11_2d_ctrl17 { +struct { +u8 max_tap_distance:8 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +/** +* @min_flick_distance - the minimum finger movement for a flick gesture, +* in 1-millimeter units. +* @min_flick_speed - the minimum finger speed for a flick gesture, in +* 10-millimeter/second units. +*/ +union f11_2d_ctrl18_19 { +struct { +u8 min_flick_distance:8 ; +u8 min_flick_speed:8 ; + } __attribute__((__packed__ )); +u8 reg[2 ]; +}; + +/** +* @pen_detect_enable - enable reporting of stylus activity. +* @pen_jitter_filter_enable - Setting this enables the stylus anti-jitter +* filter. +* @pen_z_threshold - This is the stylus-detection lower threshold. Smaller +* values result in higher sensitivity. +*/ +union f11_2d_ctrl20_21 { +struct { +bool pen_detect_enable:1 ; +bool pen_jitter_filter_enable:1 ; +u8 ctrl20_reserved:6 ; +u8 pen_z_threshold:8 ; + } __attribute__((__packed__ )); +u8 reg[2 ]; +}; + +/** +* These are not accessible through sysfs yet. +* +* @proximity_detect_int_en - enable proximity detection feature. +* @proximity_jitter_filter_en - enables an anti-jitter filter on proximity +* data. +* @proximity_detection_z_threshold - the threshold for finger-proximity +* detection. +* @proximity_delta_x_threshold - In reduced-reporting modes, this is the +* threshold for proximate-finger movement in the direction parallel to the +* X-axis. +* @proximity_delta_y_threshold - In reduced-reporting modes, this is the +* threshold for proximate-finger movement in the direction parallel to the +* Y-axis. +* * @proximity_delta_Z_threshold - In reduced-reporting modes, this is the +* threshold for proximate-finger movement in the direction parallel to the +* Z-axis. +*/ +union f11_2d_ctrl22_26 { +struct { +/* control 22 */ +bool proximity_detect_int_en:1 ; +bool proximity_jitter_filter_en:1 ; +u8 f11_2d_ctrl6_b3__7:6 ; + +/* control 23 */ +u8 proximity_detection_z_threshold; + +/* control 24 */ +u8 proximity_delta_x_threshold; + +/* control 25 */ +u8 proximity_delta_y_threshold; + +/* control 26 */ +u8 proximity_delta_z_threshold; + } __attribute__((__packed__ )); +u8 regs[5 ]; +}; + +/** +* @palm_detecy_sensitivity - When this value is small, smaller objects will +* be identified as palms; when this value is large, only larger objects will +* be identified as palms. 0 represents the factory default. +* @suppress_on_palm_detect - when set, all F11 interrupts except palm_detect +* are suppressed while a palm is detected. +*/ +union f11_2d_ctrl27 { +struct { +s8 palm_detect_sensitivity:4 ; +bool suppress_on_palm_detect:1 ; +u8 f11_2d_ctrl27_b5__7:3 ; + } __attribute__((__packed__ )); +u8 regs[1 ]; +}; + +/** +* @multi_finger_scroll_mode - allows choice of multi-finger scroll mode and +* determines whether and how X or Y displacements are reported. +* @edge_motion_en - enables the edge_motion feature. +* @multi_finger_scroll_momentum - controls the length of time that scrolling +* continues after fingers have been lifted. +*/ +union f11_2d_ctrl28 { +struct { +u8 multi_finger_scroll_mode:2 ; +bool edge_motion_en:1 ; +bool f11_2d_ctrl28b_3:1 ; +u8 multi_finger_scroll_momentum:4 ; + } __attribute__((__packed__ )); +u8 regs[1 ]; +}; + +/** +* @z_touch_threshold - Specifies the finger-arrival Z threshold. Large values +* may cause smaller fingers to be rejected. +* @z_touch_hysteresis - Specifies the difference between the finger-arrival +* Z threshold and the finger-departure Z threshold. +*/ +union f11_2d_ctrl29_30 { +struct { +u8 z_touch_threshold; +u8 z_touch_hysteresis; + } __attribute__((__packed__ )); +struct { +u8 regs[2 ]; +u16 address; + } __attribute__((__packed__ )); +}; + + +struct f11_2d_ctrl { +union f11_2d_ctrl0_9 *ctrl0_9; +union f11_2d_ctrl10 *ctrl10; +union f11_2d_ctrl11 *ctrl11; +union f11_2d_ctrl12 *ctrl12; +u8 ctrl12_size; +union f11_2d_ctrl14 *ctrl14; +union f11_2d_ctrl15 *ctrl15; +union f11_2d_ctrl16 *ctrl16; +union f11_2d_ctrl17 *ctrl17; +union f11_2d_ctrl18_19 *ctrl18_19; +union f11_2d_ctrl20_21 *ctrl20_21; +union f11_2d_ctrl22_26 *ctrl22_26; +union f11_2d_ctrl27 *ctrl27; +union f11_2d_ctrl28 *ctrl28; +union f11_2d_ctrl29_30 *ctrl29_30; +}; + +/** +* @x_msb - top 8 bits of X finger position. +* @y_msb - top 8 bits of Y finger position. +* @x_lsb - bottom 4 bits of X finger position. +* @y_lsb - bottom 4 bits of Y finger position. +* @w_y - contact patch width along Y axis. +* @w_x - contact patch width along X axis. +* @z - finger Z value (proxy for pressure). +*/ +struct f11_2d_data_1_5 { +u8 x_msb; +u8 y_msb; +u8 x_lsb:4 ; +u8 y_lsb:4 ; +u8 w_y:4 ; +u8 w_x:4 ; +u8 z; +}; + +/** +* @delta_x - relative motion along X axis. +* @delta_y - relative motion along Y axis. +*/ +struct f11_2d_data_6_7 { +s8 delta_x; +s8 delta_y; +}; + +/** +* @single_tap - a single tap was recognized. +* @tap_and_hold - a tap-and-hold gesture was recognized. +* @double_tap - a double tap gesture was recognized. +* @early_tap - a tap gesture might be happening. +* @flick - a flick gesture was detected. +* @press - a press gesture was recognized. +* @pinch - a pinch gesture was detected. +*/ +struct f11_2d_data_8 { +bool single_tap:1 ; +bool tap_and_hold:1 ; +bool double_tap:1 ; +bool early_tap:1 ; +bool flick:1 ; +bool press:1 ; +bool pinch:1 ; +}; + +/** +* @palm_detect - a palm or other large object is in contact with the sensor. +* @rotate - a rotate gesture was detected. +* @shape - a TouchShape has been activated. +* @scrollzone - scrolling data is available. +* @finger_count - number of fingers involved in the reported gesture. +*/ +struct f11_2d_data_9 { +bool palm_detect:1 ; +bool rotate:1 ; +bool shape:1 ; +bool scrollzone:1 ; +u8 finger_count:3 ; +}; + +/** +* @pinch_motion - when a pinch gesture is detected, this is the change in +* distance between the two fingers since this register was last read. +*/ +struct f11_2d_data_10 { +s8 pinch_motion; +}; + +/** +* @x_flick_dist - when a flick gesture is detected, the distance of flick +* gesture in X direction. +* @y_flick_dist - when a flick gesture is detected, the distance of flick +* gesture in Y direction. +* @flick_time - the total time of the flick gesture, in 10ms units. +*/ +struct f11_2d_data_10_12 { +s8 x_flick_dist; +s8 y_flick_dist; +u8 flick_time; +}; + +/** +* @motion - when a rotate gesture is detected, the accumulated distance +* of the rotate motion. Clockwise motion is positive and counterclockwise +* motion is negative. +* @finger_separation - when a rotate gesture is detected, the distance +* between the fingers. +*/ +struct f11_2d_data_11_12 { +s8 motion; +u8 finger_separation; +}; + +/** +* @shape_n - a bitmask of the currently activate TouchShapes (if any). +*/ +struct f11_2d_data_13 { +u8 shape_n; +}; + +/** +* @horizontal - chiral scrolling distance in the X direction. +* @vertical - chiral scrolling distance in the Y direction. +*/ +struct f11_2d_data_14_15 { +s8 horizontal; +s8 vertical; +}; + +/** +* @x_low - scroll zone motion along the lower edge of the sensor. +* @y_right - scroll zone motion along the right edge of the sensor. +* @x_upper - scroll zone motion along the upper edge of the sensor. +* @y_left - scroll zone motion along the left edge of the sensor. +*/ +struct f11_2d_data_14_17 { +s8 x_low; +s8 y_right; +s8 x_upper; +s8 y_left; +}; + +struct f11_2d_data { +u8 *f_state; +const struct f11_2d_data_1_5 *abs_pos; +const struct f11_2d_data_6_7 *rel_pos; +const struct f11_2d_data_8 *gest_1; +const struct f11_2d_data_9 *gest_2; +const struct f11_2d_data_10 *pinch; +const struct f11_2d_data_10_12 *flick; +const struct f11_2d_data_11_12 *rotate; +const struct f11_2d_data_13 *shapes; +const struct f11_2d_data_14_15 *multi_scroll; +const struct f11_2d_data_14_17 *scroll_zones; +}; + +struct f11_2d_sensor { +struct rmi_f11_2d_axis_alignment axis_align; +struct f11_2d_sensor_query sens_query; +struct f11_2d_data data; +int prev_x[F11_MAX_NUM_OF_FINGERS ]; +int prev_y[F11_MAX_NUM_OF_FINGERS ]; +u16 max_x; +u16 max_y; +u8 nbr_fingers; +u8 finger_tracker[F11_MAX_NUM_OF_FINGERS ]; +u8 *data_pkt; +int pkt_size; +u8 sensor_index; +u8 *button_map; +struct rmi_f11_virtualbutton_map virtual_buttons; +bool type_a; +char input_name[MAX_NAME_LENGTH ]; +char input_phys[MAX_NAME_LENGTH ]; +struct input_dev *input; +struct input_dev *mouse_input; +struct rmi_function_container *fc; + +#ifdef CONFIG_RMI4_DEBUG +struct dentry *debugfs_flip; +struct dentry *debugfs_clip; +struct dentry *debugfs_delta_threshold; +struct dentry *debugfs_offset; +struct dentry *debugfs_swap; +struct dentry *debugfs_type_a; +#endif +}; + +struct f11_data { +struct f11_2d_device_query dev_query; +struct f11_2d_ctrl dev_controls; +struct mutex dev_controls_mutex; +u16 rezero_wait_ms; +struct f11_2d_sensor sensors[F11_MAX_NUM_OF_SENSORS ]; + +#ifdef CONFIG_RMI4_DEBUG +struct dentry *debugfs_rezero_wait; +#endif +}; + +enum finger_state_values { +F11_NO_FINGER =0x00 , +F11_PRESENT =0x01 , +F11_INACCURATE =0x02 , +F11_RESERVED =0x03 +}; + +/* ctrl sysfs files */ +show_store_union_struct_prototype(abs_pos_filt) +show_store_union_struct_prototype(z_touch_threshold) +show_store_union_struct_prototype(z_touch_hysteresis) + +#ifdef CONFIG_RMI4_DEBUG + +struct sensor_debugfs_data { +bool done; +struct f11_2d_sensor *sensor; +}; + +static int sensor_debug_open (struct inode *inodep,struct file *filp) +{ +struct sensor_debugfs_data *data; +struct f11_2d_sensor *sensor = inodep->i_private; +struct rmi_function_container *fc = sensor->fc; + + data =devm_kzalloc (&fc->dev,sizeof (struct sensor_debugfs_data ), +GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + data->sensor = sensor; + filp->private_data = data; +return 0 ; +} + +static ssize_t flip_read (struct file *filp,char __user *buffer,size_t size, +loff_t *offset) { +int retval; +char local_buf[size]; +struct sensor_debugfs_data *data = filp->private_data; + +if (data->done) +return 0 ; + + data->done =1 ; + + retval =snprintf (local_buf, size,"%u %u\n" , + data->sensor->axis_align.flip_x, + data->sensor->axis_align.flip_y); + +if (retval <=0 ||copy_to_user (buffer, local_buf, retval)) +return -EFAULT ; + +return retval; +} + +static ssize_t flip_write (struct file *filp,const char __user *buffer, +size_t size,loff_t *offset) { +int retval; +char local_buf[size]; +unsigned int new_X; +unsigned int new_Y; +struct sensor_debugfs_data *data = filp->private_data; + + retval =copy_from_user (local_buf, buffer, size); +if (retval) +return -EFAULT ; + + retval =sscanf (local_buf,"%u %u" , &new_X, &new_Y); +if (retval !=2 || new_X >1 || new_Y >1 ) +return -EINVAL ; + + data->sensor->axis_align.flip_x = new_X; + data->sensor->axis_align.flip_y = new_Y; + +return size; +} + +static const struct file_operations flip_fops = { + .owner =THIS_MODULE , + .open = sensor_debug_open, + .read = flip_read, + .write = flip_write, +}; + + +static ssize_t delta_threshold_read (struct file *filp,char __user *buffer, +size_t size,loff_t *offset) { +int retval; +char local_buf[size]; +struct sensor_debugfs_data *data = filp->private_data; +struct f11_data *f11 = data->sensor->fc->data; +struct f11_2d_ctrl *ctrl = &f11->dev_controls; + +if (data->done) +return 0 ; + + data->done =1 ; + + retval =snprintf (local_buf, size,"%u %u\n" , + ctrl->ctrl0_9->delta_x_threshold, + ctrl->ctrl0_9->delta_y_threshold); + +if (retval <=0 ||copy_to_user (buffer, local_buf, retval)) +return -EFAULT ; + +return retval; +} + +static ssize_t delta_threshold_write (struct file *filp, +const char __user *buffer,size_t size,loff_t *offset) { +int retval; +char local_buf[size]; +unsigned int new_X, new_Y; +u8 save_X, save_Y; +int rc; +struct sensor_debugfs_data *data = filp->private_data; +struct f11_data *f11 = data->sensor->fc->data; +struct f11_2d_ctrl *ctrl = &f11->dev_controls; +struct rmi_device *rmi_dev = data->sensor->fc->rmi_dev; + + retval =copy_from_user (local_buf, buffer, size); +if (retval) +return -EFAULT ; + + retval =sscanf (local_buf,"%u %u" , &new_X, &new_Y); +if (retval !=2 || new_X >1 || new_Y >1 ) +return -EINVAL ; + + save_X = ctrl->ctrl0_9->delta_x_threshold; + save_Y = ctrl->ctrl0_9->delta_y_threshold; + + ctrl->ctrl0_9->delta_x_threshold = new_X; + ctrl->ctrl0_9->delta_y_threshold = new_Y; + rc =rmi_write_block (rmi_dev, + ctrl->ctrl0_9->address, + ctrl->ctrl0_9->regs, +sizeof (ctrl->ctrl0_9->regs)); +if (rc <0 ) { +dev_warn (&data->sensor->fc->dev, +"Failed to write to delta_threshold. Code: %d.\n" , + rc); + ctrl->ctrl0_9->delta_x_threshold = save_X; + ctrl->ctrl0_9->delta_y_threshold = save_Y; + } +return size; +} + +static const struct file_operations delta_threshold_fops = { + .owner =THIS_MODULE , + .open = sensor_debug_open, + .read = delta_threshold_read, + .write = delta_threshold_write, +}; + +static ssize_t offset_read (struct file *filp,char __user *buffer,size_t size, +loff_t *offset) { +int retval; +char local_buf[size]; +struct sensor_debugfs_data *data = filp->private_data; + +if (data->done) +return 0 ; + + data->done =1 ; + retval =snprintf (local_buf, size,"%u %u\n" , + data->sensor->axis_align.offset_X, + data->sensor->axis_align.offset_Y); + +if (retval <=0 ||copy_to_user (buffer, local_buf, retval)) +return -EFAULT ; + +return retval; +} + +static ssize_t offset_write (struct file *filp,const char __user *buffer, +size_t size,loff_t *offset) +{ +int retval; +char local_buf[size]; +int new_X; +int new_Y; +struct sensor_debugfs_data *data = filp->private_data; + + retval =copy_from_user (local_buf, buffer, size); +if (retval) +return -EFAULT ; + retval =sscanf (local_buf,"%u %u" , &new_X, &new_Y); +if (retval !=2 ) +return -EINVAL ; + + data->sensor->axis_align.offset_X = new_X; + data->sensor->axis_align.offset_Y = new_Y; + +return size; +} + +static const struct file_operations offset_fops = { + .owner =THIS_MODULE , + .open = sensor_debug_open, + .read = offset_read, + .write = offset_write, +}; + +static ssize_t clip_read (struct file *filp,char __user *buffer,size_t size, +loff_t *offset) { +int retval; +char local_buf[size]; +struct sensor_debugfs_data *data = filp->private_data; + +if (data->done) +return 0 ; + + data->done =1 ; + + retval =snprintf (local_buf, size,"%u %u %u %u\n" , + data->sensor->axis_align.clip_X_low, + data->sensor->axis_align.clip_X_high, + data->sensor->axis_align.clip_Y_low, + data->sensor->axis_align.clip_Y_high); + +if (retval <=0 ||copy_to_user (buffer, local_buf, retval)) +return -EFAULT ; + +return retval; +} + +static ssize_t clip_write (struct file *filp,const char __user *buffer, +size_t size,loff_t *offset) +{ +int retval; +char local_buf[size]; +unsigned int new_X_low, new_X_high, new_Y_low, new_Y_high; +struct sensor_debugfs_data *data = filp->private_data; + + retval =copy_from_user (local_buf, buffer, size); +if (retval) +return -EFAULT ; + + retval =sscanf (local_buf,"%u %u %u %u" , + &new_X_low, &new_X_high, &new_Y_low, &new_Y_high); +if (retval !=4 ) +return -EINVAL ; + +if (new_X_low >= new_X_high || new_Y_low >= new_Y_high) +return -EINVAL ; + + data->sensor->axis_align.clip_X_low = new_X_low; + data->sensor->axis_align.clip_X_high = new_X_high; + data->sensor->axis_align.clip_Y_low = new_Y_low; + data->sensor->axis_align.clip_Y_high = new_Y_high; + +return size; +} + +static const struct file_operations clip_fops = { + .owner =THIS_MODULE , + .open = sensor_debug_open, + .read = clip_read, + .write = clip_write, +}; + +static ssize_t swap_read (struct file *filp,char __user *buffer,size_t size, +loff_t *offset) { +int retval; +char local_buf[size]; +struct sensor_debugfs_data *data = filp->private_data; + +if (data->done) +return 0 ; + + data->done =1 ; + + retval =snprintf (local_buf, size,"%u\n" , + data->sensor->axis_align.swap_axes); + +if (retval <=0 ||copy_to_user (buffer, local_buf, retval)) +return -EFAULT ; + +return retval; +} + +static ssize_t swap_write (struct file *filp,const char __user *buffer, +size_t size,loff_t *offset) +{ +int retval; +char local_buf[size]; +int new_value; +struct sensor_debugfs_data *data = filp->private_data; + + retval =copy_from_user (local_buf, buffer, size); +if (retval) +return -EFAULT ; + retval =sscanf (local_buf,"%u" , &new_value); +if (retval !=1 || new_value >1 ) +return -EINVAL ; + + data->sensor->axis_align.swap_axes = new_value; +return size; +} + +static const struct file_operations swap_fops = { + .owner =THIS_MODULE , + .open = sensor_debug_open, + .read = swap_read, + .write = swap_write, +}; + +static ssize_t type_a_read (struct file *filp,char __user *buffer,size_t size, +loff_t *offset) { +int retval; +char local_buf[size]; +struct sensor_debugfs_data *data = filp->private_data; + +if (data->done) +return 0 ; + + data->done =1 ; + + retval =snprintf (local_buf, size,"%u\n" , + data->sensor->type_a); + +if (retval <=0 ||copy_to_user (buffer, local_buf, retval)) +return -EFAULT ; + +return retval; +} + +static ssize_t type_a_write (struct file *filp,const char __user *buffer, +size_t size,loff_t *offset) +{ +int retval; +char local_buf[size]; +int new_value; +struct sensor_debugfs_data *data = filp->private_data; + + retval =copy_from_user (local_buf, buffer, size); +if (retval) +return -EFAULT ; + retval =sscanf (local_buf,"%u" , &new_value); +if (retval !=1 || new_value >1 ) +return -EINVAL ; + + data->sensor->type_a = new_value; +return size; +} + +static const struct file_operations type_a_fops = { + .owner =THIS_MODULE , + .open = sensor_debug_open, + .read = type_a_read, + .write = type_a_write, +}; + + +static int setup_sensor_debugfs (struct f11_2d_sensor *sensor) +{ +int retval =0 ; +char fname[MAX_NAME_LENGTH ]; +struct rmi_function_container *fc = sensor->fc; +struct rmi_device *rmi_dev = fc->rmi_dev; + +if (!fc->debugfs_root) +return -ENODEV ; + + retval =snprintf (fname,MAX_NAME_LENGTH ,"flip.%d" , + sensor->sensor_index); + sensor->debugfs_flip =debugfs_create_file (fname,RMI_RW_ATTR , + fc->debugfs_root, sensor, &flip_fops); +if (!sensor->debugfs_flip) +dev_warn (&rmi_dev->dev,"Failed to create debugfs %s.\n" , + fname); + + retval =snprintf (fname,MAX_NAME_LENGTH ,"clip.%d" , + sensor->sensor_index); + sensor->debugfs_clip =debugfs_create_file (fname,RMI_RW_ATTR , + fc->debugfs_root, sensor, &clip_fops); +if (!sensor->debugfs_clip) +dev_warn (&rmi_dev->dev,"Failed to create debugfs %s.\n" , + fname); + + retval =snprintf (fname,MAX_NAME_LENGTH ,"delta_threshold.%d" , + sensor->sensor_index); + sensor->debugfs_clip =debugfs_create_file (fname,RMI_RW_ATTR , + fc->debugfs_root, sensor, + &delta_threshold_fops); +if (!sensor->debugfs_delta_threshold) +dev_warn (&rmi_dev->dev,"Failed to create debugfs %s.\n" , + fname); + + retval =snprintf (fname,MAX_NAME_LENGTH ,"offset.%d" , + sensor->sensor_index); + sensor->debugfs_offset =debugfs_create_file (fname,RMI_RW_ATTR , + fc->debugfs_root, sensor, &offset_fops); +if (!sensor->debugfs_offset) +dev_warn (&rmi_dev->dev,"Failed to create debugfs %s.\n" , + fname); + + retval =snprintf (fname,MAX_NAME_LENGTH ,"swap.%d" , + sensor->sensor_index); + sensor->debugfs_swap =debugfs_create_file (fname,RMI_RW_ATTR , + fc->debugfs_root, sensor, &swap_fops); +if (!sensor->debugfs_swap) +dev_warn (&rmi_dev->dev,"Failed to create debugfs %s.\n" , + fname); + + retval =snprintf (fname,MAX_NAME_LENGTH ,"type_a.%d" , + sensor->sensor_index); + sensor->debugfs_type_a =debugfs_create_file (fname,RMI_RW_ATTR , + fc->debugfs_root, sensor, &type_a_fops); +if (!sensor->debugfs_type_a) +dev_warn (&rmi_dev->dev,"Failed to create debugfs %s.\n" , + fname); + +return retval; +} + +static void teardown_sensor_debugfs (struct f11_2d_sensor *sensor) +{ +if (sensor->debugfs_flip) +debugfs_remove (sensor->debugfs_flip); + +if (sensor->debugfs_clip) +debugfs_remove (sensor->debugfs_clip); + +if (sensor->debugfs_offset) +debugfs_remove (sensor->debugfs_offset); + +if (sensor->debugfs_swap) +debugfs_remove (sensor->debugfs_swap); + +if (sensor->debugfs_type_a) +debugfs_remove (sensor->debugfs_type_a); +} + +struct f11_debugfs_data { +bool done; +struct rmi_function_container *fc; +}; + +static int f11_debug_open (struct inode *inodep,struct file *filp) +{ +struct f11_debugfs_data *data; +struct rmi_function_container *fc = inodep->i_private; + + data =devm_kzalloc (&fc->dev,sizeof (struct f11_debugfs_data ), +GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + data->fc = fc; + filp->private_data = data; +return 0 ; +} + +static ssize_t rezero_wait_read (struct file *filp,char __user *buffer, +size_t size,loff_t *offset) { +int retval; +char local_buf[size]; +struct f11_debugfs_data *data = filp->private_data; +struct f11_data *f11 = data->fc->data; + +if (data->done) +return 0 ; + + data->done =1 ; + + retval =snprintf (local_buf, size,"%u\n" , f11->rezero_wait_ms); + +if (retval <=0 ||copy_to_user (buffer, local_buf, retval)) +return -EFAULT ; + +return retval; +} + +static ssize_t rezero_wait_write (struct file *filp,const char __user *buffer, +size_t size,loff_t *offset) +{ +int retval; +char local_buf[size]; +int new_value; +struct f11_debugfs_data *data = filp->private_data; +struct f11_data *f11 = data->fc->data; + + retval =copy_from_user (local_buf, buffer, size); +if (retval) +return -EFAULT ; + retval =sscanf (local_buf,"%u" , &new_value); +if (retval !=1 || new_value >65535 ) +return -EINVAL ; + + f11->rezero_wait_ms = new_value; +return size; +} + +static const struct file_operations rezero_wait_fops = { + .owner =THIS_MODULE , + .open = f11_debug_open, + .read = rezero_wait_read, + .write = rezero_wait_write, +}; + +static int setup_f11_debugfs (struct rmi_function_container *fc) +{ +struct f11_data *f11 = fc->data; + +if (!fc->debugfs_root) +return -ENODEV ; + + f11->debugfs_rezero_wait =debugfs_create_file ("rezero_wait" , +RMI_RW_ATTR , fc->debugfs_root, fc, &rezero_wait_fops); +if (!f11->debugfs_rezero_wait) +dev_warn (&fc->dev, +"Failed to create debugfs rezero_wait.\n" ); + +return 0 ; +} + +static void teardown_f11_debugfs (struct f11_data *f11) +{ +if (f11->debugfs_rezero_wait) +debugfs_remove (f11->debugfs_rezero_wait); +} +#endif +/* End adding debugfs */ + +/* This is a group in case we add the other ctrls. */ +static struct attribute *attrs_ctrl0[] = { +attrify (abs_pos_filt), +NULL +}; +static struct attribute_group attrs_control0 =GROUP (attrs_ctrl0); + +static struct attribute *attrs_ctrl29_30[] = { +attrify (z_touch_threshold), +attrify (z_touch_hysteresis), +NULL +}; +static struct attribute_group attrs_control29_30 =GROUP (attrs_ctrl29_30); + +/** F11_INACCURATE state is overloaded to indicate pen present. */ +#define F11_PEN F11_INACCURATE + +static int get_tool_type (struct f11_2d_sensor *sensor,u8 finger_state) +{ +if (IS_ENABLED (CONFIG_RMI4_F11_PEN ) && + sensor->sens_query.query9.has_pen && + finger_state ==F11_PEN ) +return MT_TOOL_PEN ; +return MT_TOOL_FINGER ; +} + +static void rmi_f11_rel_pos_report (struct f11_2d_sensor *sensor,u8 n_finger) +{ +struct f11_2d_data *data = &sensor->data; +struct rmi_f11_2d_axis_alignment *axis_align = &sensor->axis_align; +s8 x, y; +s8 temp; + + x = data->rel_pos[n_finger].delta_x; + y = data->rel_pos[n_finger].delta_y; + + x =min (F11_REL_POS_MAX ,max (F11_REL_POS_MIN , (int )x)); + y =min (F11_REL_POS_MAX ,max (F11_REL_POS_MIN , (int )y)); + +if (axis_align->swap_axes) { + temp = x; + x = y; + y = temp; + } +if (axis_align->flip_x) + x =min (F11_REL_POS_MAX , -x); +if (axis_align->flip_y) + y =min (F11_REL_POS_MAX , -y); + +if (x || y) { +input_report_rel (sensor->input,REL_X , x); +input_report_rel (sensor->input,REL_Y , y); +input_report_rel (sensor->mouse_input,REL_X , x); +input_report_rel (sensor->mouse_input,REL_Y , y); + } +input_sync (sensor->mouse_input); +} + +static void rmi_f11_abs_pos_report (struct f11_data *f11, +struct f11_2d_sensor *sensor, +u8 finger_state,u8 n_finger) +{ +struct f11_2d_data *data = &sensor->data; +struct rmi_f11_2d_axis_alignment *axis_align = &sensor->axis_align; +u8 prev_state = sensor->finger_tracker[n_finger]; +int x, y, z; +int w_x, w_y, w_max, w_min, orient; +int temp; + +if (prev_state && !finger_state) { +/* this is a release */ + x = y = z = w_max = w_min = orient =0 ; + }else if (!prev_state && !finger_state) { +/* nothing to report */ +return ; + }else { + x = ((data->abs_pos[n_finger].x_msb <<4 ) | + data->abs_pos[n_finger].x_lsb); + y = ((data->abs_pos[n_finger].y_msb <<4 ) | + data->abs_pos[n_finger].y_lsb); + z = data->abs_pos[n_finger].z; + w_x = data->abs_pos[n_finger].w_x; + w_y = data->abs_pos[n_finger].w_y; + w_max =max (w_x, w_y); + w_min =min (w_x, w_y); + +if (axis_align->swap_axes) { + temp = x; + x = y; + y = temp; + temp = w_x; + w_x = w_y; + w_y = temp; + } + + orient = w_x > w_y ?1 :0 ; + +if (axis_align->flip_x) + x =max (sensor->max_x - x,0 ); + +if (axis_align->flip_y) + y =max (sensor->max_y - y,0 ); + +/* +** here checking if X offset or y offset are specified is +** redundant. We just add the offsets or, clip the values +** +** note: offsets need to be done before clipping occurs, +** or we could get funny values that are outside +** clipping boundaries. +*/ + x += axis_align->offset_X; + y += axis_align->offset_Y; + x =max (axis_align->clip_X_low, x); + y =max (axis_align->clip_Y_low, y); +if (axis_align->clip_X_high) + x =min (axis_align->clip_X_high, x); +if (axis_align->clip_Y_high) + y =min (axis_align->clip_Y_high, y); + + } + +/* Some UIs ignore W of zero, so we fudge it to 1 for pens. */ +if (IS_ENABLED (CONFIG_RMI4_F11_PEN ) && +get_tool_type (sensor, finger_state) ==MT_TOOL_PEN ) { + w_max =max (1 , w_max); + w_min =max (1 , w_min); + } + +if (sensor->type_a) { +input_report_abs (sensor->input,ABS_MT_TRACKING_ID , n_finger); +input_report_abs (sensor->input,ABS_MT_TOOL_TYPE , +get_tool_type (sensor, finger_state)); + }else { +input_mt_slot (sensor->input, n_finger); +input_mt_report_slot_state (sensor->input, +get_tool_type (sensor, finger_state), finger_state); + } + +input_report_abs (sensor->input,ABS_MT_PRESSURE , z); +input_report_abs (sensor->input,ABS_MT_TOUCH_MAJOR , w_max); +input_report_abs (sensor->input,ABS_MT_TOUCH_MINOR , w_min); +input_report_abs (sensor->input,ABS_MT_ORIENTATION , orient); +input_report_abs (sensor->input,ABS_MT_POSITION_X , x); +input_report_abs (sensor->input,ABS_MT_POSITION_Y , y); +dev_dbg (&sensor->fc->dev, +"finger[%d]:%d - x:%d y:%d z:%d w_max:%d w_min:%d\n" , + n_finger, finger_state, x, y, z, w_max, w_min); +/* MT sync between fingers */ +if (sensor->type_a) +input_mt_sync (sensor->input); + + sensor->finger_tracker[n_finger] = finger_state; +} + +#ifdef CONFIG_RMI4_VIRTUAL_BUTTON +static int rmi_f11_virtual_button_handler (struct f11_2d_sensor *sensor) +{ +int i; +int x; +int y; +struct rmi_button_map *virtualbutton_map; + +if (sensor->sens_query.has_gestures && + sensor->data.gest_1->single_tap) { + virtualbutton_map = &sensor->virtualbutton_map; + x = ((sensor->data.abs_pos[0 ].x_msb <<4 ) | + sensor->data.abs_pos[0 ].x_lsb); + y = ((sensor->data.abs_pos[0 ].y_msb <<4 ) | + sensor->data.abs_pos[0 ].y_lsb); +for (i =0 ; i < virtualbutton_map->buttons; i++) { +if (INBOX (x, y, virtualbutton_map->map[i])) { +input_report_key (sensor->input, + virtualbutton_map->map[i].code,1 ); +input_report_key (sensor->input, + virtualbutton_map->map[i].code,0 ); +input_sync (sensor->input); +return 0 ; + } + } + } +return 0 ; +} +#else +#define rmi_f11_virtual_button_handler (sensor) +#endif +static void rmi_f11_finger_handler (struct f11_data *f11, +struct f11_2d_sensor *sensor) +{ +const u8 *f_state = sensor->data.f_state; +u8 finger_state; +u8 finger_pressed_count; +u8 i; + +for (i =0 , finger_pressed_count =0 ; i < sensor->nbr_fingers; i++) { +/* Possible of having 4 fingers per f_statet register */ + finger_state =GET_FINGER_STATE (f_state, i); + +if (finger_state ==F11_RESERVED ) { +pr_err ("%s: Invalid finger state[%d]:0x%02x." , __func__, + i, finger_state); +continue ; + }else if ((finger_state ==F11_PRESENT ) || + (finger_state ==F11_INACCURATE )) { + finger_pressed_count++; + } + +if (sensor->data.abs_pos) +rmi_f11_abs_pos_report (f11, sensor, finger_state, i); + +if (sensor->data.rel_pos) +rmi_f11_rel_pos_report (sensor, i); + } +input_report_key (sensor->input,BTN_TOUCH , finger_pressed_count); +input_sync (sensor->input); +} + +static int f11_2d_construct_data (struct f11_2d_sensor *sensor) +{ +struct f11_2d_sensor_query *query = &sensor->sens_query; +struct f11_2d_data *data = &sensor->data; +int i; + + sensor->nbr_fingers = (query->number_of_fingers ==5 ?10 : + query->number_of_fingers +1 ); + + sensor->pkt_size =F11_CEIL (sensor->nbr_fingers,4 ); + +if (query->has_abs) + sensor->pkt_size += (sensor->nbr_fingers *5 ); + +if (query->has_rel) + sensor->pkt_size += (sensor->nbr_fingers *2 ); + +/* Check if F11_2D_Query7 is non-zero */ +if (query->f11_2d_query7__8[0 ]) + sensor->pkt_size +=sizeof (u8); + +/* Check if F11_2D_Query7 or F11_2D_Query8 is non-zero */ +if (query->f11_2d_query7__8[0 ] || query->f11_2d_query7__8[1 ]) + sensor->pkt_size +=sizeof (u8); + +if (query->has_pinch || query->has_flick || query->has_rotate) { + sensor->pkt_size +=3 ; +if (!query->has_flick) + sensor->pkt_size--; +if (!query->has_rotate) + sensor->pkt_size--; + } + +if (query->has_touch_shapes) + sensor->pkt_size +=F11_CEIL (query->nbr_touch_shapes +1 ,8 ); + + sensor->data_pkt =kzalloc (sensor->pkt_size,GFP_KERNEL ); +if (!sensor->data_pkt) +return -ENOMEM ; + + data->f_state = sensor->data_pkt; + i =F11_CEIL (sensor->nbr_fingers,4 ); + +if (query->has_abs) { + data->abs_pos = (struct f11_2d_data_1_5 *) + &sensor->data_pkt[i]; + i += (sensor->nbr_fingers *5 ); + } + +if (query->has_rel) { + data->rel_pos = (struct f11_2d_data_6_7 *) + &sensor->data_pkt[i]; + i += (sensor->nbr_fingers *2 ); + } + +if (query->f11_2d_query7__8[0 ]) { + data->gest_1 = (struct f11_2d_data_8 *)&sensor->data_pkt[i]; + i++; + } + +if (query->f11_2d_query7__8[0 ] || query->f11_2d_query7__8[1 ]) { + data->gest_2 = (struct f11_2d_data_9 *)&sensor->data_pkt[i]; + i++; + } + +if (query->has_pinch) { + data->pinch = (struct f11_2d_data_10 *)&sensor->data_pkt[i]; + i++; + } + +if (query->has_flick) { +if (query->has_pinch) { + data->flick = (struct f11_2d_data_10_12 *)data->pinch; + i +=2 ; + }else { + data->flick = (struct f11_2d_data_10_12 *) + &sensor->data_pkt[i]; + i +=3 ; + } + } + +if (query->has_rotate) { +if (query->has_flick) { + data->rotate = (struct f11_2d_data_11_12 *) + (data->flick +1 ); + }else { + data->rotate = (struct f11_2d_data_11_12 *) + &sensor->data_pkt[i]; + i +=2 ; + } + } + +if (query->has_touch_shapes) + data->shapes = (struct f11_2d_data_13 *)&sensor->data_pkt[i]; + +return 0 ; +} + +static int f11_read_control_regs (struct rmi_device *rmi_dev, +struct f11_2d_ctrl *ctrl, +u16 ctrl_base_addr) { +u16 read_address = ctrl_base_addr; +int error =0 ; + + ctrl->ctrl0_9->address = read_address; + error =rmi_read_block (rmi_dev, read_address, ctrl->ctrl0_9->regs, +sizeof (ctrl->ctrl0_9->regs)); +if (error <0 ) { +dev_err (&rmi_dev->dev, +"Failed to read F11 ctrl0, code: %d.\n" , error); +return error; + } + read_address = read_address +sizeof (ctrl->ctrl0_9->regs); + +if (ctrl->ctrl10) { + error =rmi_read_block (rmi_dev, read_address, + &ctrl->ctrl10->reg,sizeof (union f11_2d_ctrl10 )); +if (error <0 ) { +dev_err (&rmi_dev->dev, +"Failed to read F11 ctrl10, code: %d.\n" , + error); +return error; + } + read_address = read_address +sizeof (union f11_2d_ctrl10 ); + } + +if (ctrl->ctrl11) { + error =rmi_read_block (rmi_dev, read_address, + &ctrl->ctrl11->reg,sizeof (union f11_2d_ctrl11 )); +if (error <0 ) { +dev_err (&rmi_dev->dev, +"Failed to read F11 ctrl11, code: %d.\n" , + error); +return error; + } + read_address = read_address +sizeof (union f11_2d_ctrl11 ); + } + +if (ctrl->ctrl14) { + error =rmi_read_block (rmi_dev, read_address, + &ctrl->ctrl14->reg,sizeof (union f11_2d_ctrl14 )); +if (error <0 ) { +dev_err (&rmi_dev->dev, +"Failed to read F11 ctrl14, code: %d.\n" , + error); +return error; + } + read_address = read_address +sizeof (union f11_2d_ctrl14 ); + } + +if (ctrl->ctrl15) { + error =rmi_read_block (rmi_dev, read_address, + &ctrl->ctrl15->reg,sizeof (union f11_2d_ctrl15 )); +if (error <0 ) { +dev_err (&rmi_dev->dev, +"Failed to read F11 ctrl15, code: %d.\n" , + error); +return error; + } + read_address = read_address +sizeof (union f11_2d_ctrl15 ); + } + +if (ctrl->ctrl16) { + error =rmi_read_block (rmi_dev, read_address, + &ctrl->ctrl16->reg,sizeof (union f11_2d_ctrl16 )); +if (error <0 ) { +dev_err (&rmi_dev->dev, +"Failed to read F11 ctrl16, code: %d.\n" , + error); +return error; + } + read_address = read_address +sizeof (union f11_2d_ctrl16 ); + } + +if (ctrl->ctrl17) { + error =rmi_read_block (rmi_dev, read_address, + &ctrl->ctrl17->reg,sizeof (union f11_2d_ctrl17 )); +if (error <0 ) { +dev_err (&rmi_dev->dev, +"Failed to read F11 ctrl17, code: %d.\n" , + error); +return error; + } + read_address = read_address +sizeof (union f11_2d_ctrl17 ); + } + +if (ctrl->ctrl18_19) { + error =rmi_read_block (rmi_dev, read_address, + ctrl->ctrl18_19->reg,sizeof (union f11_2d_ctrl18_19 )); +if (error <0 ) { +dev_err (&rmi_dev->dev, +"Failed to read F11 ctrl18_19, code: %d.\n" , + error); +return error; + } + read_address = read_address +sizeof (union f11_2d_ctrl18_19 ); + } + +if (ctrl->ctrl20_21) { + error =rmi_read_block (rmi_dev, read_address, + ctrl->ctrl20_21->reg,sizeof (union f11_2d_ctrl20_21 )); +if (error <0 ) { +dev_err (&rmi_dev->dev, +"Failed to read F11 ctrl20_21, code: %d.\n" , + error); +return error; + } + read_address = read_address +sizeof (union f11_2d_ctrl20_21 ); + } + +if (ctrl->ctrl22_26) { + error =rmi_read_block (rmi_dev, read_address, + ctrl->ctrl22_26->regs,sizeof (union f11_2d_ctrl22_26 )); +if (error <0 ) { +dev_err (&rmi_dev->dev, +"Failed to read F11 ctrl22_26, code: %d.\n" , + error); +return error; + } + read_address = read_address +sizeof (union f11_2d_ctrl22_26 ); + } + +if (ctrl->ctrl27) { + error =rmi_read_block (rmi_dev, read_address, + ctrl->ctrl27->regs,sizeof (union f11_2d_ctrl27 )); +if (error <0 ) { +dev_err (&rmi_dev->dev, +"Failed to read F11 ctrl27, code: %d.\n" , + error); +return error; + } + read_address = read_address +sizeof (union f11_2d_ctrl27 ); + } + +if (ctrl->ctrl28) { + error =rmi_read_block (rmi_dev, read_address, + ctrl->ctrl28->regs,sizeof (union f11_2d_ctrl28 )); +if (error <0 ) { +dev_err (&rmi_dev->dev, +"Failed to read F11 ctrl28, code: %d.\n" , + error); +return error; + } + read_address = read_address +sizeof (union f11_2d_ctrl28 ); + } + +if (ctrl->ctrl29_30) { + ctrl->ctrl29_30->address = read_address; + error =rmi_read_block (rmi_dev, read_address, + ctrl->ctrl29_30->regs,sizeof (ctrl->ctrl29_30->regs)); +if (error <0 ) { +dev_err (&rmi_dev->dev, +"Failed to read F11 ctrl29_30, code: %d.\n" , + error); +return error; + } + read_address = read_address +sizeof (ctrl->ctrl29_30->regs); + } +return 0 ; +} + +static int f11_allocate_control_regs (struct rmi_device *rmi_dev, +struct f11_2d_device_query *device_query, +struct f11_2d_sensor_query *sensor_query, +struct f11_2d_ctrl *ctrl, +u16 ctrl_base_addr) { + +struct rmi_driver_data *driver_data =dev_get_drvdata (&rmi_dev->dev); +struct rmi_function_container *fc = driver_data->f01_container; + + ctrl->ctrl0_9 =devm_kzalloc (&fc->dev,sizeof (union f11_2d_ctrl0_9 ), +GFP_KERNEL ); +if (!ctrl->ctrl0_9) +return -ENOMEM ; +if (sensor_query->f11_2d_query7__8[0 ]) { + ctrl->ctrl10 =devm_kzalloc (&fc->dev, +sizeof (union f11_2d_ctrl10 ),GFP_KERNEL ); +if (!ctrl->ctrl10) +return -ENOMEM ; + } + +if (sensor_query->f11_2d_query7__8[1 ]) { + ctrl->ctrl11 =devm_kzalloc (&fc->dev, +sizeof (union f11_2d_ctrl11 ),GFP_KERNEL ); +if (!ctrl->ctrl11) +return -ENOMEM ; + } + +if (device_query->has_query9 && sensor_query->query9.has_pen) { + ctrl->ctrl20_21 =devm_kzalloc (&fc->dev, +sizeof (union f11_2d_ctrl20_21 ),GFP_KERNEL ); +if (!ctrl->ctrl20_21) +return -ENOMEM ; + } + +if (device_query->has_query9 && sensor_query->query9.has_proximity) { + ctrl->ctrl22_26 =devm_kzalloc (&fc->dev, +sizeof (union f11_2d_ctrl22_26 ),GFP_KERNEL ); +if (!ctrl->ctrl22_26) +return -ENOMEM ; + } + +if (device_query->has_query9 && + (sensor_query->query9.has_palm_det_sensitivity || + sensor_query->query9.has_suppress_on_palm_detect)) { + ctrl->ctrl27 =devm_kzalloc (&fc->dev, +sizeof (union f11_2d_ctrl27 ),GFP_KERNEL ); +if (!ctrl->ctrl27) +return -ENOMEM ; + } + +if (sensor_query->has_multi_finger_scroll) { + ctrl->ctrl28 =devm_kzalloc (&fc->dev, +sizeof (union f11_2d_ctrl28 ),GFP_KERNEL ); +if (!ctrl->ctrl28) +return -ENOMEM ; + } + +if (device_query->has_query11 && device_query->has_z_tuning) { + ctrl->ctrl29_30 =devm_kzalloc (&fc->dev, +sizeof (union f11_2d_ctrl29_30 ),GFP_KERNEL ); +if (!ctrl->ctrl29_30) +return -ENOMEM ; + } + +return f11_read_control_regs (rmi_dev, ctrl, ctrl_base_addr); +} + +static int f11_write_control_regs (struct rmi_device *rmi_dev, +struct f11_2d_sensor_query *query, +struct f11_2d_ctrl *ctrl, +u16 ctrl_base_addr) +{ +u16 write_address = ctrl_base_addr; +int error; + + error =rmi_write_block (rmi_dev, write_address, + ctrl->ctrl0_9->regs, +sizeof (ctrl->ctrl0_9->regs)); +if (error <0 ) +return error; + write_address +=sizeof (ctrl->ctrl0_9); + +if (ctrl->ctrl10) { + error =rmi_write_block (rmi_dev, write_address, + &ctrl->ctrl10->reg,1 ); +if (error <0 ) +return error; + write_address++; + } + +if (ctrl->ctrl11) { + error =rmi_write_block (rmi_dev, write_address, + &ctrl->ctrl11->reg,1 ); +if (error <0 ) +return error; + write_address++; + } + +if (ctrl->ctrl12 && ctrl->ctrl12_size && query->configurable) { +if (ctrl->ctrl12_size > query->max_electrodes) { +dev_err (&rmi_dev->dev, +"%s: invalid cfg size:%d, should be < %d.\n" , + __func__, ctrl->ctrl12_size, + query->max_electrodes); +return -EINVAL ; + } + error =rmi_write_block (rmi_dev, write_address, + &ctrl->ctrl12->reg, + ctrl->ctrl12_size); +if (error <0 ) +return error; + write_address += ctrl->ctrl12_size; + } + +if (ctrl->ctrl14) { + error =rmi_write_block (rmi_dev, write_address, + &ctrl->ctrl14->reg,1 ); +if (error <0 ) +return error; + write_address++; + } + +if (ctrl->ctrl15) { + error =rmi_write_block (rmi_dev, write_address, + &ctrl->ctrl15->reg,1 ); +if (error <0 ) +return error; + write_address++; + } + +if (ctrl->ctrl16) { + error =rmi_write_block (rmi_dev, write_address, + &ctrl->ctrl16->reg,1 ); +if (error <0 ) +return error; + write_address++; + } + +if (ctrl->ctrl17) { + error =rmi_write_block (rmi_dev, write_address, + &ctrl->ctrl17->reg,1 ); +if (error <0 ) +return error; + write_address++; + } + +if (ctrl->ctrl18_19) { + error =rmi_write_block (rmi_dev, write_address, + ctrl->ctrl18_19->reg,sizeof (union f11_2d_ctrl18_19 )); +if (error <0 ) +return error; + write_address +=sizeof (union f11_2d_ctrl18_19 ); + } + +if (ctrl->ctrl20_21) { + error =rmi_write_block (rmi_dev, write_address, + ctrl->ctrl20_21->reg, +sizeof (union f11_2d_ctrl20_21 )); +if (error <0 ) +return error; + write_address +=sizeof (union f11_2d_ctrl20_21 ); + } + +if (ctrl->ctrl22_26) { + error =rmi_write_block (rmi_dev, write_address, + ctrl->ctrl22_26->regs, +sizeof (union f11_2d_ctrl22_26 )); +if (error <0 ) +return error; + write_address +=sizeof (union f11_2d_ctrl22_26 ); + } + +if (ctrl->ctrl27) { + error =rmi_write_block (rmi_dev, write_address, + ctrl->ctrl27->regs, +sizeof (union f11_2d_ctrl27 )); +if (error <0 ) +return error; + write_address +=sizeof (union f11_2d_ctrl27 ); + } + +if (ctrl->ctrl28) { + error =rmi_write_block (rmi_dev, write_address, + ctrl->ctrl28->regs, +sizeof (union f11_2d_ctrl28 )); +if (error <0 ) +return error; + write_address +=sizeof (union f11_2d_ctrl28 ); + } + +if (ctrl->ctrl29_30) { + error =rmi_write_block (rmi_dev, write_address, + ctrl->ctrl29_30->regs, +sizeof (union f11_2d_ctrl29_30 )); +if (error <0 ) +return error; + write_address +=sizeof (union f11_2d_ctrl29_30 ); + } + +return 0 ; +} + +static int rmi_f11_get_query_parameters (struct rmi_device *rmi_dev, +struct f11_2d_sensor_query *query,u16 query_base_addr) +{ +int query_size; +int rc; + + rc =rmi_read_block (rmi_dev, query_base_addr, query->f11_2d_query1__4, +sizeof (query->f11_2d_query1__4)); +if (rc <0 ) +return rc; + query_size = rc; + +if (query->has_abs) { + rc =rmi_read (rmi_dev, query_base_addr + query_size, + &query->f11_2d_query5); +if (rc <0 ) +return rc; + query_size++; + } + +if (query->has_rel) { + rc =rmi_read (rmi_dev, query_base_addr + query_size, + &query->f11_2d_query6); +if (rc <0 ) +return rc; + query_size++; + } + +if (query->has_gestures) { + rc =rmi_read_block (rmi_dev, query_base_addr + query_size, + query->f11_2d_query7__8, +sizeof (query->f11_2d_query7__8)); +if (rc <0 ) +return rc; + query_size +=sizeof (query->f11_2d_query7__8); + } + +if (query->has_touch_shapes) { + rc =rmi_read (rmi_dev, query_base_addr + query_size, + &query->f11_2d_query10); +if (rc <0 ) +return rc; + query_size++; + } + +return query_size; +} + +/* This operation is done in a number of places, so we have a handy routine +* for it. +*/ +static void f11_set_abs_params (struct rmi_function_container *fc,int index) +{ +struct f11_data *f11 = fc->data; +struct f11_2d_sensor *sensor = &f11->sensors[index]; +struct input_dev *input = sensor->input; +int device_x_max = + f11->dev_controls.ctrl0_9->sensor_max_x_pos; +int device_y_max = + f11->dev_controls.ctrl0_9->sensor_max_y_pos; +int x_min, x_max, y_min, y_max; +if (sensor->axis_align.swap_axes) { +int temp = device_x_max; + device_x_max = device_y_max; + device_y_max = temp; + } +/* Use the max X and max Y read from the device, or the clip values, +* whichever is stricter. +*/ + x_min = sensor->axis_align.clip_X_low; +if (sensor->axis_align.clip_X_high) + x_max =min ((int ) device_x_max, + sensor->axis_align.clip_X_high); +else + x_max = device_x_max; + + y_min = sensor->axis_align.clip_Y_low; +if (sensor->axis_align.clip_Y_high) + y_max =min ((int ) device_y_max, + sensor->axis_align.clip_Y_high); +else + y_max = device_y_max; + +dev_dbg (&fc->dev,"Set ranges X=[%d..%d] Y=[%d..%d]." , + x_min, x_max, y_min, y_max); + +input_set_abs_params (input,ABS_MT_PRESSURE ,0 , +DEFAULT_MAX_ABS_MT_PRESSURE ,0 ,0 ); +input_set_abs_params (input,ABS_MT_TOUCH_MAJOR , +0 ,DEFAULT_MAX_ABS_MT_TOUCH ,0 ,0 ); +input_set_abs_params (input,ABS_MT_TOUCH_MINOR , +0 ,DEFAULT_MAX_ABS_MT_TOUCH ,0 ,0 ); +input_set_abs_params (input,ABS_MT_ORIENTATION , +0 ,DEFAULT_MAX_ABS_MT_ORIENTATION ,0 ,0 ); +input_set_abs_params (input,ABS_MT_TRACKING_ID , +DEFAULT_MIN_ABS_MT_TRACKING_ID , +DEFAULT_MAX_ABS_MT_TRACKING_ID ,0 ,0 ); +/* TODO get max_x_pos (and y) from control registers. */ +input_set_abs_params (input,ABS_MT_POSITION_X , + x_min, x_max,0 ,0 ); +input_set_abs_params (input,ABS_MT_POSITION_Y , + y_min, y_max,0 ,0 ); +if (!sensor->type_a) +input_mt_init_slots (input, sensor->nbr_fingers); +if (IS_ENABLED (CONFIG_RMI4_F11_PEN ) && + sensor->sens_query.query9.has_pen) +input_set_abs_params (input,ABS_MT_TOOL_TYPE , +0 ,MT_TOOL_MAX ,0 ,0 ); +else +input_set_abs_params (input,ABS_MT_TOOL_TYPE , +0 ,MT_TOOL_FINGER ,0 ,0 ); +} + +static int f11_device_init (struct rmi_function_container *fc) +{ +int rc; + + rc =rmi_f11_initialize (fc); +if (rc <0 ) + goto err_free_data; + + rc =rmi_f11_register_devices (fc); +if (rc <0 ) + goto err_free_data; + + rc =rmi_f11_create_sysfs (fc); +if (rc <0 ) + goto err_free_data; + +return 0 ; + +err_free_data: +rmi_f11_free_memory (fc); + +return rc; +} + +static void rmi_f11_free_memory (struct rmi_function_container *fc) +{ +struct f11_data *f11 = fc->data; +int i; + +if (f11) { +for (i =0 ; i < f11->dev_query.nbr_of_sensors +1 ; i++) +kfree (f11->sensors[i].button_map); + } +} + + +static int rmi_f11_initialize (struct rmi_function_container *fc) +{ +struct rmi_device *rmi_dev = fc->rmi_dev; +struct f11_data *f11; +struct f11_2d_ctrl *ctrl; +u8 query_offset; +u16 query_base_addr; +u16 control_base_addr; +u16 max_x_pos, max_y_pos, temp; +int rc; +int i; +struct rmi_device_platform_data *pdata =to_rmi_platform_data (rmi_dev); + +dev_dbg (&fc->dev,"Initializing F11 values for %s.\n" , + pdata->sensor_name); + +/* +** init instance data, fill in values and create any sysfs files +*/ + f11 =devm_kzalloc (&fc->dev,sizeof (struct f11_data ),GFP_KERNEL ); +if (!f11) +return -ENOMEM ; + + fc->data = f11; + f11->rezero_wait_ms = pdata->f11_rezero_wait; + + query_base_addr = fc->fd.query_base_addr; + control_base_addr = fc->fd.control_base_addr; + + rc =rmi_read (rmi_dev, query_base_addr, &f11->dev_query.f11_2d_query0); +if (rc <0 ) +return rc; + + query_offset = (query_base_addr +1 ); +/* Increase with one since number of sensors is zero based */ +for (i =0 ; i < (f11->dev_query.nbr_of_sensors +1 ); i++) { +struct f11_2d_sensor *sensor = &f11->sensors[i]; + sensor->sensor_index = i; + sensor->fc = fc; + + rc =rmi_f11_get_query_parameters (rmi_dev, &sensor->sens_query, + query_offset); +if (rc <0 ) +return rc; + query_offset += rc; + +if (f11->dev_query.has_query9) { + rc =rmi_read (rmi_dev, query_offset, + &sensor->sens_query.query9.reg); +if (rc <0 ) { +dev_err (&fc->dev,"Failed to read query 9.\n" ); +return rc; + } + query_offset += rc; + } + + rc =f11_allocate_control_regs (rmi_dev, + &f11->dev_query, &sensor->sens_query, + &f11->dev_controls, control_base_addr); +if (rc <0 ) { +dev_err (&fc->dev, +"Failed to initialize F11 control params.\n" ); +return rc; + } + +if (i < pdata->f11_sensor_count) { + sensor->axis_align = + pdata->f11_sensor_data[i].axis_align; + sensor->virtual_buttons = + pdata->f11_sensor_data[i].virtual_buttons; + sensor->type_a = pdata->f11_sensor_data[i].type_a; + } + + rc =rmi_read_block (rmi_dev, + control_base_addr +F11_CTRL_SENSOR_MAX_X_POS_OFFSET , + (u8 *)&max_x_pos,sizeof (max_x_pos)); +if (rc <0 ) +return rc; + + rc =rmi_read_block (rmi_dev, + control_base_addr +F11_CTRL_SENSOR_MAX_Y_POS_OFFSET , + (u8 *)&max_y_pos,sizeof (max_y_pos)); +if (rc <0 ) +return rc; + +if (sensor->axis_align.swap_axes) { + temp = max_x_pos; + max_x_pos = max_y_pos; + max_y_pos = temp; + } + sensor->max_x = max_x_pos; + sensor->max_y = max_y_pos; + + rc =f11_2d_construct_data (sensor); +if (rc <0 ) +return rc; + + ctrl = &f11->dev_controls; +if (sensor->axis_align.delta_x_threshold) { + ctrl->ctrl0_9->delta_x_threshold = + sensor->axis_align.delta_x_threshold; + rc =rmi_write_block (rmi_dev, + ctrl->ctrl0_9->address, + ctrl->ctrl0_9->regs, +sizeof (ctrl->ctrl0_9->regs)); +if (rc <0 ) +dev_warn (&fc->dev,"Failed to write to delta_x_threshold %d. Code: %d.\n" , + i, rc); + + } + +if (sensor->axis_align.delta_y_threshold) { + ctrl->ctrl0_9->delta_y_threshold = + sensor->axis_align.delta_y_threshold; + rc =rmi_write_block (rmi_dev, + ctrl->ctrl0_9->address, + ctrl->ctrl0_9->regs, +sizeof (ctrl->ctrl0_9->regs)); +if (rc <0 ) +dev_warn (&fc->dev,"Failed to write to delta_y_threshold %d. Code: %d.\n" , + i, rc); + } + +if (IS_ENABLED (CONFIG_RMI4_DEBUG )) { + rc =setup_sensor_debugfs (sensor); +if (rc <0 ) +dev_warn (&fc->dev,"Failed to setup debugfs for F11 sensor %d. Code: %d.\n" , + i, rc); + } + } + +if (IS_ENABLED (CONFIG_RMI4_DEBUG )) { + rc =setup_f11_debugfs (fc); +if (rc <0 ) +dev_warn (&fc->dev,"Failed to setup debugfs for F11. Code: %d.\n" , + rc); + } + +mutex_init (&f11->dev_controls_mutex); +return 0 ; +} + +static void register_virtual_buttons (struct rmi_function_container *fc, +struct f11_2d_sensor *sensor) { +int j; + +if (!sensor->sens_query.has_gestures) +return ; +if (!sensor->virtual_buttons.buttons) { +dev_warn (&fc->dev,"No virtual button platform data for 2D sensor %d.\n" , + sensor->sensor_index); +return ; + } +/* call devm_kcalloc when it will be defined in kernel */ + sensor->button_map =devm_kzalloc (&fc->dev, + sensor->virtual_buttons.buttons, +GFP_KERNEL ); +if (!sensor->button_map) { +dev_err (&fc->dev,"Failed to allocate the virtual button map.\n" ); +return ; + } + +/* manage button map using input subsystem */ + sensor->input->keycode = sensor->button_map; + sensor->input->keycodesize =sizeof (u8); + sensor->input->keycodemax = sensor->virtual_buttons.buttons; + +/* set bits for each button... */ +for (j =0 ; j < sensor->virtual_buttons.buttons; j++) { + sensor->button_map[j] = sensor->virtual_buttons.map[j].code; +set_bit (sensor->button_map[j], sensor->input->keybit); + } +} + +static int rmi_f11_register_devices (struct rmi_function_container *fc) +{ +struct rmi_device *rmi_dev = fc->rmi_dev; +struct f11_data *f11 = fc->data; +struct input_dev *input_dev; +struct input_dev *input_dev_mouse; +int sensors_itertd =0 ; +int i; +int rc; + +for (i =0 ; i < (f11->dev_query.nbr_of_sensors +1 ); i++) { +struct f11_2d_sensor *sensor = &f11->sensors[i]; + sensors_itertd = i; + input_dev =input_allocate_device (); +if (!input_dev) { + rc = -ENOMEM ; + goto error_unregister; + } + + sensor->input = input_dev; +/* TODO how to modify the dev name and +* phys name for input device */ +sprintf (sensor->input_name,"%sfn%02x" , +dev_name (&rmi_dev->dev), fc->fd.function_number); + input_dev->name = sensor->input_name; +sprintf (sensor->input_phys,"%s/input0" , + input_dev->name); + input_dev->phys = sensor->input_phys; + input_dev->dev.parent = &rmi_dev->dev; +input_set_drvdata (input_dev, f11); + +set_bit (EV_SYN , input_dev->evbit); +set_bit (EV_ABS , input_dev->evbit); +input_set_capability (input_dev,EV_KEY ,BTN_TOUCH ); +set_bit (INPUT_PROP_DIRECT , input_dev->propbit); + +f11_set_abs_params (fc, i); + +dev_dbg (&fc->dev,"%s: Sensor %d hasRel %d.\n" , + __func__, i, sensor->sens_query.has_rel); +if (sensor->sens_query.has_rel) { +set_bit (EV_REL , input_dev->evbit); +set_bit (REL_X , input_dev->relbit); +set_bit (REL_Y , input_dev->relbit); + } + rc =input_register_device (input_dev); +if (rc <0 ) { +input_free_device (input_dev); + sensor->input =NULL ; + goto error_unregister; + } + +if (IS_ENABLED (CONFIG_RMI4_VIRTUAL_BUTTON )) +register_virtual_buttons (fc, sensor); + +if (sensor->sens_query.has_rel) { +/*create input device for mouse events */ + input_dev_mouse =input_allocate_device (); +if (!input_dev_mouse) { + rc = -ENOMEM ; + goto error_unregister; + } + + sensor->mouse_input = input_dev_mouse; + input_dev_mouse->name ="rmi_mouse" ; + input_dev_mouse->phys ="rmi_f11/input0" ; + + input_dev_mouse->id.vendor =0x18d1 ; + input_dev_mouse->id.product =0x0210 ; + input_dev_mouse->id.version =0x0100 ; + +set_bit (EV_REL , input_dev_mouse->evbit); +set_bit (REL_X , input_dev_mouse->relbit); +set_bit (REL_Y , input_dev_mouse->relbit); + +set_bit (BTN_MOUSE , input_dev_mouse->evbit); +/* Register device's buttons and keys */ +set_bit (EV_KEY , input_dev_mouse->evbit); +set_bit (BTN_LEFT , input_dev_mouse->keybit); +set_bit (BTN_MIDDLE , input_dev_mouse->keybit); +set_bit (BTN_RIGHT , input_dev_mouse->keybit); + + rc =input_register_device (input_dev_mouse); +if (rc <0 ) { +input_free_device (input_dev_mouse); + sensor->mouse_input =NULL ; + goto error_unregister; + } + +set_bit (BTN_RIGHT , input_dev_mouse->keybit); + } + + } + +return 0 ; + +error_unregister: +for (; sensors_itertd >0 ; sensors_itertd--) { +if (f11->sensors[sensors_itertd].input) { +if (f11->sensors[sensors_itertd].mouse_input) { +input_unregister_device ( + f11->sensors[sensors_itertd].mouse_input); + f11->sensors[sensors_itertd].mouse_input =NULL ; + } +input_unregister_device (f11->sensors[i].input); + f11->sensors[i].input =NULL ; + } + } + +return rc; +} + +static void rmi_f11_free_devices (struct rmi_function_container *fc) +{ +struct f11_data *f11 = fc->data; +int i; + +for (i =0 ; i < (f11->dev_query.nbr_of_sensors +1 ); i++) { +if (f11->sensors[i].input) +input_unregister_device (f11->sensors[i].input); +if (f11->sensors[i].sens_query.has_rel && + f11->sensors[i].mouse_input) +input_unregister_device (f11->sensors[i].mouse_input); + } +} + +static int rmi_f11_create_sysfs (struct rmi_function_container *fc) +{ +int attr_count =0 ; +int rc; +struct f11_data *f11 = fc->data; + +dev_dbg (&fc->dev,"Creating sysfs files.\n" ); +/* Set up sysfs device attributes. */ +for (attr_count =0 ; attr_count <ARRAY_SIZE (attrs); attr_count++) { +if (sysfs_create_file + (&fc->dev.kobj, &attrs[attr_count].attr) <0 ) { +dev_err (&fc->dev, +"Failed to create sysfs file for %s." , + attrs[attr_count].attr.name); + rc = -ENODEV ; + goto err_remove_sysfs; + } + } +if (sysfs_create_group (&fc->dev.kobj, &attrs_control0) <0 ) { +dev_err (&fc->dev,"Failed to create query sysfs files.\n" ); +return -ENODEV ; + } +if (f11->dev_controls.ctrl29_30) { +if (sysfs_create_group (&fc->dev.kobj, + &attrs_control29_30) <0 ) { +dev_err (&fc->dev, +"Failed to create query sysfs files." ); +return -ENODEV ; + } + } + +return 0 ; + +err_remove_sysfs: +for (attr_count--; attr_count >=0 ; attr_count--) +sysfs_remove_file (&fc->dev.kobj, &attrs[attr_count].attr); +sysfs_remove_group (&fc->dev.kobj, &attrs_control0); +if (f11->dev_controls.ctrl29_30) +sysfs_remove_group (&fc->dev.kobj, &attrs_control29_30); +return rc; +} + +static int rmi_f11_config (struct rmi_function_container *fc) +{ +struct f11_data *f11 = fc->data; +int i; +int rc; + +for (i =0 ; i < (f11->dev_query.nbr_of_sensors +1 ); i++) { + rc =f11_write_control_regs (fc->rmi_dev, + &f11->sensors[i].sens_query, + &f11->dev_controls, + fc->fd.query_base_addr); +if (rc <0 ) +return rc; + } + +return 0 ; +} + +int rmi_f11_attention (struct rmi_function_container *fc,u8 *irq_bits) +{ +struct rmi_device *rmi_dev = fc->rmi_dev; +struct f11_data *f11 = fc->data; +u16 data_base_addr = fc->fd.data_base_addr; +u16 data_base_addr_offset =0 ; +int error; +int i; + +for (i =0 ; i < f11->dev_query.nbr_of_sensors +1 ; i++) { + error =rmi_read_block (rmi_dev, + data_base_addr + data_base_addr_offset, + f11->sensors[i].data_pkt, + f11->sensors[i].pkt_size); +if (error <0 ) +return error; + +rmi_f11_finger_handler (f11, &f11->sensors[i]); +rmi_f11_virtual_button_handler (&f11->sensors[i]); + data_base_addr_offset += f11->sensors[i].pkt_size; + } + +return 0 ; +} + +#ifdef CONFIG_PM +static int rmi_f11_resume (struct rmi_function_container *fc) +{ +struct rmi_device *rmi_dev = fc->rmi_dev; +struct f11_data *data = fc->data; +/* Command register always reads as 0, so we can just use a local. */ +union f11_2d_commands commands = {}; +int retval =0 ; + +dev_dbg (&fc->dev,"Resuming...\n" ); +if (!data->rezero_wait_ms) +return 0 ; + +mdelay (data->rezero_wait_ms); + + commands.rezero =1 ; + retval =rmi_write_block (rmi_dev, fc->fd.command_base_addr, + &commands.reg,sizeof (commands.reg)); +if (retval <0 ) { +dev_err (&rmi_dev->dev,"%s: failed to issue rezero command, error = %d." , + __func__, retval); +return retval; + } + +return retval; +} +#endif /* CONFIG_PM */ + +static int f11_remove_device (struct device *dev) +{ +int attr_count =0 ; +struct f11_data *f11; +struct rmi_function_container *fc =to_rmi_function_container (dev); + + f11 = fc->data; + +if (IS_ENABLED (CONFIG_RMI4_DEBUG )) { +int i; + +for (i =0 ; i < f11->dev_query.nbr_of_sensors +1 ; i++) +teardown_sensor_debugfs (&f11->sensors[i]); +teardown_f11_debugfs (f11); + } + +for (attr_count =0 ; attr_count <ARRAY_SIZE (attrs); attr_count++) +sysfs_remove_file (&fc->dev.kobj, &attrs[attr_count].attr); + +sysfs_remove_group (&fc->dev.kobj, &attrs_control0); +if (f11->dev_controls.ctrl29_30) +sysfs_remove_group (&fc->dev.kobj, &attrs_control29_30); + +rmi_f11_free_devices (fc); + +rmi_f11_free_memory (fc); + +return 0 ; +} + +static int f11_probe (struct device *dev); + +static struct rmi_function_handler function_handler = { + .driver = { + .owner =THIS_MODULE , + .name ="rmi_f11" , + .bus = &rmi_bus_type, + .probe = f11_probe, + .remove = f11_remove_device, + }, + .func =0x11 , + .config = rmi_f11_config, + .attention = rmi_f11_attention, +#ifdef CONFIG_PM + .resume = rmi_f11_resume +#endif +}; + +static __devinit int f11_probe (struct device *dev) +{ +struct rmi_function_container *fc; + +if (dev->type != &rmi_function_type) { +dev_dbg (dev,"Not a function device.\n" ); +return 1 ; + } + fc =to_rmi_function_container (dev); +if (fc->fd.function_number != function_handler.func) { +dev_dbg (dev,"Device is F%02X, not F%02X.\n" , + fc->fd.function_number, function_handler.func); +return 1 ; + } + +return f11_device_init (fc); +} + +static int __init rmi_f11_module_init (void ) +{ +int error; + + error =driver_register (&function_handler.driver); +if (error <0 ) { +pr_err ("%s: register driver failed!\n" , __func__); +return error; + } + +return 0 ; +} + +static void __exit rmi_f11_module_exit(void) +{ +driver_unregister (&function_handler.driver); +} + +static ssize_t f11_maxPos_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct rmi_function_container *fc; +struct f11_data *data; + + fc =to_rmi_function_container (dev); + data = fc->data; + +return snprintf (buf,PAGE_SIZE ,"%u %u\n" , + data->sensors[0 ].max_x, data->sensors[0 ].max_y); +} + +static ssize_t f11_relreport_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct rmi_function_container *fc; +struct f11_data *instance_data; + + fc =to_rmi_function_container (dev); + instance_data = fc->data; + +return snprintf (buf,PAGE_SIZE ,"%u\n" , + instance_data-> + sensors[0 ].axis_align.rel_report_enabled); +} + +static ssize_t f11_relreport_store (struct device *dev, +struct device_attribute *attr, +const char *buf, +size_t count) +{ +struct rmi_function_container *fc; +struct f11_data *instance_data; +unsigned int new_value; + + fc =to_rmi_function_container (dev); + instance_data = fc->data; + + +if (sscanf (buf,"%u" , &new_value) !=1 ) +return -EINVAL ; +if (new_value <0 || new_value >1 ) +return -EINVAL ; + instance_data->sensors[0 ].axis_align.rel_report_enabled = new_value; + +return count; +} + +static ssize_t f11_rezero_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct rmi_function_container *fc =NULL ; +unsigned int rezero; +int retval =0 ; +/* Command register always reads as 0, so we can just use a local. */ +union f11_2d_commands commands = {}; + + fc =to_rmi_function_container (dev); + +if (sscanf (buf,"%u" , &rezero) !=1 ) +return -EINVAL ; +if (rezero <0 || rezero >1 ) +return -EINVAL ; + +/* Per spec, 0 has no effect, so we skip it entirely. */ +if (rezero) { + commands.rezero =1 ; + retval =rmi_write_block (fc->rmi_dev, fc->fd.command_base_addr, + &commands.reg,sizeof (commands.reg)); +if (retval <0 ) { +dev_err (dev,"%s: failed to issue rezero command, error = %d." , + __func__, retval); +return retval; + } + } + +return count; +} + +/* Control sysfs files */ +show_store_union_struct_unsigned(dev_controls, ctrl0_9, abs_pos_filt) +show_store_union_struct_unsigned(dev_controls, ctrl29_30, z_touch_threshold) +show_store_union_struct_unsigned(dev_controls, ctrl29_30, z_touch_hysteresis) + +module_init (rmi_f11_module_init); +module_exit (rmi_f11_module_exit); + +MODULE_AUTHOR ("Christopher Heiny <[email protected]" ); +MODULE_DESCRIPTION ("RMI F11 module" ); +MODULE_LICENSE ("GPL" ); +MODULE_VERSION (RMI_DRIVER_VERSION );
RFC PATCH 4/6 input/rmi4: Config files and makefiles
In reply to Christopher HeinyNot much to say here, except that we've reduced the number of different Kconfig options, which will hopefully make it easier to configure RMI4 support in kernels.
---
drivers/input/Kconfig | 2 + drivers/input/Makefile | 2 + drivers/input/rmi4/Kconfig | 86 +++++++++++++++++++++++++++++++++++++++++++ drivers/input/rmi4/Makefile | 26 +++++++++++++ 4 files changed, 116 insertions(+), 0 deletions(-)
drivers/input/Kconfig +2 -0
@@ -188,6 +188,8 @@ source "drivers/input/touchscreen/Kconfig" source "drivers/input/misc/Kconfig" +source "drivers/input/rmi4/Kconfig" + endif menu "Hardware I/O ports"
drivers/input/Makefile +2 -0
@@ -24,4 +24,6 @@ obj-$(CONFIG_INPUT_TABLET) += tablet/ obj-$(CONFIG_INPUT_TOUCHSCREEN) += touchscreen/ obj-$(CONFIG_INPUT_MISC) += misc/ +obj-y += rmi4/ + obj-$(CONFIG_INPUT_APMPOWER) += apm-power.o
drivers/input/rmi4/Kconfig new file +86 -0
86 lines not on this page · raw message
drivers/input/rmi4/Makefile new file +26 -0
@@ -0,0 +1,26 @@ +obj-$(CONFIG_RMI4_BUS) += rmi_bus.o +obj-$(CONFIG_RMI4_I2C) += rmi_i2c.o +obj-$(CONFIG_RMI4_GENERIC) += rmi_driver.o rmi_f01.o +obj-$(CONFIG_RMI4_F11) += rmi_f11.o + +ccflags-$(CONFIG_RMI4_DEBUG) += -DDEBUG + +ifeq ($(KERNELRELEASE),) + +# KERNELDIR ?= /home/<AndroidKernelDirectory> +PWD := $(shell pwd) + +.PHONY: build clean + +build: + $(MAKE) -C $(KERNELDIR) M=$(PWD) modules + +clean: + rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c +else + +$(info Building with KERNELRELEASE = ${KERNELRELEASE}) +obj-m += rmi_dev.o + +endif +
RFC PATCH 1/6 input/rmi4: Public header and documentation
In reply to Christopher HeinyAs requested in the feedback from the previous patch, we've documented the debugfs and sysfs attributes in files in Documentation/ABI/testing. There's two files, one for debugfs and one for sysfs.
---
Documentation/ABI/testing/debugfs-rmi4 | 99 +++++ Documentation/ABI/testing/sysfs-rmi4 | 103 +++++ include/linux/rmi.h | 696 ++++++++++++++++++++++++++++++++ 3 files changed, 898 insertions(+), 0 deletions(-)
Documentation/ABI/testing/debugfs-rmi4 new file +99 -0
@@ -0,0 +1,99 @@ +What: /sys/kernel/debug/rmi/devices +Date: October 2012 +KernelVersion: 3.x +Contact: Christopher Heiny <[email protected]> +Description: + + The RMI4 driver implementation exposes a set of informational and control + parameters via debugs. These parameters are those that typically are only + viewed or adjusted during product development, tuning, and debug. + For parameters that are referenced and/or adjusted during normal operation, + please see sysfs-rmi4 in this directory. + + General debugging parameters for a particular RMI4 sensor are found in + /sys/kernel/debug/rmi/sensorXX/, where XX is a the device's ID as a two + digit number (padded with leading zeros). Function specific parameters + for an RMI4 sensor are found in /sys/kernel/debug/rmi/devices/FYY/, where + XX is a the device's ID as a two digit number (padded with leading zeros) + and YY is the hexdecimal function number (for example, F11 for RMI function + F11). + + For RMI4 functions that support multiple sensor instances (such as F11), + the parameters for individual sensors have .Z appended to them, where Z is + the index of the sensor instance (for example, clip.0, clip.1, clip.2, and + so on). + + Some of the parameters exposed here are described in detail in the + RMI4 Specification, which is found here: + http://www.synaptics.com/sites/default/files/511-000136-01_revD.pdf + For such parameters, we'll reference you to that document, rather than + copying the contents here. + + /sys/kernel/debug/rmi/ + /sensorXX/ + attn_count - (ro) Shows the number of ATTN interrupts handled so far. + comms_debug - (rw) Write 1 to this dump information about register + reads and writes to the console. Write 0 to this to turn + this feature off. WARNING: Imposes a major performance + penalty when turned on. + irq_debug - (rw) Write 1 to this dump information about interrupts + to the console. Write 0 to this to turn this feature off. + WARNIG: Imposes a major performance penalty when turned on. + phys - (ro) Presents information about the physical connection of + this device. It has one line, with the format: + + prot tx_count tx_bytes tx_errors rx_count rx_bytes rx_errors attn + + Where + prot is one of i2c, spi1, or spi2 + tx_count is the number of write operations + tx_bytes is the number of bytes written + tx_errors is the number of write operations that encountered errors + rx_count is the number of read operations + rx_bytes is the total number of bytes read + rx_errors is the number of read operations that encountered errors + + All counts are 64-bit unsigned values, and are set to zero + when the physical layer driver is initialized. + + /sensorXX/F01/ + interrupt_enable - (rw) allows you to read or modify the F01 + interrupt enable mask (the F01_RMI_Ctrl1 register(s)). + + /sensorXX/F11/ + clip.Z - (rw) Controls in-driver coordinate clipping for the 2D + sensor Z. This is a set of four unsigned values in the + range [0..65535], representing the lower bounds on X, the + upper bounds on X, the lower bounds on Y, and the upper + bounds on Y. Coordinates will be clipped to these ranges. + If enabled, clip is the final transformation to be applied + to the coordinates. The default upper and lower bounds for + clip are 0 and 65535 respectively for both axes. + delta_threshold.Z - (rw) Controls the F11 distance thresholds. This + contains two values, corresponding to F11_2D_Ctrl2 and + F11_2D_Ctrl3. Se the spec for more details. + flip.Z - (rw) This parameter is a pair of single binary digits (for + example, "0 0" or "1 0"), corresponding to the X and Y axis. + Writing a 1 for a particular axis will invert the coordinates + reported by the device along that axis. For example writing + "0 1" to this parameter will flip the Y axis top to bottom, + but leave the X axis unchanged. If enabled, flip is applied + after swap and before offset. + offset.Z - (rw) This is a pair of values that will be SUBTRACTED + from the X and Y coordinates, respectively. If non-zero, + offset will be applied after flip and before clip. The + default value for offset is 0 for both X and Y. + rezero_wait - (rw) If non-zero, F11 will wait this many milliseconds + after exiting suspend mode before recalibrating the sensor(s). + This is useful in systems were there may be unusual + electrical conditions during the resume process, allowing + you to delay recalibration until the electrical environment + has stabilized. + swap.Z - (rw) Writing 1 to this parameter swaps the X and Y axis as + reported by the sensor instance Z, rotating the reported + coordinates by 90 degrees. This can be useful when + installing a landscape sensor over a portrait display, for + example. The default state for this parameter is 0. If + enabled, swap is applied before any other transformation. + type_a - (rw) Most RMI4 F11 implementations support MT-B reporting. + You can write 1 to this parameter to force MT-A reporting.
Documentation/ABI/testing/sysfs-rmi4 new file +103 -0
103 lines not on this page · raw message
include/linux/rmi.h new file +696 -0
696 lines not on this page · raw message
Re: [RFC PATCH 02/06] input/rmi4: Core files
In reply to Christopher HeinyOn Fri, 2012-10-05 at 21:09 -0700, Christopher Heiny wrote:
[]
Just some trivial comments:
drivers/input/rmi4/rmi_driver.c
Quoted 1 line
drivers/input/rmi4/rmi_driver.c +0
-0
[]
drivers/input/rmi4/rmi_driver.c
Quoted 1 line
drivers/input/rmi4/rmi_driver.c +0
-0@@ -0,0 +1,1529 @@
[]
Quoted 16 lines
drivers/input/rmi4/rmi_driver.c +16
-0+static ssize_t delay_write (struct file *filp,const char __user *buffer, +size_t size,loff_t *offset) { +struct driver_debugfs_data *data = filp->private_data; +struct rmi_device_platform_data *pdata = + data->rmi_dev->phys->dev->platform_data; +int retval; +char local_buf[size]; +unsigned int new_read_delay; +unsigned int new_write_delay; +unsigned int new_block_delay; +unsigned int new_pre_delay; +unsigned int new_post_delay; + + retval =copy_from_user (local_buf, buffer, size); +if (retval) +return -EFAULT ;
drivers/input/rmi4/rmi_driver.c line 144
Quoted 10 lines
drivers/input/rmi4/rmi_driver.c +10
-0+ + retval =sscanf (local_buf,"%u %u %u %u %u" , &new_read_delay, + &new_write_delay, &new_block_delay, + &new_pre_delay, &new_post_delay); +if (retval !=5 ) { +dev_err (&data->rmi_dev->dev, +"Incorrect number of values provided for delay." ); +return -EINVAL ; + } +if (new_read_delay <0 ) {
These are unnecessary tests as unsigned values are never < 0.
drivers/input/rmi4/rmi_driver.c line 149
Quoted 5 lines
drivers/input/rmi4/rmi_driver.c +5
-0+dev_err (&data->rmi_dev->dev, +"Byte delay must be positive microseconds.\n" ); +return -EINVAL ; + } +if (new_write_delay <0 ) {
etc.
drivers/input/rmi4/rmi_driver.c line 197
Quoted 6 lines
drivers/input/rmi4/rmi_driver.c +6
-0+static ssize_t phys_read (struct file *filp,char __user *buffer,size_t size, +loff_t *offset) { +struct driver_debugfs_data *data = filp->private_data; +struct rmi_phys_info *info = &data->rmi_dev->phys->info; +int retval; +char local_buf[size];
size comes from where? possible stack overflow?
drivers/input/rmi4/rmi_driver.c line 270
Quoted 4 lines
drivers/input/rmi4/rmi_driver.c +4
-0+static ssize_t irq_debug_write (struct file *filp,const char __user *buffer, +size_t size,loff_t *offset) { +int retval; +char local_buf[size];
here too
[]
drivers/input/rmi4/rmi_driver.c line 43
Quoted 2 lines
drivers/input/rmi4/rmi_driver.c +2
-0+static int process_interrupt_requests (struct rmi_device *rmi_dev) +{
[]
drivers/input/rmi4/rmi_driver.c line 549
Quoted 4 lines
drivers/input/rmi4/rmi_driver.c +4
-0+list_for_each_entry (entry, &data->rmi_functions.list, list) +if (entry->irq_mask) +process_one_interrupt (entry, irq_status, + data);
style nit, it'd be nicer with braces.
drivers/input/rmi4/rmi_driver.h
Quoted 1 line
drivers/input/rmi4/rmi_driver.h +0
-0
[]
drivers/input/rmi4/rmi_driver.h line 36
Quoted 6 lines
drivers/input/rmi4/rmi_driver.h +4
-0@@ -0,0 +1,438 @@ + +#define tricat (x, y, z) tricat_(x, y, z) + +#define tricat_ (x, y, z) x##y##z
I think these tricat macros are merely obfuscating and don't need to be used.
Re: [RFC PATCH 02/06] input/rmi4: Core files
Quoted 29 lines · Joe Perches
On Fri, 2012-10-05 at 21:09 -0700, Christopher Heiny wrote:
[]Just some trivial comments:
drivers/input/rmi4/rmi_driver.c
Quoted 1 line
drivers/input/rmi4/rmi_driver.c +0
-0[]
drivers/input/rmi4/rmi_driver.c
Quoted 1 line
drivers/input/rmi4/rmi_driver.c +0
-0@@ -0,0 +1,1529 @@[]
Quoted 20 lines
drivers/input/rmi4/rmi_driver.c +20
-0+static ssize_t delay_write (struct file *filp,const char __user *buffer, +size_t size,loff_t *offset) { +struct driver_debugfs_data *data = filp->private_data; +struct rmi_device_platform_data *pdata = + data->rmi_dev->phys->dev->platform_data; +int retval; +char local_buf[size]; +unsigned int new_read_delay; +unsigned int new_write_delay; +unsigned int new_block_delay; +unsigned int new_pre_delay; +unsigned int new_post_delay; + + retval =copy_from_user (local_buf, buffer, size); +if (retval) +return -EFAULT ; + + retval =sscanf (local_buf,"%u %u %u %u %u" , &new_read_delay, + &new_write_delay, &new_block_delay, + &new_pre_delay, &new_post_delay);
Quoted 9 lines
drivers/input/rmi4/rmi_driver.c line 144
Quoted 6 lines
drivers/input/rmi4/rmi_driver.c +6
-0+if (retval !=5 ) { +dev_err (&data->rmi_dev->dev, +"Incorrect number of values provided for delay." ); +return -EINVAL ; + } +if (new_read_delay <0 ) {These are unnecessary tests as unsigned values are never < 0.
Nope.
1 main()
2 {
3 char buf[100] = "1 -2";
4 int t, t2;
5
6 sscanf(buf, "%u %u", &t, &t2);
7
8 if (t > 0) {
9 printf("greater\n");
10 }
11
12 if (t2 > 0) {
13 printf("greater\n");
14 } else {
15 printf("lesser\n");
16 }
17 }
Thanks,
Re: [RFC PATCH 02/06] input/rmi4: Core files
Quoted 31 lines · devendra.aaru
Quoted 30 lines · Joe Perches
On Fri, 2012-10-05 at 21:09 -0700, Christopher Heiny wrote:
[]Just some trivial comments:
drivers/input/rmi4/rmi_driver.c
Quoted 1 line
drivers/input/rmi4/rmi_driver.c +0
-0[]
drivers/input/rmi4/rmi_driver.c
Quoted 1 line
drivers/input/rmi4/rmi_driver.c +0
-0@@ -0,0 +1,1529 @@[]
Quoted 21 lines
drivers/input/rmi4/rmi_driver.c +21
-0+static ssize_t delay_write (struct file *filp,const char __user *buffer, +size_t size,loff_t *offset) { +struct driver_debugfs_data *data = filp->private_data; +struct rmi_device_platform_data *pdata = + data->rmi_dev->phys->dev->platform_data; +int retval; +char local_buf[size]; +unsigned int new_read_delay; +unsigned int new_write_delay; +unsigned int new_block_delay; +unsigned int new_pre_delay; +unsigned int new_post_delay; + + retval =copy_from_user (local_buf, buffer, size); +if (retval) +return -EFAULT ; + + retval =sscanf (local_buf,"%u %u %u %u %u" , &new_read_delay, + &new_write_delay, &new_block_delay, + &new_pre_delay, &new_post_delay); +if (retval !=5 ) {
Quoted 9 lines
Quoted 8 lines
drivers/input/rmi4/rmi_driver.c line 144
Quoted 5 lines
drivers/input/rmi4/rmi_driver.c +5
-0+dev_err (&data->rmi_dev->dev, +"Incorrect number of values provided for delay." ); +return -EINVAL ; + } +if (new_read_delay <0 ) {These are unnecessary tests as unsigned values are never < 0.
Oops, i m sorry, i mistakenly took the variable as int, it should be unsinged int.
sorry joe, you are right the are never < 0.
Thanks,
Re: [RFC PATCH 01/06] input/rmi4: Public header and documentation
In reply to Christopher HeinyQuoted 3 lines · Christopher Heiny
As requested in the feedback from the previous patch, we've documented the debugfs and sysfs attributes in files in
Documentation/ABI/testing. There's two files, one for debugfs and one for sysfs.
This is a massive improvement! Atleast as far as I've read... If you fix the below remarks I think I'm ready to accept this file, but that's just me and doesn't say anything about what Dmitry et al will comment on...
(...)
Documentation/ABI/testing/debugfs-rmi4 line 8
Quoted 2 lines
Documentation/ABI/testing/debugfs-rmi4 new file +2
-0+ The RMI4 driver implementation exposes a set of informational and control + parameters via debugs. These parameters are those that typically are only
s/debugs/debugfs
(...)
Documentation/ABI/testing/debugfs-rmi4 line 41
Quoted 7 lines
Documentation/ABI/testing/debugfs-rmi4 new file +7
-0+ comms_debug - (rw) Write 1 to this dump information about register + reads and writes to the console. Write 0 to this to turn + this feature off. WARNING: Imposes a major performance + penalty when turned on. + irq_debug - (rw) Write 1 to this dump information about interrupts + to the console. Write 0 to this to turn this feature off. + WARNIG: Imposes a major performance penalty when turned on.
Hm. Usually we control dynamic debug prints by standard kernel frameworks, can you tell what is wrong with this and why you need a custom mechanism? See the following:Documentation/dynamic-debug-howto.txt
http://lwn.net/Articles/434833/
(...)
Quoted 1 line
+++ b/Documentation/ABI/testing/sysfs-rmi4
(...)
Documentation/ABI/testing/sysfs-rmi4 line 39
Quoted 7 lines
Documentation/ABI/testing/sysfs-rmi4 new file +7
-0+ chargerinput ... (rw) User space programs can use this to tell the + sensor that the system is plugged into an external power + source (as opposed to running on batteries). This allows + the sensor firmware to make necessary adjustments for the + current capacitence regime. Write 1 to this when the + system is using external power, write 0 to this when the + system is running on batteries. See spec for full details.
I remember discussing in-kernel notifiers for this. I don't really see the point in tunnelling a notification from the drivers/power subsystem to the drivers/input subsystem through userspace for no good.
It's no blocker though, I don't expect you to fix this as part of this driver submission.
Maybe Anton can comment?
(...)
Documentation/ABI/testing/sysfs-rmi4 line 57
Quoted 2 lines
Documentation/ABI/testing/sysfs-rmi4 new file +2
-0+ interrupt_enable ... (ro) This represents the current RMI4 interrupt + mask (F01_RMI_Ctrl1 registers). See spec for full details.
What does the userspace have to do with this stuff? Seems way too low-level, but whatever.
(...)
Documentation/ABI/testing/sysfs-rmi4 line 82
Quoted 8 lines
Documentation/ABI/testing/sysfs-rmi4 new file +8
-0+ sleepmode ... (rw) Controls power management on the device. Writing + 0 to this parameter puts the device into its normal operating + mode. Writing 1 to this parameter fully disables touch + sensors and similar inputs - no touch data will be reported + from the device in this mode. Writing 2 or 3 to this device + may or may not have an effect, depending on the particular + device - see the product specification for your sensor for + details.
Usually power management is controlled from kernelspace, but no big deal, maybe userspace knows even more details in some cases.
Documentation/ABI/testing/sysfs-rmi4 line 87
Quoted 2 lines
Documentation/ABI/testing/sysfs-rmi4 new file +2
-0+ unconfigured ... (ro) This is the opposite of the configured bit, + described above.
So why is it needed? Isn't it implicit from the "configured" property if this is 0 then it's unconfigured? Seems superfluous.
(...)
Quoted 1 line
+++
b/include/linux/rmi.h
(...)
include/linux/rmi.h line 36
Quoted 3 lines
include/linux/rmi.h new file +3
-0+#ifdef CONFIG_RMI4_DEBUG +#include <linux/debugfs.h> +#endif
Don't include it conditionally, always just include it whether you use it or not.
It doesn't hurt, and doesn't cause compile problems.
(...)
Quoted 2 lines
+/**
+ * structrmi_device_platform_data_spi- provides paramters used in SPI
s/paramters/parameters/
Quoted 1 line
+ * communitcations. All Synaptics SPI products support a standard SPI
s/communitcations/communications
Quoted 7 lines
+ * @cs_assert - For systems where the SPI subsystem does not control the CS/SSB
+ * line, or where such control is broken, you can provide a custom routine to
+ * handle a GPIO as CS/SSB. This routine will be called at the beginning and
+ * end of each SPI transaction. The RMI SPI implementation will wait
+ *pre_delay_usafter this routine returns before starting the SPI transfer;
+ * andpost_delay_usafter completion of the SPI transfer(s) before calling it
+ * with assert==FALSE.
Hm hm, can you describe the case where this happens?
Usually we don't avoid fixes for broken drivers by duct-taping solutions into other drivers, instead we fix the SPI driver.
I can think of systems where CS is asserted not by using GPIO but by poking some special register for example, which is a valid reason for including this, but working around broken SPI drivers is not a valid reason to include this.
(Paging Mark about it.)
(...)
Quoted 4 lines
+/**
+ * structrmi_device_platform_data- system specific configuration info.
+ *
+ * @driver_name
(...)
include/linux/rmi.h line 295
Quoted 2 lines
include/linux/rmi.h new file +2
-0+struct rmi_device_platform_data { +char *driver_name;
I don't understand what the driver name is doing in the platform data. The driver name should be part of the device driver struct, and match on dev_name(struct device *), not be passed in here.
Please explain...
(...)
include/linux/rmi.h line 431
Quoted 3 lines
include/linux/rmi.h new file +3
-0+#ifdef CONFIG_RMI4_DEBUG +struct dentry *debugfs_root; +#endif
Maybe just use CONFIG_DEBUG_FS instead, it's more to the point?
(occurs twice)
(...)
Quoted 7 lines
+/**
+ *rmi_register_phys_device- register a physical device connection on the RMI
+ * bus. Physical drivers provide communication from the devices on the bus to
+ * the RMI4 sensor on a bus such as SPI, I2C, and so on.
+ *
+ * @phys: the physical device to register
+ */
Don't put the kerneldoc here in the header, put it in the code.
Only documentation for structs, enums and inline functions go into the header files.
(Same comment for all functions.)
Quoted 1 line
+int
rmi_register_phys_device(struct rmi_phys_device *phys);
(...)
Quoted 5 lines
+/**
+ * Helper function to convert a 16 bit value (in host processor endianess) to
+ * a byte array in the RMI endianess for u16s. See above comment for
+ * why we dont us htons or something like that.
+ */
So in this case it's correct to document it here, because this is an inline function.
include/linux/rmi.h line 657
Quoted 4 lines
include/linux/rmi.h new file +4
-0+static inline void hstoba (u8 *dest,u16 src) +{ + dest[0 ] = src %0x100 ; + dest[1 ] = src /0x100 ;
But please use arithmetic operators (I think I said this on the last review):
dest[0] = src & 0xFF;
dest[1] = src >> 8;
Doing it the above way makes artithmetic look like maths, and it isn't. Besides it's done this way in most parts of the kernel and we're familiar with it.
(...)
Quoted 6 lines
include/linux/rmi.h new file +6
-0+#ifdef CONFIG_RMI4_DEBUG +/** +* Utility routine to handle writes to read-only attributes. Hopefully +* this will never happen, but if the user does something stupid, we don't +* want to accept it quietly (which is what can happen if you just put NULL +* for the attribute's store function).
include/linux/rmi.h line 675
Quoted 10 lines
include/linux/rmi.h new file +10
-0+*/ +static inline ssize_t rmi_store_error (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +dev_warn (dev, +"WARNING: Attempt to write %d characters to read-only attribute %s." , + count, attr->attr.name); +return -EPERM ; +}
Here it looks like you're hiding a lot of stuff that should be dev_warn()? Consider my earlier point about dynamic debug.
include/linux/rmi.h line 684
Quoted 2 lines
include/linux/rmi.h new file +2
-0+static inline ssize_t rmi_show_error (struct device *dev, +struct device_attribute *attr,char *buf)
Dito.
Yours,
Linus Walleij
Re: [RFC PATCH 01/06] input/rmi4: Public header and documentation
Quoted 15 lines · Linus Walleij
Quoted 7 lines · Christopher Heiny
+ * @cs_assert - For systems where the SPI subsystem does not control the CS/SSB
+ * line, or where such control is broken, you can provide a custom routine to
+ * handle a GPIO as CS/SSB. This routine will be called at the beginning and
+ * end of each SPI transaction. The RMI SPI implementation will wait
+ *pre_delay_usafter this routine returns before starting the SPI transfer;
+ * andpost_delay_usafter completion of the SPI transfer(s) before calling it
+ * with assert==FALSE.Hm hm, can you describe the case where this happens?
Usually we don't avoid fixes for broken drivers by duct-taping solutions into other drivers, instead we fix the SPI driver.
Quoted 6 lines
I can think of systems where CS is asserted not by using GPIO but by poking some special register for example, which is a valid reason for including this, but working around broken SPI drivers is not a valid reason to include this.
(Paging Mark about it.)
Yeah, this seems silly - by this logic we'd have to go round implementing manual /CS control in every single SPI client driver which isn't terribly sensible. The driver should just assume that the SPI controller does what it's told. As you say if there's an issue the relevant controller driver should take care of things.
We should also have generic support in the SPI framework for GPIO based /CS, there's enough drivers open coding this already either due to hardware limitations or to support extra chip selects.
The ability of SPI hardware and driver authors to get /CS right is pretty depressing :/
Re: [RFC PATCH 02/06] input/rmi4: Core files
In reply to Christopher HeinyQuoted 6 lines · Christopher Heiny
rmi_bus.cimplements the basic functionality of the RMI bus. This file is greatly simplified compared to the previous patch - we've switched from "do it yourself" device/driver binding to usingdevice_typeto distinguish between the two kinds of devices on the bus (sensor devices and function specific devices) and using the standard bus implementation to manage devices and drivers.
So I think you really want Greg KH to look at this bus implementation now. Please include Greg on future mailings...
It looks much improved from previous versions, and sorry if I am now adding even more comments, but it's because you cleared out some noise that was disturbing my perception so I can cleanly review the architecture of this thing now. (I'm impressed by your work and new high-speed turnaround time!)
drivers/input/rmi4/rmi_bus.c line 30
Quoted 3 lines
drivers/input/rmi4/rmi_bus.c new file +3
-0+#ifdef CONFIG_RMI4_DEBUG +#include <linux/debugfs.h> +#endif
As noted previously, drop the #ifdef:s
drivers/input/rmi4/rmi_bus.c line 76
Quoted 3 lines
drivers/input/rmi4/rmi_bus.c new file +3
-0+#ifdef CONFIG_RMI4_DEBUG +static struct dentry *rmi_debugfs_root; +#endif
I'd use #ifdef CONFIG_DEBUG_FS and try to move this declaration closer to the actual debugfs code block.
Apart from this the core bus looks good to me, but it's not my area of expertise...
(...)
drivers/input/rmi4/rmi_driver.c
Quoted 3 lines
drivers/input/rmi4/rmi_driver.c +1
-0+#ifdef CONFIG_RMI4_DEBUG
I'd just use CONFIG_DEBUG_FS
Quoted 4 lines
drivers/input/rmi4/rmi_driver.c +4
-0+struct driver_debugfs_data { +bool done; +struct rmi_device *rmi_dev; +};
(...)
Quoted 1 line
+#define
DELAY_NAME"delay"
This is only used in one place, why not just use the string "delay" there?
(...)
drivers/input/rmi4/rmi_driver.c line 307
Quoted 4 lines
drivers/input/rmi4/rmi_driver.c +4
-0+if (IS_ENABLED (CONFIG_RMI4_SPI ) && !strncmp ("spi" , info->proto,3 )) { + data->debugfs_delay =debugfs_create_file (DELAY_NAME , +RMI_RW_ATTR , rmi_dev->debugfs_root, rmi_dev, + &delay_fops);
i.e. there.
(...)
Quoted 5 lines
drivers/input/rmi4/rmi_driver.c +5
-0+/* Useful helper functions for u8* */ + +static bool u8_is_any_set (u8 *target,int size) +{ +int i;
drivers/input/rmi4/rmi_driver.c line 390
Quoted 10 lines
drivers/input/rmi4/rmi_driver.c +10
-0+/* We'd like to use find_first_bit, but it ALWAYS returns 1, +* no matter what we pass it. So we have to do this the hard way. +* return find_first_bit((long unsigned int *) target, size) != 0; +*/ +for (i =0 ; i < size; i++) { +if (target[i]) +return true; + } +return false; +}
Instead of:
if (u8_is_any_set(foo, 128) {}
Why can't you use:
if (!bitmap_empty(foo, 128*8) {}
?
If you look at the implementation in the <linux/bitmap.h> header and __bitmap_empty() in lib/bitmap.c you will realize that this function is already optimized like this (and I actually don't think the RMI4 code is performance-critical for these functions anyway, but prove me wrong!)
drivers/input/rmi4/rmi_driver.c line 400
Quoted 10 lines
drivers/input/rmi4/rmi_driver.c +10
-0+ +/** This is here because all those casts made for some ugly code. +*/ +static void u8_and (u8 *dest,u8 *target1,u8 *target2,int nbits) +{ +bitmap_and ((long unsigned int *) dest, + (long unsigned int *) target1, + (long unsigned int *) target2, + nbits); +}
Hm, getting rid of unreadable casts is a valid case.
I'll be OK with this but maybe the real solution is to introduce such helpers into <linux/bitmap.h>?
(...)
drivers/input/rmi4/rmi_driver.c line 527
Quoted 6 lines
drivers/input/rmi4/rmi_driver.c +6
-0+static int process_interrupt_requests (struct rmi_device *rmi_dev) +{ +struct rmi_driver_data *data =dev_get_drvdata (&rmi_dev->dev); +struct device *dev = &rmi_dev->dev; +struct rmi_function_container *entry; +u8 irq_status[data->num_of_irq_regs];
Looking at this...
What does the data->num_of_irq_regs actually contain?
I just fear that it is something constant like always 2 or always 4, so there is actually, in reality, a 16 or 32 bit register hiding in there.
In that case what you should do is to represent it as a u16 or u32 here, just or the bits into a status word, and then walk over that status word with something like ffs(bitword); ...
(...)
Quoted 1 line
+static int
standard_resume(struct rmi_device *rmi_dev)
Standard eh? :-)
Atleast prefix with rmi4_*...
drivers/input/rmi4/rmi_driver.c line 1362
Quoted 11 lines
drivers/input/rmi4/rmi_driver.c +11
-0+static int rmi_driver_suspend (struct device *dev) +{ +struct rmi_device *rmi_dev =to_rmi_device (dev); +return standard_suspend (rmi_dev); +} + +static int rmi_driver_resume (struct device *dev) +{ +struct rmi_device *rmi_dev =to_rmi_device (dev); +return standard_resume (rmi_dev); +}
If all these two are doing are to call another function with almost the same name, what is the point? Just sink the code from "standard_suspend()" and "standard_resume()" into these functions and remove a pointless layer of abstraction.
Apart from this the core driver looks good to me.
(...)
Quoted 1 line
drivers/input/rmi4/rmi_driver.h +0
-0
(...)
drivers/input/rmi4/rmi_driver.h line 84
Quoted 12 lines
drivers/input/rmi4/rmi_driver.h +12
-0+#define simple_show_union_struct (regtype, propname, fmt)\ +static ssize_t tricat(rmi_fn_, FNUM, _##propname##_show)(struct device *dev,\ + struct device_attribute *attr, char *buf) {\ + struct rmi_function_container *fc;\ + struct FUNCTION_DATA *data;\ +\ + fc = to_rmi_function_container(dev);\ + data = fc->data;\ +\ + return snprintf(buf, PAGE_SIZE, fmt,\ + data->regtype.propname);\ +}
OK I see the point, but is there really no other way to do this than to #define huge static inlines like these? Is it really not possible to create just generic functions instead of going this far?
(same comment for all)
drivers/input/rmi4/rmi_driver.h line 351
Quoted 7 lines
drivers/input/rmi4/rmi_driver.h +7
-0+union pdt_properties { +struct { +u8 reserved_1:6 ; +u8 has_bsr:1 ; +u8 reserved_2:1 ; + } __attribute__((__packed__ )); +u8 regs[1 ];
I don't understand what this union is trying to achieve.
regs[1] does not look right considering what you're trying to achieve. Since the above fields require a regs[2] (9 bits!) to be stored. Maybe write out what you're trying to do here so I can understand it? (If everyone else in the world gets it immediately, it's maybe me that need fixing instead...)
Apart from these remarks it's looking real nice now!
Yours,
Linus Walleij
Re: [RFC PATCH 03/06] input/rmi4: I2C physical interface
In reply to Christopher HeinyQuoted 9 lines · Christopher Heiny
The I2C physical driver is not extensively changed in terms of functionality since the previous patch. Management of the attention GPIO has been moved to
rmi_driver.c(see previous email), and most of the debug related interfaces have been moved from sysfs to debugfs. Control of the debug features has been moved from compile-time to runtime switches available via debugfs.The core I2C functionality was previously ACKed by Jean Delvare. I don't believe that portion of the code has changed much since then, but we'd appreciate a second glance at this.
The above commit blurb looks more like a changelog than a description of the actual patch. Nothing wrong with that but begin by describing the patch first.
(...)
drivers/input/rmi4/rmi_i2c.c line 47
Quoted 4 lines
drivers/input/rmi4/rmi_i2c.c new file +4
-0+#ifdef CONFIG_RMI4_DEBUG + +#include <linux/debugfs.h> +#include <linux/uaccess.h>
Just move these up to the common includes. It doesn't matter that they get included even when debug is not enabled.
drivers/input/rmi4/rmi_i2c.c line 50
Quoted 2 lines
drivers/input/rmi4/rmi_i2c.c new file +2
-0+static int setup_debugfs (struct rmi_device *rmi_dev,struct rmi_i2c_data *data); +static void teardown_debugfs (struct rmi_i2c_data *data);
Why do you need to forward-declare these? Can't you just move them up above the functions using them?
drivers/input/rmi4/rmi_i2c.c line 53
Quoted 2 lines
drivers/input/rmi4/rmi_i2c.c new file +2
-0+struct i2c_debugfs_data { +bool done;
Done with what? ... needs some doc.
Quoted 2 lines
drivers/input/rmi4/rmi_i2c.c new file +2
-0+struct rmi_i2c_data *i2c_data; +};
(...)
Quoted 2 lines
drivers/input/rmi4/rmi_i2c.c new file +2
-0+static int __devinit rmi_i2c_probe (struct i2c_client *client, +const struct i2c_device_id *id)
(...)
Quoted 1 line
+
rmi_phys=kzalloc(sizeof(struct rmi_phys_device), GFP_KERNEL);
(...)
Quoted 1 line
+ data =
kzalloc(sizeof(struct rmi_i2c_data), GFP_KERNEL);
Can you use devm_kzalloc(&client->dev, ...) for these so you don't need to free() them explicitly?
(...)
drivers/input/rmi4/rmi_i2c.c line 408
Quoted 7 lines
drivers/input/rmi4/rmi_i2c.c new file +7
-0+static int __devexit rmi_i2c_remove(struct i2c_client *client) +{ +struct rmi_phys_device *phys =i2c_get_clientdata (client); +struct rmi_device_platform_data *pd = client->dev.platform_data; + +/* Can I remove this disable_device */ +/*disable_device(phys); */
So just delete these two lines then?
Yours,
Linus Walleij
Re: [RFC PATCH 04/06] input/rmi4: Config files and makefiles
In reply to Christopher HeinyOn Sat, Oct 6, 2012 at 6:10 AM, Christopher Heiny <[email protected]> wrote:
(...)
Quoted 1 line
drivers/input/rmi4/Kconfig +0
-0
(...)
drivers/input/rmi4/Kconfig line 16
Quoted 3 lines
drivers/input/rmi4/Kconfig +3
-0+config RMI4_DEBUG + bool "RMI4 Debugging" + depends on RMI4_BUS
select DEBUG_FS
This has been illustrated many times in the review. You definatley have code depending on debugfs when this is selected.
Yours,
Linus Walleij
Re: [RFC PATCH 05/06] input/rmi4: F01 - device control
In reply to Christopher HeinyQuoted 13 lines · Christopher Heiny
RMI Function 01 implements basic device control and power management behaviors for the RMI4 sensor. Since the last patch, we've decoupled
rmi_f01.cimplementation fromrmi_driver.c, sormi_f01.cacts as a standard driver module to handle F01 devices on the RMI bus.Like other modules, a number of attributes have been moved from sysfs to debugfs, depending on their expected use.
rmi_f01.hexports definitions that we expect to be used by other functionality in the future (such as firmware reflash).
Quoted 8 lines
Signed-off-by Christopher Heiny <[email protected]>Cc Dmitry Torokhov <[email protected]>Cc Linus Walleij <[email protected]>Cc Naveen Kumar Gaddipati <[email protected]>Cc Joeri de Gram <[email protected]>---
There is liberal whitespacing above. (No big deal, but anyway.)
(...)
drivers/input/rmi4/rmi_f01.c line 38
Quoted 10 lines
drivers/input/rmi4/rmi_f01.c new file +10
-0+/** +* @reset - set this bit to force a firmware reset of the sensor. +*/ +union f01_device_commands { +struct { +bool reset:1 ; +u8 reserved:7 ; + } __attribute__((__packed__ )); +u8 reg; +};
I'm still scared by these unions. I see what you're doing but my preferred style of driver writing is to use a simple u8 if you just treat it the right way with some |= and &= ...
#include <linux/bitops.h>
#define F01_RESET BIT(0)
u8 my_command = F01_RESET;
send(&my_command);
I will not insist on this because it's a bit about programming style. For memory-mapped devices we usually do it my way, but this is more like some protocol and I know protocols like to do things with structs and stuff so no big deal.
drivers/input/rmi4/rmi_f01.c line 157
Quoted 13 lines
drivers/input/rmi4/rmi_f01.c new file +13
-0+#ifdef CONFIG_RMI4_DEBUG +struct f01_debugfs_data { +bool done; +struct rmi_function_container *fc; +}; + +static int f01_debug_open (struct inode *inodep,struct file *filp) +{ +struct f01_debugfs_data *data; +struct rmi_function_container *fc = inodep->i_private; + + data =devm_kzalloc (&fc->dev,sizeof (struct f01_debugfs_data ), +GFP_KERNEL );
Wait, you probably did this because I requested it, but I was maybe wrong?
Will this not re-allocate a chunk every time you look at a debugfs file? So it leaks memory?
In that case common kzalloc() and kfree() is the way to go, as it is for dynamic buffers. Sorry for screwing things up for you. :-(
drivers/input/rmi4/rmi_f01.c line 244
Quoted 8 lines
drivers/input/rmi4/rmi_f01.c new file +8
-0+for (i =0 ; i < f01->irq_count && *local_buf !=0 ; + i++, local_buf +=2 ) { +int irq_shift; +int interrupt_enable; +int result; + + irq_reg = i /8 ; + irq_shift = i %8 ;
Please stop doing these arithmetics-turned-maths things.
irq_reg = i >> 8;irq_shift = i & 0xFF;
(...)
Quoted 9 lines
drivers/input/rmi4/rmi_f01.c new file +9
-0+static ssize_t rmi_fn_01_interrupt_enable_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct rmi_function_container *fc; +struct f01_data *data; +int i, len, total_len =0 ; +char *current_buf = buf; + + fc =to_rmi_function_container (dev);
drivers/input/rmi4/rmi_f01.c line 760
Quoted 10 lines
drivers/input/rmi4/rmi_f01.c new file +10
-0+ data = fc->data; +/* loop through each irq value and copy its +* string representation into buf */ +for (i =0 ; i < data->irq_count; i++) { +int irq_reg; +int irq_shift; +int interrupt_enable; + + irq_reg = i /8 ; + irq_shift = i %8 ;
Dito.
(...)
Quoted 1 line
+static int
f01_probe(struct device *dev);
Do you really need to forward-declare this?
(...)
Quoted 7 lines
drivers/input/rmi4/rmi_f01.c new file +7
-0+static struct rmi_function_handler function_handler = { + .driver = { + .owner =THIS_MODULE , + .name ="rmi_f01" , + .bus = &rmi_bus_type, + .probe = f01_probe, + .remove = f01_remove_device,
drivers/input/rmi4/rmi_f01.c line 1418
Quoted 10 lines
drivers/input/rmi4/rmi_f01.c new file +10
-0+ }, + .func = 0x01, + .config = rmi_f01_config, + .attention = rmi_f01_attention, + +#ifdef CONFIG_PM + .suspend = rmi_f01_suspend, + .resume = rmi_f01_resume, +#endif /* CONFIG_PM */ +};
Just move this block of struct *below* the probe function...
Quoted 1 line
+static
__devinitintf01_probe(struct device *dev)
Header file looks OK (if these unions is the way to go...)
Yours,
Linus Walleij
Re: [RFC PATCH 06/06] input/rmi4: F11 - 2D touch interface
In reply to Christopher HeinyOn Sat, Oct 6, 2012 at 6:10 AM, Christopher Heiny <[email protected]> wrote:
So looking closer at this one since we will use it. Maybe it's in such a good shape now that I should be able to actually test it with the hardware?
(...)
Quoted 1 line
drivers/input/rmi4/rmi_f11.c +0
-0
(...)
drivers/input/rmi4/rmi_f11.c line 37
Quoted 5 lines
drivers/input/rmi4/rmi_f11.c +5
-0+#ifdef CONFIG_RMI4_DEBUG +#include <linux/debugfs.h> +#include <linux/fs.h> +#include <linux/uaccess.h> +#endif
Skip the #ifdef
drivers/input/rmi4/rmi_f11.c line 53
Quoted 4 lines
drivers/input/rmi4/rmi_f11.c +4
-0+#define F11_CTRL_SENSOR_MAX_X_POS_OFFSET 6 +#define F11_CTRL_SENSOR_MAX_Y_POS_OFFSET 8 + +#define F11_CEIL (x, y) (((x) + ((y)-1)) / (y))
Use existing kernel macros in <linux/kernel.h>
In this case:
#define F11_CEIL(x, y) DIV_ROUND_UP(x, y)
Or just use DIV_ROUND_UP() directly in the code, your choice.
Quoted 1 line
+#define
MAX_NAME_LENGTH256
Really? Are you sure there is not a null terminator or length byte included so it's actually 255?
(...)
drivers/input/rmi4/rmi_f11.c line 807
Quoted 8 lines
drivers/input/rmi4/rmi_f11.c +8
-0+static int sensor_debug_open (struct inode *inodep,struct file *filp) +{ +struct sensor_debugfs_data *data; +struct f11_2d_sensor *sensor = inodep->i_private; +struct rmi_function_container *fc = sensor->fc; + + data =devm_kzalloc (&fc->dev,sizeof (struct sensor_debugfs_data ), +GFP_KERNEL );
Again I may have lead you astray. Check if this leaks memory, in that case use kzalloc()/kfree(). Sorry :-(
(...)
drivers/input/rmi4/rmi_f11.c line 1227
Quoted 7 lines
drivers/input/rmi4/rmi_f11.c +7
-0+static int f11_debug_open (struct inode *inodep,struct file *filp) +{ +struct f11_debugfs_data *data; +struct rmi_function_container *fc = inodep->i_private; + + data =devm_kzalloc (&fc->dev,sizeof (struct f11_debugfs_data ), +GFP_KERNEL );
Dito. :-(
(...)
Quoted 3 lines
drivers/input/rmi4/rmi_f11.c +3
-0+static void rmi_f11_abs_pos_report (struct f11_data *f11, +struct f11_2d_sensor *sensor, +u8 finger_state,u8 n_finger)
(...)
drivers/input/rmi4/rmi_f11.c line 1417
Quoted 11 lines
drivers/input/rmi4/rmi_f11.c +11
-0+if (axis_align->flip_y) + y =max (sensor->max_y - y,0 ); + +/* +** here checking if X offset or y offset are specified is +** redundant. We just add the offsets or, clip the values +** +** note: offsets need to be done before clipping occurs, +** or we could get funny values that are outside +** clipping boundaries. +*/
This is a weird commenting style, what's wrong with a single star? (No big deal but it stands out...)
(...)
drivers/input/rmi4/rmi_f11.c line 1795
Quoted 11 lines
drivers/input/rmi4/rmi_f11.c +11
-0+static int f11_allocate_control_regs (struct rmi_device *rmi_dev, +struct f11_2d_device_query *device_query, +struct f11_2d_sensor_query *sensor_query, +struct f11_2d_ctrl *ctrl, +u16 ctrl_base_addr) { + +struct rmi_driver_data *driver_data =dev_get_drvdata (&rmi_dev->dev); +struct rmi_function_container *fc = driver_data->f01_container; + + ctrl->ctrl0_9 =devm_kzalloc (&fc->dev,sizeof (union f11_2d_ctrl0_9 ), +GFP_KERNEL );
If this is called from .probe() only, this is correct.
So the rule is: use devm_* for anything that is allocated at .probe() and released on .remove(). Any other dynamic buffers etc need to use common kzalloc()/kfree().
Quoted 42 lines
drivers/input/rmi4/rmi_f11.c +42
-0+if (!ctrl->ctrl0_9) +return -ENOMEM ; +if (sensor_query->f11_2d_query7__8[0 ]) { + ctrl->ctrl10 =devm_kzalloc (&fc->dev, +sizeof (union f11_2d_ctrl10 ),GFP_KERNEL ); +if (!ctrl->ctrl10) +return -ENOMEM ; + } + +if (sensor_query->f11_2d_query7__8[1 ]) { + ctrl->ctrl11 =devm_kzalloc (&fc->dev, +sizeof (union f11_2d_ctrl11 ),GFP_KERNEL ); +if (!ctrl->ctrl11) +return -ENOMEM ; + } + +if (device_query->has_query9 && sensor_query->query9.has_pen) { + ctrl->ctrl20_21 =devm_kzalloc (&fc->dev, +sizeof (union f11_2d_ctrl20_21 ),GFP_KERNEL ); +if (!ctrl->ctrl20_21) +return -ENOMEM ; + } + +if (device_query->has_query9 && sensor_query->query9.has_proximity) { + ctrl->ctrl22_26 =devm_kzalloc (&fc->dev, +sizeof (union f11_2d_ctrl22_26 ),GFP_KERNEL ); +if (!ctrl->ctrl22_26) +return -ENOMEM ; + } + +if (device_query->has_query9 && + (sensor_query->query9.has_palm_det_sensitivity || + sensor_query->query9.has_suppress_on_palm_detect)) { + ctrl->ctrl27 =devm_kzalloc (&fc->dev, +sizeof (union f11_2d_ctrl27 ),GFP_KERNEL ); +if (!ctrl->ctrl27) +return -ENOMEM ; + } + +if (sensor_query->has_multi_finger_scroll) { + ctrl->ctrl28 =devm_kzalloc (&fc->dev, +sizeof (union f11_2d_ctrl28 ),GFP_KERNEL );
drivers/input/rmi4/rmi_f11.c line 1847
Quoted 10 lines
drivers/input/rmi4/rmi_f11.c +10
-0+if (!ctrl->ctrl28) +return -ENOMEM ; + } + +if (device_query->has_query11 && device_query->has_z_tuning) { + ctrl->ctrl29_30 =devm_kzalloc (&fc->dev, +sizeof (union f11_2d_ctrl29_30 ),GFP_KERNEL ); +if (!ctrl->ctrl29_30) +return -ENOMEM ; + }
All of these are probably correct as well.
drivers/input/rmi4/rmi_f11.c line 1849
Quoted 2 lines
drivers/input/rmi4/rmi_f11.c +2
-0+ +return f11_read_control_regs (rmi_dev, ctrl, ctrl_base_addr);
Hey why are you ending with a call to that function? The function name gets misleading.
Instead call both functions in succession at the call site on .probe().
(...)
Quoted 23 lines
drivers/input/rmi4/rmi_f11.c +23
-0+static int f11_device_init (struct rmi_function_container *fc) +{ +int rc; + + rc =rmi_f11_initialize (fc); +if (rc <0 ) + goto err_free_data; + + rc =rmi_f11_register_devices (fc); +if (rc <0 ) + goto err_free_data; + + rc =rmi_f11_create_sysfs (fc); +if (rc <0 ) + goto err_free_data; + +return 0 ; + +err_free_data: +rmi_f11_free_memory (fc); + +return rc; +}
drivers/input/rmi4/rmi_f11.c line 2132
Quoted 10 lines
drivers/input/rmi4/rmi_f11.c +10
-0+ +static void rmi_f11_free_memory (struct rmi_function_container *fc) +{ +struct f11_data *f11 = fc->data; +int i; + +if (f11) { +for (i =0 ; i < f11->dev_query.nbr_of_sensors +1 ; i++) +kfree (f11->sensors[i].button_map); + }
This is wrong. The button_map was allocated with devm_kzalloc() so it will get automatically freed. Just skip this step.
(...)
Quoted 2 lines
drivers/input/rmi4/rmi_f11.c +2
-0+static int rmi_f11_initialize (struct rmi_function_container *fc) +{
(...)
drivers/input/rmi4/rmi_f11.c line 2197
Quoted 6 lines
drivers/input/rmi4/rmi_f11.c +6
-0+ rc =f11_allocate_control_regs (rmi_dev, + &f11->dev_query, &sensor->sens_query, + &f11->dev_controls, control_base_addr); +if (rc <0 ) { +dev_err (&fc->dev, +"Failed to initialize F11 control params.\n" );
"failed to allocate F11 control params"
drivers/input/rmi4/rmi_f11.c
Quoted 2 lines
drivers/input/rmi4/rmi_f11.c +2
-0+return rc; + }
So after this call the read regs explicitly instead as described above.
(...)
Quoted 9 lines
drivers/input/rmi4/rmi_f11.c +9
-0+static void register_virtual_buttons (struct rmi_function_container *fc, +struct f11_2d_sensor *sensor) { +int j; + +if (!sensor->sens_query.has_gestures) +return ; +if (!sensor->virtual_buttons.buttons) { +dev_warn (&fc->dev,"No virtual button platform data for 2D sensor %d.\n" , + sensor->sensor_index);
drivers/input/rmi4/rmi_f11.c line 2296
Quoted 10 lines
drivers/input/rmi4/rmi_f11.c +10
-0+return ; + } +/* call devm_kcalloc when it will be defined in kernel */ + sensor->button_map =devm_kzalloc (&fc->dev, + sensor->virtual_buttons.buttons, +GFP_KERNEL ); +if (!sensor->button_map) { +dev_err (&fc->dev,"Failed to allocate the virtual button map.\n" ); +return ; + }
So as noted above, since it's using devm_kzalloc(), don't free() it.
(...)
drivers/input/rmi4/rmi_f11.c line 2379
Quoted 7 lines
drivers/input/rmi4/rmi_f11.c +7
-0+ sensor->mouse_input = input_dev_mouse; + input_dev_mouse->name ="rmi_mouse" ; + input_dev_mouse->phys ="rmi_f11/input0" ; + + input_dev_mouse->id.vendor =0x18d1 ; + input_dev_mouse->id.product =0x0210 ; + input_dev_mouse->id.version =0x0100 ;
As noted in previous review, 0x18d1 is Google's vendor ID. Please use a Synaptics Vendor ID, Product ID and version!
Hint: synaptics Vendor ID is 0x06cb.
Yours,
Linus Walleij
Re: [RFC PATCH 06/06] input/rmi4: F11 - 2D touch interface
In reply to Christopher HeinyHi Christopher,
Quoted 3 lines
rmi_f11.cis a driver for 2D touch sensors. It has been updated to support the MT-B specification, partition control attributes between debugfs and sysfs, and to use the standard bus model for loading/unloading.
Please find comments inline.
Generally, if you want this merged as an input device sometime in the future, you need to reduce the size and complexity of the whole patchset. Given that you only need to feed the input subsystem with raw data, you can make do without most of the sysfs nodes, debug output, and internal gesture state.
The 2D sensor data, currently living in debugfs, might eventually find a home in the input subsystem, based on the growing interest from several directions. However, if you are just looking for a way to transport the rmi data to userland, please consider implementing this under a different subsystem.
Quoted 44 lines
drivers/input/rmi4/rmi_f11.c new file +38
-0@@ -0,0 +1,2727 @@ +/* +* Copyright (c) 2011,2012 Synaptics Incorporated +* Copyright (c) 2011 Unixphere +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#define FUNCTION_DATA f11_data +#define FNUM 11 + +#include <linux/kernel.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/input.h> +#include <linux/input/mt.h> +#include <linux/kconfig.h> +#include <linux/rmi.h> +#include <linux/slab.h> +#include "rmi_driver.h" + +#ifdef CONFIG_RMI4_DEBUG +#include <linux/debugfs.h> +#include <linux/fs.h> +#include <linux/uaccess.h> +#endif +
drivers/input/rmi4/rmi_f11.c line 48
Quoted 10 lines
drivers/input/rmi4/rmi_f11.c new file +10
-0+#define F11_MAX_NUM_OF_SENSORS 8 +#define F11_MAX_NUM_OF_FINGERS 10 +#define F11_MAX_NUM_OF_TOUCH_SHAPES 16 + +#define F11_REL_POS_MIN -128 +#define F11_REL_POS_MAX 127 + +#define FINGER_STATE_MASK 0x03 +#define GET_FINGER_STATE (f_states, i) \ + ((f_states[i / 4] >> (2 * (i % 4))) & FINGER_STATE_MASK)
These could be open-coded or put in a function instead.
Quoted 34 lines
drivers/input/rmi4/rmi_f11.c new file +34
-0+ +#define F11_CTRL_SENSOR_MAX_X_POS_OFFSET 6 +#define F11_CTRL_SENSOR_MAX_Y_POS_OFFSET 8 + +#define F11_CEIL (x, y) (((x) + ((y)-1)) / (y)) +#define INBOX (x, y, box) (x >= box.x && x < (box.x + box.width) \ + && y >= box.y && y < (box.y + box.height)) + +#define DEFAULT_XY_MAX 9999 +#define DEFAULT_MAX_ABS_MT_PRESSURE 255 +#define DEFAULT_MAX_ABS_MT_TOUCH 15 +#define DEFAULT_MAX_ABS_MT_ORIENTATION 1 +#define DEFAULT_MIN_ABS_MT_TRACKING_ID 1 +#define DEFAULT_MAX_ABS_MT_TRACKING_ID 10 +#define MAX_NAME_LENGTH 256 + +static ssize_t f11_relreport_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +static ssize_t f11_relreport_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count); + +static ssize_t f11_maxPos_show (struct device *dev, +struct device_attribute *attr,char *buf); + +static ssize_t f11_rezero_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count); + +static void rmi_f11_free_memory (struct rmi_function_container *fc); + +static int rmi_f11_initialize (struct rmi_function_container *fc);
drivers/input/rmi4/rmi_f11.c line 92
Quoted 10 lines
drivers/input/rmi4/rmi_f11.c new file +10
-0+ +static int rmi_f11_create_sysfs (struct rmi_function_container *fc); + +static int rmi_f11_config (struct rmi_function_container *fc); + +static int rmi_f11_register_devices (struct rmi_function_container *fc); + +static void rmi_f11_free_devices (struct rmi_function_container *fc); + +static void f11_set_abs_params (struct rmi_function_container *fc,int index);
Please try to get rid of these.
Quoted 8 lines
drivers/input/rmi4/rmi_f11.c new file +8
-0+ +static struct device_attribute attrs[] = { +__ATTR (relreport,RMI_RW_ATTR , f11_relreport_show, f11_relreport_store), +__ATTR (maxPos,RMI_RO_ATTR , f11_maxPos_show, rmi_store_error), +__ATTR (rezero,RMI_WO_ATTR , rmi_show_error, f11_rezero_store) +}; + +/**
drivers/input/rmi4/rmi_f11.c line 110
Quoted 10 lines
drivers/input/rmi4/rmi_f11.c new file +10
-0+* @rezero - writing 1 to this will cause the sensor to calibrate to the +* current capacitive state. +*/ +union f11_2d_commands { +struct { +bool rezero:1 ; +u8 reserved:7 ; + } __attribute__((__packed__ )); +u8 reg; +};
Maybe a constant would be more suitable here?
Quoted 24 lines
drivers/input/rmi4/rmi_f11.c new file +24
-0+ +/** +* @nbr_of_sensors - the number of 2D sensors on the touch device. +* @has_query9 - indicates the F11_2D_Query9 register exists. +* @has_query11 - indicates the F11_2D_Query11 register exists. +* @has_z_tuning - if set, the sensor supports Z tuning and registers +* F11_2D_Ctrl29 through F11_2D_Ctrl33 exist. +* @has_pos_interpolation_tuning - TBD +* @has_w_tuning - the sensor supports Wx and Wy scaling and registers +* F11_2D_Ctrl36 through F11_2D_Ctrl39 exist. +* @has_pitch_info - the X and Y pitches of the sensor electrodes can be +* configured and registers F11_2D_Ctrl40 and F11_2D_Ctrl41 exist. +* @has_default_finger_width - the default finger width settings for the +* sensor can be configured and registers F11_2D_Ctrl42 through F11_2D_Ctrl44 +* exist. +* @has_segmentation_aggressiveness - the sensor’s ability to distinguish +* multiple objects close together can be configured and register F11_2D_Ctrl45 +* exists. +* @has_tx_rw_clip - the inactive outside borders of the sensor can be +* configured and registers F11_2D_Ctrl46 through F11_2D_Ctrl49 exist. +* @has_drumming_correction - the sensor can be configured to distinguish +* between a fast flick and a quick drumming movement and registers +* F11_2D_Ctrl50 and F11_2D_Ctrl51 exist. +*/
drivers/input/rmi4/rmi_f11.c line 144
Quoted 10 lines
drivers/input/rmi4/rmi_f11.c new file +10
-0+struct f11_2d_device_query { +union { +struct { +u8 nbr_of_sensors:3 ; +bool has_query9:1 ; +bool has_query11:1 ; +u8 reserved:3 ; + } __attribute__((__packed__ )); +u8 f11_2d_query0; + };
Why union here? It seems all you need is a packed struct named query0.
Quoted 5 lines
drivers/input/rmi4/rmi_f11.c new file +5
-0+ + union { + struct { + bool has_z_tuning:1; + bool has_pos_interpolation_tuning:1;
drivers/input/rmi4/rmi_f11.c line 159
Quoted 10 lines
drivers/input/rmi4/rmi_f11.c new file +10
-0+ bool has_w_tuning:1; + bool has_pitch_info:1; + bool has_default_finger_width:1; + bool has_segmentation_aggressiveness:1; + bool has_tx_rw_clip:1; + bool has_drumming_correction:1; + } __attribute__((__packed__)); +u8 f11_2d_query11; + }; +};
Ditto.
Quoted 14 lines
drivers/input/rmi4/rmi_f11.c new file +14
-0+ +/** +* @has_pen - detection of a stylus is supported and registers F11_2D_Ctrl20 +* and F11_2D_Ctrl21 exist. +* @has_proximity - detection of fingers near the sensor is supported and +* registers F11_2D_Ctrl22 through F11_2D_Ctrl26 exist. +* @has_palm_det_sensitivity - the sensor supports the palm detect sensitivity +* feature and register F11_2D_Ctrl27 exists. +* @has_two_pen_thresholds - is has_pen is also set, then F11_2D_Ctrl35 exists. +* @has_contact_geometry - the sensor supports the use of contact geometry to +* map absolute X and Y target positions and registers F11_2D_Data18.* through +* F11_2D_Data27 exist. +*/ +union f11_2d_query9 {
drivers/input/rmi4/rmi_f11.c line 183
Quoted 10 lines
drivers/input/rmi4/rmi_f11.c new file +10
-0+struct { +bool has_pen:1 ; +bool has_proximity:1 ; +bool has_palm_det_sensitivity:1 ; +bool has_suppress_on_palm_detect:1 ; +bool has_two_pen_thresholds:1 ; +bool has_contact_geometry:1 ; + } __attribute__((__packed__ )); +u8 reg; +};
Ditto.
Quoted 104 lines
drivers/input/rmi4/rmi_f11.c new file +104
-0+ +/** +* @number_of_fingers - describes the maximum number of fingers the 2-D sensor +* supports. +* @has_rel - the sensor supports relative motion reporting. +* @has_abs - the sensor supports absolute poition reporting. +* @has_gestures - the sensor supports gesture reporting. +* @has_sensitivity_adjust - the sensor supports a global sensitivity +* adjustment. +* @configurable - the sensor supports various configuration options. +* @num_of_x_electrodes - the maximum number of electrodes the 2-D sensor +* supports on the X axis. +* @num_of_y_electrodes - the maximum number of electrodes the 2-D sensor +* supports on the Y axis. +* @max_electrodes - the total number of X and Y electrodes that may be +* configured. +* @abs_data_size - describes the format of data reported by the absolute +* data source. Only one format (the kind used here) is supported at this +* time. +* @has_anchored_finger - then the sensor supports the high-precision second +* finger tracking provided by the manual tracking and motion sensitivity +* options. +* @has_adjust_hyst - the difference between the finger release threshold and +* the touch threshold. +* @has_dribble - the sensor supports the generation of dribble interrupts, +* which may be enabled or disabled with the dribble control bit. +* @f11_2d_query6 - reserved. +* @has_single_tap - a basic single-tap gesture is supported. +* @has_tap_n_hold - tap-and-hold gesture is supported. +* @has_double_tap - double-tap gesture is supported. +* @has_early_tap - early tap is supported and reported as soon as the finger +* lifts for any tap event that could be interpreted as either a single tap +* or as the first tap of a double-tap or tap-and-hold gesture. +* @has_flick - flick detection is supported. +* @has_press - press gesture reporting is supported. +* @has_pinch - pinch gesture detection is supported. +* @has_palm_det - the 2-D sensor notifies the host whenever a large conductive +* object such as a palm or a cheek touches the 2-D sensor. +* @has_rotate - rotation gesture detection is supported. +* @has_touch_shapes - TouchShapes are supported. A TouchShape is a fixed +* rectangular area on the sensor that behaves like a capacitive button. +* @has_scroll_zones - scrolling areas near the sensor edges are supported. +* @has_individual_scroll_zones - if 1, then 4 scroll zones are supported; +* if 0, then only two are supported. +* @has_multi_finger_scroll - the multifinger_scrolling bit will be set when +* more than one finger is involved in a scrolling action. +* @nbr_touch_shapes - the total number of touch shapes supported. +*/ +struct f11_2d_sensor_query { +union { +struct { +/* query1 */ +u8 number_of_fingers:3 ; +bool has_rel:1 ; +bool has_abs:1 ; +bool has_gestures:1 ; +bool has_sensitivity_adjust:1 ; +bool configurable:1 ; +/* query2 */ +u8 num_of_x_electrodes:7 ; +u8 reserved_1:1 ; +/* query3 */ +u8 num_of_y_electrodes:7 ; +u8 reserved_2:1 ; +/* query4 */ +u8 max_electrodes:7 ; +u8 reserved_3:1 ; + } __attribute__((__packed__ )); +u8 f11_2d_query1__4[4 ]; + }; + +union { +struct { +u8 abs_data_size:3 ; +bool has_anchored_finger:1 ; +bool has_adj_hyst:1 ; +bool has_dribble:1 ; +u8 reserved_4:2 ; + } __attribute__((__packed__ )); +u8 f11_2d_query5; + }; + +u8 f11_2d_query6; + +union { +struct { +bool has_single_tap:1 ; +bool has_tap_n_hold:1 ; +bool has_double_tap:1 ; +bool has_early_tap:1 ; +bool has_flick:1 ; +bool has_press:1 ; +bool has_pinch:1 ; +bool padding:1 ; + +bool has_palm_det:1 ; +bool has_rotate:1 ; +bool has_touch_shapes:1 ; +bool has_scroll_zones:1 ; +bool has_individual_scroll_zones:1 ; +bool has_multi_finger_scroll:1 ; + } __attribute__((__packed__ )); +u8 f11_2d_query7__8[2 ]; + };
drivers/input/rmi4/rmi_f11.c line 297
Quoted 10 lines
drivers/input/rmi4/rmi_f11.c new file +10
-0+ +union f11_2d_query9 query9; + +union { +struct { +u8 nbr_touch_shapes:5 ; + } __attribute__((__packed__ )); +u8 f11_2d_query10; + }; +};
Ditto. It is nice with some documentation, but in this case, it might make sense to add it on the same line in the struct. Also, since an MT device outputs the raw position data and leaves the gestures to userspace, this whole construct is more complex than it needs to be.
Quoted 181 lines
drivers/input/rmi4/rmi_f11.c new file +181
-0+ +/** +* @reporting_mode - controls how often finger position data is reported. +* @abs_pos_filt - when set, enables various noise and jitter filtering +* algorithms for absolute reports. +* @rel_pos_filt - when set, enables various noise and jitter filtering +* algorithms for relative reports. +* @rel_ballistics - enables ballistics processing for the relative finger +* motion on the 2-D sensor. +* @dribble - enables the dribbling feature. +* @report_beyond_clip - when this is set, fingers outside the active area +* specified by the x_clip and y_clip registers will be reported, but with +* reported finger position clipped to the edge of the active area. +* @palm_detect_thresh - the threshold at which a wide finger is considered a +* palm. A value of 0 inhibits palm detection. +* @motion_sensitivity - specifies the threshold an anchored finger must move +* before it is considered no longer anchored. High values mean more +* sensitivity. +* @man_track_en - for anchored finger tracking, whether the host (1) or the +* device (0) determines which finger is the tracked finger. +* @man_tracked_finger - when man_track_en is 1, specifies whether finger 0 or +* finger 1 is the tracked finger. +* @delta_x_threshold - 2-D position update interrupts are inhibited unless +* the finger moves more than a certain threshold distance along the X axis. +* @delta_y_threshold - 2-D position update interrupts are inhibited unless +* the finger moves more than a certain threshold distance along the Y axis. +* @velocity - When rel_ballistics is set, this register defines the +* velocity ballistic parameter applied to all relative motion events. +* @acceleration - When rel_ballistics is set, this register defines the +* acceleration ballistic parameter applied to all relative motion events. +* @sensor_max_x_pos - the maximum X coordinate reported by the sensor. +* @sensor_max_y_pos - the maximum Y coordinate reported by the sensor. +*/ +union f11_2d_ctrl0_9 { +struct { +/* F11_2D_Ctrl0 */ +u8 reporting_mode:3 ; +bool abs_pos_filt:1 ; +bool rel_pos_filt:1 ; +bool rel_ballistics:1 ; +bool dribble:1 ; +bool report_beyond_clip:1 ; +/* F11_2D_Ctrl1 */ +u8 palm_detect_thres:4 ; +u8 motion_sensitivity:2 ; +bool man_track_en:1 ; +bool man_tracked_finger:1 ; +/* F11_2D_Ctrl2 and 3 */ +u8 delta_x_threshold:8 ; +u8 delta_y_threshold:8 ; +/* F11_2D_Ctrl4 and 5 */ +u8 velocity:8 ; +u8 acceleration:8 ; +/* F11_2D_Ctrl6 thru 9 */ +u16 sensor_max_x_pos:12 ; +u8 ctrl7_reserved:4 ; +u16 sensor_max_y_pos:12 ; +u8 ctrl9_reserved:4 ; + } __attribute__((__packed__ )); +struct { +u8 regs[10 ]; +u16 address; + } __attribute__((__packed__ )); +}; + +/** +* @single_tap_int_enable - enable tap gesture recognition. +* @tap_n_hold_int_enable - enable tap-and-hold gesture recognition. +* @double_tap_int_enable - enable double-tap gesture recognition. +* @early_tap_int_enable - enable early tap notification. +* @flick_int_enable - enable flick detection. +* @press_int_enable - enable press gesture recognition. +* @pinch_int_enable - enable pinch detection. +*/ +union f11_2d_ctrl10 { +struct { +bool single_tap_int_enable:1 ; +bool tap_n_hold_int_enable:1 ; +bool double_tap_int_enable:1 ; +bool early_tap_int_enable:1 ; +bool flick_int_enable:1 ; +bool press_int_enable:1 ; +bool pinch_int_enable:1 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +/** +* @palm_detect_int_enable - enable palm detection feature. +* @rotate_int_enable - enable rotate gesture detection. +* @touch_shape_int_enable - enable the TouchShape feature. +* @scroll_zone_int_enable - enable scroll zone reporting. +* @multi_finger_scroll_int_enable - enable the multfinger scroll feature. +*/ +union f11_2d_ctrl11 { +struct { +bool palm_detect_int_enable:1 ; +bool rotate_int_enable:1 ; +bool touch_shape_int_enable:1 ; +bool scroll_zone_int_enable:1 ; +bool multi_finger_scroll_int_enable:1 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +union f11_2d_ctrl12 { +struct { +u8 sensor_map:7 ; +bool xy_sel:1 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +/** +* @sens_adjustment - allows a host to alter the overall sensitivity of a +* 2-D sensor. A positive value in this register will make the sensor more +* sensitive than the factory defaults, and a negative value will make it +* less sensitive. +* @hyst_adjustment - increase the touch/no-touch hysteresis by 2 Z-units for +* each one unit increment in this setting. +*/ +union f11_2d_ctrl14 { +struct { +s8 sens_adjustment:5 ; +u8 hyst_adjustment:3 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +/** +* @max_tap_time - the maximum duration of a tap, in 10-millisecond units. +*/ +union f11_2d_ctrl15 { +struct { +u8 max_tap_time:8 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +/** +* @min_press_time - The minimum duration required for stationary finger(s) to +* generate a press gesture, in 10-millisecond units. +*/ +union f11_2d_ctrl16 { +struct { +u8 min_press_time:8 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +/** +* @max_tap_distance - Determines the maximum finger movement allowed during +* a tap, in 0.1-millimeter units. +*/ +union f11_2d_ctrl17 { +struct { +u8 max_tap_distance:8 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +/** +* @min_flick_distance - the minimum finger movement for a flick gesture, +* in 1-millimeter units. +* @min_flick_speed - the minimum finger speed for a flick gesture, in +* 10-millimeter/second units. +*/ +union f11_2d_ctrl18_19 { +struct { +u8 min_flick_distance:8 ; +u8 min_flick_speed:8 ; + } __attribute__((__packed__ )); +u8 reg[2 ]; +}; + +/** +* @pen_detect_enable - enable reporting of stylus activity. +* @pen_jitter_filter_enable - Setting this enables the stylus anti-jitter +* filter. +* @pen_z_threshold - This is the stylus-detection lower threshold. Smaller +* values result in higher sensitivity.
drivers/input/rmi4/rmi_f11.c line 488
Quoted 10 lines
drivers/input/rmi4/rmi_f11.c new file +10
-0+*/ +union f11_2d_ctrl20_21 { +struct { +bool pen_detect_enable:1 ; +bool pen_jitter_filter_enable:1 ; +u8 ctrl20_reserved:6 ; +u8 pen_z_threshold:8 ; + } __attribute__((__packed__ )); +u8 reg[2 ]; +};
Given that most of the above will not be used in this driver, it can probably be compressed quite a bit.
Quoted 99 lines
drivers/input/rmi4/rmi_f11.c new file +99
-0+ +/** +* These are not accessible through sysfs yet. +* +* @proximity_detect_int_en - enable proximity detection feature. +* @proximity_jitter_filter_en - enables an anti-jitter filter on proximity +* data. +* @proximity_detection_z_threshold - the threshold for finger-proximity +* detection. +* @proximity_delta_x_threshold - In reduced-reporting modes, this is the +* threshold for proximate-finger movement in the direction parallel to the +* X-axis. +* @proximity_delta_y_threshold - In reduced-reporting modes, this is the +* threshold for proximate-finger movement in the direction parallel to the +* Y-axis. +* * @proximity_delta_Z_threshold - In reduced-reporting modes, this is the +* threshold for proximate-finger movement in the direction parallel to the +* Z-axis. +*/ +union f11_2d_ctrl22_26 { +struct { +/* control 22 */ +bool proximity_detect_int_en:1 ; +bool proximity_jitter_filter_en:1 ; +u8 f11_2d_ctrl6_b3__7:6 ; + +/* control 23 */ +u8 proximity_detection_z_threshold; + +/* control 24 */ +u8 proximity_delta_x_threshold; + +/* control 25 */ +u8 proximity_delta_y_threshold; + +/* control 26 */ +u8 proximity_delta_z_threshold; + } __attribute__((__packed__ )); +u8 regs[5 ]; +}; + +/** +* @palm_detecy_sensitivity - When this value is small, smaller objects will +* be identified as palms; when this value is large, only larger objects will +* be identified as palms. 0 represents the factory default. +* @suppress_on_palm_detect - when set, all F11 interrupts except palm_detect +* are suppressed while a palm is detected. +*/ +union f11_2d_ctrl27 { +struct { +s8 palm_detect_sensitivity:4 ; +bool suppress_on_palm_detect:1 ; +u8 f11_2d_ctrl27_b5__7:3 ; + } __attribute__((__packed__ )); +u8 regs[1 ]; +}; + +/** +* @multi_finger_scroll_mode - allows choice of multi-finger scroll mode and +* determines whether and how X or Y displacements are reported. +* @edge_motion_en - enables the edge_motion feature. +* @multi_finger_scroll_momentum - controls the length of time that scrolling +* continues after fingers have been lifted. +*/ +union f11_2d_ctrl28 { +struct { +u8 multi_finger_scroll_mode:2 ; +bool edge_motion_en:1 ; +bool f11_2d_ctrl28b_3:1 ; +u8 multi_finger_scroll_momentum:4 ; + } __attribute__((__packed__ )); +u8 regs[1 ]; +}; + +/** +* @z_touch_threshold - Specifies the finger-arrival Z threshold. Large values +* may cause smaller fingers to be rejected. +* @z_touch_hysteresis - Specifies the difference between the finger-arrival +* Z threshold and the finger-departure Z threshold. +*/ +union f11_2d_ctrl29_30 { +struct { +u8 z_touch_threshold; +u8 z_touch_hysteresis; + } __attribute__((__packed__ )); +struct { +u8 regs[2 ]; +u16 address; + } __attribute__((__packed__ )); +}; + + +struct f11_2d_ctrl { +union f11_2d_ctrl0_9 *ctrl0_9; +union f11_2d_ctrl10 *ctrl10; +union f11_2d_ctrl11 *ctrl11; +union f11_2d_ctrl12 *ctrl12; +u8 ctrl12_size; +union f11_2d_ctrl14 *ctrl14;
drivers/input/rmi4/rmi_f11.c line 597
Quoted 10 lines
drivers/input/rmi4/rmi_f11.c new file +10
-0+union f11_2d_ctrl15 *ctrl15; +union f11_2d_ctrl16 *ctrl16; +union f11_2d_ctrl17 *ctrl17; +union f11_2d_ctrl18_19 *ctrl18_19; +union f11_2d_ctrl20_21 *ctrl20_21; +union f11_2d_ctrl22_26 *ctrl22_26; +union f11_2d_ctrl27 *ctrl27; +union f11_2d_ctrl28 *ctrl28; +union f11_2d_ctrl29_30 *ctrl29_30; +};
Will any of this data be used at all?
Quoted 160 lines
drivers/input/rmi4/rmi_f11.c new file +160
-0+ +/** +* @x_msb - top 8 bits of X finger position. +* @y_msb - top 8 bits of Y finger position. +* @x_lsb - bottom 4 bits of X finger position. +* @y_lsb - bottom 4 bits of Y finger position. +* @w_y - contact patch width along Y axis. +* @w_x - contact patch width along X axis. +* @z - finger Z value (proxy for pressure). +*/ +struct f11_2d_data_1_5 { +u8 x_msb; +u8 y_msb; +u8 x_lsb:4 ; +u8 y_lsb:4 ; +u8 w_y:4 ; +u8 w_x:4 ; +u8 z; +}; + +/** +* @delta_x - relative motion along X axis. +* @delta_y - relative motion along Y axis. +*/ +struct f11_2d_data_6_7 { +s8 delta_x; +s8 delta_y; +}; + +/** +* @single_tap - a single tap was recognized. +* @tap_and_hold - a tap-and-hold gesture was recognized. +* @double_tap - a double tap gesture was recognized. +* @early_tap - a tap gesture might be happening. +* @flick - a flick gesture was detected. +* @press - a press gesture was recognized. +* @pinch - a pinch gesture was detected. +*/ +struct f11_2d_data_8 { +bool single_tap:1 ; +bool tap_and_hold:1 ; +bool double_tap:1 ; +bool early_tap:1 ; +bool flick:1 ; +bool press:1 ; +bool pinch:1 ; +}; + +/** +* @palm_detect - a palm or other large object is in contact with the sensor. +* @rotate - a rotate gesture was detected. +* @shape - a TouchShape has been activated. +* @scrollzone - scrolling data is available. +* @finger_count - number of fingers involved in the reported gesture. +*/ +struct f11_2d_data_9 { +bool palm_detect:1 ; +bool rotate:1 ; +bool shape:1 ; +bool scrollzone:1 ; +u8 finger_count:3 ; +}; + +/** +* @pinch_motion - when a pinch gesture is detected, this is the change in +* distance between the two fingers since this register was last read. +*/ +struct f11_2d_data_10 { +s8 pinch_motion; +}; + +/** +* @x_flick_dist - when a flick gesture is detected, the distance of flick +* gesture in X direction. +* @y_flick_dist - when a flick gesture is detected, the distance of flick +* gesture in Y direction. +* @flick_time - the total time of the flick gesture, in 10ms units. +*/ +struct f11_2d_data_10_12 { +s8 x_flick_dist; +s8 y_flick_dist; +u8 flick_time; +}; + +/** +* @motion - when a rotate gesture is detected, the accumulated distance +* of the rotate motion. Clockwise motion is positive and counterclockwise +* motion is negative. +* @finger_separation - when a rotate gesture is detected, the distance +* between the fingers. +*/ +struct f11_2d_data_11_12 { +s8 motion; +u8 finger_separation; +}; + +/** +* @shape_n - a bitmask of the currently activate TouchShapes (if any). +*/ +struct f11_2d_data_13 { +u8 shape_n; +}; + +/** +* @horizontal - chiral scrolling distance in the X direction. +* @vertical - chiral scrolling distance in the Y direction. +*/ +struct f11_2d_data_14_15 { +s8 horizontal; +s8 vertical; +}; + +/** +* @x_low - scroll zone motion along the lower edge of the sensor. +* @y_right - scroll zone motion along the right edge of the sensor. +* @x_upper - scroll zone motion along the upper edge of the sensor. +* @y_left - scroll zone motion along the left edge of the sensor. +*/ +struct f11_2d_data_14_17 { +s8 x_low; +s8 y_right; +s8 x_upper; +s8 y_left; +}; + +struct f11_2d_data { +u8 *f_state; +const struct f11_2d_data_1_5 *abs_pos; +const struct f11_2d_data_6_7 *rel_pos; +const struct f11_2d_data_8 *gest_1; +const struct f11_2d_data_9 *gest_2; +const struct f11_2d_data_10 *pinch; +const struct f11_2d_data_10_12 *flick; +const struct f11_2d_data_11_12 *rotate; +const struct f11_2d_data_13 *shapes; +const struct f11_2d_data_14_15 *multi_scroll; +const struct f11_2d_data_14_17 *scroll_zones; +}; + +struct f11_2d_sensor { +struct rmi_f11_2d_axis_alignment axis_align; +struct f11_2d_sensor_query sens_query; +struct f11_2d_data data; +int prev_x[F11_MAX_NUM_OF_FINGERS ]; +int prev_y[F11_MAX_NUM_OF_FINGERS ]; +u16 max_x; +u16 max_y; +u8 nbr_fingers; +u8 finger_tracker[F11_MAX_NUM_OF_FINGERS ]; +u8 *data_pkt; +int pkt_size; +u8 sensor_index; +u8 *button_map; +struct rmi_f11_virtualbutton_map virtual_buttons; +bool type_a; +char input_name[MAX_NAME_LENGTH ]; +char input_phys[MAX_NAME_LENGTH ]; +struct input_dev *input; +struct input_dev *mouse_input; +struct rmi_function_container *fc;
drivers/input/rmi4/rmi_f11.c line 767
Quoted 10 lines
drivers/input/rmi4/rmi_f11.c new file +10
-0+ +#ifdef CONFIG_RMI4_DEBUG +struct dentry *debugfs_flip; +struct dentry *debugfs_clip; +struct dentry *debugfs_delta_threshold; +struct dentry *debugfs_offset; +struct dentry *debugfs_swap; +struct dentry *debugfs_type_a; +#endif +};
Up to this point in the file, very little is essential to the input deivce.
Quoted 21 lines
drivers/input/rmi4/rmi_f11.c new file +21
-0+ +struct f11_data { +struct f11_2d_device_query dev_query; +struct f11_2d_ctrl dev_controls; +struct mutex dev_controls_mutex; +u16 rezero_wait_ms; +struct f11_2d_sensor sensors[F11_MAX_NUM_OF_SENSORS ]; + +#ifdef CONFIG_RMI4_DEBUG +struct dentry *debugfs_rezero_wait; +#endif +}; + +enum finger_state_values { +F11_NO_FINGER =0x00 , +F11_PRESENT =0x01 , +F11_INACCURATE =0x02 , +F11_RESERVED =0x03 +}; + +/* ctrl sysfs files */
drivers/input/rmi4/rmi_f11.c line 798
Quoted 10 lines
drivers/input/rmi4/rmi_f11.c new file +10
-0+show_store_union_struct_prototype(abs_pos_filt) +show_store_union_struct_prototype(z_touch_threshold) +show_store_union_struct_prototype(z_touch_hysteresis) + +#ifdef CONFIG_RMI4_DEBUG + +struct sensor_debugfs_data { +bool done; +struct f11_2d_sensor *sensor; +};
And this is really needed?
[...]
drivers/input/rmi4/rmi_f11.c line 1371
Quoted 7 lines
drivers/input/rmi4/rmi_f11.c new file +7
-0+static void rmi_f11_abs_pos_report (struct f11_data *f11, +struct f11_2d_sensor *sensor, +u8 finger_state,u8 n_finger) +{ +struct f11_2d_data *data = &sensor->data; +struct rmi_f11_2d_axis_alignment *axis_align = &sensor->axis_align; +u8 prev_state = sensor->finger_tracker[n_finger];
No need to keep track of the old state.
drivers/input/rmi4/rmi_f11.c line 1378
Quoted 7 lines
drivers/input/rmi4/rmi_f11.c new file +7
-0+int x, y, z; +int w_x, w_y, w_max, w_min, orient; +int temp; + +if (prev_state && !finger_state) { +/* this is a release */ + x = y = z = w_max = w_min = orient =0 ;
This data is not sent during a release.
Quoted 37 lines
drivers/input/rmi4/rmi_f11.c new file +37
-0+ }else if (!prev_state && !finger_state) { +/* nothing to report */ +return ; + }else { + x = ((data->abs_pos[n_finger].x_msb <<4 ) | + data->abs_pos[n_finger].x_lsb); + y = ((data->abs_pos[n_finger].y_msb <<4 ) | + data->abs_pos[n_finger].y_lsb); + z = data->abs_pos[n_finger].z; + w_x = data->abs_pos[n_finger].w_x; + w_y = data->abs_pos[n_finger].w_y; + w_max =max (w_x, w_y); + w_min =min (w_x, w_y); + +if (axis_align->swap_axes) { + temp = x; + x = y; + y = temp; + temp = w_x; + w_x = w_y; + w_y = temp; + } + + orient = w_x > w_y ?1 :0 ; + +if (axis_align->flip_x) + x =max (sensor->max_x - x,0 ); + +if (axis_align->flip_y) + y =max (sensor->max_y - y,0 ); + +/* +** here checking if X offset or y offset are specified is +** redundant. We just add the offsets or, clip the values +** +** note: offsets need to be done before clipping occurs, +** or we could get funny values that are outside
drivers/input/rmi4/rmi_f11.c line 1425
Quoted 10 lines
drivers/input/rmi4/rmi_f11.c new file +10
-0+** clipping boundaries. +*/ + x += axis_align->offset_X; + y += axis_align->offset_Y; + x =max (axis_align->clip_X_low, x); + y =max (axis_align->clip_Y_low, y); +if (axis_align->clip_X_high) + x =min (axis_align->clip_X_high, x); +if (axis_align->clip_Y_high) + y =min (axis_align->clip_Y_high, y);
Why is the clipping configurable?
drivers/input/rmi4/rmi_f11.c line 1434
Quoted 9 lines
drivers/input/rmi4/rmi_f11.c new file +9
-0+ + } + +/* Some UIs ignore W of zero, so we fudge it to 1 for pens. */ +if (IS_ENABLED (CONFIG_RMI4_F11_PEN ) && +get_tool_type (sensor, finger_state) ==MT_TOOL_PEN ) { + w_max =max (1 , w_max); + w_min =max (1 , w_min); + }
Is this not true for all tool types?
drivers/input/rmi4/rmi_f11.c line 1444
Quoted 10 lines
drivers/input/rmi4/rmi_f11.c new file +10
-0+ +if (sensor->type_a) { +input_report_abs (sensor->input,ABS_MT_TRACKING_ID , n_finger); +input_report_abs (sensor->input,ABS_MT_TOOL_TYPE , +get_tool_type (sensor, finger_state)); + }else { +input_mt_slot (sensor->input, n_finger); +input_mt_report_slot_state (sensor->input, +get_tool_type (sensor, finger_state), finger_state); + }
The driver should only report MT-B, please.
drivers/input/rmi4/rmi_f11.c line 1451
Quoted 6 lines
drivers/input/rmi4/rmi_f11.c new file +6
-0+input_report_abs (sensor->input,ABS_MT_PRESSURE , z); +input_report_abs (sensor->input,ABS_MT_TOUCH_MAJOR , w_max); +input_report_abs (sensor->input,ABS_MT_TOUCH_MINOR , w_min); +input_report_abs (sensor->input,ABS_MT_ORIENTATION , orient); +input_report_abs (sensor->input,ABS_MT_POSITION_X , x); +input_report_abs (sensor->input,ABS_MT_POSITION_Y , y);
Only if finger_state is true.
Quoted 31 lines
drivers/input/rmi4/rmi_f11.c new file +31
-0+dev_dbg (&sensor->fc->dev, +"finger[%d]:%d - x:%d y:%d z:%d w_max:%d w_min:%d\n" , + n_finger, finger_state, x, y, z, w_max, w_min); +/* MT sync between fingers */ +if (sensor->type_a) +input_mt_sync (sensor->input); + + sensor->finger_tracker[n_finger] = finger_state; +} + +#ifdef CONFIG_RMI4_VIRTUAL_BUTTON +static int rmi_f11_virtual_button_handler (struct f11_2d_sensor *sensor) +{ +int i; +int x; +int y; +struct rmi_button_map *virtualbutton_map; + +if (sensor->sens_query.has_gestures && + sensor->data.gest_1->single_tap) { + virtualbutton_map = &sensor->virtualbutton_map; + x = ((sensor->data.abs_pos[0 ].x_msb <<4 ) | + sensor->data.abs_pos[0 ].x_lsb); + y = ((sensor->data.abs_pos[0 ].y_msb <<4 ) | + sensor->data.abs_pos[0 ].y_lsb); +for (i =0 ; i < virtualbutton_map->buttons; i++) { +if (INBOX (x, y, virtualbutton_map->map[i])) { +input_report_key (sensor->input, + virtualbutton_map->map[i].code,1 ); +input_report_key (sensor->input, + virtualbutton_map->map[i].code,0 );
drivers/input/rmi4/rmi_f11.c line 1492
Quoted 10 lines
drivers/input/rmi4/rmi_f11.c new file +10
-0+input_sync (sensor->input); + return 0; + } + } + } +return 0 ; +} +#else +#define rmi_f11_virtual_button_handler (sensor) +#endif
No virtual buttons, please, this can easily be mapped in userspace.
Quoted 18 lines
drivers/input/rmi4/rmi_f11.c new file +18
-0+static void rmi_f11_finger_handler (struct f11_data *f11, +struct f11_2d_sensor *sensor) +{ +const u8 *f_state = sensor->data.f_state; +u8 finger_state; +u8 finger_pressed_count; +u8 i; + +for (i =0 , finger_pressed_count =0 ; i < sensor->nbr_fingers; i++) { +/* Possible of having 4 fingers per f_statet register */ + finger_state =GET_FINGER_STATE (f_state, i); + +if (finger_state ==F11_RESERVED ) { +pr_err ("%s: Invalid finger state[%d]:0x%02x." , __func__, + i, finger_state); +continue ; + }else if ((finger_state ==F11_PRESENT ) || + (finger_state ==F11_INACCURATE )) {
drivers/input/rmi4/rmi_f11.c line 1520
Quoted 10 lines
drivers/input/rmi4/rmi_f11.c new file +10
-0+ finger_pressed_count++; + } + +if (sensor->data.abs_pos) +rmi_f11_abs_pos_report (f11, sensor, finger_state, i); + +if (sensor->data.rel_pos) +rmi_f11_rel_pos_report (sensor, i); + } +input_report_key (sensor->input,BTN_TOUCH , finger_pressed_count);
Please use input_mt_sync_frame() here instead.
drivers/input/rmi4/rmi_f11.c line 955
Quoted 2 lines
drivers/input/rmi4/rmi_f11.c new file +2
-0+input_sync (sensor->input); +}
Stopping here.
Thanks,
Henrik
--
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
RE: [RFC PATCH 02/06] input/rmi4: Core files
In reply to Joe PerchesQuoted 4 lines · Joe Perches
On Fri, 2012-10-05 at 21:09 -0700, Christopher Heiny wrote:
[]Just some trivial comments:
Thanks - see below for responses.
Quoted 28 lines
drivers/input/rmi4/rmi_driver.c
Quoted 2 lines
drivers/input/rmi4/rmi_driver.c +0
-0[]
drivers/input/rmi4/rmi_driver.c
Quoted 1 line
drivers/input/rmi4/rmi_driver.c +0
-0@@ -0,0 +1,1529 @@[]
Quoted 20 lines
drivers/input/rmi4/rmi_driver.c +20
-0+static ssize_t delay_write (struct file *filp,const char __user *buffer, +size_t size,loff_t *offset) { +struct driver_debugfs_data *data = filp->private_data; +struct rmi_device_platform_data *pdata = + data->rmi_dev->phys->dev->platform_data; +int retval; +char local_buf[size]; +unsigned int new_read_delay; +unsigned int new_write_delay; +unsigned int new_block_delay; +unsigned int new_pre_delay; +unsigned int new_post_delay; + + retval =copy_from_user (local_buf, buffer, size); +if (retval) +return -EFAULT ; + + retval =sscanf (local_buf,"%u %u %u %u %u" , &new_read_delay, + &new_write_delay, &new_block_delay, + &new_pre_delay, &new_post_delay);
Quoted 8 lines
drivers/input/rmi4/rmi_driver.c line 144
Quoted 6 lines
drivers/input/rmi4/rmi_driver.c +6
-0+if (retval !=5 ) { +dev_err (&data->rmi_dev->dev, +"Incorrect number of values provided for delay." ); +return -EINVAL ; + } +if (new_read_delay <0 ) {These are unnecessary tests as unsigned values are never < 0.
Right. Thought we'd taken care of most of the silliness like that, but obviously missed some. We'll recheck the codebase.
[snip]
Quoted 8 lines
drivers/input/rmi4/rmi_driver.c line 197
Quoted 6 lines
drivers/input/rmi4/rmi_driver.c +1
-0+static ssize_t phys_read(struct file *filp, char __user *buffer, size_tsize, +
loff_t*offset) {drivers/input/rmi4/rmi_driver.c +4
-0+struct driver_debugfs_data *data = filp->private_data; +struct rmi_phys_info *info = &data->rmi_dev->phys->info; +int retval; +char local_buf[size];size comes from where? possible stack overflow?
Hmmmm. Good point. We'll look at this.
[snip]
Quoted 8 lines
[]
drivers/input/rmi4/rmi_driver.c line 549
Quoted 4 lines
drivers/input/rmi4/rmi_driver.c +4
-0+list_for_each_entry (entry, &data->rmi_functions.list, list) +if (entry->irq_mask) +process_one_interrupt (entry, irq_status, + data);style nit, it'd be nicer with braces.
I agree with you, but checkpatch.pl doesn't. :-(
Quoted 7 lines
drivers/input/rmi4/rmi_driver.h
Quoted 3 lines
drivers/input/rmi4/rmi_driver.h +0
-0[]
Quoted 2 lines
drivers/input/rmi4/rmi_driver.h +0
-0@@ -0,0 +1,438 @@
Quoted 7 lines
drivers/input/rmi4/rmi_driver.h line 36
Quoted 4 lines
drivers/input/rmi4/rmi_driver.h +4
-0+ +#define tricat (x, y, z) tricat_(x, y, z) + +#define tricat_ (x, y, z) x##y##zI think these tricat macros are merely obfuscating and don't need to be used.
tricat is used internally by another collection of macros that helps generate sysfs files. In particular, it's used to generate the RMI4 register name symbols.
Re: [RFC PATCH 02/06] input/rmi4: Core files
Quoted 1 line · Christopher Heiny
Joe Perches wrote:
[]
Quoted 8 lines
Quoted 6 lines
drivers/input/rmi4/rmi_driver.c line 549
Quoted 4 lines
drivers/input/rmi4/rmi_driver.c new file +4
-0+list_for_each_entry (entry, &data->rmi_functions.list, list) +if (entry->irq_mask) +process_one_interrupt (entry, irq_status, + data);style nit, it'd be nicer with braces.
I agree with you, but checkpatch.pl doesn't. :-(
Sure it does.
$ cat t.c
{
list_for_each_entry(entry, &data->rmi_functions.list, list) {
if (entry->irq_mask)
process_one_interrupt(entry, irq_status, data);
}
}
$ ./scripts/checkpatch.pl --strict -f t.c
total: 0 errors, 0 warnings, 0 checks, 7 lines checkedt.c has no obvious style problems and is ready for submission.
RE: [RFC PATCH 01/06] input/rmi4: Public header and documentation
In reply to Linus WalleijQuoted 9 lines · Linus Walleij
Quoted 4 lines · Christopher Heiny
As requested in the feedback from the previous patch, we've documented the debugfs and sysfs attributes in files in
Documentation/ABI/testing. There's two files, one for debugfs and one for sysfs.This is a massive improvement! Atleast as far as I've read... If you fix the below remarks I think I'm ready to accept this file, but that's just me and doesn't say anything about what Dmitry et al will comment on...
Thanks! See my comments below.
Quoted 18 lines
(...)
Quoted 3 lines
+ The RMI4 driver implementation exposes a set of informational and control + parameters via debugs. These parameters are those that typically are only
s/debugs/debugfs
(...)
Quoted 8 lines
+
comms_debug- (rw) Write 1 to this dump information about
register + reads and writes to the console. Write 0 to
this to turn + this feature off. WARNING: Imposes a
major performance + penalty when turned on.
+irq_debug- (rw) Write 1 to this dump information about
interrupts + to the console. Write 0 to this to turn
this feature off. + WARNIG: Imposes a major performance
penalty when turned on.
Quoted 5 lines
Hm. Usually we control dynamic debug prints by standard kernel frameworks, can you tell what is wrong with this and why you need a custom mechanism? See the following:
Documentation/dynamic-debug-howto.txt
http://lwn.net/Articles/434833/
The current arrangement was arrived at after some discussion with customers. Originally we went with the Kconfig based approach you suggested in August. However, the response from our guinea pigs, um, very helpful test customers, was "AAAAAAAggh! Too complicated and too static!!" As a result we explored alternatives. The dynamic debug interface was considered, but it is usually disabled in our customer's kernel configurations, even during development. In the end, we arrived at some simple debugfs on/off switches for the more verbose features (like comms_debug and irq_debug, above).
If this is a deal-breaker, I can go back to the customers and see if they are willing to consider enabling dynamic debug during prototyping and development.
Quoted 20 lines
(...)
Quoted 1 line
+++ b/Documentation/ABI/testing/sysfs-rmi4
(...)
Quoted 8 lines
+ chargerinput ... (rw) User space programs can use this to tell
the + sensor that the system is plugged into an external
power + source (as opposed to running on
batteries). This allows + the sensor firmware to make
necessary adjustments for the + current capacitence
regime. Write 1 to this when the + system is using
external power, write 0 to this when the + system is
running on batteries. See spec for full details.I remember discussing in-kernel notifiers for this. I don't really see the point in tunnelling a notification from the
drivers/powersubsystem to thedrivers/inputsubsystem through userspace for no good.
Quoted 4 lines
It's no blocker though, I don't expect you to fix this as part of this driver submission.
Maybe Anton can comment?
Hmmm. I agree that it'd be good to avoid looping through userspace. But....
I found ways to notfiy the kernel that the charger is plugged/unplugged, but that's only useful if you're a battery charger device driver. I also found ways for userspace to get notification of charger events. I didn't spot any way for in-kernel drivers to get notification of such events. Perhaps I'm not looking the right places, though - can you provide a pointer?
Quoted 8 lines
(...)
Quoted 3 lines
+
interrupt_enable... (ro) This represents the current RMI4
interrupt + mask (F01_RMI_Ctrl1registers). See spec
for full details.What does the userspace have to do with this stuff? Seems way too low-level, but whatever.
It's primarily used in hardware prototyping and bring up. Perhaps it belongs in debugfs in that case.
Quoted 13 lines
(...)
Quoted 9 lines
+ sleepmode ... (rw) Controls power management on the
device. Writing + 0 to this parameter puts the device
into its normal operating + mode. Writing 1 to this
parameter fully disables touch + sensors and similar
inputs - no touch data will be reported + from the
device in this mode. Writing 2 or 3 to this device
+ may or may not have an effect, depending on the
particular + device - see the product specification for
your sensor for + details.
Quoted 3 lines
Usually power management is controlled from kernelspace, but no big deal, maybe userspace knows even more details in some cases.
Well, in some cases userspace does think it knows more :-). This one should definitely stay in sysfs.
Quoted 6 lines
Quoted 3 lines
+ unconfigured ... (ro) This is the opposite of the configured
bit, + described above.So why is it needed? Isn't it implicit from the "configured" property if this is 0 then it's unconfigured? Seems superfluous.
You're right - we can omit one of them from sysfs as currently implemented.
Quoted 15 lines
(...)
Quoted 1 line
+++
b/include/linux/rmi.h(...)
include/linux/rmi.h line 36
Quoted 3 lines
include/linux/rmi.h new file +3
-0+#ifdef CONFIG_RMI4_DEBUG +#include <linux/debugfs.h> +#endif Don't include it conditionally, always just include it whether you use it or not.
It doesn't hurt, and doesn't cause compile problems.
Quoted 1 line
(...)
Will fix. I won't re-comment on the other places where you call out this sort of #ifdef.
Quoted 23 lines
Quoted 3 lines
+/**
+ * structrmi_device_platform_data_spi- provides paramters used in SPIs/paramters/parameters/
Quoted 1 line
+ * communitcations. All Synaptics SPI products support a standard SPI
s/communitcations/communications
Quoted 7 lines
+ * @cs_assert - For systems where the SPI subsystem does not control the CS/SSB + * line, or where such control is broken, you can provide a custom routine to + * handle a GPIO as CS/SSB. This routine will be called at the beginning and + * end of each SPI transaction. The RMI SPI implementation will wait + *
pre_delay_usafter this routine returns before starting the SPI transfer; + * andpost_delay_usafter completion of the SPI transfer(s) before calling it + * with assert==FALSE.Hm hm, can you describe the case where this happens?
Usually we don't avoid fixes for broken drivers by duct-taping solutions into other drivers, instead we fix the SPI driver.
Quoted 6 lines
I can think of systems where CS is asserted not by using GPIO but by poking some special register for example, which is a valid reason for including this, but working around broken SPI drivers is not a valid reason to include this.
(Paging Mark about it.)
I see Mark has replied - I'll address this there.
Quoted 10 lines
(...)
Quoted 4 lines
+/**
+ * structrmi_device_platform_data- system specific configuration info.
+ *
+ * @driver_name(...)
Quoted 8 lines
include/linux/rmi.h line 295
Quoted 2 lines
include/linux/rmi.h new file +2
-0+struct rmi_device_platform_data { +char *driver_name;I don't understand what the driver name is doing in the platform data. The driver name should be part of the device driver struct, and match on
dev_name(struct device *), not be passed in here.Please explain...
This is a vestige of the old roll-your-own bus matching code. We'll get rid of it.
Quoted 11 lines
(...)
include/linux/rmi.h line 431
Quoted 3 lines
include/linux/rmi.h new file +3
-0+#ifdef CONFIG_RMI4_DEBUG +struct dentry *debugfs_root; +#endif Maybe just use
CONFIG_DEBUG_FSinstead, it's more to the point?(occurs twice)
CONFIG_DEBUG_FS might be enabled, but the customer might not desire RMI4 debugging features for some reason.
Quoted 11 lines
(...)
Quoted 7 lines
+/**
+ *rmi_register_phys_device- register a physical device connection on the RMI + * bus. Physical drivers provide communication from the devices on the bus to + * the RMI4 sensor on a bus such as SPI, I2C, and so on.
+ *
+ * @phys: the physical device to register
+ */
Quoted 6 lines
Don't put the kerneldoc here in the header, put it in the code.
Only documentation for structs, enums and inline functions go into the header files.
(Same comment for all functions.)
OK - thanks for clarification.
Quoted 22 lines
Quoted 2 lines
+int
rmi_register_phys_device(struct rmi_phys_device *phys);(...)
Quoted 5 lines
+/**
+ * Helper function to convert a 16 bit value (in host processor endianess) to + * a byte array in the RMI endianess for u16s. See above comment for + * why we dont us htons or something like that.
+ */So in this case it's correct to document it here, because this is an inline function.
include/linux/rmi.h line 657
Quoted 4 lines
include/linux/rmi.h new file +4
-0+static inline void hstoba (u8 *dest,u16 src) +{ + dest[0 ] = src %0x100 ; + dest[1 ] = src /0x100 ;But please use arithmetic operators (I think I said this on the last review):
Quoted 6 lines
dest[0] = src &
0xFF;
dest[1] = src >> 8;Doing it the above way makes artithmetic look like maths, and it isn't. Besides it's done this way in most parts of the kernel and we're familiar with it.
Yes, you mentioned it previously. I'm somewhat paranoid, though, and don't trust the shift/mask method to work correctly on big-endian machines. If the shifts can be relied on to behave (I'm guessing the answer is "yes", since you say this idiom is used widely in the kernel), then I'll change it.
Quoted 15 lines
(...)
Quoted 12 lines
include/linux/rmi.h new file +4
-0+#ifdef CONFIG_RMI4_DEBUG +/** +* Utility routine to handle writes to read-only attributes. Hopefully +* this will never happen, but if the user does something stupid, we don't
+ * want to accept it quietly (which is what can happen if you just put NULL + * for the attribute's store function).
+ */include/linux/rmi.h new file +4
-0+static inline ssize_t rmi_store_error (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +2
-0+ dev_warn(dev, + "WARNING: Attempt to write %d characters to read-onlyattribute %s.", + count,
attr->attr.name);(quoted diff) +2
-0+ return -EPERM; +}Here it looks like you're hiding a lot of stuff that should be
dev_warn()? Consider my earlier point about dynamic debug.
In previous patch submissions, we always used these warning functions. But in the feedback on those patches, we were asked to just make sysfs show/store NULL if the attribute is write/read only. However, during their development process, our customers want to see the warnings if the attributes are accessed incorrectly. So we made these warnings a debug option.
RE: [RFC PATCH 01/06] input/rmi4: Public header and documentation
In reply to Mark BrownQuoted 29 lines · Mark Brown
Quoted 15 lines · Linus Walleij
Quoted 8 lines · Christopher Heiny
+ * @cs_assert - For systems where the SPI subsystem does not control the CS/SSB + * line, or where such control is broken, you can provide a custom routine to + * handle a GPIO as CS/SSB. This routine will be called at the beginning and + * end of each SPI transaction. The RMI SPI implementation will wait + *
pre_delay_usafter this routine returns before starting the SPI transfer; + * andpost_delay_usafter completion of the SPI transfer(s) before calling it + * with assert==FALSE.Hm hm, can you describe the case where this happens?
Usually we don't avoid fixes for broken drivers by duct-taping solutions into other drivers, instead we fix the SPI driver.
Quoted 6 lines
I can think of systems where CS is asserted not by using GPIO but by poking some special register for example, which is a valid reason for including this, but working around broken SPI drivers is not a valid reason to include this.
(Paging Mark about it.)
Yeah, this seems silly - by this logic we'd have to go round implementing manual /CS control in every single SPI client driver which isn't terribly sensible. The driver should just assume that the SPI controller does what it's told. As you say if there's an issue the relevant controller driver should take care of things.
Quoted 6 lines
We should also have generic support in the SPI framework for GPIO based /CS, there's enough drivers open coding this already either due to hardware limitations or to support extra chip selects.
The ability of SPI hardware and driver authors to get /CS right is pretty depressing :/
You will get no argument at all from me on that point. I'll even add board layout engineers to the list ("it wasn't convenient to run CS, so we just used a different pin. You can just mux it, right?"). Basically this feature exists to help get prototype systems up and running while the SPI hardware/driver/layout matures.
If this feature is a deal-breaker, we can take it out. In the absence of a generic GPIO implementation for CS, though, I'd much rather leave it in. Once generic GPIO CS arrives, we'll remove it pretty quickly.
RE: [RFC PATCH 02/06] input/rmi4: Core files
In reply to Linus WalleijQuoted 8 lines · you
Quoted 6 lines · Christopher Heiny
rmi_bus.cimplements the basic functionality of the RMI bus. This file is greatly simplified compared to the previous patch - we've switched from "do it yourself" device/driver binding to usingdevice_typeto distinguish between the two kinds of devices on the bus (sensor devices and function specific devices) and using the standard bus implementation to manage devices and drivers.
Quoted 8 lines
So I think you really want Greg KH to look at this bus implementation now. Please include Greg on future mailings...
It looks much improved from previous versions, and sorry if I am now adding even more comments, but it's because you cleared out some noise that was disturbing my perception so I can cleanly review the architecture of this thing now. (I'm impressed by your work and new high-speed turnaround time!)
Thanks for the praise - it means a lot to me and my team.
We'll cc Greg on the next patch drop.
[snip some items covered in a previous email]
Quoted 5 lines
(...)
drivers/input/rmi4/rmi_driver.c
Quoted 2 lines
drivers/input/rmi4/rmi_driver.c +0
-0
[snip some items covered in a previous email]
Quoted 8 lines
Quoted 2 lines
+#define
DELAY_NAME"delay"This is only used in one place, why not just use the string "delay" there?
(...)
Quoted 7 lines
Quoted 5 lines
+ if (
IS_ENABLED(CONFIG_RMI4_SPI)&& !strncmp("spi",info->proto,
3)) { +data->debugfs_delay=
debugfs_create_file(DELAY_NAME,
+RMI_RW_ATTR,rmi_dev->debugfs_root,rmi_dev, +&delay_fops);i.e. there.
That's a left-over. We'll consolidate it.
Quoted 28 lines
(...)
Quoted 9 lines
drivers/input/rmi4/rmi_driver.c +8
-0+/* Useful helper functions for u8* */ + +static bool u8_is_any_set (u8 *target,int size) +{ +int i; +/* We'd like to use find_first_bit, but it ALWAYS returns 1, +* no matter what we pass it. So we have to do this the hard way. +* return find_first_bit((long unsigned int *) target, size) != 0;
drivers/input/rmi4/rmi_driver.c line 390
Quoted 7 lines
drivers/input/rmi4/rmi_driver.c +7
-0+*/ +for (i =0 ; i < size; i++) { +if (target[i]) +return true; + } +return false; +}Instead of:
if (
u8_is_any_set(foo, 128){}Why can't you use:
if (!bitmap_empty(foo, 128*8) {}
Quoted 7 lines
?
If you look at the implementation in the <
linux/bitmap.h> header and__bitmap_empty()inlib/bitmap.cyou will realize that this function is already optimized like this (and I actually don't think the RMI4 code is performance-critical for these functions anyway, but prove me wrong!)
We'll give !bitmap_empty a try.
Quoted 14 lines
drivers/input/rmi4/rmi_driver.c line 400
Quoted 11 lines
drivers/input/rmi4/rmi_driver.c +10
-0+ +/** This is here because all those casts made for some ugly code. +*/ +static void u8_and (u8 *dest,u8 *target1,u8 *target2,int nbits) +{ +bitmap_and ((long unsigned int *) dest, + (long unsigned int *) target1, + (long unsigned int *) target2, + nbits); +}Hm, getting rid of unreadable casts is a valid case.
Quoted 2 lines
I'll be OK with this but maybe the real solution is to introduce such helpers into <
linux/bitmap.h>?
Hmmm. We'll give that some thought. Thought I'd like to get the RMI4 driver nailed down, just to keep the area of change small. Once we've got all the kinks worked out here, we'll look at bitmap.h helpers.
Quoted 12 lines
(...)
drivers/input/rmi4/rmi_driver.c line 527
Quoted 6 lines
drivers/input/rmi4/rmi_driver.c +6
-0+static int process_interrupt_requests (struct rmi_device *rmi_dev) +{ +struct rmi_driver_data *data =dev_get_drvdata (&rmi_dev->dev); +struct device *dev = &rmi_dev->dev; +struct rmi_function_container *entry; +u8 irq_status[data->num_of_irq_regs];Looking at this...
Quoted 8 lines
What does the
data->num_of_irq_regsactually contain?I just fear that it is something constant like always 2 or always 4, so there is actually, in reality, a 16 or 32 bit register hiding in there.
In that case what you should do is to represent it as a u16 or u32 here, just or the bits into a status word, and then walk over that status word with something like ffs(bitword); ...
Nope, it's not constant. In theory, and RMI4 based sensor can have up to 128 functions (in practice, it's far fewer), and each function can have as many as 7 interrupts. So the number of IRQ registers can vary from RMI4 sensor to RMI4 sensor, and needs to be computed during the scan of the product descriptor table.
Quoted 8 lines
(...)
Quoted 1 line
+static int
standard_resume(struct rmi_device *rmi_dev)Standard eh?
Atleast prefix with rmi4_*...
Ooops - we excised the Android based stuff, but forgot to change that function name.
Quoted 17 lines
drivers/input/rmi4/rmi_driver.c line 1362
Quoted 12 lines
drivers/input/rmi4/rmi_driver.c +11
-0+static int rmi_driver_suspend (struct device *dev) +{ +struct rmi_device *rmi_dev =to_rmi_device (dev); +return standard_suspend (rmi_dev); +} + +static int rmi_driver_resume (struct device *dev) +{ +struct rmi_device *rmi_dev =to_rmi_device (dev); +return standard_resume (rmi_dev); +}If all these two are doing are to call another function with almost the same name, what is the point? Just sink the code from "
standard_suspend()" and "standard_resume()" into these functions and remove a pointless layer of abstraction.
Good point.
Quoted 26 lines
Apart from this the core driver looks good to me.
(...)
Quoted 2 lines
drivers/input/rmi4/rmi_driver.h +0
-0(...)
drivers/input/rmi4/rmi_driver.h line 84
Quoted 12 lines
drivers/input/rmi4/rmi_driver.h +2
-0+#define simple_show_union_struct (regtype, propname, fmt)\ +static ssize_t tricat(rmi_fn_, FNUM, _##propname##_show)(struct device*dev,\ + struct
device_attribute*attr,
char *buf) {\ + structrmi_function_container*fc;\drivers/input/rmi4/rmi_driver.h +8
-0+struct FUNCTION_DATA *data;\ +\ + fc =to_rmi_function_container (dev);\ + data = fc->data;\ +\ +return snprintf (buf,PAGE_SIZE , fmt,\ + data->regtype.propname);\ +}OK I see the point, but is there really no other way to do this than to #define huge static inlines like these? Is it really not possible to create just generic functions instead of going this far?
Quoted 1 line
(same comment for all)
We tried generic functions previously, and it wound up really really ugly. We'd be willing to look at it again, though, since this isn't real beautiful either. If you've got an example implementation in mind. a pointer would help a great deal.
Quoted 11 lines
drivers/input/rmi4/rmi_driver.h line 351
Quoted 8 lines
drivers/input/rmi4/rmi_driver.h +7
-0+union pdt_properties { +struct { +u8 reserved_1:6 ; +u8 has_bsr:1 ; +u8 reserved_2:1 ; + } __attribute__((__packed__ )); +u8 regs[1 ];I don't understand what this union is trying to achieve.
Quoted 7 lines
regs[1] does not look right considering what you're trying to achieve. Since the above fields require a regs[2] (9 bits!) to be stored. Maybe write out what you're trying to do here so I can understand it? (If everyone else in the world gets it immediately, it's maybe me that need fixing instead...)
Apart from these remarks it's looking real nice now!
I only count 8 bits there, unless there's something about packing I'm not aware of. Is there something else you found confusing about the union?
RE: [RFC PATCH 03/06] input/rmi4: I2C physical interface
In reply to Linus WalleijQuoted 8 lines · Linus Walleij
Quoted 7 lines · Christopher Heiny
The I2C physical driver is not extensively changed in terms of functionality since the previous patch. Management of the attention GPIO has been moved to
rmi_driver.c(see previous email), and most of the debug related interfaces have been moved from sysfs to debugfs. Control of the debug features has been moved from compile-time to runtime switches available via debugfs.
Quoted 7 lines
Quoted 3 lines
The core I2C functionality was previously ACKed by Jean Delvare. I don't believe that portion of the code has changed much since then, but we'd appreciate a second glance at this.
The above commit blurb looks more like a changelog than a description of the actual patch. Nothing wrong with that but begin by describing the patch first.
Good point. I was describing the patch, but not from the correct point of view. :-)
[snip some items covered in a previous email]
Quoted 6 lines
Quoted 3 lines
+static int
setup_debugfs(struct rmi_device *rmi_dev, struct rmi_i2c_data *data); +static voidteardown_debugfs(struct rmi_i2c_data *data);Why do you need to forward-declare these? Can't you just move them up above the functions using them?
Probably. We'll do that if possible.
Quoted 5 lines
drivers/input/rmi4/rmi_i2c.c line 53
Quoted 3 lines
drivers/input/rmi4/rmi_i2c.c new file +2
-0+struct i2c_debugfs_data { +bool done;Done with what? ... needs some doc.
OK.
Quoted 11 lines
Quoted 3 lines
drivers/input/rmi4/rmi_i2c.c new file +2
-0+struct rmi_i2c_data *i2c_data; +};(...)
Quoted 2 lines
drivers/input/rmi4/rmi_i2c.c new file +2
-0+static int __devinit rmi_i2c_probe (struct i2c_client *client, +const struct i2c_device_id *id)(...)
Quoted 8 lines
Quoted 1 line
+
rmi_phys=kzalloc(sizeof(struct rmi_phys_device), GFP_KERNEL);(...)
Quoted 1 line
+ data =
kzalloc(sizeof(struct rmi_i2c_data), GFP_KERNEL);Can you use
devm_kzalloc(&client->dev, ...)for these so you don't need tofree()them explicitly?
Hmmmmmm. That looks like a merge regression - I'm pretty sure we implemented devm_kzalloc there.
Quoted 12 lines
(...)
drivers/input/rmi4/rmi_i2c.c line 408
Quoted 7 lines
drivers/input/rmi4/rmi_i2c.c new file +7
-0+static int __devexit rmi_i2c_remove(struct i2c_client *client) +{ +struct rmi_phys_device *phys =i2c_get_clientdata (client); +struct rmi_device_platform_data *pd = client->dev.platform_data; + +/* Can I remove this disable_device */ +/*disable_device(phys); */ So just delete these two lines then?
Yes.
RE: [RFC PATCH 04/06] input/rmi4: Config files and makefiles
In reply to Linus WalleijQuoted 9 lines · Linus Walleij
On Sat, Oct 6, 2012 at 6:10 AM, Christopher Heiny <[email protected]> wrote:
(...)
Quoted 1 line
drivers/input/rmi4/Kconfig +0
-0(...)
Quoted 8 lines
drivers/input/rmi4/Kconfig line 16
Quoted 3 lines
drivers/input/rmi4/Kconfig +3
-0+config RMI4_DEBUG + bool "RMI4 Debugging" + depends on RMI4_BUSselect
DEBUG_FSThis has been illustrated many times in the review. You definatley have code depending on debugfs when this is selected.
Agreed.
RE: [RFC PATCH 05/06] input/rmi4: F01 - device control
In reply to Linus WalleijQuoted 46 lines · Linus Walleij
Quoted 13 lines · Christopher Heiny
RMI Function 01 implements basic device control and power management behaviors for the RMI4 sensor. Since the last patch, we've decoupled
rmi_f01.cimplementation fromrmi_driver.c, sormi_f01.cacts as a standard driver module to handle F01 devices on the RMI bus.Like other modules, a number of attributes have been moved from sysfs to debugfs, depending on their expected use.
rmi_f01.hexports definitions that we expect to be used by other functionality in the future (such as firmware reflash).Quoted 8 lines
Signed-off-by Christopher Heiny <[email protected]>Cc Dmitry Torokhov <[email protected]>Cc Linus Walleij <[email protected]>Cc Naveen Kumar Gaddipati <[email protected]>Cc Joeri de Gram <[email protected]>---
There is liberal whitespacing above. (No big deal, but anyway.)
(...)
drivers/input/rmi4/rmi_f01.c line 38
Quoted 10 lines
drivers/input/rmi4/rmi_f01.c new file +10
-0+/** +* @reset - set this bit to force a firmware reset of the sensor. +*/ +union f01_device_commands { +struct { +bool reset:1 ; +u8 reserved:7 ; + } __attribute__((__packed__ )); +u8 reg; +};I'm still scared by these unions. I see what you're doing but my preferred style of driver writing is to use a simple u8 if you just treat it the right way with some |= and &= ...
#include <
linux/bitops.h>#define
F01_RESETBIT(0)
Quoted 8 lines
u8
my_command=F01_RESET;
send(&my_command);I will not insist on this because it's a bit about programming style. For memory-mapped devices we usually do it my way, but this is more like some protocol and I know protocols like to do things with structs and stuff so no big deal.
That's a good summary of what we're trying to do. Our original version did more of the traditional mask+shift approach to manipulating the fields in the various registers, but in the case of complicated functions such as F11 this rapidly became unreadable. We found the unions worked a lot better - the code was more readable and less error prone. For consistency we decided to apply them throughout the code.
Quoted 18 lines
Quoted 4 lines
drivers/input/rmi4/rmi_f01.c new file +3
-0+#ifdef CONFIG_RMI4_DEBUG +struct f01_debugfs_data { + bool done;drivers/input/rmi4/rmi_f01.c line 157
Quoted 10 lines
drivers/input/rmi4/rmi_f01.c new file +10
-0+struct rmi_function_container *fc; +}; + +static int f01_debug_open (struct inode *inodep,struct file *filp) +{ +struct f01_debugfs_data *data; +struct rmi_function_container *fc = inodep->i_private; + + data =devm_kzalloc (&fc->dev,sizeof (struct f01_debugfs_data ), +GFP_KERNEL );Wait, you probably did this because I requested it, but I was maybe wrong?
Quoted 5 lines
Will this not re-allocate a chunk every time you look at a debugfs file? So it leaks memory?
In that case common
kzalloc()andkfree()is the way to go, as it is for dynamic buffers. Sorry for screwing things up for you.
No problem - we'll fix it. Or unfix it. Or something like that. :-)
Quoted 10 lines
drivers/input/rmi4/rmi_f01.c line 244
Quoted 9 lines
drivers/input/rmi4/rmi_f01.c new file +8
-0+for (i =0 ; i < f01->irq_count && *local_buf !=0 ; + i++, local_buf +=2 ) { +int irq_shift; +int interrupt_enable; +int result; + + irq_reg = i /8 ; + irq_shift = i %8 ;
Quoted 4 lines
Please stop doing these arithmetics-turned-maths things.
irq_reg= i >> 8;irq_shift= i &0xFF;
See note on this in a previous email.
Quoted 25 lines
(...)
Quoted 9 lines
drivers/input/rmi4/rmi_f01.c new file +9
-0+static ssize_t rmi_fn_01_interrupt_enable_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct rmi_function_container *fc; +struct f01_data *data; +int i, len, total_len =0 ; +char *current_buf = buf; + + fc =to_rmi_function_container (dev);drivers/input/rmi4/rmi_f01.c line 760
Quoted 10 lines
drivers/input/rmi4/rmi_f01.c new file +10
-0+ data = fc->data; +/* loop through each irq value and copy its +* string representation into buf */ +for (i =0 ; i < data->irq_count; i++) { +int irq_reg; +int irq_shift; +int interrupt_enable; + + irq_reg = i /8 ; + irq_shift = i %8 ;Dito.
Quoted 5 lines
(...)
Quoted 1 line
+static int
f01_probe(struct device *dev);Do you really need to forward-declare this?
It's a leftover from the process of eliminating roll-your-own bus implementation, and move the other code around as well. (same applies for similar code in rmi_f11.c).
Quoted 29 lines
(...)
Quoted 7 lines
drivers/input/rmi4/rmi_f01.c new file +7
-0+static struct rmi_function_handler function_handler = { + .driver = { + .owner =THIS_MODULE , + .name ="rmi_f01" , + .bus = &rmi_bus_type, + .probe = f01_probe, + .remove = f01_remove_device,drivers/input/rmi4/rmi_f01.c line 1418
Quoted 10 lines
drivers/input/rmi4/rmi_f01.c new file +10
-0+ }, + .func = 0x01, + .config = rmi_f01_config, + .attention = rmi_f01_attention, + +#ifdef CONFIG_PM + .suspend = rmi_f01_suspend, + .resume = rmi_f01_resume, +#endif /* CONFIG_PM */ +};Just move this block of struct below the probe function...
Quoted 1 line
+static
__devinitintf01_probe(struct device *dev)Header file looks OK (if these unions is the way to go...)
Yours,
Linus Walleij
RE: [RFC PATCH 06/06] input/rmi4: F11 - 2D touch interface
In reply to Linus WalleijQuoted 5 lines · Linus Walleij
On Sat, Oct 6, 2012 at 6:10 AM, Christopher Heiny <[email protected]> wrote:
So looking closer at this one since we will use it. Maybe it's in such a good shape now that I should be able to actually test it with the hardware?
Well, it's been possible to test at least since the patch submitted last December. The code might have been ugly, but it was working.
Quoted 4 lines
(...)
drivers/input/rmi4/rmi_f11.c
Quoted 1 line
drivers/input/rmi4/rmi_f11.c +0
-0
[snip previously mentioned stuff]
Quoted 8 lines
drivers/input/rmi4/rmi_f11.c line 53
Quoted 5 lines
drivers/input/rmi4/rmi_f11.c +4
-0+#define F11_CTRL_SENSOR_MAX_X_POS_OFFSET 6 +#define F11_CTRL_SENSOR_MAX_Y_POS_OFFSET 8 + +#define F11_CEIL (x, y) (((x) + ((y)-1)) / (y))Use existing kernel macros in <
linux/kernel.h>
Quoted 4 lines
In this case:
#defineF11_CEIL(x, y)DIV_ROUND_UP(x, y)Or just use
DIV_ROUND_UP()directly in the code, your choice.
Use it directly is simpler.
Quoted 5 lines
Quoted 2 lines
+#define
MAX_NAME_LENGTH256Really? Are you sure there is not a null terminator or length byte included so it's actually 255?
We were assuming 255 + terminator. Perhaps a better name such as NAME_BUFFER_SIZE would be clearer?
Quoted 14 lines
(...)
drivers/input/rmi4/rmi_f11.c line 807
Quoted 8 lines
drivers/input/rmi4/rmi_f11.c +8
-0+static int sensor_debug_open (struct inode *inodep,struct file *filp) +{ +struct sensor_debugfs_data *data; +struct f11_2d_sensor *sensor = inodep->i_private; +struct rmi_function_container *fc = sensor->fc; + + data =devm_kzalloc (&fc->dev,sizeof (struct sensor_debugfs_data ), +GFP_KERNEL );Again I may have lead you astray. Check if this leaks memory, in that case use kzalloc()/kfree(). Sorry
No problem - will correct it.
Quoted 34 lines
(...)
drivers/input/rmi4/rmi_f11.c line 1227
Quoted 7 lines
drivers/input/rmi4/rmi_f11.c +7
-0+static int f11_debug_open (struct inode *inodep,struct file *filp) +{ +struct f11_debugfs_data *data; +struct rmi_function_container *fc = inodep->i_private; + + data =devm_kzalloc (&fc->dev,sizeof (struct f11_debugfs_data ), +GFP_KERNEL );Dito.
(...)
Quoted 3 lines
drivers/input/rmi4/rmi_f11.c +3
-0+static void rmi_f11_abs_pos_report (struct f11_data *f11, +struct f11_2d_sensor *sensor, +u8 finger_state,u8 n_finger)(...)
drivers/input/rmi4/rmi_f11.c line 1417
Quoted 12 lines
drivers/input/rmi4/rmi_f11.c +6
-0+if (axis_align->flip_y) + y =max (sensor->max_y - y,0 ); + +/* +** here checking if X offset or y offset are specified is +** redundant. We just add the offsets or, clip the values
drivers/input/rmi4/rmi_f11.c +5
-0+** +** note: offsets need to be done before clipping occurs, +** or we could get funny values that are outside +** clipping boundaries. +*/
Quoted 2 lines
This is a weird commenting style, what's wrong with a single star? (No big deal but it stands out...)
It's probably just someone's editor settings. We can tidy it up.
Quoted 17 lines
(...)
Quoted 11 lines
drivers/input/rmi4/rmi_f11.c +7
-0+static int f11_allocate_control_regs (struct rmi_device *rmi_dev, +struct f11_2d_device_query *device_query, +struct f11_2d_sensor_query *sensor_query, +struct f11_2d_ctrl *ctrl, +u16 ctrl_base_addr) { + + struct rmi_driver_data *driver_data =
dev_get_drvdata(&rmi_dev->dev); + structrmi_function_container*fc
=driver_data->f01_container; +
+ctrl->ctrl0_9= devm_kzalloc(&fc->dev, sizeof(unionf11_2d_ctrl0_9), +GFP_KERNEL);If this is called from .probe() only, this is correct.
Quoted 3 lines
So the rule is: use devm_* for anything that is allocated at .probe() and released on .remove(). Any other dynamic buffers etc need to use common kzalloc()/kfree().
OK - we'll review to make sure that rule is followed, and change as required.
[snip a bunch of the same]
Quoted 9 lines
drivers/input/rmi4/rmi_f11.c line 1849
Quoted 3 lines
drivers/input/rmi4/rmi_f11.c +2
-0+ +return f11_read_control_regs (rmi_dev, ctrl, ctrl_base_addr);Hey why are you ending with a call to that function? The function name gets misleading.
Instead call both functions in succession at the call site on .probe().
OK.
Quoted 31 lines
(...)
Quoted 28 lines
drivers/input/rmi4/rmi_f11.c +28
-0+static int f11_device_init (struct rmi_function_container *fc) +{ +int rc; + + rc =rmi_f11_initialize (fc); +if (rc <0 ) + goto err_free_data; + + rc =rmi_f11_register_devices (fc); +if (rc <0 ) + goto err_free_data; + + rc =rmi_f11_create_sysfs (fc); +if (rc <0 ) + goto err_free_data; + +return 0 ; + +err_free_data: +rmi_f11_free_memory (fc); + +return rc; +} + +static void rmi_f11_free_memory (struct rmi_function_container *fc) +{ +struct f11_data *f11 = fc->data; +int i;
Quoted 8 lines
drivers/input/rmi4/rmi_f11.c line 2132
Quoted 5 lines
drivers/input/rmi4/rmi_f11.c +5
-0+ +if (f11) { +for (i =0 ; i < f11->dev_query.nbr_of_sensors +1 ; i++) +kfree (f11->sensors[i].button_map); + }This is wrong. The
button_mapwas allocated withdevm_kzalloc()so it will get automatically freed. Just skip this step.
We'll correct that.
Quoted 15 lines
(...)
Quoted 2 lines
drivers/input/rmi4/rmi_f11.c +2
-0+static int rmi_f11_initialize (struct rmi_function_container *fc) +{(...)
Quoted 7 lines
drivers/input/rmi4/rmi_f11.c +6
-0+ rc =f11_allocate_control_regs (rmi_dev, + &f11->dev_query, &sensor->sens_query, + &f11->dev_controls, control_base_addr); +if (rc <0 ) { + dev_err(&fc->dev, + "Failed to initialize F11 controlparams.\n");
Quoted 6 lines
"failed to allocate F11 control params"
drivers/input/rmi4/rmi_f11.c
Quoted 2 lines
drivers/input/rmi4/rmi_f11.c +2
-0+return rc; + }So after this call the read regs explicitly instead as described above.
OK
Quoted 16 lines
(...)
Quoted 13 lines
drivers/input/rmi4/rmi_f11.c +8
-0+static void register_virtual_buttons (struct rmi_function_container *fc, +struct f11_2d_sensor *sensor) { +int j; + +if (!sensor->sens_query.has_gestures) +return ; +if (!sensor->virtual_buttons.buttons) { + dev_warn(&fc->dev, "No virtual button platform data for 2Dsensor %d.\n", +
sensor->sensor_index);drivers/input/rmi4/rmi_f11.c +4
-0+return ; + } +/* call devm_kcalloc when it will be defined in kernel */ + sensor->button_map = devm_kzalloc(&fc->dev,
Quoted 8 lines
Quoted 6 lines
drivers/input/rmi4/rmi_f11.c +4
-0+ sensor->virtual_buttons.buttons, + GFP_KERNEL); +if (!sensor->button_map) { + dev_err(&fc->dev, "Failed to allocate the virtual buttonmap.\n"); + return;
+ }So as noted above, since it's using
devm_kzalloc(), don'tfree()it.
OK.
Quoted 11 lines
(...)
drivers/input/rmi4/rmi_f11.c line 2379
Quoted 7 lines
drivers/input/rmi4/rmi_f11.c +7
-0+ sensor->mouse_input = input_dev_mouse; + input_dev_mouse->name ="rmi_mouse" ; + input_dev_mouse->phys ="rmi_f11/input0" ; + + input_dev_mouse->id.vendor =0x18d1 ; + input_dev_mouse->id.product =0x0210 ; + input_dev_mouse->id.version =0x0100 ;
Quoted 4 lines
As noted in previous review,
0x18d1is Google's vendor ID. Please use a Synaptics Vendor ID, Product ID and version!Hint: synaptics Vendor ID is
0x06cb.
That's kind of embarrassing. We'll fix it.
Dmitry Torokhov
maintainerRe: [RFC PATCH 02/06] input/rmi4: Core files
In reply to Christopher HeinyQuoted 17 lines · Christopher Heiny
Quoted 16 lines · you
drivers/input/rmi4/rmi_driver.c line 400
Quoted 10 lines · Christopher Heiny
drivers/input/rmi4/rmi_driver.c new file +10
-0+ +/** This is here because all those casts made for some ugly code. +*/ +static void u8_and (u8 *dest,u8 *target1,u8 *target2,int nbits) +{ +bitmap_and ((long unsigned int *) dest, + (long unsigned int *) target1, + (long unsigned int *) target2, + nbits); +}Hm, getting rid of unreadable casts is a valid case.
Quoted 6 lines
Quoted 2 lines
I'll be OK with this but maybe the real solution is to introduce such helpers into <
linux/bitmap.h>?Hmmm. We'll give that some thought. Thought I'd like to get the RMI4 driver nailed down, just to keep the area of change small. Once we've got all the kinks worked out here, we'll look at
bitmap.hhelpers.
The question is why you are using u8 for bitmaps instead of doing DECALRE_BITMAP() and using it instead? Then you would not need silly wrappers around existing APIs.
Quoted 22 lines
Quoted 13 lines
(...)
drivers/input/rmi4/rmi_driver.c line 527
Quoted 6 lines
drivers/input/rmi4/rmi_driver.c new file +6
-0+static int process_interrupt_requests (struct rmi_device *rmi_dev) +{ +struct rmi_driver_data *data =dev_get_drvdata (&rmi_dev->dev); +struct device *dev = &rmi_dev->dev; +struct rmi_function_container *entry; +u8 irq_status[data->num_of_irq_regs];Looking at this...
Quoted 8 lines
What does the
data->num_of_irq_regsactually contain?I just fear that it is something constant like always 2 or always 4, so there is actually, in reality, a 16 or 32 bit register hiding in there.
In that case what you should do is to represent it as a u16 or u32 here, just or the bits into a status word, and then walk over that status word with something like ffs(bitword); ...
Quoted 5 lines
Nope, it's not constant. In theory, and RMI4 based sensor can have up to 128 functions (in practice, it's far fewer), and each function can have as many as 7 interrupts. So the number of IRQ registers can vary from RMI4 sensor to RMI4 sensor, and needs to be computed during the scan of the product descriptor table.
Is it a good idea to have it on stack then? Should it be part of rmi_device instead?
Quoted 18 lines
Quoted 18 lines
drivers/input/rmi4/rmi_driver.h line 84
Quoted 13 lines
(quoted diff) +2
-0+#define simple_show_union_struct(regtype, propname, fmt)\ +static ssize_t tricat(rmi_fn_, FNUM, _##propname##_show)(struct device*dev,\ + struct
device_attribute*attr,
char *buf) {\ + structrmi_function_container*fc;\drivers/input/rmi4/rmi_driver.h new file +8
-0+struct FUNCTION_DATA *data;\ +\ + fc =to_rmi_function_container (dev);\ + data = fc->data;\ +\ +return snprintf (buf,PAGE_SIZE , fmt,\ + data->regtype.propname);\ +}OK I see the point, but is there really no other way to do this than to #define huge static inlines like these? Is it really not possible to create just generic functions instead of going this far?
Quoted 4 lines
Quoted 1 line
(same comment for all)
We tried generic functions previously, and it wound up really really ugly. We'd be willing to look at it again, though, since this isn't real beautiful either. If you've got an example implementation in mind. a pointer would help a great deal.
You just need to wrap around a custome structure around struct device_attribute and then you shoudl be able to use generics. If you look into trackpoint.c you should gett the idea.
Thanks.
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerRe: [RFC PATCH 01/06] input/rmi4: Public header and documentation
In reply to Christopher Heinyinclude/linux/rmi.h line 511
Quoted 6 lines · Christopher Heiny
include/linux/rmi.h new file +6
-0+ +int (*write_block)(struct rmi_phys_device *phys,u16 addr,u8 *buf, +int len); +int (*read_block)(struct rmi_phys_device *phys,u16 addr,u8 *buf, +int len); +
If you declare your buffer as [const] void * instead of u8 * I think you will be able to get rid of most of your unions.
Quoted 14 lines
include/linux/rmi.h new file +14
-0+ +/** +* Helper fn to convert a byte array representing a 16 bit value in the RMI +* endian-ness to a 16-bit value in the native processor's specific endianness. +* We don't use ntohs/htons here because, well, we're not dealing with +* a pair of 16 bit values. Casting dest to u16* wouldn't work, because +* that would imply knowing the byte order of u16 in the first place. The +* same applies for using shifts and masks. +*/ +static inline u16 batohs (u8 *src) +{ +return src[1 ] *0x100 + src[0 ]; +} +
include/linux/rmi.h line 658
Quoted 10 lines
include/linux/rmi.h new file +10
-0+/** +* Helper function to convert a 16 bit value (in host processor endianess) to +* a byte array in the RMI endianess for u16s. See above comment for +* why we dont us htons or something like that. +*/ +static inline void hstoba (u8 *dest,u16 src) +{ + dest[0 ] = src %0x100 ; + dest[1 ] = src /0x100 ; +}
These are not used anymore, right?
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerRe: [RFC PATCH 01/06] input/rmi4: Public header and documentation
In reply to Christopher HeinyQuoted 24 lines · Christopher Heiny
Quoted 14 lines · Linus Walleij
Quoted 12 lines · Christopher Heiny
include/linux/rmi.h new file +4
-0+#ifdef CONFIG_RMI4_DEBUG +/** +* Utility routine to handle writes to read-only attributes. Hopefully +* this will never happen, but if the user does something stupid, we don't
+ * want to accept it quietly (which is what can happen if you just put NULL + * for the attribute's store function).
+ */include/linux/rmi.h new file +4
-0+static inline ssize_t rmi_store_error (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +2
-0+ dev_warn(dev, + "WARNING: Attempt to write %d characters to read-onlyattribute %s.", + count,
attr->attr.name);(quoted diff) +2
-0+ return -EPERM; +}Here it looks like you're hiding a lot of stuff that should be
dev_warn()? Consider my earlier point about dynamic debug.
Quoted 6 lines
In previous patch submissions, we always used these warning functions. But in the feedback on those patches, we were asked to just make sysfs show/store NULL if the attribute is write/read only. However, during their development process, our customers want to see the warnings if the attributes are accessed incorrectly. So we made these warnings a debug option.
I think it is the case when customer is not always right. Given that the attributes are created with S_IRUGO mask how will we even get these methods to fire?
Signature · 1 line
Dmitry
Re: [RFC PATCH 01/06] input/rmi4: Public header and documentation
In reply to Christopher HeinyQuoted 21 lines · Christopher Heiny
Quoted 15 lines · Linus Walleij
Quoted 8 lines · Christopher Heiny
+ chargerinput ... (rw) User space programs can use this to tell
the + sensor that the system is plugged into an external
power + source (as opposed to running on
batteries). This allows + the sensor firmware to make
necessary adjustments for the + current capacitence
regime. Write 1 to this when the + system is using
external power, write 0 to this when the + system is
running on batteries. See spec for full details.I remember discussing in-kernel notifiers for this. I don't really see the point in tunnelling a notification from the
drivers/powersubsystem to thedrivers/inputsubsystem through userspace for no good.Quoted 4 lines
It's no blocker though, I don't expect you to fix this as part of this driver submission.
Maybe Anton can comment?
Quoted 8 lines
Hmmm. I agree that it'd be good to avoid looping through userspace. But....
I found ways to notfiy the kernel that the charger is plugged/unplugged, but that's only useful if you're a battery charger device driver. I also found ways for userspace to get notification of charger events. I didn't spot any way for in-kernel drivers to get notification of such events. Perhaps I'm not looking the right places, though - can you provide a pointer?
So my point was that there is indeed no such in-kernel notification mechanism.
Maybe something engineered similar to this:
http://www.spinics.net/lists/lm-sensors/msg33834.html
Yours,
Linus Walleij
Re: [RFC PATCH 01/06] input/rmi4: Public header and documentation
In reply to Christopher HeinyQuoted 12 lines · Christopher Heiny
Quoted 9 lines · Linus Walleij
But please use arithmetic operators (I think I said this on the last review):
dest[0] = src &
0xFF;
dest[1] = src >> 8;Doing it the above way makes artithmetic look like maths, and it isn't. Besides it's done this way in most parts of the kernel and we're familiar with it.
Quoted 5 lines
Yes, you mentioned it previously. I'm somewhat paranoid, though, and don't trust the shift/mask method to work correctly on big-endian machines. If the shifts can be relied on to behave (I'm guessing the answer is "yes", since you say this idiom is used widely in the kernel), then I'll change it.
If the behaviour was not consistent across different endianness it would not be part of the C language specification...
<< means shift left in the accumulator or whatever you have. It will work the same no matter how bits are laid out in memory.
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
include/linux/rmi.h new file +4
-0+static inline ssize_t rmi_store_error (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +2
-0+ dev_warn(dev, + "WARNING: Attempt to write %d characters to read-onlyattribute %s.", + count,
attr->attr.name);(quoted diff) +2
-0+ return -EPERM; +}Here it looks like you're hiding a lot of stuff that should be
dev_warn()? Consider my earlier point about dynamic debug.
Quoted 6 lines
In previous patch submissions, we always used these warning functions. But in the feedback on those patches, we were asked to just make sysfs show/store NULL if the attribute is write/read only. However, during their development process, our customers want to see the warnings if the attributes are accessed incorrectly. So we made these warnings a debug option.
See Dmitry's comment ...
Basically my stance is that you should not lower yourself to the level of others not getting the point of your technical solution by making unelegant compromises, what
you should do is to bring them up to your level so they understand that your solution is elegant.
Maybe a bit utopist I know...
Yours,
Linus Walleij
Re: [RFC PATCH 02/06] input/rmi4: Core files
In reply to Christopher HeinyQuoted 18 lines · Christopher Heiny
Quoted 16 lines · On Thursday, October 11, 2012 02:21:53 AM I wrote:
drivers/input/rmi4/rmi_driver.h line 351
Quoted 7 lines
drivers/input/rmi4/rmi_driver.h new file +7
-0+union pdt_properties { +struct { +u8 reserved_1:6 ; +u8 has_bsr:1 ; +u8 reserved_2:1 ; + } __attribute__((__packed__ )); +u8 regs[1 ];I don't understand what this union is trying to achieve.
regs[1] does not look right considering what you're trying to achieve. Since the above fields require a regs[2] (9 bits!) to be stored. Maybe write out what you're trying to do here so I can understand it? (If everyone else in the world gets it immediately, it's maybe me that need fixing instead...)
Quoted 5 lines
Quoted 1 line
Apart from these remarks it's looking real nice now!
I only count 8 bits there, unless there's something about packing I'm not aware of. Is there something else you found confusing about the union?
I just did bad maths, too many figured in the struct...
But consider Dmitry's suggestion that you might get rid of this unionizing.
Yours,
Linus Walleij
Re: [RFC PATCH 01/06] input/rmi4: Public header and documentation
In reply to Christopher HeinyOn Thu, Oct 11, 2012 at 03:56:22AM +0000, Christopher Heiny wrote:
Fix your mailer to word wrap within paragraphs.
Quoted 3 lines
If this feature is a deal-breaker, we can take it out. In the absence of a generic GPIO implementation for CS, though, I'd much rather leave it in. Once generic GPIO CS arrives, we'll remove it pretty quickly.
Why not just implement this at an appropriate level in the SPI subsystem? One of the great things about Linux is that you can change the core code...
Re: [RFC PATCH 01/06] input/rmi4: Public header and documentation
In reply to Linus WalleijQuoted 9 lines · Linus Walleij
Quoted 6 lines · Christopher Heiny
In previous patch submissions, we always used these warning functions. But in the feedback on those patches, we were asked to just make sysfs show/store NULL if the attribute is write/read only. However, during their development process, our customers want to see the warnings if the attributes are accessed incorrectly. So we made these warnings a debug option.
Quoted 5 lines
Basically my stance is that you should not lower yourself to the level of others not getting the point of your technical solution by making unelegant compromises, what
you should do is to bring them up to your level so they understand that your solution is elegant.
It seems like what you really want to do is add a debug feature to sysfs which will optionally complain loudly at bad accesses; obviously it's not something that should be there all the time as running then handling an error is a perfectly legitimate thing to do. As with the /CS handling it'd mean it was handled at an appropriate level and could be reused elsewhere (it might also help make it clear to your customers why this is generally bad form).
Re: [RFC PATCH 02/06] input/rmi4: Core files
In reply to Joe PerchesQuoted 24 lines · Joe Perches
Quoted 1 line · Christopher Heiny
Joe Perches wrote:
[]
Quoted 8 lines
Quoted 6 lines
drivers/input/rmi4/rmi_driver.c line 549
Quoted 4 lines
drivers/input/rmi4/rmi_driver.c new file +4
-0+list_for_each_entry (entry, &data->rmi_functions.list, list) +if (entry->irq_mask) +process_one_interrupt (entry, irq_status, + data);style nit, it'd be nicer with braces.
I agree with you, but checkpatch.pl doesn't. :-(
Sure it does.
$ cat t.c { list_for_each_entry(entry, &data->rmi_functions.list, list) { if (entry->irq_mask) process_one_interrupt(entry, irq_status, data); } } $ ./scripts/checkpatch.pl --strict -f t.c total: 0 errors, 0 warnings, 0 checks, 7 lines checked
Quoted 1 line
t.chas no obvious style problems and is ready for submission.
I stand corrected. Thanks!
Re: [RFC PATCH 01/06] input/rmi4: Public header and documentation
In reply to Mark BrownQuoted 3 lines · Mark Brown
On Thu, Oct 11, 2012 at 03:56:22AM +0000, Christopher Heiny wrote:
Fix your mailer to word wrap within paragraphs.
Sorry - I was on the road and had to use a web interface. It looked OK during composition. Is this better?
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
If this feature is a deal-breaker, we can take it out. In the absence of a generic GPIO implementation for CS, though, I'd much rather leave it in. Once generic GPIO CS arrives, we'll remove it pretty quickly.
Why not just implement this at an appropriate level in the SPI subsystem? One of the great things about Linux is that you can change the core code...
At the moment, we're trying to keep our work focused on just the core RMI4 driver. It's evident that we've still got a bit to learn, and I'd be more comfortable keeping our learning experiences confined as they are now.
However, a general capability in SPI core is a fine idea for future work, once we get the RMI4 driver ironed out. Can we agree to defer that for now?
Thanks,
Chris
Re: [RFC PATCH 01/06] input/rmi4: Public header and documentation
In reply to Dmitry TorokhovQuoted 10 lines · Dmitry Torokhov
include/linux/rmi.h line 511
Quoted 6 lines · Christopher Heiny
include/linux/rmi.h new file +6
-0+ +int (*write_block)(struct rmi_phys_device *phys,u16 addr,u8 *buf, +int len); +int (*read_block)(struct rmi_phys_device *phys,u16 addr,u8 *buf, +int len); +If you declare your buffer as [const] void * instead of u8 * I think you will be able to get rid of most of your unions.
Good point. We'll explore that. If you see it in the next patch, you'll know it worked out.
Quoted 16 lines
Quoted 16 lines
+ * Helper fn to convert a byte array representing a 16 bit value in the RMI
+ * endian-ness to a 16-bit value in the native processor's specific endianness.
+ * We don't use ntohs/htons here because, well, we're not dealing with
+ * a pair of 16 bit values. Casting dest to u16* wouldn't work, because
+ * that would imply knowing the byte order of u16 in the first place. The
+ * same applies for using shifts and masks.
+ */include/linux/rmi.h new file +9
-0+static inline u16 batohs (u8 *src) +{ +return src[1 ] *0x100 + src[0 ]; +} + +/** +* Helper function to convert a 16 bit value (in host processor endianess) to +* a byte array in the RMI endianess for u16s. See above comment for +* why we dont us htons or something like that.
Quoted 8 lines
include/linux/rmi.h line 658
Quoted 6 lines
+ */
include/linux/rmi.h new file +5
-0+static inline void hstoba (u8 *dest,u16 src) +{ + dest[0 ] = src %0x100 ; + dest[1 ] = src /0x100 ; +}These are not used anymore, right?
There are function drivers that we chose not to include that depend on these. We'll drop these from rmi.h until we're ready to submit those other function drivers.
Dmitry Torokhov
maintainerRe: [RFC PATCH 01/06] input/rmi4: Public header and documentation
Quoted 40 lines · Christopher Heiny
Quoted 10 lines · Dmitry Torokhov
include/linux/rmi.h line 511
Quoted 6 lines · Christopher Heiny
include/linux/rmi.h new file +6
-0+ +int (*write_block)(struct rmi_phys_device *phys,u16 addr,u8 *buf, +int len); +int (*read_block)(struct rmi_phys_device *phys,u16 addr,u8 *buf, +int len); +If you declare your buffer as [const] void * instead of u8 * I think you will be able to get rid of most of your unions.
Good point. We'll explore that. If you see it in the next patch, you'll know it worked out.
Quoted 16 lines
Quoted 16 lines
+ * Helper fn to convert a byte array representing a 16 bit value in the RMI + * endian-ness to a 16-bit value in the native processor's specific endianness. + * We don't use ntohs/htons here because, well, we're not dealing with + * a pair of 16 bit values. Casting dest to u16* wouldn't work, because + * that would imply knowing the byte order of u16 in the first place. The + * same applies for using shifts and masks.
+ */include/linux/rmi.h new file +7
-0+static inline u16 batohs (u8 *src) +{ +return src[1 ] *0x100 + src[0 ]; +} + +/** +* Helper function to convert a 16 bit value (in host processor endianess) to + * a byte array in the RMI endianess for u16s. See above comment for + * why we dont us htons or something like that.
Quoted 8 lines
include/linux/rmi.h line 658
Quoted 6 lines
+ */
include/linux/rmi.h new file +5
-0+static inline void hstoba (u8 *dest,u16 src) +{ + dest[0 ] = src %0x100 ; + dest[1 ] = src /0x100 ; +}These are not used anymore, right?
Quoted 3 lines
There are function drivers that we chose not to include that depend on these. We'll drop these from
rmi.huntil we're ready to submit those other function drivers.
OK, in this case, like last time we discussed, your function drivers should use cpu_to_le16() and le16_to_cpu() instead.
Thanks.
Signature · 1 line
Dmitry
Re: [RFC PATCH 01/06] input/rmi4: Public header and documentation
In reply to Dmitry TorokhovQuoted 32 lines · Dmitry Torokhov
Quoted 24 lines · Christopher Heiny
Quoted 24 lines
Quoted 22 lines · Linus Walleij
Quoted 22 lines · Christopher Heiny
Quoted 10 lines
Quoted 10 lines
include/linux/rmi.h new file +4
-0+#ifdef CONFIG_RMI4_DEBUG +/** +* Utility routine to handle writes to read-only attributes. Hopefully +* this will never happen, but if the user does something stupid, we don't
+ * want to accept it quietly (which is what can happen if you just put NULL + * for the attribute's store function).
+ */
+static inlinessize_trmi_store_error(struct device *dev,Quoted 8 lines
Review
Quoted 8 lines
include/linux/rmi.h new file +5
-0+struct device_attribute *attr, + const char *buf, size_t count) +{ +dev_warn (dev , + "WARNING: Attempt to write %d characters to read-onlyattribute %s.", + count,
attr->attr.name);(quoted diff) +2
-0+ return -EPERM; +}Here it looks like you're hiding a lot of stuff that should be
dev_warn()? Consider my earlier point about dynamic debug.Quoted 6 lines
Quoted 6 lines
In previous patch submissions, we always used these warning functions. But in the feedback on those patches, we were asked to just make sysfs show/store NULL if the attribute is write/read only. However, during their development process, our customers want to see the warnings if the attributes are accessed incorrectly. So we made these warnings a debug option.
Quoted 3 lines
I think it is the case when customer is not always right. Given that the attributes are created with
S_IRUGOmask how will we even get these methods to fire?
We were able to get those to fire in earlier kernels under some UIs (such as Android). However, we no longer support those earlier version.
I have checked the behavior on up-to-date kernels and UI versions, and
everyone seems to handle this correctly. That means we can drop these definitions entirely, so we'll do that.
Re: [RFC PATCH 01/06] input/rmi4: Public header and documentation
In reply to Linus WalleijQuoted 19 lines · Linus Walleij
Quoted 12 lines · Christopher Heiny
Quoted 9 lines · Linus Walleij
But please use arithmetic operators (I think I said this on the last review):
dest[0] = src &
0xFF;
dest[1] = src >> 8;Doing it the above way makes artithmetic look like maths, and it isn't. Besides it's done this way in most parts of the kernel and we're familiar with it.
Quoted 5 lines
Yes, you mentioned it previously. I'm somewhat paranoid, though, and don't trust the shift/mask method to work correctly on big-endian machines. If the shifts can be relied on to behave (I'm guessing the answer is "yes", since you say this idiom is used widely in the kernel), then I'll change it.
Quoted 6 lines
If the behaviour was not consistent across different endianness it would not be part of the C language specification...
<< means shift left in the accumulator or whatever you have. It will work the same no matter how bits are laid out in memory.
OK, after reviewing the spec I'll accept that. We'll make the change.
Quoted 22 lines
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
include/linux/rmi.h new file +4
-0+static inline ssize_t rmi_store_error (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +2
-0+ dev_warn(dev, + "WARNING: Attempt to write %d characters to read-onlyattribute %s.", + count,
attr->attr.name);(quoted diff) +2
-0+ return -EPERM; +}Here it looks like you're hiding a lot of stuff that should be
dev_warn()? Consider my earlier point about dynamic debug.Quoted 6 lines
In previous patch submissions, we always used these warning functions. But in the feedback on those patches, we were asked to just make sysfs show/store NULL if the attribute is write/read only. However, during their development process, our customers want to see the warnings if the attributes are accessed incorrectly. So we made these warnings a debug option.
See Dmitry's comment ...
Quoted 7 lines
Basically my stance is that you should not lower yourself to the level of others not getting the point of your technical solution by making unelegant compromises, what
you should do is to bring them up to your level so they understand that your solution is elegant.Maybe a bit utopist I know...
What's the old saying? "I want to live in Theory. Everything is always so nice there..." :-)
Anyway, see my reply to Dmitry a bit ago. These are no longer needed, so we'll drop them.
Re: [RFC PATCH 01/06] input/rmi4: Public header and documentation
In reply to Mark BrownQuoted 16 lines · Mark Brown
Quoted 9 lines · Linus Walleij
Quoted 6 lines · Christopher Heiny
In previous patch submissions, we always used these warning functions. But in the feedback on those patches, we were asked to just make sysfs show/store NULL if the attribute is write/read only. However, during their development process, our customers want to see the warnings if the attributes are accessed incorrectly. So we made these warnings a debug option.
Quoted 5 lines
Basically my stance is that you should not lower yourself to the level of others not getting the point of your technical solution by making unelegant compromises, what
you should do is to bring them up to your level so they understand that your solution is elegant.
Quoted 7 lines
It seems like what you really want to do is add a debug feature to sysfs which will optionally complain loudly at bad accesses; obviously it's not something that should be there all the time as running then handling an error is a perfectly legitimate thing to do. As with the /CS handling it'd mean it was handled at an appropriate level and could be reused elsewhere (it might also help make it clear to your customers why this is generally bad form).
See my reply to Dmitry of a bit ago. These are no longer needed, and we'll be dropping them.
Re: [RFC PATCH 02/06] input/rmi4: Core files
In reply to Dmitry TorokhovQuoted 21 lines · Dmitry Torokhov
Quoted 20 lines · Christopher Heiny
Quoted 18 lines · you
drivers/input/rmi4/rmi_driver.c line 400
Quoted 10 lines · Christopher Heiny
drivers/input/rmi4/rmi_driver.c new file +10
-0+ +/** This is here because all those casts made for some ugly code. +*/ +static void u8_and (u8 *dest,u8 *target1,u8 *target2,int nbits) +{ +bitmap_and ((long unsigned int *) dest, + (long unsigned int *) target1, + (long unsigned int *) target2, + nbits); +}Hm, getting rid of unreadable casts is a valid case.
I'll be OK with this but maybe the real solution is to introduce such helpers into <
linux/bitmap.h>?
Quoted 7 lines
Quoted 3 lines
Hmmm. We'll give that some thought. Thought I'd like to get the RMI4 driver nailed down, just to keep the area of change small. Once we've got all the kinks worked out here, we'll look at
bitmap.hhelpers.The question is why you are using u8 for bitmaps instead of doing
DECALRE_BITMAP()and using it instead? Then you would not need silly wrappers around existing APIs.
OK, we'll look into that. My big concern is whether the bit-order in bitmask.h will be the same as the bit order in the RMI4 sensor registers. If that works out OK, we'll switch.
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
(...)
drivers/input/rmi4/rmi_driver.c line 527
Quoted 6 lines
drivers/input/rmi4/rmi_driver.c new file +6
-0+static int process_interrupt_requests (struct rmi_device *rmi_dev) +{ +struct rmi_driver_data *data =dev_get_drvdata (&rmi_dev->dev); +struct device *dev = &rmi_dev->dev; +struct rmi_function_container *entry; +u8 irq_status[data->num_of_irq_regs];Looking at this...
What does the
data->num_of_irq_regsactually contain?I just fear that it is something constant like always 2 or always 4, so there is actually, in reality, a 16 or 32 bit register hiding in there.
In that case what you should do is to represent it as a u16 or u32 here, just or the bits into a status word, and then walk over that status word with something like ffs(bitword); ...
Quoted 8 lines
Quoted 5 lines
Nope, it's not constant. In theory, and RMI4 based sensor can have up to 128 functions (in practice, it's far fewer), and each function can have as many as 7 interrupts. So the number of IRQ registers can vary from RMI4 sensor to RMI4 sensor, and needs to be computed during the scan of the product descriptor table.
Is it a good idea to have it on stack then? Should it be part of
rmi_deviceinstead?
It's not coming off the stack. We're allocating it via devm_kzalloc() in rmi_driver_probe().
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
drivers/input/rmi4/rmi_driver.h line 84
Quoted 12 lines
(quoted diff) +2
-0+#define simple_show_union_struct(regtype, propname, fmt)\ +static ssize_t tricat(rmi_fn_, FNUM, _##propname##_show)(struct device*dev,\ + struct
device_attribute*attr,
char *buf) {\ + structrmi_function_container*fc;\drivers/input/rmi4/rmi_driver.h new file +8
-0+struct FUNCTION_DATA *data;\ +\ + fc =to_rmi_function_container (dev);\ + data = fc->data;\ +\ +return snprintf (buf,PAGE_SIZE , fmt,\ + data->regtype.propname);\ +}OK I see the point, but is there really no other way to do this than to #define huge static inlines like these? Is it really not possible to create just generic functions instead of going this far?
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
(same comment for all)
We tried generic functions previously, and it wound up really really ugly. We'd be willing to look at it again, though, since this isn't real beautiful either. If you've got an example implementation in mind. a pointer would help a great deal.
You just need to wrap around a custome structure around struct
device_attributeand then you shoudl be able to use generics. If you look intotrackpoint.cyou should gett the idea.
That looks a lot tidier. We'll work on it for sysfs (and maybe for debugfs, too). It might not be applicable in all cases, but it promises to make a lot of things tidier.
Thanks!
Dmitry Torokhov
maintainerRe: [RFC PATCH 02/06] input/rmi4: Core files
Quoted 4 lines · Christopher Heiny
Quoted 3 lines · Dmitry Torokhov
Quoted 2 lines · Christopher Heiny
Quoted 1 line · you
On Sat, Oct 6, 2012 at 6:09 AM, Christopher Heiny <[email protected]>
Quoted 20 lines · wrote:
Quoted 20 lines
Quoted 19 lines
Quoted 13 lines
drivers/input/rmi4/rmi_driver.c line 400
Quoted 10 lines
drivers/input/rmi4/rmi_driver.c new file +10
-0+ +/** This is here because all those casts made for some ugly code. +*/ +static void u8_and (u8 *dest,u8 *target1,u8 *target2,int nbits) +{ +bitmap_and ((long unsigned int *) dest, + (long unsigned int *) target1, + (long unsigned int *) target2, + nbits); +}Hm, getting rid of unreadable casts is a valid case.
Quoted 2 lines
I'll be OK with this but maybe the real solution is to introduce such helpers into <
linux/bitmap.h>?Hmmm. We'll give that some thought. Thought I'd like to get the RMI4 driver nailed down, just to keep the area of change small. Once we've got all the kinks worked out here, we'll look at
bitmap.hhelpers.
Quoted 7 lines
Quoted 3 lines
The question is why you are using u8 for bitmaps instead of doing
DECALRE_BITMAP()and using it instead? Then you would not need silly wrappers around existing APIs.OK, we'll look into that. My big concern is whether the bit-order in
bitmask.hwill be the same as the bit order in the RMI4 sensor registers. If that works out OK, we'll switch.
I think if you properly convert data to/from cpu-endianness it will clear matters a lot.
Quoted 28 lines
Quoted 28 lines
Quoted 27 lines
Quoted 14 lines
(...)
drivers/input/rmi4/rmi_driver.c line 527
Quoted 6 lines
drivers/input/rmi4/rmi_driver.c new file +6
-0+static int process_interrupt_requests (struct rmi_device *rmi_dev) +{ +struct rmi_driver_data *data =dev_get_drvdata (&rmi_dev->dev); +struct device *dev = &rmi_dev->dev; +struct rmi_function_container *entry; +u8 irq_status[data->num_of_irq_regs];Looking at this...
What does the
data->num_of_irq_regsactually contain?Quoted 7 lines
I just fear that it is something constant like always 2 or always 4, so there is actually, in reality, a 16 or 32 bit register hiding in there.
In that case what you should do is to represent it as a u16 or u32 here, just or the bits into a status word, and then walk over that status word with something like ffs(bitword); ...
Nope, it's not constant. In theory, and RMI4 based sensor can have up to 128 functions (in practice, it's far fewer), and each function can have as many as 7 interrupts. So the number of IRQ registers can vary from RMI4 sensor to RMI4 sensor, and needs to be computed during the scan of the product descriptor table.
Quoted 5 lines
Quoted 2 lines
Is it a good idea to have it on stack then? Should it be part of
rmi_deviceinstead?It's not coming off the stack. We're allocating it via
devm_kzalloc()inrmi_driver_probe().
No, look at the part of the code that was quoted. "u8 irq_status[data-
Quoted 1 line
num_of_irq_regs];" is on stack.
Thanks.
Signature · 1 line
Dmitry
Re: [RFC PATCH 02/06] input/rmi4: Core files
Quoted 6 lines · Dmitry Torokhov
Quoted 4 lines · Christopher Heiny
Quoted 3 lines · Dmitry Torokhov
Quoted 2 lines · Christopher Heiny
Quoted 1 line · you
On Sat, Oct 6, 2012 at 6:09 AM, Christopher Heiny <[email protected]>
wrote:
[snip]
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 11 lines
drivers/input/rmi4/rmi_driver.c line 527
Quoted 6 lines
drivers/input/rmi4/rmi_driver.c new file +6
-0+static int process_interrupt_requests (struct rmi_device *rmi_dev) +{ +struct rmi_driver_data *data =dev_get_drvdata (&rmi_dev->dev); +struct device *dev = &rmi_dev->dev; +struct rmi_function_container *entry; +u8 irq_status[data->num_of_irq_regs];Looking at this...
What does the
data->num_of_irq_regsactually contain?Quoted 7 lines
I just fear that it is something constant like always 2 or always 4, so there is actually, in reality, a 16 or 32 bit register hiding in there.
In that case what you should do is to represent it as a u16 or u32 here, just or the bits into a status word, and then walk over that status word with something like ffs(bitword); ...
Nope, it's not constant. In theory, and RMI4 based sensor can have up to 128 functions (in practice, it's far fewer), and each function can have as many as 7 interrupts. So the number of IRQ registers can vary from RMI4 sensor to RMI4 sensor, and needs to be computed during the scan of the product descriptor table.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Is it a good idea to have it on stack then? Should it be part of
rmi_deviceinstead?It's not coming off the stack. We're allocating it via
devm_kzalloc()inrmi_driver_probe().No, look at the part of the code that was quoted. "u8 irq_status[data-
num_of_irq_regs];" is on stack.
Sorry - I thought you were referring to data->num_of_irq_regs rather than irq_status. We'll move that.
Re: [RFC PATCH 01/06] input/rmi4: Public header and documentation
In reply to Christopher HeinyQuoted 7 lines · Christopher Heiny
Quoted 3 lines · Mark Brown
On Thu, Oct 11, 2012 at 03:56:22AM +0000, Christopher Heiny wrote:
Fix your mailer to word wrap within paragraphs.
Sorry - I was on the road and had to use a web interface. It looked OK during composition. Is this better?
Yes, that's great - thanks.
Quoted 3 lines
However, a general capability in SPI core is a fine idea for future work, once we get the RMI4 driver ironed out. Can we agree to defer that for now?
Obviously there's no pressure to implement the framework feature, however it shouldn't be implemented at the driver level.
Re: [RFC PATCH 06/06] input/rmi4: F11 - 2D touch interface
In reply to Henrik RydbergQuoted 7 lines · Henrik Rydberg
Hi Christopher,
Quoted 3 lines
rmi_f11.cis a driver for 2D touch sensors. It has been updated to support the MT-B specification, partition control attributes between debugfs andsysfs, and to use the standard bus model for loading/unloading.Please find comments inline.
Thanks very much. I though I'd replied to this along with the other replies sent a couple of weeks ago, but don't see it in the archives. My apologies if this is a duplicate message.
Quoted 7 lines
Generally, if you want this merged as an input device sometime in the future, you need to reduce the size and complexity of the whole patchset. Given that you only need to feed the input subsystem with raw data, you can make do without most of the sysfs nodes, debug output, and internal gesture state.
Quoted 5 lines
The 2D sensor data, currently living in debugfs, might eventually find a home in the input subsystem, based on the growing interest from several directions. However, if you are just looking for a way to transport the rmi data to userland, please consider implementing this under a different subsystem.
I must disagree with some of this. Feeding raw data to the input subsystem is not the only thing that needs to be done - there needs to be a way to configure and control the operation of the touch sensor, both during product prototyping/development (we've partitioned that stuff into debugfs) and during normal operation (we've put that stuff in sysfs). If we remove the related code, that would not be possible. If we move it to a different subsystem, where do you suggest it be moved to?
The gesture data is a different matter. Although the most popular user space implementations may contain gesture recognition engines, not all of them do. In that case, it is desirable to have the touch sensor firmware perform basic gesture recognition. However, there is at this time no way standard way to transfer that via the input subsystem. We chose to use sysfs for this, but alternatively we could investigate using a custom event stream in the input subsystem. We'd also be quite happy to work with you to define a standard set of gesture events for basic gestures.
Quoted 2 lines
Quoted 2 lines
drivers/input/rmi4/rmi_f11.c +0
-0
[snip]
Quoted 6 lines
drivers/input/rmi4/rmi_f11.c line 48
Quoted 4 lines
drivers/input/rmi4/rmi_f11.c +4
-0+ +#define FINGER_STATE_MASK 0x03 +#define GET_FINGER_STATE (f_states, i) \ + ((f_states[i / 4] >> (2 * (i % 4))) & FINGER_STATE_MASK)These could be open-coded or put in a function instead.
We'll put that in a function.
Quoted 38 lines
Quoted 38 lines
drivers/input/rmi4/rmi_f11.c +38
-0+ +#define F11_CTRL_SENSOR_MAX_X_POS_OFFSET 6 +#define F11_CTRL_SENSOR_MAX_Y_POS_OFFSET 8 + +#define F11_CEIL (x, y) (((x) + ((y)-1)) / (y)) +#define INBOX (x, y, box) (x >= box.x && x < (box.x + box.width) \ + && y >= box.y && y < (box.y + box.height)) + +#define DEFAULT_XY_MAX 9999 +#define DEFAULT_MAX_ABS_MT_PRESSURE 255 +#define DEFAULT_MAX_ABS_MT_TOUCH 15 +#define DEFAULT_MAX_ABS_MT_ORIENTATION 1 +#define DEFAULT_MIN_ABS_MT_TRACKING_ID 1 +#define DEFAULT_MAX_ABS_MT_TRACKING_ID 10 +#define MAX_NAME_LENGTH 256 + +static ssize_t f11_relreport_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +static ssize_t f11_relreport_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count); + +static ssize_t f11_maxPos_show (struct device *dev, +struct device_attribute *attr,char *buf); + +static ssize_t f11_rezero_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count); + +static void rmi_f11_free_memory (struct rmi_function_container *fc); + +static int rmi_f11_initialize (struct rmi_function_container *fc); + +static int rmi_f11_create_sysfs (struct rmi_function_container *fc); + +static int rmi_f11_config (struct rmi_function_container *fc);
Quoted 8 lines
drivers/input/rmi4/rmi_f11.c line 92
Quoted 6 lines
drivers/input/rmi4/rmi_f11.c +6
-0+ +static int rmi_f11_register_devices (struct rmi_function_container *fc); + +static void rmi_f11_free_devices (struct rmi_function_container *fc); + +static void f11_set_abs_params (struct rmi_function_container *fc,int index);Please try to get rid of these.
OK
[snip]
Quoted 6 lines
Quoted 6 lines
drivers/input/rmi4/rmi_f11.c +6
-0+ +/** +* @rezero - writing 1 to this will cause the sensor to calibrate to the +* current capacitive state. +*/ +union f11_2d_commands {
Quoted 8 lines
drivers/input/rmi4/rmi_f11.c line 110
Quoted 6 lines
drivers/input/rmi4/rmi_f11.c +6
-0+struct { +bool rezero:1 ; +u8 reserved:7 ; + } __attribute__((__packed__ )); +u8 reg; +};Maybe a constant would be more suitable here?
We're trying to use a single idiom for accessing registers (the union/struct mechanism you see here). In a couple of cases, that means we use a struct to control a single bit, instead of a constant. The end result is the same, and we find that not mixing our idioms makes the code a lot easier to maintain.
Quoted 29 lines
Quoted 29 lines
drivers/input/rmi4/rmi_f11.c +28
-0+ +/** +* @nbr_of_sensors - the number of 2D sensors on the touch device. +* @has_query9 - indicates the F11_2D_Query9 register exists. +* @has_query11 - indicates the F11_2D_Query11 register exists. +* @has_z_tuning - if set, the sensor supports Z tuning and registers +* F11_2D_Ctrl29 through F11_2D_Ctrl33 exist. +* @has_pos_interpolation_tuning - TBD +* @has_w_tuning - the sensor supports Wx and Wy scaling and registers +* F11_2D_Ctrl36 through F11_2D_Ctrl39 exist. +* @has_pitch_info - the X and Y pitches of the sensor electrodes can be +* configured and registers F11_2D_Ctrl40 and F11_2D_Ctrl41 exist. +* @has_default_finger_width - the default finger width settings for the +* sensor can be configured and registers F11_2D_Ctrl42 through F11_2D_Ctrl44 +* exist. +* @has_segmentation_aggressiveness - the sensor’s ability to distinguish +* multiple objects close together can be configured and register F11_2D_Ctrl45 +* exists. +* @has_tx_rw_clip - the inactive outside borders of the sensor can be +* configured and registers F11_2D_Ctrl46 through F11_2D_Ctrl49 exist. +* @has_drumming_correction - the sensor can be configured to distinguish +* between a fast flick and a quick drumming movement and registers +* F11_2D_Ctrl50 and F11_2D_Ctrl51 exist. +*/ +struct f11_2d_device_query { + union { + struct { + u8 nbr_of_sensors:3;
Quoted 8 lines
drivers/input/rmi4/rmi_f11.c line 144
Quoted 6 lines
drivers/input/rmi4/rmi_f11.c +6
-0+ bool has_query9:1; + bool has_query11:1; + u8 reserved:3; + } __attribute__((__packed__)); +u8 f11_2d_query0; + };Why union here? It seems all you need is a packed struct named query0.
If Dmitry's suggestion (discussed in other emails) to use void * instead of u8 * for data buffers works out, then this union will become just a struct.
[snip dittos of the above topic]
Quoted 112 lines
Quoted 112 lines
drivers/input/rmi4/rmi_f11.c +111
-0+ +/** +* @number_of_fingers - describes the maximum number of fingers the 2-Dsensor +* supports. +* @has_rel - the sensor supports relative motion reporting. +* @has_abs - the sensor supports absolute poition reporting. +* @has_gestures - the sensor supports gesture reporting. +* @has_sensitivity_adjust - the sensor supports a global sensitivity +* adjustment. +* @configurable - the sensor supports various configuration options. +* @num_of_x_electrodes - the maximum number of electrodes the 2-D sensor +* supports on the X axis. +* @num_of_y_electrodes - the maximum number of electrodes the 2-D sensor +* supports on the Y axis. +* @max_electrodes - the total number of X and Y electrodes that may be +* configured. +* @abs_data_size - describes the format of data reported by the absolute +* data source. Only one format (the kind used here) is supported at this +* time. +* @has_anchored_finger - then the sensor supports the high-precision second +* finger tracking provided by the manual tracking and motion sensitivity +* options. +* @has_adjust_hyst - the difference between the finger release threshold and +* the touch threshold. +* @has_dribble - the sensor supports the generation of dribble interrupts, +* which may be enabled or disabled with the dribble control bit. +* @f11_2d_query6 - reserved. +* @has_single_tap - a basic single-tap gesture is supported. +* @has_tap_n_hold - tap-and-hold gesture is supported. +* @has_double_tap - double-tap gesture is supported. +* @has_early_tap - early tap is supported and reported as soon as the finger +* lifts for any tap event that could be interpreted as either a singletap +* or as the first tap of a double-tap or tap-and-hold gesture. +* @has_flick - flick detection is supported. +* @has_press - press gesture reporting is supported. +* @has_pinch - pinch gesture detection is supported. +* @has_palm_det - the 2-D sensor notifies the host whenever a large conductive +* object such as a palm or a cheek touches the 2-D sensor. +* @has_rotate - rotation gesture detection is supported. +* @has_touch_shapes - TouchShapes are supported. A TouchShape is a fixed +* rectangular area on the sensor that behaves like a capacitive button. +* @has_scroll_zones - scrolling areas near the sensor edges are supported. +* @has_individual_scroll_zones - if 1, then 4 scroll zones are supported; +* if 0, then only two are supported. +* @has_multi_finger_scroll - the multifinger_scrolling bit will be setwhen +* more than one finger is involved in a scrolling action. +* @nbr_touch_shapes - the total number of touch shapes supported. +*/ +struct f11_2d_sensor_query { +union { +struct { +/* query1 */ +u8 number_of_fingers:3 ; +bool has_rel:1 ; +bool has_abs:1 ; +bool has_gestures:1 ; +bool has_sensitivity_adjust:1 ; +bool configurable:1 ; +/* query2 */ +u8 num_of_x_electrodes:7 ; +u8 reserved_1:1 ; +/* query3 */ +u8 num_of_y_electrodes:7 ; +u8 reserved_2:1 ; +/* query4 */ +u8 max_electrodes:7 ; +u8 reserved_3:1 ; + } __attribute__((__packed__ )); +u8 f11_2d_query1__4[4 ]; + }; + +union { +struct { +u8 abs_data_size:3 ; +bool has_anchored_finger:1 ; +bool has_adj_hyst:1 ; +bool has_dribble:1 ; +u8 reserved_4:2 ; + } __attribute__((__packed__ )); +u8 f11_2d_query5; + }; + +u8 f11_2d_query6; + +union { +struct { +bool has_single_tap:1 ; +bool has_tap_n_hold:1 ; +bool has_double_tap:1 ; +bool has_early_tap:1 ; +bool has_flick:1 ; +bool has_press:1 ; +bool has_pinch:1 ; +bool padding:1 ; + +bool has_palm_det:1 ; +bool has_rotate:1 ; +bool has_touch_shapes:1 ; +bool has_scroll_zones:1 ; +bool has_individual_scroll_zones:1 ; +bool has_multi_finger_scroll:1 ; + } __attribute__((__packed__ )); +u8 f11_2d_query7__8[2 ]; + }; + +union f11_2d_query9 query9; + +union { +struct { +u8 nbr_touch_shapes:5 ; + } __attribute__((__packed__ ));
Quoted 8 lines
drivers/input/rmi4/rmi_f11.c line 297
Quoted 3 lines
drivers/input/rmi4/rmi_f11.c +3
-0+u8 f11_2d_query10; + }; +};Ditto. It is nice with some documentation, but in this case, it might make sense to add it on the same line in the struct. Also, since an MT device outputs the raw position data and leaves the gestures to userspace, this whole construct is more complex than it needs to be.
See remarks on gestures at the top of this email.
Quoted 187 lines
Quoted 187 lines
drivers/input/rmi4/rmi_f11.c +186
-0+ +/** +* @reporting_mode - controls how often finger position data is reported. +* @abs_pos_filt - when set, enables various noise and jitter filtering +* algorithms for absolute reports. +* @rel_pos_filt - when set, enables various noise and jitter filtering +* algorithms for relative reports. +* @rel_ballistics - enables ballistics processing for the relative finger +* motion on the 2-D sensor. +* @dribble - enables the dribbling feature. +* @report_beyond_clip - when this is set, fingers outside the active area +* specified by the x_clip and y_clip registers will be reported, but with +* reported finger position clipped to the edge of the active area. +* @palm_detect_thresh - the threshold at which a wide finger is considered a +* palm. A value of 0 inhibits palm detection. +* @motion_sensitivity - specifies the threshold an anchored finger must move +* before it is considered no longer anchored. High values mean more +* sensitivity. +* @man_track_en - for anchored finger tracking, whether the host (1) or the +* device (0) determines which finger is the tracked finger. +* @man_tracked_finger - when man_track_en is 1, specifies whether finger 0 or +* finger 1 is the tracked finger. +* @delta_x_threshold - 2-D position update interrupts are inhibited unless +* the finger moves more than a certain threshold distance along the X axis. +* @delta_y_threshold - 2-D position update interrupts are inhibited unless +* the finger moves more than a certain threshold distance along the Y axis. +* @velocity - When rel_ballistics is set, this register defines the +* velocity ballistic parameter applied to all relative motion events. +* @acceleration - When rel_ballistics is set, this register defines the +* acceleration ballistic parameter applied to all relative motion events. +* @sensor_max_x_pos - the maximum X coordinate reported by the sensor. +* @sensor_max_y_pos - the maximum Y coordinate reported by the sensor. +*/ +union f11_2d_ctrl0_9 { +struct { +/* F11_2D_Ctrl0 */ +u8 reporting_mode:3 ; +bool abs_pos_filt:1 ; +bool rel_pos_filt:1 ; +bool rel_ballistics:1 ; +bool dribble:1 ; +bool report_beyond_clip:1 ; +/* F11_2D_Ctrl1 */ +u8 palm_detect_thres:4 ; +u8 motion_sensitivity:2 ; +bool man_track_en:1 ; +bool man_tracked_finger:1 ; +/* F11_2D_Ctrl2 and 3 */ +u8 delta_x_threshold:8 ; +u8 delta_y_threshold:8 ; +/* F11_2D_Ctrl4 and 5 */ +u8 velocity:8 ; +u8 acceleration:8 ; +/* F11_2D_Ctrl6 thru 9 */ +u16 sensor_max_x_pos:12 ; +u8 ctrl7_reserved:4 ; +u16 sensor_max_y_pos:12 ; +u8 ctrl9_reserved:4 ; + } __attribute__((__packed__ )); +struct { +u8 regs[10 ]; +u16 address; + } __attribute__((__packed__ )); +}; + +/** +* @single_tap_int_enable - enable tap gesture recognition. +* @tap_n_hold_int_enable - enable tap-and-hold gesture recognition. +* @double_tap_int_enable - enable double-tap gesture recognition. +* @early_tap_int_enable - enable early tap notification. +* @flick_int_enable - enable flick detection. +* @press_int_enable - enable press gesture recognition. +* @pinch_int_enable - enable pinch detection. +*/ +union f11_2d_ctrl10 { +struct { +bool single_tap_int_enable:1 ; +bool tap_n_hold_int_enable:1 ; +bool double_tap_int_enable:1 ; +bool early_tap_int_enable:1 ; +bool flick_int_enable:1 ; +bool press_int_enable:1 ; +bool pinch_int_enable:1 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +/** +* @palm_detect_int_enable - enable palm detection feature. +* @rotate_int_enable - enable rotate gesture detection. +* @touch_shape_int_enable - enable the TouchShape feature. +* @scroll_zone_int_enable - enable scroll zone reporting. +* @multi_finger_scroll_int_enable - enable the multfinger scroll feature. +*/ +union f11_2d_ctrl11 { +struct { +bool palm_detect_int_enable:1 ; +bool rotate_int_enable:1 ; +bool touch_shape_int_enable:1 ; +bool scroll_zone_int_enable:1 ; +bool multi_finger_scroll_int_enable:1 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +union f11_2d_ctrl12 { +struct { +u8 sensor_map:7 ; +bool xy_sel:1 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +/** +* @sens_adjustment - allows a host to alter the overall sensitivity ofa +* 2-D sensor. A positive value in this register will make the sensor more +* sensitive than the factory defaults, and a negative value will make it +* less sensitive. +* @hyst_adjustment - increase the touch/no-touch hysteresis by 2 Z-units for +* each one unit increment in this setting. +*/ +union f11_2d_ctrl14 { +struct { +s8 sens_adjustment:5 ; +u8 hyst_adjustment:3 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +/** +* @max_tap_time - the maximum duration of a tap, in 10-millisecond units. +*/ +union f11_2d_ctrl15 { +struct { +u8 max_tap_time:8 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +/** +* @min_press_time - The minimum duration required for stationary finger(s) to +* generate a press gesture, in 10-millisecond units. +*/ +union f11_2d_ctrl16 { +struct { +u8 min_press_time:8 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +/** +* @max_tap_distance - Determines the maximum finger movement allowed during +* a tap, in 0.1-millimeter units. +*/ +union f11_2d_ctrl17 { +struct { +u8 max_tap_distance:8 ; + } __attribute__((__packed__ )); +u8 reg; +}; + +/** +* @min_flick_distance - the minimum finger movement for a flick gesture, +* in 1-millimeter units. +* @min_flick_speed - the minimum finger speed for a flick gesture, in +* 10-millimeter/second units. +*/ +union f11_2d_ctrl18_19 { +struct { +u8 min_flick_distance:8 ; +u8 min_flick_speed:8 ; + } __attribute__((__packed__ )); +u8 reg[2 ]; +}; + +/** +* @pen_detect_enable - enable reporting of stylus activity. +* @pen_jitter_filter_enable - Setting this enables the stylus anti-jitter +* filter. +* @pen_z_threshold - This is the stylus-detection lower threshold. Smaller +* values result in higher sensitivity. +*/ +union f11_2d_ctrl20_21 { +struct { +bool pen_detect_enable:1 ; +bool pen_jitter_filter_enable:1 ;
Quoted 8 lines
drivers/input/rmi4/rmi_f11.c line 488
Quoted 5 lines
drivers/input/rmi4/rmi_f11.c +5
-0+ u8 ctrl20_reserved:6; + u8 pen_z_threshold:8; + } __attribute__((__packed__)); +u8 reg[2 ]; +};Given that most of the above will not be used in this driver, it can probably be compressed quite a bit.
I'm not sure why you say these will not be used. They are currently or soon will be used by userspace control and configuration programs.
Quoted 104 lines
Quoted 104 lines
drivers/input/rmi4/rmi_f11.c +103
-0+ +/** +* These are not accessible through sysfs yet. +* +* @proximity_detect_int_en - enable proximity detection feature. +* @proximity_jitter_filter_en - enables an anti-jitter filter on proximity +* data. +* @proximity_detection_z_threshold - the threshold for finger-proximity +* detection. +* @proximity_delta_x_threshold - In reduced-reporting modes, this is the +* threshold for proximate-finger movement in the direction parallel tothe +* X-axis. +* @proximity_delta_y_threshold - In reduced-reporting modes, this is the +* threshold for proximate-finger movement in the direction parallel tothe +* Y-axis. +* * @proximity_delta_Z_threshold - In reduced-reporting modes, this isthe +* threshold for proximate-finger movement in the direction parallel tothe +* Z-axis. +*/ +union f11_2d_ctrl22_26 { +struct { +/* control 22 */ +bool proximity_detect_int_en:1 ; +bool proximity_jitter_filter_en:1 ; +u8 f11_2d_ctrl6_b3__7:6 ; + +/* control 23 */ +u8 proximity_detection_z_threshold; + +/* control 24 */ +u8 proximity_delta_x_threshold; + +/* control 25 */ +u8 proximity_delta_y_threshold; + +/* control 26 */ +u8 proximity_delta_z_threshold; + } __attribute__((__packed__ )); +u8 regs[5 ]; +}; + +/** +* @palm_detecy_sensitivity - When this value is small, smaller objectswill +* be identified as palms; when this value is large, only larger objects will +* be identified as palms. 0 represents the factory default. +* @suppress_on_palm_detect - when set, all F11 interrupts except palm_detect +* are suppressed while a palm is detected. +*/ +union f11_2d_ctrl27 { +struct { +s8 palm_detect_sensitivity:4 ; +bool suppress_on_palm_detect:1 ; +u8 f11_2d_ctrl27_b5__7:3 ; + } __attribute__((__packed__ )); +u8 regs[1 ]; +}; + +/** +* @multi_finger_scroll_mode - allows choice of multi-finger scroll mode and +* determines whether and how X or Y displacements are reported. +* @edge_motion_en - enables the edge_motion feature. +* @multi_finger_scroll_momentum - controls the length of time that scrolling +* continues after fingers have been lifted. +*/ +union f11_2d_ctrl28 { +struct { +u8 multi_finger_scroll_mode:2 ; +bool edge_motion_en:1 ; +bool f11_2d_ctrl28b_3:1 ; +u8 multi_finger_scroll_momentum:4 ; + } __attribute__((__packed__ )); +u8 regs[1 ]; +}; + +/** +* @z_touch_threshold - Specifies the finger-arrival Z threshold. Largevalues +* may cause smaller fingers to be rejected. +* @z_touch_hysteresis - Specifies the difference between the finger-arrival +* Z threshold and the finger-departure Z threshold. +*/ +union f11_2d_ctrl29_30 { +struct { +u8 z_touch_threshold; +u8 z_touch_hysteresis; + } __attribute__((__packed__ )); +struct { +u8 regs[2 ]; +u16 address; + } __attribute__((__packed__ )); +}; + + +struct f11_2d_ctrl { +union f11_2d_ctrl0_9 *ctrl0_9; +union f11_2d_ctrl10 *ctrl10; +union f11_2d_ctrl11 *ctrl11; +union f11_2d_ctrl12 *ctrl12; +u8 ctrl12_size; +union f11_2d_ctrl14 *ctrl14; +union f11_2d_ctrl15 *ctrl15; +union f11_2d_ctrl16 *ctrl16; +union f11_2d_ctrl17 *ctrl17; +union f11_2d_ctrl18_19 *ctrl18_19;
Quoted 8 lines
drivers/input/rmi4/rmi_f11.c line 597
Quoted 6 lines
drivers/input/rmi4/rmi_f11.c +6
-0+union f11_2d_ctrl20_21 *ctrl20_21; +union f11_2d_ctrl22_26 *ctrl22_26; +union f11_2d_ctrl27 *ctrl27; +union f11_2d_ctrl28 *ctrl28; +union f11_2d_ctrl29_30 *ctrl29_30; +};Will any of this data be used at all?
Yes.
Quoted 165 lines
Quoted 165 lines
drivers/input/rmi4/rmi_f11.c +164
-0+ +/** +* @x_msb - top 8 bits of X finger position. +* @y_msb - top 8 bits of Y finger position. +* @x_lsb - bottom 4 bits of X finger position. +* @y_lsb - bottom 4 bits of Y finger position. +* @w_y - contact patch width along Y axis. +* @w_x - contact patch width along X axis. +* @z - finger Z value (proxy for pressure). +*/ +struct f11_2d_data_1_5 { +u8 x_msb; +u8 y_msb; +u8 x_lsb:4 ; +u8 y_lsb:4 ; +u8 w_y:4 ; +u8 w_x:4 ; +u8 z; +}; + +/** +* @delta_x - relative motion along X axis. +* @delta_y - relative motion along Y axis. +*/ +struct f11_2d_data_6_7 { +s8 delta_x; +s8 delta_y; +}; + +/** +* @single_tap - a single tap was recognized. +* @tap_and_hold - a tap-and-hold gesture was recognized. +* @double_tap - a double tap gesture was recognized. +* @early_tap - a tap gesture might be happening. +* @flick - a flick gesture was detected. +* @press - a press gesture was recognized. +* @pinch - a pinch gesture was detected. +*/ +struct f11_2d_data_8 { +bool single_tap:1 ; +bool tap_and_hold:1 ; +bool double_tap:1 ; +bool early_tap:1 ; +bool flick:1 ; +bool press:1 ; +bool pinch:1 ; +}; + +/** +* @palm_detect - a palm or other large object is in contact with the sensor. +* @rotate - a rotate gesture was detected. +* @shape - a TouchShape has been activated. +* @scrollzone - scrolling data is available. +* @finger_count - number of fingers involved in the reported gesture. +*/ +struct f11_2d_data_9 { +bool palm_detect:1 ; +bool rotate:1 ; +bool shape:1 ; +bool scrollzone:1 ; +u8 finger_count:3 ; +}; + +/** +* @pinch_motion - when a pinch gesture is detected, this is the changein +* distance between the two fingers since this register was last read. +*/ +struct f11_2d_data_10 { +s8 pinch_motion; +}; + +/** +* @x_flick_dist - when a flick gesture is detected, the distance of flick +* gesture in X direction. +* @y_flick_dist - when a flick gesture is detected, the distance of flick +* gesture in Y direction. +* @flick_time - the total time of the flick gesture, in 10ms units. +*/ +struct f11_2d_data_10_12 { +s8 x_flick_dist; +s8 y_flick_dist; +u8 flick_time; +}; + +/** +* @motion - when a rotate gesture is detected, the accumulated distance +* of the rotate motion. Clockwise motion is positive and counterclockwise +* motion is negative. +* @finger_separation - when a rotate gesture is detected, the distance +* between the fingers. +*/ +struct f11_2d_data_11_12 { +s8 motion; +u8 finger_separation; +}; + +/** +* @shape_n - a bitmask of the currently activate TouchShapes (if any). +*/ +struct f11_2d_data_13 { +u8 shape_n; +}; + +/** +* @horizontal - chiral scrolling distance in the X direction. +* @vertical - chiral scrolling distance in the Y direction. +*/ +struct f11_2d_data_14_15 { +s8 horizontal; +s8 vertical; +}; + +/** +* @x_low - scroll zone motion along the lower edge of the sensor. +* @y_right - scroll zone motion along the right edge of the sensor. +* @x_upper - scroll zone motion along the upper edge of the sensor. +* @y_left - scroll zone motion along the left edge of the sensor. +*/ +struct f11_2d_data_14_17 { +s8 x_low; +s8 y_right; +s8 x_upper; +s8 y_left; +}; + +struct f11_2d_data { +u8 *f_state; +const struct f11_2d_data_1_5 *abs_pos; +const struct f11_2d_data_6_7 *rel_pos; +const struct f11_2d_data_8 *gest_1; +const struct f11_2d_data_9 *gest_2; +const struct f11_2d_data_10 *pinch; +const struct f11_2d_data_10_12 *flick; +const struct f11_2d_data_11_12 *rotate; +const struct f11_2d_data_13 *shapes; +const struct f11_2d_data_14_15 *multi_scroll; +const struct f11_2d_data_14_17 *scroll_zones; +}; + +struct f11_2d_sensor { +struct rmi_f11_2d_axis_alignment axis_align; +struct f11_2d_sensor_query sens_query; +struct f11_2d_data data; +int prev_x[F11_MAX_NUM_OF_FINGERS ]; +int prev_y[F11_MAX_NUM_OF_FINGERS ]; +u16 max_x; +u16 max_y; +u8 nbr_fingers; +u8 finger_tracker[F11_MAX_NUM_OF_FINGERS ]; +u8 *data_pkt; +int pkt_size; +u8 sensor_index; +u8 *button_map; +struct rmi_f11_virtualbutton_map virtual_buttons; +bool type_a; +char input_name[MAX_NAME_LENGTH ]; +char input_phys[MAX_NAME_LENGTH ]; +struct input_dev *input; +struct input_dev *mouse_input; +struct rmi_function_container *fc; + +#ifdef CONFIG_RMI4_DEBUG +struct dentry *debugfs_flip; +struct dentry *debugfs_clip;
Quoted 8 lines
drivers/input/rmi4/rmi_f11.c line 767
Quoted 6 lines
drivers/input/rmi4/rmi_f11.c +6
-0+struct dentry *debugfs_delta_threshold; +struct dentry *debugfs_offset; +struct dentry *debugfs_swap; +struct dentry *debugfs_type_a; +#endif +};Up to this point in the file, very little is essential to the input deivce.
I really don't understand what you're saying here. If we remove the things corresponding to the data reported by the sensor, how can that data be read and reported to user space (whether by input subsystem or via sysfs)? If we remove the configuration parameters, how should the sensor be configured to operate correctly?
Quoted 26 lines
Quoted 26 lines
drivers/input/rmi4/rmi_f11.c +25
-0+ +struct f11_data { +struct f11_2d_device_query dev_query; +struct f11_2d_ctrl dev_controls; +struct mutex dev_controls_mutex; +u16 rezero_wait_ms; +struct f11_2d_sensor sensors[F11_MAX_NUM_OF_SENSORS ]; + +#ifdef CONFIG_RMI4_DEBUG +struct dentry *debugfs_rezero_wait; +#endif +}; + +enum finger_state_values { +F11_NO_FINGER =0x00 , +F11_PRESENT =0x01 , +F11_INACCURATE =0x02 , +F11_RESERVED =0x03 +}; + +/* ctrl sysfs files */ +show_store_union_struct_prototype(abs_pos_filt) +show_store_union_struct_prototype(z_touch_threshold) +show_store_union_struct_prototype(z_touch_hysteresis) +
Quoted 8 lines
drivers/input/rmi4/rmi_f11.c line 798
Quoted 6 lines
drivers/input/rmi4/rmi_f11.c +6
-0+#ifdef CONFIG_RMI4_DEBUG + +struct sensor_debugfs_data { +bool done; +struct f11_2d_sensor *sensor; +};And this is really needed?
Yes - please see notes on configuration at the top of this email.
Quoted 12 lines
[...]
drivers/input/rmi4/rmi_f11.c line 1371
Quoted 7 lines
drivers/input/rmi4/rmi_f11.c +7
-0+static void rmi_f11_abs_pos_report (struct f11_data *f11, +struct f11_2d_sensor *sensor, +u8 finger_state,u8 n_finger) +{ +struct f11_2d_data *data = &sensor->data; +struct rmi_f11_2d_axis_alignment *axis_align = &sensor->axis_align; +u8 prev_state = sensor->finger_tracker[n_finger];No need to keep track of the old state.
We'll look into that. In previous versions of this code, some of the user space implementations didn't behave correctly if we didn't do that.
However, since that time we've dropped support for older user spaces,
so maybe we don't need that any more.
Quoted 9 lines
drivers/input/rmi4/rmi_f11.c line 1378
Quoted 7 lines
drivers/input/rmi4/rmi_f11.c +7
-0+int x, y, z; +int w_x, w_y, w_max, w_min, orient; +int temp; + +if (prev_state && !finger_state) { +/* this is a release */ + x = y = z = w_max = w_min = orient =0 ;This data is not sent during a release.
OK.
Quoted 5 lines
Quoted 5 lines
drivers/input/rmi4/rmi_f11.c +4
-0+ }else if (!prev_state && !finger_state) { +/* nothing to report */ +return ; + }else {
[snip]
Quoted 8 lines
drivers/input/rmi4/rmi_f11.c line 1425
Quoted 6 lines
drivers/input/rmi4/rmi_f11.c +6
-0+ x =max (axis_align->clip_X_low, x); + y =max (axis_align->clip_Y_low, y); +if (axis_align->clip_X_high) + x =min (axis_align->clip_X_high, x); +if (axis_align->clip_Y_high) + y =min (axis_align->clip_Y_high, y);Why is the clipping configurable?
Because during prototyping of new products, engineers sometimes use a sensor that is bigger than the display and not necessarily aligned to the origin. This is frequent enough a use case that we include it in the driver as a convenience feature in debugfs.
Quoted 12 lines
drivers/input/rmi4/rmi_f11.c line 1434
Quoted 10 lines
drivers/input/rmi4/rmi_f11.c +9
-0+ + } + +/* Some UIs ignore W of zero, so we fudge it to 1 for pens. */ +if (IS_ENABLED (CONFIG_RMI4_F11_PEN ) && +get_tool_type (sensor, finger_state) ==MT_TOOL_PEN ) { + w_max =max (1 , w_max); + w_min =max (1 , w_min); + }Is this not true for all tool types?
In our experience, no. It ought to be true in an ideal world, but unfortunately we aren't living in one :-(.
Quoted 4 lines
Quoted 4 lines
drivers/input/rmi4/rmi_f11.c +4
-0+ +if (sensor->type_a) { +input_report_abs (sensor->input,ABS_MT_TRACKING_ID , n_finger); + input_report_abs(sensor->input, ABS_MT_TOOL_TYPE,
Quoted 8 lines
drivers/input/rmi4/rmi_f11.c line 1444
Quoted 6 lines
drivers/input/rmi4/rmi_f11.c +6
-0+ get_tool_type(sensor, finger_state)); + }else { +input_mt_slot (sensor->input, n_finger); +input_mt_report_slot_state (sensor->input, +get_tool_type (sensor, finger_state), finger_state); + }The driver should only report MT-B, please.
Is that valid even if we have a type A sensor?
Quoted 8 lines
drivers/input/rmi4/rmi_f11.c line 1451
Quoted 6 lines
drivers/input/rmi4/rmi_f11.c +6
-0+input_report_abs (sensor->input,ABS_MT_PRESSURE , z); +input_report_abs (sensor->input,ABS_MT_TOUCH_MAJOR , w_max); +input_report_abs (sensor->input,ABS_MT_TOUCH_MINOR , w_min); +input_report_abs (sensor->input,ABS_MT_ORIENTATION , orient); +input_report_abs (sensor->input,ABS_MT_POSITION_X , x); +input_report_abs (sensor->input,ABS_MT_POSITION_Y , y);Only if
finger_stateis true.
OK.
Quoted 36 lines
Quoted 36 lines
drivers/input/rmi4/rmi_f11.c +35
-0+dev_dbg (&sensor->fc->dev, +"finger[%d]:%d - x:%d y:%d z:%d w_max:%d w_min:%d\n" , + n_finger, finger_state, x, y, z, w_max, w_min); +/* MT sync between fingers */ +if (sensor->type_a) +input_mt_sync (sensor->input); + + sensor->finger_tracker[n_finger] = finger_state; +} + +#ifdef CONFIG_RMI4_VIRTUAL_BUTTON +static int rmi_f11_virtual_button_handler (struct f11_2d_sensor *sensor) +{ +int i; +int x; +int y; +struct rmi_button_map *virtualbutton_map; + +if (sensor->sens_query.has_gestures && + sensor->data.gest_1->single_tap) { + virtualbutton_map = &sensor->virtualbutton_map; + x = ((sensor->data.abs_pos[0 ].x_msb <<4 ) | + sensor->data.abs_pos[0 ].x_lsb); + y = ((sensor->data.abs_pos[0 ].y_msb <<4 ) | + sensor->data.abs_pos[0 ].y_lsb); +for (i =0 ; i < virtualbutton_map->buttons; i++) { +if (INBOX (x, y, virtualbutton_map->map[i])) { +input_report_key (sensor->input, + virtualbutton_map->map[i].code,1 ); +input_report_key (sensor->input, + virtualbutton_map->map[i].code,0 ); +input_sync (sensor->input); +return 0 ; + } + }
Quoted 8 lines
drivers/input/rmi4/rmi_f11.c line 1492
Quoted 6 lines
drivers/input/rmi4/rmi_f11.c +6
-0+ } +return 0 ; +} +#else +#define rmi_f11_virtual_button_handler (sensor) +#endif No virtual buttons, please, this can easily be mapped in userspace.
Not for all user spaces. But we can remove this from the next submission.
Quoted 23 lines
Quoted 23 lines
drivers/input/rmi4/rmi_f11.c +22
-0+static void rmi_f11_finger_handler (struct f11_data *f11, +struct f11_2d_sensor *sensor) +{ +const u8 *f_state = sensor->data.f_state; +u8 finger_state; +u8 finger_pressed_count; +u8 i; + +for (i =0 , finger_pressed_count =0 ; i < sensor->nbr_fingers; i++) { +/* Possible of having 4 fingers per f_statet register */ + finger_state =GET_FINGER_STATE (f_state, i); + +if (finger_state ==F11_RESERVED ) { +pr_err ("%s: Invalid finger state[%d]:0x%02x." , __func__, + i, finger_state); +continue ; + }else if ((finger_state ==F11_PRESENT ) || + (finger_state ==F11_INACCURATE )) { + finger_pressed_count++; + } + +if (sensor->data.abs_pos)
Quoted 8 lines
drivers/input/rmi4/rmi_f11.c line 1520
Quoted 6 lines
drivers/input/rmi4/rmi_f11.c +6
-0+rmi_f11_abs_pos_report (f11, sensor, finger_state, i); + +if (sensor->data.rel_pos) +rmi_f11_rel_pos_report (sensor, i); + } +input_report_key (sensor->input,BTN_TOUCH , finger_pressed_count);Please use
input_mt_sync_frame()here instead.
OK
Quoted 5 lines
drivers/input/rmi4/rmi_f11.c
Quoted 3 lines
drivers/input/rmi4/rmi_f11.c +2
-0+input_sync (sensor->input); +}Stopping here.
--
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