diff mbox

Input: alps - Demystify trackstick initialization for v3 and v6 protocols

Message ID 20180312230915.26050-1-pali.rohar@gmail.com (mailing list archive)
State Accepted
Headers show

Commit Message

Pali Rohár March 12, 2018, 11:09 p.m. UTC
Remove cite "Not sure what this does, but it is absolutely essential".

Extract initialization of trackstick part when touchpad is in passthrought
mode for v3 and v6 protocols into own function. Initialization for v3 is:
setscale11, setscale11, setscale11, nibble 0x9, nibble 0x4. Initialization
for v6 is: setscale11, setscale11, setscale11, setrate 0xC8, setrate 0x14.
Nibbles 0x9 and 0x4 for v3 protocol correspondent to setrate 0xC8 and 0x14,
therefore these sequences are same.

When touchpad is in passthrought mode, then OS communicates with trackstick
and this sequence is some magic vendor PS/2 command to put trackstick into
"extended" mode. After that sequence trackstick starts reporting packets in
some vendor 4 bytes format (first byte is always 0xE8).

Next step after configuring trackstick to be in "extended" mode, is to
configure touchpad for v3 protocol to expect that trackstick reports data
in "extended" mode. For v3 protocol this is done by setting bit 1 in
register 0xC2C8 (offset 0x08 from base address 0xC2C0).

When both touchpad and trackstick are not configured for "extended" mode
then touchpad reports trackstick packets in different format, which is not
supported by psmouse/alps driver (yet).

In Cirque documentation GP-AN- 130823 INTERFACING TO GEN4 OVER I2C (PDF)
available at http://www.cirque.com/gen4-dev-resources is Logical Address
0xC2C8 named as PS2AuxControl and Bit Number 1 as ProcessAuxExtendedData
with description: Auxiliary device data is assumed to be extended data when
set.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
---
 drivers/input/mouse/alps.c | 80 ++++++++++++++++++++++++++++------------------
 1 file changed, 49 insertions(+), 31 deletions(-)

Comments

Pali Rohár March 12, 2018, 11:13 p.m. UTC | #1
Masaki, if you have access to the internal ALPS v3 / Rushmore
documentation, I would like to have a review of this patch or
confirmation of those information :-)

On Tuesday 13 March 2018 00:09:15 Pali Rohár wrote:
> Remove cite "Not sure what this does, but it is absolutely essential".
> 
> Extract initialization of trackstick part when touchpad is in passthrought
> mode for v3 and v6 protocols into own function. Initialization for v3 is:
> setscale11, setscale11, setscale11, nibble 0x9, nibble 0x4. Initialization
> for v6 is: setscale11, setscale11, setscale11, setrate 0xC8, setrate 0x14.
> Nibbles 0x9 and 0x4 for v3 protocol correspondent to setrate 0xC8 and 0x14,
> therefore these sequences are same.
> 
> When touchpad is in passthrought mode, then OS communicates with trackstick
> and this sequence is some magic vendor PS/2 command to put trackstick into
> "extended" mode. After that sequence trackstick starts reporting packets in
> some vendor 4 bytes format (first byte is always 0xE8).
> 
> Next step after configuring trackstick to be in "extended" mode, is to
> configure touchpad for v3 protocol to expect that trackstick reports data
> in "extended" mode. For v3 protocol this is done by setting bit 1 in
> register 0xC2C8 (offset 0x08 from base address 0xC2C0).
> 
> When both touchpad and trackstick are not configured for "extended" mode
> then touchpad reports trackstick packets in different format, which is not
> supported by psmouse/alps driver (yet).
> 
> In Cirque documentation GP-AN- 130823 INTERFACING TO GEN4 OVER I2C (PDF)
> available at http://www.cirque.com/gen4-dev-resources is Logical Address
> 0xC2C8 named as PS2AuxControl and Bit Number 1 as ProcessAuxExtendedData
> with description: Auxiliary device data is assumed to be extended data when
> set.
> 
> Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
> ---
>  drivers/input/mouse/alps.c | 80 ++++++++++++++++++++++++++++------------------
>  1 file changed, 49 insertions(+), 31 deletions(-)
> 
> diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
> index dbe57da8c1a1..010c1bcdb06d 100644
> --- a/drivers/input/mouse/alps.c
> +++ b/drivers/input/mouse/alps.c
> @@ -2063,14 +2063,11 @@ static int alps_hw_init_v1_v2(struct psmouse *psmouse)
>  	return 0;
>  }
>  
> -static int alps_hw_init_v6(struct psmouse *psmouse)
> +/* Must be in passthrough mode when calling this function */
> +static int alps_trackstick_enter_extended_mode_v3_v6(struct psmouse *psmouse)
>  {
>  	unsigned char param[2] = {0xC8, 0x14};
>  
> -	/* Enter passthrough mode to let trackpoint enter 6byte raw mode */
> -	if (alps_passthrough_mode_v2(psmouse, true))
> -		return -1;
> -
>  	if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
>  	    ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
>  	    ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
> @@ -2078,9 +2075,25 @@ static int alps_hw_init_v6(struct psmouse *psmouse)
>  	    ps2_command(&psmouse->ps2dev, &param[1], PSMOUSE_CMD_SETRATE))
>  		return -1;
>  
> +	return 0;
> +}
> +
> +static int alps_hw_init_v6(struct psmouse *psmouse)
> +{
> +	int ret;
> +
> +	/* Enter passthrough mode to let trackpoint enter 6byte raw mode */
> +	if (alps_passthrough_mode_v2(psmouse, true))
> +		return -1;
> +
> +	ret = alps_trackstick_enter_extended_mode_v3_v6(psmouse);
> +
>  	if (alps_passthrough_mode_v2(psmouse, false))
>  		return -1;
>  
> +	if (ret)
> +		return ret;
> +
>  	if (alps_absolute_mode_v6(psmouse)) {
>  		psmouse_err(psmouse, "Failed to enable absolute mode\n");
>  		return -1;
> @@ -2154,10 +2167,18 @@ static int alps_probe_trackstick_v3_v7(struct psmouse *psmouse, int reg_base)
>  
>  static int alps_setup_trackstick_v3(struct psmouse *psmouse, int reg_base)
>  {
> -	struct ps2dev *ps2dev = &psmouse->ps2dev;
>  	int ret = 0;
> +	int reg_val;
>  	unsigned char param[4];
>  
> +	/*
> +	 * We need to configure trackstick to report data for touchpad in
> +	 * extended format. And also we need to tell touchpad to expect data
> +	 * from trackstick in extended format. Without this configuration
> +	 * trackstick packets sent from touchpad are in basic format which is
> +	 * different from what we expect.
> +	 */
> +
>  	if (alps_passthrough_mode_v3(psmouse, reg_base, true))
>  		return -EIO;
>  
> @@ -2175,39 +2196,36 @@ static int alps_setup_trackstick_v3(struct psmouse *psmouse, int reg_base)
>  		ret = -ENODEV;
>  	} else {
>  		psmouse_dbg(psmouse, "trackstick E7 report: %3ph\n", param);
> -
> -		/*
> -		 * Not sure what this does, but it is absolutely
> -		 * essential. Without it, the touchpad does not
> -		 * work at all and the trackstick just emits normal
> -		 * PS/2 packets.
> -		 */
> -		if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
> -		    ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
> -		    ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
> -		    alps_command_mode_send_nibble(psmouse, 0x9) ||
> -		    alps_command_mode_send_nibble(psmouse, 0x4)) {
> -			psmouse_err(psmouse,
> -				    "Error sending magic E6 sequence\n");
> +		if (alps_trackstick_enter_extended_mode_v3_v6(psmouse)) {
> +			psmouse_err(psmouse, "Failed to enter into trackstick extended mode\n");
>  			ret = -EIO;
> -			goto error;
>  		}
> +	}
> +
> +	if (alps_passthrough_mode_v3(psmouse, reg_base, false))
> +		return -EIO;
> +
> +	if (ret)
> +		return ret;
>  
> +	if (alps_enter_command_mode(psmouse))
> +		return -EIO;
> +
> +	reg_val = alps_command_mode_read_reg(psmouse, reg_base + 0x08);
> +	if (reg_val == -1) {
> +		ret = -EIO;
> +	} else {
>  		/*
> -		 * This ensures the trackstick packets are in the format
> -		 * supported by this driver. If bit 1 isn't set the packet
> -		 * format is different.
> +		 * Tell touchpad that trackstick is now in extended mode.
> +		 * If bit 1 isn't set the packet format is different.
>  		 */
> -		if (alps_enter_command_mode(psmouse) ||
> -		    alps_command_mode_write_reg(psmouse,
> -						reg_base + 0x08, 0x82) ||
> -		    alps_exit_command_mode(psmouse))
> +		reg_val |= BIT(1);
> +		if (__alps_command_mode_write_reg(psmouse, reg_val))
>  			ret = -EIO;
>  	}
>  
> -error:
> -	if (alps_passthrough_mode_v3(psmouse, reg_base, false))
> -		ret = -EIO;
> +	if (alps_exit_command_mode(psmouse))
> +		return -EIO;
>  
>  	return ret;
>  }
Pali Rohár March 14, 2018, 10:58 p.m. UTC | #2
Hi! Thank you for information.

Your PS/2 Aux Port Control description seems to really matches. Just
there is reverse order of bits. Bit 0 in description is highest,
therefore matches BIT(7) macro.

Bit 6 in description (BIT(1) in code) describes SP Extended Mode which
alps.c enabled. And in that description is written:

"If 1 SP is extended packet format (driver must set SP raw mode and GP
absolute mode)."

Do you have any idea what "SP raw mode" is? How to set it? For me it
looks like it could be that extended mode of trackstick itself.

"GP absolute mode" I guess is GlidePoint absolute mode, therefore enable
6 byte absolute mode for touchpad.

And for Bit 7 (BIT(0)) is written:

This bit is used with the PS/2 Aux port to use the Pass-Thru mode ( see
appendix A ). Do you have some information about this appendix A?

On Wednesday 14 March 2018 10:21:43 Masaki Ota wrote:
> Hi, Pali,
> 
> I just picked up the spec which relates with trackstic.
> 
> Best Regards,
> Masaki Ota
> -----Original Message-----
> From: Pali Rohár [mailto:pali.rohar@gmail.com] 
> Sent: Tuesday, March 13, 2018 8:14 AM
> To: 太田 真喜 Masaki Ota <masaki.ota@jp.alps.com>; Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Cc: linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] Input: alps - Demystify trackstick initialization for v3 and v6 protocols
> 
> Masaki, if you have access to the internal ALPS v3 / Rushmore documentation, I would like to have a review of this patch or confirmation of those information :-)
Pali Rohár March 16, 2018, 10:58 a.m. UTC | #3
Great, thank you. Enabling that RAW/extended/SP4 mode is done by
sequence E6, E6, E6, F3, C8, F3, 14 (written in page 35) and it matches
what function alps_trackstick_enter_extended_mode_v3_v6() in my patch is
doing. So is correct.

On page 36 I see that there is described Method 1 for reporting stick
data which prevents cursor jumps. Seems that kernel uses Method 2.
Method 1 depends on some prioritization.

Do you have some information how to activate Method 1? Sometimes I
observe that problem with "cursor jumps" and from Method 1 could prevent
it. So I would like to try experimenting...

On Wednesday 14 March 2018 23:56:46 Masaki Ota wrote:
> Hi, Pali,
> 
> I have added Appendix.
> According to this spec documents, SP raw mode is SP 4 byte mode.
> I think Extended mode meaning is almost all the same as Raw mode.
> The description of how to set is written in Page 35.
> 
> Best Regards,
> Masaki Ota
> -----Original Message-----
> From: Pali Rohár [mailto:pali.rohar@gmail.com] 
> Sent: Thursday, March 15, 2018 7:58 AM
> To: 太田 真喜 Masaki Ota <masaki.ota@jp.alps.com>
> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] Input: alps - Demystify trackstick initialization for v3 and v6 protocols
> 
> Hi! Thank you for information.
> 
> Your PS/2 Aux Port Control description seems to really matches. Just there is reverse order of bits. Bit 0 in description is highest, therefore matches BIT(7) macro.
> 
> Bit 6 in description (BIT(1) in code) describes SP Extended Mode which alps.c enabled. And in that description is written:
> 
> "If 1 SP is extended packet format (driver must set SP raw mode and GP absolute mode)."
> 
> Do you have any idea what "SP raw mode" is? How to set it? For me it looks like it could be that extended mode of trackstick itself.
> 
> "GP absolute mode" I guess is GlidePoint absolute mode, therefore enable
> 6 byte absolute mode for touchpad.
> 
> And for Bit 7 (BIT(0)) is written:
> 
> This bit is used with the PS/2 Aux port to use the Pass-Thru mode ( see appendix A ). Do you have some information about this appendix A?
> 
> On Wednesday 14 March 2018 10:21:43 Masaki Ota wrote:
> > Hi, Pali,
> > 
> > I just picked up the spec which relates with trackstic.
> > 
> > Best Regards,
> > Masaki Ota
> > -----Original Message-----
> > From: Pali Rohár [mailto:pali.rohar@gmail.com]
> > Sent: Tuesday, March 13, 2018 8:14 AM
> > To: 太田 真喜 Masaki Ota <masaki.ota@jp.alps.com>; Dmitry Torokhov 
> > <dmitry.torokhov@gmail.com>
> > Cc: linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
> > Subject: Re: [PATCH] Input: alps - Demystify trackstick initialization 
> > for v3 and v6 protocols
> > 
> > Masaki, if you have access to the internal ALPS v3 / Rushmore 
> > documentation, I would like to have a review of this patch or 
> > confirmation of those information :-)
> 
> --
> Pali Rohár
> pali.rohar@gmail.com
Masaki Ota March 19, 2018, 8:41 a.m. UTC | #4
Hi, Pali,

v3/v6 devices are T3 type, and it can use only Method 2.
P36 (At this time GLIDEPOINT_T3 uses the Method 2 ....)
T3 has the potential that uses Method2, but I think it needs to change Firmware.

Best Regards,
Masaki Ota
-----Original Message-----
From: Pali Rohár [mailto:pali.rohar@gmail.com] 

Sent: Friday, March 16, 2018 7:58 PM
To: 太田 真喜 Masaki Ota <masaki.ota@jp.alps.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Input: alps - Demystify trackstick initialization for v3 and v6 protocols

Great, thank you. Enabling that RAW/extended/SP4 mode is done by sequence E6, E6, E6, F3, C8, F3, 14 (written in page 35) and it matches what function alps_trackstick_enter_extended_mode_v3_v6() in my patch is doing. So is correct.

On page 36 I see that there is described Method 1 for reporting stick data which prevents cursor jumps. Seems that kernel uses Method 2.
Method 1 depends on some prioritization.

Do you have some information how to activate Method 1? Sometimes I observe that problem with "cursor jumps" and from Method 1 could prevent it. So I would like to try experimenting...

On Wednesday 14 March 2018 23:56:46 Masaki Ota wrote:
> Hi, Pali,

> 

> I have added Appendix.

> According to this spec documents, SP raw mode is SP 4 byte mode.

> I think Extended mode meaning is almost all the same as Raw mode.

> The description of how to set is written in Page 35.

> 

> Best Regards,

> Masaki Ota

> -----Original Message-----

> From: Pali Rohár [mailto:pali.rohar@gmail.com]

> Sent: Thursday, March 15, 2018 7:58 AM

> To: 太田 真喜 Masaki Ota <masaki.ota@jp.alps.com>

> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>; 

> linux-input@vger.kernel.org; linux-kernel@vger.kernel.org

> Subject: Re: [PATCH] Input: alps - Demystify trackstick initialization 

> for v3 and v6 protocols

> 

> Hi! Thank you for information.

> 

> Your PS/2 Aux Port Control description seems to really matches. Just there is reverse order of bits. Bit 0 in description is highest, therefore matches BIT(7) macro.

> 

> Bit 6 in description (BIT(1) in code) describes SP Extended Mode which alps.c enabled. And in that description is written:

> 

> "If 1 SP is extended packet format (driver must set SP raw mode and GP absolute mode)."

> 

> Do you have any idea what "SP raw mode" is? How to set it? For me it looks like it could be that extended mode of trackstick itself.

> 

> "GP absolute mode" I guess is GlidePoint absolute mode, therefore 

> enable

> 6 byte absolute mode for touchpad.

> 

> And for Bit 7 (BIT(0)) is written:

> 

> This bit is used with the PS/2 Aux port to use the Pass-Thru mode ( see appendix A ). Do you have some information about this appendix A?

> 

> On Wednesday 14 March 2018 10:21:43 Masaki Ota wrote:

> > Hi, Pali,

> > 

> > I just picked up the spec which relates with trackstic.

> > 

> > Best Regards,

> > Masaki Ota

> > -----Original Message-----

> > From: Pali Rohár [mailto:pali.rohar@gmail.com]

> > Sent: Tuesday, March 13, 2018 8:14 AM

> > To: 太田 真喜 Masaki Ota <masaki.ota@jp.alps.com>; Dmitry Torokhov 

> > <dmitry.torokhov@gmail.com>

> > Cc: linux-input@vger.kernel.org; linux-kernel@vger.kernel.org

> > Subject: Re: [PATCH] Input: alps - Demystify trackstick 

> > initialization for v3 and v6 protocols

> > 

> > Masaki, if you have access to the internal ALPS v3 / Rushmore 

> > documentation, I would like to have a review of this patch or 

> > confirmation of those information :-)

> 

> --

> Pali Rohár

> pali.rohar@gmail.com


--
Pali Rohár
pali.rohar@gmail.com
Pali Rohár March 21, 2018, 4:41 p.m. UTC | #5
That is pity, but OK.

Anyway, as wrote patch which I sent in the first email matches this
documentation.

Dmitry, can you review/comment/accept/reject this patch?

On Monday 19 March 2018 08:41:19 Masaki Ota wrote:
> Hi, Pali,
> 
> v3/v6 devices are T3 type, and it can use only Method 2.
> P36 (At this time GLIDEPOINT_T3 uses the Method 2 ....)
> T3 has the potential that uses Method2, but I think it needs to change Firmware.
> 
> Best Regards,
> Masaki Ota
> -----Original Message-----
> From: Pali Rohár [mailto:pali.rohar@gmail.com] 
> Sent: Friday, March 16, 2018 7:58 PM
> To: 太田 真喜 Masaki Ota <masaki.ota@jp.alps.com>
> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] Input: alps - Demystify trackstick initialization for v3 and v6 protocols
> 
> Great, thank you. Enabling that RAW/extended/SP4 mode is done by sequence E6, E6, E6, F3, C8, F3, 14 (written in page 35) and it matches what function alps_trackstick_enter_extended_mode_v3_v6() in my patch is doing. So is correct.
> 
> On page 36 I see that there is described Method 1 for reporting stick data which prevents cursor jumps. Seems that kernel uses Method 2.
> Method 1 depends on some prioritization.
> 
> Do you have some information how to activate Method 1? Sometimes I observe that problem with "cursor jumps" and from Method 1 could prevent it. So I would like to try experimenting...
> 
> On Wednesday 14 March 2018 23:56:46 Masaki Ota wrote:
> > Hi, Pali,
> > 
> > I have added Appendix.
> > According to this spec documents, SP raw mode is SP 4 byte mode.
> > I think Extended mode meaning is almost all the same as Raw mode.
> > The description of how to set is written in Page 35.
> > 
> > Best Regards,
> > Masaki Ota
> > -----Original Message-----
> > From: Pali Rohár [mailto:pali.rohar@gmail.com]
> > Sent: Thursday, March 15, 2018 7:58 AM
> > To: 太田 真喜 Masaki Ota <masaki.ota@jp.alps.com>
> > Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>; 
> > linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
> > Subject: Re: [PATCH] Input: alps - Demystify trackstick initialization 
> > for v3 and v6 protocols
> > 
> > Hi! Thank you for information.
> > 
> > Your PS/2 Aux Port Control description seems to really matches. Just there is reverse order of bits. Bit 0 in description is highest, therefore matches BIT(7) macro.
> > 
> > Bit 6 in description (BIT(1) in code) describes SP Extended Mode which alps.c enabled. And in that description is written:
> > 
> > "If 1 SP is extended packet format (driver must set SP raw mode and GP absolute mode)."
> > 
> > Do you have any idea what "SP raw mode" is? How to set it? For me it looks like it could be that extended mode of trackstick itself.
> > 
> > "GP absolute mode" I guess is GlidePoint absolute mode, therefore 
> > enable
> > 6 byte absolute mode for touchpad.
> > 
> > And for Bit 7 (BIT(0)) is written:
> > 
> > This bit is used with the PS/2 Aux port to use the Pass-Thru mode ( see appendix A ). Do you have some information about this appendix A?
> > 
> > On Wednesday 14 March 2018 10:21:43 Masaki Ota wrote:
> > > Hi, Pali,
> > > 
> > > I just picked up the spec which relates with trackstic.
> > > 
> > > Best Regards,
> > > Masaki Ota
> > > -----Original Message-----
> > > From: Pali Rohár [mailto:pali.rohar@gmail.com]
> > > Sent: Tuesday, March 13, 2018 8:14 AM
> > > To: 太田 真喜 Masaki Ota <masaki.ota@jp.alps.com>; Dmitry Torokhov 
> > > <dmitry.torokhov@gmail.com>
> > > Cc: linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
> > > Subject: Re: [PATCH] Input: alps - Demystify trackstick 
> > > initialization for v3 and v6 protocols
> > > 
> > > Masaki, if you have access to the internal ALPS v3 / Rushmore 
> > > documentation, I would like to have a review of this patch or 
> > > confirmation of those information :-)
> > 
> > --
> > Pali Rohár
> > pali.rohar@gmail.com
> 
> --
> Pali Rohár
> pali.rohar@gmail.com
Pali Rohár April 18, 2018, 11:40 a.m. UTC | #6
Dmitry, ping

On Wednesday 21 March 2018 17:41:26 Pali Rohár wrote:
> That is pity, but OK.
> 
> Anyway, as wrote patch which I sent in the first email matches this
> documentation.
> 
> Dmitry, can you review/comment/accept/reject this patch?
> 
> On Monday 19 March 2018 08:41:19 Masaki Ota wrote:
> > Hi, Pali,
> > 
> > v3/v6 devices are T3 type, and it can use only Method 2.
> > P36 (At this time GLIDEPOINT_T3 uses the Method 2 ....)
> > T3 has the potential that uses Method2, but I think it needs to change Firmware.
> > 
> > Best Regards,
> > Masaki Ota
> > -----Original Message-----
> > From: Pali Rohár [mailto:pali.rohar@gmail.com] 
> > Sent: Friday, March 16, 2018 7:58 PM
> > To: 太田 真喜 Masaki Ota <masaki.ota@jp.alps.com>
> > Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
> > Subject: Re: [PATCH] Input: alps - Demystify trackstick initialization for v3 and v6 protocols
> > 
> > Great, thank you. Enabling that RAW/extended/SP4 mode is done by sequence E6, E6, E6, F3, C8, F3, 14 (written in page 35) and it matches what function alps_trackstick_enter_extended_mode_v3_v6() in my patch is doing. So is correct.
> > 
> > On page 36 I see that there is described Method 1 for reporting stick data which prevents cursor jumps. Seems that kernel uses Method 2.
> > Method 1 depends on some prioritization.
> > 
> > Do you have some information how to activate Method 1? Sometimes I observe that problem with "cursor jumps" and from Method 1 could prevent it. So I would like to try experimenting...
> > 
> > On Wednesday 14 March 2018 23:56:46 Masaki Ota wrote:
> > > Hi, Pali,
> > > 
> > > I have added Appendix.
> > > According to this spec documents, SP raw mode is SP 4 byte mode.
> > > I think Extended mode meaning is almost all the same as Raw mode.
> > > The description of how to set is written in Page 35.
> > > 
> > > Best Regards,
> > > Masaki Ota
> > > -----Original Message-----
> > > From: Pali Rohár [mailto:pali.rohar@gmail.com]
> > > Sent: Thursday, March 15, 2018 7:58 AM
> > > To: 太田 真喜 Masaki Ota <masaki.ota@jp.alps.com>
> > > Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>; 
> > > linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
> > > Subject: Re: [PATCH] Input: alps - Demystify trackstick initialization 
> > > for v3 and v6 protocols
> > > 
> > > Hi! Thank you for information.
> > > 
> > > Your PS/2 Aux Port Control description seems to really matches. Just there is reverse order of bits. Bit 0 in description is highest, therefore matches BIT(7) macro.
> > > 
> > > Bit 6 in description (BIT(1) in code) describes SP Extended Mode which alps.c enabled. And in that description is written:
> > > 
> > > "If 1 SP is extended packet format (driver must set SP raw mode and GP absolute mode)."
> > > 
> > > Do you have any idea what "SP raw mode" is? How to set it? For me it looks like it could be that extended mode of trackstick itself.
> > > 
> > > "GP absolute mode" I guess is GlidePoint absolute mode, therefore 
> > > enable
> > > 6 byte absolute mode for touchpad.
> > > 
> > > And for Bit 7 (BIT(0)) is written:
> > > 
> > > This bit is used with the PS/2 Aux port to use the Pass-Thru mode ( see appendix A ). Do you have some information about this appendix A?
> > > 
> > > On Wednesday 14 March 2018 10:21:43 Masaki Ota wrote:
> > > > Hi, Pali,
> > > > 
> > > > I just picked up the spec which relates with trackstic.
> > > > 
> > > > Best Regards,
> > > > Masaki Ota
> > > > -----Original Message-----
> > > > From: Pali Rohár [mailto:pali.rohar@gmail.com]
> > > > Sent: Tuesday, March 13, 2018 8:14 AM
> > > > To: 太田 真喜 Masaki Ota <masaki.ota@jp.alps.com>; Dmitry Torokhov 
> > > > <dmitry.torokhov@gmail.com>
> > > > Cc: linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
> > > > Subject: Re: [PATCH] Input: alps - Demystify trackstick 
> > > > initialization for v3 and v6 protocols
> > > > 
> > > > Masaki, if you have access to the internal ALPS v3 / Rushmore 
> > > > documentation, I would like to have a review of this patch or 
> > > > confirmation of those information :-)
> > > 
> > > --
> > > Pali Rohár
> > > pali.rohar@gmail.com
> > 
> > --
> > Pali Rohár
> > pali.rohar@gmail.com
>
Dmitry Torokhov April 23, 2018, 11:40 p.m. UTC | #7
On Wed, Apr 18, 2018 at 01:40:30PM +0200, Pali Rohár wrote:
> Dmitry, ping

Applied, thank you. Can you tell me if I am missing anything else for
ALPS?

Thanks!

> 
> On Wednesday 21 March 2018 17:41:26 Pali Rohár wrote:
> > That is pity, but OK.
> > 
> > Anyway, as wrote patch which I sent in the first email matches this
> > documentation.
> > 
> > Dmitry, can you review/comment/accept/reject this patch?
> > 
> > On Monday 19 March 2018 08:41:19 Masaki Ota wrote:
> > > Hi, Pali,
> > > 
> > > v3/v6 devices are T3 type, and it can use only Method 2.
> > > P36 (At this time GLIDEPOINT_T3 uses the Method 2 ....)
> > > T3 has the potential that uses Method2, but I think it needs to change Firmware.
> > > 
> > > Best Regards,
> > > Masaki Ota
> > > -----Original Message-----
> > > From: Pali Rohár [mailto:pali.rohar@gmail.com] 
> > > Sent: Friday, March 16, 2018 7:58 PM
> > > To: 太田 真喜 Masaki Ota <masaki.ota@jp.alps.com>
> > > Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
> > > Subject: Re: [PATCH] Input: alps - Demystify trackstick initialization for v3 and v6 protocols
> > > 
> > > Great, thank you. Enabling that RAW/extended/SP4 mode is done by sequence E6, E6, E6, F3, C8, F3, 14 (written in page 35) and it matches what function alps_trackstick_enter_extended_mode_v3_v6() in my patch is doing. So is correct.
> > > 
> > > On page 36 I see that there is described Method 1 for reporting stick data which prevents cursor jumps. Seems that kernel uses Method 2.
> > > Method 1 depends on some prioritization.
> > > 
> > > Do you have some information how to activate Method 1? Sometimes I observe that problem with "cursor jumps" and from Method 1 could prevent it. So I would like to try experimenting...
> > > 
> > > On Wednesday 14 March 2018 23:56:46 Masaki Ota wrote:
> > > > Hi, Pali,
> > > > 
> > > > I have added Appendix.
> > > > According to this spec documents, SP raw mode is SP 4 byte mode.
> > > > I think Extended mode meaning is almost all the same as Raw mode.
> > > > The description of how to set is written in Page 35.
> > > > 
> > > > Best Regards,
> > > > Masaki Ota
> > > > -----Original Message-----
> > > > From: Pali Rohár [mailto:pali.rohar@gmail.com]
> > > > Sent: Thursday, March 15, 2018 7:58 AM
> > > > To: 太田 真喜 Masaki Ota <masaki.ota@jp.alps.com>
> > > > Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>; 
> > > > linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
> > > > Subject: Re: [PATCH] Input: alps - Demystify trackstick initialization 
> > > > for v3 and v6 protocols
> > > > 
> > > > Hi! Thank you for information.
> > > > 
> > > > Your PS/2 Aux Port Control description seems to really matches. Just there is reverse order of bits. Bit 0 in description is highest, therefore matches BIT(7) macro.
> > > > 
> > > > Bit 6 in description (BIT(1) in code) describes SP Extended Mode which alps.c enabled. And in that description is written:
> > > > 
> > > > "If 1 SP is extended packet format (driver must set SP raw mode and GP absolute mode)."
> > > > 
> > > > Do you have any idea what "SP raw mode" is? How to set it? For me it looks like it could be that extended mode of trackstick itself.
> > > > 
> > > > "GP absolute mode" I guess is GlidePoint absolute mode, therefore 
> > > > enable
> > > > 6 byte absolute mode for touchpad.
> > > > 
> > > > And for Bit 7 (BIT(0)) is written:
> > > > 
> > > > This bit is used with the PS/2 Aux port to use the Pass-Thru mode ( see appendix A ). Do you have some information about this appendix A?
> > > > 
> > > > On Wednesday 14 March 2018 10:21:43 Masaki Ota wrote:
> > > > > Hi, Pali,
> > > > > 
> > > > > I just picked up the spec which relates with trackstic.
> > > > > 
> > > > > Best Regards,
> > > > > Masaki Ota
> > > > > -----Original Message-----
> > > > > From: Pali Rohár [mailto:pali.rohar@gmail.com]
> > > > > Sent: Tuesday, March 13, 2018 8:14 AM
> > > > > To: 太田 真喜 Masaki Ota <masaki.ota@jp.alps.com>; Dmitry Torokhov 
> > > > > <dmitry.torokhov@gmail.com>
> > > > > Cc: linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
> > > > > Subject: Re: [PATCH] Input: alps - Demystify trackstick 
> > > > > initialization for v3 and v6 protocols
> > > > > 
> > > > > Masaki, if you have access to the internal ALPS v3 / Rushmore 
> > > > > documentation, I would like to have a review of this patch or 
> > > > > confirmation of those information :-)
> > > > 
> > > > --
> > > > Pali Rohár
> > > > pali.rohar@gmail.com
> > > 
> > > --
> > > Pali Rohár
> > > pali.rohar@gmail.com
> > 
> 
> -- 
> Pali Rohár
> pali.rohar@gmail.com
Pali Rohár April 24, 2018, 11:14 a.m. UTC | #8
On Monday 23 April 2018 16:40:26 Dmitry Torokhov wrote:
> On Wed, Apr 18, 2018 at 01:40:30PM +0200, Pali Rohár wrote:
> > Dmitry, ping
> 
> Applied, thank you. Can you tell me if I am missing anything else for
> ALPS?

Hi! All remaining ALPS patches should be already processed.

> 
> Thanks!
> 
> > 
> > On Wednesday 21 March 2018 17:41:26 Pali Rohár wrote:
> > > That is pity, but OK.
> > > 
> > > Anyway, as wrote patch which I sent in the first email matches this
> > > documentation.
> > > 
> > > Dmitry, can you review/comment/accept/reject this patch?
> > > 
> > > On Monday 19 March 2018 08:41:19 Masaki Ota wrote:
> > > > Hi, Pali,
> > > > 
> > > > v3/v6 devices are T3 type, and it can use only Method 2.
> > > > P36 (At this time GLIDEPOINT_T3 uses the Method 2 ....)
> > > > T3 has the potential that uses Method2, but I think it needs to change Firmware.
> > > > 
> > > > Best Regards,
> > > > Masaki Ota
> > > > -----Original Message-----
> > > > From: Pali Rohár [mailto:pali.rohar@gmail.com] 
> > > > Sent: Friday, March 16, 2018 7:58 PM
> > > > To: 太田 真喜 Masaki Ota <masaki.ota@jp.alps.com>
> > > > Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>; linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
> > > > Subject: Re: [PATCH] Input: alps - Demystify trackstick initialization for v3 and v6 protocols
> > > > 
> > > > Great, thank you. Enabling that RAW/extended/SP4 mode is done by sequence E6, E6, E6, F3, C8, F3, 14 (written in page 35) and it matches what function alps_trackstick_enter_extended_mode_v3_v6() in my patch is doing. So is correct.
> > > > 
> > > > On page 36 I see that there is described Method 1 for reporting stick data which prevents cursor jumps. Seems that kernel uses Method 2.
> > > > Method 1 depends on some prioritization.
> > > > 
> > > > Do you have some information how to activate Method 1? Sometimes I observe that problem with "cursor jumps" and from Method 1 could prevent it. So I would like to try experimenting...
> > > > 
> > > > On Wednesday 14 March 2018 23:56:46 Masaki Ota wrote:
> > > > > Hi, Pali,
> > > > > 
> > > > > I have added Appendix.
> > > > > According to this spec documents, SP raw mode is SP 4 byte mode.
> > > > > I think Extended mode meaning is almost all the same as Raw mode.
> > > > > The description of how to set is written in Page 35.
> > > > > 
> > > > > Best Regards,
> > > > > Masaki Ota
> > > > > -----Original Message-----
> > > > > From: Pali Rohár [mailto:pali.rohar@gmail.com]
> > > > > Sent: Thursday, March 15, 2018 7:58 AM
> > > > > To: 太田 真喜 Masaki Ota <masaki.ota@jp.alps.com>
> > > > > Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>; 
> > > > > linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
> > > > > Subject: Re: [PATCH] Input: alps - Demystify trackstick initialization 
> > > > > for v3 and v6 protocols
> > > > > 
> > > > > Hi! Thank you for information.
> > > > > 
> > > > > Your PS/2 Aux Port Control description seems to really matches. Just there is reverse order of bits. Bit 0 in description is highest, therefore matches BIT(7) macro.
> > > > > 
> > > > > Bit 6 in description (BIT(1) in code) describes SP Extended Mode which alps.c enabled. And in that description is written:
> > > > > 
> > > > > "If 1 SP is extended packet format (driver must set SP raw mode and GP absolute mode)."
> > > > > 
> > > > > Do you have any idea what "SP raw mode" is? How to set it? For me it looks like it could be that extended mode of trackstick itself.
> > > > > 
> > > > > "GP absolute mode" I guess is GlidePoint absolute mode, therefore 
> > > > > enable
> > > > > 6 byte absolute mode for touchpad.
> > > > > 
> > > > > And for Bit 7 (BIT(0)) is written:
> > > > > 
> > > > > This bit is used with the PS/2 Aux port to use the Pass-Thru mode ( see appendix A ). Do you have some information about this appendix A?
> > > > > 
> > > > > On Wednesday 14 March 2018 10:21:43 Masaki Ota wrote:
> > > > > > Hi, Pali,
> > > > > > 
> > > > > > I just picked up the spec which relates with trackstic.
> > > > > > 
> > > > > > Best Regards,
> > > > > > Masaki Ota
> > > > > > -----Original Message-----
> > > > > > From: Pali Rohár [mailto:pali.rohar@gmail.com]
> > > > > > Sent: Tuesday, March 13, 2018 8:14 AM
> > > > > > To: 太田 真喜 Masaki Ota <masaki.ota@jp.alps.com>; Dmitry Torokhov 
> > > > > > <dmitry.torokhov@gmail.com>
> > > > > > Cc: linux-input@vger.kernel.org; linux-kernel@vger.kernel.org
> > > > > > Subject: Re: [PATCH] Input: alps - Demystify trackstick 
> > > > > > initialization for v3 and v6 protocols
> > > > > > 
> > > > > > Masaki, if you have access to the internal ALPS v3 / Rushmore 
> > > > > > documentation, I would like to have a review of this patch or 
> > > > > > confirmation of those information :-)
> > > > > 
> > > > > --
> > > > > Pali Rohár
> > > > > pali.rohar@gmail.com
> > > > 
> > > > --
> > > > Pali Rohár
> > > > pali.rohar@gmail.com
> > > 
> > 
> > -- 
> > Pali Rohár
> > pali.rohar@gmail.com
>
diff mbox

Patch

diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index dbe57da8c1a1..010c1bcdb06d 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -2063,14 +2063,11 @@  static int alps_hw_init_v1_v2(struct psmouse *psmouse)
 	return 0;
 }
 
-static int alps_hw_init_v6(struct psmouse *psmouse)
+/* Must be in passthrough mode when calling this function */
+static int alps_trackstick_enter_extended_mode_v3_v6(struct psmouse *psmouse)
 {
 	unsigned char param[2] = {0xC8, 0x14};
 
-	/* Enter passthrough mode to let trackpoint enter 6byte raw mode */
-	if (alps_passthrough_mode_v2(psmouse, true))
-		return -1;
-
 	if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
 	    ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
 	    ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
@@ -2078,9 +2075,25 @@  static int alps_hw_init_v6(struct psmouse *psmouse)
 	    ps2_command(&psmouse->ps2dev, &param[1], PSMOUSE_CMD_SETRATE))
 		return -1;
 
+	return 0;
+}
+
+static int alps_hw_init_v6(struct psmouse *psmouse)
+{
+	int ret;
+
+	/* Enter passthrough mode to let trackpoint enter 6byte raw mode */
+	if (alps_passthrough_mode_v2(psmouse, true))
+		return -1;
+
+	ret = alps_trackstick_enter_extended_mode_v3_v6(psmouse);
+
 	if (alps_passthrough_mode_v2(psmouse, false))
 		return -1;
 
+	if (ret)
+		return ret;
+
 	if (alps_absolute_mode_v6(psmouse)) {
 		psmouse_err(psmouse, "Failed to enable absolute mode\n");
 		return -1;
@@ -2154,10 +2167,18 @@  static int alps_probe_trackstick_v3_v7(struct psmouse *psmouse, int reg_base)
 
 static int alps_setup_trackstick_v3(struct psmouse *psmouse, int reg_base)
 {
-	struct ps2dev *ps2dev = &psmouse->ps2dev;
 	int ret = 0;
+	int reg_val;
 	unsigned char param[4];
 
+	/*
+	 * We need to configure trackstick to report data for touchpad in
+	 * extended format. And also we need to tell touchpad to expect data
+	 * from trackstick in extended format. Without this configuration
+	 * trackstick packets sent from touchpad are in basic format which is
+	 * different from what we expect.
+	 */
+
 	if (alps_passthrough_mode_v3(psmouse, reg_base, true))
 		return -EIO;
 
@@ -2175,39 +2196,36 @@  static int alps_setup_trackstick_v3(struct psmouse *psmouse, int reg_base)
 		ret = -ENODEV;
 	} else {
 		psmouse_dbg(psmouse, "trackstick E7 report: %3ph\n", param);
-
-		/*
-		 * Not sure what this does, but it is absolutely
-		 * essential. Without it, the touchpad does not
-		 * work at all and the trackstick just emits normal
-		 * PS/2 packets.
-		 */
-		if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
-		    ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
-		    ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) ||
-		    alps_command_mode_send_nibble(psmouse, 0x9) ||
-		    alps_command_mode_send_nibble(psmouse, 0x4)) {
-			psmouse_err(psmouse,
-				    "Error sending magic E6 sequence\n");
+		if (alps_trackstick_enter_extended_mode_v3_v6(psmouse)) {
+			psmouse_err(psmouse, "Failed to enter into trackstick extended mode\n");
 			ret = -EIO;
-			goto error;
 		}
+	}
+
+	if (alps_passthrough_mode_v3(psmouse, reg_base, false))
+		return -EIO;
+
+	if (ret)
+		return ret;
 
+	if (alps_enter_command_mode(psmouse))
+		return -EIO;
+
+	reg_val = alps_command_mode_read_reg(psmouse, reg_base + 0x08);
+	if (reg_val == -1) {
+		ret = -EIO;
+	} else {
 		/*
-		 * This ensures the trackstick packets are in the format
-		 * supported by this driver. If bit 1 isn't set the packet
-		 * format is different.
+		 * Tell touchpad that trackstick is now in extended mode.
+		 * If bit 1 isn't set the packet format is different.
 		 */
-		if (alps_enter_command_mode(psmouse) ||
-		    alps_command_mode_write_reg(psmouse,
-						reg_base + 0x08, 0x82) ||
-		    alps_exit_command_mode(psmouse))
+		reg_val |= BIT(1);
+		if (__alps_command_mode_write_reg(psmouse, reg_val))
 			ret = -EIO;
 	}
 
-error:
-	if (alps_passthrough_mode_v3(psmouse, reg_base, false))
-		ret = -EIO;
+	if (alps_exit_command_mode(psmouse))
+		return -EIO;
 
 	return ret;
 }