xref: /openbmc/linux/drivers/media/usb/gspca/sn9c2028.h (revision a2cce7a9)
1 /*
2  * SN9C2028 common functions
3  *
4  * Copyright (C) 2009 Theodore Kilgore <kilgota@auburn,edu>
5  *
6  * Based closely upon the file gspca/pac_common.h
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 by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23 
24 static const unsigned char sn9c2028_sof_marker[] = {
25 	0xff, 0xff, 0x00, 0xc4, 0xc4, 0x96,
26 	0x00,
27 	0x00, /* seq */
28 	0x00,
29 	0x00,
30 	0x00, /* avg luminance lower 8 bit */
31 	0x00, /* avg luminance higher 8 bit */
32 };
33 
34 static unsigned char *sn9c2028_find_sof(struct gspca_dev *gspca_dev,
35 					unsigned char *m, int len)
36 {
37 	struct sd *sd = (struct sd *) gspca_dev;
38 	int i;
39 
40 	/* Search for the SOF marker (fixed part) in the header */
41 	for (i = 0; i < len; i++) {
42 		if ((m[i] == sn9c2028_sof_marker[sd->sof_read]) ||
43 		    (sd->sof_read > 5)) {
44 			sd->sof_read++;
45 			if (sd->sof_read == 11)
46 				sd->avg_lum_l = m[i];
47 			if (sd->sof_read == 12)
48 				sd->avg_lum = (m[i] << 8) + sd->avg_lum_l;
49 			if (sd->sof_read == sizeof(sn9c2028_sof_marker)) {
50 				PDEBUG(D_FRAM,
51 					"SOF found, bytes to analyze: %u."
52 					" Frame starts at byte #%u",
53 					len, i + 1);
54 				sd->sof_read = 0;
55 				return m + i + 1;
56 			}
57 		} else {
58 			sd->sof_read = 0;
59 		}
60 	}
61 
62 	return NULL;
63 }
64