Input: atkbd - fix LED state at suspend/resume
Subsystems (2)
PATCH 1/1 Input: atkbd - fix LED state at suspend/resume
After we turn on the keyboard CAPSL LED and let the system suspend, the keyboard LED is not off, and the kernel log is as follows:
[ 185.987574] i8042: [44060] ed -> i8042 (kbd-data) [ 185.988057] i8042: [44061] ** <- i8042 (interrupt, 0, 1) [ 185.988067] i8042: [44061] 04 -> i8042 (kbd-data) [ 185.988248] i8042: [44061] ** <- i8042 (interrupt, 0, 1)
The log shows that after the command 0xed is sent, the data sent is 0x04 instead of 0x00.
Solution:
Add a bitmap variable ledon in the atkbd structure, and then set ledon according to code-value in the event, in the atkbd_set_leds function, first look at the value of lenon, if it is 0, there is no need to look at the value of dev->led, otherwise, Need to look at dev->led to determine the keyboard LED on/off.
--- drivers/input/keyboard/atkbd.c | 35 +++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)
drivers/input/keyboard/atkbd.c +26 -9
@@ -237,6 +237,8 @@ struct atkbd {struct mutex mutex;struct vivaldi_data vdata; + +unsigned long ledon[BITS_TO_LONGS (LED_CNT )]; };/*
@@ -604,24 +606,34 @@ static int atkbd_set_repeat_rate(struct atkbd *atkbd)return ps2_command (&atkbd->ps2dev, ¶m,ATKBD_CMD_SETREP ); } +#define ATKBD_DO_LED_TOGGLE (dev, atkbd, type, v, bits, on) \ +({ \ + unsigned char __tmp = 0; \ + if (test_bit(LED_##type, atkbd->on)) \ + __tmp = test_bit(LED_##type, dev->bits) ? v : 0; \ + else \ + __tmp = 0; \ + __tmp; \ +}) +static int atkbd_set_leds (struct atkbd *atkbd) {struct input_dev *dev = atkbd->dev; -unsigned char param[2 ]; +unsigned char param[2 ] = {0 }; - param[0 ] = (test_bit (LED_SCROLLL , dev->led) ?1 :0 ) - | (test_bit (LED_NUML , dev->led) ?2 :0 ) - | (test_bit (LED_CAPSL , dev->led) ?4 :0 ); + param[0 ] =ATKBD_DO_LED_TOGGLE (dev, atkbd,SCROLLL ,1 , led, ledon) + |ATKBD_DO_LED_TOGGLE (dev, atkbd,NUML ,2 , led, ledon) + |ATKBD_DO_LED_TOGGLE (dev, atkbd,CAPSL ,4 , led, ledon);if (ps2_command (&atkbd->ps2dev, param,ATKBD_CMD_SETLEDS ))return -1 ;if (atkbd->extra) { param[0 ] =0 ; - param[1 ] = (test_bit (LED_COMPOSE , dev->led) ?0x01 :0 ) - | (test_bit (LED_SLEEP , dev->led) ?0x02 :0 ) - | (test_bit (LED_SUSPEND , dev->led) ?0x04 :0 ) - | (test_bit (LED_MISC , dev->led) ?0x10 :0 ) - | (test_bit (LED_MUTE , dev->led) ?0x20 :0 ); + param[1 ] =ATKBD_DO_LED_TOGGLE (dev, atkbd,COMPOSE ,0x01 , led, ledon) + |ATKBD_DO_LED_TOGGLE (dev, atkbd,SLEEP ,0x02 , led, ledon) + |ATKBD_DO_LED_TOGGLE (dev, atkbd,SUSPEND ,0x04 , led, ledon) + |ATKBD_DO_LED_TOGGLE (dev, atkbd,MISC ,0x10 , led, ledon) + |ATKBD_DO_LED_TOGGLE (dev, atkbd,MUTE ,0x20 , led, ledon);if (ps2_command (&atkbd->ps2dev, param,ATKBD_CMD_EX_SETLEDS ))return -1 ; }
@@ -695,6 +707,11 @@ static int atkbd_event(struct input_dev *dev,switch (type) {case EV_LED : +if (value) +__set_bit (code, atkbd->ledon); +else +__clear_bit (code, atkbd->ledon); +atkbd_schedule_event_work (atkbd,ATKBD_LED_EVENT_BIT );return 0 ;
Signature · 1 line
2.20.1
On Fri, 26 Jul 2024 18:27:30 +0800
Qiang Ma <[email protected]> wrote:
Sorry, add the correct email address: [email protected]
Quoted 111 lines
After we turn on the keyboard CAPSL LED and let the system suspend, the keyboard LED is not off, and the kernel log is as follows:
[ 185.987574] i8042: [44060] ed -> i8042 (kbd-data) [ 185.988057] i8042: [44061] ** <- i8042 (interrupt, 0, 1) [ 185.988067] i8042: [44061] 04 -> i8042 (kbd-data) [ 185.988248] i8042: [44061] ** <- i8042 (interrupt, 0, 1)The log shows that after the command
0xedis sent, the data sent is0x04instead of0x00.Solution:
Add a bitmap variable ledon in the atkbd structure, and then set ledon according to code-value in the event, in theatkbd_set_ledsfunction, first look at the value of lenon, if it is 0, there is no need to look at the value ofdev->led, otherwise, Need to look atdev->ledto determine the keyboard LED on/off.Signed-off-by Qiang Ma <[email protected]>--- drivers/input/keyboard/atkbd.c | 35+++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)
(quoted diff) +0
-0
b/drivers/input/keyboard/atkbd.cindex7f67f9f2946b..27d8f375929e100644 ---a/drivers/input/keyboard/atkbd.c
+++b/drivers/input/keyboard/atkbd.cdrivers/input/keyboard/atkbd.c +10
-0@@ -237,6 +237,8 @@ struct atkbd {struct mutex mutex;struct vivaldi_data vdata; + +unsigned long ledon[BITS_TO_LONGS (LED_CNT )]; };/* @@ -604,24 +606,34 @@ static int atkbd_set_repeat_rate(struct atkbd *atkbd) return ps2_command(&atkbd->ps2dev, ¶m, ATKBD_CMD_SETREP); } +#define ATKBD_DO_LED_TOGGLE (dev, atkbd, type, v, bits, on) \ +({ \ +unsigned char __tmp =0 ; \ + if (test_bit(LED_##type, atkbd->on)) \ + __tmp = test_bit(LED_##type, dev->bits) ? v :0 ; \ +else \ + __tmp =0 ; \ + __tmp;\ +}) +
static intatkbd_set_leds(struct atkbd *atkbd)
{drivers/input/keyboard/atkbd.c +2
-4struct input_dev *dev = atkbd->dev; -unsigned char param[2 ]; +unsigned char param[2 ] = {0 }; - param[0 ] = (test_bit (LED_SCROLLL , dev->led) ?1 :0 ) - | (test_bit (LED_NUML , dev->led) ?2 :0 ) - | (test_bit (LED_CAPSL , dev->led) ?4 :0 ); + param[0] = ATKBD_DO_LED_TOGGLE(dev, atkbd, SCROLLL, 1, led,ledon)
(quoted diff) +1
-0+ | ATKBD_DO_LED_TOGGLE(dev, atkbd, NUML, 2, led,ledon)
(quoted diff) +1
-0+ | ATKBD_DO_LED_TOGGLE(dev, atkbd, CAPSL, 4, led,ledon); if (
ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_SETLEDS))drivers/input/keyboard/atkbd.c +0
-1return -1 ;if (atkbd->extra) { param[0 ] =0 ; - param[1] = (test_bit(LED_COMPOSE, dev->led) ? 0x01 :0)
(quoted diff) +0
-1- | (test_bit(LED_SLEEP, dev->led) ? 0x02 :0)
(quoted diff) +0
-1- | (test_bit(LED_SUSPEND, dev->led) ? 0x04 :0)
(quoted diff) +0
-1- | (test_bit(LED_MISC, dev->led) ? 0x10 :0)
(quoted diff) +0
-1- | (test_bit(LED_MUTE, dev->led) ? 0x20 :0);
(quoted diff) +1
-0+ param[1] = ATKBD_DO_LED_TOGGLE(dev, atkbd, COMPOSE,
0x01, led, ledon)(quoted diff) +1
-0+ | ATKBD_DO_LED_TOGGLE(dev, atkbd, SLEEP,
0x02, led, ledon)(quoted diff) +1
-0+ | ATKBD_DO_LED_TOGGLE(dev, atkbd, SUSPEND,
0x04, led, ledon)(quoted diff) +1
-0+ | ATKBD_DO_LED_TOGGLE(dev, atkbd, MISC,
0x10, led, ledon)(quoted diff) +1
-0+ | ATKBD_DO_LED_TOGGLE(dev, atkbd, MUTE,
0x20, led, ledon); if (ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_EX_SETLEDS)) return -1;drivers/input/keyboard/atkbd.c +5
-0}@@ -695,6 +707,11 @@ static int atkbd_event(struct input_dev *dev,switch (type) {case EV_LED : +if (value) +__set_bit (code, atkbd->ledon); +else +__clear_bit (code, atkbd->ledon); +atkbd_schedule_event_work (atkbd,ATKBD_LED_EVENT_BIT );return 0 ;
On Fri, 26 Jul 2024 18:27:30 +0800
Qiang Ma <[email protected]> wrote:
Sorry, add the correct email address: [email protected]
Quoted 111 lines
After we turn on the keyboard CAPSL LED and let the system suspend, the keyboard LED is not off, and the kernel log is as follows:
[ 185.987574] i8042: [44060] ed -> i8042 (kbd-data) [ 185.988057] i8042: [44061] ** <- i8042 (interrupt, 0, 1) [ 185.988067] i8042: [44061] 04 -> i8042 (kbd-data) [ 185.988248] i8042: [44061] ** <- i8042 (interrupt, 0, 1)The log shows that after the command
0xedis sent, the data sent is0x04instead of0x00.Solution:
Add a bitmap variable ledon in the atkbd structure, and then set ledon according to code-value in the event, in theatkbd_set_ledsfunction, first look at the value of lenon, if it is 0, there is no need to look at the value ofdev->led, otherwise, Need to look atdev->ledto determine the keyboard LED on/off.Signed-off-by Qiang Ma <[email protected]>--- drivers/input/keyboard/atkbd.c | 35+++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)
(quoted diff) +0
-0
b/drivers/input/keyboard/atkbd.cindex7f67f9f2946b..27d8f375929e100644 ---a/drivers/input/keyboard/atkbd.c
+++b/drivers/input/keyboard/atkbd.cdrivers/input/keyboard/atkbd.c +10
-0@@ -237,6 +237,8 @@ struct atkbd {struct mutex mutex;struct vivaldi_data vdata; + +unsigned long ledon[BITS_TO_LONGS (LED_CNT )]; };/* @@ -604,24 +606,34 @@ static int atkbd_set_repeat_rate(struct atkbd *atkbd) return ps2_command(&atkbd->ps2dev, ¶m, ATKBD_CMD_SETREP); } +#define ATKBD_DO_LED_TOGGLE (dev, atkbd, type, v, bits, on) \ +({ \ +unsigned char __tmp =0 ; \ + if (test_bit(LED_##type, atkbd->on)) \ + __tmp = test_bit(LED_##type, dev->bits) ? v :0 ; \ +else \ + __tmp =0 ; \ + __tmp;\ +}) +
static intatkbd_set_leds(struct atkbd *atkbd)
{drivers/input/keyboard/atkbd.c +2
-4struct input_dev *dev = atkbd->dev; -unsigned char param[2 ]; +unsigned char param[2 ] = {0 }; - param[0 ] = (test_bit (LED_SCROLLL , dev->led) ?1 :0 ) - | (test_bit (LED_NUML , dev->led) ?2 :0 ) - | (test_bit (LED_CAPSL , dev->led) ?4 :0 ); + param[0] = ATKBD_DO_LED_TOGGLE(dev, atkbd, SCROLLL, 1, led,ledon)
(quoted diff) +1
-0+ | ATKBD_DO_LED_TOGGLE(dev, atkbd, NUML, 2, led,ledon)
(quoted diff) +1
-0+ | ATKBD_DO_LED_TOGGLE(dev, atkbd, CAPSL, 4, led,ledon); if (
ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_SETLEDS))drivers/input/keyboard/atkbd.c +0
-1return -1 ;if (atkbd->extra) { param[0 ] =0 ; - param[1] = (test_bit(LED_COMPOSE, dev->led) ? 0x01 :0)
(quoted diff) +0
-1- | (test_bit(LED_SLEEP, dev->led) ? 0x02 :0)
(quoted diff) +0
-1- | (test_bit(LED_SUSPEND, dev->led) ? 0x04 :0)
(quoted diff) +0
-1- | (test_bit(LED_MISC, dev->led) ? 0x10 :0)
(quoted diff) +0
-1- | (test_bit(LED_MUTE, dev->led) ? 0x20 :0);
(quoted diff) +1
-0+ param[1] = ATKBD_DO_LED_TOGGLE(dev, atkbd, COMPOSE,
0x01, led, ledon)(quoted diff) +1
-0+ | ATKBD_DO_LED_TOGGLE(dev, atkbd, SLEEP,
0x02, led, ledon)(quoted diff) +1
-0+ | ATKBD_DO_LED_TOGGLE(dev, atkbd, SUSPEND,
0x04, led, ledon)(quoted diff) +1
-0+ | ATKBD_DO_LED_TOGGLE(dev, atkbd, MISC,
0x10, led, ledon)(quoted diff) +1
-0+ | ATKBD_DO_LED_TOGGLE(dev, atkbd, MUTE,
0x20, led, ledon); if (ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_EX_SETLEDS)) return -1;drivers/input/keyboard/atkbd.c +5
-0}@@ -695,6 +707,11 @@ static int atkbd_event(struct input_dev *dev,switch (type) {case EV_LED : +if (value) +__set_bit (code, atkbd->ledon); +else +__clear_bit (code, atkbd->ledon); +atkbd_schedule_event_work (atkbd,ATKBD_LED_EVENT_BIT );return 0 ;
Le 26/07/2024 à 12:27, Qiang Ma a écrit :
Quoted 8 lines
After we turn on the keyboard CAPSL LED and let the system suspend, the keyboard LED is not off, and the kernel log is as follows:
[ 185.987574] i8042: [44060] ed -> i8042 (kbd-data) [ 185.988057] i8042: [44061] ** <- i8042 (interrupt, 0, 1) [ 185.988067] i8042: [44061] 04 -> i8042 (kbd-data) [ 185.988248] i8042: [44061] ** <- i8042 (interrupt, 0, 1)
Quoted 6 lines
The log shows that after the command
0xedis sent, the data sent is0x04instead of0x00.Solution:
Add a bitmap variable ledon in the atkbd structure, and then set ledon according to code-value in the event, in theatkbd_set_ledsfunction,
Hi,
s/atkbd_set_leds function/atkbd_set_leds()/
Quoted 1 line
first look at the value of lenon, if it is 0, there is no need to
s/lenon/ledon/
Quoted 1 line
look at the value of
dev->led, otherwise, Need to look atdev->led
s/Need/need/
Quoted 12 lines
to determine the keyboard LED on/off.
Signed-off-by Qiang Ma <[email protected]>--- drivers/input/keyboard/atkbd.c | 35 +++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)drivers/input/keyboard/atkbd.c +0
-0
drivers/input/keyboard/atkbd.c struct atkbd { · line 241
Quoted 5 lines
drivers/input/keyboard/atkbd.c +2
-0@@ -237,6 +237,8 @@ struct atkbd {struct mutex mutex;struct vivaldi_data vdata; + +unsigned long ledon[BITS_TO_LONGS (LED_CNT )];
DECLARE_BITMAP()?
Quoted 4 lines
drivers/input/keyboard/atkbd.c +0
-0};/*
drivers/input/keyboard/atkbd.c static int atkbd_set_repeat_rate(struct atkbd *atkbd) · line 615
Quoted 10 lines
drivers/input/keyboard/atkbd.c +7
-0@@ -604,24 +606,34 @@ static int atkbd_set_repeat_rate(struct atkbd *atkbd)return ps2_command (&atkbd->ps2dev, ¶m,ATKBD_CMD_SETREP ); } +#define ATKBD_DO_LED_TOGGLE (dev, atkbd, type, v, bits, on) \ +({ \ + unsigned char __tmp = 0; \ + if (test_bit(LED_##type, atkbd->on)) \ + __tmp = test_bit(LED_##type, dev->bits) ? v : 0; \ + else \ + __tmp = 0; \
Is it needed? __tmp is already initialized as 0.
drivers/input/keyboard/atkbd.c static int atkbd_set_repeat_rate(struct atkbd *atkbd) · line 622
Quoted 8 lines
drivers/input/keyboard/atkbd.c +4
-1+ __tmp; \ +}) +static int atkbd_set_leds (struct atkbd *atkbd) {struct input_dev *dev = atkbd->dev; -unsigned char param[2 ]; +unsigned char param[2 ] = {0 };
This extra initialization does not seem necessary. IIUC, the length to sent is already encoded in ATKBD_CMD_SETLEDS and ATKBD_CMD_EX_SETLEDS.
Quoted 37 lines
drivers/input/keyboard/atkbd.c +13
-8- param[0 ] = (test_bit (LED_SCROLLL , dev->led) ?1 :0 ) - | (test_bit (LED_NUML , dev->led) ?2 :0 ) - | (test_bit (LED_CAPSL , dev->led) ?4 :0 ); + param[0 ] =ATKBD_DO_LED_TOGGLE (dev, atkbd,SCROLLL ,1 , led, ledon) + |ATKBD_DO_LED_TOGGLE (dev, atkbd,NUML ,2 , led, ledon) + |ATKBD_DO_LED_TOGGLE (dev, atkbd,CAPSL ,4 , led, ledon);if (ps2_command (&atkbd->ps2dev, param,ATKBD_CMD_SETLEDS ))return -1 ;if (atkbd->extra) { param[0 ] =0 ; - param[1 ] = (test_bit (LED_COMPOSE , dev->led) ?0x01 :0 ) - | (test_bit (LED_SLEEP , dev->led) ?0x02 :0 ) - | (test_bit (LED_SUSPEND , dev->led) ?0x04 :0 ) - | (test_bit (LED_MISC , dev->led) ?0x10 :0 ) - | (test_bit (LED_MUTE , dev->led) ?0x20 :0 ); + param[1 ] =ATKBD_DO_LED_TOGGLE (dev, atkbd,COMPOSE ,0x01 , led, ledon) + |ATKBD_DO_LED_TOGGLE (dev, atkbd,SLEEP ,0x02 , led, ledon) + |ATKBD_DO_LED_TOGGLE (dev, atkbd,SUSPEND ,0x04 , led, ledon) + |ATKBD_DO_LED_TOGGLE (dev, atkbd,MISC ,0x10 , led, ledon) + |ATKBD_DO_LED_TOGGLE (dev, atkbd,MUTE ,0x20 , led, ledon);if (ps2_command (&atkbd->ps2dev, param,ATKBD_CMD_EX_SETLEDS ))return -1 ; }@@ -695,6 +707,11 @@ static int atkbd_event(struct input_dev *dev,switch (type) {case EV_LED : +if (value) +__set_bit (code, atkbd->ledon); +else +__clear_bit (code, atkbd->ledon); +atkbd_schedule_event_work (atkbd,ATKBD_LED_EVENT_BIT );return 0 ;
Quoted 21 lines · On Fri, 26 Jul 2024 16:43:54 +0200 Christophe JAILLET…
Le 26/07/2024 à 12:27, Qiang Ma a écrit :
Quoted 8 lines
After we turn on the keyboard CAPSL LED and let the system suspend, the keyboard LED is not off, and the kernel log is as follows:
[ 185.987574] i8042: [44060] ed -> i8042 (kbd-data) [ 185.988057] i8042: [44061] ** <- i8042 (interrupt, 0, 1) [ 185.988067] i8042: [44061] 04 -> i8042 (kbd-data) [ 185.988248] i8042: [44061] ** <- i8042 (interrupt, 0, 1)Quoted 7 lines
The log shows that after the command
0xedis sent, the data sent is0x04instead of0x00.Solution:
Add a bitmap variable ledon in the atkbd structure, and then set ledon according to code-value in the event, in theatkbd_set_ledsfunction,Hi,
s/atkbd_set_leds function/atkbd_set_leds()/
Quoted 8 lines
Quoted 1 line
first look at the value of lenon, if it is 0, there is no need to
s/lenon/ledon/
Quoted 1 line
look at the value of
dev->led, otherwise, Need to look atdev->leds/Need/need/
Thank you very much for pointing it out, I will fix it in the V2 patch version.
Quoted 15 lines
Quoted 15 lines
to determine the keyboard LED on/off.
Signed-off-by Qiang Ma <[email protected]>--- drivers/input/keyboard/atkbd.c | 35+++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)
(quoted diff) +0
-0
b/drivers/input/keyboard/atkbd.cindex7f67f9f2946b..27d8f375929e100644 ---a/drivers/input/keyboard/atkbd.c
+++b/drivers/input/keyboard/atkbd.cdrivers/input/keyboard/atkbd.c +0
-0@@ -237,6 +237,8 @@ struct atkbd {struct mutex mutex;
Quoted 6 lines
drivers/input/keyboard/atkbd.c struct atkbd { · line 241
Quoted 3 lines
drivers/input/keyboard/atkbd.c +2
-0struct vivaldi_data vdata; + +unsigned long ledon[BITS_TO_LONGS (LED_CNT )];
DECLARE_BITMAP()?
Refer to dev->led, instead of calling DECLARE_BITMAP(), consider using it.
Quoted 16 lines
Quoted 16 lines
(quoted diff) +5
-0}; /*@@ -604,24 +606,34 @@ static int atkbd_set_repeat_rate(struct atkbd *atkbd) return ps2_command(&atkbd->ps2dev, ¶m, ATKBD_CMD_SETREP); } +#define ATKBD_DO_LED_TOGGLE(dev, atkbd, type, v, bits, on) \ +({ \ + unsigned char __tmp = 0; \ + if (test_bit(LED_##type, atkbd->on)) \ + __tmp = test_bit(LED_##type, dev->bits) ? v :
Quoted 8 lines
Quoted 6 lines
(quoted diff) +1
-00; \ +else
\(quoted diff) +1
-0+ __tmp =0; \
Is it needed?
__tmpis already initialized as 0.
It's really not necessary.
Quoted 14 lines
drivers/input/keyboard/atkbd.c static int atkbd_set_repeat_rate(struct atkbd *atkbd) · line 622
Quoted 9 lines
+
__tmp;
\ +}) +
static intatkbd_set_leds(struct atkbd *atkbd)
{
structinput_dev*dev =atkbd->dev;drivers/input/keyboard/atkbd.c +1
-1-unsigned char param[2 ]; +unsigned char param[2 ] = {0 };This extra initialization does not seem necessary. IIUC, the length to sent is already encoded in
ATKBD_CMD_SETLEDSandATKBD_CMD_EX_SETLEDS.
Looking again at the ps2_command function, yes, the length to sent is already encoded in ATKBD_CMD_SETLEDS and ATKBD_CMD_EX_SETLEDS.
Quoted 39 lines
Quoted 39 lines
drivers/input/keyboard/atkbd.c +1
-3- param[0 ] = (test_bit (LED_SCROLLL , dev->led) ?1 :0 ) - | (test_bit (LED_NUML , dev->led) ?2 :0 ) - | (test_bit (LED_CAPSL , dev->led) ?4 :0 ); + param[0] = ATKBD_DO_LED_TOGGLE(dev, atkbd, SCROLLL, 1,led, ledon)
(quoted diff) +1
-0+ | ATKBD_DO_LED_TOGGLE(dev, atkbd, NUML, 2,led, ledon)
(quoted diff) +1
-0+ | ATKBD_DO_LED_TOGGLE(dev, atkbd, CAPSL, 4,led, ledon); if (
ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_SETLEDS)) return -1;if (atkbd->extra) { param[0] = 0;(quoted diff) +0
-1- param[1] = (test_bit(LED_COMPOSE, dev->led) ?
0x01: 0)(quoted diff) +0
-1- | (test_bit(LED_SLEEP, dev->led) ?
0x02: 0)(quoted diff) +0
-1- | (test_bit(LED_SUSPEND, dev->led) ?
0x04: 0)(quoted diff) +0
-1- | (test_bit(LED_MISC, dev->led) ?
0x10: 0)(quoted diff) +0
-1- | (test_bit(LED_MUTE, dev->led) ?
0x20: 0);(quoted diff) +1
-0+ param[1] = ATKBD_DO_LED_TOGGLE(dev, atkbd,COMPOSE,
0x01, led, ledon)(quoted diff) +1
-0+ | ATKBD_DO_LED_TOGGLE(dev, atkbd,SLEEP,
0x02, led, ledon)(quoted diff) +1
-0+ | ATKBD_DO_LED_TOGGLE(dev, atkbd,SUSPEND,
0x04, led, ledon)(quoted diff) +1
-0+ | ATKBD_DO_LED_TOGGLE(dev, atkbd,MISC,
0x10, led, ledon)(quoted diff) +1
-0+ | ATKBD_DO_LED_TOGGLE(dev, atkbd,MUTE,
0x20, led, ledon); if (ps2_command(&atkbd->ps2dev, param,ATKBD_CMD_EX_SETLEDS)) return -1;
}drivers/input/keyboard/atkbd.c +0
-0@@ -695,6 +707,11 @@ static int atkbd_event(struct input_dev *dev,switch (type) {
Quoted 11 lines
drivers/input/keyboard/atkbd.c static int atkbd_event(struct input_dev *dev, · line 717
Quoted 9 lines
drivers/input/keyboard/atkbd.c +5
-0case EV_LED : +if (value) +__set_bit (code, atkbd->ledon); +else +__clear_bit (code, atkbd->ledon); +atkbd_schedule_event_work (atkbd,ATKBD_LED_EVENT_BIT );return 0 ;
Thank review, I will fix them in the v2 patch version.
Dmitry Torokhov
maintainerHi Qiang,
Quoted 11 lines · Qiang Ma
After we turn on the keyboard CAPSL LED and let the system suspend, the keyboard LED is not off, and the kernel log is as follows:
[ 185.987574] i8042: [44060] ed -> i8042 (kbd-data) [ 185.988057] i8042: [44061] ** <- i8042 (interrupt, 0, 1) [ 185.988067] i8042: [44061] 04 -> i8042 (kbd-data) [ 185.988248] i8042: [44061] ** <- i8042 (interrupt, 0, 1)The log shows that after the command
0xedis sent, the data sent is0x04instead of0x00.
Quoted 6 lines
Solution:
Add a bitmap variable ledon in the atkbd structure, and then set ledon according to code-value in the event, in theatkbd_set_ledsfunction, first look at the value of lenon, if it is 0, there is no need to look at the value ofdev->led, otherwise, Need to look atdev->ledto determine the keyboard LED on/off.
I am not sure why duplicating input_dev->led which is supposed to record which LEDs are currently active on an input device would solve the issue. Could you please explain?
The input core is supposed to turn off all LEDs on suspend. This happens in input_dev_toggle() which is called from input_dev_suspend(). It iterates over all LEDs on a device and turns off active ones one by one.
I think what happens here is we are running afoul of the throttling done in atkbd (see atkbd_schedule_event_work), and it does not actually turn off all LEDs in time. But on the other hand atkbd_cleanup() (which is called to suspend the keyboard) calls
ps2_command(&atkbd->ps2dev, NULL, ATKBD_CMD_RESET_DEF);
which should turn off everything anyways.
I think we need better understand what is going on here. Maybe post the entire communication between the kernel and i8042?
Thanks.
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerQuoted 21 lines · Dmitry Torokhov
Hi Qiang,
Quoted 11 lines · Qiang Ma
After we turn on the keyboard CAPSL LED and let the system suspend, the keyboard LED is not off, and the kernel log is as follows:
[ 185.987574] i8042: [44060] ed -> i8042 (kbd-data) [ 185.988057] i8042: [44061] ** <- i8042 (interrupt, 0, 1) [ 185.988067] i8042: [44061] 04 -> i8042 (kbd-data) [ 185.988248] i8042: [44061] ** <- i8042 (interrupt, 0, 1)The log shows that after the command
0xedis sent, the data sent is0x04instead of0x00.Quoted 6 lines
Solution:
Add a bitmap variable ledon in the atkbd structure, and then set ledon according to code-value in the event, in theatkbd_set_ledsfunction, first look at the value of lenon, if it is 0, there is no need to look at the value ofdev->led, otherwise, Need to look atdev->ledto determine the keyboard LED on/off.
Quoted 3 lines
I am not sure why duplicating
input_dev->ledwhich is supposed to record which LEDs are currently active on an input device would solve the issue. Could you please explain?
Ah, OK, I see it now. We do not actually toggle input_dev->led when suspending, so atkbd uses wrong data to determine the LED state.
Quoted 6 lines
The input core is supposed to turn off all LEDs on suspend. This happens in
input_dev_toggle()which is called frominput_dev_suspend(). It iterates over all LEDs on a device and turns off active ones one by one.
Quoted 8 lines
I think what happens here is we are running afoul of the throttling done in atkbd (see
atkbd_schedule_event_work), and it does not actually turn off all LEDs in time. But on the other handatkbd_cleanup()(which is called to suspend the keyboard) callsps2_command(&atkbd->ps2dev, NULL, ATKBD_CMD_RESET_DEF);which should turn off everything anyways.
But still, why ATKBD_CMD_RESET_DEF does not shut off the LEDs for you?
Thanks.
Signature · 1 line
Dmitry
On Fri, 26 Jul 2024 14:57:03 -0700
Dmitry Torokhov <[email protected]> wrote:
Hi Dmitry,
Quoted 21 lines
Hi Qiang,
Quoted 11 lines · Qiang Ma
After we turn on the keyboard CAPSL LED and let the system suspend, the keyboard LED is not off, and the kernel log is as follows:
[ 185.987574] i8042: [44060] ed -> i8042 (kbd-data) [ 185.988057] i8042: [44061] ** <- i8042 (interrupt, 0, 1) [ 185.988067] i8042: [44061] 04 -> i8042 (kbd-data) [ 185.988248] i8042: [44061] ** <- i8042 (interrupt, 0, 1)The log shows that after the command
0xedis sent, the data sent is0x04instead of0x00.Quoted 6 lines
Solution:
Add a bitmap variable ledon in the atkbd structure, and then set ledon according to code-value in the event, in theatkbd_set_ledsfunction, first look at the value of lenon, if it is 0, there is no need to look at the value ofdev->led, otherwise, Need to look atdev->ledto determine the keyboard LED on/off.
Quoted 3 lines
I am not sure why duplicating
input_dev->ledwhich is supposed to record which LEDs are currently active on an input device would solve the issue. Could you please explain?
At this point, the suspend purpose is to turn off the led(calling input_dev_toggle(input_dev, false) in function input_dev_suspend()), but the dev->led gets the status is on, so it will not turn off the led.
Quoted 6 lines
The input core is supposed to turn off all LEDs on suspend. This happens in
input_dev_toggle()which is called frominput_dev_suspend(). It iterates over all LEDs on a device and turns off active ones one by one.
Quoted 8 lines
I think what happens here is we are running afoul of the throttling done in atkbd (see
atkbd_schedule_event_work), and it does not actually turn off all LEDs in time. But on the other handatkbd_cleanup()(which is called to suspend the keyboard) callsps2_command(&atkbd->ps2dev, NULL, ATKBD_CMD_RESET_DEF);which should turn off everything anyways.
Send reset command under the actual test did not turn off the led, get it just reset the i8042 register? Did not change the led corresponding gpio status?
Quoted 6 lines
I think we need better understand what is going on here. Maybe post the entire communication between the kernel and i8042?
Thanks.
---
Qiang
A message that is not in the archive (sent off-list or not yet received): 20240730101708.50fa6734@john-PC
Quoted 47 lines · On Tue, 30 Jul 2024 10:17:08 +0800 Qiang Ma <[email protected]> wrote:
On Fri, 26 Jul 2024 14:57:03 -0700
Dmitry Torokhov <[email protected]> wrote:Hi Dmitry,
Quoted 22 lines
Hi Qiang,
Quoted 12 lines · Qiang Ma
After we turn on the keyboard CAPSL LED and let the system suspend, the keyboard LED is not off, and the kernel log is as follows:
[ 185.987574] i8042: [44060] ed -> i8042 (kbd-data) [ 185.988057] i8042: [44061] ** <- i8042 (interrupt, 0, 1) [ 185.988067] i8042: [44061] 04 -> i8042 (kbd-data) [ 185.988248] i8042: [44061] ** <- i8042 (interrupt, 0, 1)The log shows that after the command
0xedis sent, the data sent is0x04instead of0x00.Quoted 6 lines
Solution:
Add a bitmap variable ledon in the atkbd structure, and then set ledon according to code-value in the event, in theatkbd_set_ledsfunction, first look at the value of lenon, if it is 0, there is no need to look at the value ofdev->led, otherwise, Need to look atdev->ledto determine the keyboard LED on/off.Quoted 3 lines
I am not sure why duplicating
input_dev->ledwhich is supposed to record which LEDs are currently active on an input device would solve the issue. Could you please explain?At this point, the suspend purpose is to turn off the
led(calling input_dev_toggle(input_dev, false) in function input_dev_suspend()), but thedev->ledgets the status is on, so it will not turn off the led.Quoted 11 lines
The input core is supposed to turn off all LEDs on suspend. This happens in
input_dev_toggle()which is called frominput_dev_suspend(). It iterates over all LEDs on a device and turns off active ones one by one.I think what happens here is we are running afoul of the throttling done in atkbd (see
atkbd_schedule_event_work), and it does not actually turn off all LEDs in time. But on the other handatkbd_cleanup()(which is called to suspend the keyboard) calls
Quoted 12 lines
Quoted 3 lines
ps2_command(&atkbd->ps2dev, NULL, ATKBD_CMD_RESET_DEF);which should turn off everything anyways.
Send reset command under the actual test did not turn off the led, get it just reset the i8042 register? Did not change the led corresponding gpio status?
Quoted 4 lines
I think we need better understand what is going on here. Maybe post the entire communication between the kernel and i8042?
Description of ps/2 keyboard interface on this website(http://www-ug.eecg.toronto.edu/msl/nios_devices/datasheets/PS2%20Keyboard%20Protocol.htm):
0xF6 (Set Default) - Load default typematic rate/delay (10.9cps / 500ms), key types (all keys typematic/make/break), and scan code set (2).
It seems that sending this F6 reset command does not mention what effect it has on the LED.
Quoted 5 lines
Quoted 2 lines
Thanks.
---
Qiang
Quoted 23 lines · On Fri, 26 Jul 2024 14:57:03 -0700 Dmitry Torokhov <[email protected]>…
Quoted 22 lines · Dmitry Torokhov
Hi Qiang,
Quoted 18 lines · Qiang Ma
After we turn on the keyboard CAPSL LED and let the system suspend, the keyboard LED is not off, and the kernel log is as follows:
[ 185.987574] i8042: [44060] ed -> i8042 (kbd-data) [ 185.988057] i8042: [44061] ** <- i8042 (interrupt, 0, 1) [ 185.988067] i8042: [44061] 04 -> i8042 (kbd-data) [ 185.988248] i8042: [44061] ** <- i8042 (interrupt, 0, 1)The log shows that after the command
0xedis sent, the data sent is0x04instead of0x00.Solution:
Add a bitmap variable ledon in the atkbd structure, and then set ledon according to code-value in the event, in theatkbd_set_ledsfunction, first look at the value of lenon, if it is 0, there is no need to look at the value ofdev->led, otherwise, Need to look atdev->ledto determine the keyboard LED on/off.
Quoted 7 lines
Quoted 3 lines
I am not sure why duplicating
input_dev->ledwhich is supposed to record which LEDs are currently active on an input device would solve the issue. Could you please explain?Ah, OK, I see it now. We do not actually toggle
input_dev->ledwhen suspending, so atkbd uses wrong data to determine the LED state.
Yes, that's true.
Quoted 11 lines
Quoted 11 lines
The input core is supposed to turn off all LEDs on suspend. This happens in
input_dev_toggle()which is called frominput_dev_suspend(). It iterates over all LEDs on a device and turns off active ones one by one.I think what happens here is we are running afoul of the throttling done in atkbd (see
atkbd_schedule_event_work), and it does not actually turn off all LEDs in time. But on the other handatkbd_cleanup()(which is called to suspend the keyboard) calls
Quoted 6 lines
Quoted 3 lines
ps2_command(&atkbd->ps2dev, NULL, ATKBD_CMD_RESET_DEF);which should turn off everything anyways.
But still, why
ATKBD_CMD_RESET_DEFdoes not shut off the LEDs for you?
Looking at a ps/2 keyboard document(http://www-ug.eecg.toronto.edu/msl/nios_devices/datasheets/PS2%20Keyboard%20Protocol.htm), the F6 command does not seem to affect the state of the LED.
Quoted 4 lines
Thanks.
Signature · 1 line
Dmitry
--
Qiang