# \[PATCH\] Fix sentelic multi-touch driver

- Subsystems: INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN) DRIVERS, THE REST
- Maintainers: Dmitry Torokhov, Linus Torvalds
- List: linux-input
- 10 messages, 3 authors
- Page: https://ratatoskr.run/linux-input/2012/06/3885785/t

## \[PATCH\] Fix sentelic multi-touch driver

- From: Olivier Goffart \<hidden\>
- Date: 2012-06-27 21:47:11 
- Message: https://ratatoskr.run/linux-input/2012/06/3885785.md

```text
Always report both finger between the sync.  Even if the documentation
of input-mt says one can only report one at the time, it does not
work otherwise. This fix scrolling in X11 which flickers a lot.

Ignore the duplicate or release events. They keep some gestures from
working (such as the two-finger tap)

This seems to fix the problems reported here:
https://bugzilla.kernel.org/show_bug.cgi?id=43591

Signed-off-by: Olivier Goffart <redacted>
---
 drivers/input/mouse/sentelic.c | 46 +++++++++++++++++++++++++++++++++++++-----
 drivers/input/mouse/sentelic.h |  3 +++
 2 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/drivers/input/mouse/sentelic.c b/drivers/input/mouse/sentelic.c
index 3f5649f..b205857 100644
--- a/drivers/input/mouse/sentelic.c
+++ b/drivers/input/mouse/sentelic.c
@@ -731,6 +731,17 @@ static psmouse_ret_t fsp_process_byte(struct psmouse *psmouse)
 			 */
 			fgrs = 2;
 
+			if (abs_x == 0 && abs_y == 0) {
+				/*
+				 * We can ignore multi-finger release events.
+				 * We notice a finger has left the touchpad
+				 * when we receive events for the other finger.
+				 * And for the last finger, we receive
+				 * single-finger release events.
+				 */
+				return PSMOUSE_FULL_PACKET;
+			}
+
 			/* MFMC packet */
 			if (packet[0] & FSP_PB0_MFMC_FGR2) {
 				/* 2nd finger */
@@ -742,10 +753,16 @@ static psmouse_ret_t fsp_process_byte(struct psmouse *psmouse)
 					 */
 					fgrs = 1;
 					fsp_set_slot(dev, 0, false, 0, 0);
+					fsp_set_slot(dev, 1, fgrs == 1,
+						     abs_x, abs_y);
+				} else {
+					ad->last_mt_fgr = 2;
+					fsp_set_slot(dev, 0, true,
+						     ad->finger1_abs_x,
+						     ad->finger1_abs_y);
+					fsp_set_slot(dev, 1, fgrs == 2,
+						     abs_x, abs_y);
 				}
-				ad->last_mt_fgr = 2;
-
-				fsp_set_slot(dev, 1, fgrs == 2, abs_x, abs_y);
 			} else {
 				/* 1st finger */
 				if (ad->last_mt_fgr == 1) {
@@ -755,10 +772,29 @@ static psmouse_ret_t fsp_process_byte(struct psmouse *psmouse)
 					 * the 2nd finger is up
 					 */
 					fgrs = 1;
+					fsp_set_slot(dev, 0, fgrs != 0,
+						     abs_x, abs_y);
 					fsp_set_slot(dev, 1, false, 0, 0);
+				} else {
+					ad->finger1_abs_x = abs_x;
+					ad->finger1_abs_y = abs_y;
+
+					/*
+					 * There is a superflous event from the
+					 * driver when the two fingers are put
+					 * on the touchpad. Don't set
+					 * last_mt_fgr if we have not seen the
+					 * second figner yet, so the previous
+					 * workarond is not triggered and the
+					 * superflous event is ignored.
+					 * This is required to get the two
+					 * finger tap gesture working.
+					 */
+					if (ad->last_mt_fgr != 0)
+						ad->last_mt_fgr = 1;
+
+					return PSMOUSE_FULL_PACKET;
 				}
-				ad->last_mt_fgr = 1;
-				fsp_set_slot(dev, 0, fgrs != 0, abs_x, abs_y);
 			}
 		} else {
 			/* SFAC packet */
diff --git a/drivers/input/mouse/sentelic.h b/drivers/input/mouse/sentelic.h
index aa697ec..7224f84 100644
--- a/drivers/input/mouse/sentelic.h
+++ b/drivers/input/mouse/sentelic.h
@@ -117,6 +117,9 @@ struct fsp_data {
 	unsigned char	last_reg;	/* Last register we requested read from */
 	unsigned char	last_val;
 	unsigned int	last_mt_fgr;	/* Last seen finger(multitouch) */
+
+	unsigned short finger1_abs_x; /* finger1 absolute position */
+	unsigned short finger1_abs_y;
 };
 
 #ifdef CONFIG_MOUSE_PS2_SENTELIC
-- 
1.7.11.1

```

## Re: \[PATCH\] Fix sentelic multi-touch driver

- From: Tai-hwa Liang \<hidden\>
- Date: 2012-06-28 08:02:19 
- Message: https://ratatoskr.run/linux-input/2012/06/8919788.md

```text
On Wed, 27 Jun 2012, Olivier Goffart wrote:
> Always report both finger between the sync.  Even if the documentation
> of input-mt says one can only report one at the time, it does not
> work otherwise. This fix scrolling in X11 which flickers a lot.

  I have a similar patch to address this issue. Would you please try to
see if https://bugzilla.kernel.org/attachment.cgi?id=73991 works for you?

> Ignore the duplicate or release events. They keep some gestures from
> working (such as the two-finger tap)
>
> This seems to fix the problems reported here:
> https://bugzilla.kernel.org/show_bug.cgi?id=43591

  FWIW, https://bugzilla.kernel.org/show_bug.cgi?id=43197 is the original
thread of the aforementioned patch.

Thanks,

Tai-hwa Liang
```

## Re: \[PATCH\] Fix sentelic multi-touch driver

- From: Olivier Goffart \<hidden\>
- Date: 2012-06-28 08:32:08 
- Message: https://ratatoskr.run/linux-input/2012/06/8919789.md

```text
On Thursday 28 June 2012 16:02:15 Tai-hwa Liang wrote:
> On Wed, 27 Jun 2012, Olivier Goffart wrote:
> > Always report both finger between the sync.  Even if the documentation
> > of input-mt says one can only report one at the time, it does not
> > work otherwise. This fix scrolling in X11 which flickers a lot.
> 
>    I have a similar patch to address this issue. Would you please try to
> see if https://bugzilla.kernel.org/attachment.cgi?id=73991 works for you?


Hi,

That patch also fixes the issue here.  (It fixes scrolling and two finger tap)
But the case in which you put two finger into the touchpad then release one 
finger is not handled properly. (I took care of that issue)

(I have a Asus Zenbook UX31)

 
> > Ignore the duplicate or release events. They keep some gestures from
> > working (such as the two-finger tap)
> > 
> > This seems to fix the problems reported here:
> > https://bugzilla.kernel.org/show_bug.cgi?id=43591
> 
>    FWIW, https://bugzilla.kernel.org/show_bug.cgi?id=43197 is the original
> thread of the aforementioned patch.


```

## Re: \[PATCH\] Fix sentelic multi-touch driver

- From: Tai-hwa Liang \<hidden\>
- Date: 2012-06-28 09:17:55 
- Message: https://ratatoskr.run/linux-input/2012/06/8919790.md

```text
On Thu, 28 Jun 2012, Olivier Goffart wrote:
> On Thursday 28 June 2012 16:02:15 Tai-hwa Liang wrote:
[...]
>>    I have a similar patch to address this issue. Would you please try to
>> see if https://bugzilla.kernel.org/attachment.cgi?id=73991 works for you?
>
> Hi,
>
> That patch also fixes the issue here.  (It fixes scrolling and two finger tap)
> But the case in which you put two finger into the touchpad then release one
> finger is not handled properly. (I took care of that issue)

  Would you please be more specific about the steps to reproduce this?
I've tested both of these two patches but failed to see the difference in
this case.

Thanks,

Tai-hwa Liang
```

## Re: \[PATCH\] Fix sentelic multi-touch driver

- From: Olivier Goffart \<hidden\>
- Date: 2012-06-28 09:44:46 
- Message: https://ratatoskr.run/linux-input/2012/06/8919791.md

```text
On Thursday 28 June 2012 17:17:50 Tai-hwa Liang wrote:
> On Thu, 28 Jun 2012, Olivier Goffart wrote:
> > On Thursday 28 June 2012 16:02:15 Tai-hwa Liang wrote:
> [...]
> 
> >>    I have a similar patch to address this issue. Would you please try to
> >> 
> >> see if https://bugzilla.kernel.org/attachment.cgi?id=73991 works for you?
> > 
> > Hi,
> > 
> > That patch also fixes the issue here.  (It fixes scrolling and two finger
> > tap) But the case in which you put two finger into the touchpad then
> > release one finger is not handled properly. (I took care of that issue)
> 
>    Would you please be more specific about the steps to reproduce this?
> I've tested both of these two patches but failed to see the difference in
> this case.


 - Touch the touchpad with one finger and move it: this moves the cursor
 - Place a second finger: this allows you to scoll
 - Release a finger: you should now be able to move the cursor again.  This is 
the part that does not work in one of the patch

```

## Re: \[PATCH\] Fix sentelic multi-touch driver

- From: Tai-hwa Liang \<hidden\>
- Date: 2012-06-29 03:03:20 
- Message: https://ratatoskr.run/linux-input/2012/06/8919796.md

```text
On Thu, 28 Jun 2012, Olivier Goffart wrote:
[...]
> - Touch the touchpad with one finger and move it: this moves the cursor
> - Place a second finger: this allows you to scoll
> - Release a finger: you should now be able to move the cursor again.  This is
> the part that does not work in one of the patch

  Sorry, I didn't realise that one of my patch submitted a few months ago
(namely, http://www.spinics.net/lists/linux-input/msg19443.html) isn't
in the master tree, which is different from my local working copy.

  With the correct flag(FSP_BIT_SWC1_EN_GID) being set, the hardware
clears MFMC bit during 2 -> 1 finger transition.  The attached patch is
an aggregated version against Dmitry's master branch, which supposes to fix the testing case listed above.

Thanks,

Tai-hwa Liang
```

## Re: \[PATCH\] Fix sentelic multi-touch driver

- From: Olivier Goffart \<hidden\>
- Date: 2012-06-29 07:52:39 
- Message: https://ratatoskr.run/linux-input/2012/06/8919797.md

```text
On Friday 29 June 2012 11:03:12 Tai-hwa Liang wrote:
> On Thu, 28 Jun 2012, Olivier Goffart wrote:
> [...]
> 
> > - Touch the touchpad with one finger and move it: this moves the cursor
> > - Place a second finger: this allows you to scoll
> > - Release a finger: you should now be able to move the cursor again.  This
> > is the part that does not work in one of the patch
> 
>    Sorry, I didn't realise that one of my patch submitted a few months ago
> (namely, http://www.spinics.net/lists/linux-input/msg19443.html) isn't
> in the master tree, which is different from my local working copy.
> 
>    With the correct flag(FSP_BIT_SWC1_EN_GID) being set, the hardware
> clears MFMC bit during 2 -> 1 finger transition.  The attached patch is
> an aggregated version against Dmitry's master branch, which supposes to fix
> the testing case listed above.
> 
> Thanks,
> 
> Tai-hwa Liang

I am testing against the stable 3.4.y branch.
With that patch, scrolling is very slow, and it emits middle click sometimes 
while I want to scroll fast. 

Looking at the debug output, i see a lot of NOTIFY packets, for the same  
number of packets/seconds (77). So then there is 5 times less multi touch 
events. Maybe that's why.

Regards
-- 
Olivier
```

## Re: \[PATCH\] Fix sentelic multi-touch driver

- From: Tai-hwa Liang \<hidden\>
- Date: 2012-06-29 14:51:20 
- Message: https://ratatoskr.run/linux-input/2012/06/8919799.md

```text
On Fri, 29 Jun 2012, Olivier Goffart wrote:
> On Friday 29 June 2012 11:03:12 Tai-hwa Liang wrote:
[...]
>>    With the correct flag(FSP_BIT_SWC1_EN_GID) being set, the hardware
>> clears MFMC bit during 2 -> 1 finger transition.  The attached patch is
>> an aggregated version against Dmitry's master branch, which supposes to fix
>> the testing case listed above.
>
> I am testing against the stable 3.4.y branch.
> With that patch, scrolling is very slow, and it emits middle click sometimes
> while I want to scroll fast.
>
> Looking at the debug output, i see a lot of NOTIFY packets, for the same
> number of packets/seconds (77). So then there is 5 times less multi touch
> events. Maybe that's why.

  I see. It appears to me that we'd better to revert back to the last_mt_fgr
workaround to avoid such delay.

-- 
Thanks,

Tai-hwa Liang
```

## Re: \[PATCH\] Fix sentelic multi-touch driver

- From: Olivier Goffart \<hidden\>
- Date: 2012-06-29 15:01:07 
- Message: https://ratatoskr.run/linux-input/2012/06/8919800.md

```text
On Friday 29 June 2012 22:51:16 Tai-hwa Liang wrote:
> On Fri, 29 Jun 2012, Olivier Goffart wrote:
> > On Friday 29 June 2012 11:03:12 Tai-hwa Liang wrote:
> [...]
> 
> >>    With the correct flag(FSP_BIT_SWC1_EN_GID) being set, the hardware
> >> 
> >> clears MFMC bit during 2 -> 1 finger transition.  The attached patch is
> >> an aggregated version against Dmitry's master branch, which supposes to
> >> fix
> >> the testing case listed above.
> > 
> > I am testing against the stable 3.4.y branch.
> > With that patch, scrolling is very slow, and it emits middle click
> > sometimes while I want to scroll fast.
> > 
> > Looking at the debug output, i see a lot of NOTIFY packets, for the same
> > number of packets/seconds (77). So then there is 5 times less multi touch
> > events. Maybe that's why.
> 
>    I see. It appears to me that we'd better to revert back to the
> last_mt_fgr workaround to avoid such delay.

That last patch seems to work perfectly.

Thanks
-- 
Olivier
```

## Re: \[PATCH\] Fix sentelic multi-touch driver

- From: Olivier Goffart \<hidden\>
- Date: 2012-07-11 08:50:41 
- Message: https://ratatoskr.run/linux-input/2012/07/8919898.md

```text
On Friday 29 June 2012 17:00:39 Olivier Goffart wrote:
> On Friday 29 June 2012 22:51:16 Tai-hwa Liang wrote:
> > On Fri, 29 Jun 2012, Olivier Goffart wrote:
> > > On Friday 29 June 2012 11:03:12 Tai-hwa Liang wrote:
> > [...]
> > 
> > >>    With the correct flag(FSP_BIT_SWC1_EN_GID) being set, the hardware
> > >> 
> > >> clears MFMC bit during 2 -> 1 finger transition.  The attached patch is
> > >> an aggregated version against Dmitry's master branch, which supposes to
> > >> fix
> > >> the testing case listed above.
> > > 
> > > I am testing against the stable 3.4.y branch.
> > > With that patch, scrolling is very slow, and it emits middle click
> > > sometimes while I want to scroll fast.
> > > 
> > > Looking at the debug output, i see a lot of NOTIFY packets, for the same
> > > number of packets/seconds (77). So then there is 5 times less multi
> > > touch
> > > events. Maybe that's why.
> > > 
> >    I see. It appears to me that we'd better to revert back to the
> > 
> > last_mt_fgr workaround to avoid such delay.
> 
> That last patch seems to work perfectly.
> 
> Thanks

Hi,

Is there any news regarding this issue?  When is it going to be fixed 
upstream?
I am using that last patch and it is working very well.

-- 
Olivier
```
