psmouse: add support for 4th button using the 4th bit
Subsystems (2)
RFC 1/1 psmouse: add support for 4th button using the 4th bit
Some mice like the Cortron Trackball use the fourth bit of the first byte (yes, that one that the protocol tells to be always 1, oh well) to represent the fourth button. This patch adds an option to use the fourth bit to represent the fourth button.
Please comment on this and please keep me on Cc list, I'm not subscribed to linux-input.
--- drivers/input/mouse/psmouse-base.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/input/mouse/psmouse-base.c +18 -0
@@ -64,6 +64,13 @@ static unsigned int psmouse_resync_time;module_param_named (resync_time, psmouse_resync_time, uint,0644 );MODULE_PARM_DESC (resync_time,"How long can mouse stay idle before forcing resync (in seconds, 0 = never)." ); +static unsigned int psmouse_4th_bit_as_button; +module_param_named(4th_bit_as_button, psmouse_4th_bit_as_button, uint, 0); +MODULE_PARM_DESC(4th_bit_as_button, "Interpret the 4th bit of the first byte " +"as 4th button. Some mice like Cortron Trackballs use the " +"4th bit (which should be always set) of the first byte as " +"4th button" ); +PSMOUSE_DEFINE_ATTR (protocol,S_IWUSR |S_IRUGO ,NULL , psmouse_attr_show_protocol, psmouse_attr_set_protocol);
@@ -176,6 +183,14 @@ static psmouse_ret_t psmouse_process_byt packet[1 ] |= (packet[0 ] &0x40 ) <<1 ; } +/* +* Use the 4th bit of the first package as button +*/ +if (psmouse_4th_bit_as_button) { +input_report_key (dev,BTN_SIDE , (packet[0 ] >>3 ) &1 ); + packet[0 ] |=0x08 ; + } +/* * Generic PS/2 Mouse */
@@ -643,6 +658,9 @@ static int psmouse_extensions(struct psmpsmouse_reset (psmouse); } +if (psmouse_4th_bit_as_button) +set_bit (BTN_SIDE , psmouse->dev->keybit); +return PSMOUSE_PS2 ; }
Dmitry Torokhov
maintainerHi Aristeu,
Quoted 8 lines · Aristeu Rozanski
Some mice like the Cortron Trackball use the fourth bit of the first byte (yes, that one that the protocol tells to be always 1, oh well) to represent the fourth button. This patch adds an option to use the fourth bit to represent the fourth button.
Please comment on this and please keep me on Cc list, I'm not subscribed to linux-input.
Do you know if there is a way (like a magic knock) that would allow to identify Cortron's devices? I don't like the module option too much, given the fact that it will affect all devices. Maybe we should define Cortron protocol instead and activate it manually via sysfs?
Signature · 1 line
Dmitry
Hi Dmitry,
Quoted 4 lines
Do you know if there is a way (like a magic knock) that would allow to identify Cortron's devices? I don't like the module option too much, given the fact that it will affect all devices. Maybe we should define Cortron protocol instead and activate it manually via sysfs?
there's no way to detect this Cortron device, it was my first try. Hm, the new protocol/sysfs idea seems to be much better, I didn't know that was possible. I'll rework the patch and resubmit.
Thanks!
Signature · 1 line
Aristeu
Dmitry Torokhov
maintainerQuoted 6 lines · Aristeu Rozanski
Hi Dmitry,
Quoted 4 lines
Do you know if there is a way (like a magic knock) that would allow to identify Cortron's devices? I don't like the module option too much, given the fact that it will affect all devices. Maybe we should define Cortron protocol instead and activate it manually via sysfs?
there's no way to detect this Cortron device, it was my first try.
That's unfortunate. BTW, is this your observation or did you ask Cortron and this was their response?
Quoted 3 lines
Hm, the
new protocol/sysfs idea seems to be much better, I didn't know that was possible. I'll rework the patch and resubmit.
You'd need to add something like this to psmouse_protocols[]:
{
.type = PSMOUSE_CORTRON,
.name = "CortronPS/2",
.alias = "cortps",
.detect = cortron_detect,
},
and then model cortron_detect after ps2bare_detect (where you don't actually detect anything, just force protocol).
Signature · 1 line
Dmitry
Quoted 2 lines
That's unfortunate. BTW, is this your observation or did you ask Cortron and this was their response?
The customer got in touch with Cortron about this and Cortron told it's not possible to detect it. I can try talking with them to make sure it's the case.
Quoted 11 lines
You'd need to add something like this to psmouse_protocols[]:
{
.type =PSMOUSE_CORTRON,
.name = "CortronPS/2",
.alias = "cortps",
.detect =cortron_detect,
},and then model
cortron_detectafterps2bare_detect(where you don't actually detect anything, just force protocol).
ok!
Thanks,
Signature · 1 line
Aristeu
Hi Dmitry,
Quoted 11 lines
You'd need to add something like this to psmouse_protocols[]:
{
.type =PSMOUSE_CORTRON,
.name = "CortronPS/2",
.alias = "cortps",
.detect =cortron_detect,
},and then model
cortron_detectafterps2bare_detect(where you don't actually detect anything, just force protocol).
we asked Cortron again about a possible auto-detection sequence but they didn't implemented anything in this matter. So I updated the patch according your recomendations and Chris tested again with the Trackball, with success. If you're ok with that, I'll resubmit it with proper description/signed-off-by header.
drivers/input/mouse/psmouse-base.c +29 -0
@@ -177,6 +177,15 @@ static psmouse_ret_t psmouse_process_byt }/* +* Cortron PS2 Trackball reports SIDE button on the 4th bit of the first +* byte. +*/ +if (psmouse->type ==PSMOUSE_CORTRON ) { +input_report_key (dev,BTN_SIDE , (packet[0 ] >>3 ) &1 ); + packet[0 ] |=0x08 ; + } + +/* * Generic PS/2 Mouse */
@@ -538,6 +547,20 @@ static int ps2bare_detect(struct psmousereturn 0 ; } +/* +* Cortron PS/2 protocol detection. There's no special way to detect it, so it +* must be forced by sysfs protocol writing. +*/ +static int cortron_detect (struct psmouse *psmouse,int set_properties) +{ +if (set_properties) { + psmouse->vendor ="Cortron" ; + psmouse->name ="PS/2 Trackball" ; +set_bit (BTN_SIDE , psmouse->dev->keybit); + } + +return 0 ; +}/* * psmouse_extensions() probes for any extensions to the basic PS/2 protocol
@@ -655,6 +678,12 @@ static const struct psmouse_protocol psm .detect = ps2bare_detect, }, { + .type = PSMOUSE_CORTRON, + .name = "CortronPS/2", + .alias = "cortps", + .detect = cortron_detect, + }, + { .type = PSMOUSE_PS2PP, .name = "PS2++", .alias = "logitech",
drivers/input/mouse/psmouse.h +1 -0
@@ -78,6 +78,7 @@ struct psmouse {enum psmouse_type {PSMOUSE_NONE ,PSMOUSE_PS2 , +PSMOUSE_CORTRON ,PSMOUSE_PS2PP ,PSMOUSE_THINKPS ,PSMOUSE_GENPS ,
Dmitry Torokhov
maintainerHi Aristeu,
Quoted 10 lines · Aristeu Rozanski
Hi Dmitry,
Quoted 9 lines
You'd need to add something like this to psmouse_protocols[]:
{
.type =PSMOUSE_CORTRON,
.name = "CortronPS/2",
.alias = "cortps",
.detect =cortron_detect,
},
Quoted 8 lines
Quoted 2 lines
and then model
cortron_detectafterps2bare_detect(where you don't actually detect anything, just force protocol).we asked Cortron again about a possible auto-detection sequence but they didn't implemented anything in this matter. So I updated the patch according your recomendations and Chris tested again with the Trackball, with success. If you're ok with that, I'll resubmit it with proper description/signed-off-by header.
Looks good, please resend. There may be issues with box losing manually set protocols when coming out of suspend but that's for another patch.
Thank you.
Signature · 1 line
Dmitry
PATCH 1/1 psmouse: add support for 4th button using the 4th bit
Cortron PS/2 Trackballs (700-0001A) reports the 4th button using the 4th bit of the first packet (yes, it breaks the protocol). This patch adds an extra protocol to generate BTN_SIDE based on the 4th bit. There's no way to detect those trackballs using any kind of special sequence, thus the protocol is only available if selected writing 'protocol' file in sysfs, e.g.:
echo -n "cortps" >/sys/devices/platform/i8042/serio1/protocol
drivers/input/mouse/psmouse-base.c +29 -0
@@ -177,6 +177,15 @@ static psmouse_ret_t psmouse_process_byt }/* +* Cortron PS2 Trackball reports SIDE button on the 4th bit of the first +* byte. +*/ +if (psmouse->type ==PSMOUSE_CORTRON ) { +input_report_key (dev,BTN_SIDE , (packet[0 ] >>3 ) &1 ); + packet[0 ] |=0x08 ; + } + +/* * Generic PS/2 Mouse */
@@ -538,6 +547,20 @@ static int ps2bare_detect(struct psmousereturn 0 ; } +/* +* Cortron PS/2 protocol detection. There's no special way to detect it, so it +* must be forced by sysfs protocol writing. +*/ +static int cortron_detect (struct psmouse *psmouse,int set_properties) +{ +if (set_properties) { + psmouse->vendor ="Cortron" ; + psmouse->name ="PS/2 Trackball" ; +set_bit (BTN_SIDE , psmouse->dev->keybit); + } + +return 0 ; +}/* * psmouse_extensions() probes for any extensions to the basic PS/2 protocol
@@ -655,6 +678,12 @@ static const struct psmouse_protocol psm .detect = ps2bare_detect, }, { + .type = PSMOUSE_CORTRON, + .name = "CortronPS/2", + .alias = "cortps", + .detect = cortron_detect, + }, + { .type = PSMOUSE_PS2PP, .name = "PS2++", .alias = "logitech",
drivers/input/mouse/psmouse.h +1 -0
@@ -78,6 +78,7 @@ struct psmouse {enum psmouse_type {PSMOUSE_NONE ,PSMOUSE_PS2 , +PSMOUSE_CORTRON ,PSMOUSE_PS2PP ,PSMOUSE_THINKPS ,PSMOUSE_GENPS ,
Dmitry Torokhov
maintainerdrivers/input/mouse/psmouse.h struct psmouse { · line 84
Quoted 11 lines · Aristeu Rozanski
drivers/input/mouse/psmouse.h +1
-0@@ -78,6 +78,7 @@ struct psmouse {enum psmouse_type {PSMOUSE_NONE ,PSMOUSE_PS2 , +PSMOUSE_CORTRON ,PSMOUSE_PS2PP ,PSMOUSE_THINKPS ,PSMOUSE_GENPS ,
I moved PSMOUSE_CORTRON to the end of the list - psmouse type is exported to userspace as input_dev.id.product and so we should not change existing types.
Signature · 1 line
Dmitry
Quoted 7 lines
Quoted 7 lines
drivers/input/mouse/psmouse.h +1
-0@@ -78,6 +78,7 @@ struct psmouse {enum psmouse_type {PSMOUSE_NONE ,PSMOUSE_PS2 , +PSMOUSE_CORTRON ,
Quoted 8 lines
drivers/input/mouse/psmouse.h struct psmouse { · line 84
Quoted 4 lines
drivers/input/mouse/psmouse.h +0
-0PSMOUSE_PS2PP ,PSMOUSE_THINKPS , PSMOUSE_GENPS,I moved
PSMOUSE_CORTRONto the end of the list - psmouse type is exported to userspace as input_dev.id.product and so we should not change existing types.
ok!
Signature · 1 line
Aristeu