1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Copyright (c) 2024 Intel Corporation */ 3 4 #ifndef _QUICKSPI_DEV_H_ 5 #define _QUICKSPI_DEV_H_ 6 7 #include <linux/bits.h> 8 #include <linux/hid-over-spi.h> 9 #include <linux/sizes.h> 10 #include <linux/wait.h> 11 12 #include "quickspi-protocol.h" 13 14 #define PCI_DEVICE_ID_INTEL_THC_MTL_DEVICE_ID_SPI_PORT1 0x7E49 15 #define PCI_DEVICE_ID_INTEL_THC_MTL_DEVICE_ID_SPI_PORT2 0x7E4B 16 #define PCI_DEVICE_ID_INTEL_THC_LNL_DEVICE_ID_SPI_PORT1 0xA849 17 #define PCI_DEVICE_ID_INTEL_THC_LNL_DEVICE_ID_SPI_PORT2 0xA84B 18 #define PCI_DEVICE_ID_INTEL_THC_PTL_H_DEVICE_ID_SPI_PORT1 0xE349 19 #define PCI_DEVICE_ID_INTEL_THC_PTL_H_DEVICE_ID_SPI_PORT2 0xE34B 20 #define PCI_DEVICE_ID_INTEL_THC_PTL_U_DEVICE_ID_SPI_PORT1 0xE449 21 #define PCI_DEVICE_ID_INTEL_THC_PTL_U_DEVICE_ID_SPI_PORT2 0xE44B 22 #define PCI_DEVICE_ID_INTEL_THC_WCL_DEVICE_ID_SPI_PORT1 0x4D49 23 #define PCI_DEVICE_ID_INTEL_THC_WCL_DEVICE_ID_SPI_PORT2 0x4D4B 24 #define PCI_DEVICE_ID_INTEL_THC_ARL_DEVICE_ID_SPI_PORT1 0x7749 25 #define PCI_DEVICE_ID_INTEL_THC_ARL_DEVICE_ID_SPI_PORT2 0x774B 26 27 /* HIDSPI special ACPI parameters DSM methods */ 28 #define ACPI_QUICKSPI_REVISION_NUM 2 29 #define ACPI_QUICKSPI_FUNC_NUM_INPUT_REP_HDR_ADDR 1 30 #define ACPI_QUICKSPI_FUNC_NUM_INPUT_REP_BDY_ADDR 2 31 #define ACPI_QUICKSPI_FUNC_NUM_OUTPUT_REP_ADDR 3 32 #define ACPI_QUICKSPI_FUNC_NUM_READ_OPCODE 4 33 #define ACPI_QUICKSPI_FUNC_NUM_WRITE_OPCODE 5 34 #define ACPI_QUICKSPI_FUNC_NUM_IO_MODE 6 35 36 /* QickSPI device special ACPI parameters DSM methods */ 37 #define ACPI_QUICKSPI_FUNC_NUM_CONNECTION_SPEED 1 38 #define ACPI_QUICKSPI_FUNC_NUM_LIMIT_PACKET_SIZE 2 39 #define ACPI_QUICKSPI_FUNC_NUM_PERFORMANCE_LIMIT 3 40 41 /* Platform special ACPI parameters DSM methods */ 42 #define ACPI_QUICKSPI_FUNC_NUM_ACTIVE_LTR 1 43 #define ACPI_QUICKSPI_FUNC_NUM_LP_LTR 2 44 45 #define SPI_WRITE_IO_MODE BIT(13) 46 #define SPI_IO_MODE_OPCODE GENMASK(15, 14) 47 #define PERFORMANCE_LIMITATION GENMASK(15, 0) 48 49 /* Packet size value, the unit is 16 bytes */ 50 #define DEFAULT_MIN_PACKET_SIZE_VALUE 4 51 #define MAX_PACKET_SIZE_VALUE_MTL 128 52 #define MAX_PACKET_SIZE_VALUE_LNL 256 53 54 /* 55 * THC uses runtime auto suspend to dynamically switch between THC active LTR 56 * and low power LTR to save CPU power. 57 * Default value is 5000ms, that means if no touch event in this time, THC will 58 * change to low power LTR mode. 59 */ 60 #define DEFAULT_AUTO_SUSPEND_DELAY_MS 5000 61 62 enum quickspi_dev_state { 63 QUICKSPI_NONE, 64 QUICKSPI_INITIATED, 65 QUICKSPI_RESETING, 66 QUICKSPI_RESET, 67 QUICKSPI_ENABLED, 68 QUICKSPI_DISABLED, 69 }; 70 71 /** 72 * struct quickspi_driver_data - Driver specific data for quickspi device 73 * @max_packet_size_value: identify max packet size, unit is 16 bytes 74 */ 75 struct quickspi_driver_data { 76 u32 max_packet_size_value; 77 }; 78 79 struct device; 80 struct pci_dev; 81 struct thc_device; 82 struct hid_device; 83 struct acpi_device; 84 85 /** 86 * struct quickspi_device - THC QuickSpi device struct 87 * @dev: point to kernel device 88 * @pdev: point to PCI device 89 * @thc_hw: point to THC device 90 * @hid_dev: point to hid device 91 * @acpi_dev: point to ACPI device 92 * @driver_data: point to quickspi specific driver data 93 * @state: THC SPI device state 94 * @mem_addr: MMIO memory address 95 * @dev_desc: device descriptor for HIDSPI protocol 96 * @input_report_hdr_addr: device input report header address 97 * @input_report_bdy_addr: device input report body address 98 * @output_report_bdy_addr: device output report address 99 * @spi_freq_val: device supported max SPI frequnecy, in Hz 100 * @spi_read_io_mode: device supported SPI read io mode 101 * @spi_write_io_mode: device supported SPI write io mode 102 * @spi_read_opcode: device read opcode 103 * @spi_write_opcode: device write opcode 104 * @limit_packet_size: 1 - limit read/write packet to 64Bytes 105 * 0 - device no packet size limiation for read/write 106 * @performance_limit: delay time, in ms. 107 * if device has performance limitation, must give a delay 108 * before write operation after a read operation. 109 * @active_ltr_val: THC active LTR value 110 * @low_power_ltr_val: THC low power LTR value 111 * @report_descriptor: store a copy of device report descriptor 112 * @input_buf: store a copy of latest input report data 113 * @report_buf: store a copy of latest input/output report packet from set/get feature 114 * @report_len: the length of input/output report packet 115 * @reset_ack_wq: workqueue for waiting reset response from device 116 * @reset_ack: indicate reset response received or not 117 * @nondma_int_received_wq: workqueue for waiting THC non-DMA interrupt 118 * @nondma_int_received: indicate THC non-DMA interrupt received or not 119 * @report_desc_got_wq: workqueue for waiting device report descriptor 120 * @report_desc_got: indicate device report descritor received or not 121 * @set_power_on_wq: workqueue for waiting set power on response from device 122 * @set_power_on: indicate set power on response received or not 123 * @get_feature_cmpl_wq: workqueue for waiting get feature response from device 124 * @get_feature_cmpl: indicate get feature received or not 125 * @set_feature_cmpl_wq: workqueue for waiting set feature to device 126 * @set_feature_cmpl: indicate set feature send complete or not 127 */ 128 struct quickspi_device { 129 struct device *dev; 130 struct pci_dev *pdev; 131 struct thc_device *thc_hw; 132 struct hid_device *hid_dev; 133 struct acpi_device *acpi_dev; 134 struct quickspi_driver_data *driver_data; 135 enum quickspi_dev_state state; 136 137 void __iomem *mem_addr; 138 139 struct hidspi_dev_descriptor dev_desc; 140 u32 input_report_hdr_addr; 141 u32 input_report_bdy_addr; 142 u32 output_report_addr; 143 u32 spi_freq_val; 144 u32 spi_read_io_mode; 145 u32 spi_write_io_mode; 146 u32 spi_read_opcode; 147 u32 spi_write_opcode; 148 u32 limit_packet_size; 149 u32 spi_packet_size; 150 u32 performance_limit; 151 152 u32 active_ltr_val; 153 u32 low_power_ltr_val; 154 155 u8 *report_descriptor; 156 u8 *input_buf; 157 u8 *report_buf; 158 u32 report_len; 159 160 wait_queue_head_t reset_ack_wq; 161 bool reset_ack; 162 163 wait_queue_head_t nondma_int_received_wq; 164 bool nondma_int_received; 165 166 wait_queue_head_t report_desc_got_wq; 167 bool report_desc_got; 168 169 wait_queue_head_t get_report_cmpl_wq; 170 bool get_report_cmpl; 171 172 wait_queue_head_t set_report_cmpl_wq; 173 bool set_report_cmpl; 174 }; 175 176 #endif /* _QUICKSPI_DEV_H_ */ 177