[media] rcar-vin: rework how subdevice is found and bound
[deliverable/linux.git] / drivers / media / platform / rcar-vin / rcar-vin.h
CommitLineData
f00add96
NS
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 {
f00add96
NS
33 RCAR_H1,
34 RCAR_M1,
23eb2c86 35 RCAR_GEN2,
f00add96
NS
36};
37
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
43 */
44enum rvin_dma_state {
45 STOPPED = 0,
46 RUNNING,
47 STALLED,
48 STOPPING,
49};
50
51/**
52 * struct rvin_source_fmt - Source information
53 * @code: Media bus format from source
54 * @width: Width from source
55 * @height: Height from source
56 */
57struct rvin_source_fmt {
58 u32 code;
59 u32 width;
60 u32 height;
61};
62
63/**
64 * struct rvin_video_format - Data format stored in memory
65 * @fourcc: Pixelformat
66 * @bpp: Bytes per pixel
67 */
68struct rvin_video_format {
69 u32 fourcc;
70 u8 bpp;
71};
72
83fba2c0
NS
73/**
74 * struct rvin_graph_entity - Video endpoint from async framework
75 * @asd: sub-device descriptor for async framework
76 * @subdev: subdevice matched using async framework
77 */
f00add96 78struct rvin_graph_entity {
f00add96
NS
79 struct v4l2_async_subdev asd;
80 struct v4l2_subdev *subdev;
81};
82
83/**
84 * struct rvin_dev - Renesas VIN device structure
85 * @dev: (OF) device
86 * @base: device I/O register space remapped to virtual memory
87 * @chip: type of VIN chip
88 * @mbus_cfg media bus configuration
89 *
90 * @vdev: V4L2 video device associated with VIN
91 * @v4l2_dev: V4L2 device
fa037403 92 * @src_pad_idx: source pad index for media controller drivers
f00add96
NS
93 * @ctrl_handler: V4L2 control handler
94 * @notifier: V4L2 asynchronous subdevs notifier
4869ce9d 95 * @digital: entity in the DT for local digital subdevice
f00add96
NS
96 *
97 * @lock: protects @queue
98 * @queue: vb2 buffers queue
f00add96
NS
99 *
100 * @qlock: protects @queue_buf, @buf_list, @continuous, @sequence
101 * @state
102 * @queue_buf: Keeps track of buffers given to HW slot
103 * @buf_list: list of queued buffers
104 * @continuous: tracks if active operation is continuous or single mode
105 * @sequence: V4L2 buffers sequence number
106 * @state: keeps track of operation state
107 *
108 * @source: active format from the video source
109 * @format: active V4L2 pixel format
110 *
111 * @crop: active cropping
112 * @compose: active composing
113 */
114struct rvin_dev {
115 struct device *dev;
116 void __iomem *base;
117 enum chip_id chip;
118 struct v4l2_mbus_config mbus_cfg;
119
120 struct video_device vdev;
121 struct v4l2_device v4l2_dev;
fa037403 122 int src_pad_idx;
f00add96
NS
123 struct v4l2_ctrl_handler ctrl_handler;
124 struct v4l2_async_notifier notifier;
4869ce9d 125 struct rvin_graph_entity digital;
f00add96
NS
126
127 struct mutex lock;
128 struct vb2_queue queue;
f00add96
NS
129
130 spinlock_t qlock;
131 struct vb2_v4l2_buffer *queue_buf[HW_BUFFER_NUM];
132 struct list_head buf_list;
133 bool continuous;
134 unsigned int sequence;
135 enum rvin_dma_state state;
136
137 struct rvin_source_fmt source;
138 struct v4l2_pix_format format;
139
140 struct v4l2_rect crop;
141 struct v4l2_rect compose;
142};
143
4869ce9d 144#define vin_to_source(vin) vin->digital.subdev
f00add96
NS
145
146/* Debug */
147#define vin_dbg(d, fmt, arg...) dev_dbg(d->dev, fmt, ##arg)
148#define vin_info(d, fmt, arg...) dev_info(d->dev, fmt, ##arg)
149#define vin_warn(d, fmt, arg...) dev_warn(d->dev, fmt, ##arg)
150#define vin_err(d, fmt, arg...) dev_err(d->dev, fmt, ##arg)
151
152int rvin_dma_probe(struct rvin_dev *vin, int irq);
153void rvin_dma_remove(struct rvin_dev *vin);
154
155int rvin_v4l2_probe(struct rvin_dev *vin);
156void rvin_v4l2_remove(struct rvin_dev *vin);
157
158const struct rvin_video_format *rvin_format_from_pixel(u32 pixelformat);
159
160/* Cropping, composing and scaling */
161void rvin_scale_try(struct rvin_dev *vin, struct v4l2_pix_format *pix,
162 u32 width, u32 height);
163void rvin_crop_scale_comp(struct rvin_dev *vin);
164
165#endif
This page took 0.0421 seconds and 5 git commands to generate.