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 21 /* 22 * One is for none sensor specific response which is not used now. 23 * Another is for sensor specific response 24 */ 25 #define ISP4SD_MAX_FW_RESP_STREAM_NUM 2 26 27 /* Indicates the ISP status */ 28 enum isp4sd_status { 29 ISP4SD_STATUS_PWR_OFF, 30 ISP4SD_STATUS_PWR_ON, 31 ISP4SD_STATUS_FW_RUNNING, 32 ISP4SD_STATUS_MAX 33 }; 34 35 /* Indicates sensor and output stream status */ 36 enum isp4sd_start_status { 37 ISP4SD_START_STATUS_OFF, 38 ISP4SD_START_STATUS_STARTED, 39 ISP4SD_START_STATUS_START_FAIL, 40 }; 41 42 struct isp4sd_img_buf_node { 43 struct list_head node; 44 struct isp4if_img_buf_info buf_info; 45 }; 46 47 /* This is ISP output after processing Bayer raw sensor input */ 48 struct isp4sd_output_info { 49 enum isp4sd_start_status start_status; 50 u32 image_size; 51 }; 52 53 /* 54 * Struct for sensor info used as ISP input or source. 55 * status: sensor status. 56 * output_info: ISP output after processing the sensor input. 57 * start_stream_cmd_sent: indicates if ISP4FW_CMD_ID_START_STREAM was sent 58 * to firmware. 59 * buf_sent_cnt: number of buffers sent to receive images. 60 */ 61 struct isp4sd_sensor_info { 62 struct isp4sd_output_info output_info; 63 enum isp4sd_start_status status; 64 bool start_stream_cmd_sent; 65 u32 buf_sent_cnt; 66 }; 67 68 /* 69 * The thread is created by the driver to handle firmware responses which will 70 * be waken up when a firmware-to-driver response interrupt occurs. 71 */ 72 struct isp4sd_thread_handler { 73 struct task_struct *thread; 74 wait_queue_head_t waitq; 75 bool resp_ready; 76 }; 77 78 struct isp4_subdev_thread_param { 79 u32 idx; 80 struct isp4_subdev *isp_subdev; 81 }; 82 83 struct isp4_subdev { 84 struct v4l2_subdev sdev; 85 struct isp4_interface ispif; 86 87 struct media_pad sdev_pad; 88 89 enum isp4sd_status isp_status; 90 /* mutex used to synchronize the operation with firmware */ 91 struct mutex ops_mutex; 92 93 struct isp4sd_thread_handler 94 fw_resp_thread[ISP4SD_MAX_FW_RESP_STREAM_NUM]; 95 96 u32 host2fw_seq_num; 97 98 struct isp4sd_sensor_info sensor_info; 99 100 /* gpio descriptor */ 101 struct gpio_desc *enable_gpio; 102 struct device *dev; 103 void __iomem *mmio; 104 struct isp4_subdev_thread_param 105 isp_resp_para[ISP4SD_MAX_FW_RESP_STREAM_NUM]; 106 int irq[ISP4SD_MAX_FW_RESP_STREAM_NUM]; 107 bool irq_enabled; 108 /* spin lock to access ISP_SYS_INT0_EN exclusively */ 109 spinlock_t irq_lock; 110 }; 111 112 int isp4sd_init(struct isp4_subdev *isp_subdev, struct v4l2_device *v4l2_dev, 113 int irq[ISP4SD_MAX_FW_RESP_STREAM_NUM]); 114 void isp4sd_deinit(struct isp4_subdev *isp_subdev); 115 int isp4sd_ioc_send_img_buf(struct v4l2_subdev *sd, 116 struct isp4if_img_buf_info *buf_info); 117 int isp4sd_pwron_and_init(struct v4l2_subdev *sd); 118 int isp4sd_pwroff_and_deinit(struct v4l2_subdev *sd); 119 120 #endif /* _ISP4_SUBDEV_H_ */ 121