Input: auo_pixcir_ts - add devicetree support
Subsystems (4)
cover Input: auo_pixcir_ts - add devicetree support
Some small cleanups needed and the parsing of the dt data.
Heiko Stuebner (4):
Input: auo-pixcir-ts - set input direction for interrupt gpio
Input: auo-pixcir-ts - handle reset gpio directly
Input: auo_pixcir_ts - keep own pointer to platform_data
Input: auo_pixcir_ts - add devicetree support
.../bindings/input/touchscreen/auo_pixcir_ts.txt | 30 ++++++ drivers/input/touchscreen/auo-pixcir-ts.c | 104 +++++++++++++++++-- include/linux/input/auo-pixcir-ts.h | 4 +- 3 files changed, 124 insertions(+), 14 deletions(-) create mode 100644
Documentation/devicetree/bindings/input/touchscreen/auo_pixcir_ts.txt
Signature · 1 line
1.7.2.3
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/4 Input: auo-pixcir-ts - set input direction for interrupt gpio
Previously the gpio was not configured at all.
--- drivers/input/touchscreen/auo-pixcir-ts.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
drivers/input/touchscreen/auo-pixcir-ts.c +8 -0
@@ -504,6 +504,13 @@ static int auo_pixcir_probe(struct i2c_client *client, goto err_gpio_int; } + ret =gpio_direction_input (pdata->gpio_int); +if (ret) { +dev_err (&client->dev,"setting direction of gpio %d failed %d\n" , + pdata->gpio_int, ret); + goto err_gpio_dir; + } +if (pdata->init_hw) pdata->init_hw (client);
@@ -592,6 +599,7 @@ err_fw_vers: err_input_alloc:if (pdata->exit_hw) pdata->exit_hw (client); +err_gpio_dir:gpio_free (pdata->gpio_int); err_gpio_int:kfree (ts);
Signature · 1 line
1.7.2.3
PATCH 2/4 Input: auo-pixcir-ts - handle reset gpio directly
In reply to a message not in the archiveDevicetree based platforms don't handle device callbacks very well and until now no board has come along that needs more extended hwinit than pulling the rst gpio high.
Therefore pull the reset handling directly into the driver and remove the callbacks from the driver.
If extended device setup is needed at some later point, power-sequences would probably be the solution of choice.
--- drivers/input/touchscreen/auo-pixcir-ts.c | 26 ++++++++++++++++++++------ include/linux/input/auo-pixcir-ts.h | 4 +--- 2 files changed, 21 insertions(+), 9 deletions(-)
drivers/input/touchscreen/auo-pixcir-ts.c +20 -6
@@ -511,8 +511,21 @@ static int auo_pixcir_probe(struct i2c_client *client, goto err_gpio_dir; } -if (pdata->init_hw) - pdata->init_hw (client); + ret =gpio_request (pdata->gpio_rst,"auo_pixcir_ts_rst" ); +if (ret) { +dev_err (&client->dev,"request of gpio %d failed, %d\n" , + pdata->gpio_rst, ret); + goto err_gpio_dir; + } + + ret =gpio_direction_output (pdata->gpio_rst,1 ); +if (ret) { +dev_err (&client->dev,"setting direction of gpio %d failed %d\n" , + pdata->gpio_rst, ret); + goto err_gpio_rst; + } + +msleep (200 ); ts->client = client; ts->touch_ind_mode =0 ;
@@ -597,8 +610,9 @@ err_input_register: err_fw_vers:input_free_device (input_dev); err_input_alloc: -if (pdata->exit_hw) - pdata->exit_hw (client); +gpio_set_value (pdata->gpio_rst,0 ); +err_gpio_rst: +gpio_free (pdata->gpio_rst); err_gpio_dir:gpio_free (pdata->gpio_int); err_gpio_int:
@@ -616,8 +630,8 @@ static int auo_pixcir_remove(struct i2c_client *client)input_unregister_device (ts->input); -if (pdata->exit_hw) - pdata->exit_hw (client); +gpio_set_value (pdata->gpio_rst,0 ); +gpio_free (pdata->gpio_rst);gpio_free (pdata->gpio_int);
include/linux/input/auo-pixcir-ts.h +1 -3
@@ -43,12 +43,10 @@*/ struct auo_pixcir_ts_platdata {int gpio_int; +int gpio_rst;int int_setting; -void (*init_hw)(struct i2c_client *); -void (*exit_hw)(struct i2c_client *); -unsigned int x_max;unsigned int y_max; };
Signature · 1 line
1.7.2.3
PATCH 3/4 Input: auo_pixcir_ts - keep own pointer to platform_data
In reply to a message not in the archiveWhen supporting devicetree the platformdata may not necessarily come from the dev but may be generated in the driver instead.
Therefore keep the pointer in the driver struct instead of using dev.platform_data.
--- drivers/input/touchscreen/auo-pixcir-ts.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
drivers/input/touchscreen/auo-pixcir-ts.c +6 -5
@@ -111,6 +111,7 @@struct auo_pixcir_ts {struct i2c_client *client;struct input_dev *input; +const struct auo_pixcir_ts_platdata *pdata;char phys[32 ];/* special handling for touch_indicate interupt mode */
@@ -132,7 +133,7 @@ static int auo_pixcir_collect_data(struct auo_pixcir_ts *ts, struct auo_point_t *point) {struct i2c_client *client = ts->client; -const struct auo_pixcir_ts_platdata *pdata = client->dev.platform_data; +const struct auo_pixcir_ts_platdata *pdata = ts->pdata;uint8_t raw_coord[8 ];uint8_t raw_area[4 ];int i, ret;
@@ -178,8 +179,7 @@ static int auo_pixcir_collect_data(struct auo_pixcir_ts *ts,static irqreturn_t auo_pixcir_interrupt (int irq,void *dev_id) {struct auo_pixcir_ts *ts = dev_id; -struct i2c_client *client = ts->client; -const struct auo_pixcir_ts_platdata *pdata = client->dev.platform_data; +const struct auo_pixcir_ts_platdata *pdata = ts->pdata;struct auo_point_t point[AUO_PIXCIR_REPORT_POINTS ];int i;int ret;
@@ -290,7 +290,7 @@ static int auo_pixcir_int_config(struct auo_pixcir_ts *ts, int int_setting) {struct i2c_client *client = ts->client; -struct auo_pixcir_ts_platdata *pdata = client->dev.platform_data; +const struct auo_pixcir_ts_platdata *pdata = ts->pdata;int ret; ret =i2c_smbus_read_byte_data (client,AUO_PIXCIR_REG_INT_SETTING );
@@ -527,6 +527,7 @@ static int auo_pixcir_probe(struct i2c_client *client,msleep (200 ); + ts->pdata = pdata; ts->client = client; ts->touch_ind_mode =0 ;init_waitqueue_head (&ts->wait);
@@ -624,7 +625,7 @@ err_gpio_int:static int auo_pixcir_remove (struct i2c_client *client) {struct auo_pixcir_ts *ts =i2c_get_clientdata (client); -const struct auo_pixcir_ts_platdata *pdata = client->dev.platform_data; +const struct auo_pixcir_ts_platdata *pdata = ts->pdata;free_irq (client->irq, ts);
Signature · 1 line
1.7.2.3
PATCH 4/4 Input: auo_pixcir_ts - add devicetree support
In reply to a message not in the archiveAdd the necessary code to create the needed platformdata from devicetree informations.
The interrupt mode of the chip is not set via devicetree, as it is not a property of the hardware but instead only a preferred type of operation. This should probably be made settable via configfs in the future. The option set as default is the mode the datasheet mentions as default.
--- .../bindings/input/touchscreen/auo_pixcir_ts.txt | 30 ++++++++++ drivers/input/touchscreen/auo-pixcir-ts.c | 59 ++++++++++++++++++++ 2 files changed, 89 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/auo_pixcir_ts.txt
Documentation/devicetree/bindings/input/touchscreen/auo_pixcir_ts.txt new file +30 -0
@@ -0,0 +1,30 @@ +* AUO in-cell touchscreen controller using Pixcir sensors + +Required properties: +- compatible: must be "auo,auo_pixcir_ts" +- reg: I2C address of the chip +- interrupts: interrupt to which the chip is connected +- gpios: gpios the chip is connected to + first one is the interrupt gpio and second one the reset gpio +- x-size: horizontal resolution of touchscreen +- y-size: vertical resolution of touchscreen + +Example: + + i2c@00000000 { + /* ... */ + + auo_pixcir_ts@5c { + compatible = "auo,auo_pixcir_ts"; + reg = <0x5c>; + interrupts = <2 0>; + + gpios = <&gpf 2 0 2>, /* INT */ + <&gpf 5 1 0>; /* RST */ + + x-size = <800>; + y-size = <600>; + }; + + /* ... */ + };
drivers/input/touchscreen/auo-pixcir-ts.c +59 -0
88 lines not on this page · raw message
Signature · 1 line
1.7.2.3
Dmitry Torokhov
maintainerHi Heiko,
Quoted 5 lines · Heiko Stübner
(quoted diff) +5
-0+static struct auo_pixcir_ts_platdata *auo_pixcir_parse_dt(struct device *dev) +{ + struct auo_pixcir_ts_platdata *pdata = NULL; + +#ifdef CONFIG_OF
Review
Quoted 10 lines
(quoted diff) +10
-0+ struct device_node *np = dev->of_node; + + if (!np) + return NULL; + + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) { + dev_err(dev, "failed to allocate platform data\n"); + return NULL; + }
I disike #ifdefs in the middle of the code, also it would be nice if we signal the proper error instead of always using -EINVAL when there are issues with platform/DT data.
How about the version of the patch below?
Thanks.
Signature · 21 lines
Dmitry Input: auo_pixcir_ts - add devicetree support From: Heiko Stübner <[email protected]> Add the necessary code to create the needed platformdata from devicetree informations. The interrupt mode of the chip is not set via devicetree, as it is not a property of the hardware but instead only a preferred type of operation. This should probably be made settable via configfs in the future. The option set as default is the mode the datasheet mentions as default. Signed-off-by: Heiko Stuebner <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]> --- .../bindings/input/touchscreen/auo_pixcir_ts.txt | 30 ++++++++ drivers/input/touchscreen/auo-pixcir-ts.c | 74 +++++++++++++++++++- 2 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/auo_pixcir_ts.txt
Documentation/devicetree/bindings/input/touchscreen/auo_pixcir_ts.txt new file +30 -0
@@ -0,0 +1,30 @@ +* AUO in-cell touchscreen controller using Pixcir sensors + +Required properties: +- compatible: must be "auo,auo_pixcir_ts" +- reg: I2C address of the chip +- interrupts: interrupt to which the chip is connected +- gpios: gpios the chip is connected to + first one is the interrupt gpio and second one the reset gpio +- x-size: horizontal resolution of touchscreen +- y-size: vertical resolution of touchscreen + +Example: + + i2c@00000000 { + /* ... */ + + auo_pixcir_ts@5c { + compatible = "auo,auo_pixcir_ts"; + reg = <0x5c>; + interrupts = <2 0>; + + gpios = <&gpf 2 0 2>, /* INT */ + <&gpf 5 1 0>; /* RST */ + + x-size = <800>; + y-size = <600>; + }; + + /* ... */ + };
drivers/input/touchscreen/auo-pixcir-ts.c +69 -5
105 lines not on this page · raw message
--
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
A message that is not in the archive (sent off-list or not yet received): 20130224080015.GA20590-WlK9ik9hQGAhIp7JRqBPierSzoNAToWh@public.gmane.org
Hi Dmitry,
Am Sonntag, 24. Februar 2013, 09:00:15 schrieb Dmitry Torokhov:
Quoted 23 lines
Hi Heiko,
Quoted 5 lines · Heiko Stübner
+static struct
auo_pixcir_ts_platdata*auo_pixcir_parse_dt(struct device *dev) +{drivers/input/touchscreen/auo-pixcir-ts.c +3
-0+struct auo_pixcir_ts_platdata *pdata =NULL ; + +#ifdef CONFIG_OF drivers/input/touchscreen/auo-pixcir-ts.c unlock: · line 500
Quoted 10 lines
drivers/input/touchscreen/auo-pixcir-ts.c +10
-0+struct device_node *np = dev->of_node; + +if (!np) +return NULL ; + + pdata =devm_kzalloc (dev,sizeof (*pdata),GFP_KERNEL ); +if (!pdata) { +dev_err (dev,"failed to allocate platform data\n" ); +return NULL ; + }I disike #ifdefs in the middle of the code, also it would be nice if we signal the proper error instead of always using
-EINVALwhen there are issues with platform/DT data.
Quoted 1 line
How about the version of the patch below?
I tested it and everything of course still works :-) .
I have no real preference for one way or the other. I had seen both types in different drivers and could not really decide which I like better, so I'm fine with using your variant instead.
Thanks
Heiko
Dmitry Torokhov
maintainerQuoted 26 lines · Heiko Stübner
Hi Dmitry,
Am Sonntag, 24. Februar 2013, 09:00:15 schrieb Dmitry Torokhov:
Quoted 23 lines
Hi Heiko,
Quoted 5 lines · Heiko Stübner
+static struct
auo_pixcir_ts_platdata*auo_pixcir_parse_dt(struct device *dev) +{(quoted diff) +3
-0+ struct auo_pixcir_ts_platdata *pdata = NULL; + +#ifdef CONFIG_OFReview
Quoted 10 lines
(quoted diff) +10
-0+ struct device_node *np = dev->of_node; + + if (!np) + return NULL; + + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) { + dev_err(dev, "failed to allocate platform data\n"); + return NULL; + }I disike #ifdefs in the middle of the code, also it would be nice if we signal the proper error instead of always using
-EINVALwhen there are issues with platform/DT data.
Quoted 3 lines
Quoted 1 line
How about the version of the patch below?
I tested it and everything of course still works :-) .
OK, great, then I will queue these for the next merge window.
Could you also try this patch (it however needs attached patch enhancing devres to support custom actions).
Thanks.
Signature · 12 lines
Dmitry Input: auo-pixer-ts - switch to using managed resources From: Dmitry Torokhov <[email protected]> This simplifier error unwinding and device teardown. Signed-off-by: Dmitry Torokhov <[email protected]> --- drivers/input/touchscreen/auo-pixcir-ts.c | 162 ++++++++++++----------------- 1 file changed, 68 insertions(+), 94 deletions(-)
drivers/input/touchscreen/auo-pixcir-ts.c +68 -94
@@ -533,13 +533,21 @@ static struct auo_pixcir_ts_platdata *auo_pixcir_parse_dt(struct device *dev) }#endif +static void auo_pixcir_reset (void *data) +{ +struct auo_pixcir_ts *ts = data; + +gpio_set_value (ts->pdata->gpio_rst,0 ); +} +static int auo_pixcir_probe (struct i2c_client *client, -const struct i2c_device_id *id) +const struct i2c_device_id *id) {const struct auo_pixcir_ts_platdata *pdata;struct auo_pixcir_ts *ts;struct input_dev *input_dev; -int ret; +int version; +int error; pdata =dev_get_platdata (&client->dev);if (!pdata) {
@@ -548,60 +556,30 @@ static int auo_pixcir_probe(struct i2c_client *client,return PTR_ERR (pdata); } - ts =kzalloc (sizeof (struct auo_pixcir_ts ),GFP_KERNEL ); + ts =devm_kzalloc (&client->dev, +sizeof (struct auo_pixcir_ts ),GFP_KERNEL );if (!ts)return -ENOMEM ; - ret =gpio_request (pdata->gpio_int,"auo_pixcir_ts_int" ); -if (ret) { -dev_err (&client->dev,"request of gpio %d failed, %d\n" , - pdata->gpio_int, ret); - goto err_gpio_int; - } - - ret =gpio_direction_input (pdata->gpio_int); -if (ret) { -dev_err (&client->dev,"setting direction of gpio %d failed %d\n" , - pdata->gpio_int, ret); - goto err_gpio_dir; - } - - ret =gpio_request (pdata->gpio_rst,"auo_pixcir_ts_rst" ); -if (ret) { -dev_err (&client->dev,"request of gpio %d failed, %d\n" , - pdata->gpio_rst, ret); - goto err_gpio_dir; - } - - ret =gpio_direction_output (pdata->gpio_rst,1 ); -if (ret) { -dev_err (&client->dev,"setting direction of gpio %d failed %d\n" , - pdata->gpio_rst, ret); - goto err_gpio_rst; + input_dev =devm_input_allocate_device (&client->dev); +if (!input_dev) { +dev_err (&client->dev,"could not allocate input device\n" ); +return -ENOMEM ; } -msleep (200 ); - ts->pdata = pdata; ts->client = client; + ts->input = input_dev; ts->touch_ind_mode =0 ; + ts->stopped = true;init_waitqueue_head (&ts->wait);snprintf (ts->phys,sizeof (ts->phys),"%s/input0" ,dev_name (&client->dev)); - input_dev =input_allocate_device (); -if (!input_dev) { -dev_err (&client->dev,"could not allocate input device\n" ); - goto err_input_alloc; - } - - ts->input = input_dev; - input_dev->name ="AUO-Pixcir touchscreen" ; input_dev->phys = ts->phys; input_dev->id.bustype =BUS_I2C ; - input_dev->dev.parent = &client->dev; input_dev->open = auo_pixcir_input_open; input_dev->close = auo_pixcir_input_close;
@@ -626,72 +604,69 @@ static int auo_pixcir_probe(struct i2c_client *client, AUO_PIXCIR_MAX_AREA, 0, 0);input_set_abs_params (input_dev,ABS_MT_ORIENTATION ,0 ,1 ,0 ,0 ); - ret =i2c_smbus_read_byte_data (client,AUO_PIXCIR_REG_VERSION ); -if (ret <0 ) - goto err_fw_vers; -dev_info (&client->dev,"firmware version 0x%X\n" , ret); - - ret =auo_pixcir_int_config (ts, pdata->int_setting); -if (ret) - goto err_fw_vers; -input_set_drvdata (ts->input, ts); - ts->stopped = true; - ret =request_threaded_irq (client->irq,NULL , auo_pixcir_interrupt, -IRQF_TRIGGER_RISING |IRQF_ONESHOT , - input_dev->name, ts); -if (ret) { -dev_err (&client->dev,"irq %d requested failed\n" , client->irq); - goto err_fw_vers; + error =devm_gpio_request_one (&client->dev, pdata->gpio_int, +GPIOF_DIR_IN ,"auo_pixcir_ts_int" ); +if (error) { +dev_err (&client->dev,"request of gpio %d failed, %d\n" , + pdata->gpio_int, error); +return error; } -/* stop device and put it into deep sleep until it is opened */ - ret =auo_pixcir_stop (ts); -if (ret <0 ) - goto err_input_register; - - ret =input_register_device (input_dev); -if (ret) { -dev_err (&client->dev,"could not register input device\n" ); - goto err_input_register; + error =devm_gpio_request_one (&client->dev, pdata->gpio_rst, +GPIOF_DIR_OUT |GPIOF_INIT_HIGH , +"auo_pixcir_ts_int" ); +if (error) { +dev_err (&client->dev,"request of gpio %d failed, %d\n" , + pdata->gpio_rst, error); +return error; } -i2c_set_clientdata (client, ts); - -return 0 ; - -err_input_register: -free_irq (client->irq, ts); -err_fw_vers: -input_free_device (input_dev); -err_input_alloc: -gpio_set_value (pdata->gpio_rst,0 ); -err_gpio_rst: -gpio_free (pdata->gpio_rst); -err_gpio_dir: -gpio_free (pdata->gpio_int); -err_gpio_int: -kfree (ts); + error =devm_add_action (&client->dev, auo_pixcir_reset, ts); +if (error) { +auo_pixcir_reset (ts); +dev_err (&client->dev,"failed to register xxx action, %d\n" , + error); +return error; + } -return ret; -} +msleep (200 ); -static int auo_pixcir_remove (struct i2c_client *client) -{ -struct auo_pixcir_ts *ts =i2c_get_clientdata (client); -const struct auo_pixcir_ts_platdata *pdata = ts->pdata; + version =i2c_smbus_read_byte_data (client,AUO_PIXCIR_REG_VERSION ); +if (version <0 ) { + error = version; +return error; + } -free_irq (client->irq, ts); +dev_info (&client->dev,"firmware version 0x%X\n" , version); -input_unregister_device (ts->input); + error =auo_pixcir_int_config (ts, pdata->int_setting); +if (error) +return error; -gpio_set_value (pdata->gpio_rst,0 ); -gpio_free (pdata->gpio_rst); + error =request_threaded_irq (client->irq,NULL , auo_pixcir_interrupt, +IRQF_TRIGGER_RISING |IRQF_ONESHOT , + input_dev->name, ts); +if (error) { +dev_err (&client->dev,"irq %d requested failed, %d\n" , + client->irq, error); +return error; + } -gpio_free (pdata->gpio_int); +/* stop device and put it into deep sleep until it is opened */ + error =auo_pixcir_stop (ts); +if (error) +return error; + + error =input_register_device (input_dev); +if (error) { +dev_err (&client->dev,"could not register input device, %d\n" , + error); +return error; + } -kfree (ts); +i2c_set_clientdata (client, ts);return 0 ; }
@@ -718,7 +693,6 @@ static struct i2c_driver auo_pixcir_driver = { .of_match_table = of_match_ptr(auo_pixcir_ts_dt_idtable), }, .probe = auo_pixcir_probe, - .remove = auo_pixcir_remove, .id_table = auo_pixcir_idtable, };
devres: allow adding custom actions to the stack
From: Dmitry Torokhov <[email protected]>
Sometimes drivers need to execute one-off actions in their error handling or device teardown paths. An example would be toggling a GPIO line to reset the controlled device into predefined state.
To allow performing such actions when using managed resources let's allow adding them to stack/group of devres resources.
--- drivers/base/devres.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/device.h | 4 +++ 2 files changed, 78 insertions(+)
drivers/base/devres.c +74 -0
80 lines not on this page · raw message
include/linux/device.h +4 -0
@@ -578,6 +578,10 @@ extern void devm_kfree(struct device *dev, void *p);void __iomem *devm_request_and_ioremap (struct device *dev,struct resource *res); +/* allows to add/remove a custom action to devres stack */ +int devm_add_action (struct device *dev,void (*action)(void *),void *data); +void devm_remove_action (struct device *dev,void (*action)(void *),void *data); +struct device_dma_parameters {/* * a low level driver may set these to teach IOMMU code about
Heiko Stübner
Tested-byAm Montag, 25. Februar 2013, 04:06:41 schrieb Dmitry Torokhov:
Quoted 29 lines · Heiko Stübner
Quoted 28 lines
Hi Dmitry,
Am Sonntag, 24. Februar 2013, 09:00:15 schrieb Dmitry Torokhov:
Quoted 24 lines
Hi Heiko,
Quoted 5 lines · Heiko Stübner
+static struct
auo_pixcir_ts_platdata*auo_pixcir_parse_dt(struct device *dev) +{(quoted diff) +3
-0+ struct auo_pixcir_ts_platdata *pdata = NULL; + +#ifdef CONFIG_OFReview
Quoted 10 lines
(quoted diff) +10
-0+ struct device_node *np = dev->of_node; + + if (!np) + return NULL; + + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) { + dev_err(dev, "failed to allocate platform data\n"); + return NULL; + }I disike #ifdefs in the middle of the code, also it would be nice if we signal the proper error instead of always using
-EINVALwhen there are issues with platform/DT data.How about the version of the patch below?
Quoted 8 lines
Quoted 1 line
I tested it and everything of course still works :-) .
OK, great, then I will queue these for the next merge window.
Could you also try this patch (it however needs attached patch enhancing devres to support custom actions).
Thanks.
In general looks really nice and also works. I have some small nitpicks (patch desc, reset gpio naming) and it will also need to use devm_request_threaded_irq to get the irq correctly freed on removal. [all also marked at the corresponding places below]
Otherwise:
Heiko
Quoted 5 lines
Input: auo-pixer-ts - switch to using managed resources
From: Dmitry Torokhov <[email protected]>
This simplifier error unwinding and device teardown.
^^ simplifies
Quoted 166 lines
Signed-off-by Dmitry Torokhov <[email protected]>---
drivers/input/touchscreen/auo-pixcir-ts.c | 162++++++++++++----------------- 1 file changed, 68 insertions(+), 94 deletions(-)
(quoted diff) +0
-0
b/drivers/input/touchscreen/auo-pixcir-ts.cindex dfa6d54..f4ba6ffa 100644drivers/input/touchscreen/auo-pixcir-ts.c +24
-55@@ -533,13 +533,21 @@ static struct auo_pixcir_ts_platdata *auo_pixcir_parse_dt(struct device *dev) }#endif +static void auo_pixcir_reset (void *data) +{ +struct auo_pixcir_ts *ts = data; + +gpio_set_value (ts->pdata->gpio_rst,0 ); +} +static int auo_pixcir_probe (struct i2c_client *client, -const struct i2c_device_id *id) +const struct i2c_device_id *id) {const struct auo_pixcir_ts_platdata *pdata;struct auo_pixcir_ts *ts;struct input_dev *input_dev; -int ret; +int version; +int error; pdata =dev_get_platdata (&client->dev);if (!pdata) {@@ -548,60 +556,30 @@ static int auo_pixcir_probe(struct i2c_client *client, return PTR_ERR(pdata); } - ts =kzalloc (sizeof (struct auo_pixcir_ts ),GFP_KERNEL ); + ts =devm_kzalloc (&client->dev, +sizeof (struct auo_pixcir_ts ),GFP_KERNEL );if (!ts)return -ENOMEM ; - ret =gpio_request (pdata->gpio_int,"auo_pixcir_ts_int" ); -if (ret) { -dev_err (&client->dev,"request of gpio %d failed, %d\n" , - pdata->gpio_int, ret); - goto err_gpio_int; - } - - ret =gpio_direction_input (pdata->gpio_int); -if (ret) { - dev_err(&client->dev, "setting direction of gpio %d failed %d\n", - pdata->gpio_int, ret); - goto err_gpio_dir; - } - - ret =gpio_request (pdata->gpio_rst,"auo_pixcir_ts_rst" ); -if (ret) { -dev_err (&client->dev,"request of gpio %d failed, %d\n" , - pdata->gpio_rst, ret); - goto err_gpio_dir; - } - - ret =gpio_direction_output (pdata->gpio_rst,1 ); -if (ret) { - dev_err(&client->dev, "setting direction of gpio %d failed %d\n", - pdata->gpio_rst, ret); - goto err_gpio_rst; + input_dev = devm_input_allocate_device(&client->dev); +if (!input_dev) { +dev_err (&client->dev,"could not allocate input device\n" ); +return -ENOMEM ; } -msleep (200 ); - ts->pdata = pdata; ts->client = client; + ts->input = input_dev; ts->touch_ind_mode =0 ; + ts->stopped = true;init_waitqueue_head (&ts->wait);snprintf (ts->phys,sizeof (ts->phys),"%s/input0" ,dev_name (&client->dev)); - input_dev =input_allocate_device (); -if (!input_dev) { -dev_err (&client->dev,"could not allocate input device\n" ); - goto err_input_alloc; - } - - ts->input = input_dev; - input_dev->name ="AUO-Pixcir touchscreen" ; input_dev->phys = ts->phys; input_dev->id.bustype =BUS_I2C ; - input_dev->dev.parent = &client->dev; input_dev->open = auo_pixcir_input_open; input_dev->close = auo_pixcir_input_close;@@ -626,72 +604,69 @@ static int auo_pixcir_probe(struct i2c_client *client, AUO_PIXCIR_MAX_AREA, 0, 0);input_set_abs_params (input_dev,ABS_MT_ORIENTATION ,0 ,1 ,0 ,0 ); - ret =i2c_smbus_read_byte_data (client,AUO_PIXCIR_REG_VERSION ); -if (ret <0 ) - goto err_fw_vers; -dev_info (&client->dev,"firmware version 0x%X\n" , ret); - - ret =auo_pixcir_int_config (ts, pdata->int_setting); -if (ret) - goto err_fw_vers; -input_set_drvdata (ts->input, ts); - ts->stopped = true; - ret =request_threaded_irq (client->irq,NULL , auo_pixcir_interrupt, -IRQF_TRIGGER_RISING |IRQF_ONESHOT , - input_dev->name, ts); -if (ret) { -dev_err (&client->dev,"irq %d requested failed\n" , client->irq); - goto err_fw_vers; + error =devm_gpio_request_one (&client->dev, pdata->gpio_int, +GPIOF_DIR_IN ,"auo_pixcir_ts_int" ); +if (error) { +dev_err (&client->dev,"request of gpio %d failed, %d\n" , + pdata->gpio_int, error); +return error; } -/* stop device and put it into deep sleep until it is opened */ - ret =auo_pixcir_stop (ts);
drivers/input/touchscreen/auo-pixcir-ts.c static int auo_pixcir_probe(struct i2c_client · line 626
Quoted 10 lines
drivers/input/touchscreen/auo-pixcir-ts.c +3
-7-if (ret <0 ) - goto err_input_register; - - ret =input_register_device (input_dev); -if (ret) { -dev_err (&client->dev,"could not register input device\n" ); - goto err_input_register; + error =devm_gpio_request_one (&client->dev, pdata->gpio_rst, +GPIOF_DIR_OUT |GPIOF_INIT_HIGH , +"auo_pixcir_ts_int" );
^^ auo_pixcir_ts_rst
Quoted 46 lines
drivers/input/touchscreen/auo-pixcir-ts.c +16
-23+if (error) { +dev_err (&client->dev,"request of gpio %d failed, %d\n" , + pdata->gpio_rst, error); +return error; } -i2c_set_clientdata (client, ts); - -return 0 ; - -err_input_register: -free_irq (client->irq, ts); -err_fw_vers: -input_free_device (input_dev); -err_input_alloc: -gpio_set_value (pdata->gpio_rst,0 ); -err_gpio_rst: -gpio_free (pdata->gpio_rst); -err_gpio_dir: -gpio_free (pdata->gpio_int); -err_gpio_int: -kfree (ts); + error =devm_add_action (&client->dev, auo_pixcir_reset, ts); +if (error) { +auo_pixcir_reset (ts); + dev_err(&client->dev, "failed to register xxx action, %d\n", + error); + return error; + } - return ret; -} +msleep (200 ); -static int auo_pixcir_remove (struct i2c_client *client) -{ -struct auo_pixcir_ts *ts =i2c_get_clientdata (client); -const struct auo_pixcir_ts_platdata *pdata = ts->pdata; + version =i2c_smbus_read_byte_data (client,AUO_PIXCIR_REG_VERSION ); +if (version <0 ) { + error = version; +return error; + } -free_irq (client->irq, ts);
drivers/input/touchscreen/auo-pixcir-ts.c static int auo_pixcir_probe(struct i2c_client *client,
Quoted 10 lines
drivers/input/touchscreen/auo-pixcir-ts.c +5
-3+dev_info (&client->dev,"firmware version 0x%X\n" , version); -input_unregister_device (ts->input); + error =auo_pixcir_int_config (ts, pdata->int_setting); +if (error) +return error; -gpio_set_value (pdata->gpio_rst,0 ); -gpio_free (pdata->gpio_rst); + error = request_threaded_irq(client->irq, NULL,
+ error = devm_request_threaded_irq(&client->dev, client->irq, NULL,
Quoted 38 lines
auo_pixcir_interrupt, +IRQF_TRIGGER_RISING|IRQF_ONESHOT, +input_dev->name, ts);drivers/input/touchscreen/auo-pixcir-ts.c +13
-1+if (error) { +dev_err (&client->dev,"irq %d requested failed, %d\n" , + client->irq, error); +return error; + } -gpio_free (pdata->gpio_int); +/* stop device and put it into deep sleep until it is opened */ + error =auo_pixcir_stop (ts); +if (error) +return error; + + error =input_register_device (input_dev); +if (error) { + dev_err(&client->dev, "could not register input device,%d\n", + error);
drivers/input/touchscreen/auo-pixcir-ts.c +3
-2+return error; + } -kfree (ts); +i2c_set_clientdata (client, ts);return 0 ; }@@ -718,7 +693,6 @@ static struct i2c_driver auo_pixcir_driver = { .of_match_table = of_match_ptr(auo_pixcir_ts_dt_idtable), }, .probe = auo_pixcir_probe, - .remove = auo_pixcir_remove,
Quoted 3 lines
.id_table =
auo_pixcir_idtable,};
--
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
Dmitry Torokhov
maintainerQuoted 39 lines · Heiko Stübner
Am Montag, 25. Februar 2013, 04:06:41 schrieb Dmitry Torokhov:
Quoted 29 lines · Heiko Stübner
Quoted 28 lines
Hi Dmitry,
Am Sonntag, 24. Februar 2013, 09:00:15 schrieb Dmitry Torokhov:
Quoted 24 lines
Hi Heiko,
Quoted 5 lines · Heiko Stübner
+static struct
auo_pixcir_ts_platdata*auo_pixcir_parse_dt(struct device *dev) +{(quoted diff) +3
-0+ struct auo_pixcir_ts_platdata *pdata = NULL; + +#ifdef CONFIG_OFReview
Quoted 10 lines
(quoted diff) +10
-0+ struct device_node *np = dev->of_node; + + if (!np) + return NULL; + + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) { + dev_err(dev, "failed to allocate platform data\n"); + return NULL; + }I disike #ifdefs in the middle of the code, also it would be nice if we signal the proper error instead of always using
-EINVALwhen there are issues with platform/DT data.How about the version of the patch below?
Quoted 8 lines
Quoted 1 line
I tested it and everything of course still works :-) .
OK, great, then I will queue these for the next merge window.
Could you also try this patch (it however needs attached patch enhancing devres to support custom actions).
Thanks.
Quoted 8 lines
In general looks really nice and also works. I have some small nitpicks (patch desc, reset gpio naming) and it will also need to use
devm_request_threaded_irqto get the irq correctly freed on removal. [all also marked at the corresponding places below]Otherwise:
Tested-by Heiko Stuebner <[email protected]>
Thank you Heiko, I made the changes you mentioned and queued with the rest of the patches for 3.10.
Signature · 5 lines
Dmitry -- 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