Input: pixcir_i2c_ts - move platform data
Subsystems (3)
Dmitry Torokhov
maintainerPATCH 1/6 Input: pixcir_i2c_ts - move platform data
Let's move driver's platform data definitions from include/linux/input/ into include/linux/platform_data/ so that it stays with the rest of platform data definitions.
--- drivers/input/touchscreen/pixcir_i2c_ts.c | 2 +- include/linux/input/pixcir_ts.h | 64 ----------------------------- include/linux/platform_data/pixcir_i2c_ts.h | 64 +++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 65 deletions(-) delete mode 100644 include/linux/input/pixcir_ts.h create mode 100644 include/linux/platform_data/pixcir_i2c_ts.h
drivers/input/touchscreen/pixcir_i2c_ts.c +1 -1
@@ -24,11 +24,11 @@#include <linux/i2c.h> #include <linux/input.h> #include <linux/input/mt.h> -#include <linux/input/pixcir_ts.h> #include <linux/gpio.h> #include <linux/of.h> #include <linux/of_gpio.h> #include <linux/of_device.h> +#include <linux/platform_data/pixcir_i2c_ts.h> #define PIXCIR_MAX_SLOTS 5/* Max fingers supported by driver */
include/linux/input/pixcir_ts.h deleted +0 -64
64 lines not on this page · raw message
include/linux/platform_data/pixcir_i2c_ts.h new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
2.4.3.573.g4eafbef
Dmitry Torokhov
maintainerPATCH 2/6 Input: pixcir_i2c_ts - switch the device over to gpiod
This allows uniform parsing on legacy, DT and ACPI systems.
--- drivers/input/touchscreen/pixcir_i2c_ts.c | 26 +++++++++----------------- include/linux/platform_data/pixcir_i2c_ts.h | 1 - 2 files changed, 9 insertions(+), 18 deletions(-)
drivers/input/touchscreen/pixcir_i2c_ts.c +9 -17
@@ -25,8 +25,8 @@#include <linux/input.h> #include <linux/input/mt.h> #include <linux/gpio.h> +#include <linux/gpio/consumer.h> #include <linux/of.h> -#include <linux/of_gpio.h> #include <linux/of_device.h> #include <linux/platform_data/pixcir_i2c_ts.h>
@@ -35,6 +35,7 @@struct pixcir_i2c_ts_data {struct i2c_client *client;struct input_dev *input; +struct gpio_desc *gpio_attb;const struct pixcir_ts_platform_data *pdata;bool running;int max_fingers;/* Max fingers supported in this instance */
@@ -161,7 +162,6 @@ static void pixcir_ts_report(struct pixcir_i2c_ts_data *ts,static irqreturn_t pixcir_ts_isr (int irq,void *dev_id) {struct pixcir_i2c_ts_data *tsdata = dev_id; -const struct pixcir_ts_platform_data *pdata = tsdata->pdata;struct pixcir_report_data report;while (tsdata->running) {
@@ -171,7 +171,7 @@ static irqreturn_t pixcir_ts_isr(int irq, void *dev_id)/* report it */ pixcir_ts_report (tsdata, &report); -if (gpio_get_value (pdata->gpio_attb)) { +if (gpiod_get_value (tsdata->gpio_attb)) {if (report.num_touches) {/* * Last report with no finger up?
@@ -427,9 +427,6 @@ static struct pixcir_ts_platform_data *pixcir_parse_dt(struct device *dev) pdata->chip = *(const struct pixcir_i2c_chip_data *)match->data; - pdata->gpio_attb =of_get_named_gpio (np,"attb-gpio" ,0 ); -/* gpio_attb validity is checked in probe */ -if (of_property_read_u32 (np,"touchscreen-size-x" , &pdata->x_max)) {dev_err (dev,"Failed to get touchscreen-size-x property\n" );return ERR_PTR (-EINVAL );
@@ -442,8 +439,8 @@ static struct pixcir_ts_platform_data *pixcir_parse_dt(struct device *dev) } pdata->y_max -=1 ; -dev_dbg (dev,"%s: x %d, y %d, gpio %d\n" , __func__, - pdata->x_max +1 , pdata->y_max +1 , pdata->gpio_attb); +dev_dbg (dev,"%s: x %d, y %d\n" , __func__, + pdata->x_max +1 , pdata->y_max +1 );return pdata; }
@@ -476,11 +473,6 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client,return -EINVAL ; } -if (!gpio_is_valid (pdata->gpio_attb)) { -dev_err (dev,"Invalid gpio_attb in pdata\n" ); -return -EINVAL ; - } -if (!pdata->chip.max_fingers) {dev_err (dev,"Invalid max_fingers in pdata\n" );return -EINVAL ;
@@ -530,10 +522,10 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client,input_set_drvdata (input, tsdata); - error =devm_gpio_request_one (dev, pdata->gpio_attb, -GPIOF_DIR_IN ,"pixcir_i2c_attb" ); -if (error) { -dev_err (dev,"Failed to request ATTB gpio\n" ); + tsdata->gpio_attb =devm_gpiod_get (dev,"attb" ,GPIOD_IN ); +if (IS_ERR (tsdata->gpio_attb)) { + error =PTR_ERR (tsdata->gpio_attb); +dev_err (dev,"Failed to request ATTB gpio: %d\n" , error);return error; }
include/linux/platform_data/pixcir_i2c_ts.h +0 -1
@@ -57,7 +57,6 @@ struct pixcir_i2c_chip_data {struct pixcir_ts_platform_data {int x_max;int y_max; -int gpio_attb;/* GPIO connected to ATTB line */ struct pixcir_i2c_chip_data chip; };
Signature · 1 line
2.4.3.573.g4eafbef
Re: [PATCH 2/6] Input: pixcir_i2c_ts - switch the device over to gpiod
Quoted 3 lines · Dmitry Torokhov
This allows uniform parsing on legacy, DT and ACPI systems.
Signed-off-by Dmitry Torokhov <[email protected]>
cheers,
-roger
Quoted 105 lines
--- drivers/input/touchscreen/pixcir_i2c_ts.c | 26 +++++++++----------------- include/linux/platform_data/pixcir_i2c_ts.h | 1 - 2 files changed, 9 insertions(+), 18 deletions(-)drivers/input/touchscreen/pixcir_i2c_ts.c +9
-17@@ -25,8 +25,8 @@#include <linux/input.h> #include <linux/input/mt.h> #include <linux/gpio.h> +#include <linux/gpio/consumer.h> #include <linux/of.h> -#include <linux/of_gpio.h> #include <linux/of_device.h> #include <linux/platform_data/pixcir_i2c_ts.h> @@ -35,6 +35,7 @@struct pixcir_i2c_ts_data {struct i2c_client *client;struct input_dev *input; +struct gpio_desc *gpio_attb;const struct pixcir_ts_platform_data *pdata;bool running;int max_fingers;/* Max fingers supported in this instance */ @@ -161,7 +162,6 @@ static void pixcir_ts_report(struct pixcir_i2c_ts_data *ts,static irqreturn_t pixcir_ts_isr (int irq,void *dev_id) {struct pixcir_i2c_ts_data *tsdata = dev_id; -const struct pixcir_ts_platform_data *pdata = tsdata->pdata;struct pixcir_report_data report;while (tsdata->running) {@@ -171,7 +171,7 @@ static irqreturn_t pixcir_ts_isr(int irq, void *dev_id)/* report it */ pixcir_ts_report (tsdata, &report); -if (gpio_get_value (pdata->gpio_attb)) { +if (gpiod_get_value (tsdata->gpio_attb)) {if (report.num_touches) {/* * Last report with no finger up? @@ -427,9 +427,6 @@ static struct pixcir_ts_platform_data *pixcir_parse_dt(struct device *dev) pdata->chip = *(const struct pixcir_i2c_chip_data *)match->data; - pdata->gpio_attb =of_get_named_gpio (np,"attb-gpio" ,0 ); -/* gpio_attb validity is checked in probe */ -if (of_property_read_u32 (np,"touchscreen-size-x" , &pdata->x_max)) {dev_err (dev,"Failed to get touchscreen-size-x property\n" );return ERR_PTR (-EINVAL );@@ -442,8 +439,8 @@ static struct pixcir_ts_platform_data *pixcir_parse_dt(struct device *dev) } pdata->y_max -=1 ; -dev_dbg (dev,"%s: x %d, y %d, gpio %d\n" , __func__, - pdata->x_max +1 , pdata->y_max +1 , pdata->gpio_attb); +dev_dbg (dev,"%s: x %d, y %d\n" , __func__, + pdata->x_max +1 , pdata->y_max +1 );return pdata; }@@ -476,11 +473,6 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client,return -EINVAL ; } -if (!gpio_is_valid (pdata->gpio_attb)) { -dev_err (dev,"Invalid gpio_attb in pdata\n" ); -return -EINVAL ; - } -if (!pdata->chip.max_fingers) {dev_err (dev,"Invalid max_fingers in pdata\n" );return -EINVAL ;@@ -530,10 +522,10 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client,input_set_drvdata (input, tsdata); - error =devm_gpio_request_one (dev, pdata->gpio_attb, -GPIOF_DIR_IN ,"pixcir_i2c_attb" ); -if (error) { -dev_err (dev,"Failed to request ATTB gpio\n" ); + tsdata->gpio_attb =devm_gpiod_get (dev,"attb" ,GPIOD_IN ); +if (IS_ERR (tsdata->gpio_attb)) { + error =PTR_ERR (tsdata->gpio_attb); +dev_err (dev,"Failed to request ATTB gpio: %d\n" , error);return error; }include/linux/platform_data/pixcir_i2c_ts.h +0
-1@@ -57,7 +57,6 @@ struct pixcir_i2c_chip_data {struct pixcir_ts_platform_data {int x_max;int y_max; -int gpio_attb;/* GPIO connected to ATTB line */ struct pixcir_i2c_chip_data chip; };
Dmitry Torokhov
maintainerPATCH 3/6 Input: pixcir_i2c_ts - allow using with GPIO expanders
In reply to Dmitry TorokhovWe are using threaded interrupt handler and thus are allowed to sleep. Let's switch over to gpiod_get_value_cansleep() so that we do not get ugly warnings in case GPIO controller might sleep when accessing GPIO.
--- drivers/input/touchscreen/pixcir_i2c_ts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/touchscreen/pixcir_i2c_ts.c +1 -1
@@ -171,7 +171,7 @@ static irqreturn_t pixcir_ts_isr(int irq, void *dev_id)/* report it */ pixcir_ts_report (tsdata, &report); -if (gpiod_get_value (tsdata->gpio_attb)) { +if (gpiod_get_value_cansleep (tsdata->gpio_attb)) {if (report.num_touches) {/* * Last report with no finger up?
Signature · 1 line
2.4.3.573.g4eafbef
Re: [PATCH 3/6] Input: pixcir_i2c_ts - allow using with GPIO expanders
Quoted 5 lines · Dmitry Torokhov
We are using threaded interrupt handler and thus are allowed to sleep. Let's switch over to
gpiod_get_value_cansleep()so that we do not get ugly warnings in case GPIO controller might sleep when accessing GPIO.Signed-off-by Dmitry Torokhov <[email protected]>
cheers,
-roger
Quoted 18 lines
--- drivers/input/touchscreen/pixcir_i2c_ts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/input/touchscreen/pixcir_i2c_ts.c +1
-1@@ -171,7 +171,7 @@ static irqreturn_t pixcir_ts_isr(int irq, void *dev_id)/* report it */ pixcir_ts_report (tsdata, &report); -if (gpiod_get_value (tsdata->gpio_attb)) { +if (gpiod_get_value_cansleep (tsdata->gpio_attb)) {if (report.num_touches) {/* * Last report with no finger up?
Dmitry Torokhov
maintainerPATCH 4/6 Input: pixcir_i2c_ts - add RESET gpio
In reply to Dmitry TorokhovFrom: Roger Quadros <[email protected]>
The controller has a RESET pin which is usually controlled over a GPIO line. If such a GPIO is provided, perform a RESET during probe.
--- .../bindings/input/touchscreen/pixcir_i2c_ts.txt | 3 +++ drivers/input/touchscreen/pixcir_i2c_ts.c | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+)
Documentation/devicetree/bindings/input/touchscreen/pixcir_i2c_ts.txt +3 -0
@@ -8,6 +8,9 @@ Required properties: - touchscreen-size-x: horizontal resolution of touchscreen (in pixels) - touchscreen-size-y: vertical resolution of touchscreen (in pixels) +Optional properties: +- reset-gpio: GPIO connected to the RESET line of the chip + Example: i2c@00000000 {
drivers/input/touchscreen/pixcir_i2c_ts.c +22 -0
@@ -36,6 +36,7 @@ struct pixcir_i2c_ts_data {struct i2c_client *client;struct input_dev *input;struct gpio_desc *gpio_attb; +struct gpio_desc *gpio_reset;const struct pixcir_ts_platform_data *pdata;bool running;int max_fingers;/* Max fingers supported in this instance */
@@ -189,6 +190,17 @@ static irqreturn_t pixcir_ts_isr(int irq, void *dev_id)return IRQ_HANDLED ; } +static void pixcir_reset (struct pixcir_i2c_ts_data *tsdata) +{ +if (!IS_ERR_OR_NULL (tsdata->gpio_reset)) { +gpiod_set_value_cansleep (tsdata->gpio_reset,1 ); +ndelay (100 );/* datasheet section 1.2.3 says 80ns min. */ +gpiod_set_value_cansleep (tsdata->gpio_reset,0 ); +/* wait for controller ready. 100ms guess. */ +msleep (100 ); + } +} +static int pixcir_set_power_mode (struct pixcir_i2c_ts_data *ts,enum pixcir_power_mode mode) {
@@ -529,6 +541,14 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client,return error; } + tsdata->gpio_reset =devm_gpiod_get_optional (dev,"reset" , +GPIOD_OUT_LOW ); +if (IS_ERR (tsdata->gpio_reset)) { + error =PTR_ERR (tsdata->gpio_reset); +dev_err (dev,"Failed to request RESET gpio: %d\n" , error); +return error; + } + error =devm_request_threaded_irq (dev, client->irq,NULL , pixcir_ts_isr,IRQF_TRIGGER_FALLING |IRQF_ONESHOT , client->name, tsdata);
@@ -537,6 +557,8 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client,return error; } +pixcir_reset (tsdata); +/* Always be in IDLE mode to save power, device supports auto wake */ error =pixcir_set_power_mode (tsdata,PIXCIR_POWER_IDLE );if (error) {
Signature · 1 line
2.4.3.573.g4eafbef
Dmitry Torokhov
maintainerPATCH 5/6 Input: pixcir_i2c_ts - simplify input device initialization
In reply to Dmitry Torokhovinput_mt_init_slots() will perform necessary settings for performing multi-touch to single-touch emulation, we do not need to do that ourselves.
--- drivers/input/touchscreen/pixcir_i2c_ts.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/input/touchscreen/pixcir_i2c_ts.c +0 -5
@@ -510,11 +510,6 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client, input->close = pixcir_input_close; input->dev.parent = &client->dev; -__set_bit (EV_KEY , input->evbit); -__set_bit (EV_ABS , input->evbit); -__set_bit (BTN_TOUCH , input->keybit); -input_set_abs_params (input,ABS_X ,0 , pdata->x_max,0 ,0 ); -input_set_abs_params (input,ABS_Y ,0 , pdata->y_max,0 ,0 );input_set_abs_params (input,ABS_MT_POSITION_X ,0 , pdata->x_max,0 ,0 );input_set_abs_params (input,ABS_MT_POSITION_Y ,0 , pdata->y_max,0 ,0 );
Signature · 1 line
2.4.3.573.g4eafbef
Re: [PATCH 5/6] Input: pixcir_i2c_ts - simplify input device initialization
Quoted 4 lines · Dmitry Torokhov
input_mt_init_slots()will perform necessary settings for performing multi-touch to single-touch emulation, we do not need to do that ourselves.Signed-off-by Dmitry Torokhov <[email protected]>
cheers,
-roger
Quoted 21 lines
--- drivers/input/touchscreen/pixcir_i2c_ts.c | 5 ----- 1 file changed, 5 deletions(-)drivers/input/touchscreen/pixcir_i2c_ts.c +0
-5@@ -510,11 +510,6 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client, input->close = pixcir_input_close; input->dev.parent = &client->dev; -__set_bit (EV_KEY , input->evbit); -__set_bit (EV_ABS , input->evbit); -__set_bit (BTN_TOUCH , input->keybit); -input_set_abs_params (input,ABS_X ,0 , pdata->x_max,0 ,0 ); -input_set_abs_params (input,ABS_Y ,0 , pdata->y_max,0 ,0 );input_set_abs_params (input,ABS_MT_POSITION_X ,0 , pdata->x_max,0 ,0 );input_set_abs_params (input,ABS_MT_POSITION_Y ,0 , pdata->y_max,0 ,0 );
Dmitry Torokhov
maintainerPATCH 6/6 Input: pixcir_i2c_ts - use standard OF touchscreen parsing code
In reply to Dmitry TorokhovLet's switch to using standard touchscreen device properties parsing module instead of doing it by hand in the driver.
--- drivers/input/touchscreen/pixcir_i2c_ts.c | 95 ++++++++++++++----------------- 1 file changed, 44 insertions(+), 51 deletions(-)
drivers/input/touchscreen/pixcir_i2c_ts.c +44 -51
@@ -24,9 +24,10 @@#include <linux/i2c.h> #include <linux/input.h> #include <linux/input/mt.h> +#include <linux/input/touchscreen.h> #include <linux/gpio.h> #include <linux/gpio/consumer.h> -#include <linux/of.h> +/*#include <linux/of.h>*/ #include <linux/of_device.h> #include <linux/platform_data/pixcir_i2c_ts.h>
@@ -37,9 +38,9 @@ struct pixcir_i2c_ts_data {struct input_dev *input;struct gpio_desc *gpio_attb;struct gpio_desc *gpio_reset; -const struct pixcir_ts_platform_data *pdata; -bool running; +const struct pixcir_i2c_chip_data *chip;int max_fingers;/* Max fingers supported in this instance */ +bool running; };struct pixcir_touch {
@@ -62,7 +63,7 @@ static void pixcir_ts_parse(struct pixcir_i2c_ts_data *tsdata,u8 touch;int ret, i;int readsize; -const struct pixcir_i2c_chip_data *chip = &tsdata->pdata->chip; +const struct pixcir_i2c_chip_data *chip = tsdata->chip;memset (report,0 ,sizeof (struct pixcir_report_data ));
@@ -115,13 +116,13 @@ static void pixcir_ts_report(struct pixcir_i2c_ts_data *ts,struct pixcir_touch *touch;int n, i, slot;struct device *dev = &ts->client->dev; -const struct pixcir_i2c_chip_data *chip = &ts->pdata->chip; +const struct pixcir_i2c_chip_data *chip = ts->chip; n = report->num_touches;if (n >PIXCIR_MAX_SLOTS ) n =PIXCIR_MAX_SLOTS ; -if (!chip->has_hw_ids) { +if (!ts->chip->has_hw_ids) {for (i =0 ; i < n; i++) { touch = &report->touches[i]; pos[i].x = touch->x;
@@ -423,77 +424,59 @@ static SIMPLE_DEV_PM_OPS(pixcir_dev_pm_ops,#ifdef CONFIG_OF static const struct of_device_id pixcir_of_match[]; -static struct pixcir_ts_platform_data *pixcir_parse_dt (struct device *dev) +static int pixcir_parse_dt (struct device *dev, +struct pixcir_i2c_ts_data *tsdata) { -struct pixcir_ts_platform_data *pdata; -struct device_node *np = dev->of_node;const struct of_device_id *match; match =of_match_device (of_match_ptr (pixcir_of_match), dev);if (!match) -return ERR_PTR (-EINVAL ); - - pdata =devm_kzalloc (dev,sizeof (*pdata),GFP_KERNEL ); -if (!pdata) -return ERR_PTR (-ENOMEM ); - - pdata->chip = *(const struct pixcir_i2c_chip_data *)match->data; - -if (of_property_read_u32 (np,"touchscreen-size-x" , &pdata->x_max)) { -dev_err (dev,"Failed to get touchscreen-size-x property\n" ); -return ERR_PTR (-EINVAL ); - } - pdata->x_max -=1 ; - -if (of_property_read_u32 (np,"touchscreen-size-y" , &pdata->y_max)) { -dev_err (dev,"Failed to get touchscreen-size-y property\n" ); -return ERR_PTR (-EINVAL ); - } - pdata->y_max -=1 ; +return -EINVAL ; -dev_dbg (dev,"%s: x %d, y %d\n" , __func__, - pdata->x_max +1 , pdata->y_max +1 ); + tsdata->chip = (const struct pixcir_i2c_chip_data *)match->data; +if (!tsdata->chip) +return -EINVAL ; -return pdata; +return 0 ; }#else -static struct pixcir_ts_platform_data *pixcir_parse_dt (struct device *dev) +static int pixcir_parse_dt (struct device *dev, +struct pixcir_i2c_ts_data *tsdata) { -return ERR_PTR (-EINVAL ); +return -EINVAL ; }#endif static int pixcir_i2c_ts_probe (struct i2c_client *client, -const struct i2c_device_id *id) +const struct i2c_device_id *id) {const struct pixcir_ts_platform_data *pdata =dev_get_platdata (&client->dev);struct device *dev = &client->dev; -struct device_node *np = dev->of_node;struct pixcir_i2c_ts_data *tsdata;struct input_dev *input;int error; -if (np && !pdata) { - pdata =pixcir_parse_dt (dev); -if (IS_ERR (pdata)) -return PTR_ERR (pdata); - } + tsdata =devm_kzalloc (dev,sizeof (*tsdata),GFP_KERNEL ); +if (!tsdata) +return -ENOMEM ; -if (!pdata) { +if (pdata) { + tsdata->chip = &pdata->chip; + }else if (dev->of_node) { + error =pixcir_parse_dt (dev, tsdata); +if (error) +return error; + }else {dev_err (&client->dev,"platform data not defined\n" );return -EINVAL ; } -if (!pdata->chip.max_fingers) { -dev_err (dev,"Invalid max_fingers in pdata\n" ); +if (!tsdata->chip->max_fingers) { +dev_err (dev,"Invalid max_fingers in chip data\n" );return -EINVAL ; } - tsdata =devm_kzalloc (dev,sizeof (*tsdata),GFP_KERNEL ); -if (!tsdata) -return -ENOMEM ; - input =devm_input_allocate_device (dev);if (!input) {dev_err (dev,"Failed to allocate input device\n" );
@@ -502,7 +485,6 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client, tsdata->client = client; tsdata->input = input; - tsdata->pdata = pdata; input->name = client->name; input->id.bustype =BUS_I2C ;
@@ -510,10 +492,21 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client, input->close = pixcir_input_close; input->dev.parent = &client->dev; -input_set_abs_params (input,ABS_MT_POSITION_X ,0 , pdata->x_max,0 ,0 ); -input_set_abs_params (input,ABS_MT_POSITION_Y ,0 , pdata->y_max,0 ,0 ); +if (pdata) { +input_set_abs_params (input,ABS_MT_POSITION_X ,0 , pdata->x_max,0 ,0 ); +input_set_abs_params (input,ABS_MT_POSITION_Y ,0 , pdata->y_max,0 ,0 ); + }else { +input_set_capability (input,EV_ABS ,ABS_MT_POSITION_X ); +input_set_capability (input,EV_ABS ,ABS_MT_POSITION_Y ); +touchscreen_parse_properties (input, true); +if (!input_abs_get_max (input,ABS_MT_POSITION_X ) || + !input_abs_get_max (input,ABS_MT_POSITION_Y )) { +dev_err (dev,"Touchscreen size is not specified\n" ); +return -EINVAL ; + } + } - tsdata->max_fingers = tsdata->pdata->chip.max_fingers; + tsdata->max_fingers = tsdata->chip->max_fingers;if (tsdata->max_fingers >PIXCIR_MAX_SLOTS ) { tsdata->max_fingers =PIXCIR_MAX_SLOTS ; dev_info(dev, "Limiting maximum fingers to %d\n",
Signature · 1 line
2.4.3.573.g4eafbef
Re: [PATCH 6/6] Input: pixcir_i2c_ts - use standard OF touchscreen parsing code
Quoted 4 lines · Dmitry Torokhov
Let's switch to using standard touchscreen device properties parsing module instead of doing it by hand in the driver.
Signed-off-by Dmitry Torokhov <[email protected]>
cheers,
-roger
Quoted 192 lines
--- drivers/input/touchscreen/pixcir_i2c_ts.c | 95 ++++++++++++++----------------- 1 file changed, 44 insertions(+), 51 deletions(-)drivers/input/touchscreen/pixcir_i2c_ts.c +44
-51@@ -24,9 +24,10 @@#include <linux/i2c.h> #include <linux/input.h> #include <linux/input/mt.h> +#include <linux/input/touchscreen.h> #include <linux/gpio.h> #include <linux/gpio/consumer.h> -#include <linux/of.h> +/*#include <linux/of.h>*/ #include <linux/of_device.h> #include <linux/platform_data/pixcir_i2c_ts.h> @@ -37,9 +38,9 @@ struct pixcir_i2c_ts_data {struct input_dev *input;struct gpio_desc *gpio_attb;struct gpio_desc *gpio_reset; -const struct pixcir_ts_platform_data *pdata; -bool running; +const struct pixcir_i2c_chip_data *chip;int max_fingers;/* Max fingers supported in this instance */ +bool running; };struct pixcir_touch {@@ -62,7 +63,7 @@ static void pixcir_ts_parse(struct pixcir_i2c_ts_data *tsdata,u8 touch;int ret, i;int readsize; -const struct pixcir_i2c_chip_data *chip = &tsdata->pdata->chip; +const struct pixcir_i2c_chip_data *chip = tsdata->chip;memset (report,0 ,sizeof (struct pixcir_report_data ));@@ -115,13 +116,13 @@ static void pixcir_ts_report(struct pixcir_i2c_ts_data *ts,struct pixcir_touch *touch;int n, i, slot;struct device *dev = &ts->client->dev; -const struct pixcir_i2c_chip_data *chip = &ts->pdata->chip; +const struct pixcir_i2c_chip_data *chip = ts->chip; n = report->num_touches;if (n >PIXCIR_MAX_SLOTS ) n =PIXCIR_MAX_SLOTS ; -if (!chip->has_hw_ids) { +if (!ts->chip->has_hw_ids) {for (i =0 ; i < n; i++) { touch = &report->touches[i]; pos[i].x = touch->x;@@ -423,77 +424,59 @@ static SIMPLE_DEV_PM_OPS(pixcir_dev_pm_ops,#ifdef CONFIG_OF static const struct of_device_id pixcir_of_match[]; -static struct pixcir_ts_platform_data *pixcir_parse_dt (struct device *dev) +static int pixcir_parse_dt (struct device *dev, +struct pixcir_i2c_ts_data *tsdata) { -struct pixcir_ts_platform_data *pdata; -struct device_node *np = dev->of_node;const struct of_device_id *match; match =of_match_device (of_match_ptr (pixcir_of_match), dev);if (!match) -return ERR_PTR (-EINVAL ); - - pdata =devm_kzalloc (dev,sizeof (*pdata),GFP_KERNEL ); -if (!pdata) -return ERR_PTR (-ENOMEM ); - - pdata->chip = *(const struct pixcir_i2c_chip_data *)match->data; - -if (of_property_read_u32 (np,"touchscreen-size-x" , &pdata->x_max)) { -dev_err (dev,"Failed to get touchscreen-size-x property\n" ); -return ERR_PTR (-EINVAL ); - } - pdata->x_max -=1 ; - -if (of_property_read_u32 (np,"touchscreen-size-y" , &pdata->y_max)) { -dev_err (dev,"Failed to get touchscreen-size-y property\n" ); -return ERR_PTR (-EINVAL ); - } - pdata->y_max -=1 ; +return -EINVAL ; -dev_dbg (dev,"%s: x %d, y %d\n" , __func__, - pdata->x_max +1 , pdata->y_max +1 ); + tsdata->chip = (const struct pixcir_i2c_chip_data *)match->data; +if (!tsdata->chip) +return -EINVAL ; -return pdata; +return 0 ; }#else -static struct pixcir_ts_platform_data *pixcir_parse_dt (struct device *dev) +static int pixcir_parse_dt (struct device *dev, +struct pixcir_i2c_ts_data *tsdata) { -return ERR_PTR (-EINVAL ); +return -EINVAL ; }#endif static int pixcir_i2c_ts_probe (struct i2c_client *client, -const struct i2c_device_id *id) +const struct i2c_device_id *id) {const struct pixcir_ts_platform_data *pdata =dev_get_platdata (&client->dev);struct device *dev = &client->dev; -struct device_node *np = dev->of_node;struct pixcir_i2c_ts_data *tsdata;struct input_dev *input;int error; -if (np && !pdata) { - pdata =pixcir_parse_dt (dev); -if (IS_ERR (pdata)) -return PTR_ERR (pdata); - } + tsdata =devm_kzalloc (dev,sizeof (*tsdata),GFP_KERNEL ); +if (!tsdata) +return -ENOMEM ; -if (!pdata) { +if (pdata) { + tsdata->chip = &pdata->chip; + }else if (dev->of_node) { + error =pixcir_parse_dt (dev, tsdata); +if (error) +return error; + }else {dev_err (&client->dev,"platform data not defined\n" );return -EINVAL ; } -if (!pdata->chip.max_fingers) { -dev_err (dev,"Invalid max_fingers in pdata\n" ); +if (!tsdata->chip->max_fingers) { +dev_err (dev,"Invalid max_fingers in chip data\n" );return -EINVAL ; } - tsdata =devm_kzalloc (dev,sizeof (*tsdata),GFP_KERNEL ); -if (!tsdata) -return -ENOMEM ; - input =devm_input_allocate_device (dev);if (!input) {dev_err (dev,"Failed to allocate input device\n" );@@ -502,7 +485,6 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client, tsdata->client = client; tsdata->input = input; - tsdata->pdata = pdata; input->name = client->name; input->id.bustype =BUS_I2C ;@@ -510,10 +492,21 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client, input->close = pixcir_input_close; input->dev.parent = &client->dev; -input_set_abs_params (input,ABS_MT_POSITION_X ,0 , pdata->x_max,0 ,0 ); -input_set_abs_params (input,ABS_MT_POSITION_Y ,0 , pdata->y_max,0 ,0 ); +if (pdata) { +input_set_abs_params (input,ABS_MT_POSITION_X ,0 , pdata->x_max,0 ,0 ); +input_set_abs_params (input,ABS_MT_POSITION_Y ,0 , pdata->y_max,0 ,0 ); + }else { +input_set_capability (input,EV_ABS ,ABS_MT_POSITION_X ); +input_set_capability (input,EV_ABS ,ABS_MT_POSITION_Y ); +touchscreen_parse_properties (input, true); +if (!input_abs_get_max (input,ABS_MT_POSITION_X ) || + !input_abs_get_max (input,ABS_MT_POSITION_Y )) { +dev_err (dev,"Touchscreen size is not specified\n" ); +return -EINVAL ; + } + } - tsdata->max_fingers = tsdata->pdata->chip.max_fingers; + tsdata->max_fingers = tsdata->chip->max_fingers;if (tsdata->max_fingers >PIXCIR_MAX_SLOTS ) { tsdata->max_fingers =PIXCIR_MAX_SLOTS ; dev_info(dev, "Limiting maximum fingers to %d\n",
Quoted 5 lines · Dmitry Torokhov
Let's move driver's platform data definitions from
include/linux/input/intoinclude/linux/platform_data/so that it stays with the rest of platform data definitions.Signed-off-by Dmitry Torokhov <[email protected]>
cheers,
-roger
Quoted 166 lines
--- drivers/input/touchscreen/pixcir_i2c_ts.c | 2 +- include/linux/input/pixcir_ts.h | 64 ----------------------------- include/linux/platform_data/pixcir_i2c_ts.h | 64 +++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 65 deletions(-)delete mode 100644
include/linux/input/pixcir_ts.hcreate mode 100644include/linux/platform_data/pixcir_i2c_ts.hdrivers/input/touchscreen/pixcir_i2c_ts.c +1
-1@@ -24,11 +24,11 @@#include <linux/i2c.h> #include <linux/input.h> #include <linux/input/mt.h> -#include <linux/input/pixcir_ts.h> #include <linux/gpio.h> #include <linux/of.h> #include <linux/of_gpio.h> #include <linux/of_device.h> +#include <linux/platform_data/pixcir_i2c_ts.h> #define PIXCIR_MAX_SLOTS 5/* Max fingers supported by driver */ include/linux/input/pixcir_ts.h deleted +0
-64@@ -1,64 +0,0 @@ -#ifndef _PIXCIR_I2C_TS_H -#define _PIXCIR_I2C_TS_H - -/* -* Register map -*/ -#define PIXCIR_REG_POWER_MODE 51 -#define PIXCIR_REG_INT_MODE 52 - -/* -* Power modes: -* active: max scan speed -* idle: lower scan speed with automatic transition to active on touch -* halt: datasheet says sleep but this is more like halt as the chip -* clocks are cut and it can only be brought out of this mode -* using the RESET pin. -*/ -enum pixcir_power_mode { -PIXCIR_POWER_ACTIVE , -PIXCIR_POWER_IDLE , -PIXCIR_POWER_HALT , -}; - -#define PIXCIR_POWER_MODE_MASK 0x03 -#define PIXCIR_POWER_ALLOW_IDLE (1UL << 2) - -/* -* Interrupt modes: -* periodical: interrupt is asserted periodicaly -* diff coordinates: interrupt is asserted when coordinates change -* level on touch: interrupt level asserted during touch -* pulse on touch: interrupt pulse asserted druing touch -* -*/ -enum pixcir_int_mode { -PIXCIR_INT_PERIODICAL , -PIXCIR_INT_DIFF_COORD , -PIXCIR_INT_LEVEL_TOUCH , -PIXCIR_INT_PULSE_TOUCH , -}; - -#define PIXCIR_INT_MODE_MASK 0x03 -#define PIXCIR_INT_ENABLE (1UL << 3) -#define PIXCIR_INT_POL_HIGH (1UL << 2) - -/** -* struct pixcir_irc_chip_data - chip related data -* @max_fingers: Max number of fingers reported simultaneously by h/w -* @has_hw_ids: Hardware supports finger tracking IDs -* -*/ -struct pixcir_i2c_chip_data { -u8 max_fingers; -bool has_hw_ids; -}; - -struct pixcir_ts_platform_data { -int x_max; -int y_max; -int gpio_attb;/* GPIO connected to ATTB line */ -struct pixcir_i2c_chip_data chip; -}; - -#endif include/linux/platform_data/pixcir_i2c_ts.h new file +64
-0@@ -0,0 +1,64 @@ +#ifndef _PIXCIR_I2C_TS_H +#define _PIXCIR_I2C_TS_H + +/* +* Register map +*/ +#define PIXCIR_REG_POWER_MODE 51 +#define PIXCIR_REG_INT_MODE 52 + +/* +* Power modes: +* active: max scan speed +* idle: lower scan speed with automatic transition to active on touch +* halt: datasheet says sleep but this is more like halt as the chip +* clocks are cut and it can only be brought out of this mode +* using the RESET pin. +*/ +enum pixcir_power_mode { +PIXCIR_POWER_ACTIVE , +PIXCIR_POWER_IDLE , +PIXCIR_POWER_HALT , +}; + +#define PIXCIR_POWER_MODE_MASK 0x03 +#define PIXCIR_POWER_ALLOW_IDLE (1UL << 2) + +/* +* Interrupt modes: +* periodical: interrupt is asserted periodicaly +* diff coordinates: interrupt is asserted when coordinates change +* level on touch: interrupt level asserted during touch +* pulse on touch: interrupt pulse asserted druing touch +* +*/ +enum pixcir_int_mode { +PIXCIR_INT_PERIODICAL , +PIXCIR_INT_DIFF_COORD , +PIXCIR_INT_LEVEL_TOUCH , +PIXCIR_INT_PULSE_TOUCH , +}; + +#define PIXCIR_INT_MODE_MASK 0x03 +#define PIXCIR_INT_ENABLE (1UL << 3) +#define PIXCIR_INT_POL_HIGH (1UL << 2) + +/** +* struct pixcir_irc_chip_data - chip related data +* @max_fingers: Max number of fingers reported simultaneously by h/w +* @has_hw_ids: Hardware supports finger tracking IDs +* +*/ +struct pixcir_i2c_chip_data { +u8 max_fingers; +bool has_hw_ids; +}; + +struct pixcir_ts_platform_data { +int x_max; +int y_max; +int gpio_attb;/* GPIO connected to ATTB line */ +struct pixcir_i2c_chip_data chip; +}; + +#endif