aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/platform/omap/omap_voutlib.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-10-07 04:49:05 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-10-07 04:49:05 -0400
commit0b8e74c6f44094189dbe78baf4101acc7570c6af (patch)
tree6440561d09fb71ba5928664604ec92f29940be6b /drivers/media/platform/omap/omap_voutlib.c
parent7f60ba388f5b9dd8b0da463b394412dace3ab814 (diff)
parentbd0d10498826ed150da5e4c45baf8b9c7088fb71 (diff)
Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
Pull media updates from Mauro Carvalho Chehab: "The first part of the media updates for Kernel 3.7. This series contain: - A major tree renaming patch series: now, drivers are organized internally by their used bus, instead of by V4L2 and/or DVB API, providing a cleaner driver location for hybrid drivers that implement both APIs, and allowing to cleanup the Kconfig items and make them more intuitive for the end user; - Media Kernel developers are typically very lazy with their duties of keeping the MAINTAINERS entries for their drivers updated. As now the tree is more organized, we're doing an effort to add/update those entries for the drivers that aren't currently orphan; - Several DVB USB drivers got moved to a new DVB USB v2 core; the new core fixes several bugs (as the existing one that got bitroted). Now, suspend/resume finally started to work fine (at least with some devices - we should expect more work with regards to it); - added multistream support for DVB-T2, and unified the API for DVB-S2 and ISDB-S. Backward binary support is preserved; - as usual, a few new drivers, some V4L2 core improvements and lots of drivers improvements and fixes. There are some points to notice on this series: 1) you should expect a trivial merge conflict on your tree, with the removal of Documentation/feature-removal-schedule.txt: this series would be adding two additional entries there. I opted to not rebase it due to this recent change; 2) With regards to the PCTV 520e udev-related breakage, I opted to fix it in a way that the patches can be backported to 3.5 even without your firmware fix patch. This way, Greg doesn't need to rush backporting your patch (as there are still the firmware cache and firmware path customization issues to be addressed there). I'll send later a patch (likely after the end of the merge window) reverting the rest of the DRX-K async firmware request, fully restoring its original behaviour to allow media drivers to initialize everything serialized as before for 3.7 and upper. 3) I'm planning to work on this weekend to test the DMABUF patches for V4L2. The patches are on my queue for several Kernel cycles, but, up to now, there is/was no way to test the series locally. I have some concerns about this particular changeset with regards to security issues, and with regards to the replacement of the old VIDIOC_OVERLAY ioctl's that is broken on modern systems, due to GPU drivers change. The Overlay API allows direct PCI2PCI transfers from a media capture card into the GPU framebuffer, but its API is crappy. Also, the only existing X11 driver that implements it requires a XV extension that is not available anymore on modern drivers. The DMABUF can do the same thing, but with it is promising to be a properly-designed API. If I can successfully test this series and be happy with it, I should be asking you to pull them next week." * 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: (717 commits) em28xx: regression fix: use DRX-K sync firmware requests on em28xx drxk: allow loading firmware synchrousnously em28xx: Make all em28xx extensions to be initialized asynchronously [media] tda18271: properly report read errors in tda18271_get_id [media] tda18271: delay IR & RF calibration until init() if delay_cal is set [media] MAINTAINERS: add Michael Krufky as tda827x maintainer [media] MAINTAINERS: add Michael Krufky as tda8290 maintainer [media] MAINTAINERS: add Michael Krufky as cxusb maintainer [media] MAINTAINERS: add Michael Krufky as lg2160 maintainer [media] MAINTAINERS: add Michael Krufky as lgdt3305 maintainer [media] MAINTAINERS: add Michael Krufky as mxl111sf maintainer [media] MAINTAINERS: add Michael Krufky as mxl5007t maintainer [media] MAINTAINERS: add Michael Krufky as tda18271 maintainer [media] s5p-tv: Report only multi-plane capabilities in vidioc_querycap [media] s5p-mfc: Fix misplaced return statement in s5p_mfc_suspend() [media] exynos-gsc: Add missing static storage class specifiers [media] exynos-gsc: Remove <linux/version.h> header file inclusion [media] s5p-fimc: Fix incorrect condition in fimc_lite_reqbufs() [media] s5p-tv: Fix potential NULL pointer dereference error [media] s5k6aa: Fix possible NULL pointer dereference ...
Diffstat (limited to 'drivers/media/platform/omap/omap_voutlib.c')
-rw-r--r--drivers/media/platform/omap/omap_voutlib.c339
1 files changed, 339 insertions, 0 deletions
diff --git a/drivers/media/platform/omap/omap_voutlib.c b/drivers/media/platform/omap/omap_voutlib.c
new file mode 100644
index 000000000000..115408b9274f
--- /dev/null
+++ b/drivers/media/platform/omap/omap_voutlib.c
@@ -0,0 +1,339 @@
1/*
2 * omap_voutlib.c
3 *
4 * Copyright (C) 2005-2010 Texas Instruments.
5 *
6 * This file is licensed under the terms of the GNU General Public License
7 * version 2. This program is licensed "as is" without any warranty of any
8 * kind, whether express or implied.
9 *
10 * Based on the OMAP2 camera driver
11 * Video-for-Linux (Version 2) camera capture driver for
12 * the OMAP24xx camera controller.
13 *
14 * Author: Andy Lowe (source@mvista.com)
15 *
16 * Copyright (C) 2004 MontaVista Software, Inc.
17 * Copyright (C) 2010 Texas Instruments.
18 *
19 */
20
21#include <linux/module.h>
22#include <linux/errno.h>
23#include <linux/kernel.h>
24#include <linux/types.h>
25#include <linux/videodev2.h>
26
27#include <linux/dma-mapping.h>
28
29#include <plat/cpu.h>
30
31#include "omap_voutlib.h"
32
33MODULE_AUTHOR("Texas Instruments");
34MODULE_DESCRIPTION("OMAP Video library");
35MODULE_LICENSE("GPL");
36
37/* Return the default overlay cropping rectangle in crop given the image
38 * size in pix and the video display size in fbuf. The default
39 * cropping rectangle is the largest rectangle no larger than the capture size
40 * that will fit on the display. The default cropping rectangle is centered in
41 * the image. All dimensions and offsets are rounded down to even numbers.
42 */
43void omap_vout_default_crop(struct v4l2_pix_format *pix,
44 struct v4l2_framebuffer *fbuf, struct v4l2_rect *crop)
45{
46 crop->width = (pix->width < fbuf->fmt.width) ?
47 pix->width : fbuf->fmt.width;
48 crop->height = (pix->height < fbuf->fmt.height) ?
49 pix->height : fbuf->fmt.height;
50 crop->width &= ~1;
51 crop->height &= ~1;
52 crop->left = ((pix->width - crop->width) >> 1) & ~1;
53 crop->top = ((pix->height - crop->height) >> 1) & ~1;
54}
55EXPORT_SYMBOL_GPL(omap_vout_default_crop);
56
57/* Given a new render window in new_win, adjust the window to the
58 * nearest supported configuration. The adjusted window parameters are
59 * returned in new_win.
60 * Returns zero if successful, or -EINVAL if the requested window is
61 * impossible and cannot reasonably be adjusted.
62 */
63int omap_vout_try_window(struct v4l2_framebuffer *fbuf,
64 struct v4l2_window *new_win)
65{
66 struct v4l2_rect try_win;
67
68 /* make a working copy of the new_win rectangle */
69 try_win = new_win->w;
70
71 /* adjust the preview window so it fits on the display by clipping any
72 * offscreen areas
73 */
74 if (try_win.left < 0) {
75 try_win.width += try_win.left;
76 try_win.left = 0;
77 }
78 if (try_win.top < 0) {
79 try_win.height += try_win.top;
80 try_win.top = 0;
81 }
82 try_win.width = (try_win.width < fbuf->fmt.width) ?
83 try_win.width : fbuf->fmt.width;
84 try_win.height = (try_win.height < fbuf->fmt.height) ?
85 try_win.height : fbuf->fmt.height;
86 if (try_win.left + try_win.width > fbuf->fmt.width)
87 try_win.width = fbuf->fmt.width - try_win.left;
88 if (try_win.top + try_win.height > fbuf->fmt.height)
89 try_win.height = fbuf->fmt.height - try_win.top;
90 try_win.width &= ~1;
91 try_win.height &= ~1;
92
93 if (try_win.width <= 0 || try_win.height <= 0)
94 return -EINVAL;
95
96 /* We now have a valid preview window, so go with it */
97 new_win->w = try_win;
98 new_win->field = V4L2_FIELD_ANY;
99 return 0;
100}
101EXPORT_SYMBOL_GPL(omap_vout_try_window);
102
103/* Given a new render window in new_win, adjust the window to the
104 * nearest supported configuration. The image cropping window in crop
105 * will also be adjusted if necessary. Preference is given to keeping the
106 * the window as close to the requested configuration as possible. If
107 * successful, new_win, vout->win, and crop are updated.
108 * Returns zero if successful, or -EINVAL if the requested preview window is
109 * impossible and cannot reasonably be adjusted.
110 */
111int omap_vout_new_window(struct v4l2_rect *crop,
112 struct v4l2_window *win, struct v4l2_framebuffer *fbuf,
113 struct v4l2_window *new_win)
114{
115 int err;
116
117 err = omap_vout_try_window(fbuf, new_win);
118 if (err)
119 return err;
120
121 /* update our preview window */
122 win->w = new_win->w;
123 win->field = new_win->field;
124 win->chromakey = new_win->chromakey;
125
126 /* Adjust the cropping window to allow for resizing limitation */
127 if (cpu_is_omap24xx()) {
128 /* For 24xx limit is 8x to 1/2x scaling. */
129 if ((crop->height/win->w.height) >= 2)
130 crop->height = win->w.height * 2;
131
132 if ((crop->width/win->w.width) >= 2)
133 crop->width = win->w.width * 2;
134
135 if (crop->width > 768) {
136 /* The OMAP2420 vertical resizing line buffer is 768
137 * pixels wide. If the cropped image is wider than
138 * 768 pixels then it cannot be vertically resized.
139 */
140 if (crop->height != win->w.height)
141 crop->width = 768;
142 }
143 } else if (cpu_is_omap34xx()) {
144 /* For 34xx limit is 8x to 1/4x scaling. */
145 if ((crop->height/win->w.height) >= 4)
146 crop->height = win->w.height * 4;
147
148 if ((crop->width/win->w.width) >= 4)
149 crop->width = win->w.width * 4;
150 }
151 return 0;
152}
153EXPORT_SYMBOL_GPL(omap_vout_new_window);
154
155/* Given a new cropping rectangle in new_crop, adjust the cropping rectangle to
156 * the nearest supported configuration. The image render window in win will
157 * also be adjusted if necessary. The preview window is adjusted such that the
158 * horizontal and vertical rescaling ratios stay constant. If the render
159 * window would fall outside the display boundaries, the cropping rectangle
160 * will also be adjusted to maintain the rescaling ratios. If successful, crop
161 * and win are updated.
162 * Returns zero if successful, or -EINVAL if the requested cropping rectangle is
163 * impossible and cannot reasonably be adjusted.
164 */
165int omap_vout_new_crop(struct v4l2_pix_format *pix,
166 struct v4l2_rect *crop, struct v4l2_window *win,
167 struct v4l2_framebuffer *fbuf, const struct v4l2_rect *new_crop)
168{
169 struct v4l2_rect try_crop;
170 unsigned long vresize, hresize;
171
172 /* make a working copy of the new_crop rectangle */
173 try_crop = *new_crop;
174
175 /* adjust the cropping rectangle so it fits in the image */
176 if (try_crop.left < 0) {
177 try_crop.width += try_crop.left;
178 try_crop.left = 0;
179 }
180 if (try_crop.top < 0) {
181 try_crop.height += try_crop.top;
182 try_crop.top = 0;
183 }
184 try_crop.width = (try_crop.width < pix->width) ?
185 try_crop.width : pix->width;
186 try_crop.height = (try_crop.height < pix->height) ?
187 try_crop.height : pix->height;
188 if (try_crop.left + try_crop.width > pix->width)
189 try_crop.width = pix->width - try_crop.left;
190 if (try_crop.top + try_crop.height > pix->height)
191 try_crop.height = pix->height - try_crop.top;
192
193 try_crop.width &= ~1;
194 try_crop.height &= ~1;
195
196 if (try_crop.width <= 0 || try_crop.height <= 0)
197 return -EINVAL;
198
199 if (cpu_is_omap24xx()) {
200 if (try_crop.height != win->w.height) {
201 /* If we're resizing vertically, we can't support a
202 * crop width wider than 768 pixels.
203 */
204 if (try_crop.width > 768)
205 try_crop.width = 768;
206 }
207 }
208 /* vertical resizing */
209 vresize = (1024 * try_crop.height) / win->w.height;
210 if (cpu_is_omap24xx() && (vresize > 2048))
211 vresize = 2048;
212 else if (cpu_is_omap34xx() && (vresize > 4096))
213 vresize = 4096;
214
215 win->w.height = ((1024 * try_crop.height) / vresize) & ~1;
216 if (win->w.height == 0)
217 win->w.height = 2;
218 if (win->w.height + win->w.top > fbuf->fmt.height) {
219 /* We made the preview window extend below the bottom of the
220 * display, so clip it to the display boundary and resize the
221 * cropping height to maintain the vertical resizing ratio.
222 */
223 win->w.height = (fbuf->fmt.height - win->w.top) & ~1;
224 if (try_crop.height == 0)
225 try_crop.height = 2;
226 }
227 /* horizontal resizing */
228 hresize = (1024 * try_crop.width) / win->w.width;
229 if (cpu_is_omap24xx() && (hresize > 2048))
230 hresize = 2048;
231 else if (cpu_is_omap34xx() && (hresize > 4096))
232 hresize = 4096;
233
234 win->w.width = ((1024 * try_crop.width) / hresize) & ~1;
235 if (win->w.width == 0)
236 win->w.width = 2;
237 if (win->w.width + win->w.left > fbuf->fmt.width) {
238 /* We made the preview window extend past the right side of the
239 * display, so clip it to the display boundary and resize the
240 * cropping width to maintain the horizontal resizing ratio.
241 */
242 win->w.width = (fbuf->fmt.width - win->w.left) & ~1;
243 if (try_crop.width == 0)
244 try_crop.width = 2;
245 }
246 if (cpu_is_omap24xx()) {
247 if ((try_crop.height/win->w.height) >= 2)
248 try_crop.height = win->w.height * 2;
249
250 if ((try_crop.width/win->w.width) >= 2)
251 try_crop.width = win->w.width * 2;
252
253 if (try_crop.width > 768) {
254 /* The OMAP2420 vertical resizing line buffer is
255 * 768 pixels wide. If the cropped image is wider
256 * than 768 pixels then it cannot be vertically resized.
257 */
258 if (try_crop.height != win->w.height)
259 try_crop.width = 768;
260 }
261 } else if (cpu_is_omap34xx()) {
262 if ((try_crop.height/win->w.height) >= 4)
263 try_crop.height = win->w.height * 4;
264
265 if ((try_crop.width/win->w.width) >= 4)
266 try_crop.width = win->w.width * 4;
267 }
268 /* update our cropping rectangle and we're done */
269 *crop = try_crop;
270 return 0;
271}
272EXPORT_SYMBOL_GPL(omap_vout_new_crop);
273
274/* Given a new format in pix and fbuf, crop and win
275 * structures are initialized to default values. crop
276 * is initialized to the largest window size that will fit on the display. The
277 * crop window is centered in the image. win is initialized to
278 * the same size as crop and is centered on the display.
279 * All sizes and offsets are constrained to be even numbers.
280 */
281void omap_vout_new_format(struct v4l2_pix_format *pix,
282 struct v4l2_framebuffer *fbuf, struct v4l2_rect *crop,
283 struct v4l2_window *win)
284{
285 /* crop defines the preview source window in the image capture
286 * buffer
287 */
288 omap_vout_default_crop(pix, fbuf, crop);
289
290 /* win defines the preview target window on the display */
291 win->w.width = crop->width;
292 win->w.height = crop->height;
293 win->w.left = ((fbuf->fmt.width - win->w.width) >> 1) & ~1;
294 win->w.top = ((fbuf->fmt.height - win->w.height) >> 1) & ~1;
295}
296EXPORT_SYMBOL_GPL(omap_vout_new_format);
297
298/*
299 * Allocate buffers
300 */
301unsigned long omap_vout_alloc_buffer(u32 buf_size, u32 *phys_addr)
302{
303 u32 order, size;
304 unsigned long virt_addr, addr;
305
306 size = PAGE_ALIGN(buf_size);
307 order = get_order(size);
308 virt_addr = __get_free_pages(GFP_KERNEL, order);
309 addr = virt_addr;
310
311 if (virt_addr) {
312 while (size > 0) {
313 SetPageReserved(virt_to_page(addr));
314 addr += PAGE_SIZE;
315 size -= PAGE_SIZE;
316 }
317 }
318 *phys_addr = (u32) virt_to_phys((void *) virt_addr);
319 return virt_addr;
320}
321
322/*
323 * Free buffers
324 */
325void omap_vout_free_buffer(unsigned long virtaddr, u32 buf_size)
326{
327 u32 order, size;
328 unsigned long addr = virtaddr;
329
330 size = PAGE_ALIGN(buf_size);
331 order = get_order(size);
332
333 while (size > 0) {
334 ClearPageReserved(virt_to_page(addr));
335 addr += PAGE_SIZE;
336 size -= PAGE_SIZE;
337 }
338 free_pages((unsigned long) virtaddr, order);
339}