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
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
52 * struct rvin_source_fmt - Source information
53 * @code: Media bus format from source
54 * @width: Width from source
55 * @height: Height from source
57 struct rvin_source_fmt
{
64 * struct rvin_video_format - Data format stored in memory
65 * @fourcc: Pixelformat
66 * @bpp: Bytes per pixel
68 struct rvin_video_format
{
73 struct rvin_graph_entity
{
74 struct device_node
*node
;
75 struct media_entity
*entity
;
77 struct v4l2_async_subdev asd
;
78 struct v4l2_subdev
*subdev
;
82 * struct rvin_dev - Renesas VIN device structure
84 * @base: device I/O register space remapped to virtual memory
85 * @chip: type of VIN chip
86 * @mbus_cfg media bus configuration
88 * @vdev: V4L2 video device associated with VIN
89 * @v4l2_dev: V4L2 device
90 * @src_pad_idx: source pad index for media controller drivers
91 * @ctrl_handler: V4L2 control handler
92 * @notifier: V4L2 asynchronous subdevs notifier
93 * @entity: entity in the DT for subdevice
95 * @lock: protects @queue
96 * @queue: vb2 buffers queue
98 * @qlock: protects @queue_buf, @buf_list, @continuous, @sequence
100 * @queue_buf: Keeps track of buffers given to HW slot
101 * @buf_list: list of queued buffers
102 * @continuous: tracks if active operation is continuous or single mode
103 * @sequence: V4L2 buffers sequence number
104 * @state: keeps track of operation state
106 * @source: active format from the video source
107 * @format: active V4L2 pixel format
109 * @crop: active cropping
110 * @compose: active composing
116 struct v4l2_mbus_config mbus_cfg
;
118 struct video_device vdev
;
119 struct v4l2_device v4l2_dev
;
121 struct v4l2_ctrl_handler ctrl_handler
;
122 struct v4l2_async_notifier notifier
;
123 struct rvin_graph_entity entity
;
126 struct vb2_queue queue
;
129 struct vb2_v4l2_buffer
*queue_buf
[HW_BUFFER_NUM
];
130 struct list_head buf_list
;
132 unsigned int sequence
;
133 enum rvin_dma_state state
;
135 struct rvin_source_fmt source
;
136 struct v4l2_pix_format format
;
138 struct v4l2_rect crop
;
139 struct v4l2_rect compose
;
142 #define vin_to_source(vin) vin->entity.subdev
145 #define vin_dbg(d, fmt, arg...) dev_dbg(d->dev, fmt, ##arg)
146 #define vin_info(d, fmt, arg...) dev_info(d->dev, fmt, ##arg)
147 #define vin_warn(d, fmt, arg...) dev_warn(d->dev, fmt, ##arg)
148 #define vin_err(d, fmt, arg...) dev_err(d->dev, fmt, ##arg)
150 int rvin_dma_probe(struct rvin_dev
*vin
, int irq
);
151 void rvin_dma_remove(struct rvin_dev
*vin
);
153 int rvin_v4l2_probe(struct rvin_dev
*vin
);
154 void rvin_v4l2_remove(struct rvin_dev
*vin
);
156 const struct rvin_video_format
*rvin_format_from_pixel(u32 pixelformat
);
158 /* Cropping, composing and scaling */
159 void rvin_scale_try(struct rvin_dev
*vin
, struct v4l2_pix_format
*pix
,
160 u32 width
, u32 height
);
161 void rvin_crop_scale_comp(struct rvin_dev
*vin
);