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.
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
40 * STOPPED - No operation in progress
41 * RUNNING - Operation in progress have buffers
42 * STOPPING - Stopping operation
51 * struct rvin_video_format - Data format stored in memory
52 * @fourcc: Pixelformat
53 * @bpp: Bytes per pixel
55 struct rvin_video_format {
61 * struct rvin_graph_entity - Video endpoint from async framework
62 * @asd: sub-device descriptor for async framework
63 * @subdev: subdevice matched using async framework
64 * @source_pad: source pad of remote subdevice
65 * @sink_pad: sink pad of remote subdevice
67 struct rvin_graph_entity {
68 struct v4l2_async_subdev asd;
69 struct v4l2_subdev *subdev;
71 unsigned int source_pad;
72 unsigned int sink_pad;
76 * struct rvin_info - Information about the particular VIN implementation
78 * @max_width: max input width the VIN supports
79 * @max_height: max input height the VIN supports
84 unsigned int max_width;
85 unsigned int max_height;
89 * struct rvin_dev - Renesas VIN device structure
91 * @base: device I/O register space remapped to virtual memory
92 * @info: info about VIN instance
94 * @vdev: V4L2 video device associated with VIN
95 * @v4l2_dev: V4L2 device
96 * @ctrl_handler: V4L2 control handler
97 * @notifier: V4L2 asynchronous subdevs notifier
98 * @digital: entity in the DT for local digital subdevice
100 * @lock: protects @queue
101 * @queue: vb2 buffers queue
102 * @scratch: cpu address for scratch buffer
103 * @scratch_phys: physical address of the scratch buffer
105 * @qlock: protects @queue_buf, @buf_list, @sequence
107 * @queue_buf: Keeps track of buffers given to HW slot
108 * @buf_list: list of queued buffers
109 * @sequence: V4L2 buffers sequence number
110 * @state: keeps track of operation state
112 * @mbus_cfg: media bus configuration from DT
113 * @mbus_code: media bus format code
114 * @format: active V4L2 pixel format
116 * @crop: active cropping
117 * @compose: active composing
118 * @source: active size of the video source
119 * @std: active video standard of the video source
124 const struct rvin_info *info;
126 struct video_device vdev;
127 struct v4l2_device v4l2_dev;
128 struct v4l2_ctrl_handler ctrl_handler;
129 struct v4l2_async_notifier notifier;
130 struct rvin_graph_entity *digital;
133 struct vb2_queue queue;
135 dma_addr_t scratch_phys;
138 struct vb2_v4l2_buffer *queue_buf[HW_BUFFER_NUM];
139 struct list_head buf_list;
140 unsigned int sequence;
141 enum rvin_dma_state state;
143 struct v4l2_mbus_config mbus_cfg;
145 struct v4l2_pix_format format;
147 struct v4l2_rect crop;
148 struct v4l2_rect compose;
149 struct v4l2_rect source;
153 #define vin_to_source(vin) ((vin)->digital->subdev)
156 #define vin_dbg(d, fmt, arg...) dev_dbg(d->dev, fmt, ##arg)
157 #define vin_info(d, fmt, arg...) dev_info(d->dev, fmt, ##arg)
158 #define vin_warn(d, fmt, arg...) dev_warn(d->dev, fmt, ##arg)
159 #define vin_err(d, fmt, arg...) dev_err(d->dev, fmt, ##arg)
161 int rvin_dma_register(struct rvin_dev *vin, int irq);
162 void rvin_dma_unregister(struct rvin_dev *vin);
164 int rvin_v4l2_register(struct rvin_dev *vin);
165 void rvin_v4l2_unregister(struct rvin_dev *vin);
167 const struct rvin_video_format *rvin_format_from_pixel(u32 pixelformat);
169 /* Cropping, composing and scaling */
170 void rvin_crop_scale_comp(struct rvin_dev *vin);