brintos

brintos / linux-shallow public Read only

0
0
Text · 6.5 KiB · 3fb009d Raw
215 lines · c
1/* SPDX-License-Identifier: GPL-2.0 */2/*3 * Copyright (C) STMicroelectronics SA 20144 * Authors: Fabien Dessenne <fabien.dessenne@st.com> for STMicroelectronics.5 */6 7#include <linux/clk.h>8#include <linux/ktime.h>9#include <linux/platform_device.h>10#include <linux/spinlock.h>11 12#include <media/v4l2-ctrls.h>13#include <media/v4l2-device.h>14#include <media/v4l2-mem2mem.h>15 16#include <media/videobuf2-dma-contig.h>17 18#define BDISP_NAME              "bdisp"19 20/*21 *  Max nb of nodes in node-list:22 *   - 2 nodes to handle wide 4K pictures23 *   - 2 nodes to handle two planes (Y & CbCr) */24#define MAX_OUTPUT_PLANES       225#define MAX_VERTICAL_STRIDES    226#define MAX_NB_NODE             (MAX_OUTPUT_PLANES * MAX_VERTICAL_STRIDES)27 28/* struct bdisp_ctrls - bdisp control set29 * @hflip:      horizontal flip30 * @vflip:      vertical flip31 */32struct bdisp_ctrls {33	struct v4l2_ctrl        *hflip;34	struct v4l2_ctrl        *vflip;35};36 37/**38 * struct bdisp_fmt - driver's internal color format data39 * @pixelformat:fourcc code for this format40 * @nb_planes:  number of planes  (ex: [0]=RGB/Y - [1]=Cb/Cr, ...)41 * @bpp:        bits per pixel (general)42 * @bpp_plane0: byte per pixel for the 1st plane43 * @w_align:    width alignment in pixel (multiple of)44 * @h_align:    height alignment in pixel (multiple of)45 */46struct bdisp_fmt {47	u32                     pixelformat;48	u8                      nb_planes;49	u8                      bpp;50	u8                      bpp_plane0;51	u8                      w_align;52	u8                      h_align;53};54 55/**56 * struct bdisp_frame - frame properties57 *58 * @width:      frame width (including padding)59 * @height:     frame height (including padding)60 * @fmt:        pointer to frame format descriptor61 * @field:      frame / field type62 * @bytesperline: stride of the 1st plane63 * @sizeimage:  image size in bytes64 * @colorspace: colorspace65 * @crop:       crop area66 * @paddr:      image physical addresses per plane ([0]=RGB/Y - [1]=Cb/Cr, ...)67 */68struct bdisp_frame {69	u32                     width;70	u32                     height;71	const struct bdisp_fmt  *fmt;72	enum v4l2_field         field;73	u32                     bytesperline;74	u32                     sizeimage;75	enum v4l2_colorspace    colorspace;76	struct v4l2_rect        crop;77	dma_addr_t              paddr[4];78};79 80/**81 * struct bdisp_request - bdisp request82 *83 * @src:        source frame properties84 * @dst:        destination frame properties85 * @hflip:      horizontal flip86 * @vflip:      vertical flip87 * @nb_req:     number of run request88 */89struct bdisp_request {90	struct bdisp_frame      src;91	struct bdisp_frame      dst;92	unsigned int            hflip:1;93	unsigned int            vflip:1;94	int                     nb_req;95};96 97/**98 * struct bdisp_ctx - device context data99 *100 * @src:        source frame properties101 * @dst:        destination frame properties102 * @state:      flags to keep track of user configuration103 * @hflip:      horizontal flip104 * @vflip:      vertical flip105 * @bdisp_dev:  the device this context applies to106 * @node:       node array107 * @node_paddr: node physical address array108 * @fh:         v4l2 file handle109 * @ctrl_handler: v4l2 controls handler110 * @bdisp_ctrls: bdisp control set111 * @ctrls_rdy:  true if the control handler is initialized112 */113struct bdisp_ctx {114	struct bdisp_frame      src;115	struct bdisp_frame      dst;116	u32                     state;117	unsigned int            hflip:1;118	unsigned int            vflip:1;119	struct bdisp_dev        *bdisp_dev;120	struct bdisp_node       *node[MAX_NB_NODE];121	dma_addr_t              node_paddr[MAX_NB_NODE];122	struct v4l2_fh          fh;123	struct v4l2_ctrl_handler ctrl_handler;124	struct bdisp_ctrls      bdisp_ctrls;125	bool                    ctrls_rdy;126};127 128/**129 * struct bdisp_m2m_device - v4l2 memory-to-memory device data130 *131 * @vdev:       video device node for v4l2 m2m mode132 * @m2m_dev:    v4l2 m2m device data133 * @ctx:        hardware context data134 * @refcnt:     reference counter135 */136struct bdisp_m2m_device {137	struct video_device     *vdev;138	struct v4l2_m2m_dev     *m2m_dev;139	struct bdisp_ctx        *ctx;140	int                     refcnt;141};142 143/**144 * struct bdisp_dbg - debug info145 *146 * @debugfs_entry: debugfs147 * @copy_node:     array of last used nodes148 * @copy_request:  last bdisp request149 * @hw_start:      start time of last HW request150 * @last_duration: last HW processing duration in microsecs151 * @min_duration:  min HW processing duration in microsecs152 * @max_duration:  max HW processing duration in microsecs153 * @tot_duration:  total HW processing duration in microsecs154 */155struct bdisp_dbg {156	struct dentry           *debugfs_entry;157	struct bdisp_node       *copy_node[MAX_NB_NODE];158	struct bdisp_request    copy_request;159	ktime_t                 hw_start;160	s64                     last_duration;161	s64                     min_duration;162	s64                     max_duration;163	s64                     tot_duration;164};165 166/**167 * struct bdisp_dev - abstraction for bdisp entity168 *169 * @v4l2_dev:   v4l2 device170 * @vdev:       video device171 * @pdev:       platform device172 * @dev:        device173 * @lock:       mutex protecting this data structure174 * @slock:      spinlock protecting this data structure175 * @id:         device index176 * @m2m:        memory-to-memory V4L2 device information177 * @state:      flags used to synchronize m2m and capture mode operation178 * @clock:      IP clock179 * @regs:       registers180 * @irq_queue:  interrupt handler waitqueue181 * @work_queue: workqueue to handle timeouts182 * @timeout_work: IRQ timeout structure183 * @dbg:        debug info184 */185struct bdisp_dev {186	struct v4l2_device      v4l2_dev;187	struct video_device     vdev;188	struct platform_device  *pdev;189	struct device           *dev;190	spinlock_t              slock;191	struct mutex            lock;192	u16                     id;193	struct bdisp_m2m_device m2m;194	unsigned long           state;195	struct clk              *clock;196	void __iomem            *regs;197	wait_queue_head_t       irq_queue;198	struct workqueue_struct *work_queue;199	struct delayed_work     timeout_work;200	struct bdisp_dbg        dbg;201};202 203void bdisp_hw_free_nodes(struct bdisp_ctx *ctx);204int bdisp_hw_alloc_nodes(struct bdisp_ctx *ctx);205void bdisp_hw_free_filters(struct device *dev);206int bdisp_hw_alloc_filters(struct device *dev);207int bdisp_hw_reset(struct bdisp_dev *bdisp);208int bdisp_hw_get_and_clear_irq(struct bdisp_dev *bdisp);209int bdisp_hw_update(struct bdisp_ctx *ctx);210 211void bdisp_debugfs_remove(struct bdisp_dev *bdisp);212void bdisp_debugfs_create(struct bdisp_dev *bdisp);213void bdisp_dbg_perf_begin(struct bdisp_dev *bdisp);214void bdisp_dbg_perf_end(struct bdisp_dev *bdisp);215