All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>
To: Henrik Rydberg <rydberg-Hk7bIW8heu4wFerOooGFRg@public.gmane.org>,
	dmitry.torokhov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Cc: balbi-l0cyMroinI0@public.gmane.org,
	dmurphy-l0cyMroinI0@public.gmane.org,
	mugunthanvnm-l0cyMroinI0@public.gmane.org,
	nsekhar-l0cyMroinI0@public.gmane.org,
	linux-input-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v5 4/7] Input: pixcir_i2c_ts: Use Type-B Multi-Touch protocol
Date: Mon, 19 May 2014 10:42:49 +0300	[thread overview]
Message-ID: <5379B5F9.70900@ti.com> (raw)
In-Reply-To: <5379ACF1.6080305-Hk7bIW8heu4wFerOooGFRg@public.gmane.org>

Hi Henrik,

On 05/19/2014 10:04 AM, Henrik Rydberg wrote:
> Hi Roger,
> 
> Thanks for the patch series. I think the patch looks great in general. Please
> see some minor comments below.
> 
> On 05/06/2014 01:06 PM, Roger Quadros wrote:
>> Switch to using the Type-B Multi-Touch protocol.
>>
>> Signed-off-by: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>
>> ---
>>  drivers/input/touchscreen/pixcir_i2c_ts.c | 125 ++++++++++++++++++++++--------
>>  1 file changed, 94 insertions(+), 31 deletions(-)
>>
>> diff --git a/drivers/input/touchscreen/pixcir_i2c_ts.c b/drivers/input/touchscreen/pixcir_i2c_ts.c
>> index 8a7da61..1b6e4e5 100644
>> --- a/drivers/input/touchscreen/pixcir_i2c_ts.c
>> +++ b/drivers/input/touchscreen/pixcir_i2c_ts.c
>> @@ -23,9 +23,12 @@
>>  #include <linux/slab.h>
>>  #include <linux/i2c.h>
>>  #include <linux/input.h>
>> +#include <linux/input/mt.h>
>>  #include <linux/input/pixcir_ts.h>
>>  #include <linux/gpio.h>
>>  
>> +#define PIXCIR_MAX_SLOTS       2
>> +
>>  struct pixcir_i2c_ts_data {
>>  	struct i2c_client *client;
>>  	struct input_dev *input;
>> @@ -33,12 +36,25 @@ struct pixcir_i2c_ts_data {
>>  	bool running;
>>  };
>>  
>> -static void pixcir_ts_poscheck(struct pixcir_i2c_ts_data *data)
>> +struct pixcir_touch {
>> +	int x;
>> +	int y;
>> +};
>> +
>> +struct pixcir_report_data {
>> +	int num_touches;
>> +	struct pixcir_touch touches[PIXCIR_MAX_SLOTS];
>> +};
>> +
>> +static void pixcir_ts_parse(struct pixcir_i2c_ts_data *tsdata,
>> +			    struct pixcir_report_data *report)
>>  {
>> -	struct pixcir_i2c_ts_data *tsdata = data;
>>  	u8 rdbuf[10], wrbuf[1] = { 0 };
>> +	u8 *bufptr;
>>  	u8 touch;
>> -	int ret;
>> +	int ret, i;
>> +
>> +	memset(report, 0, sizeof(struct pixcir_report_data));
>>  
>>  	ret = i2c_master_send(tsdata->client, wrbuf, sizeof(wrbuf));
>>  	if (ret != sizeof(wrbuf)) {
>> @@ -56,45 +72,85 @@ static void pixcir_ts_poscheck(struct pixcir_i2c_ts_data *data)
>>  		return;
>>  	}
>>  
>> -	touch = rdbuf[0];
>> -	if (touch) {
>> -		u16 posx1 = (rdbuf[3] << 8) | rdbuf[2];
>> -		u16 posy1 = (rdbuf[5] << 8) | rdbuf[4];
>> -		u16 posx2 = (rdbuf[7] << 8) | rdbuf[6];
>> -		u16 posy2 = (rdbuf[9] << 8) | rdbuf[8];
>> -
>> -		input_report_key(tsdata->input, BTN_TOUCH, 1);
>> -		input_report_abs(tsdata->input, ABS_X, posx1);
>> -		input_report_abs(tsdata->input, ABS_Y, posy1);
>> -
>> -		input_report_abs(tsdata->input, ABS_MT_POSITION_X, posx1);
>> -		input_report_abs(tsdata->input, ABS_MT_POSITION_Y, posy1);
>> -		input_mt_sync(tsdata->input);
>> -
>> -		if (touch == 2) {
>> -			input_report_abs(tsdata->input,
>> -					 ABS_MT_POSITION_X, posx2);
>> -			input_report_abs(tsdata->input,
>> -					 ABS_MT_POSITION_Y, posy2);
>> -			input_mt_sync(tsdata->input);
>> -		}
>> -	} else {
>> -		input_report_key(tsdata->input, BTN_TOUCH, 0);
>> +	touch = rdbuf[0] & 0x7;
>> +	if (touch > PIXCIR_MAX_SLOTS)
>> +		touch = PIXCIR_MAX_SLOTS;
>> +
>> +	report->num_touches = touch;
>> +	bufptr = &rdbuf[2];
>> +
>> +	for (i = 0; i < touch; i++) {
>> +		report->touches[i].x = (bufptr[1] << 8) | bufptr[0];
>> +		report->touches[i].y = (bufptr[3] << 8) | bufptr[2];
>> +
>> +		bufptr = &bufptr[4];
>>  	}
>> +}
> 
> In many places, the '&ptr[index]' form makes a lot of sense, but here, it would
> have been clearer to use 'bufptr += 4'.

Agreed. I'll update it.

> 
>> +
>> +static void pixcir_ts_report(struct pixcir_i2c_ts_data *ts,
>> +			     struct pixcir_report_data *report)
>> +{
>> +	struct input_mt_pos pos[PIXCIR_MAX_SLOTS];
>> +	int slots[PIXCIR_MAX_SLOTS];
>> +	struct pixcir_touch *touch;
>> +	int n, i, slot;
>> +	struct device *dev = &ts->client->dev;
>>  
>> -	input_sync(tsdata->input);
>> +	n = report->num_touches;
>> +	if (n > PIXCIR_MAX_SLOTS)
>> +		n = PIXCIR_MAX_SLOTS;
>> +
>> +	for (i = 0; i < n; i++) {
>> +		touch = &report->touches[i];
>> +		pos[i].x = touch->x;
>> +		pos[i].y = touch->y;
>> +	}
>> +
>> +	input_mt_assign_slots(ts->input, slots, pos, n);
>> +
>> +	for (i = 0; i < n; i++) {
>> +		touch = &report->touches[i];
>> +		slot = slots[i];
>> +
>> +		input_mt_slot(ts->input, slot);
>> +		input_mt_report_slot_state(ts->input,
>> +					   MT_TOOL_FINGER, true);
>> +
>> +		input_event(ts->input, EV_ABS, ABS_MT_POSITION_X, touch->x);
>> +		input_event(ts->input, EV_ABS, ABS_MT_POSITION_Y, touch->y);
>> +
>> +		dev_dbg(dev, "%d: slot %d, x %d, y %d\n",
>> +			i, slot, touch->x, touch->y);
>> +	}
>> +
>> +	input_mt_sync_frame(ts->input);
>> +	input_sync(ts->input);
>>  }
>>  
>>  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->chip;
>> +	struct pixcir_report_data report;
>>  
>>  	while (tsdata->running) {
>> -		pixcir_ts_poscheck(tsdata);
>> -
>> -		if (gpio_get_value(pdata->gpio_attb))
>> +		/* parse packet */
>> +		pixcir_ts_parse(tsdata, &report);
>> +
>> +		/* report it */
>> +		pixcir_ts_report(tsdata, &report);
>> +
>> +		if (gpio_get_value(pdata->gpio_attb)) {
>> +			if (report.num_touches) {
>> +				/*
>> +				 * Last report with no finger up?
>> +				 * Do it now then.
>> +				 */
>> +				input_mt_sync_frame(tsdata->input);
>> +				input_sync(tsdata->input);
> 
> I think this construct is alright for this particular patch. If anything, it
> points at a need for a better model of interrupted contacts in the core.

OK. 

> 
>> +			}
>>  			break;
>> +		}
>>  
>>  		msleep(20);
>>  	}
>> @@ -333,6 +389,13 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client,
>>  	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);
>>  
>> +	error = input_mt_init_slots(input, PIXCIR_MAX_SLOTS,
>> +				    INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
>> +	if (error) {
>> +		dev_err(dev, "Error initializing Multi-Touch slots\n");
>> +		return error;
>> +	}
>> +
>>  	input_set_drvdata(input, tsdata);
>>  
>>  	error = devm_gpio_request_one(dev, pdata->gpio_attb,
>>
> 
>     Reviewed-by: Henrik Rydberg <rydberg-Hk7bIW8heu4wFerOooGFRg@public.gmane.org>

Thanks for the review.

cheers,
-roger

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

WARNING: multiple messages have this Message-ID (diff)
From: Roger Quadros <rogerq@ti.com>
To: Henrik Rydberg <rydberg@euromail.se>, <dmitry.torokhov@gmail.com>
Cc: <balbi@ti.com>, <dmurphy@ti.com>, <mugunthanvnm@ti.com>,
	<nsekhar@ti.com>, <linux-input@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>
Subject: Re: [PATCH v5 4/7] Input: pixcir_i2c_ts: Use Type-B Multi-Touch protocol
Date: Mon, 19 May 2014 10:42:49 +0300	[thread overview]
Message-ID: <5379B5F9.70900@ti.com> (raw)
In-Reply-To: <5379ACF1.6080305@euromail.se>

Hi Henrik,

On 05/19/2014 10:04 AM, Henrik Rydberg wrote:
> Hi Roger,
> 
> Thanks for the patch series. I think the patch looks great in general. Please
> see some minor comments below.
> 
> On 05/06/2014 01:06 PM, Roger Quadros wrote:
>> Switch to using the Type-B Multi-Touch protocol.
>>
>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>> ---
>>  drivers/input/touchscreen/pixcir_i2c_ts.c | 125 ++++++++++++++++++++++--------
>>  1 file changed, 94 insertions(+), 31 deletions(-)
>>
>> diff --git a/drivers/input/touchscreen/pixcir_i2c_ts.c b/drivers/input/touchscreen/pixcir_i2c_ts.c
>> index 8a7da61..1b6e4e5 100644
>> --- a/drivers/input/touchscreen/pixcir_i2c_ts.c
>> +++ b/drivers/input/touchscreen/pixcir_i2c_ts.c
>> @@ -23,9 +23,12 @@
>>  #include <linux/slab.h>
>>  #include <linux/i2c.h>
>>  #include <linux/input.h>
>> +#include <linux/input/mt.h>
>>  #include <linux/input/pixcir_ts.h>
>>  #include <linux/gpio.h>
>>  
>> +#define PIXCIR_MAX_SLOTS       2
>> +
>>  struct pixcir_i2c_ts_data {
>>  	struct i2c_client *client;
>>  	struct input_dev *input;
>> @@ -33,12 +36,25 @@ struct pixcir_i2c_ts_data {
>>  	bool running;
>>  };
>>  
>> -static void pixcir_ts_poscheck(struct pixcir_i2c_ts_data *data)
>> +struct pixcir_touch {
>> +	int x;
>> +	int y;
>> +};
>> +
>> +struct pixcir_report_data {
>> +	int num_touches;
>> +	struct pixcir_touch touches[PIXCIR_MAX_SLOTS];
>> +};
>> +
>> +static void pixcir_ts_parse(struct pixcir_i2c_ts_data *tsdata,
>> +			    struct pixcir_report_data *report)
>>  {
>> -	struct pixcir_i2c_ts_data *tsdata = data;
>>  	u8 rdbuf[10], wrbuf[1] = { 0 };
>> +	u8 *bufptr;
>>  	u8 touch;
>> -	int ret;
>> +	int ret, i;
>> +
>> +	memset(report, 0, sizeof(struct pixcir_report_data));
>>  
>>  	ret = i2c_master_send(tsdata->client, wrbuf, sizeof(wrbuf));
>>  	if (ret != sizeof(wrbuf)) {
>> @@ -56,45 +72,85 @@ static void pixcir_ts_poscheck(struct pixcir_i2c_ts_data *data)
>>  		return;
>>  	}
>>  
>> -	touch = rdbuf[0];
>> -	if (touch) {
>> -		u16 posx1 = (rdbuf[3] << 8) | rdbuf[2];
>> -		u16 posy1 = (rdbuf[5] << 8) | rdbuf[4];
>> -		u16 posx2 = (rdbuf[7] << 8) | rdbuf[6];
>> -		u16 posy2 = (rdbuf[9] << 8) | rdbuf[8];
>> -
>> -		input_report_key(tsdata->input, BTN_TOUCH, 1);
>> -		input_report_abs(tsdata->input, ABS_X, posx1);
>> -		input_report_abs(tsdata->input, ABS_Y, posy1);
>> -
>> -		input_report_abs(tsdata->input, ABS_MT_POSITION_X, posx1);
>> -		input_report_abs(tsdata->input, ABS_MT_POSITION_Y, posy1);
>> -		input_mt_sync(tsdata->input);
>> -
>> -		if (touch == 2) {
>> -			input_report_abs(tsdata->input,
>> -					 ABS_MT_POSITION_X, posx2);
>> -			input_report_abs(tsdata->input,
>> -					 ABS_MT_POSITION_Y, posy2);
>> -			input_mt_sync(tsdata->input);
>> -		}
>> -	} else {
>> -		input_report_key(tsdata->input, BTN_TOUCH, 0);
>> +	touch = rdbuf[0] & 0x7;
>> +	if (touch > PIXCIR_MAX_SLOTS)
>> +		touch = PIXCIR_MAX_SLOTS;
>> +
>> +	report->num_touches = touch;
>> +	bufptr = &rdbuf[2];
>> +
>> +	for (i = 0; i < touch; i++) {
>> +		report->touches[i].x = (bufptr[1] << 8) | bufptr[0];
>> +		report->touches[i].y = (bufptr[3] << 8) | bufptr[2];
>> +
>> +		bufptr = &bufptr[4];
>>  	}
>> +}
> 
> In many places, the '&ptr[index]' form makes a lot of sense, but here, it would
> have been clearer to use 'bufptr += 4'.

Agreed. I'll update it.

> 
>> +
>> +static void pixcir_ts_report(struct pixcir_i2c_ts_data *ts,
>> +			     struct pixcir_report_data *report)
>> +{
>> +	struct input_mt_pos pos[PIXCIR_MAX_SLOTS];
>> +	int slots[PIXCIR_MAX_SLOTS];
>> +	struct pixcir_touch *touch;
>> +	int n, i, slot;
>> +	struct device *dev = &ts->client->dev;
>>  
>> -	input_sync(tsdata->input);
>> +	n = report->num_touches;
>> +	if (n > PIXCIR_MAX_SLOTS)
>> +		n = PIXCIR_MAX_SLOTS;
>> +
>> +	for (i = 0; i < n; i++) {
>> +		touch = &report->touches[i];
>> +		pos[i].x = touch->x;
>> +		pos[i].y = touch->y;
>> +	}
>> +
>> +	input_mt_assign_slots(ts->input, slots, pos, n);
>> +
>> +	for (i = 0; i < n; i++) {
>> +		touch = &report->touches[i];
>> +		slot = slots[i];
>> +
>> +		input_mt_slot(ts->input, slot);
>> +		input_mt_report_slot_state(ts->input,
>> +					   MT_TOOL_FINGER, true);
>> +
>> +		input_event(ts->input, EV_ABS, ABS_MT_POSITION_X, touch->x);
>> +		input_event(ts->input, EV_ABS, ABS_MT_POSITION_Y, touch->y);
>> +
>> +		dev_dbg(dev, "%d: slot %d, x %d, y %d\n",
>> +			i, slot, touch->x, touch->y);
>> +	}
>> +
>> +	input_mt_sync_frame(ts->input);
>> +	input_sync(ts->input);
>>  }
>>  
>>  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->chip;
>> +	struct pixcir_report_data report;
>>  
>>  	while (tsdata->running) {
>> -		pixcir_ts_poscheck(tsdata);
>> -
>> -		if (gpio_get_value(pdata->gpio_attb))
>> +		/* parse packet */
>> +		pixcir_ts_parse(tsdata, &report);
>> +
>> +		/* report it */
>> +		pixcir_ts_report(tsdata, &report);
>> +
>> +		if (gpio_get_value(pdata->gpio_attb)) {
>> +			if (report.num_touches) {
>> +				/*
>> +				 * Last report with no finger up?
>> +				 * Do it now then.
>> +				 */
>> +				input_mt_sync_frame(tsdata->input);
>> +				input_sync(tsdata->input);
> 
> I think this construct is alright for this particular patch. If anything, it
> points at a need for a better model of interrupted contacts in the core.

OK. 

> 
>> +			}
>>  			break;
>> +		}
>>  
>>  		msleep(20);
>>  	}
>> @@ -333,6 +389,13 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client,
>>  	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);
>>  
>> +	error = input_mt_init_slots(input, PIXCIR_MAX_SLOTS,
>> +				    INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
>> +	if (error) {
>> +		dev_err(dev, "Error initializing Multi-Touch slots\n");
>> +		return error;
>> +	}
>> +
>>  	input_set_drvdata(input, tsdata);
>>  
>>  	error = devm_gpio_request_one(dev, pdata->gpio_attb,
>>
> 
>     Reviewed-by: Henrik Rydberg <rydberg@euromail.se>

Thanks for the review.

cheers,
-roger


  parent reply	other threads:[~2014-05-19  7:42 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-06 11:06 [PATCH v5 0/7] Input: pixcir_i2c_ts: Add Type-B Multi-touch and DT support Roger Quadros
2014-05-06 11:06 ` Roger Quadros
2014-05-06 11:06 ` [PATCH v5 1/7] Input: pixcir_i2c_ts: Use devres managed resource allocations Roger Quadros
2014-05-06 11:06   ` Roger Quadros
2014-05-19  5:54   ` Dmitry Torokhov
2014-05-06 11:06 ` [PATCH v5 3/7] Input: pixcir_i2c_ts: Get rid of pdata->attb_read_val() Roger Quadros
2014-05-06 11:06   ` Roger Quadros
2014-05-19  5:55   ` Dmitry Torokhov
2014-05-06 11:06 ` [PATCH v5 4/7] Input: pixcir_i2c_ts: Use Type-B Multi-Touch protocol Roger Quadros
2014-05-06 11:06   ` Roger Quadros
2014-05-19  5:54   ` Dmitry Torokhov
2014-05-19  7:04   ` Henrik Rydberg
     [not found]     ` <5379ACF1.6080305-Hk7bIW8heu4wFerOooGFRg@public.gmane.org>
2014-05-19  7:42       ` Roger Quadros [this message]
2014-05-19  7:42         ` Roger Quadros
     [not found]   ` <1399374372-29123-5-git-send-email-rogerq-l0cyMroinI0@public.gmane.org>
2014-05-19  8:24     ` [PATCH v6 " Roger Quadros
2014-05-19  8:24       ` Roger Quadros
2014-06-04  8:53       ` Roger Quadros
2014-06-04  8:53         ` Roger Quadros
     [not found] ` <1399374372-29123-1-git-send-email-rogerq-l0cyMroinI0@public.gmane.org>
2014-05-06 11:06   ` [PATCH v5 2/7] Input: pixcir_i2c_ts - initialize interrupt mode and power mode Roger Quadros
2014-05-06 11:06     ` Roger Quadros
2014-05-19  5:55     ` Dmitry Torokhov
2014-05-06 11:06   ` [PATCH v5 5/7] Input: pixcir_i2c_ts: support upto 5 fingers and hardware provided tracking IDs Roger Quadros
2014-05-06 11:06     ` Roger Quadros
2014-05-19  8:26     ` [PATCH v6 " Roger Quadros
2014-05-19  8:26       ` Roger Quadros
2014-05-06 11:06 ` [PATCH v5 6/7] Input: pixcir_i2c_ts: Implement wakeup from suspend Roger Quadros
2014-05-06 11:06   ` Roger Quadros
2014-05-19  5:55   ` Dmitry Torokhov
2014-05-06 11:06 ` [PATCH v5 7/7] Input: pixcir_i2c_ts: Add device tree support Roger Quadros
2014-05-06 11:06   ` Roger Quadros
2014-05-19  5:54   ` Dmitry Torokhov
2014-05-19  7:50     ` Roger Quadros
2014-05-19  7:50       ` Roger Quadros
2014-05-19  8:27   ` [PATCH v6 " Roger Quadros
2014-05-19  8:27     ` Roger Quadros

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5379B5F9.70900@ti.com \
    --to=rogerq-l0cymroini0@public.gmane.org \
    --cc=balbi-l0cyMroinI0@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=dmitry.torokhov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=dmurphy-l0cyMroinI0@public.gmane.org \
    --cc=linux-input-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mugunthanvnm-l0cyMroinI0@public.gmane.org \
    --cc=nsekhar-l0cyMroinI0@public.gmane.org \
    --cc=rydberg-Hk7bIW8heu4wFerOooGFRg@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.