media: rcar-vin: enable Gen3 hardware configuration
[linux-2.6-block.git] / drivers / media / platform / rcar-vin / rcar-vin.h
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
32 enum model_id {
33         RCAR_H1,
34         RCAR_M1,
35         RCAR_GEN2,
36         RCAR_GEN3,
37 };
38
39 /**
40  * STOPPED  - No operation in progress
41  * RUNNING  - Operation in progress have buffers
42  * STOPPING - Stopping operation
43  */
44 enum rvin_dma_state {
45         STOPPED = 0,
46         RUNNING,
47         STOPPING,
48 };
49
50 /**
51  * struct rvin_video_format - Data format stored in memory
52  * @fourcc:     Pixelformat
53  * @bpp:        Bytes per pixel
54  */
55 struct rvin_video_format {
56         u32 fourcc;
57         u8 bpp;
58 };
59
60 /**
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
66  */
67 struct rvin_graph_entity {
68         struct v4l2_async_subdev asd;
69         struct v4l2_subdev *subdev;
70
71         unsigned int source_pad;
72         unsigned int sink_pad;
73 };
74
75 /**
76  * struct rvin_info - Information about the particular VIN implementation
77  * @model:              VIN model
78  * @max_width:          max input width the VIN supports
79  * @max_height:         max input height the VIN supports
80  */
81 struct rvin_info {
82         enum model_id model;
83
84         unsigned int max_width;
85         unsigned int max_height;
86 };
87
88 /**
89  * struct rvin_dev - Renesas VIN device structure
90  * @dev:                (OF) device
91  * @base:               device I/O register space remapped to virtual memory
92  * @info:               info about VIN instance
93  *
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
99  *
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
104  *
105  * @qlock:              protects @queue_buf, @buf_list, @sequence
106  *                      @state
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
111  *
112  * @mbus_cfg:           media bus configuration from DT
113  * @mbus_code:          media bus format code
114  * @format:             active V4L2 pixel format
115  *
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
120  */
121 struct rvin_dev {
122         struct device *dev;
123         void __iomem *base;
124         const struct rvin_info *info;
125
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;
131
132         struct mutex lock;
133         struct vb2_queue queue;
134         void *scratch;
135         dma_addr_t scratch_phys;
136
137         spinlock_t qlock;
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;
142
143         struct v4l2_mbus_config mbus_cfg;
144         u32 mbus_code;
145         struct v4l2_pix_format format;
146
147         struct v4l2_rect crop;
148         struct v4l2_rect compose;
149         struct v4l2_rect source;
150         v4l2_std_id std;
151 };
152
153 #define vin_to_source(vin)              ((vin)->digital->subdev)
154
155 /* Debug */
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)
160
161 int rvin_dma_register(struct rvin_dev *vin, int irq);
162 void rvin_dma_unregister(struct rvin_dev *vin);
163
164 int rvin_v4l2_register(struct rvin_dev *vin);
165 void rvin_v4l2_unregister(struct rvin_dev *vin);
166
167 const struct rvin_video_format *rvin_format_from_pixel(u32 pixelformat);
168
169 /* Cropping, composing and scaling */
170 void rvin_crop_scale_comp(struct rvin_dev *vin);
171
172 #endif