au0828-cards.c 10 KB

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