Linux 4.14.51
[linux/fpc-iii.git] / drivers / media / platform / rcar-vin / rcar-vin.h
blob9bfb5a7c4dc4f215bc27e8c877299bb38cad4d85
1 /*
2 * Driver for Renesas R-Car VIN
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
9 * Based on the soc-camera rcar_vin driver
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.
17 #ifndef __RCAR_VIN__
18 #define __RCAR_VIN__
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>
26 /* Number of HW buffers */
27 #define HW_BUFFER_NUM 3
29 /* Address alignment mask for HW buffers */
30 #define HW_BUFFER_MASK 0x7f
32 enum chip_id {
33 RCAR_H1,
34 RCAR_M1,
35 RCAR_GEN2,
38 /**
39 * STOPPED - No operation in progress
40 * RUNNING - Operation in progress have buffers
41 * STALLED - No operation in progress have no buffers
42 * STOPPING - Stopping operation
44 enum rvin_dma_state {
45 STOPPED = 0,
46 RUNNING,
47 STALLED,
48 STOPPING,
51 /**
52 * struct rvin_source_fmt - Source information
53 * @width: Width from source
54 * @height: Height from source
56 struct rvin_source_fmt {
57 u32 width;
58 u32 height;
61 /**
62 * struct rvin_video_format - Data format stored in memory
63 * @fourcc: Pixelformat
64 * @bpp: Bytes per pixel
66 struct rvin_video_format {
67 u32 fourcc;
68 u8 bpp;
71 /**
72 * struct rvin_graph_entity - Video endpoint from async framework
73 * @asd: sub-device descriptor for async framework
74 * @subdev: subdevice matched using async framework
75 * @code: Media bus format from source
76 * @mbus_cfg: Media bus format from DT
77 * @source_pad: source pad of remote subdevice
78 * @sink_pad: sink pad of remote subdevice
80 struct rvin_graph_entity {
81 struct v4l2_async_subdev asd;
82 struct v4l2_subdev *subdev;
84 u32 code;
85 struct v4l2_mbus_config mbus_cfg;
87 unsigned int source_pad;
88 unsigned int sink_pad;
91 /**
92 * struct rvin_dev - Renesas VIN device structure
93 * @dev: (OF) device
94 * @base: device I/O register space remapped to virtual memory
95 * @chip: type of VIN chip
97 * @vdev: V4L2 video device associated with VIN
98 * @v4l2_dev: V4L2 device
99 * @ctrl_handler: V4L2 control handler
100 * @notifier: V4L2 asynchronous subdevs notifier
101 * @digital: entity in the DT for local digital subdevice
103 * @lock: protects @queue
104 * @queue: vb2 buffers queue
106 * @qlock: protects @queue_buf, @buf_list, @continuous, @sequence
107 * @state
108 * @queue_buf: Keeps track of buffers given to HW slot
109 * @buf_list: list of queued buffers
110 * @continuous: tracks if active operation is continuous or single mode
111 * @sequence: V4L2 buffers sequence number
112 * @state: keeps track of operation state
114 * @source: active format from the video source
115 * @format: active V4L2 pixel format
117 * @crop: active cropping
118 * @compose: active composing
120 struct rvin_dev {
121 struct device *dev;
122 void __iomem *base;
123 enum chip_id chip;
125 struct video_device vdev;
126 struct v4l2_device v4l2_dev;
127 struct v4l2_ctrl_handler ctrl_handler;
128 struct v4l2_async_notifier notifier;
129 struct rvin_graph_entity digital;
131 struct mutex lock;
132 struct vb2_queue queue;
134 spinlock_t qlock;
135 struct vb2_v4l2_buffer *queue_buf[HW_BUFFER_NUM];
136 struct list_head buf_list;
137 bool continuous;
138 unsigned int sequence;
139 enum rvin_dma_state state;
141 struct rvin_source_fmt source;
142 struct v4l2_pix_format format;
144 struct v4l2_rect crop;
145 struct v4l2_rect compose;
148 #define vin_to_source(vin) vin->digital.subdev
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)
156 int rvin_dma_probe(struct rvin_dev *vin, int irq);
157 void rvin_dma_remove(struct rvin_dev *vin);
159 int rvin_v4l2_probe(struct rvin_dev *vin);
160 void rvin_v4l2_remove(struct rvin_dev *vin);
162 const struct rvin_video_format *rvin_format_from_pixel(u32 pixelformat);
164 /* Cropping, composing and scaling */
165 void rvin_scale_try(struct rvin_dev *vin, struct v4l2_pix_format *pix,
166 u32 width, u32 height);
167 void rvin_crop_scale_comp(struct rvin_dev *vin);
169 #endif