au0828-cards.c 9.7 KB

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