linux/drivers/media/platform/rcar-vin/rcar-vin.h
<<
>>
Prefs
   1/*
   2 * Driver for Renesas R-Car VIN
   3 *
   4 * Copyright (C) 2016 Renesas Electronics Corp.
   5 * Copyright (C) 2011-2013 Renesas Solutions Corp.
   6 * Copyright (C) 2013 Cogent Embedded, Inc., <source@cogentembedded.com>
   7 * Copyright (C) 2008 Magnus Damm
   8 *
   9 * Based on the soc-camera rcar_vin driver
  10 *
  11 * This program is free software; you can redistribute  it and/or modify it
  12 * under  the terms of  the GNU General  Public License as published by the
  13 * Free Software Foundation;  either version 2 of the  License, or (at your
  14 * option) any later version.
  15 */
  16
  17#ifndef __RCAR_VIN__
  18#define __RCAR_VIN__
  19
  20#include <media/v4l2-async.h>
  21#include <media/v4l2-ctrls.h>
  22#include <media/v4l2-dev.h>
  23#include <media/v4l2-device.h>
  24#include <media/videobuf2-v4l2.h>
  25
  26/* Number of HW buffers */
  27#define HW_BUFFER_NUM 3
  28
  29/* Address alignment mask for HW buffers */
  30#define HW_BUFFER_MASK 0x7f
  31
  32enum chip_id {
  33        RCAR_H1,
  34        RCAR_M1,
  35        RCAR_GEN2,
  36};
  37
  38/**
  39 * STOPPED  - No operation in progress
  40 * RUNNING  - Operation in progress have buffers
  41 * STOPPING - Stopping operation
  42 */
  43enum rvin_dma_state {
  44        STOPPED = 0,
  45        RUNNING,
  46        STOPPING,
  47};
  48
  49/**
  50 * struct rvin_source_fmt - Source information
  51 * @width:      Width from source
  52 * @height:     Height from source
  53 */
  54struct rvin_source_fmt {
  55        u32 width;
  56        u32 height;
  57};
  58
  59/**
  60 * struct rvin_video_format - Data format stored in memory
  61 * @fourcc:     Pixelformat
  62 * @bpp:        Bytes per pixel
  63 */
  64struct rvin_video_format {
  65        u32 fourcc;
  66        u8 bpp;
  67};
  68
  69/**
  70 * struct rvin_graph_entity - Video endpoint from async framework
  71 * @asd:        sub-device descriptor for async framework
  72 * @subdev:     subdevice matched using async framework
  73 * @code:       Media bus format from source
  74 * @mbus_cfg:   Media bus format from DT
  75 * @source_pad: source pad of remote subdevice
  76 * @sink_pad:   sink pad of remote subdevice
  77 */
  78struct rvin_graph_entity {
  79        struct v4l2_async_subdev asd;
  80        struct v4l2_subdev *subdev;
  81
  82        u32 code;
  83        struct v4l2_mbus_config mbus_cfg;
  84
  85        unsigned int source_pad;
  86        unsigned int sink_pad;
  87};
  88
  89/**
  90 * struct rvin_dev - Renesas VIN device structure
  91 * @dev:                (OF) device
  92 * @base:               device I/O register space remapped to virtual memory
  93 * @chip:               type of VIN chip
  94 *
  95 * @vdev:               V4L2 video device associated with VIN
  96 * @v4l2_dev:           V4L2 device
  97 * @ctrl_handler:       V4L2 control handler
  98 * @notifier:           V4L2 asynchronous subdevs notifier
  99 * @digital:            entity in the DT for local digital subdevice
 100 *
 101 * @lock:               protects @queue
 102 * @queue:              vb2 buffers queue
 103 * @scratch:            cpu address for scratch buffer
 104 * @scratch_phys:       physical address of the scratch buffer
 105 *
 106 * @qlock:              protects @queue_buf, @buf_list, @sequence
 107 *                      @state
 108 * @queue_buf:          Keeps track of buffers given to HW slot
 109 * @buf_list:           list of queued buffers
 110 * @sequence:           V4L2 buffers sequence number
 111 * @state:              keeps track of operation state
 112 *
 113 * @source:             active format from the video source
 114 * @format:             active V4L2 pixel format
 115 *
 116 * @crop:               active cropping
 117 * @compose:            active composing
 118 */
 119struct rvin_dev {
 120        struct device *dev;
 121        void __iomem *base;
 122        enum chip_id chip;
 123
 124        struct video_device vdev;
 125        struct v4l2_device v4l2_dev;
 126        struct v4l2_ctrl_handler ctrl_handler;
 127        struct v4l2_async_notifier notifier;
 128        struct rvin_graph_entity *digital;
 129
 130        struct mutex lock;
 131        struct vb2_queue queue;
 132        void *scratch;
 133        dma_addr_t scratch_phys;
 134
 135        spinlock_t qlock;
 136        struct vb2_v4l2_buffer *queue_buf[HW_BUFFER_NUM];
 137        struct list_head buf_list;
 138        unsigned int sequence;
 139        enum rvin_dma_state state;
 140
 141        struct rvin_source_fmt source;
 142        struct v4l2_pix_format format;
 143
 144        struct v4l2_rect crop;
 145        struct v4l2_rect compose;
 146};
 147
 148#define vin_to_source(vin)              ((vin)->digital->subdev)
 149
 150/* Debug */
 151#define vin_dbg(d, fmt, arg...)         dev_dbg(d->dev, fmt, ##arg)
 152#define vin_info(d, fmt, arg...)        dev_info(d->dev, fmt, ##arg)
 153#define vin_warn(d, fmt, arg...)        dev_warn(d->dev, fmt, ##arg)
 154#define vin_err(d, fmt, arg...)         dev_err(d->dev, fmt, ##arg)
 155
 156int rvin_dma_probe(struct rvin_dev *vin, int irq);
 157void rvin_dma_remove(struct rvin_dev *vin);
 158
 159int rvin_v4l2_probe(struct rvin_dev *vin);
 160void rvin_v4l2_remove(struct rvin_dev *vin);
 161
 162const struct rvin_video_format *rvin_format_from_pixel(u32 pixelformat);
 163
 164/* Cropping, composing and scaling */
 165void rvin_scale_try(struct rvin_dev *vin, struct v4l2_pix_format *pix,
 166                    u32 width, u32 height);
 167void rvin_crop_scale_comp(struct rvin_dev *vin);
 168
 169#endif
 170