OMAP3: PM: Prevented DVFS state switches when enabling off-mode
[linux-ginger.git] / drivers / input / keyboard / amikbd.c
blob35149ec455a9fa3770a33ae2e1c61e2d6fb06a02
1 /*
2 * Copyright (c) 2000-2001 Vojtech Pavlik
4 * Based on the work of:
5 * Hamish Macdonald
6 */
8 /*
9 * Amiga keyboard driver for Linux/m68k
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * Should you need to contact me, the author, you can do so either by
28 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
29 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
32 #include <linux/module.h>
33 #include <linux/init.h>
34 #include <linux/input.h>
35 #include <linux/delay.h>
36 #include <linux/interrupt.h>
37 #include <linux/keyboard.h>
39 #include <asm/amigaints.h>
40 #include <asm/amigahw.h>
41 #include <asm/irq.h>
43 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
44 MODULE_DESCRIPTION("Amiga keyboard driver");
45 MODULE_LICENSE("GPL");
47 static unsigned char amikbd_keycode[0x78] __initdata = {
48 [0] = KEY_GRAVE,
49 [1] = KEY_1,
50 [2] = KEY_2,
51 [3] = KEY_3,
52 [4] = KEY_4,
53 [5] = KEY_5,
54 [6] = KEY_6,
55 [7] = KEY_7,
56 [8] = KEY_8,
57 [9] = KEY_9,
58 [10] = KEY_0,
59 [11] = KEY_MINUS,
60 [12] = KEY_EQUAL,
61 [13] = KEY_BACKSLASH,
62 [15] = KEY_KP0,
63 [16] = KEY_Q,
64 [17] = KEY_W,
65 [18] = KEY_E,
66 [19] = KEY_R,
67 [20] = KEY_T,
68 [21] = KEY_Y,
69 [22] = KEY_U,
70 [23] = KEY_I,
71 [24] = KEY_O,
72 [25] = KEY_P,
73 [26] = KEY_LEFTBRACE,
74 [27] = KEY_RIGHTBRACE,
75 [29] = KEY_KP1,
76 [30] = KEY_KP2,
77 [31] = KEY_KP3,
78 [32] = KEY_A,
79 [33] = KEY_S,
80 [34] = KEY_D,
81 [35] = KEY_F,
82 [36] = KEY_G,
83 [37] = KEY_H,
84 [38] = KEY_J,
85 [39] = KEY_K,
86 [40] = KEY_L,
87 [41] = KEY_SEMICOLON,
88 [42] = KEY_APOSTROPHE,
89 [43] = KEY_BACKSLASH,
90 [45] = KEY_KP4,
91 [46] = KEY_KP5,
92 [47] = KEY_KP6,
93 [48] = KEY_102ND,
94 [49] = KEY_Z,
95 [50] = KEY_X,
96 [51] = KEY_C,
97 [52] = KEY_V,
98 [53] = KEY_B,
99 [54] = KEY_N,
100 [55] = KEY_M,
101 [56] = KEY_COMMA,
102 [57] = KEY_DOT,
103 [58] = KEY_SLASH,
104 [60] = KEY_KPDOT,
105 [61] = KEY_KP7,
106 [62] = KEY_KP8,
107 [63] = KEY_KP9,
108 [64] = KEY_SPACE,
109 [65] = KEY_BACKSPACE,
110 [66] = KEY_TAB,
111 [67] = KEY_KPENTER,
112 [68] = KEY_ENTER,
113 [69] = KEY_ESC,
114 [70] = KEY_DELETE,
115 [74] = KEY_KPMINUS,
116 [76] = KEY_UP,
117 [77] = KEY_DOWN,
118 [78] = KEY_RIGHT,
119 [79] = KEY_LEFT,
120 [80] = KEY_F1,
121 [81] = KEY_F2,
122 [82] = KEY_F3,
123 [83] = KEY_F4,
124 [84] = KEY_F5,
125 [85] = KEY_F6,
126 [86] = KEY_F7,
127 [87] = KEY_F8,
128 [88] = KEY_F9,
129 [89] = KEY_F10,
130 [90] = KEY_KPLEFTPAREN,
131 [91] = KEY_KPRIGHTPAREN,
132 [92] = KEY_KPSLASH,
133 [93] = KEY_KPASTERISK,
134 [94] = KEY_KPPLUS,
135 [95] = KEY_HELP,
136 [96] = KEY_LEFTSHIFT,
137 [97] = KEY_RIGHTSHIFT,
138 [98] = KEY_CAPSLOCK,
139 [99] = KEY_LEFTCTRL,
140 [100] = KEY_LEFTALT,
141 [101] = KEY_RIGHTALT,
142 [102] = KEY_LEFTMETA,
143 [103] = KEY_RIGHTMETA
146 static const char *amikbd_messages[8] = {
147 [0] = KERN_ALERT "amikbd: Ctrl-Amiga-Amiga reset warning!!\n",
148 [1] = KERN_WARNING "amikbd: keyboard lost sync\n",
149 [2] = KERN_WARNING "amikbd: keyboard buffer overflow\n",
150 [3] = KERN_WARNING "amikbd: keyboard controller failure\n",
151 [4] = KERN_ERR "amikbd: keyboard selftest failure\n",
152 [5] = KERN_INFO "amikbd: initiate power-up key stream\n",
153 [6] = KERN_INFO "amikbd: terminate power-up key stream\n",
154 [7] = KERN_WARNING "amikbd: keyboard interrupt\n"
157 static struct input_dev *amikbd_dev;
159 static irqreturn_t amikbd_interrupt(int irq, void *dummy)
161 unsigned char scancode, down;
163 scancode = ~ciaa.sdr; /* get and invert scancode (keyboard is active low) */
164 ciaa.cra |= 0x40; /* switch SP pin to output for handshake */
165 udelay(85); /* wait until 85 us have expired */
166 ciaa.cra &= ~0x40; /* switch CIA serial port to input mode */
168 down = !(scancode & 1); /* lowest bit is release bit */
169 scancode >>= 1;
171 if (scancode < 0x78) { /* scancodes < 0x78 are keys */
172 if (scancode == 98) { /* CapsLock is a toggle switch key on Amiga */
173 input_report_key(amikbd_dev, scancode, 1);
174 input_report_key(amikbd_dev, scancode, 0);
175 } else {
176 input_report_key(amikbd_dev, scancode, down);
179 input_sync(amikbd_dev);
180 } else /* scancodes >= 0x78 are error codes */
181 printk(amikbd_messages[scancode - 0x78]);
183 return IRQ_HANDLED;
186 static int __init amikbd_init(void)
188 int i, j, err;
190 if (!AMIGAHW_PRESENT(AMI_KEYBOARD))
191 return -ENODEV;
193 if (!request_mem_region(CIAA_PHYSADDR-1+0xb00, 0x100, "amikeyb"))
194 return -EBUSY;
196 amikbd_dev = input_allocate_device();
197 if (!amikbd_dev) {
198 printk(KERN_ERR "amikbd: not enough memory for input device\n");
199 err = -ENOMEM;
200 goto fail1;
203 amikbd_dev->name = "Amiga Keyboard";
204 amikbd_dev->phys = "amikbd/input0";
205 amikbd_dev->id.bustype = BUS_AMIGA;
206 amikbd_dev->id.vendor = 0x0001;
207 amikbd_dev->id.product = 0x0001;
208 amikbd_dev->id.version = 0x0100;
210 amikbd_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
212 for (i = 0; i < 0x78; i++)
213 set_bit(i, amikbd_dev->keybit);
215 for (i = 0; i < MAX_NR_KEYMAPS; i++) {
216 static u_short temp_map[NR_KEYS] __initdata;
217 if (!key_maps[i])
218 continue;
219 memset(temp_map, 0, sizeof(temp_map));
220 for (j = 0; j < 0x78; j++) {
221 if (!amikbd_keycode[j])
222 continue;
223 temp_map[j] = key_maps[i][amikbd_keycode[j]];
225 for (j = 0; j < NR_KEYS; j++) {
226 if (!temp_map[j])
227 temp_map[j] = 0xf200;
229 memcpy(key_maps[i], temp_map, sizeof(temp_map));
231 ciaa.cra &= ~0x41; /* serial data in, turn off TA */
232 if (request_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd",
233 amikbd_interrupt)) {
234 err = -EBUSY;
235 goto fail2;
238 err = input_register_device(amikbd_dev);
239 if (err)
240 goto fail3;
242 return 0;
244 fail3: free_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt);
245 fail2: input_free_device(amikbd_dev);
246 fail1: release_mem_region(CIAA_PHYSADDR - 1 + 0xb00, 0x100);
247 return err;
250 static void __exit amikbd_exit(void)
252 free_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt);
253 input_unregister_device(amikbd_dev);
254 release_mem_region(CIAA_PHYSADDR - 1 + 0xb00, 0x100);
257 module_init(amikbd_init);
258 module_exit(amikbd_exit);