^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2005 Mike Isely <isely@pobox.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include "pvrusb2-std.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "pvrusb2-debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <asm/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) struct std_name {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) v4l2_std_id id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define CSTD_PAL \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) (V4L2_STD_PAL_B| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) V4L2_STD_PAL_B1| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) V4L2_STD_PAL_G| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) V4L2_STD_PAL_H| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) V4L2_STD_PAL_I| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) V4L2_STD_PAL_D| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) V4L2_STD_PAL_D1| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) V4L2_STD_PAL_K| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) V4L2_STD_PAL_M| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) V4L2_STD_PAL_N| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) V4L2_STD_PAL_Nc| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) V4L2_STD_PAL_60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define CSTD_NTSC \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) (V4L2_STD_NTSC_M| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) V4L2_STD_NTSC_M_JP| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) V4L2_STD_NTSC_M_KR| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) V4L2_STD_NTSC_443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define CSTD_ATSC \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) (V4L2_STD_ATSC_8_VSB| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) V4L2_STD_ATSC_16_VSB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define CSTD_SECAM \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) (V4L2_STD_SECAM_B| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) V4L2_STD_SECAM_D| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) V4L2_STD_SECAM_G| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) V4L2_STD_SECAM_H| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) V4L2_STD_SECAM_K| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) V4L2_STD_SECAM_K1| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) V4L2_STD_SECAM_L| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) V4L2_STD_SECAM_LC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define TSTD_B (V4L2_STD_PAL_B|V4L2_STD_SECAM_B)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define TSTD_B1 (V4L2_STD_PAL_B1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define TSTD_D (V4L2_STD_PAL_D|V4L2_STD_SECAM_D)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define TSTD_D1 (V4L2_STD_PAL_D1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define TSTD_G (V4L2_STD_PAL_G|V4L2_STD_SECAM_G)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define TSTD_H (V4L2_STD_PAL_H|V4L2_STD_SECAM_H)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define TSTD_I (V4L2_STD_PAL_I)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define TSTD_K (V4L2_STD_PAL_K|V4L2_STD_SECAM_K)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define TSTD_K1 (V4L2_STD_SECAM_K1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define TSTD_L (V4L2_STD_SECAM_L)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define TSTD_M (V4L2_STD_PAL_M|V4L2_STD_NTSC_M)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define TSTD_N (V4L2_STD_PAL_N)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define TSTD_Nc (V4L2_STD_PAL_Nc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define TSTD_60 (V4L2_STD_PAL_60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define CSTD_ALL (CSTD_PAL|CSTD_NTSC|CSTD_ATSC|CSTD_SECAM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /* Mapping of standard bits to color system */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static const struct std_name std_groups[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {"PAL",CSTD_PAL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {"NTSC",CSTD_NTSC},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) {"SECAM",CSTD_SECAM},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {"ATSC",CSTD_ATSC},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /* Mapping of standard bits to modulation system */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static const struct std_name std_items[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) {"B",TSTD_B},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {"B1",TSTD_B1},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {"D",TSTD_D},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) {"D1",TSTD_D1},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {"G",TSTD_G},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {"H",TSTD_H},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {"I",TSTD_I},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {"K",TSTD_K},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {"K1",TSTD_K1},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {"L",TSTD_L},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {"LC",V4L2_STD_SECAM_LC},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {"M",TSTD_M},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {"Mj",V4L2_STD_NTSC_M_JP},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {"443",V4L2_STD_NTSC_443},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {"Mk",V4L2_STD_NTSC_M_KR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {"N",TSTD_N},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) {"Nc",TSTD_Nc},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) {"60",TSTD_60},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {"8VSB",V4L2_STD_ATSC_8_VSB},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {"16VSB",V4L2_STD_ATSC_16_VSB},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) // Search an array of std_name structures and return a pointer to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) // element with the matching name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static const struct std_name *find_std_name(const struct std_name *arrPtr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) unsigned int arrSize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) const char *bufPtr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) unsigned int bufSize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) unsigned int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) const struct std_name *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) for (idx = 0; idx < arrSize; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) p = arrPtr + idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (strlen(p->name) != bufSize) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (!memcmp(bufPtr,p->name,bufSize)) return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) int pvr2_std_str_to_id(v4l2_std_id *idPtr,const char *bufPtr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) unsigned int bufSize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) v4l2_std_id id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) v4l2_std_id cmsk = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) v4l2_std_id t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) int mMode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) unsigned int cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) char ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) const struct std_name *sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) while (bufSize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (!mMode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) while ((cnt < bufSize) && (bufPtr[cnt] != '-')) cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (cnt >= bufSize) return 0; // No more characters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) sp = find_std_name(std_groups, ARRAY_SIZE(std_groups),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) bufPtr,cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (!sp) return 0; // Illegal color system name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) bufPtr += cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) bufSize -= cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) mMode = !0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) cmsk = sp->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) while (cnt < bufSize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) ch = bufPtr[cnt];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (ch == ';') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) mMode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (ch == '/') break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) sp = find_std_name(std_items, ARRAY_SIZE(std_items),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) bufPtr,cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (!sp) return 0; // Illegal modulation system ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) t = sp->id & cmsk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (!t) return 0; // Specific color + modulation system illegal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) id |= t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (cnt < bufSize) cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) bufPtr += cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) bufSize -= cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (idPtr) *idPtr = id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return !0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) unsigned int pvr2_std_id_to_str(char *bufPtr, unsigned int bufSize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) v4l2_std_id id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) unsigned int idx1,idx2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) const struct std_name *ip,*gp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) int gfl,cfl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) unsigned int c1,c2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) cfl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) c1 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) for (idx1 = 0; idx1 < ARRAY_SIZE(std_groups); idx1++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) gp = std_groups + idx1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) gfl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) for (idx2 = 0; idx2 < ARRAY_SIZE(std_items); idx2++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) ip = std_items + idx2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (!(gp->id & ip->id & id)) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (!gfl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (cfl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) c2 = scnprintf(bufPtr,bufSize,";");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) c1 += c2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) bufSize -= c2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) bufPtr += c2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) cfl = !0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) c2 = scnprintf(bufPtr,bufSize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) "%s-",gp->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) gfl = !0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) c2 = scnprintf(bufPtr,bufSize,"/");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) c1 += c2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) bufSize -= c2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) bufPtr += c2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) c2 = scnprintf(bufPtr,bufSize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) ip->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) c1 += c2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) bufSize -= c2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) bufPtr += c2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return c1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) // Template data for possible enumerated video standards. Here we group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) // standards which share common frame rates and resolution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static struct v4l2_standard generic_standards[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) .id = (TSTD_B|TSTD_B1|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) TSTD_D|TSTD_D1|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) TSTD_G|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) TSTD_H|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) TSTD_I|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) TSTD_K|TSTD_K1|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) TSTD_L|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) V4L2_STD_SECAM_LC |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) TSTD_N|TSTD_Nc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) .frameperiod =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) .numerator = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) .denominator= 25
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) .framelines = 625,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) .reserved = {0,0,0,0}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) .id = (TSTD_M|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) V4L2_STD_NTSC_M_JP|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) V4L2_STD_NTSC_M_KR),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) .frameperiod =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) .numerator = 1001,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) .denominator= 30000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) .framelines = 525,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) .reserved = {0,0,0,0}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }, { // This is a total wild guess
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) .id = (TSTD_60),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) .frameperiod =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) .numerator = 1001,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) .denominator= 30000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) .framelines = 525,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) .reserved = {0,0,0,0}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }, { // This is total wild guess
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) .id = V4L2_STD_NTSC_443,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) .frameperiod =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) .numerator = 1001,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) .denominator= 30000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) .framelines = 525,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) .reserved = {0,0,0,0}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static struct v4l2_standard *match_std(v4l2_std_id id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) unsigned int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) for (idx = 0; idx < ARRAY_SIZE(generic_standards); idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (generic_standards[idx].id & id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) return generic_standards + idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static int pvr2_std_fill(struct v4l2_standard *std,v4l2_std_id id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) struct v4l2_standard *template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) unsigned int bcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) template = match_std(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (!template) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) idx = std->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) memcpy(std,template,sizeof(*template));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) std->index = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) std->id = id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) bcnt = pvr2_std_id_to_str(std->name,sizeof(std->name)-1,id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) std->name[bcnt] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) pvr2_trace(PVR2_TRACE_STD,"Set up standard idx=%u name=%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) std->index,std->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) return !0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) /* These are special cases of combined standards that we should enumerate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) separately if the component pieces are present. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static v4l2_std_id std_mixes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) V4L2_STD_PAL_B | V4L2_STD_PAL_G,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) V4L2_STD_PAL_D | V4L2_STD_PAL_K,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) V4L2_STD_SECAM_B | V4L2_STD_SECAM_G,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) V4L2_STD_SECAM_D | V4L2_STD_SECAM_K,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) struct v4l2_standard *pvr2_std_create_enum(unsigned int *countptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) v4l2_std_id id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) unsigned int std_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) unsigned int idx,bcnt,idx2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) v4l2_std_id idmsk,cmsk,fmsk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) struct v4l2_standard *stddefs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (pvrusb2_debug & PVR2_TRACE_STD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) char buf[100];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) bcnt = pvr2_std_id_to_str(buf,sizeof(buf),id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) pvr2_trace(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) PVR2_TRACE_STD,"Mapping standards mask=0x%x (%.*s)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) (int)id,bcnt,buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) *countptr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) std_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) fmsk = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) for (idmsk = 1, cmsk = id; cmsk; idmsk <<= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (!(idmsk & cmsk)) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) cmsk &= ~idmsk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (match_std(idmsk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) std_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) fmsk |= idmsk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) for (idx2 = 0; idx2 < ARRAY_SIZE(std_mixes); idx2++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) if ((id & std_mixes[idx2]) == std_mixes[idx2]) std_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) /* Don't complain about ATSC standard values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) fmsk &= ~CSTD_ATSC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (fmsk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) char buf[100];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) bcnt = pvr2_std_id_to_str(buf,sizeof(buf),fmsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) pvr2_trace(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) PVR2_TRACE_ERROR_LEGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) "***WARNING*** Failed to classify the following standard(s): %.*s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) bcnt,buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) pvr2_trace(PVR2_TRACE_STD,"Setting up %u unique standard(s)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) std_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) if (!std_cnt) return NULL; // paranoia
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) stddefs = kcalloc(std_cnt, sizeof(struct v4l2_standard),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (!stddefs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) for (idx = 0; idx < std_cnt; idx++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) stddefs[idx].index = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) /* Enumerate potential special cases */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) for (idx2 = 0; (idx2 < ARRAY_SIZE(std_mixes)) && (idx < std_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) idx2++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (!(id & std_mixes[idx2])) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) if (pvr2_std_fill(stddefs+idx,std_mixes[idx2])) idx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) /* Now enumerate individual pieces */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) for (idmsk = 1, cmsk = id; cmsk && (idx < std_cnt); idmsk <<= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (!(idmsk & cmsk)) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) cmsk &= ~idmsk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (!pvr2_std_fill(stddefs+idx,idmsk)) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) idx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) *countptr = std_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) return stddefs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) v4l2_std_id pvr2_std_get_usable(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) return CSTD_ALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }