input/touchscreen: Synaptics Touchscreen Driver
Subsystems (2)
cover input/touchscreen: Synaptics Touchscreen Driver
This patch adds an initial driver supporting Synaptics ClearPad touchscreens that use the RMI4 protocol, as defined here:
http://www.synaptics.com/sites/default/files/511-000136-01_revA.pdf
This patch addresses most of the feedback relating to our previous submission. Any elements not acted on (such as creation of an 'rmi' bus on the kernel bus architecture) are captured as TODOs in the code, and will be implemented in a future submission. In addition:
- We think we've resolved all the whitespace issues. For Kconfig, we used the indent pattern used by other modules. For all other sources, we've converted to 8-space hard TAB characters.
- Some concerns were expressed regarding our I2C implementation. Dmitry recommended we contact Jean Delvare for further review, so we are cc'ing him on this patch.
This version of the driver does not support all features of the RMI4 protocol yet. We felt it more important to start with a solid implementation of the basic functionality, and then build on that base to support additional features (such as gestures, proximity detection, capacitive buttons, and so on).
Additionally, as this is our team's first venture into the wonderful world of kernel submissions, we figured it was important to start out initially with a fairly simple codebase, just in case we're doing something horribly wrong.
The significant files in this version of the driver are:
rmi_core.c
Implements the basic core of the RMI4 protocol including self-discovery of RMI4 functions. This also implements RMI4 function 0x01, which provides generic device control.
rmi_function_11.c
Implements basic RMI4 function 0x11 (2D sensor) features, including multitouch up to 10 fingers.
rmi_app_touchpad.c
The major driver functions (mod_init, mod_exit,
and so on).
An additional file is included, but will eventually be changed/dropped
rmi_i2c_gta01.c
Provides platform setup for development. This will be replaced in the future by a generic approach to specifying platform parameters.
More detailed descriptions can be found in each file's comments.
We chose to use multiple source files because it makes it easy to add support for additional RMI4 functions with minimal impact to existing functions. Additionally, this supports future changes to the configuration to allow you to compile in only those RMI4 functions that you need for your particular device.
There are two existing drivers for similar Synaptics devices in the current kernel tree (excluding the PS/2 touchpad driver). These are:
./linux-2.6/drivers/input/mouse/synaptics_i2c.c
A driver for the Exeda 15mm touchpad, written by Mike Rapoport <[email protected]> and Igor Grinberg <[email protected]>
./linux-2.6/drivers/staging/dream/synaptics_i2c_rmi.c
A driver for the HTC Dream ClearPad, written by Arve Hjønnevåg <[email protected]>
We have not extended these drivers for a couple of reasons. First, the two drivers are specific to particular Synaptics products, and it is our desire to produce a general solution that takes advantage of the 'self describing' features of products that use the RMI protocol.
Second, and more importantly, is that the existing drivers are written for an older version of the RMI protocol (aka RMI3) that is being retired in favor of a more recent and substantially changed version (aka RMI4). Most currently shipping Synaptics ClearPads speak the RMI4 protocol, and it will be Synaptics protocol of choice going forward. In almost all respects, RMI4 is not backward compatible with RMI3, making it impractical to support both versions in the same driver.
Comments and other feedback on this driver are welcomed.
Bill Manson
Allie Xiong
Christopher Heiny
---
RFC PATCH 1/1 input/touchscreen: Synaptics Touchscreen Driver
Initial driver for Synaptics touchscreens using RMI4 protocol.
---
drivers/input/touchscreen/Kconfig | 13 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/rmi.h | 196 ++++++++ drivers/input/touchscreen/rmi_app_touchpad.c | 355 +++++++++++++++ drivers/input/touchscreen/rmi_core.c | 632 ++++++++++++++++++++++++++ drivers/input/touchscreen/rmi_core.h | 57 +++ drivers/input/touchscreen/rmi_function_11.c | 352 ++++++++++++++ drivers/input/touchscreen/rmi_function_11.h | 39 ++ drivers/input/touchscreen/rmi_functions.h | 109 +++++ drivers/input/touchscreen/rmi_i2c.h | 54 +++ drivers/input/touchscreen/rmi_i2c_gta01.c | 122 +++++ drivers/input/touchscreen/rmi_phys_i2c.c | 545 ++++++++++++++++++++++ 12 files changed, 2475 insertions(+), 0 deletions(-)
drivers/input/touchscreen/Kconfig +13 -0
@@ -307,6 +307,19 @@ config TOUCHSCREEN_MIGOR To compile this driver as a module, choose M here: the module will be called migor_ts. +config TOUCHSCREEN_SYNAPTICS_RMI4_I2C + tristate "Synaptics RMI4 I2C touchscreens" + depends on I2C + help + Say Y here if you have a Synaptics RMI4 I2C touchscreen connected to + your system. This enables support for Synaptics RMI4 over I2C based + touchscreens. + + If unsure, say N. + + To compile this driver as a set of modules, choose M here: the + modules will be called rmi, rmi_app_touchpad, rmi_phys_i2c. + config TOUCHSCREEN_TOUCHRIGHT tristate "Touchright serial touchscreen" select SERIO
drivers/input/touchscreen/Makefile +1 -0
@@ -31,6 +31,7 @@ obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE) += usbtouchscreen.o obj-$(CONFIG_TOUCHSCREEN_PCAP) += pcap_ts.o obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o +obj-$(CONFIG_TOUCHSCREEN_SYNAPTICS_RMI4_I2C) += rmi_core.o rmi_app_touchpad.o rmi_function_11.o rmi_phys_i2c.o rmi_i2c_gta01.o obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o
drivers/input/touchscreen/rmi.h new file +196 -0
196 lines not on this page · raw message
drivers/input/touchscreen/rmi_app_touchpad.c new file +355 -0
355 lines not on this page · raw message
drivers/input/touchscreen/rmi_core.c new file +632 -0
632 lines not on this page · raw message
drivers/input/touchscreen/rmi_core.h new file +57 -0
57 lines not on this page · raw message
drivers/input/touchscreen/rmi_function_11.c new file +352 -0
352 lines not on this page · raw message
drivers/input/touchscreen/rmi_function_11.h new file +39 -0
@@ -0,0 +1,39 @@ +/** +* +* Synaptics Register Mapped Interface (RMI4) Function $11 support for 2D. +* Copyright (c) 2009 Synaptics Incorporated +* +* For every RMI4 function that has a data source - like 2D sensors, buttons, LEDs, +* GPIOs, etc. - the user will create a new rmi_function_xx.c file and add these +* functions to perform the config(), init(), report() and detect() functionality. +* The function pointers are then stored under the RMI function info and these +* functions will automatically be called by the global config(), init(), report() +* and detect() functions that will loop through all data sources and call the +* data sources functions using these functions pointed to by the function ptrs. +*/ +/* +* This file is licensed under the GPL2 license. +* +*############################################################################# +* GPL +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published +* by the Free Software Foundation. +* +* 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. +* +*############################################################################# +*/ +#ifndef _RMI_FUNCTION_11_H +#define _RMI_FUNCTION_11_H + +int FN_11_report (struct rmi_application *app,struct rmi_function_info *rfi,struct input_dev *input); +int FN_11_config (struct rmi_application *app,struct rmi_function_info *rfi); +int FN_11_init (struct input_dev *input); +int FN_11_detect (struct rmi_application *app,struct rmi_function_info *rfi,struct rmi_function_descriptor *fd,unsigned int interruptCount); + +#endif
drivers/input/touchscreen/rmi_functions.h new file +109 -0
109 lines not on this page · raw message
drivers/input/touchscreen/rmi_i2c.h new file +54 -0
54 lines not on this page · raw message
drivers/input/touchscreen/rmi_i2c_gta01.c new file +122 -0
122 lines not on this page · raw message
drivers/input/touchscreen/rmi_phys_i2c.c new file +545 -0
545 lines not on this page · raw message
Hi Christopher,
Sorry for the delay. Here finally come my comments on your code. I'm only commenting on the i2c side of things.
Quoted 51 lines · Christopher Heiny
Initial driver for Synaptics touchscreens using RMI4 protocol.
Signed-off-by William Manson <[email protected]>Signed-off-by Allie Xiong <[email protected]>Signed-off-by Christopher Heiny <[email protected]>---
drivers/input/touchscreen/Kconfig | 13 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/rmi.h | 196 ++++++++ drivers/input/touchscreen/rmi_app_touchpad.c | 355 +++++++++++++++ drivers/input/touchscreen/rmi_core.c | 632 ++++++++++++++++++++++++++ drivers/input/touchscreen/rmi_core.h | 57 +++ drivers/input/touchscreen/rmi_function_11.c | 352 ++++++++++++++ drivers/input/touchscreen/rmi_function_11.h | 39 ++ drivers/input/touchscreen/rmi_functions.h | 109 +++++ drivers/input/touchscreen/rmi_i2c.h | 54 +++ drivers/input/touchscreen/rmi_i2c_gta01.c | 122 +++++ drivers/input/touchscreen/rmi_phys_i2c.c | 545 ++++++++++++++++++++++ 12 files changed, 2475 insertions(+), 0 deletions(-)(...)
drivers/input/touchscreen/rmi_i2c.h new file +23
-0@@ -0,0 +1,54 @@ +/** +* +* Synaptics RMI over I2C Physical Layer Driver Header File. +* Copyright (c) 2007-2009 Synaptics Incorporated +* +*/ +/* +* This file is licensed under the GPL2 license. +* +*############################################################################# +* GPL +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published +* by the Free Software Foundation. +* +* 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. +* +*############################################################################# +*/
drivers/input/touchscreen/rmi_i2c.h line 33
Quoted 10 lines
drivers/input/touchscreen/rmi_i2c.h new file +10
-0+ +#ifndef _RMI_I2C_H +#define _RMI_I2C_H + +/* Platform-specific configuration data. +* This structure is used by the platform-specific driver to designate +* specific information about the hardware. A platform client may supply +* an array of these to the rmi_phys_i2c driver. +*/ +struct rmi_i2c_clientdata {
This name is unfortunate. "client data" usually refers to run-time state data of an i2c client. For configuration data, we rather use the terms "platform data" or "setup data".
drivers/input/touchscreen/rmi_i2c.h line 35
Quoted 2 lines
drivers/input/touchscreen/rmi_i2c.h new file +2
-0+/* The seven-bit i2c address of the device. */ +int i2c_address;
This is already included in the i2c client struct itself, so you shouldn't have to carry it.
Quoted 53 lines
drivers/input/touchscreen/rmi_i2c.h new file +19
-0+/* The number of the irq. Set to zero if polling is required. */ +int irq; +/* The type of the irq (e.g., IRQF_TRIGGER_FALLING).Only valid if irq != 0 */ +int irq_type; +/* Function used to query the state of the attention line. It always +* returns 1 for "active" regardless of the polarity of the attention line. +*/ + int (*get_attention)(void); +}; + +/* Descriptor structure. +* Describes the number of i2c devices on the bus that speak RMI. +*/ +struct rmi_i2c_data { +int num_clients; +struct rmi_i2c_clientdata *clientdata; +}; + +#endif drivers/input/touchscreen/rmi_phys_i2c.c new file +27
-0@@ -0,0 +1,545 @@ +/** +* +* Synaptics Register Mapped Interface (RMI4) I2C Physical Layer Driver. +* Copyright (c) 2007-2009, Synaptics Incorporated +* +*/ +/* +* This file is licensed under the GPL2 license. +* +*############################################################################# +* GPL +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published +* by the Free Software Foundation. +* +* 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. +* +*############################################################################# +*/ + +#include <linux/module.h> +#include <linux/i2c.h> +#include <linux/platform_device.h>
drivers/input/touchscreen/rmi_phys_i2c.c line 37
Quoted 10 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +10
-0+#include <linux/interrupt.h> +#include <linux/delay.h> +#include "rmi_i2c.h" +#include "rmi.h" + +#define DRIVER_NAME "rmi4_i2c" + +/* Used to lock access to the page address. +*/ +static DEFINE_MUTEX (page_mutex);
It would seem better, performance-wise, to make this a per-device mutex.
drivers/input/touchscreen/rmi_phys_i2c.c line 41
Quoted 4 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +4
-0+ + +static const struct i2c_device_id rmi_i2c_id_table[] = { + {DRIVER_NAME ,0 },
This is incorrect. What goes in device ID tables is _device_ names, nor _driver_ names. It might be the same string, but you don't want to use the driver symbol.
Quoted 5 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +5
-0+ { }, +}; +MODULE_DEVICE_TABLE (i2c, rmi_i2c_id_table); + +
drivers/input/touchscreen/rmi_phys_i2c.c line 56
Quoted 10 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +10
-0+/* +* This is the data kept on a per instance (client) basis. This data is +* always accessible by using the container_of() macro of the various elements +* inside. +*/ +struct instance_data { +int instance_no; +int irq; +struct rmi_phys_driver rpd; +struct i2c_client i2cclient;
You don't need a copy of the i2c client in your own structure. It is allocated by the i2c core, if you need a reference to it, then just store a pointer thereto.
This is the only blocker point in your driver as far as I am concerned. All my other comments are minor things.
Quoted 20 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +20
-0+int page; +int (*get_attention)(void ); +}; + +/* +* 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. This function sets the page. +* +* The page_mutex lock must be held when this function is entered. +* +* param[in] id TBD +* param[in] page The new page address. +* returns zero on success, non-zero on failure. +*/ +int +rmi_set_page (struct instance_data *id,unsigned int page) +{ +char txbuf[2 ];
drivers/input/touchscreen/rmi_phys_i2c.c line 86
Quoted 10 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +10
-0+int retval; + txbuf[0 ] =0xff ; + txbuf[1 ] = page; + retval =i2c_master_send (&id->i2cclient, txbuf,2 ); +if (retval !=2 ) { +printk (KERN_ERR "rmi_i2c: Set page fail: %d\n" , retval); + }else { + retval =0 ; + id->page = page; + }
This works, but I would encourage you to use i2c_smbus_write_byte_data instead, as it is more portable.
Quoted 30 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +30
-0+return retval; +} + +/* +* Read a single register through i2c. +* +* param[in] pd TBD +* param[in] address The address at which to start the data read. +* param[out] valp Pointer to the buffer where the data will be stored. +* returns xero upon success (with the byte read in valp), non-zero upon error. +*/ +static int +rmi_i2c_read (struct rmi_phys_driver *pd,unsigned short address,char *valp) +{ + struct instance_data *id = container_of(pd, struct instance_data, rpd); +char txbuf[2 ]; +int retval =0 ; +int retry_count =0 ; + +/* Can't have anyone else changing the page behind our backs */ +mutex_lock (&page_mutex); + +if (((address >>8 ) &0xff ) != id->page) { +/* Switch pages */ + retval =rmi_set_page (id, ((address >>8 ) &0xff )); +if (retval) { + goto exit; + } + } +
drivers/input/touchscreen/rmi_phys_i2c.c line 126
Quoted 10 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +10
-0+retry: + txbuf[0 ] = address &0xff ; + retval =i2c_master_send (&id->i2cclient, txbuf,1 ); + +if (retval !=1 ) { +printk (KERN_ERR "rmi_i2c.rmi_i2c_read: Write fail: %d\n" , + retval); + goto exit; + } + retval =i2c_master_recv (&id->i2cclient, txbuf,1 );
Using i2c_smbus_read_byte_data() would look better, be more portable, faster and more robust, if your device supports I2C repeated-start.
Quoted 50 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +50
-0+ +if (retval !=1 ) { +if (++retry_count ==5 ) { +printk (KERN_ERR "rmi_i2c.rmi_i2c_read: " +"Read of 0x%04x fail: %d\n" , address, retval); + }else { +mdelay (10 ); +rmi_set_page (id, ((address >>8 ) &0xff )); + goto retry; + } + }else { + retval =0 ; + *valp = txbuf[0 ]; + } +exit: +mutex_unlock (&page_mutex); +return retval; +} + +/* +* Same as rmi_i2c_read, except that multiple bytes are allowed to be read. +* +* param[in] pd TBD +* param[in] address The address at which to start the data read. +* param[out] valp Pointer to the buffer where the data will be stored. This +* buffer must be at least size bytes long. +* param[in] size The number of bytes to be read. +* returns zero upon success (with the byte read in valp), non-zero upon error. +* +*/ +static int +rmi_i2c_read_multiple (struct rmi_phys_driver *pd,unsigned short address, +char *valp,int size) +{ + struct instance_data *id = container_of(pd, struct instance_data, rpd); +char txbuf[2 ]; +int retval =0 ; +int retry_count =0 ; + +/* Can't have anyone else changing the page behind our backs */ +mutex_lock (&page_mutex); + +if (((address >>8 ) &0xff ) != id->page) { +/* Switch pages */ + retval =rmi_set_page (id, ((address >>8 ) &0xff )); +if (retval) { + goto exit; + } + } +
drivers/input/touchscreen/rmi_phys_i2c.c line 186
Quoted 10 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +10
-0+retry: + txbuf[0 ] = address &0xff ; + retval =i2c_master_send (&id->i2cclient, txbuf,1 ); + +if (retval !=1 ) { +printk (KERN_ERR "rmi_i2c.rmi_i2c_read: Write fail: %d\n" , + retval); + goto exit; + } + retval =i2c_master_recv (&id->i2cclient, valp, size);
Likewise, i2c_smbus_read_i2c_block_data() would be better, if you never need to read more than 32 bytes at once. If you need to, then i2c_transfer() would still be better than i2c_master_send + i2c_master_recv, as you avoid the downtime between the 2 messages on the bus.
Quoted 42 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +42
-0+ +if (retval != size) { +if (++retry_count ==5 ) { +printk (KERN_ERR "rmi_2ic.rmi_i2c_read_multiple: " +"Read of 0x%04x size %d fail: %d\n" , + address, size, retval); + }else { +mdelay (10 ); +rmi_set_page (id, ((address >>8 ) &0xff )); + goto retry; + } + }else { + retval =0 ; + } +exit: +mutex_unlock (&page_mutex); +return retval; +} + + +/* +* Write a single register through i2c. +* You can write multiple registers at once, but I made the functions for that +* seperate for performance reasons. Writing multiple requires allocation and +* freeing. +* +* param[in] pd TBD +* param[in] address The address at which to start the write. +* param[in] data The data to be written. +* returns one upon success, something else upon error. +*/ +static int +rmi_i2c_write (struct rmi_phys_driver *pd,unsigned short address,char data) +{ + struct instance_data *id = container_of(pd, struct instance_data, rpd); +unsigned char txbuf[2 ]; +int retval =0 ; + +/* Can't have anyone else changing the page behind our backs */ +mutex_lock (&page_mutex); + +if (((address >>8 ) &0xff ) != id->page) {
drivers/input/touchscreen/rmi_phys_i2c.c line 238
Quoted 10 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +10
-0+/* Switch pages */ + retval =rmi_set_page (id, ((address >>8 ) &0xff )); +if (retval) { + goto exit; + } + } + + txbuf[0 ] = address &0xff ; + txbuf[1 ] = data; + retval =i2c_master_send (&id->i2cclient, txbuf,2 );
Could be implemented using i2c_smbus_write_data_byte().
Quoted 20 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +20
-0+ +if (retval !=2 ) { +printk (KERN_ERR "rmi_i2c.rmi_i2c_write: Write fail: %d\n" , + retval); + goto exit;/* Leave this in case we add code below */ + } +exit: +mutex_unlock (&page_mutex); +return retval; +} + +/* +* Write multiple registers. +* +* param[in] pd TBD +* param[in] address The address at which to start the write. +* param[in] valp A pointer to a buffer containing the data to be written. +* param[in] size The number of bytes to write. +* returns one upon success, something else upon error. +*/
drivers/input/touchscreen/rmi_phys_i2c.c line 268
Quoted 10 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +10
-0+static int +rmi_i2c_write_multiple (struct rmi_phys_driver *pd,unsigned short address, +char *valp,int size) +{ + struct instance_data *id = container_of(pd, struct instance_data, rpd); +unsigned char *txbuf; +unsigned char txbuf_most[16 ]; +int retval =0 ; + +if (size <15 ) {
Whould be <= 15, if I'm not mistaken. Using <= sizeof(txbuf_most) + 1 would be better.
drivers/input/touchscreen/rmi_phys_i2c.c line 277
Quoted 9 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +9
-0+/* Avoid an allocation if we can help it. */ + txbuf = txbuf_most; + }else { + txbuf =kmalloc (size +1 ,GFP_KERNEL ); +if (!txbuf) +return -ENOMEM ; + } + +/* Yes, it stinks here that we have to copy the buffer */
If you were using i2c_smbus_write_i2c_block_data(), you wouldn't have to. Unless you must write more than 32 bytes sometimes? In that case, it's indeed not an option.
drivers/input/touchscreen/rmi_phys_i2c.c line 283
Quoted 6 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +6
-0+ { +int i; +for (i =0 ; i < size; i++) { + txbuf[i +1 ] = valp[i]; + } + }
If you keep that code, please just define "i" earlier in your function to save the extra indentation, it's bad coding practice.
Quoted 7 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +7
-0+ +/* Can't have anyone else changing the page behind our backs */ +mutex_lock (&page_mutex); + +if (((address >>8 ) &0xff ) != id->page) { +/* Switch pages */ + retval =rmi_set_page (id, ((address >>8 ) &0xff ));
drivers/input/touchscreen/rmi_phys_i2c.c line 300
Quoted 10 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +10
-0+if (retval) { + goto exit; + } + } + + txbuf[0 ] = address &0xff ; + retval =i2c_master_send (&id->i2cclient, txbuf, size +1 ); + +if (retval !=1 ) { +printk (KERN_ERR "rmi_i2c.rmi_i2c_read: Write fail: %d\n" , retval);
That's what you get when hard-coding function names in log messages ;) You'd rather use %s and __func__, so you don't get it wrong.
drivers/input/touchscreen/rmi_phys_i2c.c line 308
Quoted 8 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +8
-0+ goto exit; + } +exit: +mutex_unlock (&page_mutex); +if (txbuf != txbuf_most) +kfree (txbuf); +return retval; +}
I am curious why your read functions have a retry mechanism and your write functions do not?
Quoted 8 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +8
-0+ +/* +* Get the state of the attention line. +* This function returns 1 for an active attention regardless of the +* polarity of the ATTN signal. If the get_attention function of the instance +* is not available (probably because ATTN is not implemented), then it always +* returns inactive. +*/
drivers/input/touchscreen/rmi_phys_i2c.c line 326
Quoted 10 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +10
-0+static int +rmi_i2c_get_attention (struct rmi_phys_driver *rpd) +{ + struct instance_data *id = container_of(rpd, struct instance_data, rpd); +if (id->get_attention) { +return id->get_attention (); + }else { +return 0 ;/* return inactive */ + } +}
This function has nothing i2c-specific, so I'm curious why it is there.
Quoted 9 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +9
-0+ +/* +* This is the Interrupt Service Routine. It just notifies the application +* layer that attention is required. +*/ +static irqreturn_t +i2c_attn_isr (int irq,void *info) +{ +struct instance_data *id = info;
drivers/input/touchscreen/rmi_phys_i2c.c line 345
Quoted 10 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +10
-0+disable_irq (id->irq); +if (id->rpd.attention) { + id->rpd.attention (&id->rpd, id->instance_no); + } +return IRQ_HANDLED ; +} + +/* +* The Driver probe function - will allocate and initialize the instance data and +* request the irq and set the instance data as the clients clientdta then
Typo: clientdata.
drivers/input/touchscreen/rmi_phys_i2c.c line 356
Quoted 11 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +11
-0+* register the physical driver which will do a scan of the RMI4 Physical Device Table +* and enumerate any RMI4 functions that have data sources associated with them. +* +*/ +static int +rmi_i2c_probe (struct i2c_client *client,const struct i2c_device_id *dev_id) +{ +struct instance_data *id; +int retval =0 ; +int i; +int numclients =0 ;
Useless initialization.
drivers/input/touchscreen/rmi_phys_i2c.c line 363
Quoted 7 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +7
-0+struct rmi_i2c_data *rmii2cdata; +struct rmi_i2c_clientdata *clientdata; + +pr_debug ("Probing i2c RMI device\n" ); + +/* Allocate and initialize the instance data for this client */ + id =kzalloc (sizeof (*id) *2 ,GFP_KERNEL );
Why * 2?
Quoted 5 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +5
-0+if (!id) { +printk (KERN_ERR "rmi_i2c_probe: Out of memory trying to allocate instance_data.\n" ); +return -ENOMEM ; + } +
drivers/input/touchscreen/rmi_phys_i2c.c line 378
Quoted 10 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +10
-0+ id->rpd.name =DRIVER_NAME ; + id->rpd.write = rmi_i2c_write; + id->rpd.read = rmi_i2c_read; + id->rpd.write_multiple = rmi_i2c_write_multiple; + id->rpd.read_multiple = rmi_i2c_read_multiple; + id->rpd.get_attention = rmi_i2c_get_attention; + id->rpd.module =THIS_MODULE ; + id->page =0xffff ;/* So we set the page correctly the first time */ + + rmii2cdata = ((struct rmi_i2c_data *)(client->dev.platform_data));
platform_data is void* so no cast is needed.
drivers/input/touchscreen/rmi_phys_i2c.c line 380
Quoted 2 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +2
-0+ numclients = rmii2cdata->num_clients; +/* Loop through the client data and locate the one that was found */
Now I am confused. Instead of attaching the proper platform data to each I2C device, you have a single object with all the platform data for all devices in it, and you pass that big object as the platform data of all devices, and they have to find out which part is meant for them? This is odd. What's the point of doing that? Why don't you just set the platform data pointer to the right subset of data for every device?
Quoted 39 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +39
-0+for (i =0 ; i < numclients; i++) { + clientdata = &(rmii2cdata->clientdata[i]); +if (client->addr == clientdata->i2c_address) { + id->instance_no = i; + id->get_attention = clientdata->get_attention; + +/* +* Determine if we need to poll (inefficient) or use interrupts. +*/ +if (clientdata->irq) { +int irqtype; + + id->irq = clientdata->irq; +switch (clientdata->irq_type) { +case IORESOURCE_IRQ_HIGHEDGE : + irqtype =IRQF_TRIGGER_RISING ; +break ; +case IORESOURCE_IRQ_LOWEDGE : + irqtype =IRQF_TRIGGER_FALLING ; +break ; +case IORESOURCE_IRQ_HIGHLEVEL : + irqtype =IRQF_TRIGGER_HIGH ; +break ; +case IORESOURCE_IRQ_LOWLEVEL : + irqtype =IRQF_TRIGGER_LOW ; +break ; +default : +printk (KERN_WARNING "rmi_i2c_probe: Invalid IRQ flags in " +"platform data\n" ); +kfree (id); +return -ENXIO ; + } + + retval =request_irq (id->irq, i2c_attn_isr, irqtype,"rmi_i2c" , id); +if (retval) { +printk (KERN_WARNING "rmi_i2c_probe: Unable to get attn " +"irq %d. Reverting to polling.\n" , id->irq); + id->rpd.polling_required = true; + }else {
drivers/input/touchscreen/rmi_phys_i2c.c line 429
Quoted 10 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +10
-0+pr_debug ("rmi_i2c_probe: got irq\n" ); + id->rpd.polling_required = false; + } + }else { + id->rpd.polling_required = true; +printk (KERN_INFO "rmi_i2c_probe: No IRQ info given. " +"Polling required.\n" ); + } + } + }
What if no matching device has been found at this point? You shouldn't continue.
Quoted 5 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +5
-0+ +/* Store the instance data in the i2c_client - we need to do this prior to calling +* register_physical_driver since it may use the read, write finctions. +*/ +i2c_set_clientdata (client, id);
drivers/input/touchscreen/rmi_phys_i2c.c line 444
Quoted 10 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +10
-0+ +/* Register physical driver - this will call the detect function that will then +* scan the device and determine the supported RMI4 functions. +*/ + retval =rmi_register_phys_driver (&id->rpd); +if (retval) { +printk (KERN_ERR "rmi_i2c_probe : Failed to Register %s phys driver\n" , id->rpd.name); +i2c_set_clientdata (client,NULL ); +if (id->irq) { +free_irq (id->irq, id);
If id->irq is set but you failed to request the irq (request_irq() failed), you're freeing an irq you never got. Not good. You should only set id->irq after you successfully requested the irq.
Quoted 10 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +10
-0+ } +kfree (id); +return retval; + } + +pr_debug ("rmi_i2c_probe : Successfully Registered %s phys driver\n" , id->rpd.name); + +return retval; +} +
drivers/input/touchscreen/rmi_phys_i2c.c line 464
Quoted 10 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +10
-0+/* +* The Driver remove function. We tear down the instance data and unregister the phys driver +* in this call. +*/ +static int +rmi_i2c_remove (struct i2c_client *client) +{ +struct instance_data *id =i2c_get_clientdata (client); + +pr_debug ("Unregistering phys driver %s\n" , id->rpd.name);
Please use dev_dbg(&client->dev, ...) instead, everywhere. This makes it much easier to find out who is sending the message. Same for all the rest of your code, BTW: dev_warn() is preferred pr_warning(), etc.
drivers/input/touchscreen/rmi_phys_i2c.c line 471
Quoted 7 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +7
-0+ +rmi_unregister_phys_driver (&id->rpd); + +pr_debug ("Unregistered phys driver %s\n" , id->rpd.name); + +if (id->irq) { +free_irq (id->irq, id);
Same problem here.
Quoted 44 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +44
-0+ } + +kfree (id); +pr_debug ("remove successful\n" ); + +return 0 ; +} + +#ifdef CONFIG_PM +static int +rmi_i2c_suspend (struct i2c_client *client,pm_message_t mesg) +{ +/* Touch sleep mode */ +return 0 ; +} + +static int +rmi_i2c_resume (struct i2c_client *client) +{ +/* Re-initialize upon resume */ +return 0 ; +} +#else +#define rmi_i2c_suspend NULL +#define rmi_i2c_resume NULL +#endif + +/* +* This structure tells the i2c subsystem about us. +* +* TODO: we should add .suspend and .resume fns. +* +*/ +static struct i2c_driver rmi_i2c_driver = { + .probe = rmi_i2c_probe, + .remove = rmi_i2c_remove, + .suspend = rmi_i2c_suspend, + .resume = rmi_i2c_resume, + .driver = { + .name =DRIVER_NAME , + .owner =THIS_MODULE , + }, + .id_table = rmi_i2c_id_table, +};
drivers/input/touchscreen/rmi_phys_i2c.c line 525
Quoted 10 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +10
-0+ +/* +* Register ourselves with i2c Chip Driver. +* +*/ +static int __init rmi_phys_i2c_init (void ) +{ +if (RMI_ALLOC_STATS ) { +pr_debug ("Allocation Stats Enabled\n" ); + }
I'd much prefer:
#if RMI_ALLOC_STATS
pr_debug("Allocation Stats Enabled\n");#endif
for consistency with the rest of the use cases. I'm also unsure why you print this here rather than in rmi_core_init(), given that this is nothing i2c-specific.
Quoted 10 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +10
-0+ +return i2c_add_driver (&rmi_i2c_driver); +} + +/* +* Un-register ourselves from the i2c Chip Driver. +* +*/ +static void __exit rmi_phys_i2c_exit(void) +{
drivers/input/touchscreen/rmi_phys_i2c.c line 545
Quoted 10 lines
drivers/input/touchscreen/rmi_phys_i2c.c new file +10
-0+i2c_del_driver (&rmi_i2c_driver); +} + + +module_init (rmi_phys_i2c_init); +module_exit (rmi_phys_i2c_exit); + +MODULE_AUTHOR ("Synaptics, Inc." ); +MODULE_DESCRIPTION ("RMI4 Driver I2C Physical Layer" ); +MODULE_LICENSE ("GPL" );
This is it. Hope it was helpful.
Signature · 2 lines
Jean Delvare http://khali.linux-fr.org/wishlist.html
Quoted 2 lines · Jean Delvare
Sorry for the delay. Here finally come my comments on your code. I'm only commenting on the i2c side of things.
Hi Jean,
Thanks for the input! It's quite helpful and clears up some things we were a bit puzzled about. We'll fold most of your suggestions into the next patch. Answers to some questions you raised will be coming shortly.
Thanks again,
Chris
On Mon, Mar 22, 2010 at 7:07 PM, Christopher Heiny <[email protected]> wrote:
...
Quoted 7 lines
There are two existing drivers for similar Synaptics devices in the current kernel tree (excluding the PS/2 touchpad driver). These are:
./linux-2.6/drivers/input/mouse/synaptics_i2c.c
A driver for the Exeda 15mm touchpad, written by Mike Rapoport <[email protected]> and Igor Grinberg <[email protected]>
Quoted 9 lines
./linux-2.6/drivers/staging/dream/synaptics_i2c_rmi.c
A driver for the HTC Dream ClearPad, written by Arve Hjønnevåg <[email protected]>We have not extended these drivers for a couple of reasons. First, the two drivers are specific to particular Synaptics products, and it is our desire to produce a general solution that takes advantage of the 'self describing' features of products that use the RMI protocol.
Do you plan to add platform data to align the reported touchscreen data with the screen behind it, or do the new hardware allow the the firmware handle this? In the past we even needed separate parameters for different firmware versions (seen in drivers/staging/dream/synaptics_i2c_rmi.h).
Signature · 5 lines
Arve Hjønnevåg -- 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
Quoted 19 lines · Arve Hjønnevåg
On Mon, Mar 22, 2010 at 7:07 PM, Christopher Heiny<[email protected]> wrote:
...Quoted 7 lines
There are two existing drivers for similar Synaptics devices in the current kernel tree (excluding the PS/2 touchpad driver). These are:
./linux-2.6/drivers/input/mouse/synaptics_i2c.c
A driver for the Exeda 15mm touchpad, written by Mike Rapoport <[email protected]> and Igor Grinberg<[email protected]>Quoted 9 lines
./linux-2.6/drivers/staging/dream/synaptics_i2c_rmi.c
A driver for the HTC Dream ClearPad, written by Arve Hjønnevåg <[email protected]>We have not extended these drivers for a couple of reasons. First, the two drivers are specific to particular Synaptics products, and it is our desire to produce a general solution that takes advantage of the 'self describing' features of products that use the RMI protocol.
Quoted 5 lines
Do you plan to add platform data to align the reported touchscreen data with the screen behind it, or do the new hardware allow the the firmware handle this? In the past we even needed separate parameters for different firmware versions (seen in
drivers/staging/dream/synaptics_i2c_rmi.h).
Hi Arve,
RMI4 touchscreens allow adjustment of the reported coordinate range (see the F11_2D_Ctrl6..9 registers, page 48 of the current version of the spec at http://www.synaptics.com/developers/manuals). Using this feature, the device can be configured to report the same number of positions on each axis as there are pixels on the display.
We plan to make these settings accessible via sysfs, so that it can be dynamically tweaked if the user changes the display resolution (not likely on a phone, probable on a tablet/slate/ereader type device). Assuming there are no significant issues with our current patch, we plan to include that in the next one. We're holding off that implementation because we're still finding our feet on the submission process, and wanted to keep the initial submits small so changes would be more manageable.
Coordinate rotation/reflection settings will be handled at the driver level, again via sysfs.
These features should be independent of the touchscreen firmware level.
Initial settings for these features should probably be done at the
platform level.
Chris
--
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
2010/3/23 Christopher Heiny <[email protected]>:
Quoted 29 lines · Arve Hjønnevåg
Quoted 22 lines
On Mon, Mar 22, 2010 at 7:07 PM, Christopher Heiny<[email protected]> wrote:
...Quoted 8 lines
There are two existing drivers for similar Synaptics devices in the current kernel tree (excluding the PS/2 touchpad driver). These are:
./linux-2.6/drivers/input/mouse/synaptics_i2c.c
A driver for the Exeda 15mm touchpad, written by Mike Rapoport <[email protected]> and Igor Grinberg<[email protected]>Quoted 9 lines
./linux-2.6/drivers/staging/dream/synaptics_i2c_rmi.c
A driver for the HTC Dream ClearPad, written by Arve Hjønnevåg <[email protected]>We have not extended these drivers for a couple of reasons. First, the two drivers are specific to particular Synaptics products, and it is our desire to produce a general solution that takes advantage of the 'self describing' features of products that use the RMI protocol.
Quoted 5 lines
Do you plan to add platform data to align the reported touchscreen data with the screen behind it, or do the new hardware allow the the firmware handle this? In the past we even needed separate parameters for different firmware versions (seen in
drivers/staging/dream/synaptics_i2c_rmi.h).
Quoted 8 lines
Hi Arve,
RMI4 touchscreens allow adjustment of the reported coordinate range (see the F11_2D_Ctrl6..9 registers, page 48 of the current version of the spec at
http://www.synaptics.com/developers/manuals). Using this feature, the device can be configured to report the same number of positions on each axis as there are pixels on the display.
This does not help aligning the touchscreen values with the screen behind it. It just moves the linear scaling from userspace (which can use fixed or floating point values to preserve subpixel precision) to the firmware.
Quoted 7 lines
We plan to make these settings accessible via sysfs, so that it can be dynamically tweaked if the user changes the display resolution (not likely on a phone, probable on a tablet/slate/ereader type device). Assuming there are no significant issues with our current patch, we plan to include that in the next one. We're holding off that implementation because we're still finding our feet on the submission process, and wanted to keep the initial submits small so changes would be more manageable.
You could also post a patch series instead of one patch.
Quoted 4 lines
Coordinate rotation/reflection settings will be handled at the driver level, again via sysfs.
Do you also have a plan to let the userspace know that touchscreen coordinate x1,y1 correspond to screen coordinate 0,0 and x2,y2 correspond to screen coordinate xmax,ymax? The android driver sets absmin/max to the values reported when touching the display edges (not the actual min and max that the touchscreen can report), but other solutions are also possible.
Quoted 1 line
These features should be independent of the touchscreen firmware level.
In the past they have depended on the firmware version for two reasons. On one product, firmware changes to improve the edges of the screen completely changed the relationship between values reported and the physical touch location. On another product, the physical size of the sensor changed, and the firmware version was used to detect this. If all RMI4 based product allow field updates of the firmware the first case it less important, but we still need to cover the second case.
Quoted 5 lines
Initial settings for these features should probably be done at the platform level.
Chris
Signature · 5 lines
Arve Hjønnevåg -- 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
Quoted 39 lines · Arve Hjønnevåg
2010/3/23 Christopher Heiny<[email protected]>:
Quoted 29 lines · Arve Hjønnevåg
Quoted 22 lines
On Mon, Mar 22, 2010 at 7:07 PM, Christopher Heiny<[email protected]>
wrote:
...Quoted 8 lines
There are two existing drivers for similar Synaptics devices in the current kernel tree (excluding the PS/2 touchpad driver). These are:
./linux-2.6/drivers/input/mouse/synaptics_i2c.c
A driver for the Exeda 15mm touchpad, written by Mike Rapoport
<[email protected]> and Igor Grinberg<[email protected]>Quoted 9 lines
./linux-2.6/drivers/staging/dream/synaptics_i2c_rmi.c
A driver for the HTC Dream ClearPad, written by Arve Hjønnevåg <[email protected]>We have not extended these drivers for a couple of reasons. First, the two drivers are specific to particular Synaptics products, and it is our desire to produce a general solution that takes advantage of the 'self describing' features of products that use the RMI protocol.
Quoted 5 lines
Do you plan to add platform data to align the reported touchscreen data with the screen behind it, or do the new hardware allow the the firmware handle this? In the past we even needed separate parameters for different firmware versions (seen in
drivers/staging/dream/synaptics_i2c_rmi.h).Quoted 8 lines
Hi Arve,
RMI4 touchscreens allow adjustment of the reported coordinate range (see the F11_2D_Ctrl6..9 registers, page 48 of the current version of the spec at
http://www.synaptics.com/developers/manuals). Using this feature, the device can be configured to report the same number of positions on each axis as there are pixels on the display.
Quoted 4 lines
This does not help aligning the touchscreen values with the screen behind it. It just moves the linear scaling from userspace (which can use fixed or floating point values to preserve subpixel precision) to the firmware.
Hi Arve,
It sounds like your concern is for cases when the origin of the touchscreen coordinates does not correspond to a corner of the pixel area. Is that correct?
In any case, it's a perfectly valid issue - not all manufacturers take care to map the touchscreen to the display screen that way (though most do). Adding a translation control to the driver would be easy - we'll put it on the todo list.
Quoted 10 lines
Quoted 8 lines
We plan to make these settings accessible via sysfs, so that it can be dynamically tweaked if the user changes the display resolution (not likely on a phone, probable on a tablet/slate/ereader type device). Assuming there are no significant issues with our current patch, we plan to include that in the next one. We're holding off that implementation because we're still finding our feet on the submission process, and wanted to keep the initial submits small so changes would be more manageable.
You could also post a patch series instead of one patch.
It's more the other direction - we were concerned (validly, it turned out) that some extensive changes might be required as a result of feedback on the initial submissions, and wanted to keep the codebase we'd have to refactor small.
As the codebase grows, we'll switch to using patch series. Probably with the next submission or (more likely) the one after that.
Quoted 9 lines
Quoted 3 lines
Coordinate rotation/reflection settings will be handled at the driver level, again via sysfs.
Do you also have a plan to let the userspace know that touchscreen coordinate x1,y1 correspond to screen coordinate 0,0 and x2,y2 correspond to screen coordinate xmax,ymax? The android driver sets absmin/max to the values reported when touching the display edges (not the actual min and max that the touchscreen can report), but other solutions are also possible.
We are not planning on that, since it would require the driver to know the orientation (standard? rot 90? rot -90? rot 180?) and resolution of the display and track whenever that changes. It is better to handle that information at a higher level, which can then tell the touchscreen driver the desired resolution/rotation/etc settings.
Quoted 6 lines
Quoted 1 line
These features should be independent of the touchscreen firmware level.
In the past they have depended on the firmware version for two reasons. On one product, firmware changes to improve the edges of the screen completely changed the relationship between values reported and the physical touch location.
Good point.
Quoted 5 lines
On another product, the physical size of
the sensor changed, and the firmware version was used to detect this. If all RMI4 based product allow field updates of the firmware the first case it less important, but we still need to cover the second case.
Hmmmm. I can see a lot of other cases where it might be desirable to know the size of the touchscreen in a platform independent manner. Certainly the firmware version is not a reliable way to do this going forward. I will contact the spec maintainer and see if we can have the device report the relative information in a query.
Thanks,
Chris
--
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