void gcore_input_report_key(struct gcore_data *gdata, int scancode, int value) { struct input_dev *idev = gdata->input_dev; int error; struct input_keymap_entry ke = { .flags = 0, .len = sizeof(scancode), }; *((int *) ke.scancode) = scancode; error = input_get_keycode(idev, &ke); if (!error && ke.keycode != KEY_UNKNOWN && ke.keycode != KEY_RESERVED) { /* Only report mapped keys */ input_report_key(idev, ke.keycode, value); } else if (!!value) { /* Or report MSC_SCAN on keypress of an unmapped key */ input_event(idev, EV_MSC, MSC_SCAN, scancode); } } EXPORT_SYMBOL_GPL(gcore_input_report_key); void gcore_input_remove(struct gcore_data *gdata) { input_unregister_device(gdata->input_dev); kfree(gdata->input_dev->keycode); }
static int getkeycode_helper(struct input_handle *handle, void *data) { struct getset_keycode_data *d = data; d->error = input_get_keycode(handle->dev, &d->ke); return d->error == 0; /* stop as soon as we successfully get one */ }
static int g19_input_get_keycode(struct input_dev * dev, unsigned int scancode, unsigned int * keycode) { int retval; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37) struct input_keymap_entry ke = { .flags = 0, .len = sizeof(scancode), .index = scancode, .scancode = { scancode }, }; retval = input_get_keycode(dev, &ke); *keycode = ke.keycode; #else retval = input_get_keycode(dev, scancode, keycode); #endif return retval; } static void g19_led_send(struct hid_device *hdev) { struct g19_data *data = hid_get_g19data(hdev); data->led_report->field[0]->value[0] = data->led&0xFF; usbhid_submit_report(hdev, data->led_report, USB_DIR_OUT); } static void g19_screen_bl_send(struct hid_device *hdev) { struct usb_interface *intf; struct usb_device *usb_dev; struct g19_data *data = hid_get_g19data(hdev); unsigned int pipe; int i = 0; unsigned char cp[9]; cp[0] = data->screen_bl; cp[1] = 0xe2; cp[2] = 0x12; cp[3] = 0x00; cp[4] = 0x8c; cp[5] = 0x11; cp[6] = 0x00; cp[7] = 0x10; cp[8] = 0x00; intf = to_usb_interface(hdev->dev.parent); usb_dev = interface_to_usbdev(intf); pipe = usb_sndctrlpipe(usb_dev, 0x00); i = usb_control_msg(usb_dev, pipe, 0x0a, USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 0, 0, cp, sizeof(cp), 1 * HZ); if (i < 0) { dev_warn(&hdev->dev, G19_NAME " error setting LCD backlight level %d\n", i); } } static void g19_rgb_send(struct hid_device *hdev) { struct g19_data *data = hid_get_g19data(hdev); data->backlight_report->field[0]->value[0] = data->rgb[0]; data->backlight_report->field[0]->value[1] = data->rgb[1]; data->backlight_report->field[0]->value[2] = data->rgb[2]; usbhid_submit_report(hdev, data->backlight_report, USB_DIR_OUT); } static void g19_led_set(struct led_classdev *led_cdev, enum led_brightness value, int led_num) { struct device *dev; struct hid_device *hdev; struct g19_data *data; u8 mask; /* Get the device associated with the led */ dev = led_cdev->dev->parent; /* Get the hid associated with the device */ hdev = container_of(dev, struct hid_device, dev); /* Get the underlying data value */ data = hid_get_g19data(hdev); mask = 0x80>>led_num; if (value) data->led |= mask; else data->led &= ~mask; g19_led_send(hdev); } static void g19_led_m1_brightness_set(struct led_classdev *led_cdev, enum led_brightness value) { g19_led_set(led_cdev, value, G19_LED_M1); }
static int ginput_get_keycode(struct input_dev * dev, unsigned int scancode, unsigned int * keycode) { return input_get_keycode(dev, scancode, keycode); }
static int g15_input_get_keycode(struct input_dev * dev, unsigned int scancode, unsigned int * keycode) { int retval; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37) struct input_keymap_entry ke = { .flags = 0, .len = sizeof(scancode), .index = scancode, .scancode = { scancode }, }; retval = input_get_keycode(dev, &ke); *keycode = ke.keycode; #else retval = input_get_keycode(dev, scancode, keycode); #endif return retval; } static void g15_msg_send(struct hid_device *hdev, u8 msg, u8 value1, u8 value2) { struct g15_data *data = hid_get_g15data(hdev); data->led_report->field[0]->value[0] = msg; data->led_report->field[0]->value[1] = value1; data->led_report->field[0]->value[2] = value2; usbhid_submit_report(hdev, data->led_report, USB_DIR_OUT); } static void g15_led_set(struct led_classdev *led_cdev, enum led_brightness value, int led_num) { struct device *dev; struct hid_device *hdev; struct g15_data *data; u8 mask; /* Get the device associated with the led */ dev = led_cdev->dev->parent; /* Get the hid associated with the device */ hdev = container_of(dev, struct hid_device, dev); /* Get the underlying data value */ data = hid_get_g15data(hdev); mask = 0x01<<led_num; if (value) data->led |= mask; else data->led &= ~mask; g15_msg_send(hdev, 0x04, ~(data->led), 0); } static void g15_led_m1_brightness_set(struct led_classdev *led_cdev, enum led_brightness value) { g15_led_set(led_cdev, value, G15_LED_M1); }