xref: /openbmc/linux/drivers/media/common/tveeprom.c (revision e2ad626f)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * tveeprom - eeprom decoder for tvcard configuration eeproms
4  *
5  * Data and decoding routines shamelessly borrowed from bttv-cards.c
6  * eeprom access routine shamelessly borrowed from bttv-if.c
7  * which are:
8 
9     Copyright (C) 1996,97,98 Ralph  Metzler (rjkm@thp.uni-koeln.de)
10 			   & Marcus Metzler (mocm@thp.uni-koeln.de)
11     (c) 1999-2001 Gerd Knorr <kraxel@goldbach.in-berlin.de>
12 
13  * Adjustments to fit a more general model and all bugs:
14 
15 	Copyright (C) 2003 John Klar <linpvr at projectplasma.com>
16 
17  */
18 
19 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 
21 #include <linux/module.h>
22 #include <linux/errno.h>
23 #include <linux/kernel.h>
24 #include <linux/init.h>
25 #include <linux/types.h>
26 #include <linux/videodev2.h>
27 #include <linux/i2c.h>
28 
29 #include <media/tuner.h>
30 #include <media/tveeprom.h>
31 #include <media/v4l2-common.h>
32 
33 MODULE_DESCRIPTION("i2c Hauppauge eeprom decoder driver");
34 MODULE_AUTHOR("John Klar");
35 MODULE_LICENSE("GPL");
36 
37 #define STRM(array, i) \
38 	(i < sizeof(array) / sizeof(char *) ? array[i] : "unknown")
39 
40 
41 /*
42  * The Hauppauge eeprom uses an 8bit field to determine which
43  * tuner formats the tuner supports.
44  */
45 static const struct {
46 	int	id;
47 	const char * const name;
48 } hauppauge_tuner_fmt[] = {
49 	{ V4L2_STD_UNKNOWN,                   " UNKNOWN" },
50 	{ V4L2_STD_UNKNOWN,                   " FM" },
51 	{ V4L2_STD_B|V4L2_STD_GH,             " PAL(B/G)" },
52 	{ V4L2_STD_MN,                        " NTSC(M)" },
53 	{ V4L2_STD_PAL_I,                     " PAL(I)" },
54 	{ V4L2_STD_SECAM_L|V4L2_STD_SECAM_LC, " SECAM(L/L')" },
55 	{ V4L2_STD_DK,                        " PAL(D/D1/K)" },
56 	{ V4L2_STD_ATSC,                      " ATSC/DVB Digital" },
57 };
58 
59 /* This is the full list of possible tuners. Many thanks to Hauppauge for
60    supplying this information. Note that many tuners where only used for
61    testing and never made it to the outside world. So you will only see
62    a subset in actual produced cards. */
63 static const struct {
64 	int  id;
65 	const char * const name;
66 } hauppauge_tuner[] = {
67 	/* 0-9 */
68 	{ TUNER_ABSENT,			"None" },
69 	{ TUNER_ABSENT,			"External" },
70 	{ TUNER_ABSENT,			"Unspecified" },
71 	{ TUNER_PHILIPS_PAL,		"Philips FI1216" },
72 	{ TUNER_PHILIPS_SECAM,		"Philips FI1216MF" },
73 	{ TUNER_PHILIPS_NTSC,		"Philips FI1236" },
74 	{ TUNER_PHILIPS_PAL_I,		"Philips FI1246" },
75 	{ TUNER_PHILIPS_PAL_DK,		"Philips FI1256" },
76 	{ TUNER_PHILIPS_PAL,		"Philips FI1216 MK2" },
77 	{ TUNER_PHILIPS_SECAM,		"Philips FI1216MF MK2" },
78 	/* 10-19 */
79 	{ TUNER_PHILIPS_NTSC,		"Philips FI1236 MK2" },
80 	{ TUNER_PHILIPS_PAL_I,		"Philips FI1246 MK2" },
81 	{ TUNER_PHILIPS_PAL_DK,		"Philips FI1256 MK2" },
82 	{ TUNER_TEMIC_NTSC,		"Temic 4032FY5" },
83 	{ TUNER_TEMIC_PAL,		"Temic 4002FH5" },
84 	{ TUNER_TEMIC_PAL_I,		"Temic 4062FY5" },
85 	{ TUNER_PHILIPS_PAL,		"Philips FR1216 MK2" },
86 	{ TUNER_PHILIPS_SECAM,		"Philips FR1216MF MK2" },
87 	{ TUNER_PHILIPS_NTSC,		"Philips FR1236 MK2" },
88 	{ TUNER_PHILIPS_PAL_I,		"Philips FR1246 MK2" },
89 	/* 20-29 */
90 	{ TUNER_PHILIPS_PAL_DK,		"Philips FR1256 MK2" },
91 	{ TUNER_PHILIPS_PAL,		"Philips FM1216" },
92 	{ TUNER_PHILIPS_SECAM,		"Philips FM1216MF" },
93 	{ TUNER_PHILIPS_NTSC,		"Philips FM1236" },
94 	{ TUNER_PHILIPS_PAL_I,		"Philips FM1246" },
95 	{ TUNER_PHILIPS_PAL_DK,		"Philips FM1256" },
96 	{ TUNER_TEMIC_4036FY5_NTSC,	"Temic 4036FY5" },
97 	{ TUNER_ABSENT,			"Samsung TCPN9082D" },
98 	{ TUNER_ABSENT,			"Samsung TCPM9092P" },
99 	{ TUNER_TEMIC_4006FH5_PAL,	"Temic 4006FH5" },
100 	/* 30-39 */
101 	{ TUNER_ABSENT,			"Samsung TCPN9085D" },
102 	{ TUNER_ABSENT,			"Samsung TCPB9085P" },
103 	{ TUNER_ABSENT,			"Samsung TCPL9091P" },
104 	{ TUNER_TEMIC_4039FR5_NTSC,	"Temic 4039FR5" },
105 	{ TUNER_PHILIPS_FQ1216ME,	"Philips FQ1216 ME" },
106 	{ TUNER_TEMIC_4066FY5_PAL_I,	"Temic 4066FY5" },
107 	{ TUNER_PHILIPS_NTSC,		"Philips TD1536" },
108 	{ TUNER_PHILIPS_NTSC,		"Philips TD1536D" },
109 	{ TUNER_PHILIPS_NTSC,		"Philips FMR1236" }, /* mono radio */
110 	{ TUNER_ABSENT,			"Philips FI1256MP" },
111 	/* 40-49 */
112 	{ TUNER_ABSENT,			"Samsung TCPQ9091P" },
113 	{ TUNER_TEMIC_4006FN5_MULTI_PAL,"Temic 4006FN5" },
114 	{ TUNER_TEMIC_4009FR5_PAL,	"Temic 4009FR5" },
115 	{ TUNER_TEMIC_4046FM5,		"Temic 4046FM5" },
116 	{ TUNER_TEMIC_4009FN5_MULTI_PAL_FM, "Temic 4009FN5" },
117 	{ TUNER_ABSENT,			"Philips TD1536D FH 44"},
118 	{ TUNER_LG_NTSC_FM,		"LG TP18NSR01F"},
119 	{ TUNER_LG_PAL_FM,		"LG TP18PSB01D"},
120 	{ TUNER_LG_PAL,		"LG TP18PSB11D"},
121 	{ TUNER_LG_PAL_I_FM,		"LG TAPC-I001D"},
122 	/* 50-59 */
123 	{ TUNER_LG_PAL_I,		"LG TAPC-I701D"},
124 	{ TUNER_ABSENT,			"Temic 4042FI5"},
125 	{ TUNER_MICROTUNE_4049FM5,	"Microtune 4049 FM5"},
126 	{ TUNER_ABSENT,			"LG TPI8NSR11F"},
127 	{ TUNER_ABSENT,			"Microtune 4049 FM5 Alt I2C"},
128 	{ TUNER_PHILIPS_FM1216ME_MK3,	"Philips FQ1216ME MK3"},
129 	{ TUNER_ABSENT,			"Philips FI1236 MK3"},
130 	{ TUNER_PHILIPS_FM1216ME_MK3,	"Philips FM1216 ME MK3"},
131 	{ TUNER_PHILIPS_FM1236_MK3,	"Philips FM1236 MK3"},
132 	{ TUNER_ABSENT,			"Philips FM1216MP MK3"},
133 	/* 60-69 */
134 	{ TUNER_PHILIPS_FM1216ME_MK3,	"LG S001D MK3"},
135 	{ TUNER_ABSENT,			"LG M001D MK3"},
136 	{ TUNER_PHILIPS_FM1216ME_MK3,	"LG S701D MK3"},
137 	{ TUNER_ABSENT,			"LG M701D MK3"},
138 	{ TUNER_ABSENT,			"Temic 4146FM5"},
139 	{ TUNER_ABSENT,			"Temic 4136FY5"},
140 	{ TUNER_ABSENT,			"Temic 4106FH5"},
141 	{ TUNER_ABSENT,			"Philips FQ1216LMP MK3"},
142 	{ TUNER_LG_NTSC_TAPE,		"LG TAPE H001F MK3"},
143 	{ TUNER_LG_NTSC_TAPE,		"LG TAPE H701F MK3"},
144 	/* 70-79 */
145 	{ TUNER_ABSENT,			"LG TALN H200T"},
146 	{ TUNER_ABSENT,			"LG TALN H250T"},
147 	{ TUNER_ABSENT,			"LG TALN M200T"},
148 	{ TUNER_ABSENT,			"LG TALN Z200T"},
149 	{ TUNER_ABSENT,			"LG TALN S200T"},
150 	{ TUNER_ABSENT,			"Thompson DTT7595"},
151 	{ TUNER_ABSENT,			"Thompson DTT7592"},
152 	{ TUNER_ABSENT,			"Silicon TDA8275C1 8290"},
153 	{ TUNER_ABSENT,			"Silicon TDA8275C1 8290 FM"},
154 	{ TUNER_ABSENT,			"Thompson DTT757"},
155 	/* 80-89 */
156 	{ TUNER_PHILIPS_FQ1216LME_MK3,	"Philips FQ1216LME MK3"},
157 	{ TUNER_LG_PAL_NEW_TAPC,	"LG TAPC G701D"},
158 	{ TUNER_LG_NTSC_NEW_TAPC,	"LG TAPC H791F"},
159 	{ TUNER_LG_PAL_NEW_TAPC,	"TCL 2002MB 3"},
160 	{ TUNER_LG_PAL_NEW_TAPC,	"TCL 2002MI 3"},
161 	{ TUNER_TCL_2002N,		"TCL 2002N 6A"},
162 	{ TUNER_PHILIPS_FM1236_MK3,	"Philips FQ1236 MK3"},
163 	{ TUNER_SAMSUNG_TCPN_2121P30A,	"Samsung TCPN 2121P30A"},
164 	{ TUNER_ABSENT,			"Samsung TCPE 4121P30A"},
165 	{ TUNER_PHILIPS_FM1216ME_MK3,	"TCL MFPE05 2"},
166 	/* 90-99 */
167 	{ TUNER_ABSENT,			"LG TALN H202T"},
168 	{ TUNER_PHILIPS_FQ1216AME_MK4,	"Philips FQ1216AME MK4"},
169 	{ TUNER_PHILIPS_FQ1236A_MK4,	"Philips FQ1236A MK4"},
170 	{ TUNER_ABSENT,			"Philips FQ1286A MK4"},
171 	{ TUNER_ABSENT,			"Philips FQ1216ME MK5"},
172 	{ TUNER_ABSENT,			"Philips FQ1236 MK5"},
173 	{ TUNER_SAMSUNG_TCPG_6121P30A,	"Samsung TCPG 6121P30A"},
174 	{ TUNER_TCL_2002MB,		"TCL 2002MB_3H"},
175 	{ TUNER_ABSENT,			"TCL 2002MI_3H"},
176 	{ TUNER_TCL_2002N,		"TCL 2002N 5H"},
177 	/* 100-109 */
178 	{ TUNER_PHILIPS_FMD1216ME_MK3,	"Philips FMD1216ME"},
179 	{ TUNER_TEA5767,		"Philips TEA5768HL FM Radio"},
180 	{ TUNER_ABSENT,			"Panasonic ENV57H12D5"},
181 	{ TUNER_PHILIPS_FM1236_MK3,	"TCL MFNM05-4"},
182 	{ TUNER_PHILIPS_FM1236_MK3,	"TCL MNM05-4"},
183 	{ TUNER_PHILIPS_FM1216ME_MK3,	"TCL MPE05-2"},
184 	{ TUNER_ABSENT,			"TCL MQNM05-4"},
185 	{ TUNER_ABSENT,			"LG TAPC-W701D"},
186 	{ TUNER_ABSENT,			"TCL 9886P-WM"},
187 	{ TUNER_ABSENT,			"TCL 1676NM-WM"},
188 	/* 110-119 */
189 	{ TUNER_ABSENT,			"Thompson DTT75105"},
190 	{ TUNER_ABSENT,			"Conexant_CX24109"},
191 	{ TUNER_TCL_2002N,		"TCL M2523_5N_E"},
192 	{ TUNER_TCL_2002MB,		"TCL M2523_3DB_E"},
193 	{ TUNER_ABSENT,			"Philips 8275A"},
194 	{ TUNER_ABSENT,			"Microtune MT2060"},
195 	{ TUNER_PHILIPS_FM1236_MK3,	"Philips FM1236 MK5"},
196 	{ TUNER_PHILIPS_FM1216ME_MK3,	"Philips FM1216ME MK5"},
197 	{ TUNER_ABSENT,			"TCL M2523_3DI_E"},
198 	{ TUNER_ABSENT,			"Samsung THPD5222FG30A"},
199 	/* 120-129 */
200 	{ TUNER_XC2028,			"Xceive XC3028"},
201 	{ TUNER_PHILIPS_FQ1216LME_MK3,	"Philips FQ1216LME MK5"},
202 	{ TUNER_ABSENT,			"Philips FQD1216LME"},
203 	{ TUNER_ABSENT,			"Conexant CX24118A"},
204 	{ TUNER_ABSENT,			"TCL DMF11WIP"},
205 	{ TUNER_ABSENT,			"TCL MFNM05_4H_E"},
206 	{ TUNER_ABSENT,			"TCL MNM05_4H_E"},
207 	{ TUNER_ABSENT,			"TCL MPE05_2H_E"},
208 	{ TUNER_ABSENT,			"TCL MQNM05_4_U"},
209 	{ TUNER_ABSENT,			"TCL M2523_5NH_E"},
210 	/* 130-139 */
211 	{ TUNER_ABSENT,			"TCL M2523_3DBH_E"},
212 	{ TUNER_ABSENT,			"TCL M2523_3DIH_E"},
213 	{ TUNER_ABSENT,			"TCL MFPE05_2_U"},
214 	{ TUNER_PHILIPS_FMD1216MEX_MK3,	"Philips FMD1216MEX"},
215 	{ TUNER_ABSENT,			"Philips FRH2036B"},
216 	{ TUNER_ABSENT,			"Panasonic ENGF75_01GF"},
217 	{ TUNER_ABSENT,			"MaxLinear MXL5005"},
218 	{ TUNER_ABSENT,			"MaxLinear MXL5003"},
219 	{ TUNER_ABSENT,			"Xceive XC2028"},
220 	{ TUNER_ABSENT,			"Microtune MT2131"},
221 	/* 140-149 */
222 	{ TUNER_ABSENT,			"Philips 8275A_8295"},
223 	{ TUNER_ABSENT,			"TCL MF02GIP_5N_E"},
224 	{ TUNER_ABSENT,			"TCL MF02GIP_3DB_E"},
225 	{ TUNER_ABSENT,			"TCL MF02GIP_3DI_E"},
226 	{ TUNER_ABSENT,			"Microtune MT2266"},
227 	{ TUNER_ABSENT,			"TCL MF10WPP_4N_E"},
228 	{ TUNER_ABSENT,			"LG TAPQ_H702F"},
229 	{ TUNER_ABSENT,			"TCL M09WPP_4N_E"},
230 	{ TUNER_ABSENT,			"MaxLinear MXL5005_v2"},
231 	{ TUNER_PHILIPS_TDA8290,	"Philips 18271_8295"},
232 	/* 150-159 */
233 	{ TUNER_XC5000,                 "Xceive XC5000"},
234 	{ TUNER_ABSENT,                 "Xceive XC3028L"},
235 	{ TUNER_ABSENT,                 "NXP 18271C2_716x"},
236 	{ TUNER_ABSENT,                 "Xceive XC4000"},
237 	{ TUNER_ABSENT,                 "Dibcom 7070"},
238 	{ TUNER_PHILIPS_TDA8290,        "NXP 18271C2"},
239 	{ TUNER_ABSENT,                 "Siano SMS1010"},
240 	{ TUNER_ABSENT,                 "Siano SMS1150"},
241 	{ TUNER_ABSENT,                 "MaxLinear 5007"},
242 	{ TUNER_ABSENT,                 "TCL M09WPP_2P_E"},
243 	/* 160-169 */
244 	{ TUNER_ABSENT,                 "Siano SMS1180"},
245 	{ TUNER_ABSENT,                 "Maxim_MAX2165"},
246 	{ TUNER_ABSENT,                 "Siano SMS1140"},
247 	{ TUNER_ABSENT,                 "Siano SMS1150 B1"},
248 	{ TUNER_ABSENT,                 "MaxLinear 111"},
249 	{ TUNER_ABSENT,                 "Dibcom 7770"},
250 	{ TUNER_ABSENT,                 "Siano SMS1180VNS"},
251 	{ TUNER_ABSENT,                 "Siano SMS1184"},
252 	{ TUNER_PHILIPS_FQ1236_MK5,	"TCL M30WTP-4N-E"},
253 	{ TUNER_ABSENT,                 "TCL_M11WPP_2PN_E"},
254 	/* 170-179 */
255 	{ TUNER_ABSENT,                 "MaxLinear 301"},
256 	{ TUNER_ABSENT,                 "Mirics MSi001"},
257 	{ TUNER_ABSENT,                 "MaxLinear MxL241SF"},
258 	{ TUNER_XC5000C,                "Xceive XC5000C"},
259 	{ TUNER_ABSENT,                 "Montage M68TS2020"},
260 	{ TUNER_ABSENT,                 "Siano SMS1530"},
261 	{ TUNER_ABSENT,                 "Dibcom 7090"},
262 	{ TUNER_ABSENT,                 "Xceive XC5200C"},
263 	{ TUNER_ABSENT,                 "NXP 18273"},
264 	{ TUNER_ABSENT,                 "Montage M88TS2022"},
265 	/* 180-188 */
266 	{ TUNER_ABSENT,                 "NXP 18272M"},
267 	{ TUNER_ABSENT,                 "NXP 18272S"},
268 
269 	{ TUNER_ABSENT,                 "Mirics MSi003"},
270 	{ TUNER_ABSENT,                 "MaxLinear MxL256"},
271 	{ TUNER_ABSENT,                 "SiLabs Si2158"},
272 	{ TUNER_ABSENT,                 "SiLabs Si2178"},
273 	{ TUNER_ABSENT,                 "SiLabs Si2157"},
274 	{ TUNER_ABSENT,                 "SiLabs Si2177"},
275 	{ TUNER_ABSENT,                 "ITE IT9137FN"},
276 };
277 
278 /* Use TVEEPROM_AUDPROC_INTERNAL for those audio 'chips' that are
279  * internal to a video chip, i.e. not a separate audio chip. */
280 static const struct {
281 	u32   id;
282 	const char * const name;
283 } audio_ic[] = {
284 	/* 0-4 */
285 	{ TVEEPROM_AUDPROC_NONE,  "None"      },
286 	{ TVEEPROM_AUDPROC_OTHER, "TEA6300"   },
287 	{ TVEEPROM_AUDPROC_OTHER, "TEA6320"   },
288 	{ TVEEPROM_AUDPROC_OTHER, "TDA9850"   },
289 	{ TVEEPROM_AUDPROC_MSP,   "MSP3400C"  },
290 	/* 5-9 */
291 	{ TVEEPROM_AUDPROC_MSP,   "MSP3410D"  },
292 	{ TVEEPROM_AUDPROC_MSP,   "MSP3415"   },
293 	{ TVEEPROM_AUDPROC_MSP,   "MSP3430"   },
294 	{ TVEEPROM_AUDPROC_MSP,   "MSP3438"   },
295 	{ TVEEPROM_AUDPROC_OTHER, "CS5331"    },
296 	/* 10-14 */
297 	{ TVEEPROM_AUDPROC_MSP,   "MSP3435"   },
298 	{ TVEEPROM_AUDPROC_MSP,   "MSP3440"   },
299 	{ TVEEPROM_AUDPROC_MSP,   "MSP3445"   },
300 	{ TVEEPROM_AUDPROC_MSP,   "MSP3411"   },
301 	{ TVEEPROM_AUDPROC_MSP,   "MSP3416"   },
302 	/* 15-19 */
303 	{ TVEEPROM_AUDPROC_MSP,   "MSP3425"   },
304 	{ TVEEPROM_AUDPROC_MSP,   "MSP3451"   },
305 	{ TVEEPROM_AUDPROC_MSP,   "MSP3418"   },
306 	{ TVEEPROM_AUDPROC_OTHER, "Type 0x12" },
307 	{ TVEEPROM_AUDPROC_OTHER, "OKI7716"   },
308 	/* 20-24 */
309 	{ TVEEPROM_AUDPROC_MSP,   "MSP4410"   },
310 	{ TVEEPROM_AUDPROC_MSP,   "MSP4420"   },
311 	{ TVEEPROM_AUDPROC_MSP,   "MSP4440"   },
312 	{ TVEEPROM_AUDPROC_MSP,   "MSP4450"   },
313 	{ TVEEPROM_AUDPROC_MSP,   "MSP4408"   },
314 	/* 25-29 */
315 	{ TVEEPROM_AUDPROC_MSP,   "MSP4418"   },
316 	{ TVEEPROM_AUDPROC_MSP,   "MSP4428"   },
317 	{ TVEEPROM_AUDPROC_MSP,   "MSP4448"   },
318 	{ TVEEPROM_AUDPROC_MSP,   "MSP4458"   },
319 	{ TVEEPROM_AUDPROC_MSP,   "Type 0x1d" },
320 	/* 30-34 */
321 	{ TVEEPROM_AUDPROC_INTERNAL, "CX880"     },
322 	{ TVEEPROM_AUDPROC_INTERNAL, "CX881"     },
323 	{ TVEEPROM_AUDPROC_INTERNAL, "CX883"     },
324 	{ TVEEPROM_AUDPROC_INTERNAL, "CX882"     },
325 	{ TVEEPROM_AUDPROC_INTERNAL, "CX25840"   },
326 	/* 35-39 */
327 	{ TVEEPROM_AUDPROC_INTERNAL, "CX25841"   },
328 	{ TVEEPROM_AUDPROC_INTERNAL, "CX25842"   },
329 	{ TVEEPROM_AUDPROC_INTERNAL, "CX25843"   },
330 	{ TVEEPROM_AUDPROC_INTERNAL, "CX23418"   },
331 	{ TVEEPROM_AUDPROC_INTERNAL, "CX23885"   },
332 	/* 40-44 */
333 	{ TVEEPROM_AUDPROC_INTERNAL, "CX23888"   },
334 	{ TVEEPROM_AUDPROC_INTERNAL, "SAA7131"   },
335 	{ TVEEPROM_AUDPROC_INTERNAL, "CX23887"   },
336 	{ TVEEPROM_AUDPROC_INTERNAL, "SAA7164"   },
337 	{ TVEEPROM_AUDPROC_INTERNAL, "AU8522"    },
338 	/* 45-49 */
339 	{ TVEEPROM_AUDPROC_INTERNAL, "AVF4910B"  },
340 	{ TVEEPROM_AUDPROC_INTERNAL, "SAA7231"   },
341 	{ TVEEPROM_AUDPROC_INTERNAL, "CX23102"   },
342 	{ TVEEPROM_AUDPROC_INTERNAL, "SAA7163"   },
343 	{ TVEEPROM_AUDPROC_OTHER,    "AK4113"    },
344 	/* 50-52 */
345 	{ TVEEPROM_AUDPROC_OTHER,    "CS5340"    },
346 	{ TVEEPROM_AUDPROC_OTHER,    "CS8416"    },
347 	{ TVEEPROM_AUDPROC_OTHER,    "CX20810"   },
348 };
349 
350 /* This list is supplied by Hauppauge. Thanks! */
351 static const char *decoderIC[] = {
352 	/* 0-4 */
353 	"None", "BT815", "BT817", "BT819", "BT815A",
354 	/* 5-9 */
355 	"BT817A", "BT819A", "BT827", "BT829", "BT848",
356 	/* 10-14 */
357 	"BT848A", "BT849A", "BT829A", "BT827A", "BT878",
358 	/* 15-19 */
359 	"BT879", "BT880", "VPX3226E", "SAA7114", "SAA7115",
360 	/* 20-24 */
361 	"CX880", "CX881", "CX883", "SAA7111", "SAA7113",
362 	/* 25-29 */
363 	"CX882", "TVP5150A", "CX25840", "CX25841", "CX25842",
364 	/* 30-34 */
365 	"CX25843", "CX23418", "NEC61153", "CX23885", "CX23888",
366 	/* 35-39 */
367 	"SAA7131", "CX25837", "CX23887", "CX23885A", "CX23887A",
368 	/* 40-44 */
369 	"SAA7164", "CX23885B", "AU8522", "ADV7401", "AVF4910B",
370 	/* 45-49 */
371 	"SAA7231", "CX23102", "SAA7163", "ADV7441A", "ADV7181C",
372 	/* 50-53 */
373 	"CX25836", "TDA9955", "TDA19977", "ADV7842"
374 };
375 
376 static int hasRadioTuner(int tunerType)
377 {
378 	switch (tunerType) {
379 	case 18: /* PNPEnv_TUNER_FR1236_MK2 */
380 	case 23: /* PNPEnv_TUNER_FM1236 */
381 	case 38: /* PNPEnv_TUNER_FMR1236 */
382 	case 16: /* PNPEnv_TUNER_FR1216_MK2 */
383 	case 19: /* PNPEnv_TUNER_FR1246_MK2 */
384 	case 21: /* PNPEnv_TUNER_FM1216 */
385 	case 24: /* PNPEnv_TUNER_FM1246 */
386 	case 17: /* PNPEnv_TUNER_FR1216MF_MK2 */
387 	case 22: /* PNPEnv_TUNER_FM1216MF */
388 	case 20: /* PNPEnv_TUNER_FR1256_MK2 */
389 	case 25: /* PNPEnv_TUNER_FM1256 */
390 	case 33: /* PNPEnv_TUNER_4039FR5 */
391 	case 42: /* PNPEnv_TUNER_4009FR5 */
392 	case 52: /* PNPEnv_TUNER_4049FM5 */
393 	case 54: /* PNPEnv_TUNER_4049FM5_AltI2C */
394 	case 44: /* PNPEnv_TUNER_4009FN5 */
395 	case 31: /* PNPEnv_TUNER_TCPB9085P */
396 	case 30: /* PNPEnv_TUNER_TCPN9085D */
397 	case 46: /* PNPEnv_TUNER_TP18NSR01F */
398 	case 47: /* PNPEnv_TUNER_TP18PSB01D */
399 	case 49: /* PNPEnv_TUNER_TAPC_I001D */
400 	case 60: /* PNPEnv_TUNER_TAPE_S001D_MK3 */
401 	case 57: /* PNPEnv_TUNER_FM1216ME_MK3 */
402 	case 59: /* PNPEnv_TUNER_FM1216MP_MK3 */
403 	case 58: /* PNPEnv_TUNER_FM1236_MK3 */
404 	case 68: /* PNPEnv_TUNER_TAPE_H001F_MK3 */
405 	case 61: /* PNPEnv_TUNER_TAPE_M001D_MK3 */
406 	case 78: /* PNPEnv_TUNER_TDA8275C1_8290_FM */
407 	case 89: /* PNPEnv_TUNER_TCL_MFPE05_2 */
408 	case 92: /* PNPEnv_TUNER_PHILIPS_FQ1236A_MK4 */
409 	case 105:
410 		return 1;
411 	}
412 	return 0;
413 }
414 
415 void tveeprom_hauppauge_analog(struct tveeprom *tvee,
416 			       unsigned char *eeprom_data)
417 {
418 	/* ----------------------------------------------
419 	** The hauppauge eeprom format is tagged
420 	**
421 	** if packet[0] == 0x84, then packet[0..1] == length
422 	** else length = packet[0] & 3f;
423 	** if packet[0] & f8 == f8, then EOD and packet[1] == checksum
424 	**
425 	** In our (ivtv) case we're interested in the following:
426 	** tuner type:   tag [00].05 or [0a].01 (index into hauppauge_tuner)
427 	** tuner fmts:   tag [00].04 or [0a].00 (bitmask index into
428 	**		 hauppauge_tuner_fmt)
429 	** radio:        tag [00].{last} or [0e].00  (bitmask.  bit2=FM)
430 	** audio proc:   tag [02].01 or [05].00 (mask with 0x7f)
431 	** decoder proc: tag [09].01)
432 
433 	** Fun info:
434 	** model:      tag [00].07-08 or [06].00-01
435 	** revision:   tag [00].09-0b or [06].04-06
436 	** serial#:    tag [01].05-07 or [04].04-06
437 
438 	** # of inputs/outputs ???
439 	*/
440 
441 	int i, j, len, done, beenhere, tag, start;
442 
443 	int tuner1 = 0, t_format1 = 0, audioic = -1;
444 	const char *t_name1 = NULL;
445 	const char *t_fmt_name1[8] = { " none", "", "", "", "", "", "", "" };
446 
447 	int tuner2 = 0, t_format2 = 0;
448 	const char *t_name2 = NULL;
449 	const char *t_fmt_name2[8] = { " none", "", "", "", "", "", "", "" };
450 
451 	memset(tvee, 0, sizeof(*tvee));
452 	tvee->tuner_type = TUNER_ABSENT;
453 	tvee->tuner2_type = TUNER_ABSENT;
454 
455 	done = len = beenhere = 0;
456 
457 	/* Different eeprom start offsets for em28xx, cx2388x and cx23418 */
458 	if (eeprom_data[0] == 0x1a &&
459 	    eeprom_data[1] == 0xeb &&
460 	    eeprom_data[2] == 0x67 &&
461 	    eeprom_data[3] == 0x95)
462 		start = 0xa0; /* Generic em28xx offset */
463 	else if ((eeprom_data[0] & 0xe1) == 0x01 &&
464 		 eeprom_data[1] == 0x00 &&
465 		 eeprom_data[2] == 0x00 &&
466 		 eeprom_data[8] == 0x84)
467 		start = 8; /* Generic cx2388x offset */
468 	else if (eeprom_data[1] == 0x70 &&
469 		 eeprom_data[2] == 0x00 &&
470 		 eeprom_data[4] == 0x74 &&
471 		 eeprom_data[8] == 0x84)
472 		start = 8; /* Generic cx23418 offset (models 74xxx) */
473 	else
474 		start = 0;
475 
476 	for (i = start; !done && i < 256; i += len) {
477 		if (eeprom_data[i] == 0x84) {
478 			len = eeprom_data[i + 1] + (eeprom_data[i + 2] << 8);
479 			i += 3;
480 		} else if ((eeprom_data[i] & 0xf0) == 0x70) {
481 			if (eeprom_data[i] & 0x08) {
482 				/* verify checksum! */
483 				done = 1;
484 				break;
485 			}
486 			len = eeprom_data[i] & 0x07;
487 			++i;
488 		} else {
489 			pr_warn("Encountered bad packet header [%02x]. Corrupt or not a Hauppauge eeprom.\n",
490 				eeprom_data[i]);
491 			return;
492 		}
493 
494 		pr_debug("Tag [%02x] + %d bytes: %*ph\n",
495 			eeprom_data[i], len - 1, len, &eeprom_data[i]);
496 
497 		/* process by tag */
498 		tag = eeprom_data[i];
499 		switch (tag) {
500 		case 0x00:
501 			/* tag: 'Comprehensive' */
502 			tuner1 = eeprom_data[i+6];
503 			t_format1 = eeprom_data[i+5];
504 			tvee->has_radio = eeprom_data[i+len-1];
505 			/* old style tag, don't know how to detect
506 			IR presence, mark as unknown. */
507 			tvee->has_ir = 0;
508 			tvee->model =
509 				eeprom_data[i+8] +
510 				(eeprom_data[i+9] << 8);
511 			tvee->revision = eeprom_data[i+10] +
512 				(eeprom_data[i+11] << 8) +
513 				(eeprom_data[i+12] << 16);
514 			break;
515 
516 		case 0x01:
517 			/* tag: 'SerialID' */
518 			tvee->serial_number =
519 				eeprom_data[i+6] +
520 				(eeprom_data[i+7] << 8) +
521 				(eeprom_data[i+8] << 16);
522 			break;
523 
524 		case 0x02:
525 			/* tag 'AudioInfo'
526 			Note mask with 0x7F, high bit used on some older models
527 			to indicate 4052 mux was removed in favor of using MSP
528 			inputs directly. */
529 			audioic = eeprom_data[i+2] & 0x7f;
530 			if (audioic < ARRAY_SIZE(audio_ic))
531 				tvee->audio_processor = audio_ic[audioic].id;
532 			else
533 				tvee->audio_processor = TVEEPROM_AUDPROC_OTHER;
534 			break;
535 
536 		/* case 0x03: tag 'EEInfo' */
537 
538 		case 0x04:
539 			/* tag 'SerialID2' */
540 			tvee->serial_number =
541 				eeprom_data[i+5] +
542 				(eeprom_data[i+6] << 8) +
543 				(eeprom_data[i+7] << 16)+
544 				(eeprom_data[i+8] << 24);
545 
546 			if (eeprom_data[i + 8] == 0xf0) {
547 				tvee->MAC_address[0] = 0x00;
548 				tvee->MAC_address[1] = 0x0D;
549 				tvee->MAC_address[2] = 0xFE;
550 				tvee->MAC_address[3] = eeprom_data[i + 7];
551 				tvee->MAC_address[4] = eeprom_data[i + 6];
552 				tvee->MAC_address[5] = eeprom_data[i + 5];
553 				tvee->has_MAC_address = 1;
554 			}
555 			break;
556 
557 		case 0x05:
558 			/* tag 'Audio2'
559 			Note mask with 0x7F, high bit used on some older models
560 			to indicate 4052 mux was removed in favor of using MSP
561 			inputs directly. */
562 			audioic = eeprom_data[i+1] & 0x7f;
563 			if (audioic < ARRAY_SIZE(audio_ic))
564 				tvee->audio_processor = audio_ic[audioic].id;
565 			else
566 				tvee->audio_processor = TVEEPROM_AUDPROC_OTHER;
567 
568 			break;
569 
570 		case 0x06:
571 			/* tag 'ModelRev' */
572 			tvee->model =
573 				eeprom_data[i + 1] +
574 				(eeprom_data[i + 2] << 8) +
575 				(eeprom_data[i + 3] << 16) +
576 				(eeprom_data[i + 4] << 24);
577 			tvee->revision =
578 				eeprom_data[i + 5] +
579 				(eeprom_data[i + 6] << 8) +
580 				(eeprom_data[i + 7] << 16);
581 			break;
582 
583 		case 0x07:
584 			/* tag 'Details': according to Hauppauge not interesting
585 			on any PCI-era or later boards. */
586 			break;
587 
588 		/* there is no tag 0x08 defined */
589 
590 		case 0x09:
591 			/* tag 'Video' */
592 			tvee->decoder_processor = eeprom_data[i + 1];
593 			break;
594 
595 		case 0x0a:
596 			/* tag 'Tuner' */
597 			if (beenhere == 0) {
598 				tuner1 = eeprom_data[i + 2];
599 				t_format1 = eeprom_data[i + 1];
600 				beenhere = 1;
601 			} else {
602 				/* a second (radio) tuner may be present */
603 				tuner2 = eeprom_data[i + 2];
604 				t_format2 = eeprom_data[i + 1];
605 				/* not a TV tuner? */
606 				if (t_format2 == 0)
607 					tvee->has_radio = 1; /* must be radio */
608 			}
609 			break;
610 
611 		case 0x0b:
612 			/* tag 'Inputs': according to Hauppauge this is specific
613 			to each driver family, so no good assumptions can be
614 			made. */
615 			break;
616 
617 		/* case 0x0c: tag 'Balun' */
618 		/* case 0x0d: tag 'Teletext' */
619 
620 		case 0x0e:
621 			/* tag: 'Radio' */
622 			tvee->has_radio = eeprom_data[i+1];
623 			break;
624 
625 		case 0x0f:
626 			/* tag 'IRInfo' */
627 			tvee->has_ir = 1 | (eeprom_data[i+1] << 1);
628 			break;
629 
630 		/* case 0x10: tag 'VBIInfo' */
631 		/* case 0x11: tag 'QCInfo' */
632 		/* case 0x12: tag 'InfoBits' */
633 
634 		default:
635 			pr_debug("Not sure what to do with tag [%02x]\n",
636 					tag);
637 			/* dump the rest of the packet? */
638 		}
639 	}
640 
641 	if (!done) {
642 		pr_warn("Ran out of data!\n");
643 		return;
644 	}
645 
646 	if (tvee->revision != 0) {
647 		tvee->rev_str[0] = 32 + ((tvee->revision >> 18) & 0x3f);
648 		tvee->rev_str[1] = 32 + ((tvee->revision >> 12) & 0x3f);
649 		tvee->rev_str[2] = 32 + ((tvee->revision >>  6) & 0x3f);
650 		tvee->rev_str[3] = 32 + (tvee->revision & 0x3f);
651 		tvee->rev_str[4] = 0;
652 	}
653 
654 	if (hasRadioTuner(tuner1) && !tvee->has_radio) {
655 		pr_info("The eeprom says no radio is present, but the tuner type\n");
656 		pr_info("indicates otherwise. I will assume that radio is present.\n");
657 		tvee->has_radio = 1;
658 	}
659 
660 	if (tuner1 < ARRAY_SIZE(hauppauge_tuner)) {
661 		tvee->tuner_type = hauppauge_tuner[tuner1].id;
662 		t_name1 = hauppauge_tuner[tuner1].name;
663 	} else {
664 		t_name1 = "unknown";
665 	}
666 
667 	if (tuner2 < ARRAY_SIZE(hauppauge_tuner)) {
668 		tvee->tuner2_type = hauppauge_tuner[tuner2].id;
669 		t_name2 = hauppauge_tuner[tuner2].name;
670 	} else {
671 		t_name2 = "unknown";
672 	}
673 
674 	tvee->tuner_hauppauge_model = tuner1;
675 	tvee->tuner2_hauppauge_model = tuner2;
676 	tvee->tuner_formats = 0;
677 	tvee->tuner2_formats = 0;
678 	for (i = j = 0; i < 8; i++) {
679 		if (t_format1 & (1 << i)) {
680 			tvee->tuner_formats |= hauppauge_tuner_fmt[i].id;
681 			t_fmt_name1[j++] = hauppauge_tuner_fmt[i].name;
682 		}
683 	}
684 	for (i = j = 0; i < 8; i++) {
685 		if (t_format2 & (1 << i)) {
686 			tvee->tuner2_formats |= hauppauge_tuner_fmt[i].id;
687 			t_fmt_name2[j++] = hauppauge_tuner_fmt[i].name;
688 		}
689 	}
690 
691 	pr_info("Hauppauge model %d, rev %s, serial# %u\n",
692 		tvee->model, tvee->rev_str, tvee->serial_number);
693 	if (tvee->has_MAC_address == 1)
694 		pr_info("MAC address is %pM\n", tvee->MAC_address);
695 	pr_info("tuner model is %s (idx %d, type %d)\n",
696 		t_name1, tuner1, tvee->tuner_type);
697 	pr_info("TV standards%s%s%s%s%s%s%s%s (eeprom 0x%02x)\n",
698 		t_fmt_name1[0], t_fmt_name1[1], t_fmt_name1[2],
699 		t_fmt_name1[3],	t_fmt_name1[4], t_fmt_name1[5],
700 		t_fmt_name1[6], t_fmt_name1[7],	t_format1);
701 	if (tuner2)
702 		pr_info("second tuner model is %s (idx %d, type %d)\n",
703 					t_name2, tuner2, tvee->tuner2_type);
704 	if (t_format2)
705 		pr_info("TV standards%s%s%s%s%s%s%s%s (eeprom 0x%02x)\n",
706 			t_fmt_name2[0], t_fmt_name2[1], t_fmt_name2[2],
707 			t_fmt_name2[3],	t_fmt_name2[4], t_fmt_name2[5],
708 			t_fmt_name2[6], t_fmt_name2[7], t_format2);
709 	if (audioic < 0) {
710 		pr_info("audio processor is unknown (no idx)\n");
711 		tvee->audio_processor = TVEEPROM_AUDPROC_OTHER;
712 	} else {
713 		if (audioic < ARRAY_SIZE(audio_ic))
714 			pr_info("audio processor is %s (idx %d)\n",
715 					audio_ic[audioic].name, audioic);
716 		else
717 			pr_info("audio processor is unknown (idx %d)\n",
718 								audioic);
719 	}
720 	if (tvee->decoder_processor)
721 		pr_info("decoder processor is %s (idx %d)\n",
722 			STRM(decoderIC, tvee->decoder_processor),
723 			tvee->decoder_processor);
724 	if (tvee->has_ir)
725 		pr_info("has %sradio, has %sIR receiver, has %sIR transmitter\n",
726 				tvee->has_radio ? "" : "no ",
727 				(tvee->has_ir & 2) ? "" : "no ",
728 				(tvee->has_ir & 4) ? "" : "no ");
729 	else
730 		pr_info("has %sradio\n",
731 				tvee->has_radio ? "" : "no ");
732 }
733 EXPORT_SYMBOL(tveeprom_hauppauge_analog);
734 
735 /* ----------------------------------------------------------------------- */
736 /* generic helper functions                                                */
737 
738 int tveeprom_read(struct i2c_client *c, unsigned char *eedata, int len)
739 {
740 	unsigned char buf;
741 	int err;
742 
743 	buf = 0;
744 	err = i2c_master_send(c, &buf, 1);
745 	if (err != 1) {
746 		pr_info("Huh, no eeprom present (err=%d)?\n", err);
747 		return -1;
748 	}
749 	err = i2c_master_recv(c, eedata, len);
750 	if (err != len) {
751 		pr_warn("i2c eeprom read error (err=%d)\n", err);
752 		return -1;
753 	}
754 
755 	print_hex_dump_debug("full 256-byte eeprom dump:", DUMP_PREFIX_NONE,
756 			     16, 1, eedata, len, true);
757 	return 0;
758 }
759 EXPORT_SYMBOL(tveeprom_read);
760