^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) * drivers/input/tablet/wacom_sys.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * USB Wacom tablet support - system specific code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "wacom_wac.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "wacom.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/input/mt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define WAC_MSG_RETRIES 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define WAC_CMD_RETRIES 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define DEV_ATTR_RW_PERM (S_IRUGO | S_IWUSR | S_IWGRP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define DEV_ATTR_WO_PERM (S_IWUSR | S_IWGRP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define DEV_ATTR_RO_PERM (S_IRUSR | S_IRGRP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static int wacom_get_report(struct hid_device *hdev, u8 type, u8 *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) size_t size, unsigned int retries)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) retval = hid_hw_raw_request(hdev, buf[0], buf, size, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) HID_REQ_GET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) } while ((retval == -ETIMEDOUT || retval == -EAGAIN) && --retries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) hid_err(hdev, "wacom_get_report: ran out of retries "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) "(last error = %d)\n", retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static int wacom_set_report(struct hid_device *hdev, u8 type, u8 *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) size_t size, unsigned int retries)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) retval = hid_hw_raw_request(hdev, buf[0], buf, size, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) } while ((retval == -ETIMEDOUT || retval == -EAGAIN) && --retries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) hid_err(hdev, "wacom_set_report: ran out of retries "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) "(last error = %d)\n", retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static void wacom_wac_queue_insert(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct kfifo_rec_ptr_2 *fifo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) u8 *raw_data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) bool warned = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) while (kfifo_avail(fifo) < size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (!warned)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) hid_warn(hdev, "%s: kfifo has filled, starting to drop events\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) warned = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) kfifo_skip(fifo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) kfifo_in(fifo, raw_data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static void wacom_wac_queue_flush(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct kfifo_rec_ptr_2 *fifo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) while (!kfifo_is_empty(fifo)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) u8 buf[WACOM_PKGLEN_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) size = kfifo_out(fifo, buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) err = hid_report_raw_event(hdev, HID_INPUT_REPORT, buf, size, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) hid_warn(hdev, "%s: unable to flush event due to error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) __func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static int wacom_wac_pen_serial_enforce(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct hid_report *report, u8 *raw_data, int report_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct wacom *wacom = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct wacom_wac *wacom_wac = &wacom->wacom_wac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct wacom_features *features = &wacom_wac->features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) bool flush = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) bool insert = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (wacom_wac->serial[0] || !(features->quirks & WACOM_QUIRK_TOOLSERIAL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /* Queue events which have invalid tool type or serial number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) for (i = 0; i < report->maxfield; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) for (j = 0; j < report->field[i]->maxusage; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct hid_field *field = report->field[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct hid_usage *usage = &field->usage[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) unsigned int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) unsigned int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) unsigned int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (equivalent_usage != HID_DG_INRANGE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) equivalent_usage != HID_DG_TOOLSERIALNUMBER &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) equivalent_usage != WACOM_HID_WD_SERIALHI &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) equivalent_usage != WACOM_HID_WD_TOOLTYPE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) offset = field->report_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) size = field->report_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) value = hid_field_extract(hdev, raw_data+1, offset + j * size, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* If we go out of range, we need to flush the queue ASAP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (equivalent_usage == HID_DG_INRANGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) value = !value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) flush = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) switch (equivalent_usage) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) case HID_DG_TOOLSERIALNUMBER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) wacom_wac->serial[0] = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) case WACOM_HID_WD_SERIALHI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) wacom_wac->serial[0] |= ((__u64)value) << 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) case WACOM_HID_WD_TOOLTYPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) wacom_wac->id[0] = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) insert = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (flush)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) wacom_wac_queue_flush(hdev, wacom_wac->pen_fifo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) else if (insert)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) wacom_wac_queue_insert(hdev, wacom_wac->pen_fifo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) raw_data, report_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return insert && !flush;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) u8 *raw_data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) struct wacom *wacom = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (size > WACOM_PKGLEN_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (wacom_wac_pen_serial_enforce(hdev, report, raw_data, size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) memcpy(wacom->wacom_wac.data, raw_data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) wacom_wac_irq(&wacom->wacom_wac, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static int wacom_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct wacom *wacom = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return hid_hw_open(wacom->hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static void wacom_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) struct wacom *wacom = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * wacom->hdev should never be null, but surprisingly, I had the case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * once while unplugging the Wacom Wireless Receiver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (wacom->hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) hid_hw_close(wacom->hdev);
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * Calculate the resolution of the X or Y axis using hidinput_calc_abs_res.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static int wacom_calc_hid_res(int logical_extents, int physical_extents,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) unsigned unit, int exponent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct hid_field field = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) .logical_maximum = logical_extents,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) .physical_maximum = physical_extents,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) .unit = unit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) .unit_exponent = exponent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) return hidinput_calc_abs_res(&field, ABS_X);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static void wacom_hid_usage_quirk(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) struct hid_field *field, struct hid_usage *usage)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct wacom *wacom = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct wacom_features *features = &wacom->wacom_wac.features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * The Dell Canvas 27 needs to be switched to its vendor-defined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * report to provide the best resolution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (hdev->vendor == USB_VENDOR_ID_WACOM &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) hdev->product == 0x4200 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) field->application == HID_UP_MSVENDOR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) wacom->wacom_wac.mode_report = field->report->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) wacom->wacom_wac.mode_value = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * ISDv4 devices which predate HID's adoption of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * HID_DG_BARELSWITCH2 usage use 0x000D0000 in its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * position instead. We can accurately detect if a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * usage with that value should be HID_DG_BARRELSWITCH2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * based on the surrounding usages, which have remained
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * constant across generations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (features->type == HID_GENERIC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) usage->hid == 0x000D0000 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) field->application == HID_DG_PEN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) field->physical == HID_DG_STYLUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) int i = usage->usage_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (i-4 >= 0 && i+1 < field->maxusage &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) field->usage[i-4].hid == HID_DG_TIPSWITCH &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) field->usage[i-3].hid == HID_DG_BARRELSWITCH &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) field->usage[i-2].hid == HID_DG_ERASER &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) field->usage[i-1].hid == HID_DG_INVERT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) field->usage[i+1].hid == HID_DG_INRANGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) usage->hid = HID_DG_BARRELSWITCH2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * Wacom's AES devices use different vendor-defined usages to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * report serial number information compared to their branded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * hardware. The usages are also sometimes ill-defined and do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * not have the correct logical min/max values set. Lets patch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * the descriptor to use the branded usage convention and fix
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * the errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (usage->hid == WACOM_HID_WT_SERIALNUMBER &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) field->report_size == 16 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) field->index + 2 < field->report->maxfield) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) struct hid_field *a = field->report->field[field->index + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct hid_field *b = field->report->field[field->index + 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (a->maxusage > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) a->usage[0].hid == HID_DG_TOOLSERIALNUMBER &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) a->report_size == 32 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) b->maxusage > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) b->usage[0].hid == 0xFF000000 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) b->report_size == 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) features->quirks |= WACOM_QUIRK_AESPEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) usage->hid = WACOM_HID_WD_TOOLTYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) field->logical_minimum = S16_MIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) field->logical_maximum = S16_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) a->logical_minimum = S32_MIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) a->logical_maximum = S32_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) b->usage[0].hid = WACOM_HID_WD_SERIALHI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) b->logical_minimum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) b->logical_maximum = U8_MAX;
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) /* 2nd-generation Intuos Pro Large has incorrect Y maximum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) if (hdev->vendor == USB_VENDOR_ID_WACOM &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) hdev->product == 0x0358 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) WACOM_PEN_FIELD(field) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) equivalent_usage == HID_GD_Y) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) field->logical_maximum = 43200;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static void wacom_feature_mapping(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) struct hid_field *field, struct hid_usage *usage)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct wacom *wacom = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct wacom_features *features = &wacom->wacom_wac.features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) struct hid_data *hid_data = &wacom->wacom_wac.hid_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) u8 *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) u32 n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) wacom_hid_usage_quirk(hdev, field, usage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) switch (equivalent_usage) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) case WACOM_HID_WD_TOUCH_RING_SETTING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) wacom->generic_has_leds = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) case HID_DG_CONTACTMAX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) /* leave touch_max as is if predefined */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (!features->touch_max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) /* read manually */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) n = hid_report_len(field->report);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) data = hid_alloc_report_buf(field->report, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) data[0] = field->report->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) ret = wacom_get_report(hdev, HID_FEATURE_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) data, n, WAC_CMD_RETRIES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (ret == n && features->type == HID_GENERIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) ret = hid_report_raw_event(hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) HID_FEATURE_REPORT, data, n, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) } else if (ret == 2 && features->type != HID_GENERIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) features->touch_max = data[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) features->touch_max = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) hid_warn(hdev, "wacom_feature_mapping: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) "could not get HID_DG_CONTACTMAX, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) "defaulting to %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) features->touch_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) case HID_DG_INPUTMODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) /* Ignore if value index is out of bounds. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if (usage->usage_index >= field->report_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) dev_err(&hdev->dev, "HID_DG_INPUTMODE out of range\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) hid_data->inputmode = field->report->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) hid_data->inputmode_index = usage->usage_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) case HID_UP_DIGITIZER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) if (field->report->id == 0x0B &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) (field->application == WACOM_HID_G9_PEN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) field->application == WACOM_HID_G11_PEN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) wacom->wacom_wac.mode_report = field->report->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) wacom->wacom_wac.mode_value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) case WACOM_HID_WD_DATAMODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) wacom->wacom_wac.mode_report = field->report->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) wacom->wacom_wac.mode_value = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) case WACOM_HID_UP_G9:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) case WACOM_HID_UP_G11:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) if (field->report->id == 0x03 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) (field->application == WACOM_HID_G9_TOUCHSCREEN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) field->application == WACOM_HID_G11_TOUCHSCREEN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) wacom->wacom_wac.mode_report = field->report->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) wacom->wacom_wac.mode_value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) case WACOM_HID_WD_OFFSETLEFT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) case WACOM_HID_WD_OFFSETTOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) case WACOM_HID_WD_OFFSETRIGHT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) case WACOM_HID_WD_OFFSETBOTTOM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) /* read manually */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) n = hid_report_len(field->report);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) data = hid_alloc_report_buf(field->report, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) data[0] = field->report->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) ret = wacom_get_report(hdev, HID_FEATURE_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) data, n, WAC_CMD_RETRIES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (ret == n) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) data, n, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) hid_warn(hdev, "%s: could not retrieve sensor offsets\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) * Interface Descriptor of wacom devices can be incomplete and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) * inconsistent so wacom_features table is used to store stylus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) * device's packet lengths, various maximum values, and tablet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) * resolution based on product ID's.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) * For devices that contain 2 interfaces, wacom_features table is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) * inaccurate for the touch interface. Since the Interface Descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) * for touch interfaces has pretty complete data, this function exists
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) * to query tablet for this missing information instead of hard coding in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) * an additional table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) * A typical Interface Descriptor for a stylus will contain a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) * boot mouse application collection that is not of interest and this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) * function will ignore it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) * It also contains a digitizer application collection that also is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) * of interest since any information it contains would be duplicate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) * of what is in wacom_features. Usually it defines a report of an array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) * of bytes that could be used as max length of the stylus packet returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) * If it happens to define a Digitizer-Stylus Physical Collection then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) * the X and Y logical values contain valid data but it is ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) * A typical Interface Descriptor for a touch interface will contain a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) * Digitizer-Finger Physical Collection which will define both logical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) * X/Y maximum as well as the physical size of tablet. Since touch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) * interfaces haven't supported pressure or distance, this is enough
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) * information to override invalid values in the wacom_features table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) * Intuos5 touch interface and 3rd gen Bamboo Touch do not contain useful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) * data. We deal with them after returning from this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static void wacom_usage_mapping(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) struct hid_field *field, struct hid_usage *usage)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) struct wacom *wacom = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) struct wacom_features *features = &wacom->wacom_wac.features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) bool finger = WACOM_FINGER_FIELD(field);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) bool pen = WACOM_PEN_FIELD(field);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) unsigned equivalent_usage = wacom_equivalent_usage(usage->hid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) * Requiring Stylus Usage will ignore boot mouse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) * X/Y values and some cases of invalid Digitizer X/Y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) * values commonly reported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (pen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) features->device_type |= WACOM_DEVICETYPE_PEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) else if (finger)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) features->device_type |= WACOM_DEVICETYPE_TOUCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) wacom_hid_usage_quirk(hdev, field, usage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) switch (equivalent_usage) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) case HID_GD_X:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) features->x_max = field->logical_maximum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) if (finger) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) features->x_phy = field->physical_maximum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) if ((features->type != BAMBOO_PT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) (features->type != BAMBOO_TOUCH)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) features->unit = field->unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) features->unitExpo = field->unit_exponent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) case HID_GD_Y:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) features->y_max = field->logical_maximum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) if (finger) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) features->y_phy = field->physical_maximum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) if ((features->type != BAMBOO_PT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) (features->type != BAMBOO_TOUCH)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) features->unit = field->unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) features->unitExpo = field->unit_exponent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) case HID_DG_TIPPRESSURE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) if (pen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) features->pressure_max = field->logical_maximum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) if (features->type == HID_GENERIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) wacom_wac_usage_mapping(hdev, field, usage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) static void wacom_post_parse_hid(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) struct wacom_features *features)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) struct wacom *wacom = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) struct wacom_wac *wacom_wac = &wacom->wacom_wac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (features->type == HID_GENERIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) /* Any last-minute generic device setup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) if (wacom_wac->has_mode_change) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) if (wacom_wac->is_direct_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) features->device_type |= WACOM_DEVICETYPE_DIRECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) features->device_type &= ~WACOM_DEVICETYPE_DIRECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) if (features->touch_max > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) if (features->device_type & WACOM_DEVICETYPE_DIRECT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) input_mt_init_slots(wacom_wac->touch_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) wacom_wac->features.touch_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) INPUT_MT_DIRECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) input_mt_init_slots(wacom_wac->touch_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) wacom_wac->features.touch_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) INPUT_MT_POINTER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) static void wacom_parse_hid(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) struct wacom_features *features)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) struct hid_report_enum *rep_enum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) struct hid_report *hreport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) /* check features first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) rep_enum = &hdev->report_enum[HID_FEATURE_REPORT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) list_for_each_entry(hreport, &rep_enum->report_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) for (i = 0; i < hreport->maxfield; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) /* Ignore if report count is out of bounds. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) if (hreport->field[i]->report_count < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) for (j = 0; j < hreport->field[i]->maxusage; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) wacom_feature_mapping(hdev, hreport->field[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) hreport->field[i]->usage + j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) }
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) /* now check the input usages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) rep_enum = &hdev->report_enum[HID_INPUT_REPORT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) list_for_each_entry(hreport, &rep_enum->report_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) if (!hreport->maxfield)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) for (i = 0; i < hreport->maxfield; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) for (j = 0; j < hreport->field[i]->maxusage; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) wacom_usage_mapping(hdev, hreport->field[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) hreport->field[i]->usage + j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) wacom_post_parse_hid(hdev, features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) static int wacom_hid_set_device_mode(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) struct wacom *wacom = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) struct hid_data *hid_data = &wacom->wacom_wac.hid_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) struct hid_report *r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) struct hid_report_enum *re;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) if (hid_data->inputmode < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) re = &(hdev->report_enum[HID_FEATURE_REPORT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) r = re->report_id_hash[hid_data->inputmode];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) r->field[0]->value[hid_data->inputmode_index] = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) hid_hw_request(hdev, r, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) static int wacom_set_device_mode(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) struct wacom_wac *wacom_wac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) u8 *rep_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) struct hid_report *r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) struct hid_report_enum *re;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) u32 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) int error = -ENOMEM, limit = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) if (wacom_wac->mode_report < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) re = &(hdev->report_enum[HID_FEATURE_REPORT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) r = re->report_id_hash[wacom_wac->mode_report];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) if (!r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) rep_data = hid_alloc_report_buf(r, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) if (!rep_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) length = hid_report_len(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) rep_data[0] = wacom_wac->mode_report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) rep_data[1] = wacom_wac->mode_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) error = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) length, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) if (error >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) error = wacom_get_report(hdev, HID_FEATURE_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) rep_data, length, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) } while (error >= 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) rep_data[1] != wacom_wac->mode_report &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) limit++ < WAC_MSG_RETRIES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) kfree(rep_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) return error < 0 ? error : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) static int wacom_bt_query_tablet_data(struct hid_device *hdev, u8 speed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) struct wacom_features *features)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) struct wacom *wacom = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) u8 rep_data[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) switch (features->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) case GRAPHIRE_BT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) rep_data[0] = 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) rep_data[1] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) if (ret >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) rep_data[0] = speed == 0 ? 0x05 : 0x06;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) rep_data[1] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) ret = wacom_set_report(hdev, HID_FEATURE_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) rep_data, 2, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) if (ret >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) wacom->wacom_wac.bt_high_speed = speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) * Note that if the raw queries fail, it's not a hard failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) * and it is safe to continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) hid_warn(hdev, "failed to poke device, command %d, err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) rep_data[0], ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) case INTUOS4WL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) if (speed == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) wacom->wacom_wac.bt_features &= ~0x20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) wacom->wacom_wac.bt_features |= 0x20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) rep_data[0] = 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) rep_data[1] = wacom->wacom_wac.bt_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) wacom->wacom_wac.bt_high_speed = speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) * Switch the tablet into its most-capable mode. Wacom tablets are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) * typically configured to power-up in a mode which sends mouse-like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) * reports to the OS. To get absolute position, pressure data, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) * from the tablet, it is necessary to switch the tablet out of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) * mode and into one which sends the full range of tablet data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) static int _wacom_query_tablet_data(struct wacom *wacom)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) struct hid_device *hdev = wacom->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) struct wacom_wac *wacom_wac = &wacom->wacom_wac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) struct wacom_features *features = &wacom_wac->features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) if (hdev->bus == BUS_BLUETOOTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) return wacom_bt_query_tablet_data(hdev, 1, features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) if (features->type != HID_GENERIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) if (features->device_type & WACOM_DEVICETYPE_TOUCH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) if (features->type > TABLETPC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) /* MT Tablet PC touch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) wacom_wac->mode_report = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) wacom_wac->mode_value = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) } else if (features->type == WACOM_24HDT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) wacom_wac->mode_report = 18;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) wacom_wac->mode_value = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) } else if (features->type == WACOM_27QHDT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) wacom_wac->mode_report = 131;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) wacom_wac->mode_value = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) } else if (features->type == BAMBOO_PAD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) wacom_wac->mode_report = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) wacom_wac->mode_value = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) } else if (features->device_type & WACOM_DEVICETYPE_PEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) if (features->type <= BAMBOO_PT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) wacom_wac->mode_report = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) wacom_wac->mode_value = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) wacom_set_device_mode(hdev, wacom_wac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) if (features->type == HID_GENERIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) return wacom_hid_set_device_mode(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) static void wacom_retrieve_hid_descriptor(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) struct wacom_features *features)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) struct wacom *wacom = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) struct usb_interface *intf = wacom->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) /* default features */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) features->x_fuzz = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) features->y_fuzz = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) features->pressure_fuzz = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) features->distance_fuzz = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) features->tilt_fuzz = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) * The wireless device HID is basic and layout conflicts with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) * other tablets (monitor and touch interface can look like pen).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) * Skip the query for this type and modify defaults based on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) * interface number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) if (features->type == WIRELESS && intf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) if (intf->cur_altsetting->desc.bInterfaceNumber == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) features->device_type = WACOM_DEVICETYPE_WL_MONITOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) features->device_type = WACOM_DEVICETYPE_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) wacom_parse_hid(hdev, features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) struct wacom_hdev_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) struct kref kref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) struct hid_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) struct wacom_shared shared;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) static LIST_HEAD(wacom_udev_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) static DEFINE_MUTEX(wacom_udev_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) static bool wacom_are_sibling(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) struct hid_device *sibling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) struct wacom *wacom = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) struct wacom_features *features = &wacom->wacom_wac.features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) struct wacom *sibling_wacom = hid_get_drvdata(sibling);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) struct wacom_features *sibling_features = &sibling_wacom->wacom_wac.features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) __u32 oVid = features->oVid ? features->oVid : hdev->vendor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) __u32 oPid = features->oPid ? features->oPid : hdev->product;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) /* The defined oVid/oPid must match that of the sibling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) if (features->oVid != HID_ANY_ID && sibling->vendor != oVid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) if (features->oPid != HID_ANY_ID && sibling->product != oPid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) * Devices with the same VID/PID must share the same physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) * device path, while those with different VID/PID must share
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) * the same physical parent device path.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) if (hdev->vendor == sibling->vendor && hdev->product == sibling->product) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) if (!hid_compare_device_paths(hdev, sibling, '/'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) if (!hid_compare_device_paths(hdev, sibling, '.'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) /* Skip the remaining heuristics unless you are a HID_GENERIC device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) if (features->type != HID_GENERIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) * Direct-input devices may not be siblings of indirect-input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) * devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) if ((features->device_type & WACOM_DEVICETYPE_DIRECT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) !(sibling_features->device_type & WACOM_DEVICETYPE_DIRECT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) * Indirect-input devices may not be siblings of direct-input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) * devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) if (!(features->device_type & WACOM_DEVICETYPE_DIRECT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) (sibling_features->device_type & WACOM_DEVICETYPE_DIRECT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) /* Pen devices may only be siblings of touch devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) if ((features->device_type & WACOM_DEVICETYPE_PEN) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) !(sibling_features->device_type & WACOM_DEVICETYPE_TOUCH))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) /* Touch devices may only be siblings of pen devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) if ((features->device_type & WACOM_DEVICETYPE_TOUCH) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) !(sibling_features->device_type & WACOM_DEVICETYPE_PEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) * No reason could be found for these two devices to NOT be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) * siblings, so there's a good chance they ARE siblings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) static struct wacom_hdev_data *wacom_get_hdev_data(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) struct wacom_hdev_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) /* Try to find an already-probed interface from the same device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) list_for_each_entry(data, &wacom_udev_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) if (hid_compare_device_paths(hdev, data->dev, '/')) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) kref_get(&data->kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) return data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) /* Fallback to finding devices that appear to be "siblings" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) list_for_each_entry(data, &wacom_udev_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) if (wacom_are_sibling(hdev, data->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) kref_get(&data->kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) return data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) static void wacom_release_shared_data(struct kref *kref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) struct wacom_hdev_data *data =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) container_of(kref, struct wacom_hdev_data, kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) mutex_lock(&wacom_udev_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) list_del(&data->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) mutex_unlock(&wacom_udev_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) static void wacom_remove_shared_data(void *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) struct wacom *wacom = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) struct wacom_hdev_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) struct wacom_wac *wacom_wac = &wacom->wacom_wac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) if (wacom_wac->shared) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) data = container_of(wacom_wac->shared, struct wacom_hdev_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) shared);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) if (wacom_wac->shared->touch == wacom->hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) wacom_wac->shared->touch = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) else if (wacom_wac->shared->pen == wacom->hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) wacom_wac->shared->pen = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) kref_put(&data->kref, wacom_release_shared_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) wacom_wac->shared = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) static int wacom_add_shared_data(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) struct wacom *wacom = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) struct wacom_wac *wacom_wac = &wacom->wacom_wac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) struct wacom_hdev_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) mutex_lock(&wacom_udev_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) data = wacom_get_hdev_data(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) if (!data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) data = kzalloc(sizeof(struct wacom_hdev_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) if (!data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) kref_init(&data->kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) data->dev = hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) list_add_tail(&data->list, &wacom_udev_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) wacom_wac->shared = &data->shared;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) retval = devm_add_action(&hdev->dev, wacom_remove_shared_data, wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) mutex_unlock(&wacom_udev_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) wacom_remove_shared_data(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) wacom_wac->shared->touch = hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) else if (wacom_wac->features.device_type & WACOM_DEVICETYPE_PEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) wacom_wac->shared->pen = hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) mutex_unlock(&wacom_udev_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) static int wacom_led_control(struct wacom *wacom)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) unsigned char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) unsigned char report_id = WAC_CMD_LED_CONTROL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) int buf_size = 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) if (!wacom->led.groups)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) return -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) if (wacom->wacom_wac.features.type == REMOTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) return -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) if (wacom->wacom_wac.pid) { /* wireless connected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) report_id = WAC_CMD_WL_LED_CONTROL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) buf_size = 13;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) else if (wacom->wacom_wac.features.type == INTUOSP2_BT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) report_id = WAC_CMD_WL_INTUOSP2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) buf_size = 51;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) buf = kzalloc(buf_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) if (wacom->wacom_wac.features.type == HID_GENERIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) buf[0] = WAC_CMD_LED_CONTROL_GENERIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) buf[1] = wacom->led.llv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) buf[2] = wacom->led.groups[0].select & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) } else if ((wacom->wacom_wac.features.type >= INTUOS5S &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) wacom->wacom_wac.features.type <= INTUOSPL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) * Touch Ring and crop mark LED luminance may take on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) * one of four values:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) * 0 = Low; 1 = Medium; 2 = High; 3 = Off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) int ring_led = wacom->led.groups[0].select & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) int ring_lum = (((wacom->led.llv & 0x60) >> 5) - 1) & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) int crop_lum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) unsigned char led_bits = (crop_lum << 4) | (ring_lum << 2) | (ring_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) buf[0] = report_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) if (wacom->wacom_wac.pid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) wacom_get_report(wacom->hdev, HID_FEATURE_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) buf, buf_size, WAC_CMD_RETRIES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) buf[0] = report_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) buf[4] = led_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) buf[1] = led_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) else if (wacom->wacom_wac.features.type == INTUOSP2_BT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) buf[0] = report_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) buf[4] = 100; // Power Connection LED (ORANGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) buf[5] = 100; // BT Connection LED (BLUE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) buf[6] = 100; // Paper Mode (RED?)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) buf[7] = 100; // Paper Mode (GREEN?)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) buf[8] = 100; // Paper Mode (BLUE?)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) buf[9] = wacom->led.llv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) buf[10] = wacom->led.groups[0].select & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) int led = wacom->led.groups[0].select | 0x4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) if (wacom->wacom_wac.features.type == WACOM_21UX2 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) wacom->wacom_wac.features.type == WACOM_24HD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) led |= (wacom->led.groups[1].select << 4) | 0x40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) buf[0] = report_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) buf[1] = led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) buf[2] = wacom->led.llv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) buf[3] = wacom->led.hlv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) buf[4] = wacom->led.img_lum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, buf_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) WAC_CMD_RETRIES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) static int wacom_led_putimage(struct wacom *wacom, int button_id, u8 xfer_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) const unsigned len, const void *img)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) unsigned char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) int i, retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) const unsigned chunk_len = len / 4; /* 4 chunks are needed to be sent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) buf = kzalloc(chunk_len + 3 , GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) /* Send 'start' command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) buf[0] = WAC_CMD_ICON_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) buf[1] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) WAC_CMD_RETRIES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) buf[0] = xfer_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) buf[1] = button_id & 0x07;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) for (i = 0; i < 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) buf[2] = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) memcpy(buf + 3, img + i * chunk_len, chunk_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) buf, chunk_len + 3, WAC_CMD_RETRIES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) /* Send 'stop' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) buf[0] = WAC_CMD_ICON_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) buf[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) WAC_CMD_RETRIES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) static ssize_t wacom_led_select_store(struct device *dev, int set_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) struct wacom *wacom = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) unsigned int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) err = kstrtouint(buf, 10, &id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) mutex_lock(&wacom->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) wacom->led.groups[set_id].select = id & 0x3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) err = wacom_led_control(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) mutex_unlock(&wacom->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) return err < 0 ? err : count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) #define DEVICE_LED_SELECT_ATTR(SET_ID) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) struct device_attribute *attr, const char *buf, size_t count) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) return wacom_led_select_store(dev, SET_ID, buf, count); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) struct device_attribute *attr, char *buf) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) struct hid_device *hdev = to_hid_device(dev);\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) struct wacom *wacom = hid_get_drvdata(hdev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) return scnprintf(buf, PAGE_SIZE, "%d\n", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) wacom->led.groups[SET_ID].select); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) static DEVICE_ATTR(status_led##SET_ID##_select, DEV_ATTR_RW_PERM, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) wacom_led##SET_ID##_select_show, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) wacom_led##SET_ID##_select_store)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) DEVICE_LED_SELECT_ATTR(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) DEVICE_LED_SELECT_ATTR(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) unsigned int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) err = kstrtouint(buf, 10, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) mutex_lock(&wacom->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) *dest = value & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) err = wacom_led_control(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) mutex_unlock(&wacom->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) return err < 0 ? err : count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) #define DEVICE_LUMINANCE_ATTR(name, field) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) static ssize_t wacom_##name##_luminance_store(struct device *dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) struct device_attribute *attr, const char *buf, size_t count) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) struct hid_device *hdev = to_hid_device(dev);\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) struct wacom *wacom = hid_get_drvdata(hdev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) return wacom_luminance_store(wacom, &wacom->led.field, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) buf, count); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) static ssize_t wacom_##name##_luminance_show(struct device *dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) struct device_attribute *attr, char *buf) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) struct wacom *wacom = dev_get_drvdata(dev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) return scnprintf(buf, PAGE_SIZE, "%d\n", wacom->led.field); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) static DEVICE_ATTR(name##_luminance, DEV_ATTR_RW_PERM, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) wacom_##name##_luminance_show, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) wacom_##name##_luminance_store)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) DEVICE_LUMINANCE_ATTR(status0, llv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) DEVICE_LUMINANCE_ATTR(status1, hlv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) DEVICE_LUMINANCE_ATTR(buttons, img_lum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) static ssize_t wacom_button_image_store(struct device *dev, int button_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) struct wacom *wacom = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) unsigned len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) u8 xfer_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) if (hdev->bus == BUS_BLUETOOTH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) len = 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) xfer_id = WAC_CMD_ICON_BT_XFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) len = 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) xfer_id = WAC_CMD_ICON_XFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) if (count != len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) mutex_lock(&wacom->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) err = wacom_led_putimage(wacom, button_id, xfer_id, len, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) mutex_unlock(&wacom->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) return err < 0 ? err : count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) struct device_attribute *attr, const char *buf, size_t count) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) static DEVICE_ATTR(button##BUTTON_ID##_rawimg, DEV_ATTR_WO_PERM, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) NULL, wacom_btnimg##BUTTON_ID##_store)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) DEVICE_BTNIMG_ATTR(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) DEVICE_BTNIMG_ATTR(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) DEVICE_BTNIMG_ATTR(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) DEVICE_BTNIMG_ATTR(3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) DEVICE_BTNIMG_ATTR(4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) DEVICE_BTNIMG_ATTR(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) DEVICE_BTNIMG_ATTR(6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) DEVICE_BTNIMG_ATTR(7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) static struct attribute *cintiq_led_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) &dev_attr_status_led0_select.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) &dev_attr_status_led1_select.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) static struct attribute_group cintiq_led_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) .name = "wacom_led",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) .attrs = cintiq_led_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) static struct attribute *intuos4_led_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) &dev_attr_status0_luminance.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) &dev_attr_status1_luminance.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) &dev_attr_status_led0_select.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) &dev_attr_buttons_luminance.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) &dev_attr_button0_rawimg.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) &dev_attr_button1_rawimg.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) &dev_attr_button2_rawimg.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) &dev_attr_button3_rawimg.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) &dev_attr_button4_rawimg.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) &dev_attr_button5_rawimg.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) &dev_attr_button6_rawimg.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) &dev_attr_button7_rawimg.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) static struct attribute_group intuos4_led_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) .name = "wacom_led",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) .attrs = intuos4_led_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) static struct attribute *intuos5_led_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) &dev_attr_status0_luminance.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) &dev_attr_status_led0_select.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) static struct attribute_group intuos5_led_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) .name = "wacom_led",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) .attrs = intuos5_led_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) static struct attribute *generic_led_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) &dev_attr_status0_luminance.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) &dev_attr_status_led0_select.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) static struct attribute_group generic_led_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) .name = "wacom_led",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) .attrs = generic_led_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) struct wacom_sysfs_group_devres {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) struct attribute_group *group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) struct kobject *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) static void wacom_devm_sysfs_group_release(struct device *dev, void *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) struct wacom_sysfs_group_devres *devres = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) struct kobject *kobj = devres->root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) dev_dbg(dev, "%s: dropping reference to %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) __func__, devres->group->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) sysfs_remove_group(kobj, devres->group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) static int __wacom_devm_sysfs_create_group(struct wacom *wacom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) struct kobject *root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) struct attribute_group *group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) struct wacom_sysfs_group_devres *devres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) devres = devres_alloc(wacom_devm_sysfs_group_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) sizeof(struct wacom_sysfs_group_devres),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) if (!devres)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) devres->group = group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) devres->root = root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) error = sysfs_create_group(devres->root, group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) devres_free(devres);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) devres_add(&wacom->hdev->dev, devres);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) static int wacom_devm_sysfs_create_group(struct wacom *wacom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) struct attribute_group *group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) return __wacom_devm_sysfs_create_group(wacom, &wacom->hdev->dev.kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) static void wacom_devm_kfifo_release(struct device *dev, void *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) struct kfifo_rec_ptr_2 *devres = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) kfifo_free(devres);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) static int wacom_devm_kfifo_alloc(struct wacom *wacom)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) struct wacom_wac *wacom_wac = &wacom->wacom_wac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) struct kfifo_rec_ptr_2 *pen_fifo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) pen_fifo = devres_alloc(wacom_devm_kfifo_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) sizeof(struct kfifo_rec_ptr_2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) if (!pen_fifo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) error = kfifo_alloc(pen_fifo, WACOM_PKGLEN_MAX, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) devres_free(pen_fifo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) devres_add(&wacom->hdev->dev, pen_fifo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) wacom_wac->pen_fifo = pen_fifo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) enum led_brightness wacom_leds_brightness_get(struct wacom_led *led)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) struct wacom *wacom = led->wacom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) if (wacom->led.max_hlv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) return led->hlv * LED_FULL / wacom->led.max_hlv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) if (wacom->led.max_llv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) return led->llv * LED_FULL / wacom->led.max_llv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) /* device doesn't support brightness tuning */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) return LED_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) static enum led_brightness __wacom_led_brightness_get(struct led_classdev *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) struct wacom_led *led = container_of(cdev, struct wacom_led, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) struct wacom *wacom = led->wacom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) if (wacom->led.groups[led->group].select != led->id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) return LED_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) return wacom_leds_brightness_get(led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) static int wacom_led_brightness_set(struct led_classdev *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) enum led_brightness brightness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) struct wacom_led *led = container_of(cdev, struct wacom_led, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) struct wacom *wacom = led->wacom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) mutex_lock(&wacom->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) if (!wacom->led.groups || (brightness == LED_OFF &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) wacom->led.groups[led->group].select != led->id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) led->llv = wacom->led.llv = wacom->led.max_llv * brightness / LED_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) led->hlv = wacom->led.hlv = wacom->led.max_hlv * brightness / LED_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) wacom->led.groups[led->group].select = led->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) error = wacom_led_control(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) mutex_unlock(&wacom->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) static void wacom_led_readonly_brightness_set(struct led_classdev *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) enum led_brightness brightness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) static int wacom_led_register_one(struct device *dev, struct wacom *wacom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) struct wacom_led *led, unsigned int group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) unsigned int id, bool read_only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) name = devm_kasprintf(dev, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) "%s::wacom-%d.%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) dev_name(dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) if (!name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) if (!read_only) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) led->trigger.name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) error = devm_led_trigger_register(dev, &led->trigger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) hid_err(wacom->hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) "failed to register LED trigger %s: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) led->cdev.name, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) led->group = group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) led->id = id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) led->wacom = wacom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) led->llv = wacom->led.llv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) led->hlv = wacom->led.hlv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) led->cdev.name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) led->cdev.max_brightness = LED_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) led->cdev.flags = LED_HW_PLUGGABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) led->cdev.brightness_get = __wacom_led_brightness_get;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) if (!read_only) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) led->cdev.brightness_set_blocking = wacom_led_brightness_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) led->cdev.default_trigger = led->cdev.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) led->cdev.brightness_set = wacom_led_readonly_brightness_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) error = devm_led_classdev_register(dev, &led->cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) hid_err(wacom->hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) "failed to register LED %s: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) led->cdev.name, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) led->cdev.name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) static void wacom_led_groups_release_one(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) struct wacom_group_leds *group = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) devres_release_group(group->dev, group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) static int wacom_led_groups_alloc_and_register_one(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) struct wacom *wacom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) int group_id, int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) bool read_only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) struct wacom_led *leds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) int i, error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) if (group_id >= wacom->led.count || count <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) if (!devres_open_group(dev, &wacom->led.groups[group_id], GFP_KERNEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) leds = devm_kcalloc(dev, count, sizeof(struct wacom_led), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) if (!leds) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) wacom->led.groups[group_id].leds = leds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) wacom->led.groups[group_id].count = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) error = wacom_led_register_one(dev, wacom, &leds[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) group_id, i, read_only);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) wacom->led.groups[group_id].dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) devres_close_group(dev, &wacom->led.groups[group_id]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) * There is a bug (?) in devm_led_classdev_register() in which its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) * increments the refcount of the parent. If the parent is an input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) * device, that means the ref count never reaches 0 when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) * devm_input_device_release() gets called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) * This means that the LEDs are still there after disconnect.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) * Manually force the release of the group so that the leds are released
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) * once we are done using them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) error = devm_add_action_or_reset(&wacom->hdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) wacom_led_groups_release_one,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) &wacom->led.groups[group_id]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) devres_release_group(dev, &wacom->led.groups[group_id]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) struct wacom_led *wacom_led_find(struct wacom *wacom, unsigned int group_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) unsigned int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) struct wacom_group_leds *group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) if (group_id >= wacom->led.count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) group = &wacom->led.groups[group_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) if (!group->leds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) id %= group->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) return &group->leds[id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) * wacom_led_next: gives the next available led with a wacom trigger.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) * returns the next available struct wacom_led which has its default trigger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) * or the current one if none is available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) struct wacom_led *wacom_led_next(struct wacom *wacom, struct wacom_led *cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) struct wacom_led *next_led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) int group, next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) if (!wacom || !cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) group = cur->group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) next = cur->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) next_led = wacom_led_find(wacom, group, ++next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) if (!next_led || next_led == cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) return next_led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) } while (next_led->cdev.trigger != &next_led->trigger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) return next_led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) static void wacom_led_groups_release(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) struct wacom *wacom = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) wacom->led.groups = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) wacom->led.count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) static int wacom_led_groups_allocate(struct wacom *wacom, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) struct device *dev = &wacom->hdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) struct wacom_group_leds *groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) groups = devm_kcalloc(dev, count, sizeof(struct wacom_group_leds),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) if (!groups)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) error = devm_add_action_or_reset(dev, wacom_led_groups_release, wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) wacom->led.groups = groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) wacom->led.count = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) static int wacom_leds_alloc_and_register(struct wacom *wacom, int group_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) int led_per_group, bool read_only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) int i, error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) if (!wacom->wacom_wac.pad_input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) dev = &wacom->wacom_wac.pad_input->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) error = wacom_led_groups_allocate(wacom, group_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) for (i = 0; i < group_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) error = wacom_led_groups_alloc_and_register_one(dev, wacom, i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) led_per_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) read_only);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) int wacom_initialize_leds(struct wacom *wacom)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) if (!(wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) /* Initialize default values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) switch (wacom->wacom_wac.features.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) case HID_GENERIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) if (!wacom->generic_has_leds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) wacom->led.llv = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) wacom->led.max_llv = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) error = wacom_leds_alloc_and_register(wacom, 1, 4, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) hid_err(wacom->hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) "cannot create leds err: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) error = wacom_devm_sysfs_create_group(wacom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) &generic_led_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) case INTUOS4S:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) case INTUOS4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) case INTUOS4WL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) case INTUOS4L:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) wacom->led.llv = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) wacom->led.hlv = 20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) wacom->led.max_llv = 127;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) wacom->led.max_hlv = 127;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) wacom->led.img_lum = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) error = wacom_leds_alloc_and_register(wacom, 1, 4, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) hid_err(wacom->hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) "cannot create leds err: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) error = wacom_devm_sysfs_create_group(wacom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) &intuos4_led_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) case WACOM_24HD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) case WACOM_21UX2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) wacom->led.llv = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) wacom->led.hlv = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) wacom->led.img_lum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) error = wacom_leds_alloc_and_register(wacom, 2, 4, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) hid_err(wacom->hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) "cannot create leds err: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) error = wacom_devm_sysfs_create_group(wacom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) &cintiq_led_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) case INTUOS5S:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) case INTUOS5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) case INTUOS5L:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) case INTUOSPS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) case INTUOSPM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) case INTUOSPL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) wacom->led.llv = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) wacom->led.max_llv = 96;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) error = wacom_leds_alloc_and_register(wacom, 1, 4, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) hid_err(wacom->hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) "cannot create leds err: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) error = wacom_devm_sysfs_create_group(wacom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) &intuos5_led_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) case INTUOSP2_BT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) wacom->led.llv = 50;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) wacom->led.max_llv = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) error = wacom_leds_alloc_and_register(wacom, 1, 4, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) hid_err(wacom->hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) "cannot create leds err: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) case REMOTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) wacom->led.llv = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) wacom->led.max_llv = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) error = wacom_led_groups_allocate(wacom, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) hid_err(wacom->hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) "cannot create leds err: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) hid_err(wacom->hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) "cannot create sysfs group err: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) static void wacom_init_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) struct wacom *wacom = container_of(work, struct wacom, init_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) _wacom_query_tablet_data(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) wacom_led_control(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) static void wacom_query_tablet_data(struct wacom *wacom)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) schedule_delayed_work(&wacom->init_work, msecs_to_jiffies(1000));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) static enum power_supply_property wacom_battery_props[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) POWER_SUPPLY_PROP_MODEL_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) POWER_SUPPLY_PROP_PRESENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) POWER_SUPPLY_PROP_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) POWER_SUPPLY_PROP_SCOPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) POWER_SUPPLY_PROP_CAPACITY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) static int wacom_battery_get_property(struct power_supply *psy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) enum power_supply_property psp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) union power_supply_propval *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) struct wacom_battery *battery = power_supply_get_drvdata(psy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) switch (psp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) case POWER_SUPPLY_PROP_MODEL_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) val->strval = battery->wacom->wacom_wac.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) case POWER_SUPPLY_PROP_PRESENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) val->intval = battery->bat_connected;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) case POWER_SUPPLY_PROP_SCOPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) val->intval = POWER_SUPPLY_SCOPE_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) case POWER_SUPPLY_PROP_CAPACITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) val->intval = battery->battery_capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) case POWER_SUPPLY_PROP_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) if (battery->bat_status != WACOM_POWER_SUPPLY_STATUS_AUTO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) val->intval = battery->bat_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) else if (battery->bat_charging)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) val->intval = POWER_SUPPLY_STATUS_CHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) else if (battery->battery_capacity == 100 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) battery->ps_connected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) val->intval = POWER_SUPPLY_STATUS_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) else if (battery->ps_connected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) static int __wacom_initialize_battery(struct wacom *wacom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) struct wacom_battery *battery)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) static atomic_t battery_no = ATOMIC_INIT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) struct device *dev = &wacom->hdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) struct power_supply_config psy_cfg = { .drv_data = battery, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) struct power_supply *ps_bat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) struct power_supply_desc *bat_desc = &battery->bat_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) unsigned long n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) if (!devres_open_group(dev, bat_desc, GFP_KERNEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) battery->wacom = wacom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) n = atomic_inc_return(&battery_no) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) bat_desc->properties = wacom_battery_props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) bat_desc->num_properties = ARRAY_SIZE(wacom_battery_props);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) bat_desc->get_property = wacom_battery_get_property;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) sprintf(battery->bat_name, "wacom_battery_%ld", n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) bat_desc->name = battery->bat_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) bat_desc->type = POWER_SUPPLY_TYPE_USB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) bat_desc->use_for_apm = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) ps_bat = devm_power_supply_register(dev, bat_desc, &psy_cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) if (IS_ERR(ps_bat)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) error = PTR_ERR(ps_bat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) power_supply_powers(ps_bat, &wacom->hdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) battery->battery = ps_bat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) devres_close_group(dev, bat_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) devres_release_group(dev, bat_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) static int wacom_initialize_battery(struct wacom *wacom)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) return __wacom_initialize_battery(wacom, &wacom->battery);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) static void wacom_destroy_battery(struct wacom *wacom)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) if (wacom->battery.battery) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) devres_release_group(&wacom->hdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) &wacom->battery.bat_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) wacom->battery.battery = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) static ssize_t wacom_show_speed(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) struct device_attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) struct wacom *wacom = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) return snprintf(buf, PAGE_SIZE, "%i\n", wacom->wacom_wac.bt_high_speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) static ssize_t wacom_store_speed(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) struct wacom *wacom = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) u8 new_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) if (kstrtou8(buf, 0, &new_speed))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) if (new_speed != 0 && new_speed != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) wacom_bt_query_tablet_data(hdev, new_speed, &wacom->wacom_wac.features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) static DEVICE_ATTR(speed, DEV_ATTR_RW_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) wacom_show_speed, wacom_store_speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) static ssize_t wacom_show_remote_mode(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) struct kobj_attribute *kattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) char *buf, int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) struct device *dev = kobj_to_dev(kobj->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) struct wacom *wacom = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) u8 mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) mode = wacom->led.groups[index].select;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) return sprintf(buf, "%d\n", mode < 3 ? mode : -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) #define DEVICE_EKR_ATTR_GROUP(SET_ID) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) static ssize_t wacom_show_remote##SET_ID##_mode(struct kobject *kobj, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) struct kobj_attribute *kattr, char *buf) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) return wacom_show_remote_mode(kobj, kattr, buf, SET_ID); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) static struct kobj_attribute remote##SET_ID##_mode_attr = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) .attr = {.name = "remote_mode", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) .mode = DEV_ATTR_RO_PERM}, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) .show = wacom_show_remote##SET_ID##_mode, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) }; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) static struct attribute *remote##SET_ID##_serial_attrs[] = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) &remote##SET_ID##_mode_attr.attr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) NULL \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) }; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) static struct attribute_group remote##SET_ID##_serial_group = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) .name = NULL, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) .attrs = remote##SET_ID##_serial_attrs, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) DEVICE_EKR_ATTR_GROUP(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) DEVICE_EKR_ATTR_GROUP(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) DEVICE_EKR_ATTR_GROUP(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) DEVICE_EKR_ATTR_GROUP(3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) DEVICE_EKR_ATTR_GROUP(4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) static int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) struct wacom_remote *remote = wacom->remote;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) remote->remotes[index].group.name = devm_kasprintf(&wacom->hdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) "%d", serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) if (!remote->remotes[index].group.name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) error = __wacom_devm_sysfs_create_group(wacom, remote->remote_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) &remote->remotes[index].group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) remote->remotes[index].group.name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) hid_err(wacom->hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) "cannot create sysfs group err: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) static int wacom_cmd_unpair_remote(struct wacom *wacom, unsigned char selector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) const size_t buf_size = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) unsigned char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) buf = kzalloc(buf_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) buf[0] = WAC_CMD_DELETE_PAIRING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) buf[1] = selector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) retval = wacom_set_report(wacom->hdev, HID_OUTPUT_REPORT, buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) buf_size, WAC_CMD_RETRIES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) static ssize_t wacom_store_unpair_remote(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) struct kobj_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) unsigned char selector = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) struct device *dev = kobj_to_dev(kobj->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) struct hid_device *hdev = to_hid_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) struct wacom *wacom = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) if (!strncmp(buf, "*\n", 2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) selector = WAC_CMD_UNPAIR_ALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) hid_info(wacom->hdev, "remote: unrecognized unpair code: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) mutex_lock(&wacom->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) err = wacom_cmd_unpair_remote(wacom, selector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) mutex_unlock(&wacom->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) return err < 0 ? err : count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) static struct kobj_attribute unpair_remote_attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) .attr = {.name = "unpair_remote", .mode = 0200},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) .store = wacom_store_unpair_remote,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) static const struct attribute *remote_unpair_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) &unpair_remote_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) static void wacom_remotes_destroy(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) struct wacom *wacom = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) struct wacom_remote *remote = wacom->remote;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) if (!remote)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) kobject_put(remote->remote_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) kfifo_free(&remote->remote_fifo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) wacom->remote = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) static int wacom_initialize_remotes(struct wacom *wacom)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) struct wacom_remote *remote;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) if (wacom->wacom_wac.features.type != REMOTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) remote = devm_kzalloc(&wacom->hdev->dev, sizeof(*wacom->remote),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) if (!remote)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) wacom->remote = remote;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) spin_lock_init(&remote->remote_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) error = kfifo_alloc(&remote->remote_fifo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) 5 * sizeof(struct wacom_remote_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) hid_err(wacom->hdev, "failed allocating remote_fifo\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) remote->remotes[0].group = remote0_serial_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) remote->remotes[1].group = remote1_serial_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) remote->remotes[2].group = remote2_serial_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) remote->remotes[3].group = remote3_serial_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) remote->remotes[4].group = remote4_serial_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) remote->remote_dir = kobject_create_and_add("wacom_remote",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) &wacom->hdev->dev.kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) if (!remote->remote_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) error = sysfs_create_files(remote->remote_dir, remote_unpair_attrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) hid_err(wacom->hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) "cannot create sysfs group err: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) for (i = 0; i < WACOM_MAX_REMOTES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) remote->remotes[i].serial = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) error = devm_add_action_or_reset(&wacom->hdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) wacom_remotes_destroy, wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) static struct input_dev *wacom_allocate_input(struct wacom *wacom)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) struct hid_device *hdev = wacom->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) input_dev = devm_input_allocate_device(&hdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) if (!input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) input_dev->name = wacom_wac->features.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) input_dev->phys = hdev->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) input_dev->dev.parent = &hdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) input_dev->open = wacom_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) input_dev->close = wacom_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) input_dev->uniq = hdev->uniq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) input_dev->id.bustype = hdev->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) input_dev->id.vendor = hdev->vendor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) input_dev->id.product = wacom_wac->pid ? wacom_wac->pid : hdev->product;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) input_dev->id.version = hdev->version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) input_set_drvdata(input_dev, wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) return input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) static int wacom_allocate_inputs(struct wacom *wacom)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) wacom_wac->pen_input = wacom_allocate_input(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) wacom_wac->touch_input = wacom_allocate_input(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) wacom_wac->pad_input = wacom_allocate_input(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) if (!wacom_wac->pen_input ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) !wacom_wac->touch_input ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) !wacom_wac->pad_input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) wacom_wac->pen_input->name = wacom_wac->pen_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) wacom_wac->touch_input->name = wacom_wac->touch_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) wacom_wac->pad_input->name = wacom_wac->pad_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) static int wacom_register_inputs(struct wacom *wacom)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) struct input_dev *pen_input_dev, *touch_input_dev, *pad_input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) pen_input_dev = wacom_wac->pen_input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) touch_input_dev = wacom_wac->touch_input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) pad_input_dev = wacom_wac->pad_input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) if (!pen_input_dev || !touch_input_dev || !pad_input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) error = wacom_setup_pen_input_capabilities(pen_input_dev, wacom_wac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) /* no pen in use on this interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) input_free_device(pen_input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) wacom_wac->pen_input = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) pen_input_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) error = input_register_device(pen_input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) error = wacom_setup_touch_input_capabilities(touch_input_dev, wacom_wac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) /* no touch in use on this interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) input_free_device(touch_input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) wacom_wac->touch_input = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) touch_input_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) error = input_register_device(touch_input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) error = wacom_setup_pad_input_capabilities(pad_input_dev, wacom_wac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) /* no pad in use on this interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) input_free_device(pad_input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) wacom_wac->pad_input = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) pad_input_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) error = input_register_device(pad_input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) wacom_wac->pad_input = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) wacom_wac->touch_input = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) wacom_wac->pen_input = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) * Not all devices report physical dimensions from HID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) * Compute the default from hardcoded logical dimension
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) * and resolution before driver overwrites them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) static void wacom_set_default_phy(struct wacom_features *features)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) if (features->x_resolution) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) features->x_phy = (features->x_max * 100) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) features->x_resolution;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) features->y_phy = (features->y_max * 100) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) features->y_resolution;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) static void wacom_calculate_res(struct wacom_features *features)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) /* set unit to "100th of a mm" for devices not reported by HID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) if (!features->unit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) features->unit = 0x11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) features->unitExpo = -3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) features->x_resolution = wacom_calc_hid_res(features->x_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) features->x_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) features->unit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) features->unitExpo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) features->y_resolution = wacom_calc_hid_res(features->y_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) features->y_phy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) features->unit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) features->unitExpo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) void wacom_battery_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) struct wacom *wacom = container_of(work, struct wacom, battery_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) !wacom->battery.battery) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) wacom_initialize_battery(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) else if (!(wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) wacom->battery.battery) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) wacom_destroy_battery(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) static size_t wacom_compute_pktlen(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) struct hid_report_enum *report_enum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) struct hid_report *report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) size_t size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) report_enum = hdev->report_enum + HID_INPUT_REPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) list_for_each_entry(report, &report_enum->report_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) size_t report_size = hid_report_len(report);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) if (report_size > size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) size = report_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) static void wacom_update_name(struct wacom *wacom, const char *suffix)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) struct wacom_wac *wacom_wac = &wacom->wacom_wac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) struct wacom_features *features = &wacom_wac->features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) char name[WACOM_NAME_MAX - 20]; /* Leave some room for suffixes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) /* Generic devices name unspecified */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) if ((features->type == HID_GENERIC) && !strcmp("Wacom HID", features->name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) char *product_name = wacom->hdev->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) if (hid_is_usb(wacom->hdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) struct usb_interface *intf = to_usb_interface(wacom->hdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) struct usb_device *dev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) product_name = dev->product;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) if (wacom->hdev->bus == BUS_I2C) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) snprintf(name, sizeof(name), "%s %X",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) features->name, wacom->hdev->product);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) } else if (strstr(product_name, "Wacom") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) strstr(product_name, "wacom") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) strstr(product_name, "WACOM")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) strlcpy(name, product_name, sizeof(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) snprintf(name, sizeof(name), "Wacom %s", product_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) /* strip out excess whitespaces */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) char *gap = strstr(name, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) if (gap == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) /* shift everything including the terminator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) memmove(gap, gap+1, strlen(gap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) /* get rid of trailing whitespace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) if (name[strlen(name)-1] == ' ')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) name[strlen(name)-1] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) strlcpy(name, features->name, sizeof(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) snprintf(wacom_wac->name, sizeof(wacom_wac->name), "%s%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) name, suffix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) /* Append the device type to the name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) snprintf(wacom_wac->pen_name, sizeof(wacom_wac->pen_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) "%s%s Pen", name, suffix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) snprintf(wacom_wac->touch_name, sizeof(wacom_wac->touch_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) "%s%s Finger", name, suffix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) "%s%s Pad", name, suffix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) static void wacom_release_resources(struct wacom *wacom)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) struct hid_device *hdev = wacom->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) if (!wacom->resources)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) devres_release_group(&hdev->dev, wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) wacom->resources = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) wacom->wacom_wac.pen_input = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) wacom->wacom_wac.touch_input = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) wacom->wacom_wac.pad_input = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) static void wacom_set_shared_values(struct wacom_wac *wacom_wac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) wacom_wac->shared->type = wacom_wac->features.type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) wacom_wac->shared->touch_input = wacom_wac->touch_input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) if (wacom_wac->has_mute_touch_switch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) wacom_wac->shared->has_mute_touch_switch = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) wacom_wac->shared->is_touch_on = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) if (wacom_wac->shared->has_mute_touch_switch &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) wacom_wac->shared->touch_input) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) set_bit(EV_SW, wacom_wac->shared->touch_input->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) input_set_capability(wacom_wac->shared->touch_input, EV_SW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) SW_MUTE_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) static int wacom_parse_and_register(struct wacom *wacom, bool wireless)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) struct wacom_wac *wacom_wac = &wacom->wacom_wac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) struct wacom_features *features = &wacom_wac->features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) struct hid_device *hdev = wacom->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) unsigned int connect_mask = HID_CONNECT_HIDRAW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) features->pktlen = wacom_compute_pktlen(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) if (features->pktlen > WACOM_PKGLEN_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) if (!devres_open_group(&hdev->dev, wacom, GFP_KERNEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) wacom->resources = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) error = wacom_allocate_inputs(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) * Bamboo Pad has a generic hid handling for the Pen, and we switch it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) * into debug mode for the touch part.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) * We ignore the other interfaces.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) if (features->type == BAMBOO_PAD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) if (features->pktlen == WACOM_PKGLEN_PENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) features->type = HID_GENERIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) } else if ((features->pktlen != WACOM_PKGLEN_BPAD_TOUCH) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) (features->pktlen != WACOM_PKGLEN_BPAD_TOUCH_USB)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) error = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) /* set the default size in case we do not get them from hid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) wacom_set_default_phy(features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) /* Retrieve the physical and logical size for touch devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) wacom_retrieve_hid_descriptor(hdev, features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) wacom_setup_device_quirks(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) if (features->device_type == WACOM_DEVICETYPE_NONE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) features->type != WIRELESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) error = features->type == HID_GENERIC ? -ENODEV : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) dev_warn(&hdev->dev, "Unknown device_type for '%s'. %s.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) hdev->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) error ? "Ignoring" : "Assuming pen");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) features->device_type |= WACOM_DEVICETYPE_PEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) wacom_calculate_res(features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) wacom_update_name(wacom, wireless ? " (WL)" : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) /* pen only Bamboo neither support touch nor pad */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) if ((features->type == BAMBOO_PEN) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) ((features->device_type & WACOM_DEVICETYPE_TOUCH) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) (features->device_type & WACOM_DEVICETYPE_PAD))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) error = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) error = wacom_add_shared_data(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) if (!(features->device_type & WACOM_DEVICETYPE_WL_MONITOR) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) (features->quirks & WACOM_QUIRK_BATTERY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) error = wacom_initialize_battery(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) error = wacom_register_inputs(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) if (wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PAD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) error = wacom_initialize_leds(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) error = wacom_initialize_remotes(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) if (features->type == HID_GENERIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) connect_mask |= HID_CONNECT_DRIVER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) /* Regular HID work starts now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) error = hid_hw_start(hdev, connect_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) hid_err(hdev, "hw start failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) if (!wireless) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) /* Note that if query fails it is not a hard failure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) wacom_query_tablet_data(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) /* touch only Bamboo doesn't support pen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) if ((features->type == BAMBOO_TOUCH) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) (features->device_type & WACOM_DEVICETYPE_PEN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) cancel_delayed_work_sync(&wacom->init_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) _wacom_query_tablet_data(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) error = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) goto fail_quirks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) error = hid_hw_open(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) wacom_set_shared_values(wacom_wac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) devres_close_group(&hdev->dev, wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) fail_quirks:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) hid_hw_stop(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) wacom_release_resources(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) static void wacom_wireless_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) struct wacom *wacom = container_of(work, struct wacom, wireless_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) struct usb_device *usbdev = wacom->usbdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) struct wacom_wac *wacom_wac = &wacom->wacom_wac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) struct hid_device *hdev1, *hdev2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) struct wacom *wacom1, *wacom2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) struct wacom_wac *wacom_wac1, *wacom_wac2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) * Regardless if this is a disconnect or a new tablet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) * remove any existing input and battery devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) wacom_destroy_battery(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) if (!usbdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) /* Stylus interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) hdev1 = usb_get_intfdata(usbdev->config->interface[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) wacom1 = hid_get_drvdata(hdev1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) wacom_wac1 = &(wacom1->wacom_wac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) wacom_release_resources(wacom1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) /* Touch interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) hdev2 = usb_get_intfdata(usbdev->config->interface[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) wacom2 = hid_get_drvdata(hdev2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) wacom_wac2 = &(wacom2->wacom_wac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) wacom_release_resources(wacom2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) if (wacom_wac->pid == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) hid_info(wacom->hdev, "wireless tablet disconnected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) const struct hid_device_id *id = wacom_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) hid_info(wacom->hdev, "wireless tablet connected with PID %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) wacom_wac->pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) while (id->bus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) if (id->vendor == USB_VENDOR_ID_WACOM &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) id->product == wacom_wac->pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) id++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) if (!id->bus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) hid_info(wacom->hdev, "ignoring unknown PID.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) /* Stylus interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) wacom_wac1->features =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) *((struct wacom_features *)id->driver_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) wacom_wac1->pid = wacom_wac->pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) hid_hw_stop(hdev1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) error = wacom_parse_and_register(wacom1, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) /* Touch interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) if (wacom_wac1->features.touch_max ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) (wacom_wac1->features.type >= INTUOSHT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) wacom_wac1->features.type <= BAMBOO_PT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) wacom_wac2->features =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) *((struct wacom_features *)id->driver_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) wacom_wac2->pid = wacom_wac->pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) hid_hw_stop(hdev2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) error = wacom_parse_and_register(wacom2, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) strlcpy(wacom_wac->name, wacom_wac1->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) sizeof(wacom_wac->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) error = wacom_initialize_battery(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) wacom_release_resources(wacom1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) wacom_release_resources(wacom2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) struct wacom_remote *remote = wacom->remote;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) u32 serial = remote->remotes[index].serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) for (i = 0; i < WACOM_MAX_REMOTES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) if (remote->remotes[i].serial == serial) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) spin_lock_irqsave(&remote->remote_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) remote->remotes[i].registered = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) spin_unlock_irqrestore(&remote->remote_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) if (remote->remotes[i].battery.battery)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) devres_release_group(&wacom->hdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) &remote->remotes[i].battery.bat_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) if (remote->remotes[i].group.name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) devres_release_group(&wacom->hdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) &remote->remotes[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) remote->remotes[i].serial = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) remote->remotes[i].group.name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) remote->remotes[i].battery.battery = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) static int wacom_remote_create_one(struct wacom *wacom, u32 serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) unsigned int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) struct wacom_remote *remote = wacom->remote;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) struct device *dev = &wacom->hdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) int error, k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) /* A remote can pair more than once with an EKR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) * check to make sure this serial isn't already paired.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) for (k = 0; k < WACOM_MAX_REMOTES; k++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) if (remote->remotes[k].serial == serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) if (k < WACOM_MAX_REMOTES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) remote->remotes[index].serial = serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) if (!devres_open_group(dev, &remote->remotes[index], GFP_KERNEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) error = wacom_remote_create_attr_group(wacom, serial, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) remote->remotes[index].input = wacom_allocate_input(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) if (!remote->remotes[index].input) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) remote->remotes[index].input->uniq = remote->remotes[index].group.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) remote->remotes[index].input->name = wacom->wacom_wac.pad_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) if (!remote->remotes[index].input->name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) error = wacom_setup_pad_input_capabilities(remote->remotes[index].input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) &wacom->wacom_wac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) remote->remotes[index].serial = serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) error = input_register_device(remote->remotes[index].input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) error = wacom_led_groups_alloc_and_register_one(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) &remote->remotes[index].input->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) wacom, index, 3, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) remote->remotes[index].registered = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) devres_close_group(dev, &remote->remotes[index]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) devres_release_group(dev, &remote->remotes[index]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) remote->remotes[index].serial = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) static int wacom_remote_attach_battery(struct wacom *wacom, int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) struct wacom_remote *remote = wacom->remote;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) if (!remote->remotes[index].registered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) if (remote->remotes[index].battery.battery)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) if (wacom->led.groups[index].select == WACOM_STATUS_UNKNOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) error = __wacom_initialize_battery(wacom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) &wacom->remote->remotes[index].battery);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) static void wacom_remote_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) struct wacom *wacom = container_of(work, struct wacom, remote_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) struct wacom_remote *remote = wacom->remote;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) struct wacom_remote_data data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) unsigned int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) u32 serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) spin_lock_irqsave(&remote->remote_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) count = kfifo_out(&remote->remote_fifo, &data, sizeof(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) if (count != sizeof(data)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) hid_err(wacom->hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) "workitem triggered without status available\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) spin_unlock_irqrestore(&remote->remote_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) if (!kfifo_is_empty(&remote->remote_fifo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) wacom_schedule_work(&wacom->wacom_wac, WACOM_WORKER_REMOTE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) spin_unlock_irqrestore(&remote->remote_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) for (i = 0; i < WACOM_MAX_REMOTES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) serial = data.remote[i].serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) if (data.remote[i].connected) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) if (remote->remotes[i].serial == serial) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) wacom_remote_attach_battery(wacom, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) if (remote->remotes[i].serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) wacom_remote_destroy_one(wacom, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) wacom_remote_create_one(wacom, serial, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) } else if (remote->remotes[i].serial) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) wacom_remote_destroy_one(wacom, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) static void wacom_mode_change_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) struct wacom *wacom = container_of(work, struct wacom, mode_change_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) struct wacom_shared *shared = wacom->wacom_wac.shared;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) struct wacom *wacom1 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) struct wacom *wacom2 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) bool is_direct = wacom->wacom_wac.is_direct_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) if (shared->pen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) wacom1 = hid_get_drvdata(shared->pen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) wacom_release_resources(wacom1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) hid_hw_stop(wacom1->hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) wacom1->wacom_wac.has_mode_change = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) wacom1->wacom_wac.is_direct_mode = is_direct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) if (shared->touch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) wacom2 = hid_get_drvdata(shared->touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) wacom_release_resources(wacom2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) hid_hw_stop(wacom2->hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) wacom2->wacom_wac.has_mode_change = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) wacom2->wacom_wac.is_direct_mode = is_direct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) if (wacom1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) error = wacom_parse_and_register(wacom1, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) if (wacom2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) error = wacom_parse_and_register(wacom2, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) static int wacom_probe(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) const struct hid_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) struct wacom *wacom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) struct wacom_wac *wacom_wac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) struct wacom_features *features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) if (!id->driver_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) /* hid-core sets this quirk for the boot interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) hdev->quirks &= ~HID_QUIRK_NOGET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) wacom = devm_kzalloc(&hdev->dev, sizeof(struct wacom), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) if (!wacom)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) hid_set_drvdata(hdev, wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) wacom->hdev = hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) wacom_wac = &wacom->wacom_wac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) wacom_wac->features = *((struct wacom_features *)id->driver_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) features = &wacom_wac->features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) if (features->check_for_hid_type && features->hid_type != hdev->type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) error = wacom_devm_kfifo_alloc(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) wacom_wac->hid_data.inputmode = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) wacom_wac->mode_report = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) if (hid_is_usb(hdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) struct usb_device *dev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) wacom->usbdev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) wacom->intf = intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) mutex_init(&wacom->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) INIT_DELAYED_WORK(&wacom->init_work, wacom_init_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) INIT_WORK(&wacom->wireless_work, wacom_wireless_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) INIT_WORK(&wacom->battery_work, wacom_battery_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) INIT_WORK(&wacom->remote_work, wacom_remote_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) INIT_WORK(&wacom->mode_change_work, wacom_mode_change_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) /* ask for the report descriptor to be loaded by HID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) error = hid_parse(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) hid_err(hdev, "parse failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) error = wacom_parse_and_register(wacom, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) if (hdev->bus == BUS_BLUETOOTH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) error = device_create_file(&hdev->dev, &dev_attr_speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) hid_warn(hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) "can't create sysfs speed attribute err: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) static void wacom_remove(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) struct wacom *wacom = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) struct wacom_wac *wacom_wac = &wacom->wacom_wac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) struct wacom_features *features = &wacom_wac->features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) hid_hw_close(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) hid_hw_stop(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) cancel_delayed_work_sync(&wacom->init_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) cancel_work_sync(&wacom->wireless_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) cancel_work_sync(&wacom->battery_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) cancel_work_sync(&wacom->remote_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) cancel_work_sync(&wacom->mode_change_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) if (hdev->bus == BUS_BLUETOOTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) device_remove_file(&hdev->dev, &dev_attr_speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) /* make sure we don't trigger the LEDs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) wacom_led_groups_release(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) if (wacom->wacom_wac.features.type != REMOTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) wacom_release_resources(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) static int wacom_resume(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) struct wacom *wacom = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) mutex_lock(&wacom->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) /* switch to wacom mode first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) _wacom_query_tablet_data(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) wacom_led_control(wacom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) mutex_unlock(&wacom->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) static int wacom_reset_resume(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) return wacom_resume(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) #endif /* CONFIG_PM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) static struct hid_driver wacom_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) .name = "wacom",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) .id_table = wacom_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) .probe = wacom_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) .remove = wacom_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) .report = wacom_wac_report,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) .resume = wacom_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) .reset_resume = wacom_reset_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) .raw_event = wacom_raw_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) module_hid_driver(wacom_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) MODULE_VERSION(DRIVER_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) MODULE_AUTHOR(DRIVER_AUTHOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) MODULE_LICENSE("GPL");