blob: 51ad59b30358aa7e869a94d6d68df581e2d7b539 [file] [log] [blame]
Tomasz Stanislawskifef1c8d2011-02-02 05:40:08 -03001/*
2 * Samsung TV Mixer driver
3 *
4 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
5 *
6 * Tomasz Stanislawski, <t.stanislaws@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published
10 * by the Free Software Foundiation. either version 2 of the License,
11 * or (at your option) any later version
12 */
13
14#ifndef SAMSUNG_MIXER_H
15#define SAMSUNG_MIXER_H
16
17#ifdef CONFIG_VIDEO_SAMSUNG_S5P_MIXER_DEBUG
18 #define DEBUG
19#endif
20
21#include <linux/fb.h>
22#include <linux/kernel.h>
23#include <linux/spinlock.h>
24#include <linux/wait.h>
25#include <media/v4l2-device.h>
26#include <media/videobuf2-core.h>
27
28#include "regs-mixer.h"
29
30/** maximum number of output interfaces */
31#define MXR_MAX_OUTPUTS 2
32/** maximum number of input interfaces (layers) */
33#define MXR_MAX_LAYERS 3
34#define MXR_DRIVER_NAME "s5p-mixer"
35/** maximal number of planes for every layer */
36#define MXR_MAX_PLANES 2
37
38#define MXR_ENABLE 1
39#define MXR_DISABLE 0
40
41/** description of a macroblock for packed formats */
42struct mxr_block {
43 /** vertical number of pixels in macroblock */
44 unsigned int width;
45 /** horizontal number of pixels in macroblock */
46 unsigned int height;
47 /** size of block in bytes */
48 unsigned int size;
49};
50
51/** description of supported format */
52struct mxr_format {
53 /** format name/mnemonic */
54 const char *name;
55 /** fourcc identifier */
56 u32 fourcc;
57 /** colorspace identifier */
58 enum v4l2_colorspace colorspace;
59 /** number of planes in image data */
60 int num_planes;
61 /** description of block for each plane */
62 struct mxr_block plane[MXR_MAX_PLANES];
63 /** number of subframes in image data */
64 int num_subframes;
65 /** specifies to which subframe belong given plane */
66 int plane2subframe[MXR_MAX_PLANES];
67 /** internal code, driver dependant */
68 unsigned long cookie;
69};
70
71/** description of crop configuration for image */
72struct mxr_crop {
73 /** width of layer in pixels */
74 unsigned int full_width;
75 /** height of layer in pixels */
76 unsigned int full_height;
77 /** horizontal offset of first pixel to be displayed */
78 unsigned int x_offset;
79 /** vertical offset of first pixel to be displayed */
80 unsigned int y_offset;
81 /** width of displayed data in pixels */
82 unsigned int width;
83 /** height of displayed data in pixels */
84 unsigned int height;
85 /** indicate which fields are present in buffer */
86 unsigned int field;
87};
88
89/** description of transformation from source to destination image */
90struct mxr_geometry {
91 /** cropping for source image */
92 struct mxr_crop src;
93 /** cropping for destination image */
94 struct mxr_crop dst;
95 /** layer-dependant description of horizontal scaling */
96 unsigned int x_ratio;
97 /** layer-dependant description of vertical scaling */
98 unsigned int y_ratio;
99};
100
101/** instance of a buffer */
102struct mxr_buffer {
103 /** common v4l buffer stuff -- must be first */
104 struct vb2_buffer vb;
105 /** node for layer's lists */
106 struct list_head list;
107};
108
109
110/** internal states of layer */
111enum mxr_layer_state {
112 /** layers is not shown */
113 MXR_LAYER_IDLE = 0,
Tomasz Stanislawskifef1c8d2011-02-02 05:40:08 -0300114 /** layer is shown */
115 MXR_LAYER_STREAMING,
116 /** state before STREAMOFF is finished */
117 MXR_LAYER_STREAMING_FINISH,
118};
119
120/** forward declarations */
121struct mxr_device;
122struct mxr_layer;
123
124/** callback for layers operation */
125struct mxr_layer_ops {
126 /* TODO: try to port it to subdev API */
127 /** handler for resource release function */
128 void (*release)(struct mxr_layer *);
129 /** setting buffer to HW */
130 void (*buffer_set)(struct mxr_layer *, struct mxr_buffer *);
131 /** setting format and geometry in HW */
132 void (*format_set)(struct mxr_layer *);
133 /** streaming stop/start */
134 void (*stream_set)(struct mxr_layer *, int);
135 /** adjusting geometry */
136 void (*fix_geometry)(struct mxr_layer *);
137};
138
139/** layer instance, a single window and content displayed on output */
140struct mxr_layer {
141 /** parent mixer device */
142 struct mxr_device *mdev;
143 /** layer index (unique identifier) */
144 int idx;
145 /** callbacks for layer methods */
146 struct mxr_layer_ops ops;
147 /** format array */
148 const struct mxr_format **fmt_array;
149 /** size of format array */
150 unsigned long fmt_array_size;
151
152 /** lock for protection of list and state fields */
153 spinlock_t enq_slock;
154 /** list for enqueued buffers */
155 struct list_head enq_list;
156 /** buffer currently owned by hardware in temporary registers */
157 struct mxr_buffer *update_buf;
158 /** buffer currently owned by hardware in shadow registers */
159 struct mxr_buffer *shadow_buf;
160 /** state of layer IDLE/STREAMING */
161 enum mxr_layer_state state;
162
163 /** mutex for protection of fields below */
164 struct mutex mutex;
165 /** handler for video node */
166 struct video_device vfd;
167 /** queue for output buffers */
168 struct vb2_queue vb_queue;
169 /** current image format */
170 const struct mxr_format *fmt;
171 /** current geometry of image */
172 struct mxr_geometry geo;
173};
174
175/** description of mixers output interface */
176struct mxr_output {
177 /** name of output */
178 char name[32];
179 /** output subdev */
180 struct v4l2_subdev *sd;
181 /** cookie used for configuration of registers */
182 int cookie;
183};
184
185/** specify source of output subdevs */
186struct mxr_output_conf {
187 /** name of output (connector) */
188 char *output_name;
189 /** name of module that generates output subdev */
190 char *module_name;
191 /** cookie need for mixer HW */
192 int cookie;
193};
194
195struct clk;
196struct regulator;
197
198/** auxiliary resources used my mixer */
199struct mxr_resources {
200 /** interrupt index */
201 int irq;
202 /** pointer to Mixer registers */
203 void __iomem *mxr_regs;
204 /** pointer to Video Processor registers */
205 void __iomem *vp_regs;
206 /** other resources, should used under mxr_device.mutex */
207 struct clk *mixer;
208 struct clk *vp;
209 struct clk *sclk_mixer;
210 struct clk *sclk_hdmi;
211 struct clk *sclk_dac;
212};
213
214/* event flags used */
215enum mxr_devide_flags {
216 MXR_EVENT_VSYNC = 0,
217};
218
219/** drivers instance */
220struct mxr_device {
221 /** master device */
222 struct device *dev;
223 /** state of each layer */
224 struct mxr_layer *layer[MXR_MAX_LAYERS];
225 /** state of each output */
226 struct mxr_output *output[MXR_MAX_OUTPUTS];
227 /** number of registered outputs */
228 int output_cnt;
229
230 /* video resources */
231
232 /** V4L2 device */
233 struct v4l2_device v4l2_dev;
234 /** context of allocator */
235 void *alloc_ctx;
236 /** event wait queue */
237 wait_queue_head_t event_queue;
238 /** state flags */
239 unsigned long event_flags;
240
241 /** spinlock for protection of registers */
242 spinlock_t reg_slock;
243
244 /** mutex for protection of fields below */
245 struct mutex mutex;
246 /** number of entities depndant on output configuration */
247 int n_output;
248 /** number of users that do streaming */
249 int n_streamer;
250 /** index of current output */
251 int current_output;
252 /** auxiliary resources used my mixer */
253 struct mxr_resources res;
254};
255
256/** transform device structure into mixer device */
257static inline struct mxr_device *to_mdev(struct device *dev)
258{
259 struct v4l2_device *vdev = dev_get_drvdata(dev);
260 return container_of(vdev, struct mxr_device, v4l2_dev);
261}
262
263/** get current output data, should be called under mdev's mutex */
264static inline struct mxr_output *to_output(struct mxr_device *mdev)
265{
266 return mdev->output[mdev->current_output];
267}
268
269/** get current output subdev, should be called under mdev's mutex */
270static inline struct v4l2_subdev *to_outsd(struct mxr_device *mdev)
271{
272 struct mxr_output *out = to_output(mdev);
273 return out ? out->sd : NULL;
274}
275
276/** forward declaration for mixer platform data */
277struct mxr_platform_data;
278
279/** acquiring common video resources */
280int __devinit mxr_acquire_video(struct mxr_device *mdev,
281 struct mxr_output_conf *output_cont, int output_count);
282
283/** releasing common video resources */
284void __devexit mxr_release_video(struct mxr_device *mdev);
285
286struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx);
287struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx);
288struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
289 int idx, char *name, struct mxr_layer_ops *ops);
290
291void mxr_base_layer_release(struct mxr_layer *layer);
292void mxr_layer_release(struct mxr_layer *layer);
293
294int mxr_base_layer_register(struct mxr_layer *layer);
295void mxr_base_layer_unregister(struct mxr_layer *layer);
296
297unsigned long mxr_get_plane_size(const struct mxr_block *blk,
298 unsigned int width, unsigned int height);
299
300/** adds new consumer for mixer's power */
301int __must_check mxr_power_get(struct mxr_device *mdev);
302/** removes consumer for mixer's power */
303void mxr_power_put(struct mxr_device *mdev);
304/** add new client for output configuration */
305void mxr_output_get(struct mxr_device *mdev);
306/** removes new client for output configuration */
307void mxr_output_put(struct mxr_device *mdev);
308/** add new client for streaming */
309void mxr_streamer_get(struct mxr_device *mdev);
310/** removes new client for streaming */
311void mxr_streamer_put(struct mxr_device *mdev);
312/** returns format of data delivared to current output */
313void mxr_get_mbus_fmt(struct mxr_device *mdev,
314 struct v4l2_mbus_framefmt *mbus_fmt);
315
316/* Debug */
317
318#define mxr_err(mdev, fmt, ...) dev_err(mdev->dev, fmt, ##__VA_ARGS__)
319#define mxr_warn(mdev, fmt, ...) dev_warn(mdev->dev, fmt, ##__VA_ARGS__)
320#define mxr_info(mdev, fmt, ...) dev_info(mdev->dev, fmt, ##__VA_ARGS__)
321
322#ifdef CONFIG_VIDEO_SAMSUNG_S5P_MIXER_DEBUG
323 #define mxr_dbg(mdev, fmt, ...) dev_dbg(mdev->dev, fmt, ##__VA_ARGS__)
324#else
325 #define mxr_dbg(mdev, fmt, ...) do { (void) mdev; } while (0)
326#endif
327
328/* accessing Mixer's and Video Processor's registers */
329
330void mxr_vsync_set_update(struct mxr_device *mdev, int en);
331void mxr_reg_reset(struct mxr_device *mdev);
332irqreturn_t mxr_irq_handler(int irq, void *dev_data);
333void mxr_reg_s_output(struct mxr_device *mdev, int cookie);
334void mxr_reg_streamon(struct mxr_device *mdev);
335void mxr_reg_streamoff(struct mxr_device *mdev);
336int mxr_reg_wait4vsync(struct mxr_device *mdev);
337void mxr_reg_set_mbus_fmt(struct mxr_device *mdev,
338 struct v4l2_mbus_framefmt *fmt);
339void mxr_reg_graph_layer_stream(struct mxr_device *mdev, int idx, int en);
340void mxr_reg_graph_buffer(struct mxr_device *mdev, int idx, dma_addr_t addr);
341void mxr_reg_graph_format(struct mxr_device *mdev, int idx,
342 const struct mxr_format *fmt, const struct mxr_geometry *geo);
343
344void mxr_reg_vp_layer_stream(struct mxr_device *mdev, int en);
345void mxr_reg_vp_buffer(struct mxr_device *mdev,
346 dma_addr_t luma_addr[2], dma_addr_t chroma_addr[2]);
347void mxr_reg_vp_format(struct mxr_device *mdev,
348 const struct mxr_format *fmt, const struct mxr_geometry *geo);
349void mxr_reg_dump(struct mxr_device *mdev);
350
351#endif /* SAMSUNG_MIXER_H */
352