Patchwork PS/2 keyboard Scancode Set 3 support

login
register
mail settings
Submitter Roy Tam
Date Feb. 13, 2011, 7:32 a.m.
Message ID <AANLkTin+aqCOFZjmK_P-HPis0oC2jfnw9ipG58Hu9PDR@mail.gmail.com>
Download mbox | patch
Permalink /patch/82970/
State New
Headers show

Comments

Roy Tam - Feb. 13, 2011, 7:32 a.m.
The following patch adds PS/2 keyboard Scancode Set 3 support.

Sign-off-by: Roy Tam <roytam@gmail.com>
--
Blue Swirl - Feb. 13, 2011, 8:57 a.m.
On Sun, Feb 13, 2011 at 9:32 AM, Roy Tam <roytam@gmail.com> wrote:
> The following patch adds PS/2 keyboard Scancode Set 3 support.
>
> Sign-off-by: Roy Tam <roytam@gmail.com>
> --
> diff --git a/hw/ps2.c b/hw/ps2.c
> index 762bb00..4b73967 100644
> --- a/hw/ps2.c
> +++ b/hw/ps2.c
> @@ -143,12 +143,87 @@ static void ps2_put_keycode(void *opaque, int keycode)
>  {
>     PS2KbdState *s = opaque;
>
> -    /* XXX: add support for scancode sets 1 and 3 */
> -    if (!s->translate && keycode < 0xe0 && s->scancode_set == 2)
> +    /* XXX: add support for scancode sets 1 */
> +    if (!s->translate && keycode < 0xe0 && s->scancode_set > 1)
>       {

The braces belong to the previous line and the indentation is off.
Please run the patch through scripts/checkpatch.pl.

>         if (keycode & 0x80)
>             ps2_queue(&s->common, 0xf0);
>         keycode = ps2_raw_keycode[keycode & 0x7f];
> +        if (s->scancode_set == 3)
> +          {
> +            switch (keycode)
> +              {
> +                case 0x1:
> +                  keycode = 0x47;
> +                  break;
> +                case 0x3:
> +                  keycode = 0x27;
> +                  break;
> +                case 0x4:
> +                  keycode = 0x17;
> +                  break;
> +                case 0x5:
> +                  keycode = 0x7;
> +                  break;
> +                case 0x6:
> +                  keycode = 0xf;
> +                  break;
> +                case 0x7:
> +                  keycode = 0x5e;
> +                  break;
> +                case 0x9:
> +                  keycode = 0x4f;
> +                  break;
> +                case 0xa:
> +                  keycode = 0x3f;
> +                  break;
> +                case 0xb:
> +                  keycode = 0x2f;
> +                  break;
> +                case 0xc:
> +                  keycode = 0x1f;
> +                  break;
> +                case 0x11:
> +                  keycode = 0x19;
> +                  break;
> +                case 0x14:
> +                  keycode = 0x11;
> +                  break;
> +                case 0x58:
> +                  keycode = 0x14;
> +                  break;
> +                case 0x5d:
> +                  keycode = 0x5c;
> +                  break;
> +                case 0x76:
> +                  keycode = 0x8;
> +                  break;
> +                case 0x77:
> +                  keycode = 0x76;
> +                  break;
> +                case 0x78:
> +                  keycode = 0x56;
> +                  break;
> +                case 0x79:
> +                  keycode = 0x7c;
> +                  break;
> +                case 0x7b:
> +                  keycode = 0x84;
> +                  break;
> +                case 0x7c:
> +                  keycode = 0x7e;
> +                  break;
> +                case 0x7e:
> +                  keycode = 0x5f;
> +                  break;
> +                case 0x83:
> +                  keycode = 0x37;
> +                  break;
> +                case 0x84:
> +                  keycode = 0x57;
> +                  break;
> +              }
> +          }
>       }
>     ps2_queue(&s->common, keycode);
>  }
>
>

Patch

diff --git a/hw/ps2.c b/hw/ps2.c
index 762bb00..4b73967 100644
--- a/hw/ps2.c
+++ b/hw/ps2.c
@@ -143,12 +143,87 @@  static void ps2_put_keycode(void *opaque, int keycode)
 {
     PS2KbdState *s = opaque;

-    /* XXX: add support for scancode sets 1 and 3 */
-    if (!s->translate && keycode < 0xe0 && s->scancode_set == 2)
+    /* XXX: add support for scancode sets 1 */
+    if (!s->translate && keycode < 0xe0 && s->scancode_set > 1)
       {
         if (keycode & 0x80)
             ps2_queue(&s->common, 0xf0);
         keycode = ps2_raw_keycode[keycode & 0x7f];
+        if (s->scancode_set == 3)
+          {
+            switch (keycode)
+              {
+                case 0x1:
+                  keycode = 0x47;
+                  break;
+                case 0x3:
+                  keycode = 0x27;
+                  break;
+                case 0x4:
+                  keycode = 0x17;
+                  break;
+                case 0x5:
+                  keycode = 0x7;
+                  break;
+                case 0x6:
+                  keycode = 0xf;
+                  break;
+                case 0x7:
+                  keycode = 0x5e;
+                  break;
+                case 0x9:
+                  keycode = 0x4f;
+                  break;
+                case 0xa:
+                  keycode = 0x3f;
+                  break;
+                case 0xb:
+                  keycode = 0x2f;
+                  break;
+                case 0xc:
+                  keycode = 0x1f;
+                  break;
+                case 0x11:
+                  keycode = 0x19;
+                  break;
+                case 0x14:
+                  keycode = 0x11;
+                  break;
+                case 0x58:
+                  keycode = 0x14;
+                  break;
+                case 0x5d:
+                  keycode = 0x5c;
+                  break;
+                case 0x76:
+                  keycode = 0x8;
+                  break;
+                case 0x77:
+                  keycode = 0x76;
+                  break;
+                case 0x78:
+                  keycode = 0x56;
+                  break;
+                case 0x79:
+                  keycode = 0x7c;
+                  break;
+                case 0x7b:
+                  keycode = 0x84;
+                  break;
+                case 0x7c:
+                  keycode = 0x7e;
+                  break;
+                case 0x7e:
+                  keycode = 0x5f;
+                  break;
+                case 0x83:
+                  keycode = 0x37;
+                  break;
+                case 0x84:
+                  keycode = 0x57;
+                  break;
+              }
+          }
       }
     ps2_queue(&s->common, keycode);
 }