linux/drivers/staging/media/omap4iss/iss_video.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0+ */
   2/*
   3 * TI OMAP4 ISS V4L2 Driver - Generic video node
   4 *
   5 * Copyright (C) 2012 Texas Instruments, Inc.
   6 *
   7 * Author: Sergio Aguirre <sergio.a.aguirre@gmail.com>
   8 */
   9
  10#ifndef OMAP4_ISS_VIDEO_H
  11#define OMAP4_ISS_VIDEO_H
  12
  13#include <linux/v4l2-mediabus.h>
  14#include <media/media-entity.h>
  15#include <media/v4l2-dev.h>
  16#include <media/v4l2-fh.h>
  17#include <media/videobuf2-v4l2.h>
  18#include <media/videobuf2-dma-contig.h>
  19
  20#define ISS_VIDEO_DRIVER_NAME           "issvideo"
  21#define ISS_VIDEO_DRIVER_VERSION        "0.0.2"
  22
  23struct iss_device;
  24struct iss_video;
  25struct v4l2_mbus_framefmt;
  26struct v4l2_pix_format;
  27
  28/*
  29 * struct iss_format_info - ISS media bus format information
  30 * @code: V4L2 media bus format code
  31 * @truncated: V4L2 media bus format code for the same format truncated to 10
  32 *      bits. Identical to @code if the format is 10 bits wide or less.
  33 * @uncompressed: V4L2 media bus format code for the corresponding uncompressed
  34 *      format. Identical to @code if the format is not DPCM compressed.
  35 * @flavor: V4L2 media bus format code for the same pixel layout but
  36 *      shifted to be 8 bits per pixel. =0 if format is not shiftable.
  37 * @pixelformat: V4L2 pixel format FCC identifier
  38 * @bpp: Bits per pixel
  39 * @description: Human-readable format description
  40 */
  41struct iss_format_info {
  42        u32 code;
  43        u32 truncated;
  44        u32 uncompressed;
  45        u32 flavor;
  46        u32 pixelformat;
  47        unsigned int bpp;
  48        const char *description;
  49};
  50
  51enum iss_pipeline_stream_state {
  52        ISS_PIPELINE_STREAM_STOPPED = 0,
  53        ISS_PIPELINE_STREAM_CONTINUOUS = 1,
  54        ISS_PIPELINE_STREAM_SINGLESHOT = 2,
  55};
  56
  57enum iss_pipeline_state {
  58        /* The stream has been started on the input video node. */
  59        ISS_PIPELINE_STREAM_INPUT = 1,
  60        /* The stream has been started on the output video node. */
  61        ISS_PIPELINE_STREAM_OUTPUT = (1 << 1),
  62        /* At least one buffer is queued on the input video node. */
  63        ISS_PIPELINE_QUEUE_INPUT = (1 << 2),
  64        /* At least one buffer is queued on the output video node. */
  65        ISS_PIPELINE_QUEUE_OUTPUT = (1 << 3),
  66        /* The input entity is idle, ready to be started. */
  67        ISS_PIPELINE_IDLE_INPUT = (1 << 4),
  68        /* The output entity is idle, ready to be started. */
  69        ISS_PIPELINE_IDLE_OUTPUT = (1 << 5),
  70        /* The pipeline is currently streaming. */
  71        ISS_PIPELINE_STREAM = (1 << 6),
  72};
  73
  74/*
  75 * struct iss_pipeline - An OMAP4 ISS hardware pipeline
  76 * @ent_enum: Entities in the pipeline
  77 * @error: A hardware error occurred during capture
  78 */
  79struct iss_pipeline {
  80        struct media_pipeline pipe;
  81        spinlock_t lock;                /* Pipeline state and queue flags */
  82        unsigned int state;
  83        enum iss_pipeline_stream_state stream_state;
  84        struct iss_video *input;
  85        struct iss_video *output;
  86        struct media_entity_enum ent_enum;
  87        atomic_t frame_number;
  88        bool do_propagation; /* of frame number */
  89        bool error;
  90        struct v4l2_fract max_timeperframe;
  91        struct v4l2_subdev *external;
  92        unsigned int external_rate;
  93        int external_bpp;
  94};
  95
  96#define to_iss_pipeline(__e) \
  97        container_of((__e)->pipe, struct iss_pipeline, pipe)
  98
  99static inline int iss_pipeline_ready(struct iss_pipeline *pipe)
 100{
 101        return pipe->state == (ISS_PIPELINE_STREAM_INPUT |
 102                               ISS_PIPELINE_STREAM_OUTPUT |
 103                               ISS_PIPELINE_QUEUE_INPUT |
 104                               ISS_PIPELINE_QUEUE_OUTPUT |
 105                               ISS_PIPELINE_IDLE_INPUT |
 106                               ISS_PIPELINE_IDLE_OUTPUT);
 107}
 108
 109/*
 110 * struct iss_buffer - ISS buffer
 111 * @buffer: ISS video buffer
 112 * @iss_addr: Physical address of the buffer.
 113 */
 114struct iss_buffer {
 115        /* common v4l buffer stuff -- must be first */
 116        struct vb2_v4l2_buffer  vb;
 117        struct list_head        list;
 118        dma_addr_t iss_addr;
 119};
 120
 121#define to_iss_buffer(buf)      container_of(buf, struct iss_buffer, vb)
 122
 123enum iss_video_dmaqueue_flags {
 124        /* Set if DMA queue becomes empty when ISS_PIPELINE_STREAM_CONTINUOUS */
 125        ISS_VIDEO_DMAQUEUE_UNDERRUN = (1 << 0),
 126        /* Set when queuing buffer to an empty DMA queue */
 127        ISS_VIDEO_DMAQUEUE_QUEUED = (1 << 1),
 128};
 129
 130#define iss_video_dmaqueue_flags_clr(video)     \
 131                        ({ (video)->dmaqueue_flags = 0; })
 132
 133/*
 134 * struct iss_video_operations - ISS video operations
 135 * @queue:      Resume streaming when a buffer is queued. Called on VIDIOC_QBUF
 136 *              if there was no buffer previously queued.
 137 */
 138struct iss_video_operations {
 139        int (*queue)(struct iss_video *video, struct iss_buffer *buffer);
 140};
 141
 142struct iss_video {
 143        struct video_device video;
 144        enum v4l2_buf_type type;
 145        struct media_pad pad;
 146
 147        struct mutex mutex;             /* format and crop settings */
 148        atomic_t active;
 149
 150        struct iss_device *iss;
 151
 152        unsigned int capture_mem;
 153        unsigned int bpl_alignment;     /* alignment value */
 154        unsigned int bpl_zero_padding;  /* whether the alignment is optional */
 155        unsigned int bpl_max;           /* maximum bytes per line value */
 156        unsigned int bpl_value;         /* bytes per line value */
 157        unsigned int bpl_padding;       /* padding at end of line */
 158
 159        /* Pipeline state */
 160        struct iss_pipeline pipe;
 161        struct mutex stream_lock;       /* pipeline and stream states */
 162        bool error;
 163
 164        /* Video buffers queue */
 165        struct vb2_queue *queue;
 166        spinlock_t qlock;               /* protects dmaqueue and error */
 167        struct list_head dmaqueue;
 168        enum iss_video_dmaqueue_flags dmaqueue_flags;
 169
 170        const struct iss_video_operations *ops;
 171};
 172
 173#define to_iss_video(vdev)      container_of(vdev, struct iss_video, video)
 174
 175struct iss_video_fh {
 176        struct v4l2_fh vfh;
 177        struct iss_video *video;
 178        struct vb2_queue queue;
 179        struct v4l2_format format;
 180        struct v4l2_fract timeperframe;
 181};
 182
 183#define to_iss_video_fh(fh)     container_of(fh, struct iss_video_fh, vfh)
 184#define iss_video_queue_to_iss_video_fh(q) \
 185                                container_of(q, struct iss_video_fh, queue)
 186
 187int omap4iss_video_init(struct iss_video *video, const char *name);
 188void omap4iss_video_cleanup(struct iss_video *video);
 189int omap4iss_video_register(struct iss_video *video,
 190                            struct v4l2_device *vdev);
 191void omap4iss_video_unregister(struct iss_video *video);
 192struct iss_buffer *omap4iss_video_buffer_next(struct iss_video *video);
 193void omap4iss_video_cancel_stream(struct iss_video *video);
 194struct media_pad *omap4iss_video_remote_pad(struct iss_video *video);
 195
 196const struct iss_format_info *
 197omap4iss_video_format_info(u32 code);
 198
 199#endif /* OMAP4_ISS_VIDEO_H */
 200