au0828-cards.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /*
  2. * Driver for the Auvitek USB bridge
  3. *
  4. * Copyright (c) 2008 Steven Toth <stoth@linuxtv.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. *
  15. * GNU General Public License for more details.
  16. */
  17. #include "au0828.h"
  18. #include "au0828-cards.h"
  19. #include "au8522.h"
  20. #include "media/tuner.h"
  21. #include "media/v4l2-common.h"
  22. static void hvr950q_cs5340_audio(void *priv, int enable)
  23. {
  24. /* Because the HVR-950q shares an i2s bus between the cs5340 and the
  25. au8522, we need to hold cs5340 in reset when using the au8522 */
  26. struct au0828_dev *dev = priv;
  27. if (enable == 1)
  28. au0828_set(dev, REG_000, 0x10);
  29. else
  30. au0828_clear(dev, REG_000, 0x10);
  31. }
  32. /*
  33. * WARNING: There's a quirks table at sound/usb/quirks-table.h
  34. * that should also be updated every time a new device with V4L2 support
  35. * is added here.
  36. */
  37. struct au0828_board au0828_boards[] = {
  38. [AU0828_BOARD_UNKNOWN] = {
  39. .name = "Unknown board",
  40. .tuner_type = -1U,
  41. .tuner_addr = ADDR_UNSET,
  42. },
  43. [AU0828_BOARD_HAUPPAUGE_HVR850] = {
  44. .name = "Hauppauge HVR850",
  45. .tuner_type = TUNER_XC5000,
  46. .tuner_addr = 0x61,
  47. .has_ir_i2c = 1,
  48. .has_analog = 1,
  49. .i2c_clk_divider = AU0828_I2C_CLK_250KHZ,
  50. .input = {
  51. {
  52. .type = AU0828_VMUX_TELEVISION,
  53. .vmux = AU8522_COMPOSITE_CH4_SIF,
  54. .amux = AU8522_AUDIO_SIF,
  55. },
  56. {
  57. .type = AU0828_VMUX_COMPOSITE,
  58. .vmux = AU8522_COMPOSITE_CH1,
  59. .amux = AU8522_AUDIO_NONE,
  60. .audio_setup = hvr950q_cs5340_audio,
  61. },
  62. {
  63. .type = AU0828_VMUX_SVIDEO,
  64. .vmux = AU8522_SVIDEO_CH13,
  65. .amux = AU8522_AUDIO_NONE,
  66. .audio_setup = hvr950q_cs5340_audio,
  67. },
  68. },
  69. },
  70. [AU0828_BOARD_HAUPPAUGE_HVR950Q] = {
  71. .name = "Hauppauge HVR950Q",
  72. .tuner_type = TUNER_XC5000,
  73. .tuner_addr = 0x61,
  74. .has_ir_i2c = 1,
  75. .has_analog = 1,
  76. .i2c_clk_divider = AU0828_I2C_CLK_250KHZ,
  77. .input = {
  78. {
  79. .type = AU0828_VMUX_TELEVISION,
  80. .vmux = AU8522_COMPOSITE_CH4_SIF,
  81. .amux = AU8522_AUDIO_SIF,
  82. },
  83. {
  84. .type = AU0828_VMUX_COMPOSITE,
  85. .vmux = AU8522_COMPOSITE_CH1,
  86. .amux = AU8522_AUDIO_NONE,
  87. .audio_setup = hvr950q_cs5340_audio,
  88. },
  89. {
  90. .type = AU0828_VMUX_SVIDEO,
  91. .vmux = AU8522_SVIDEO_CH13,
  92. .amux = AU8522_AUDIO_NONE,
  93. .audio_setup = hvr950q_cs5340_audio,
  94. },
  95. },
  96. },
  97. [AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL] = {
  98. .name = "Hauppauge HVR950Q rev xxF8",
  99. .tuner_type = TUNER_XC5000,
  100. .tuner_addr = 0x61,
  101. .i2c_clk_divider = AU0828_I2C_CLK_250KHZ,
  102. },
  103. [AU0828_BOARD_DVICO_FUSIONHDTV7] = {
  104. .name = "DViCO FusionHDTV USB",
  105. .tuner_type = TUNER_XC5000,
  106. .tuner_addr = 0x61,
  107. .i2c_clk_divider = AU0828_I2C_CLK_250KHZ,
  108. },
  109. [AU0828_BOARD_HAUPPAUGE_WOODBURY] = {
  110. .name = "Hauppauge Woodbury",
  111. .tuner_type = TUNER_NXP_TDA18271,
  112. .tuner_addr = 0x60,
  113. .i2c_clk_divider = AU0828_I2C_CLK_250KHZ,
  114. },
  115. };
  116. /* Tuner callback function for au0828 boards. Currently only needed
  117. * for HVR1500Q, which has an xc5000 tuner.
  118. */
  119. int au0828_tuner_callback(void *priv, int component, int command, int arg)
  120. {
  121. struct au0828_dev *dev = priv;
  122. dprintk(1, "%s()\n", __func__);
  123. switch (dev->boardnr) {
  124. case AU0828_BOARD_HAUPPAUGE_HVR850:
  125. case AU0828_BOARD_HAUPPAUGE_HVR950Q:
  126. case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
  127. case AU0828_BOARD_DVICO_FUSIONHDTV7:
  128. if (command == 0) {
  129. /* Tuner Reset Command from xc5000 */
  130. /* Drive the tuner into reset and out */
  131. au0828_clear(dev, REG_001, 2);
  132. mdelay(10);
  133. au0828_set(dev, REG_001, 2);
  134. mdelay(10);
  135. return 0;
  136. } else {
  137. pr_err("%s(): Unknown command.\n", __func__);
  138. return -EINVAL;
  139. }
  140. break;
  141. }
  142. return 0; /* Should never be here */
  143. }
  144. static void hauppauge_eeprom(struct au0828_dev *dev, u8 *eeprom_data)
  145. {
  146. struct tveeprom tv;
  147. tveeprom_hauppauge_analog(&tv, eeprom_data);
  148. dev->board.tuner_type = tv.tuner_type;
  149. /* Make sure we support the board model */
  150. switch (tv.model) {
  151. case 72000: /* WinTV-HVR950q (Retail, IR, ATSC/QAM */
  152. case 72001: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and analog video */
  153. case 72101: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and analog video */
  154. case 72201: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
  155. case 72211: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
  156. case 72221: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
  157. case 72231: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
  158. case 72241: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */
  159. case 72251: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and analog video */
  160. case 72261: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */
  161. case 72271: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */
  162. case 72281: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */
  163. case 72301: /* WinTV-HVR850 (Retail, IR, ATSC and analog video */
  164. case 72500: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM */
  165. break;
  166. default:
  167. pr_warn("%s: warning: unknown hauppauge model #%d\n",
  168. __func__, tv.model);
  169. break;
  170. }
  171. pr_info("%s: hauppauge eeprom: model=%d\n",
  172. __func__, tv.model);
  173. }
  174. void au0828_card_analog_fe_setup(struct au0828_dev *dev);
  175. void au0828_card_setup(struct au0828_dev *dev)
  176. {
  177. static u8 eeprom[256];
  178. dprintk(1, "%s()\n", __func__);
  179. if (dev->i2c_rc == 0) {
  180. dev->i2c_client.addr = 0xa0 >> 1;
  181. tveeprom_read(&dev->i2c_client, eeprom, sizeof(eeprom));
  182. }
  183. switch (dev->boardnr) {
  184. case AU0828_BOARD_HAUPPAUGE_HVR850:
  185. case AU0828_BOARD_HAUPPAUGE_HVR950Q:
  186. case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
  187. case AU0828_BOARD_HAUPPAUGE_WOODBURY:
  188. if (dev->i2c_rc == 0)
  189. hauppauge_eeprom(dev, eeprom+0xa0);
  190. break;
  191. }
  192. au0828_card_analog_fe_setup(dev);
  193. }
  194. void au0828_card_analog_fe_setup(struct au0828_dev *dev)
  195. {
  196. #ifdef CONFIG_VIDEO_AU0828_V4L2
  197. struct tuner_setup tun_setup;
  198. struct v4l2_subdev *sd;
  199. unsigned int mode_mask = T_ANALOG_TV;
  200. if (AUVI_INPUT(0).type != AU0828_VMUX_UNDEFINED) {
  201. /* Load the analog demodulator driver (note this would need to
  202. be abstracted out if we ever need to support a different
  203. demod) */
  204. sd = v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
  205. "au8522", 0x8e >> 1, NULL);
  206. if (sd == NULL)
  207. pr_err("analog subdev registration failed\n");
  208. }
  209. /* Setup tuners */
  210. if (dev->board.tuner_type != TUNER_ABSENT && dev->board.has_analog) {
  211. /* Load the tuner module, which does the attach */
  212. sd = v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
  213. "tuner", dev->board.tuner_addr, NULL);
  214. if (sd == NULL)
  215. pr_err("tuner subdev registration fail\n");
  216. tun_setup.mode_mask = mode_mask;
  217. tun_setup.type = dev->board.tuner_type;
  218. tun_setup.addr = dev->board.tuner_addr;
  219. tun_setup.tuner_callback = au0828_tuner_callback;
  220. v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr,
  221. &tun_setup);
  222. }
  223. #endif
  224. }
  225. /*
  226. * The bridge has between 8 and 12 gpios.
  227. * Regs 1 and 0 deal with output enables.
  228. * Regs 3 and 2 deal with direction.
  229. */
  230. void au0828_gpio_setup(struct au0828_dev *dev)
  231. {
  232. dprintk(1, "%s()\n", __func__);
  233. switch (dev->boardnr) {
  234. case AU0828_BOARD_HAUPPAUGE_HVR850:
  235. case AU0828_BOARD_HAUPPAUGE_HVR950Q:
  236. case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
  237. case AU0828_BOARD_HAUPPAUGE_WOODBURY:
  238. /* GPIO's
  239. * 4 - CS5340
  240. * 5 - AU8522 Demodulator
  241. * 6 - eeprom W/P
  242. * 7 - power supply
  243. * 9 - XC5000 Tuner
  244. */
  245. /* Set relevant GPIOs as outputs (leave the EEPROM W/P
  246. as an input since we will never touch it and it has
  247. a pullup) */
  248. au0828_write(dev, REG_003, 0x02);
  249. au0828_write(dev, REG_002, 0x80 | 0x20 | 0x10);
  250. /* Into reset */
  251. au0828_write(dev, REG_001, 0x0);
  252. au0828_write(dev, REG_000, 0x0);
  253. msleep(50);
  254. /* Bring power supply out of reset */
  255. au0828_write(dev, REG_000, 0x80);
  256. msleep(50);
  257. /* Bring xc5000 and au8522 out of reset (leave the
  258. cs5340 in reset until needed) */
  259. au0828_write(dev, REG_001, 0x02); /* xc5000 */
  260. au0828_write(dev, REG_000, 0x80 | 0x20); /* PS + au8522 */
  261. msleep(250);
  262. break;
  263. case AU0828_BOARD_DVICO_FUSIONHDTV7:
  264. /* GPIO's
  265. * 6 - ?
  266. * 8 - AU8522 Demodulator
  267. * 9 - XC5000 Tuner
  268. */
  269. /* Into reset */
  270. au0828_write(dev, REG_003, 0x02);
  271. au0828_write(dev, REG_002, 0xa0);
  272. au0828_write(dev, REG_001, 0x0);
  273. au0828_write(dev, REG_000, 0x0);
  274. msleep(100);
  275. /* Out of reset */
  276. au0828_write(dev, REG_003, 0x02);
  277. au0828_write(dev, REG_002, 0xa0);
  278. au0828_write(dev, REG_001, 0x02);
  279. au0828_write(dev, REG_000, 0xa0);
  280. msleep(250);
  281. break;
  282. }
  283. }
  284. /* table of devices that work with this driver */
  285. struct usb_device_id au0828_usb_id_table[] = {
  286. { USB_DEVICE(0x2040, 0x7200),
  287. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
  288. { USB_DEVICE(0x2040, 0x7240),
  289. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR850 },
  290. { USB_DEVICE(0x0fe9, 0xd620),
  291. .driver_info = AU0828_BOARD_DVICO_FUSIONHDTV7 },
  292. { USB_DEVICE(0x2040, 0x7210),
  293. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
  294. { USB_DEVICE(0x2040, 0x7217),
  295. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
  296. { USB_DEVICE(0x2040, 0x721b),
  297. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
  298. { USB_DEVICE(0x2040, 0x721e),
  299. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
  300. { USB_DEVICE(0x2040, 0x721f),
  301. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
  302. { USB_DEVICE(0x2040, 0x7280),
  303. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
  304. { USB_DEVICE(0x0fd9, 0x0008),
  305. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
  306. { USB_DEVICE(0x2040, 0x7201),
  307. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
  308. { USB_DEVICE(0x2040, 0x7211),
  309. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
  310. { USB_DEVICE(0x2040, 0x7281),
  311. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
  312. { USB_DEVICE(0x05e1, 0x0480),
  313. .driver_info = AU0828_BOARD_HAUPPAUGE_WOODBURY },
  314. { USB_DEVICE(0x2040, 0x8200),
  315. .driver_info = AU0828_BOARD_HAUPPAUGE_WOODBURY },
  316. { USB_DEVICE(0x2040, 0x7260),
  317. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
  318. { USB_DEVICE(0x2040, 0x7213),
  319. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
  320. { USB_DEVICE(0x2040, 0x7270),
  321. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
  322. { },
  323. };
  324. MODULE_DEVICE_TABLE(usb, au0828_usb_id_table);