xref: /linux/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.h (revision b80a75cf6999fb79971b41eaec7af2bb4b514714)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2024 Intel Corporation */
3 
4 #ifndef _INTEL_THC_DEV_H_
5 #define _INTEL_THC_DEV_H_
6 
7 #include <linux/cdev.h>
8 #include <linux/mutex.h>
9 #include <linux/workqueue.h>
10 
11 #include "intel-thc-dma.h"
12 #include "intel-thc-wot.h"
13 
14 #define THC_REGMAP_COMMON_OFFSET  0x10
15 #define THC_REGMAP_MMIO_OFFSET    0x1000
16 
17 /*
18  * THC Port type
19  * @THC_PORT_TYPE_SPI: This port is used for HIDSPI
20  * @THC_PORT_TYPE_I2C: This port is used for HIDI2C
21  */
22 enum thc_port_type {
23 	THC_PORT_TYPE_SPI = 0,
24 	THC_PORT_TYPE_I2C = 1,
25 };
26 
27 /**
28  * THC interrupt flag
29  * @THC_NONDMA_INT: THC non-DMA interrupt
30  * @THC_RXDMA1_INT: THC RxDMA1 interrupt
31  * @THC_RXDMA2_INT: THC RxDMA2 interrupt
32  * @THC_SWDMA_INT: THC SWDMA interrupt
33  * @THC_TXDMA_INT: THC TXDMA interrupt
34  * @THC_PIO_DONE_INT: THC PIO complete interrupt
35  * @THC_I2CSUBIP_INT: THC I2C subsystem interrupt
36  * @THC_TXN_ERR_INT: THC transfer error interrupt
37  * @THC_FATAL_ERR_INT: THC fatal error interrupt
38  */
39 enum thc_int_type {
40 	THC_NONDMA_INT = 0,
41 	THC_RXDMA1_INT = 1,
42 	THC_RXDMA2_INT = 2,
43 	THC_SWDMA_INT = 3,
44 	THC_TXDMA_INT = 4,
45 	THC_PIO_DONE_INT = 5,
46 	THC_I2CSUBIP_INT = 6,
47 	THC_TXN_ERR_INT = 7,
48 	THC_FATAL_ERR_INT = 8,
49 	THC_UNKNOWN_INT
50 };
51 
52 /**
53  * struct thc_device - THC private device struct
54  * @thc_regmap: MMIO regmap structure for accessing THC registers
55  * @mmio_addr: MMIO registers address
56  * @thc_bus_lock: Mutex locker for THC config
57  * @port_type: Port type of THC port instance
58  * @pio_int_supported: PIO interrupt supported flag
59  * @dma_ctx: DMA specific data
60  * @wot: THC Wake-on-Touch data
61  * @write_complete_wait: Signal event for DMA write complete
62  * @swdma_complete_wait: Signal event for SWDMA sequence complete
63  * @write_done: Bool value that indicates if DMA write is done
64  * @swdma_done: Bool value that indicates if SWDMA sequence is done
65  * @perf_limit: The delay between read operation and write operation
66  * @i2c_subip_regs: The copy of THC I2C sub-system registers for resuming restore
67  * @i2c_max_rx_size: I2C Rx transfer max input size
68  * @i2c_int_delay_us: I2C input interrupt delay, unit is us
69  * @i2c_max_rx_size_en: Bool value that indicates I2C max input size control enabled or not
70  * @i2c_int_delay_en: Bool value that indicates I2C input interrupt delay enabled or not
71  */
72 struct thc_device {
73 	struct device *dev;
74 	struct regmap *thc_regmap;
75 	void __iomem *mmio_addr;
76 	struct mutex thc_bus_lock;
77 	enum thc_port_type port_type;
78 	bool pio_int_supported;
79 
80 	struct thc_dma_context *dma_ctx;
81 
82 	struct thc_wot wot;
83 
84 	wait_queue_head_t write_complete_wait;
85 	wait_queue_head_t swdma_complete_wait;
86 	bool write_done;
87 	bool swdma_done;
88 
89 	u32 perf_limit;
90 
91 	u32 *i2c_subip_regs;
92 
93 	u32 i2c_max_rx_size;
94 	u32 i2c_int_delay_us;
95 	bool i2c_max_rx_size_en;
96 	bool i2c_int_delay_en;
97 };
98 
99 struct thc_device *thc_dev_init(struct device *device, void __iomem *mem_addr);
100 int thc_tic_pio_read(struct thc_device *dev, const u32 address,
101 		     const u32 size, u32 *actual_size, u32 *buffer);
102 int thc_tic_pio_write(struct thc_device *dev, const u32 address,
103 		      const u32 size, const u32 *buffer);
104 int thc_tic_pio_write_and_read(struct thc_device *dev, const u32 address,
105 			       const u32 write_size, const u32 *write_buffer,
106 			       const u32 read_size, u32 *actual_size, u32 *read_buffer);
107 void thc_interrupt_config(struct thc_device *dev);
108 void thc_int_trigger_type_select(struct thc_device *dev, bool edge_trigger);
109 void thc_interrupt_enable(struct thc_device *dev, bool int_enable);
110 void thc_set_pio_interrupt_support(struct thc_device *dev, bool supported);
111 int thc_interrupt_quiesce(const struct thc_device *dev, bool int_quiesce);
112 void thc_ltr_config(struct thc_device *dev, u32 active_ltr_us, u32 lp_ltr_us);
113 void thc_change_ltr_mode(struct thc_device *dev, u32 ltr_mode);
114 void thc_ltr_unconfig(struct thc_device *dev);
115 u32 thc_int_cause_read(struct thc_device *dev);
116 int thc_interrupt_handler(struct thc_device *dev);
117 int thc_port_select(struct thc_device *dev, enum thc_port_type port_type);
118 int thc_spi_read_config(struct thc_device *dev, u32 spi_freq_val,
119 			u32 io_mode, u32 opcode, u32 spi_rd_mps);
120 int thc_spi_write_config(struct thc_device *dev, u32 spi_freq_val,
121 			 u32 io_mode, u32 opcode, u32 spi_wr_mps, u32 perf_limit);
122 void thc_spi_input_output_address_config(struct thc_device *dev, u32 input_hdr_addr,
123 					 u32 input_bdy_addr, u32 output_addr);
124 int thc_i2c_subip_init(struct thc_device *dev, const u32 target_address,
125 		       const u32 speed, const u32 hcnt, const u32 lcnt);
126 int thc_i2c_subip_regs_save(struct thc_device *dev);
127 int thc_i2c_subip_regs_restore(struct thc_device *dev);
128 int thc_i2c_set_rx_max_size(struct thc_device *dev, u32 max_rx_size);
129 int thc_i2c_rx_max_size_enable(struct thc_device *dev, bool enable);
130 int thc_i2c_set_rx_int_delay(struct thc_device *dev, u32 delay_us);
131 int thc_i2c_rx_int_delay_enable(struct thc_device *dev, bool enable);
132 
133 #endif /* _INTEL_THC_DEV_H_ */
134