Input: atkbd - restore repeat rate when resuming

Make the AT keyboard driver restore previously set repeat rate
when resuming. Noticed by Linus Torvalds.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

+60 -43
+60 -43
drivers/input/keyboard/atkbd.c
··· 482 return IRQ_HANDLED; 483 } 484 485 /* 486 * atkbd_event_work() is used to complete processing of events that 487 * can not be processed by input_event() which is often called from ··· 539 540 static void atkbd_event_work(void *data) 541 { 542 - const short period[32] = 543 - { 33, 37, 42, 46, 50, 54, 58, 63, 67, 75, 83, 92, 100, 109, 116, 125, 544 - 133, 149, 167, 182, 200, 217, 232, 250, 270, 303, 333, 370, 400, 435, 470, 500 }; 545 - const short delay[4] = 546 - { 250, 500, 750, 1000 }; 547 - 548 struct atkbd *atkbd = data; 549 - struct input_dev *dev = atkbd->dev; 550 - unsigned char param[2]; 551 - int i, j; 552 553 mutex_lock(&atkbd->event_mutex); 554 555 - if (test_and_clear_bit(ATKBD_LED_EVENT_BIT, &atkbd->event_mask)) { 556 - param[0] = (test_bit(LED_SCROLLL, dev->led) ? 1 : 0) 557 - | (test_bit(LED_NUML, dev->led) ? 2 : 0) 558 - | (test_bit(LED_CAPSL, dev->led) ? 4 : 0); 559 - ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_SETLEDS); 560 561 - if (atkbd->extra) { 562 - param[0] = 0; 563 - param[1] = (test_bit(LED_COMPOSE, dev->led) ? 0x01 : 0) 564 - | (test_bit(LED_SLEEP, dev->led) ? 0x02 : 0) 565 - | (test_bit(LED_SUSPEND, dev->led) ? 0x04 : 0) 566 - | (test_bit(LED_MISC, dev->led) ? 0x10 : 0) 567 - | (test_bit(LED_MUTE, dev->led) ? 0x20 : 0); 568 - ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_EX_SETLEDS); 569 - } 570 - } 571 - 572 - if (test_and_clear_bit(ATKBD_REP_EVENT_BIT, &atkbd->event_mask)) { 573 - i = j = 0; 574 - while (i < 31 && period[i] < dev->rep[REP_PERIOD]) 575 - i++; 576 - while (j < 3 && delay[j] < dev->rep[REP_DELAY]) 577 - j++; 578 - dev->rep[REP_PERIOD] = period[i]; 579 - dev->rep[REP_DELAY] = delay[j]; 580 - param[0] = i | (j << 5); 581 - ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_SETREP); 582 - } 583 584 mutex_unlock(&atkbd->event_mutex); 585 } ··· 992 { 993 struct atkbd *atkbd = serio_get_drvdata(serio); 994 struct serio_driver *drv = serio->drv; 995 - unsigned char param[1]; 996 997 if (!atkbd || !drv) { 998 printk(KERN_DEBUG "atkbd: reconnect request, but serio is disconnected, ignoring...\n"); ··· 1001 atkbd_disable(atkbd); 1002 1003 if (atkbd->write) { 1004 - param[0] = (test_bit(LED_SCROLLL, atkbd->dev->led) ? 1 : 0) 1005 - | (test_bit(LED_NUML, atkbd->dev->led) ? 2 : 0) 1006 - | (test_bit(LED_CAPSL, atkbd->dev->led) ? 4 : 0); 1007 - 1008 if (atkbd_probe(atkbd)) 1009 return -1; 1010 if (atkbd->set != atkbd_select_set(atkbd, atkbd->set, atkbd->extra)) ··· 1008 1009 atkbd_activate(atkbd); 1010 1011 - if (ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_SETLEDS)) 1012 - return -1; 1013 } 1014 1015 atkbd_enable(atkbd);
··· 482 return IRQ_HANDLED; 483 } 484 485 + static int atkbd_set_repeat_rate(struct atkbd *atkbd) 486 + { 487 + const short period[32] = 488 + { 33, 37, 42, 46, 50, 54, 58, 63, 67, 75, 83, 92, 100, 109, 116, 125, 489 + 133, 149, 167, 182, 200, 217, 232, 250, 270, 303, 333, 370, 400, 435, 470, 500 }; 490 + const short delay[4] = 491 + { 250, 500, 750, 1000 }; 492 + 493 + struct input_dev *dev = atkbd->dev; 494 + unsigned char param; 495 + int i = 0, j = 0; 496 + 497 + while (i < ARRAY_SIZE(period) - 1 && period[i] < dev->rep[REP_PERIOD]) 498 + i++; 499 + dev->rep[REP_PERIOD] = period[i]; 500 + 501 + while (j < ARRAY_SIZE(period) - 1 && delay[j] < dev->rep[REP_DELAY]) 502 + j++; 503 + dev->rep[REP_DELAY] = delay[j]; 504 + 505 + param = i | (j << 5); 506 + return ps2_command(&atkbd->ps2dev, &param, ATKBD_CMD_SETREP); 507 + } 508 + 509 + static int atkbd_set_leds(struct atkbd *atkbd) 510 + { 511 + struct input_dev *dev = atkbd->dev; 512 + unsigned char param[2]; 513 + 514 + param[0] = (test_bit(LED_SCROLLL, dev->led) ? 1 : 0) 515 + | (test_bit(LED_NUML, dev->led) ? 2 : 0) 516 + | (test_bit(LED_CAPSL, dev->led) ? 4 : 0); 517 + if (ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_SETLEDS)) 518 + return -1; 519 + 520 + if (atkbd->extra) { 521 + param[0] = 0; 522 + param[1] = (test_bit(LED_COMPOSE, dev->led) ? 0x01 : 0) 523 + | (test_bit(LED_SLEEP, dev->led) ? 0x02 : 0) 524 + | (test_bit(LED_SUSPEND, dev->led) ? 0x04 : 0) 525 + | (test_bit(LED_MISC, dev->led) ? 0x10 : 0) 526 + | (test_bit(LED_MUTE, dev->led) ? 0x20 : 0); 527 + if (ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_EX_SETLEDS)) 528 + return -1; 529 + } 530 + 531 + return 0; 532 + } 533 + 534 /* 535 * atkbd_event_work() is used to complete processing of events that 536 * can not be processed by input_event() which is often called from ··· 490 491 static void atkbd_event_work(void *data) 492 { 493 struct atkbd *atkbd = data; 494 495 mutex_lock(&atkbd->event_mutex); 496 497 + if (test_and_clear_bit(ATKBD_LED_EVENT_BIT, &atkbd->event_mask)) 498 + atkbd_set_leds(atkbd); 499 500 + if (test_and_clear_bit(ATKBD_REP_EVENT_BIT, &atkbd->event_mask)) 501 + atkbd_set_repeat_rate(atkbd); 502 503 mutex_unlock(&atkbd->event_mutex); 504 } ··· 975 { 976 struct atkbd *atkbd = serio_get_drvdata(serio); 977 struct serio_driver *drv = serio->drv; 978 979 if (!atkbd || !drv) { 980 printk(KERN_DEBUG "atkbd: reconnect request, but serio is disconnected, ignoring...\n"); ··· 985 atkbd_disable(atkbd); 986 987 if (atkbd->write) { 988 if (atkbd_probe(atkbd)) 989 return -1; 990 if (atkbd->set != atkbd_select_set(atkbd, atkbd->set, atkbd->extra)) ··· 996 997 atkbd_activate(atkbd); 998 999 + /* 1000 + * Restore repeat rate and LEDs (that were reset by atkbd_activate) 1001 + * to pre-resume state 1002 + */ 1003 + if (!atkbd->softrepeat) 1004 + atkbd_set_repeat_rate(atkbd); 1005 + atkbd_set_leds(atkbd); 1006 } 1007 1008 atkbd_enable(atkbd);