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. * 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. 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. .has_ir_i2c = 1,
  47. .has_analog = 1,
  48. .i2c_clk_divider = AU0828_I2C_CLK_250KHZ,
  49. .input = {
  50. {
  51. .type = AU0828_VMUX_TELEVISION,
  52. .vmux = AU8522_COMPOSITE_CH4_SIF,
  53. .amux = AU8522_AUDIO_SIF,
  54. },
  55. {
  56. .type = AU0828_VMUX_COMPOSITE,
  57. .vmux = AU8522_COMPOSITE_CH1,
  58. .amux = AU8522_AUDIO_NONE,
  59. .audio_setup = hvr950q_cs5340_audio,
  60. },
  61. {
  62. .type = AU0828_VMUX_SVIDEO,
  63. .vmux = AU8522_SVIDEO_CH13,
  64. .amux = AU8522_AUDIO_NONE,
  65. .audio_setup = hvr950q_cs5340_audio,
  66. },
  67. },
  68. },
  69. [AU0828_BOARD_HAUPPAUGE_HVR950Q] = {
  70. .name = "Hauppauge HVR950Q",
  71. .tuner_type = TUNER_XC5000,
  72. .tuner_addr = 0x61,
  73. .has_ir_i2c = 1,
  74. .has_analog = 1,
  75. .i2c_clk_divider = AU0828_I2C_CLK_250KHZ,
  76. .input = {
  77. {
  78. .type = AU0828_VMUX_TELEVISION,
  79. .vmux = AU8522_COMPOSITE_CH4_SIF,
  80. .amux = AU8522_AUDIO_SIF,
  81. },
  82. {
  83. .type = AU0828_VMUX_COMPOSITE,
  84. .vmux = AU8522_COMPOSITE_CH1,
  85. .amux = AU8522_AUDIO_NONE,
  86. .audio_setup = hvr950q_cs5340_audio,
  87. },
  88. {
  89. .type = AU0828_VMUX_SVIDEO,
  90. .vmux = AU8522_SVIDEO_CH13,
  91. .amux = AU8522_AUDIO_NONE,
  92. .audio_setup = hvr950q_cs5340_audio,
  93. },
  94. },
  95. },
  96. [AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL] = {
  97. .name = "Hauppauge HVR950Q rev xxF8",
  98. .tuner_type = TUNER_XC5000,
  99. .tuner_addr = 0x61,
  100. .i2c_clk_divider = AU0828_I2C_CLK_250KHZ,
  101. },
  102. [AU0828_BOARD_DVICO_FUSIONHDTV7] = {
  103. .name = "DViCO FusionHDTV USB",
  104. .tuner_type = TUNER_XC5000,
  105. .tuner_addr = 0x61,
  106. .i2c_clk_divider = AU0828_I2C_CLK_250KHZ,
  107. },
  108. [AU0828_BOARD_HAUPPAUGE_WOODBURY] = {
  109. .name = "Hauppauge Woodbury",
  110. .tuner_type = TUNER_NXP_TDA18271,
  111. .tuner_addr = 0x60,
  112. .i2c_clk_divider = AU0828_I2C_CLK_250KHZ,
  113. },
  114. };
  115. /* Tuner callback function for au0828 boards. Currently only needed
  116. * for HVR1500Q, which has an xc5000 tuner.
  117. */
  118. int au0828_tuner_callback(void *priv, int component, int command, int arg)
  119. {
  120. struct au0828_dev *dev = priv;
  121. dprintk(1, "%s()\n", __func__);
  122. switch (dev->boardnr) {
  123. case AU0828_BOARD_HAUPPAUGE_HVR850:
  124. case AU0828_BOARD_HAUPPAUGE_HVR950Q:
  125. case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
  126. case AU0828_BOARD_DVICO_FUSIONHDTV7:
  127. if (command == 0) {
  128. /* Tuner Reset Command from xc5000 */
  129. /* Drive the tuner into reset and out */
  130. au0828_clear(dev, REG_001, 2);
  131. mdelay(10);
  132. au0828_set(dev, REG_001, 2);
  133. mdelay(10);
  134. return 0;
  135. } else {
  136. pr_err("%s(): Unknown command.\n", __func__);
  137. return -EINVAL;
  138. }
  139. break;
  140. }
  141. return 0; /* Should never be here */
  142. }
  143. static void hauppauge_eeprom(struct au0828_dev *dev, u8 *eeprom_data)
  144. {
  145. struct tveeprom tv;
  146. tveeprom_hauppauge_analog(&dev->i2c_client, &tv, eeprom_data);
  147. dev->board.tuner_type = tv.tuner_type;
  148. /* Make sure we support the board model */
  149. switch (tv.model) {
  150. case 72000: /* WinTV-HVR950q (Retail, IR, ATSC/QAM */
  151. case 72001: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and analog video */
  152. case 72101: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and analog video */
  153. case 72201: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
  154. case 72211: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
  155. case 72221: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
  156. case 72231: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
  157. case 72241: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */
  158. case 72251: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and analog video */
  159. case 72261: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */
  160. case 72271: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */
  161. case 72281: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */
  162. case 72301: /* WinTV-HVR850 (Retail, IR, ATSC and analog video */
  163. case 72500: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM */
  164. break;
  165. default:
  166. pr_warn("%s: warning: unknown hauppauge model #%d\n",
  167. __func__, tv.model);
  168. break;
  169. }
  170. pr_info("%s: hauppauge eeprom: model=%d\n",
  171. __func__, tv.model);
  172. }
  173. void au0828_card_analog_fe_setup(struct au0828_dev *dev);
  174. void au0828_card_setup(struct au0828_dev *dev)
  175. {
  176. static u8 eeprom[256];
  177. dprintk(1, "%s()\n", __func__);
  178. dev->board = au0828_boards[dev->boardnr];
  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);