xref: /linux/drivers/media/platform/amd/isp4/isp4_subdev.h (revision 8c13415c8a4383447c21ec832b20b3b283f0e01a)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (C) 2025 Advanced Micro Devices, Inc.
4  */
5 
6 #ifndef _ISP4_SUBDEV_H_
7 #define _ISP4_SUBDEV_H_
8 
9 #include <linux/debugfs.h>
10 #include <linux/delay.h>
11 #include <linux/firmware.h>
12 #include <linux/pm_runtime.h>
13 #include <linux/types.h>
14 #include <linux/uaccess.h>
15 #include <media/v4l2-device.h>
16 
17 #include "isp4_fw_cmd_resp.h"
18 #include "isp4_hw_reg.h"
19 #include "isp4_interface.h"
20 #include "isp4_video.h"
21 
22 /*
23  * One is for none sensor specific response which is not used now.
24  * Another is for sensor specific response
25  */
26 #define ISP4SD_MAX_FW_RESP_STREAM_NUM 2
27 
28 /* Indicates the ISP status */
29 enum isp4sd_status {
30 	ISP4SD_STATUS_PWR_OFF,
31 	ISP4SD_STATUS_PWR_ON,
32 	ISP4SD_STATUS_FW_RUNNING,
33 	ISP4SD_STATUS_MAX
34 };
35 
36 /* Indicates sensor and output stream status */
37 enum isp4sd_start_status {
38 	ISP4SD_START_STATUS_OFF,
39 	ISP4SD_START_STATUS_STARTED,
40 	ISP4SD_START_STATUS_START_FAIL,
41 };
42 
43 struct isp4sd_img_buf_node {
44 	struct list_head node;
45 	struct isp4if_img_buf_info buf_info;
46 };
47 
48 /* This is ISP output after processing Bayer raw sensor input */
49 struct isp4sd_output_info {
50 	enum isp4sd_start_status start_status;
51 	u32 image_size;
52 };
53 
54 /*
55  * Struct for sensor info used as ISP input or source.
56  * status: sensor status.
57  * output_info: ISP output after processing the sensor input.
58  * start_stream_cmd_sent: indicates if ISP4FW_CMD_ID_START_STREAM was sent
59  * to firmware.
60  * buf_sent_cnt: number of buffers sent to receive images.
61  */
62 struct isp4sd_sensor_info {
63 	struct isp4sd_output_info output_info;
64 	enum isp4sd_start_status status;
65 	bool start_stream_cmd_sent;
66 	u32 buf_sent_cnt;
67 };
68 
69 /*
70  * The thread is created by the driver to handle firmware responses which will
71  * be waken up when a firmware-to-driver response interrupt occurs.
72  */
73 struct isp4sd_thread_handler {
74 	struct task_struct *thread;
75 	wait_queue_head_t waitq;
76 	bool resp_ready;
77 };
78 
79 struct isp4_subdev_thread_param {
80 	u32 idx;
81 	struct isp4_subdev *isp_subdev;
82 };
83 
84 struct isp4_subdev {
85 	struct v4l2_subdev sdev;
86 	struct isp4_interface ispif;
87 	struct isp4vid_dev isp_vdev;
88 
89 	struct media_pad sdev_pad;
90 
91 	enum isp4sd_status isp_status;
92 	/* mutex used to synchronize the operation with firmware */
93 	struct mutex ops_mutex;
94 
95 	struct isp4sd_thread_handler
96 		fw_resp_thread[ISP4SD_MAX_FW_RESP_STREAM_NUM];
97 
98 	u32 host2fw_seq_num;
99 
100 	struct isp4sd_sensor_info sensor_info;
101 
102 	/* gpio descriptor */
103 	struct gpio_desc *enable_gpio;
104 	struct device *dev;
105 	void __iomem *mmio;
106 	struct isp4_subdev_thread_param
107 		isp_resp_para[ISP4SD_MAX_FW_RESP_STREAM_NUM];
108 	int irq[ISP4SD_MAX_FW_RESP_STREAM_NUM];
109 	bool irq_enabled;
110 	/* spin lock to access ISP_SYS_INT0_EN exclusively */
111 	spinlock_t irq_lock;
112 #ifdef CONFIG_DEBUG_FS
113 	bool enable_fw_log;
114 	struct dentry *debugfs_dir;
115 	char *fw_log_output;
116 #endif
117 };
118 
119 int isp4sd_init(struct isp4_subdev *isp_subdev, struct v4l2_device *v4l2_dev,
120 		int irq[ISP4SD_MAX_FW_RESP_STREAM_NUM]);
121 void isp4sd_deinit(struct isp4_subdev *isp_subdev);
122 int isp4sd_ioc_send_img_buf(struct v4l2_subdev *sd,
123 			    struct isp4if_img_buf_info *buf_info);
124 int isp4sd_pwron_and_init(struct v4l2_subdev *sd);
125 int isp4sd_pwroff_and_deinit(struct v4l2_subdev *sd);
126 
127 #endif /* _ISP4_SUBDEV_H_ */
128