1f6a04605STerry Lambert /* 2f6a04605STerry Lambert * HID driver for primax and similar keyboards with in-band modifiers 3f6a04605STerry Lambert * 4f6a04605STerry Lambert * Copyright 2011 Google Inc. All Rights Reserved 5f6a04605STerry Lambert * 6f6a04605STerry Lambert * Author: 7f6a04605STerry Lambert * Terry Lambert <tlambert@google.com> 8f6a04605STerry Lambert * 9f6a04605STerry Lambert * This software is licensed under the terms of the GNU General Public 10f6a04605STerry Lambert * License version 2, as published by the Free Software Foundation, and 11f6a04605STerry Lambert * may be copied, distributed, and modified under those terms. 12f6a04605STerry Lambert * 13f6a04605STerry Lambert * This program is distributed in the hope that it will be useful, 14f6a04605STerry Lambert * but WITHOUT ANY WARRANTY; without even the implied warranty of 15f6a04605STerry Lambert * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16f6a04605STerry Lambert * GNU General Public License for more details. 17f6a04605STerry Lambert */ 18f6a04605STerry Lambert 19f6a04605STerry Lambert #include <linux/device.h> 20f6a04605STerry Lambert #include <linux/hid.h> 21f6a04605STerry Lambert #include <linux/module.h> 22f6a04605STerry Lambert 23f6a04605STerry Lambert #include "hid-ids.h" 24f6a04605STerry Lambert 25f6a04605STerry Lambert static int px_raw_event(struct hid_device *hid, struct hid_report *report, 26f6a04605STerry Lambert u8 *data, int size) 27f6a04605STerry Lambert { 28f6a04605STerry Lambert int idx = size; 29f6a04605STerry Lambert 30f6a04605STerry Lambert switch (report->id) { 31f6a04605STerry Lambert case 0: /* keyboard input */ 32f6a04605STerry Lambert /* 33f6a04605STerry Lambert * Convert in-band modifier key values into out of band 34f6a04605STerry Lambert * modifier bits and pull the key strokes from the report. 35f6a04605STerry Lambert * Thus a report data set which looked like: 36f6a04605STerry Lambert * 37f6a04605STerry Lambert * [00][00][E0][30][00][00][00][00] 38f6a04605STerry Lambert * (no modifier bits + "Left Shift" key + "1" key) 39f6a04605STerry Lambert * 40f6a04605STerry Lambert * Would be converted to: 41f6a04605STerry Lambert * 42f6a04605STerry Lambert * [01][00][00][30][00][00][00][00] 43f6a04605STerry Lambert * (Left Shift modifier bit + "1" key) 44f6a04605STerry Lambert * 45f6a04605STerry Lambert * As long as it's in the size range, the upper level 46f6a04605STerry Lambert * drivers don't particularly care if there are in-band 47f6a04605STerry Lambert * 0-valued keys, so they don't stop parsing. 48f6a04605STerry Lambert */ 49f6a04605STerry Lambert while (--idx > 1) { 50f6a04605STerry Lambert if (data[idx] < 0xE0 || data[idx] > 0xE7) 51f6a04605STerry Lambert continue; 52f6a04605STerry Lambert data[0] |= (1 << (data[idx] - 0xE0)); 53f6a04605STerry Lambert data[idx] = 0; 54f6a04605STerry Lambert } 55f6a04605STerry Lambert hid_report_raw_event(hid, HID_INPUT_REPORT, data, size, 0); 56f6a04605STerry Lambert return 1; 57f6a04605STerry Lambert 58f6a04605STerry Lambert default: /* unknown report */ 59f6a04605STerry Lambert /* Unknown report type; pass upstream */ 60f6a04605STerry Lambert hid_info(hid, "unknown report type %d\n", report->id); 61f6a04605STerry Lambert break; 62f6a04605STerry Lambert } 63f6a04605STerry Lambert 64f6a04605STerry Lambert return 0; 65f6a04605STerry Lambert } 66f6a04605STerry Lambert 67f6a04605STerry Lambert static const struct hid_device_id px_devices[] = { 68f6a04605STerry Lambert { HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) }, 69f6a04605STerry Lambert { } 70f6a04605STerry Lambert }; 71f6a04605STerry Lambert MODULE_DEVICE_TABLE(hid, px_devices); 72f6a04605STerry Lambert 73f6a04605STerry Lambert static struct hid_driver px_driver = { 74f6a04605STerry Lambert .name = "primax", 75f6a04605STerry Lambert .id_table = px_devices, 76f6a04605STerry Lambert .raw_event = px_raw_event, 77f6a04605STerry Lambert }; 78f425458eSH Hartley Sweeten module_hid_driver(px_driver); 79f6a04605STerry Lambert 80f6a04605STerry Lambert MODULE_AUTHOR("Terry Lambert <tlambert@google.com>"); 81f6a04605STerry Lambert MODULE_LICENSE("GPL"); 82