Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * HID driver for primax and similar keyboards with in-band modifiers
0004  *
0005  * Copyright 2011 Google Inc. All Rights Reserved
0006  *
0007  * Author:
0008  *  Terry Lambert <tlambert@google.com>
0009  */
0010 
0011 #include <linux/device.h>
0012 #include <linux/hid.h>
0013 #include <linux/module.h>
0014 
0015 #include "hid-ids.h"
0016 
0017 static int px_raw_event(struct hid_device *hid, struct hid_report *report,
0018      u8 *data, int size)
0019 {
0020     int idx = size;
0021 
0022     switch (report->id) {
0023     case 0:     /* keyboard input */
0024         /*
0025          * Convert in-band modifier key values into out of band
0026          * modifier bits and pull the key strokes from the report.
0027          * Thus a report data set which looked like:
0028          *
0029          * [00][00][E0][30][00][00][00][00]
0030          * (no modifier bits + "Left Shift" key + "1" key)
0031          *
0032          * Would be converted to:
0033          *
0034          * [01][00][00][30][00][00][00][00]
0035          * (Left Shift modifier bit + "1" key)
0036          *
0037          * As long as it's in the size range, the upper level
0038          * drivers don't particularly care if there are in-band
0039          * 0-valued keys, so they don't stop parsing.
0040          */
0041         while (--idx > 1) {
0042             if (data[idx] < 0xE0 || data[idx] > 0xE7)
0043                 continue;
0044             data[0] |= (1 << (data[idx] - 0xE0));
0045             data[idx] = 0;
0046         }
0047         hid_report_raw_event(hid, HID_INPUT_REPORT, data, size, 0);
0048         return 1;
0049 
0050     default:    /* unknown report */
0051         /* Unknown report type; pass upstream */
0052         hid_info(hid, "unknown report type %d\n", report->id);
0053         break;
0054     }
0055 
0056     return 0;
0057 }
0058 
0059 static const struct hid_device_id px_devices[] = {
0060     { HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) },
0061     { }
0062 };
0063 MODULE_DEVICE_TABLE(hid, px_devices);
0064 
0065 static struct hid_driver px_driver = {
0066     .name = "primax",
0067     .id_table = px_devices,
0068     .raw_event = px_raw_event,
0069 };
0070 module_hid_driver(px_driver);
0071 
0072 MODULE_AUTHOR("Terry Lambert <tlambert@google.com>");
0073 MODULE_LICENSE("GPL");