qt2160: add slider support
Subsystems (2)
PATCH 1/8 qt2160: add slider support
Supports keys only, slider only, slider & keys configurations.
--- drivers/input/keyboard/qt2160.c | 180 +++++++++++++++++++++++++++++++++------ include/linux/input/qt2160.h | 26 ++++++ 2 files changed, 181 insertions(+), 25 deletions(-) mode change 100644 => 100755 drivers/input/keyboard/qt2160.c create mode 100755 include/linux/input/qt2160.h
drivers/input/keyboard/qt2160.c +155 -25
@@ -27,6 +27,9 @@#include <linux/irq.h> #include <linux/interrupt.h> #include <linux/input.h> +#include <linux/delay.h> + +#include <linux/input/qt2160.h> #define QT2160_VALID_CHIPID 0x11
@@ -39,14 +42,32 @@#define QT2160_CMD_GPIOS 6#define QT2160_CMD_SUBVER 7#define QT2160_CMD_CALIBRATE 10 +#define QT2160_CMD_RESET 11 +#define QT2160_CMD_SLIDE_CTRL 20 +#define QT2160_CMD_SLIDE_OPT 21 +#define QT2160_CMD_KEY0_AKS 22#define QT2160_CYCLE_INTERVAL (2*HZ) -static unsigned char qt2160_key2code[] = { -KEY_0 ,KEY_1 ,KEY_2 ,KEY_3 , -KEY_4 ,KEY_5 ,KEY_6 ,KEY_7 , -KEY_8 ,KEY_9 ,KEY_A ,KEY_B , -KEY_C ,KEY_D ,KEY_E ,KEY_F , +#define QT2160_SLIDE_RESOLUTION (8) +#define QT2160_SLIDE_HYSTERESIS (10) +#define QT2160_SLIDE_MAX_VALUE (0xFF) + +static struct qt2160_info default_hw_info = { + .slider_length =0 , + .slider_axis =0 , + .keycodes = { +KEY_0 ,KEY_1 ,KEY_2 ,KEY_3 , +KEY_4 ,KEY_5 ,KEY_6 ,KEY_7 , +KEY_8 ,KEY_9 ,KEY_A ,KEY_B , +KEY_C ,KEY_D ,KEY_E ,KEY_F , + }, + .key_aks = { +0 ,0 ,0 ,0 , +0 ,0 ,0 ,0 , +0 ,0 ,0 ,0 , +0 ,0 ,0 ,0 , + }, };struct qt2160_data {
@@ -54,8 +75,10 @@ struct qt2160_data {struct input_dev *input;struct delayed_work dwork;spinlock_t lock;/* Protects canceling/rescheduling of dwork */ -unsigned short keycodes[ARRAY_SIZE (qt2160_key2code)]; +struct qt2160_info *hw_info;u16 key_matrix; +u8 slide_val; +unsigned char num_keys; }; static int qt2160_read_block(struct i2c_client *client,
@@ -113,8 +136,10 @@ static int qt2160_get_key_matrix(struct qt2160_data *qt2160) {struct i2c_client *client = qt2160->client;struct input_dev *input = qt2160->input; +struct qt2160_info *hw_info = qt2160->hw_info;u8 regs[6 ];u16 old_matrix, new_matrix; +u8 old_slide;int ret, i, mask;dev_dbg (&client->dev,"requesting keys...\n" );
@@ -130,17 +155,30 @@ static int qt2160_get_key_matrix(struct qt2160_data *qt2160)return ret; } - old_matrix = qt2160->key_matrix; - qt2160->key_matrix = new_matrix = (regs[2 ] <<8 ) | regs[1 ]; - - mask =0x01 ; -for (i =0 ; i <16 ; ++i, mask <<=1 ) { -int keyval = new_matrix & mask; +if (hw_info->slider_length) { + old_slide = qt2160->slide_val; +if (old_slide != regs[3 ]) { + qt2160->slide_val = regs[3 ]; +input_report_abs (input, hw_info->slider_axis, regs[3 ]); + } + } -if ((old_matrix & mask) != keyval) { -input_report_key (input, qt2160->keycodes[i], keyval); -dev_dbg (&client->dev,"key %d %s\n" , - i, keyval ?"pressed" :"released" ); +if (qt2160->num_keys) { + old_matrix = qt2160->key_matrix; + qt2160->key_matrix = new_matrix = (regs[2 ] <<8 ) | regs[1 ]; + + mask =0x01 << hw_info->slider_length; +for (i = hw_info->slider_length; i <QT2160_MAXKEYS ; + ++i, mask <<=1 ) { +int keyval = new_matrix & mask; + +if (((old_matrix & mask) != keyval) && + (hw_info->keycodes[i])) { +input_report_key (input, hw_info->keycodes[i], + keyval); +dev_dbg (&client->dev,"key %d %s\n" , + i, keyval ?"pressed" :"released" ); + } } }
@@ -226,6 +264,52 @@ static int __devinit qt2160_write(struct i2c_client *client, u8 reg, u8 data)return error; } +static int __devinit qt2160_configure_device (struct i2c_client *client, +struct qt2160_data *qt2160) +{ +struct qt2160_info *pdata = qt2160->hw_info; +int i; +int error =0 ; + +/* perform software reset and wait for at least 32ms */ +i2c_smbus_write_byte_data (client,QT2160_CMD_RESET ,0xFF ); +msleep (200 ); + +/* perform dummy write to reset I2C state */ +i2c_smbus_write_byte (client,QT2160_CMD_CHIPID ); + +/* setup slider control and slider options */ +if (pdata->slider_length) { + error |=i2c_smbus_write_byte_data ( + client, +QT2160_CMD_SLIDE_CTRL , + (QT2160_SLIDE_HYSTERESIS <<4 ) | + (pdata->slider_length &0x0F )); + error |=i2c_smbus_write_byte_data (client,QT2160_CMD_SLIDE_OPT , +8 -QT2160_SLIDE_RESOLUTION ); + }else { + error =i2c_smbus_write_byte_data (client, +QT2160_CMD_SLIDE_CTRL ,0 ); + } +if (error) { +dev_err (&client->dev,"could not write slider config\n" ); + goto config_fault; + } + +for (i =0 ; i <QT2160_MAXKEYS ; i++) { +/* set AKS */ + error |=i2c_smbus_write_byte_data (client, +QT2160_CMD_KEY0_AKS + i, + pdata->key_aks[i]); + } +if (error) { +dev_err (&client->dev,"could not write key config\n" ); + goto config_fault; + } + +config_fault: +return error; +}static bool __devinit qt2160_identify (struct i2c_client *client) {
@@ -263,6 +347,8 @@ static int __devinit qt2160_probe(struct i2c_client *client, {struct qt2160_data *qt2160;struct input_dev *input; +struct qt2160_info *pdata; +struct qt2160_info *hw_info;int i;int error;
@@ -275,6 +361,8 @@ static int __devinit qt2160_probe(struct i2c_client *client,return -ENODEV ; } + pdata = client->dev.platform_data; +if (!qt2160_identify (client))return -ENODEV ;
@@ -287,6 +375,33 @@ static int __devinit qt2160_probe(struct i2c_client *client, goto err_free_mem; } +if (pdata) + qt2160->hw_info = pdata; +else + qt2160->hw_info = &default_hw_info; + hw_info = qt2160->hw_info; + + qt2160->num_keys =0 ; +for (i = hw_info->slider_length; i <QT2160_MAXKEYS ; ++i) { +if (hw_info->keycodes[i]) + qt2160->num_keys++; + } +if ((!qt2160->num_keys) && + (hw_info->slider_length <QT2160_MIN_SLIDER_LENGTH )) { +dev_err (&client->dev,"No valid input device specified\n" ); + error = -EINVAL ; + goto err_free_mem; + } +if (hw_info->slider_length !=0 ) { +if ((hw_info->slider_length >QT2160_MAX_SLIDER_LENGTH ) || + (hw_info->slider_length <QT2160_MIN_SLIDER_LENGTH )) { +dev_err (&client->dev,"%d keys slider not supported\n" , + hw_info->slider_length); + error = -EINVAL ; + goto err_free_mem; + } + } + qt2160->client = client; qt2160->input = input;INIT_DELAYED_WORK (&qt2160->dwork, qt2160_worker);
@@ -295,17 +410,32 @@ static int __devinit qt2160_probe(struct i2c_client *client, input->name ="AT42QT2160 Touch Sense Keyboard" ; input->id.bustype =BUS_I2C ; - input->keycode = qt2160->keycodes; - input->keycodesize =sizeof (qt2160->keycodes[0 ]); - input->keycodemax =ARRAY_SIZE (qt2160_key2code); +if (qt2160->num_keys) { + input->keycode = hw_info->keycodes; + input->keycodesize =sizeof (hw_info->keycodes[0 ]); + input->keycodemax =QT2160_MAXKEYS - hw_info->slider_length; + +__set_bit (EV_KEY , input->evbit); +__clear_bit (EV_REP , input->evbit); +for (i = hw_info->slider_length; i <QT2160_MAXKEYS ; i++) { +if (hw_info->keycodes[i]) +__set_bit (hw_info->keycodes[i], input->keybit); + } +__clear_bit (KEY_RESERVED , input->keybit); + } +if (hw_info->slider_length) { +__set_bit (EV_ABS , input->evbit); +__set_bit (hw_info->slider_axis, input->absbit); +input_set_abs_params (input, hw_info->slider_axis,0 , +QT2160_SLIDE_MAX_VALUE ,0 ,0 ); + } -__set_bit (EV_KEY , input->evbit); -__clear_bit (EV_REP , input->evbit); -for (i =0 ; i <ARRAY_SIZE (qt2160_key2code); i++) { - qt2160->keycodes[i] = qt2160_key2code[i]; -__set_bit (qt2160_key2code[i], input->keybit); +/* Configure device */ + error =qt2160_configure_device (client, qt2160); +if (error) { +dev_err (&client->dev,"failed to configure device\n" ); + goto err_free_mem; } -__clear_bit (KEY_RESERVED , input->keybit);/* Calibrate device */ error =qt2160_write (client,QT2160_CMD_CALIBRATE ,1 );
include/linux/input/qt2160.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef __QT2160_H__ +#define __QT2160_H__ + +#define QT2160_MAXKEYS 16 +#define QT2160_MAX_SLIDER_LENGTH 8 +#define QT2160_MIN_SLIDER_LENGTH 2 + +/** +* struct qt2160_info - defines the chip configuration +* @slider_length: number of keys to use as slider, max 8 keys, min 2 keys +* @slider_axis: absolute axis type, value 0 is ABS_X +* @keycodes: key codes for keys that are part of the slider are ignored; slider +* keys always start from key index 0 and end at key index (slider_length - 1); +* set to value 0 if key is not used; +* @key_aks: adjacent key suppression; keys that form a slider must be in the +* same aks group; keys in the same aks group will only report 1 active key at +* any time; value 0 disables aks group; valid aks groups are 1, 2, 3 +*/ +struct qt2160_info { +unsigned char slider_length; +unsigned int slider_axis; +unsigned short keycodes[QT2160_MAXKEYS ]; +unsigned char key_aks[QT2160_MAXKEYS ]; +}; + +#endif /* __QT2160_H__ */
Signature · 1 line
1.7.0.4
PATCH 2/8 qt2160: configurable key sensitivity
Add configurable key sensitivity, disable unused keys. Configurable key sensitivity to compensate for different touch sensor circuits. Disable unused keys to reduce power consumption.
Conflicts:
include/linux/input/qt2160.h --- drivers/input/keyboard/qt2160.c | 38 ++++++++++++++++++++++++++++++++++++++ include/linux/input/qt2160.h | 2 ++ 2 files changed, 40 insertions(+), 0 deletions(-)
drivers/input/keyboard/qt2160.c +38 -0
@@ -43,9 +43,26 @@#define QT2160_CMD_SUBVER 7#define QT2160_CMD_CALIBRATE 10#define QT2160_CMD_RESET 11 +#define QT2160_CMD_BURST_REP 13 +#define QT2160_CMD_NEG_DRIFT 15 +#define QT2160_CMD_POS_DRIFT 16 +#define QT2160_CMD_DI_LIMIT 17 +#define QT2160_CMD_NEG_RECAL 18 +#define QT2160_CMD_DHTA 19#define QT2160_CMD_SLIDE_CTRL 20#define QT2160_CMD_SLIDE_OPT 21#define QT2160_CMD_KEY0_AKS 22 +#define QT2160_CMD_KEY0_NEGT 38 +#define QT2160_CMD_KEY0_BURST 54 +#define QT2160_CMD_GPIO_DRV1 70 +#define QT2160_CMD_GPIO_DRV2 71 +#define QT2160_CMD_GPIO_DIR 73 +#define QT2160_CMD_GPIO_PWM1 74 +#define QT2160_CMD_GPIO_PWM2 75 +#define QT2160_CMD_PWM_LEVEL 76 +#define QT2160_CMD_GPIO_WAKE 77 +#define QT2160_CMD_CC_KEYS1 78 +#define QT2160_CMD_CC_KEYS2 79#define QT2160_CYCLE_INTERVAL (2*HZ)
@@ -297,6 +314,27 @@ static int __devinit qt2160_configure_device(struct i2c_client *client, }for (i =0 ; i <QT2160_MAXKEYS ; i++) { +/* setup burst length and disable unused keys */ +if (i < pdata->slider_length) { +if (pdata->key_burst_length[i]) + error |=i2c_smbus_write_byte_data ( + client, +QT2160_CMD_KEY0_BURST + i, + pdata->key_burst_length[i]); + }else { +if (pdata->keycodes[i]) { +if (pdata->key_burst_length[i]) + error |=i2c_smbus_write_byte_data ( + client, +QT2160_CMD_KEY0_BURST + i, + pdata->key_burst_length[i]); + }else { + error |=i2c_smbus_write_byte_data ( + client, +QT2160_CMD_KEY0_BURST + i, +0 ); + } + }/* set AKS */ error |= i2c_smbus_write_byte_data(client, QT2160_CMD_KEY0_AKS + i,
include/linux/input/qt2160.h +2 -0
@@ -15,12 +15,14 @@* @key_aks: adjacent key suppression; keys that form a slider must be in the * same aks group; keys in the same aks group will only report 1 active key at * any time; value 0 disables aks group; valid aks groups are 1, 2, 3 +* @key_burst_length: key sensitivity; 0 use default */ struct qt2160_info {unsigned char slider_length;unsigned int slider_axis;unsigned short keycodes[QT2160_MAXKEYS ];unsigned char key_aks[QT2160_MAXKEYS ]; +unsigned char key_burst_length[QT2160_MAXKEYS ]; };#endif /* __QT2160_H__ */
Signature · 1 line
1.7.0.4
PATCH 2/8 qt2160: configurable key sensitivity
Add configurable key sensitivity, disable unused keys. Configurable key sensitivity to compensate for different touch sensor circuits. Disable unused keys to reduce power consumption.
--- drivers/input/keyboard/qt2160.c | 38 ++++++++++++++++++++++++++++++++++++++ include/linux/input/qt2160.h | 2 ++ 2 files changed, 40 insertions(+), 0 deletions(-)
drivers/input/keyboard/qt2160.c +38 -0
@@ -43,9 +43,26 @@#define QT2160_CMD_SUBVER 7#define QT2160_CMD_CALIBRATE 10#define QT2160_CMD_RESET 11 +#define QT2160_CMD_BURST_REP 13 +#define QT2160_CMD_NEG_DRIFT 15 +#define QT2160_CMD_POS_DRIFT 16 +#define QT2160_CMD_DI_LIMIT 17 +#define QT2160_CMD_NEG_RECAL 18 +#define QT2160_CMD_DHTA 19#define QT2160_CMD_SLIDE_CTRL 20#define QT2160_CMD_SLIDE_OPT 21#define QT2160_CMD_KEY0_AKS 22 +#define QT2160_CMD_KEY0_NEGT 38 +#define QT2160_CMD_KEY0_BURST 54 +#define QT2160_CMD_GPIO_DRV1 70 +#define QT2160_CMD_GPIO_DRV2 71 +#define QT2160_CMD_GPIO_DIR 73 +#define QT2160_CMD_GPIO_PWM1 74 +#define QT2160_CMD_GPIO_PWM2 75 +#define QT2160_CMD_PWM_LEVEL 76 +#define QT2160_CMD_GPIO_WAKE 77 +#define QT2160_CMD_CC_KEYS1 78 +#define QT2160_CMD_CC_KEYS2 79#define QT2160_CYCLE_INTERVAL (2*HZ)
@@ -297,6 +314,27 @@ static int __devinit qt2160_configure_device(struct i2c_client *client, }for (i =0 ; i <QT2160_MAXKEYS ; i++) { +/* setup burst length and disable unused keys */ +if (i < pdata->slider_length) { +if (pdata->key_burst_length[i]) + error |=i2c_smbus_write_byte_data ( + client, +QT2160_CMD_KEY0_BURST + i, + pdata->key_burst_length[i]); + }else { +if (pdata->keycodes[i]) { +if (pdata->key_burst_length[i]) + error |=i2c_smbus_write_byte_data ( + client, +QT2160_CMD_KEY0_BURST + i, + pdata->key_burst_length[i]); + }else { + error |=i2c_smbus_write_byte_data ( + client, +QT2160_CMD_KEY0_BURST + i, +0 ); + } + }/* set AKS */ error |= i2c_smbus_write_byte_data(client, QT2160_CMD_KEY0_AKS + i,
include/linux/input/qt2160.h +2 -0
@@ -15,12 +15,14 @@* @key_aks: adjacent key suppression; keys that form a slider must be in the * same aks group; keys in the same aks group will only report 1 active key at * any time; value 0 disables aks group; valid aks groups are 1, 2, 3 +* @key_burst_length: key sensitivity; 0 use default */ struct qt2160_info {unsigned char slider_length;unsigned int slider_axis;unsigned short keycodes[QT2160_MAXKEYS ];unsigned char key_aks[QT2160_MAXKEYS ]; +unsigned char key_burst_length[QT2160_MAXKEYS ]; };#endif /* __QT2160_H__ */
Signature · 1 line
1.7.0.4
PATCH 3/8 qt2160: add PM support
In reply to jooaunAdd power management support.
--- drivers/input/keyboard/qt2160.c | 34 ++++++++++++++++++++++++++++++++++ 1 files changed, 34 insertions(+), 0 deletions(-)
drivers/input/keyboard/qt2160.c +34 -0
@@ -43,6 +43,7 @@#define QT2160_CMD_SUBVER 7#define QT2160_CMD_CALIBRATE 10#define QT2160_CMD_RESET 11 +#define QT2160_CMD_LP_MODE 12#define QT2160_CMD_BURST_REP 13#define QT2160_CMD_NEG_DRIFT 15#define QT2160_CMD_POS_DRIFT 16
@@ -66,6 +67,9 @@#define QT2160_CYCLE_INTERVAL (2*HZ) +#define QT2160_LP_MODE_DEFAULT_VALUE (1) +#define QT2160_LP_MODE_SLEEP_VALUE (0) +#define QT2160_SLIDE_RESOLUTION (8)#define QT2160_SLIDE_HYSTERESIS (10)#define QT2160_SLIDE_MAX_VALUE (0xFF)
@@ -529,6 +533,34 @@ static int __devexit qt2160_remove(struct i2c_client *client)return 0 ; } +#ifdef CONFIG_PM +static int qt2160_suspend (struct i2c_client *client,pm_message_t message) +{ +int error; + + error =i2c_smbus_write_byte_data (client,QT2160_CMD_LP_MODE , +QT2160_LP_MODE_SLEEP_VALUE ); +if (error) +dev_err (&client->dev,"could not write power config\n" ); +return error; +} + +static int qt2160_resume (struct i2c_client *client) +{ +int error; +u8 lp_mode_val =QT2160_LP_MODE_DEFAULT_VALUE ; + + error =i2c_smbus_write_byte_data (client,QT2160_CMD_LP_MODE , + lp_mode_val); +if (error) +dev_err (&client->dev,"could not write power config\n" ); +return error; +} +#else +#define qt2160_suspend NULL +#define qt2160_resume NULL +#endif +static const struct i2c_device_id qt2160_idtable[] = { {"qt2160" ,0 , }, { }
@@ -545,6 +577,8 @@ static struct i2c_driver qt2160_driver = { .id_table = qt2160_idtable, .probe = qt2160_probe, .remove = __devexit_p(qt2160_remove), + .suspend = qt2160_suspend, + .resume = qt2160_resume, };static int __init qt2160_init (void )
Signature · 1 line
1.7.0.4
PATCH 4/8 qt2160: add configurable power mode
In reply to jooaunAdd configurable low power mode to reduce power consumption. We trade off responsiveness for lower power consumption. Each +1 increment in value causes the chip to sleep 16ms longer before detecting a touch.
--- drivers/input/keyboard/qt2160.c | 13 +++++++++++++ include/linux/input/qt2160.h | 3 +++ 2 files changed, 16 insertions(+), 0 deletions(-)
drivers/input/keyboard/qt2160.c +13 -0
@@ -299,6 +299,15 @@ static int __devinit qt2160_configure_device(struct i2c_client *client,/* perform dummy write to reset I2C state */ i2c_smbus_write_byte (client,QT2160_CMD_CHIPID ); +/* setup LP mode */ +if (pdata->low_power_mode) { + error =i2c_smbus_write_byte_data (client,QT2160_CMD_LP_MODE , + pdata->low_power_mode); +if (error) { +dev_err (&client->dev,"could not write power config\n" ); + goto config_fault; + } + }/* setup slider control and slider options */ if (pdata->slider_length) { error |= i2c_smbus_write_byte_data(
@@ -547,9 +556,13 @@ static int qt2160_suspend(struct i2c_client *client, pm_message_t message)static int qt2160_resume (struct i2c_client *client) { +struct qt2160_data *qt2160 =i2c_get_clientdata (client); +struct qt2160_info *hw_info = qt2160->hw_info;int error;u8 lp_mode_val =QT2160_LP_MODE_DEFAULT_VALUE ; +if (hw_info->low_power_mode) + lp_mode_val = hw_info->low_power_mode; error =i2c_smbus_write_byte_data (client,QT2160_CMD_LP_MODE , lp_mode_val);if (error)
include/linux/input/qt2160.h +3 -0
@@ -16,6 +16,8 @@* same aks group; keys in the same aks group will only report 1 active key at * any time; value 0 disables aks group; valid aks groups are 1, 2, 3 * @key_burst_length: key sensitivity; 0 use default +* @low_power_mode: value 0 use default; each +1 increment causes the chip to +* sleep 16ms longer before detecting a touch (slower response); max 255 */ struct qt2160_info {unsigned char slider_length;
@@ -23,6 +25,7 @@ struct qt2160_info {unsigned short keycodes[QT2160_MAXKEYS ];unsigned char key_aks[QT2160_MAXKEYS ];unsigned char key_burst_length[QT2160_MAXKEYS ]; + unsigned char low_power_mode; };#endif /* __QT2160_H__ */
Signature · 1 line
1.7.0.4
PATCH 5/8 qt2160: fix starting of device calibration
In reply to jooaunWriting of calibration command and non-zero data value must be performed in one I2C transaction.
--- drivers/input/keyboard/qt2160.c | 23 +---------------------- 1 files changed, 1 insertions(+), 22 deletions(-)
drivers/input/keyboard/qt2160.c +1 -22
@@ -264,27 +264,6 @@ static int __devinit qt2160_read(struct i2c_client *client, u8 reg)return ret; } -static int __devinit qt2160_write (struct i2c_client *client,u8 reg,u8 data) -{ -int error; - - error =i2c_smbus_write_byte (client, reg); -if (error) { -dev_err (&client->dev, -"couldn't send request. Returned %d\n" , error); -return error; - } - - error =i2c_smbus_write_byte (client, data); -if (error) { -dev_err (&client->dev, -"couldn't write data. Returned %d\n" , error); -return error; - } - -return error; -} -static int __devinit qt2160_configure_device (struct i2c_client *client,struct qt2160_data *qt2160) {
@@ -489,7 +468,7 @@ static int __devinit qt2160_probe(struct i2c_client *client, }/* Calibrate device */ - error =qt2160_write (client,QT2160_CMD_CALIBRATE ,1 ); + error =i2c_smbus_write_byte_data (client,QT2160_CMD_CALIBRATE ,1 );if (error) {dev_err (&client->dev,"failed to calibrate device\n" ); goto err_free_mem;
Signature · 1 line
1.7.0.4
PATCH 6/8 qt2160: only read device when Change pin is active
In reply to jooaunCheck Change state and only read device when required.
Conflicts:
include/linux/input/qt2160.h --- drivers/input/keyboard/qt2160.c | 12 ++++++++++++ include/linux/input/qt2160.h | 5 +++++ 2 files changed, 17 insertions(+), 0 deletions(-)
drivers/input/keyboard/qt2160.c +12 -0
@@ -213,6 +213,12 @@ static irqreturn_t qt2160_irq(int irq, void *_qt2160)struct qt2160_data *qt2160 = _qt2160;unsigned long flags; +if (qt2160->hw_info->getchange) { +/* if change is not active, no IRQ to service */ +if (qt2160->hw_info->getchange (qt2160->hw_info->data) >0 ) +return IRQ_HANDLED ; + } +spin_lock_irqsave (&qt2160->lock, flags);__cancel_delayed_work (&qt2160->dwork);
@@ -225,6 +231,12 @@ static irqreturn_t qt2160_irq(int irq, void *_qt2160)static void qt2160_schedule_read (struct qt2160_data *qt2160) { +if (qt2160->hw_info->getchange) { +/* if change is not active, no need to read device */ +if (qt2160->hw_info->getchange (qt2160->hw_info->data) >0 ) +return ; + } +spin_lock_irq (&qt2160->lock);schedule_delayed_work (&qt2160->dwork,QT2160_CYCLE_INTERVAL );spin_unlock_irq (&qt2160->lock);
include/linux/input/qt2160.h +5 -0
@@ -7,6 +7,9 @@/** * struct qt2160_info - defines the chip configuration +* @data: private data for lowlevel IO abstraction routines +* @getchange: return 0 when CHANGE pin is active/low; return 1 when CHANGE pin +* is deactivated/high * @slider_length: number of keys to use as slider, max 8 keys, min 2 keys * @slider_axis: absolute axis type, value 0 is ABS_X * @keycodes: key codes for keys that are part of the slider are ignored; slider
@@ -20,6 +23,8 @@* sleep 16ms longer before detecting a touch (slower response); max 255 */ struct qt2160_info { +void *data; +int (*getchange) (void *data);unsigned char slider_length;unsigned int slider_axis;unsigned short keycodes[QT2160_MAXKEYS ];
Signature · 1 line
1.7.0.4
PATCH 6/8 qt2160: only read device when Change pin is active
Check Change state and only read device when required.
--- drivers/input/keyboard/qt2160.c | 12 ++++++++++++ include/linux/input/qt2160.h | 5 +++++ 2 files changed, 17 insertions(+), 0 deletions(-)
drivers/input/keyboard/qt2160.c +12 -0
@@ -213,6 +213,12 @@ static irqreturn_t qt2160_irq(int irq, void *_qt2160)struct qt2160_data *qt2160 = _qt2160;unsigned long flags; +if (qt2160->hw_info->getchange) { +/* if change is not active, no IRQ to service */ +if (qt2160->hw_info->getchange (qt2160->hw_info->data) >0 ) +return IRQ_HANDLED ; + } +spin_lock_irqsave (&qt2160->lock, flags);__cancel_delayed_work (&qt2160->dwork);
@@ -225,6 +231,12 @@ static irqreturn_t qt2160_irq(int irq, void *_qt2160)static void qt2160_schedule_read (struct qt2160_data *qt2160) { +if (qt2160->hw_info->getchange) { +/* if change is not active, no need to read device */ +if (qt2160->hw_info->getchange (qt2160->hw_info->data) >0 ) +return ; + } +spin_lock_irq (&qt2160->lock);schedule_delayed_work (&qt2160->dwork,QT2160_CYCLE_INTERVAL );spin_unlock_irq (&qt2160->lock);
include/linux/input/qt2160.h +5 -0
@@ -7,6 +7,9 @@/** * struct qt2160_info - defines the chip configuration +* @data: private data for lowlevel IO abstraction routines +* @getchange: return 0 when CHANGE pin is active/low; return 1 when CHANGE pin +* is deactivated/high * @slider_length: number of keys to use as slider, max 8 keys, min 2 keys * @slider_axis: absolute axis type, value 0 is ABS_X * @keycodes: key codes for keys that are part of the slider are ignored; slider
@@ -20,6 +23,8 @@* sleep 16ms longer before detecting a touch (slower response); max 255 */ struct qt2160_info { +void *data; +int (*getchange) (void *data);unsigned char slider_length;unsigned int slider_axis;unsigned short keycodes[QT2160_MAXKEYS ];
Signature · 1 line
1.7.0.4
PATCH 7/8 qt2160: optional interrupt flag
In reply to jooaunSome GPIOs do not support falling edge only interrupt, so make interrupt flag configurable.
Conflicts:
include/linux/input/qt2160.h --- drivers/input/keyboard/qt2160.c | 11 +++++++++-- include/linux/input/qt2160.h | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-)
drivers/input/keyboard/qt2160.c +9 -2
@@ -487,8 +487,15 @@ static int __devinit qt2160_probe(struct i2c_client *client, }if (client->irq) { - error =request_irq (client->irq, qt2160_irq, -IRQF_TRIGGER_FALLING ,"qt2160" , qt2160); +if (hw_info->irq_flags) { + error =request_irq (client->irq, qt2160_irq, + hw_info->irq_flags,"qt2160" , + qt2160); + }else { + error =request_irq (client->irq, qt2160_irq, +IRQF_TRIGGER_FALLING ,"qt2160" , + qt2160); + }if (error) {dev_err (&client->dev,"failed to allocate irq %d\n" , client->irq);
include/linux/input/qt2160.h +2 -0
@@ -21,6 +21,7 @@* @key_burst_length: key sensitivity; 0 use default * @low_power_mode: value 0 use default; each +1 increment causes the chip to * sleep 16ms longer before detecting a touch (slower response); max 255 +* @irq_flags: value 0 use default IRQF_TRIGGER_FALLING */ struct qt2160_info {void *data;
@@ -31,6 +32,7 @@ struct qt2160_info {unsigned char key_aks[QT2160_MAXKEYS ];unsigned char key_burst_length[QT2160_MAXKEYS ];unsigned char low_power_mode; + unsigned long irq_flags; };#endif /* __QT2160_H__ */
Signature · 1 line
1.7.0.4
PATCH 7/8 qt2160: optional interrupt flag
Some GPIOs do not support falling edge only interrupt, so make interrupt flag configurable.
--- drivers/input/keyboard/qt2160.c | 11 +++++++++-- include/linux/input/qt2160.h | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-)
drivers/input/keyboard/qt2160.c +9 -2
@@ -487,8 +487,15 @@ static int __devinit qt2160_probe(struct i2c_client *client, }if (client->irq) { - error =request_irq (client->irq, qt2160_irq, -IRQF_TRIGGER_FALLING ,"qt2160" , qt2160); +if (hw_info->irq_flags) { + error =request_irq (client->irq, qt2160_irq, + hw_info->irq_flags,"qt2160" , + qt2160); + }else { + error =request_irq (client->irq, qt2160_irq, +IRQF_TRIGGER_FALLING ,"qt2160" , + qt2160); + }if (error) {dev_err (&client->dev,"failed to allocate irq %d\n" , client->irq);
include/linux/input/qt2160.h +2 -0
@@ -21,6 +21,7 @@* @key_burst_length: key sensitivity; 0 use default * @low_power_mode: value 0 use default; each +1 increment causes the chip to * sleep 16ms longer before detecting a touch (slower response); max 255 +* @irq_flags: value 0 use default IRQF_TRIGGER_FALLING */ struct qt2160_info {void *data;
@@ -31,6 +32,7 @@ struct qt2160_info {unsigned char key_aks[QT2160_MAXKEYS ];unsigned char key_burst_length[QT2160_MAXKEYS ];unsigned char low_power_mode; + unsigned long irq_flags; };#endif /* __QT2160_H__ */
Signature · 1 line
1.7.0.4
PATCH 8/8 qt2160: add hardware reset
In reply to jooaunUse hardware reset if defined, fall back on soft reset.
Conflicts:
include/linux/input/qt2160.h --- drivers/input/keyboard/qt2160.c | 8 +++++++- include/linux/input/qt2160.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletions(-)
drivers/input/keyboard/qt2160.c +7 -1
@@ -284,7 +284,13 @@ static int __devinit qt2160_configure_device(struct i2c_client *client,int error =0 ;/* perform software reset and wait for at least 32ms */ -i2c_smbus_write_byte_data (client,QT2160_CMD_RESET ,0xFF ); +if (pdata->setrst) { + pdata->setrst (pdata->data,0 ); +udelay (10 ); + pdata->setrst (pdata->data,1 ); + }else { +i2c_smbus_write_byte_data (client,QT2160_CMD_RESET ,0xFF ); + }msleep (200 );/* perform dummy write to reset I2C state */
include/linux/input/qt2160.h +2 -0
@@ -10,6 +10,7 @@* @data: private data for lowlevel IO abstraction routines * @getchange: return 0 when CHANGE pin is active/low; return 1 when CHANGE pin * is deactivated/high +* @setrst: 0 activates RESET pin; 1 deactivates RESET pin * @slider_length: number of keys to use as slider, max 8 keys, min 2 keys * @slider_axis: absolute axis type, value 0 is ABS_X * @keycodes: key codes for keys that are part of the slider are ignored; slider
@@ -26,6 +27,7 @@struct qt2160_info {void *data;int (*getchange) (void *data); +void (*setrst) (void *data,int state);unsigned char slider_length;unsigned int slider_axis;unsigned short keycodes[QT2160_MAXKEYS ];
Signature · 1 line
1.7.0.4
PATCH 8/8 qt2160: add hardware reset
Use hardware reset if defined, fall back on soft reset.
--- drivers/input/keyboard/qt2160.c | 8 +++++++- include/linux/input/qt2160.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletions(-)
drivers/input/keyboard/qt2160.c +7 -1
@@ -284,7 +284,13 @@ static int __devinit qt2160_configure_device(struct i2c_client *client,int error =0 ;/* perform software reset and wait for at least 32ms */ -i2c_smbus_write_byte_data (client,QT2160_CMD_RESET ,0xFF ); +if (pdata->setrst) { + pdata->setrst (pdata->data,0 ); +udelay (10 ); + pdata->setrst (pdata->data,1 ); + }else { +i2c_smbus_write_byte_data (client,QT2160_CMD_RESET ,0xFF ); + }msleep (200 );/* perform dummy write to reset I2C state */
include/linux/input/qt2160.h +2 -0
@@ -10,6 +10,7 @@* @data: private data for lowlevel IO abstraction routines * @getchange: return 0 when CHANGE pin is active/low; return 1 when CHANGE pin * is deactivated/high +* @setrst: 0 activates RESET pin; 1 deactivates RESET pin * @slider_length: number of keys to use as slider, max 8 keys, min 2 keys * @slider_axis: absolute axis type, value 0 is ABS_X * @keycodes: key codes for keys that are part of the slider are ignored; slider
@@ -26,6 +27,7 @@struct qt2160_info {void *data;int (*getchange) (void *data); +void (*setrst) (void *data,int state);unsigned char slider_length;unsigned int slider_axis;unsigned short keycodes[QT2160_MAXKEYS ];
Signature · 1 line
1.7.0.4