2 * linux/drivers/hil/hilkbd.c
4 * Copyright (C) 1998 Philip Blundell <philb@gnu.org>
5 * Copyright (C) 1999 Matthew Wilcox <willy@bofh.ai>
6 * Copyright (C) 1999-2007 Helge Deller <deller@gmx.de>
8 * Very basic HP Human Interface Loop (HIL) driver.
9 * This driver handles the keyboard on HP300 (m68k) and on some
10 * HP700 (parisc) series machines.
13 * This file is subject to the terms and conditions of the GNU General Public
14 * License version 2. See the file COPYING in the main directory of this
15 * archive for more details.
18 #include <linux/pci_ids.h>
19 #include <linux/ioport.h>
20 #include <linux/module.h>
21 #include <linux/errno.h>
22 #include <linux/input.h>
23 #include <linux/init.h>
24 #include <linux/interrupt.h>
25 #include <linux/hil.h>
27 #include <linux/sched.h>
28 #include <linux/spinlock.h>
31 #include <asm/hwtest.h>
35 MODULE_AUTHOR("Philip Blundell, Matthew Wilcox, Helge Deller");
36 MODULE_DESCRIPTION("HIL keyboard driver (basic functionality)");
37 MODULE_LICENSE("GPL v2");
40 #if defined(CONFIG_PARISC)
43 #include <asm/hardware.h>
44 #include <asm/parisc-device.h>
45 static unsigned long hil_base
; /* HPA for the HIL device */
46 static unsigned int hil_irq
;
47 #define HILBASE hil_base /* HPPA (parisc) port address */
48 #define HIL_DATA 0x800
50 #define HIL_IRQ hil_irq
51 #define hil_readb(p) gsc_readb(p)
52 #define hil_writeb(v,p) gsc_writeb((v),(p))
54 #elif defined(CONFIG_HP300)
56 #define HILBASE 0xf0428000UL /* HP300 (m68k) port address */
60 #define hil_readb(p) readb(p)
61 #define hil_writeb(v,p) writeb((v),(p))
64 #error "HIL is not supported on this platform"
69 /* HIL helper functions */
71 #define hil_busy() (hil_readb(HILBASE + HIL_CMD) & HIL_BUSY)
72 #define hil_data_available() (hil_readb(HILBASE + HIL_CMD) & HIL_DATA_RDY)
73 #define hil_status() (hil_readb(HILBASE + HIL_CMD))
74 #define hil_command(x) do { hil_writeb((x), HILBASE + HIL_CMD); } while (0)
75 #define hil_read_data() (hil_readb(HILBASE + HIL_DATA))
76 #define hil_write_data(x) do { hil_writeb((x), HILBASE + HIL_DATA); } while (0)
81 #define HIL_DATA_RDY 0x01
83 #define HIL_SETARD 0xA0 /* set auto-repeat delay */
84 #define HIL_SETARR 0xA2 /* set auto-repeat rate */
85 #define HIL_SETTONE 0xA3 /* set tone generator */
86 #define HIL_CNMT 0xB2 /* clear nmi */
87 #define HIL_INTON 0x5C /* Turn on interrupts. */
88 #define HIL_INTOFF 0x5D /* Turn off interrupts. */
90 #define HIL_READKBDSADR 0xF9
91 #define HIL_WRITEKBDSADR 0xE9
93 static unsigned int hphilkeyb_keycode
[HIL_KEYCODES_SET1_TBLSIZE
] __read_mostly
=
94 { HIL_KEYCODES_SET1
};
98 struct input_dev
*dev
;
106 unsigned char data
[16];
110 void *dev_id
; /* native bus device */
114 static void poll_finished(void)
120 switch (hil_dev
.data
[0]) {
122 down
= (hil_dev
.data
[1] & 1) == 0;
123 scode
= hil_dev
.data
[1] >> 1;
124 key
= hphilkeyb_keycode
[scode
];
125 input_report_key(hil_dev
.dev
, key
, down
);
132 static inline void handle_status(unsigned char s
, unsigned char c
)
141 poll_finished(); /* just in case */
142 hil_dev
.curdev
= c
& 7;
149 static inline void handle_data(unsigned char s
, unsigned char c
)
151 if (hil_dev
.curdev
) {
152 hil_dev
.data
[hil_dev
.ptr
++] = c
;
158 /* handle HIL interrupts */
159 static irqreturn_t
hil_interrupt(int irq
, void *handle
)
184 /* send a command to the HIL */
185 static void hil_do(unsigned char cmd
, unsigned char *data
, unsigned int len
)
189 spin_lock_irqsave(&hil_dev
.lock
, flags
);
196 hil_write_data(*(data
++));
198 spin_unlock_irqrestore(&hil_dev
.lock
, flags
);
203 static int __devinit
hil_keyb_init(void)
206 unsigned int i
, kbid
;
207 wait_queue_head_t hil_wait
;
211 return -ENODEV
; /* already initialized */
213 init_waitqueue_head(&hil_wait
);
214 spin_lock_init(&hil_dev
.lock
);
216 hil_dev
.dev
= input_allocate_device();
220 err
= request_irq(HIL_IRQ
, hil_interrupt
, 0, "hil", hil_dev
.dev_id
);
222 printk(KERN_ERR
"HIL: Can't get IRQ\n");
226 /* Turn on interrupts */
227 hil_do(HIL_INTON
, NULL
, 0);
229 /* Look for keyboards */
230 hil_dev
.valid
= 0; /* clear any pending data */
231 hil_do(HIL_READKBDSADR
, NULL
, 0);
233 wait_event_interruptible_timeout(hil_wait
, hil_dev
.valid
, 3 * HZ
);
235 printk(KERN_WARNING
"HIL: timed out, assuming no keyboard present\n");
241 printk(KERN_WARNING
"HIL: no keyboard present\n");
244 printk(KERN_INFO
"HIL: keyboard found at id %d\n", kbid
);
247 /* set it to raw mode */
249 hil_do(HIL_WRITEKBDSADR
, &c
, 1);
251 for (i
= 0; i
< HIL_KEYCODES_SET1_TBLSIZE
; i
++)
252 if (hphilkeyb_keycode
[i
] != KEY_RESERVED
)
253 __set_bit(hphilkeyb_keycode
[i
], hil_dev
.dev
->keybit
);
255 hil_dev
.dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_REP
);
256 hil_dev
.dev
->ledbit
[0] = BIT_MASK(LED_NUML
) | BIT_MASK(LED_CAPSL
) |
257 BIT_MASK(LED_SCROLLL
);
258 hil_dev
.dev
->keycodemax
= HIL_KEYCODES_SET1_TBLSIZE
;
259 hil_dev
.dev
->keycodesize
= sizeof(hphilkeyb_keycode
[0]);
260 hil_dev
.dev
->keycode
= hphilkeyb_keycode
;
261 hil_dev
.dev
->name
= "HIL keyboard";
262 hil_dev
.dev
->phys
= "hpkbd/input0";
264 hil_dev
.dev
->id
.bustype
= BUS_HIL
;
265 hil_dev
.dev
->id
.vendor
= PCI_VENDOR_ID_HP
;
266 hil_dev
.dev
->id
.product
= 0x0001;
267 hil_dev
.dev
->id
.version
= 0x0010;
269 err
= input_register_device(hil_dev
.dev
);
271 printk(KERN_ERR
"HIL: Can't register device\n");
275 printk(KERN_INFO
"input: %s, ID %d at 0x%08lx (irq %d) found and attached\n",
276 hil_dev
.dev
->name
, kbid
, HILBASE
, HIL_IRQ
);
281 hil_do(HIL_INTOFF
, NULL
, 0);
282 free_irq(HIL_IRQ
, hil_dev
.dev_id
);
284 input_free_device(hil_dev
.dev
);
289 static void __devexit
hil_keyb_exit(void)
292 free_irq(HIL_IRQ
, hil_dev
.dev_id
);
294 /* Turn off interrupts */
295 hil_do(HIL_INTOFF
, NULL
, 0);
297 input_unregister_device(hil_dev
.dev
);
301 #if defined(CONFIG_PARISC)
302 static int __devinit
hil_probe_chip(struct parisc_device
*dev
)
304 /* Only allow one HIL keyboard */
309 printk(KERN_WARNING
"HIL: IRQ not found for HIL bus at 0x%p\n",
310 (void *)dev
->hpa
.start
);
314 hil_base
= dev
->hpa
.start
;
316 hil_dev
.dev_id
= dev
;
318 printk(KERN_INFO
"Found HIL bus at 0x%08lx, IRQ %d\n", hil_base
, hil_irq
);
320 return hil_keyb_init();
323 static int __devexit
hil_remove_chip(struct parisc_device
*dev
)
330 static struct parisc_device_id hil_tbl
[] = {
331 { HPHW_FIO
, HVERSION_REV_ANY_ID
, HVERSION_ANY_ID
, 0x00073 },
336 /* Disabled to avoid conflicts with the HP SDC HIL drivers */
337 MODULE_DEVICE_TABLE(parisc
, hil_tbl
);
340 static struct parisc_driver hil_driver
= {
343 .probe
= hil_probe_chip
,
344 .remove
= __devexit_p(hil_remove_chip
),
347 static int __init
hil_init(void)
349 return register_parisc_driver(&hil_driver
);
352 static void __exit
hil_exit(void)
354 unregister_parisc_driver(&hil_driver
);
357 #else /* !CONFIG_PARISC */
359 static int __init
hil_init(void)
363 /* Only allow one HIL keyboard */
370 if (!hwreg_present((void *)(HILBASE
+ HIL_DATA
))) {
371 printk(KERN_ERR
"HIL: hardware register was not found\n");
375 if (!request_region(HILBASE
+ HIL_DATA
, 2, "hil")) {
376 printk(KERN_ERR
"HIL: IOPORT region already used\n");
380 error
= hil_keyb_init();
382 release_region(HILBASE
+ HIL_DATA
, 2);
389 static void __exit
hil_exit(void)
392 release_region(HILBASE
+ HIL_DATA
, 2);
395 #endif /* CONFIG_PARISC */
397 module_init(hil_init
);
398 module_exit(hil_exit
);