@@ -237,6 +237,8 @@ struct atkbd {
struct mutex mutex;
struct vivaldi_data vdata;
+
+ DECLARE_BITMAP(ledon, LED_CNT);
};
/*
@@ -604,24 +606,32 @@ 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; \
+ __tmp; \
+})
+
static int atkbd_set_leds(struct atkbd *atkbd)
{
struct input_dev *dev = atkbd->dev;
unsigned char param[2];
- 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 +705,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;