^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * HID Driver for ELAN Touchpad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Currently only supports touchpad found on HP Pavilion X2 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (c) 2016 Alexandrov Stanislav <neko@nya.ai>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/input/mt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "hid-ids.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define ELAN_MT_I2C 0x5d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define ELAN_SINGLE_FINGER 0x81
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define ELAN_MT_FIRST_FINGER 0x82
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define ELAN_MT_SECOND_FINGER 0x83
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define ELAN_INPUT_REPORT_SIZE 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define ELAN_I2C_REPORT_SIZE 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define ELAN_FINGER_DATA_LEN 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define ELAN_MAX_FINGERS 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define ELAN_MAX_PRESSURE 255
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define ELAN_TP_USB_INTF 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define ELAN_FEATURE_REPORT 0x0d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define ELAN_FEATURE_SIZE 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define ELAN_PARAM_MAX_X 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define ELAN_PARAM_MAX_Y 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define ELAN_PARAM_RES 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define ELAN_MUTE_LED_REPORT 0xBC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define ELAN_LED_REPORT_SIZE 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define ELAN_HAS_LED BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct elan_drvdata {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) u8 prev_report[ELAN_INPUT_REPORT_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct led_classdev mute_led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) u8 mute_led_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) u16 max_x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) u16 max_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) u16 res_x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) u16 res_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static int is_not_elan_touchpad(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (hid_is_usb(hdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return (intf->altsetting->desc.bInterfaceNumber !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) ELAN_TP_USB_INTF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static int elan_input_mapping(struct hid_device *hdev, struct hid_input *hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct hid_field *field, struct hid_usage *usage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) unsigned long **bit, int *max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (is_not_elan_touchpad(hdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (field->report->id == ELAN_SINGLE_FINGER ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) field->report->id == ELAN_MT_FIRST_FINGER ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) field->report->id == ELAN_MT_SECOND_FINGER ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) field->report->id == ELAN_MT_I2C)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static int elan_get_device_param(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) unsigned char *dmabuf, unsigned char param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) dmabuf[0] = ELAN_FEATURE_REPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) dmabuf[1] = 0x05;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) dmabuf[2] = 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) dmabuf[3] = param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) dmabuf[4] = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) ret = hid_hw_raw_request(hdev, ELAN_FEATURE_REPORT, dmabuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) ELAN_FEATURE_SIZE, HID_FEATURE_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (ret != ELAN_FEATURE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) hid_err(hdev, "Set report error for parm %d: %d\n", param, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) ret = hid_hw_raw_request(hdev, ELAN_FEATURE_REPORT, dmabuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) ELAN_FEATURE_SIZE, HID_FEATURE_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) HID_REQ_GET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (ret != ELAN_FEATURE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) hid_err(hdev, "Get report error for parm %d: %d\n", param, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static unsigned int elan_convert_res(char val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * (value from firmware) * 10 + 790 = dpi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * dpi * 10 / 254 = dots/mm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return (val * 10 + 790) * 10 / 254;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static int elan_get_device_params(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct elan_drvdata *drvdata = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) unsigned char *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) dmabuf = kmalloc(ELAN_FEATURE_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (!dmabuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) ret = elan_get_device_param(hdev, dmabuf, ELAN_PARAM_MAX_X);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) drvdata->max_x = (dmabuf[4] << 8) | dmabuf[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) ret = elan_get_device_param(hdev, dmabuf, ELAN_PARAM_MAX_Y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) drvdata->max_y = (dmabuf[4] << 8) | dmabuf[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) ret = elan_get_device_param(hdev, dmabuf, ELAN_PARAM_RES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) drvdata->res_x = elan_convert_res(dmabuf[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) drvdata->res_y = elan_convert_res(dmabuf[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) kfree(dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static int elan_input_configured(struct hid_device *hdev, struct hid_input *hi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct elan_drvdata *drvdata = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (is_not_elan_touchpad(hdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) ret = elan_get_device_params(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) input = devm_input_allocate_device(&hdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (!input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) input->name = "Elan Touchpad";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) input->phys = hdev->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) input->uniq = hdev->uniq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) input->id.bustype = hdev->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) input->id.vendor = hdev->vendor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) input->id.product = hdev->product;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) input->id.version = hdev->version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) input->dev.parent = &hdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) input_set_abs_params(input, ABS_MT_POSITION_X, 0, drvdata->max_x,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) input_set_abs_params(input, ABS_MT_POSITION_Y, 0, drvdata->max_y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) input_set_abs_params(input, ABS_MT_PRESSURE, 0, ELAN_MAX_PRESSURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) __set_bit(BTN_LEFT, input->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) ret = input_mt_init_slots(input, ELAN_MAX_FINGERS, INPUT_MT_POINTER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) hid_err(hdev, "Failed to init elan MT slots: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) input_free_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) input_abs_set_res(input, ABS_X, drvdata->res_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) input_abs_set_res(input, ABS_Y, drvdata->res_y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) ret = input_register_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) hid_err(hdev, "Failed to register elan input device: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) input_mt_destroy_slots(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) input_free_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) drvdata->input = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static void elan_report_mt_slot(struct elan_drvdata *drvdata, u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) unsigned int slot_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct input_dev *input = drvdata->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) int x, y, p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) bool active = !!data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) input_mt_slot(input, slot_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) input_mt_report_slot_state(input, MT_TOOL_FINGER, active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) x = ((data[0] & 0xF0) << 4) | data[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) y = drvdata->max_y -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) (((data[0] & 0x07) << 8) | data[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) p = data[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) input_report_abs(input, ABS_MT_POSITION_X, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) input_report_abs(input, ABS_MT_POSITION_Y, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) input_report_abs(input, ABS_MT_PRESSURE, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static void elan_usb_report_input(struct elan_drvdata *drvdata, u8 *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct input_dev *input = drvdata->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * There is 3 types of reports: for single touch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * for multitouch - first finger and for multitouch - second finger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) * packet structure for ELAN_SINGLE_FINGER and ELAN_MT_FIRST_FINGER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * byte 1: 1 0 0 0 0 0 0 1 // 0x81 or 0x82
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * byte 2: 0 0 0 0 0 0 0 0 // looks like unused
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * byte 3: f5 f4 f3 f2 f1 0 0 L
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * byte 4: x12 x11 x10 x9 0? y11 y10 y9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * byte 5: x8 x7 x6 x5 x4 x3 x2 x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * byte 6: y8 y7 y6 y5 y4 y3 y2 y1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * byte 7: sy4 sy3 sy2 sy1 sx4 sx3 sx2 sx1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * byte 8: p8 p7 p6 p5 p4 p3 p2 p1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * packet structure for ELAN_MT_SECOND_FINGER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * byte 1: 1 0 0 0 0 0 1 1 // 0x83
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * byte 2: x12 x11 x10 x9 0 y11 y10 y9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * byte 3: x8 x7 x6 x5 x4 x3 x2 x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * byte 4: y8 y7 y6 y5 y4 y3 y2 y1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * byte 5: sy4 sy3 sy2 sy1 sx4 sx3 sx2 sx1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * byte 6: p8 p7 p6 p5 p4 p3 p2 p1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * byte 7: 0 0 0 0 0 0 0 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * byte 8: 0 0 0 0 0 0 0 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * f5-f1: finger touch bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * L: clickpad button
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * sy / sx: finger width / height expressed in traces, the total number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * of traces can be queried by doing a HID_REQ_SET_REPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * { 0x0d, 0x05, 0x03, 0x05, 0x01 } followed by a GET, in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * returned buf, buf[3]=no-x-traces, buf[4]=no-y-traces.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * p: pressure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (data[0] == ELAN_SINGLE_FINGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) for (i = 0; i < ELAN_MAX_FINGERS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (data[2] & BIT(i + 3))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) elan_report_mt_slot(drvdata, data + 3, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) elan_report_mt_slot(drvdata, NULL, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) input_report_key(input, BTN_LEFT, data[2] & 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * When touched with two fingers Elan touchpad will emit two HID reports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * first is ELAN_MT_FIRST_FINGER and second is ELAN_MT_SECOND_FINGER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * we will save ELAN_MT_FIRST_FINGER report and wait for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * ELAN_MT_SECOND_FINGER to finish multitouch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if (data[0] == ELAN_MT_FIRST_FINGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) memcpy(drvdata->prev_report, data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) sizeof(drvdata->prev_report));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (data[0] == ELAN_MT_SECOND_FINGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) int first = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) u8 *prev_report = drvdata->prev_report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) if (prev_report[0] != ELAN_MT_FIRST_FINGER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) for (i = 0; i < ELAN_MAX_FINGERS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) if (prev_report[2] & BIT(i + 3)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) if (!first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) first = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) elan_report_mt_slot(drvdata, prev_report + 3, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) elan_report_mt_slot(drvdata, data + 1, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) elan_report_mt_slot(drvdata, NULL, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) input_report_key(input, BTN_LEFT, prev_report[2] & 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) input_mt_sync_frame(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) input_sync(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static void elan_i2c_report_input(struct elan_drvdata *drvdata, u8 *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) struct input_dev *input = drvdata->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) u8 *finger_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * Elan MT touchpads in i2c mode send finger data in the same format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * as in USB mode, but then with all fingers in a single packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * packet structure for ELAN_MT_I2C:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) * byte 1: 1 0 0 1 1 1 0 1 // 0x5d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) * byte 2: f5 f4 f3 f2 f1 0 0 L
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) * byte 3: x12 x11 x10 x9 0? y11 y10 y9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) * byte 4: x8 x7 x6 x5 x4 x3 x2 x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * byte 5: y8 y7 y6 y5 y4 y3 y2 y1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) * byte 6: sy4 sy3 sy2 sy1 sx4 sx3 sx2 sx1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) * byte 7: p8 p7 p6 p5 p4 p3 p2 p1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) * byte 8-12: Same as byte 3-7 for second finger down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) * byte 13-17: Same as byte 3-7 for third finger down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) * byte 18-22: Same as byte 3-7 for fourth finger down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * byte 23-27: Same as byte 3-7 for fifth finger down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) finger_data = data + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) for (i = 0; i < ELAN_MAX_FINGERS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) if (data[1] & BIT(i + 3)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) elan_report_mt_slot(drvdata, finger_data, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) finger_data += ELAN_FINGER_DATA_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) elan_report_mt_slot(drvdata, NULL, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) input_report_key(input, BTN_LEFT, data[1] & 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) input_mt_sync_frame(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) input_sync(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) static int elan_raw_event(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) struct hid_report *report, u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) struct elan_drvdata *drvdata = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if (is_not_elan_touchpad(hdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) if (data[0] == ELAN_SINGLE_FINGER ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) data[0] == ELAN_MT_FIRST_FINGER ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) data[0] == ELAN_MT_SECOND_FINGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (size == ELAN_INPUT_REPORT_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) elan_usb_report_input(drvdata, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (data[0] == ELAN_MT_I2C && size == ELAN_I2C_REPORT_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) elan_i2c_report_input(drvdata, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) static int elan_start_multitouch(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) * This byte sequence will enable multitouch mode and disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) * mouse emulation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static const unsigned char buf[] = { 0x0D, 0x00, 0x03, 0x21, 0x00 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) unsigned char *dmabuf = kmemdup(buf, sizeof(buf), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) if (!dmabuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) ret = hid_hw_raw_request(hdev, dmabuf[0], dmabuf, sizeof(buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) kfree(dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (ret != sizeof(buf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) hid_err(hdev, "Failed to start multitouch: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) static enum led_brightness elan_mute_led_get_brigtness(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) struct device *dev = led_cdev->dev->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) struct elan_drvdata *drvdata = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) return drvdata->mute_led_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) static int elan_mute_led_set_brigtness(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) u8 led_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) struct device *dev = led_cdev->dev->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) struct elan_drvdata *drvdata = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) unsigned char *dmabuf = kzalloc(ELAN_LED_REPORT_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if (!dmabuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) led_state = !!value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) dmabuf[0] = ELAN_MUTE_LED_REPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) dmabuf[1] = 0x02;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) dmabuf[2] = led_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) ret = hid_hw_raw_request(hdev, dmabuf[0], dmabuf, ELAN_LED_REPORT_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) kfree(dmabuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) if (ret != ELAN_LED_REPORT_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) hid_err(hdev, "Failed to set mute led brightness: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) drvdata->mute_led_state = led_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) static int elan_init_mute_led(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) struct elan_drvdata *drvdata = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) struct led_classdev *mute_led = &drvdata->mute_led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) mute_led->name = "elan:red:mute";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) mute_led->brightness_get = elan_mute_led_get_brigtness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) mute_led->brightness_set_blocking = elan_mute_led_set_brigtness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) mute_led->max_brightness = LED_ON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) mute_led->dev = &hdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) return devm_led_classdev_register(&hdev->dev, mute_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) static int elan_probe(struct hid_device *hdev, const struct hid_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) struct elan_drvdata *drvdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) drvdata = devm_kzalloc(&hdev->dev, sizeof(*drvdata), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (!drvdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) hid_set_drvdata(hdev, drvdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) ret = hid_parse(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) hid_err(hdev, "Hid Parse failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) hid_err(hdev, "Hid hw start failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if (is_not_elan_touchpad(hdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) if (!drvdata->input) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) hid_err(hdev, "Input device is not registered\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) ret = -ENAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) ret = elan_start_multitouch(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) if (id->driver_data & ELAN_HAS_LED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) ret = elan_init_mute_led(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) hid_hw_stop(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) static void elan_remove(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) hid_hw_stop(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) static const struct hid_device_id elan_devices[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) { HID_USB_DEVICE(USB_VENDOR_ID_ELAN, USB_DEVICE_ID_HP_X2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) .driver_data = ELAN_HAS_LED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) { HID_USB_DEVICE(USB_VENDOR_ID_ELAN, USB_DEVICE_ID_HP_X2_10_COVER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) .driver_data = ELAN_HAS_LED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) { HID_I2C_DEVICE(USB_VENDOR_ID_ELAN, USB_DEVICE_ID_TOSHIBA_CLICK_L9W) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) MODULE_DEVICE_TABLE(hid, elan_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) static struct hid_driver elan_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) .name = "elan",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) .id_table = elan_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) .input_mapping = elan_input_mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) .input_configured = elan_input_configured,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) .raw_event = elan_raw_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) .probe = elan_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) .remove = elan_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) module_hid_driver(elan_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) MODULE_AUTHOR("Alexandrov Stanislav");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) MODULE_DESCRIPTION("Driver for HID ELAN Touchpads");