1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright (C) 2013--2024 Intel Corporation */
3 
4 #ifndef IPU6_BUTTRESS_H
5 #define IPU6_BUTTRESS_H
6 
7 #include <linux/completion.h>
8 #include <linux/irqreturn.h>
9 #include <linux/list.h>
10 #include <linux/mutex.h>
11 
12 struct device;
13 struct firmware;
14 struct ipu6_device;
15 struct ipu6_bus_device;
16 
17 #define BUTTRESS_PS_FREQ_STEP		25U
18 #define BUTTRESS_MIN_FORCE_PS_FREQ	(BUTTRESS_PS_FREQ_STEP * 8)
19 #define BUTTRESS_MAX_FORCE_PS_FREQ	(BUTTRESS_PS_FREQ_STEP * 32)
20 
21 #define BUTTRESS_IS_FREQ_STEP		25U
22 #define BUTTRESS_MIN_FORCE_IS_FREQ	(BUTTRESS_IS_FREQ_STEP * 8)
23 #define BUTTRESS_MAX_FORCE_IS_FREQ	(BUTTRESS_IS_FREQ_STEP * 22)
24 
25 struct ipu6_buttress_ctrl {
26 	u32 freq_ctl, pwr_sts_shift, pwr_sts_mask, pwr_sts_on, pwr_sts_off;
27 	unsigned int ratio;
28 	unsigned int qos_floor;
29 	bool started;
30 };
31 
32 struct ipu6_buttress_ipc {
33 	struct completion send_complete;
34 	struct completion recv_complete;
35 	u32 nack;
36 	u32 nack_mask;
37 	u32 recv_data;
38 	u32 csr_out;
39 	u32 csr_in;
40 	u32 db0_in;
41 	u32 db0_out;
42 	u32 data0_out;
43 	u32 data0_in;
44 };
45 
46 struct ipu6_buttress {
47 	struct mutex power_mutex, auth_mutex, cons_mutex, ipc_mutex;
48 	struct ipu6_buttress_ipc cse;
49 	struct ipu6_buttress_ipc ish;
50 	struct list_head constraints;
51 	u32 wdt_cached_value;
52 	bool force_suspend;
53 	u32 ref_clk;
54 };
55 
56 enum ipu6_buttress_ipc_domain {
57 	IPU6_BUTTRESS_IPC_CSE,
58 	IPU6_BUTTRESS_IPC_ISH,
59 };
60 
61 struct ipu6_ipc_buttress_bulk_msg {
62 	u32 cmd;
63 	u32 expected_resp;
64 	bool require_resp;
65 	u8 cmd_size;
66 };
67 
68 int ipu6_buttress_ipc_reset(struct ipu6_device *isp,
69 			    struct ipu6_buttress_ipc *ipc);
70 int ipu6_buttress_map_fw_image(struct ipu6_bus_device *sys,
71 			       const struct firmware *fw,
72 			       struct sg_table *sgt);
73 void ipu6_buttress_unmap_fw_image(struct ipu6_bus_device *sys,
74 				  struct sg_table *sgt);
75 int ipu6_buttress_power(struct device *dev, struct ipu6_buttress_ctrl *ctrl,
76 			bool on);
77 bool ipu6_buttress_get_secure_mode(struct ipu6_device *isp);
78 int ipu6_buttress_authenticate(struct ipu6_device *isp);
79 int ipu6_buttress_reset_authentication(struct ipu6_device *isp);
80 bool ipu6_buttress_auth_done(struct ipu6_device *isp);
81 int ipu6_buttress_start_tsc_sync(struct ipu6_device *isp);
82 void ipu6_buttress_tsc_read(struct ipu6_device *isp, u64 *val);
83 u64 ipu6_buttress_tsc_ticks_to_ns(u64 ticks, const struct ipu6_device *isp);
84 
85 irqreturn_t ipu6_buttress_isr(int irq, void *isp_ptr);
86 irqreturn_t ipu6_buttress_isr_threaded(int irq, void *isp_ptr);
87 int ipu6_buttress_init(struct ipu6_device *isp);
88 void ipu6_buttress_exit(struct ipu6_device *isp);
89 void ipu6_buttress_csi_port_config(struct ipu6_device *isp,
90 				   u32 legacy, u32 combo);
91 void ipu6_buttress_restore(struct ipu6_device *isp);
92 #endif /* IPU6_BUTTRESS_H */
93