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 
13 #define THC_REGMAP_COMMON_OFFSET  0x10
14 #define THC_REGMAP_MMIO_OFFSET    0x1000
15 
16 /*
17  * THC Port type
18  * @THC_PORT_TYPE_SPI: This port is used for HIDSPI
19  * @THC_PORT_TYPE_I2C: This port is used for HIDI2C
20  */
21 enum thc_port_type {
22 	THC_PORT_TYPE_SPI = 0,
23 	THC_PORT_TYPE_I2C = 1,
24 };
25 
26 /**
27  * THC interrupt flag
28  * @THC_NONDMA_INT: THC non-DMA interrupt
29  * @THC_RXDMA1_INT: THC RxDMA1 interrupt
30  * @THC_RXDMA2_INT: THC RxDMA2 interrupt
31  * @THC_SWDMA_INT: THC SWDMA interrupt
32  * @THC_TXDMA_INT: THC TXDMA interrupt
33  * @THC_PIO_DONE_INT: THC PIO complete interrupt
34  * @THC_I2CSUBIP_INT: THC I2C subsystem interrupt
35  * @THC_TXN_ERR_INT: THC transfer error interrupt
36  * @THC_FATAL_ERR_INT: THC fatal error interrupt
37  */
38 enum thc_int_type {
39 	THC_NONDMA_INT = 0,
40 	THC_RXDMA1_INT = 1,
41 	THC_RXDMA2_INT = 2,
42 	THC_SWDMA_INT = 3,
43 	THC_TXDMA_INT = 4,
44 	THC_PIO_DONE_INT = 5,
45 	THC_I2CSUBIP_INT = 6,
46 	THC_TXN_ERR_INT = 7,
47 	THC_FATAL_ERR_INT = 8,
48 	THC_UNKNOWN_INT
49 };
50 
51 /**
52  * struct thc_device - THC private device struct
53  * @thc_regmap: MMIO regmap structure for accessing THC registers
54  * @mmio_addr: MMIO registers address
55  * @thc_bus_lock: mutex locker for THC config
56  * @port_type: port type of THC port instance
57  * @pio_int_supported: PIO interrupt supported flag
58  * @dma_ctx: DMA specific data
59  * @write_complete_wait: signal event for DMA write complete
60  * @swdma_complete_wait: signal event for SWDMA sequence complete
61  * @write_done: bool value that indicates if DMA write is done
62  * @swdma_done: bool value that indicates if SWDMA swquence is done
63  * @perf_limit: the delay between read operation and write operation
64  * @i2c_subip_regs: the copy of THC I2C sub-system registers for resuming restore
65  */
66 struct thc_device {
67 	struct device *dev;
68 	struct regmap *thc_regmap;
69 	void __iomem *mmio_addr;
70 	struct mutex thc_bus_lock;
71 	enum thc_port_type port_type;
72 	bool pio_int_supported;
73 
74 	struct thc_dma_context *dma_ctx;
75 
76 	wait_queue_head_t write_complete_wait;
77 	wait_queue_head_t swdma_complete_wait;
78 	bool write_done;
79 	bool swdma_done;
80 
81 	u32 perf_limit;
82 
83 	u32 *i2c_subip_regs;
84 };
85 
86 struct thc_device *thc_dev_init(struct device *device, void __iomem *mem_addr);
87 int thc_tic_pio_read(struct thc_device *dev, const u32 address,
88 		     const u32 size, u32 *actual_size, u32 *buffer);
89 int thc_tic_pio_write(struct thc_device *dev, const u32 address,
90 		      const u32 size, const u32 *buffer);
91 int thc_tic_pio_write_and_read(struct thc_device *dev, const u32 address,
92 			       const u32 write_size, const u32 *write_buffer,
93 			       const u32 read_size, u32 *actual_size, u32 *read_buffer);
94 void thc_interrupt_config(struct thc_device *dev);
95 void thc_int_trigger_type_select(struct thc_device *dev, bool edge_trigger);
96 void thc_interrupt_enable(struct thc_device *dev, bool int_enable);
97 void thc_set_pio_interrupt_support(struct thc_device *dev, bool supported);
98 int thc_interrupt_quiesce(const struct thc_device *dev, bool int_quiesce);
99 void thc_ltr_config(struct thc_device *dev, u32 active_ltr_us, u32 lp_ltr_us);
100 void thc_change_ltr_mode(struct thc_device *dev, u32 ltr_mode);
101 void thc_ltr_unconfig(struct thc_device *dev);
102 u32 thc_int_cause_read(struct thc_device *dev);
103 int thc_interrupt_handler(struct thc_device *dev);
104 int thc_port_select(struct thc_device *dev, enum thc_port_type port_type);
105 int thc_spi_read_config(struct thc_device *dev, u32 spi_freq_val,
106 			u32 io_mode, u32 opcode, u32 spi_rd_mps);
107 int thc_spi_write_config(struct thc_device *dev, u32 spi_freq_val,
108 			 u32 io_mode, u32 opcode, u32 spi_wr_mps, u32 perf_limit);
109 void thc_spi_input_output_address_config(struct thc_device *dev, u32 input_hdr_addr,
110 					 u32 input_bdy_addr, u32 output_addr);
111 int thc_i2c_subip_init(struct thc_device *dev, const u32 target_address,
112 		       const u32 speed, const u32 hcnt, const u32 lcnt);
113 int thc_i2c_subip_regs_save(struct thc_device *dev);
114 int thc_i2c_subip_regs_restore(struct thc_device *dev);
115 
116 #endif /* _INTEL_THC_DEV_H_ */
117