RE: Alps touchpad generates IRQ storm after S3

2019-08-27 Thread Masaki Ota
Hi, Kai-Heng,

Sorry, I'm not in charge of Linux task now.

Hi, XiaoJian,

Please check the following mail.
If you have any question, please ask Kai-Heng.

Best Regards,
Masaki Ota
-Original Message-
From: Kai-Heng Feng  
Sent: Wednesday, August 28, 2019 3:22 PM
To: 太田 真喜 Masaki Ota 
Cc: Mario Limonciello ; open list:HID CORE LAYER 
; Linux Kernel Mailing List 

Subject: Alps touchpad generates IRQ storm after S3

Hi Masaki,

The Alps touchpad (044E:1220) on Dell Precision 7530 causes IRQ storm after 
system suspend (S3).
Commit "HID: i2c-hid: Don't reset device upon system resume” which solves the 
same issue for other vendors, cause the issue on Alps touchpad.
So I’d like to know the correct command Alps touchpad expects after system 
resume.

Also Cc Mario because this could relate to BIOS.

Kai-Heng


RE: [PATCH] Input: ALPS - add support for 73 03 28 devices (Thinkpad L570)

2018-03-27 Thread Masaki Ota
Hi, Dennis

I know your issue, and I added the solution for Thinkpad L/E system last year.
BTW, Pali also knows about it.

  On Wednesday 29 November 2017 17:33:58 Masaki Ota wrote:
From: Masaki Ota mailto:dennis.wassenb...@secunet.com] 
Sent: Tuesday, March 27, 2018 10:56 PM
To: Pali Rohár 
Cc: Dmitry Torokhov ; 太田 真喜 Masaki Ota 
; Takashi Iwai ; Kees Cook 
; Nir Perry ; 
linux-in...@vger.kernel.org; linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Input: ALPS - add support for 73 03 28 devices (Thinkpad 
L570)

Hi,

oh ok, understood. Thanks for this hint.

So maybe there is something wrong with the alps_update_dual_info_ss4_v2 
function or the reporting of the hardware.

alps_update_dual_info_ss4_v2 detects the ThinkPad L570 as ss4plus device but 
not as dualpoint device. This means that the ALPS_DUALPOINT and the 
ALPS_DUALPOINT_WITH_PRESSURE flag will not be set which results in a non 
function trackstick and hardware mouse buttons. Each time I touch the 
trackstick I get the message: "alps: Rejected trackstick packet from non 
DualPoint device".

The value of otp[0][0] inside alps_update_dual_info_ss4_v2 is 0xCE. Are there 
any ideas why it is not detected as dualpoint device?

Thank you & best regards,

Dennis

On 23.03.2018 15:33, Pali Rohár wrote:
> On Friday 23 March 2018 15:23:55 Dennis Wassenberg wrote:
>> The Lenovo Thinkpad L570 uses V8 protocol.
>> Add 0x73 0x03 0x28 devices to use V8 protovol which makes trackstick 
>> and mouse buttons work with Lenovo Thinkpad L570.
>>
>> Signed-off-by: Dennis Wassenberg 
>> ---
>>  drivers/input/mouse/alps.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c 
>> index dbe57da..5523d4e 100644
>> --- a/drivers/input/mouse/alps.c
>> +++ b/drivers/input/mouse/alps.c
>> @@ -136,6 +136,8 @@
>>  { { 0x73, 0x02, 0x0a }, { ALPS_PROTO_V2, 0xf8, 0xf8, 0 } },
>>  { { 0x73, 0x02, 0x14 }, { ALPS_PROTO_V2, 0xf8, 0xf8, ALPS_FW_BK_2 } },  
>> /* Ahtec Laptop */
>>  { { 0x73, 0x02, 0x50 }, { ALPS_PROTO_V2, 0xcf, 0xcf, ALPS_FOUR_BUTTONS 
>> } }, /* Dell Vostro 1400 */
>> +{ { 0x73, 0x03, 0x28 }, { ALPS_PROTO_V8, 0x18, 0x18,
>> +ALPS_DUALPOINT | ALPS_DUALPOINT_WITH_PRESSURE | ALPS_BUTTONPAD 
>> } }, /* Lenovo L570 */
>>  };
>>  
>>  static const struct alps_protocol_info alps_v3_protocol_data = {
> 
> Hi! alps_model_data table is used for fixed identification of v1 and 
> v2 protocols. Why you need to add there v8 protocol which 
> autodetection is already done in alps_identify() function? There is already 
> code:
> 
>   } else if (e7[0] == 0x73 && e7[1] == 0x03 &&
>  (e7[2] == 0x14 || e7[2] == 0x28)) {
>   protocol = &alps_v8_protocol_data;
> 
> Which matches above your E7 detection 0x73, 0x03, 0x28.
> 
> Also you patch matches basically all v8 device and therefore has 
> potential to break proper v8 autodetection for other v8 devices...
> 


RE: [PATCH] Input: ALPS - fix DualPoint flag for 74 03 28 devices

2018-03-26 Thread Masaki Ota
Hi, 

We can get OTP page 0 value by EA EA E9 commands, but we cannot get it by EA EA 
EA E9.
As far as I remember, Device initialization finish at EA command, then sends EA 
EA E9 commands.
In this case we cannot get correct OTP page 0 value.
So I changed this order. (We can get OTP page 1 value by both of EA F0 F0 E9 
and F0 F0 E9.)

Best Regards,
Masaki Ota
-Original Message-
From: Pali Rohár [mailto:pali.ro...@gmail.com] 
Sent: Monday, March 26, 2018 6:26 AM
To: 太田 真喜 Masaki Ota 
Cc: Dmitry Torokhov ; linux-in...@vger.kernel.org; 
linux-kernel@vger.kernel.org; Aaron Ma 
Subject: Re: [PATCH] Input: ALPS - fix DualPoint flag for 74 03 28 devices

On Tuesday 20 March 2018 11:47:26 Dmitry Torokhov wrote:
> On Mon, Jan 29, 2018 at 2:51 PM, dmitry.torok...@gmail.com 
>  wrote:
> > Hi,
> >
> > On Thu, Nov 16, 2017 at 07:27:02AM +, Masaki Ota wrote:
> >> Hi, Pali, Aaron,
> >>
> >> Current code is correct device setting, previous code is wrong.
> >> If the trackstick does not work(DUALPOINT flag disable), Device Firmware 
> >> setting is wrong.
> >>
> >> But recently I received the same report from Thinkpad L570 user, and I 
> >> checked this device and found this device Firmware setting is wrong. Sorry 
> >> for our mistake.
> >> Is your laptop L570 ?
> >>
> >> I will add code that supports the trackstick for this device.
> >
> > Sorry for resurrecting this old thread, I am just trying to 
> > understand what went wrong here. Is the sequence of "f0 f0 e9" and 
> > "ea ea e9" is important in getting the correct OTP data and we 
> > originally got this order wrong? It is not clear from the original 
> > patch and discussion that this change was intentional.
> 
> Could I please get an answer to my question?
> 
> Thanks!

Masaki, this question is for you ↑↑↑

> >
> > Thanks.
> >
> >>
> >> Best Regards,
> >> Masaki Ota
> >> -Original Message-
> >> From: Pali Rohár [mailto:pali.ro...@gmail.com]
> >> Sent: Wednesday, November 15, 2017 5:35 PM
> >> To: 太田 真喜 Masaki Ota 
> >> Cc: linux-in...@vger.kernel.org; linux-kernel@vger.kernel.org; 
> >> dmitry.torok...@gmail.com; Aaron Ma 
> >> Subject: Re: [PATCH] Input: ALPS - fix DualPoint flag for 74 03 28 
> >> devices
> >>
> >> On Wednesday 15 November 2017 14:34:04 Aaron Ma wrote:
> >> > There is a regression of commit 4a646580f793 ("Input: ALPS - fix 
> >> > two-finger scroll breakage"), ALPS device fails with log:
> >> >
> >> > psmouse serio1: alps: Rejected trackstick packet from non 
> >> > DualPoint device
> >> >
> >> > ALPS device with id "74 03 28" report OTP[0] data 0xCE after 
> >> > commit 4a646580f793, after restore the OTP reading order, it 
> >> > becomes to 0x10 as before and reports the right flag.
> >> >
> >> > Fixes: 4a646580f793 ("Input: ALPS - fix two-finger scroll 
> >> > breakage")
> >> > Cc: 
> >> > Signed-off-by: Aaron Ma 
> >> > ---
> >> >  drivers/input/mouse/alps.c | 4 ++--
> >> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >> >
> >> > diff --git a/drivers/input/mouse/alps.c 
> >> > b/drivers/input/mouse/alps.c index 579b899add26..c59b8f7ca2fc 
> >> > 100644
> >> > --- a/drivers/input/mouse/alps.c
> >> > +++ b/drivers/input/mouse/alps.c
> >> > @@ -2562,8 +2562,8 @@ static int alps_set_defaults_ss4_v2(struct 
> >> > psmouse *psmouse,
> >> >
> >> > memset(otp, 0, sizeof(otp));
> >> >
> >> > -   if (alps_get_otp_values_ss4_v2(psmouse, 1, &otp[1][0]) ||
> >> > -   alps_get_otp_values_ss4_v2(psmouse, 0, &otp[0][0]))
> >> > +   if (alps_get_otp_values_ss4_v2(psmouse, 0, &otp[0][0]) ||
> >> > +   alps_get_otp_values_ss4_v2(psmouse, 1, &otp[1][0]))
> >> > return -1;
> >> >
> >> > alps_update_device_area_ss4_v2(otp, priv);
> >>
> >> Masaki Ota, please look at this patch as it partially revert your 
> >> commit
> >> 4a646580f793 ("Input: ALPS - fix two-finger scroll breakage"). Something 
> >> smells here.
> >>
> >> --
> >> Pali Rohár
> >> pali.ro...@gmail.com
> >
> > --
> > Dmitry
> 
> 
> 

--
Pali Rohár
pali.ro...@gmail.com


RE: [PATCH] Input: alps - Demystify trackstick initialization for v3 and v6 protocols

2018-03-19 Thread Masaki Ota
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.ro...@gmail.com] 
Sent: Friday, March 16, 2018 7:58 PM
To: 太田 真喜 Masaki Ota 
Cc: Dmitry Torokhov ; linux-in...@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.ro...@gmail.com]
> Sent: Thursday, March 15, 2018 7:58 AM
> To: 太田 真喜 Masaki Ota 
> Cc: Dmitry Torokhov ; 
> linux-in...@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.ro...@gmail.com]
> > Sent: Tuesday, March 13, 2018 8:14 AM
> > To: 太田 真喜 Masaki Ota ; Dmitry Torokhov 
> > 
> > Cc: linux-in...@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.ro...@gmail.com

--
Pali Rohár
pali.ro...@gmail.com


RE: [PATCH] input: multi-touch fix for ALPS touchpads ("SS4 plus" variant)

2018-01-11 Thread Masaki Ota
Hi, Nir,

Wow, thank you for fixing the bug.
Your code is correct!

Best Regards,
Masaki Ota
-Original Message-
From: Nir Perry [mailto:nirpe...@gmail.com] 
Sent: Saturday, January 06, 2018 8:55 PM
To: 太田 真喜 Masaki Ota ; Dmitry Torokhov 
; Pali Rohár 
Cc: linux-kernel@vger.kernel.org; linux-in...@vger.kernel.org
Subject: [PATCH] input: multi-touch fix for ALPS touchpads ("SS4 plus" variant)

Hi all,

I think a minor "typo" bug was accidentally introduced to ALPS touchpad driver 
by a previous bug-fix (commit 4a646580f793d19717f7e034c8d473b509c27d49, "Input: 
ALPS - fix two-finger scroll breakage in right side on ALPS touchpad").
It breaks how multi-touch events are decoded on some ALPS touchpads, so for 
example tapping with three-fingers can no longer be used to emulate 
middle-mouse-button (the kernel doesn't recognize this as the proper event, and 
doesn't report it correctly to userspace).
This affects touchpads that use SS4 "plus" protocol variant, like those found 
on Dell E7270 & E7470 laptops (tested on E7270).

The cause of the problem
--
First, probably due to a typo, the code in alps_decode_ss4_v2() for case 
SS4_PACKET_ID_MULTI used inconsistent indices to "f->mt[]". You can see 0 & 1 
are used for the "if" part but 2 & 3 are used for the "else" part, which I 
believe is a typo.
Second, in the previous patch, new macros were introduced to decode X 
coordinates specific to the SS4 "plus" variant, but the macro to define the 
maximum X value wasn't changed accordingly. The macros to decode X values for 
"plus" variant are effectively shifted right by 1 bit, but the max wasn't 
shifted too. This causes the driver to incorrectly handle "no data" cases, 
which also interfered with how multi-touch was handled. To fix it - I created 
new SS4 "plus" macros for the max value - SS4_PLUS_MFPACKET_NO_AX & 
SS4_PLUS_MFPACKET_NO_AX_BL. To make the change a little more readable, I moved 
also the Y-max lines so they are closer to the X-max lines.
To get three-finger tap to work both changes are required.

The included patch was generated against the mainline tree today, but was also 
tested against the 4.14 kernel branch. I've included in this e-mail the people 
involved with the old patch from August, plus Pali Rohár who is listed as the 
ALPS PS/2 touchpad driver reviewer (in the maintainers file).

Fixes: 4a646580f793d19717f7e034c8d473b509c27d49 ("Input: ALPS - fix two-finger 
scroll breakage in right side on ALPS touchpad")

Regards,
Nir

Signed-off-by: Nir Perry  diff --git 
a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c index 
579b899..dbe57da 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -1250,29 +1250,32 @@ static int alps_decode_ss4_v2(struct alps_fields *f,
case SS4_PACKET_ID_MULTI:
if (priv->flags & ALPS_BUTTONPAD) {
if (IS_SS4PLUS_DEV(priv->dev_id)) {
-   f->mt[0].x = SS4_PLUS_BTL_MF_X_V2(p, 0);
-   f->mt[1].x = SS4_PLUS_BTL_MF_X_V2(p, 1);
+   f->mt[2].x = SS4_PLUS_BTL_MF_X_V2(p, 0);
+   f->mt[3].x = SS4_PLUS_BTL_MF_X_V2(p, 1);
+   no_data_x = SS4_PLUS_MFPACKET_NO_AX_BL;
} else {
f->mt[2].x = SS4_BTL_MF_X_V2(p, 0);
f->mt[3].x = SS4_BTL_MF_X_V2(p, 1);
+   no_data_x = SS4_MFPACKET_NO_AX_BL;
}
+   no_data_y = SS4_MFPACKET_NO_AY_BL;

f->mt[2].y = SS4_BTL_MF_Y_V2(p, 0);
f->mt[3].y = SS4_BTL_MF_Y_V2(p, 1);
-   no_data_x = SS4_MFPACKET_NO_AX_BL;
-   no_data_y = SS4_MFPACKET_NO_AY_BL;
} else {
if (IS_SS4PLUS_DEV(priv->dev_id)) {
-   f->mt[0].x = SS4_PLUS_STD_MF_X_V2(p, 0);
-   f->mt[1].x = SS4_PLUS_STD_MF_X_V2(p, 1);
+   f->mt[2].x = SS4_PLUS_STD_MF_X_V2(p, 0);
+   f->mt[3].x = SS4_PLUS_STD_MF_X_V2(p, 1);
+   no_data_x = SS4_PLUS_MFPACKET_NO_AX;
} else {
-   f->mt[0].x = SS4_STD_MF_X_V2(p, 0);
-   f->mt[1].x = SS4_STD_MF_X_V2(p, 1);
+   f->mt[2].x = SS4_STD_MF_X_V2(p, 0);
+   f->mt[3].x = SS4_STD_MF_X_V2(p, 1);
+   no_data_x = SS4_MFPACKET_NO_AX;
}
+   no_data_y = SS4_MF

RE: [PATCH] Support TrackStick of Thinkpad L570

2017-12-05 Thread Masaki Ota
Hi, Pali,

OK, I got it.
So, the problem of structure will be solved next chance.

Best Regards,
Masaki Ota
-Original Message-
From: Pali Rohár [mailto:pali.ro...@gmail.com] 
Sent: Monday, December 04, 2017 6:51 PM
To: 太田 真喜 Masaki Ota 
Cc: Masaki Ota <012ne...@gmail.com>; dmitry.torok...@gmail.com; 
benjamin.tissoi...@redhat.com; aaron...@canonical.com; j...@ristioja.ee; 
linux-in...@vger.kernel.org; linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Support TrackStick of Thinkpad L570

On Monday 04 December 2017 09:40:04 Masaki Ota wrote:
> Hi, Pali,
> 
> It does not work in my test result.

Hm.. that is strange, we have dangling pointers in struct alps_data?
Otherwise I have no idea why does not work.

> BTW, other some functions also use both of "struct psmouse" and "struct 
> alps_data" argument.

It does not make sense to pass one structure (via pointers) two times.
And if this "pattern" is already used in code and reason is that one pointer 
"does not work" because it is dangling, then it is really wrong.

I know it is irrelevant to your patch, but this problem with dangling pointer 
should be fixed, e.g. in next patches (not in this one).

Problems (with memory allocation/pointers) should not be camouflaged.
Memory corruption in kernel can lead to fatal problems.

> I just followed it.

Blindly following bad code is a bad idea. When we see something like this, we 
should at least stop and ask question "why is this code pattern used?".

> Best Regards,
> Masaki Ota
> -Original Message-
> From: Pali Rohár [mailto:pali.ro...@gmail.com]
> Sent: Monday, December 04, 2017 6:12 PM
> To: 太田 真喜 Masaki Ota 
> Cc: Masaki Ota <012ne...@gmail.com>; dmitry.torok...@gmail.com; 
> benjamin.tissoi...@redhat.com; aaron...@canonical.com; 
> j...@ristioja.ee; linux-in...@vger.kernel.org; 
> linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] Support TrackStick of Thinkpad L570
> 
> On Monday 04 December 2017 04:48:43 Masaki Ota wrote:
> > Hi, Pali,
> > 
> > I don't get your point.
> > Please modify the code if you have an idea.
> 
> See below
> 
> > Best Regards,
> > Masaki Ota
> > -Original Message-
> > From: Pali Rohár [mailto:pali.ro...@gmail.com]
> > Sent: Saturday, December 02, 2017 6:08 AM
> > To: Masaki Ota <012ne...@gmail.com>
> > Cc: dmitry.torok...@gmail.com; benjamin.tissoi...@redhat.com; 
> > aaron...@canonical.com; j...@ristioja.ee; 太田 真喜 Masaki Ota 
> > ; linux-in...@vger.kernel.org; 
> > linux-kernel@vger.kernel.org
> > Subject: Re: [PATCH] Support TrackStick of Thinkpad L570
> > 
> > On Wednesday 29 November 2017 17:33:58 Masaki Ota wrote:
> > > From: Masaki Ota 
> > > - The issue is that Thinkpad L570 TrackStick does not work. Because the 
> > > main interface of Thinkpad L570 device is SMBus, so ALPS overlooked PS2 
> > > interface Firmware setting of TrackStick. The detail is that TrackStick 
> > > otp bit is disabled.
> > > - Add the code that checks 0xD7 address value. This value is device 
> > > number information, so we can identify the device by checking this value.
> > > - If we check 0xD7 value, we need to enable Command mode and after check 
> > > the value we need to disable Command mode, then we have to enable the 
> > > device(0xF4 command).
> > > - Thinkpad L570 device number is 0x0C or 0x1D. If it is TRUE, enable 
> > > ALPS_DUALPOINT flag.
> > > 
> > > Signed-off-by: Masaki Ota 
> > > ---
> > >  drivers/input/mouse/alps.c | 24 +---
> > >  1 file changed, 21 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/drivers/input/mouse/alps.c 
> > > b/drivers/input/mouse/alps.c index 850b00e3ad8e..6f092bdd9fc5 
> > > 100644
> > > --- a/drivers/input/mouse/alps.c
> > > +++ b/drivers/input/mouse/alps.c
> > > @@ -2541,13 +2541,31 @@ static int 
> > > alps_update_btn_info_ss4_v2(unsigned char otp[][4],  }
> > >  
> > >  static int alps_update_dual_info_ss4_v2(unsigned char otp[][4],
> > > -struct alps_data *priv)
> > > +struct alps_data *priv,
> > > + struct psmouse *psmouse)
> > >  {
> 
> You can access psmouse from the priv structure as:
> 
>   struct psmouse *psmouse = priv->psmouse;
> 
> Therefore you do not have to extend function parameters with psmouse pointer 
> as that is already present int alps_data.
> 
> struct alps_data is defined as:
> 
> struct alps_data {

RE: [PATCH] Support TrackStick of Thinkpad L570

2017-12-04 Thread Masaki Ota
Hi, Pali,

It does not work in my test result.

BTW, other some functions also use both of "struct psmouse" and "struct 
alps_data" argument.
I just followed it.

Best Regards,
Masaki Ota
-Original Message-
From: Pali Rohár [mailto:pali.ro...@gmail.com] 
Sent: Monday, December 04, 2017 6:12 PM
To: 太田 真喜 Masaki Ota 
Cc: Masaki Ota <012ne...@gmail.com>; dmitry.torok...@gmail.com; 
benjamin.tissoi...@redhat.com; aaron...@canonical.com; j...@ristioja.ee; 
linux-in...@vger.kernel.org; linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Support TrackStick of Thinkpad L570

On Monday 04 December 2017 04:48:43 Masaki Ota wrote:
> Hi, Pali,
> 
> I don't get your point.
> Please modify the code if you have an idea.

See below

> Best Regards,
> Masaki Ota
> -Original Message-
> From: Pali Rohár [mailto:pali.ro...@gmail.com]
> Sent: Saturday, December 02, 2017 6:08 AM
> To: Masaki Ota <012ne...@gmail.com>
> Cc: dmitry.torok...@gmail.com; benjamin.tissoi...@redhat.com; 
> aaron...@canonical.com; j...@ristioja.ee; 太田 真喜 Masaki Ota 
> ; linux-in...@vger.kernel.org; 
> linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] Support TrackStick of Thinkpad L570
> 
> On Wednesday 29 November 2017 17:33:58 Masaki Ota wrote:
> > From: Masaki Ota 
> > - The issue is that Thinkpad L570 TrackStick does not work. Because the 
> > main interface of Thinkpad L570 device is SMBus, so ALPS overlooked PS2 
> > interface Firmware setting of TrackStick. The detail is that TrackStick otp 
> > bit is disabled.
> > - Add the code that checks 0xD7 address value. This value is device number 
> > information, so we can identify the device by checking this value.
> > - If we check 0xD7 value, we need to enable Command mode and after check 
> > the value we need to disable Command mode, then we have to enable the 
> > device(0xF4 command).
> > - Thinkpad L570 device number is 0x0C or 0x1D. If it is TRUE, enable 
> > ALPS_DUALPOINT flag.
> > 
> > Signed-off-by: Masaki Ota 
> > ---
> >  drivers/input/mouse/alps.c | 24 +---
> >  1 file changed, 21 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c 
> > index 850b00e3ad8e..6f092bdd9fc5 100644
> > --- a/drivers/input/mouse/alps.c
> > +++ b/drivers/input/mouse/alps.c
> > @@ -2541,13 +2541,31 @@ static int
> > alps_update_btn_info_ss4_v2(unsigned char otp[][4],  }
> >  
> >  static int alps_update_dual_info_ss4_v2(unsigned char otp[][4],
> > -  struct alps_data *priv)
> > +  struct alps_data *priv,
> > +   struct psmouse *psmouse)
> >  {

You can access psmouse from the priv structure as:

  struct psmouse *psmouse = priv->psmouse;

Therefore you do not have to extend function parameters with psmouse pointer as 
that is already present int alps_data.

struct alps_data is defined as:

struct alps_data {
struct psmouse *psmouse;
...
}

> > bool is_dual = false;
> > +   int reg_val = 0;
> > +   struct ps2dev *ps2dev = &psmouse->ps2dev;
> >  
> > -   if (IS_SS4PLUS_DEV(priv->dev_id))
> > +   if (IS_SS4PLUS_DEV(priv->dev_id)) {
> > is_dual = (otp[0][0] >> 4) & 0x01;
> >  
> > +   if (!is_dual) {
> > +   /* For support TrackStick of Thinkpad L/E series */
> > +   if (alps_exit_command_mode(psmouse) == 0 &&
> > +   alps_enter_command_mode(psmouse) == 0) {
> > +   reg_val = alps_command_mode_read_reg(psmouse,
> > +   0xD7);
> > +   }
> > +   alps_exit_command_mode(psmouse);
> > +   ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE);
> > +
> > +   if (reg_val == 0x0C || reg_val == 0x1D)
> > +   is_dual = true;
> > +   }
> > +   }
> > +
> > if (is_dual)
> > priv->flags |= ALPS_DUALPOINT |
> > ALPS_DUALPOINT_WITH_PRESSURE;
> > @@ -2570,7 +2588,7 @@ static int alps_set_defaults_ss4_v2(struct 
> > psmouse *psmouse,
> >  
> > alps_update_btn_info_ss4_v2(otp, priv);
> >  
> > -   alps_update_dual_info_ss4_v2(otp, priv);
> > +   alps_update_dual_info_ss4_v2(otp, priv, psmouse);
> 
> Now looking at this change... Is there reason why you are passing psmouse 
> parameter there? Because struct alps_data contains psmouse member.
> 
> >  
> > return 0;
> >  }
> 
> --
> Pali Rohár
> pali.ro...@gmail.com

--
Pali Rohár
pali.ro...@gmail.com


RE: [PATCH] Support TrackStick of Thinkpad L570

2017-12-03 Thread Masaki Ota
Hi, Pali,

I don't get your point.
Please modify the code if you have an idea.

Best Regards,
Masaki Ota
-Original Message-
From: Pali Rohár [mailto:pali.ro...@gmail.com] 
Sent: Saturday, December 02, 2017 6:08 AM
To: Masaki Ota <012ne...@gmail.com>
Cc: dmitry.torok...@gmail.com; benjamin.tissoi...@redhat.com; 
aaron...@canonical.com; j...@ristioja.ee; 太田 真喜 Masaki Ota 
; linux-in...@vger.kernel.org; 
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Support TrackStick of Thinkpad L570

On Wednesday 29 November 2017 17:33:58 Masaki Ota wrote:
> From: Masaki Ota 
> - The issue is that Thinkpad L570 TrackStick does not work. Because the main 
> interface of Thinkpad L570 device is SMBus, so ALPS overlooked PS2 interface 
> Firmware setting of TrackStick. The detail is that TrackStick otp bit is 
> disabled.
> - Add the code that checks 0xD7 address value. This value is device number 
> information, so we can identify the device by checking this value.
> - If we check 0xD7 value, we need to enable Command mode and after check the 
> value we need to disable Command mode, then we have to enable the device(0xF4 
> command).
> - Thinkpad L570 device number is 0x0C or 0x1D. If it is TRUE, enable 
> ALPS_DUALPOINT flag.
> 
> Signed-off-by: Masaki Ota 
> ---
>  drivers/input/mouse/alps.c | 24 +---
>  1 file changed, 21 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c 
> index 850b00e3ad8e..6f092bdd9fc5 100644
> --- a/drivers/input/mouse/alps.c
> +++ b/drivers/input/mouse/alps.c
> @@ -2541,13 +2541,31 @@ static int 
> alps_update_btn_info_ss4_v2(unsigned char otp[][4],  }
>  
>  static int alps_update_dual_info_ss4_v2(unsigned char otp[][4],
> -struct alps_data *priv)
> +struct alps_data *priv,
> + struct psmouse *psmouse)
>  {
>   bool is_dual = false;
> + int reg_val = 0;
> + struct ps2dev *ps2dev = &psmouse->ps2dev;
>  
> - if (IS_SS4PLUS_DEV(priv->dev_id))
> + if (IS_SS4PLUS_DEV(priv->dev_id)) {
>   is_dual = (otp[0][0] >> 4) & 0x01;
>  
> + if (!is_dual) {
> + /* For support TrackStick of Thinkpad L/E series */
> + if (alps_exit_command_mode(psmouse) == 0 &&
> + alps_enter_command_mode(psmouse) == 0) {
> + reg_val = alps_command_mode_read_reg(psmouse,
> + 0xD7);
> + }
> + alps_exit_command_mode(psmouse);
> + ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE);
> +
> + if (reg_val == 0x0C || reg_val == 0x1D)
> + is_dual = true;
> + }
> + }
> +
>   if (is_dual)
>   priv->flags |= ALPS_DUALPOINT |
>   ALPS_DUALPOINT_WITH_PRESSURE;
> @@ -2570,7 +2588,7 @@ static int alps_set_defaults_ss4_v2(struct 
> psmouse *psmouse,
>  
>   alps_update_btn_info_ss4_v2(otp, priv);
>  
> - alps_update_dual_info_ss4_v2(otp, priv);
> + alps_update_dual_info_ss4_v2(otp, priv, psmouse);

Now looking at this change... Is there reason why you are passing psmouse 
parameter there? Because struct alps_data contains psmouse member.

>  
>   return 0;
>  }

--
Pali Rohár
pali.ro...@gmail.com


[PATCH] Support TrackStick of Thinkpad L570

2017-11-29 Thread Masaki Ota
From: Masaki Ota 
- The issue is that Thinkpad L570 TrackStick does not work. Because the main 
interface of Thinkpad L570 device is SMBus, so ALPS overlooked PS2 interface 
Firmware setting of TrackStick. The detail is that TrackStick otp bit is 
disabled.
- Add the code that checks 0xD7 address value. This value is device number 
information, so we can identify the device by checking this value.
- If we check 0xD7 value, we need to enable Command mode and after check the 
value we need to disable Command mode, then we have to enable the device(0xF4 
command).
- Thinkpad L570 device number is 0x0C or 0x1D. If it is TRUE, enable 
ALPS_DUALPOINT flag.

Signed-off-by: Masaki Ota 
---
 drivers/input/mouse/alps.c | 24 +---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 850b00e3ad8e..6f092bdd9fc5 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -2541,13 +2541,31 @@ static int alps_update_btn_info_ss4_v2(unsigned char 
otp[][4],
 }
 
 static int alps_update_dual_info_ss4_v2(unsigned char otp[][4],
-  struct alps_data *priv)
+  struct alps_data *priv,
+   struct psmouse *psmouse)
 {
bool is_dual = false;
+   int reg_val = 0;
+   struct ps2dev *ps2dev = &psmouse->ps2dev;
 
-   if (IS_SS4PLUS_DEV(priv->dev_id))
+   if (IS_SS4PLUS_DEV(priv->dev_id)) {
is_dual = (otp[0][0] >> 4) & 0x01;
 
+   if (!is_dual) {
+   /* For support TrackStick of Thinkpad L/E series */
+   if (alps_exit_command_mode(psmouse) == 0 &&
+   alps_enter_command_mode(psmouse) == 0) {
+   reg_val = alps_command_mode_read_reg(psmouse,
+   0xD7);
+   }
+   alps_exit_command_mode(psmouse);
+   ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE);
+
+   if (reg_val == 0x0C || reg_val == 0x1D)
+   is_dual = true;
+   }
+   }
+
if (is_dual)
priv->flags |= ALPS_DUALPOINT |
ALPS_DUALPOINT_WITH_PRESSURE;
@@ -2570,7 +2588,7 @@ static int alps_set_defaults_ss4_v2(struct psmouse 
*psmouse,
 
alps_update_btn_info_ss4_v2(otp, priv);
 
-   alps_update_dual_info_ss4_v2(otp, priv);
+   alps_update_dual_info_ss4_v2(otp, priv, psmouse);
 
return 0;
 }
-- 
2.14.1



[PATCH] Support TrackStick of Thinkpad L570

2017-11-28 Thread Masaki Ota
From: Masaki Ota 
- The issue is that Thinkpad L570 TrackStick does not work. Because the main 
interface of Thinkpad L570 device is SMBus, so ALPS overlooked PS2 interface 
Firmware setting of TrackStick. The detail is that TrackStick otp bit is 
disabled.
- Add the code that checks 0xD7 address value. This value is device number 
information, so we can identify the device by checking this value.
- If we check 0xD7 value, we need to enable Command mode and after check the 
value we need to disable Command mode, then we have to enable the device(0xF4 
command).
- Thinkpad L570 device number is 0x0C or 0x1D. If it is TRUE, enable 
ALPS_DUALPOINT flag.

Signed-off-by: Masaki Ota 
---
 drivers/input/mouse/alps.c | 24 +---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 850b00e3ad8e..dd2c9e9f4830 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -2541,13 +2541,31 @@ static int alps_update_btn_info_ss4_v2(unsigned char 
otp[][4],
 }
 
 static int alps_update_dual_info_ss4_v2(unsigned char otp[][4],
-  struct alps_data *priv)
+  struct alps_data *priv,
+   struct psmouse *psmouse)
 {
bool is_dual = false;
+   int reg_val = 0;
+   struct ps2dev *ps2dev = &psmouse->ps2dev;
 
-   if (IS_SS4PLUS_DEV(priv->dev_id))
+   if (IS_SS4PLUS_DEV(priv->dev_id)) {
is_dual = (otp[0][0] >> 4) & 0x01;
 
+   if (!is_dual) {
+   /* For support TrackStick of Thinkpad L570 device */
+   if (alps_exit_command_mode(psmouse) == 0 &&
+   alps_enter_command_mode(psmouse) == 0) {
+   reg_val = alps_command_mode_read_reg(psmouse,
+   0xD7);
+   }
+   alps_exit_command_mode(psmouse);
+   ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE);
+
+   if (reg_val == 0x0C || reg_val == 0x1D)
+   is_dual = true;
+   }
+   }
+
if (is_dual)
priv->flags |= ALPS_DUALPOINT |
ALPS_DUALPOINT_WITH_PRESSURE;
@@ -2570,7 +2588,7 @@ static int alps_set_defaults_ss4_v2(struct psmouse 
*psmouse,
 
alps_update_btn_info_ss4_v2(otp, priv);
 
-   alps_update_dual_info_ss4_v2(otp, priv);
+   alps_update_dual_info_ss4_v2(otp, priv, psmouse);
 
return 0;
 }
-- 
2.14.1



RE: [PATCH] Support TrackStick of Thinkpad L570

2017-11-28 Thread Masaki Ota
Hi, Domitry,

I think we can add the code to HID for this device, but we will not use SMBus 
interface for Touchpad in the future.
We should not do it.

Best Regards,
Masaki Ota
-Original Message-
From: Dmitry Torokhov [mailto:dmitry.torok...@gmail.com] 
Sent: Sunday, November 26, 2017 9:16 AM
To: Masaki Ota <012ne...@gmail.com>
Cc: benjamin.tissoi...@redhat.com; pali.ro...@gmail.com; 
aaron...@canonical.com; j...@ristioja.ee; 太田 真喜 Masaki Ota 
; linux-in...@vger.kernel.org; 
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Support TrackStick of Thinkpad L570

Hi,

On Mon, Nov 20, 2017 at 04:55:30PM +0900, Masaki Ota wrote:
> From: Masaki Ota 
> - The issue is that Thinkpad L570 TrackStick does not work. Because the main 
> interface of Thinkpad L570 device is SMBus, so ALPS overlooked PS2 interface 
> Firmware setting of TrackStick. The detail is that TrackStick otp bit is 
> disabled.

Is it custom protocol over SMBus/I2C or HID (via i2c-hid)? If it is custom 
protocol, can we add the proper driver to the kernel for it so we can get away 
from the PS/2 emulation in firmware?

Thanks!

> - Add the code that checks 0xD7 address value. This value is device number 
> information, so we can identify the device by checking this value.
> - If we check 0xD7 value, we need to enable Command mode and after check the 
> value we need to disable Command mode, then we have to enable the device(0xF4 
> command).
> - Thinkpad L570 device number is 0x0C or 0x1D. If it is TRUE, enable 
> ALPS_DUALPOINT flag.
> 
> Signed-off-by: Masaki Ota 
> ---
>  drivers/input/mouse/alps.c | 21 ++---
>  1 file changed, 18 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c 
> index 850b00e3ad8e..cce52104ed5a 100644
> --- a/drivers/input/mouse/alps.c
> +++ b/drivers/input/mouse/alps.c
> @@ -2541,13 +2541,28 @@ static int 
> alps_update_btn_info_ss4_v2(unsigned char otp[][4],  }
>  
>  static int alps_update_dual_info_ss4_v2(unsigned char otp[][4],
> -struct alps_data *priv)
> +struct alps_data *priv,
> + struct psmouse *psmouse)
>  {
>   bool is_dual = false;
> + int reg_val = 0;
> + struct ps2dev *ps2dev = &psmouse->ps2dev;
>  
> - if (IS_SS4PLUS_DEV(priv->dev_id))
> + if (IS_SS4PLUS_DEV(priv->dev_id)) {
>   is_dual = (otp[0][0] >> 4) & 0x01;
>  
> + /* For support TrackStick of Thinkpad L570 device */
> + if (alps_exit_command_mode(psmouse) == 0 &&
> + alps_enter_command_mode(psmouse) == 0) {
> + reg_val = alps_command_mode_read_reg(psmouse, 0xD7);
> + }
> + alps_exit_command_mode(psmouse);
> + ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE);
> +
> + if (reg_val == 0x0C || reg_val == 0x1D)
> + is_dual = true;
> + }
> +
>   if (is_dual)
>   priv->flags |= ALPS_DUALPOINT |
>   ALPS_DUALPOINT_WITH_PRESSURE;
> @@ -2570,7 +2585,7 @@ static int alps_set_defaults_ss4_v2(struct 
> psmouse *psmouse,
>  
>   alps_update_btn_info_ss4_v2(otp, priv);
>  
> - alps_update_dual_info_ss4_v2(otp, priv);
> + alps_update_dual_info_ss4_v2(otp, priv, psmouse);
>  
>   return 0;
>  }
> --
> 2.14.1
> 

-- 
Dmitry


RE: [PATCH] Support TrackStick of Thinkpad L570

2017-11-20 Thread Masaki Ota
Hi, Pali,

1) Yes, but we don't have FW update plan.
 And this device works as SMBus in Windows, so this issue happens on only Linux.

2) Yes.

Best Regards,
Masaki Ota
-Original Message-
From: Pali Rohár [mailto:pali.ro...@gmail.com] 
Sent: Monday, November 20, 2017 5:30 PM
To: Masaki Ota <012ne...@gmail.com>; dmitry.torok...@gmail.com
Cc: benjamin.tissoi...@redhat.com; aaron...@canonical.com; j...@ristioja.ee; 太田 
真喜 Masaki Ota ; linux-in...@vger.kernel.org; 
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Support TrackStick of Thinkpad L570

On Monday 20 November 2017 16:55:30 Masaki Ota wrote:
> From: Masaki Ota 
> - The issue is that Thinkpad L570 TrackStick does not work. Because the main 
> interface of Thinkpad L570 device is SMBus, so ALPS overlooked PS2 interface 
> Firmware setting of TrackStick. The detail is that TrackStick otp bit is 
> disabled.
> - Add the code that checks 0xD7 address value. This value is device number 
> information, so we can identify the device by checking this value.
> - If we check 0xD7 value, we need to enable Command mode and after check the 
> value we need to disable Command mode, then we have to enable the device(0xF4 
> command).
> - Thinkpad L570 device number is 0x0C or 0x1D. If it is TRUE, enable 
> ALPS_DUALPOINT flag.

So, the root of this problem is in ALPS firmware which provides wrong 
information to kernel?

Masaki, I have two questions:

1) Can ALPS or Lenovo release a new firmware update for this Thinkpad to
   fix this issue?

2) Have all Thinkpad L570 machines trackpoint?

Dmitry, as a workaround for firmware bug on particular notebook, would not be 
better to check DMI information and DMI based hook?

> Signed-off-by: Masaki Ota 
> ---
>  drivers/input/mouse/alps.c | 21 ++---
>  1 file changed, 18 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c 
> index 850b00e3ad8e..cce52104ed5a 100644
> --- a/drivers/input/mouse/alps.c
> +++ b/drivers/input/mouse/alps.c
> @@ -2541,13 +2541,28 @@ static int 
> alps_update_btn_info_ss4_v2(unsigned char otp[][4],  }
>  
>  static int alps_update_dual_info_ss4_v2(unsigned char otp[][4],
> -struct alps_data *priv)
> +struct alps_data *priv,
> + struct psmouse *psmouse)
>  {
>   bool is_dual = false;
> + int reg_val = 0;
> + struct ps2dev *ps2dev = &psmouse->ps2dev;
>  
> - if (IS_SS4PLUS_DEV(priv->dev_id))
> + if (IS_SS4PLUS_DEV(priv->dev_id)) {
>   is_dual = (otp[0][0] >> 4) & 0x01;
>  
> + /* For support TrackStick of Thinkpad L570 device */
> + if (alps_exit_command_mode(psmouse) == 0 &&
> + alps_enter_command_mode(psmouse) == 0) {
> + reg_val = alps_command_mode_read_reg(psmouse, 0xD7);
> + }
> + alps_exit_command_mode(psmouse);
> + ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE);
> +
> + if (reg_val == 0x0C || reg_val == 0x1D)
> + is_dual = true;
> + }
> +
>   if (is_dual)
>   priv->flags |= ALPS_DUALPOINT |
>   ALPS_DUALPOINT_WITH_PRESSURE;
> @@ -2570,7 +2585,7 @@ static int alps_set_defaults_ss4_v2(struct 
> psmouse *psmouse,
>  
>   alps_update_btn_info_ss4_v2(otp, priv);
>  
> - alps_update_dual_info_ss4_v2(otp, priv);
> + alps_update_dual_info_ss4_v2(otp, priv, psmouse);
>  
>   return 0;
>  }

--
Pali Rohár
pali.ro...@gmail.com


[PATCH] Support TrackStick of Thinkpad L570

2017-11-19 Thread Masaki Ota
From: Masaki Ota 
- The issue is that Thinkpad L570 TrackStick does not work. Because the main 
interface of Thinkpad L570 device is SMBus, so ALPS overlooked PS2 interface 
Firmware setting of TrackStick. The detail is that TrackStick otp bit is 
disabled.
- Add the code that checks 0xD7 address value. This value is device number 
information, so we can identify the device by checking this value.
- If we check 0xD7 value, we need to enable Command mode and after check the 
value we need to disable Command mode, then we have to enable the device(0xF4 
command).
- Thinkpad L570 device number is 0x0C or 0x1D. If it is TRUE, enable 
ALPS_DUALPOINT flag.

Signed-off-by: Masaki Ota 
---
 drivers/input/mouse/alps.c | 21 ++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 850b00e3ad8e..cce52104ed5a 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -2541,13 +2541,28 @@ static int alps_update_btn_info_ss4_v2(unsigned char 
otp[][4],
 }
 
 static int alps_update_dual_info_ss4_v2(unsigned char otp[][4],
-  struct alps_data *priv)
+  struct alps_data *priv,
+   struct psmouse *psmouse)
 {
bool is_dual = false;
+   int reg_val = 0;
+   struct ps2dev *ps2dev = &psmouse->ps2dev;
 
-   if (IS_SS4PLUS_DEV(priv->dev_id))
+   if (IS_SS4PLUS_DEV(priv->dev_id)) {
is_dual = (otp[0][0] >> 4) & 0x01;
 
+   /* For support TrackStick of Thinkpad L570 device */
+   if (alps_exit_command_mode(psmouse) == 0 &&
+   alps_enter_command_mode(psmouse) == 0) {
+   reg_val = alps_command_mode_read_reg(psmouse, 0xD7);
+   }
+   alps_exit_command_mode(psmouse);
+   ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE);
+
+   if (reg_val == 0x0C || reg_val == 0x1D)
+   is_dual = true;
+   }
+
if (is_dual)
priv->flags |= ALPS_DUALPOINT |
ALPS_DUALPOINT_WITH_PRESSURE;
@@ -2570,7 +2585,7 @@ static int alps_set_defaults_ss4_v2(struct psmouse 
*psmouse,
 
alps_update_btn_info_ss4_v2(otp, priv);
 
-   alps_update_dual_info_ss4_v2(otp, priv);
+   alps_update_dual_info_ss4_v2(otp, priv, psmouse);
 
return 0;
 }
-- 
2.14.1



RE: [PATCH] Input: ALPS - fix DualPoint flag for 74 03 28 devices

2017-11-15 Thread Masaki Ota
Hi, Pali, Aaron,

Current code is correct device setting, previous code is wrong.
If the trackstick does not work(DUALPOINT flag disable), Device Firmware 
setting is wrong.

But recently I received the same report from Thinkpad L570 user, and I checked 
this device and found this device Firmware setting is wrong. Sorry for our 
mistake.
Is your laptop L570 ?

I will add code that supports the trackstick for this device.

Best Regards,
Masaki Ota
-Original Message-
From: Pali Rohár [mailto:pali.ro...@gmail.com] 
Sent: Wednesday, November 15, 2017 5:35 PM
To: 太田 真喜 Masaki Ota 
Cc: linux-in...@vger.kernel.org; linux-kernel@vger.kernel.org; 
dmitry.torok...@gmail.com; Aaron Ma 
Subject: Re: [PATCH] Input: ALPS - fix DualPoint flag for 74 03 28 devices

On Wednesday 15 November 2017 14:34:04 Aaron Ma wrote:
> There is a regression of commit 4a646580f793 ("Input: ALPS - fix 
> two-finger scroll breakage"), ALPS device fails with log:
> 
> psmouse serio1: alps: Rejected trackstick packet from non DualPoint 
> device
> 
> ALPS device with id "74 03 28" report OTP[0] data 0xCE after commit 
> 4a646580f793, after restore the OTP reading order, it becomes to 0x10 
> as before and reports the right flag.
> 
> Fixes: 4a646580f793 ("Input: ALPS - fix two-finger scroll breakage")
> Cc: 
> Signed-off-by: Aaron Ma 
> ---
>  drivers/input/mouse/alps.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c 
> index 579b899add26..c59b8f7ca2fc 100644
> --- a/drivers/input/mouse/alps.c
> +++ b/drivers/input/mouse/alps.c
> @@ -2562,8 +2562,8 @@ static int alps_set_defaults_ss4_v2(struct 
> psmouse *psmouse,
>  
>   memset(otp, 0, sizeof(otp));
>  
> - if (alps_get_otp_values_ss4_v2(psmouse, 1, &otp[1][0]) ||
> - alps_get_otp_values_ss4_v2(psmouse, 0, &otp[0][0]))
> + if (alps_get_otp_values_ss4_v2(psmouse, 0, &otp[0][0]) ||
> + alps_get_otp_values_ss4_v2(psmouse, 1, &otp[1][0]))
>   return -1;
>  
>   alps_update_device_area_ss4_v2(otp, priv);

Masaki Ota, please look at this patch as it partially revert your commit
4a646580f793 ("Input: ALPS - fix two-finger scroll breakage"). Something smells 
here.

--
Pali Rohár
pali.ro...@gmail.com


[PATCH]Support new Alps HID Touchpad device

2017-10-05 Thread Masaki Ota
Hi, Jiri,

Sorry, I have fixed the build warning error, and send the patch again.

Best Regards,
Masaki Ota


[PATCH 1/7] Delete unnecessary structure

2017-10-05 Thread Masaki Ota
From: Masaki Ota 
-Delete "struct u1_dev devInfo" structure, because u1_dev structure is already 
declared as "struct u1_dev *data", and this structure is used for getting U1 
data in [PATCH 2/7].

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 69 +-
 1 file changed, 34 insertions(+), 35 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index ed9c0ea5b026..519bfcf9eaf0 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -259,7 +259,6 @@ static int alps_input_configured(struct hid_device *hdev, 
struct hid_input *hi)
 {
struct u1_dev *data = hid_get_drvdata(hdev);
struct input_dev *input = hi->input, *input2;
-   struct u1_dev devInfo;
int ret;
int res_x, res_y, i;
 
@@ -275,58 +274,58 @@ static int alps_input_configured(struct hid_device *hdev, 
struct hid_input *hi)
 
/* Device initialization */
ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1,
-   &devInfo.dev_ctrl, 0, true);
+   &data->dev_ctrl, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_DEV_CTRL_1 (%d)\n", ret);
goto exit;
}
 
-   devInfo.dev_ctrl &= ~U1_DISABLE_DEV;
-   devInfo.dev_ctrl |= U1_TP_ABS_MODE;
+   data->dev_ctrl &= ~U1_DISABLE_DEV;
+   data->dev_ctrl |= U1_TP_ABS_MODE;
ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1,
-   NULL, devInfo.dev_ctrl, false);
+   NULL, data->dev_ctrl, false);
if (ret < 0) {
dev_err(&hdev->dev, "failed to change TP mode (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_X,
-   &devInfo.sen_line_num_x, 0, true);
+   &data->sen_line_num_x, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_NUM_SENS_X (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_Y,
-   &devInfo.sen_line_num_y, 0, true);
+   &data->sen_line_num_y, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_NUM_SENS_Y (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_X,
-   &devInfo.pitch_x, 0, true);
+   &data->pitch_x, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PITCH_SENS_X (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_Y,
-   &devInfo.pitch_y, 0, true);
+   &data->pitch_y, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PITCH_SENS_Y (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_RESO_DWN_ABS,
-   &devInfo.resolution, 0, true);
+   &data->resolution, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_RESO_DWN_ABS (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PAD_BTN,
-   &devInfo.btn_info, 0, true);
+   &data->btn_info, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PAD_BTN (%d)\n", ret);
goto exit;
@@ -334,29 +333,29 @@ static int alps_input_configured(struct hid_device *hdev, 
struct hid_input *hi)
 
/* Check StickPointer device */
ret = u1_read_write_register(hdev, ADDRESS_U1_DEVICE_TYP,
-   &devInfo.dev_type, 0, true);
+   &data->dev_type, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_DEVICE_TYP (%d)\n", ret);
goto exit;
}
 
-   devInfo.x_active_len_mm =
-   (devInfo.pitch_x * (devInfo.sen_line_num_x - 1)) / 10;
-   devInfo.y_active_len_mm =
-   (devInfo.pitch_y * (devInfo.sen_line_num_y - 1)) / 10;
+   data->x_active_len_mm =
+   (data->pitch_x * (data->sen_line_num_x - 1)) / 10;
+   data->y_active_len_mm =
+   (data->pitch_y * (data->sen_line_num_y - 1)) / 10;
 
-   devInfo.x_max =
-   (devInfo.resolution << 2) * (devInfo.sen_line_num_x - 1);
-   devInfo.y_max =
-   (devInfo.resolution << 2) * (devInfo.sen_line_num_y - 1);
+  

[PATCH 2/7] Separate U1 device code

2017-10-05 Thread Masaki Ota
From: Masaki Ota 
-Create "static int u1_init()" function for separate U1 device initialization 
code from Main initialization.
-Create "has_sp" variable for checking whether it has SP device or not.

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 120 +++--
 1 file changed, 67 insertions(+), 53 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index 519bfcf9eaf0..c4ea5c6c9be9 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -75,6 +75,7 @@
  * @y_max: maximum y coordinate value
  * @btn_cnt: number of buttons
  * @sp_btn_cnt: number of stick buttons
+ * @has_sp: boolean of sp existense
  */
 struct u1_dev {
struct input_dev *input;
@@ -96,6 +97,7 @@ struct u1_dev {
u32 y_max;
u32 btn_cnt;
u32 sp_btn_cnt;
+   u8  has_sp;
 };
 
 static int u1_read_write_register(struct hid_device *hdev, u32 address,
@@ -255,99 +257,130 @@ static int alps_post_resume(struct hid_device *hdev)
 }
 #endif /* CONFIG_PM */
 
-static int alps_input_configured(struct hid_device *hdev, struct hid_input *hi)
+static int u1_init(struct hid_device *hdev, struct u1_dev *pri_data)
 {
-   struct u1_dev *data = hid_get_drvdata(hdev);
-   struct input_dev *input = hi->input, *input2;
int ret;
-   int res_x, res_y, i;
-
-   data->input = input;
-
-   hid_dbg(hdev, "Opening low level driver\n");
-   ret = hid_hw_open(hdev);
-   if (ret)
-   return ret;
-
-   /* Allow incoming hid reports */
-   hid_device_io_start(hdev);
 
/* Device initialization */
ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1,
-   &data->dev_ctrl, 0, true);
+   &pri_data->dev_ctrl, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_DEV_CTRL_1 (%d)\n", ret);
goto exit;
}
 
-   data->dev_ctrl &= ~U1_DISABLE_DEV;
-   data->dev_ctrl |= U1_TP_ABS_MODE;
+   pri_data->dev_ctrl &= ~U1_DISABLE_DEV;
+   pri_data->dev_ctrl |= U1_TP_ABS_MODE;
ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1,
-   NULL, data->dev_ctrl, false);
+   NULL, pri_data->dev_ctrl, false);
if (ret < 0) {
dev_err(&hdev->dev, "failed to change TP mode (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_X,
-   &data->sen_line_num_x, 0, true);
+   &pri_data->sen_line_num_x, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_NUM_SENS_X (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_Y,
-   &data->sen_line_num_y, 0, true);
+   &pri_data->sen_line_num_y, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_NUM_SENS_Y (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_X,
-   &data->pitch_x, 0, true);
+   &pri_data->pitch_x, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PITCH_SENS_X (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_Y,
-   &data->pitch_y, 0, true);
+   &pri_data->pitch_y, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PITCH_SENS_Y (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_RESO_DWN_ABS,
-   &data->resolution, 0, true);
+   &pri_data->resolution, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_RESO_DWN_ABS (%d)\n", ret);
goto exit;
}
+   pri_data->x_active_len_mm =
+   (pri_data->pitch_x * (pri_data->sen_line_num_x - 1)) / 10;
+   pri_data->y_active_len_mm =
+   (pri_data->pitch_y * (pri_data->sen_line_num_y - 1)) / 10;
+
+   pri_data->x_max =
+   (pri_data->resolution << 2) * (pri_data->sen_line_num_x - 1);
+   pri_data->y_max =
+   (pri_data->resolution << 2) * (pri_data->sen_line_num_y - 1);
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PAD_BTN,
-   &data->btn_info, 0, true);
+   &pri_data->btn_info, 0, true);
if (ret < 0)

[PATCH 4/7] replace some variables

2017-10-05 Thread Masaki Ota
From: Masaki Ota 
-Move some variables(dev_ctrl, dev_type, sen_line_num_x, sen_line_num_y, 
pitch_x, pitch_y, resolution, btn_info) from u1_dev structure to "u1_init()", 
because these variables are only used in "u1_init()" function.

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 67 --
 1 file changed, 27 insertions(+), 40 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index 201fe175cba3..4c323b58e009 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -61,14 +61,10 @@
  * @input2: pointer to the kernel input2 device
  * @hdev: pointer to the struct hid_device
  *
- * @dev_ctrl: device control parameter
  * @dev_type: device type
- * @sen_line_num_x: number of sensor line of X
- * @sen_line_num_y: number of sensor line of Y
- * @pitch_x: sensor pitch of X
- * @pitch_y: sensor pitch of Y
- * @resolution: resolution
- * @btn_info: button information
+ * @max_fingers: total number of fingers
+ * @has_sp: boolean of sp existense
+ * @sp_btn_info: button information
  * @x_active_len_mm: active area length of X (mm)
  * @y_active_len_mm: active area length of Y (mm)
  * @x_max: maximum x coordinate value
@@ -77,22 +73,14 @@
  * @y_min: minimum y coordinate value
  * @btn_cnt: number of buttons
  * @sp_btn_cnt: number of stick buttons
- * @has_sp: boolean of sp existense
- * @max_fingers: total number of fingers
  */
 struct u1_dev {
struct input_dev *input;
struct input_dev *input2;
struct hid_device *hdev;
 
-   u8  dev_ctrl;
-   u8  dev_type;
-   u8  sen_line_num_x;
-   u8  sen_line_num_y;
-   u8  pitch_x;
-   u8  pitch_y;
-   u8  resolution;
-   u8  btn_info;
+   u8  max_fingers;
+   u8  has_sp;
u8  sp_btn_info;
u32 x_active_len_mm;
u32 y_active_len_mm;
@@ -102,8 +90,6 @@ struct u1_dev {
u32 y_min;
u32 btn_cnt;
u32 sp_btn_cnt;
-   u8  has_sp;
-   u8  max_fingers;
 };
 
 static int u1_read_write_register(struct hid_device *hdev, u32 address,
@@ -266,78 +252,80 @@ static int alps_post_resume(struct hid_device *hdev)
 static int u1_init(struct hid_device *hdev, struct u1_dev *pri_data)
 {
int ret;
+   u8 tmp, dev_ctrl, sen_line_num_x, sen_line_num_y;
+   u8 pitch_x, pitch_y, resolution;
 
/* Device initialization */
ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1,
-   &pri_data->dev_ctrl, 0, true);
+   &dev_ctrl, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_DEV_CTRL_1 (%d)\n", ret);
goto exit;
}
 
-   pri_data->dev_ctrl &= ~U1_DISABLE_DEV;
-   pri_data->dev_ctrl |= U1_TP_ABS_MODE;
+   dev_ctrl &= ~U1_DISABLE_DEV;
+   dev_ctrl |= U1_TP_ABS_MODE;
ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1,
-   NULL, pri_data->dev_ctrl, false);
+   NULL, dev_ctrl, false);
if (ret < 0) {
dev_err(&hdev->dev, "failed to change TP mode (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_X,
-   &pri_data->sen_line_num_x, 0, true);
+   &sen_line_num_x, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_NUM_SENS_X (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_Y,
-   &pri_data->sen_line_num_y, 0, true);
+   &sen_line_num_y, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_NUM_SENS_Y (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_X,
-   &pri_data->pitch_x, 0, true);
+   &pitch_x, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PITCH_SENS_X (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_Y,
-   &pri_data->pitch_y, 0, true);
+   &pitch_y, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PITCH_SENS_Y (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_RESO_DWN_ABS,
-   &pri_data->resolution, 0, true);
+   &resolution, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_RESO_DWN_ABS (%d)\n", ret);
goto 

[PATCH 6/7] Add new U1 device ID

2017-10-05 Thread Masaki Ota
From: Masaki Ota 
-Add new U1 device Product ID
-This device is used on HP Elite book x360 series

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 3 +++
 drivers/hid/hid-core.c | 1 +
 drivers/hid/hid-ids.h  | 1 +
 3 files changed, 5 insertions(+)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index 5ae2cba8fe76..b1eeb4839bfc 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -767,6 +767,7 @@ static int alps_probe(struct hid_device *hdev, const struct 
hid_device_id *id)
data->dev_type = T4;
break;
case HID_DEVICE_ID_ALPS_U1_DUAL:
+   case HID_DEVICE_ID_ALPS_U1:
data->dev_type = U1;
break;
default:
@@ -791,6 +792,8 @@ static const struct hid_device_id alps_id[] = {
{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1_DUAL) },
{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
+   USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1) },
+   { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_BTNLESS) },
{ }
 };
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 9c3cb2e467e9..779e26cb3ba9 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1775,6 +1775,7 @@ static const struct hid_device_id 
hid_have_special_driver[] = {
{ HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
{ HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0xf705) },
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1_DUAL) },
+   { HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1) },
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_BTNLESS) 
},
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) 
},
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGICMOUSE) },
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 0b9726d321ee..2b50d12b993e 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -75,6 +75,7 @@
 
 #define USB_VENDOR_ID_ALPS_JP  0x044E
 #define HID_DEVICE_ID_ALPS_U1_DUAL 0x120B
+#define HID_DEVICE_ID_ALPS_U1  0x1215
 #define HID_DEVICE_ID_ALPS_T4_BTNLESS  0x120C
 
 #define USB_VENDOR_ID_AMI  0x046b
-- 
2.11.0



[PATCH 5/7] Support Alps T4 Touchpad device

2017-10-05 Thread Masaki Ota
From: Masaki Ota 
-Define T4 device specification value for support T4 device.
-Create "t4_contact_data" and "t4_input_report" structure for decode T4 data 
and store it.
-Create "t4_calc_check_sum()" function for calculate checksum value to send the 
device. T4 needs to send this value when read/write device address value.
-Create "t4_read_write_register()" function for read/write device address value.
-Create "t4_raw_event()" function for decode device XYZ data, palm and button 
data.
-Replace "MAX_TOUCHES" fixed variable to "max_fingers" variable.
-Add T4 devuce product ID. (0x120C)
-T4 device is used on HP EliteBook 1000 series and Zbook Stduio

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 339 ++---
 drivers/hid/hid-core.c |   3 +-
 drivers/hid/hid-ids.h  |   1 +
 3 files changed, 322 insertions(+), 21 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index 4c323b58e009..5ae2cba8fe76 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -52,8 +52,30 @@
 #define ADDRESS_U1_PAD_BTN 0x00800052
 #define ADDRESS_U1_SP_BTN  0x0080009F
 
+#define T4_INPUT_REPORT_LENsizeof(struct t4_input_report)
+#define T4_FEATURE_REPORT_LEN  T4_INPUT_REPORT_LEN
+#define T4_FEATURE_REPORT_ID   7
+#define T4_CMD_REGISTER_READ   0x08
+#define T4_CMD_REGISTER_WRITE  0x07
+
+#define T4_ADDRESS_BASE0xC2C0
+#define PRM_SYS_CONFIG_1   (T4_ADDRESS_BASE + 0x0002)
+#define T4_PRM_FEED_CONFIG_1   (T4_ADDRESS_BASE + 0x0004)
+#define T4_PRM_FEED_CONFIG_4   (T4_ADDRESS_BASE + 0x001A)
+#define T4_PRM_ID_CONFIG_3 (T4_ADDRESS_BASE + 0x00B0)
+
+
+#define T4_FEEDCFG4_ADVANCED_ABS_ENABLE0x01
+#define T4_I2C_ABS 0x78
+
+#define T4_COUNT_PER_ELECTRODE 256
 #define MAX_TOUCHES5
 
+enum dev_num {
+   U1,
+   T4,
+   UNKNOWN,
+};
 /**
  * struct u1_data
  *
@@ -74,11 +96,12 @@
  * @btn_cnt: number of buttons
  * @sp_btn_cnt: number of stick buttons
  */
-struct u1_dev {
+struct alps_dev {
struct input_dev *input;
struct input_dev *input2;
struct hid_device *hdev;
 
+   enum dev_num dev_type;
u8  max_fingers;
u8  has_sp;
u8  sp_btn_info;
@@ -92,6 +115,141 @@ struct u1_dev {
u32 sp_btn_cnt;
 };
 
+struct t4_contact_data {
+   u8  palm;
+   u8  x_lo;
+   u8  x_hi;
+   u8  y_lo;
+   u8  y_hi;
+};
+
+struct t4_input_report {
+   u8  reportID;
+   u8  numContacts;
+   struct t4_contact_data contact[5];
+   u8  button;
+   u8  track[5];
+   u8  zx[5], zy[5];
+   u8  palmTime[5];
+   u8  kilroy;
+   u16 timeStamp;
+};
+
+static u16 t4_calc_check_sum(u8 *buffer,
+   unsigned long offset, unsigned long length)
+{
+   u16 sum1 = 0xFF, sum2 = 0xFF;
+   unsigned long i = 0;
+
+   if (offset + length >= 50)
+   return 0;
+
+   while (length > 0) {
+   u32 tlen = length > 20 ? 20 : length;
+
+   length -= tlen;
+
+   do {
+   sum1 += buffer[offset + i];
+   sum2 += sum1;
+   i++;
+   } while (--tlen > 0);
+
+   sum1 = (sum1 & 0xFF) + (sum1 >> 8);
+   sum2 = (sum2 & 0xFF) + (sum2 >> 8);
+   }
+
+   sum1 = (sum1 & 0xFF) + (sum1 >> 8);
+   sum2 = (sum2 & 0xFF) + (sum2 >> 8);
+
+   return(sum2 << 8 | sum1);
+}
+
+static int t4_read_write_register(struct hid_device *hdev, u32 address,
+   u8 *read_val, u8 write_val, bool read_flag)
+{
+   int ret;
+   u16 check_sum;
+   u8 *input;
+   u8 *readbuf;
+
+   input = kzalloc(T4_FEATURE_REPORT_LEN, GFP_KERNEL);
+   if (!input)
+   return -ENOMEM;
+
+   input[0] = T4_FEATURE_REPORT_ID;
+   if (read_flag) {
+   input[1] = T4_CMD_REGISTER_READ;
+   input[8] = 0x00;
+   } else {
+   input[1] = T4_CMD_REGISTER_WRITE;
+   input[8] = write_val;
+   }
+   put_unaligned_le32(address, input + 2);
+   input[6] = 1;
+   input[7] = 0;
+
+   /* Calculate the checksum */
+   check_sum = t4_calc_check_sum(input, 1, 8);
+   input[9] = (u8)check_sum;
+   input[10] = (u8)(check_sum >> 8);
+   input[11] = 0;
+
+   ret = hid_hw_raw_request(hdev, T4_FEATURE_REPORT_ID, input,
+   T4_FEATURE_REPORT_LEN,
+   HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
+
+   if (ret < 0) {
+   dev_err(&hdev->dev, "failed to read command (%d)\n", ret);
+   goto exit;
+   

[PATCH 7/7] Support Alps U1 USB Touchpad device

2017-10-05 Thread Masaki Ota
From: Masaki Ota 
-Add T4 USB device Product ID. (0x1216)
-Separate T4 USB device initialization code from T4 Standard device code. 
-T4 USB device is used on HP Elite x2 series

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 35 +--
 drivers/hid/hid-core.c |  1 +
 drivers/hid/hid-ids.h  |  1 +
 3 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index b1eeb4839bfc..939ae8255805 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -440,6 +440,7 @@ static int alps_raw_event(struct hid_device *hdev,
 
switch (hdev->product) {
case HID_PRODUCT_ID_T4_BTNLESS:
+   case HID_DEVICE_ID_ALPS_T4_USB:
ret = t4_raw_event(hdata, data, size);
break;
default:
@@ -594,13 +595,29 @@ static int T4_init(struct hid_device *hdev, struct 
alps_dev *pri_data)
int ret;
u8 tmp, sen_line_num_x, sen_line_num_y;
 
-   ret = t4_read_write_register(hdev, T4_PRM_ID_CONFIG_3, &tmp, 0, true);
-   if (ret < 0) {
-   dev_err(&hdev->dev, "failed T4_PRM_ID_CONFIG_3 (%d)\n", ret);
+   if (hdev->product == HID_DEVICE_ID_ALPS_T4_BTNLESS) {
+   ret = t4_read_write_register(hdev,
+   T4_PRM_ID_CONFIG_3, &tmp, 0, true);
+   if (ret < 0) {
+   dev_err(&hdev->dev,
+   "failed T4_PRM_ID_CONFIG_3 (%d)\n", ret);
goto exit;
+   }
+   sen_line_num_x = 16 + ((tmp & 0x0F)  | (tmp & 0x08 ? 0xF0 : 0));
+   sen_line_num_y =
+   12 + (((tmp & 0xF0) >> 4)  | (tmp & 0x80 ? 0xF0 : 0));
+
+   ret = t4_read_write_register(hdev,
+   PRM_SYS_CONFIG_1, &tmp, 0, true);
+   if (ret < 0) {
+   dev_err(&hdev->dev,
+   "failed PRM_SYS_CONFIG_1 (%d)\n", ret);
+   goto exit;
+   }
+   } else {
+   sen_line_num_x = 20;
+   sen_line_num_y = 12;
}
-   sen_line_num_x = 16 + ((tmp & 0x0F)  | (tmp & 0x08 ? 0xF0 : 0));
-   sen_line_num_y = 12 + (((tmp & 0xF0) >> 4)  | (tmp & 0x80 ? 0xF0 : 0));
 
pri_data->x_max = sen_line_num_x * T4_COUNT_PER_ELECTRODE;
pri_data->x_min = T4_COUNT_PER_ELECTRODE;
@@ -609,11 +626,6 @@ static int T4_init(struct hid_device *hdev, struct 
alps_dev *pri_data)
pri_data->x_active_len_mm = pri_data->y_active_len_mm = 0;
pri_data->btn_cnt = 1;
 
-   ret = t4_read_write_register(hdev, PRM_SYS_CONFIG_1, &tmp, 0, true);
-   if (ret < 0) {
-   dev_err(&hdev->dev, "failed PRM_SYS_CONFIG_1 (%d)\n", ret);
-   goto exit;
-   }
tmp |= 0x02;
ret = t4_read_write_register(hdev, PRM_SYS_CONFIG_1, NULL, tmp, false);
if (ret < 0) {
@@ -764,6 +776,7 @@ static int alps_probe(struct hid_device *hdev, const struct 
hid_device_id *id)
 
switch (hdev->product) {
case HID_DEVICE_ID_ALPS_T4_BTNLESS:
+   case HID_DEVICE_ID_ALPS_T4_USB:
data->dev_type = T4;
break;
case HID_DEVICE_ID_ALPS_U1_DUAL:
@@ -795,6 +808,8 @@ static const struct hid_device_id alps_id[] = {
USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1) },
{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_BTNLESS) },
+   { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
+   USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_USB) },
{ }
 };
 MODULE_DEVICE_TABLE(hid, alps_id);
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 779e26cb3ba9..13ded460885e 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1777,6 +1777,7 @@ static const struct hid_device_id 
hid_have_special_driver[] = {
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1_DUAL) },
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1) },
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_BTNLESS) 
},
+   { HID_USB_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_USB) },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) 
},
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGICMOUSE) },
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 2b50d12b993e..71c2a021e296 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -76,6 +76,7 @@
 #define USB_VENDOR_ID_ALPS_JP  0x044E
 #define HID_DEVICE_ID_ALPS_U1_DUAL 0x120B
 #define HID_DEVICE_ID_ALPS_U1  0x1215
+#define HID_DEVICE_ID_ALPS_T4_USB  0x1216
 #define HID_DEVICE_ID_ALPS_T4_BTNLESS  0x120C
 
 #define USB_VENDOR_ID_AMI  0x046b
-- 
2.11.0



[PATCH 3/7] Add some variables

2017-10-05 Thread Masaki Ota
From: Masaki Ota 
-Create x_min, y_min and max_fingers variables for set correct XY minimum value 
and the number of max finger on each devices.
-Move the Button pad checking code to U1 init function, because this checking 
code is for U1 device.

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 38 --
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index c4ea5c6c9be9..201fe175cba3 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -73,9 +73,12 @@
  * @y_active_len_mm: active area length of Y (mm)
  * @x_max: maximum x coordinate value
  * @y_max: maximum y coordinate value
+ * @x_min: minimum x coordinate value
+ * @y_min: minimum y coordinate value
  * @btn_cnt: number of buttons
  * @sp_btn_cnt: number of stick buttons
  * @has_sp: boolean of sp existense
+ * @max_fingers: total number of fingers
  */
 struct u1_dev {
struct input_dev *input;
@@ -95,9 +98,12 @@ struct u1_dev {
u32 y_active_len_mm;
u32 x_max;
u32 y_max;
+   u32 x_min;
+   u32 y_min;
u32 btn_cnt;
u32 sp_btn_cnt;
u8  has_sp;
+   u8  max_fingers;
 };
 
 static int u1_read_write_register(struct hid_device *hdev, u32 address,
@@ -319,8 +325,10 @@ static int u1_init(struct hid_device *hdev, struct u1_dev 
*pri_data)
 
pri_data->x_max =
(pri_data->resolution << 2) * (pri_data->sen_line_num_x - 1);
+   pri_data->x_min = 1;
pri_data->y_max =
(pri_data->resolution << 2) * (pri_data->sen_line_num_y - 1);
+   pri_data->y_min = 1;
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PAD_BTN,
&pri_data->btn_info, 0, true);
@@ -328,6 +336,12 @@ static int u1_init(struct hid_device *hdev, struct u1_dev 
*pri_data)
dev_err(&hdev->dev, "failed U1_PAD_BTN (%d)\n", ret);
goto exit;
}
+   if ((pri_data->btn_info & 0x0F) == (pri_data->btn_info & 0xF0) >> 4) {
+   pri_data->btn_cnt = (pri_data->btn_info & 0x0F);
+   } else {
+   /* Button pad */
+   pri_data->btn_cnt = 1;
+   }
 
pri_data->has_sp = 0;
/* Check StickPointer device */
@@ -355,7 +369,7 @@ static int u1_init(struct hid_device *hdev, struct u1_dev 
*pri_data)
}
pri_data->has_sp = 1;
}
-
+   pri_data->max_fingers = 5;
 exit:
return ret;
 }
@@ -383,8 +397,10 @@ static int alps_input_configured(struct hid_device *hdev, 
struct hid_input *hi)
goto exit;
 
__set_bit(EV_ABS, input->evbit);
-   input_set_abs_params(input, ABS_MT_POSITION_X, 1, data->x_max, 0, 0);
-   input_set_abs_params(input, ABS_MT_POSITION_Y, 1, data->y_max, 0, 0);
+   input_set_abs_params(input, ABS_MT_POSITION_X,
+   data->x_min, data->x_max, 0, 0);
+   input_set_abs_params(input, ABS_MT_POSITION_Y,
+   data->y_min, data->y_max, 0, 0);
 
if (data->x_active_len_mm && data->y_active_len_mm) {
res_x = (data->x_max - 1) / data->x_active_len_mm;
@@ -396,26 +412,21 @@ static int alps_input_configured(struct hid_device *hdev, 
struct hid_input *hi)
 
input_set_abs_params(input, ABS_MT_PRESSURE, 0, 64, 0, 0);
 
-   input_mt_init_slots(input, MAX_TOUCHES, INPUT_MT_POINTER);
+   input_mt_init_slots(input, data->max_fingers, INPUT_MT_POINTER);
 
__set_bit(EV_KEY, input->evbit);
-   if ((data->btn_info & 0x0F) == (data->btn_info & 0xF0) >> 4) {
-   data->btn_cnt = (data->btn_info & 0x0F);
-   } else {
-   /* Button pad */
-   data->btn_cnt = 1;
+
+   if (data->btn_cnt == 1)
__set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
-   }
 
for (i = 0; i < data->btn_cnt; i++)
__set_bit(BTN_LEFT + i, input->keybit);
 
-
/* Stick device initialization */
if (data->has_sp) {
input2 = input_allocate_device();
if (!input2) {
-   ret = -ENOMEM;
+   input_free_device(input2);
goto exit;
}
 
@@ -439,8 +450,7 @@ static int alps_input_configured(struct hid_device *hdev, 
struct hid_input *hi)
__set_bit(INPUT_PROP_POINTER, input2->propbit);
__set_bit(INPUT_PROP_POINTING_STICK, input2->propbit);
 
-   ret = input_register_device(data->input2);
-   if (ret) {
+   if (input_register_device(data->input2)) {
input_free_device(input2);
goto exit;
}
-- 
2.11.0



[PATCH 1/7] Delete unnecessary structure

2017-10-05 Thread Masaki Ota
From: Masaki Ota 
-Delete "struct u1_dev devInfo" structure, because u1_dev structure is already 
declared as "struct u1_dev *data", and this structure is used for getting U1 
data in [PATCH 2/7].

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 69 +-
 1 file changed, 34 insertions(+), 35 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index ed9c0ea5b026..519bfcf9eaf0 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -259,7 +259,6 @@ static int alps_input_configured(struct hid_device *hdev, 
struct hid_input *hi)
 {
struct u1_dev *data = hid_get_drvdata(hdev);
struct input_dev *input = hi->input, *input2;
-   struct u1_dev devInfo;
int ret;
int res_x, res_y, i;
 
@@ -275,58 +274,58 @@ static int alps_input_configured(struct hid_device *hdev, 
struct hid_input *hi)
 
/* Device initialization */
ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1,
-   &devInfo.dev_ctrl, 0, true);
+   &data->dev_ctrl, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_DEV_CTRL_1 (%d)\n", ret);
goto exit;
}
 
-   devInfo.dev_ctrl &= ~U1_DISABLE_DEV;
-   devInfo.dev_ctrl |= U1_TP_ABS_MODE;
+   data->dev_ctrl &= ~U1_DISABLE_DEV;
+   data->dev_ctrl |= U1_TP_ABS_MODE;
ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1,
-   NULL, devInfo.dev_ctrl, false);
+   NULL, data->dev_ctrl, false);
if (ret < 0) {
dev_err(&hdev->dev, "failed to change TP mode (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_X,
-   &devInfo.sen_line_num_x, 0, true);
+   &data->sen_line_num_x, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_NUM_SENS_X (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_Y,
-   &devInfo.sen_line_num_y, 0, true);
+   &data->sen_line_num_y, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_NUM_SENS_Y (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_X,
-   &devInfo.pitch_x, 0, true);
+   &data->pitch_x, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PITCH_SENS_X (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_Y,
-   &devInfo.pitch_y, 0, true);
+   &data->pitch_y, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PITCH_SENS_Y (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_RESO_DWN_ABS,
-   &devInfo.resolution, 0, true);
+   &data->resolution, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_RESO_DWN_ABS (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PAD_BTN,
-   &devInfo.btn_info, 0, true);
+   &data->btn_info, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PAD_BTN (%d)\n", ret);
goto exit;
@@ -334,29 +333,29 @@ static int alps_input_configured(struct hid_device *hdev, 
struct hid_input *hi)
 
/* Check StickPointer device */
ret = u1_read_write_register(hdev, ADDRESS_U1_DEVICE_TYP,
-   &devInfo.dev_type, 0, true);
+   &data->dev_type, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_DEVICE_TYP (%d)\n", ret);
goto exit;
}
 
-   devInfo.x_active_len_mm =
-   (devInfo.pitch_x * (devInfo.sen_line_num_x - 1)) / 10;
-   devInfo.y_active_len_mm =
-   (devInfo.pitch_y * (devInfo.sen_line_num_y - 1)) / 10;
+   data->x_active_len_mm =
+   (data->pitch_x * (data->sen_line_num_x - 1)) / 10;
+   data->y_active_len_mm =
+   (data->pitch_y * (data->sen_line_num_y - 1)) / 10;
 
-   devInfo.x_max =
-   (devInfo.resolution << 2) * (devInfo.sen_line_num_x - 1);
-   devInfo.y_max =
-   (devInfo.resolution << 2) * (devInfo.sen_line_num_y - 1);
+  

[PATCH 6/7] Add new U1 device ID

2017-10-05 Thread Masaki Ota
From: Masaki Ota 
-Add new U1 device Product ID
-This device is used on HP Elite book x360 series

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 3 +++
 drivers/hid/hid-core.c | 1 +
 drivers/hid/hid-ids.h  | 1 +
 3 files changed, 5 insertions(+)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index bd02c98fa53d..18ec1ef57b2c 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -767,6 +767,7 @@ static int alps_probe(struct hid_device *hdev, const struct 
hid_device_id *id)
data->dev_type = T4;
break;
case HID_DEVICE_ID_ALPS_U1_DUAL:
+   case HID_DEVICE_ID_ALPS_U1:
data->dev_type = U1;
break;
default:
@@ -791,6 +792,8 @@ static const struct hid_device_id alps_id[] = {
{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1_DUAL) },
{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
+   USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1) },
+   { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_BTNLESS) },
{ }
 };
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 9c3cb2e467e9..779e26cb3ba9 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1775,6 +1775,7 @@ static const struct hid_device_id 
hid_have_special_driver[] = {
{ HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
{ HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0xf705) },
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1_DUAL) },
+   { HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1) },
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_BTNLESS) 
},
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) 
},
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGICMOUSE) },
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 0b9726d321ee..2b50d12b993e 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -75,6 +75,7 @@
 
 #define USB_VENDOR_ID_ALPS_JP  0x044E
 #define HID_DEVICE_ID_ALPS_U1_DUAL 0x120B
+#define HID_DEVICE_ID_ALPS_U1  0x1215
 #define HID_DEVICE_ID_ALPS_T4_BTNLESS  0x120C
 
 #define USB_VENDOR_ID_AMI  0x046b
-- 
2.11.0



[PATCH 3/7] Add some variables

2017-10-05 Thread Masaki Ota
From: Masaki Ota 
-Create x_min, y_min and max_fingers variables for set correct XY minimum value 
and the number of max finger on each devices.
-Move the Button pad checking code to U1 init function, because this checking 
code is for U1 device.

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 38 --
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index c4ea5c6c9be9..201fe175cba3 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -73,9 +73,12 @@
  * @y_active_len_mm: active area length of Y (mm)
  * @x_max: maximum x coordinate value
  * @y_max: maximum y coordinate value
+ * @x_min: minimum x coordinate value
+ * @y_min: minimum y coordinate value
  * @btn_cnt: number of buttons
  * @sp_btn_cnt: number of stick buttons
  * @has_sp: boolean of sp existense
+ * @max_fingers: total number of fingers
  */
 struct u1_dev {
struct input_dev *input;
@@ -95,9 +98,12 @@ struct u1_dev {
u32 y_active_len_mm;
u32 x_max;
u32 y_max;
+   u32 x_min;
+   u32 y_min;
u32 btn_cnt;
u32 sp_btn_cnt;
u8  has_sp;
+   u8  max_fingers;
 };
 
 static int u1_read_write_register(struct hid_device *hdev, u32 address,
@@ -319,8 +325,10 @@ static int u1_init(struct hid_device *hdev, struct u1_dev 
*pri_data)
 
pri_data->x_max =
(pri_data->resolution << 2) * (pri_data->sen_line_num_x - 1);
+   pri_data->x_min = 1;
pri_data->y_max =
(pri_data->resolution << 2) * (pri_data->sen_line_num_y - 1);
+   pri_data->y_min = 1;
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PAD_BTN,
&pri_data->btn_info, 0, true);
@@ -328,6 +336,12 @@ static int u1_init(struct hid_device *hdev, struct u1_dev 
*pri_data)
dev_err(&hdev->dev, "failed U1_PAD_BTN (%d)\n", ret);
goto exit;
}
+   if ((pri_data->btn_info & 0x0F) == (pri_data->btn_info & 0xF0) >> 4) {
+   pri_data->btn_cnt = (pri_data->btn_info & 0x0F);
+   } else {
+   /* Button pad */
+   pri_data->btn_cnt = 1;
+   }
 
pri_data->has_sp = 0;
/* Check StickPointer device */
@@ -355,7 +369,7 @@ static int u1_init(struct hid_device *hdev, struct u1_dev 
*pri_data)
}
pri_data->has_sp = 1;
}
-
+   pri_data->max_fingers = 5;
 exit:
return ret;
 }
@@ -383,8 +397,10 @@ static int alps_input_configured(struct hid_device *hdev, 
struct hid_input *hi)
goto exit;
 
__set_bit(EV_ABS, input->evbit);
-   input_set_abs_params(input, ABS_MT_POSITION_X, 1, data->x_max, 0, 0);
-   input_set_abs_params(input, ABS_MT_POSITION_Y, 1, data->y_max, 0, 0);
+   input_set_abs_params(input, ABS_MT_POSITION_X,
+   data->x_min, data->x_max, 0, 0);
+   input_set_abs_params(input, ABS_MT_POSITION_Y,
+   data->y_min, data->y_max, 0, 0);
 
if (data->x_active_len_mm && data->y_active_len_mm) {
res_x = (data->x_max - 1) / data->x_active_len_mm;
@@ -396,26 +412,21 @@ static int alps_input_configured(struct hid_device *hdev, 
struct hid_input *hi)
 
input_set_abs_params(input, ABS_MT_PRESSURE, 0, 64, 0, 0);
 
-   input_mt_init_slots(input, MAX_TOUCHES, INPUT_MT_POINTER);
+   input_mt_init_slots(input, data->max_fingers, INPUT_MT_POINTER);
 
__set_bit(EV_KEY, input->evbit);
-   if ((data->btn_info & 0x0F) == (data->btn_info & 0xF0) >> 4) {
-   data->btn_cnt = (data->btn_info & 0x0F);
-   } else {
-   /* Button pad */
-   data->btn_cnt = 1;
+
+   if (data->btn_cnt == 1)
__set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
-   }
 
for (i = 0; i < data->btn_cnt; i++)
__set_bit(BTN_LEFT + i, input->keybit);
 
-
/* Stick device initialization */
if (data->has_sp) {
input2 = input_allocate_device();
if (!input2) {
-   ret = -ENOMEM;
+   input_free_device(input2);
goto exit;
}
 
@@ -439,8 +450,7 @@ static int alps_input_configured(struct hid_device *hdev, 
struct hid_input *hi)
__set_bit(INPUT_PROP_POINTER, input2->propbit);
__set_bit(INPUT_PROP_POINTING_STICK, input2->propbit);
 
-   ret = input_register_device(data->input2);
-   if (ret) {
+   if (input_register_device(data->input2)) {
input_free_device(input2);
goto exit;
}
-- 
2.11.0



[PATCH]Support new Alps HID Touchpad device

2017-10-05 Thread Masaki Ota
I have modified the Patch.
About __maybe_unused annotation, it was specified by Benjamin in previous 
review.
So I added this annotation.
Best Regards,
Masaki OTa


[PATCH 4/7] replace some variables

2017-10-05 Thread Masaki Ota
From: Masaki Ota 
-Move some variables(dev_ctrl, dev_type, sen_line_num_x, sen_line_num_y, 
pitch_x, pitch_y, resolution, btn_info) from u1_dev structure to "u1_init()", 
because these variables are only used in "u1_init()" function.

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 67 --
 1 file changed, 27 insertions(+), 40 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index 201fe175cba3..4c323b58e009 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -61,14 +61,10 @@
  * @input2: pointer to the kernel input2 device
  * @hdev: pointer to the struct hid_device
  *
- * @dev_ctrl: device control parameter
  * @dev_type: device type
- * @sen_line_num_x: number of sensor line of X
- * @sen_line_num_y: number of sensor line of Y
- * @pitch_x: sensor pitch of X
- * @pitch_y: sensor pitch of Y
- * @resolution: resolution
- * @btn_info: button information
+ * @max_fingers: total number of fingers
+ * @has_sp: boolean of sp existense
+ * @sp_btn_info: button information
  * @x_active_len_mm: active area length of X (mm)
  * @y_active_len_mm: active area length of Y (mm)
  * @x_max: maximum x coordinate value
@@ -77,22 +73,14 @@
  * @y_min: minimum y coordinate value
  * @btn_cnt: number of buttons
  * @sp_btn_cnt: number of stick buttons
- * @has_sp: boolean of sp existense
- * @max_fingers: total number of fingers
  */
 struct u1_dev {
struct input_dev *input;
struct input_dev *input2;
struct hid_device *hdev;
 
-   u8  dev_ctrl;
-   u8  dev_type;
-   u8  sen_line_num_x;
-   u8  sen_line_num_y;
-   u8  pitch_x;
-   u8  pitch_y;
-   u8  resolution;
-   u8  btn_info;
+   u8  max_fingers;
+   u8  has_sp;
u8  sp_btn_info;
u32 x_active_len_mm;
u32 y_active_len_mm;
@@ -102,8 +90,6 @@ struct u1_dev {
u32 y_min;
u32 btn_cnt;
u32 sp_btn_cnt;
-   u8  has_sp;
-   u8  max_fingers;
 };
 
 static int u1_read_write_register(struct hid_device *hdev, u32 address,
@@ -266,78 +252,80 @@ static int alps_post_resume(struct hid_device *hdev)
 static int u1_init(struct hid_device *hdev, struct u1_dev *pri_data)
 {
int ret;
+   u8 tmp, dev_ctrl, sen_line_num_x, sen_line_num_y;
+   u8 pitch_x, pitch_y, resolution;
 
/* Device initialization */
ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1,
-   &pri_data->dev_ctrl, 0, true);
+   &dev_ctrl, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_DEV_CTRL_1 (%d)\n", ret);
goto exit;
}
 
-   pri_data->dev_ctrl &= ~U1_DISABLE_DEV;
-   pri_data->dev_ctrl |= U1_TP_ABS_MODE;
+   dev_ctrl &= ~U1_DISABLE_DEV;
+   dev_ctrl |= U1_TP_ABS_MODE;
ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1,
-   NULL, pri_data->dev_ctrl, false);
+   NULL, dev_ctrl, false);
if (ret < 0) {
dev_err(&hdev->dev, "failed to change TP mode (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_X,
-   &pri_data->sen_line_num_x, 0, true);
+   &sen_line_num_x, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_NUM_SENS_X (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_Y,
-   &pri_data->sen_line_num_y, 0, true);
+   &sen_line_num_y, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_NUM_SENS_Y (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_X,
-   &pri_data->pitch_x, 0, true);
+   &pitch_x, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PITCH_SENS_X (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_Y,
-   &pri_data->pitch_y, 0, true);
+   &pitch_y, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PITCH_SENS_Y (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_RESO_DWN_ABS,
-   &pri_data->resolution, 0, true);
+   &resolution, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_RESO_DWN_ABS (%d)\n", ret);
goto 

[PATCH 2/7] Separate U1 device code

2017-10-05 Thread Masaki Ota
From: Masaki Ota 
-Create "static int u1_init()" function for separate U1 device initialization 
code from Main initialization.
-Create "has_sp" variable for checking whether it has SP device or not.

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 120 +++--
 1 file changed, 67 insertions(+), 53 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index 519bfcf9eaf0..c4ea5c6c9be9 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -75,6 +75,7 @@
  * @y_max: maximum y coordinate value
  * @btn_cnt: number of buttons
  * @sp_btn_cnt: number of stick buttons
+ * @has_sp: boolean of sp existense
  */
 struct u1_dev {
struct input_dev *input;
@@ -96,6 +97,7 @@ struct u1_dev {
u32 y_max;
u32 btn_cnt;
u32 sp_btn_cnt;
+   u8  has_sp;
 };
 
 static int u1_read_write_register(struct hid_device *hdev, u32 address,
@@ -255,99 +257,130 @@ static int alps_post_resume(struct hid_device *hdev)
 }
 #endif /* CONFIG_PM */
 
-static int alps_input_configured(struct hid_device *hdev, struct hid_input *hi)
+static int u1_init(struct hid_device *hdev, struct u1_dev *pri_data)
 {
-   struct u1_dev *data = hid_get_drvdata(hdev);
-   struct input_dev *input = hi->input, *input2;
int ret;
-   int res_x, res_y, i;
-
-   data->input = input;
-
-   hid_dbg(hdev, "Opening low level driver\n");
-   ret = hid_hw_open(hdev);
-   if (ret)
-   return ret;
-
-   /* Allow incoming hid reports */
-   hid_device_io_start(hdev);
 
/* Device initialization */
ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1,
-   &data->dev_ctrl, 0, true);
+   &pri_data->dev_ctrl, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_DEV_CTRL_1 (%d)\n", ret);
goto exit;
}
 
-   data->dev_ctrl &= ~U1_DISABLE_DEV;
-   data->dev_ctrl |= U1_TP_ABS_MODE;
+   pri_data->dev_ctrl &= ~U1_DISABLE_DEV;
+   pri_data->dev_ctrl |= U1_TP_ABS_MODE;
ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1,
-   NULL, data->dev_ctrl, false);
+   NULL, pri_data->dev_ctrl, false);
if (ret < 0) {
dev_err(&hdev->dev, "failed to change TP mode (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_X,
-   &data->sen_line_num_x, 0, true);
+   &pri_data->sen_line_num_x, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_NUM_SENS_X (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_Y,
-   &data->sen_line_num_y, 0, true);
+   &pri_data->sen_line_num_y, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_NUM_SENS_Y (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_X,
-   &data->pitch_x, 0, true);
+   &pri_data->pitch_x, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PITCH_SENS_X (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_Y,
-   &data->pitch_y, 0, true);
+   &pri_data->pitch_y, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PITCH_SENS_Y (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_RESO_DWN_ABS,
-   &data->resolution, 0, true);
+   &pri_data->resolution, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_RESO_DWN_ABS (%d)\n", ret);
goto exit;
}
+   pri_data->x_active_len_mm =
+   (pri_data->pitch_x * (pri_data->sen_line_num_x - 1)) / 10;
+   pri_data->y_active_len_mm =
+   (pri_data->pitch_y * (pri_data->sen_line_num_y - 1)) / 10;
+
+   pri_data->x_max =
+   (pri_data->resolution << 2) * (pri_data->sen_line_num_x - 1);
+   pri_data->y_max =
+   (pri_data->resolution << 2) * (pri_data->sen_line_num_y - 1);
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PAD_BTN,
-   &data->btn_info, 0, true);
+   &pri_data->btn_info, 0, true);
if (ret < 0)

[PATCH 7/7] Support Alps U1 USB Touchpad device

2017-10-05 Thread Masaki Ota
From: Masaki Ota 
-Add T4 USB device Product ID. (0x1216)
-Separate T4 USB device initialization code from T4 Standard device code. 
-T4 USB device is used on HP Elite x2 series

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 35 +--
 drivers/hid/hid-core.c |  1 +
 drivers/hid/hid-ids.h  |  1 +
 3 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index 18ec1ef57b2c..8bc079ba9cc5 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -440,6 +440,7 @@ static int alps_raw_event(struct hid_device *hdev,
 
switch (hdev->product) {
case HID_PRODUCT_ID_T4_BTNLESS:
+   case HID_DEVICE_ID_ALPS_T4_USB:
ret = t4_raw_event(hdata, data, size);
break;
default:
@@ -594,13 +595,29 @@ static int T4_init(struct hid_device *hdev, struct 
alps_dev *pri_data)
int ret;
u8 tmp, sen_line_num_x, sen_line_num_y;
 
-   ret = t4_read_write_register(hdev, T4_PRM_ID_CONFIG_3, &tmp, 0, true);
-   if (ret < 0) {
-   dev_err(&hdev->dev, "failed T4_PRM_ID_CONFIG_3 (%d)\n", ret);
+   if (hdev->product == HID_DEVICE_ID_ALPS_T4_BTNLESS) {
+   ret = t4_read_write_register(hdev,
+   T4_PRM_ID_CONFIG_3, &tmp, 0, true);
+   if (ret < 0) {
+   dev_err(&hdev->dev,
+   "failed T4_PRM_ID_CONFIG_3 (%d)\n", ret);
goto exit;
+   }
+   sen_line_num_x = 16 + ((tmp & 0x0F)  | (tmp & 0x08 ? 0xF0 : 0));
+   sen_line_num_y =
+   12 + (((tmp & 0xF0) >> 4)  | (tmp & 0x80 ? 0xF0 : 0));
+
+   ret = t4_read_write_register(hdev,
+   PRM_SYS_CONFIG_1, &tmp, 0, true);
+   if (ret < 0) {
+   dev_err(&hdev->dev,
+   "failed PRM_SYS_CONFIG_1 (%d)\n", ret);
+   goto exit;
+   }
+   } else {
+   sen_line_num_x = 20;
+   sen_line_num_y = 12;
}
-   sen_line_num_x = 16 + ((tmp & 0x0F)  | (tmp & 0x08 ? 0xF0 : 0));
-   sen_line_num_y = 12 + (((tmp & 0xF0) >> 4)  | (tmp & 0x80 ? 0xF0 : 0));
 
pri_data->x_max = sen_line_num_x * T4_COUNT_PER_ELECTRODE;
pri_data->x_min = T4_COUNT_PER_ELECTRODE;
@@ -609,11 +626,6 @@ static int T4_init(struct hid_device *hdev, struct 
alps_dev *pri_data)
pri_data->x_active_len_mm = pri_data->y_active_len_mm = 0;
pri_data->btn_cnt = 1;
 
-   ret = t4_read_write_register(hdev, PRM_SYS_CONFIG_1, &tmp, 0, true);
-   if (ret < 0) {
-   dev_err(&hdev->dev, "failed PRM_SYS_CONFIG_1 (%d)\n", ret);
-   goto exit;
-   }
tmp |= 0x02;
ret = t4_read_write_register(hdev, PRM_SYS_CONFIG_1, NULL, tmp, false);
if (ret < 0) {
@@ -764,6 +776,7 @@ static int alps_probe(struct hid_device *hdev, const struct 
hid_device_id *id)
 
switch (hdev->product) {
case HID_DEVICE_ID_ALPS_T4_BTNLESS:
+   case HID_DEVICE_ID_ALPS_T4_USB:
data->dev_type = T4;
break;
case HID_DEVICE_ID_ALPS_U1_DUAL:
@@ -795,6 +808,8 @@ static const struct hid_device_id alps_id[] = {
USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1) },
{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_BTNLESS) },
+   { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
+   USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_USB) },
{ }
 };
 MODULE_DEVICE_TABLE(hid, alps_id);
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 779e26cb3ba9..13ded460885e 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1777,6 +1777,7 @@ static const struct hid_device_id 
hid_have_special_driver[] = {
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1_DUAL) },
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1) },
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_BTNLESS) 
},
+   { HID_USB_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_USB) },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) 
},
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGICMOUSE) },
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 2b50d12b993e..71c2a021e296 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -76,6 +76,7 @@
 #define USB_VENDOR_ID_ALPS_JP  0x044E
 #define HID_DEVICE_ID_ALPS_U1_DUAL 0x120B
 #define HID_DEVICE_ID_ALPS_U1  0x1215
+#define HID_DEVICE_ID_ALPS_T4_USB  0x1216
 #define HID_DEVICE_ID_ALPS_T4_BTNLESS  0x120C
 
 #define USB_VENDOR_ID_AMI  0x046b
-- 
2.11.0



[PATCH 5/7] Support Alps T4 Touchpad device

2017-10-05 Thread Masaki Ota
From: Masaki Ota 
-Define T4 device specification value for support T4 device.
-Create "t4_contact_data" and "t4_input_report" structure for decode T4 data 
and store it.
-Create "t4_calc_check_sum()" function for calculate checksum value to send the 
device. T4 needs to send this value when read/write device address value.
-Create "t4_read_write_register()" function for read/write device address value.
-Create "t4_raw_event()" function for decode device XYZ data, palm and button 
data.
-Replace "MAX_TOUCHES" fixed variable to "max_fingers" variable.
-Add T4 devuce product ID. (0x120C)
-T4 device is used on HP EliteBook 1000 series and Zbook Stduio

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 339 ++---
 drivers/hid/hid-core.c |   3 +-
 drivers/hid/hid-ids.h  |   1 +
 3 files changed, 322 insertions(+), 21 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index 4c323b58e009..bd02c98fa53d 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -52,8 +52,30 @@
 #define ADDRESS_U1_PAD_BTN 0x00800052
 #define ADDRESS_U1_SP_BTN  0x0080009F
 
+#define T4_INPUT_REPORT_LENsizeof(struct t4_input_report)
+#define T4_FEATURE_REPORT_LEN  T4_INPUT_REPORT_LEN
+#define T4_FEATURE_REPORT_ID   7
+#define T4_CMD_REGISTER_READ   0x08
+#define T4_CMD_REGISTER_WRITE  0x07
+
+#define T4_ADDRESS_BASE0xC2C0
+#define PRM_SYS_CONFIG_1   (T4_ADDRESS_BASE + 0x0002)
+#define T4_PRM_FEED_CONFIG_1   (T4_ADDRESS_BASE + 0x0004)
+#define T4_PRM_FEED_CONFIG_4   (T4_ADDRESS_BASE + 0x001A)
+#define T4_PRM_ID_CONFIG_3 (T4_ADDRESS_BASE + 0x00B0)
+
+
+#define T4_FEEDCFG4_ADVANCED_ABS_ENABLE0x01
+#define T4_I2C_ABS 0x78
+
+#define T4_COUNT_PER_ELECTRODE 256
 #define MAX_TOUCHES5
 
+enum dev_num {
+   U1,
+   T4,
+   UNKNOWN,
+};
 /**
  * struct u1_data
  *
@@ -74,11 +96,12 @@
  * @btn_cnt: number of buttons
  * @sp_btn_cnt: number of stick buttons
  */
-struct u1_dev {
+struct alps_dev {
struct input_dev *input;
struct input_dev *input2;
struct hid_device *hdev;
 
+   enum dev_num dev_type;
u8  max_fingers;
u8  has_sp;
u8  sp_btn_info;
@@ -92,6 +115,141 @@ struct u1_dev {
u32 sp_btn_cnt;
 };
 
+struct t4_contact_data {
+   u8  palm;
+   u8  x_lo;
+   u8  x_hi;
+   u8  y_lo;
+   u8  y_hi;
+};
+
+struct t4_input_report {
+   u8  reportID;
+   u8  numContacts;
+   struct t4_contact_data contact[5];
+   u8  button;
+   u8  track[5];
+   u8  zx[5], zy[5];
+   u8  palmTime[5];
+   u8  kilroy;
+   u16 timeStamp;
+};
+
+static u16 t4_calc_check_sum(u8 *buffer,
+   unsigned long offset, unsigned long length)
+{
+   u16 sum1 = 0xFF, sum2 = 0xFF;
+   unsigned long i = 0;
+
+   if (offset + length >= 50)
+   return 0;
+
+   while (length > 0) {
+   u32 tlen = length > 20 ? 20 : length;
+
+   length -= tlen;
+
+   do {
+   sum1 += buffer[offset + i];
+   sum2 += sum1;
+   i++;
+   } while (--tlen > 0);
+
+   sum1 = (sum1 & 0xFF) + (sum1 >> 8);
+   sum2 = (sum2 & 0xFF) + (sum2 >> 8);
+   }
+
+   sum1 = (sum1 & 0xFF) + (sum1 >> 8);
+   sum2 = (sum2 & 0xFF) + (sum2 >> 8);
+
+   return(sum2 << 8 | sum1);
+}
+
+static int t4_read_write_register(struct hid_device *hdev, u32 address,
+   u8 *read_val, u8 write_val, bool read_flag)
+{
+   int ret;
+   u16 check_sum;
+   u8 *input;
+   u8 *readbuf;
+
+   input = kzalloc(T4_FEATURE_REPORT_LEN, GFP_KERNEL);
+   if (!input)
+   return -ENOMEM;
+
+   input[0] = T4_FEATURE_REPORT_ID;
+   if (read_flag) {
+   input[1] = T4_CMD_REGISTER_READ;
+   input[8] = 0x00;
+   } else {
+   input[1] = T4_CMD_REGISTER_WRITE;
+   input[8] = write_val;
+   }
+   put_unaligned_le32(address, input + 2);
+   input[6] = 1;
+   input[7] = 0;
+
+   /* Calculate the checksum */
+   check_sum = t4_calc_check_sum(input, 1, 8);
+   input[9] = (u8)check_sum;
+   input[10] = (u8)(check_sum >> 8);
+   input[11] = 0;
+
+   ret = hid_hw_raw_request(hdev, T4_FEATURE_REPORT_ID, input,
+   T4_FEATURE_REPORT_LEN,
+   HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
+
+   if (ret < 0) {
+   dev_err(&hdev->dev, "failed to read command (%d)\n", ret);
+   

[PATCH 2/7] Minor changes in hid-alps.c for support new Alps device(Separate U1 device code)

2017-09-11 Thread Masaki Ota
From: Masaki Ota 
-To support Alps T4 device, separate U1 device code

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 120 +++--
 1 file changed, 67 insertions(+), 53 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index 519bfcf9eaf0..c4ea5c6c9be9 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -75,6 +75,7 @@
  * @y_max: maximum y coordinate value
  * @btn_cnt: number of buttons
  * @sp_btn_cnt: number of stick buttons
+ * @has_sp: boolean of sp existense
  */
 struct u1_dev {
struct input_dev *input;
@@ -96,6 +97,7 @@ struct u1_dev {
u32 y_max;
u32 btn_cnt;
u32 sp_btn_cnt;
+   u8  has_sp;
 };
 
 static int u1_read_write_register(struct hid_device *hdev, u32 address,
@@ -255,99 +257,130 @@ static int alps_post_resume(struct hid_device *hdev)
 }
 #endif /* CONFIG_PM */
 
-static int alps_input_configured(struct hid_device *hdev, struct hid_input *hi)
+static int u1_init(struct hid_device *hdev, struct u1_dev *pri_data)
 {
-   struct u1_dev *data = hid_get_drvdata(hdev);
-   struct input_dev *input = hi->input, *input2;
int ret;
-   int res_x, res_y, i;
-
-   data->input = input;
-
-   hid_dbg(hdev, "Opening low level driver\n");
-   ret = hid_hw_open(hdev);
-   if (ret)
-   return ret;
-
-   /* Allow incoming hid reports */
-   hid_device_io_start(hdev);
 
/* Device initialization */
ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1,
-   &data->dev_ctrl, 0, true);
+   &pri_data->dev_ctrl, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_DEV_CTRL_1 (%d)\n", ret);
goto exit;
}
 
-   data->dev_ctrl &= ~U1_DISABLE_DEV;
-   data->dev_ctrl |= U1_TP_ABS_MODE;
+   pri_data->dev_ctrl &= ~U1_DISABLE_DEV;
+   pri_data->dev_ctrl |= U1_TP_ABS_MODE;
ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1,
-   NULL, data->dev_ctrl, false);
+   NULL, pri_data->dev_ctrl, false);
if (ret < 0) {
dev_err(&hdev->dev, "failed to change TP mode (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_X,
-   &data->sen_line_num_x, 0, true);
+   &pri_data->sen_line_num_x, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_NUM_SENS_X (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_Y,
-   &data->sen_line_num_y, 0, true);
+   &pri_data->sen_line_num_y, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_NUM_SENS_Y (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_X,
-   &data->pitch_x, 0, true);
+   &pri_data->pitch_x, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PITCH_SENS_X (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_Y,
-   &data->pitch_y, 0, true);
+   &pri_data->pitch_y, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PITCH_SENS_Y (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_RESO_DWN_ABS,
-   &data->resolution, 0, true);
+   &pri_data->resolution, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_RESO_DWN_ABS (%d)\n", ret);
goto exit;
}
+   pri_data->x_active_len_mm =
+   (pri_data->pitch_x * (pri_data->sen_line_num_x - 1)) / 10;
+   pri_data->y_active_len_mm =
+   (pri_data->pitch_y * (pri_data->sen_line_num_y - 1)) / 10;
+
+   pri_data->x_max =
+   (pri_data->resolution << 2) * (pri_data->sen_line_num_x - 1);
+   pri_data->y_max =
+   (pri_data->resolution << 2) * (pri_data->sen_line_num_y - 1);
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PAD_BTN,
-   &data->btn_info, 0, true);
+   &pri_data->btn_info, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PAD_BTN (%d)\n", ret);
goto exit;
}
 
+   pri_dat

[PATCH 1/7] Minor changes in hid-alps.c for support new Alps device(Delete unnecessary structure)

2017-09-11 Thread Masaki Ota
From: Masaki Ota 
-To support Alps T4 device, clean up the source code
-Delete unnecessary structure

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 69 +-
 1 file changed, 34 insertions(+), 35 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index ed9c0ea5b026..519bfcf9eaf0 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -259,7 +259,6 @@ static int alps_input_configured(struct hid_device *hdev, 
struct hid_input *hi)
 {
struct u1_dev *data = hid_get_drvdata(hdev);
struct input_dev *input = hi->input, *input2;
-   struct u1_dev devInfo;
int ret;
int res_x, res_y, i;
 
@@ -275,58 +274,58 @@ static int alps_input_configured(struct hid_device *hdev, 
struct hid_input *hi)
 
/* Device initialization */
ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1,
-   &devInfo.dev_ctrl, 0, true);
+   &data->dev_ctrl, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_DEV_CTRL_1 (%d)\n", ret);
goto exit;
}
 
-   devInfo.dev_ctrl &= ~U1_DISABLE_DEV;
-   devInfo.dev_ctrl |= U1_TP_ABS_MODE;
+   data->dev_ctrl &= ~U1_DISABLE_DEV;
+   data->dev_ctrl |= U1_TP_ABS_MODE;
ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1,
-   NULL, devInfo.dev_ctrl, false);
+   NULL, data->dev_ctrl, false);
if (ret < 0) {
dev_err(&hdev->dev, "failed to change TP mode (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_X,
-   &devInfo.sen_line_num_x, 0, true);
+   &data->sen_line_num_x, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_NUM_SENS_X (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_Y,
-   &devInfo.sen_line_num_y, 0, true);
+   &data->sen_line_num_y, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_NUM_SENS_Y (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_X,
-   &devInfo.pitch_x, 0, true);
+   &data->pitch_x, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PITCH_SENS_X (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_Y,
-   &devInfo.pitch_y, 0, true);
+   &data->pitch_y, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PITCH_SENS_Y (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_RESO_DWN_ABS,
-   &devInfo.resolution, 0, true);
+   &data->resolution, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_RESO_DWN_ABS (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PAD_BTN,
-   &devInfo.btn_info, 0, true);
+   &data->btn_info, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PAD_BTN (%d)\n", ret);
goto exit;
@@ -334,29 +333,29 @@ static int alps_input_configured(struct hid_device *hdev, 
struct hid_input *hi)
 
/* Check StickPointer device */
ret = u1_read_write_register(hdev, ADDRESS_U1_DEVICE_TYP,
-   &devInfo.dev_type, 0, true);
+   &data->dev_type, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_DEVICE_TYP (%d)\n", ret);
goto exit;
}
 
-   devInfo.x_active_len_mm =
-   (devInfo.pitch_x * (devInfo.sen_line_num_x - 1)) / 10;
-   devInfo.y_active_len_mm =
-   (devInfo.pitch_y * (devInfo.sen_line_num_y - 1)) / 10;
+   data->x_active_len_mm =
+   (data->pitch_x * (data->sen_line_num_x - 1)) / 10;
+   data->y_active_len_mm =
+   (data->pitch_y * (data->sen_line_num_y - 1)) / 10;
 
-   devInfo.x_max =
-   (devInfo.resolution << 2) * (devInfo.sen_line_num_x - 1);
-   devInfo.y_max =
-   (devInfo.resolution << 2) * (devInfo.sen_line_num_y - 1);
+   data->x_max =
+   (data->resolution << 2) * (data->sen_line_num_x - 1);
+   data->y_max =

[PATCH 7/7] Support Alps U1 USB device

2017-09-11 Thread Masaki Ota
From: Masaki Ota 
-Add T4 USB device code and Product ID
-This device is used on HP Elite x2 series

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 35 +--
 drivers/hid/hid-core.c |  1 +
 drivers/hid/hid-ids.h  |  1 +
 3 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index e7ae3a7b8e7d..e7a4e063597f 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -444,6 +444,7 @@ static int alps_raw_event(struct hid_device *hdev,
 
switch (hdev->product) {
case HID_PRODUCT_ID_T4_BTNLESS:
+   case HID_DEVICE_ID_ALPS_T4_USB:
ret = t4_raw_event(hdata, data, size);
break;
default:
@@ -598,13 +599,29 @@ static int T4_init(struct hid_device *hdev, struct 
alps_dev *pri_data)
int ret;
u8 tmp, sen_line_num_x, sen_line_num_y;
 
-   ret = t4_read_write_register(hdev, T4_PRM_ID_CONFIG_3, &tmp, 0, true);
-   if (ret < 0) {
-   dev_err(&hdev->dev, "failed T4_PRM_ID_CONFIG_3 (%d)\n", ret);
+   if (hdev->product == HID_DEVICE_ID_ALPS_T4_BTNLESS) {
+   ret = t4_read_write_register(hdev,
+   T4_PRM_ID_CONFIG_3, &tmp, 0, true);
+   if (ret < 0) {
+   dev_err(&hdev->dev,
+   "failed T4_PRM_ID_CONFIG_3 (%d)\n", ret);
goto exit;
+   }
+   sen_line_num_x = 16 + ((tmp & 0x0F)  | (tmp & 0x08 ? 0xF0 : 0));
+   sen_line_num_y =
+   12 + (((tmp & 0xF0) >> 4)  | (tmp & 0x80 ? 0xF0 : 0));
+
+   ret = t4_read_write_register(hdev,
+   PRM_SYS_CONFIG_1, &tmp, 0, true);
+   if (ret < 0) {
+   dev_err(&hdev->dev,
+   "failed PRM_SYS_CONFIG_1 (%d)\n", ret);
+   goto exit;
+   }
+   } else {
+   sen_line_num_x = 20;
+   sen_line_num_y = 12;
}
-   sen_line_num_x = 16 + ((tmp & 0x0F)  | (tmp & 0x08 ? 0xF0 : 0));
-   sen_line_num_y = 12 + (((tmp & 0xF0) >> 4)  | (tmp & 0x80 ? 0xF0 : 0));
 
pri_data->x_max = sen_line_num_x * T4_COUNT_PER_ELECTRODE;
pri_data->x_min = T4_COUNT_PER_ELECTRODE;
@@ -613,11 +630,6 @@ static int T4_init(struct hid_device *hdev, struct 
alps_dev *pri_data)
pri_data->x_active_len_mm = pri_data->y_active_len_mm = 0;
pri_data->btn_cnt = 1;
 
-   ret = t4_read_write_register(hdev, PRM_SYS_CONFIG_1, &tmp, 0, true);
-   if (ret < 0) {
-   dev_err(&hdev->dev, "failed PRM_SYS_CONFIG_1 (%d)\n", ret);
-   goto exit;
-   }
tmp |= 0x02;
ret = t4_read_write_register(hdev, PRM_SYS_CONFIG_1, NULL, tmp, false);
if (ret < 0) {
@@ -768,6 +780,7 @@ static int alps_probe(struct hid_device *hdev, const struct 
hid_device_id *id)
 
switch (hdev->product) {
case HID_DEVICE_ID_ALPS_T4_BTNLESS:
+   case HID_DEVICE_ID_ALPS_T4_USB:
data->dev_type = T4;
break;
case HID_DEVICE_ID_ALPS_U1_DUAL:
@@ -799,6 +812,8 @@ static const struct hid_device_id alps_id[] = {
USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1) },
{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_BTNLESS) },
+   { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
+   USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_USB) },
{ }
 };
 MODULE_DEVICE_TABLE(hid, alps_id);
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 779e26cb3ba9..13ded460885e 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1777,6 +1777,7 @@ static const struct hid_device_id 
hid_have_special_driver[] = {
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1_DUAL) },
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1) },
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_BTNLESS) 
},
+   { HID_USB_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_USB) },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) 
},
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGICMOUSE) },
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 2b50d12b993e..71c2a021e296 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -76,6 +76,7 @@
 #define USB_VENDOR_ID_ALPS_JP  0x044E
 #define HID_DEVICE_ID_ALPS_U1_DUAL 0x120B
 #define HID_DEVICE_ID_ALPS_U1  0x1215
+#define HID_DEVICE_ID_ALPS_T4_USB  0x1216
 #define HID_DEVICE_ID_ALPS_T4_BTNLESS  0x120C
 
 #define USB_VENDOR_ID_AMI  0x046b
-- 
2.11.0



[PATCH 4/7] Minor changes in hid-alps.c for support new Alps device(replace some variables)

2017-09-11 Thread Masaki Ota
From: Masaki Ota 
-To support Alps T4 device, replace some variables

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 67 --
 1 file changed, 27 insertions(+), 40 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index 201fe175cba3..4c323b58e009 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -61,14 +61,10 @@
  * @input2: pointer to the kernel input2 device
  * @hdev: pointer to the struct hid_device
  *
- * @dev_ctrl: device control parameter
  * @dev_type: device type
- * @sen_line_num_x: number of sensor line of X
- * @sen_line_num_y: number of sensor line of Y
- * @pitch_x: sensor pitch of X
- * @pitch_y: sensor pitch of Y
- * @resolution: resolution
- * @btn_info: button information
+ * @max_fingers: total number of fingers
+ * @has_sp: boolean of sp existense
+ * @sp_btn_info: button information
  * @x_active_len_mm: active area length of X (mm)
  * @y_active_len_mm: active area length of Y (mm)
  * @x_max: maximum x coordinate value
@@ -77,22 +73,14 @@
  * @y_min: minimum y coordinate value
  * @btn_cnt: number of buttons
  * @sp_btn_cnt: number of stick buttons
- * @has_sp: boolean of sp existense
- * @max_fingers: total number of fingers
  */
 struct u1_dev {
struct input_dev *input;
struct input_dev *input2;
struct hid_device *hdev;
 
-   u8  dev_ctrl;
-   u8  dev_type;
-   u8  sen_line_num_x;
-   u8  sen_line_num_y;
-   u8  pitch_x;
-   u8  pitch_y;
-   u8  resolution;
-   u8  btn_info;
+   u8  max_fingers;
+   u8  has_sp;
u8  sp_btn_info;
u32 x_active_len_mm;
u32 y_active_len_mm;
@@ -102,8 +90,6 @@ struct u1_dev {
u32 y_min;
u32 btn_cnt;
u32 sp_btn_cnt;
-   u8  has_sp;
-   u8  max_fingers;
 };
 
 static int u1_read_write_register(struct hid_device *hdev, u32 address,
@@ -266,78 +252,80 @@ static int alps_post_resume(struct hid_device *hdev)
 static int u1_init(struct hid_device *hdev, struct u1_dev *pri_data)
 {
int ret;
+   u8 tmp, dev_ctrl, sen_line_num_x, sen_line_num_y;
+   u8 pitch_x, pitch_y, resolution;
 
/* Device initialization */
ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1,
-   &pri_data->dev_ctrl, 0, true);
+   &dev_ctrl, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_DEV_CTRL_1 (%d)\n", ret);
goto exit;
}
 
-   pri_data->dev_ctrl &= ~U1_DISABLE_DEV;
-   pri_data->dev_ctrl |= U1_TP_ABS_MODE;
+   dev_ctrl &= ~U1_DISABLE_DEV;
+   dev_ctrl |= U1_TP_ABS_MODE;
ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1,
-   NULL, pri_data->dev_ctrl, false);
+   NULL, dev_ctrl, false);
if (ret < 0) {
dev_err(&hdev->dev, "failed to change TP mode (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_X,
-   &pri_data->sen_line_num_x, 0, true);
+   &sen_line_num_x, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_NUM_SENS_X (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_Y,
-   &pri_data->sen_line_num_y, 0, true);
+   &sen_line_num_y, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_NUM_SENS_Y (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_X,
-   &pri_data->pitch_x, 0, true);
+   &pitch_x, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PITCH_SENS_X (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_Y,
-   &pri_data->pitch_y, 0, true);
+   &pitch_y, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PITCH_SENS_Y (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_RESO_DWN_ABS,
-   &pri_data->resolution, 0, true);
+   &resolution, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_RESO_DWN_ABS (%d)\n", ret);
goto exit;
}
pri_data->x_active_len_mm =
-   (pri_data->pitch_x * (pri_data->sen_line_num_x - 1)) / 10;
+   (pitch_x * (sen_line_num_x

[PATCH 3/7] Minor changes in hid-alps.c for support new Alps device(Add some variables)

2017-09-11 Thread Masaki Ota
From: Masaki Ota 
-To support Alps T4 device, add x_min, y_min, max_fingers variables

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 38 --
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index c4ea5c6c9be9..201fe175cba3 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -73,9 +73,12 @@
  * @y_active_len_mm: active area length of Y (mm)
  * @x_max: maximum x coordinate value
  * @y_max: maximum y coordinate value
+ * @x_min: minimum x coordinate value
+ * @y_min: minimum y coordinate value
  * @btn_cnt: number of buttons
  * @sp_btn_cnt: number of stick buttons
  * @has_sp: boolean of sp existense
+ * @max_fingers: total number of fingers
  */
 struct u1_dev {
struct input_dev *input;
@@ -95,9 +98,12 @@ struct u1_dev {
u32 y_active_len_mm;
u32 x_max;
u32 y_max;
+   u32 x_min;
+   u32 y_min;
u32 btn_cnt;
u32 sp_btn_cnt;
u8  has_sp;
+   u8  max_fingers;
 };
 
 static int u1_read_write_register(struct hid_device *hdev, u32 address,
@@ -319,8 +325,10 @@ static int u1_init(struct hid_device *hdev, struct u1_dev 
*pri_data)
 
pri_data->x_max =
(pri_data->resolution << 2) * (pri_data->sen_line_num_x - 1);
+   pri_data->x_min = 1;
pri_data->y_max =
(pri_data->resolution << 2) * (pri_data->sen_line_num_y - 1);
+   pri_data->y_min = 1;
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PAD_BTN,
&pri_data->btn_info, 0, true);
@@ -328,6 +336,12 @@ static int u1_init(struct hid_device *hdev, struct u1_dev 
*pri_data)
dev_err(&hdev->dev, "failed U1_PAD_BTN (%d)\n", ret);
goto exit;
}
+   if ((pri_data->btn_info & 0x0F) == (pri_data->btn_info & 0xF0) >> 4) {
+   pri_data->btn_cnt = (pri_data->btn_info & 0x0F);
+   } else {
+   /* Button pad */
+   pri_data->btn_cnt = 1;
+   }
 
pri_data->has_sp = 0;
/* Check StickPointer device */
@@ -355,7 +369,7 @@ static int u1_init(struct hid_device *hdev, struct u1_dev 
*pri_data)
}
pri_data->has_sp = 1;
}
-
+   pri_data->max_fingers = 5;
 exit:
return ret;
 }
@@ -383,8 +397,10 @@ static int alps_input_configured(struct hid_device *hdev, 
struct hid_input *hi)
goto exit;
 
__set_bit(EV_ABS, input->evbit);
-   input_set_abs_params(input, ABS_MT_POSITION_X, 1, data->x_max, 0, 0);
-   input_set_abs_params(input, ABS_MT_POSITION_Y, 1, data->y_max, 0, 0);
+   input_set_abs_params(input, ABS_MT_POSITION_X,
+   data->x_min, data->x_max, 0, 0);
+   input_set_abs_params(input, ABS_MT_POSITION_Y,
+   data->y_min, data->y_max, 0, 0);
 
if (data->x_active_len_mm && data->y_active_len_mm) {
res_x = (data->x_max - 1) / data->x_active_len_mm;
@@ -396,26 +412,21 @@ static int alps_input_configured(struct hid_device *hdev, 
struct hid_input *hi)
 
input_set_abs_params(input, ABS_MT_PRESSURE, 0, 64, 0, 0);
 
-   input_mt_init_slots(input, MAX_TOUCHES, INPUT_MT_POINTER);
+   input_mt_init_slots(input, data->max_fingers, INPUT_MT_POINTER);
 
__set_bit(EV_KEY, input->evbit);
-   if ((data->btn_info & 0x0F) == (data->btn_info & 0xF0) >> 4) {
-   data->btn_cnt = (data->btn_info & 0x0F);
-   } else {
-   /* Button pad */
-   data->btn_cnt = 1;
+
+   if (data->btn_cnt == 1)
__set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
-   }
 
for (i = 0; i < data->btn_cnt; i++)
__set_bit(BTN_LEFT + i, input->keybit);
 
-
/* Stick device initialization */
if (data->has_sp) {
input2 = input_allocate_device();
if (!input2) {
-   ret = -ENOMEM;
+   input_free_device(input2);
goto exit;
}
 
@@ -439,8 +450,7 @@ static int alps_input_configured(struct hid_device *hdev, 
struct hid_input *hi)
__set_bit(INPUT_PROP_POINTER, input2->propbit);
__set_bit(INPUT_PROP_POINTING_STICK, input2->propbit);
 
-   ret = input_register_device(data->input2);
-   if (ret) {
+   if (input_register_device(data->input2)) {
input_free_device(input2);
goto exit;
}
-- 
2.11.0



[PATCH 6/7] Add new U1 device ID for supporting it

2017-09-11 Thread Masaki Ota
From: Masaki Ota 
-Add new U1 device Product ID
-This device is used on HP Elite book x360 series

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 3 +++
 drivers/hid/hid-core.c | 1 +
 drivers/hid/hid-ids.h  | 1 +
 3 files changed, 5 insertions(+)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index 0a6c54fb47c8..e7ae3a7b8e7d 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -771,6 +771,7 @@ static int alps_probe(struct hid_device *hdev, const struct 
hid_device_id *id)
data->dev_type = T4;
break;
case HID_DEVICE_ID_ALPS_U1_DUAL:
+   case HID_DEVICE_ID_ALPS_U1:
data->dev_type = U1;
break;
default:
@@ -795,6 +796,8 @@ static const struct hid_device_id alps_id[] = {
{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1_DUAL) },
{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
+   USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1) },
+   { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_BTNLESS) },
{ }
 };
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 9c3cb2e467e9..779e26cb3ba9 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1775,6 +1775,7 @@ static const struct hid_device_id 
hid_have_special_driver[] = {
{ HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
{ HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0xf705) },
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1_DUAL) },
+   { HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1) },
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_BTNLESS) 
},
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) 
},
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGICMOUSE) },
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 0b9726d321ee..2b50d12b993e 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -75,6 +75,7 @@
 
 #define USB_VENDOR_ID_ALPS_JP  0x044E
 #define HID_DEVICE_ID_ALPS_U1_DUAL 0x120B
+#define HID_DEVICE_ID_ALPS_U1  0x1215
 #define HID_DEVICE_ID_ALPS_T4_BTNLESS  0x120C
 
 #define USB_VENDOR_ID_AMI  0x046b
-- 
2.11.0



[PATCH 5/7] Support new Alps device that name is T4

2017-09-11 Thread Masaki Ota
From: Masaki Ota 
-Add T4 device code and Product ID
-This device is used on HP EliteBook 1000 series and Zbook Stduio

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 343 ++---
 drivers/hid/hid-core.c |   3 +-
 drivers/hid/hid-ids.h  |   1 +
 3 files changed, 326 insertions(+), 21 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index 4c323b58e009..0a6c54fb47c8 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -52,8 +52,30 @@
 #define ADDRESS_U1_PAD_BTN 0x00800052
 #define ADDRESS_U1_SP_BTN  0x0080009F
 
+#define T4_INPUT_REPORT_LENsizeof(struct t4_input_report)
+#define T4_FEATURE_REPORT_LEN  T4_INPUT_REPORT_LEN
+#define T4_FEATURE_REPORT_ID   7
+#define T4_CMD_REGISTER_READ   0x08
+#define T4_CMD_REGISTER_WRITE  0x07
+
+#define T4_ADDRESS_BASE0xC2C0
+#define PRM_SYS_CONFIG_1   (T4_ADDRESS_BASE + 0x0002)
+#define T4_PRM_FEED_CONFIG_1   (T4_ADDRESS_BASE + 0x0004)
+#define T4_PRM_FEED_CONFIG_4   (T4_ADDRESS_BASE + 0x001A)
+#define T4_PRM_ID_CONFIG_3 (T4_ADDRESS_BASE + 0x00B0)
+
+
+#define T4_FEEDCFG4_ADVANCED_ABS_ENABLE0x01
+#define T4_I2C_ABS 0x78
+
+#define T4_COUNT_PER_ELECTRODE 256
 #define MAX_TOUCHES5
 
+enum dev_num {
+   U1,
+   T4,
+   UNKNOWN,
+};
 /**
  * struct u1_data
  *
@@ -74,11 +96,12 @@
  * @btn_cnt: number of buttons
  * @sp_btn_cnt: number of stick buttons
  */
-struct u1_dev {
+struct alps_dev {
struct input_dev *input;
struct input_dev *input2;
struct hid_device *hdev;
 
+   enum dev_num dev_type;
u8  max_fingers;
u8  has_sp;
u8  sp_btn_info;
@@ -92,6 +115,145 @@ struct u1_dev {
u32 sp_btn_cnt;
 };
 
+struct t4_contact_data {
+   u8  palm;
+   u8  x_lo;
+   u8  x_hi;
+   u8  y_lo;
+   u8  y_hi;
+};
+
+struct t4_input_report {
+   u8  reportID;
+   u8  numContacts;
+   struct t4_contact_data contact[5];
+   u8  button;
+   u8  track[5];
+   u8  zx[5], zy[5];
+   u8  palmTime[5];
+   u8  kilroy;
+   u16 timeStamp;
+};
+
+static u16 t4_calc_check_sum(u8 *buffer,
+   unsigned long offset, unsigned long length)
+{
+   u16 sum1 = 0xFF, sum2 = 0xFF;
+   unsigned long i = 0;
+
+   if (offset + length >= 50)
+   return 0;
+
+   while (length > 0) {
+   u32 tlen = length > 20 ? 20 : length;
+
+   length -= tlen;
+
+   do {
+   sum1 += buffer[offset + i];
+   sum2 += sum1;
+   i++;
+   } while (--tlen > 0);
+
+   sum1 = (sum1 & 0xFF) + (sum1 >> 8);
+   sum2 = (sum2 & 0xFF) + (sum2 >> 8);
+   }
+
+   sum1 = (sum1 & 0xFF) + (sum1 >> 8);
+   sum2 = (sum2 & 0xFF) + (sum2 >> 8);
+
+   return(sum2 << 8 | sum1);
+}
+
+static int t4_read_write_register(struct hid_device *hdev, u32 address,
+   u8 *read_val, u8 write_val, bool read_flag)
+{
+   int ret;
+   u16 check_sum;
+   u8 *input;
+   u8 *readbuf;
+
+   input = kzalloc(T4_FEATURE_REPORT_LEN, GFP_KERNEL);
+   if (!input)
+   return -ENOMEM;
+
+   input[0] = T4_FEATURE_REPORT_ID;
+   if (read_flag) {
+   input[1] = T4_CMD_REGISTER_READ;
+   input[8] = 0x00;
+   } else {
+   input[1] = T4_CMD_REGISTER_WRITE;
+   input[8] = write_val;
+   }
+   put_unaligned_le32(address, input + 2);
+   input[6] = 1;
+   input[7] = 0;
+
+   /* Calculate the checksum */
+   check_sum = t4_calc_check_sum(input, 1, 8);
+   input[9] = (u8)check_sum;
+   input[10] = (u8)(check_sum >> 8);
+   input[11] = 0;
+
+   ret = hid_hw_raw_request(hdev, T4_FEATURE_REPORT_ID, input,
+   T4_FEATURE_REPORT_LEN,
+   HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
+
+   if (ret < 0) {
+   dev_err(&hdev->dev, "failed to read command (%d)\n", ret);
+   goto exit;
+   }
+
+   if (read_flag) {
+   readbuf = kzalloc(T4_FEATURE_REPORT_LEN, GFP_KERNEL);
+   if (!readbuf) {
+   ret = -ENOMEM;
+   goto exit;
+   }
+
+   ret = hid_hw_raw_request(hdev, T4_FEATURE_REPORT_ID, readbuf,
+   T4_FEATURE_REPORT_LEN,
+   HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
+   if (ret < 0) {
+   dev_err(&hdev->dev, "failed read register (%d)\n", ret);
+   kfree(readbuf);
+

[PATCH] Support new Alps HID Touchpad device

2017-09-11 Thread Masaki Ota
Hi, Jiri, Benjamin,

This is the patch for support new Alps HID Touchpad device.
I submitted these patch before, but it was not completed.
So I separate the patch to some parts and release it again. 

Best Regards,
Masaki Ota



[PATCH] Fix Alps Touchpad two finger scroll does not work on right side

2017-07-20 Thread Masaki Ota
From: Masaki Ota 

Fixed the issue that two finger scroll does not work correctly
on V8 protocol. The cause is that V8 protocol X-coordinate decode
is wrong at SS4 PLUS device. I added SS4 PLUS X decode definition.

Signed-off-by: Masaki Ota 
Tested-by: Takashi Iwai 
---
 drivers/input/mouse/alps.c | 41 +++--
 drivers/input/mouse/alps.h |  8 
 2 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index f210e19ddba6..2627c724bb7c 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -1210,14 +1210,24 @@ static int alps_decode_ss4_v2(struct alps_fields *f,
 
case SS4_PACKET_ID_TWO:
if (priv->flags & ALPS_BUTTONPAD) {
-   f->mt[0].x = SS4_BTL_MF_X_V2(p, 0);
+   if (IS_SS4PLUS_DEV(priv->dev_id)) {
+   f->mt[0].x = SS4_PLUS_BTL_MF_X_V2(p, 0);
+   f->mt[1].x = SS4_PLUS_BTL_MF_X_V2(p, 1);
+   } else {
+   f->mt[0].x = SS4_BTL_MF_X_V2(p, 0);
+   f->mt[1].x = SS4_BTL_MF_X_V2(p, 1);
+   }
f->mt[0].y = SS4_BTL_MF_Y_V2(p, 0);
-   f->mt[1].x = SS4_BTL_MF_X_V2(p, 1);
f->mt[1].y = SS4_BTL_MF_Y_V2(p, 1);
} else {
-   f->mt[0].x = SS4_STD_MF_X_V2(p, 0);
+   if (IS_SS4PLUS_DEV(priv->dev_id)) {
+   f->mt[0].x = SS4_PLUS_STD_MF_X_V2(p, 0);
+   f->mt[1].x = SS4_PLUS_STD_MF_X_V2(p, 1);
+   } else {
+   f->mt[0].x = SS4_STD_MF_X_V2(p, 0);
+   f->mt[1].x = SS4_STD_MF_X_V2(p, 1);
+   }
f->mt[0].y = SS4_STD_MF_Y_V2(p, 0);
-   f->mt[1].x = SS4_STD_MF_X_V2(p, 1);
f->mt[1].y = SS4_STD_MF_Y_V2(p, 1);
}
f->pressure = SS4_MF_Z_V2(p, 0) ? 0x30 : 0;
@@ -1234,16 +1244,27 @@ static int alps_decode_ss4_v2(struct alps_fields *f,
 
case SS4_PACKET_ID_MULTI:
if (priv->flags & ALPS_BUTTONPAD) {
-   f->mt[2].x = SS4_BTL_MF_X_V2(p, 0);
+   if (IS_SS4PLUS_DEV(priv->dev_id)) {
+   f->mt[0].x = SS4_PLUS_BTL_MF_X_V2(p, 0);
+   f->mt[1].x = SS4_PLUS_BTL_MF_X_V2(p, 1);
+   } else {
+   f->mt[2].x = SS4_BTL_MF_X_V2(p, 0);
+   f->mt[3].x = SS4_BTL_MF_X_V2(p, 1);
+   }
+
f->mt[2].y = SS4_BTL_MF_Y_V2(p, 0);
-   f->mt[3].x = SS4_BTL_MF_X_V2(p, 1);
f->mt[3].y = SS4_BTL_MF_Y_V2(p, 1);
no_data_x = SS4_MFPACKET_NO_AX_BL;
no_data_y = SS4_MFPACKET_NO_AY_BL;
} else {
-   f->mt[2].x = SS4_STD_MF_X_V2(p, 0);
+   if (IS_SS4PLUS_DEV(priv->dev_id)) {
+   f->mt[0].x = SS4_PLUS_STD_MF_X_V2(p, 0);
+   f->mt[1].x = SS4_PLUS_STD_MF_X_V2(p, 1);
+   } else {
+   f->mt[0].x = SS4_STD_MF_X_V2(p, 0);
+   f->mt[1].x = SS4_STD_MF_X_V2(p, 1);
+   }
f->mt[2].y = SS4_STD_MF_Y_V2(p, 0);
-   f->mt[3].x = SS4_STD_MF_X_V2(p, 1);
f->mt[3].y = SS4_STD_MF_Y_V2(p, 1);
no_data_x = SS4_MFPACKET_NO_AX;
no_data_y = SS4_MFPACKET_NO_AY;
@@ -2536,8 +2557,8 @@ static int alps_set_defaults_ss4_v2(struct psmouse 
*psmouse,
 
memset(otp, 0, sizeof(otp));
 
-   if (alps_get_otp_values_ss4_v2(psmouse, 0, &otp[0][0]) ||
-   alps_get_otp_values_ss4_v2(psmouse, 1, &otp[1][0]))
+   if (alps_get_otp_values_ss4_v2(psmouse, 1, &otp[1][0]) ||
+   alps_get_otp_values_ss4_v2(psmouse, 0, &otp[0][0]))
return -1;
 
alps_update_device_area_ss4_v2(otp, priv);
diff --git a/drivers/input/mouse/alps.h b/drivers/input/mouse/alps.h
index 4334f2805d93..75542199edda 100644
--- a/drivers/input/mouse/alps.h
+++ b/drivers/input/mouse/alps.h
@@ -99,6 +99,10 @@ enum SS4_PACKET_ID {
 ((_b[1 + _i * 3]  << 5) & 0x1F00)  \
)
 
+#define SS4_PLUS_STD_MF_X_V2(_b, _i) (((_b[0 + (_i) * 3] << 4) & 0x0070) | \
+((_b[1 + (_i) * 3]  << 4) & 0x0F80)\
+ 

RE: [REGRESSION] Touchpad failure after e7348396c6d5 ("Input: ALPS - fix V8+ protocol handling (73 03 28)")

2017-07-20 Thread Masaki Ota
Hi, 

Some user reported that this issue happened from kernel 4.10.7.
Because the below patch was applied on it.
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/commit/?id=0186e6a4e501d39f5f90dd7e5887bc668aef06c4

So, I thought the cause of this issue is this patch.
Original code meaning is Kernel 4.10.6, it seems not to have this issue.

Best Regards,
Masaki Ota
-Original Message-
From: Takashi Iwai [mailto:ti...@suse.de] 
Sent: Thursday, July 20, 2017 6:35 PM
To: 太田 真喜 Masaki Ota 
Cc: Paul Donohue ; Laura Abbott ; 
Dmitry Torokhov ; Pali Rohar ; 
Nick Fletcher ; linux-in...@vger.kernel.org; 
linux-kernel@vger.kernel.org; scott.s.l...@gmail.com
Subject: Re: [REGRESSION] Touchpad failure after e7348396c6d5 ("Input: ALPS - 
fix V8+ protocol handling (73 03 28)")

On Thu, 20 Jul 2017 11:20:20 +0200,
Masaki Ota wrote:
> 
> Hi, Takashi-san,
> 
> That's great! 
> 
> Actually, SS4 PLUS device is a little different from SS4 device.
> I added SS4 PLUS code as below.
> Could you try it?

Yes, it works as expected.  Feel free to take:
  Tested-by: Takashi Iwai 

> And I still wonder why this issue does not happen on original code though X 
> value is so large.

Which original code are you referring to?
The bug manifests itself only for decoding multi-touch events.


thanks,

Takashi

> 
> --- a/drivers/input/mouse/alps.c
> +++ b/drivers/input/mouse/alps.c
> @@ -1210,14 +1210,24 @@ static int alps_decode_ss4_v2(struct 
> alps_fields *f,
>  
>   case SS4_PACKET_ID_TWO:
>   if (priv->flags & ALPS_BUTTONPAD) {
> - f->mt[0].x = SS4_BTL_MF_X_V2(p, 0);
> + if (IS_SS4PLUS_DEV(priv->dev_id)) {
> + f->mt[0].x = SS4_PLUS_BTL_MF_X_V2(p, 0);
> + f->mt[1].x = SS4_PLUS_BTL_MF_X_V2(p, 1);
> + } else {
> + f->mt[0].x = SS4_BTL_MF_X_V2(p, 0);
> + f->mt[1].x = SS4_BTL_MF_X_V2(p, 1);
> + }
>   f->mt[0].y = SS4_BTL_MF_Y_V2(p, 0);
> - f->mt[1].x = SS4_BTL_MF_X_V2(p, 1);
>   f->mt[1].y = SS4_BTL_MF_Y_V2(p, 1);
>   } else {
> - f->mt[0].x = SS4_STD_MF_X_V2(p, 0);
> + if (IS_SS4PLUS_DEV(priv->dev_id)) {
> + f->mt[0].x = SS4_PLUS_STD_MF_X_V2(p, 0);
> + f->mt[1].x = SS4_PLUS_STD_MF_X_V2(p, 1);
> + } else {
> + f->mt[0].x = SS4_STD_MF_X_V2(p, 0);
> + f->mt[1].x = SS4_STD_MF_X_V2(p, 1);
> + }
>   f->mt[0].y = SS4_STD_MF_Y_V2(p, 0);
> - f->mt[1].x = SS4_STD_MF_X_V2(p, 1);
>   f->mt[1].y = SS4_STD_MF_Y_V2(p, 1);
>   }
>   f->pressure = SS4_MF_Z_V2(p, 0) ? 0x30 : 0; @@ -1234,16 
> +1244,27 @@ 
> static int alps_decode_ss4_v2(struct alps_fields *f,
>  
>   case SS4_PACKET_ID_MULTI:
>   if (priv->flags & ALPS_BUTTONPAD) {
> - f->mt[2].x = SS4_BTL_MF_X_V2(p, 0);
> + if (IS_SS4PLUS_DEV(priv->dev_id)) {
> + f->mt[0].x = SS4_PLUS_BTL_MF_X_V2(p, 0);
> + f->mt[1].x = SS4_PLUS_BTL_MF_X_V2(p, 1);
> + } else {
> + f->mt[2].x = SS4_BTL_MF_X_V2(p, 0);
> + f->mt[3].x = SS4_BTL_MF_X_V2(p, 1);
> + }
> +
>   f->mt[2].y = SS4_BTL_MF_Y_V2(p, 0);
> - f->mt[3].x = SS4_BTL_MF_X_V2(p, 1);
>   f->mt[3].y = SS4_BTL_MF_Y_V2(p, 1);
>   no_data_x = SS4_MFPACKET_NO_AX_BL;
>   no_data_y = SS4_MFPACKET_NO_AY_BL;
>   } else {
> - f->mt[2].x = SS4_STD_MF_X_V2(p, 0);
> + if (IS_SS4PLUS_DEV(priv->dev_id)) {
> + f->mt[0].x = SS4_PLUS_STD_MF_X_V2(p, 0);
> + f->mt[1].x = SS4_PLUS_STD_MF_X_V2(p, 1);
> + } else {
> + f->mt[0].x = SS4_STD_MF_X_V2(p, 0);
> + f->mt[1].x = SS4_STD_MF_X_V2(p, 1);
> + }
>   f->mt[2].y = SS4_STD_MF_Y_V2(p, 0);
> - f->mt[3].x = SS4_STD_MF_X_V2(p, 1);
>   f->mt[3].y = SS4_STD_MF_Y_V2(p, 1);
>   no_data_x = SS4_MFPACKET_NO_AX;
>  

RE: [REGRESSION] Touchpad failure after e7348396c6d5 ("Input: ALPS - fix V8+ protocol handling (73 03 28)")

2017-07-20 Thread Masaki Ota
12,10 @@ enum SS4_PACKET_ID {
 ((_b[0 + (_i) * 3] >> 3) & 0x0010) \
)
 
+#define SS4_PLUS_BTL_MF_X_V2(_b, _i) (SS4_PLUS_STD_MF_X_V2(_b, _i) |   \
+((_b[0 + (_i) * 3] >> 4) & 0x0008) \
+       )
+
 #define SS4_BTL_MF_Y_V2(_b, _i)(SS4_STD_MF_Y_V2(_b, _i) | \
 ((_b[0 + (_i) * 3] >> 3) & 0x0008) \
)
--

Best Regards,
Masaki Ota
-Original Message-
From: Takashi Iwai [mailto:ti...@suse.de] 
Sent: Wednesday, July 19, 2017 5:57 PM
To: Paul Donohue 
Cc: Laura Abbott ; 太田 真喜 Masaki Ota 
; Dmitry Torokhov ; Pali 
Rohar ; Nick Fletcher ; 
linux-in...@vger.kernel.org; linux-kernel@vger.kernel.org; 
scott.s.l...@gmail.com
Subject: Re: [REGRESSION] Touchpad failure after e7348396c6d5 ("Input: ALPS - 
fix V8+ protocol handling (73 03 28)")

On Wed, 12 Jul 2017 18:28:41 +0200,
Paul Donohue wrote:
> 
> On Wed, Jul 12, 2017 at 09:16:43AM +0200, Takashi Iwai wrote:
> > On Tue, 11 Jul 2017 21:58:21 +0200,
> > Paul Donohue wrote:
> > > 
> > > On Tue, Jul 11, 2017 at 05:50:07PM +0200, Takashi Iwai wrote:
> > > > Hi, just joining to the party in the middle, as I'm also facing 
> > > > the same problem on Dell E7270 laptop.  Has this issue already 
> > > > been addressed?
> > > > 
> > > > If not, the following was my result:
> > > > 
> > > > - the first patch slowed the pointer movement a lot, it's even slower
> > > >   than the old kernel (e.g. 4.4.x).
> > > >   The two finger scroll works fine on all touchpad area now.
> > > > 
> > > > - the second patch made the pointer movement even faster than now (as
> > > >   I feel, not quite sure).  The two finger scroll doesn't work at the
> > > >   right side of the touchpad.
> > > > 
> > > > 
> > > > The kernel output from the first patch is below:
> > > >   psmouse serio1: alps: test1 pitch 37x37 num-electrodes 8x7 
> > > > physical size 25x22mm res 69x69 max 1792x1536
> > > > 
> > > > Let me know if you have any further test.
> > > > 
> > > > 
> > > > thanks,
> > > > 
> > > > Takashi
> > > 
> > > Do you have the kernel output from the second patch?
> > 
> > Here it is:
> > 
> > psmouse serio1: alps: test2 pitch 50x54 num-electrodes 20x11 
> > physical size 95x54mm res 25x23 max 2432x1280
> 
> Thanks!
> 
> Wow, this is weird ... Values that cause scrolling issues for you work fine 
> for me.
> 
> It looks like the priv->x_max value that is causing your problem, but perhaps 
> you can confirm this with another test:
> Revert the patches above, then just before the 'return' at the end of 
> alps_update_device_area_ss4_v2() add the following line:
> priv->x_max = 1792;
> I suspect this line will make two-finger scrolling work again.
> 
> It might also help if you could experiment with other x_max values.  2432 is 
> the correct value that causes problems for you..  Does a small value like 500 
> or a large value like 5000 change the behavior?
> 
> Another test you can try is to add a print statement in the 'case 
> SS4_PACKET_ID_TWO' section of alps_decode_ss4_v2() and print out the 
> f->mt[0].x and f->mt[1].x values.  With x_max set to 2432, what range of x 
> values does this print when scrolling works, and what range of values are 
> printed when scrolling doesn't work?

Sorry for the late reply.

I checked your suggestion, and noticed that actually x_max is a red herring.  
Then I started looking at the output of evtest (should have done from the 
beginning!), and the problem became obvious: the reported X values for MT with 
finger > 1 are doubled, e.g. it reports
4800 instead of 2400.  The MT_Y coordinate looks OK, so it's only about MT_X.  
And finger=1 reports correctly.

After reading the code, I ended up the patch like below.  This seems working 
through a quick test.  Could anyone check the patch to see whether it works / 
breaks anything?

The evtest showed that the MT_X for finger 3 and 4 are also bogus, and the 
patch should address it, too.

My only concern so far is whether correcting this globally is right, or it's 
specific to some certain models.  This needs the confirmation from ALPS 
people...


thanks,

Takashi


--- a/drivers/input/mouse/alps.h
+++ b/drivers/input/mouse/alps.h
@@ -96,8 +96,8 @@ enum SS4_PACKET_ID {
 
 #define SS4_BTN_V2(_b) ((_b[0] >> 5) & SS4_MASK_NORMAL_BUTTONS)
 
-#define SS4_S

[PATCH] Support PTP Stick and Touchpad device

2017-06-15 Thread Masaki Ota
From: Masaki Ota 
- Support PTP Stick and Touchpad device.
- This Touchpad is Precision Touchpad(PTP),
 and Stick Pointer data is the same as Mouse.
- Stick Pointer works as Mouse.

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-ids.h|  2 ++
 drivers/hid/hid-multitouch.c | 23 +--
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 8ca1e8ce0af2..d36d4ac508f6 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -75,6 +75,8 @@
 
 #define USB_VENDOR_ID_ALPS_JP  0x044E
 #define HID_DEVICE_ID_ALPS_U1_DUAL 0x120B
+#define HID_DEVICE_ID_ALPS_U1_DUAL_PTP 0x121F
+#define HID_DEVICE_ID_ALPS_U1_DUAL_3BTN_PTP0x1220
 
 #define USB_VENDOR_ID_AMI  0x046b
 #define USB_DEVICE_ID_AMI_VIRT_KEYBOARD_AND_MOUSE  0xff10
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
index 24d5b6deb571..ba9d9020f958 100644
--- a/drivers/hid/hid-multitouch.c
+++ b/drivers/hid/hid-multitouch.c
@@ -148,6 +148,7 @@ static void mt_post_parse(struct mt_device *td);
 /* reserved0x0011 */
 #define MT_CLS_WIN_8   0x0012
 #define MT_CLS_EXPORT_ALL_INPUTS   0x0013
+#define MT_CLS_WIN_8_DUAL  0x0014
 
 /* vendor specific classes */
 #define MT_CLS_3M  0x0101
@@ -217,6 +218,12 @@ static struct mt_class mt_classes[] = {
.quirks = MT_QUIRK_ALWAYS_VALID |
MT_QUIRK_CONTACT_CNT_ACCURATE,
.export_all_inputs = true },
+   { .name = MT_CLS_WIN_8_DUAL,
+   .quirks = MT_QUIRK_ALWAYS_VALID |
+   MT_QUIRK_IGNORE_DUPLICATES |
+   MT_QUIRK_HOVERING |
+   MT_QUIRK_CONTACT_CNT_ACCURATE,
+   .export_all_inputs = true },
 
/*
 * vendor specific classes
@@ -512,7 +519,8 @@ static int mt_touch_input_mapping(struct hid_device *hdev, 
struct hid_input *hi,
mt_store_field(usage, td, hi);
return 1;
case HID_DG_CONFIDENCE:
-   if (cls->name == MT_CLS_WIN_8 &&
+   if ((cls->name == MT_CLS_WIN_8 ||
+   cls->name == MT_CLS_WIN_8_DUAL) &&
field->application == HID_DG_TOUCHPAD)
cls->quirks |= MT_QUIRK_CONFIDENCE;
mt_store_field(usage, td, hi);
@@ -579,7 +587,8 @@ static int mt_touch_input_mapping(struct hid_device *hdev, 
struct hid_input *hi,
 * MS PTP spec says that external buttons left and right have
 * usages 2 and 3.
 */
-   if (cls->name == MT_CLS_WIN_8 &&
+   if ((cls->name == MT_CLS_WIN_8 ||
+   cls->name == MT_CLS_WIN_8_DUAL) &&
field->application == HID_DG_TOUCHPAD &&
(usage->hid & HID_USAGE) > 1)
code--;
@@ -1290,6 +1299,16 @@ static const struct hid_device_id mt_devices[] = {
MT_USB_DEVICE(USB_VENDOR_ID_3M,
USB_DEVICE_ID_3M3266) },
 
+   /* Alps devices */
+   { .driver_data = MT_CLS_WIN_8_DUAL,
+   HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
+   USB_VENDOR_ID_ALPS_JP,
+   HID_DEVICE_ID_ALPS_U1_DUAL_PTP) },
+   { .driver_data = MT_CLS_WIN_8_DUAL,
+   HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
+   USB_VENDOR_ID_ALPS_JP,
+   HID_DEVICE_ID_ALPS_U1_DUAL_3BTN_PTP) },
+
/* Anton devices */
{ .driver_data = MT_CLS_EXPORT_ALL_INPUTS,
MT_USB_DEVICE(USB_VENDOR_ID_ANTON,
-- 
2.11.0



RE: [REGRESSION] Touchpad failure after e7348396c6d5 ("Input: ALPS - fix V8+ protocol handling (73 03 28)")

2017-06-14 Thread Masaki Ota
Hi, Paul, Dmitry,

About Laura's test result, it seems like this issue has to do with x_max, 
y_max, x_res, y_res.
This values are set as following code.
input_set_abs_params(dev1, ABS_MT_POSITION_X, 0, priv->x_max, 0, 0);
input_set_abs_params(dev1, ABS_MT_POSITION_Y, 0, priv->y_max, 0, 0);

input_abs_set_res(dev1, ABS_MT_POSITION_X, priv->x_res);
input_abs_set_res(dev1, ABS_MT_POSITION_Y, priv->y_res);

For testing this code, I assigned an abnormal value to x_max, y_max , and it 
seems to effect only cursor speed.
About x_res, y_res , there is no effect, even if I set an abnormal value.(need 
this code?)
I don't understand why these values have to do with this issue.

Can you guess the root cause of this issue?

Best Regards,
Masaki Ota
-Original Message-
From: Laura Abbott [mailto:labb...@redhat.com] 
Sent: Thursday, June 15, 2017 3:53 AM
To: 太田 真喜 Masaki Ota ; Paul Donohue 

Cc: Dmitry Torokhov ; Pali Rohar 
; Nick Fletcher ; 
linux-in...@vger.kernel.org; linux-kernel@vger.kernel.org; 
scott.s.l...@gmail.com
Subject: Re: [REGRESSION] Touchpad failure after e7348396c6d5 ("Input: ALPS - 
fix V8+ protocol handling (73 03 28)")

On 06/11/2017 10:25 PM, Masaki Ota wrote:
> Hi, Laura,
> 
> Could you try to check below modification?
> https://bugzilla.kernel.org/show_bug.cgi?id=195215#c10
> 
> This thread person said, the issue was fixed by this change.
> I guess it's a XY coordinate setting problem, though the code that before the 
> patch is applied also has a problem.
> 

With the previous patch plus the part you suggested:

"it appears as if this resolves all remaining touchpad issues.
Cursor movement works as expected, both on the left-hand and right-hand sides 
of the touchpad, and I did not see any issues with two-finger scrolling on 
either side of the touchpad. Behavior with this test build appeared to be 
identical to 4.10.5, the last "official" kernel release to work with my 
touchpad."

So it sounds like both parts together fix the issue.

Thanks,
Laura

> Best Regards,
> Masaki Ota
> -Original Message-
> From: Laura Abbott [mailto:labb...@redhat.com]
> Sent: Wednesday, June 07, 2017 1:59 AM
> To: Paul Donohue 
> Cc: 太田 真喜 Masaki Ota ; Dmitry Torokhov 
> ; Pali Rohar ; Nick 
> Fletcher ; linux-in...@vger.kernel.org; 
> linux-kernel@vger.kernel.org; scott.s.l...@gmail.com
> Subject: Re: [REGRESSION] Touchpad failure after e7348396c6d5 ("Input: 
> ALPS - fix V8+ protocol handling (73 03 28)")
> 
> On 06/02/2017 09:03 PM, Paul Donohue wrote:
>> This might be related to
>> https://bugzilla.kernel.org/show_bug.cgi?id=195215
>>
>> Could you have the user try this change? 
>> https://bugzilla.kernel.org/show_bug.cgi?id=195215#c12
>>
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=1447327#c13
> 
> "Cursor movement seems to work, but there are intermittent two-finger 
> scrolling issues on the right-hand side of the touchpad. There are no issues 
> with cursor movement or two-finger scrolling on the left-hand side of the 
> touchpad."
> 
>> On Fri, Jun 02, 2017 at 10:54:52AM -0700, Laura Abbott wrote:
>>> Hi,
>>>
>>> Fedora got a bug report
>>> https://bugzilla.redhat.com/show_bug.cgi?id=1447327
>>> of a touchpad failure on a Dell Latitude E7370. Testing showed that 
>>> the bad commit was
>>>
>>> commit e7348396c6d51b57c95c6646c390cd078e038e19
>>> Author: Masaki Ota 
>>> Date:   Fri Mar 17 14:10:57 2017 -0700
>>>
>>> Input: ALPS - fix V8+ protocol handling (73 03 28)
>>>     
>>> Devices identified as E7="73 03 28" use slightly modified version of V8
>>> protocol, with lower count per electrode, different offsets, and 
>>> different
>>> feature bits in OTP data.
>>> 
>>> Fixes: aeaa881f9b17 ("Input: ALPS - set DualPoint flag for 74 03 28 
>>> devices")
>>> Signed-off-by: Masaki Ota 
>>> Acked-by: Pali Rohar 
>>> Tested-by: Paul Donohue 
>>> Tested-by: Nick Fletcher 
>>> Cc: sta...@vger.kernel.org
>>> Signed-off-by: Dmitry Torokhov 
>>>
>>> I suspect this particular model needs special handling as well?
>>>
>>> Thanks,
>>> Laura
>>>
> 



[PATCH 1/1] Support PTP Stick and Touchpad device

2017-06-14 Thread Masaki Ota
>From Masaki Ota 
 Support PTP Stick and Touchpad device.
 This Touchpad is Precision Touchpad(PTP),
 and Stick Pointer data is the same as Mouse.
 So Stick Pointer works as Mouse.

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-ids.h|  2 ++
 drivers/hid/hid-multitouch.c | 24 ++--
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 8ca1e8ce0af2..d36d4ac508f6 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -75,6 +75,8 @@
 
 #define USB_VENDOR_ID_ALPS_JP  0x044E
 #define HID_DEVICE_ID_ALPS_U1_DUAL 0x120B
+#define HID_DEVICE_ID_ALPS_U1_DUAL_PTP 0x121F
+#define HID_DEVICE_ID_ALPS_U1_DUAL_3BTN_PTP0x1220
 
 #define USB_VENDOR_ID_AMI  0x046b
 #define USB_DEVICE_ID_AMI_VIRT_KEYBOARD_AND_MOUSE  0xff10
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
index 24d5b6deb571..4ffdda9d80da 100644
--- a/drivers/hid/hid-multitouch.c
+++ b/drivers/hid/hid-multitouch.c
@@ -161,6 +161,7 @@ static void mt_post_parse(struct mt_device *td);
 #define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109
 #define MT_CLS_LG  0x010a
 #define MT_CLS_VTL 0x0110
+#define MT_CLS_WIN_8_DUAL  0x0111
 
 #define MT_DEFAULT_MAXCONTACT  10
 #define MT_MAX_MAXCONTACT  250
@@ -278,6 +279,13 @@ static struct mt_class mt_classes[] = {
MT_QUIRK_CONTACT_CNT_ACCURATE |
MT_QUIRK_FORCE_GET_FEATURE,
},
+   { .name = MT_CLS_WIN_8_DUAL,
+   .quirks = MT_QUIRK_ALWAYS_VALID |
+   MT_QUIRK_IGNORE_DUPLICATES |
+   MT_QUIRK_HOVERING |
+   MT_QUIRK_CONTACT_CNT_ACCURATE,
+   .export_all_inputs = true
+   },
{ }
 };
 
@@ -512,7 +520,8 @@ static int mt_touch_input_mapping(struct hid_device *hdev, 
struct hid_input *hi,
mt_store_field(usage, td, hi);
return 1;
case HID_DG_CONFIDENCE:
-   if (cls->name == MT_CLS_WIN_8 &&
+   if ((cls->name == MT_CLS_WIN_8 ||
+   cls->name == MT_CLS_WIN_8_DUAL) &&
field->application == HID_DG_TOUCHPAD)
cls->quirks |= MT_QUIRK_CONFIDENCE;
mt_store_field(usage, td, hi);
@@ -579,7 +588,8 @@ static int mt_touch_input_mapping(struct hid_device *hdev, 
struct hid_input *hi,
 * MS PTP spec says that external buttons left and right have
 * usages 2 and 3.
 */
-   if (cls->name == MT_CLS_WIN_8 &&
+   if ((cls->name == MT_CLS_WIN_8 ||
+   cls->name == MT_CLS_WIN_8_DUAL) &&
field->application == HID_DG_TOUCHPAD &&
(usage->hid & HID_USAGE) > 1)
code--;
@@ -1290,6 +1300,16 @@ static const struct hid_device_id mt_devices[] = {
MT_USB_DEVICE(USB_VENDOR_ID_3M,
USB_DEVICE_ID_3M3266) },
 
+   /* Alps devices */
+   { .driver_data = MT_CLS_WIN_8_DUAL,
+   HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
+   USB_VENDOR_ID_ALPS_JP,
+   HID_DEVICE_ID_ALPS_U1_DUAL_PTP) },
+   { .driver_data = MT_CLS_WIN_8_DUAL,
+   HID_DEVICE(BUS_I2C, HID_GROUP_MULTITOUCH_WIN_8,
+   USB_VENDOR_ID_ALPS_JP,
+   HID_DEVICE_ID_ALPS_U1_DUAL_3BTN_PTP) },
+
/* Anton devices */
{ .driver_data = MT_CLS_EXPORT_ALL_INPUTS,
MT_USB_DEVICE(USB_VENDOR_ID_ANTON,
-- 
2.11.0



RE: [REGRESSION] Touchpad failure after e7348396c6d5 ("Input: ALPS - fix V8+ protocol handling (73 03 28)")

2017-06-11 Thread Masaki Ota
Hi, Laura,

Could you try to check below modification?
https://bugzilla.kernel.org/show_bug.cgi?id=195215#c10

This thread person said, the issue was fixed by this change.
I guess it's a XY coordinate setting problem, though the code that before the 
patch is applied also has a problem.

Best Regards,
Masaki Ota
-Original Message-
From: Laura Abbott [mailto:labb...@redhat.com] 
Sent: Wednesday, June 07, 2017 1:59 AM
To: Paul Donohue 
Cc: 太田 真喜 Masaki Ota ; Dmitry Torokhov 
; Pali Rohar ; Nick Fletcher 
; linux-in...@vger.kernel.org; 
linux-kernel@vger.kernel.org; scott.s.l...@gmail.com
Subject: Re: [REGRESSION] Touchpad failure after e7348396c6d5 ("Input: ALPS - 
fix V8+ protocol handling (73 03 28)")

On 06/02/2017 09:03 PM, Paul Donohue wrote:
> This might be related to 
> https://bugzilla.kernel.org/show_bug.cgi?id=195215
> 
> Could you have the user try this change? 
> https://bugzilla.kernel.org/show_bug.cgi?id=195215#c12
> 

https://bugzilla.redhat.com/show_bug.cgi?id=1447327#c13

"Cursor movement seems to work, but there are intermittent two-finger scrolling 
issues on the right-hand side of the touchpad. There are no issues with cursor 
movement or two-finger scrolling on the left-hand side of the touchpad."

> On Fri, Jun 02, 2017 at 10:54:52AM -0700, Laura Abbott wrote:
>> Hi,
>>
>> Fedora got a bug report 
>> https://bugzilla.redhat.com/show_bug.cgi?id=1447327
>> of a touchpad failure on a Dell Latitude E7370. Testing showed that 
>> the bad commit was
>>
>> commit e7348396c6d51b57c95c6646c390cd078e038e19
>> Author: Masaki Ota 
>> Date:   Fri Mar 17 14:10:57 2017 -0700
>>
>> Input: ALPS - fix V8+ protocol handling (73 03 28)
>> 
>> Devices identified as E7="73 03 28" use slightly modified version of V8
>> protocol, with lower count per electrode, different offsets, and 
>> different
>>     feature bits in OTP data.
>> 
>> Fixes: aeaa881f9b17 ("Input: ALPS - set DualPoint flag for 74 03 28 
>> devices")
>> Signed-off-by: Masaki Ota 
>> Acked-by: Pali Rohar 
>> Tested-by: Paul Donohue 
>> Tested-by: Nick Fletcher 
>> Cc: sta...@vger.kernel.org
>> Signed-off-by: Dmitry Torokhov 
>>
>> I suspect this particular model needs special handling as well?
>>
>> Thanks,
>> Laura
>>



[PATCH 4/4] Add Alps T4 USB Touchpad device ID

2017-04-27 Thread Masaki Ota
From: Masaki Ota 
-Support Alps T4 USB Touchpad device
-Laptop names that use this Touchpad:Elite x2 1012 G1 Tablet, HP Pro x2 612 G2

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 37 ++---
 drivers/hid/hid-core.c |  1 +
 drivers/hid/hid-ids.h  |  1 +
 3 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index e7ae3a7..d2d34c4 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -444,6 +444,7 @@ static int alps_raw_event(struct hid_device *hdev,
 
switch (hdev->product) {
case HID_PRODUCT_ID_T4_BTNLESS:
+   case HID_DEVICE_ID_ALPS_T4_USB:
ret = t4_raw_event(hdata, data, size);
break;
default:
@@ -598,13 +599,29 @@ static int T4_init(struct hid_device *hdev, struct 
alps_dev *pri_data)
int ret;
u8 tmp, sen_line_num_x, sen_line_num_y;
 
-   ret = t4_read_write_register(hdev, T4_PRM_ID_CONFIG_3, &tmp, 0, true);
-   if (ret < 0) {
-   dev_err(&hdev->dev, "failed T4_PRM_ID_CONFIG_3 (%d)\n", ret);
-   goto exit;
+   if (hdev->product == HID_DEVICE_ID_ALPS_T4_BTNLESS) {
+   ret = t4_read_write_register(hdev,
+   T4_PRM_ID_CONFIG_3, &tmp, 0, true);
+   if (ret < 0) {
+   dev_err(&hdev->dev,
+   "failed T4_PRM_ID_CONFIG_3 (%d)\n", ret);
+   goto exit;
+   }
+   sen_line_num_x =
+   16 + ((tmp & 0x0F) | (tmp & 0x08 ? 0xF0 : 0));
+   sen_line_num_y =
+   12 + (((tmp & 0xF0) >> 4) | (tmp & 0x80 ? 0xF0 : 0));
+   ret = t4_read_write_register(hdev,
+   PRM_SYS_CONFIG_1, &tmp, 0, true);
+   if (ret < 0) {
+   dev_err(&hdev->dev,
+   "failed PRM_SYS_CONFIG_1 (%d)\n", ret);
+   goto exit;
+   }
+   } else {
+   sen_line_num_x = 20;
+   sen_line_num_y = 12;
}
-   sen_line_num_x = 16 + ((tmp & 0x0F)  | (tmp & 0x08 ? 0xF0 : 0));
-   sen_line_num_y = 12 + (((tmp & 0xF0) >> 4)  | (tmp & 0x80 ? 0xF0 : 0));
 
pri_data->x_max = sen_line_num_x * T4_COUNT_PER_ELECTRODE;
pri_data->x_min = T4_COUNT_PER_ELECTRODE;
@@ -613,11 +630,6 @@ static int T4_init(struct hid_device *hdev, struct 
alps_dev *pri_data)
pri_data->x_active_len_mm = pri_data->y_active_len_mm = 0;
pri_data->btn_cnt = 1;
 
-   ret = t4_read_write_register(hdev, PRM_SYS_CONFIG_1, &tmp, 0, true);
-   if (ret < 0) {
-   dev_err(&hdev->dev, "failed PRM_SYS_CONFIG_1 (%d)\n", ret);
-   goto exit;
-   }
tmp |= 0x02;
ret = t4_read_write_register(hdev, PRM_SYS_CONFIG_1, NULL, tmp, false);
if (ret < 0) {
@@ -768,6 +780,7 @@ static int alps_probe(struct hid_device *hdev, const struct 
hid_device_id *id)
 
switch (hdev->product) {
case HID_DEVICE_ID_ALPS_T4_BTNLESS:
+   case HID_DEVICE_ID_ALPS_T4_USB:
data->dev_type = T4;
break;
case HID_DEVICE_ID_ALPS_U1_DUAL:
@@ -799,6 +812,8 @@ static const struct hid_device_id alps_id[] = {
USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1) },
{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_BTNLESS) },
+   { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
+   USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_USB) },
{ }
 };
 MODULE_DEVICE_TABLE(hid, alps_id);
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 779e26c..13ded46 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1777,6 +1777,7 @@ static const struct hid_device_id 
hid_have_special_driver[] = {
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1_DUAL) },
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1) },
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_BTNLESS) 
},
+   { HID_USB_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_USB) },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) 
},
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGICMOUSE) },
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 2b50d12..71c2a02 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -76,6 +76,7 @@
 #define USB_VENDOR_ID_ALPS_JP  0x044E
 #define HID_DEVICE_ID_ALPS_U1_DUAL 0x120B
 #define HID_DEVICE_ID_ALPS_U1  0x1215
+#define HID_DEVICE_ID_ALPS_T4_USB  0x1216
 #define HID_DEVICE_ID_ALPS_T4_BTNLESS  0x120C
 
 #define USB_VENDOR_ID_AMI  0x046b
-- 
2.7.4



[PATCH 1/4] Replace Alps U1 Touchpad code

2017-04-27 Thread Masaki Ota
>From Masaki Ota 

- Separate U1 device initialization from common initialization.

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 188 ++---
 1 file changed, 99 insertions(+), 89 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index ed9c0ea..984e452 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -55,24 +55,22 @@
 #define MAX_TOUCHES5
 
 /**
- * struct u1_data
+ * struct u1_dev
  *
  * @input: pointer to the kernel input device
  * @input2: pointer to the kernel input2 device
  * @hdev: pointer to the struct hid_device
  *
- * @dev_ctrl: device control parameter
  * @dev_type: device type
- * @sen_line_num_x: number of sensor line of X
- * @sen_line_num_y: number of sensor line of Y
- * @pitch_x: sensor pitch of X
- * @pitch_y: sensor pitch of Y
- * @resolution: resolution
- * @btn_info: button information
+ * @max_fingers: total number of fingers
+ * @has_sp: boolean of sp existense
+ * @sp_btn_info: button information
  * @x_active_len_mm: active area length of X (mm)
  * @y_active_len_mm: active area length of Y (mm)
  * @x_max: maximum x coordinate value
  * @y_max: maximum y coordinate value
+ * @x_min: minimum x coordinate value
+ * @y_min: minimum y coordinate value
  * @btn_cnt: number of buttons
  * @sp_btn_cnt: number of stick buttons
  */
@@ -81,19 +79,15 @@ struct u1_dev {
struct input_dev *input2;
struct hid_device *hdev;
 
-   u8  dev_ctrl;
-   u8  dev_type;
-   u8  sen_line_num_x;
-   u8  sen_line_num_y;
-   u8  pitch_x;
-   u8  pitch_y;
-   u8  resolution;
-   u8  btn_info;
+   u8  max_fingers;
+   u8  has_sp;
u8  sp_btn_info;
u32 x_active_len_mm;
u32 y_active_len_mm;
u32 x_max;
u32 y_max;
+   u32 x_min;
+   u32 y_min;
u32 btn_cnt;
u32 sp_btn_cnt;
 };
@@ -255,108 +249,149 @@ static int alps_post_resume(struct hid_device *hdev)
 }
 #endif /* CONFIG_PM */
 
-static int alps_input_configured(struct hid_device *hdev, struct hid_input *hi)
+static int u1_init(struct hid_device *hdev, struct u1_dev *pri_data)
 {
-   struct u1_dev *data = hid_get_drvdata(hdev);
-   struct input_dev *input = hi->input, *input2;
-   struct u1_dev devInfo;
int ret;
-   int res_x, res_y, i;
-
-   data->input = input;
-
-   hid_dbg(hdev, "Opening low level driver\n");
-   ret = hid_hw_open(hdev);
-   if (ret)
-   return ret;
-
-   /* Allow incoming hid reports */
-   hid_device_io_start(hdev);
+   u8 tmp, dev_ctrl, sen_line_num_x, sen_line_num_y;
+   u8 pitch_x, pitch_y, resolution;
 
/* Device initialization */
ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1,
-   &devInfo.dev_ctrl, 0, true);
+   &dev_ctrl, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_DEV_CTRL_1 (%d)\n", ret);
goto exit;
}
 
-   devInfo.dev_ctrl &= ~U1_DISABLE_DEV;
-   devInfo.dev_ctrl |= U1_TP_ABS_MODE;
+   dev_ctrl &= ~U1_DISABLE_DEV;
+   dev_ctrl |= U1_TP_ABS_MODE;
ret = u1_read_write_register(hdev, ADDRESS_U1_DEV_CTRL_1,
-   NULL, devInfo.dev_ctrl, false);
+   NULL, dev_ctrl, false);
if (ret < 0) {
dev_err(&hdev->dev, "failed to change TP mode (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_X,
-   &devInfo.sen_line_num_x, 0, true);
+   &sen_line_num_x, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_NUM_SENS_X (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_NUM_SENS_Y,
-   &devInfo.sen_line_num_y, 0, true);
+   &sen_line_num_y, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_NUM_SENS_Y (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_X,
-   &devInfo.pitch_x, 0, true);
+   &pitch_x, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PITCH_SENS_X (%d)\n", ret);
goto exit;
}
 
ret = u1_read_write_register(hdev, ADDRESS_U1_PITCH_SENS_Y,
-   &devInfo.pitch_y, 0, true);
+   &pitch_y, 0, true);
if (ret < 0) {
dev_err(&hdev->dev, "failed U1_PITCH_SENS_Y (%d)\n", ret);
goto exit

[PATCH 2/4] Support Alps HID I2C T4 Touchpad device

2017-04-27 Thread Masaki Ota
From: Masaki Ota 
-Support Alps HID I2C T4 Touchpad device.
-Laptop names that use this Touchpad:HP Zbook Studio, Elitebook Folio G1, 
Elitebook 1030 G1, Elitebook 1040 G3.

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 345 ++---
 drivers/hid/hid-core.c |   3 +-
 drivers/hid/hid-ids.h  |   1 +
 3 files changed, 327 insertions(+), 22 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index 984e452..0a6c54f 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -52,10 +52,32 @@
 #define ADDRESS_U1_PAD_BTN 0x00800052
 #define ADDRESS_U1_SP_BTN  0x0080009F
 
+#define T4_INPUT_REPORT_LENsizeof(struct t4_input_report)
+#define T4_FEATURE_REPORT_LEN  T4_INPUT_REPORT_LEN
+#define T4_FEATURE_REPORT_ID   7
+#define T4_CMD_REGISTER_READ   0x08
+#define T4_CMD_REGISTER_WRITE  0x07
+
+#define T4_ADDRESS_BASE0xC2C0
+#define PRM_SYS_CONFIG_1   (T4_ADDRESS_BASE + 0x0002)
+#define T4_PRM_FEED_CONFIG_1   (T4_ADDRESS_BASE + 0x0004)
+#define T4_PRM_FEED_CONFIG_4   (T4_ADDRESS_BASE + 0x001A)
+#define T4_PRM_ID_CONFIG_3 (T4_ADDRESS_BASE + 0x00B0)
+
+
+#define T4_FEEDCFG4_ADVANCED_ABS_ENABLE0x01
+#define T4_I2C_ABS 0x78
+
+#define T4_COUNT_PER_ELECTRODE 256
 #define MAX_TOUCHES5
 
+enum dev_num {
+   U1,
+   T4,
+   UNKNOWN,
+};
 /**
- * struct u1_dev
+ * struct u1_data
  *
  * @input: pointer to the kernel input device
  * @input2: pointer to the kernel input2 device
@@ -74,11 +96,12 @@
  * @btn_cnt: number of buttons
  * @sp_btn_cnt: number of stick buttons
  */
-struct u1_dev {
+struct alps_dev {
struct input_dev *input;
struct input_dev *input2;
struct hid_device *hdev;
 
+   enum dev_num dev_type;
u8  max_fingers;
u8  has_sp;
u8  sp_btn_info;
@@ -92,6 +115,145 @@ struct u1_dev {
u32 sp_btn_cnt;
 };
 
+struct t4_contact_data {
+   u8  palm;
+   u8  x_lo;
+   u8  x_hi;
+   u8  y_lo;
+   u8  y_hi;
+};
+
+struct t4_input_report {
+   u8  reportID;
+   u8  numContacts;
+   struct t4_contact_data contact[5];
+   u8  button;
+   u8  track[5];
+   u8  zx[5], zy[5];
+   u8  palmTime[5];
+   u8  kilroy;
+   u16 timeStamp;
+};
+
+static u16 t4_calc_check_sum(u8 *buffer,
+   unsigned long offset, unsigned long length)
+{
+   u16 sum1 = 0xFF, sum2 = 0xFF;
+   unsigned long i = 0;
+
+   if (offset + length >= 50)
+   return 0;
+
+   while (length > 0) {
+   u32 tlen = length > 20 ? 20 : length;
+
+   length -= tlen;
+
+   do {
+   sum1 += buffer[offset + i];
+   sum2 += sum1;
+   i++;
+   } while (--tlen > 0);
+
+   sum1 = (sum1 & 0xFF) + (sum1 >> 8);
+   sum2 = (sum2 & 0xFF) + (sum2 >> 8);
+   }
+
+   sum1 = (sum1 & 0xFF) + (sum1 >> 8);
+   sum2 = (sum2 & 0xFF) + (sum2 >> 8);
+
+   return(sum2 << 8 | sum1);
+}
+
+static int t4_read_write_register(struct hid_device *hdev, u32 address,
+   u8 *read_val, u8 write_val, bool read_flag)
+{
+   int ret;
+   u16 check_sum;
+   u8 *input;
+   u8 *readbuf;
+
+   input = kzalloc(T4_FEATURE_REPORT_LEN, GFP_KERNEL);
+   if (!input)
+   return -ENOMEM;
+
+   input[0] = T4_FEATURE_REPORT_ID;
+   if (read_flag) {
+   input[1] = T4_CMD_REGISTER_READ;
+   input[8] = 0x00;
+   } else {
+   input[1] = T4_CMD_REGISTER_WRITE;
+   input[8] = write_val;
+   }
+   put_unaligned_le32(address, input + 2);
+   input[6] = 1;
+   input[7] = 0;
+
+   /* Calculate the checksum */
+   check_sum = t4_calc_check_sum(input, 1, 8);
+   input[9] = (u8)check_sum;
+   input[10] = (u8)(check_sum >> 8);
+   input[11] = 0;
+
+   ret = hid_hw_raw_request(hdev, T4_FEATURE_REPORT_ID, input,
+   T4_FEATURE_REPORT_LEN,
+   HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
+
+   if (ret < 0) {
+   dev_err(&hdev->dev, "failed to read command (%d)\n", ret);
+   goto exit;
+   }
+
+   if (read_flag) {
+   readbuf = kzalloc(T4_FEATURE_REPORT_LEN, GFP_KERNEL);
+   if (!readbuf) {
+   ret = -ENOMEM;
+   goto exit;
+   }
+
+   ret = hid_hw_raw_request(hdev, T4_FEATURE_REPORT_ID, readbuf,
+   T4_FEATURE_REPORT_LEN,
+   HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
+   

[PATCH 0/4] Support new Alps HID I2C Touchpad device

2017-04-27 Thread Masaki Ota
Hi, Benjamin,

I modified the patch and added the code that supports Alps USB Touchpad as 
PATCH 4/4.

Best Regards,
Masaki Ota



[PATCH 3/4] Add new Alps U1 Touchpad device

2017-04-27 Thread Masaki Ota
From: Masaki Ota 
-Add new Alps U1 Touchpad device ID
-Laptop names that use this Touchpad:HP Elitebook x360 1030 G2

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 3 +++
 drivers/hid/hid-core.c | 1 +
 drivers/hid/hid-ids.h  | 1 +
 3 files changed, 5 insertions(+)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index 0a6c54f..e7ae3a7 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -771,6 +771,7 @@ static int alps_probe(struct hid_device *hdev, const struct 
hid_device_id *id)
data->dev_type = T4;
break;
case HID_DEVICE_ID_ALPS_U1_DUAL:
+   case HID_DEVICE_ID_ALPS_U1:
data->dev_type = U1;
break;
default:
@@ -795,6 +796,8 @@ static const struct hid_device_id alps_id[] = {
{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1_DUAL) },
{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
+   USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1) },
+   { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_BTNLESS) },
{ }
 };
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 9c3cb2e..779e26c 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1775,6 +1775,7 @@ static const struct hid_device_id 
hid_have_special_driver[] = {
{ HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
{ HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0xf705) },
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1_DUAL) },
+   { HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1) },
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_BTNLESS) 
},
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) 
},
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGICMOUSE) },
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 0b9726d..2b50d12 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -75,6 +75,7 @@
 
 #define USB_VENDOR_ID_ALPS_JP  0x044E
 #define HID_DEVICE_ID_ALPS_U1_DUAL 0x120B
+#define HID_DEVICE_ID_ALPS_U1  0x1215
 #define HID_DEVICE_ID_ALPS_T4_BTNLESS  0x120C
 
 #define USB_VENDOR_ID_AMI  0x046b
-- 
2.7.4



RE: [PATCH 1/2] Alps HID I2C T4 device support

2017-04-05 Thread Masaki Ota
Hi, Nikolaus,

Could you add below debug message to hid-alps.c, and check it?
This device is "HID_DEVICE_ID_ALPS_T4_BTNLESS"(0x120C).
If the device is UNKNOWN, this device does not work completely.
And if the system does not call here, it has nothing to do with my patch.

static int alps_probe()
{ ...
...
...
printk("> ALPS Debug Log: (%x) \n", hdev->product);
switch (hdev->product) {
case HID_DEVICE_ID_ALPS_T4_BTNLESS:
data->dev_type = T4;
break;
case HID_DEVICE_ID_ALPS_U1_DUAL:
data->dev_type = U1;
break;
default:
data->dev_type = UNKNOWN;
} 

Best Regards,
Masaki Ota
-Original Message-
From: Nikolaus Rath [mailto:nikol...@rath.org] 
Sent: Thursday, April 06, 2017 3:36 AM
To: 太田 真喜 Masaki Ota 
Cc: linux-kernel ; linux-in...@vger.kernel.org
Subject: Re: [PATCH 1/2] Alps HID I2C T4 device support

Hi Masaki,

Could you be a little more specific about what you need? I don't like executing 
scripts containing several instances of 'sudo rm -rf [something]'.

It seems that the script is meant to install debugging versions of some 
modules. Could you simply send me a patch against the official kernel that 
includes your debugging code? I'm perfectly able to compile it and load the 
modules on my own :-).

Thanks,
-Nikolaus

On Apr 05 2017, Masaki Ota  wrote:
> Hi, Nikolaus,
>
> If you have a time, please try below debug method.
>
> Download below file, copy it to your system and unpack.
> https://www.filesanywhere.com/fs/v.aspx?v=8b716a8e5b6773baa799
>
> Procedure ex:
> #cd Desktop/LinuxModDebug
> #sudo chmod 755 linux_kr_rebuild_tool_hid.sh #sudo 
> ./linux_kr_rebuild_tool_hid.sh /init linux-4.10.tar.gz #sudo 
> ./linux_kr_rebuild_tool_hid.sh /build DebugSrc
>
> After that Touchpad all features should work.
> If Touchpad does not work, something error appears on dmesg.
>
> Best Regards,
> Masaki Ota
> -Original Message-----
> From: Nikolaus Rath [mailto:nikol...@rath.org]
> Sent: Wednesday, April 05, 2017 9:01 AM
> To: 太田 真喜 Masaki Ota 
> Cc: linux-kernel ; 
> linux-in...@vger.kernel.org
> Subject: Re: [PATCH 1/2] Alps HID I2C T4 device support
>
> Hi Masaki,
>
> Well, I'd be pleasently surprised if every bug always came together 
> with an associated error message :-). No matter if there's a dmesg 
> entry or not, at the moment this patch will make life much worse for 
> at least some EliteBook owners.
>
> Is there anything I can do to help you debug this?
>
> Best,
> -Nikolaus
>
>
> On Apr 04 2017, Masaki Ota  wrote:
>> Hi, Nikolaus,
>>
>> Um, but demesg log does not have any error of this Touchpad.
>> It's a strange.
>>
>> Best Regards,
>> Masaki Ota
>> -Original Message-
>> From: Nikolaus Rath [mailto:nikol...@rath.org]
>> Sent: Wednesday, April 05, 2017 8:43 AM
>> To: 太田 真喜 Masaki Ota 
>> Cc: linux-kernel ; 
>> linux-in...@vger.kernel.org
>> Subject: Re: [PATCH 1/2] Alps HID I2C T4 device support
>>
>> Hi Masaki,
>>
>> Yes, without your patch the touchpad is mostly working - I just can't 
>> configure it.
>>
>> Please take a look at https://bugs.freedesktop.org/show_bug.cgi?id=100345.
>>
>> Best,
>> -Nikolaus
>>
>> On Apr 04 2017, Masaki Ota  wrote:
>>> Hi, Nikolaus,
>>>
>>> There is no 044E:120C device, but it looks like Alps Touchpad is detected 
>>> as PS/2 Touchpad.
>>>
>>> Actually, this Touchpad has two interfaces. One is I2C, the other is PS/2.
>>> Default setting is I2C, and if the system does not support I2C, Touchpad 
>>> works as PS/2.
>>>
>>> However, both of interface should work properly on Linux.
>>> I tested it on Ubuntu +4.10 kernel.
>>>
>>> If you don't apply my patch, does device work as I2C? (044E:120C
>>> appears?)
>>>
>>> Best Regards,
>>> Masaki Ota
>>> -Original Message-
>>> From: Nikolaus Rath [mailto:nikol...@rath.org]
>>> Sent: Wednesday, April 05, 2017 2:09 AM
>>> To: 太田 真喜 Masaki Ota 
>>> Cc: linux-kernel ; 
>>> linux-in...@vger.kernel.org
>>> Subject: Re: [PATCH 1/2] Alps HID I2C T4 device support
>>>
>>> Hi Masaki,
>>>
>>> Yes, I think I have a 044E:120C. Is there a way to find out for sure?
>>> It's not listed by e.g. lspci.
>>>
>>> The touchpad is definitely not reacting to anything. evemu-record does not 
>>> show any events either.
>>>
>>> I have attached the dme

RE: [PATCH 1/2] Alps HID I2C T4 device support

2017-04-05 Thread Masaki Ota
Hi, Nikolaus,

If you have a time, please try below debug method.

Download below file, copy it to your system and unpack.
https://www.filesanywhere.com/fs/v.aspx?v=8b716a8e5b6773baa799

Procedure ex:
#cd Desktop/LinuxModDebug
#sudo chmod 755 linux_kr_rebuild_tool_hid.sh
#sudo ./linux_kr_rebuild_tool_hid.sh /init linux-4.10.tar.gz
#sudo ./linux_kr_rebuild_tool_hid.sh /build DebugSrc

After that Touchpad all features should work.
If Touchpad does not work, something error appears on dmesg.

Best Regards,
Masaki Ota
-Original Message-
From: Nikolaus Rath [mailto:nikol...@rath.org] 
Sent: Wednesday, April 05, 2017 9:01 AM
To: 太田 真喜 Masaki Ota 
Cc: linux-kernel ; linux-in...@vger.kernel.org
Subject: Re: [PATCH 1/2] Alps HID I2C T4 device support

Hi Masaki,

Well, I'd be pleasently surprised if every bug always came together with an 
associated error message :-). No matter if there's a dmesg entry or not, at the 
moment this patch will make life much worse for at least some EliteBook owners.

Is there anything I can do to help you debug this?

Best,
-Nikolaus


On Apr 04 2017, Masaki Ota  wrote:
> Hi, Nikolaus,
>
> Um, but demesg log does not have any error of this Touchpad.
> It's a strange.
>
> Best Regards,
> Masaki Ota
> -Original Message-
> From: Nikolaus Rath [mailto:nikol...@rath.org]
> Sent: Wednesday, April 05, 2017 8:43 AM
> To: 太田 真喜 Masaki Ota 
> Cc: linux-kernel ; 
> linux-in...@vger.kernel.org
> Subject: Re: [PATCH 1/2] Alps HID I2C T4 device support
>
> Hi Masaki,
>
> Yes, without your patch the touchpad is mostly working - I just can't 
> configure it.
>
> Please take a look at https://bugs.freedesktop.org/show_bug.cgi?id=100345.
>
> Best,
> -Nikolaus
>
> On Apr 04 2017, Masaki Ota  wrote:
>> Hi, Nikolaus,
>>
>> There is no 044E:120C device, but it looks like Alps Touchpad is detected as 
>> PS/2 Touchpad.
>>
>> Actually, this Touchpad has two interfaces. One is I2C, the other is PS/2.
>> Default setting is I2C, and if the system does not support I2C, Touchpad 
>> works as PS/2.
>>
>> However, both of interface should work properly on Linux.
>> I tested it on Ubuntu +4.10 kernel.
>>
>> If you don't apply my patch, does device work as I2C? (044E:120C
>> appears?)
>>
>> Best Regards,
>> Masaki Ota
>> -Original Message-
>> From: Nikolaus Rath [mailto:nikol...@rath.org]
>> Sent: Wednesday, April 05, 2017 2:09 AM
>> To: 太田 真喜 Masaki Ota 
>> Cc: linux-kernel ; 
>> linux-in...@vger.kernel.org
>> Subject: Re: [PATCH 1/2] Alps HID I2C T4 device support
>>
>> Hi Masaki,
>>
>> Yes, I think I have a 044E:120C. Is there a way to find out for sure?
>> It's not listed by e.g. lspci.
>>
>> The touchpad is definitely not reacting to anything. evemu-record does not 
>> show any events either.
>>
>> I have attached the dmesg output.
>>
>> Best,
>> -Nikolaus
>>
>>
>> On Apr 04 2017, Masaki Ota  wrote:
>>> Hi, Nikolaus,
>>>
>>> Your Touchpad is 044E:120C, right?
>>>
>>> PATCH 1/2 supports 044E:120C Touchpad device.
>>> I think you can use all features of this Touchpad.
>>>
>>> PATCH 2/2 supports 044E:1215 Touchpad device.
>>> You don't need to care about this.
>>>
>>> If Touchpad does not work completely, there is something an error.
>>> What does dmesg show?
>>>
>>> Best Regards,
>>> Masaki Ota
>>> -Original Message-
>>> From: Nikolaus Rath [mailto:nikol...@rath.org]
>>> Sent: Tuesday, April 04, 2017 12:09 PM
>>> To: 太田 真喜 Masaki Ota ; linux-kernel 
>>> ; linux-in...@vger.kernel.org
>>> Subject: Re: [PATCH 1/2] Alps HID I2C T4 device support
>>>
>>> Hi Ota,
>>>
>>>> -Support Alps HID I2C T4 Touchpad device.
>>>> -Laptop names that use this Touchpad:HP Zbook Studio, Elitebook 
>>>> Folio G1, Elitebook 1030 G1, Elitebook 1040 G3
>>>>
>>>> Signed-off-by: Masaki Ota 
>>>> ---
>>>>  drivers/hid/hid-alps.c | 500 
>>>> +++--
>>>>  drivers/hid/hid-core.c |   3 +-
>>>>  drivers/hid/hid-ids.h  |   1 +
>>>>  3 files changed, 403 insertions(+), 101 deletions(-)
>>>  
>>> I tried your patch on an HP Elitebook, but with rather limited 
>>> success. Before, I was able to use the touchpad in limited fashion 
>>> (https://bugs.freedesktop.org/show_bug.cgi?id=100345). With your 
>>> patch (applied on top of 4.10), the touchpad no longer reacts at all.
>>>
>>> That said, I didn't find a patch 2/2 anywhere.. is there something missing?
>>>
>>> Thanks,
>>> -Nikolaus
>>>
>>> --
>>> GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F
>>>
>>>  »Time flies like an arrow, fruit flies like a Banana.«
>>
>>
>> --
>> GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F
>>
>>  »Time flies like an arrow, fruit flies like a Banana.«
>
>
> --
> GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F
>
>  »Time flies like an arrow, fruit flies like a Banana.«


--
GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

 »Time flies like an arrow, fruit flies like a Banana.«


RE: [PATCH 1/2] Alps HID I2C T4 device support

2017-04-04 Thread Masaki Ota
Hi, Nikolaus,

Um, but demesg log does not have any error of this Touchpad.
It's a strange.

Best Regards,
Masaki Ota
-Original Message-
From: Nikolaus Rath [mailto:nikol...@rath.org] 
Sent: Wednesday, April 05, 2017 8:43 AM
To: 太田 真喜 Masaki Ota 
Cc: linux-kernel ; linux-in...@vger.kernel.org
Subject: Re: [PATCH 1/2] Alps HID I2C T4 device support

Hi Masaki,

Yes, without your patch the touchpad is mostly working - I just can't configure 
it.

Please take a look at https://bugs.freedesktop.org/show_bug.cgi?id=100345.

Best,
-Nikolaus

On Apr 04 2017, Masaki Ota  wrote:
> Hi, Nikolaus,
>
> There is no 044E:120C device, but it looks like Alps Touchpad is detected as 
> PS/2 Touchpad.
>
> Actually, this Touchpad has two interfaces. One is I2C, the other is PS/2.
> Default setting is I2C, and if the system does not support I2C, Touchpad 
> works as PS/2.
>
> However, both of interface should work properly on Linux.
> I tested it on Ubuntu +4.10 kernel.
>
> If you don't apply my patch, does device work as I2C? (044E:120C 
> appears?)
>
> Best Regards,
> Masaki Ota
> -Original Message-
> From: Nikolaus Rath [mailto:nikol...@rath.org]
> Sent: Wednesday, April 05, 2017 2:09 AM
> To: 太田 真喜 Masaki Ota 
> Cc: linux-kernel ; 
> linux-in...@vger.kernel.org
> Subject: Re: [PATCH 1/2] Alps HID I2C T4 device support
>
> Hi Masaki,
>
> Yes, I think I have a 044E:120C. Is there a way to find out for sure?
> It's not listed by e.g. lspci.
>
> The touchpad is definitely not reacting to anything. evemu-record does not 
> show any events either.
>
> I have attached the dmesg output.
>
> Best,
> -Nikolaus
>
>
> On Apr 04 2017, Masaki Ota  wrote:
>> Hi, Nikolaus,
>>
>> Your Touchpad is 044E:120C, right?
>>
>> PATCH 1/2 supports 044E:120C Touchpad device.
>> I think you can use all features of this Touchpad.
>>
>> PATCH 2/2 supports 044E:1215 Touchpad device.
>> You don't need to care about this.
>>
>> If Touchpad does not work completely, there is something an error.
>> What does dmesg show?
>>
>> Best Regards,
>> Masaki Ota
>> -Original Message-
>> From: Nikolaus Rath [mailto:nikol...@rath.org]
>> Sent: Tuesday, April 04, 2017 12:09 PM
>> To: 太田 真喜 Masaki Ota ; linux-kernel 
>> ; linux-in...@vger.kernel.org
>> Subject: Re: [PATCH 1/2] Alps HID I2C T4 device support
>>
>> Hi Ota,
>>
>>> -Support Alps HID I2C T4 Touchpad device.
>>> -Laptop names that use this Touchpad:HP Zbook Studio, Elitebook 
>>> Folio G1, Elitebook 1030 G1, Elitebook 1040 G3
>>>
>>> Signed-off-by: Masaki Ota 
>>> ---
>>>  drivers/hid/hid-alps.c | 500 
>>> +++--
>>>  drivers/hid/hid-core.c |   3 +-
>>>  drivers/hid/hid-ids.h  |   1 +
>>>  3 files changed, 403 insertions(+), 101 deletions(-)
>>  
>> I tried your patch on an HP Elitebook, but with rather limited 
>> success. Before, I was able to use the touchpad in limited fashion 
>> (https://bugs.freedesktop.org/show_bug.cgi?id=100345). With your 
>> patch (applied on top of 4.10), the touchpad no longer reacts at all.
>>
>> That said, I didn't find a patch 2/2 anywhere.. is there something missing?
>>
>> Thanks,
>> -Nikolaus
>>
>> --
>> GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F
>>
>>  »Time flies like an arrow, fruit flies like a Banana.«
>
>
> --
> GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F
>
>  »Time flies like an arrow, fruit flies like a Banana.«


--
GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

 »Time flies like an arrow, fruit flies like a Banana.«


RE: [PATCH 1/2] Alps HID I2C T4 device support

2017-04-04 Thread Masaki Ota
Hi, Nikolaus,

There is no 044E:120C device, but it looks like Alps Touchpad is detected as 
PS/2 Touchpad.

Actually, this Touchpad has two interfaces. One is I2C, the other is PS/2.
Default setting is I2C, and if the system does not support I2C, Touchpad works 
as PS/2.

However, both of interface should work properly on Linux.
I tested it on Ubuntu +4.10 kernel.

If you don't apply my patch, does device work as I2C? (044E:120C appears?)

Best Regards,
Masaki Ota
-Original Message-
From: Nikolaus Rath [mailto:nikol...@rath.org] 
Sent: Wednesday, April 05, 2017 2:09 AM
To: 太田 真喜 Masaki Ota 
Cc: linux-kernel ; linux-in...@vger.kernel.org
Subject: Re: [PATCH 1/2] Alps HID I2C T4 device support

Hi Masaki,

Yes, I think I have a 044E:120C. Is there a way to find out for sure?
It's not listed by e.g. lspci.

The touchpad is definitely not reacting to anything. evemu-record does not show 
any events either.

I have attached the dmesg output.

Best,
-Nikolaus


On Apr 04 2017, Masaki Ota  wrote:
> Hi, Nikolaus,
>
> Your Touchpad is 044E:120C, right?
>
> PATCH 1/2 supports 044E:120C Touchpad device.
> I think you can use all features of this Touchpad.
>
> PATCH 2/2 supports 044E:1215 Touchpad device.
> You don't need to care about this.
>
> If Touchpad does not work completely, there is something an error.
> What does dmesg show?
>
> Best Regards,
> Masaki Ota
> -Original Message-
> From: Nikolaus Rath [mailto:nikol...@rath.org]
> Sent: Tuesday, April 04, 2017 12:09 PM
> To: 太田 真喜 Masaki Ota ; linux-kernel 
> ; linux-in...@vger.kernel.org
> Subject: Re: [PATCH 1/2] Alps HID I2C T4 device support
>
> Hi Ota,
>
>> -Support Alps HID I2C T4 Touchpad device.
>> -Laptop names that use this Touchpad:HP Zbook Studio, Elitebook Folio 
>> G1, Elitebook 1030 G1, Elitebook 1040 G3
>>
>> Signed-off-by: Masaki Ota 
>> ---
>>  drivers/hid/hid-alps.c | 500 
>> +++--
>>  drivers/hid/hid-core.c |   3 +-
>>  drivers/hid/hid-ids.h  |   1 +
>>  3 files changed, 403 insertions(+), 101 deletions(-)
>  
> I tried your patch on an HP Elitebook, but with rather limited success. 
> Before, I was able to use the touchpad in limited fashion 
> (https://bugs.freedesktop.org/show_bug.cgi?id=100345). With your patch 
> (applied on top of 4.10), the touchpad no longer reacts at all.
>
> That said, I didn't find a patch 2/2 anywhere.. is there something missing?
>
> Thanks,
> -Nikolaus
>
> --
> GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F
>
>  »Time flies like an arrow, fruit flies like a Banana.«


--
GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

 »Time flies like an arrow, fruit flies like a Banana.«


RE: [PATCH 1/2] Alps HID I2C T4 device support

2017-04-03 Thread Masaki Ota
Hi, Nikolaus,

Your Touchpad is 044E:120C, right?

PATCH 1/2 supports 044E:120C Touchpad device.
I think you can use all features of this Touchpad.

PATCH 2/2 supports 044E:1215 Touchpad device.
You don't need to care about this.

If Touchpad does not work completely, there is something an error.
What does dmesg show?

Best Regards,
Masaki Ota
-Original Message-
From: Nikolaus Rath [mailto:nikol...@rath.org] 
Sent: Tuesday, April 04, 2017 12:09 PM
To: 太田 真喜 Masaki Ota ; linux-kernel 
; linux-in...@vger.kernel.org
Subject: Re: [PATCH 1/2] Alps HID I2C T4 device support

Hi Ota,

> -Support Alps HID I2C T4 Touchpad device.
> -Laptop names that use this Touchpad:HP Zbook Studio, Elitebook Folio 
> G1, Elitebook 1030 G1, Elitebook 1040 G3
>
> Signed-off-by: Masaki Ota 
> ---
>  drivers/hid/hid-alps.c | 500 
> +++--
>  drivers/hid/hid-core.c |   3 +-
>  drivers/hid/hid-ids.h  |   1 +
>  3 files changed, 403 insertions(+), 101 deletions(-)
 
I tried your patch on an HP Elitebook, but with rather limited success. Before, 
I was able to use the touchpad in limited fashion 
(https://bugs.freedesktop.org/show_bug.cgi?id=100345). With your patch (applied 
on top of 4.10), the touchpad no longer reacts at all.

That said, I didn't find a patch 2/2 anywhere.. is there something missing?

Thanks,
-Nikolaus

--
GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

 »Time flies like an arrow, fruit flies like a Banana.«


[PATCH 0/2] Support new Alps HID I2C Touchpad device

2017-03-29 Thread Masaki Ota
Hi, Jiri,

This is the patch for new Alps HID I2C Touchpad device.
These devices are used for HP Laptop.


Best Regards,
Masaki Ota


[PATCH 2/2] Add new U1 device ID

2017-03-29 Thread Masaki Ota
-Add new Alps U1 Touchpad device ID
-Laptop names that use this Touchpad:HP Elitebook x360 1030 G2

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 3 +++
 drivers/hid/hid-core.c | 1 +
 drivers/hid/hid-ids.h  | 1 +
 3 files changed, 5 insertions(+)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index 13a6db1..f19a7f4 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -758,6 +758,7 @@ static int alps_probe(struct hid_device *hdev, const struct 
hid_device_id *id)
data->dev_type = T4;
break;
case HID_DEVICE_ID_ALPS_U1_DUAL:
+   case HID_DEVICE_ID_ALPS_U1:
data->dev_type = U1;
break;
default:
@@ -782,6 +783,8 @@ static const struct hid_device_id alps_id[] = {
{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1_DUAL) },
{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
+   USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1) },
+   { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY,
USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_BTNLESS) },
{ }
 };
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index f315192..0f88944 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1770,6 +1770,7 @@ static const struct hid_device_id 
hid_have_special_driver[] = {
{ HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
{ HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0xf705) },
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1_DUAL) },
+   { HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_U1) },
{ HID_I2C_DEVICE(USB_VENDOR_ID_ALPS_JP, HID_DEVICE_ID_ALPS_T4_BTNLESS) 
},
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) 
},
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGICMOUSE) },
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 9239543..e0bad95 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -75,6 +75,7 @@
 
 #define USB_VENDOR_ID_ALPS_JP  0x044E
 #define HID_DEVICE_ID_ALPS_U1_DUAL 0x120B
+#define HID_DEVICE_ID_ALPS_U1  0x1215
 #define HID_DEVICE_ID_ALPS_T4_BTNLESS  0x120C
 
 #define USB_VENDOR_ID_AMI  0x046b
-- 
2.9.3



[PATCH 1/2] Alps HID I2C T4 device support

2017-03-29 Thread Masaki Ota
>From Masaki Ota 

-Support Alps HID I2C T4 Touchpad device.
-Laptop names that use this Touchpad:HP Zbook Studio, Elitebook Folio G1, 
Elitebook 1030 G1, Elitebook 1040 G3

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 500 +++--
 drivers/hid/hid-core.c |   3 +-
 drivers/hid/hid-ids.h  |   1 +
 3 files changed, 403 insertions(+), 101 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index ed9c0ea..13a6db1 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -52,8 +52,30 @@
 #define ADDRESS_U1_PAD_BTN 0x00800052
 #define ADDRESS_U1_SP_BTN  0x0080009F
 
+#define T4_INPUT_REPORT_LENsizeof(T4_INPUT_REPORT)
+#define T4_FEATURE_REPORT_LEN  T4_INPUT_REPORT_LEN
+#define T4_FEATURE_REPORT_ID   7
+#define T4_CMD_REGISTER_READ   0x08
+#define T4_CMD_REGISTER_WRITE  0x07
+
+#define T4_ADDRESS_BASE0xC2C0
+#define PRM_SYS_CONFIG_1   (T4_ADDRESS_BASE + 0x0002)
+#define T4_PRM_FEED_CONFIG_1   (T4_ADDRESS_BASE + 0x0004)
+#define T4_PRM_FEED_CONFIG_4   (T4_ADDRESS_BASE + 0x001A)
+#define T4_PRM_ID_CONFIG_3 (T4_ADDRESS_BASE + 0x00B0)
+
+
+#define T4_FEEDCFG4_ADVANCED_ABS_ENABLE0x01
+#define T4_I2C_ABS 0x78
+
+#define T4_COUNT_PER_ELECTRODE 256
 #define MAX_TOUCHES5
 
+typedef enum {
+   U1,
+   T4,
+   UNKNOWN,
+} DEV_TYPE;
 /**
  * struct u1_data
  *
@@ -61,43 +83,168 @@
  * @input2: pointer to the kernel input2 device
  * @hdev: pointer to the struct hid_device
  *
- * @dev_ctrl: device control parameter
  * @dev_type: device type
- * @sen_line_num_x: number of sensor line of X
- * @sen_line_num_y: number of sensor line of Y
- * @pitch_x: sensor pitch of X
- * @pitch_y: sensor pitch of Y
- * @resolution: resolution
- * @btn_info: button information
+ * @max_fingers: total number of fingers
+ * @has_sp: boolean of sp existense
+ * @sp_btn_info: button information
  * @x_active_len_mm: active area length of X (mm)
  * @y_active_len_mm: active area length of Y (mm)
  * @x_max: maximum x coordinate value
  * @y_max: maximum y coordinate value
+ * @x_min: minimum x coordinate value
+ * @y_min: minimum y coordinate value
  * @btn_cnt: number of buttons
  * @sp_btn_cnt: number of stick buttons
  */
-struct u1_dev {
+struct alps_dev {
struct input_dev *input;
struct input_dev *input2;
struct hid_device *hdev;
 
-   u8  dev_ctrl;
-   u8  dev_type;
-   u8  sen_line_num_x;
-   u8  sen_line_num_y;
-   u8  pitch_x;
-   u8  pitch_y;
-   u8  resolution;
-   u8  btn_info;
+   DEV_TYPE dev_type;
+   u8  max_fingers;
+   u8  has_sp;
u8  sp_btn_info;
u32 x_active_len_mm;
u32 y_active_len_mm;
u32 x_max;
u32 y_max;
+   u32 x_min;
+   u32 y_min;
u32 btn_cnt;
u32 sp_btn_cnt;
 };
 
+typedef struct _T4_CONTACT_DATA {
+   u8  Palm;
+   u8  x_lo;
+   u8  x_hi;
+   u8  y_lo;
+   u8  y_hi;
+} T4_CONTACT_DATA, *PT4_CONTACT_DATA;
+
+typedef struct _T4_INPUT_REPORT {
+   u8  ReportID;
+   u8  NumContacts;
+   T4_CONTACT_DATA Contact[5];
+   u8  Button;
+   u8  Track[5];
+   u8  ZX[5], ZY[5];
+   u8  PalmTime[5];
+   u8  Kilroy;
+   u16 TimeStamp;
+} T4_INPUT_REPORT, *PT4_INPUT_REPORT;
+
+static u16 t4_calc_check_sum(u8 *buffer,
+   unsigned long offset, unsigned long length)
+{
+   u16 sum1 = 0xFF, sum2 = 0xFF;
+   unsigned long i = 0;
+
+   if (offset + length >= 50)
+   return 0;
+
+   while (length > 0) {
+   u32 tlen = length > 20 ? 20 : length;
+
+   length -= tlen;
+
+   do {
+   sum1 += buffer[offset + i];
+   sum2 += sum1;
+   i++;
+   } while (--tlen > 0);
+
+   sum1 = (sum1 & 0xFF) + (sum1 >> 8);
+   sum2 = (sum2 & 0xFF) + (sum2 >> 8);
+   }
+
+   sum1 = (sum1 & 0xFF) + (sum1 >> 8);
+   sum2 = (sum2 & 0xFF) + (sum2 >> 8);
+
+   return(sum2 << 8 | sum1);
+}
+
+static int T4_read_write_register(struct hid_device *hdev, u32 address,
+   u8 *read_val, u8 write_val, bool read_flag)
+{
+   int ret;
+   u16 check_sum;
+   u8 *input;
+   u8 *readbuf;
+
+   input = kzalloc(T4_FEATURE_REPORT_LEN, GFP_KERNEL);
+   if (!input)
+   return -ENOMEM;
+
+   input[0] = T4_FEATURE_REPORT_ID;
+   if (read_flag) {
+   input[1] = T4_CMD_REGISTER_READ;
+   input[8] = 0x00;
+   } else {
+   input[1] = T4_CMD_REGISTER_WRITE;
+   input

[PATCH 1/2] Fix V8 device information issue

2017-03-13 Thread Masaki Ota
From: Masaki Ota 
-Fix the issue that V8(E7=73 03 28) devices are not assined correct device 
information bit from OTP.
-Specified correct OTP bit for the V8 device setting of Button pad, DualPoint 
and Touchpad size.
-Deleted extra code from alps_v8_protocol_data decision process.

Signed-off-by: Masaki Ota 

Acked-by: Pali Rohar 
---
 drivers/input/mouse/alps.c | 66 +++---
 drivers/input/mouse/alps.h | 11 
 2 files changed, 61 insertions(+), 16 deletions(-)

diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index e761955..253f742 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -2467,14 +2467,34 @@ static int alps_update_device_area_ss4_v2(unsigned char 
otp[][4],
int num_y_electrode;
int x_pitch, y_pitch, x_phys, y_phys;
 
-   num_x_electrode = SS4_NUMSENSOR_XOFFSET + (otp[1][0] & 0x0F);
-   num_y_electrode = SS4_NUMSENSOR_YOFFSET + ((otp[1][0] >> 4) & 0x0F);
+   if (IS_SS4PLUS_DEV(priv->dev_id)) {
+   num_x_electrode =
+   SS4PLUS_NUMSENSOR_XOFFSET + (otp[0][2] & 0x0F);
+   num_y_electrode =
+   SS4PLUS_NUMSENSOR_YOFFSET + ((otp[0][2] >> 4) & 0x0F);
 
-   priv->x_max = (num_x_electrode - 1) * SS4_COUNT_PER_ELECTRODE;
-   priv->y_max = (num_y_electrode - 1) * SS4_COUNT_PER_ELECTRODE;
+   priv->x_max =
+   (num_x_electrode - 1) * SS4PLUS_COUNT_PER_ELECTRODE;
+   priv->y_max =
+   (num_y_electrode - 1) * SS4PLUS_COUNT_PER_ELECTRODE;
 
-   x_pitch = ((otp[1][2] >> 2) & 0x07) + SS4_MIN_PITCH_MM;
-   y_pitch = ((otp[1][2] >> 5) & 0x07) + SS4_MIN_PITCH_MM;
+   x_pitch = (otp[0][1] & 0x0F) + SS4PLUS_MIN_PITCH_MM;
+   y_pitch = ((otp[0][1] >> 4) & 0x0F) + SS4PLUS_MIN_PITCH_MM;
+
+   } else {
+   num_x_electrode =
+   SS4_NUMSENSOR_XOFFSET + (otp[1][0] & 0x0F);
+   num_y_electrode =
+   SS4_NUMSENSOR_YOFFSET + ((otp[1][0] >> 4) & 0x0F);
+
+   priv->x_max =
+   (num_x_electrode - 1) * SS4_COUNT_PER_ELECTRODE;
+   priv->y_max =
+   (num_y_electrode - 1) * SS4_COUNT_PER_ELECTRODE;
+
+   x_pitch = ((otp[1][2] >> 2) & 0x07) + SS4_MIN_PITCH_MM;
+   y_pitch = ((otp[1][2] >> 5) & 0x07) + SS4_MIN_PITCH_MM;
+   }
 
x_phys = x_pitch * (num_x_electrode - 1); /* In 0.1 mm units */
y_phys = y_pitch * (num_y_electrode - 1); /* In 0.1 mm units */
@@ -2490,7 +2510,10 @@ static int alps_update_btn_info_ss4_v2(unsigned char 
otp[][4],
 {
unsigned char is_btnless;
 
-   is_btnless = (otp[1][1] >> 3) & 0x01;
+   if (IS_SS4PLUS_DEV(priv->dev_id))
+   is_btnless = (otp[1][0] >> 1) & 0x01;
+   else
+   is_btnless = (otp[1][1] >> 3) & 0x01;
 
if (is_btnless)
priv->flags |= ALPS_BUTTONPAD;
@@ -2498,6 +2521,21 @@ static int alps_update_btn_info_ss4_v2(unsigned char 
otp[][4],
return 0;
 }
 
+static int alps_update_dual_info_ss4_v2(unsigned char otp[][4],
+  struct alps_data *priv)
+{
+   bool is_dual = false;
+
+   if (IS_SS4PLUS_DEV(priv->dev_id))
+   is_dual = (otp[0][0] >> 4) & 0x01;
+
+   if (is_dual)
+   priv->flags |= ALPS_DUALPOINT |
+   ALPS_DUALPOINT_WITH_PRESSURE;
+
+   return 0;
+}
+
 static int alps_set_defaults_ss4_v2(struct psmouse *psmouse,
struct alps_data *priv)
 {
@@ -2513,6 +2551,8 @@ static int alps_set_defaults_ss4_v2(struct psmouse 
*psmouse,
 
alps_update_btn_info_ss4_v2(otp, priv);
 
+   alps_update_dual_info_ss4_v2(otp, priv);
+
return 0;
 }
 
@@ -2758,10 +2798,6 @@ static int alps_set_protocol(struct psmouse *psmouse,
if (alps_set_defaults_ss4_v2(psmouse, priv))
return -EIO;
 
-   if (priv->fw_ver[1] == 0x1)
-   priv->flags |= ALPS_DUALPOINT |
-   ALPS_DUALPOINT_WITH_PRESSURE;
-
break;
}
 
@@ -2831,10 +2867,7 @@ static int alps_identify(struct psmouse *psmouse, struct 
alps_data *priv)
   ec[2] >= 0x90 && ec[2] <= 0x9d) {
protocol = &alps_v3_protocol_data;
} else if (e7[0] == 0x73 && e7[1] == 0x03 &&
-  e7[2] == 0x14 && ec[1] == 0x02) {
-   protocol = &alps_v8_protocol_data;
-   } else if (e7[0] == 0x73 && e7[1] == 0x03 &&
-  

[PATCH 2/2] Fix the issue that V8 Button pad Stick button does not work

2017-03-13 Thread Masaki Ota
From: Masaki Ota 
- V8 Button pad Stick Right and Middle button don't work.
- Alps stick devices have physical buttons absolutely, so delete 
"ALPS_BUTTONPAD" check Flag from Stick button process.

Signed-off-by: Masaki Ota 

Acked-by: Pali Rohar 
---
 drivers/input/mouse/alps.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 253f742..262d105 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -1287,10 +1287,8 @@ static int alps_decode_ss4_v2(struct alps_fields *f,
/* handle buttons */
if (pkt_id == SS4_PACKET_ID_STICK) {
f->ts_left = !!(SS4_BTN_V2(p) & 0x01);
-   if (!(priv->flags & ALPS_BUTTONPAD)) {
-   f->ts_right = !!(SS4_BTN_V2(p) & 0x02);
-   f->ts_middle = !!(SS4_BTN_V2(p) & 0x04);
-   }
+   f->ts_right = !!(SS4_BTN_V2(p) & 0x02);
+   f->ts_middle = !!(SS4_BTN_V2(p) & 0x04);
} else {
f->left = !!(SS4_BTN_V2(p) & 0x01);
if (!(priv->flags & ALPS_BUTTONPAD)) {
-- 
2.9.3



[PATCH 1/2] Fix V8 device information issue

2017-03-13 Thread Masaki Ota
From: Masaki Ota 
-Fix the issue that V8(E7=73 03 28) devices are not assined correct device 
information bit from OTP.
-Specified correct OTP bit for the V8 device setting of Button pad, DualPoint 
and Touchpad size.
-Deleted extra code from alps_v8_protocol_data decision process.

Signed-off-by: Masaki Ota 
---
 drivers/input/mouse/alps.c | 66 +++---
 drivers/input/mouse/alps.h | 11 
 2 files changed, 61 insertions(+), 16 deletions(-)

diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index e761955..a70c860 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -2467,14 +2467,34 @@ static int alps_update_device_area_ss4_v2(unsigned char 
otp[][4],
int num_y_electrode;
int x_pitch, y_pitch, x_phys, y_phys;
 
-   num_x_electrode = SS4_NUMSENSOR_XOFFSET + (otp[1][0] & 0x0F);
-   num_y_electrode = SS4_NUMSENSOR_YOFFSET + ((otp[1][0] >> 4) & 0x0F);
+   if (IS_SS4PLUS_DEV(priv->dev_id)) {
+   num_x_electrode =
+   SS4PLUS_NUMSENSOR_XOFFSET + (otp[0][2] & 0x0F);
+   num_y_electrode =
+   SS4PLUS_NUMSENSOR_YOFFSET + ((otp[0][2] >> 4) & 0x0F);
 
-   priv->x_max = (num_x_electrode - 1) * SS4_COUNT_PER_ELECTRODE;
-   priv->y_max = (num_y_electrode - 1) * SS4_COUNT_PER_ELECTRODE;
+   priv->x_max =
+   (num_x_electrode - 1) * SS4PLUS_COUNT_PER_ELECTRODE;
+   priv->y_max =
+   (num_y_electrode - 1) * SS4PLUS_COUNT_PER_ELECTRODE;
 
-   x_pitch = ((otp[1][2] >> 2) & 0x07) + SS4_MIN_PITCH_MM;
-   y_pitch = ((otp[1][2] >> 5) & 0x07) + SS4_MIN_PITCH_MM;
+   x_pitch = (otp[0][1] & 0x0F) + SS4PLUS_MIN_PITCH_MM;
+   y_pitch = ((otp[0][1] >> 4) & 0x0F) + SS4PLUS_MIN_PITCH_MM;
+
+   } else {
+   num_x_electrode =
+   SS4_NUMSENSOR_XOFFSET + (otp[1][0] & 0x0F);
+   num_y_electrode =
+   SS4_NUMSENSOR_YOFFSET + ((otp[1][0] >> 4) & 0x0F);
+
+   priv->x_max =
+   (num_x_electrode - 1) * SS4_COUNT_PER_ELECTRODE;
+   priv->y_max =
+   (num_y_electrode - 1) * SS4_COUNT_PER_ELECTRODE;
+
+   x_pitch = ((otp[1][2] >> 2) & 0x07) + SS4_MIN_PITCH_MM;
+   y_pitch = ((otp[1][2] >> 5) & 0x07) + SS4_MIN_PITCH_MM;
+   }
 
x_phys = x_pitch * (num_x_electrode - 1); /* In 0.1 mm units */
y_phys = y_pitch * (num_y_electrode - 1); /* In 0.1 mm units */
@@ -2490,7 +2510,10 @@ static int alps_update_btn_info_ss4_v2(unsigned char 
otp[][4],
 {
unsigned char is_btnless;
 
-   is_btnless = (otp[1][1] >> 3) & 0x01;
+   if (IS_SS4PLUS_DEV(priv->dev_id))
+   is_btnless = (otp[1][0] >> 1) & 0x01;
+   else
+   is_btnless = (otp[1][1] >> 3) & 0x01;
 
if (is_btnless)
priv->flags |= ALPS_BUTTONPAD;
@@ -2498,6 +2521,21 @@ static int alps_update_btn_info_ss4_v2(unsigned char 
otp[][4],
return 0;
 }
 
+static int alps_update_dual_info_ss4_v2(unsigned char otp[][4],
+  struct alps_data *priv)
+{
+   unsigned char is_dual = 0;
+
+   if (IS_SS4PLUS_DEV(priv->dev_id))
+   is_dual = (otp[0][0] >> 4) & 0x01;
+
+   if (is_dual)
+   priv->flags |= ALPS_DUALPOINT |
+   ALPS_DUALPOINT_WITH_PRESSURE;
+
+   return 0;
+}
+
 static int alps_set_defaults_ss4_v2(struct psmouse *psmouse,
struct alps_data *priv)
 {
@@ -2513,6 +2551,8 @@ static int alps_set_defaults_ss4_v2(struct psmouse 
*psmouse,
 
alps_update_btn_info_ss4_v2(otp, priv);
 
+   alps_update_dual_info_ss4_v2(otp, priv);
+
return 0;
 }
 
@@ -2758,10 +2798,6 @@ static int alps_set_protocol(struct psmouse *psmouse,
if (alps_set_defaults_ss4_v2(psmouse, priv))
return -EIO;
 
-   if (priv->fw_ver[1] == 0x1)
-   priv->flags |= ALPS_DUALPOINT |
-   ALPS_DUALPOINT_WITH_PRESSURE;
-
break;
}
 
@@ -2831,10 +2867,7 @@ static int alps_identify(struct psmouse *psmouse, struct 
alps_data *priv)
   ec[2] >= 0x90 && ec[2] <= 0x9d) {
protocol = &alps_v3_protocol_data;
} else if (e7[0] == 0x73 && e7[1] == 0x03 &&
-  e7[2] == 0x14 && ec[1] == 0x02) {
-   protocol = &alps_v8_protocol_data;
-   } else if (e7[0] == 0x73 && e7[1] == 0x03 &&
-   

[PATCH 2/2] Fix the issue that V8 Button pad Stick button does not work

2017-03-13 Thread Masaki Ota
From: Masaki Ota 
- V8 Button pad Stick Right and Middle button don't work.
- Alps stick devices have physical buttons absolutely, so delete 
"ALPS_BUTTONPAD" check Flag from Stick button process.

Signed-off-by: Masaki Ota 
---
 drivers/input/mouse/alps.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index a70c860..a13404f 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -1287,10 +1287,8 @@ static int alps_decode_ss4_v2(struct alps_fields *f,
/* handle buttons */
if (pkt_id == SS4_PACKET_ID_STICK) {
f->ts_left = !!(SS4_BTN_V2(p) & 0x01);
-   if (!(priv->flags & ALPS_BUTTONPAD)) {
-   f->ts_right = !!(SS4_BTN_V2(p) & 0x02);
-   f->ts_middle = !!(SS4_BTN_V2(p) & 0x04);
-   }
+   f->ts_right = !!(SS4_BTN_V2(p) & 0x02);
+   f->ts_middle = !!(SS4_BTN_V2(p) & 0x04);
} else {
f->left = !!(SS4_BTN_V2(p) & 0x01);
if (!(priv->flags & ALPS_BUTTONPAD)) {
-- 
2.9.3



[PATCH] Fix V8 device information issue

2017-03-09 Thread Masaki Ota
From: Masaki Ota 
-Fix the issue that V8(E7=73 03 28) devices are not assined correct device 
information from OTP.
-Specified correct OTP bit for the V8 device setting of Button pad, DualPoint 
and Touchpad size.

Signed-off-by: Masaki Ota 
---
 drivers/input/mouse/alps.c | 74 --
 drivers/input/mouse/alps.h |  6 
 2 files changed, 64 insertions(+), 16 deletions(-)

diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index e761955..462871c 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -2467,21 +2467,46 @@ static int alps_update_device_area_ss4_v2(unsigned char 
otp[][4],
int num_y_electrode;
int x_pitch, y_pitch, x_phys, y_phys;
 
-   num_x_electrode = SS4_NUMSENSOR_XOFFSET + (otp[1][0] & 0x0F);
-   num_y_electrode = SS4_NUMSENSOR_YOFFSET + ((otp[1][0] >> 4) & 0x0F);
+   if (priv->dev_id[2] == 0x28) {
+   num_x_electrode =
+   SS4PLUS_NUMSENSOR_XOFFSET + (otp[0][2] & 0x0F);
+   num_y_electrode =
+   SS4PLUS_NUMSENSOR_YOFFSET + ((otp[0][2] >> 4) & 0x0F);
 
-   priv->x_max = (num_x_electrode - 1) * SS4_COUNT_PER_ELECTRODE;
-   priv->y_max = (num_y_electrode - 1) * SS4_COUNT_PER_ELECTRODE;
+   priv->x_max =
+   (num_x_electrode - 1) * SS4PLUS_COUNT_PER_ELECTRODE;
+   priv->y_max =
+   (num_y_electrode - 1) * SS4PLUS_COUNT_PER_ELECTRODE;
 
-   x_pitch = ((otp[1][2] >> 2) & 0x07) + SS4_MIN_PITCH_MM;
-   y_pitch = ((otp[1][2] >> 5) & 0x07) + SS4_MIN_PITCH_MM;
+   x_pitch = (otp[0][1] & 0x0F) + SS4PLUS_MIN_PITCH_MM;
+   y_pitch = ((otp[0][1] >> 4) & 0x0F) + SS4PLUS_MIN_PITCH_MM;
 
-   x_phys = x_pitch * (num_x_electrode - 1); /* In 0.1 mm units */
-   y_phys = y_pitch * (num_y_electrode - 1); /* In 0.1 mm units */
+   x_phys = x_pitch * (num_x_electrode - 1); /* In 0.1 mm units */
+   y_phys = y_pitch * (num_y_electrode - 1); /* In 0.1 mm units */
 
-   priv->x_res = priv->x_max * 10 / x_phys; /* units / mm */
-   priv->y_res = priv->y_max * 10 / y_phys; /* units / mm */
+   priv->x_res = priv->x_max * 10 / x_phys; /* units / mm */
+   priv->y_res = priv->y_max * 10 / y_phys; /* units / mm */
+
+   } else {
+   num_x_electrode =
+   SS4_NUMSENSOR_XOFFSET + (otp[1][0] & 0x0F);
+   num_y_electrode =
+   SS4_NUMSENSOR_YOFFSET + ((otp[1][0] >> 4) & 0x0F);
+
+   priv->x_max =
+   (num_x_electrode - 1) * SS4_COUNT_PER_ELECTRODE;
+   priv->y_max =
+   (num_y_electrode - 1) * SS4_COUNT_PER_ELECTRODE;
+
+   x_pitch = ((otp[1][2] >> 2) & 0x07) + SS4_MIN_PITCH_MM;
+   y_pitch = ((otp[1][2] >> 5) & 0x07) + SS4_MIN_PITCH_MM;
 
+   x_phys = x_pitch * (num_x_electrode - 1); /* In 0.1 mm units */
+   y_phys = y_pitch * (num_y_electrode - 1); /* In 0.1 mm units */
+
+   priv->x_res = priv->x_max * 10 / x_phys; /* units / mm */
+   priv->y_res = priv->y_max * 10 / y_phys; /* units / mm */
+   }
return 0;
 }
 
@@ -2490,7 +2515,10 @@ static int alps_update_btn_info_ss4_v2(unsigned char 
otp[][4],
 {
unsigned char is_btnless;
 
-   is_btnless = (otp[1][1] >> 3) & 0x01;
+   if (priv->dev_id[2] == 0x28)
+   is_btnless = (otp[1][0] >> 1) & 0x01;
+   else
+   is_btnless = (otp[1][1] >> 3) & 0x01;
 
if (is_btnless)
priv->flags |= ALPS_BUTTONPAD;
@@ -2498,6 +2526,21 @@ static int alps_update_btn_info_ss4_v2(unsigned char 
otp[][4],
return 0;
 }
 
+static int alps_update_dual_info_ss4_v2(unsigned char otp[][4],
+  struct alps_data *priv)
+{
+   unsigned char is_dual = 0;
+
+   if (priv->dev_id[2] == 0x28)
+   is_dual = (otp[0][0] >> 4) & 0x01;
+
+   if (is_dual)
+   priv->flags |= ALPS_DUALPOINT |
+   ALPS_DUALPOINT_WITH_PRESSURE;
+
+   return 0;
+}
+
 static int alps_set_defaults_ss4_v2(struct psmouse *psmouse,
struct alps_data *priv)
 {
@@ -2513,6 +2556,8 @@ static int alps_set_defaults_ss4_v2(struct psmouse 
*psmouse,
 
alps_update_btn_info_ss4_v2(otp, priv);
 
+   alps_update_dual_info_ss4_v2(otp, priv);
+
return 0;
 }
 
@@ -2758,10 +2803,6 @@ static int alps_set_protocol(struct psmouse *psmouse,
if (alps_set_defaults_ss4_v2(psmouse, priv))
return -EIO;
 
-   if (priv->fw_ve

RE: [REGRESSION][v4.9.y][v4.10.y] Input: ALPS - set DualPoint flag for 74 03 28 devices

2017-03-07 Thread Masaki Ota
Hi, Dmitry,

OK, I will do it.

Best Regards,
Masaki Ota
-Original Message-
From: dmitry.torok...@gmail.com [mailto:dmitry.torok...@gmail.com] 
Sent: Wednesday, March 08, 2017 2:58 AM
To: 太田 真喜 Masaki Ota 
Cc: Paul Donohue ; Nick Fletcher 
; Joseph Salisbury ; 
b...@smart-cactus.org; mho...@suse.com; pali.ro...@gmail.com; 
rydb...@bitmath.org; li...@roeck-us.net; open list:HID CORE LAYER 
; LKML ; 
sta...@vger.kernel.org
Subject: Re: [REGRESSION][v4.9.y][v4.10.y] Input: ALPS - set DualPoint flag for 
74 03 28 devices

Hi Masaki,

On Tue, Mar 07, 2017 at 08:40:20AM +, Masaki Ota wrote:
> Hi, Paul,
> 
> I have modified the source code. 
> 
> There are three issues.
> #1. E7=73 03 28 Button pad device is not assigned "ALPS_BUTTONPAD" Flag 
> correctly.
> #2. E7=73 03 28 devices are not assigned " ALPS_DUALPOINT" Flag correctly.
> #3. E7=73 03 28 device cursor speed is slow.
> 
> Actually, the cause is all the same.
> E7=73 03 28 device does not get correct information from OTP.
> OTP is the device information byte. I specified correct bit.
> 
> Then, I think it is also the issue.
> #4. Stick Pointer cursor speed is fast.
> 
> I will check Stick parameter.

Could you please submit this as a proper patch now that we have confirmation 
that it works? Also, I wonder if V8PLUS should be full protocol instead of a 
flag.

Thanks.

--
Dmitry


RE: [REGRESSION][v4.9.y][v4.10.y] Input: ALPS - set DualPoint flag for 74 03 28 devices

2017-03-07 Thread Masaki Ota
Hi, Paul,

I have modified the source code. 

There are three issues.
#1. E7=73 03 28 Button pad device is not assigned "ALPS_BUTTONPAD" Flag 
correctly.
#2. E7=73 03 28 devices are not assigned " ALPS_DUALPOINT" Flag correctly.
#3. E7=73 03 28 device cursor speed is slow.

Actually, the cause is all the same.
E7=73 03 28 device does not get correct information from OTP.
OTP is the device information byte. I specified correct bit.

Then, I think it is also the issue.
#4. Stick Pointer cursor speed is fast.

I will check Stick parameter.

Best Regards,
Masaki Ota
-Original Message-
From: Paul Donohue [mailto:linux-ker...@paulsd.com] 
Sent: Tuesday, March 07, 2017 11:18 AM
To: 太田 真喜 Masaki Ota 
Cc: Nick Fletcher ; Joseph Salisbury 
; b...@smart-cactus.org; mho...@suse.com; 
dmitry.torok...@gmail.com; pali.ro...@gmail.com; rydb...@bitmath.org; 
li...@roeck-us.net; open list:HID CORE LAYER ; 
LKML ; sta...@vger.kernel.org
Subject: Re: [REGRESSION][v4.9.y][v4.10.y] Input: ALPS - set DualPoint flag for 
74 03 28 devices

Excellent!  Thanks!  Let me know if you see anything else that needs to change.

On Mon, Mar 06, 2017 at 08:45:33AM +, Masaki Ota wrote:
> Hi, Paul,
> 
> I understand the current situation.
> We have three devices that have ID: E7=73 03 28.
> 
> DELL: Normal Pad type (There are Left and right button below 
> Touchpad.)
> ID: E7=73 03 28, EC=73 01 13
> ID: E7=73 03 28, EC=73 01 22
> 
> TOSHIBA: Button Pad type
> ID: E7=73 03 28, EC=73 01 14
> 
> I think Nick mentioned about TOSHIBA device.
> I have checked the source code and I guess EC=73 01 14 device does not have 
> "ALPS_BUTTONPAD" Flag, although it is the Button Pad.
> Because "alps_update_btn_info_ss4_v2()" does not support E7=73 03 28 devices.
> 
> E7=73 03 14 device can use below code.
> is_btnless = (otp[1][1] >> 3) & 0x01;
> 
> E7=73 03 28 device has to use below bit.
> is_btnless = (otp[1][0] >> 1) & 0x01;
> 
> I will check other parts of source code.
> 
> Best Regards,
> Masaki Ota
> -Original Message-
> From: Paul Donohue [mailto:linux-ker...@paulsd.com]
> Sent: Monday, March 06, 2017 3:09 AM
> To: Nick Fletcher ; 太田 真喜 Masaki Ota 
> 
> Cc: Joseph Salisbury ; 
> b...@smart-cactus.org; mho...@suse.com; dmitry.torok...@gmail.com; 
> pali.ro...@gmail.com; rydb...@bitmath.org; li...@roeck-us.net; open 
> list:HID CORE LAYER ; LKML 
> ; sta...@vger.kernel.org
> Subject: Re: [REGRESSION][v4.9.y][v4.10.y] Input: ALPS - set DualPoint 
> flag for 74 03 28 devices
> 
> Oops, forgot the attachments
> 
> On Sun, Mar 05, 2017 at 12:56:19PM -0500, Paul Donohue wrote:
> > Masaki: Do you have any information about this touchpad you can share?  Is 
> > the third byte in EC relevant to the protocol and something we should look 
> > for when identifying devices in the driver?
> > 
> > Nick:
> > 
> > Unfortunately, I didn't print quite enough information in the two-finger 
> > message, but yeah, this kinda looks like a different protocol.
> > 
> > I've attached two tarballs this time:
> > 1) alps_2a.tar.gz prints some additional info in the two-finger message 
> > which may help figure out what protocol your device is speaking:
> > sudo -s
> > dkms remove alps_ss5/1.0 --all
> > cd /usr/src/
> > rm -rf alps_ss5-1.0
> > tar -xvzf alps_2a.tar.gz
> > dkms install alps_ss5/1.0
> > modprobe -r psmouse ; modprobe psmouse # Try two-finger scrolling, 
> > then run:
> > dmesg | grep 'two-finger'
> > 
> > 2) alps_2b.tar.gz disables the driver unless the third byte in EC is 0x13 
> > (the value my device uses) ... This driver should make your mouse work 
> > properly:
> > sudo -s
> > dkms remove alps_ss5/1.0 --all
> > cd /usr/src/
> > rm -rf alps_ss5-1.0
> > tar -xvzf alps_2b.tar.gz
> > dkms install alps_ss5/1.0
> > modprobe -r psmouse ; modprobe psmouse
> > 
> > Try those out and let's see where that gets us.
> > 
> > When you are done testing, you can revert back to whatever driver came with 
> > your kernel by running:
> > sudo -s
> > dkms remove alps_ss5/1.0 --all
> > modprobe -r psmouse ; modprobe psmouse
> > 
> > -Paul
> > 
> > On Sun, Mar 05, 2017 at 09:09:01AM +, Nick Fletcher wrote:
> > > Hi All,
> > > 
> > > My touchpad has the physical buttons above the touchpad.
> > > 
> > > I have cut and pasted the the results of the two dmesg commands 
> > > below.  The trackpad of course stopped working correctly again 
> > > after installing alps_ss5-1.0.
> > > 
> > > I'

RE: [REGRESSION][v4.9.y][v4.10.y] Input: ALPS - set DualPoint flag for 74 03 28 devices

2017-03-06 Thread Masaki Ota
Hi, Paul,

I understand the current situation.
We have three devices that have ID: E7=73 03 28.

DELL: Normal Pad type (There are Left and right button below Touchpad.)
ID: E7=73 03 28, EC=73 01 13
ID: E7=73 03 28, EC=73 01 22

TOSHIBA: Button Pad type
ID: E7=73 03 28, EC=73 01 14

I think Nick mentioned about TOSHIBA device.
I have checked the source code and I guess EC=73 01 14 device does not have 
"ALPS_BUTTONPAD" Flag, although it is the Button Pad.
Because "alps_update_btn_info_ss4_v2()" does not support E7=73 03 28 devices.

E7=73 03 14 device can use below code.
is_btnless = (otp[1][1] >> 3) & 0x01;

E7=73 03 28 device has to use below bit.
is_btnless = (otp[1][0] >> 1) & 0x01;

I will check other parts of source code.

Best Regards,
Masaki Ota
-Original Message-
From: Paul Donohue [mailto:linux-ker...@paulsd.com] 
Sent: Monday, March 06, 2017 3:09 AM
To: Nick Fletcher ; 太田 真喜 Masaki Ota 

Cc: Joseph Salisbury ; b...@smart-cactus.org; 
mho...@suse.com; dmitry.torok...@gmail.com; pali.ro...@gmail.com; 
rydb...@bitmath.org; li...@roeck-us.net; open list:HID CORE LAYER 
; LKML ; 
sta...@vger.kernel.org
Subject: Re: [REGRESSION][v4.9.y][v4.10.y] Input: ALPS - set DualPoint flag for 
74 03 28 devices

Oops, forgot the attachments

On Sun, Mar 05, 2017 at 12:56:19PM -0500, Paul Donohue wrote:
> Masaki: Do you have any information about this touchpad you can share?  Is 
> the third byte in EC relevant to the protocol and something we should look 
> for when identifying devices in the driver?
> 
> Nick:
> 
> Unfortunately, I didn't print quite enough information in the two-finger 
> message, but yeah, this kinda looks like a different protocol.
> 
> I've attached two tarballs this time:
> 1) alps_2a.tar.gz prints some additional info in the two-finger message which 
> may help figure out what protocol your device is speaking:
> sudo -s
> dkms remove alps_ss5/1.0 --all
> cd /usr/src/
> rm -rf alps_ss5-1.0
> tar -xvzf alps_2a.tar.gz
> dkms install alps_ss5/1.0
> modprobe -r psmouse ; modprobe psmouse # Try two-finger scrolling, 
> then run:
> dmesg | grep 'two-finger'
> 
> 2) alps_2b.tar.gz disables the driver unless the third byte in EC is 0x13 
> (the value my device uses) ... This driver should make your mouse work 
> properly:
> sudo -s
> dkms remove alps_ss5/1.0 --all
> cd /usr/src/
> rm -rf alps_ss5-1.0
> tar -xvzf alps_2b.tar.gz
> dkms install alps_ss5/1.0
> modprobe -r psmouse ; modprobe psmouse
> 
> Try those out and let's see where that gets us.
> 
> When you are done testing, you can revert back to whatever driver came with 
> your kernel by running:
> sudo -s
> dkms remove alps_ss5/1.0 --all
> modprobe -r psmouse ; modprobe psmouse
> 
> -Paul
> 
> On Sun, Mar 05, 2017 at 09:09:01AM +, Nick Fletcher wrote:
> > Hi All,
> > 
> > My touchpad has the physical buttons above the touchpad.
> > 
> > I have cut and pasted the the results of the two dmesg commands 
> > below.  The trackpad of course stopped working correctly again after 
> > installing alps_ss5-1.0.
> > 
> > I'm afraid any experimenting with the code myself may be beyond my ability.
> > :-(
> > 
> > root@brassneck-test:/usr/src# modprobe -r psmouse ; modprobe psmouse 
> > root@brassneck-test:/usr/src# dmesg | grep 'ALPS ID'
> > [  239.983818] psmouse serio1: alps: ALPS ID: E7=73 03 28, EC=73 01 
> > 14 [  240.433532] psmouse serio1: alps: ALPS ID: E7=73 03 28, EC=73 
> > 01 14 root@brassneck-test:/usr/src# dmesg | grep two-finger [  
> > 279.294490] psmouse serio1: alps: ALPS two-finger packet w/ button
> > (buttonpad: 0): d9 73 24
> > 
> > 
> > Thank you for your help in this and thank you to Joseph for building 
> > all the test kernels whilst attempting to find out which commit 
> > first caused my issue.
> > 
> > Cheers,
> > Nick.
> > 
> > On 4 March 2017 at 16:15, Paul Donohue  wrote:
> > 
> > > I have a 74 03 28 device on a Dell Precision laptop that handles 
> > > two-finger scrolling fine.  Without this patch, my mouse functions 
> > > only as a dumb PS/2 mouse, which means I lose all multi-touch and 
> > > scrolling capabilities entirely.  So I would rather not see this 
> > > reverted. :)
> > >
> > > I suspect one of two things:
> > > 1) My device has physical buttons below the touchpad.  There are 
> > > some different code paths for devices without physical buttons 
> > > below the touchpad.  Perhaps there is a bug in those alternate 
> > > code paths?  Does the buggy device have physical buttons?
> > > 2) Perhaps this is a new ALP

RE: Unknown ALPS touchpad

2017-02-20 Thread Masaki Ota
Hi, Pali,

I know these devices, and they are supported in new kernel.
I'm not sure when they are supported from.
In alps.c has below code.

static int alps_identify(struct psmouse *psmouse, struct alps_data *priv)
{...
...
if (e7[0] == 0x73 && e7[1] == 0x03 && e7[2] == 0x50 &&
   ec[0] == 0x73 && (ec[1] == 0x01 || ec[1] == 0x02)) {
protocol = &alps_v5_protocol_data;
} else if (ec[0] == 0x88 &&
   ((ec[1] & 0xf0) == 0xb0 || (ec[1] & 0xf0) == 0xc0)) {
protocol = &alps_v7_protocol_data;}
}

E7=73 03 50, EC=73 02 02 <- alps_v5_protocol_data
E7=73 03 0a, EC=88 b3 22 <- alps_v7_protocol_data
E7=73 03 0a, EC=88 b3 18 <- alps_v7_protocol_data

Best Regards,
Masaki Ota
-Original Message-
From: Pali Rohár [mailto:pali.ro...@gmail.com] 
Sent: Tuesday, February 21, 2017 12:51 AM
To: Marcos Paulo de Souza ; 太田 真喜 Masaki Ota 

Cc: John Preston ; Dmitry Torokhov 
; linux-in...@vger.kernel.org; 
linux-kernel@vger.kernel.org
Subject: Unknown ALPS touchpad

Adding Masaki into discussion.

On Sunday 19 February 2017 20:01:07 Marcos Paulo de Souza wrote:
> There are other open bugs mentioning the same problem, with similar ALPS 
> devices:
> https://bugzilla.kernel.org/show_bug.cgi?id=57841

Unknown ALPS touchpad: E7=73 03 50, EC=73 02 02

> https://bugzilla.kernel.org/show_bug.cgi?id=43931

Unknown ALPS touchpad: E7=73 00 14, EC=10 00 64

Should be supported since commit 95f75e91 which was introduced in Linux version 
v3.13-rc4.

> https://bugzilla.kernel.org/show_bug.cgi?id=80181

Unknown ALPS touchpad: E7=73 03 0a, EC=88 b3 22

> https://bugzilla.kernel.org/show_bug.cgi?id=67941

Unknown ALPS touchpad: E7=73 03 0a, EC=88 b3 18

> This one without even a dmesg output:
> https://bugzilla.kernel.org/show_bug.cgi?id=84081

Sorry, this one does not contain any useful information.

> Maybe they are related, or  also need some touch to let them being discovered 
> as proper devices?

Masaki, can you look at those unknown ALPS touchpad identifiers and provide 
some information about protocol which they are using?

Basically touchpads with these identifiers are unsupported by last kernel 
version:

E7=73 03 50, EC=73 02 02
E7=73 03 0a, EC=88 b3 22
E7=73 03 0a, EC=88 b3 18

--
Pali Rohár
pali.ro...@gmail.com


[PATCH] Fix a issue that Alps Touchpad cursor does not work

2016-09-26 Thread Masaki Ota
fix Touchpad cursor does not work after touching Touchpad 
by 3 or more fingers.

Issue reproduction procedure
1.Three or more fingers put on Touchpad.
2.release fingers from Touchpad.
3.move the cursor by one finger.
4.the cursor does not move.

Cause
This code does not notify multi fingers state correctly to system.
For example, when three fingers release from Touchpad,
fingers state is 3 -> 0. It needs to notify
first, second and third finger's releasing state.
But this code does not notify second and third finger's
releasing state by "break" code.

Solution
Delete "break" code, and move xyz input code to the correct place.

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index 048befd..610df92 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -190,16 +190,16 @@ static int alps_raw_event(struct hid_device *hdev,
if (z != 0) {
input_mt_report_slot_state(hdata->input,
MT_TOOL_FINGER, 1);
+   input_report_abs(hdata->input,
+   ABS_MT_POSITION_X, x);
+   input_report_abs(hdata->input,
+   ABS_MT_POSITION_Y, y);
+   input_report_abs(hdata->input,
+   ABS_MT_PRESSURE, z);
} else {
input_mt_report_slot_state(hdata->input,
MT_TOOL_FINGER, 0);
-   break;
}
-
-   input_report_abs(hdata->input, ABS_MT_POSITION_X, x);
-   input_report_abs(hdata->input, ABS_MT_POSITION_Y, y);
-   input_report_abs(hdata->input, ABS_MT_PRESSURE, z);
-
}
 
input_mt_sync_frame(hdata->input);
-- 
2.7.4



[PATCH] Fix a issue that Alps Touchpad cursor does not work

2016-09-22 Thread Masaki Ota
fix Touchpad cursor does not work after touching Touchpad 
by 3 or more fingers.

Signed-off-by: Masaki Ota 
---
 drivers/hid/hid-alps.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index 048befd..610df92 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -190,16 +190,16 @@ static int alps_raw_event(struct hid_device *hdev,
if (z != 0) {
input_mt_report_slot_state(hdata->input,
MT_TOOL_FINGER, 1);
+   input_report_abs(hdata->input,
+   ABS_MT_POSITION_X, x);
+   input_report_abs(hdata->input,
+   ABS_MT_POSITION_Y, y);
+   input_report_abs(hdata->input,
+   ABS_MT_PRESSURE, z);
} else {
input_mt_report_slot_state(hdata->input,
MT_TOOL_FINGER, 0);
-   break;
}
-
-   input_report_abs(hdata->input, ABS_MT_POSITION_X, x);
-   input_report_abs(hdata->input, ABS_MT_POSITION_Y, y);
-   input_report_abs(hdata->input, ABS_MT_PRESSURE, z);
-
}
 
input_mt_sync_frame(hdata->input);
-- 
2.7.4