upload tizen1.0 source
[kernel/linux-2.6.36.git] / drivers / media / video / s5p-tv / mixer.h
1 /*
2  * Samsung TV Mixer driver
3  *
4  * Copyright (c) 2010 Samsung Electronics
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 #include <linux/fb.h>
18 #include <linux/kernel.h>
19 #include <linux/spinlock.h>
20 #include <linux/wait.h>
21 #include <media/v4l2-device.h>
22 #include <media/videobuf2-core.h>
23
24 #include "regs-vmx.h"
25
26 /** maximum number of output interfaces */
27 #define MXR_OUTPUTS 2
28 /** maximum number of input interfaces (layers) */
29 #define MXR_MAX_LAYERS 3
30 #define MXR_DRIVER_NAME "s5p-mixer"
31 /** maximal number of planes for every layer */
32 #define MXR_MAX_PLANES  2
33
34 #define MXR_ENABLE 1
35 #define MXR_DISABLE 0
36
37 /** description of a macroblock for packed formats */
38 struct mxr_block {
39         /** vertical number of pixels in macroblock */
40         unsigned int pxWidth:8;
41         /** horizontal number of pixels in macroblock */
42         unsigned int pxHeight:8;
43         /** size of block in bytes */
44         unsigned int bSize:16;
45 };
46
47 /** description of supported format */
48 struct mxr_format {
49         /** format name/mnemonic */
50         char *name;
51         /** fourcc identifier */
52         u32 fourcc;
53         /** number of planes in image data */
54         int num_planes;
55         /** description of block for each plane */
56         struct mxr_block plane[MXR_MAX_PLANES];
57         /** number of subframes in image data */
58         int num_subframes;
59         /** specifies to which subframe belong given plane */
60         int plane2subframe[MXR_MAX_PLANES];
61         /** internal code, driver dependant */
62         unsigned long hwCode;
63 };
64
65 /** description of crop configuration for image */
66 struct mxr_crop {
67         /** width of layer in pixels */
68         unsigned int full_width;
69         /** height of layer in pixels */
70         unsigned int full_height;
71         /** horizontal offset of first pixel to be displayed */
72         unsigned int x_offset;
73         /** vertical offset of first pixel to be displayed */
74         unsigned int y_offset;
75         /** width of displayed data in pixels */
76         unsigned int width;
77         /** height of displayed data in pixels */
78         unsigned int height;
79 };
80
81 /** description of transformation from source to destination image */
82 struct mxr_geometry {
83         /** cropping for source image */
84         struct mxr_crop src;
85         /** cropping for destination image */
86         struct mxr_crop dst;
87         /** layer-dependant description of horizontal scaling */
88         unsigned int x_ratio;
89         /** layer-dependant description of vertical scaling */
90         unsigned int y_ratio;
91 };
92
93 /** instance of a buffer */
94 struct mxr_buffer {
95         /** common v4l buffer stuff -- must be first */
96         struct vb2_buffer       vb;
97         /** node for layer's lists */
98         struct list_head        list;
99 };
100
101
102 /** internal states of layer */
103 enum mxr_layer_state {
104         /** layers is not shown */
105         MXR_LAYER_IDLE = 0,
106         /** state between STREAMON and hardware start */
107         MXR_LAYER_STREAMING_START,
108         /** layer is shown */
109         MXR_LAYER_STREAMING,
110         /** state before STREAMOFF is finished */
111         MXR_LAYER_STREAMING_FINISH,
112 };
113
114 /** forward declarations */
115 struct mxr_device;
116 struct mxr_layer;
117
118 /** callback for layers operation */
119 struct mxr_layer_ops {
120         /* TODO: try to port it to subdev API */
121         /** handler for resource release function */
122         void (*release)(struct mxr_layer *);
123         /** setting buffer to HW */
124         void (*buffer_set)(struct mxr_layer *, struct mxr_buffer *);
125         /** setting format and geometry in HW */
126         void (*format_set)(struct mxr_layer *);
127         /** streaming stop/start */
128         void (*stream_set)(struct mxr_layer *, int);
129         /** adjusting geometry */
130         void (*fix_geometry)(struct mxr_layer *);
131 };
132
133 /** layer instance, a single window and content displayed on output */
134 struct mxr_layer {
135         /** parent mixer device */
136         struct mxr_device *mdev;
137         /** layer index (unique identifier) */
138         int idx;
139         /** callbacks for layer methods */
140         struct mxr_layer_ops ops;
141         /** format array */
142         const struct mxr_format **fmt_array;
143         /** size of format array */
144         unsigned long fmt_array_size;
145
146         /** lock for protection of list and state fields */
147         spinlock_t enq_slock;
148         /** list for enqueued buffers */
149         struct list_head enq_list;
150         /** buffer currently owned by hardware in temporary registers */
151         struct mxr_buffer *update_buf;
152         /** buffer currently owned by hardware in shadow registers */
153         struct mxr_buffer *shadow_buf;
154         /** state of layer IDLE/STREAMING */
155         enum mxr_layer_state state;
156
157         /** mutex for protection of fields below */
158         struct mutex mutex;
159         /** use count */
160         int n_user;
161         /** handler for video node */
162         struct video_device vfd;
163         /** queue for output buffers */
164         struct vb2_queue vb_queue;
165         /** current image format */
166         const struct mxr_format *fmt;
167         /** current geometry of image */
168         struct mxr_geometry geo;
169 };
170
171 /** description of mixers output interface */
172 struct mxr_output {
173         /** name of output */
174         char name[32];
175         /** output subdev */
176         struct v4l2_subdev *sd;
177 };
178
179 /** drivers instance */
180 struct mxr_device {
181         /** interrupt index */
182         int irq;
183         /** master device */
184         struct device *dev;
185         /** state of each layer */
186         struct mxr_layer *layer[MXR_MAX_LAYERS];
187         /** state of each output */
188         struct mxr_output *output[MXR_OUTPUTS];
189
190         /* video resources */
191
192         /** V4L2 device */
193         struct v4l2_device v4l2_dev;
194         /** context of allocator */
195         void *alloc_ctx;
196
197         /** spinlock for protection of registers */
198         spinlock_t reg_slock;
199         /** pointer to Mixer registers */
200         void __iomem *mxr_regs;
201         /** pointer to Video Processor registers */
202         void __iomem *vp_regs;
203
204         /** mutex for protection of fields below */
205         struct mutex mutex;
206         /** number of power consumers */
207         int n_power;
208         /** number of entities depndant on output configuration */
209         int n_output;
210         /** number of users that do streaming */
211         int n_streamer;
212         /** index of current output */
213         int current_output;
214 };
215
216 /** transform device structure into mixer device */
217 static inline struct mxr_device *to_mdev(struct device *dev)
218 {
219         struct v4l2_device *vdev = dev_get_drvdata(dev);
220         return container_of(vdev, struct mxr_device, v4l2_dev);
221 }
222
223 /** get current output data, should be called under mdev's mutex */
224 static inline struct mxr_output *to_output(struct mxr_device *mdev)
225 {
226         return mdev->output[mdev->current_output];
227 }
228
229 /** get current output subdev, should be called under mdev's mutex */
230 static inline struct v4l2_subdev *to_outsd(struct mxr_device *mdev)
231 {
232         struct mxr_output *out = to_output(mdev);
233         return out ? out->sd : NULL;
234 }
235
236 /** forward declaration for mixer platform data */
237 struct mxr_platform_data;
238
239 /** acquiring common video resources */
240 int __devinit mxr_acquire_video(struct mxr_device *mdev,
241         struct mxr_platform_data *pdata);
242
243 /** releasing common video resources */
244 void __devexit mxr_release_video(struct mxr_device *mdev);
245
246 struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx);
247 struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx);
248 struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
249         int idx, char *name, struct mxr_layer_ops *ops);
250
251 void mxr_base_layer_release(struct mxr_layer *layer);
252 void mxr_layer_release(struct mxr_layer *layer);
253
254 int mxr_base_layer_register(struct mxr_layer *layer);
255 void mxr_base_layer_unregister(struct mxr_layer *layer);
256
257 unsigned long mxr_get_plane_size(const struct mxr_block *blk,
258         unsigned int width, unsigned int height);
259
260 /** adds new consumer for mixer's power */
261 void mxr_power_get(struct mxr_device *mdev);
262 /** removes consumer for mixer's power */
263 void mxr_power_put(struct mxr_device *mdev);
264 /** add new client for output configuration */
265 void mxr_output_get(struct mxr_device *mdev);
266 /** removes new client for output configuration */
267 void mxr_output_put(struct mxr_device *mdev);
268 /** add new client for streaming */
269 void mxr_streamer_get(struct mxr_device *mdev);
270 /** removes new client for streaming */
271 void mxr_streamer_put(struct mxr_device *mdev);
272 /** returns format of data delivared to current output */
273 void mxr_get_mbus_fmt(struct mxr_device *mdev,
274         struct v4l2_mbus_framefmt *mbus_fmt);
275
276
277 #define MXR_CHECK printk(KERN_ERR "%s:%d\n", __func__, __LINE__)
278
279
280 #endif /* _SAMSUNG_MIXER_H_ */
281