au0828-cards.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. 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. struct au0828_board au0828_boards[] = {
  37. [AU0828_BOARD_UNKNOWN] = {
  38. .name = "Unknown board",
  39. .tuner_type = UNSET,
  40. .tuner_addr = ADDR_UNSET,
  41. },
  42. [AU0828_BOARD_HAUPPAUGE_HVR850] = {
  43. .name = "Hauppauge HVR850",
  44. .tuner_type = TUNER_XC5000,
  45. .tuner_addr = 0x61,
  46. .input = {
  47. {
  48. .type = AU0828_VMUX_TELEVISION,
  49. .vmux = AU8522_COMPOSITE_CH4_SIF,
  50. .amux = AU8522_AUDIO_SIF,
  51. },
  52. {
  53. .type = AU0828_VMUX_COMPOSITE,
  54. .vmux = AU8522_COMPOSITE_CH1,
  55. .amux = AU8522_AUDIO_NONE,
  56. .audio_setup = hvr950q_cs5340_audio,
  57. },
  58. {
  59. .type = AU0828_VMUX_SVIDEO,
  60. .vmux = AU8522_SVIDEO_CH13,
  61. .amux = AU8522_AUDIO_NONE,
  62. .audio_setup = hvr950q_cs5340_audio,
  63. },
  64. },
  65. },
  66. [AU0828_BOARD_HAUPPAUGE_HVR950Q] = {
  67. .name = "Hauppauge HVR950Q",
  68. .tuner_type = TUNER_XC5000,
  69. .tuner_addr = 0x61,
  70. .input = {
  71. {
  72. .type = AU0828_VMUX_TELEVISION,
  73. .vmux = AU8522_COMPOSITE_CH4_SIF,
  74. .amux = AU8522_AUDIO_SIF,
  75. },
  76. {
  77. .type = AU0828_VMUX_COMPOSITE,
  78. .vmux = AU8522_COMPOSITE_CH1,
  79. .amux = AU8522_AUDIO_NONE,
  80. .audio_setup = hvr950q_cs5340_audio,
  81. },
  82. {
  83. .type = AU0828_VMUX_SVIDEO,
  84. .vmux = AU8522_SVIDEO_CH13,
  85. .amux = AU8522_AUDIO_NONE,
  86. .audio_setup = hvr950q_cs5340_audio,
  87. },
  88. },
  89. },
  90. [AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL] = {
  91. .name = "Hauppauge HVR950Q rev xxF8",
  92. .tuner_type = UNSET,
  93. .tuner_addr = ADDR_UNSET,
  94. },
  95. [AU0828_BOARD_DVICO_FUSIONHDTV7] = {
  96. .name = "DViCO FusionHDTV USB",
  97. .tuner_type = UNSET,
  98. .tuner_addr = ADDR_UNSET,
  99. },
  100. [AU0828_BOARD_HAUPPAUGE_WOODBURY] = {
  101. .name = "Hauppauge Woodbury",
  102. .tuner_type = UNSET,
  103. .tuner_addr = ADDR_UNSET,
  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(200);
  123. au0828_set(dev, REG_001, 2);
  124. mdelay(50);
  125. return 0;
  126. } else {
  127. printk(KERN_ERR
  128. "%s(): Unknown command.\n", __func__);
  129. return -EINVAL;
  130. }
  131. break;
  132. }
  133. return 0; /* Should never be here */
  134. }
  135. static void hauppauge_eeprom(struct au0828_dev *dev, u8 *eeprom_data)
  136. {
  137. struct tveeprom tv;
  138. tveeprom_hauppauge_analog(&dev->i2c_client, &tv, eeprom_data);
  139. dev->board.tuner_type = tv.tuner_type;
  140. /* Make sure we support the board model */
  141. switch (tv.model) {
  142. case 72000: /* WinTV-HVR950q (Retail, IR, ATSC/QAM */
  143. case 72001: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and analog video */
  144. case 72211: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
  145. case 72221: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
  146. case 72231: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
  147. case 72241: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */
  148. case 72251: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and analog video */
  149. case 72301: /* WinTV-HVR850 (Retail, IR, ATSC and analog video */
  150. case 72500: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM */
  151. break;
  152. default:
  153. printk(KERN_WARNING "%s: warning: "
  154. "unknown hauppauge model #%d\n", __func__, tv.model);
  155. break;
  156. }
  157. printk(KERN_INFO "%s: hauppauge eeprom: model=%d\n",
  158. __func__, tv.model);
  159. }
  160. void au0828_card_setup(struct au0828_dev *dev)
  161. {
  162. static u8 eeprom[256];
  163. struct tuner_setup tun_setup;
  164. struct v4l2_subdev *sd;
  165. unsigned int mode_mask = T_ANALOG_TV |
  166. T_DIGITAL_TV;
  167. dprintk(1, "%s()\n", __func__);
  168. memcpy(&dev->board, &au0828_boards[dev->boardnr], sizeof(dev->board));
  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. if (AUVI_INPUT(0).type != AU0828_VMUX_UNDEFINED) {
  183. /* Load the analog demodulator driver (note this would need to
  184. be abstracted out if we ever need to support a different
  185. demod) */
  186. sd = v4l2_i2c_new_subdev(&dev->i2c_adap, "au8522", "au8522",
  187. 0x8e >> 1);
  188. if (sd == NULL)
  189. printk(KERN_ERR "analog subdev registration failed\n");
  190. }
  191. /* Setup tuners */
  192. if (dev->board.tuner_type != TUNER_ABSENT) {
  193. /* Load the tuner module, which does the attach */
  194. sd = v4l2_i2c_new_subdev(&dev->i2c_adap, "tuner", "tuner",
  195. dev->board.tuner_addr);
  196. if (sd == NULL)
  197. printk(KERN_ERR "tuner subdev registration fail\n");
  198. tun_setup.mode_mask = mode_mask;
  199. tun_setup.type = dev->board.tuner_type;
  200. tun_setup.addr = dev->board.tuner_addr;
  201. tun_setup.tuner_callback = au0828_tuner_callback;
  202. au0828_call_i2c_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup);
  203. }
  204. }
  205. /*
  206. * The bridge has between 8 and 12 gpios.
  207. * Regs 1 and 0 deal with output enables.
  208. * Regs 3 and 2 deal with direction.
  209. */
  210. void au0828_gpio_setup(struct au0828_dev *dev)
  211. {
  212. dprintk(1, "%s()\n", __func__);
  213. switch (dev->boardnr) {
  214. case AU0828_BOARD_HAUPPAUGE_HVR850:
  215. case AU0828_BOARD_HAUPPAUGE_HVR950Q:
  216. case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
  217. case AU0828_BOARD_HAUPPAUGE_WOODBURY:
  218. /* GPIO's
  219. * 4 - CS5340
  220. * 5 - AU8522 Demodulator
  221. * 6 - eeprom W/P
  222. * 7 - power supply
  223. * 9 - XC5000 Tuner
  224. */
  225. /* Into reset */
  226. au0828_write(dev, REG_003, 0x02);
  227. au0828_write(dev, REG_002, 0x80 | 0x20 | 0x10);
  228. au0828_write(dev, REG_001, 0x0);
  229. au0828_write(dev, REG_000, 0x0);
  230. msleep(100);
  231. /* Out of reset (leave the cs5340 in reset until needed) */
  232. au0828_write(dev, REG_003, 0x02);
  233. au0828_write(dev, REG_001, 0x02);
  234. au0828_write(dev, REG_002, 0x80 | 0x20 | 0x10);
  235. au0828_write(dev, REG_000, 0x80 | 0x40 | 0x20);
  236. msleep(250);
  237. break;
  238. case AU0828_BOARD_DVICO_FUSIONHDTV7:
  239. /* GPIO's
  240. * 6 - ?
  241. * 8 - AU8522 Demodulator
  242. * 9 - XC5000 Tuner
  243. */
  244. /* Into reset */
  245. au0828_write(dev, REG_003, 0x02);
  246. au0828_write(dev, REG_002, 0xa0);
  247. au0828_write(dev, REG_001, 0x0);
  248. au0828_write(dev, REG_000, 0x0);
  249. msleep(100);
  250. /* Out of reset */
  251. au0828_write(dev, REG_003, 0x02);
  252. au0828_write(dev, REG_002, 0xa0);
  253. au0828_write(dev, REG_001, 0x02);
  254. au0828_write(dev, REG_000, 0xa0);
  255. msleep(250);
  256. break;
  257. }
  258. }
  259. /* table of devices that work with this driver */
  260. struct usb_device_id au0828_usb_id_table[] = {
  261. { USB_DEVICE(0x2040, 0x7200),
  262. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
  263. { USB_DEVICE(0x2040, 0x7240),
  264. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR850 },
  265. { USB_DEVICE(0x0fe9, 0xd620),
  266. .driver_info = AU0828_BOARD_DVICO_FUSIONHDTV7 },
  267. { USB_DEVICE(0x2040, 0x7210),
  268. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
  269. { USB_DEVICE(0x2040, 0x7217),
  270. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
  271. { USB_DEVICE(0x2040, 0x721b),
  272. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
  273. { USB_DEVICE(0x2040, 0x721e),
  274. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
  275. { USB_DEVICE(0x2040, 0x721f),
  276. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
  277. { USB_DEVICE(0x2040, 0x7280),
  278. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
  279. { USB_DEVICE(0x0fd9, 0x0008),
  280. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
  281. { USB_DEVICE(0x2040, 0x7201),
  282. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
  283. { USB_DEVICE(0x2040, 0x7211),
  284. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
  285. { USB_DEVICE(0x2040, 0x7281),
  286. .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
  287. { USB_DEVICE(0x2040, 0x8200),
  288. .driver_info = AU0828_BOARD_HAUPPAUGE_WOODBURY },
  289. { },
  290. };
  291. MODULE_DEVICE_TABLE(usb, au0828_usb_id_table);