Pull pnpacpi into release branch
[sfrench/cifs-2.6.git] / drivers / char / keyboard.c
index 449d029ad4f40abc936fb85f6ee66f60511201a6..5755b7e5f1873eba30bacec7ce71c07fc49610da 100644 (file)
@@ -74,7 +74,7 @@ void compute_shiftstate(void);
        k_self,         k_fn,           k_spec,         k_pad,\
        k_dead,         k_cons,         k_cur,          k_shift,\
        k_meta,         k_ascii,        k_lock,         k_lowercase,\
-       k_slock,        k_dead2,        k_ignore,       k_ignore
+       k_slock,        k_dead2,        k_brl,          k_ignore
 
 typedef void (k_handler_fn)(struct vc_data *vc, unsigned char value,
                            char up_flag, struct pt_regs *regs);
@@ -100,7 +100,7 @@ static fn_handler_fn *fn_handler[] = { FN_HANDLERS };
 const int max_vals[] = {
        255, ARRAY_SIZE(func_table) - 1, ARRAY_SIZE(fn_handler) - 1, NR_PAD - 1,
        NR_DEAD - 1, 255, 3, NR_SHIFT - 1, 255, NR_ASCII - 1, NR_LOCK - 1,
-       255, NR_LOCK - 1, 255
+       255, NR_LOCK - 1, 255, NR_BRL - 1
 };
 
 const int NR_TYPES = ARRAY_SIZE(max_vals);
@@ -126,7 +126,7 @@ static unsigned long key_down[NBITS(KEY_MAX)];              /* keyboard key bitmap */
 static unsigned char shift_down[NR_SHIFT];             /* shift state counters.. */
 static int dead_key_next;
 static int npadch = -1;                                        /* -1 or number assembled on pad */
-static unsigned char diacr;
+static unsigned int diacr;
 static char rep;                                       /* flag telling character repeat */
 
 static unsigned char ledstate = 0xff;                  /* undefined */
@@ -394,22 +394,30 @@ void compute_shiftstate(void)
  * Otherwise, conclude that DIACR was not combining after all,
  * queue it and return CH.
  */
-static unsigned char handle_diacr(struct vc_data *vc, unsigned char ch)
+static unsigned int handle_diacr(struct vc_data *vc, unsigned int ch)
 {
-       int d = diacr;
+       unsigned int d = diacr;
        unsigned int i;
 
        diacr = 0;
 
-       for (i = 0; i < accent_table_size; i++) {
-               if (accent_table[i].diacr == d && accent_table[i].base == ch)
-                       return accent_table[i].result;
+       if ((d & ~0xff) == BRL_UC_ROW) {
+               if ((ch & ~0xff) == BRL_UC_ROW)
+                       return d | ch;
+       } else {
+               for (i = 0; i < accent_table_size; i++)
+                       if (accent_table[i].diacr == d && accent_table[i].base == ch)
+                               return accent_table[i].result;
        }
 
-       if (ch == ' ' || ch == d)
+       if (ch == ' ' || ch == (BRL_UC_ROW|0) || ch == d)
                return d;
 
-       put_queue(vc, d);
+       if (kbd->kbdmode == VC_UNICODE)
+               to_utf8(vc, d);
+       else if (d < 0x100)
+               put_queue(vc, d);
+
        return ch;
 }
 
@@ -419,7 +427,10 @@ static unsigned char handle_diacr(struct vc_data *vc, unsigned char ch)
 static void fn_enter(struct vc_data *vc, struct pt_regs *regs)
 {
        if (diacr) {
-               put_queue(vc, diacr);
+               if (kbd->kbdmode == VC_UNICODE)
+                       to_utf8(vc, diacr);
+               else if (diacr < 0x100)
+                       put_queue(vc, diacr);
                diacr = 0;
        }
        put_queue(vc, 13);
@@ -615,7 +626,7 @@ static void k_lowercase(struct vc_data *vc, unsigned char value, char up_flag, s
        printk(KERN_ERR "keyboard.c: k_lowercase was called - impossible\n");
 }
 
-static void k_self(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs)
+static void k_unicode(struct vc_data *vc, unsigned int value, char up_flag, struct pt_regs *regs)
 {
        if (up_flag)
                return;         /* no action, if this is a key release */
@@ -628,7 +639,10 @@ static void k_self(struct vc_data *vc, unsigned char value, char up_flag, struct
                diacr = value;
                return;
        }
-       put_queue(vc, value);
+       if (kbd->kbdmode == VC_UNICODE)
+               to_utf8(vc, value);
+       else if (value < 0x100)
+               put_queue(vc, value);
 }
 
 /*
@@ -636,13 +650,23 @@ static void k_self(struct vc_data *vc, unsigned char value, char up_flag, struct
  * dead keys modifying the same character. Very useful
  * for Vietnamese.
  */
-static void k_dead2(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs)
+static void k_deadunicode(struct vc_data *vc, unsigned int value, char up_flag, struct pt_regs *regs)
 {
        if (up_flag)
                return;
        diacr = (diacr ? handle_diacr(vc, value) : value);
 }
 
+static void k_self(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs)
+{
+       k_unicode(vc, value, up_flag, regs);
+}
+
+static void k_dead2(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs)
+{
+       k_deadunicode(vc, value, up_flag, regs);
+}
+
 /*
  * Obsolete - for backwards compatibility only
  */
@@ -650,7 +674,7 @@ static void k_dead(struct vc_data *vc, unsigned char value, char up_flag, struct
 {
        static unsigned char ret_diacr[NR_DEAD] = {'`', '\'', '^', '~', '"', ',' };
        value = ret_diacr[value];
-       k_dead2(vc, value, up_flag, regs);
+       k_deadunicode(vc, value, up_flag, regs);
 }
 
 static void k_cons(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs)
@@ -835,6 +859,80 @@ static void k_slock(struct vc_data *vc, unsigned char value, char up_flag, struc
        }
 }
 
+/* by default, 300ms interval for combination release */
+static unsigned brl_timeout = 300;
+MODULE_PARM_DESC(brl_timeout, "Braille keys release delay in ms (0 for commit on first key release)");
+module_param(brl_timeout, uint, 0644);
+
+static unsigned brl_nbchords = 1;
+MODULE_PARM_DESC(brl_nbchords, "Number of chords that produce a braille pattern (0 for dead chords)");
+module_param(brl_nbchords, uint, 0644);
+
+static void k_brlcommit(struct vc_data *vc, unsigned int pattern, char up_flag, struct pt_regs *regs)
+{
+       static unsigned long chords;
+       static unsigned committed;
+
+       if (!brl_nbchords)
+               k_deadunicode(vc, BRL_UC_ROW | pattern, up_flag, regs);
+       else {
+               committed |= pattern;
+               chords++;
+               if (chords == brl_nbchords) {
+                       k_unicode(vc, BRL_UC_ROW | committed, up_flag, regs);
+                       chords = 0;
+                       committed = 0;
+               }
+       }
+}
+
+static void k_brl(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs)
+{
+       static unsigned pressed,committing;
+       static unsigned long releasestart;
+
+       if (kbd->kbdmode != VC_UNICODE) {
+               if (!up_flag)
+                       printk("keyboard mode must be unicode for braille patterns\n");
+               return;
+       }
+
+       if (!value) {
+               k_unicode(vc, BRL_UC_ROW, up_flag, regs);
+               return;
+       }
+
+       if (value > 8)
+               return;
+
+       if (up_flag) {
+               if (brl_timeout) {
+                       if (!committing ||
+                           jiffies - releasestart > (brl_timeout * HZ) / 1000) {
+                               committing = pressed;
+                               releasestart = jiffies;
+                       }
+                       pressed &= ~(1 << (value - 1));
+                       if (!pressed) {
+                               if (committing) {
+                                       k_brlcommit(vc, committing, 0, regs);
+                                       committing = 0;
+                               }
+                       }
+               } else {
+                       if (committing) {
+                               k_brlcommit(vc, committing, 0, regs);
+                               committing = 0;
+                       }
+                       pressed &= ~(1 << (value - 1));
+               }
+       } else {
+               pressed |= 1 << (value - 1);
+               if (!brl_timeout)
+                       committing = pressed;
+       }
+}
+
 /*
  * The leds display either (i) the status of NumLock, CapsLock, ScrollLock,
  * or (ii) whatever pattern of lights people want to show using KDSETLED,
@@ -930,8 +1028,8 @@ static void kbd_refresh_leds(struct input_handle *handle)
 }
 
 #if defined(CONFIG_X86) || defined(CONFIG_IA64) || defined(CONFIG_ALPHA) ||\
-    defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_SPARC32) ||\
-    defined(CONFIG_SPARC64) || defined(CONFIG_PARISC) || defined(CONFIG_SUPERH) ||\
+    defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) ||\
+    defined(CONFIG_PARISC) || defined(CONFIG_SUPERH) ||\
     (defined(CONFIG_ARM) && defined(CONFIG_KEYBOARD_ATKBD) && !defined(CONFIG_ARCH_RPC))
 
 #define HW_RAW(dev) (test_bit(EV_MSC, dev->evbit) && test_bit(MSC_RAW, dev->mscbit) &&\
@@ -958,7 +1056,7 @@ static unsigned short x86_keycodes[256] =
 extern int mac_hid_mouse_emulate_buttons(int, int, int);
 #endif /* CONFIG_MAC_EMUMOUSEBTN */
 
-#if defined(CONFIG_SPARC32) || defined(CONFIG_SPARC64)
+#ifdef CONFIG_SPARC
 static int sparc_l1_a_state = 0;
 extern void sun_do_break(void);
 #endif
@@ -1045,7 +1143,7 @@ static void kbd_keycode(unsigned int keycode, int down,
 
        if (keycode == KEY_LEFTALT || keycode == KEY_RIGHTALT)
                sysrq_alt = down;
-#if defined(CONFIG_SPARC32) || defined(CONFIG_SPARC64)
+#ifdef CONFIG_SPARC
        if (keycode == KEY_STOP)
                sparc_l1_a_state = down;
 #endif
@@ -1072,7 +1170,7 @@ static void kbd_keycode(unsigned int keycode, int down,
                return;
        }
 #endif
-#if defined(CONFIG_SPARC32) || defined(CONFIG_SPARC64)
+#ifdef CONFIG_SPARC
        if (keycode == KEY_A && sparc_l1_a_state) {
                sparc_l1_a_state = 0;
                sun_do_break();
@@ -1125,9 +1223,13 @@ static void kbd_keycode(unsigned int keycode, int down,
        }
 
        if (keycode > NR_KEYS)
-               return;
+               if (keycode >= KEY_BRL_DOT1 && keycode <= KEY_BRL_DOT8)
+                       keysym = K(KT_BRL, keycode - KEY_BRL_DOT1 + 1);
+               else
+                       return;
+       else
+               keysym = key_map[keycode];
 
-       keysym = key_map[keycode];
        type = KTYP(keysym);
 
        if (type < 0xf0) {