1 /* $Id: pcikbd.c,v 1.35 1999/09/01 08:09:26 davem Exp $
2 * pcikbd.c: Ultra/AX PC keyboard support.
4 * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
5 * JavaStation support by Pete A. Zaitcev.
7 * This code is mainly put together from various places in
8 * drivers/char, please refer to these sources for credits
9 * to the original authors.
12 #include <linux/config.h>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/interrupt.h>
17 #include <linux/ioport.h>
18 #include <linux/poll.h>
19 #include <linux/malloc.h>
20 #include <linux/errno.h>
21 #include <linux/random.h>
22 #include <linux/miscdevice.h>
23 #include <linux/kbd_ll.h>
24 #include <linux/delay.h>
25 #include <linux/init.h>
28 #include <asm/oplib.h>
31 #include <asm/uaccess.h>
34 * Different platforms provide different permutations of names.
35 * AXi - kb_ps2, kdmouse.
36 * MrCoffee - keyboard, mouse.
37 * Espresso - keyboard, kdmouse.
39 #define PCI_KB_NAME1 "kb_ps2"
40 #define PCI_KB_NAME2 "keyboard"
41 #define PCI_MS_NAME1 "kdmouse"
42 #define PCI_MS_NAME2 "mouse"
45 #include "sunserial.h"
48 static int pcikbd_mrcoffee
= 0;
50 #define pcikbd_mrcoffee 0
53 static unsigned long pcikbd_iobase
= 0;
54 static unsigned int pcikbd_irq
= 0;
56 /* used only by send_data - set by keyboard_interrupt */
57 static volatile unsigned char reply_expected
= 0;
58 static volatile unsigned char acknowledge
= 0;
59 static volatile unsigned char resend
= 0;
61 unsigned char pckbd_read_mask
= KBD_STAT_OBF
;
63 extern int pcikbd_init(void);
64 extern void pci_compute_shiftstate(void);
65 extern int pci_setkeycode(unsigned int, unsigned int);
66 extern int pci_getkeycode(unsigned int);
67 extern void pci_setledstate(struct kbd_struct
*, unsigned int);
68 extern unsigned char pci_getledstate(void);
72 static __inline__
unsigned char pcikbd_inb(unsigned long port
)
77 static __inline__
void pcikbd_outb(unsigned char val
, unsigned long port
)
84 static __inline__
unsigned char pcikbd_inb(unsigned long port
)
86 return *(volatile unsigned char *)port
;
89 static __inline__
void pcikbd_outb(unsigned char val
, unsigned long port
)
91 *(volatile unsigned char *)port
= val
;
96 static inline void kb_wait(void)
98 unsigned long start
= jiffies
;
101 if(!(pcikbd_inb(pcikbd_iobase
+ KBD_STATUS_REG
) & KBD_STAT_IBF
))
103 } while (jiffies
- start
< KBC_TIMEOUT
);
107 * Translation of escaped scancodes to keycodes.
108 * This is now user-settable.
109 * The keycodes 1-88,96-111,119 are fairly standard, and
110 * should probably not be changed - changing might confuse X.
111 * X also interprets scancode 0x5d (KEY_Begin).
113 * For 1-88 keycode equals scancode.
116 #define E0_KPENTER 96
118 #define E0_KPSLASH 98
121 #define E0_BREAK 101 /* (control-pause) */
136 * The keycodes below are randomly located in 89-95,112-118,120-127.
137 * They could be thrown away (and all occurrences below replaced by 0),
138 * but that would force many users to use the `setkeycodes' utility, where
139 * they needed not before. It does not matter that there are duplicates, as
140 * long as no duplication occurs for any single keyboard.
144 #define FOCUS_PF1 85 /* actual code! */
152 #define FOCUS_PF9 120
153 #define FOCUS_PF10 121
154 #define FOCUS_PF11 122
155 #define FOCUS_PF12 123
158 /* tfj@olivia.ping.dk:
159 * The four keys are located over the numeric keypad, and are
160 * labelled A1-A4. It's an rc930 keyboard, from
161 * Regnecentralen/RC International, Now ICL.
162 * Scancodes: 59, 5a, 5b, 5c.
169 static unsigned char high_keys
[128 - SC_LIM
] = {
170 RGN1
, RGN2
, RGN3
, RGN4
, 0, 0, 0, /* 0x59-0x5f */
171 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60-0x67 */
172 0, 0, 0, 0, 0, FOCUS_PF11
, 0, FOCUS_PF12
, /* 0x68-0x6f */
173 0, 0, 0, FOCUS_PF2
, FOCUS_PF9
, 0, 0, FOCUS_PF3
, /* 0x70-0x77 */
174 FOCUS_PF4
, FOCUS_PF5
, FOCUS_PF6
, FOCUS_PF7
, /* 0x78-0x7b */
175 FOCUS_PF8
, JAP_86
, FOCUS_PF10
, 0 /* 0x7c-0x7f */
186 #define E0_KPMINPLUS 118
188 * My OmniKey generates e0 4c for the "OMNI" key and the
189 * right alt key does nada. [kkoller@nyx10.cs.du.edu]
193 * New microsoft keyboard is rumoured to have
194 * e0 5b (left window button), e0 5c (right window button),
195 * e0 5d (menu button). [or: LBANNER, RBANNER, RMENU]
196 * [or: Windows_L, Windows_R, TaskMan]
202 static unsigned char e0_keys
[128] = {
203 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00-0x07 */
204 0, 0, 0, 0, 0, 0, 0, 0, /* 0x08-0x0f */
205 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10-0x17 */
206 0, 0, 0, 0, E0_KPENTER
, E0_RCTRL
, 0, 0, /* 0x18-0x1f */
207 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20-0x27 */
208 0, 0, 0, 0, 0, 0, 0, 0, /* 0x28-0x2f */
209 0, 0, 0, 0, 0, E0_KPSLASH
, 0, E0_PRSCR
, /* 0x30-0x37 */
210 E0_RALT
, 0, 0, 0, 0, E0_F13
, E0_F14
, E0_HELP
, /* 0x38-0x3f */
211 E0_DO
, E0_F17
, 0, 0, 0, 0, E0_BREAK
, E0_HOME
, /* 0x40-0x47 */
212 E0_UP
, E0_PGUP
, 0, E0_LEFT
, E0_OK
, E0_RIGHT
, E0_KPMINPLUS
, E0_END
,/* 0x48-0x4f */
213 E0_DOWN
, E0_PGDN
, E0_INS
, E0_DEL
, 0, 0, 0, 0, /* 0x50-0x57 */
214 0, 0, 0, E0_MSLW
, E0_MSRW
, E0_MSTM
, 0, 0, /* 0x58-0x5f */
215 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60-0x67 */
216 0, 0, 0, 0, 0, 0, 0, E0_MACRO
, /* 0x68-0x6f */
217 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70-0x77 */
218 0, 0, 0, 0, 0, 0, 0, 0 /* 0x78-0x7f */
221 /* Simple translation table for the SysRq keys */
223 #ifdef CONFIG_MAGIC_SYSRQ
224 unsigned char pcikbd_sysrq_xlate
[128] =
225 "\000\0331234567890-=\177\t" /* 0x00 - 0x0f */
226 "qwertyuiop[]\r\000as" /* 0x10 - 0x1f */
227 "dfghjkl;'`\000\\zxcv" /* 0x20 - 0x2f */
228 "bnm,./\000*\000 \000\201\202\203\204\205" /* 0x30 - 0x3f */
229 "\206\207\210\211\212\000\000789-456+1" /* 0x40 - 0x4f */
230 "230\177\000\000\213\214\000\000\000\000\000\000\000\000\000\000" /* 0x50 - 0x5f */
231 "\r\000/"; /* 0x60 - 0x6f */
234 int pcikbd_setkeycode(unsigned int scancode
, unsigned int keycode
)
236 if(scancode
< SC_LIM
|| scancode
> 255 || keycode
> 127)
239 high_keys
[scancode
- SC_LIM
] = keycode
;
241 e0_keys
[scancode
- 128] = keycode
;
245 int pcikbd_getkeycode(unsigned int scancode
)
248 (scancode
< SC_LIM
|| scancode
> 255) ? -EINVAL
:
249 (scancode
< 128) ? high_keys
[scancode
- SC_LIM
] :
250 e0_keys
[scancode
- 128];
253 int do_acknowledge(unsigned char scancode
)
256 if(scancode
== KBD_REPLY_ACK
) {
260 } else if(scancode
== KBD_REPLY_RESEND
) {
269 int pcikbd_translate(unsigned char scancode
, unsigned char *keycode
,
272 static int prev_scancode
= 0;
274 if (scancode
== 0xe0 || scancode
== 0xe1) {
275 prev_scancode
= scancode
;
278 if (scancode
== 0x00 || scancode
== 0xff) {
284 if(prev_scancode
!= 0xe0) {
285 if(prev_scancode
== 0xe1 && scancode
== 0x1d) {
286 prev_scancode
= 0x100;
288 } else if(prev_scancode
== 0x100 && scancode
== 0x45) {
297 if(scancode
== 0x2a || scancode
== 0x36)
299 if(e0_keys
[scancode
])
300 *keycode
= e0_keys
[scancode
];
304 } else if(scancode
>= SC_LIM
) {
305 *keycode
= high_keys
[scancode
- SC_LIM
];
314 char pcikbd_unexpected_up(unsigned char keycode
)
316 if(keycode
>= SC_LIM
|| keycode
== 85)
323 pcikbd_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
325 unsigned char status
;
328 status
= pcikbd_inb(pcikbd_iobase
+ KBD_STATUS_REG
);
330 unsigned char scancode
;
332 if(status
& pckbd_read_mask
& KBD_STAT_MOUSE_OBF
)
334 scancode
= pcikbd_inb(pcikbd_iobase
+ KBD_DATA_REG
);
335 if((status
& KBD_STAT_OBF
) && do_acknowledge(scancode
))
336 handle_scancode(scancode
, !(scancode
& 0x80));
337 status
= pcikbd_inb(pcikbd_iobase
+ KBD_STATUS_REG
);
338 } while(status
& KBD_STAT_OBF
);
339 mark_bh(KEYBOARD_BH
);
342 static int send_data(unsigned char data
)
349 acknowledge
= resend
= 0;
351 pcikbd_outb(data
, pcikbd_iobase
+ KBD_DATA_REG
);
356 if(jiffies
- start
>= KBD_TIMEOUT
)
359 } while(retries
-- > 0);
363 void pcikbd_leds(unsigned char leds
)
365 if(!send_data(KBD_CMD_SET_LEDS
) || !send_data(leds
))
366 send_data(KBD_CMD_ENABLE
);
370 static int __init
pcikbd_wait_for_input(void)
373 unsigned long start
= jiffies
;
376 status
= pcikbd_inb(pcikbd_iobase
+ KBD_STATUS_REG
);
377 if(!(status
& KBD_STAT_OBF
))
379 data
= pcikbd_inb(pcikbd_iobase
+ KBD_DATA_REG
);
380 if(status
& (KBD_STAT_GTO
| KBD_STAT_PERR
))
382 return (data
& 0xff);
383 } while(jiffies
- start
< KBD_INIT_TIMEOUT
);
387 static void __init
pcikbd_write(int address
, int data
)
392 status
= pcikbd_inb(pcikbd_iobase
+ KBD_STATUS_REG
);
393 } while (status
& KBD_STAT_IBF
);
394 pcikbd_outb(data
, pcikbd_iobase
+ address
);
399 static unsigned long pcibeep_iobase
= 0;
401 /* Timer routine to turn off the beep after the interval expires. */
402 static void pcikbd_kd_nosound(unsigned long __unused
)
404 outl(0, pcibeep_iobase
);
408 * Initiate a keyboard beep. If the frequency is zero, then we stop
409 * the beep. Any other frequency will start a monotone beep. The beep
410 * will be stopped by a timer after "ticks" jiffies. If ticks is 0,
411 * then we do not start a timer.
413 static void pcikbd_kd_mksound(unsigned int hz
, unsigned int ticks
)
416 static struct timer_list sound_timer
= { NULL
, NULL
, 0, 0,
419 save_flags(flags
); cli();
420 del_timer(&sound_timer
);
422 outl(1, pcibeep_iobase
);
424 sound_timer
.expires
= jiffies
+ ticks
;
425 add_timer(&sound_timer
);
428 outl(0, pcibeep_iobase
);
429 restore_flags(flags
);
433 static void nop_kd_mksound(unsigned int hz
, unsigned int ticks
)
437 extern void (*kd_mksound
)(unsigned int hz
, unsigned int ticks
);
439 static char * __init
do_pcikbd_init_hw(void)
442 while(pcikbd_wait_for_input() != -1)
445 pcikbd_write(KBD_CNTL_REG
, KBD_CCMD_SELF_TEST
);
446 if(pcikbd_wait_for_input() != 0x55)
447 return "Keyboard failed self test";
449 pcikbd_write(KBD_CNTL_REG
, KBD_CCMD_KBD_TEST
);
450 if(pcikbd_wait_for_input() != 0x00)
451 return "Keyboard interface failed self test";
453 pcikbd_write(KBD_CNTL_REG
, KBD_CCMD_KBD_ENABLE
);
454 pcikbd_write(KBD_DATA_REG
, KBD_CMD_RESET
);
455 if(pcikbd_wait_for_input() != KBD_REPLY_ACK
)
456 return "Keyboard reset failed, no ACK";
457 if(pcikbd_wait_for_input() != KBD_REPLY_POR
)
458 return "Keyboard reset failed, no ACK";
460 pcikbd_write(KBD_DATA_REG
, KBD_CMD_DISABLE
);
461 if(pcikbd_wait_for_input() != KBD_REPLY_ACK
)
462 return "Disable keyboard: no ACK";
464 pcikbd_write(KBD_CNTL_REG
, KBD_CCMD_WRITE_MODE
);
465 pcikbd_write(KBD_DATA_REG
,
466 (KBD_MODE_KBD_INT
| KBD_MODE_SYS
|
467 KBD_MODE_DISABLE_MOUSE
| KBD_MODE_KCC
));
468 pcikbd_write(KBD_DATA_REG
, KBD_CMD_ENABLE
);
469 if(pcikbd_wait_for_input() != KBD_REPLY_ACK
)
470 return "Enable keyboard: no ACK";
472 pcikbd_write(KBD_DATA_REG
, KBD_CMD_SET_RATE
);
473 if(pcikbd_wait_for_input() != KBD_REPLY_ACK
)
474 return "Set rate: no ACK";
475 pcikbd_write(KBD_DATA_REG
, 0x00);
476 if(pcikbd_wait_for_input() != KBD_REPLY_ACK
)
477 return "Set rate: no ACK";
479 return NULL
; /* success */
482 void __init
pcikbd_init_hw(void)
484 struct linux_ebus
*ebus
;
485 struct linux_ebus_device
*edev
;
486 struct linux_ebus_child
*child
;
489 if (pcikbd_mrcoffee
) {
490 if ((pcikbd_iobase
= (unsigned long) sparc_alloc_io(0x71300060,
491 0, 8, "ps2kbd-regs", 0x0, 0)) == 0) {
492 prom_printf("pcikbd_init_hw: cannot map\n");
495 pcikbd_irq
= 13 | 0x20;
496 if (request_irq(pcikbd_irq
, &pcikbd_interrupt
,
497 SA_SHIRQ
, "keyboard", (void *)pcikbd_iobase
)) {
498 printk("8042: cannot register IRQ %x\n", pcikbd_irq
);
501 printk("8042(kbd): iobase[%08x] irq[%x]\n",
502 (unsigned)pcikbd_iobase
, pcikbd_irq
);
504 for_each_ebus(ebus
) {
505 for_each_ebusdev(edev
, ebus
) {
506 if(!strcmp(edev
->prom_name
, "8042")) {
507 for_each_edevchild(edev
, child
) {
508 if (strcmp(child
->prom_name
, PCI_KB_NAME1
) == 0 ||
509 strcmp(child
->prom_name
, PCI_KB_NAME2
) == 0)
515 printk("pcikbd_init_hw: no 8042 found\n");
519 pcikbd_iobase
= child
->resource
[0].start
;
520 pcikbd_irq
= child
->irqs
[0];
521 if (request_irq(pcikbd_irq
, &pcikbd_interrupt
,
522 SA_SHIRQ
, "keyboard", (void *)pcikbd_iobase
)) {
523 printk("8042: cannot register IRQ %s\n",
524 __irq_itoa(pcikbd_irq
));
528 printk("8042(kbd) at 0x%lx (irq %s)\n", pcikbd_iobase
,
529 __irq_itoa(pcikbd_irq
));
532 kd_mksound
= nop_kd_mksound
;
536 for_each_ebus(ebus
) {
537 for_each_ebusdev(edev
, ebus
) {
538 if(!strcmp(edev
->prom_name
, "beeper"))
545 * XXX: my 3.1.3 PROM does not give me the beeper node for the audio
546 * auxio register, though I know it is there... (ecd)
548 * JavaStations appear not to have beeper. --zaitcev
551 pcibeep_iobase
= (pcikbd_iobase
& ~(0xffffff)) | 0x722000;
553 pcibeep_iobase
= edev
->resource
[0].start
;
555 kd_mksound
= pcikbd_kd_mksound
;
556 printk("8042(speaker): iobase[%016lx]%s\n", pcibeep_iobase
,
557 edev
? "" : " (forced)");
560 disable_irq(pcikbd_irq
);
561 msg
= do_pcikbd_init_hw();
562 enable_irq(pcikbd_irq
);
565 printk("8042: keyboard init failure [%s]\n", msg
);
570 * Here begins the Mouse Driver.
573 static unsigned long pcimouse_iobase
= 0;
574 static unsigned int pcimouse_irq
;
576 #define AUX_BUF_SIZE 2048
581 wait_queue_head_t proc_list
;
582 struct fasync_struct
*fasync
;
583 unsigned char buf
[AUX_BUF_SIZE
];
586 static struct aux_queue
*queue
;
587 static int aux_ready
= 0;
588 static int aux_count
= 0;
589 static int aux_present
= 0;
593 static __inline__
unsigned char pcimouse_inb(unsigned long port
)
598 static __inline__
void pcimouse_outb(unsigned char val
, unsigned long port
)
605 static __inline__
unsigned char pcimouse_inb(unsigned long port
)
607 return *(volatile unsigned char *)port
;
610 static __inline__
void pcimouse_outb(unsigned char val
, unsigned long port
)
612 *(volatile unsigned char *)port
= val
;
621 static unsigned int get_from_queue(void)
628 result
= queue
->buf
[queue
->tail
];
629 queue
->tail
= (queue
->tail
+ 1) & (AUX_BUF_SIZE
-1);
630 restore_flags(flags
);
635 static inline int queue_empty(void)
637 return queue
->head
== queue
->tail
;
640 static int aux_fasync(int fd
, struct file
*filp
, int on
)
644 retval
= fasync_helper(fd
, filp
, on
, &queue
->fasync
);
654 #define AUX_INTS_OFF (KBD_MODE_KCC | KBD_MODE_DISABLE_MOUSE | \
655 KBD_MODE_SYS | KBD_MODE_KBD_INT)
657 #define AUX_INTS_ON (KBD_MODE_KCC | KBD_MODE_SYS | \
658 KBD_MODE_MOUSE_INT | KBD_MODE_KBD_INT)
660 #define MAX_RETRIES 60 /* some aux operations take long time*/
666 static int poll_aux_status(void)
670 while ((pcimouse_inb(pcimouse_iobase
+ KBD_STATUS_REG
) &
671 (KBD_STAT_IBF
| KBD_STAT_OBF
)) && retries
< MAX_RETRIES
) {
672 if ((pcimouse_inb(pcimouse_iobase
+ KBD_STATUS_REG
) & AUX_STAT_OBF
)
674 pcimouse_inb(pcimouse_iobase
+ KBD_DATA_REG
);
675 current
->state
= TASK_INTERRUPTIBLE
;
676 schedule_timeout((5*HZ
+ 99) / 100);
679 return (retries
< MAX_RETRIES
);
683 * Write to aux device
686 static void aux_write_dev(int val
)
689 pcimouse_outb(KBD_CCMD_WRITE_MOUSE
, pcimouse_iobase
+ KBD_CNTL_REG
);/* Write magic cookie */
691 pcimouse_outb(val
, pcimouse_iobase
+ KBD_DATA_REG
); /* Write data */
696 * Write to device & handle returned ack
699 static int __init
aux_write_ack(int val
)
704 if ((pcimouse_inb(pcimouse_iobase
+ KBD_STATUS_REG
) & AUX_STAT_OBF
) == AUX_STAT_OBF
)
705 return (pcimouse_inb(pcimouse_iobase
+ KBD_DATA_REG
));
710 * Write aux device command
713 static void aux_write_cmd(int val
)
716 pcimouse_outb(KBD_CCMD_WRITE_MODE
, pcimouse_iobase
+ KBD_CNTL_REG
);
718 pcimouse_outb(val
, pcimouse_iobase
+ KBD_DATA_REG
);
722 * AUX handler critical section start and end.
724 * Only one process can be in the critical section and all keyboard sends are
725 * deferred as long as we're inside. This is necessary as we may sleep when
726 * waiting for the keyboard controller and other processes / BH's can
727 * preempt us. Please note that the input buffer must be flushed when
728 * aux_end_atomic() is called and the interrupt is no longer enabled as not
729 * doing so might cause the keyboard driver to ignore all incoming keystrokes.
732 static DECLARE_MUTEX(aux_sema4
);
734 static inline void aux_start_atomic(void)
737 disable_bh(KEYBOARD_BH
);
740 static inline void aux_end_atomic(void)
742 enable_bh(KEYBOARD_BH
);
747 * Interrupt from the auxiliary device: a character
748 * is waiting in the keyboard/aux controller.
751 void pcimouse_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
753 int head
= queue
->head
;
754 int maxhead
= (queue
->tail
-1) & (AUX_BUF_SIZE
-1);
756 if ((pcimouse_inb(pcimouse_iobase
+ KBD_STATUS_REG
) & AUX_STAT_OBF
) != AUX_STAT_OBF
)
759 add_mouse_randomness(queue
->buf
[head
] = pcimouse_inb(pcimouse_iobase
+ KBD_DATA_REG
));
760 if (head
!= maxhead
) {
762 head
&= AUX_BUF_SIZE
-1;
767 kill_fasync(queue
->fasync
, SIGIO
);
768 wake_up_interruptible(&queue
->proc_list
);
771 static int aux_release(struct inode
* inode
, struct file
* file
)
773 aux_fasync(-1, file
, 0);
778 /* Disable controller ints */
779 aux_write_cmd(AUX_INTS_OFF
);
782 /* Disable Aux device */
783 pcimouse_outb(KBD_CCMD_MOUSE_DISABLE
, pcimouse_iobase
+ KBD_CNTL_REG
);
792 * Install interrupt handler.
793 * Enable auxiliary device.
796 static int aux_open(struct inode
* inode
, struct file
* file
)
806 if (!poll_aux_status()) { /* FIXME: Race condition */
811 queue
->head
= queue
->tail
= 0; /* Flush input queue */
816 pcimouse_outb(KBD_CCMD_MOUSE_ENABLE
, pcimouse_iobase
+KBD_CNTL_REG
); /* Enable Aux */
817 aux_write_dev(AUX_ENABLE_DEV
); /* Enable aux device */
818 aux_write_cmd(AUX_INTS_ON
); /* Enable controller ints */
827 * Write to the aux device.
830 static ssize_t
aux_write(struct file
* file
, const char * buffer
,
831 size_t count
, loff_t
*ppos
)
841 if (!poll_aux_status())
843 pcimouse_outb(KBD_CCMD_WRITE_MOUSE
, pcimouse_iobase
+ KBD_CNTL_REG
);
844 if (!poll_aux_status())
846 get_user(c
, buffer
++);
847 pcimouse_outb(c
, pcimouse_iobase
+ KBD_DATA_REG
);
854 file
->f_dentry
->d_inode
->i_mtime
= CURRENT_TIME
;
862 * Generic part continues...
866 * Put bytes from input queue to buffer.
869 static ssize_t
aux_read(struct file
* file
, char * buffer
,
870 size_t count
, loff_t
*ppos
)
872 DECLARE_WAITQUEUE(wait
, current
);
877 if (file
->f_flags
& O_NONBLOCK
)
879 add_wait_queue(&queue
->proc_list
, &wait
);
881 set_current_state(TASK_INTERRUPTIBLE
);
882 if (queue_empty() && !signal_pending(current
)) {
886 current
->state
= TASK_RUNNING
;
887 remove_wait_queue(&queue
->proc_list
, &wait
);
889 while (i
> 0 && !queue_empty()) {
890 c
= get_from_queue();
891 put_user(c
, buffer
++);
894 aux_ready
= !queue_empty();
896 file
->f_dentry
->d_inode
->i_atime
= CURRENT_TIME
;
899 if (signal_pending(current
))
904 static unsigned int aux_poll(struct file
*file
, poll_table
* wait
)
906 poll_wait(file
, &queue
->proc_list
, wait
);
908 return POLLIN
| POLLRDNORM
;
912 struct file_operations psaux_fops
= {
927 static struct miscdevice psaux_mouse
= {
928 PSMOUSE_MINOR
, "ps2aux", &psaux_fops
931 int __init
pcimouse_init(void)
933 struct linux_ebus
*ebus
;
934 struct linux_ebus_device
*edev
;
935 struct linux_ebus_child
*child
;
937 if (pcikbd_mrcoffee
) {
938 if ((pcimouse_iobase
= pcikbd_iobase
) == 0) {
939 printk("pcimouse_init: no 8042 given\n");
942 pcimouse_irq
= pcikbd_irq
;
944 for_each_ebus(ebus
) {
945 for_each_ebusdev(edev
, ebus
) {
946 if(!strcmp(edev
->prom_name
, "8042")) {
947 for_each_edevchild(edev
, child
) {
948 if (strcmp(child
->prom_name
, PCI_MS_NAME1
) == 0 ||
949 strcmp(child
->prom_name
, PCI_MS_NAME2
) == 0)
955 printk("pcimouse_init: no 8042 found\n");
959 pcimouse_iobase
= child
->resource
[0].start
;
960 pcimouse_irq
= child
->irqs
[0];
963 queue
= (struct aux_queue
*) kmalloc(sizeof(*queue
), GFP_KERNEL
);
965 printk("pcimouse_init: kmalloc(aux_queue) failed.\n");
968 memset(queue
, 0, sizeof(*queue
));
970 init_waitqueue_head(&queue
->proc_list
);
972 if (request_irq(pcimouse_irq
, &pcimouse_interrupt
,
973 SA_SHIRQ
, "mouse", (void *)pcimouse_iobase
)) {
974 printk("8042: Cannot register IRQ %s\n",
975 __irq_itoa(pcimouse_irq
));
979 printk("8042(mouse) at %lx (irq %s)\n", pcimouse_iobase
,
980 __irq_itoa(pcimouse_irq
));
982 printk("8042: PS/2 auxiliary pointing device detected.\n");
984 pckbd_read_mask
= AUX_STAT_OBF
;
986 misc_register(&psaux_mouse
);
988 pcimouse_outb(KBD_CCMD_MOUSE_ENABLE
, pcimouse_iobase
+ KBD_CNTL_REG
);
989 aux_write_ack(AUX_RESET
);
990 aux_write_ack(AUX_SET_SAMPLE
);
992 aux_write_ack(AUX_SET_RES
);
994 aux_write_ack(AUX_SET_SCALE21
);
996 pcimouse_outb(KBD_CCMD_MOUSE_DISABLE
, pcimouse_iobase
+ KBD_CNTL_REG
);
998 pcimouse_outb(KBD_CCMD_WRITE_MODE
, pcimouse_iobase
+ KBD_CNTL_REG
);
1000 pcimouse_outb(AUX_INTS_OFF
, pcimouse_iobase
+ KBD_DATA_REG
);
1008 int __init
ps2kbd_probe(unsigned long *memory_start
)
1010 int pnode
, enode
, node
, dnode
, xnode
;
1011 int kbnode
= 0, msnode
= 0, bnode
= 0;
1016 #ifndef __sparc_v9__
1018 * MrCoffee has hardware but has no PROM nodes whatsoever.
1020 len
= prom_getproperty(prom_root_node
, "name", prop
, sizeof(prop
));
1022 printk("ps2kbd_probe: no name of root node\n");
1025 if (strncmp(prop
, "SUNW,JavaStation-1", len
) == 0) {
1026 pcikbd_mrcoffee
= 1; /* Brain damage detected */
1031 * Get the nodes for keyboard and mouse from aliases on normal systems.
1033 node
= prom_getchild(prom_root_node
);
1034 node
= prom_searchsiblings(node
, "aliases");
1038 len
= prom_getproperty(node
, "keyboard", prop
, sizeof(prop
));
1041 kbnode
= prom_finddevice(prop
);
1046 len
= prom_getproperty(node
, "mouse", prop
, sizeof(prop
));
1049 msnode
= prom_finddevice(prop
);
1055 * Find matching EBus nodes...
1057 node
= prom_getchild(prom_root_node
);
1058 pnode
= prom_searchsiblings(node
, "pci");
1061 * Check for SUNW,sabre on Ultra5/10/AXi.
1063 len
= prom_getproperty(pnode
, "model", prop
, sizeof(prop
));
1064 if ((len
> 0) && !strncmp(prop
, "SUNW,sabre", len
)) {
1065 pnode
= prom_getchild(pnode
);
1066 pnode
= prom_searchsiblings(pnode
, "pci");
1070 * For each PCI bus...
1073 enode
= prom_getchild(pnode
);
1074 enode
= prom_searchsiblings(enode
, "ebus");
1077 * For each EBus on this PCI...
1080 node
= prom_getchild(enode
);
1081 bnode
= prom_searchsiblings(node
, "beeper");
1083 node
= prom_getchild(enode
);
1084 node
= prom_searchsiblings(node
, "8042");
1087 * For each '8042' on this EBus...
1090 dnode
= prom_getchild(node
);
1095 if ((xnode
= prom_searchsiblings(dnode
, PCI_KB_NAME1
)) == kbnode
) {
1097 } else if ((xnode
= prom_searchsiblings(dnode
, PCI_KB_NAME2
)) == kbnode
) {
1101 if ((xnode
= prom_searchsiblings(dnode
, PCI_MS_NAME1
)) == msnode
) {
1103 } else if ((xnode
= prom_searchsiblings(dnode
, PCI_MS_NAME2
)) == msnode
) {
1108 * Found everything we need?
1113 node
= prom_getsibling(node
);
1114 node
= prom_searchsiblings(node
, "8042");
1116 enode
= prom_getsibling(enode
);
1117 enode
= prom_searchsiblings(enode
, "ebus");
1119 pnode
= prom_getsibling(pnode
);
1120 pnode
= prom_searchsiblings(pnode
, "pci");
1125 sunkbd_setinitfunc(memory_start
, pcimouse_init
);
1126 sunkbd_setinitfunc(memory_start
, pcikbd_init
);
1127 kbd_ops
.compute_shiftstate
= pci_compute_shiftstate
;
1128 kbd_ops
.setledstate
= pci_setledstate
;
1129 kbd_ops
.getledstate
= pci_getledstate
;
1130 kbd_ops
.setkeycode
= pci_setkeycode
;
1131 kbd_ops
.getkeycode
= pci_getkeycode
;