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 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 52 | #define HIL_PACKET_MAX_LENGTH 16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 70 | struct hil_dev { |
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. */ |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 75 | hil_packet data[HIL_PACKET_MAX_LENGTH]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | int idx4; /* four counts per packet */ |
| 77 | |
| 78 | /* Raw device info records from HIL bus, see hil.h for fields. */ |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 79 | char idd[HIL_PACKET_MAX_LENGTH]; /* DID byte and IDD record */ |
| 80 | char rsc[HIL_PACKET_MAX_LENGTH]; /* RSC record */ |
| 81 | char exd[HIL_PACKET_MAX_LENGTH]; /* EXD record */ |
| 82 | char rnm[HIL_PACKET_MAX_LENGTH + 1]; /* RNM record + NULL term. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 87 | static bool hil_dev_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 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 98 | static void hil_dev_handle_command_response(struct hil_dev *dev) |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame] | 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 | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 104 | idx = dev->idx4 / 4; |
| 105 | p = dev->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 | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 109 | buf = dev->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 | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 113 | buf = dev->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 | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 117 | buf = dev->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 | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 121 | dev->rnm[HIL_PACKET_MAX_LENGTH] = 0; |
| 122 | buf = dev->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++) |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 135 | buf[i] = dev->data[i] & HIL_PKT_DATA_MASK; |
| 136 | for (; i < HIL_PACKET_MAX_LENGTH; i++) |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame] | 137 | buf[i] = 0; |
| 138 | out: |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 139 | complete(&dev->cmd_done); |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 142 | static void hil_dev_handle_key_events(struct hil_dev *kbd) |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame] | 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 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 201 | static void hil_dev_process_err(struct hil_dev *dev) |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 202 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | printk(KERN_WARNING PREFIX "errored HIL packet\n"); |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 204 | dev->idx4 = 0; |
| 205 | complete(&dev->cmd_done); /* just in case somebody is waiting */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 208 | static irqreturn_t hil_dev_interrupt(struct serio *serio, |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 209 | unsigned char data, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | { |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 211 | struct hil_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | hil_packet packet; |
| 213 | int idx; |
| 214 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 215 | dev = serio_get_drvdata(serio); |
| 216 | BUG_ON(dev == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 218 | if (dev->idx4 >= HIL_PACKET_MAX_LENGTH * sizeof(hil_packet)) { |
| 219 | hil_dev_process_err(dev); |
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 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 223 | idx = dev->idx4 / 4; |
| 224 | if (!(dev->idx4 % 4)) |
| 225 | dev->data[idx] = 0; |
| 226 | packet = dev->data[idx]; |
| 227 | packet |= ((hil_packet)data) << ((3 - (dev->idx4 % 4)) * 8); |
| 228 | dev->data[idx] = packet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
| 230 | /* Records of N 4-byte hil_packets must terminate with a command. */ |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 231 | if ((++dev->idx4 % 4) == 0) { |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame] | 232 | if ((packet & 0xffff0000) != HIL_ERR_INT) { |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 233 | hil_dev_process_err(dev); |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame] | 234 | } else if (packet & HIL_PKT_CMD) { |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 235 | if (hil_dev_is_command_response(packet)) |
| 236 | hil_dev_handle_command_response(dev); |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame] | 237 | else |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 238 | hil_dev_handle_key_events(dev); |
| 239 | dev->idx4 = 0; |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame] | 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 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 246 | static void hil_dev_disconnect(struct serio *serio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | { |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 248 | struct hil_dev *dev = serio_get_drvdata(serio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 250 | BUG_ON(dev == 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); |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 253 | input_unregister_device(dev->dev); |
| 254 | kfree(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 257 | static int hil_dev_connect(struct serio *serio, struct serio_driver *drv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 259 | struct hil_dev *dev; |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame] | 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 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 265 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame] | 266 | input_dev = input_allocate_device(); |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 267 | if (!dev || !input_dev) { |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame] | 268 | error = -ENOMEM; |
| 269 | goto bail0; |
| 270 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 272 | dev->serio = serio; |
| 273 | dev->dev = input_dev; |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame] | 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 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 279 | serio_set_drvdata(serio, dev); |
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 | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 282 | init_completion(&dev->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 | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 287 | error = wait_for_completion_killable(&dev->cmd_done); |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame] | 288 | if (error) |
| 289 | goto bail1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 291 | init_completion(&dev->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 | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 296 | error = wait_for_completion_killable(&dev->cmd_done); |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame] | 297 | if (error) |
| 298 | goto bail1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 300 | init_completion(&dev->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 | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 305 | error = wait_for_completion_killable(&dev->cmd_done); |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame] | 306 | if (error) |
| 307 | goto bail1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 309 | init_completion(&dev->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 | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 314 | error = wait_for_completion_killable(&dev->cmd_done); |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame] | 315 | if (error) |
| 316 | goto bail1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 318 | did = dev->idd[0]; |
| 319 | idd = dev->idd + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 343 | input_dev->name = strlen(dev->rnm) ? dev->rnm : HIL_GENERIC_NAME; |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame] | 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 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 364 | error = input_register_device(input_dev); |
Dmitry Torokhov | 6777f01 | 2009-08-07 23:17:46 -0700 | [diff] [blame] | 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); |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 375 | kfree(dev); |
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 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 379 | static struct serio_device_id hil_dev_ids[] = { |
Matthew Wilcox | 6ab0f5c | 2005-10-21 22:58:51 -0400 | [diff] [blame] | 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 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 389 | static struct serio_driver hil_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", |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 394 | .id_table = hil_dev_ids, |
| 395 | .connect = hil_dev_connect, |
| 396 | .disconnect = hil_dev_disconnect, |
| 397 | .interrupt = hil_dev_interrupt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | }; |
| 399 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 400 | static int __init hil_dev_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | { |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 402 | return serio_register_driver(&hil_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 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 405 | static void __exit hil_dev_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | { |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 407 | serio_unregister_driver(&hil_serio_drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | } |
Helge Deller | ffd51f4 | 2007-02-28 23:51:29 -0500 | [diff] [blame] | 409 | |
Dmitry Torokhov | 1437dc3 | 2009-08-07 23:17:47 -0700 | [diff] [blame^] | 410 | module_init(hil_dev_init); |
| 411 | module_exit(hil_dev_exit); |