linux/drivers/media/platform/exynos4-is/fimc-lite.h
<<
>>
Prefs
   1/*
   2 * Copyright (C) 2012 Samsung Electronics Co., Ltd.
   3 *
   4 * This program is free software; you can redistribute it and/or modify
   5 * it under the terms of the GNU General Public License version 2 as
   6 * published by the Free Software Foundation.
   7 */
   8
   9#ifndef FIMC_LITE_H_
  10#define FIMC_LITE_H_
  11
  12#include <linux/sizes.h>
  13#include <linux/io.h>
  14#include <linux/irqreturn.h>
  15#include <linux/platform_device.h>
  16#include <linux/sched.h>
  17#include <linux/spinlock.h>
  18#include <linux/types.h>
  19#include <linux/videodev2.h>
  20
  21#include <media/media-entity.h>
  22#include <media/videobuf2-core.h>
  23#include <media/v4l2-ctrls.h>
  24#include <media/v4l2-device.h>
  25#include <media/v4l2-mediabus.h>
  26#include <media/s5p_fimc.h>
  27
  28#define FIMC_LITE_DRV_NAME      "exynos-fimc-lite"
  29#define FLITE_CLK_NAME          "flite"
  30#define FIMC_LITE_MAX_DEVS      2
  31#define FLITE_REQ_BUFS_MIN      2
  32
  33/* Bit index definitions for struct fimc_lite::state */
  34enum {
  35        ST_FLITE_LPM,
  36        ST_FLITE_PENDING,
  37        ST_FLITE_RUN,
  38        ST_FLITE_STREAM,
  39        ST_FLITE_SUSPENDED,
  40        ST_FLITE_OFF,
  41        ST_FLITE_IN_USE,
  42        ST_FLITE_CONFIG,
  43        ST_SENSOR_STREAM,
  44};
  45
  46#define FLITE_SD_PAD_SINK       0
  47#define FLITE_SD_PAD_SOURCE_DMA 1
  48#define FLITE_SD_PAD_SOURCE_ISP 2
  49#define FLITE_SD_PADS_NUM       3
  50
  51struct flite_drvdata {
  52        unsigned short max_width;
  53        unsigned short max_height;
  54        unsigned short out_width_align;
  55        unsigned short win_hor_offs_align;
  56        unsigned short out_hor_offs_align;
  57};
  58
  59#define fimc_lite_get_drvdata(_pdev) \
  60        ((struct flite_drvdata *) platform_get_device_id(_pdev)->driver_data)
  61
  62struct fimc_lite_events {
  63        unsigned int data_overflow;
  64};
  65
  66#define FLITE_MAX_PLANES        1
  67
  68/**
  69 * struct flite_frame - source/target frame properties
  70 * @f_width: full pixel width
  71 * @f_height: full pixel height
  72 * @rect: crop/composition rectangle
  73 * @fmt: pointer to pixel format description data structure
  74 */
  75struct flite_frame {
  76        u16 f_width;
  77        u16 f_height;
  78        struct v4l2_rect rect;
  79        const struct fimc_fmt *fmt;
  80};
  81
  82/**
  83 * struct flite_buffer - video buffer structure
  84 * @vb:    vb2 buffer
  85 * @list:  list head for the buffers queue
  86 * @paddr: precalculated physical address
  87 */
  88struct flite_buffer {
  89        struct vb2_buffer vb;
  90        struct list_head list;
  91        dma_addr_t paddr;
  92};
  93
  94/**
  95 * struct fimc_lite - fimc lite structure
  96 * @pdev: pointer to FIMC-LITE platform device
  97 * @dd: SoC specific driver data structure
  98 * @v4l2_dev: pointer to top the level v4l2_device
  99 * @vfd: video device node
 100 * @fh: v4l2 file handle
 101 * @alloc_ctx: videobuf2 memory allocator context
 102 * @subdev: FIMC-LITE subdev
 103 * @vd_pad: media (sink) pad for the capture video node
 104 * @subdev_pads: the subdev media pads
 105 * @sensor: sensor subdev attached to FIMC-LITE directly or through MIPI-CSIS
 106 * @ctrl_handler: v4l2 control handler
 107 * @test_pattern: test pattern controls
 108 * @index: FIMC-LITE platform device index
 109 * @pipeline: video capture pipeline data structure
 110 * @pipeline_ops: media pipeline ops for the video node driver
 111 * @slock: spinlock protecting this data structure and the hw registers
 112 * @lock: mutex serializing video device and the subdev operations
 113 * @clock: FIMC-LITE gate clock
 114 * @regs: memory mapped io registers
 115 * @irq_queue: interrupt handler waitqueue
 116 * @payload: image size in bytes (w x h x bpp)
 117 * @inp_frame: camera input frame structure
 118 * @out_frame: DMA output frame structure
 119 * @out_path: output data path (DMA or FIFO)
 120 * @source_subdev_grp_id: source subdev group id
 121 * @state: driver state flags
 122 * @pending_buf_q: pending buffers queue head
 123 * @active_buf_q: the queue head of buffers scheduled in hardware
 124 * @vb_queue: vb2 buffers queue
 125 * @active_buf_count: number of video buffers scheduled in hardware
 126 * @frame_count: the captured frames counter
 127 * @reqbufs_count: the number of buffers requested with REQBUFS ioctl
 128 * @ref_count: driver's private reference counter
 129 */
 130struct fimc_lite {
 131        struct platform_device  *pdev;
 132        struct flite_drvdata    *dd;
 133        struct v4l2_device      *v4l2_dev;
 134        struct video_device     vfd;
 135        struct v4l2_fh          fh;
 136        struct vb2_alloc_ctx    *alloc_ctx;
 137        struct v4l2_subdev      subdev;
 138        struct media_pad        vd_pad;
 139        struct media_pad        subdev_pads[FLITE_SD_PADS_NUM];
 140        struct v4l2_subdev      *sensor;
 141        struct v4l2_ctrl_handler ctrl_handler;
 142        struct v4l2_ctrl        *test_pattern;
 143        int                     index;
 144        struct fimc_pipeline    pipeline;
 145        const struct fimc_pipeline_ops *pipeline_ops;
 146
 147        struct mutex            lock;
 148        spinlock_t              slock;
 149
 150        struct clk              *clock;
 151        void __iomem            *regs;
 152        wait_queue_head_t       irq_queue;
 153
 154        unsigned long           payload[FLITE_MAX_PLANES];
 155        struct flite_frame      inp_frame;
 156        struct flite_frame      out_frame;
 157        atomic_t                out_path;
 158        unsigned int            source_subdev_grp_id;
 159
 160        unsigned long           state;
 161        struct list_head        pending_buf_q;
 162        struct list_head        active_buf_q;
 163        struct vb2_queue        vb_queue;
 164        unsigned int            frame_count;
 165        unsigned int            reqbufs_count;
 166        int                     ref_count;
 167
 168        struct fimc_lite_events events;
 169        bool                    streaming;
 170};
 171
 172static inline bool fimc_lite_active(struct fimc_lite *fimc)
 173{
 174        unsigned long flags;
 175        bool ret;
 176
 177        spin_lock_irqsave(&fimc->slock, flags);
 178        ret = fimc->state & (1 << ST_FLITE_RUN) ||
 179                fimc->state & (1 << ST_FLITE_PENDING);
 180        spin_unlock_irqrestore(&fimc->slock, flags);
 181        return ret;
 182}
 183
 184static inline void fimc_lite_active_queue_add(struct fimc_lite *dev,
 185                                         struct flite_buffer *buf)
 186{
 187        list_add_tail(&buf->list, &dev->active_buf_q);
 188}
 189
 190static inline struct flite_buffer *fimc_lite_active_queue_pop(
 191                                        struct fimc_lite *dev)
 192{
 193        struct flite_buffer *buf = list_entry(dev->active_buf_q.next,
 194                                              struct flite_buffer, list);
 195        list_del(&buf->list);
 196        return buf;
 197}
 198
 199static inline void fimc_lite_pending_queue_add(struct fimc_lite *dev,
 200                                        struct flite_buffer *buf)
 201{
 202        list_add_tail(&buf->list, &dev->pending_buf_q);
 203}
 204
 205static inline struct flite_buffer *fimc_lite_pending_queue_pop(
 206                                        struct fimc_lite *dev)
 207{
 208        struct flite_buffer *buf = list_entry(dev->pending_buf_q.next,
 209                                              struct flite_buffer, list);
 210        list_del(&buf->list);
 211        return buf;
 212}
 213
 214#endif /* FIMC_LITE_H_ */
 215