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> |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 40 | #include <linux/completion.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 | |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 84 | struct completion cmd_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | }; |
| 86 | |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 87 | static bool hil_kbd_is_command_response(hil_packet p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | { |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 89 | if ((p & ~HIL_CMDCT_POL) == (HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_POL)) |
| 90 | return false; |
| 91 | |
| 92 | if ((p & ~HIL_CMDCT_RPL) == (HIL_ERR_INT | HIL_PKT_CMD | HIL_CMD_RPL)) |
| 93 | return false; |
| 94 | |
| 95 | return true; |
| 96 | } |
| 97 | |
| 98 | static void hil_kbd_handle_command_response(struct hil_kbd *kbd) |
| 99 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | hil_packet p; |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 101 | char *buf; |
| 102 | int i, idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 104 | idx = kbd->idx4 / 4; |
| 105 | p = kbd->data[idx - 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | switch (p & HIL_PKT_DATA_MASK) { |
| 108 | case HIL_CMD_IDD: |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 109 | buf = kbd->idd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | break; |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | case HIL_CMD_RSC: |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 113 | buf = kbd->rsc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | break; |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | case HIL_CMD_EXD: |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 117 | buf = kbd->exd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | break; |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | case HIL_CMD_RNM: |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 121 | kbd->rnm[HIL_KBD_MAX_LENGTH] = 0; |
| 122 | buf = kbd->rnm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | break; |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | default: |
| 126 | /* These occur when device isn't present */ |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 127 | if (p != (HIL_ERR_INT | HIL_PKT_CMD)) { |
| 128 | /* Anything else we'd like to know about. */ |
| 129 | printk(KERN_WARNING PREFIX "Device sent unknown record %x\n", p); |
| 130 | } |
| 131 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 134 | for (i = 0; i < idx; i++) |
| 135 | buf[i] = kbd->data[i] & HIL_PKT_DATA_MASK; |
| 136 | for (; i < HIL_KBD_MAX_LENGTH; i++) |
| 137 | buf[i] = 0; |
| 138 | out: |
| 139 | complete(&kbd->cmd_done); |
| 140 | } |
| 141 | |
| 142 | static void hil_kbd_handle_key_events(struct hil_kbd *kbd) |
| 143 | { |
| 144 | struct input_dev *dev = kbd->dev; |
| 145 | int idx = kbd->idx4 / 4; |
| 146 | int i; |
| 147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | switch (kbd->data[0] & HIL_POL_CHARTYPE_MASK) { |
| 149 | case HIL_POL_CHARTYPE_NONE: |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 150 | return; |
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: |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 153 | for (i = 1; i < idx - 1; i++) |
| 154 | input_report_key(dev, kbd->data[i] & 0x7f, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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: |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 160 | for (i = 1; i < idx - 1; i++) |
| 161 | input_report_key(dev, kbd->data[i], 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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: |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 165 | for (i = 1; i < idx - 1; i++) { |
| 166 | unsigned int key = kbd->data[i]; |
| 167 | int up = key & HIL_KBD_SET1_UPBIT; |
| 168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | key &= (~HIL_KBD_SET1_UPBIT & 0xff); |
| 170 | key = hil_kbd_set1[key >> HIL_KBD_SET1_SHIFT]; |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 171 | input_report_key(dev, key, !up); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
| 173 | break; |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | case HIL_POL_CHARTYPE_SET2: |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 176 | for (i = 1; i < idx - 1; i++) { |
| 177 | unsigned int key = kbd->data[i]; |
| 178 | int up = key & HIL_KBD_SET2_UPBIT; |
| 179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | key &= (~HIL_KBD_SET1_UPBIT & 0xff); |
| 181 | key = key >> HIL_KBD_SET2_SHIFT; |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 182 | input_report_key(dev, key, !up); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | } |
| 184 | break; |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | case HIL_POL_CHARTYPE_SET3: |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 187 | for (i = 1; i < idx - 1; i++) { |
| 188 | unsigned int key = kbd->data[i]; |
| 189 | int up = key & HIL_KBD_SET3_UPBIT; |
| 190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | key &= (~HIL_KBD_SET1_UPBIT & 0xff); |
| 192 | key = hil_kbd_set3[key >> HIL_KBD_SET3_SHIFT]; |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 193 | input_report_key(dev, key, !up); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } |
| 195 | break; |
| 196 | } |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 197 | |
| 198 | input_sync(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 201 | static void hil_kbd_process_err(struct hil_kbd *kbd) |
| 202 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | printk(KERN_WARNING PREFIX "errored HIL packet\n"); |
| 204 | kbd->idx4 = 0; |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 205 | complete(&kbd->cmd_done); /* just in case somebody is waiting */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 208 | static irqreturn_t hil_kbd_interrupt(struct serio *serio, |
| 209 | unsigned char data, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | { |
| 211 | struct hil_kbd *kbd; |
| 212 | hil_packet packet; |
| 213 | int idx; |
| 214 | |
Matthew Wilcox | 6ab0f5c | 2005-10-21 22:58:51 -0400 | [diff] [blame] | 215 | kbd = serio_get_drvdata(serio); |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 216 | BUG_ON(kbd == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 218 | if (kbd->idx4 >= HIL_KBD_MAX_LENGTH * sizeof(hil_packet)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | hil_kbd_process_err(kbd); |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 220 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | } |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 222 | |
| 223 | idx = kbd->idx4 / 4; |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 224 | if (!(kbd->idx4 % 4)) |
| 225 | kbd->data[idx] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | packet = kbd->data[idx]; |
| 227 | packet |= ((hil_packet)data) << ((3 - (kbd->idx4 % 4)) * 8); |
| 228 | kbd->data[idx] = packet; |
| 229 | |
| 230 | /* Records of N 4-byte hil_packets must terminate with a command. */ |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 231 | if ((++kbd->idx4 % 4) == 0) { |
| 232 | if ((packet & 0xffff0000) != HIL_ERR_INT) { |
| 233 | hil_kbd_process_err(kbd); |
| 234 | } else if (packet & HIL_PKT_CMD) { |
| 235 | if (hil_kbd_is_command_response(packet)) |
| 236 | hil_kbd_handle_command_response(kbd); |
| 237 | else |
| 238 | hil_kbd_handle_key_events(kbd); |
| 239 | kbd->idx4 = 0; |
| 240 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | } |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 242 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | return IRQ_HANDLED; |
| 244 | } |
| 245 | |
| 246 | static void hil_kbd_disconnect(struct serio *serio) |
| 247 | { |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 248 | struct hil_kbd *kbd = serio_get_drvdata(serio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 250 | BUG_ON(kbd == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | serio_close(serio); |
Kyle McMartin | cd7a920 | 2006-03-30 11:47:32 -0500 | [diff] [blame] | 253 | input_unregister_device(kbd->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | kfree(kbd); |
| 255 | } |
| 256 | |
Matthew Wilcox | 6ab0f5c | 2005-10-21 22:58:51 -0400 | [diff] [blame] | 257 | static int hil_kbd_connect(struct serio *serio, struct serio_driver *drv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 259 | struct hil_kbd *kbd; |
| 260 | struct input_dev *input_dev; |
| 261 | uint8_t did, *idd; |
| 262 | int i; |
| 263 | int error; |
Dmitry Torokhov | 95d465f | 2006-04-02 00:08:05 -0500 | [diff] [blame] | 264 | |
Eric Sesterhenn | b39787a | 2006-03-14 00:09:16 -0500 | [diff] [blame] | 265 | kbd = kzalloc(sizeof(*kbd), GFP_KERNEL); |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 266 | input_dev = input_allocate_device(); |
| 267 | if (!kbd || !input_dev) { |
| 268 | error = -ENOMEM; |
| 269 | goto bail0; |
| 270 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 272 | kbd->serio = serio; |
| 273 | kbd->dev = input_dev; |
| 274 | |
| 275 | error = serio_open(serio, drv); |
| 276 | if (error) |
Dmitry Torokhov | 95d465f | 2006-04-02 00:08:05 -0500 | [diff] [blame] | 277 | goto bail0; |
| 278 | |
Matthew Wilcox | 6ab0f5c | 2005-10-21 22:58:51 -0400 | [diff] [blame] | 279 | serio_set_drvdata(serio, kbd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
| 281 | /* Get device info. MLC driver supplies devid/status/etc. */ |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 282 | init_completion(&kbd->cmd_done); |
Dmitry Torokhov | dd0d544 | 2009-08-05 00:30:26 -0700 | [diff] [blame] | 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); |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 287 | error = wait_for_completion_killable(&kbd->cmd_done); |
| 288 | if (error) |
| 289 | goto bail1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 291 | init_completion(&kbd->cmd_done); |
Dmitry Torokhov | dd0d544 | 2009-08-05 00:30:26 -0700 | [diff] [blame] | 292 | serio_write(serio, 0); |
| 293 | serio_write(serio, 0); |
| 294 | serio_write(serio, HIL_PKT_CMD >> 8); |
| 295 | serio_write(serio, HIL_CMD_RSC); |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 296 | error = wait_for_completion_killable(&kbd->cmd_done); |
| 297 | if (error) |
| 298 | goto bail1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 300 | init_completion(&kbd->cmd_done); |
Dmitry Torokhov | dd0d544 | 2009-08-05 00:30:26 -0700 | [diff] [blame] | 301 | serio_write(serio, 0); |
| 302 | serio_write(serio, 0); |
| 303 | serio_write(serio, HIL_PKT_CMD >> 8); |
| 304 | serio_write(serio, HIL_CMD_RNM); |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 305 | error = wait_for_completion_killable(&kbd->cmd_done); |
| 306 | if (error) |
| 307 | goto bail1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 309 | init_completion(&kbd->cmd_done); |
Dmitry Torokhov | dd0d544 | 2009-08-05 00:30:26 -0700 | [diff] [blame] | 310 | serio_write(serio, 0); |
| 311 | serio_write(serio, 0); |
| 312 | serio_write(serio, HIL_PKT_CMD >> 8); |
| 313 | serio_write(serio, HIL_CMD_EXD); |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 314 | error = wait_for_completion_killable(&kbd->cmd_done); |
| 315 | if (error) |
| 316 | goto bail1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
| 318 | did = kbd->idd[0]; |
| 319 | idd = kbd->idd + 1; |
| 320 | switch (did & HIL_IDD_DID_TYPE_MASK) { |
| 321 | case HIL_IDD_DID_TYPE_KB_INTEGRAL: |
| 322 | case HIL_IDD_DID_TYPE_KB_ITF: |
| 323 | case HIL_IDD_DID_TYPE_KB_RSVD: |
| 324 | case HIL_IDD_DID_TYPE_CHAR: |
| 325 | printk(KERN_INFO PREFIX "HIL keyboard found (did = 0x%02x, lang = %s)\n", |
| 326 | did, hil_language[did & HIL_IDD_DID_TYPE_KB_LANG_MASK]); |
| 327 | break; |
| 328 | default: |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 329 | goto bail1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 332 | 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] | 333 | printk(KERN_INFO PREFIX "keyboards only, no combo devices supported.\n"); |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 334 | goto bail1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 337 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); |
| 338 | input_dev->ledbit[0] = BIT_MASK(LED_NUML) | BIT_MASK(LED_CAPSL) | |
| 339 | BIT_MASK(LED_SCROLLL); |
| 340 | input_dev->keycodemax = HIL_KEYCODES_SET1_TBLSIZE; |
| 341 | input_dev->keycodesize = sizeof(hil_kbd_set1[0]); |
| 342 | input_dev->keycode = hil_kbd_set1; |
| 343 | input_dev->name = strlen(kbd->rnm) ? kbd->rnm : HIL_GENERIC_NAME; |
| 344 | input_dev->phys = "hpkbd/input0"; /* XXX */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 346 | input_dev->id.bustype = BUS_HIL; |
| 347 | input_dev->id.vendor = PCI_VENDOR_ID_HP; |
| 348 | input_dev->id.product = 0x0001; /* TODO: get from kbd->rsc */ |
| 349 | input_dev->id.version = 0x0100; /* TODO: get from kbd->rsc */ |
| 350 | input_dev->dev.parent = &serio->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | |
| 352 | for (i = 0; i < 128; i++) { |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 353 | __set_bit(hil_kbd_set1[i], input_dev->keybit); |
| 354 | __set_bit(hil_kbd_set3[i], input_dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 356 | __clear_bit(KEY_RESERVED, input_dev->keybit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Dmitry Torokhov | dd0d544 | 2009-08-05 00:30:26 -0700 | [diff] [blame] | 358 | serio_write(serio, 0); |
| 359 | serio_write(serio, 0); |
| 360 | serio_write(serio, HIL_PKT_CMD >> 8); |
| 361 | serio_write(serio, HIL_CMD_EK1); /* Enable Keyswitch Autorepeat 1 */ |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 362 | /* No need to wait for completion */ |
| 363 | |
| 364 | error = input_register_device(kbd->dev); |
| 365 | if (error) |
| 366 | goto bail1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
Matthew Wilcox | 6ab0f5c | 2005-10-21 22:58:51 -0400 | [diff] [blame] | 368 | return 0; |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 369 | |
| 370 | bail1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | serio_close(serio); |
Matthew Wilcox | d668da8 | 2006-04-03 13:44:17 +0000 | [diff] [blame] | 372 | serio_set_drvdata(serio, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | bail0: |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 374 | input_free_device(input_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | kfree(kbd); |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame^] | 376 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Matthew Wilcox | 6ab0f5c | 2005-10-21 22:58:51 -0400 | [diff] [blame] | 379 | static struct serio_device_id hil_kbd_ids[] = { |
| 380 | { |
| 381 | .type = SERIO_HIL_MLC, |
| 382 | .proto = SERIO_HIL, |
| 383 | .id = SERIO_ANY, |
| 384 | .extra = SERIO_ANY, |
| 385 | }, |
| 386 | { 0 } |
| 387 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
Helge Deller | 3acaf54 | 2007-02-28 23:51:19 -0500 | [diff] [blame] | 389 | static struct serio_driver hil_kbd_serio_drv = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | .driver = { |
| 391 | .name = "hil_kbd", |
| 392 | }, |
| 393 | .description = "HP HIL keyboard driver", |
Matthew Wilcox | 6ab0f5c | 2005-10-21 22:58:51 -0400 | [diff] [blame] | 394 | .id_table = hil_kbd_ids, |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 395 | .connect = hil_kbd_connect, |
| 396 | .disconnect = hil_kbd_disconnect, |
| 397 | .interrupt = hil_kbd_interrupt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | }; |
| 399 | |
| 400 | static int __init hil_kbd_init(void) |
| 401 | { |
Akinobu Mita | 153a9df0 | 2006-11-23 23:35:10 -0500 | [diff] [blame] | 402 | return serio_register_driver(&hil_kbd_serio_drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | } |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | static void __exit hil_kbd_exit(void) |
| 406 | { |
| 407 | serio_unregister_driver(&hil_kbd_serio_drv); |
| 408 | } |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | module_init(hil_kbd_init); |
| 411 | module_exit(hil_kbd_exit); |