Hi,

I discussed about this with miod@. This code works correctly, but not optimal.
I need more tests to fix it.

IMHO this is not related to your original issue.

----- Forwarded message from Alexandr Shadchin <alexandr.shadc...@gmail.com> 
-----

Date: Tue, 15 Nov 2011 02:52:30 +0600
From: Alexandr Shadchin <alexandr.shadc...@gmail.com>
To: Miod Vallat <m...@online.fr>
Subject: rewrite pckbd_set_xtscancode()

Hi,

I rewrote function pckbd_set_xtscancode() for pckbd(4).

Old behavior:
 * Try enabling translation
   * If succes, then N = 3
   * If failed, then N = 2
 * Try set begin with #N
   If N=3, then check correctly set #3
   But if translation enabled, then check set #3 return 3F (not 3) [1]
   So set #3 never used.

Also sets #1 and #3 are not recommended [2]

New behavior:
 * Try set #2
 * If success
   * Try enabling translation set #2 -> set #1
     * If success, then using hardware translation
     * If failed, then using software translation
 * If failed set #2, then try set #1

Comments ? OK ?

[1] - http://www.win.tue.nl/~aeb/linux/kbd/scancodes-10.html#ss10.3
(look section "Effects of translation" - "Origin of strange scan code set 
values")

[2] - http://www.win.tue.nl/~aeb/linux/kbd/scancodes-10.html#ss10.5

-- 
Alexandr Shadchin

Index: pckbd.c
===================================================================
RCS file: /cvs/src/sys/dev/pckbc/pckbd.c,v
retrieving revision 1.31
diff -u -p -r1.31 pckbd.c
--- pckbd.c     17 Mar 2011 15:42:05 -0000      1.31
+++ pckbd.c     14 Nov 2011 19:03:58 -0000
@@ -92,8 +92,7 @@ struct pckbd_internal {
        pckbc_tag_t t_kbctag;
        pckbc_slot_t t_kbcslot;
 
-       int t_translating;
-       int t_table;
+       int t_xt;
 
        int t_lastchar;
        int t_extended;
@@ -186,95 +185,39 @@ int
 pckbd_set_xtscancode(pckbc_tag_t kbctag, pckbc_slot_t kbcslot,
     struct pckbd_internal *id)
 {
-       /* default to have the 8042 translate the keyboard with table 3. */
-       int table = 3;
+       u_char cmd[2];
 
-       if (pckbc_xt_translation(kbctag, kbcslot, 1)) {
-               if (id != NULL)
-                       id->t_translating = 1;
-       } else {
-#ifdef DEBUG
-               printf("pckbd: enabling of translation failed\n");
-#endif
-               /*
-                * Since the keyboard controller can not translate scan
-                * codes to the XT set (#1), we would like to request
-                * this exact set. However it is likely that the
-                * controller does not support it either.
-                *
-                * So try scan code set #2 as well, which this driver
-                * knows how to translate.
-                */
-               table = 2;
-               if (id != NULL)
-                       id->t_translating = 0;
-       }
+       if (id != NULL)
+               id->t_xt = 1;
 
-       /* keep falling back until we hit a table that looks usable. */
-       for (; table >= 1; table--) {
-               u_char cmd[2];
+       /* Let us try to set table 2 */
+       cmd[0] = KBC_SETTABLE;
+       cmd[1] = 2;
+       if (pckbc_poll_cmd(kbctag, kbcslot, cmd, 2, 0, NULL, 1)) {
 #ifdef DEBUG
-               printf("pckbd: trying table %d\n", table);
+               printf("pckbd: table set of 2 failed\n");
 #endif
-               cmd[0] = KBC_SETTABLE;
-               cmd[1] = table;
-               if (pckbc_poll_cmd(kbctag, kbcslot, cmd, 2, 0, NULL, 0)) {
-#ifdef DEBUG
-                       printf("pckbd: table set of %d failed\n", table);
-#endif
-                       if (table > 1) {
-                               cmd[0] = KBC_RESET;
-                               (void)pckbc_poll_cmd(kbctag, kbcslot, cmd,
-                                   1, 1, NULL, 1);
-                               pckbc_flush(kbctag, kbcslot);
-
-                               continue;
-                       }
-               }
-
-               /*
-                * the 8042 took the table set request, however, not all that
-                * report they can work with table 3 actually work, so ask what
-                * table it reports it's in.
-                */
-               if (table == 3) {
-                       u_char resp[1];
+               cmd[0] = KBC_RESET;
+               pckbc_poll_cmd(kbctag, kbcslot, cmd, 1, 1, NULL, 1);
+               pckbc_flush(kbctag, kbcslot);
+       } else {
+               if (pckbc_xt_translation(kbctag, kbcslot, 1) == 0 && id != NULL)
+                       id->t_xt = 0;
+               return (0);
+       }
 
-                       cmd[0] = KBC_SETTABLE;
-                       cmd[1] = 0;
-                       if (pckbc_poll_cmd(kbctag, kbcslot, cmd, 2, 1, resp, 
0)) {
-                               /*
-                                * query failed, step down to table 2 to be
-                                * safe.
-                                */
-#ifdef DEBUG
-                               printf("pckbd: table 3 verification failed\n");
-#endif
-                               continue;
-                       } else if (resp[0] == 3) {
-#ifdef DEBUG
-                               printf("pckbd: settling on table 3\n");
-#endif
-                               break;
-                       }
-#ifdef DEBUG
-                       else
-                               printf("pckbd: table \"%x\" != 3, trying 2\n",
-                                       resp[0]);
-#endif
-               } else {
+       /* Let us try to set table 1 */
+       cmd[0] = KBC_SETTABLE;
+       cmd[1] = 1;
+       if (pckbc_poll_cmd(kbctag, kbcslot, cmd, 2, 0, NULL, 1)) {
 #ifdef DEBUG
-                       printf("pckbd: settling on table %d\n", table);
+               printf("pckbd: table set of 1 failed\n");
 #endif
-                       break;
-               }
-       }
-
-       if (table == 0)
+               cmd[0] = KBC_RESET;
+               pckbc_poll_cmd(kbctag, kbcslot, cmd, 1, 1, NULL, 1);
+               pckbc_flush(kbctag, kbcslot);
                return (1);
-
-       if (id != NULL)
-               id->t_table = table;
+       }
 
        return (0);
 }
@@ -745,7 +688,7 @@ const u_int8_t pckbd_xtbl_ext[] = {
 int
 pckbd_scancode_translate(struct pckbd_internal *id, int datain)
 {
-       if (id->t_translating != 0 || id->t_table == 1)
+       if (id->t_xt)
                return datain;
 
        if (datain == KBR_BREAK) {
@@ -817,7 +760,7 @@ pckbd_decode(struct pckbd_internal *id, 
        } else
                id->t_extended1 = 0;
 
-       if (id->t_translating != 0 || id->t_table == 1) {
+       if (id->t_xt) {
                id->t_releasing = releasing;
        } else {
                /* id->t_releasing computed in pckbd_scancode_translate() */

----- End forwarded message -----



On Tue, Jul 24, 2012 at 03:49:42PM +0200, mlambda wrote:
> Forwarded to tech, as nobody seemed to notice this on misc.
> 
> -------- Forwarded Message --------
> > From: mlambda <mlam...@gmail.com>
> > To: m...@openbsd.org
> > Subject: Re: Running OpenBSD on an Acer Aspire One 110L netbook
> > Date: Tue, 10 Jul 2012 23:52:49 +0200
> > 
> > By the way, are you sure 'pckbd_set_xtscancode' in sys/dev/pckbc/pckbd.c
> > is correct?
> > This function tries to check for scancode set 3 using
> > 
> > 
> >                     cmd[0] = KBC_SETTABLE;
> >                     cmd[1] = 0;
> >                     if (pckbc_poll_cmd(kbctag, kbcslot, cmd, 2, 1, resp, 
> > 0)) {
> >                             /*
> >                              * query failed, step down to table 2 to be
> >                              * safe.
> >                              */
> > #ifdef DEBUG
> >                             printf("pckbd: table 3 verification failed\n");
> > #endif
> >                             continue;
> >                     } else if (resp[0] == 3) {
> > #ifdef DEBUG
> >                             printf("pckbd: settling on table 3\n");
> > #endif
> >                             break;
> >                     }
> > #ifdef DEBUG
> >                     else
> >                             printf("pckbd: table \"%x\" != 3, trying 2\n",
> >                                     resp[0]);
> > 
> > 
> > However, http://www.win.tue.nl/~aeb/linux/kbd/scancodes-10.html says:
> > 
> > "The usual PC keyboards are capable of producing three sets of
> > scancodes. Writing 0xf0 followed by 1, 2 or 3 to port 0x60 will put the
> > keyboard in scancode mode 1, 2 or 3. Writing 0xf0 followed by 0 queries
> > the mode, resulting in a scancode byte 43, 41 or 3f from the keyboard."
> > 
> > So "resp[0] == 3" always fails and the code falls back to using scancode
> > set 2.
> 

-- 
Alexandr Shadchin

Reply via email to