^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * SN9C2028 common functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2009 Theodore Kilgore <kilgota@auburn,edu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Based closely upon the file gspca/pac_common.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) static const unsigned char sn9c2028_sof_marker[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) 0xff, 0xff, 0x00, 0xc4, 0xc4, 0x96,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 0x00, /* seq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 0x00, /* avg luminance lower 8 bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 0x00, /* avg luminance higher 8 bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static unsigned char *sn9c2028_find_sof(struct gspca_dev *gspca_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) unsigned char *m, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct sd *sd = (struct sd *) gspca_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /* Search for the SOF marker (fixed part) in the header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) for (i = 0; i < len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if ((m[i] == sn9c2028_sof_marker[sd->sof_read]) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) (sd->sof_read > 5)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) sd->sof_read++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) if (sd->sof_read == 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) sd->avg_lum_l = m[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) if (sd->sof_read == 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) sd->avg_lum = (m[i] << 8) + sd->avg_lum_l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) if (sd->sof_read == sizeof(sn9c2028_sof_marker)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) gspca_dbg(gspca_dev, D_FRAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) "SOF found, bytes to analyze: %u - Frame starts at byte #%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) len, i + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) sd->sof_read = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) return m + i + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) sd->sof_read = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }