2 * Samsung TV Mixer driver
4 * Copyright (c) 2010 Samsung Electronics
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_
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>
26 /** maximum number of output interfaces */
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
37 /** description of a macroblock for packed formats */
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;
47 /** description of supported format */
49 /** format name/mnemonic */
51 /** fourcc identifier */
53 /** number of planes in image data */
55 /** description of block for each plane */
56 struct mxr_block plane[MXR_MAX_PLANES];
57 /** number of subframes in image data */
59 /** specifies to which subframe belong given plane */
60 int plane2subframe[MXR_MAX_PLANES];
61 /** internal code, driver dependant */
65 /** description of crop configuration for image */
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 */
77 /** height of displayed data in pixels */
81 /** description of transformation from source to destination image */
83 /** cropping for source image */
85 /** cropping for destination image */
87 /** layer-dependant description of horizontal scaling */
89 /** layer-dependant description of vertical scaling */
93 /** instance of a buffer */
95 /** common v4l buffer stuff -- must be first */
97 /** node for layer's lists */
98 struct list_head list;
102 /** internal states of layer */
103 enum mxr_layer_state {
104 /** layers is not shown */
106 /** state between STREAMON and hardware start */
107 MXR_LAYER_STREAMING_START,
108 /** layer is shown */
110 /** state before STREAMOFF is finished */
111 MXR_LAYER_STREAMING_FINISH,
114 /** forward declarations */
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 *);
133 /** layer instance, a single window and content displayed on output */
135 /** parent mixer device */
136 struct mxr_device *mdev;
137 /** layer index (unique identifier) */
139 /** callbacks for layer methods */
140 struct mxr_layer_ops ops;
142 const struct mxr_format **fmt_array;
143 /** size of format array */
144 unsigned long fmt_array_size;
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;
157 /** mutex for protection of fields below */
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;
171 /** description of mixers output interface */
173 /** name of output */
176 struct v4l2_subdev *sd;
179 /** drivers instance */
181 /** interrupt index */
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];
190 /* video resources */
193 struct v4l2_device v4l2_dev;
194 /** context of allocator */
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;
204 /** mutex for protection of fields below */
206 /** number of power consumers */
208 /** number of entities depndant on output configuration */
210 /** number of users that do streaming */
212 /** index of current output */
216 /** transform device structure into mixer device */
217 static inline struct mxr_device *to_mdev(struct device *dev)
219 struct v4l2_device *vdev = dev_get_drvdata(dev);
220 return container_of(vdev, struct mxr_device, v4l2_dev);
223 /** get current output data, should be called under mdev's mutex */
224 static inline struct mxr_output *to_output(struct mxr_device *mdev)
226 return mdev->output[mdev->current_output];
229 /** get current output subdev, should be called under mdev's mutex */
230 static inline struct v4l2_subdev *to_outsd(struct mxr_device *mdev)
232 struct mxr_output *out = to_output(mdev);
233 return out ? out->sd : NULL;
236 /** forward declaration for mixer platform data */
237 struct mxr_platform_data;
239 /** acquiring common video resources */
240 int __devinit mxr_acquire_video(struct mxr_device *mdev,
241 struct mxr_platform_data *pdata);
243 /** releasing common video resources */
244 void __devexit mxr_release_video(struct mxr_device *mdev);
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);
251 void mxr_base_layer_release(struct mxr_layer *layer);
252 void mxr_layer_release(struct mxr_layer *layer);
254 int mxr_base_layer_register(struct mxr_layer *layer);
255 void mxr_base_layer_unregister(struct mxr_layer *layer);
257 unsigned long mxr_get_plane_size(const struct mxr_block *blk,
258 unsigned int width, unsigned int height);
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);
277 #define MXR_CHECK printk(KERN_ERR "%s:%d\n", __func__, __LINE__)
280 #endif /* _SAMSUNG_MIXER_H_ */