OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [char/] [keyboard.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1626 jcastillo
/*
2
 * linux/drivers/char/keyboard.c
3
 *
4
 * Keyboard driver for Linux v0.99 using Latin-1.
5
 *
6
 * Written for linux by Johan Myreen as a translation from
7
 * the assembly version by Linus (with diacriticals added)
8
 *
9
 * Some additional features added by Christoph Niemann (ChN), March 1993
10
 *
11
 * Loadable keymaps by Risto Kankkunen, May 1993
12
 *
13
 * Diacriticals redone & other small changes, aeb@cwi.nl, June 1993
14
 * Added decr/incr_console, dynamic keymaps, Unicode support,
15
 * dynamic function/string keys, led setting,  Sept 1994
16
 * `Sticky' modifier keys, 951006.
17
 *
18
 */
19
 
20
#define KEYBOARD_IRQ IRQ_PS2_0
21
#define DISABLE_KBD_DURING_INTERRUPTS 0
22
 
23
#include <linux/sched.h>
24
#include <linux/interrupt.h>
25
#include <linux/tty.h>
26
#include <linux/tty_flip.h>
27
#include <linux/mm.h>
28
#include <linux/ptrace.h>
29
#include <linux/signal.h>
30
#include <linux/string.h>
31
#include <linux/ioport.h>
32
#include <linux/random.h>
33
 
34
#include <asm/bitops.h>
35
#ifdef CONFIG_OR32
36
#include <asm/irq.h>
37
#endif
38
 
39
#include "kbd_kern.h"
40
#include "diacr.h"
41
#include "vt_kern.h"
42
 
43
/*
44
 * On non-x86 hardware we do a full keyboard controller
45
 * initialization, in case the bootup software hasn't done
46
 * it. On a x86, the BIOS will already have initialized the
47
 * keyboard.
48
 */
49
#ifndef __i386__
50
#define INIT_KBD
51
static int initialize_kbd(void);
52
#endif
53
 
54
#define SIZE(x) (sizeof(x)/sizeof((x)[0]))
55
 
56
#define KBD_REPORT_ERR
57
#define KBD_REPORT_UNKN
58
/* #define KBD_IS_FOCUS_9000 */
59
 
60
#ifndef KBD_DEFMODE
61
#define KBD_DEFMODE ((1 << VC_REPEAT) | (1 << VC_META))
62
#endif
63
 
64
#ifndef KBD_DEFLEDS
65
/*
66
 * Some laptops take the 789uiojklm,. keys as number pad when NumLock
67
 * is on. This seems a good reason to start with NumLock off.
68
 */
69
#define KBD_DEFLEDS 0
70
#endif
71
 
72
#ifndef KBD_DEFLOCK
73
#define KBD_DEFLOCK 0
74
#endif
75
 
76
#include <asm/io.h>
77
#include <asm/system.h>
78
 
79
extern void poke_blanked_console(void);
80
extern void ctrl_alt_del(void);
81
extern void reset_vc(unsigned int new_console);
82
extern void scrollback(int);
83
extern void scrollfront(int);
84
 
85
unsigned char kbd_read_mask = 0x01;     /* modified by psaux.c */
86
 
87
/*
88
 * global state includes the following, and various static variables
89
 * in this module: prev_scancode, shift_state, diacr, npadch, dead_key_next.
90
 * (last_console is now a global variable)
91
 */
92
 
93
/* shift state counters.. */
94
static unsigned char k_down[NR_SHIFT] = {0, };
95
/* keyboard key bitmap */
96
#define BITS_PER_LONG (8*sizeof(unsigned long))
97
static unsigned long key_down[256/BITS_PER_LONG] = { 0, };
98
 
99
static int dead_key_next = 0;
100
/*
101
 * In order to retrieve the shift_state (for the mouse server), either
102
 * the variable must be global, or a new procedure must be created to
103
 * return the value. I chose the former way.
104
 */
105
/*static*/ int shift_state = 0;
106
static int npadch = -1;                 /* -1 or number assembled on pad */
107
static unsigned char diacr = 0;
108
static char rep = 0;                     /* flag telling character repeat */
109
struct kbd_struct kbd_table[MAX_NR_CONSOLES];
110
static struct tty_struct **ttytab;
111
static struct kbd_struct * kbd = kbd_table;
112
static struct tty_struct * tty = NULL;
113
 
114
/* used only by send_data - set by keyboard_interrupt */
115
static volatile unsigned char reply_expected = 0;
116
static volatile unsigned char acknowledge = 0;
117
static volatile unsigned char resend = 0;
118
 
119
extern void compute_shiftstate(void);
120
 
121
typedef void (*k_hand)(unsigned char value, char up_flag);
122
typedef void (k_handfn)(unsigned char value, char up_flag);
123
 
124
static k_handfn
125
        do_self, do_fn, do_spec, do_pad, do_dead, do_cons, do_cur, do_shift,
126
        do_meta, do_ascii, do_lock, do_lowercase, do_slock, do_ignore;
127
 
128
static k_hand key_handler[16] = {
129
        do_self, do_fn, do_spec, do_pad, do_dead, do_cons, do_cur, do_shift,
130
        do_meta, do_ascii, do_lock, do_lowercase, do_slock,
131
        do_ignore, do_ignore, do_ignore
132
};
133
 
134
typedef void (*void_fnp)(void);
135
typedef void (void_fn)(void);
136
 
137
static void_fn do_null, enter, show_ptregs, send_intr, lastcons, caps_toggle,
138
        num, hold, scroll_forw, scroll_back, boot_it, caps_on, compose,
139
        SAK, decr_console, incr_console, spawn_console, bare_num;
140
 
141
static void_fnp spec_fn_table[] = {
142
        do_null,        enter,          show_ptregs,    show_mem,
143
        show_state,     send_intr,      lastcons,       caps_toggle,
144
        num,            hold,           scroll_forw,    scroll_back,
145
        boot_it,        caps_on,        compose,        SAK,
146
        decr_console,   incr_console,   spawn_console,  bare_num
147
};
148
 
149
/* maximum values each key_handler can handle */
150
const int max_vals[] = {
151
        255, SIZE(func_table) - 1, SIZE(spec_fn_table) - 1, NR_PAD - 1,
152
        NR_DEAD - 1, 255, 3, NR_SHIFT - 1,
153
        255, NR_ASCII - 1, NR_LOCK - 1, 255,
154
        NR_LOCK - 1
155
};
156
 
157
const int NR_TYPES = SIZE(max_vals);
158
 
159
static void put_queue(int);
160
static unsigned char handle_diacr(unsigned char);
161
 
162
/* pt_regs - set by keyboard_interrupt(), used by show_ptregs() */
163
static struct pt_regs * pt_regs;
164
 
165
static inline void kb_wait(void)
166
{
167
        int i;
168
 
169
        for (i=0; i<0x100000; i++)
170
                if ((inb_p(KBD_BASE_ADD+0x4) & 0x02) == 0)
171
                        return;
172
        printk(KERN_WARNING "Keyboard timed out\n");
173
}
174
 
175
static inline void send_cmd(unsigned char c)
176
{
177
        kb_wait();
178
        outb(c,KBD_BASE_ADD+0x4);
179
}
180
 
181
/*
182
 * Many other routines do put_queue, but I think either
183
 * they produce ASCII, or they produce some user-assigned
184
 * string, and in both cases we might assume that it is
185
 * in utf-8 already.
186
 */
187
void to_utf8(ushort c) {
188
    if (c < 0x80)
189
        put_queue(c);                   /*  0*******  */
190
    else if (c < 0x800) {
191
        put_queue(0xc0 | (c >> 6));     /*  110***** 10******  */
192
        put_queue(0x80 | (c & 0x3f));
193
    } else {
194
        put_queue(0xe0 | (c >> 12));    /*  1110**** 10****** 10******  */
195
        put_queue(0x80 | ((c >> 6) & 0x3f));
196
        put_queue(0x80 | (c & 0x3f));
197
    }
198
    /* UTF-8 is defined for words of up to 31 bits,
199
       but we need only 16 bits here */
200
}
201
 
202
/*
203
 * Translation of escaped scancodes to keycodes.
204
 * This is now user-settable.
205
 * The keycodes 1-88,96-111,119 are fairly standard, and
206
 * should probably not be changed - changing might confuse X.
207
 * X also interprets scancode 0x5d (KEY_Begin).
208
 *
209
 * For 1-88 keycode equals scancode.
210
 */
211
 
212
#define E0_KPENTER 96
213
#define E0_RCTRL   97
214
#define E0_KPSLASH 98
215
#define E0_PRSCR   99
216
#define E0_RALT    100
217
#define E0_BREAK   101  /* (control-pause) */
218
#define E0_HOME    102
219
#define E0_UP      103
220
#define E0_PGUP    104
221
#define E0_LEFT    105
222
#define E0_RIGHT   106
223
#define E0_END     107
224
#define E0_DOWN    108
225
#define E0_PGDN    109
226
#define E0_INS     110
227
#define E0_DEL     111
228
 
229
#define E1_PAUSE   119
230
 
231
/*
232
 * The keycodes below are randomly located in 89-95,112-118,120-127.
233
 * They could be thrown away (and all occurrences below replaced by 0),
234
 * but that would force many users to use the `setkeycodes' utility, where
235
 * they needed not before. It does not matter that there are duplicates, as
236
 * long as no duplication occurs for any single keyboard.
237
 */
238
#define SC_LIM 89
239
 
240
#define FOCUS_PF1 85           /* actual code! */
241
#define FOCUS_PF2 89
242
#define FOCUS_PF3 90
243
#define FOCUS_PF4 91
244
#define FOCUS_PF5 92
245
#define FOCUS_PF6 93
246
#define FOCUS_PF7 94
247
#define FOCUS_PF8 95
248
#define FOCUS_PF9 120
249
#define FOCUS_PF10 121
250
#define FOCUS_PF11 122
251
#define FOCUS_PF12 123
252
 
253
#define JAP_86     124
254
/* tfj@olivia.ping.dk:
255
 * The four keys are located over the numeric keypad, and are
256
 * labelled A1-A4. It's an rc930 keyboard, from
257
 * Regnecentralen/RC International, Now ICL.
258
 * Scancodes: 59, 5a, 5b, 5c.
259
 */
260
#define RGN1 124
261
#define RGN2 125
262
#define RGN3 126
263
#define RGN4 127
264
 
265
static unsigned char high_keys[128 - SC_LIM] = {
266
  RGN1, RGN2, RGN3, RGN4, 0, 0, 0,                   /* 0x59-0x5f */
267
  0, 0, 0, 0, 0, 0, 0, 0,                            /* 0x60-0x67 */
268
  0, 0, 0, 0, 0, FOCUS_PF11, 0, FOCUS_PF12,          /* 0x68-0x6f */
269
  0, 0, 0, FOCUS_PF2, FOCUS_PF9, 0, 0, FOCUS_PF3,    /* 0x70-0x77 */
270
  FOCUS_PF4, FOCUS_PF5, FOCUS_PF6, FOCUS_PF7,        /* 0x78-0x7b */
271
  FOCUS_PF8, JAP_86, FOCUS_PF10, 0                   /* 0x7c-0x7f */
272
};
273
 
274
/* BTC */
275
#define E0_MACRO   112
276
/* LK450 */
277
#define E0_F13     113
278
#define E0_F14     114
279
#define E0_HELP    115
280
#define E0_DO      116
281
#define E0_F17     117
282
#define E0_KPMINPLUS 118
283
/*
284
 * My OmniKey generates e0 4c for  the "OMNI" key and the
285
 * right alt key does nada. [kkoller@nyx10.cs.du.edu]
286
 */
287
#define E0_OK   124
288
/*
289
 * New microsoft keyboard is rumoured to have
290
 * e0 5b (left window button), e0 5c (right window button),
291
 * e0 5d (menu button). [or: LBANNER, RBANNER, RMENU]
292
 * [or: Windows_L, Windows_R, TaskMan]
293
 */
294
#define E0_MSLW 125
295
#define E0_MSRW 126
296
#define E0_MSTM 127
297
 
298
static unsigned char e0_keys[128] = {
299
  0, 0, 0, 0, 0, 0, 0, 0,                             /* 0x00-0x07 */
300
  0, 0, 0, 0, 0, 0, 0, 0,                             /* 0x08-0x0f */
301
  0, 0, 0, 0, 0, 0, 0, 0,                             /* 0x10-0x17 */
302
  0, 0, 0, 0, E0_KPENTER, E0_RCTRL, 0, 0,           /* 0x18-0x1f */
303
  0, 0, 0, 0, 0, 0, 0, 0,                             /* 0x20-0x27 */
304
  0, 0, 0, 0, 0, 0, 0, 0,                             /* 0x28-0x2f */
305
  0, 0, 0, 0, 0, E0_KPSLASH, 0, E0_PRSCR,           /* 0x30-0x37 */
306
  E0_RALT, 0, 0, 0, 0, E0_F13, E0_F14, E0_HELP,           /* 0x38-0x3f */
307
  E0_DO, E0_F17, 0, 0, 0, 0, E0_BREAK, E0_HOME,           /* 0x40-0x47 */
308
  E0_UP, E0_PGUP, 0, E0_LEFT, E0_OK, E0_RIGHT, E0_KPMINPLUS, E0_END,/* 0x48-0x4f */
309
  E0_DOWN, E0_PGDN, E0_INS, E0_DEL, 0, 0, 0, 0,           /* 0x50-0x57 */
310
  0, 0, 0, E0_MSLW, E0_MSRW, E0_MSTM, 0, 0,        /* 0x58-0x5f */
311
  0, 0, 0, 0, 0, 0, 0, 0,                             /* 0x60-0x67 */
312
  0, 0, 0, 0, 0, 0, 0, E0_MACRO,                     /* 0x68-0x6f */
313
  0, 0, 0, 0, 0, 0, 0, 0,                             /* 0x70-0x77 */
314
  0, 0, 0, 0, 0, 0, 0, 0                              /* 0x78-0x7f */
315
};
316
 
317
int setkeycode(unsigned int scancode, unsigned int keycode)
318
{
319
        if (scancode < SC_LIM || scancode > 255 || keycode > 127)
320
          return -EINVAL;
321
        if (scancode < 128)
322
          high_keys[scancode - SC_LIM] = keycode;
323
        else
324
          e0_keys[scancode - 128] = keycode;
325
        return 0;
326
}
327
 
328
int getkeycode(unsigned int scancode)
329
{
330
        return
331
          (scancode < SC_LIM || scancode > 255) ? -EINVAL :
332
          (scancode < 128) ? high_keys[scancode - SC_LIM] :
333
            e0_keys[scancode - 128];
334
}
335
 
336
#if DISABLE_KBD_DURING_INTERRUPTS
337
#define disable_keyboard()      do { send_cmd(0xAD); kb_wait(); } while (0)
338
#define enable_keyboard()       send_cmd(0xAE)
339
#else
340
#define disable_keyboard()      /* nothing */
341
#define enable_keyboard()       /* nothing */
342
#endif
343
 
344
static void handle_scancode(unsigned char scancode)
345
{
346
        unsigned char keycode;
347
        static unsigned int prev_scancode = 0;   /* remember E0, E1 */
348
        char up_flag;                            /* 0 or 0200 */
349
        char raw_mode;
350
 
351
        if (reply_expected) {
352
          /* 0xfa, 0xfe only mean "acknowledge", "resend" for most keyboards */
353
          /* but they are the key-up scancodes for PF6, PF10 on a FOCUS 9000 */
354
                reply_expected = 0;
355
                if (scancode == 0xfa) {
356
                        acknowledge = 1;
357
                        return;
358
                } else if (scancode == 0xfe) {
359
                        resend = 1;
360
                        return;
361
                }
362
                /* strange ... */
363
                reply_expected = 1;
364
#if 0
365
                printk(KERN_DEBUG "keyboard reply expected - got %02x\n",
366
                       scancode);
367
#endif
368
        }
369
        if (scancode == 0) {
370
#ifdef KBD_REPORT_ERR
371
                printk(KERN_INFO "keyboard buffer overflow\n");
372
#endif
373
                prev_scancode = 0;
374
                return;
375
        }
376
        do_poke_blanked_console = 1;
377
        mark_bh(CONSOLE_BH);
378
        add_keyboard_randomness(scancode);
379
 
380
        tty = ttytab? ttytab[fg_console]: NULL;
381
        if (tty && (!tty->driver_data)) {
382
                /* This is to workaround ugly bug in tty_io.c, which
383
                   does not do locking when it should */
384
                tty = NULL;
385
        }
386
        kbd = kbd_table + fg_console;
387
        if ((raw_mode = (kbd->kbdmode == VC_RAW))) {
388
                put_queue(scancode);
389
                /* we do not return yet, because we want to maintain
390
                   the key_down array, so that we have the correct
391
                   values when finishing RAW mode or when changing VT's */
392
        }
393
 
394
        if (scancode == 0xff) {
395
                /* in scancode mode 1, my ESC key generates 0xff */
396
                /* the calculator keys on a FOCUS 9000 generate 0xff */
397
#ifndef KBD_IS_FOCUS_9000
398
#ifdef KBD_REPORT_ERR
399
                if (!raw_mode)
400
                  printk(KERN_DEBUG "keyboard error\n");
401
#endif
402
#endif
403
                prev_scancode = 0;
404
                return;
405
        }
406
 
407
        if (scancode == 0xe0 || scancode == 0xe1) {
408
                prev_scancode = scancode;
409
                return;
410
        }
411
 
412
        /*
413
         *  Convert scancode to keycode, using prev_scancode.
414
         */
415
        up_flag = (scancode & 0200);
416
        scancode &= 0x7f;
417
 
418
        if (prev_scancode) {
419
          /*
420
           * usually it will be 0xe0, but a Pause key generates
421
           * e1 1d 45 e1 9d c5 when pressed, and nothing when released
422
           */
423
          if (prev_scancode != 0xe0) {
424
              if (prev_scancode == 0xe1 && scancode == 0x1d) {
425
                  prev_scancode = 0x100;
426
                  return;
427
              } else if (prev_scancode == 0x100 && scancode == 0x45) {
428
                  keycode = E1_PAUSE;
429
                  prev_scancode = 0;
430
              } else {
431
#ifdef KBD_REPORT_UNKN
432
                  if (!raw_mode)
433
                    printk(KERN_INFO "keyboard: unknown e1 escape sequence\n");
434
#endif
435
                  prev_scancode = 0;
436
                  return;
437
              }
438
          } else {
439
              prev_scancode = 0;
440
              /*
441
               *  The keyboard maintains its own internal caps lock and
442
               *  num lock statuses. In caps lock mode E0 AA precedes make
443
               *  code and E0 2A follows break code. In num lock mode,
444
               *  E0 2A precedes make code and E0 AA follows break code.
445
               *  We do our own book-keeping, so we will just ignore these.
446
               */
447
              /*
448
               *  For my keyboard there is no caps lock mode, but there are
449
               *  both Shift-L and Shift-R modes. The former mode generates
450
               *  E0 2A / E0 AA pairs, the latter E0 B6 / E0 36 pairs.
451
               *  So, we should also ignore the latter. - aeb@cwi.nl
452
               */
453
              if (scancode == 0x2a || scancode == 0x36)
454
                return;
455
 
456
              if (e0_keys[scancode])
457
                keycode = e0_keys[scancode];
458
              else {
459
#ifdef KBD_REPORT_UNKN
460
                  if (!raw_mode)
461
                    printk(KERN_INFO "keyboard: unknown scancode e0 %02x\n",
462
                           scancode);
463
#endif
464
                  return;
465
              }
466
          }
467
        } else if (scancode >= SC_LIM) {
468
            /* This happens with the FOCUS 9000 keyboard
469
               Its keys PF1..PF12 are reported to generate
470
               55 73 77 78 79 7a 7b 7c 74 7e 6d 6f
471
               Moreover, unless repeated, they do not generate
472
               key-down events, so we have to zero up_flag below */
473
            /* Also, Japanese 86/106 keyboards are reported to
474
               generate 0x73 and 0x7d for \ - and \ | respectively. */
475
            /* Also, some Brazilian keyboard is reported to produce
476
               0x73 and 0x7e for \ ? and KP-dot, respectively. */
477
 
478
          keycode = high_keys[scancode - SC_LIM];
479
 
480
          if (!keycode) {
481
              if (!raw_mode) {
482
#ifdef KBD_REPORT_UNKN
483
                  printk(KERN_INFO "keyboard: unrecognized scancode (%02x)"
484
                         " - ignored\n", scancode);
485
#endif
486
              }
487
              return;
488
          }
489
        } else
490
          keycode = scancode;
491
 
492
        /*
493
         * At this point the variable `keycode' contains the keycode.
494
         * Note: the keycode must not be 0.
495
         * We keep track of the up/down status of the key, and
496
         * return the keycode if in MEDIUMRAW mode.
497
         */
498
 
499
        if (up_flag) {
500
                rep = 0;
501
                if(!clear_bit(keycode, key_down)) {
502
                    /* unexpected, but this can happen:
503
                       maybe this was a key release for a FOCUS 9000
504
                       PF key; if we want to see it, we have to clear
505
                       up_flag */
506
                    if (keycode >= SC_LIM || keycode == 85)
507
                      up_flag = 0;
508
                }
509
        } else
510
                rep = set_bit(keycode, key_down);
511
 
512
        if (raw_mode)
513
                return;
514
 
515
        if (kbd->kbdmode == VC_MEDIUMRAW) {
516
                /* soon keycodes will require more than one byte */
517
                put_queue(keycode + up_flag);
518
                return;
519
        }
520
 
521
        /*
522
         * Small change in philosophy: earlier we defined repetition by
523
         *       rep = keycode == prev_keycode;
524
         *       prev_keycode = keycode;
525
         * but now by the fact that the depressed key was down already.
526
         * Does this ever make a difference? Yes.
527
         */
528
 
529
        /*
530
         *  Repeat a key only if the input buffers are empty or the
531
         *  characters get echoed locally. This makes key repeat usable
532
         *  with slow applications and under heavy loads.
533
         */
534
        if (!rep ||
535
            (vc_kbd_mode(kbd,VC_REPEAT) && tty &&
536
             (L_ECHO(tty) || (tty->driver.chars_in_buffer(tty) == 0)))) {
537
                u_short keysym;
538
                u_char type;
539
 
540
                /* the XOR below used to be an OR */
541
                int shift_final = shift_state ^ kbd->lockstate ^ kbd->slockstate;
542
                ushort *key_map = key_maps[shift_final];
543
 
544
                if (key_map != NULL) {
545
                        keysym = key_map[keycode];
546
                        type = KTYP(keysym);
547
 
548
                        if (type >= 0xf0) {
549
                            type -= 0xf0;
550
                            if (type == KT_LETTER) {
551
                                type = KT_LATIN;
552
                                if (vc_kbd_led(kbd, VC_CAPSLOCK)) {
553
                                    key_map = key_maps[shift_final ^ (1<<KG_SHIFT)];
554
                                    if (key_map)
555
                                      keysym = key_map[keycode];
556
                                }
557
                            }
558
                            (*key_handler[type])(keysym & 0xff, up_flag);
559
                            if (type != KT_SLOCK)
560
                              kbd->slockstate = 0;
561
                        } else {
562
                            /* maybe only if (kbd->kbdmode == VC_UNICODE) ? */
563
                            if (!up_flag)
564
                              to_utf8(keysym);
565
                        }
566
                } else {
567
                        /* maybe beep? */
568
                        /* we have at least to update shift_state */
569
#if 1                   /* how? two almost equivalent choices follow */
570
                        compute_shiftstate();
571
#else
572
                        keysym = U(plain_map[keycode]);
573
                        type = KTYP(keysym);
574
                        if (type == KT_SHIFT)
575
                          (*key_handler[type])(keysym & 0xff, up_flag);
576
#endif
577
                }
578
        }
579
}
580
 
581
static void keyboard_interrupt(int irq, void *dev_id, struct pt_regs *regs)
582
{
583
        unsigned char status;
584
 
585
        pt_regs = regs;
586
        disable_keyboard();
587
 
588
        status = inb_p(KBD_BASE_ADD+0x4);
589
        do {
590
                unsigned char scancode;
591
 
592
                /* mouse data? */
593
                if (status & kbd_read_mask & 0x20)
594
                        break;
595
 
596
                scancode = inb(KBD_BASE_ADD+0x0);
597
                if (status & 0x01)
598
                        handle_scancode(scancode);
599
 
600
                status = inb(KBD_BASE_ADD+0x4);
601
        } while (status & 0x01);
602
 
603
        mark_bh(KEYBOARD_BH);
604
        enable_keyboard();
605
}
606
 
607
static void put_queue(int ch)
608
{
609
        wake_up(&keypress_wait);
610
        if (tty) {
611
                tty_insert_flip_char(tty, ch, 0);
612
                tty_schedule_flip(tty);
613
        }
614
}
615
 
616
static void puts_queue(char *cp)
617
{
618
        wake_up(&keypress_wait);
619
        if (!tty)
620
                return;
621
 
622
        while (*cp) {
623
                tty_insert_flip_char(tty, *cp, 0);
624
                cp++;
625
        }
626
        tty_schedule_flip(tty);
627
}
628
 
629
static void applkey(int key, char mode)
630
{
631
        static char buf[] = { 0x1b, 'O', 0x00, 0x00 };
632
 
633
        buf[1] = (mode ? 'O' : '[');
634
        buf[2] = key;
635
        puts_queue(buf);
636
}
637
 
638
static void enter(void)
639
{
640
        put_queue(13);
641
        if (vc_kbd_mode(kbd,VC_CRLF))
642
                put_queue(10);
643
}
644
 
645
static void caps_toggle(void)
646
{
647
        if (rep)
648
                return;
649
        chg_vc_kbd_led(kbd, VC_CAPSLOCK);
650
}
651
 
652
static void caps_on(void)
653
{
654
        if (rep)
655
                return;
656
        set_vc_kbd_led(kbd, VC_CAPSLOCK);
657
}
658
 
659
static void show_ptregs(void)
660
{
661
        if (pt_regs)
662
                show_regs(pt_regs);
663
}
664
 
665
static void hold(void)
666
{
667
        if (rep || !tty)
668
                return;
669
 
670
        /*
671
         * Note: SCROLLOCK will be set (cleared) by stop_tty (start_tty);
672
         * these routines are also activated by ^S/^Q.
673
         * (And SCROLLOCK can also be set by the ioctl KDSKBLED.)
674
         */
675
        if (tty->stopped)
676
                start_tty(tty);
677
        else
678
                stop_tty(tty);
679
}
680
 
681
static void num(void)
682
{
683
        if (vc_kbd_mode(kbd,VC_APPLIC))
684
                applkey('P', 1);
685
        else
686
                bare_num();
687
}
688
 
689
/*
690
 * Bind this to Shift-NumLock if you work in application keypad mode
691
 * but want to be able to change the NumLock flag.
692
 * Bind this to NumLock if you prefer that the NumLock key always
693
 * changes the NumLock flag.
694
 */
695
static void bare_num(void)
696
{
697
        if (!rep)
698
                chg_vc_kbd_led(kbd,VC_NUMLOCK);
699
}
700
 
701
static void lastcons(void)
702
{
703
        /* switch to the last used console, ChN */
704
        set_console(last_console);
705
}
706
 
707
static void decr_console(void)
708
{
709
        int i;
710
 
711
        for (i = fg_console-1; i != fg_console; i--) {
712
                if (i == -1)
713
                        i = MAX_NR_CONSOLES-1;
714
                if (vc_cons_allocated(i))
715
                        break;
716
        }
717
        set_console(i);
718
}
719
 
720
static void incr_console(void)
721
{
722
        int i;
723
 
724
        for (i = fg_console+1; i != fg_console; i++) {
725
                if (i == MAX_NR_CONSOLES)
726
                        i = 0;
727
                if (vc_cons_allocated(i))
728
                        break;
729
        }
730
        set_console(i);
731
}
732
 
733
static void send_intr(void)
734
{
735
        if (!tty)
736
                return;
737
        tty_insert_flip_char(tty, 0, TTY_BREAK);
738
        tty_schedule_flip(tty);
739
}
740
 
741
static void scroll_forw(void)
742
{
743
        scrollfront(0);
744
}
745
 
746
static void scroll_back(void)
747
{
748
        scrollback(0);
749
}
750
 
751
static void boot_it(void)
752
{
753
        ctrl_alt_del();
754
}
755
 
756
static void compose(void)
757
{
758
        dead_key_next = 1;
759
}
760
 
761
int spawnpid, spawnsig;
762
 
763
static void spawn_console(void)
764
{
765
        if (spawnpid)
766
           if(kill_proc(spawnpid, spawnsig, 1))
767
             spawnpid = 0;
768
}
769
 
770
static void SAK(void)
771
{
772
        do_SAK(tty);
773
#if 0
774
        /*
775
         * Need to fix SAK handling to fix up RAW/MEDIUM_RAW and
776
         * vt_cons modes before we can enable RAW/MEDIUM_RAW SAK
777
         * handling.
778
         *
779
         * We should do this some day --- the whole point of a secure
780
         * attention key is that it should be guaranteed to always
781
         * work.
782
         */
783
        reset_vc(fg_console);
784
        do_unblank_screen();    /* not in interrupt routine? */
785
#endif
786
}
787
 
788
static void do_ignore(unsigned char value, char up_flag)
789
{
790
}
791
 
792
static void do_null()
793
{
794
        compute_shiftstate();
795
}
796
 
797
static void do_spec(unsigned char value, char up_flag)
798
{
799
        if (up_flag)
800
                return;
801
        if (value >= SIZE(spec_fn_table))
802
                return;
803
        spec_fn_table[value]();
804
}
805
 
806
static void do_lowercase(unsigned char value, char up_flag)
807
{
808
        printk(KERN_ERR "keyboard.c: do_lowercase was called - impossible\n");
809
}
810
 
811
static void do_self(unsigned char value, char up_flag)
812
{
813
        if (up_flag)
814
                return;         /* no action, if this is a key release */
815
 
816
        if (diacr)
817
                value = handle_diacr(value);
818
 
819
        if (dead_key_next) {
820
                dead_key_next = 0;
821
                diacr = value;
822
                return;
823
        }
824
 
825
        put_queue(value);
826
}
827
 
828
#define A_GRAVE  '`'
829
#define A_ACUTE  '\''
830
#define A_CFLEX  '^'
831
#define A_TILDE  '~'
832
#define A_DIAER  '"'
833
#define A_CEDIL  ','
834
static unsigned char ret_diacr[NR_DEAD] =
835
        {A_GRAVE, A_ACUTE, A_CFLEX, A_TILDE, A_DIAER, A_CEDIL };
836
 
837
/* If a dead key pressed twice, output a character corresponding to it, */
838
/* otherwise just remember the dead key.                                */
839
 
840
static void do_dead(unsigned char value, char up_flag)
841
{
842
        if (up_flag)
843
                return;
844
 
845
        value = ret_diacr[value];
846
        if (diacr == value) {   /* pressed twice */
847
                diacr = 0;
848
                put_queue(value);
849
                return;
850
        }
851
        diacr = value;
852
}
853
 
854
 
855
/* If space is pressed, return the character corresponding the pending  */
856
/* dead key, otherwise try to combine the two.                          */
857
 
858
unsigned char handle_diacr(unsigned char ch)
859
{
860
        int d = diacr;
861
        int i;
862
 
863
        diacr = 0;
864
        if (ch == ' ')
865
                return d;
866
 
867
        for (i = 0; i < accent_table_size; i++) {
868
                if (accent_table[i].diacr == d && accent_table[i].base == ch)
869
                        return accent_table[i].result;
870
        }
871
 
872
        put_queue(d);
873
        return ch;
874
}
875
 
876
static void do_cons(unsigned char value, char up_flag)
877
{
878
        if (up_flag)
879
                return;
880
        set_console(value);
881
}
882
 
883
static void do_fn(unsigned char value, char up_flag)
884
{
885
        if (up_flag)
886
                return;
887
        if (value < SIZE(func_table)) {
888
                if (func_table[value])
889
                        puts_queue(func_table[value]);
890
        } else
891
                printk(KERN_ERR "do_fn called with value=%d\n", value);
892
}
893
 
894
static void do_pad(unsigned char value, char up_flag)
895
{
896
        static const char *pad_chars = "0123456789+-*/\015,.?";
897
        static const char *app_map = "pqrstuvwxylSRQMnn?";
898
 
899
        if (up_flag)
900
                return;         /* no action, if this is a key release */
901
 
902
        /* kludge... shift forces cursor/number keys */
903
        if (vc_kbd_mode(kbd,VC_APPLIC) && !k_down[KG_SHIFT]) {
904
                applkey(app_map[value], 1);
905
                return;
906
        }
907
 
908
        if (!vc_kbd_led(kbd,VC_NUMLOCK))
909
                switch (value) {
910
                        case KVAL(K_PCOMMA):
911
                        case KVAL(K_PDOT):
912
                                do_fn(KVAL(K_REMOVE), 0);
913
                                return;
914
                        case KVAL(K_P0):
915
                                do_fn(KVAL(K_INSERT), 0);
916
                                return;
917
                        case KVAL(K_P1):
918
                                do_fn(KVAL(K_SELECT), 0);
919
                                return;
920
                        case KVAL(K_P2):
921
                                do_cur(KVAL(K_DOWN), 0);
922
                                return;
923
                        case KVAL(K_P3):
924
                                do_fn(KVAL(K_PGDN), 0);
925
                                return;
926
                        case KVAL(K_P4):
927
                                do_cur(KVAL(K_LEFT), 0);
928
                                return;
929
                        case KVAL(K_P6):
930
                                do_cur(KVAL(K_RIGHT), 0);
931
                                return;
932
                        case KVAL(K_P7):
933
                                do_fn(KVAL(K_FIND), 0);
934
                                return;
935
                        case KVAL(K_P8):
936
                                do_cur(KVAL(K_UP), 0);
937
                                return;
938
                        case KVAL(K_P9):
939
                                do_fn(KVAL(K_PGUP), 0);
940
                                return;
941
                        case KVAL(K_P5):
942
                                applkey('G', vc_kbd_mode(kbd, VC_APPLIC));
943
                                return;
944
                }
945
 
946
        put_queue(pad_chars[value]);
947
        if (value == KVAL(K_PENTER) && vc_kbd_mode(kbd, VC_CRLF))
948
                put_queue(10);
949
}
950
 
951
static void do_cur(unsigned char value, char up_flag)
952
{
953
        static const char *cur_chars = "BDCA";
954
        if (up_flag)
955
                return;
956
 
957
        applkey(cur_chars[value], vc_kbd_mode(kbd,VC_CKMODE));
958
}
959
 
960
static void do_shift(unsigned char value, char up_flag)
961
{
962
        int old_state = shift_state;
963
 
964
        if (rep)
965
                return;
966
 
967
        /* Mimic typewriter:
968
           a CapsShift key acts like Shift but undoes CapsLock */
969
        if (value == KVAL(K_CAPSSHIFT)) {
970
                value = KVAL(K_SHIFT);
971
                if (!up_flag)
972
                        clr_vc_kbd_led(kbd, VC_CAPSLOCK);
973
        }
974
 
975
        if (up_flag) {
976
                /* handle the case that two shift or control
977
                   keys are depressed simultaneously */
978
                if (k_down[value])
979
                        k_down[value]--;
980
        } else
981
                k_down[value]++;
982
 
983
        if (k_down[value])
984
                shift_state |= (1 << value);
985
        else
986
                shift_state &= ~ (1 << value);
987
 
988
        /* kludge */
989
        if (up_flag && shift_state != old_state && npadch != -1) {
990
                if (kbd->kbdmode == VC_UNICODE)
991
                  to_utf8(npadch & 0xffff);
992
                else
993
                  put_queue(npadch & 0xff);
994
                npadch = -1;
995
        }
996
}
997
 
998
/* called after returning from RAW mode or when changing consoles -
999
   recompute k_down[] and shift_state from key_down[] */
1000
/* maybe called when keymap is undefined, so that shiftkey release is seen */
1001
void compute_shiftstate(void)
1002
{
1003
        int i, j, k, sym, val;
1004
 
1005
        shift_state = 0;
1006
        for(i=0; i < SIZE(k_down); i++)
1007
          k_down[i] = 0;
1008
 
1009
        for(i=0; i < SIZE(key_down); i++)
1010
          if(key_down[i]) {     /* skip this word if not a single bit on */
1011
            k = i*BITS_PER_LONG;
1012
            for(j=0; j<BITS_PER_LONG; j++,k++)
1013
              if(test_bit(k, key_down)) {
1014
                sym = U(plain_map[k]);
1015
                if(KTYP(sym) == KT_SHIFT) {
1016
                  val = KVAL(sym);
1017
                  if (val == KVAL(K_CAPSSHIFT))
1018
                    val = KVAL(K_SHIFT);
1019
                  k_down[val]++;
1020
                  shift_state |= (1<<val);
1021
                }
1022
              }
1023
          }
1024
}
1025
 
1026
static void do_meta(unsigned char value, char up_flag)
1027
{
1028
        if (up_flag)
1029
                return;
1030
 
1031
        if (vc_kbd_mode(kbd, VC_META)) {
1032
                put_queue('\033');
1033
                put_queue(value);
1034
        } else
1035
                put_queue(value | 0x80);
1036
}
1037
 
1038
static void do_ascii(unsigned char value, char up_flag)
1039
{
1040
        int base;
1041
 
1042
        if (up_flag)
1043
                return;
1044
 
1045
        if (value < 10)    /* decimal input of code, while Alt depressed */
1046
            base = 10;
1047
        else {       /* hexadecimal input of code, while AltGr depressed */
1048
            value -= 10;
1049
            base = 16;
1050
        }
1051
 
1052
        if (npadch == -1)
1053
          npadch = value;
1054
        else
1055
          npadch = npadch * base + value;
1056
}
1057
 
1058
static void do_lock(unsigned char value, char up_flag)
1059
{
1060
        if (up_flag || rep)
1061
                return;
1062
        chg_vc_kbd_lock(kbd, value);
1063
}
1064
 
1065
static void do_slock(unsigned char value, char up_flag)
1066
{
1067
        if (up_flag || rep)
1068
                return;
1069
        chg_vc_kbd_slock(kbd, value);
1070
}
1071
 
1072
/*
1073
 * send_data sends a character to the keyboard and waits
1074
 * for a acknowledge, possibly retrying if asked to. Returns
1075
 * the success status.
1076
 */
1077
static int send_data(unsigned char data)
1078
{
1079
        int retries = 3;
1080
        int i;
1081
 
1082
        do {
1083
                kb_wait();
1084
                acknowledge = 0;
1085
                resend = 0;
1086
                reply_expected = 1;
1087
 
1088
                outb_p(data, KBD_BASE_ADD+0x0);
1089
                for(i=0; i<0x200000; i++) {
1090
                        extern void allow_interrupts(void);
1091
                        allow_interrupts();
1092
                        inb_p(KBD_BASE_ADD+0x4);                /* just as a delay */
1093
                        if (acknowledge)
1094
                                return 1;
1095
                        if (resend)
1096
                                break;
1097
                }
1098
                if (!resend)
1099
                        return 0;
1100
        } while (retries-- > 0);
1101
        return 0;
1102
}
1103
 
1104
/*
1105
 * The leds display either (i) the status of NumLock, CapsLock, ScrollLock,
1106
 * or (ii) whatever pattern of lights people want to show using KDSETLED,
1107
 * or (iii) specified bits of specified words in kernel memory.
1108
 */
1109
 
1110
static unsigned char ledstate = 0xff; /* undefined */
1111
static unsigned char ledioctl;
1112
 
1113
unsigned char getledstate(void) {
1114
    return ledstate;
1115
}
1116
 
1117
void setledstate(struct kbd_struct *kbd, unsigned int led) {
1118
    if (!(led & ~7)) {
1119
        ledioctl = led;
1120
        kbd->ledmode = LED_SHOW_IOCTL;
1121
    } else
1122
        kbd->ledmode = LED_SHOW_FLAGS;
1123
    set_leds();
1124
}
1125
 
1126
static struct ledptr {
1127
    unsigned int *addr;
1128
    unsigned int mask;
1129
    unsigned char valid:1;
1130
} ledptrs[3];
1131
 
1132
void register_leds(int console, unsigned int led,
1133
                   unsigned int *addr, unsigned int mask) {
1134
    struct kbd_struct *kbd = kbd_table + console;
1135
    if (led < 3) {
1136
        ledptrs[led].addr = addr;
1137
        ledptrs[led].mask = mask;
1138
        ledptrs[led].valid = 1;
1139
        kbd->ledmode = LED_SHOW_MEM;
1140
    } else
1141
        kbd->ledmode = LED_SHOW_FLAGS;
1142
}
1143
 
1144
static inline unsigned char getleds(void){
1145
    struct kbd_struct *kbd = kbd_table + fg_console;
1146
    unsigned char leds;
1147
 
1148
    if (kbd->ledmode == LED_SHOW_IOCTL)
1149
      return ledioctl;
1150
    leds = kbd->ledflagstate;
1151
    if (kbd->ledmode == LED_SHOW_MEM) {
1152
        if (ledptrs[0].valid) {
1153
            if (*ledptrs[0].addr & ledptrs[0].mask)
1154
              leds |= 1;
1155
            else
1156
              leds &= ~1;
1157
        }
1158
        if (ledptrs[1].valid) {
1159
            if (*ledptrs[1].addr & ledptrs[1].mask)
1160
              leds |= 2;
1161
            else
1162
              leds &= ~2;
1163
        }
1164
        if (ledptrs[2].valid) {
1165
            if (*ledptrs[2].addr & ledptrs[2].mask)
1166
              leds |= 4;
1167
            else
1168
              leds &= ~4;
1169
        }
1170
    }
1171
    return leds;
1172
}
1173
 
1174
/*
1175
 * This routine is the bottom half of the keyboard interrupt
1176
 * routine, and runs with all interrupts enabled. It does
1177
 * console changing, led setting and copy_to_cooked, which can
1178
 * take a reasonably long time.
1179
 *
1180
 * Aside from timing (which isn't really that important for
1181
 * keyboard interrupts as they happen often), using the software
1182
 * interrupt routines for this thing allows us to easily mask
1183
 * this when we don't want any of the above to happen. Not yet
1184
 * used, but this allows for easy and efficient race-condition
1185
 * prevention later on.
1186
 */
1187
static void kbd_bh(void)
1188
{
1189
        unsigned char leds = getleds();
1190
 
1191
        if (leds != ledstate) {
1192
                ledstate = leds;
1193
                if (!send_data(0xed) || !send_data(leds))
1194
                        send_data(0xf4);        /* re-enable kbd if any errors */
1195
        }
1196
}
1197
 
1198
int kbd_init(void)
1199
{
1200
        int i;
1201
        struct kbd_struct kbd0;
1202
        extern struct tty_driver console_driver;
1203
 
1204
        kbd0.ledflagstate = kbd0.default_ledflagstate = KBD_DEFLEDS;
1205
        kbd0.ledmode = LED_SHOW_FLAGS;
1206
        kbd0.lockstate = KBD_DEFLOCK;
1207
        kbd0.slockstate = 0;
1208
        kbd0.modeflags = KBD_DEFMODE;
1209
        kbd0.kbdmode = VC_XLATE;
1210
 
1211
        for (i = 0 ; i < MAX_NR_CONSOLES ; i++)
1212
                kbd_table[i] = kbd0;
1213
 
1214
        ttytab = console_driver.table;
1215
 
1216
        request_irq(KEYBOARD_IRQ, keyboard_interrupt, 0, "keyboard", NULL);
1217
        request_region(KBD_BASE_ADD+0x0,16,"keyboard");
1218
#ifdef INIT_KBD
1219
        initialize_kbd();
1220
#endif
1221
        init_bh(KEYBOARD_BH, kbd_bh);
1222
        mark_bh(KEYBOARD_BH);
1223
        return 0;
1224
}
1225
 
1226
#ifdef INIT_KBD
1227
/*
1228
 * keyboard controller registers
1229
 */
1230
#define KBD_STATUS_REG      (unsigned int) KBD_BASE_ADD+0x4
1231
#define KBD_CNTL_REG        (unsigned int) KBD_BASE_ADD+0x4
1232
#define KBD_DATA_REG        (unsigned int) KBD_BASE_ADD+0x0
1233
/*
1234
 * controller commands
1235
 */
1236
#define KBD_READ_MODE       (unsigned int) 0x20
1237
#define KBD_WRITE_MODE      (unsigned int) 0x60
1238
#define KBD_SELF_TEST       (unsigned int) 0xAA
1239
#define KBD_SELF_TEST2      (unsigned int) 0xAB
1240
#define KBD_CNTL_ENABLE     (unsigned int) 0xAE
1241
/*
1242
 * keyboard commands
1243
 */
1244
#define KBD_ENABLE          (unsigned int) 0xF4
1245
#define KBD_DISABLE         (unsigned int) 0xF5
1246
#define KBD_RESET           (unsigned int) 0xFF
1247
/*
1248
 * keyboard replies
1249
 */
1250
#define KBD_ACK             (unsigned int) 0xFA
1251
#define KBD_POR             (unsigned int) 0xAA
1252
/*
1253
 * status register bits
1254
 */
1255
#define KBD_OBF             (unsigned int) 0x01
1256
#define KBD_IBF             (unsigned int) 0x02
1257
#define KBD_GTO             (unsigned int) 0x40
1258
#define KBD_PERR            (unsigned int) 0x80
1259
/*
1260
 * keyboard controller mode register bits
1261
 */
1262
#define KBD_EKI             (unsigned int) 0x01
1263
#define KBD_SYS             (unsigned int) 0x04
1264
#define KBD_DMS             (unsigned int) 0x20
1265
#define KBD_KCC             (unsigned int) 0x40
1266
 
1267
#define TIMEOUT_CONST   5000000
1268
 
1269
static int kbd_wait_for_input(void)
1270
{
1271
        int     n;
1272
        int     status, data;
1273
 
1274
        n = TIMEOUT_CONST;
1275
        do {
1276
                status = inb(KBD_STATUS_REG);
1277
                /*
1278
                 * Wait for input data to become available.  This bit will
1279
                 * then be cleared by the following read of the DATA
1280
                 * register.
1281
                 */
1282
 
1283
                if (!(status & KBD_OBF))
1284
                        continue;
1285
 
1286
                data = inb(KBD_DATA_REG);
1287
 
1288
                /*
1289
                 * Check to see if a timeout error has occurred.  This means
1290
                 * that transmission was started but did not complete in the
1291
                 * normal time cycle.  PERR is set when a parity error occurred
1292
                 * in the last transmission.
1293
                 */
1294
                if (status & (KBD_GTO | KBD_PERR)) {
1295
                        continue;
1296
                }
1297
                return (data & 0xff);
1298
        } while (--n);
1299
        return (-1);    /* timed-out if fell through to here... */
1300
}
1301
 
1302
static void kbd_write(int address, int data)
1303
{
1304
        int status;
1305
 
1306
        do {
1307
                status = inb(KBD_STATUS_REG);  /* spin until input buffer empty*/
1308
        } while (status & KBD_IBF);
1309
        outb(data, address);               /* write out the data*/
1310
}
1311
 
1312
static int initialize_kbd(void)
1313
{
1314
        unsigned long flags;
1315
 
1316
        save_flags(flags); cli();
1317
 
1318
        /* Flush any pending input. */
1319
        while (kbd_wait_for_input() != -1)
1320
                continue;
1321
 
1322
        /*
1323
         * Test the keyboard interface.
1324
         * This seems to be the only way to get it going.
1325
         * If the test is successful a x55 is placed in the input buffer.
1326
         */
1327
        kbd_write(KBD_CNTL_REG, KBD_SELF_TEST);
1328
        if (kbd_wait_for_input() != 0x55) {
1329
                printk(KERN_WARNING "initialize_kbd: "
1330
                       "keyboard failed self test.\n");
1331
                restore_flags(flags);
1332
                return(-1);
1333
        }
1334
 
1335
        /*
1336
         * Perform a keyboard interface test.  This causes the controller
1337
         * to test the keyboard clock and data lines.  The results of the
1338
         * test are placed in the input buffer.
1339
         */
1340
        kbd_write(KBD_CNTL_REG, KBD_SELF_TEST2);
1341
        if (kbd_wait_for_input() != 0x00) {
1342
                printk(KERN_WARNING "initialize_kbd: "
1343
                       "keyboard failed self test 2.\n");
1344
                restore_flags(flags);
1345
                return(-1);
1346
        }
1347
 
1348
        /* Enable the keyboard by allowing the keyboard clock to run. */
1349
        kbd_write(KBD_CNTL_REG, KBD_CNTL_ENABLE);
1350
 
1351
        /*
1352
         * Reset keyboard. If the read times out
1353
         * then the assumption is that no keyboard is
1354
         * plugged into the machine.
1355
         * This defaults the keyboard to scan-code set 2.
1356
         */
1357
        kbd_write(KBD_DATA_REG, KBD_RESET);
1358
        if (kbd_wait_for_input() != KBD_ACK) {
1359
                printk(KERN_WARNING "initialize_kbd: "
1360
                       "reset kbd failed, no ACK.\n");
1361
                restore_flags(flags);
1362
                return(-1);
1363
        }
1364
 
1365
        if (kbd_wait_for_input() != KBD_POR) {
1366
                printk(KERN_WARNING "initialize_kbd: "
1367
                       "reset kbd failed, not POR.\n");
1368
                restore_flags(flags);
1369
                return(-1);
1370
        }
1371
 
1372
        /*
1373
         * now do a DEFAULTS_DISABLE always
1374
         */
1375
        kbd_write(KBD_DATA_REG, KBD_DISABLE);
1376
        if (kbd_wait_for_input() != KBD_ACK) {
1377
                printk(KERN_WARNING "initialize_kbd: "
1378
                       "disable kbd failed, no ACK.\n");
1379
                restore_flags(flags);
1380
                return(-1);
1381
        }
1382
 
1383
        /*
1384
         * Enable keyboard interrupt, operate in "sys" mode,
1385
         *  enable keyboard (by clearing the disable keyboard bit),
1386
         *  disable mouse, do conversion of keycodes.
1387
         */
1388
        kbd_write(KBD_CNTL_REG, KBD_WRITE_MODE);
1389
        kbd_write(KBD_DATA_REG, KBD_EKI|KBD_SYS|KBD_DMS|KBD_KCC);
1390
 
1391
        /*
1392
         * now ENABLE the keyboard to set it scanning...
1393
         */
1394
        kbd_write(KBD_DATA_REG, KBD_ENABLE);
1395
        if (kbd_wait_for_input() != KBD_ACK) {
1396
                printk(KERN_WARNING "initialize_kbd: "
1397
                       "keyboard enable failed.\n");
1398
                restore_flags(flags);
1399
                return(-1);
1400
        }
1401
 
1402
        restore_flags(flags);
1403
 
1404
        printk("PS/2 keyboard initialized at 0x%x (irq = %d).\n", KBD_BASE_ADD, KEYBOARD_IRQ);
1405
        return (1);
1406
}
1407
#endif /* INIT_KBD */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.