linux/drivers/media/platform/omap3isp/ispvideo.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0-only */
   2/*
   3 * ispvideo.h
   4 *
   5 * TI OMAP3 ISP - Generic video node
   6 *
   7 * Copyright (C) 2009-2010 Nokia Corporation
   8 *
   9 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  10 *           Sakari Ailus <sakari.ailus@iki.fi>
  11 */
  12
  13#ifndef OMAP3_ISP_VIDEO_H
  14#define OMAP3_ISP_VIDEO_H
  15
  16#include <linux/v4l2-mediabus.h>
  17#include <media/media-entity.h>
  18#include <media/v4l2-dev.h>
  19#include <media/v4l2-fh.h>
  20#include <media/videobuf2-v4l2.h>
  21
  22#define ISP_VIDEO_DRIVER_NAME           "ispvideo"
  23#define ISP_VIDEO_DRIVER_VERSION        "0.0.2"
  24
  25struct isp_device;
  26struct isp_video;
  27struct v4l2_mbus_framefmt;
  28struct v4l2_pix_format;
  29
  30/*
  31 * struct isp_format_info - ISP media bus format information
  32 * @code: V4L2 media bus format code
  33 * @truncated: V4L2 media bus format code for the same format truncated to 10
  34 *      bits. Identical to @code if the format is 10 bits wide or less.
  35 * @uncompressed: V4L2 media bus format code for the corresponding uncompressed
  36 *      format. Identical to @code if the format is not DPCM compressed.
  37 * @flavor: V4L2 media bus format code for the same pixel layout but
  38 *      shifted to be 8 bits per pixel. =0 if format is not shiftable.
  39 * @pixelformat: V4L2 pixel format FCC identifier
  40 * @width: Bits per pixel (when transferred over a bus)
  41 * @bpp: Bytes per pixel (when stored in memory)
  42 */
  43struct isp_format_info {
  44        u32 code;
  45        u32 truncated;
  46        u32 uncompressed;
  47        u32 flavor;
  48        u32 pixelformat;
  49        unsigned int width;
  50        unsigned int bpp;
  51};
  52
  53enum isp_pipeline_stream_state {
  54        ISP_PIPELINE_STREAM_STOPPED = 0,
  55        ISP_PIPELINE_STREAM_CONTINUOUS = 1,
  56        ISP_PIPELINE_STREAM_SINGLESHOT = 2,
  57};
  58
  59enum isp_pipeline_state {
  60        /* The stream has been started on the input video node. */
  61        ISP_PIPELINE_STREAM_INPUT = 1,
  62        /* The stream has been started on the output video node. */
  63        ISP_PIPELINE_STREAM_OUTPUT = 2,
  64        /* At least one buffer is queued on the input video node. */
  65        ISP_PIPELINE_QUEUE_INPUT = 4,
  66        /* At least one buffer is queued on the output video node. */
  67        ISP_PIPELINE_QUEUE_OUTPUT = 8,
  68        /* The input entity is idle, ready to be started. */
  69        ISP_PIPELINE_IDLE_INPUT = 16,
  70        /* The output entity is idle, ready to be started. */
  71        ISP_PIPELINE_IDLE_OUTPUT = 32,
  72        /* The pipeline is currently streaming. */
  73        ISP_PIPELINE_STREAM = 64,
  74};
  75
  76/*
  77 * struct isp_pipeline - An ISP hardware pipeline
  78 * @field: The field being processed by the pipeline
  79 * @error: A hardware error occurred during capture
  80 * @ent_enum: Entities in the pipeline
  81 */
  82struct isp_pipeline {
  83        struct media_pipeline pipe;
  84        spinlock_t lock;                /* Pipeline state and queue flags */
  85        unsigned int state;
  86        enum isp_pipeline_stream_state stream_state;
  87        struct isp_video *input;
  88        struct isp_video *output;
  89        struct media_entity_enum ent_enum;
  90        unsigned long l3_ick;
  91        unsigned int max_rate;
  92        enum v4l2_field field;
  93        atomic_t frame_number;
  94        bool do_propagation; /* of frame number */
  95        bool error;
  96        struct v4l2_fract max_timeperframe;
  97        struct v4l2_subdev *external;
  98        unsigned int external_rate;
  99        unsigned int external_width;
 100};
 101
 102#define to_isp_pipeline(__e) \
 103        container_of((__e)->pipe, struct isp_pipeline, pipe)
 104
 105static inline int isp_pipeline_ready(struct isp_pipeline *pipe)
 106{
 107        return pipe->state == (ISP_PIPELINE_STREAM_INPUT |
 108                               ISP_PIPELINE_STREAM_OUTPUT |
 109                               ISP_PIPELINE_QUEUE_INPUT |
 110                               ISP_PIPELINE_QUEUE_OUTPUT |
 111                               ISP_PIPELINE_IDLE_INPUT |
 112                               ISP_PIPELINE_IDLE_OUTPUT);
 113}
 114
 115/**
 116 * struct isp_buffer - ISP video buffer
 117 * @vb: videobuf2 buffer
 118 * @irqlist: List head for insertion into IRQ queue
 119 * @dma: DMA address
 120 */
 121struct isp_buffer {
 122        struct vb2_v4l2_buffer vb;
 123        struct list_head irqlist;
 124        dma_addr_t dma;
 125};
 126
 127#define to_isp_buffer(buf)      container_of(buf, struct isp_buffer, vb)
 128
 129enum isp_video_dmaqueue_flags {
 130        /* Set if DMA queue becomes empty when ISP_PIPELINE_STREAM_CONTINUOUS */
 131        ISP_VIDEO_DMAQUEUE_UNDERRUN = (1 << 0),
 132        /* Set when queuing buffer to an empty DMA queue */
 133        ISP_VIDEO_DMAQUEUE_QUEUED = (1 << 1),
 134};
 135
 136#define isp_video_dmaqueue_flags_clr(video)     \
 137                        ({ (video)->dmaqueue_flags = 0; })
 138
 139/*
 140 * struct isp_video_operations - ISP video operations
 141 * @queue:      Resume streaming when a buffer is queued. Called on VIDIOC_QBUF
 142 *              if there was no buffer previously queued.
 143 */
 144struct isp_video_operations {
 145        int(*queue)(struct isp_video *video, struct isp_buffer *buffer);
 146};
 147
 148struct isp_video {
 149        struct video_device video;
 150        enum v4l2_buf_type type;
 151        struct media_pad pad;
 152
 153        struct mutex mutex;             /* format and crop settings */
 154        atomic_t active;
 155
 156        struct isp_device *isp;
 157
 158        unsigned int capture_mem;
 159        unsigned int bpl_alignment;     /* alignment value */
 160        unsigned int bpl_zero_padding;  /* whether the alignment is optional */
 161        unsigned int bpl_max;           /* maximum bytes per line value */
 162        unsigned int bpl_value;         /* bytes per line value */
 163        unsigned int bpl_padding;       /* padding at end of line */
 164
 165        /* Pipeline state */
 166        struct isp_pipeline pipe;
 167        struct mutex stream_lock;       /* pipeline and stream states */
 168        bool error;
 169
 170        /* Video buffers queue */
 171        struct vb2_queue *queue;
 172        struct mutex queue_lock;        /* protects the queue */
 173        spinlock_t irqlock;             /* protects dmaqueue */
 174        struct list_head dmaqueue;
 175        enum isp_video_dmaqueue_flags dmaqueue_flags;
 176
 177        const struct isp_video_operations *ops;
 178};
 179
 180#define to_isp_video(vdev)      container_of(vdev, struct isp_video, video)
 181
 182struct isp_video_fh {
 183        struct v4l2_fh vfh;
 184        struct isp_video *video;
 185        struct vb2_queue queue;
 186        struct v4l2_format format;
 187        struct v4l2_fract timeperframe;
 188};
 189
 190#define to_isp_video_fh(fh)     container_of(fh, struct isp_video_fh, vfh)
 191#define isp_video_queue_to_isp_video_fh(q) \
 192                                container_of(q, struct isp_video_fh, queue)
 193
 194int omap3isp_video_init(struct isp_video *video, const char *name);
 195void omap3isp_video_cleanup(struct isp_video *video);
 196int omap3isp_video_register(struct isp_video *video,
 197                            struct v4l2_device *vdev);
 198void omap3isp_video_unregister(struct isp_video *video);
 199struct isp_buffer *omap3isp_video_buffer_next(struct isp_video *video);
 200void omap3isp_video_cancel_stream(struct isp_video *video);
 201void omap3isp_video_resume(struct isp_video *video, int continuous);
 202struct media_pad *omap3isp_video_remote_pad(struct isp_video *video);
 203
 204const struct isp_format_info *
 205omap3isp_video_format_info(u32 code);
 206
 207#endif /* OMAP3_ISP_VIDEO_H */
 208