1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* Copyright (C) 2013--2024 Intel Corporation */ 3 4 #ifndef IPU6_ISYS_VIDEO_H 5 #define IPU6_ISYS_VIDEO_H 6 7 #include <linux/atomic.h> 8 #include <linux/completion.h> 9 #include <linux/container_of.h> 10 #include <linux/list.h> 11 #include <linux/mutex.h> 12 13 #include <media/media-entity.h> 14 #include <media/v4l2-dev.h> 15 16 #include "ipu6-isys-queue.h" 17 18 #define IPU6_ISYS_OUTPUT_PINS 11 19 #define IPU6_ISYS_MAX_PARALLEL_SOF 2 20 21 struct file; 22 struct ipu6_isys; 23 struct ipu6_isys_csi2; 24 struct ipu6_isys_subdev; 25 26 struct ipu6_isys_pixelformat { 27 u32 pixelformat; 28 u32 bpp; 29 u32 bpp_packed; 30 u32 code; 31 u32 css_pixelformat; 32 bool is_meta; 33 }; 34 35 struct sequence_info { 36 unsigned int sequence; 37 u64 timestamp; 38 }; 39 40 /* 41 * Align with firmware stream. Each stream represents a CSI virtual channel. 42 * May map to multiple video devices 43 */ 44 struct ipu6_isys_stream { 45 struct mutex mutex; 46 struct media_entity *source_entity; 47 atomic_t sequence; 48 unsigned int seq_index; 49 struct sequence_info seq[IPU6_ISYS_MAX_PARALLEL_SOF]; 50 int stream_source; 51 int stream_handle; 52 unsigned int nr_output_pins; 53 struct ipu6_isys_subdev *asd; 54 55 int nr_queues; /* Number of capture queues */ 56 int nr_streaming; 57 int streaming; /* Has streaming been really started? */ 58 struct list_head queues; 59 struct completion stream_open_completion; 60 struct completion stream_close_completion; 61 struct completion stream_start_completion; 62 struct completion stream_stop_completion; 63 struct ipu6_isys *isys; 64 65 struct ipu6_isys_queue *output_pins_queue[IPU6_ISYS_OUTPUT_PINS]; 66 int error; 67 u8 vc; 68 }; 69 70 struct video_stream_watermark { 71 u32 width; 72 u32 height; 73 u32 hblank; 74 u32 frame_rate; 75 u64 pixel_rate; 76 u64 stream_data_rate; 77 u16 sram_gran_shift; 78 u16 sram_gran_size; 79 struct list_head stream_node; 80 }; 81 82 struct ipu6_isys_video { 83 struct ipu6_isys_queue aq; 84 /* Serialise access to other fields in the struct. */ 85 struct mutex mutex; 86 struct media_pad pad; 87 struct video_device vdev; 88 struct v4l2_pix_format pix_fmt; 89 struct v4l2_meta_format meta_fmt; 90 struct ipu6_isys *isys; 91 struct ipu6_isys_csi2 *csi2; 92 struct ipu6_isys_stream *stream; 93 unsigned int streaming; 94 struct video_stream_watermark watermark; 95 u32 source_stream; 96 u8 vc; 97 u8 dt; 98 }; 99 100 #define ipu6_isys_queue_to_video(__aq) \ 101 container_of(__aq, struct ipu6_isys_video, aq) 102 103 extern const struct ipu6_isys_pixelformat ipu6_isys_pfmts[]; 104 extern const struct ipu6_isys_pixelformat ipu6_isys_pfmts_packed[]; 105 106 const struct ipu6_isys_pixelformat * 107 ipu6_isys_get_isys_format(u32 pixelformat, u32 code); 108 int ipu6_isys_video_prepare_stream(struct ipu6_isys_video *av, 109 struct media_entity *source_entity, 110 int nr_queues); 111 int ipu6_isys_video_set_streaming(struct ipu6_isys_video *av, int state, 112 struct ipu6_isys_buffer_list *bl); 113 int ipu6_isys_fw_open(struct ipu6_isys *isys); 114 void ipu6_isys_fw_close(struct ipu6_isys *isys); 115 int ipu6_isys_setup_video(struct ipu6_isys_video *av, 116 struct media_entity **source_entity, int *nr_queues); 117 int ipu6_isys_video_init(struct ipu6_isys_video *av); 118 void ipu6_isys_video_cleanup(struct ipu6_isys_video *av); 119 void ipu6_isys_put_stream(struct ipu6_isys_stream *stream); 120 struct ipu6_isys_stream * 121 ipu6_isys_query_stream_by_handle(struct ipu6_isys *isys, u8 stream_handle); 122 struct ipu6_isys_stream * 123 ipu6_isys_query_stream_by_source(struct ipu6_isys *isys, int source, u8 vc); 124 125 void ipu6_isys_configure_stream_watermark(struct ipu6_isys_video *av, 126 bool state); 127 void ipu6_isys_update_stream_watermark(struct ipu6_isys_video *av, bool state); 128 129 u32 ipu6_isys_get_format(struct ipu6_isys_video *av); 130 u32 ipu6_isys_get_data_size(struct ipu6_isys_video *av); 131 u32 ipu6_isys_get_bytes_per_line(struct ipu6_isys_video *av); 132 u32 ipu6_isys_get_frame_width(struct ipu6_isys_video *av); 133 u32 ipu6_isys_get_frame_height(struct ipu6_isys_video *av); 134 135 #endif /* IPU6_ISYS_VIDEO_H */ 136