em28xx-cards.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. /*
  2. em28xx-cards.c - driver for Empia EM2800/EM2820/2840 USB
  3. video capture devices
  4. Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
  5. Markus Rechberger <mrechberger@gmail.com>
  6. Mauro Carvalho Chehab <mchehab@infradead.org>
  7. Sascha Sommer <saschasommer@freenet.de>
  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. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #include <linux/init.h>
  21. #include <linux/module.h>
  22. #include <linux/delay.h>
  23. #include <linux/i2c.h>
  24. #include <linux/usb.h>
  25. #include <media/tuner.h>
  26. #include <media/msp3400.h>
  27. #include <media/saa7115.h>
  28. #include <media/tvp5150.h>
  29. #include <media/tveeprom.h>
  30. #include <media/audiochip.h>
  31. #include <media/v4l2-common.h>
  32. #include "em28xx.h"
  33. static int tuner = -1;
  34. module_param(tuner, int, 0444);
  35. MODULE_PARM_DESC(tuner, "tuner type");
  36. static unsigned int disable_ir;
  37. module_param(disable_ir, int, 0444);
  38. MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
  39. struct em28xx_hash_table {
  40. unsigned long hash;
  41. unsigned int model;
  42. unsigned int tuner;
  43. };
  44. struct em28xx_board em28xx_boards[] = {
  45. [EM2800_BOARD_UNKNOWN] = {
  46. .name = "Unknown EM2800 video grabber",
  47. .is_em2800 = 1,
  48. .vchannels = 2,
  49. .tda9887_conf = TDA9887_PRESENT,
  50. .decoder = EM28XX_SAA7113,
  51. .input = { {
  52. .type = EM28XX_VMUX_COMPOSITE1,
  53. .vmux = SAA7115_COMPOSITE0,
  54. .amux = 1,
  55. }, {
  56. .type = EM28XX_VMUX_SVIDEO,
  57. .vmux = SAA7115_SVIDEO3,
  58. .amux = 1,
  59. } },
  60. },
  61. [EM2820_BOARD_UNKNOWN] = {
  62. .name = "Unknown EM2750/28xx video grabber",
  63. .is_em2800 = 0,
  64. .tuner_type = TUNER_ABSENT,
  65. },
  66. [EM2820_BOARD_KWORLD_PVRTV2800RF] = {
  67. .name = "Kworld PVR TV 2800 RF",
  68. .is_em2800 = 0,
  69. .vchannels = 2,
  70. .tuner_type = TUNER_TEMIC_PAL,
  71. .tda9887_conf = TDA9887_PRESENT,
  72. .decoder = EM28XX_SAA7113,
  73. .input = { {
  74. .type = EM28XX_VMUX_COMPOSITE1,
  75. .vmux = SAA7115_COMPOSITE0,
  76. .amux = 1,
  77. }, {
  78. .type = EM28XX_VMUX_SVIDEO,
  79. .vmux = SAA7115_SVIDEO3,
  80. .amux = 1,
  81. } },
  82. },
  83. [EM2820_BOARD_TERRATEC_CINERGY_250] = {
  84. .name = "Terratec Cinergy 250 USB",
  85. .vchannels = 3,
  86. .tuner_type = TUNER_LG_PAL_NEW_TAPC,
  87. .tda9887_conf = TDA9887_PRESENT,
  88. .decoder = EM28XX_SAA7113,
  89. .input = { {
  90. .type = EM28XX_VMUX_TELEVISION,
  91. .vmux = SAA7115_COMPOSITE2,
  92. .amux = 1,
  93. }, {
  94. .type = EM28XX_VMUX_COMPOSITE1,
  95. .vmux = SAA7115_COMPOSITE0,
  96. .amux = 1,
  97. }, {
  98. .type = EM28XX_VMUX_SVIDEO,
  99. .vmux = SAA7115_SVIDEO3,
  100. .amux = 1,
  101. } },
  102. },
  103. [EM2820_BOARD_PINNACLE_USB_2] = {
  104. .name = "Pinnacle PCTV USB 2",
  105. .vchannels = 3,
  106. .tuner_type = TUNER_LG_PAL_NEW_TAPC,
  107. .tda9887_conf = TDA9887_PRESENT,
  108. .decoder = EM28XX_SAA7113,
  109. .input = { {
  110. .type = EM28XX_VMUX_TELEVISION,
  111. .vmux = SAA7115_COMPOSITE2,
  112. .amux = 0,
  113. }, {
  114. .type = EM28XX_VMUX_COMPOSITE1,
  115. .vmux = SAA7115_COMPOSITE0,
  116. .amux = 1,
  117. }, {
  118. .type = EM28XX_VMUX_SVIDEO,
  119. .vmux = SAA7115_SVIDEO3,
  120. .amux = 1,
  121. } },
  122. },
  123. [EM2820_BOARD_HAUPPAUGE_WINTV_USB_2] = {
  124. .name = "Hauppauge WinTV USB 2",
  125. .vchannels = 3,
  126. .tuner_type = TUNER_PHILIPS_FM1236_MK3,
  127. .tda9887_conf = TDA9887_PRESENT |
  128. TDA9887_PORT1_ACTIVE|
  129. TDA9887_PORT2_ACTIVE,
  130. .decoder = EM28XX_TVP5150,
  131. .has_msp34xx = 1,
  132. /*FIXME: S-Video not tested */
  133. .input = { {
  134. .type = EM28XX_VMUX_TELEVISION,
  135. .vmux = TVP5150_COMPOSITE0,
  136. .amux = MSP_INPUT_DEFAULT,
  137. }, {
  138. .type = EM28XX_VMUX_SVIDEO,
  139. .vmux = TVP5150_SVIDEO,
  140. .amux = MSP_INPUT(MSP_IN_SCART1, MSP_IN_TUNER1,
  141. MSP_DSP_IN_SCART, MSP_DSP_IN_SCART),
  142. } },
  143. },
  144. [EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900] = {
  145. .name = "Hauppauge WinTV HVR 900",
  146. .vchannels = 3,
  147. .tda9887_conf = TDA9887_PRESENT,
  148. .tuner_type = TUNER_XC2028,
  149. .mts_firmware = 1,
  150. .decoder = EM28XX_TVP5150,
  151. .input = { {
  152. .type = EM28XX_VMUX_TELEVISION,
  153. .vmux = TVP5150_COMPOSITE0,
  154. .amux = 0,
  155. }, {
  156. .type = EM28XX_VMUX_COMPOSITE1,
  157. .vmux = TVP5150_COMPOSITE1,
  158. .amux = 1,
  159. }, {
  160. .type = EM28XX_VMUX_SVIDEO,
  161. .vmux = TVP5150_SVIDEO,
  162. .amux = 1,
  163. } },
  164. },
  165. [EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950] = {
  166. .name = "Hauppauge WinTV HVR 950",
  167. .vchannels = 3,
  168. .tda9887_conf = TDA9887_PRESENT,
  169. .tuner_type = TUNER_XC2028,
  170. .mts_firmware = 1,
  171. .has_12mhz_i2s = 1,
  172. .has_dvb = 1,
  173. .decoder = EM28XX_TVP5150,
  174. .input = { {
  175. .type = EM28XX_VMUX_TELEVISION,
  176. .vmux = TVP5150_COMPOSITE0,
  177. .amux = 0,
  178. }, {
  179. .type = EM28XX_VMUX_COMPOSITE1,
  180. .vmux = TVP5150_COMPOSITE1,
  181. .amux = 1,
  182. }, {
  183. .type = EM28XX_VMUX_SVIDEO,
  184. .vmux = TVP5150_SVIDEO,
  185. .amux = 1,
  186. } },
  187. },
  188. [EM2880_BOARD_TERRATEC_HYBRID_XS] = {
  189. .name = "Terratec Hybrid XS",
  190. .vchannels = 3,
  191. .tda9887_conf = TDA9887_PRESENT,
  192. .tuner_type = TUNER_XC2028,
  193. .decoder = EM28XX_TVP5150,
  194. .input = { {
  195. .type = EM28XX_VMUX_TELEVISION,
  196. .vmux = TVP5150_COMPOSITE0,
  197. .amux = 0,
  198. }, {
  199. .type = EM28XX_VMUX_COMPOSITE1,
  200. .vmux = TVP5150_COMPOSITE1,
  201. .amux = 1,
  202. }, {
  203. .type = EM28XX_VMUX_SVIDEO,
  204. .vmux = TVP5150_SVIDEO,
  205. .amux = 1,
  206. } },
  207. },
  208. /* maybe there's a reason behind it why Terratec sells the Hybrid XS
  209. as Prodigy XS with a different PID, let's keep it separated for now
  210. maybe we'll need it lateron */
  211. [EM2880_BOARD_TERRATEC_PRODIGY_XS] = {
  212. .name = "Terratec Prodigy XS",
  213. .vchannels = 3,
  214. .tda9887_conf = TDA9887_PRESENT,
  215. .tuner_type = TUNER_XC2028,
  216. .decoder = EM28XX_TVP5150,
  217. .input = { {
  218. .type = EM28XX_VMUX_TELEVISION,
  219. .vmux = TVP5150_COMPOSITE0,
  220. .amux = 0,
  221. }, {
  222. .type = EM28XX_VMUX_COMPOSITE1,
  223. .vmux = TVP5150_COMPOSITE1,
  224. .amux = 1,
  225. }, {
  226. .type = EM28XX_VMUX_SVIDEO,
  227. .vmux = TVP5150_SVIDEO,
  228. .amux = 1,
  229. } },
  230. },
  231. [EM2820_BOARD_MSI_VOX_USB_2] = {
  232. .name = "MSI VOX USB 2.0",
  233. .vchannels = 3,
  234. .tuner_type = TUNER_LG_PAL_NEW_TAPC,
  235. .tda9887_conf = TDA9887_PRESENT |
  236. TDA9887_PORT1_ACTIVE |
  237. TDA9887_PORT2_ACTIVE,
  238. .max_range_640_480 = 1,
  239. .decoder = EM28XX_SAA7114,
  240. .input = { {
  241. .type = EM28XX_VMUX_TELEVISION,
  242. .vmux = SAA7115_COMPOSITE4,
  243. .amux = 0,
  244. }, {
  245. .type = EM28XX_VMUX_COMPOSITE1,
  246. .vmux = SAA7115_COMPOSITE0,
  247. .amux = 1,
  248. }, {
  249. .type = EM28XX_VMUX_SVIDEO,
  250. .vmux = SAA7115_SVIDEO3,
  251. .amux = 1,
  252. } },
  253. },
  254. [EM2800_BOARD_TERRATEC_CINERGY_200] = {
  255. .name = "Terratec Cinergy 200 USB",
  256. .is_em2800 = 1,
  257. .vchannels = 3,
  258. .tuner_type = TUNER_LG_PAL_NEW_TAPC,
  259. .tda9887_conf = TDA9887_PRESENT,
  260. .decoder = EM28XX_SAA7113,
  261. .input = { {
  262. .type = EM28XX_VMUX_TELEVISION,
  263. .vmux = SAA7115_COMPOSITE2,
  264. .amux = 0,
  265. }, {
  266. .type = EM28XX_VMUX_COMPOSITE1,
  267. .vmux = SAA7115_COMPOSITE0,
  268. .amux = 1,
  269. }, {
  270. .type = EM28XX_VMUX_SVIDEO,
  271. .vmux = SAA7115_SVIDEO3,
  272. .amux = 1,
  273. } },
  274. },
  275. [EM2800_BOARD_LEADTEK_WINFAST_USBII] = {
  276. .name = "Leadtek Winfast USB II",
  277. .is_em2800 = 1,
  278. .vchannels = 3,
  279. .tuner_type = TUNER_LG_PAL_NEW_TAPC,
  280. .tda9887_conf = TDA9887_PRESENT,
  281. .decoder = EM28XX_SAA7113,
  282. .input = { {
  283. .type = EM28XX_VMUX_TELEVISION,
  284. .vmux = SAA7115_COMPOSITE2,
  285. .amux = 0,
  286. }, {
  287. .type = EM28XX_VMUX_COMPOSITE1,
  288. .vmux = SAA7115_COMPOSITE0,
  289. .amux = 1,
  290. }, {
  291. .type = EM28XX_VMUX_SVIDEO,
  292. .vmux = SAA7115_SVIDEO3,
  293. .amux = 1,
  294. } },
  295. },
  296. [EM2800_BOARD_KWORLD_USB2800] = {
  297. .name = "Kworld USB2800",
  298. .is_em2800 = 1,
  299. .vchannels = 3,
  300. .tuner_type = TUNER_PHILIPS_FCV1236D,
  301. .tda9887_conf = TDA9887_PRESENT,
  302. .decoder = EM28XX_SAA7113,
  303. .input = { {
  304. .type = EM28XX_VMUX_TELEVISION,
  305. .vmux = SAA7115_COMPOSITE2,
  306. .amux = 0,
  307. }, {
  308. .type = EM28XX_VMUX_COMPOSITE1,
  309. .vmux = SAA7115_COMPOSITE0,
  310. .amux = 1,
  311. }, {
  312. .type = EM28XX_VMUX_SVIDEO,
  313. .vmux = SAA7115_SVIDEO3,
  314. .amux = 1,
  315. } },
  316. },
  317. [EM2820_BOARD_PINNACLE_DVC_90] = {
  318. .name = "Pinnacle Dazzle DVC 90/DVC 100",
  319. .vchannels = 3,
  320. .tuner_type = TUNER_ABSENT,
  321. .decoder = EM28XX_SAA7113,
  322. .input = { {
  323. .type = EM28XX_VMUX_COMPOSITE1,
  324. .vmux = SAA7115_COMPOSITE0,
  325. .amux = 1,
  326. }, {
  327. .type = EM28XX_VMUX_SVIDEO,
  328. .vmux = SAA7115_SVIDEO3,
  329. .amux = 1,
  330. } },
  331. },
  332. [EM2800_BOARD_VGEAR_POCKETTV] = {
  333. .name = "V-Gear PocketTV",
  334. .is_em2800 = 1,
  335. .vchannels = 3,
  336. .tuner_type = TUNER_LG_PAL_NEW_TAPC,
  337. .tda9887_conf = TDA9887_PRESENT,
  338. .decoder = EM28XX_SAA7113,
  339. .input = { {
  340. .type = EM28XX_VMUX_TELEVISION,
  341. .vmux = SAA7115_COMPOSITE2,
  342. .amux = 0,
  343. }, {
  344. .type = EM28XX_VMUX_COMPOSITE1,
  345. .vmux = SAA7115_COMPOSITE0,
  346. .amux = 1,
  347. }, {
  348. .type = EM28XX_VMUX_SVIDEO,
  349. .vmux = SAA7115_SVIDEO3,
  350. .amux = 1,
  351. } },
  352. },
  353. [EM2820_BOARD_PROLINK_PLAYTV_USB2] = {
  354. .name = "Pixelview Prolink PlayTV USB 2.0",
  355. .vchannels = 3,
  356. .tda9887_conf = TDA9887_PRESENT,
  357. .tuner_type = TUNER_YMEC_TVF_5533MF,
  358. .decoder = EM28XX_SAA7113,
  359. .input = { {
  360. .type = EM28XX_VMUX_TELEVISION,
  361. .vmux = SAA7115_COMPOSITE2,
  362. .amux = EM28XX_AMUX_LINE_IN,
  363. }, {
  364. .type = EM28XX_VMUX_COMPOSITE1,
  365. .vmux = SAA7115_COMPOSITE0,
  366. .amux = EM28XX_AMUX_LINE_IN,
  367. }, {
  368. .type = EM28XX_VMUX_SVIDEO,
  369. .vmux = SAA7115_SVIDEO3,
  370. .amux = EM28XX_AMUX_LINE_IN,
  371. } },
  372. },
  373. };
  374. const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards);
  375. /* table of devices that work with this driver */
  376. struct usb_device_id em28xx_id_table [] = {
  377. { USB_DEVICE(0xeb1a, 0x2750),
  378. .driver_info = EM2820_BOARD_UNKNOWN },
  379. { USB_DEVICE(0xeb1a, 0x2800),
  380. .driver_info = EM2800_BOARD_UNKNOWN },
  381. { USB_DEVICE(0xeb1a, 0x2820),
  382. .driver_info = EM2820_BOARD_UNKNOWN },
  383. { USB_DEVICE(0xeb1a, 0x2821),
  384. .driver_info = EM2820_BOARD_UNKNOWN },
  385. { USB_DEVICE(0xeb1a, 0x2860),
  386. .driver_info = EM2820_BOARD_UNKNOWN },
  387. { USB_DEVICE(0xeb1a, 0x2861),
  388. .driver_info = EM2820_BOARD_UNKNOWN },
  389. { USB_DEVICE(0xeb1a, 0x2870),
  390. .driver_info = EM2820_BOARD_UNKNOWN },
  391. { USB_DEVICE(0xeb1a, 0x2881),
  392. .driver_info = EM2820_BOARD_UNKNOWN },
  393. { USB_DEVICE(0xeb1a, 0x2883),
  394. .driver_info = EM2820_BOARD_UNKNOWN },
  395. { USB_DEVICE(0x0ccd, 0x0036),
  396. .driver_info = EM2820_BOARD_TERRATEC_CINERGY_250 },
  397. { USB_DEVICE(0x2304, 0x0208),
  398. .driver_info = EM2820_BOARD_PINNACLE_USB_2 },
  399. { USB_DEVICE(0x2040, 0x4200),
  400. .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 },
  401. { USB_DEVICE(0x2040, 0x4201),
  402. .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 },
  403. { USB_DEVICE(0x2304, 0x0207),
  404. .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
  405. { USB_DEVICE(0x2304, 0x021a),
  406. .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
  407. { USB_DEVICE(0x2040, 0x6500),
  408. .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 },
  409. { USB_DEVICE(0x2040, 0x6502),
  410. .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 },
  411. { USB_DEVICE(0x2040, 0x6513),
  412. .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 },
  413. { USB_DEVICE(0x0ccd, 0x0042),
  414. .driver_info = EM2880_BOARD_TERRATEC_HYBRID_XS },
  415. { USB_DEVICE(0x0ccd, 0x0047),
  416. .driver_info = EM2880_BOARD_TERRATEC_PRODIGY_XS },
  417. { },
  418. };
  419. MODULE_DEVICE_TABLE(usb, em28xx_id_table);
  420. /*
  421. * Reset sequences for analog/digital modes
  422. */
  423. /* Board Hauppauge WinTV HVR 900 analog */
  424. struct em28xx_reg_seq hauppauge_wintv_hvr_900_analog[] = {
  425. { -1, -1, 6},
  426. {EM_R08_GPIO, 0x2d, 10},
  427. {EM_R08_GPIO, 0x3d, 5},
  428. { -1, -1, -1},
  429. };
  430. /* Board Hauppauge WinTV HVR 900 digital */
  431. struct em28xx_reg_seq hauppauge_wintv_hvr_900_digital[] = {
  432. { -1, -1, 6},
  433. {EM_R08_GPIO, 0x2e, 6},
  434. {EM_R08_GPIO, 0x3e, 6},
  435. {EM_R04_GPO, 0x04, 10},
  436. {EM_R04_GPO, 0x0c, 10},
  437. { -1, -1, -1},
  438. };
  439. /*
  440. * EEPROM hash table for devices with generic USB IDs
  441. */
  442. static struct em28xx_hash_table em28xx_eeprom_hash [] = {
  443. /* P/N: SA 60002070465 Tuner: TVF7533-MF */
  444. {0x6ce05a8f, EM2820_BOARD_PROLINK_PLAYTV_USB2, TUNER_YMEC_TVF_5533MF},
  445. };
  446. /* I2C devicelist hash table for devices with generic USB IDs */
  447. static struct em28xx_hash_table em28xx_i2c_hash[] = {
  448. {0xb06a32c3, EM2800_BOARD_TERRATEC_CINERGY_200, TUNER_LG_PAL_NEW_TAPC},
  449. {0xf51200e3, EM2800_BOARD_VGEAR_POCKETTV, TUNER_LG_PAL_NEW_TAPC},
  450. };
  451. int em28xx_tuner_callback(void *ptr, int command, int arg)
  452. {
  453. int rc = 0;
  454. struct em28xx *dev = ptr;
  455. struct em28xx_reg_seq *gpio;
  456. if (dev->tuner_type != TUNER_XC2028)
  457. return 0;
  458. if (command != XC2028_TUNER_RESET)
  459. return 0;
  460. if (dev->mode == EM28XX_ANALOG_MODE)
  461. gpio = dev->analog_gpio;
  462. else
  463. gpio = dev->digital_gpio;
  464. /* djh - Not sure if these are still required */
  465. dev->em28xx_write_regs_req(dev, 0x00, 0x48, "\x00", 1);
  466. if (dev->mode == EM28XX_ANALOG_MODE)
  467. dev->em28xx_write_regs_req(dev, 0x00, 0x12, "\x67", 1);
  468. else
  469. dev->em28xx_write_regs_req(dev, 0x00, 0x12, "\x37", 1);
  470. msleep(6);
  471. if (!gpio)
  472. return rc;
  473. /* Send GPIO reset sequences specified at board entry */
  474. while (gpio->sleep >= 0) {
  475. if (gpio->reg >= 0)
  476. rc = dev->em28xx_write_regs(dev,
  477. gpio->reg,
  478. &gpio->val, 1);
  479. if (gpio->sleep > 0)
  480. msleep(gpio->sleep);
  481. gpio++;
  482. }
  483. return rc;
  484. }
  485. EXPORT_SYMBOL_GPL(em28xx_tuner_callback);
  486. static void em28xx_set_model(struct em28xx *dev)
  487. {
  488. dev->is_em2800 = em28xx_boards[dev->model].is_em2800;
  489. dev->has_msp34xx = em28xx_boards[dev->model].has_msp34xx;
  490. dev->tda9887_conf = em28xx_boards[dev->model].tda9887_conf;
  491. dev->decoder = em28xx_boards[dev->model].decoder;
  492. dev->video_inputs = em28xx_boards[dev->model].vchannels;
  493. dev->has_12mhz_i2s = em28xx_boards[dev->model].has_12mhz_i2s;
  494. dev->max_range_640_480 = em28xx_boards[dev->model].max_range_640_480;
  495. dev->has_dvb = em28xx_boards[dev->model].has_dvb;
  496. }
  497. /* Since em28xx_pre_card_setup() requires a proper dev->model,
  498. * this won't work for boards with generic PCI IDs
  499. */
  500. void em28xx_pre_card_setup(struct em28xx *dev)
  501. {
  502. int rc;
  503. dev->wait_after_write = 5;
  504. rc = em28xx_read_reg(dev, CHIPID_REG);
  505. if (rc > 0) {
  506. switch (rc) {
  507. case CHIP_ID_EM2883:
  508. em28xx_info("chip ID is em2882/em2883\n");
  509. dev->wait_after_write = 0;
  510. break;
  511. default:
  512. em28xx_info("em28xx chip ID = %d\n", rc);
  513. }
  514. }
  515. em28xx_set_model(dev);
  516. /* request some modules */
  517. switch (dev->model) {
  518. case EM2880_BOARD_TERRATEC_PRODIGY_XS:
  519. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
  520. case EM2880_BOARD_TERRATEC_HYBRID_XS:
  521. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
  522. em28xx_write_regs(dev, XCLK_REG, "\x27", 1);
  523. em28xx_write_regs(dev, I2C_CLK_REG, "\x40", 1);
  524. em28xx_write_regs(dev, 0x08, "\xff", 1);
  525. em28xx_write_regs(dev, 0x04, "\x00", 1);
  526. msleep(100);
  527. em28xx_write_regs(dev, 0x04, "\x08", 1);
  528. msleep(100);
  529. em28xx_write_regs(dev, 0x08, "\xff", 1);
  530. msleep(50);
  531. em28xx_write_regs(dev, 0x08, "\x2d", 1);
  532. msleep(50);
  533. em28xx_write_regs(dev, 0x08, "\x3d", 1);
  534. dev->analog_gpio = hauppauge_wintv_hvr_900_analog;
  535. dev->digital_gpio = hauppauge_wintv_hvr_900_digital;
  536. break;
  537. }
  538. }
  539. void em28xx_setup_xc3028(struct em28xx *dev, struct xc2028_ctrl *ctl)
  540. {
  541. memset(ctl, 0, sizeof(*ctl));
  542. ctl->fname = XC2028_DEFAULT_FIRMWARE;
  543. ctl->max_len = 64;
  544. ctl->mts = em28xx_boards[dev->model].mts_firmware;
  545. switch (dev->model) {
  546. /* Add card-specific parameters for xc3028 here */
  547. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
  548. ctl->demod = XC3028_FE_DEFAULT;
  549. break;
  550. default:
  551. ctl->demod = XC3028_FE_OREN538;
  552. }
  553. }
  554. EXPORT_SYMBOL_GPL(em28xx_setup_xc3028);
  555. static void em28xx_config_tuner(struct em28xx *dev)
  556. {
  557. struct v4l2_priv_tun_config xc2028_cfg;
  558. struct tuner_setup tun_setup;
  559. struct v4l2_frequency f;
  560. if (dev->tuner_type == TUNER_ABSENT)
  561. return;
  562. tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
  563. tun_setup.type = dev->tuner_type;
  564. tun_setup.addr = dev->tuner_addr;
  565. tun_setup.tuner_callback = em28xx_tuner_callback;
  566. em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup);
  567. if (dev->tuner_type == TUNER_XC2028) {
  568. struct xc2028_ctrl ctl;
  569. em28xx_setup_xc3028(dev, &ctl);
  570. xc2028_cfg.tuner = TUNER_XC2028;
  571. xc2028_cfg.priv = &ctl;
  572. em28xx_i2c_call_clients(dev, TUNER_SET_CONFIG, &xc2028_cfg);
  573. }
  574. /* configure tuner */
  575. f.tuner = 0;
  576. f.type = V4L2_TUNER_ANALOG_TV;
  577. f.frequency = 9076; /* just a magic number */
  578. dev->ctl_freq = f.frequency;
  579. em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, &f);
  580. }
  581. static int em28xx_hint_board(struct em28xx *dev)
  582. {
  583. int i;
  584. /* HINT method: EEPROM
  585. *
  586. * This method works only for boards with eeprom.
  587. * Uses a hash of all eeprom bytes. The hash should be
  588. * unique for a vendor/tuner pair.
  589. * There are a high chance that tuners for different
  590. * video standards produce different hashes.
  591. */
  592. for (i = 0; i < ARRAY_SIZE(em28xx_eeprom_hash); i++) {
  593. if (dev->hash == em28xx_eeprom_hash[i].hash) {
  594. dev->model = em28xx_eeprom_hash[i].model;
  595. dev->tuner_type = em28xx_eeprom_hash[i].tuner;
  596. em28xx_errdev("Your board has no unique USB ID.\n");
  597. em28xx_errdev("A hint were successfully done, "
  598. "based on eeprom hash.\n");
  599. em28xx_errdev("This method is not 100%% failproof.\n");
  600. em28xx_errdev("If the board were missdetected, "
  601. "please email this log to:\n");
  602. em28xx_errdev("\tV4L Mailing List "
  603. " <video4linux-list@redhat.com>\n");
  604. em28xx_errdev("Board detected as %s\n",
  605. em28xx_boards[dev->model].name);
  606. return 0;
  607. }
  608. }
  609. /* HINT method: I2C attached devices
  610. *
  611. * This method works for all boards.
  612. * Uses a hash of i2c scanned devices.
  613. * Devices with the same i2c attached chips will
  614. * be considered equal.
  615. * This method is less precise than the eeprom one.
  616. */
  617. /* user did not request i2c scanning => do it now */
  618. if (!dev->i2c_hash)
  619. em28xx_do_i2c_scan(dev);
  620. for (i = 0; i < ARRAY_SIZE(em28xx_i2c_hash); i++) {
  621. if (dev->i2c_hash == em28xx_i2c_hash[i].hash) {
  622. dev->model = em28xx_i2c_hash[i].model;
  623. dev->tuner_type = em28xx_i2c_hash[i].tuner;
  624. em28xx_errdev("Your board has no unique USB ID.\n");
  625. em28xx_errdev("A hint were successfully done, "
  626. "based on i2c devicelist hash.\n");
  627. em28xx_errdev("This method is not 100%% failproof.\n");
  628. em28xx_errdev("If the board were missdetected, "
  629. "please email this log to:\n");
  630. em28xx_errdev("\tV4L Mailing List "
  631. " <video4linux-list@redhat.com>\n");
  632. em28xx_errdev("Board detected as %s\n",
  633. em28xx_boards[dev->model].name);
  634. return 0;
  635. }
  636. }
  637. em28xx_errdev("Your board has no unique USB ID and thus need a "
  638. "hint to be detected.\n");
  639. em28xx_errdev("You may try to use card=<n> insmod option to "
  640. "workaround that.\n");
  641. em28xx_errdev("Please send an email with this log to:\n");
  642. em28xx_errdev("\tV4L Mailing List <video4linux-list@redhat.com>\n");
  643. em28xx_errdev("Board eeprom hash is 0x%08lx\n", dev->hash);
  644. em28xx_errdev("Board i2c devicelist hash is 0x%08lx\n", dev->i2c_hash);
  645. em28xx_errdev("Here is a list of valid choices for the card=<n>"
  646. " insmod option:\n");
  647. for (i = 0; i < em28xx_bcount; i++) {
  648. em28xx_errdev(" card=%d -> %s\n",
  649. i, em28xx_boards[i].name);
  650. }
  651. return -1;
  652. }
  653. /* ----------------------------------------------------------------------- */
  654. void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir)
  655. {
  656. if (disable_ir) {
  657. ir->get_key = NULL;
  658. return ;
  659. }
  660. /* detect & configure */
  661. switch (dev->model) {
  662. case (EM2800_BOARD_UNKNOWN):
  663. break;
  664. case (EM2820_BOARD_UNKNOWN):
  665. break;
  666. case (EM2800_BOARD_TERRATEC_CINERGY_200):
  667. case (EM2820_BOARD_TERRATEC_CINERGY_250):
  668. ir->ir_codes = ir_codes_em_terratec;
  669. ir->get_key = em28xx_get_key_terratec;
  670. snprintf(ir->c.name, sizeof(ir->c.name),
  671. "i2c IR (EM28XX Terratec)");
  672. break;
  673. case (EM2820_BOARD_PINNACLE_USB_2):
  674. ir->ir_codes = ir_codes_pinnacle_grey;
  675. ir->get_key = em28xx_get_key_pinnacle_usb_grey;
  676. snprintf(ir->c.name, sizeof(ir->c.name),
  677. "i2c IR (EM28XX Pinnacle PCTV)");
  678. break;
  679. case (EM2820_BOARD_HAUPPAUGE_WINTV_USB_2):
  680. ir->ir_codes = ir_codes_hauppauge_new;
  681. ir->get_key = em28xx_get_key_em_haup;
  682. snprintf(ir->c.name, sizeof(ir->c.name),
  683. "i2c IR (EM2840 Hauppauge)");
  684. break;
  685. case (EM2820_BOARD_MSI_VOX_USB_2):
  686. break;
  687. case (EM2800_BOARD_LEADTEK_WINFAST_USBII):
  688. break;
  689. case (EM2800_BOARD_KWORLD_USB2800):
  690. break;
  691. }
  692. }
  693. void em28xx_card_setup(struct em28xx *dev)
  694. {
  695. em28xx_set_model(dev);
  696. dev->tuner_type = em28xx_boards[dev->model].tuner_type;
  697. /* request some modules */
  698. switch (dev->model) {
  699. case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
  700. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
  701. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
  702. {
  703. struct tveeprom tv;
  704. #ifdef CONFIG_MODULES
  705. request_module("tveeprom");
  706. #endif
  707. /* Call first TVeeprom */
  708. dev->i2c_client.addr = 0xa0 >> 1;
  709. tveeprom_hauppauge_analog(&dev->i2c_client, &tv, dev->eedata);
  710. dev->tuner_type = tv.tuner_type;
  711. if (tv.audio_processor == AUDIO_CHIP_MSP34XX) {
  712. dev->i2s_speed = 2048000;
  713. dev->has_msp34xx = 1;
  714. }
  715. #ifdef CONFIG_MODULES
  716. if (tv.has_ir)
  717. request_module("ir-kbd-i2c");
  718. #endif
  719. break;
  720. }
  721. case EM2820_BOARD_KWORLD_PVRTV2800RF:
  722. /* GPIO enables sound on KWORLD PVR TV 2800RF */
  723. em28xx_write_regs_req(dev, 0x00, 0x08, "\xf9", 1);
  724. break;
  725. case EM2820_BOARD_UNKNOWN:
  726. case EM2800_BOARD_UNKNOWN:
  727. if (!em28xx_hint_board(dev))
  728. em28xx_set_model(dev);
  729. }
  730. /* Allow override tuner type by a module parameter */
  731. if (tuner >= 0)
  732. dev->tuner_type = tuner;
  733. #ifdef CONFIG_MODULES
  734. /* request some modules */
  735. if (dev->has_msp34xx)
  736. request_module("msp3400");
  737. if (dev->decoder == EM28XX_SAA7113 || dev->decoder == EM28XX_SAA7114)
  738. request_module("saa7115");
  739. if (dev->decoder == EM28XX_TVP5150)
  740. request_module("tvp5150");
  741. if (dev->tuner_type != TUNER_ABSENT)
  742. request_module("tuner");
  743. #endif
  744. em28xx_config_tuner(dev);
  745. }