Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: keyspan_remote - add support for loadable keymaps

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

+67 -51
+67 -51
drivers/input/misc/keyspan_remote.c
··· 46 46 47 47 #define RECV_SIZE 8 /* The UIA-11 type have a 8 byte limit. */ 48 48 49 - /* table of devices that work with this driver */ 50 - static struct usb_device_id keyspan_table[] = { 51 - { USB_DEVICE(USB_KEYSPAN_VENDOR_ID, USB_KEYSPAN_PRODUCT_UIA11) }, 52 - { } /* Terminating entry */ 53 - }; 54 - 55 - /* Structure to store all the real stuff that a remote sends to us. */ 56 - struct keyspan_message { 57 - u16 system; 58 - u8 button; 59 - u8 toggle; 60 - }; 61 - 62 - /* Structure used for all the bit testing magic needed to be done. */ 63 - struct bit_tester { 64 - u32 tester; 65 - int len; 66 - int pos; 67 - int bits_left; 68 - u8 buffer[32]; 69 - }; 70 - 71 - /* Structure to hold all of our driver specific stuff */ 72 - struct usb_keyspan { 73 - char name[128]; 74 - char phys[64]; 75 - struct usb_device* udev; 76 - struct input_dev *input; 77 - struct usb_interface* interface; 78 - struct usb_endpoint_descriptor* in_endpoint; 79 - struct urb* irq_urb; 80 - int open; 81 - dma_addr_t in_dma; 82 - unsigned char* in_buffer; 83 - 84 - /* variables used to parse messages from remote. */ 85 - struct bit_tester data; 86 - int stage; 87 - int toggle; 88 - }; 89 - 90 49 /* 91 50 * Table that maps the 31 possible keycodes to input keys. 92 51 * Currently there are 15 and 17 button models so RESERVED codes 93 52 * are blank areas in the mapping. 94 53 */ 95 - static const int keyspan_key_table[] = { 54 + static const unsigned short keyspan_key_table[] = { 96 55 KEY_RESERVED, /* 0 is just a place holder. */ 97 56 KEY_RESERVED, 98 57 KEY_STOP, ··· 84 125 KEY_KPASTERISK, 85 126 KEY_RESERVED, 86 127 KEY_MENU 128 + }; 129 + 130 + /* table of devices that work with this driver */ 131 + static struct usb_device_id keyspan_table[] = { 132 + { USB_DEVICE(USB_KEYSPAN_VENDOR_ID, USB_KEYSPAN_PRODUCT_UIA11) }, 133 + { } /* Terminating entry */ 134 + }; 135 + 136 + /* Structure to store all the real stuff that a remote sends to us. */ 137 + struct keyspan_message { 138 + u16 system; 139 + u8 button; 140 + u8 toggle; 141 + }; 142 + 143 + /* Structure used for all the bit testing magic needed to be done. */ 144 + struct bit_tester { 145 + u32 tester; 146 + int len; 147 + int pos; 148 + int bits_left; 149 + u8 buffer[32]; 150 + }; 151 + 152 + /* Structure to hold all of our driver specific stuff */ 153 + struct usb_keyspan { 154 + char name[128]; 155 + char phys[64]; 156 + unsigned short keymap[ARRAY_SIZE(keyspan_key_table)]; 157 + struct usb_device *udev; 158 + struct input_dev *input; 159 + struct usb_interface *interface; 160 + struct usb_endpoint_descriptor *in_endpoint; 161 + struct urb* irq_urb; 162 + int open; 163 + dma_addr_t in_dma; 164 + unsigned char *in_buffer; 165 + 166 + /* variables used to parse messages from remote. */ 167 + struct bit_tester data; 168 + int stage; 169 + int toggle; 87 170 }; 88 171 89 172 static struct usb_driver keyspan_driver; ··· 172 171 } 173 172 174 173 return 0; 174 + } 175 + 176 + static void keyspan_report_button(struct usb_keyspan *remote, int button, int press) 177 + { 178 + struct input_dev *input = remote->input; 179 + 180 + input_event(input, EV_MSC, MSC_SCAN, button); 181 + input_report_key(input, remote->keymap[button], press); 182 + input_sync(input); 175 183 } 176 184 177 185 /* ··· 321 311 __FUNCTION__, message.system, message.button, message.toggle); 322 312 323 313 if (message.toggle != remote->toggle) { 324 - input_report_key(remote->input, keyspan_key_table[message.button], 1); 325 - input_report_key(remote->input, keyspan_key_table[message.button], 0); 326 - input_sync(remote->input); 314 + keyspan_report_button(remote, message.button, 1); 315 + keyspan_report_button(remote, message.button, 0); 327 316 remote->toggle = message.toggle; 328 317 } 329 318 ··· 500 491 501 492 usb_make_path(udev, remote->phys, sizeof(remote->phys)); 502 493 strlcat(remote->phys, "/input0", sizeof(remote->phys)); 494 + memcpy(remote->keymap, keyspan_key_table, sizeof(remote->keymap)); 503 495 504 496 input_dev->name = remote->name; 505 497 input_dev->phys = remote->phys; 506 498 usb_to_input_id(udev, &input_dev->id); 507 499 input_dev->dev.parent = &interface->dev; 500 + input_dev->keycode = remote->keymap; 501 + input_dev->keycodesize = sizeof(unsigned short); 502 + input_dev->keycodemax = ARRAY_SIZE(remote->keymap); 508 503 509 - input_dev->evbit[0] = BIT_MASK(EV_KEY); /* We will only report KEY events. */ 504 + input_set_capability(input_dev, EV_MSC, MSC_SCAN); 505 + __set_bit(EV_KEY, input_dev->evbit); 510 506 for (i = 0; i < ARRAY_SIZE(keyspan_key_table); i++) 511 - if (keyspan_key_table[i] != KEY_RESERVED) 512 - set_bit(keyspan_key_table[i], input_dev->keybit); 507 + __set_bit(keyspan_key_table[i], input_dev->keybit); 508 + __clear_bit(KEY_RESERVED, input_dev->keybit); 513 509 514 510 input_set_drvdata(input_dev, remote); 515 511 ··· 522 508 input_dev->close = keyspan_close; 523 509 524 510 /* 525 - * Initialize the URB to access the device. The urb gets sent to the device in keyspan_open() 511 + * Initialize the URB to access the device. 512 + * The urb gets sent to the device in keyspan_open() 526 513 */ 527 514 usb_fill_int_urb(remote->irq_urb, 528 - remote->udev, usb_rcvintpipe(remote->udev, remote->in_endpoint->bEndpointAddress), 515 + remote->udev, 516 + usb_rcvintpipe(remote->udev, endpoint->bEndpointAddress), 529 517 remote->in_buffer, RECV_SIZE, keyspan_irq_recv, remote, 530 - remote->in_endpoint->bInterval); 518 + endpoint->bInterval); 531 519 remote->irq_urb->transfer_dma = remote->in_dma; 532 520 remote->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 533 521