blob: 9be5adffa874683929ec57d41e17eeb36bf600aa [file] [log] [blame]
Mauro Carvalho Chehabd56410e2006-03-25 09:19:53 -03001/* Linux driver for Philips webcam
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 Various miscellaneous functions and tables.
3 (C) 1999-2003 Nemosoft Unv.
Luc Saillard2b455db2006-04-24 10:29:46 -03004 (C) 2004-2006 Luc Saillard (luc@saillard.org)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
6 NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
7 driver and thus may have bugs that are not present in the original version.
8 Please send bug reports and support requests to <luc@saillard.org>.
9 The decompression routines have been implemented by reverse-engineering the
10 Nemosoft binary pwcx module. Caveat emptor.
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25*/
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#include "pwc.h"
29
Hans de Goede795e6eb2012-01-04 16:58:44 -030030const int pwc_image_sizes[PSZ_MAX][2] =
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
Hans de Goede795e6eb2012-01-04 16:58:44 -030032 { 128, 96 }, /* sqcif */
33 { 160, 120 }, /* qsif */
34 { 176, 144 }, /* qcif */
35 { 320, 240 }, /* sif */
36 { 352, 288 }, /* cif */
37 { 640, 480 }, /* vga */
Linus Torvalds1da177e2005-04-16 15:20:36 -070038};
39
40/* x,y -> PSZ_ */
Hans de Goede795e6eb2012-01-04 16:58:44 -030041int pwc_get_size(struct pwc_device *pdev, int width, int height)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042{
Hans de Goede795e6eb2012-01-04 16:58:44 -030043 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45 /* Find the largest size supported by the camera that fits into the
Hans de Goede795e6eb2012-01-04 16:58:44 -030046 requested size. */
47 for (i = PSZ_MAX - 1; i >= 0; i--) {
48 if (!(pdev->image_mask & (1 << i)))
49 continue;
50
51 if (pwc_image_sizes[i][0] <= width &&
52 pwc_image_sizes[i][1] <= height)
53 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 }
Hans de Goede795e6eb2012-01-04 16:58:44 -030055
56 /* No mode found, return the smallest mode we have */
57 for (i = 0; i < PSZ_MAX; i++) {
58 if (pdev->image_mask & (1 << i))
59 return i;
60 }
61
62 /* Never reached there always is atleast one supported mode */
63 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064}
65
Hans de Goede795e6eb2012-01-04 16:58:44 -030066/* initialize variables depending on type and decompressor */
Linus Torvalds1da177e2005-04-16 15:20:36 -070067void pwc_construct(struct pwc_device *pdev)
68{
Luc Saillard2b455db2006-04-24 10:29:46 -030069 if (DEVICE_USE_CODEC1(pdev->type)) {
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 pdev->image_mask = 1 << PSZ_SQCIF | 1 << PSZ_QCIF | 1 << PSZ_CIF;
72 pdev->vcinterface = 2;
73 pdev->vendpoint = 4;
74 pdev->frame_header_size = 0;
75 pdev->frame_trailer_size = 0;
Luc Saillard2b455db2006-04-24 10:29:46 -030076
77 } else if (DEVICE_USE_CODEC3(pdev->type)) {
78
Luc Saillard2b455db2006-04-24 10:29:46 -030079 pdev->image_mask = 1 << PSZ_QSIF | 1 << PSZ_SIF | 1 << PSZ_VGA;
Luc Saillard2b455db2006-04-24 10:29:46 -030080 pdev->vcinterface = 3;
81 pdev->vendpoint = 5;
82 pdev->frame_header_size = TOUCAM_HEADER_SIZE;
83 pdev->frame_trailer_size = TOUCAM_TRAILER_SIZE;
84
85 } else /* if (DEVICE_USE_CODEC2(pdev->type)) */ {
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 pdev->image_mask = 1 << PSZ_SQCIF | 1 << PSZ_QSIF | 1 << PSZ_QCIF | 1 << PSZ_SIF | 1 << PSZ_CIF | 1 << PSZ_VGA;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 pdev->vcinterface = 3;
89 pdev->vendpoint = 4;
90 pdev->frame_header_size = 0;
91 pdev->frame_trailer_size = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070093}