1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2000-2001 Vojtech Pavlik
5 * Based on the work of:
10 * Amiga keyboard driver for Linux/m68k
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/input.h>
16 #include <linux/delay.h>
17 #include <linux/interrupt.h>
18 #include <linux/keyboard.h>
19 #include <linux/platform_device.h>
21 #include <asm/amigaints.h>
22 #include <asm/amigahw.h>
25 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
26 MODULE_DESCRIPTION("Amiga keyboard driver");
27 MODULE_LICENSE("GPL");
30 static unsigned char amikbd_keycode
[0x78] __initdata
= {
57 [27] = KEY_RIGHTBRACE
,
71 [42] = KEY_APOSTROPHE
,
113 [90] = KEY_KPLEFTPAREN
,
114 [91] = KEY_KPRIGHTPAREN
,
116 [93] = KEY_KPASTERISK
,
119 [96] = KEY_LEFTSHIFT
,
120 [97] = KEY_RIGHTSHIFT
,
124 [101] = KEY_RIGHTALT
,
125 [102] = KEY_LEFTMETA
,
126 [103] = KEY_RIGHTMETA
129 static void __init
amikbd_init_console_keymaps(void)
131 /* We can spare 512 bytes on stack for temp_map in init path. */
132 unsigned short temp_map
[NR_KEYS
];
135 for (i
= 0; i
< MAX_NR_KEYMAPS
; i
++) {
138 memset(temp_map
, 0, sizeof(temp_map
));
139 for (j
= 0; j
< 0x78; j
++) {
140 if (!amikbd_keycode
[j
])
142 temp_map
[j
] = key_maps
[i
][amikbd_keycode
[j
]];
144 for (j
= 0; j
< NR_KEYS
; j
++) {
146 temp_map
[j
] = 0xf200;
148 memcpy(key_maps
[i
], temp_map
, sizeof(temp_map
));
151 #else /* !CONFIG_VT */
152 static inline void amikbd_init_console_keymaps(void) {}
153 #endif /* !CONFIG_VT */
155 static const char *amikbd_messages
[8] = {
156 [0] = KERN_ALERT
"amikbd: Ctrl-Amiga-Amiga reset warning!!\n",
157 [1] = KERN_WARNING
"amikbd: keyboard lost sync\n",
158 [2] = KERN_WARNING
"amikbd: keyboard buffer overflow\n",
159 [3] = KERN_WARNING
"amikbd: keyboard controller failure\n",
160 [4] = KERN_ERR
"amikbd: keyboard selftest failure\n",
161 [5] = KERN_INFO
"amikbd: initiate power-up key stream\n",
162 [6] = KERN_INFO
"amikbd: terminate power-up key stream\n",
163 [7] = KERN_WARNING
"amikbd: keyboard interrupt\n"
166 static irqreturn_t
amikbd_interrupt(int irq
, void *data
)
168 struct input_dev
*dev
= data
;
169 unsigned char scancode
, down
;
171 scancode
= ~ciaa
.sdr
; /* get and invert scancode (keyboard is active low) */
172 ciaa
.cra
|= 0x40; /* switch SP pin to output for handshake */
173 udelay(85); /* wait until 85 us have expired */
174 ciaa
.cra
&= ~0x40; /* switch CIA serial port to input mode */
176 down
= !(scancode
& 1); /* lowest bit is release bit */
179 if (scancode
< 0x78) { /* scancodes < 0x78 are keys */
180 if (scancode
== 98) { /* CapsLock is a toggle switch key on Amiga */
181 input_report_key(dev
, scancode
, 1);
182 input_report_key(dev
, scancode
, 0);
184 input_report_key(dev
, scancode
, down
);
188 } else /* scancodes >= 0x78 are error codes */
189 printk(amikbd_messages
[scancode
- 0x78]);
194 static int __init
amikbd_probe(struct platform_device
*pdev
)
196 struct input_dev
*dev
;
199 dev
= devm_input_allocate_device(&pdev
->dev
);
201 dev_err(&pdev
->dev
, "Not enough memory for input device\n");
205 dev
->name
= pdev
->name
;
206 dev
->phys
= "amikbd/input0";
207 dev
->id
.bustype
= BUS_AMIGA
;
208 dev
->id
.vendor
= 0x0001;
209 dev
->id
.product
= 0x0001;
210 dev
->id
.version
= 0x0100;
212 dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_REP
);
214 for (i
= 0; i
< 0x78; i
++)
215 set_bit(i
, dev
->keybit
);
217 amikbd_init_console_keymaps();
219 ciaa
.cra
&= ~0x41; /* serial data in, turn off TA */
220 err
= devm_request_irq(&pdev
->dev
, IRQ_AMIGA_CIAA_SP
, amikbd_interrupt
,
225 err
= input_register_device(dev
);
229 platform_set_drvdata(pdev
, dev
);
234 static struct platform_driver amikbd_driver
= {
236 .name
= "amiga-keyboard",
240 module_platform_driver_probe(amikbd_driver
, amikbd_probe
);
242 MODULE_ALIAS("platform:amiga-keyboard");