^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) * Copyright (c) 2013 Andrew Duggan <aduggan@synaptics.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2013 Synaptics Incorporated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2014 Benjamin Tissoires <benjamin.tissoires@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 2014 Red Hat, Inc
^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) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/input/mt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/irqdomain.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/pm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/rmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "hid-ids.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define RMI_MOUSE_REPORT_ID 0x01 /* Mouse emulation Report */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define RMI_WRITE_REPORT_ID 0x09 /* Output Report */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define RMI_READ_ADDR_REPORT_ID 0x0a /* Output Report */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define RMI_READ_DATA_REPORT_ID 0x0b /* Input Report */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define RMI_ATTN_REPORT_ID 0x0c /* Input Report */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define RMI_SET_RMI_MODE_REPORT_ID 0x0f /* Feature Report */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /* flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define RMI_READ_REQUEST_PENDING 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define RMI_READ_DATA_PENDING 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define RMI_STARTED 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* device flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define RMI_DEVICE BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define RMI_DEVICE_HAS_PHYS_BUTTONS BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define RMI_DEVICE_OUTPUT_SET_REPORT BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * retrieve the ctrl registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * the ctrl register has a size of 20 but a fw bug split it into 16 + 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * and there is no way to know if the first 20 bytes are here or not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * We use only the first 12 bytes, so get only them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define RMI_F11_CTRL_REG_COUNT 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) enum rmi_mode_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) RMI_MODE_OFF = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) RMI_MODE_ATTN_REPORTS = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) RMI_MODE_NO_PACKED_ATTN_REPORTS = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * struct rmi_data - stores information for hid communication
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * @page_mutex: Locks current page to avoid changing pages in unexpected ways.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * @page: Keeps track of the current virtual page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * @xport: transport device to be registered with the RMI4 core.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * @wait: Used for waiting for read data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * @writeReport: output buffer when writing RMI registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * @readReport: input buffer when reading RMI registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * @input_report_size: size of an input report (advertised by HID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * @output_report_size: size of an output report (advertised by HID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * @flags: flags for the current device (started, reading, etc...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * @reset_work: worker which will be called in case of a mouse report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * @hdev: pointer to the struct hid_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * @device_flags: flags which describe the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * @domain: the IRQ domain allocated for this RMI4 device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * @rmi_irq: the irq that will be used to generate events to rmi-core
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct rmi_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct mutex page_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) int page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct rmi_transport_dev xport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) wait_queue_head_t wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) u8 *writeReport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) u8 *readReport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) u32 input_report_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) u32 output_report_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct work_struct reset_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct hid_device *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) unsigned long device_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct irq_domain *domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) int rmi_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define RMI_PAGE(addr) (((addr) >> 8) & 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static int rmi_write_report(struct hid_device *hdev, u8 *report, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * rmi_set_page - Set RMI page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * @hdev: The pointer to the hid_device struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * @page: The new page address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * RMI devices have 16-bit addressing, but some of the physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * implementations (like SMBus) only have 8-bit addressing. So RMI implements
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * a page address at 0xff of every page so we can reliable page addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * every 256 registers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * The page_mutex lock must be held when this function is entered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * Returns zero on success, non-zero on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static int rmi_set_page(struct hid_device *hdev, u8 page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct rmi_data *data = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) data->writeReport[0] = RMI_WRITE_REPORT_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) data->writeReport[1] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) data->writeReport[2] = 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) data->writeReport[4] = page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) retval = rmi_write_report(hdev, data->writeReport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) data->output_report_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (retval != data->output_report_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) dev_err(&hdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) "%s: set page failed: %d.", __func__, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) data->page = page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return 0;
^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) static int rmi_set_mode(struct hid_device *hdev, u8 mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) const u8 txbuf[2] = {RMI_SET_RMI_MODE_REPORT_ID, mode};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) u8 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) buf = kmemdup(txbuf, sizeof(txbuf), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) ret = hid_hw_raw_request(hdev, RMI_SET_RMI_MODE_REPORT_ID, buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) sizeof(txbuf), HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) dev_err(&hdev->dev, "unable to set rmi mode to %d (%d)\n", mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static int rmi_write_report(struct hid_device *hdev, u8 *report, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct rmi_data *data = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (data->device_flags & RMI_DEVICE_OUTPUT_SET_REPORT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * Talk to device by using SET_REPORT requests instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) ret = hid_hw_raw_request(hdev, report[0], report,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) len, HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) ret = hid_hw_output_report(hdev, (void *)report, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) dev_err(&hdev->dev, "failed to write hid report (%d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return ret;
^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) static int rmi_hid_read_block(struct rmi_transport_dev *xport, u16 addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) void *buf, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct rmi_data *data = container_of(xport, struct rmi_data, xport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct hid_device *hdev = data->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) int bytes_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) int bytes_needed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) int retries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) int read_input_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) mutex_lock(&data->page_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (RMI_PAGE(addr) != data->page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) ret = rmi_set_page(hdev, RMI_PAGE(addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) for (retries = 5; retries > 0; retries--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) data->writeReport[0] = RMI_READ_ADDR_REPORT_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) data->writeReport[1] = 0; /* old 1 byte read count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) data->writeReport[2] = addr & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) data->writeReport[3] = (addr >> 8) & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) data->writeReport[4] = len & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) data->writeReport[5] = (len >> 8) & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) set_bit(RMI_READ_REQUEST_PENDING, &data->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) ret = rmi_write_report(hdev, data->writeReport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) data->output_report_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (ret != data->output_report_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) dev_err(&hdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) "failed to write request output report (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) bytes_read = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) bytes_needed = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) while (bytes_read < len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (!wait_event_timeout(data->wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) test_bit(RMI_READ_DATA_PENDING, &data->flags),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) msecs_to_jiffies(1000))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) hid_warn(hdev, "%s: timeout elapsed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) ret = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) read_input_count = data->readReport[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) memcpy(buf + bytes_read, &data->readReport[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) read_input_count < bytes_needed ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) read_input_count : bytes_needed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) bytes_read += read_input_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) bytes_needed -= read_input_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) clear_bit(RMI_READ_DATA_PENDING, &data->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (ret >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) break;
^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) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) clear_bit(RMI_READ_REQUEST_PENDING, &data->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) mutex_unlock(&data->page_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static int rmi_hid_write_block(struct rmi_transport_dev *xport, u16 addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) const void *buf, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) struct rmi_data *data = container_of(xport, struct rmi_data, xport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) struct hid_device *hdev = data->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) mutex_lock(&data->page_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (RMI_PAGE(addr) != data->page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) ret = rmi_set_page(hdev, RMI_PAGE(addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) data->writeReport[0] = RMI_WRITE_REPORT_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) data->writeReport[1] = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) data->writeReport[2] = addr & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) data->writeReport[3] = (addr >> 8) & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) memcpy(&data->writeReport[4], buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) ret = rmi_write_report(hdev, data->writeReport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) data->output_report_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) dev_err(&hdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) "failed to write request output report (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) mutex_unlock(&data->page_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static int rmi_reset_attn_mode(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct rmi_data *data = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) struct rmi_device *rmi_dev = data->xport.rmi_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) ret = rmi_set_mode(hdev, RMI_MODE_ATTN_REPORTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) if (test_bit(RMI_STARTED, &data->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) ret = rmi_dev->driver->reset_handler(rmi_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) static void rmi_reset_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) struct rmi_data *hdata = container_of(work, struct rmi_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) reset_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) /* switch the device to RMI if we receive a generic mouse report */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) rmi_reset_attn_mode(hdata->hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static int rmi_input_event(struct hid_device *hdev, u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) struct rmi_data *hdata = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) struct rmi_device *rmi_dev = hdata->xport.rmi_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (!(test_bit(RMI_STARTED, &hdata->flags)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) rmi_set_attn_data(rmi_dev, data[1], &data[2], size - 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) generic_handle_irq(hdata->rmi_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static int rmi_read_data_event(struct hid_device *hdev, u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) struct rmi_data *hdata = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) if (!test_bit(RMI_READ_REQUEST_PENDING, &hdata->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) hid_dbg(hdev, "no read request pending\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) memcpy(hdata->readReport, data, size < hdata->input_report_size ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) size : hdata->input_report_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) set_bit(RMI_READ_DATA_PENDING, &hdata->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) wake_up(&hdata->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) static int rmi_check_sanity(struct hid_device *hdev, u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) int valid_size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * On the Dell XPS 13 9333, the bus sometimes get confused and fills
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * the report with a sentinel value "ff". Synaptics told us that such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * behavior does not comes from the touchpad itself, so we filter out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * such reports here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) while ((data[valid_size - 1] == 0xff) && valid_size > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) valid_size--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) return valid_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) static int rmi_raw_event(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) struct hid_report *report, u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) struct rmi_data *hdata = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (!(hdata->device_flags & RMI_DEVICE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) size = rmi_check_sanity(hdev, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (size < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) switch (data[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) case RMI_READ_DATA_REPORT_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) return rmi_read_data_event(hdev, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) case RMI_ATTN_REPORT_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) return rmi_input_event(hdev, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) return 1;
^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) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) static int rmi_event(struct hid_device *hdev, struct hid_field *field,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) struct hid_usage *usage, __s32 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct rmi_data *data = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if ((data->device_flags & RMI_DEVICE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) (field->application == HID_GD_POINTER ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) field->application == HID_GD_MOUSE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (data->device_flags & RMI_DEVICE_HAS_PHYS_BUTTONS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) if ((usage->hid == HID_GD_X || usage->hid == HID_GD_Y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) && !value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) schedule_work(&data->reset_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) static void rmi_report(struct hid_device *hid, struct hid_report *report)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) struct hid_field *field = report->field[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (!(hid->claimed & HID_CLAIMED_INPUT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) switch (report->id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) case RMI_READ_DATA_REPORT_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) case RMI_ATTN_REPORT_ID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) if (field && field->hidinput && field->hidinput->input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) input_sync(field->hidinput->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) static int rmi_suspend(struct hid_device *hdev, pm_message_t message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) struct rmi_data *data = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) struct rmi_device *rmi_dev = data->xport.rmi_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) if (!(data->device_flags & RMI_DEVICE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) ret = rmi_driver_suspend(rmi_dev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) hid_warn(hdev, "Failed to suspend device: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) static int rmi_post_resume(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) struct rmi_data *data = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) struct rmi_device *rmi_dev = data->xport.rmi_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) if (!(data->device_flags & RMI_DEVICE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) /* Make sure the HID device is ready to receive events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) ret = hid_hw_open(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) ret = rmi_reset_attn_mode(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) ret = rmi_driver_resume(rmi_dev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) hid_warn(hdev, "Failed to resume device: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) hid_hw_close(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) #endif /* CONFIG_PM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) static int rmi_hid_reset(struct rmi_transport_dev *xport, u16 reset_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) struct rmi_data *data = container_of(xport, struct rmi_data, xport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) struct hid_device *hdev = data->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) return rmi_reset_attn_mode(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) static int rmi_input_configured(struct hid_device *hdev, struct hid_input *hi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) struct rmi_data *data = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) struct input_dev *input = hi->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) if (!(data->device_flags & RMI_DEVICE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) data->xport.input = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) hid_dbg(hdev, "Opening low level driver\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) ret = hid_hw_open(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) /* Allow incoming hid reports */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) hid_device_io_start(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) ret = rmi_set_mode(hdev, RMI_MODE_ATTN_REPORTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) dev_err(&hdev->dev, "failed to set rmi mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) ret = rmi_set_page(hdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) dev_err(&hdev->dev, "failed to set page select to 0.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) ret = rmi_register_transport_device(&data->xport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) dev_err(&hdev->dev, "failed to register transport driver\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) goto exit;
^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) set_bit(RMI_STARTED, &data->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) hid_device_io_stop(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) hid_hw_close(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) static int rmi_input_mapping(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) struct hid_input *hi, struct hid_field *field,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) struct hid_usage *usage, unsigned long **bit, int *max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) struct rmi_data *data = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) * we want to make HID ignore the advertised HID collection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) * for RMI deivces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) if (data->device_flags & RMI_DEVICE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) if ((data->device_flags & RMI_DEVICE_HAS_PHYS_BUTTONS) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) static int rmi_check_valid_report_id(struct hid_device *hdev, unsigned type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) unsigned id, struct hid_report **report)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) *report = hdev->report_enum[type].report_id_hash[id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) if (*report) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) for (i = 0; i < (*report)->maxfield; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) unsigned app = (*report)->field[i]->application;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) if ((app & HID_USAGE_PAGE) >= HID_UP_MSVENDOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) static struct rmi_device_platform_data rmi_hid_pdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) .sensor_pdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) .sensor_type = rmi_sensor_touchpad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) .axis_align.flip_y = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) .dribble = RMI_REG_STATE_ON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) .palm_detect = RMI_REG_STATE_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) static const struct rmi_transport_ops hid_rmi_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) .write_block = rmi_hid_write_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) .read_block = rmi_hid_read_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) .reset = rmi_hid_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) static void rmi_irq_teardown(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) struct rmi_data *hdata = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) struct irq_domain *domain = hdata->domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) if (!domain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) irq_dispose_mapping(irq_find_mapping(domain, 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) irq_domain_remove(domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) hdata->domain = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) hdata->rmi_irq = 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 rmi_irq_map(struct irq_domain *h, unsigned int virq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) irq_hw_number_t hw_irq_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) irq_set_chip_and_handler(virq, &dummy_irq_chip, handle_simple_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) static const struct irq_domain_ops rmi_irq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) .map = rmi_irq_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) static int rmi_setup_irq_domain(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) struct rmi_data *hdata = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) hdata->domain = irq_domain_create_linear(hdev->dev.fwnode, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) &rmi_irq_ops, hdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) if (!hdata->domain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) ret = devm_add_action_or_reset(&hdev->dev, &rmi_irq_teardown, hdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) hdata->rmi_irq = irq_create_mapping(hdata->domain, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) if (hdata->rmi_irq <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) hid_err(hdev, "Can't allocate an IRQ\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) return hdata->rmi_irq < 0 ? hdata->rmi_irq : -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) static int rmi_probe(struct hid_device *hdev, const struct hid_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) struct rmi_data *data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) size_t alloc_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) struct hid_report *input_report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) struct hid_report *output_report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) struct hid_report *feature_report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) data = devm_kzalloc(&hdev->dev, sizeof(struct rmi_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) INIT_WORK(&data->reset_work, rmi_reset_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) data->hdev = hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) hid_set_drvdata(hdev, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) ret = hid_parse(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) hid_err(hdev, "parse failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) if (id->driver_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) data->device_flags = id->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) * Check for the RMI specific report ids. If they are misisng
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) * simply return and let the events be processed by hid-input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) if (!rmi_check_valid_report_id(hdev, HID_FEATURE_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) RMI_SET_RMI_MODE_REPORT_ID, &feature_report)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) hid_dbg(hdev, "device does not have set mode feature report\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) goto start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) if (!rmi_check_valid_report_id(hdev, HID_INPUT_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) RMI_ATTN_REPORT_ID, &input_report)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) hid_dbg(hdev, "device does not have attention input report\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) goto start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) data->input_report_size = hid_report_len(input_report);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) if (!rmi_check_valid_report_id(hdev, HID_OUTPUT_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) RMI_WRITE_REPORT_ID, &output_report)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) hid_dbg(hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) "device does not have rmi write output report\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) goto start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) data->output_report_size = hid_report_len(output_report);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) data->device_flags |= RMI_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) alloc_size = data->output_report_size + data->input_report_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) data->writeReport = devm_kzalloc(&hdev->dev, alloc_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) if (!data->writeReport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) hid_err(hdev, "failed to allocate buffer for HID reports\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) return -ENOMEM;
^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) data->readReport = data->writeReport + data->output_report_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) init_waitqueue_head(&data->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) mutex_init(&data->page_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) ret = rmi_setup_irq_domain(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) hid_err(hdev, "failed to allocate IRQ domain\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) if (data->device_flags & RMI_DEVICE_HAS_PHYS_BUTTONS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) rmi_hid_pdata.gpio_data.disable = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) data->xport.dev = hdev->dev.parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) data->xport.pdata = rmi_hid_pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) data->xport.pdata.irq = data->rmi_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) data->xport.proto_name = "hid";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) data->xport.ops = &hid_rmi_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) start:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) hid_err(hdev, "hw start failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) static void rmi_remove(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) struct rmi_data *hdata = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) if ((hdata->device_flags & RMI_DEVICE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) && test_bit(RMI_STARTED, &hdata->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) clear_bit(RMI_STARTED, &hdata->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) cancel_work_sync(&hdata->reset_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) rmi_unregister_transport_device(&hdata->xport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) hid_hw_stop(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) static const struct hid_device_id rmi_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) { HID_USB_DEVICE(USB_VENDOR_ID_RAZER, USB_DEVICE_ID_RAZER_BLADE_14),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) .driver_data = RMI_DEVICE_HAS_PHYS_BUTTONS },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_X1_COVER) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) { HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_REZEL) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_ACER_SWITCH5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) .driver_data = RMI_DEVICE_OUTPUT_SET_REPORT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) { HID_DEVICE(HID_BUS_ANY, HID_GROUP_RMI, HID_ANY_ID, HID_ANY_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) MODULE_DEVICE_TABLE(hid, rmi_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) static struct hid_driver rmi_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) .name = "hid-rmi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) .id_table = rmi_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) .probe = rmi_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) .remove = rmi_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) .event = rmi_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) .raw_event = rmi_raw_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) .report = rmi_report,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) .input_mapping = rmi_input_mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) .input_configured = rmi_input_configured,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) .suspend = rmi_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) .resume = rmi_post_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) .reset_resume = rmi_post_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) #endif
^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) module_hid_driver(rmi_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) MODULE_AUTHOR("Andrew Duggan <aduggan@synaptics.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) MODULE_DESCRIPTION("RMI HID driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) MODULE_LICENSE("GPL");