^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Atari Keyboard driver for 680x0 Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * License. See the file COPYING in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Atari support by Robert de Vries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * enhanced by Bjoern Brauel and Roman Hodek
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * 2.6 and input cleanup (removed autorepeat stuff) for 2.6.21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * 06/07 Michael Schmitz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/keyboard.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/kd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/kbd_kern.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <asm/atariints.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <asm/atarihw.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <asm/atarikb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <asm/atari_joystick.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /* Hook for MIDI serial driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) void (*atari_MIDI_interrupt_hook) (void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /* Hook for keyboard inputdev driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) void (*atari_input_keyboard_interrupt_hook) (unsigned char, char);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /* Hook for mouse inputdev driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) void (*atari_input_mouse_interrupt_hook) (char *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) EXPORT_SYMBOL(atari_input_keyboard_interrupt_hook);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) EXPORT_SYMBOL(atari_input_mouse_interrupt_hook);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) /* variables for IKBD self test: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /* state: 0: off; >0: in progress; >1: 0xf1 received */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static volatile int ikbd_self_test;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /* timestamp when last received a char */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static volatile unsigned long self_test_last_rcv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* bitmap of keys reported as broken */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static unsigned long broken_keys[128/(sizeof(unsigned long)*8)] = { 0, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define BREAK_MASK (0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * ++roman: The following changes were applied manually:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * - The Alt (= Meta) key works in combination with Shift and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * Control, e.g. Alt+Shift+a sends Meta-A (0xc1), Alt+Control+A sends
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * Meta-Ctrl-A (0x81) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * - The parentheses on the keypad send '(' and ')' with all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * modifiers (as would do e.g. keypad '+'), but they cannot be used as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * application keys (i.e. sending Esc O c).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * - HELP and UNDO are mapped to be F21 and F24, resp, that send the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * codes "\E[M" and "\E[P". (This is better than the old mapping to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * F11 and F12, because these codes are on Shift+F1/2 anyway.) This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * way, applications that allow their own keyboard mappings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * (e.g. tcsh, X Windows) can be configured to use them in the way
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * the label suggests (providing help or undoing).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * - Console switching is done with Alt+Fx (consoles 1..10) and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * Shift+Alt+Fx (consoles 11..20).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * - The misc. special function implemented in the kernel are mapped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * to the following key combinations:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * ClrHome -> Home/Find
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * Shift + ClrHome -> End/Select
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * Shift + Up -> Page Up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * Shift + Down -> Page Down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * Alt + Help -> show system status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * Shift + Help -> show memory info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * Ctrl + Help -> show registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * Ctrl + Alt + Del -> Reboot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * Alt + Undo -> switch to last console
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * Shift + Undo -> send interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * Alt + Insert -> stop/start output (same as ^S/^Q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * Alt + Up -> Scroll back console (if implemented)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * Alt + Down -> Scroll forward console (if implemented)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * Alt + CapsLock -> NumLock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * ++Andreas:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * - Help mapped to K_HELP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * - Undo mapped to K_UNDO (= K_F246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * - Keypad Left/Right Parenthesis mapped to new K_PPAREN[LR]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) typedef enum kb_state_t {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) KEYBOARD, AMOUSE, RMOUSE, JOYSTICK, CLOCK, RESYNC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) } KB_STATE_T;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define IS_SYNC_CODE(sc) ((sc) >= 0x04 && (sc) <= 0xfb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) typedef struct keyboard_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) unsigned char buf[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) KB_STATE_T state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) } KEYBOARD_STATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) KEYBOARD_STATE kb_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /* ++roman: If a keyboard overrun happened, we can't tell in general how much
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * bytes have been lost and in which state of the packet structure we are now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * This usually causes keyboards bytes to be interpreted as mouse movements
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * and vice versa, which is very annoying. It seems better to throw away some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * bytes (that are usually mouse bytes) than to misinterpret them. Therefore I
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * introduced the RESYNC state for IKBD data. In this state, the bytes up to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * one that really looks like a key event (0x04..0xf2) or the start of a mouse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * packet (0xf8..0xfb) are thrown away, but at most 2 bytes. This at least
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * speeds up the resynchronization of the event structure, even if maybe a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * mouse movement is lost. However, nothing is perfect. For bytes 0x01..0x03,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * it's really hard to decide whether they're mouse or keyboard bytes. Since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * overruns usually occur when moving the Atari mouse rapidly, they're seen as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * mouse bytes here. If this is wrong, only a make code of the keyboard gets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * lost, which isn't too bad. Losing a break code would be disastrous,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * because then the keyboard repeat strikes...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static irqreturn_t atari_keyboard_interrupt(int irq, void *dummy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) u_char acia_stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) int scancode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int break_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) repeat:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (acia.mid_ctrl & ACIA_IRQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (atari_MIDI_interrupt_hook)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) atari_MIDI_interrupt_hook();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) acia_stat = acia.key_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /* check out if the interrupt came from this ACIA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (!((acia_stat | acia.mid_ctrl) & ACIA_IRQ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (acia_stat & ACIA_OVRN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /* a very fast typist or a slow system, give a warning */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /* ...happens often if interrupts were disabled for too long */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) pr_debug("Keyboard overrun\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) scancode = acia.key_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (ikbd_self_test)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /* During self test, don't do resyncing, just process the code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) goto interpret_scancode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) else if (IS_SYNC_CODE(scancode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /* This code seem already to be the start of a new packet or a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * single scancode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) kb_state.state = KEYBOARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) goto interpret_scancode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) /* Go to RESYNC state and skip this byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) kb_state.state = RESYNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) kb_state.len = 1; /* skip max. 1 another byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) goto repeat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (acia_stat & ACIA_RDRF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /* received a character */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) scancode = acia.key_data; /* get it or reset the ACIA, I'll get it! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) interpret_scancode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) switch (kb_state.state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) case KEYBOARD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) switch (scancode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) case 0xF7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) kb_state.state = AMOUSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) kb_state.len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) case 0xF8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) case 0xF9:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) case 0xFA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) case 0xFB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) kb_state.state = RMOUSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) kb_state.len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) kb_state.buf[0] = scancode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) case 0xFC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) kb_state.state = CLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) kb_state.len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) case 0xFE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) case 0xFF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) kb_state.state = JOYSTICK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) kb_state.len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) kb_state.buf[0] = scancode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) case 0xF1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /* during self-test, note that 0xf1 received */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (ikbd_self_test) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) ++ikbd_self_test;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) self_test_last_rcv = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) break_flag = scancode & BREAK_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) scancode &= ~BREAK_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (ikbd_self_test) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /* Scancodes sent during the self-test stand for broken
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * keys (keys being down). The code *should* be a break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * code, but nevertheless some AT keyboard interfaces send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * make codes instead. Therefore, simply ignore
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * break_flag...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) int keyval, keytyp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) set_bit(scancode, broken_keys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) self_test_last_rcv = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /* new Linux scancodes; approx. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) keyval = scancode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) keytyp = KTYP(keyval) - 0xf0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) keyval = KVAL(keyval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) pr_warn("Key with scancode %d ", scancode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (keytyp == KT_LATIN || keytyp == KT_LETTER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (keyval < ' ')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) pr_cont("('^%c') ", keyval + '@');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) pr_cont("('%c') ", keyval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) pr_cont("is broken -- will be ignored.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) } else if (test_bit(scancode, broken_keys))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (atari_input_keyboard_interrupt_hook)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) atari_input_keyboard_interrupt_hook((unsigned char)scancode, !break_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) case AMOUSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) kb_state.buf[kb_state.len++] = scancode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (kb_state.len == 5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) kb_state.state = KEYBOARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /* not yet used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /* wake up someone waiting for this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) case RMOUSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) kb_state.buf[kb_state.len++] = scancode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (kb_state.len == 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) kb_state.state = KEYBOARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (atari_input_mouse_interrupt_hook)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) atari_input_mouse_interrupt_hook(kb_state.buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) case JOYSTICK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) kb_state.buf[1] = scancode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) kb_state.state = KEYBOARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) #ifdef FIXED_ATARI_JOYSTICK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) atari_joystick_interrupt(kb_state.buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) case CLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) kb_state.buf[kb_state.len++] = scancode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (kb_state.len == 6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) kb_state.state = KEYBOARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /* wake up someone waiting for this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) But will this ever be used, as Linux keeps its own time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) Perhaps for synchronization purposes? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /* wake_up_interruptible(&clock_wait); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) case RESYNC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (kb_state.len <= 0 || IS_SYNC_CODE(scancode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) kb_state.state = KEYBOARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) goto interpret_scancode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) kb_state.len--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (acia_stat & ACIA_CTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) /* cannot happen */;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (acia_stat & (ACIA_FE | ACIA_PE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) pr_err("Error in keyboard communication\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) /* handle_scancode() can take a lot of time, so check again if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * some character arrived
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) goto repeat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) * I write to the keyboard without using interrupts, I poll instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * This takes for the maximum length string allowed (7) at 7812.5 baud
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * 8 data 1 start 1 stop bit: 9.0 ms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) * If this takes too long for normal operation, interrupt driven writing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) * is the solution. (I made a feeble attempt in that direction but I
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * kept it simple for now.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) void ikbd_write(const char *str, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) u_char acia_stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if ((len < 1) || (len > 7))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) panic("ikbd: maximum string length exceeded");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) while (len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) acia_stat = acia.key_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (acia_stat & ACIA_TDRE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) acia.key_data = *str++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) len--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) /* Reset (without touching the clock) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) void ikbd_reset(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) static const char cmd[2] = { 0x80, 0x01 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) ikbd_write(cmd, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) * if all's well code 0xF1 is returned, else the break codes of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * all keys making contact
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) /* Set mouse button action */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) void ikbd_mouse_button_action(int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) char cmd[2] = { 0x07, mode };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) ikbd_write(cmd, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) /* Set relative mouse position reporting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) void ikbd_mouse_rel_pos(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) static const char cmd[1] = { 0x08 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) ikbd_write(cmd, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) EXPORT_SYMBOL(ikbd_mouse_rel_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) /* Set absolute mouse position reporting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) void ikbd_mouse_abs_pos(int xmax, int ymax)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) char cmd[5] = { 0x09, xmax>>8, xmax&0xFF, ymax>>8, ymax&0xFF };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) ikbd_write(cmd, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) /* Set mouse keycode mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) void ikbd_mouse_kbd_mode(int dx, int dy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) char cmd[3] = { 0x0A, dx, dy };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) ikbd_write(cmd, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) /* Set mouse threshold */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) void ikbd_mouse_thresh(int x, int y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) char cmd[3] = { 0x0B, x, y };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) ikbd_write(cmd, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) EXPORT_SYMBOL(ikbd_mouse_thresh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) /* Set mouse scale */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) void ikbd_mouse_scale(int x, int y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) char cmd[3] = { 0x0C, x, y };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) ikbd_write(cmd, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) /* Interrogate mouse position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) void ikbd_mouse_pos_get(int *x, int *y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) static const char cmd[1] = { 0x0D };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) ikbd_write(cmd, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) /* wait for returning bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) /* Load mouse position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) void ikbd_mouse_pos_set(int x, int y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) char cmd[6] = { 0x0E, 0x00, x>>8, x&0xFF, y>>8, y&0xFF };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) ikbd_write(cmd, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) /* Set Y=0 at bottom */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) void ikbd_mouse_y0_bot(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) static const char cmd[1] = { 0x0F };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) ikbd_write(cmd, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) /* Set Y=0 at top */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) void ikbd_mouse_y0_top(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) static const char cmd[1] = { 0x10 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) ikbd_write(cmd, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) EXPORT_SYMBOL(ikbd_mouse_y0_top);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) /* Disable mouse */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) void ikbd_mouse_disable(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) static const char cmd[1] = { 0x12 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) ikbd_write(cmd, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) EXPORT_SYMBOL(ikbd_mouse_disable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) /* Set joystick event reporting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) void ikbd_joystick_event_on(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) static const char cmd[1] = { 0x14 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) ikbd_write(cmd, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) /* Set joystick interrogation mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) void ikbd_joystick_event_off(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static const char cmd[1] = { 0x15 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) ikbd_write(cmd, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) /* Joystick interrogation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) void ikbd_joystick_get_state(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) static const char cmd[1] = { 0x16 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) ikbd_write(cmd, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) /* This disables all other ikbd activities !!!! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) /* Set joystick monitoring */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) void ikbd_joystick_monitor(int rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) static const char cmd[2] = { 0x17, rate };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) ikbd_write(cmd, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) kb_state.state = JOYSTICK_MONITOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) /* some joystick routines not in yet (0x18-0x19) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) /* Disable joysticks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) void ikbd_joystick_disable(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) static const char cmd[1] = { 0x1A };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) ikbd_write(cmd, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) * The original code sometimes left the interrupt line of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) * the ACIAs low forever. I hope, it is fixed now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) * Martin Rogge, 20 Aug 1995
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) static int atari_keyb_done = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) int atari_keyb_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) if (atari_keyb_done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) kb_state.state = KEYBOARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) kb_state.len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) error = request_irq(IRQ_MFP_ACIA, atari_keyboard_interrupt, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) "keyboard,mouse,MIDI", atari_keyboard_interrupt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) atari_turnoff_irq(IRQ_MFP_ACIA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) /* reset IKBD ACIA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) acia.key_ctrl = ACIA_RESET |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) ((atari_switches & ATARI_SWITCH_IKBD) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) ACIA_RHTID : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) (void)acia.key_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) (void)acia.key_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) /* reset MIDI ACIA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) acia.mid_ctrl = ACIA_RESET |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) ((atari_switches & ATARI_SWITCH_MIDI) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) ACIA_RHTID : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) (void)acia.mid_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) (void)acia.mid_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) /* divide 500kHz by 64 gives 7812.5 baud */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) /* 8 data no parity 1 start 1 stop bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) /* receive interrupt enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) /* RTS low (except if switch selected), transmit interrupt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) acia.key_ctrl = (ACIA_DIV64|ACIA_D8N1S|ACIA_RIE) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) ((atari_switches & ATARI_SWITCH_IKBD) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) ACIA_RHTID : ACIA_RLTID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) acia.mid_ctrl = ACIA_DIV16 | ACIA_D8N1S |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) ((atari_switches & ATARI_SWITCH_MIDI) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) ACIA_RHTID : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) /* make sure the interrupt line is up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) } while ((st_mfp.par_dt_reg & 0x10) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) /* enable ACIA Interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) st_mfp.active_edge &= ~0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) atari_turnon_irq(IRQ_MFP_ACIA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) ikbd_self_test = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) ikbd_reset();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) /* wait for a period of inactivity (here: 0.25s), then assume the IKBD's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) * self-test is finished */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) self_test_last_rcv = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) while (time_before(jiffies, self_test_last_rcv + HZ/4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) /* if not incremented: no 0xf1 received */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) if (ikbd_self_test == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) pr_err("Keyboard self test failed!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) ikbd_self_test = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) ikbd_mouse_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) ikbd_joystick_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) #ifdef FIXED_ATARI_JOYSTICK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) atari_joystick_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) // flag init done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) atari_keyb_done = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) EXPORT_SYMBOL_GPL(atari_keyb_init);