18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * vsp1_pipe.h  --  R-Car VSP1 Pipeline
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2013-2015 Renesas Electronics Corporation
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci#ifndef __VSP1_PIPE_H__
108c2ecf20Sopenharmony_ci#define __VSP1_PIPE_H__
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/kref.h>
138c2ecf20Sopenharmony_ci#include <linux/list.h>
148c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
158c2ecf20Sopenharmony_ci#include <linux/wait.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <media/media-entity.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cistruct vsp1_dl_list;
208c2ecf20Sopenharmony_cistruct vsp1_rwpf;
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci/*
238c2ecf20Sopenharmony_ci * struct vsp1_format_info - VSP1 video format description
248c2ecf20Sopenharmony_ci * @fourcc: V4L2 pixel format FCC identifier
258c2ecf20Sopenharmony_ci * @mbus: media bus format code
268c2ecf20Sopenharmony_ci * @hwfmt: VSP1 hardware format
278c2ecf20Sopenharmony_ci * @swap: swap register control
288c2ecf20Sopenharmony_ci * @planes: number of planes
298c2ecf20Sopenharmony_ci * @bpp: bits per pixel
308c2ecf20Sopenharmony_ci * @swap_yc: the Y and C components are swapped (Y comes before C)
318c2ecf20Sopenharmony_ci * @swap_uv: the U and V components are swapped (V comes before U)
328c2ecf20Sopenharmony_ci * @hsub: horizontal subsampling factor
338c2ecf20Sopenharmony_ci * @vsub: vertical subsampling factor
348c2ecf20Sopenharmony_ci * @alpha: has an alpha channel
358c2ecf20Sopenharmony_ci */
368c2ecf20Sopenharmony_cistruct vsp1_format_info {
378c2ecf20Sopenharmony_ci	u32 fourcc;
388c2ecf20Sopenharmony_ci	unsigned int mbus;
398c2ecf20Sopenharmony_ci	unsigned int hwfmt;
408c2ecf20Sopenharmony_ci	unsigned int swap;
418c2ecf20Sopenharmony_ci	unsigned int planes;
428c2ecf20Sopenharmony_ci	unsigned int bpp[3];
438c2ecf20Sopenharmony_ci	bool swap_yc;
448c2ecf20Sopenharmony_ci	bool swap_uv;
458c2ecf20Sopenharmony_ci	unsigned int hsub;
468c2ecf20Sopenharmony_ci	unsigned int vsub;
478c2ecf20Sopenharmony_ci	bool alpha;
488c2ecf20Sopenharmony_ci};
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cienum vsp1_pipeline_state {
518c2ecf20Sopenharmony_ci	VSP1_PIPELINE_STOPPED,
528c2ecf20Sopenharmony_ci	VSP1_PIPELINE_RUNNING,
538c2ecf20Sopenharmony_ci	VSP1_PIPELINE_STOPPING,
548c2ecf20Sopenharmony_ci};
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci/*
578c2ecf20Sopenharmony_ci * struct vsp1_partition_window - Partition window coordinates
588c2ecf20Sopenharmony_ci * @left: horizontal coordinate of the partition start in pixels relative to the
598c2ecf20Sopenharmony_ci *	  left edge of the image
608c2ecf20Sopenharmony_ci * @width: partition width in pixels
618c2ecf20Sopenharmony_ci */
628c2ecf20Sopenharmony_cistruct vsp1_partition_window {
638c2ecf20Sopenharmony_ci	unsigned int left;
648c2ecf20Sopenharmony_ci	unsigned int width;
658c2ecf20Sopenharmony_ci};
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci/*
688c2ecf20Sopenharmony_ci * struct vsp1_partition - A description of a slice for the partition algorithm
698c2ecf20Sopenharmony_ci * @rpf: The RPF partition window configuration
708c2ecf20Sopenharmony_ci * @uds_sink: The UDS input partition window configuration
718c2ecf20Sopenharmony_ci * @uds_source: The UDS output partition window configuration
728c2ecf20Sopenharmony_ci * @sru: The SRU partition window configuration
738c2ecf20Sopenharmony_ci * @wpf: The WPF partition window configuration
748c2ecf20Sopenharmony_ci */
758c2ecf20Sopenharmony_cistruct vsp1_partition {
768c2ecf20Sopenharmony_ci	struct vsp1_partition_window rpf;
778c2ecf20Sopenharmony_ci	struct vsp1_partition_window uds_sink;
788c2ecf20Sopenharmony_ci	struct vsp1_partition_window uds_source;
798c2ecf20Sopenharmony_ci	struct vsp1_partition_window sru;
808c2ecf20Sopenharmony_ci	struct vsp1_partition_window wpf;
818c2ecf20Sopenharmony_ci};
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci/*
848c2ecf20Sopenharmony_ci * struct vsp1_pipeline - A VSP1 hardware pipeline
858c2ecf20Sopenharmony_ci * @pipe: the media pipeline
868c2ecf20Sopenharmony_ci * @irqlock: protects the pipeline state
878c2ecf20Sopenharmony_ci * @state: current state
888c2ecf20Sopenharmony_ci * @wq: wait queue to wait for state change completion
898c2ecf20Sopenharmony_ci * @frame_end: frame end interrupt handler
908c2ecf20Sopenharmony_ci * @lock: protects the pipeline use count and stream count
918c2ecf20Sopenharmony_ci * @kref: pipeline reference count
928c2ecf20Sopenharmony_ci * @stream_count: number of streaming video nodes
938c2ecf20Sopenharmony_ci * @buffers_ready: bitmask of RPFs and WPFs with at least one buffer available
948c2ecf20Sopenharmony_ci * @sequence: frame sequence number
958c2ecf20Sopenharmony_ci * @num_inputs: number of RPFs
968c2ecf20Sopenharmony_ci * @inputs: array of RPFs in the pipeline (indexed by RPF index)
978c2ecf20Sopenharmony_ci * @output: WPF at the output of the pipeline
988c2ecf20Sopenharmony_ci * @brx: BRx entity, if present
998c2ecf20Sopenharmony_ci * @hgo: HGO entity, if present
1008c2ecf20Sopenharmony_ci * @hgt: HGT entity, if present
1018c2ecf20Sopenharmony_ci * @lif: LIF entity, if present
1028c2ecf20Sopenharmony_ci * @uds: UDS entity, if present
1038c2ecf20Sopenharmony_ci * @uds_input: entity at the input of the UDS, if the UDS is present
1048c2ecf20Sopenharmony_ci * @entities: list of entities in the pipeline
1058c2ecf20Sopenharmony_ci * @stream_config: cached stream configuration for video pipelines
1068c2ecf20Sopenharmony_ci * @configured: when false the @stream_config shall be written to the hardware
1078c2ecf20Sopenharmony_ci * @interlaced: True when the pipeline is configured in interlaced mode
1088c2ecf20Sopenharmony_ci * @partitions: The number of partitions used to process one frame
1098c2ecf20Sopenharmony_ci * @partition: The current partition for configuration to process
1108c2ecf20Sopenharmony_ci * @part_table: The pre-calculated partitions used by the pipeline
1118c2ecf20Sopenharmony_ci */
1128c2ecf20Sopenharmony_cistruct vsp1_pipeline {
1138c2ecf20Sopenharmony_ci	struct media_pipeline pipe;
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci	spinlock_t irqlock;
1168c2ecf20Sopenharmony_ci	enum vsp1_pipeline_state state;
1178c2ecf20Sopenharmony_ci	wait_queue_head_t wq;
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci	void (*frame_end)(struct vsp1_pipeline *pipe, unsigned int completion);
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci	struct mutex lock;
1228c2ecf20Sopenharmony_ci	struct kref kref;
1238c2ecf20Sopenharmony_ci	unsigned int stream_count;
1248c2ecf20Sopenharmony_ci	unsigned int buffers_ready;
1258c2ecf20Sopenharmony_ci	unsigned int sequence;
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci	unsigned int num_inputs;
1288c2ecf20Sopenharmony_ci	struct vsp1_rwpf *inputs[VSP1_MAX_RPF];
1298c2ecf20Sopenharmony_ci	struct vsp1_rwpf *output;
1308c2ecf20Sopenharmony_ci	struct vsp1_entity *brx;
1318c2ecf20Sopenharmony_ci	struct vsp1_entity *hgo;
1328c2ecf20Sopenharmony_ci	struct vsp1_entity *hgt;
1338c2ecf20Sopenharmony_ci	struct vsp1_entity *lif;
1348c2ecf20Sopenharmony_ci	struct vsp1_entity *uds;
1358c2ecf20Sopenharmony_ci	struct vsp1_entity *uds_input;
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci	/*
1388c2ecf20Sopenharmony_ci	 * The order of this list must be identical to the order of the entities
1398c2ecf20Sopenharmony_ci	 * in the pipeline, as it is assumed by the partition algorithm that we
1408c2ecf20Sopenharmony_ci	 * can walk this list in sequence.
1418c2ecf20Sopenharmony_ci	 */
1428c2ecf20Sopenharmony_ci	struct list_head entities;
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci	struct vsp1_dl_body *stream_config;
1458c2ecf20Sopenharmony_ci	bool configured;
1468c2ecf20Sopenharmony_ci	bool interlaced;
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci	unsigned int partitions;
1498c2ecf20Sopenharmony_ci	struct vsp1_partition *partition;
1508c2ecf20Sopenharmony_ci	struct vsp1_partition *part_table;
1518c2ecf20Sopenharmony_ci};
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_civoid vsp1_pipeline_reset(struct vsp1_pipeline *pipe);
1548c2ecf20Sopenharmony_civoid vsp1_pipeline_init(struct vsp1_pipeline *pipe);
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_civoid vsp1_pipeline_run(struct vsp1_pipeline *pipe);
1578c2ecf20Sopenharmony_cibool vsp1_pipeline_stopped(struct vsp1_pipeline *pipe);
1588c2ecf20Sopenharmony_ciint vsp1_pipeline_stop(struct vsp1_pipeline *pipe);
1598c2ecf20Sopenharmony_cibool vsp1_pipeline_ready(struct vsp1_pipeline *pipe);
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_civoid vsp1_pipeline_frame_end(struct vsp1_pipeline *pipe);
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_civoid vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
1648c2ecf20Sopenharmony_ci				   struct vsp1_dl_body *dlb,
1658c2ecf20Sopenharmony_ci				   unsigned int alpha);
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_civoid vsp1_pipeline_propagate_partition(struct vsp1_pipeline *pipe,
1688c2ecf20Sopenharmony_ci				       struct vsp1_partition *partition,
1698c2ecf20Sopenharmony_ci				       unsigned int index,
1708c2ecf20Sopenharmony_ci				       struct vsp1_partition_window *window);
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ciconst struct vsp1_format_info *vsp1_get_format_info(struct vsp1_device *vsp1,
1738c2ecf20Sopenharmony_ci						    u32 fourcc);
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci#endif /* __VSP1_PIPE_H__ */
176