Input: amikbd - fix build if !CONFIG_HW_CONSOLE
[firefly-linux-kernel-4.4.55.git] / drivers / input / keyboard / amikbd.c
1 /*
2  *  Copyright (c) 2000-2001 Vojtech Pavlik
3  *
4  *  Based on the work of:
5  *      Hamish Macdonald
6  */
7
8 /*
9  * Amiga keyboard driver for Linux/m68k
10  */
11
12 /*
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.
17  *
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.
22  *
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
26  *
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
30  */
31
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>
38 #include <linux/platform_device.h>
39
40 #include <asm/amigaints.h>
41 #include <asm/amigahw.h>
42 #include <asm/irq.h>
43
44 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
45 MODULE_DESCRIPTION("Amiga keyboard driver");
46 MODULE_LICENSE("GPL");
47
48 #ifdef CONFIG_HW_CONSOLE
49 static unsigned char amikbd_keycode[0x78] __initdata = {
50         [0]      = KEY_GRAVE,
51         [1]      = KEY_1,
52         [2]      = KEY_2,
53         [3]      = KEY_3,
54         [4]      = KEY_4,
55         [5]      = KEY_5,
56         [6]      = KEY_6,
57         [7]      = KEY_7,
58         [8]      = KEY_8,
59         [9]      = KEY_9,
60         [10]     = KEY_0,
61         [11]     = KEY_MINUS,
62         [12]     = KEY_EQUAL,
63         [13]     = KEY_BACKSLASH,
64         [15]     = KEY_KP0,
65         [16]     = KEY_Q,
66         [17]     = KEY_W,
67         [18]     = KEY_E,
68         [19]     = KEY_R,
69         [20]     = KEY_T,
70         [21]     = KEY_Y,
71         [22]     = KEY_U,
72         [23]     = KEY_I,
73         [24]     = KEY_O,
74         [25]     = KEY_P,
75         [26]     = KEY_LEFTBRACE,
76         [27]     = KEY_RIGHTBRACE,
77         [29]     = KEY_KP1,
78         [30]     = KEY_KP2,
79         [31]     = KEY_KP3,
80         [32]     = KEY_A,
81         [33]     = KEY_S,
82         [34]     = KEY_D,
83         [35]     = KEY_F,
84         [36]     = KEY_G,
85         [37]     = KEY_H,
86         [38]     = KEY_J,
87         [39]     = KEY_K,
88         [40]     = KEY_L,
89         [41]     = KEY_SEMICOLON,
90         [42]     = KEY_APOSTROPHE,
91         [43]     = KEY_BACKSLASH,
92         [45]     = KEY_KP4,
93         [46]     = KEY_KP5,
94         [47]     = KEY_KP6,
95         [48]     = KEY_102ND,
96         [49]     = KEY_Z,
97         [50]     = KEY_X,
98         [51]     = KEY_C,
99         [52]     = KEY_V,
100         [53]     = KEY_B,
101         [54]     = KEY_N,
102         [55]     = KEY_M,
103         [56]     = KEY_COMMA,
104         [57]     = KEY_DOT,
105         [58]     = KEY_SLASH,
106         [60]     = KEY_KPDOT,
107         [61]     = KEY_KP7,
108         [62]     = KEY_KP8,
109         [63]     = KEY_KP9,
110         [64]     = KEY_SPACE,
111         [65]     = KEY_BACKSPACE,
112         [66]     = KEY_TAB,
113         [67]     = KEY_KPENTER,
114         [68]     = KEY_ENTER,
115         [69]     = KEY_ESC,
116         [70]     = KEY_DELETE,
117         [74]     = KEY_KPMINUS,
118         [76]     = KEY_UP,
119         [77]     = KEY_DOWN,
120         [78]     = KEY_RIGHT,
121         [79]     = KEY_LEFT,
122         [80]     = KEY_F1,
123         [81]     = KEY_F2,
124         [82]     = KEY_F3,
125         [83]     = KEY_F4,
126         [84]     = KEY_F5,
127         [85]     = KEY_F6,
128         [86]     = KEY_F7,
129         [87]     = KEY_F8,
130         [88]     = KEY_F9,
131         [89]     = KEY_F10,
132         [90]     = KEY_KPLEFTPAREN,
133         [91]     = KEY_KPRIGHTPAREN,
134         [92]     = KEY_KPSLASH,
135         [93]     = KEY_KPASTERISK,
136         [94]     = KEY_KPPLUS,
137         [95]     = KEY_HELP,
138         [96]     = KEY_LEFTSHIFT,
139         [97]     = KEY_RIGHTSHIFT,
140         [98]     = KEY_CAPSLOCK,
141         [99]     = KEY_LEFTCTRL,
142         [100]    = KEY_LEFTALT,
143         [101]    = KEY_RIGHTALT,
144         [102]    = KEY_LEFTMETA,
145         [103]    = KEY_RIGHTMETA
146 };
147
148 static void __init amikbd_init_console_keymaps(void)
149 {
150         int i, j;
151
152         for (i = 0; i < MAX_NR_KEYMAPS; i++) {
153                 static u_short temp_map[NR_KEYS] __initdata;
154                 if (!key_maps[i])
155                         continue;
156                 memset(temp_map, 0, sizeof(temp_map));
157                 for (j = 0; j < 0x78; j++) {
158                         if (!amikbd_keycode[j])
159                                 continue;
160                         temp_map[j] = key_maps[i][amikbd_keycode[j]];
161                 }
162                 for (j = 0; j < NR_KEYS; j++) {
163                         if (!temp_map[j])
164                                 temp_map[j] = 0xf200;
165                 }
166                 memcpy(key_maps[i], temp_map, sizeof(temp_map));
167         }
168 }
169 #else /* !CONFIG_HW_CONSOLE */
170 static inline void amikbd_init_console_keymaps(void) {}
171 #endif /* !CONFIG_HW_CONSOLE */
172
173 static const char *amikbd_messages[8] = {
174         [0] = KERN_ALERT "amikbd: Ctrl-Amiga-Amiga reset warning!!\n",
175         [1] = KERN_WARNING "amikbd: keyboard lost sync\n",
176         [2] = KERN_WARNING "amikbd: keyboard buffer overflow\n",
177         [3] = KERN_WARNING "amikbd: keyboard controller failure\n",
178         [4] = KERN_ERR "amikbd: keyboard selftest failure\n",
179         [5] = KERN_INFO "amikbd: initiate power-up key stream\n",
180         [6] = KERN_INFO "amikbd: terminate power-up key stream\n",
181         [7] = KERN_WARNING "amikbd: keyboard interrupt\n"
182 };
183
184 static irqreturn_t amikbd_interrupt(int irq, void *data)
185 {
186         struct input_dev *dev = data;
187         unsigned char scancode, down;
188
189         scancode = ~ciaa.sdr;           /* get and invert scancode (keyboard is active low) */
190         ciaa.cra |= 0x40;               /* switch SP pin to output for handshake */
191         udelay(85);                     /* wait until 85 us have expired */
192         ciaa.cra &= ~0x40;              /* switch CIA serial port to input mode */
193
194         down = !(scancode & 1);         /* lowest bit is release bit */
195         scancode >>= 1;
196
197         if (scancode < 0x78) {          /* scancodes < 0x78 are keys */
198                 if (scancode == 98) {   /* CapsLock is a toggle switch key on Amiga */
199                         input_report_key(dev, scancode, 1);
200                         input_report_key(dev, scancode, 0);
201                 } else {
202                         input_report_key(dev, scancode, down);
203                 }
204
205                 input_sync(dev);
206         } else                          /* scancodes >= 0x78 are error codes */
207                 printk(amikbd_messages[scancode - 0x78]);
208
209         return IRQ_HANDLED;
210 }
211
212 static int __init amikbd_probe(struct platform_device *pdev)
213 {
214         struct input_dev *dev;
215         int i, err;
216
217         dev = input_allocate_device();
218         if (!dev) {
219                 dev_err(&pdev->dev, "Not enough memory for input device\n");
220                 return -ENOMEM;
221         }
222
223         dev->name = pdev->name;
224         dev->phys = "amikbd/input0";
225         dev->id.bustype = BUS_AMIGA;
226         dev->id.vendor = 0x0001;
227         dev->id.product = 0x0001;
228         dev->id.version = 0x0100;
229         dev->dev.parent = &pdev->dev;
230
231         dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
232
233         for (i = 0; i < 0x78; i++)
234                 set_bit(i, dev->keybit);
235
236         amikbd_init_console_keymaps();
237
238         ciaa.cra &= ~0x41;       /* serial data in, turn off TA */
239         err = request_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd",
240                           dev);
241         if (err)
242                 goto fail2;
243
244         err = input_register_device(dev);
245         if (err)
246                 goto fail3;
247
248         platform_set_drvdata(pdev, dev);
249
250         return 0;
251
252  fail3: free_irq(IRQ_AMIGA_CIAA_SP, dev);
253  fail2: input_free_device(dev);
254         return err;
255 }
256
257 static int __exit amikbd_remove(struct platform_device *pdev)
258 {
259         struct input_dev *dev = platform_get_drvdata(pdev);
260
261         free_irq(IRQ_AMIGA_CIAA_SP, dev);
262         input_unregister_device(dev);
263         return 0;
264 }
265
266 static struct platform_driver amikbd_driver = {
267         .remove = __exit_p(amikbd_remove),
268         .driver   = {
269                 .name   = "amiga-keyboard",
270                 .owner  = THIS_MODULE,
271         },
272 };
273
274 module_platform_driver_probe(amikbd_driver, amikbd_probe);
275
276 MODULE_ALIAS("platform:amiga-keyboard");