18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/* Linux driver for Philips webcam
38c2ecf20Sopenharmony_ci   Various miscellaneous functions and tables.
48c2ecf20Sopenharmony_ci   (C) 1999-2003 Nemosoft Unv.
58c2ecf20Sopenharmony_ci   (C) 2004-2006 Luc Saillard (luc@saillard.org)
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci   NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
88c2ecf20Sopenharmony_ci   driver and thus may have bugs that are not present in the original version.
98c2ecf20Sopenharmony_ci   Please send bug reports and support requests to <luc@saillard.org>.
108c2ecf20Sopenharmony_ci   The decompression routines have been implemented by reverse-engineering the
118c2ecf20Sopenharmony_ci   Nemosoft binary pwcx module. Caveat emptor.
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci*/
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include "pwc.h"
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ciconst int pwc_image_sizes[PSZ_MAX][2] =
198c2ecf20Sopenharmony_ci{
208c2ecf20Sopenharmony_ci	{ 128,  96 }, /* sqcif */
218c2ecf20Sopenharmony_ci	{ 160, 120 }, /* qsif */
228c2ecf20Sopenharmony_ci	{ 176, 144 }, /* qcif */
238c2ecf20Sopenharmony_ci	{ 320, 240 }, /* sif */
248c2ecf20Sopenharmony_ci	{ 352, 288 }, /* cif */
258c2ecf20Sopenharmony_ci	{ 640, 480 }, /* vga */
268c2ecf20Sopenharmony_ci};
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci/* x,y -> PSZ_ */
298c2ecf20Sopenharmony_ciint pwc_get_size(struct pwc_device *pdev, int width, int height)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	int i;
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	/* Find the largest size supported by the camera that fits into the
348c2ecf20Sopenharmony_ci	   requested size. */
358c2ecf20Sopenharmony_ci	for (i = PSZ_MAX - 1; i >= 0; i--) {
368c2ecf20Sopenharmony_ci		if (!(pdev->image_mask & (1 << i)))
378c2ecf20Sopenharmony_ci			continue;
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci		if (pwc_image_sizes[i][0] <= width &&
408c2ecf20Sopenharmony_ci		    pwc_image_sizes[i][1] <= height)
418c2ecf20Sopenharmony_ci			return i;
428c2ecf20Sopenharmony_ci	}
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	/* No mode found, return the smallest mode we have */
458c2ecf20Sopenharmony_ci	for (i = 0; i < PSZ_MAX; i++) {
468c2ecf20Sopenharmony_ci		if (pdev->image_mask & (1 << i))
478c2ecf20Sopenharmony_ci			return i;
488c2ecf20Sopenharmony_ci	}
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	/* Never reached there always is at least one supported mode */
518c2ecf20Sopenharmony_ci	return 0;
528c2ecf20Sopenharmony_ci}
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci/* initialize variables depending on type and decompressor */
558c2ecf20Sopenharmony_civoid pwc_construct(struct pwc_device *pdev)
568c2ecf20Sopenharmony_ci{
578c2ecf20Sopenharmony_ci	if (DEVICE_USE_CODEC1(pdev->type)) {
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci		pdev->image_mask = 1 << PSZ_SQCIF | 1 << PSZ_QCIF | 1 << PSZ_CIF;
608c2ecf20Sopenharmony_ci		pdev->vcinterface = 2;
618c2ecf20Sopenharmony_ci		pdev->vendpoint = 4;
628c2ecf20Sopenharmony_ci		pdev->frame_header_size = 0;
638c2ecf20Sopenharmony_ci		pdev->frame_trailer_size = 0;
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	} else if (DEVICE_USE_CODEC3(pdev->type)) {
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci		pdev->image_mask = 1 << PSZ_QSIF | 1 << PSZ_SIF | 1 << PSZ_VGA;
688c2ecf20Sopenharmony_ci		pdev->vcinterface = 3;
698c2ecf20Sopenharmony_ci		pdev->vendpoint = 5;
708c2ecf20Sopenharmony_ci		pdev->frame_header_size = TOUCAM_HEADER_SIZE;
718c2ecf20Sopenharmony_ci		pdev->frame_trailer_size = TOUCAM_TRAILER_SIZE;
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci	} else /* if (DEVICE_USE_CODEC2(pdev->type)) */ {
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci		pdev->image_mask = 1 << PSZ_SQCIF | 1 << PSZ_QSIF | 1 << PSZ_QCIF | 1 << PSZ_SIF | 1 << PSZ_CIF | 1 << PSZ_VGA;
768c2ecf20Sopenharmony_ci		pdev->vcinterface = 3;
778c2ecf20Sopenharmony_ci		pdev->vendpoint = 4;
788c2ecf20Sopenharmony_ci		pdev->frame_header_size = 0;
798c2ecf20Sopenharmony_ci		pdev->frame_trailer_size = 0;
808c2ecf20Sopenharmony_ci	}
818c2ecf20Sopenharmony_ci}
82