blob: 8d135ed3f7abd85595fb33c0e28cd2cd452cec2a [file] [log] [blame]
Niklas Söderlundf00add92016-04-26 10:22:19 -03001/*
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
Niklas Söderlundbb3ed3f2018-04-14 07:57:00 -040032enum model_id {
Niklas Söderlundf00add92016-04-26 10:22:19 -030033 RCAR_H1,
34 RCAR_M1,
Niklas Söderlund23eb2c82016-08-15 12:06:28 -030035 RCAR_GEN2,
Niklas Söderlundf00add92016-04-26 10:22:19 -030036};
37
38/**
39 * STOPPED - No operation in progress
40 * RUNNING - Operation in progress have buffers
Niklas Söderlundf00add92016-04-26 10:22:19 -030041 * STOPPING - Stopping operation
42 */
43enum rvin_dma_state {
44 STOPPED = 0,
45 RUNNING,
Niklas Söderlundf00add92016-04-26 10:22:19 -030046 STOPPING,
47};
48
49/**
50 * struct rvin_source_fmt - Source information
Niklas Söderlundf00add92016-04-26 10:22:19 -030051 * @width: Width from source
52 * @height: Height from source
53 */
54struct rvin_source_fmt {
Niklas Söderlundf00add92016-04-26 10:22:19 -030055 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
Niklas Söderlund83fba2c2016-08-15 12:06:34 -030069/**
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
Niklas Söderlundb50b77e2016-08-15 12:06:35 -030073 * @code: Media bus format from source
74 * @mbus_cfg: Media bus format from DT
Niklas Söderlund1eb36412017-05-23 21:15:28 -030075 * @source_pad: source pad of remote subdevice
76 * @sink_pad: sink pad of remote subdevice
Niklas Söderlund83fba2c2016-08-15 12:06:34 -030077 */
Niklas Söderlundf00add92016-04-26 10:22:19 -030078struct rvin_graph_entity {
Niklas Söderlundf00add92016-04-26 10:22:19 -030079 struct v4l2_async_subdev asd;
80 struct v4l2_subdev *subdev;
Niklas Söderlundb50b77e2016-08-15 12:06:35 -030081
82 u32 code;
83 struct v4l2_mbus_config mbus_cfg;
Niklas Söderlund1eb36412017-05-23 21:15:28 -030084
85 unsigned int source_pad;
86 unsigned int sink_pad;
Niklas Söderlundf00add92016-04-26 10:22:19 -030087};
88
89/**
Niklas Söderlundbb3ed3f2018-04-14 07:57:00 -040090 * struct rvin_info - Information about the particular VIN implementation
91 * @model: VIN model
Niklas Söderlund16cdb7d2018-04-14 07:57:01 -040092 * @max_width: max input width the VIN supports
93 * @max_height: max input height the VIN supports
Niklas Söderlundbb3ed3f2018-04-14 07:57:00 -040094 */
95struct rvin_info {
96 enum model_id model;
Niklas Söderlund16cdb7d2018-04-14 07:57:01 -040097
98 unsigned int max_width;
99 unsigned int max_height;
Niklas Söderlundbb3ed3f2018-04-14 07:57:00 -0400100};
101
102/**
Niklas Söderlundf00add92016-04-26 10:22:19 -0300103 * struct rvin_dev - Renesas VIN device structure
104 * @dev: (OF) device
105 * @base: device I/O register space remapped to virtual memory
Niklas Söderlundbb3ed3f2018-04-14 07:57:00 -0400106 * @info: info about VIN instance
Niklas Söderlundf00add92016-04-26 10:22:19 -0300107 *
108 * @vdev: V4L2 video device associated with VIN
109 * @v4l2_dev: V4L2 device
110 * @ctrl_handler: V4L2 control handler
111 * @notifier: V4L2 asynchronous subdevs notifier
Niklas Söderlund4869ce92016-08-15 12:06:29 -0300112 * @digital: entity in the DT for local digital subdevice
Niklas Söderlundf00add92016-04-26 10:22:19 -0300113 *
114 * @lock: protects @queue
115 * @queue: vb2 buffers queue
Niklas Söderlund6a8ffa82018-03-13 22:49:09 -0400116 * @scratch: cpu address for scratch buffer
117 * @scratch_phys: physical address of the scratch buffer
Niklas Söderlundf00add92016-04-26 10:22:19 -0300118 *
Niklas Söderlunddc9aec72018-03-13 22:49:10 -0400119 * @qlock: protects @queue_buf, @buf_list, @sequence
Niklas Söderlundf00add92016-04-26 10:22:19 -0300120 * @state
121 * @queue_buf: Keeps track of buffers given to HW slot
122 * @buf_list: list of queued buffers
Niklas Söderlundf00add92016-04-26 10:22:19 -0300123 * @sequence: V4L2 buffers sequence number
124 * @state: keeps track of operation state
125 *
126 * @source: active format from the video source
127 * @format: active V4L2 pixel format
128 *
129 * @crop: active cropping
130 * @compose: active composing
131 */
132struct rvin_dev {
133 struct device *dev;
134 void __iomem *base;
Niklas Söderlundbb3ed3f2018-04-14 07:57:00 -0400135 const struct rvin_info *info;
Niklas Söderlundf00add92016-04-26 10:22:19 -0300136
137 struct video_device vdev;
138 struct v4l2_device v4l2_dev;
Niklas Söderlundf00add92016-04-26 10:22:19 -0300139 struct v4l2_ctrl_handler ctrl_handler;
140 struct v4l2_async_notifier notifier;
Sakari Ailus85999e82017-09-01 18:41:19 -0400141 struct rvin_graph_entity *digital;
Niklas Söderlundf00add92016-04-26 10:22:19 -0300142
143 struct mutex lock;
144 struct vb2_queue queue;
Niklas Söderlund6a8ffa82018-03-13 22:49:09 -0400145 void *scratch;
146 dma_addr_t scratch_phys;
Niklas Söderlundf00add92016-04-26 10:22:19 -0300147
148 spinlock_t qlock;
149 struct vb2_v4l2_buffer *queue_buf[HW_BUFFER_NUM];
150 struct list_head buf_list;
Niklas Söderlundf00add92016-04-26 10:22:19 -0300151 unsigned int sequence;
152 enum rvin_dma_state state;
153
154 struct rvin_source_fmt source;
155 struct v4l2_pix_format format;
156
157 struct v4l2_rect crop;
158 struct v4l2_rect compose;
159};
160
Sakari Ailus85999e82017-09-01 18:41:19 -0400161#define vin_to_source(vin) ((vin)->digital->subdev)
Niklas Söderlundf00add92016-04-26 10:22:19 -0300162
163/* Debug */
164#define vin_dbg(d, fmt, arg...) dev_dbg(d->dev, fmt, ##arg)
165#define vin_info(d, fmt, arg...) dev_info(d->dev, fmt, ##arg)
166#define vin_warn(d, fmt, arg...) dev_warn(d->dev, fmt, ##arg)
167#define vin_err(d, fmt, arg...) dev_err(d->dev, fmt, ##arg)
168
Niklas Söderlundd6ad0122018-04-14 07:56:57 -0400169int rvin_dma_register(struct rvin_dev *vin, int irq);
170void rvin_dma_unregister(struct rvin_dev *vin);
Niklas Söderlundf00add92016-04-26 10:22:19 -0300171
Niklas Söderlundd6ad0122018-04-14 07:56:57 -0400172int rvin_v4l2_register(struct rvin_dev *vin);
173void rvin_v4l2_unregister(struct rvin_dev *vin);
Niklas Söderlundf00add92016-04-26 10:22:19 -0300174
175const struct rvin_video_format *rvin_format_from_pixel(u32 pixelformat);
176
177/* Cropping, composing and scaling */
178void rvin_scale_try(struct rvin_dev *vin, struct v4l2_pix_format *pix,
179 u32 width, u32 height);
180void rvin_crop_scale_comp(struct rvin_dev *vin);
181
182#endif