Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Generic linux-input device driver for keyboard devices |
| 3 | * |
| 4 | * Copyright (c) 2001 Brian S. Julin |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions, and the following disclaimer, |
| 12 | * without modification. |
| 13 | * 2. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * Alternatively, this software may be distributed under the terms of the |
| 17 | * GNU General Public License ("GPL"). |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR |
| 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 28 | * |
| 29 | * References: |
| 30 | * HP-HIL Technical Reference Manual. Hewlett Packard Product No. 45918A |
| 31 | * |
| 32 | */ |
| 33 | |
| 34 | #include <linux/hil.h> |
| 35 | #include <linux/input.h> |
| 36 | #include <linux/serio.h> |
| 37 | #include <linux/kernel.h> |
| 38 | #include <linux/module.h> |
| 39 | #include <linux/init.h> |
Matthew Wilcox | 0f17e4c | 2008-07-24 08:30:48 -0400 | [diff] [blame] | 40 | #include <linux/semaphore.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <linux/slab.h> |
| 42 | #include <linux/pci_ids.h> |
| 43 | |
| 44 | #define PREFIX "HIL KEYB: " |
| 45 | #define HIL_GENERIC_NAME "HIL keyboard" |
| 46 | |
| 47 | MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>"); |
| 48 | MODULE_DESCRIPTION(HIL_GENERIC_NAME " driver"); |
| 49 | MODULE_LICENSE("Dual BSD/GPL"); |
Helge Deller | c10a93a | 2008-12-29 04:44:44 -0800 | [diff] [blame] | 50 | MODULE_ALIAS("serio:ty03pr25id00ex*"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | #define HIL_KBD_MAX_LENGTH 16 |
| 53 | |
| 54 | #define HIL_KBD_SET1_UPBIT 0x01 |
| 55 | #define HIL_KBD_SET1_SHIFT 1 |
Helge Deller | 3acaf54 | 2007-02-28 23:51:19 -0500 | [diff] [blame] | 56 | static unsigned int hil_kbd_set1[HIL_KEYCODES_SET1_TBLSIZE] __read_mostly = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { HIL_KEYCODES_SET1 }; |
| 58 | |
| 59 | #define HIL_KBD_SET2_UPBIT 0x01 |
| 60 | #define HIL_KBD_SET2_SHIFT 1 |
| 61 | /* Set2 is user defined */ |
| 62 | |
| 63 | #define HIL_KBD_SET3_UPBIT 0x80 |
| 64 | #define HIL_KBD_SET3_SHIFT 0 |
Helge Deller | 3acaf54 | 2007-02-28 23:51:19 -0500 | [diff] [blame] | 65 | static unsigned int hil_kbd_set3[HIL_KEYCODES_SET3_TBLSIZE] __read_mostly = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { HIL_KEYCODES_SET3 }; |
| 67 | |
Helge Deller | 3acaf54 | 2007-02-28 23:51:19 -0500 | [diff] [blame] | 68 | static const char hil_language[][16] = { HIL_LOCALE_MAP }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | struct hil_kbd { |
Helge Deller | 102c8c7 | 2006-03-26 07:41:55 -0700 | [diff] [blame] | 71 | struct input_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | struct serio *serio; |
| 73 | |
| 74 | /* Input buffer and index for packets from HIL bus. */ |
| 75 | hil_packet data[HIL_KBD_MAX_LENGTH]; |
| 76 | int idx4; /* four counts per packet */ |
| 77 | |
| 78 | /* Raw device info records from HIL bus, see hil.h for fields. */ |
| 79 | char idd[HIL_KBD_MAX_LENGTH]; /* DID byte and IDD record */ |
| 80 | char rsc[HIL_KBD_MAX_LENGTH]; /* RSC record */ |
| 81 | char exd[HIL_KBD_MAX_LENGTH]; /* EXD record */ |
| 82 | char rnm[HIL_KBD_MAX_LENGTH + 1]; /* RNM record + NULL term. */ |
| 83 | |
| 84 | /* Something to sleep around with. */ |
| 85 | struct semaphore sem; |
| 86 | }; |
| 87 | |
| 88 | /* Process a complete packet after transfer from the HIL */ |
| 89 | static void hil_kbd_process_record(struct hil_kbd *kbd) |
| 90 | { |
Helge Deller | 102c8c7 | 2006-03-26 07:41:55 -0700 | [diff] [blame] | 91 | struct input_dev *dev = kbd->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | hil_packet *data = kbd->data; |
| 93 | hil_packet p; |
| 94 | int idx, i, cnt; |
| 95 | |
| 96 | idx = kbd->idx4/4; |
| 97 | p = data[idx - 1]; |
| 98 | |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 99 | if ((p & ~HIL_CMDCT_POL) == |
| 100 | (HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_POL)) |
| 101 | goto report; |
| 102 | if ((p & ~HIL_CMDCT_RPL) == |
| 103 | (HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_RPL)) |
| 104 | goto report; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | /* Not a poll response. See if we are loading config records. */ |
| 107 | switch (p & HIL_PKT_DATA_MASK) { |
| 108 | case HIL_CMD_IDD: |
| 109 | for (i = 0; i < idx; i++) |
| 110 | kbd->idd[i] = kbd->data[i] & HIL_PKT_DATA_MASK; |
| 111 | for (; i < HIL_KBD_MAX_LENGTH; i++) |
| 112 | kbd->idd[i] = 0; |
| 113 | break; |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | case HIL_CMD_RSC: |
| 116 | for (i = 0; i < idx; i++) |
| 117 | kbd->rsc[i] = kbd->data[i] & HIL_PKT_DATA_MASK; |
| 118 | for (; i < HIL_KBD_MAX_LENGTH; i++) |
| 119 | kbd->rsc[i] = 0; |
| 120 | break; |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | case HIL_CMD_EXD: |
| 123 | for (i = 0; i < idx; i++) |
| 124 | kbd->exd[i] = kbd->data[i] & HIL_PKT_DATA_MASK; |
| 125 | for (; i < HIL_KBD_MAX_LENGTH; i++) |
| 126 | kbd->exd[i] = 0; |
| 127 | break; |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | case HIL_CMD_RNM: |
| 130 | for (i = 0; i < idx; i++) |
| 131 | kbd->rnm[i] = kbd->data[i] & HIL_PKT_DATA_MASK; |
| 132 | for (; i < HIL_KBD_MAX_LENGTH + 1; i++) |
| 133 | kbd->rnm[i] = '\0'; |
| 134 | break; |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | default: |
| 137 | /* These occur when device isn't present */ |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 138 | if (p == (HIL_ERR_INT | HIL_PKT_CMD)) |
| 139 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | /* Anything else we'd like to know about. */ |
| 141 | printk(KERN_WARNING PREFIX "Device sent unknown record %x\n", p); |
| 142 | break; |
| 143 | } |
| 144 | goto out; |
| 145 | |
| 146 | report: |
| 147 | cnt = 1; |
| 148 | switch (kbd->data[0] & HIL_POL_CHARTYPE_MASK) { |
| 149 | case HIL_POL_CHARTYPE_NONE: |
| 150 | break; |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | case HIL_POL_CHARTYPE_ASCII: |
| 153 | while (cnt < idx - 1) |
| 154 | input_report_key(dev, kbd->data[cnt++] & 0x7f, 1); |
| 155 | break; |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | case HIL_POL_CHARTYPE_RSVD1: |
| 158 | case HIL_POL_CHARTYPE_RSVD2: |
| 159 | case HIL_POL_CHARTYPE_BINARY: |
| 160 | while (cnt < idx - 1) |
| 161 | input_report_key(dev, kbd->data[cnt++], 1); |
| 162 | break; |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | case HIL_POL_CHARTYPE_SET1: |
| 165 | while (cnt < idx - 1) { |
| 166 | unsigned int key; |
| 167 | int up; |
| 168 | key = kbd->data[cnt++]; |
| 169 | up = key & HIL_KBD_SET1_UPBIT; |
| 170 | key &= (~HIL_KBD_SET1_UPBIT & 0xff); |
| 171 | key = hil_kbd_set1[key >> HIL_KBD_SET1_SHIFT]; |
| 172 | if (key != KEY_RESERVED) |
| 173 | input_report_key(dev, key, !up); |
| 174 | } |
| 175 | break; |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | case HIL_POL_CHARTYPE_SET2: |
| 178 | while (cnt < idx - 1) { |
| 179 | unsigned int key; |
| 180 | int up; |
| 181 | key = kbd->data[cnt++]; |
| 182 | up = key & HIL_KBD_SET2_UPBIT; |
| 183 | key &= (~HIL_KBD_SET1_UPBIT & 0xff); |
| 184 | key = key >> HIL_KBD_SET2_SHIFT; |
| 185 | if (key != KEY_RESERVED) |
| 186 | input_report_key(dev, key, !up); |
| 187 | } |
| 188 | break; |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | case HIL_POL_CHARTYPE_SET3: |
| 191 | while (cnt < idx - 1) { |
| 192 | unsigned int key; |
| 193 | int up; |
| 194 | key = kbd->data[cnt++]; |
| 195 | up = key & HIL_KBD_SET3_UPBIT; |
| 196 | key &= (~HIL_KBD_SET1_UPBIT & 0xff); |
| 197 | key = hil_kbd_set3[key >> HIL_KBD_SET3_SHIFT]; |
| 198 | if (key != KEY_RESERVED) |
| 199 | input_report_key(dev, key, !up); |
| 200 | } |
| 201 | break; |
| 202 | } |
| 203 | out: |
| 204 | kbd->idx4 = 0; |
| 205 | up(&kbd->sem); |
| 206 | } |
| 207 | |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 208 | static void hil_kbd_process_err(struct hil_kbd *kbd) |
| 209 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | printk(KERN_WARNING PREFIX "errored HIL packet\n"); |
| 211 | kbd->idx4 = 0; |
| 212 | up(&kbd->sem); |
| 213 | } |
| 214 | |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 215 | static irqreturn_t hil_kbd_interrupt(struct serio *serio, |
| 216 | unsigned char data, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | { |
| 218 | struct hil_kbd *kbd; |
| 219 | hil_packet packet; |
| 220 | int idx; |
| 221 | |
Matthew Wilcox | 6ab0f5c | 2005-10-21 22:58:51 -0400 | [diff] [blame] | 222 | kbd = serio_get_drvdata(serio); |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 223 | BUG_ON(kbd == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
| 225 | if (kbd->idx4 >= (HIL_KBD_MAX_LENGTH * sizeof(hil_packet))) { |
| 226 | hil_kbd_process_err(kbd); |
| 227 | return IRQ_HANDLED; |
| 228 | } |
| 229 | idx = kbd->idx4/4; |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 230 | if (!(kbd->idx4 % 4)) |
| 231 | kbd->data[idx] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | packet = kbd->data[idx]; |
| 233 | packet |= ((hil_packet)data) << ((3 - (kbd->idx4 % 4)) * 8); |
| 234 | kbd->data[idx] = packet; |
| 235 | |
| 236 | /* Records of N 4-byte hil_packets must terminate with a command. */ |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 237 | if ((++(kbd->idx4)) % 4) |
| 238 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | if ((packet & 0xffff0000) != HIL_ERR_INT) { |
| 240 | hil_kbd_process_err(kbd); |
| 241 | return IRQ_HANDLED; |
| 242 | } |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 243 | if (packet & HIL_PKT_CMD) |
| 244 | hil_kbd_process_record(kbd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | return IRQ_HANDLED; |
| 246 | } |
| 247 | |
| 248 | static void hil_kbd_disconnect(struct serio *serio) |
| 249 | { |
| 250 | struct hil_kbd *kbd; |
| 251 | |
Matthew Wilcox | 6ab0f5c | 2005-10-21 22:58:51 -0400 | [diff] [blame] | 252 | kbd = serio_get_drvdata(serio); |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 253 | BUG_ON(kbd == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | serio_close(serio); |
Kyle McMartin | cd7a920 | 2006-03-30 11:47:32 -0500 | [diff] [blame] | 256 | input_unregister_device(kbd->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | kfree(kbd); |
| 258 | } |
| 259 | |
Matthew Wilcox | 6ab0f5c | 2005-10-21 22:58:51 -0400 | [diff] [blame] | 260 | static int hil_kbd_connect(struct serio *serio, struct serio_driver *drv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | { |
| 262 | struct hil_kbd *kbd; |
| 263 | uint8_t did, *idd; |
| 264 | int i; |
Dmitry Torokhov | 95d465f | 2006-04-02 00:08:05 -0500 | [diff] [blame] | 265 | |
Eric Sesterhenn | b39787a | 2006-03-14 00:09:16 -0500 | [diff] [blame] | 266 | kbd = kzalloc(sizeof(*kbd), GFP_KERNEL); |
Matthew Wilcox | 6ab0f5c | 2005-10-21 22:58:51 -0400 | [diff] [blame] | 267 | if (!kbd) |
| 268 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
Helge Deller | 102c8c7 | 2006-03-26 07:41:55 -0700 | [diff] [blame] | 270 | kbd->dev = input_allocate_device(); |
Dmitry Torokhov | 95d465f | 2006-04-02 00:08:05 -0500 | [diff] [blame] | 271 | if (!kbd->dev) |
| 272 | goto bail0; |
| 273 | |
Dmitry Torokhov | 95d465f | 2006-04-02 00:08:05 -0500 | [diff] [blame] | 274 | if (serio_open(serio, drv)) |
| 275 | goto bail1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
Matthew Wilcox | 6ab0f5c | 2005-10-21 22:58:51 -0400 | [diff] [blame] | 277 | serio_set_drvdata(serio, kbd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | kbd->serio = serio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 280 | init_MUTEX_LOCKED(&kbd->sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
| 282 | /* Get device info. MLC driver supplies devid/status/etc. */ |
| 283 | serio->write(serio, 0); |
| 284 | serio->write(serio, 0); |
| 285 | serio->write(serio, HIL_PKT_CMD >> 8); |
| 286 | serio->write(serio, HIL_CMD_IDD); |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 287 | down(&kbd->sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
| 289 | serio->write(serio, 0); |
| 290 | serio->write(serio, 0); |
| 291 | serio->write(serio, HIL_PKT_CMD >> 8); |
| 292 | serio->write(serio, HIL_CMD_RSC); |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 293 | down(&kbd->sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
| 295 | serio->write(serio, 0); |
| 296 | serio->write(serio, 0); |
| 297 | serio->write(serio, HIL_PKT_CMD >> 8); |
| 298 | serio->write(serio, HIL_CMD_RNM); |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 299 | down(&kbd->sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
| 301 | serio->write(serio, 0); |
| 302 | serio->write(serio, 0); |
| 303 | serio->write(serio, HIL_PKT_CMD >> 8); |
| 304 | serio->write(serio, HIL_CMD_EXD); |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 305 | down(&kbd->sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 307 | up(&kbd->sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | did = kbd->idd[0]; |
| 310 | idd = kbd->idd + 1; |
| 311 | switch (did & HIL_IDD_DID_TYPE_MASK) { |
| 312 | case HIL_IDD_DID_TYPE_KB_INTEGRAL: |
| 313 | case HIL_IDD_DID_TYPE_KB_ITF: |
| 314 | case HIL_IDD_DID_TYPE_KB_RSVD: |
| 315 | case HIL_IDD_DID_TYPE_CHAR: |
| 316 | printk(KERN_INFO PREFIX "HIL keyboard found (did = 0x%02x, lang = %s)\n", |
| 317 | did, hil_language[did & HIL_IDD_DID_TYPE_KB_LANG_MASK]); |
| 318 | break; |
| 319 | default: |
Helge Deller | 102c8c7 | 2006-03-26 07:41:55 -0700 | [diff] [blame] | 320 | goto bail2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 323 | if (HIL_IDD_NUM_BUTTONS(idd) || HIL_IDD_NUM_AXES_PER_SET(*idd)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | printk(KERN_INFO PREFIX "keyboards only, no combo devices supported.\n"); |
Helge Deller | 102c8c7 | 2006-03-26 07:41:55 -0700 | [diff] [blame] | 325 | goto bail2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 328 | kbd->dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); |
| 329 | kbd->dev->ledbit[0] = BIT_MASK(LED_NUML) | BIT_MASK(LED_CAPSL) | |
| 330 | BIT_MASK(LED_SCROLLL); |
Helge Deller | 102c8c7 | 2006-03-26 07:41:55 -0700 | [diff] [blame] | 331 | kbd->dev->keycodemax = HIL_KEYCODES_SET1_TBLSIZE; |
| 332 | kbd->dev->keycodesize = sizeof(hil_kbd_set1[0]); |
| 333 | kbd->dev->keycode = hil_kbd_set1; |
| 334 | kbd->dev->name = strlen(kbd->rnm) ? kbd->rnm : HIL_GENERIC_NAME; |
| 335 | kbd->dev->phys = "hpkbd/input0"; /* XXX */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
Helge Deller | 102c8c7 | 2006-03-26 07:41:55 -0700 | [diff] [blame] | 337 | kbd->dev->id.bustype = BUS_HIL; |
| 338 | kbd->dev->id.vendor = PCI_VENDOR_ID_HP; |
| 339 | kbd->dev->id.product = 0x0001; /* TODO: get from kbd->rsc */ |
| 340 | kbd->dev->id.version = 0x0100; /* TODO: get from kbd->rsc */ |
Dmitry Torokhov | 469ba4d | 2007-04-12 01:34:58 -0400 | [diff] [blame] | 341 | kbd->dev->dev.parent = &serio->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
| 343 | for (i = 0; i < 128; i++) { |
Helge Deller | 102c8c7 | 2006-03-26 07:41:55 -0700 | [diff] [blame] | 344 | set_bit(hil_kbd_set1[i], kbd->dev->keybit); |
| 345 | set_bit(hil_kbd_set3[i], kbd->dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } |
Helge Deller | 102c8c7 | 2006-03-26 07:41:55 -0700 | [diff] [blame] | 347 | clear_bit(0, kbd->dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
Helge Deller | 102c8c7 | 2006-03-26 07:41:55 -0700 | [diff] [blame] | 349 | input_register_device(kbd->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | printk(KERN_INFO "input: %s, ID: %d\n", |
Helge Deller | 102c8c7 | 2006-03-26 07:41:55 -0700 | [diff] [blame] | 351 | kbd->dev->name, did); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
| 353 | serio->write(serio, 0); |
| 354 | serio->write(serio, 0); |
| 355 | serio->write(serio, HIL_PKT_CMD >> 8); |
| 356 | serio->write(serio, HIL_CMD_EK1); /* Enable Keyswitch Autorepeat 1 */ |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 357 | down(&kbd->sem); |
| 358 | up(&kbd->sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
Matthew Wilcox | 6ab0f5c | 2005-10-21 22:58:51 -0400 | [diff] [blame] | 360 | return 0; |
Helge Deller | 102c8c7 | 2006-03-26 07:41:55 -0700 | [diff] [blame] | 361 | bail2: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | serio_close(serio); |
Matthew Wilcox | d668da8 | 2006-04-03 13:44:17 +0000 | [diff] [blame] | 363 | serio_set_drvdata(serio, NULL); |
Helge Deller | 102c8c7 | 2006-03-26 07:41:55 -0700 | [diff] [blame] | 364 | bail1: |
| 365 | input_free_device(kbd->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | bail0: |
| 367 | kfree(kbd); |
Matthew Wilcox | 6ab0f5c | 2005-10-21 22:58:51 -0400 | [diff] [blame] | 368 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Matthew Wilcox | 6ab0f5c | 2005-10-21 22:58:51 -0400 | [diff] [blame] | 371 | static struct serio_device_id hil_kbd_ids[] = { |
| 372 | { |
| 373 | .type = SERIO_HIL_MLC, |
| 374 | .proto = SERIO_HIL, |
| 375 | .id = SERIO_ANY, |
| 376 | .extra = SERIO_ANY, |
| 377 | }, |
| 378 | { 0 } |
| 379 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | |
Helge Deller | 3acaf54 | 2007-02-28 23:51:19 -0500 | [diff] [blame] | 381 | static struct serio_driver hil_kbd_serio_drv = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | .driver = { |
| 383 | .name = "hil_kbd", |
| 384 | }, |
| 385 | .description = "HP HIL keyboard driver", |
Matthew Wilcox | 6ab0f5c | 2005-10-21 22:58:51 -0400 | [diff] [blame] | 386 | .id_table = hil_kbd_ids, |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 387 | .connect = hil_kbd_connect, |
| 388 | .disconnect = hil_kbd_disconnect, |
| 389 | .interrupt = hil_kbd_interrupt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | }; |
| 391 | |
| 392 | static int __init hil_kbd_init(void) |
| 393 | { |
Akinobu Mita | 153a9df0 | 2006-11-23 23:35:10 -0500 | [diff] [blame] | 394 | return serio_register_driver(&hil_kbd_serio_drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | } |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 396 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | static void __exit hil_kbd_exit(void) |
| 398 | { |
| 399 | serio_unregister_driver(&hil_kbd_serio_drv); |
| 400 | } |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | module_init(hil_kbd_init); |
| 403 | module_exit(hil_kbd_exit); |