2 * Samsung TV Mixer driver
4 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
6 * Tomasz Stanislawski, <t.stanislaws@samsung.com>
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
14 #ifndef SAMSUNG_MIXER_H
15 #define SAMSUNG_MIXER_H
17 #ifdef CONFIG_VIDEO_SAMSUNG_S5P_MIXER_DEBUG
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>
28 #include "regs-mixer.h"
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
41 /** description of a macroblock for packed formats */
43 /** vertical number of pixels in macroblock */
45 /** horizontal number of pixels in macroblock */
47 /** size of block in bytes */
51 /** description of supported format */
53 /** format name/mnemonic */
55 /** fourcc identifier */
57 /** colorspace identifier */
58 enum v4l2_colorspace colorspace;
59 /** number of planes in image data */
61 /** description of block for each plane */
62 struct mxr_block plane[MXR_MAX_PLANES];
63 /** number of subframes in image data */
65 /** specifies to which subframe belong given plane */
66 int plane2subframe[MXR_MAX_PLANES];
67 /** internal code, driver dependant */
71 /** description of crop configuration for image */
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 */
83 /** height of displayed data in pixels */
85 /** indicate which fields are present in buffer */
89 /** description of transformation from source to destination image */
91 /** cropping for source image */
93 /** cropping for destination image */
95 /** layer-dependant description of horizontal scaling */
97 /** layer-dependant description of vertical scaling */
101 /** instance of a 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;
110 /** internal states of layer */
111 enum mxr_layer_state {
112 /** layers is not shown */
114 /** layer is shown */
116 /** state before STREAMOFF is finished */
117 MXR_LAYER_STREAMING_FINISH,
120 /** forward declarations */
124 /** callback for layers operation */
125 struct 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 *);
139 /** layer instance, a single window and content displayed on output */
141 /** parent mixer device */
142 struct mxr_device *mdev;
143 /** layer index (unique identifier) */
145 /** callbacks for layer methods */
146 struct mxr_layer_ops ops;
148 const struct mxr_format **fmt_array;
149 /** size of format array */
150 unsigned long fmt_array_size;
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;
163 /** mutex for protection of fields below */
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;
175 /** description of mixers output interface */
177 /** name of output */
180 struct v4l2_subdev *sd;
181 /** cookie used for configuration of registers */
185 /** specify source of output subdevs */
186 struct mxr_output_conf {
187 /** name of output (connector) */
189 /** name of module that generates output subdev */
191 /** cookie need for mixer HW */
198 /** auxiliary resources used my mixer */
199 struct mxr_resources {
200 /** interrupt index */
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 */
209 struct clk *sclk_mixer;
210 struct clk *sclk_hdmi;
211 struct clk *sclk_dac;
214 /* event flags used */
215 enum mxr_devide_flags {
219 /** drivers instance */
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 */
230 /* video resources */
233 struct v4l2_device v4l2_dev;
234 /** context of allocator */
236 /** event wait queue */
237 wait_queue_head_t event_queue;
239 unsigned long event_flags;
241 /** spinlock for protection of registers */
242 spinlock_t reg_slock;
244 /** mutex for protection of fields below */
246 /** number of entities depndant on output configuration */
248 /** number of users that do streaming */
250 /** index of current output */
252 /** auxiliary resources used my mixer */
253 struct mxr_resources res;
256 /** transform device structure into mixer device */
257 static inline struct mxr_device *to_mdev(struct device *dev)
259 struct v4l2_device *vdev = dev_get_drvdata(dev);
260 return container_of(vdev, struct mxr_device, v4l2_dev);
263 /** get current output data, should be called under mdev's mutex */
264 static inline struct mxr_output *to_output(struct mxr_device *mdev)
266 return mdev->output[mdev->current_output];
269 /** get current output subdev, should be called under mdev's mutex */
270 static inline struct v4l2_subdev *to_outsd(struct mxr_device *mdev)
272 struct mxr_output *out = to_output(mdev);
273 return out ? out->sd : NULL;
276 /** forward declaration for mixer platform data */
277 struct mxr_platform_data;
279 /** acquiring common video resources */
280 int __devinit mxr_acquire_video(struct mxr_device *mdev,
281 struct mxr_output_conf *output_cont, int output_count);
283 /** releasing common video resources */
284 void __devexit mxr_release_video(struct mxr_device *mdev);
286 struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx);
287 struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx);
288 struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
289 int idx, char *name, struct mxr_layer_ops *ops);
291 void mxr_base_layer_release(struct mxr_layer *layer);
292 void mxr_layer_release(struct mxr_layer *layer);
294 int mxr_base_layer_register(struct mxr_layer *layer);
295 void mxr_base_layer_unregister(struct mxr_layer *layer);
297 unsigned long mxr_get_plane_size(const struct mxr_block *blk,
298 unsigned int width, unsigned int height);
300 /** adds new consumer for mixer's power */
301 int __must_check mxr_power_get(struct mxr_device *mdev);
302 /** removes consumer for mixer's power */
303 void mxr_power_put(struct mxr_device *mdev);
304 /** add new client for output configuration */
305 void mxr_output_get(struct mxr_device *mdev);
306 /** removes new client for output configuration */
307 void mxr_output_put(struct mxr_device *mdev);
308 /** add new client for streaming */
309 void mxr_streamer_get(struct mxr_device *mdev);
310 /** removes new client for streaming */
311 void mxr_streamer_put(struct mxr_device *mdev);
312 /** returns format of data delivared to current output */
313 void mxr_get_mbus_fmt(struct mxr_device *mdev,
314 struct v4l2_mbus_framefmt *mbus_fmt);
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__)
322 #ifdef CONFIG_VIDEO_SAMSUNG_S5P_MIXER_DEBUG
323 #define mxr_dbg(mdev, fmt, ...) dev_dbg(mdev->dev, fmt, ##__VA_ARGS__)
325 #define mxr_dbg(mdev, fmt, ...) do { (void) mdev; } while (0)
328 /* accessing Mixer's and Video Processor's registers */
330 void mxr_vsync_set_update(struct mxr_device *mdev, int en);
331 void mxr_reg_reset(struct mxr_device *mdev);
332 irqreturn_t mxr_irq_handler(int irq, void *dev_data);
333 void mxr_reg_s_output(struct mxr_device *mdev, int cookie);
334 void mxr_reg_streamon(struct mxr_device *mdev);
335 void mxr_reg_streamoff(struct mxr_device *mdev);
336 int mxr_reg_wait4vsync(struct mxr_device *mdev);
337 void mxr_reg_set_mbus_fmt(struct mxr_device *mdev,
338 struct v4l2_mbus_framefmt *fmt);
339 void mxr_reg_graph_layer_stream(struct mxr_device *mdev, int idx, int en);
340 void mxr_reg_graph_buffer(struct mxr_device *mdev, int idx, dma_addr_t addr);
341 void mxr_reg_graph_format(struct mxr_device *mdev, int idx,
342 const struct mxr_format *fmt, const struct mxr_geometry *geo);
344 void mxr_reg_vp_layer_stream(struct mxr_device *mdev, int en);
345 void mxr_reg_vp_buffer(struct mxr_device *mdev,
346 dma_addr_t luma_addr[2], dma_addr_t chroma_addr[2]);
347 void mxr_reg_vp_format(struct mxr_device *mdev,
348 const struct mxr_format *fmt, const struct mxr_geometry *geo);
349 void mxr_reg_dump(struct mxr_device *mdev);
351 #endif /* SAMSUNG_MIXER_H */