Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/hil/hilkbd.c |
| 3 | * |
| 4 | * Copyright (C) 1998 Philip Blundell <philb@gnu.org> |
| 5 | * Copyright (C) 1999 Matthew Wilcox <willy@bofh.ai> |
Helge Deller | 3acaf54 | 2007-02-28 23:51:19 -0500 | [diff] [blame] | 6 | * Copyright (C) 1999-2007 Helge Deller <deller@gmx.de> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * Very basic HP Human Interface Loop (HIL) driver. |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 9 | * This driver handles the keyboard on HP300 (m68k) and on some |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * HP700 (parisc) series machines. |
| 11 | * |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 12 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/pci_ids.h> |
| 19 | #include <linux/ioport.h> |
| 20 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/errno.h> |
| 22 | #include <linux/input.h> |
| 23 | #include <linux/init.h> |
Matthew Wilcox | 6ab0f5c | 2005-10-21 22:58:51 -0400 | [diff] [blame] | 24 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/hil.h> |
Al Viro | db71b7f | 2006-12-13 00:35:01 -0800 | [diff] [blame] | 26 | #include <linux/io.h> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 27 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/spinlock.h> |
Al Viro | db71b7f | 2006-12-13 00:35:01 -0800 | [diff] [blame] | 29 | #include <asm/irq.h> |
| 30 | #ifdef CONFIG_HP300 |
| 31 | #include <asm/hwtest.h> |
| 32 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | |
| 35 | MODULE_AUTHOR("Philip Blundell, Matthew Wilcox, Helge Deller"); |
| 36 | MODULE_DESCRIPTION("HIL keyboard driver (basic functionality)"); |
| 37 | MODULE_LICENSE("GPL v2"); |
| 38 | |
| 39 | |
| 40 | #if defined(CONFIG_PARISC) |
| 41 | |
| 42 | #include <asm/io.h> |
| 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 |
| 49 | #define HIL_CMD 0x801 |
| 50 | #define HIL_IRQ hil_irq |
| 51 | #define hil_readb(p) gsc_readb(p) |
| 52 | #define hil_writeb(v,p) gsc_writeb((v),(p)) |
| 53 | |
| 54 | #elif defined(CONFIG_HP300) |
| 55 | |
Geert Uytterhoeven | f8744bc | 2007-05-01 22:32:44 +0200 | [diff] [blame] | 56 | #define HILBASE 0xf0428000UL /* HP300 (m68k) port address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #define HIL_DATA 0x1 |
| 58 | #define HIL_CMD 0x3 |
| 59 | #define HIL_IRQ 2 |
| 60 | #define hil_readb(p) readb(p) |
| 61 | #define hil_writeb(v,p) writeb((v),(p)) |
| 62 | |
| 63 | #else |
| 64 | #error "HIL is not supported on this platform" |
| 65 | #endif |
| 66 | |
| 67 | |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | /* HIL helper functions */ |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) |
| 77 | |
| 78 | /* HIL constants */ |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | #define HIL_BUSY 0x02 |
| 81 | #define HIL_DATA_RDY 0x01 |
| 82 | |
| 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. */ |
| 89 | |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 90 | #define HIL_READKBDSADR 0xF9 |
| 91 | #define HIL_WRITEKBDSADR 0xE9 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
Helge Deller | 3acaf54 | 2007-02-28 23:51:19 -0500 | [diff] [blame] | 93 | static unsigned int hphilkeyb_keycode[HIL_KEYCODES_SET1_TBLSIZE] __read_mostly = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { HIL_KEYCODES_SET1 }; |
| 95 | |
| 96 | /* HIL structure */ |
| 97 | static struct { |
Helge Deller | 102c8c7 | 2006-03-26 07:41:55 -0700 | [diff] [blame] | 98 | struct input_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | unsigned int curdev; |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | unsigned char s; |
| 103 | unsigned char c; |
| 104 | int valid; |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | unsigned char data[16]; |
| 107 | unsigned int ptr; |
| 108 | spinlock_t lock; |
| 109 | |
| 110 | void *dev_id; /* native bus device */ |
| 111 | } hil_dev; |
| 112 | |
| 113 | |
| 114 | static void poll_finished(void) |
| 115 | { |
| 116 | int down; |
| 117 | int key; |
| 118 | unsigned char scode; |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | switch (hil_dev.data[0]) { |
| 121 | case 0x40: |
| 122 | down = (hil_dev.data[1] & 1) == 0; |
| 123 | scode = hil_dev.data[1] >> 1; |
| 124 | key = hphilkeyb_keycode[scode]; |
Helge Deller | 102c8c7 | 2006-03-26 07:41:55 -0700 | [diff] [blame] | 125 | input_report_key(hil_dev.dev, key, down); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | break; |
| 127 | } |
| 128 | hil_dev.curdev = 0; |
| 129 | } |
| 130 | |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | static inline void handle_status(unsigned char s, unsigned char c) |
| 133 | { |
| 134 | if (c & 0x8) { |
| 135 | /* End of block */ |
| 136 | if (c & 0x10) |
| 137 | poll_finished(); |
| 138 | } else { |
| 139 | if (c & 0x10) { |
| 140 | if (hil_dev.curdev) |
| 141 | poll_finished(); /* just in case */ |
| 142 | hil_dev.curdev = c & 7; |
| 143 | hil_dev.ptr = 0; |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | static inline void handle_data(unsigned char s, unsigned char c) |
| 150 | { |
| 151 | if (hil_dev.curdev) { |
| 152 | hil_dev.data[hil_dev.ptr++] = c; |
| 153 | hil_dev.ptr &= 15; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 158 | /* handle HIL interrupts */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 159 | static irqreturn_t hil_interrupt(int irq, void *handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | { |
| 161 | unsigned char s, c; |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | s = hil_status(); |
| 164 | c = hil_read_data(); |
| 165 | |
| 166 | switch (s >> 4) { |
| 167 | case 0x5: |
| 168 | handle_status(s, c); |
| 169 | break; |
| 170 | case 0x6: |
| 171 | handle_data(s, c); |
| 172 | break; |
| 173 | case 0x4: |
| 174 | hil_dev.s = s; |
| 175 | hil_dev.c = c; |
| 176 | mb(); |
| 177 | hil_dev.valid = 1; |
| 178 | break; |
| 179 | } |
| 180 | return IRQ_HANDLED; |
| 181 | } |
| 182 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 184 | /* send a command to the HIL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | static void hil_do(unsigned char cmd, unsigned char *data, unsigned int len) |
| 186 | { |
| 187 | unsigned long flags; |
| 188 | |
| 189 | spin_lock_irqsave(&hil_dev.lock, flags); |
| 190 | while (hil_busy()) |
| 191 | /* wait */; |
| 192 | hil_command(cmd); |
| 193 | while (len--) { |
| 194 | while (hil_busy()) |
| 195 | /* wait */; |
| 196 | hil_write_data(*(data++)); |
| 197 | } |
| 198 | spin_unlock_irqrestore(&hil_dev.lock, flags); |
| 199 | } |
| 200 | |
| 201 | |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 202 | /* initialize HIL */ |
Bill Pemberton | 5298cc4 | 2012-11-23 21:38:25 -0800 | [diff] [blame] | 203 | static int hil_keyb_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | { |
| 205 | unsigned char c; |
| 206 | unsigned int i, kbid; |
| 207 | wait_queue_head_t hil_wait; |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 208 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 210 | if (hil_dev.dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | return -ENODEV; /* already initialized */ |
Helge Deller | 102c8c7 | 2006-03-26 07:41:55 -0700 | [diff] [blame] | 212 | |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 213 | init_waitqueue_head(&hil_wait); |
Helge Deller | 3acaf54 | 2007-02-28 23:51:19 -0500 | [diff] [blame] | 214 | spin_lock_init(&hil_dev.lock); |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 215 | |
Helge Deller | 102c8c7 | 2006-03-26 07:41:55 -0700 | [diff] [blame] | 216 | hil_dev.dev = input_allocate_device(); |
| 217 | if (!hil_dev.dev) |
| 218 | return -ENOMEM; |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 219 | |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 220 | err = request_irq(HIL_IRQ, hil_interrupt, 0, "hil", hil_dev.dev_id); |
| 221 | if (err) { |
| 222 | printk(KERN_ERR "HIL: Can't get IRQ\n"); |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 223 | goto err1; |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 224 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
| 226 | /* Turn on interrupts */ |
| 227 | hil_do(HIL_INTON, NULL, 0); |
| 228 | |
| 229 | /* Look for keyboards */ |
| 230 | hil_dev.valid = 0; /* clear any pending data */ |
| 231 | hil_do(HIL_READKBDSADR, NULL, 0); |
| 232 | |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 233 | wait_event_interruptible_timeout(hil_wait, hil_dev.valid, 3 * HZ); |
| 234 | if (!hil_dev.valid) |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 235 | printk(KERN_WARNING "HIL: timed out, assuming no keyboard present\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 237 | c = hil_dev.c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | hil_dev.valid = 0; |
| 239 | if (c == 0) { |
| 240 | kbid = -1; |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 241 | printk(KERN_WARNING "HIL: no keyboard present\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | } else { |
| 243 | kbid = ffz(~c); |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 244 | printk(KERN_INFO "HIL: keyboard found at id %d\n", kbid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | /* set it to raw mode */ |
| 248 | c = 0; |
| 249 | hil_do(HIL_WRITEKBDSADR, &c, 1); |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | for (i = 0; i < HIL_KEYCODES_SET1_TBLSIZE; i++) |
| 252 | if (hphilkeyb_keycode[i] != KEY_RESERVED) |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 253 | __set_bit(hphilkeyb_keycode[i], hil_dev.dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 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); |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 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"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
Helge Deller | 102c8c7 | 2006-03-26 07:41:55 -0700 | [diff] [blame] | 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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 269 | err = input_register_device(hil_dev.dev); |
| 270 | if (err) { |
| 271 | printk(KERN_ERR "HIL: Can't register device\n"); |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 272 | goto err2; |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 273 | } |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | printk(KERN_INFO "input: %s, ID %d at 0x%08lx (irq %d) found and attached\n", |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 276 | hil_dev.dev->name, kbid, HILBASE, HIL_IRQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
| 278 | return 0; |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 279 | |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 280 | err2: |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 281 | hil_do(HIL_INTOFF, NULL, 0); |
| 282 | free_irq(HIL_IRQ, hil_dev.dev_id); |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 283 | err1: |
| 284 | input_free_device(hil_dev.dev); |
| 285 | hil_dev.dev = NULL; |
| 286 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Bill Pemberton | e2619cf | 2012-11-23 21:50:47 -0800 | [diff] [blame] | 289 | static void hil_keyb_exit(void) |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 290 | { |
| 291 | if (HIL_IRQ) |
| 292 | free_irq(HIL_IRQ, hil_dev.dev_id); |
| 293 | |
| 294 | /* Turn off interrupts */ |
| 295 | hil_do(HIL_INTOFF, NULL, 0); |
| 296 | |
| 297 | input_unregister_device(hil_dev.dev); |
| 298 | hil_dev.dev = NULL; |
| 299 | } |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | #if defined(CONFIG_PARISC) |
Bill Pemberton | 5298cc4 | 2012-11-23 21:38:25 -0800 | [diff] [blame] | 302 | static int hil_probe_chip(struct parisc_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | { |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 304 | /* Only allow one HIL keyboard */ |
| 305 | if (hil_dev.dev) |
| 306 | return -ENODEV; |
| 307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | if (!dev->irq) { |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 309 | printk(KERN_WARNING "HIL: IRQ not found for HIL bus at 0x%p\n", |
| 310 | (void *)dev->hpa.start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | return -ENODEV; |
| 312 | } |
| 313 | |
Matthew Wilcox | 53f01bb | 2005-10-21 22:36:40 -0400 | [diff] [blame] | 314 | hil_base = dev->hpa.start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | hil_irq = dev->irq; |
| 316 | hil_dev.dev_id = dev; |
Cyrill V. Gorcunov | b350620 | 2007-02-10 01:29:19 -0500 | [diff] [blame] | 317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | printk(KERN_INFO "Found HIL bus at 0x%08lx, IRQ %d\n", hil_base, hil_irq); |
| 319 | |
| 320 | return hil_keyb_init(); |
| 321 | } |
| 322 | |
Bill Pemberton | e2619cf | 2012-11-23 21:50:47 -0800 | [diff] [blame] | 323 | static int hil_remove_chip(struct parisc_device *dev) |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 324 | { |
| 325 | hil_keyb_exit(); |
| 326 | |
| 327 | return 0; |
| 328 | } |
| 329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | static struct parisc_device_id hil_tbl[] = { |
| 331 | { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00073 }, |
| 332 | { 0, } |
| 333 | }; |
| 334 | |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 335 | #if 0 |
| 336 | /* Disabled to avoid conflicts with the HP SDC HIL drivers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | MODULE_DEVICE_TABLE(parisc, hil_tbl); |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 338 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
| 340 | static struct parisc_driver hil_driver = { |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 341 | .name = "hil", |
| 342 | .id_table = hil_tbl, |
| 343 | .probe = hil_probe_chip, |
Bill Pemberton | 1cb0aa8 | 2012-11-23 21:27:39 -0800 | [diff] [blame] | 344 | .remove = hil_remove_chip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | static int __init hil_init(void) |
| 348 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | return register_parisc_driver(&hil_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | static void __exit hil_exit(void) |
| 353 | { |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 354 | unregister_parisc_driver(&hil_driver); |
| 355 | } |
| 356 | |
| 357 | #else /* !CONFIG_PARISC */ |
| 358 | |
| 359 | static int __init hil_init(void) |
| 360 | { |
| 361 | int error; |
| 362 | |
| 363 | /* Only allow one HIL keyboard */ |
| 364 | if (hil_dev.dev) |
| 365 | return -EBUSY; |
| 366 | |
| 367 | if (!MACH_IS_HP300) |
| 368 | return -ENODEV; |
| 369 | |
| 370 | if (!hwreg_present((void *)(HILBASE + HIL_DATA))) { |
| 371 | printk(KERN_ERR "HIL: hardware register was not found\n"); |
| 372 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 375 | if (!request_region(HILBASE + HIL_DATA, 2, "hil")) { |
| 376 | printk(KERN_ERR "HIL: IOPORT region already used\n"); |
| 377 | return -EIO; |
| 378 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 380 | error = hil_keyb_init(); |
| 381 | if (error) { |
| 382 | release_region(HILBASE + HIL_DATA, 2); |
| 383 | return error; |
| 384 | } |
Helge Deller | 102c8c7 | 2006-03-26 07:41:55 -0700 | [diff] [blame] | 385 | |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 386 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Helge Deller | b0ecc73 | 2009-03-04 23:27:15 -0800 | [diff] [blame] | 389 | static void __exit hil_exit(void) |
| 390 | { |
| 391 | hil_keyb_exit(); |
| 392 | release_region(HILBASE + HIL_DATA, 2); |
| 393 | } |
| 394 | |
| 395 | #endif /* CONFIG_PARISC */ |
| 396 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | module_init(hil_init); |
| 398 | module_exit(hil_exit); |