em28xx-cards.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  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. .has_dvb = 1,
  151. .decoder = EM28XX_TVP5150,
  152. .input = { {
  153. .type = EM28XX_VMUX_TELEVISION,
  154. .vmux = TVP5150_COMPOSITE0,
  155. .amux = 0,
  156. }, {
  157. .type = EM28XX_VMUX_COMPOSITE1,
  158. .vmux = TVP5150_COMPOSITE1,
  159. .amux = 1,
  160. }, {
  161. .type = EM28XX_VMUX_SVIDEO,
  162. .vmux = TVP5150_SVIDEO,
  163. .amux = 1,
  164. } },
  165. },
  166. [EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950] = {
  167. .name = "Hauppauge WinTV HVR 950",
  168. .vchannels = 3,
  169. .tda9887_conf = TDA9887_PRESENT,
  170. .tuner_type = TUNER_XC2028,
  171. .mts_firmware = 1,
  172. .has_12mhz_i2s = 1,
  173. .has_dvb = 1,
  174. .decoder = EM28XX_TVP5150,
  175. .input = { {
  176. .type = EM28XX_VMUX_TELEVISION,
  177. .vmux = TVP5150_COMPOSITE0,
  178. .amux = 0,
  179. }, {
  180. .type = EM28XX_VMUX_COMPOSITE1,
  181. .vmux = TVP5150_COMPOSITE1,
  182. .amux = 1,
  183. }, {
  184. .type = EM28XX_VMUX_SVIDEO,
  185. .vmux = TVP5150_SVIDEO,
  186. .amux = 1,
  187. } },
  188. },
  189. [EM2880_BOARD_TERRATEC_HYBRID_XS] = {
  190. .name = "Terratec Hybrid XS",
  191. .vchannels = 3,
  192. .tda9887_conf = TDA9887_PRESENT,
  193. .tuner_type = TUNER_XC2028,
  194. .decoder = EM28XX_TVP5150,
  195. .input = { {
  196. .type = EM28XX_VMUX_TELEVISION,
  197. .vmux = TVP5150_COMPOSITE0,
  198. .amux = 0,
  199. }, {
  200. .type = EM28XX_VMUX_COMPOSITE1,
  201. .vmux = TVP5150_COMPOSITE1,
  202. .amux = 1,
  203. }, {
  204. .type = EM28XX_VMUX_SVIDEO,
  205. .vmux = TVP5150_SVIDEO,
  206. .amux = 1,
  207. } },
  208. },
  209. /* maybe there's a reason behind it why Terratec sells the Hybrid XS
  210. as Prodigy XS with a different PID, let's keep it separated for now
  211. maybe we'll need it lateron */
  212. [EM2880_BOARD_TERRATEC_PRODIGY_XS] = {
  213. .name = "Terratec Prodigy XS",
  214. .vchannels = 3,
  215. .tda9887_conf = TDA9887_PRESENT,
  216. .tuner_type = TUNER_XC2028,
  217. .decoder = EM28XX_TVP5150,
  218. .input = { {
  219. .type = EM28XX_VMUX_TELEVISION,
  220. .vmux = TVP5150_COMPOSITE0,
  221. .amux = 0,
  222. }, {
  223. .type = EM28XX_VMUX_COMPOSITE1,
  224. .vmux = TVP5150_COMPOSITE1,
  225. .amux = 1,
  226. }, {
  227. .type = EM28XX_VMUX_SVIDEO,
  228. .vmux = TVP5150_SVIDEO,
  229. .amux = 1,
  230. } },
  231. },
  232. [EM2820_BOARD_MSI_VOX_USB_2] = {
  233. .name = "MSI VOX USB 2.0",
  234. .vchannels = 3,
  235. .tuner_type = TUNER_LG_PAL_NEW_TAPC,
  236. .tda9887_conf = TDA9887_PRESENT |
  237. TDA9887_PORT1_ACTIVE |
  238. TDA9887_PORT2_ACTIVE,
  239. .max_range_640_480 = 1,
  240. .decoder = EM28XX_SAA7114,
  241. .input = { {
  242. .type = EM28XX_VMUX_TELEVISION,
  243. .vmux = SAA7115_COMPOSITE4,
  244. .amux = 0,
  245. }, {
  246. .type = EM28XX_VMUX_COMPOSITE1,
  247. .vmux = SAA7115_COMPOSITE0,
  248. .amux = 1,
  249. }, {
  250. .type = EM28XX_VMUX_SVIDEO,
  251. .vmux = SAA7115_SVIDEO3,
  252. .amux = 1,
  253. } },
  254. },
  255. [EM2800_BOARD_TERRATEC_CINERGY_200] = {
  256. .name = "Terratec Cinergy 200 USB",
  257. .is_em2800 = 1,
  258. .vchannels = 3,
  259. .tuner_type = TUNER_LG_PAL_NEW_TAPC,
  260. .tda9887_conf = TDA9887_PRESENT,
  261. .decoder = EM28XX_SAA7113,
  262. .input = { {
  263. .type = EM28XX_VMUX_TELEVISION,
  264. .vmux = SAA7115_COMPOSITE2,
  265. .amux = 0,
  266. }, {
  267. .type = EM28XX_VMUX_COMPOSITE1,
  268. .vmux = SAA7115_COMPOSITE0,
  269. .amux = 1,
  270. }, {
  271. .type = EM28XX_VMUX_SVIDEO,
  272. .vmux = SAA7115_SVIDEO3,
  273. .amux = 1,
  274. } },
  275. },
  276. [EM2800_BOARD_LEADTEK_WINFAST_USBII] = {
  277. .name = "Leadtek Winfast USB II",
  278. .is_em2800 = 1,
  279. .vchannels = 3,
  280. .tuner_type = TUNER_LG_PAL_NEW_TAPC,
  281. .tda9887_conf = TDA9887_PRESENT,
  282. .decoder = EM28XX_SAA7113,
  283. .input = { {
  284. .type = EM28XX_VMUX_TELEVISION,
  285. .vmux = SAA7115_COMPOSITE2,
  286. .amux = 0,
  287. }, {
  288. .type = EM28XX_VMUX_COMPOSITE1,
  289. .vmux = SAA7115_COMPOSITE0,
  290. .amux = 1,
  291. }, {
  292. .type = EM28XX_VMUX_SVIDEO,
  293. .vmux = SAA7115_SVIDEO3,
  294. .amux = 1,
  295. } },
  296. },
  297. [EM2800_BOARD_KWORLD_USB2800] = {
  298. .name = "Kworld USB2800",
  299. .is_em2800 = 1,
  300. .vchannels = 3,
  301. .tuner_type = TUNER_PHILIPS_FCV1236D,
  302. .tda9887_conf = TDA9887_PRESENT,
  303. .decoder = EM28XX_SAA7113,
  304. .input = { {
  305. .type = EM28XX_VMUX_TELEVISION,
  306. .vmux = SAA7115_COMPOSITE2,
  307. .amux = 0,
  308. }, {
  309. .type = EM28XX_VMUX_COMPOSITE1,
  310. .vmux = SAA7115_COMPOSITE0,
  311. .amux = 1,
  312. }, {
  313. .type = EM28XX_VMUX_SVIDEO,
  314. .vmux = SAA7115_SVIDEO3,
  315. .amux = 1,
  316. } },
  317. },
  318. [EM2820_BOARD_PINNACLE_DVC_90] = {
  319. .name = "Pinnacle Dazzle DVC 90/DVC 100",
  320. .vchannels = 3,
  321. .tuner_type = TUNER_ABSENT,
  322. .decoder = EM28XX_SAA7113,
  323. .input = { {
  324. .type = EM28XX_VMUX_COMPOSITE1,
  325. .vmux = SAA7115_COMPOSITE0,
  326. .amux = 1,
  327. }, {
  328. .type = EM28XX_VMUX_SVIDEO,
  329. .vmux = SAA7115_SVIDEO3,
  330. .amux = 1,
  331. } },
  332. },
  333. [EM2800_BOARD_VGEAR_POCKETTV] = {
  334. .name = "V-Gear PocketTV",
  335. .is_em2800 = 1,
  336. .vchannels = 3,
  337. .tuner_type = TUNER_LG_PAL_NEW_TAPC,
  338. .tda9887_conf = TDA9887_PRESENT,
  339. .decoder = EM28XX_SAA7113,
  340. .input = { {
  341. .type = EM28XX_VMUX_TELEVISION,
  342. .vmux = SAA7115_COMPOSITE2,
  343. .amux = 0,
  344. }, {
  345. .type = EM28XX_VMUX_COMPOSITE1,
  346. .vmux = SAA7115_COMPOSITE0,
  347. .amux = 1,
  348. }, {
  349. .type = EM28XX_VMUX_SVIDEO,
  350. .vmux = SAA7115_SVIDEO3,
  351. .amux = 1,
  352. } },
  353. },
  354. [EM2820_BOARD_PROLINK_PLAYTV_USB2] = {
  355. .name = "Pixelview Prolink PlayTV USB 2.0",
  356. .vchannels = 3,
  357. .tda9887_conf = TDA9887_PRESENT,
  358. .tuner_type = TUNER_YMEC_TVF_5533MF,
  359. .decoder = EM28XX_SAA7113,
  360. .input = { {
  361. .type = EM28XX_VMUX_TELEVISION,
  362. .vmux = SAA7115_COMPOSITE2,
  363. .amux = EM28XX_AMUX_LINE_IN,
  364. }, {
  365. .type = EM28XX_VMUX_COMPOSITE1,
  366. .vmux = SAA7115_COMPOSITE0,
  367. .amux = EM28XX_AMUX_LINE_IN,
  368. }, {
  369. .type = EM28XX_VMUX_SVIDEO,
  370. .vmux = SAA7115_SVIDEO3,
  371. .amux = EM28XX_AMUX_LINE_IN,
  372. } },
  373. },
  374. };
  375. const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards);
  376. /* table of devices that work with this driver */
  377. struct usb_device_id em28xx_id_table [] = {
  378. { USB_DEVICE(0xeb1a, 0x2750),
  379. .driver_info = EM2820_BOARD_UNKNOWN },
  380. { USB_DEVICE(0xeb1a, 0x2800),
  381. .driver_info = EM2800_BOARD_UNKNOWN },
  382. { USB_DEVICE(0xeb1a, 0x2820),
  383. .driver_info = EM2820_BOARD_UNKNOWN },
  384. { USB_DEVICE(0xeb1a, 0x2821),
  385. .driver_info = EM2820_BOARD_UNKNOWN },
  386. { USB_DEVICE(0xeb1a, 0x2860),
  387. .driver_info = EM2820_BOARD_UNKNOWN },
  388. { USB_DEVICE(0xeb1a, 0x2861),
  389. .driver_info = EM2820_BOARD_UNKNOWN },
  390. { USB_DEVICE(0xeb1a, 0x2870),
  391. .driver_info = EM2820_BOARD_UNKNOWN },
  392. { USB_DEVICE(0xeb1a, 0x2881),
  393. .driver_info = EM2820_BOARD_UNKNOWN },
  394. { USB_DEVICE(0xeb1a, 0x2883),
  395. .driver_info = EM2820_BOARD_UNKNOWN },
  396. { USB_DEVICE(0x0ccd, 0x0036),
  397. .driver_info = EM2820_BOARD_TERRATEC_CINERGY_250 },
  398. { USB_DEVICE(0x2304, 0x0208),
  399. .driver_info = EM2820_BOARD_PINNACLE_USB_2 },
  400. { USB_DEVICE(0x2040, 0x4200),
  401. .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 },
  402. { USB_DEVICE(0x2040, 0x4201),
  403. .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 },
  404. { USB_DEVICE(0x2304, 0x0207),
  405. .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
  406. { USB_DEVICE(0x2304, 0x021a),
  407. .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
  408. { USB_DEVICE(0x2040, 0x6500),
  409. .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 },
  410. { USB_DEVICE(0x2040, 0x6502),
  411. .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 },
  412. { USB_DEVICE(0x2040, 0x6513), /* HCW HVR-980 */
  413. .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 },
  414. { USB_DEVICE(0x2040, 0x6517), /* HP HVR-950 */
  415. .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 },
  416. { USB_DEVICE(0x2040, 0x651b), /* RP HVR-950 */
  417. .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 },
  418. { USB_DEVICE(0x2040, 0x651f), /* HCW HVR-850 */
  419. .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 },
  420. { USB_DEVICE(0x0ccd, 0x0042),
  421. .driver_info = EM2880_BOARD_TERRATEC_HYBRID_XS },
  422. { USB_DEVICE(0x0ccd, 0x0047),
  423. .driver_info = EM2880_BOARD_TERRATEC_PRODIGY_XS },
  424. { },
  425. };
  426. MODULE_DEVICE_TABLE(usb, em28xx_id_table);
  427. /*
  428. * Reset sequences for analog/digital modes
  429. */
  430. /* Board Hauppauge WinTV HVR 900 analog */
  431. static struct em28xx_reg_seq hauppauge_wintv_hvr_900_analog[] = {
  432. {EM28XX_R08_GPIO, 0x2d, ~EM_GPIO_4, 10},
  433. {0x05, 0xff, 0x10, 10},
  434. { -1, -1, -1, -1},
  435. };
  436. /* Board Hauppauge WinTV HVR 900 digital */
  437. static struct em28xx_reg_seq hauppauge_wintv_hvr_900_digital[] = {
  438. {EM28XX_R08_GPIO, 0x2e, ~EM_GPIO_4, 10},
  439. {EM2880_R04_GPO, 0x04, 0x0f, 10},
  440. {EM2880_R04_GPO, 0x0c, 0x0f, 10},
  441. { -1, -1, -1, -1},
  442. };
  443. /* Board Hauppauge WinTV HVR 900 tuner_callback */
  444. static struct em28xx_reg_seq hauppauge_wintv_hvr_900_tuner_callback[] = {
  445. {EM28XX_R08_GPIO, EM_GPIO_4, EM_GPIO_4, 10},
  446. {EM28XX_R08_GPIO, 0, EM_GPIO_4, 10},
  447. {EM28XX_R08_GPIO, EM_GPIO_4, EM_GPIO_4, 10},
  448. { -1, -1, -1, -1},
  449. };
  450. /*
  451. * EEPROM hash table for devices with generic USB IDs
  452. */
  453. static struct em28xx_hash_table em28xx_eeprom_hash [] = {
  454. /* P/N: SA 60002070465 Tuner: TVF7533-MF */
  455. {0x6ce05a8f, EM2820_BOARD_PROLINK_PLAYTV_USB2, TUNER_YMEC_TVF_5533MF},
  456. };
  457. /* I2C devicelist hash table for devices with generic USB IDs */
  458. static struct em28xx_hash_table em28xx_i2c_hash[] = {
  459. {0xb06a32c3, EM2800_BOARD_TERRATEC_CINERGY_200, TUNER_LG_PAL_NEW_TAPC},
  460. {0xf51200e3, EM2800_BOARD_VGEAR_POCKETTV, TUNER_LG_PAL_NEW_TAPC},
  461. };
  462. int em28xx_tuner_callback(void *ptr, int command, int arg)
  463. {
  464. int rc = 0;
  465. struct em28xx *dev = ptr;
  466. if (dev->tuner_type != TUNER_XC2028)
  467. return 0;
  468. if (command != XC2028_TUNER_RESET)
  469. return 0;
  470. if (dev->mode == EM28XX_ANALOG_MODE)
  471. rc = em28xx_gpio_set(dev, dev->tun_analog_gpio);
  472. else
  473. rc = em28xx_gpio_set(dev, dev->tun_digital_gpio);
  474. return rc;
  475. }
  476. EXPORT_SYMBOL_GPL(em28xx_tuner_callback);
  477. static void em28xx_set_model(struct em28xx *dev)
  478. {
  479. dev->is_em2800 = em28xx_boards[dev->model].is_em2800;
  480. dev->has_msp34xx = em28xx_boards[dev->model].has_msp34xx;
  481. dev->tda9887_conf = em28xx_boards[dev->model].tda9887_conf;
  482. dev->decoder = em28xx_boards[dev->model].decoder;
  483. dev->video_inputs = em28xx_boards[dev->model].vchannels;
  484. dev->has_12mhz_i2s = em28xx_boards[dev->model].has_12mhz_i2s;
  485. dev->max_range_640_480 = em28xx_boards[dev->model].max_range_640_480;
  486. dev->has_dvb = em28xx_boards[dev->model].has_dvb;
  487. }
  488. /* Since em28xx_pre_card_setup() requires a proper dev->model,
  489. * this won't work for boards with generic PCI IDs
  490. */
  491. void em28xx_pre_card_setup(struct em28xx *dev)
  492. {
  493. int rc;
  494. rc = em28xx_read_reg(dev, EM2880_R04_GPO);
  495. if (rc >= 0)
  496. dev->reg_gpo = rc;
  497. dev->wait_after_write = 5;
  498. rc = em28xx_read_reg(dev, EM28XX_R0A_CHIPID);
  499. if (rc > 0) {
  500. switch (rc) {
  501. case CHIP_ID_EM2883:
  502. em28xx_info("chip ID is em2882/em2883\n");
  503. dev->wait_after_write = 0;
  504. break;
  505. default:
  506. em28xx_info("em28xx chip ID = %d\n", rc);
  507. }
  508. }
  509. em28xx_set_model(dev);
  510. /* request some modules */
  511. switch (dev->model) {
  512. case EM2880_BOARD_TERRATEC_PRODIGY_XS:
  513. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
  514. case EM2880_BOARD_TERRATEC_HYBRID_XS:
  515. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
  516. em28xx_write_regs(dev, EM28XX_R0F_XCLK, "\x27", 1);
  517. em28xx_write_regs(dev, EM28XX_R06_I2C_CLK, "\x40", 1);
  518. msleep(50);
  519. /* Sets GPO/GPIO sequences for this device */
  520. dev->analog_gpio = hauppauge_wintv_hvr_900_analog;
  521. dev->digital_gpio = hauppauge_wintv_hvr_900_digital;
  522. dev->tun_analog_gpio = hauppauge_wintv_hvr_900_tuner_callback;
  523. dev->tun_digital_gpio = hauppauge_wintv_hvr_900_tuner_callback;
  524. break;
  525. }
  526. em28xx_gpio_set(dev, dev->tun_analog_gpio);
  527. em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
  528. /* Unlock device */
  529. em28xx_set_mode(dev, EM28XX_MODE_UNDEFINED);
  530. }
  531. static void em28xx_setup_xc3028(struct em28xx *dev, struct xc2028_ctrl *ctl)
  532. {
  533. memset(ctl, 0, sizeof(*ctl));
  534. ctl->fname = XC2028_DEFAULT_FIRMWARE;
  535. ctl->max_len = 64;
  536. ctl->mts = em28xx_boards[dev->model].mts_firmware;
  537. switch (dev->model) {
  538. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
  539. ctl->demod = XC3028_FE_ZARLINK456;
  540. break;
  541. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
  542. /* FIXME: Better to specify the needed IF */
  543. ctl->demod = XC3028_FE_DEFAULT;
  544. break;
  545. default:
  546. ctl->demod = XC3028_FE_OREN538;
  547. }
  548. }
  549. static void em28xx_config_tuner(struct em28xx *dev)
  550. {
  551. struct v4l2_priv_tun_config xc2028_cfg;
  552. struct tuner_setup tun_setup;
  553. struct v4l2_frequency f;
  554. if (dev->tuner_type == TUNER_ABSENT)
  555. return;
  556. tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
  557. tun_setup.type = dev->tuner_type;
  558. tun_setup.addr = dev->tuner_addr;
  559. tun_setup.tuner_callback = em28xx_tuner_callback;
  560. em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup);
  561. if (dev->tuner_type == TUNER_XC2028) {
  562. struct xc2028_ctrl ctl;
  563. em28xx_setup_xc3028(dev, &ctl);
  564. xc2028_cfg.tuner = TUNER_XC2028;
  565. xc2028_cfg.priv = &ctl;
  566. em28xx_i2c_call_clients(dev, TUNER_SET_CONFIG, &xc2028_cfg);
  567. }
  568. /* configure tuner */
  569. f.tuner = 0;
  570. f.type = V4L2_TUNER_ANALOG_TV;
  571. f.frequency = 9076; /* just a magic number */
  572. dev->ctl_freq = f.frequency;
  573. em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, &f);
  574. }
  575. static int em28xx_hint_board(struct em28xx *dev)
  576. {
  577. int i;
  578. /* HINT method: EEPROM
  579. *
  580. * This method works only for boards with eeprom.
  581. * Uses a hash of all eeprom bytes. The hash should be
  582. * unique for a vendor/tuner pair.
  583. * There are a high chance that tuners for different
  584. * video standards produce different hashes.
  585. */
  586. for (i = 0; i < ARRAY_SIZE(em28xx_eeprom_hash); i++) {
  587. if (dev->hash == em28xx_eeprom_hash[i].hash) {
  588. dev->model = em28xx_eeprom_hash[i].model;
  589. dev->tuner_type = em28xx_eeprom_hash[i].tuner;
  590. em28xx_errdev("Your board has no unique USB ID.\n");
  591. em28xx_errdev("A hint were successfully done, "
  592. "based on eeprom hash.\n");
  593. em28xx_errdev("This method is not 100%% failproof.\n");
  594. em28xx_errdev("If the board were missdetected, "
  595. "please email this log to:\n");
  596. em28xx_errdev("\tV4L Mailing List "
  597. " <video4linux-list@redhat.com>\n");
  598. em28xx_errdev("Board detected as %s\n",
  599. em28xx_boards[dev->model].name);
  600. return 0;
  601. }
  602. }
  603. /* HINT method: I2C attached devices
  604. *
  605. * This method works for all boards.
  606. * Uses a hash of i2c scanned devices.
  607. * Devices with the same i2c attached chips will
  608. * be considered equal.
  609. * This method is less precise than the eeprom one.
  610. */
  611. /* user did not request i2c scanning => do it now */
  612. if (!dev->i2c_hash)
  613. em28xx_do_i2c_scan(dev);
  614. for (i = 0; i < ARRAY_SIZE(em28xx_i2c_hash); i++) {
  615. if (dev->i2c_hash == em28xx_i2c_hash[i].hash) {
  616. dev->model = em28xx_i2c_hash[i].model;
  617. dev->tuner_type = em28xx_i2c_hash[i].tuner;
  618. em28xx_errdev("Your board has no unique USB ID.\n");
  619. em28xx_errdev("A hint were successfully done, "
  620. "based on i2c devicelist hash.\n");
  621. em28xx_errdev("This method is not 100%% failproof.\n");
  622. em28xx_errdev("If the board were missdetected, "
  623. "please email this log to:\n");
  624. em28xx_errdev("\tV4L Mailing List "
  625. " <video4linux-list@redhat.com>\n");
  626. em28xx_errdev("Board detected as %s\n",
  627. em28xx_boards[dev->model].name);
  628. return 0;
  629. }
  630. }
  631. em28xx_errdev("Your board has no unique USB ID and thus need a "
  632. "hint to be detected.\n");
  633. em28xx_errdev("You may try to use card=<n> insmod option to "
  634. "workaround that.\n");
  635. em28xx_errdev("Please send an email with this log to:\n");
  636. em28xx_errdev("\tV4L Mailing List <video4linux-list@redhat.com>\n");
  637. em28xx_errdev("Board eeprom hash is 0x%08lx\n", dev->hash);
  638. em28xx_errdev("Board i2c devicelist hash is 0x%08lx\n", dev->i2c_hash);
  639. em28xx_errdev("Here is a list of valid choices for the card=<n>"
  640. " insmod option:\n");
  641. for (i = 0; i < em28xx_bcount; i++) {
  642. em28xx_errdev(" card=%d -> %s\n",
  643. i, em28xx_boards[i].name);
  644. }
  645. return -1;
  646. }
  647. /* ----------------------------------------------------------------------- */
  648. void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir)
  649. {
  650. if (disable_ir) {
  651. ir->get_key = NULL;
  652. return ;
  653. }
  654. /* detect & configure */
  655. switch (dev->model) {
  656. case (EM2800_BOARD_UNKNOWN):
  657. break;
  658. case (EM2820_BOARD_UNKNOWN):
  659. break;
  660. case (EM2800_BOARD_TERRATEC_CINERGY_200):
  661. case (EM2820_BOARD_TERRATEC_CINERGY_250):
  662. ir->ir_codes = ir_codes_em_terratec;
  663. ir->get_key = em28xx_get_key_terratec;
  664. snprintf(ir->c.name, sizeof(ir->c.name),
  665. "i2c IR (EM28XX Terratec)");
  666. break;
  667. case (EM2820_BOARD_PINNACLE_USB_2):
  668. ir->ir_codes = ir_codes_pinnacle_grey;
  669. ir->get_key = em28xx_get_key_pinnacle_usb_grey;
  670. snprintf(ir->c.name, sizeof(ir->c.name),
  671. "i2c IR (EM28XX Pinnacle PCTV)");
  672. break;
  673. case (EM2820_BOARD_HAUPPAUGE_WINTV_USB_2):
  674. ir->ir_codes = ir_codes_hauppauge_new;
  675. ir->get_key = em28xx_get_key_em_haup;
  676. snprintf(ir->c.name, sizeof(ir->c.name),
  677. "i2c IR (EM2840 Hauppauge)");
  678. break;
  679. case (EM2820_BOARD_MSI_VOX_USB_2):
  680. break;
  681. case (EM2800_BOARD_LEADTEK_WINFAST_USBII):
  682. break;
  683. case (EM2800_BOARD_KWORLD_USB2800):
  684. break;
  685. }
  686. }
  687. void em28xx_card_setup(struct em28xx *dev)
  688. {
  689. em28xx_set_model(dev);
  690. dev->tuner_type = em28xx_boards[dev->model].tuner_type;
  691. /* request some modules */
  692. switch (dev->model) {
  693. case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
  694. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
  695. case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
  696. {
  697. struct tveeprom tv;
  698. #ifdef CONFIG_MODULES
  699. request_module("tveeprom");
  700. #endif
  701. /* Call first TVeeprom */
  702. dev->i2c_client.addr = 0xa0 >> 1;
  703. tveeprom_hauppauge_analog(&dev->i2c_client, &tv, dev->eedata);
  704. dev->tuner_type = tv.tuner_type;
  705. if (tv.audio_processor == AUDIO_CHIP_MSP34XX) {
  706. dev->i2s_speed = 2048000;
  707. dev->has_msp34xx = 1;
  708. }
  709. #ifdef CONFIG_MODULES
  710. if (tv.has_ir)
  711. request_module("ir-kbd-i2c");
  712. #endif
  713. break;
  714. }
  715. case EM2820_BOARD_KWORLD_PVRTV2800RF:
  716. /* GPIO enables sound on KWORLD PVR TV 2800RF */
  717. em28xx_write_regs_req(dev, 0x00, 0x08, "\xf9", 1);
  718. break;
  719. case EM2820_BOARD_UNKNOWN:
  720. case EM2800_BOARD_UNKNOWN:
  721. if (!em28xx_hint_board(dev))
  722. em28xx_set_model(dev);
  723. }
  724. /* Allow override tuner type by a module parameter */
  725. if (tuner >= 0)
  726. dev->tuner_type = tuner;
  727. #ifdef CONFIG_MODULES
  728. /* request some modules */
  729. if (dev->has_msp34xx)
  730. request_module("msp3400");
  731. if (dev->decoder == EM28XX_SAA7113 || dev->decoder == EM28XX_SAA7114)
  732. request_module("saa7115");
  733. if (dev->decoder == EM28XX_TVP5150)
  734. request_module("tvp5150");
  735. if (dev->tuner_type != TUNER_ABSENT)
  736. request_module("tuner");
  737. #endif
  738. em28xx_config_tuner(dev);
  739. }