Input: eeti_ts - rename eeti_ts_priv to eeti_ts
Subsystems (5)
Dmitry Torokhov
maintainerPATCH 1/10 Input: eeti_ts - rename eeti_ts_priv to eeti_ts
Also rename 'priv' variables to eeti.
---
Hi,
This is all is not tested as I do not have the hardware, so if anyone has raumfeld device that would be awesome.
drivers/input/touchscreen/eeti_ts.c | 115 ++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 57 deletions(-)
drivers/input/touchscreen/eeti_ts.c +58 -57
@@ -43,7 +43,7 @@ static bool flip_y;module_param (flip_y, bool,0644 );MODULE_PARM_DESC (flip_y,"flip y coordinate" ); -struct eeti_ts_priv { +struct eeti_ts {struct i2c_client *client;struct input_dev *input;struct work_struct work;
@@ -60,25 +60,25 @@ struct eeti_ts_priv {#define REPORT_BIT_HAS_PRESSURE (1 << 6)#define REPORT_RES_BITS (v) (((v) >> 1) + EETI_TS_BITDEPTH) -static inline int eeti_ts_irq_active (struct eeti_ts_priv *priv) +static inline int eeti_ts_irq_active (struct eeti_ts *eeti) { -return gpio_get_value (priv->irq_gpio) == priv->irq_active_high; +return gpio_get_value (eeti->irq_gpio) == eeti->irq_active_high; }static void eeti_ts_read (struct work_struct *work) {char buf[6 ];unsigned int x, y, res, pressed, to =100 ; -struct eeti_ts_priv *priv = - container_of(work, struct eeti_ts_priv, work); +struct eeti_ts *eeti = + container_of(work, struct eeti_ts, work); -mutex_lock (&priv->mutex); +mutex_lock (&eeti->mutex); -while (eeti_ts_irq_active (priv) && --to) -i2c_master_recv (priv->client, buf,sizeof (buf)); +while (eeti_ts_irq_active (eeti) && --to) +i2c_master_recv (eeti->client, buf,sizeof (buf));if (!to) { -dev_err (&priv->client->dev, +dev_err (&eeti->client->dev,"unable to clear IRQ - line stuck?\n" ); goto out; }
@@ -103,62 +103,62 @@ static void eeti_ts_read(struct work_struct *work) y =EETI_MAXVAL - y;if (buf[0 ] &REPORT_BIT_HAS_PRESSURE ) -input_report_abs (priv->input,ABS_PRESSURE , buf[5 ]); +input_report_abs (eeti->input,ABS_PRESSURE , buf[5 ]); -input_report_abs (priv->input,ABS_X , x); -input_report_abs (priv->input,ABS_Y , y); -input_report_key (priv->input,BTN_TOUCH , !!pressed); -input_sync (priv->input); +input_report_abs (eeti->input,ABS_X , x); +input_report_abs (eeti->input,ABS_Y , y); +input_report_key (eeti->input,BTN_TOUCH , !!pressed); +input_sync (eeti->input); out: -mutex_unlock (&priv->mutex); +mutex_unlock (&eeti->mutex); }static irqreturn_t eeti_ts_isr (int irq,void *dev_id) { -struct eeti_ts_priv *priv = dev_id; +struct eeti_ts *eeti = dev_id;/* postpone I2C transactions as we are atomic */ -schedule_work (&priv->work); +schedule_work (&eeti->work);return IRQ_HANDLED ; } -static void eeti_ts_start (struct eeti_ts_priv *priv) +static void eeti_ts_start (struct eeti_ts *eeti) { -enable_irq (priv->irq); +enable_irq (eeti->irq);/* Read the events once to arm the IRQ */ -eeti_ts_read (&priv->work); +eeti_ts_read (&eeti->work); } -static void eeti_ts_stop (struct eeti_ts_priv *priv) +static void eeti_ts_stop (struct eeti_ts *eeti) { -disable_irq (priv->irq); -cancel_work_sync (&priv->work); +disable_irq (eeti->irq); +cancel_work_sync (&eeti->work); }static int eeti_ts_open (struct input_dev *dev) { -struct eeti_ts_priv *priv =input_get_drvdata (dev); +struct eeti_ts *eeti =input_get_drvdata (dev); -eeti_ts_start (priv); +eeti_ts_start (eeti);return 0 ; }static void eeti_ts_close (struct input_dev *dev) { -struct eeti_ts_priv *priv =input_get_drvdata (dev); +struct eeti_ts *eeti =input_get_drvdata (dev); -eeti_ts_stop (priv); +eeti_ts_stop (eeti); }static int eeti_ts_probe (struct i2c_client *client,const struct i2c_device_id *idp) {struct eeti_ts_platform_data *pdata =dev_get_platdata (&client->dev); -struct eeti_ts_priv *priv; +struct eeti_ts *eeti;struct input_dev *input;unsigned int irq_flags;int err = -ENOMEM ;
@@ -170,13 +170,14 @@ static int eeti_ts_probe(struct i2c_client *client,* for interrupts to occur. */ - priv =kzalloc (sizeof (*priv),GFP_KERNEL ); -if (!priv) { + eeti =kzalloc (sizeof (*eeti),GFP_KERNEL ); +if (!eeti) {dev_err (&client->dev,"failed to allocate driver data\n" );return -ENOMEM ; } -mutex_init (&priv->mutex); +mutex_init (&eeti->mutex); + input =input_allocate_device ();if (!input) {dev_err (&client->dev,"Failed to allocate input device.\n" );
@@ -196,30 +197,30 @@ static int eeti_ts_probe(struct i2c_client *client, input->open = eeti_ts_open; input->close = eeti_ts_close; - priv->client = client; - priv->input = input; - priv->irq_gpio = pdata->irq_gpio; - priv->irq =gpio_to_irq (pdata->irq_gpio); + eeti->client = client; + eeti->input = input; + eeti->irq_gpio = pdata->irq_gpio; + eeti->irq =gpio_to_irq (pdata->irq_gpio); err =gpio_request_one (pdata->irq_gpio,GPIOF_IN , client->name);if (err <0 ) goto err1; - priv->irq_active_high = pdata->irq_active_high; + eeti->irq_active_high = pdata->irq_active_high; - irq_flags = priv->irq_active_high ? + irq_flags = eeti->irq_active_high ?IRQF_TRIGGER_RISING :IRQF_TRIGGER_FALLING ; -INIT_WORK (&priv->work, eeti_ts_read); -i2c_set_clientdata (client, priv); -input_set_drvdata (input, priv); +INIT_WORK (&eeti->work, eeti_ts_read); +i2c_set_clientdata (client, eeti); +input_set_drvdata (input, eeti); err =input_register_device (input);if (err) goto err2; - err =request_irq (priv->irq, eeti_ts_isr, irq_flags, - client->name, priv); + err =request_irq (eeti->irq, eeti_ts_isr, irq_flags, + client->name, eeti);if (err) {dev_err (&client->dev,"Unable to request touchscreen IRQ.\n" ); goto err3;
@@ -229,7 +230,7 @@ static int eeti_ts_probe(struct i2c_client *client,* Disable the device for now. It will be enabled once the * input device is opened. */ -eeti_ts_stop (priv); +eeti_ts_stop (eeti);return 0 ;
@@ -240,23 +241,23 @@ static int eeti_ts_probe(struct i2c_client *client,gpio_free (pdata->irq_gpio); err1:input_free_device (input); -kfree (priv); +kfree (eeti);return err; }static int eeti_ts_remove (struct i2c_client *client) { -struct eeti_ts_priv *priv =i2c_get_clientdata (client); +struct eeti_ts *eeti =i2c_get_clientdata (client); -free_irq (priv->irq, priv); +free_irq (eeti->irq, eeti);/* * eeti_ts_stop() leaves IRQ disabled. We need to re-enable it * so that device still works if we reload the driver. */ -enable_irq (priv->irq); +enable_irq (eeti->irq); -input_unregister_device (priv->input); -kfree (priv); +input_unregister_device (eeti->input); +kfree (eeti);return 0 ; }
@@ -264,18 +265,18 @@ static int eeti_ts_remove(struct i2c_client *client)static int __maybe_unused eeti_ts_suspend (struct device *dev) {struct i2c_client *client =to_i2c_client (dev); -struct eeti_ts_priv *priv =i2c_get_clientdata (client); -struct input_dev *input_dev = priv->input; +struct eeti_ts *eeti =i2c_get_clientdata (client); +struct input_dev *input_dev = eeti->input;mutex_lock (&input_dev->mutex);if (input_dev->users) -eeti_ts_stop (priv); +eeti_ts_stop (eeti);mutex_unlock (&input_dev->mutex);if (device_may_wakeup (&client->dev)) -enable_irq_wake (priv->irq); +enable_irq_wake (eeti->irq);return 0 ; }
@@ -283,16 +284,16 @@ static int __maybe_unused eeti_ts_suspend(struct device *dev)static int __maybe_unused eeti_ts_resume (struct device *dev) {struct i2c_client *client =to_i2c_client (dev); -struct eeti_ts_priv *priv =i2c_get_clientdata (client); -struct input_dev *input_dev = priv->input; +struct eeti_ts *eeti =i2c_get_clientdata (client); +struct input_dev *input_dev = eeti->input;if (device_may_wakeup (&client->dev)) -disable_irq_wake (priv->irq); +disable_irq_wake (eeti->irq);mutex_lock (&input_dev->mutex);if (input_dev->users) -eeti_ts_start (priv); +eeti_ts_start (eeti);mutex_unlock (&input_dev->mutex);
Signature · 1 line
2.11.0.483.g087da7b7c-goog
Dmitry Torokhov
maintainerPATCH 2/10 Input: eeti_ts - use BIT(n)
Use idiomatic BIT(n) to form single-bit masks.
--- drivers/input/touchscreen/eeti_ts.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/input/touchscreen/eeti_ts.c +4 -4
@@ -54,10 +54,10 @@ struct eeti_ts {#define EETI_TS_BITDEPTH (11)#define EETI_MAXVAL ((1 << (EETI_TS_BITDEPTH + 1)) - 1) -#define REPORT_BIT_PRESSED (1 << 0) -#define REPORT_BIT_AD0 (1 << 1) -#define REPORT_BIT_AD1 (1 << 2) -#define REPORT_BIT_HAS_PRESSURE (1 << 6) +#define REPORT_BIT_PRESSED BIT(0) +#define REPORT_BIT_AD0 BIT(1) +#define REPORT_BIT_AD1 BIT(2) +#define REPORT_BIT_HAS_PRESSURE BIT(6)#define REPORT_RES_BITS (v) (((v) >> 1) + EETI_TS_BITDEPTH)static inline int eeti_ts_irq_active (struct eeti_ts *eeti)
Signature · 1 line
2.11.0.483.g087da7b7c-goog
Dmitry Torokhov
maintainerPATCH 3/10 Input: eeti_ts - use get_unaligned_be16() to retrieve data
In reply to Dmitry TorokhovInstead of manually converting big endian data on wire into host endianness, let's use helpers to do that for us. It might save us a few cycles if host endianness matches what's on wire.
--- drivers/input/touchscreen/eeti_ts.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/input/touchscreen/eeti_ts.c +4 -2
@@ -34,6 +34,7 @@#include <linux/gpio.h> #include <linux/input/eeti_ts.h> #include <linux/slab.h> +#include <asm/unaligned.h> static bool flip_x;module_param (flip_x, bool,0644 );
@@ -89,8 +90,9 @@ static void eeti_ts_read(struct work_struct *work) pressed = buf[0 ] &REPORT_BIT_PRESSED ; res =REPORT_RES_BITS (buf[0 ] & (REPORT_BIT_AD0 |REPORT_BIT_AD1 )); - x = buf[2 ] | (buf[1 ] <<8 ); - y = buf[4 ] | (buf[3 ] <<8 ); + + x =get_unaligned_be16 (&buf[1 ]); + y =get_unaligned_be16 (&buf[3 ]);/* fix the range to 11 bits */ x >>= res -EETI_TS_BITDEPTH ;
Signature · 1 line
2.11.0.483.g087da7b7c-goog
Dmitry Torokhov
maintainerPATCH 4/10 Input: eeti_ts - use input_set_capability()
In reply to Dmitry TorokhovUse input_set_capability() instead of manipulating evbit/keybit masks directly.
--- drivers/input/touchscreen/eeti_ts.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/input/touchscreen/eeti_ts.c +1 -2
@@ -186,8 +186,7 @@ static int eeti_ts_probe(struct i2c_client *client, goto err1; } - input->evbit[0 ] =BIT_MASK (EV_KEY ) |BIT_MASK (EV_ABS ); - input->keybit[BIT_WORD (BTN_TOUCH )] =BIT_MASK (BTN_TOUCH ); +input_set_capability (input,EV_KEY ,BTN_TOUCH );input_set_abs_params (input,ABS_X ,0 ,EETI_MAXVAL ,0 ,0 );input_set_abs_params (input,ABS_Y ,0 ,EETI_MAXVAL ,0 ,0 );
Signature · 1 line
2.11.0.483.g087da7b7c-goog
Dmitry Torokhov
maintainerPATCH 5/10 Input: eeti-ts - switch to using managed resources
In reply to Dmitry TorokhovUsing devm_* APIs simpifies error handling and device teardown.
--- drivers/input/touchscreen/eeti_ts.c | 70 ++++++++++++------------------------- 1 file changed, 22 insertions(+), 48 deletions(-)
drivers/input/touchscreen/eeti_ts.c +22 -48
@@ -157,13 +157,14 @@ static void eeti_ts_close(struct input_dev *dev) }static int eeti_ts_probe (struct i2c_client *client, -const struct i2c_device_id *idp) +const struct i2c_device_id *idp) { -struct eeti_ts_platform_data *pdata =dev_get_platdata (&client->dev); +struct device *dev = &client->dev; +struct eeti_ts_platform_data *pdata =dev_get_platdata (dev);struct eeti_ts *eeti;struct input_dev *input;unsigned int irq_flags; -int err = -ENOMEM ; +int error;/* * In contrast to what's described in the datasheet, there seems
@@ -172,18 +173,18 @@ static int eeti_ts_probe(struct i2c_client *client,* for interrupts to occur. */ - eeti =kzalloc (sizeof (*eeti),GFP_KERNEL ); + eeti =devm_kzalloc (dev,sizeof (*eeti),GFP_KERNEL );if (!eeti) { -dev_err (&client->dev,"failed to allocate driver data\n" ); +dev_err (dev,"failed to allocate driver data\n" );return -ENOMEM ; }mutex_init (&eeti->mutex); - input =input_allocate_device (); + input =devm_input_allocate_device (dev);if (!input) { -dev_err (&client->dev,"Failed to allocate input device.\n" ); - goto err1; +dev_err (dev,"Failed to allocate input device.\n" ); +return -ENOMEM ; }input_set_capability (input,EV_KEY ,BTN_TOUCH );
@@ -194,7 +195,6 @@ static int eeti_ts_probe(struct i2c_client *client, input->name = client->name; input->id.bustype =BUS_I2C ; - input->dev.parent = &client->dev; input->open = eeti_ts_open; input->close = eeti_ts_close;
@@ -203,9 +203,10 @@ static int eeti_ts_probe(struct i2c_client *client, eeti->irq_gpio = pdata->irq_gpio; eeti->irq =gpio_to_irq (pdata->irq_gpio); - err =gpio_request_one (pdata->irq_gpio,GPIOF_IN , client->name); -if (err <0 ) - goto err1; + error =devm_gpio_request_one (dev, pdata->irq_gpio,GPIOF_IN , + client->name); +if (error) +return error; eeti->irq_active_high = pdata->irq_active_high;
@@ -216,15 +217,16 @@ static int eeti_ts_probe(struct i2c_client *client,i2c_set_clientdata (client, eeti);input_set_drvdata (input, eeti); - err =input_register_device (input); -if (err) - goto err2; + error =input_register_device (input); +if (error) +return error; - err =request_irq (eeti->irq, eeti_ts_isr, irq_flags, - client->name, eeti); -if (err) { -dev_err (&client->dev,"Unable to request touchscreen IRQ.\n" ); - goto err3; + error =devm_request_irq (dev, eeti->irq, eeti_ts_isr, irq_flags, + client->name, eeti); +if (error) { +dev_err (dev,"Unable to request touchscreen IRQ: %d\n" , + error); +return error; }/*
@@ -234,33 +236,6 @@ static int eeti_ts_probe(struct i2c_client *client,eeti_ts_stop (eeti);return 0 ; - -err3: -input_unregister_device (input); - input =NULL ;/* so we dont try to free it below */ -err2: -gpio_free (pdata->irq_gpio); -err1: -input_free_device (input); -kfree (eeti); -return err; -} - -static int eeti_ts_remove (struct i2c_client *client) -{ -struct eeti_ts *eeti =i2c_get_clientdata (client); - -free_irq (eeti->irq, eeti); -/* -* eeti_ts_stop() leaves IRQ disabled. We need to re-enable it -* so that device still works if we reload the driver. -*/ -enable_irq (eeti->irq); - -input_unregister_device (eeti->input); -kfree (eeti); - -return 0 ; }static int __maybe_unused eeti_ts_suspend (struct device *dev)
@@ -315,7 +290,6 @@ static struct i2c_driver eeti_ts_driver = { .pm = &eeti_ts_pm, }, .probe = eeti_ts_probe, - .remove = eeti_ts_remove, .id_table = eeti_ts_id, };
Signature · 1 line
2.11.0.483.g087da7b7c-goog
Dmitry Torokhov
maintainerPATCH 6/10 Input: eeti_ts - respect interrupt set in client structure
In reply to Dmitry TorokhovInstead of expecting that GPIO is always interrupt source, let's use interrupt specified in I2C client.
--- arch/arm/mach-pxa/raumfeld.c | 1 + drivers/input/touchscreen/eeti_ts.c | 13 ++++++------- 2 files changed, 7 insertions(+), 7 deletions(-)
arch/arm/mach-pxa/raumfeld.c +1 -0
@@ -973,6 +973,7 @@ static struct eeti_ts_platform_data eeti_ts_pdata = {static struct i2c_board_info raumfeld_controller_i2c_board_info__initdata = { .type ="eeti_ts" , .addr =0x0a , + .irq =PXA_GPIO_TO_IRQ (GPIO_TOUCH_IRQ ), .platform_data = &eeti_ts_pdata, };
drivers/input/touchscreen/eeti_ts.c +6 -7
@@ -49,7 +49,7 @@ struct eeti_ts {struct input_dev *input;struct work_struct work;struct mutex mutex; -int irq_gpio, irq, irq_active_high; +int irq_gpio, irq_active_high; };#define EETI_TS_BITDEPTH (11)
@@ -128,7 +128,7 @@ static irqreturn_t eeti_ts_isr(int irq, void *dev_id)static void eeti_ts_start (struct eeti_ts *eeti) { -enable_irq (eeti->irq); +enable_irq (eeti->client->irq);/* Read the events once to arm the IRQ */ eeti_ts_read (&eeti->work);
@@ -136,7 +136,7 @@ static void eeti_ts_start(struct eeti_ts *eeti)static void eeti_ts_stop (struct eeti_ts *eeti) { -disable_irq (eeti->irq); +disable_irq (eeti->client->irq);cancel_work_sync (&eeti->work); }
@@ -201,7 +201,6 @@ static int eeti_ts_probe(struct i2c_client *client, eeti->client = client; eeti->input = input; eeti->irq_gpio = pdata->irq_gpio; - eeti->irq =gpio_to_irq (pdata->irq_gpio); error =devm_gpio_request_one (dev, pdata->irq_gpio,GPIOF_IN , client->name);
@@ -221,7 +220,7 @@ static int eeti_ts_probe(struct i2c_client *client,if (error)return error; - error =devm_request_irq (dev, eeti->irq, eeti_ts_isr, irq_flags, + error =devm_request_irq (dev, client->irq, eeti_ts_isr, irq_flags, client->name, eeti);if (error) { dev_err(dev, "Unable to request touchscreen IRQ: %d\n",
@@ -252,7 +251,7 @@ static int __maybe_unused eeti_ts_suspend(struct device *dev)mutex_unlock (&input_dev->mutex);if (device_may_wakeup (&client->dev)) -enable_irq_wake (eeti->irq); +enable_irq_wake (client->irq);return 0 ; }
@@ -264,7 +263,7 @@ static int __maybe_unused eeti_ts_resume(struct device *dev)struct input_dev *input_dev = eeti->input;if (device_may_wakeup (&client->dev)) -disable_irq_wake (eeti->irq); +disable_irq_wake (client->irq);mutex_lock (&input_dev->mutex);
Signature · 1 line
2.11.0.483.g087da7b7c-goog
Dmitry Torokhov
maintainerPATCH 7/10 Input: eeti_ts - use gpio_get_value_cansleep
In reply to Dmitry TorokhovWe are reading GPIO state in a non-atomic context (workqueue), so we can use "cansleep" variant, and thus make the driver available on systems where GPIO controllers require sleeping when reading GPIO state.
--- drivers/input/touchscreen/eeti_ts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/touchscreen/eeti_ts.c +1 -1
@@ -63,7 +63,7 @@ struct eeti_ts {static inline int eeti_ts_irq_active (struct eeti_ts *eeti) { -return gpio_get_value (eeti->irq_gpio) == eeti->irq_active_high; +return gpio_get_value_cansleep (eeti->irq_gpio) == eeti->irq_active_high; }static void eeti_ts_read (struct work_struct *work)
Signature · 1 line
2.11.0.483.g087da7b7c-goog
Dmitry Torokhov
maintainerPATCH 8/10 Input: eeti_ts - switch to using threaded interrupt
In reply to Dmitry TorokhovInstead of having standard interrupt handler and manually firing work item to perform I2C reads, let's switch to threaded interrupts, which were designed specifically for this purpose.
--- drivers/input/touchscreen/eeti_ts.c | 79 +++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 43 deletions(-)
drivers/input/touchscreen/eeti_ts.c +36 -43
@@ -47,9 +47,8 @@ MODULE_PARM_DESC(flip_y, "flip y coordinate");struct eeti_ts {struct i2c_client *client;struct input_dev *input; -struct work_struct work; -struct mutex mutex;int irq_gpio, irq_active_high; +bool running; };#define EETI_TS_BITDEPTH (11)
@@ -66,29 +65,11 @@ static inline int eeti_ts_irq_active(struct eeti_ts *eeti)return gpio_get_value_cansleep (eeti->irq_gpio) == eeti->irq_active_high; } -static void eeti_ts_read (struct work_struct *work) +static void eeti_ts_report_event (struct eeti_ts *eeti,u8 *buf) { -char buf[6 ]; -unsigned int x, y, res, pressed, to =100 ; -struct eeti_ts *eeti = - container_of(work, struct eeti_ts, work); - -mutex_lock (&eeti->mutex); - -while (eeti_ts_irq_active (eeti) && --to) -i2c_master_recv (eeti->client, buf,sizeof (buf)); - -if (!to) { -dev_err (&eeti->client->dev, -"unable to clear IRQ - line stuck?\n" ); - goto out; - } +unsigned int res; +u16 x, y; -/* drop non-report packets */ -if (!(buf[0 ] &0x80 )) - goto out; - - pressed = buf[0 ] &REPORT_BIT_PRESSED ; res =REPORT_RES_BITS (buf[0 ] & (REPORT_BIT_AD0 |REPORT_BIT_AD1 )); x =get_unaligned_be16 (&buf[1 ]);
@@ -109,35 +90,48 @@ static void eeti_ts_read(struct work_struct *work)input_report_abs (eeti->input,ABS_X , x);input_report_abs (eeti->input,ABS_Y , y); -input_report_key (eeti->input,BTN_TOUCH , !!pressed); +input_report_key (eeti->input,BTN_TOUCH , buf[0 ] &REPORT_BIT_PRESSED );input_sync (eeti->input); - -out: -mutex_unlock (&eeti->mutex); }static irqreturn_t eeti_ts_isr (int irq,void *dev_id) {struct eeti_ts *eeti = dev_id; +int len; +int error; +char buf[6 ]; -/* postpone I2C transactions as we are atomic */ -schedule_work (&eeti->work); +do { + len =i2c_master_recv (eeti->client, buf,sizeof (buf)); +if (len !=sizeof (buf)) { + error = len <0 ? len : -EIO ; +dev_err (&eeti->client->dev, +"failed to read touchscreen data: %d\n" , + error); +break ; + } + +if (buf[0 ] &0x80 ) { +/* Motion packet */ +eeti_ts_report_event (eeti, buf); + } + }while (eeti->running &&eeti_ts_irq_active (eeti));return IRQ_HANDLED ; }static void eeti_ts_start (struct eeti_ts *eeti) { + eeti->running = true; +wmb ();enable_irq (eeti->client->irq); - -/* Read the events once to arm the IRQ */ -eeti_ts_read (&eeti->work); }static void eeti_ts_stop (struct eeti_ts *eeti) { + eeti->running = false; +wmb ();disable_irq (eeti->client->irq); -cancel_work_sync (&eeti->work); }static int eeti_ts_open (struct input_dev *dev)
@@ -179,8 +173,6 @@ static int eeti_ts_probe(struct i2c_client *client,return -ENOMEM ; } -mutex_init (&eeti->mutex); - input =devm_input_allocate_device (dev);if (!input) {dev_err (dev,"Failed to allocate input device.\n" );
@@ -210,18 +202,15 @@ static int eeti_ts_probe(struct i2c_client *client, eeti->irq_active_high = pdata->irq_active_high; irq_flags = eeti->irq_active_high ? -IRQF_TRIGGER_RISING :IRQF_TRIGGER_FALLING ; +IRQF_TRIGGER_HIGH :IRQF_TRIGGER_LOW ; -INIT_WORK (&eeti->work, eeti_ts_read);i2c_set_clientdata (client, eeti);input_set_drvdata (input, eeti); - error =input_register_device (input); -if (error) -return error; - - error =devm_request_irq (dev, client->irq, eeti_ts_isr, irq_flags, - client->name, eeti); + error =devm_request_threaded_irq (dev, client->irq, +NULL , eeti_ts_isr, + irq_flags |IRQF_ONESHOT , + client->name, eeti);if (error) {dev_err (dev,"Unable to request touchscreen IRQ: %d\n" , error);
@@ -234,6 +223,10 @@ static int eeti_ts_probe(struct i2c_client *client,*/ eeti_ts_stop (eeti); + error =input_register_device (input); +if (error) +return error; +return 0 ; }
Signature · 1 line
2.11.0.483.g087da7b7c-goog
Dmitry Torokhov
maintainerPATCH 9/10 Input: eeti_ts - expect platform code to set interrupt trigger
In reply to Dmitry TorokhovInstead of keying interrupt trigger off GPIO polarity, let's reply on platform code to set it up properly for us.
--- arch/arm/mach-pxa/raumfeld.c | 8 ++++++++ drivers/input/touchscreen/eeti_ts.c | 6 +----- 2 files changed, 9 insertions(+), 5 deletions(-)
arch/arm/mach-pxa/raumfeld.c +8 -0
@@ -21,6 +21,7 @@#include <linux/property.h> #include <linux/platform_device.h> #include <linux/interrupt.h> +#include <linux/irq.h> #include <linux/gpio.h> #include <linux/gpio/machine.h> #include <linux/smsc911x.h>
@@ -1055,6 +1056,7 @@ static void __init raumfeld_common_init(void)static void __init __maybe_unused raumfeld_controller_init (void ) { +struct irq_data *irqd;int ret;pxa3xx_mfp_config (ARRAY_AND_SIZE (raumfeld_controller_pin_config));
@@ -1065,6 +1067,12 @@ static void __init __maybe_unused raumfeld_controller_init(void)platform_device_register (&rotary_encoder_device);spi_register_board_info (ARRAY_AND_SIZE (controller_spi_devices)); + +/* Set up touchscreen interrupt */ + irqd =irq_get_irq_data (PXA_GPIO_TO_IRQ (GPIO_TOUCH_IRQ )); +if (irqd) +irqd_set_trigger_type (irqd,IRQ_TYPE_LEVEL_HIGH ); +i2c_register_board_info (0 , &raumfeld_controller_i2c_board_info,1 ); ret =gpio_request (GPIO_SHUTDOWN_BATT ,"battery shutdown" );
drivers/input/touchscreen/eeti_ts.c +1 -5
@@ -157,7 +157,6 @@ static int eeti_ts_probe(struct i2c_client *client,struct eeti_ts_platform_data *pdata =dev_get_platdata (dev);struct eeti_ts *eeti;struct input_dev *input; -unsigned int irq_flags;int error;/*
@@ -201,15 +200,12 @@ static int eeti_ts_probe(struct i2c_client *client, eeti->irq_active_high = pdata->irq_active_high; - irq_flags = eeti->irq_active_high ? -IRQF_TRIGGER_HIGH :IRQF_TRIGGER_LOW ; -i2c_set_clientdata (client, eeti);input_set_drvdata (input, eeti); error =devm_request_threaded_irq (dev, client->irq,NULL , eeti_ts_isr, - irq_flags |IRQF_ONESHOT , +IRQF_ONESHOT , client->name, eeti);if (error) { dev_err(dev, "Unable to request touchscreen IRQ: %d\n",
Signature · 1 line
2.11.0.483.g087da7b7c-goog
Dmitry Torokhov
maintainerPATCH 10/10 Input: eeti_ts - switch to gpiod API
In reply to Dmitry Torokhovgpiod API allows standard way of specifying GPIO polarity and takes it into account when reading or setting GPIO state. It also allows us to switch to common way of obtaining GPIO descriptor and away form legacy platform data.
--- arch/arm/mach-pxa/raumfeld.c | 14 +++++++++----- drivers/input/touchscreen/eeti_ts.c | 24 +++++++----------------- include/linux/input/eeti_ts.h | 10 ---------- 3 files changed, 16 insertions(+), 32 deletions(-) delete mode 100644 include/linux/input/eeti_ts.h
arch/arm/mach-pxa/raumfeld.c +9 -5
@@ -27,7 +27,6 @@#include <linux/smsc911x.h> #include <linux/input.h> #include <linux/gpio_keys.h> -#include <linux/input/eeti_ts.h> #include <linux/leds.h> #include <linux/w1-gpio.h> #include <linux/sched.h>
@@ -966,16 +965,19 @@ static struct i2c_board_info raumfeld_connector_i2c_board_info __initdata = { .addr = 0x48, }; -static struct eeti_ts_platform_data eeti_ts_pdata = { - .irq_active_high =1 , - .irq_gpio =GPIO_TOUCH_IRQ , +static struct gpiod_lookup_table raumfeld_controller_gpios_table = { + .dev_id ="0-000a" , + .table = { +GPIO_LOOKUP ("gpio-pxa" , +GPIO_TOUCH_IRQ ,"attn" ,GPIO_ACTIVE_HIGH ), + { }, + }, };static struct i2c_board_info raumfeld_controller_i2c_board_info__initdata = { .type ="eeti_ts" , .addr =0x0a , .irq =PXA_GPIO_TO_IRQ (GPIO_TOUCH_IRQ ), - .platform_data = &eeti_ts_pdata, };static struct platform_device *raumfeld_common_devices[] = {
@@ -1073,6 +1075,8 @@ static void __init __maybe_unused raumfeld_controller_init(void)if (irqd)irqd_set_trigger_type (irqd,IRQ_TYPE_LEVEL_HIGH ); +gpiod_add_lookup_table (&raumfeld_controller_gpios_table); +i2c_register_board_info (0 , &raumfeld_controller_i2c_board_info,1 ); ret =gpio_request (GPIO_SHUTDOWN_BATT ,"battery shutdown" );
drivers/input/touchscreen/eeti_ts.c +7 -17
@@ -31,8 +31,7 @@#include <linux/interrupt.h> #include <linux/i2c.h> #include <linux/timer.h> -#include <linux/gpio.h> -#include <linux/input/eeti_ts.h> +#include <linux/gpio/consumer.h> #include <linux/slab.h> #include <asm/unaligned.h>
@@ -47,7 +46,7 @@ MODULE_PARM_DESC(flip_y, "flip y coordinate");struct eeti_ts {struct i2c_client *client;struct input_dev *input; -int irq_gpio, irq_active_high; +struct gpio_desc *attn_gpio;bool running; };
@@ -60,11 +59,6 @@ struct eeti_ts {#define REPORT_BIT_HAS_PRESSURE BIT(6)#define REPORT_RES_BITS (v) (((v) >> 1) + EETI_TS_BITDEPTH) -static inline int eeti_ts_irq_active (struct eeti_ts *eeti) -{ -return gpio_get_value_cansleep (eeti->irq_gpio) == eeti->irq_active_high; -} -static void eeti_ts_report_event (struct eeti_ts *eeti,u8 *buf) {unsigned int res;
@@ -115,7 +109,8 @@ static irqreturn_t eeti_ts_isr(int irq, void *dev_id)/* Motion packet */ eeti_ts_report_event (eeti, buf); } - }while (eeti->running &&eeti_ts_irq_active (eeti)); + }while (eeti->running && + eeti->attn_gpio &&gpiod_get_value_cansleep (eeti->attn_gpio));return IRQ_HANDLED ; }
@@ -154,7 +149,6 @@ static int eeti_ts_probe(struct i2c_client *client, const struct i2c_device_id *idp) {struct device *dev = &client->dev; -struct eeti_ts_platform_data *pdata =dev_get_platdata (dev);struct eeti_ts *eeti;struct input_dev *input;int error;
@@ -191,14 +185,10 @@ static int eeti_ts_probe(struct i2c_client *client, eeti->client = client; eeti->input = input; - eeti->irq_gpio = pdata->irq_gpio; - - error =devm_gpio_request_one (dev, pdata->irq_gpio,GPIOF_IN , - client->name); -if (error) -return error; - eeti->irq_active_high = pdata->irq_active_high; + eeti->attn_gpio =devm_gpiod_get_optional (dev,"attn" ,GPIOD_IN ); +if (IS_ERR (eeti->attn_gpio)) +return PTR_ERR (eeti->attn_gpio);i2c_set_clientdata (client, eeti);input_set_drvdata (input, eeti);
include/linux/input/eeti_ts.h deleted +0 -10
@@ -1,10 +0,0 @@ -#ifndef LINUX_INPUT_EETI_TS_H -#define LINUX_INPUT_EETI_TS_H - -struct eeti_ts_platform_data { -int irq_gpio; -unsigned int irq_active_high; -}; - -#endif /* LINUX_INPUT_EETI_TS_H */ -
Signature · 1 line
2.11.0.483.g087da7b7c-goog
Daniel Mack
maintainerHi Dmitry,
Quoted 9 lines · Dmitry Torokhov
Also rename 'priv' variables to eeti.
Signed-off-by Dmitry Torokhov <[email protected]>---
Hi,
This is all is not tested as I do not have the hardware, so if anyone has raumfeld device that would be awesome.
I have no access to such hardware for the time being, and the platform does not currently boot a mainline kernel either.
So I think we should just merge this set, the changes to the driver look all good to me. If, at some point, I manage to revive that hardware, I can give platform bits a try.
Sorry for not being able to really test this for now.
Thanks,
Daniel
Quoted 277 lines
drivers/input/touchscreen/eeti_ts.c | 115 ++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 57 deletions(-)drivers/input/touchscreen/eeti_ts.c +58
-57@@ -43,7 +43,7 @@ static bool flip_y;module_param (flip_y, bool,0644 );MODULE_PARM_DESC (flip_y,"flip y coordinate" ); -struct eeti_ts_priv { +struct eeti_ts {struct i2c_client *client;struct input_dev *input;struct work_struct work;@@ -60,25 +60,25 @@ struct eeti_ts_priv {#define REPORT_BIT_HAS_PRESSURE (1 << 6)#define REPORT_RES_BITS (v) (((v) >> 1) + EETI_TS_BITDEPTH) -static inline int eeti_ts_irq_active (struct eeti_ts_priv *priv) +static inline int eeti_ts_irq_active (struct eeti_ts *eeti) { -return gpio_get_value (priv->irq_gpio) == priv->irq_active_high; +return gpio_get_value (eeti->irq_gpio) == eeti->irq_active_high; }static void eeti_ts_read (struct work_struct *work) {char buf[6 ];unsigned int x, y, res, pressed, to =100 ; -struct eeti_ts_priv *priv = - container_of(work, struct eeti_ts_priv, work); +struct eeti_ts *eeti = + container_of(work, struct eeti_ts, work); -mutex_lock (&priv->mutex); +mutex_lock (&eeti->mutex); -while (eeti_ts_irq_active (priv) && --to) -i2c_master_recv (priv->client, buf,sizeof (buf)); +while (eeti_ts_irq_active (eeti) && --to) +i2c_master_recv (eeti->client, buf,sizeof (buf));if (!to) { -dev_err (&priv->client->dev, +dev_err (&eeti->client->dev,"unable to clear IRQ - line stuck?\n" ); goto out; }@@ -103,62 +103,62 @@ static void eeti_ts_read(struct work_struct *work) y =EETI_MAXVAL - y;if (buf[0 ] &REPORT_BIT_HAS_PRESSURE ) -input_report_abs (priv->input,ABS_PRESSURE , buf[5 ]); +input_report_abs (eeti->input,ABS_PRESSURE , buf[5 ]); -input_report_abs (priv->input,ABS_X , x); -input_report_abs (priv->input,ABS_Y , y); -input_report_key (priv->input,BTN_TOUCH , !!pressed); -input_sync (priv->input); +input_report_abs (eeti->input,ABS_X , x); +input_report_abs (eeti->input,ABS_Y , y); +input_report_key (eeti->input,BTN_TOUCH , !!pressed); +input_sync (eeti->input); out: -mutex_unlock (&priv->mutex); +mutex_unlock (&eeti->mutex); }static irqreturn_t eeti_ts_isr (int irq,void *dev_id) { -struct eeti_ts_priv *priv = dev_id; +struct eeti_ts *eeti = dev_id;/* postpone I2C transactions as we are atomic */ -schedule_work (&priv->work); +schedule_work (&eeti->work);return IRQ_HANDLED ; } -static void eeti_ts_start (struct eeti_ts_priv *priv) +static void eeti_ts_start (struct eeti_ts *eeti) { -enable_irq (priv->irq); +enable_irq (eeti->irq);/* Read the events once to arm the IRQ */ -eeti_ts_read (&priv->work); +eeti_ts_read (&eeti->work); } -static void eeti_ts_stop (struct eeti_ts_priv *priv) +static void eeti_ts_stop (struct eeti_ts *eeti) { -disable_irq (priv->irq); -cancel_work_sync (&priv->work); +disable_irq (eeti->irq); +cancel_work_sync (&eeti->work); }static int eeti_ts_open (struct input_dev *dev) { -struct eeti_ts_priv *priv =input_get_drvdata (dev); +struct eeti_ts *eeti =input_get_drvdata (dev); -eeti_ts_start (priv); +eeti_ts_start (eeti);return 0 ; }static void eeti_ts_close (struct input_dev *dev) { -struct eeti_ts_priv *priv =input_get_drvdata (dev); +struct eeti_ts *eeti =input_get_drvdata (dev); -eeti_ts_stop (priv); +eeti_ts_stop (eeti); }static int eeti_ts_probe (struct i2c_client *client,const struct i2c_device_id *idp) {struct eeti_ts_platform_data *pdata =dev_get_platdata (&client->dev); -struct eeti_ts_priv *priv; +struct eeti_ts *eeti;struct input_dev *input;unsigned int irq_flags;int err = -ENOMEM ;@@ -170,13 +170,14 @@ static int eeti_ts_probe(struct i2c_client *client,* for interrupts to occur. */ - priv =kzalloc (sizeof (*priv),GFP_KERNEL ); -if (!priv) { + eeti =kzalloc (sizeof (*eeti),GFP_KERNEL ); +if (!eeti) {dev_err (&client->dev,"failed to allocate driver data\n" );return -ENOMEM ; } -mutex_init (&priv->mutex); +mutex_init (&eeti->mutex); + input =input_allocate_device ();if (!input) {dev_err (&client->dev,"Failed to allocate input device.\n" );@@ -196,30 +197,30 @@ static int eeti_ts_probe(struct i2c_client *client, input->open = eeti_ts_open; input->close = eeti_ts_close; - priv->client = client; - priv->input = input; - priv->irq_gpio = pdata->irq_gpio; - priv->irq =gpio_to_irq (pdata->irq_gpio); + eeti->client = client; + eeti->input = input; + eeti->irq_gpio = pdata->irq_gpio; + eeti->irq =gpio_to_irq (pdata->irq_gpio); err =gpio_request_one (pdata->irq_gpio,GPIOF_IN , client->name);if (err <0 ) goto err1; - priv->irq_active_high = pdata->irq_active_high; + eeti->irq_active_high = pdata->irq_active_high; - irq_flags = priv->irq_active_high ? + irq_flags = eeti->irq_active_high ?IRQF_TRIGGER_RISING :IRQF_TRIGGER_FALLING ; -INIT_WORK (&priv->work, eeti_ts_read); -i2c_set_clientdata (client, priv); -input_set_drvdata (input, priv); +INIT_WORK (&eeti->work, eeti_ts_read); +i2c_set_clientdata (client, eeti); +input_set_drvdata (input, eeti); err =input_register_device (input);if (err) goto err2; - err =request_irq (priv->irq, eeti_ts_isr, irq_flags, - client->name, priv); + err =request_irq (eeti->irq, eeti_ts_isr, irq_flags, + client->name, eeti);if (err) {dev_err (&client->dev,"Unable to request touchscreen IRQ.\n" ); goto err3;@@ -229,7 +230,7 @@ static int eeti_ts_probe(struct i2c_client *client,* Disable the device for now. It will be enabled once the * input device is opened. */ -eeti_ts_stop (priv); +eeti_ts_stop (eeti);return 0 ;@@ -240,23 +241,23 @@ static int eeti_ts_probe(struct i2c_client *client,gpio_free (pdata->irq_gpio); err1:input_free_device (input); -kfree (priv); +kfree (eeti);return err; }static int eeti_ts_remove (struct i2c_client *client) { -struct eeti_ts_priv *priv =i2c_get_clientdata (client); +struct eeti_ts *eeti =i2c_get_clientdata (client); -free_irq (priv->irq, priv); +free_irq (eeti->irq, eeti);/* * eeti_ts_stop() leaves IRQ disabled. We need to re-enable it * so that device still works if we reload the driver. */ -enable_irq (priv->irq); +enable_irq (eeti->irq); -input_unregister_device (priv->input); -kfree (priv); +input_unregister_device (eeti->input); +kfree (eeti);return 0 ; }@@ -264,18 +265,18 @@ static int eeti_ts_remove(struct i2c_client *client)static int __maybe_unused eeti_ts_suspend (struct device *dev) {struct i2c_client *client =to_i2c_client (dev); -struct eeti_ts_priv *priv =i2c_get_clientdata (client); -struct input_dev *input_dev = priv->input; +struct eeti_ts *eeti =i2c_get_clientdata (client); +struct input_dev *input_dev = eeti->input;mutex_lock (&input_dev->mutex);if (input_dev->users) -eeti_ts_stop (priv); +eeti_ts_stop (eeti);mutex_unlock (&input_dev->mutex);if (device_may_wakeup (&client->dev)) -enable_irq_wake (priv->irq); +enable_irq_wake (eeti->irq);return 0 ; }@@ -283,16 +284,16 @@ static int __maybe_unused eeti_ts_suspend(struct device *dev)static int __maybe_unused eeti_ts_resume (struct device *dev) {struct i2c_client *client =to_i2c_client (dev); -struct eeti_ts_priv *priv =i2c_get_clientdata (client); -struct input_dev *input_dev = priv->input; +struct eeti_ts *eeti =i2c_get_clientdata (client); +struct input_dev *input_dev = eeti->input;if (device_may_wakeup (&client->dev)) -disable_irq_wake (priv->irq); +disable_irq_wake (eeti->irq);mutex_lock (&input_dev->mutex);if (input_dev->users) -eeti_ts_start (priv); +eeti_ts_start (eeti);mutex_unlock (&input_dev->mutex);
Dmitry Torokhov
maintainerQuoted 13 lines · Daniel Mack
Hi Dmitry,
Quoted 9 lines · Dmitry Torokhov
Also rename 'priv' variables to eeti.
Signed-off-by Dmitry Torokhov <[email protected]>---
Hi,
This is all is not tested as I do not have the hardware, so if anyone has raumfeld device that would be awesome.
Quoted 6 lines
I have no access to such hardware for the time being, and the platform does not currently boot a mainline kernel either.
So I think we should just merge this set, the changes to the driver look all good to me. If, at some point, I manage to revive that hardware, I can give platform bits a try.
OK, I'll be putting you as reviewed-by then.
Thank you for taking a look.
Signature · 1 line
Dmitry