cx23885-dvb.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. /*
  2. * Driver for the Conexant CX23885 PCIe bridge
  3. *
  4. * Copyright (c) 2006 Steven Toth <stoth@hauppauge.com>
  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 <linux/module.h>
  22. #include <linux/init.h>
  23. #include <linux/device.h>
  24. #include <linux/fs.h>
  25. #include <linux/kthread.h>
  26. #include <linux/file.h>
  27. #include <linux/suspend.h>
  28. #include "cx23885.h"
  29. #include <media/v4l2-common.h>
  30. #include "s5h1409.h"
  31. #include "mt2131.h"
  32. #include "tda8290.h"
  33. #include "tda18271.h"
  34. #include "lgdt330x.h"
  35. #include "xc5000.h"
  36. #include "tda10048.h"
  37. #include "tuner-xc2028.h"
  38. #include "tuner-simple.h"
  39. #include "dib7000p.h"
  40. #include "dibx000_common.h"
  41. static unsigned int debug;
  42. #define dprintk(level, fmt, arg...)\
  43. do { if (debug >= level)\
  44. printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
  45. } while (0)
  46. /* ------------------------------------------------------------------ */
  47. static unsigned int alt_tuner;
  48. module_param(alt_tuner, int, 0644);
  49. MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration");
  50. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  51. /* ------------------------------------------------------------------ */
  52. static int dvb_buf_setup(struct videobuf_queue *q,
  53. unsigned int *count, unsigned int *size)
  54. {
  55. struct cx23885_tsport *port = q->priv_data;
  56. port->ts_packet_size = 188 * 4;
  57. port->ts_packet_count = 32;
  58. *size = port->ts_packet_size * port->ts_packet_count;
  59. *count = 32;
  60. return 0;
  61. }
  62. static int dvb_buf_prepare(struct videobuf_queue *q,
  63. struct videobuf_buffer *vb, enum v4l2_field field)
  64. {
  65. struct cx23885_tsport *port = q->priv_data;
  66. return cx23885_buf_prepare(q, port, (struct cx23885_buffer*)vb, field);
  67. }
  68. static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
  69. {
  70. struct cx23885_tsport *port = q->priv_data;
  71. cx23885_buf_queue(port, (struct cx23885_buffer*)vb);
  72. }
  73. static void dvb_buf_release(struct videobuf_queue *q,
  74. struct videobuf_buffer *vb)
  75. {
  76. cx23885_free_buffer(q, (struct cx23885_buffer*)vb);
  77. }
  78. static struct videobuf_queue_ops dvb_qops = {
  79. .buf_setup = dvb_buf_setup,
  80. .buf_prepare = dvb_buf_prepare,
  81. .buf_queue = dvb_buf_queue,
  82. .buf_release = dvb_buf_release,
  83. };
  84. static struct s5h1409_config hauppauge_generic_config = {
  85. .demod_address = 0x32 >> 1,
  86. .output_mode = S5H1409_SERIAL_OUTPUT,
  87. .gpio = S5H1409_GPIO_ON,
  88. .qam_if = 44000,
  89. .inversion = S5H1409_INVERSION_OFF,
  90. .status_mode = S5H1409_DEMODLOCKING,
  91. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  92. };
  93. static struct tda10048_config hauppauge_hvr1200_config = {
  94. .demod_address = 0x10 >> 1,
  95. .output_mode = TDA10048_SERIAL_OUTPUT,
  96. .fwbulkwritelen = TDA10048_BULKWRITE_200,
  97. .inversion = TDA10048_INVERSION_ON
  98. };
  99. static struct s5h1409_config hauppauge_ezqam_config = {
  100. .demod_address = 0x32 >> 1,
  101. .output_mode = S5H1409_SERIAL_OUTPUT,
  102. .gpio = S5H1409_GPIO_OFF,
  103. .qam_if = 4000,
  104. .inversion = S5H1409_INVERSION_ON,
  105. .status_mode = S5H1409_DEMODLOCKING,
  106. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  107. };
  108. static struct s5h1409_config hauppauge_hvr1800lp_config = {
  109. .demod_address = 0x32 >> 1,
  110. .output_mode = S5H1409_SERIAL_OUTPUT,
  111. .gpio = S5H1409_GPIO_OFF,
  112. .qam_if = 44000,
  113. .inversion = S5H1409_INVERSION_OFF,
  114. .status_mode = S5H1409_DEMODLOCKING,
  115. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  116. };
  117. static struct s5h1409_config hauppauge_hvr1500_config = {
  118. .demod_address = 0x32 >> 1,
  119. .output_mode = S5H1409_SERIAL_OUTPUT,
  120. .gpio = S5H1409_GPIO_OFF,
  121. .inversion = S5H1409_INVERSION_OFF,
  122. .status_mode = S5H1409_DEMODLOCKING,
  123. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  124. };
  125. static struct mt2131_config hauppauge_generic_tunerconfig = {
  126. 0x61
  127. };
  128. static struct lgdt330x_config fusionhdtv_5_express = {
  129. .demod_address = 0x0e,
  130. .demod_chip = LGDT3303,
  131. .serial_mpeg = 0x40,
  132. };
  133. static struct s5h1409_config hauppauge_hvr1500q_config = {
  134. .demod_address = 0x32 >> 1,
  135. .output_mode = S5H1409_SERIAL_OUTPUT,
  136. .gpio = S5H1409_GPIO_ON,
  137. .qam_if = 44000,
  138. .inversion = S5H1409_INVERSION_OFF,
  139. .status_mode = S5H1409_DEMODLOCKING,
  140. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  141. };
  142. static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
  143. .i2c_address = 0x61,
  144. .if_khz = 5380,
  145. .tuner_callback = cx23885_tuner_callback
  146. };
  147. static struct tda829x_config tda829x_no_probe = {
  148. .probe_tuner = TDA829X_DONT_PROBE,
  149. };
  150. static struct tda18271_std_map hauppauge_tda18271_std_map = {
  151. .atsc_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3,
  152. .if_lvl = 6, .rfagc_top = 0x37 },
  153. .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,
  154. .if_lvl = 6, .rfagc_top = 0x37 },
  155. };
  156. static struct tda18271_config hauppauge_tda18271_config = {
  157. .std_map = &hauppauge_tda18271_std_map,
  158. .gate = TDA18271_GATE_ANALOG,
  159. };
  160. static struct tda18271_config hauppauge_hvr1200_tuner_config = {
  161. .gate = TDA18271_GATE_ANALOG,
  162. };
  163. static struct dibx000_agc_config xc3028_agc_config = {
  164. BAND_VHF | BAND_UHF, /* band_caps */
  165. /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=0,
  166. * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
  167. * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0,
  168. * P_agc_nb_est=2, P_agc_write=0
  169. */
  170. (0 << 15) | (0 << 14) | (0 << 11) | (0 << 10) | (0 << 9) | (0 << 8) |
  171. (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), /* setup */
  172. 712, /* inv_gain */
  173. 21, /* time_stabiliz */
  174. 0, /* alpha_level */
  175. 118, /* thlock */
  176. 0, /* wbd_inv */
  177. 2867, /* wbd_ref */
  178. 0, /* wbd_sel */
  179. 2, /* wbd_alpha */
  180. 0, /* agc1_max */
  181. 0, /* agc1_min */
  182. 39718, /* agc2_max */
  183. 9930, /* agc2_min */
  184. 0, /* agc1_pt1 */
  185. 0, /* agc1_pt2 */
  186. 0, /* agc1_pt3 */
  187. 0, /* agc1_slope1 */
  188. 0, /* agc1_slope2 */
  189. 0, /* agc2_pt1 */
  190. 128, /* agc2_pt2 */
  191. 29, /* agc2_slope1 */
  192. 29, /* agc2_slope2 */
  193. 17, /* alpha_mant */
  194. 27, /* alpha_exp */
  195. 23, /* beta_mant */
  196. 51, /* beta_exp */
  197. 1, /* perform_agc_softsplit */
  198. };
  199. /* PLL Configuration for COFDM BW_MHz = 8.000000
  200. * With external clock = 30.000000 */
  201. static struct dibx000_bandwidth_config xc3028_bw_config = {
  202. 60000, /* internal */
  203. 30000, /* sampling */
  204. 1, /* pll_cfg: prediv */
  205. 8, /* pll_cfg: ratio */
  206. 3, /* pll_cfg: range */
  207. 1, /* pll_cfg: reset */
  208. 0, /* pll_cfg: bypass */
  209. 0, /* misc: refdiv */
  210. 0, /* misc: bypclk_div */
  211. 1, /* misc: IO_CLK_en_core */
  212. 1, /* misc: ADClkSrc */
  213. 0, /* misc: modulo */
  214. (3 << 14) | (1 << 12) | (524 << 0), /* sad_cfg: refsel, sel, freq_15k */
  215. (1 << 25) | 5816102, /* ifreq = 5.200000 MHz */
  216. 20452225, /* timf */
  217. 30000000 /* xtal_hz */
  218. };
  219. static struct dib7000p_config hauppauge_hvr1400_dib7000_config = {
  220. .output_mpeg2_in_188_bytes = 1,
  221. .hostbus_diversity = 1,
  222. .tuner_is_baseband = 0,
  223. .update_lna = NULL,
  224. .agc_config_count = 1,
  225. .agc = &xc3028_agc_config,
  226. .bw = &xc3028_bw_config,
  227. .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
  228. .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
  229. .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
  230. .pwm_freq_div = 0,
  231. .agc_control = NULL,
  232. .spur_protect = 0,
  233. .output_mode = OUTMODE_MPEG2_SERIAL,
  234. };
  235. static int cx23885_hvr1500_xc3028_callback(void *ptr, int command, int arg)
  236. {
  237. struct cx23885_tsport *port = ptr;
  238. struct cx23885_dev *dev = port->dev;
  239. switch (command) {
  240. case XC2028_TUNER_RESET:
  241. /* Send the tuner in then out of reset */
  242. /* GPIO-2 xc3028 tuner */
  243. dprintk(1, "%s: XC2028_TUNER_RESET %d\n", __func__, arg);
  244. cx_set(GP0_IO, 0x00040000);
  245. cx_clear(GP0_IO, 0x00000004);
  246. msleep(5);
  247. cx_set(GP0_IO, 0x00040004);
  248. msleep(5);
  249. break;
  250. case XC2028_RESET_CLK:
  251. dprintk(1, "%s: XC2028_RESET_CLK %d\n", __func__, arg);
  252. break;
  253. default:
  254. dprintk(1, "%s: unknown command %d, arg %d\n", __func__,
  255. command, arg);
  256. return -EINVAL;
  257. }
  258. return 0;
  259. }
  260. static int dvb_register(struct cx23885_tsport *port)
  261. {
  262. struct cx23885_dev *dev = port->dev;
  263. struct cx23885_i2c *i2c_bus = NULL;
  264. /* init struct videobuf_dvb */
  265. port->dvb.name = dev->name;
  266. /* init frontend */
  267. switch (dev->board) {
  268. case CX23885_BOARD_HAUPPAUGE_HVR1250:
  269. i2c_bus = &dev->i2c_bus[0];
  270. port->dvb.frontend = dvb_attach(s5h1409_attach,
  271. &hauppauge_generic_config,
  272. &i2c_bus->i2c_adap);
  273. if (port->dvb.frontend != NULL) {
  274. dvb_attach(mt2131_attach, port->dvb.frontend,
  275. &i2c_bus->i2c_adap,
  276. &hauppauge_generic_tunerconfig, 0);
  277. }
  278. break;
  279. case CX23885_BOARD_HAUPPAUGE_HVR1800:
  280. i2c_bus = &dev->i2c_bus[0];
  281. switch (alt_tuner) {
  282. case 1:
  283. port->dvb.frontend =
  284. dvb_attach(s5h1409_attach,
  285. &hauppauge_ezqam_config,
  286. &i2c_bus->i2c_adap);
  287. if (port->dvb.frontend != NULL) {
  288. dvb_attach(tda829x_attach, port->dvb.frontend,
  289. &dev->i2c_bus[1].i2c_adap, 0x42,
  290. &tda829x_no_probe);
  291. dvb_attach(tda18271_attach, port->dvb.frontend,
  292. 0x60, &dev->i2c_bus[1].i2c_adap,
  293. &hauppauge_tda18271_config);
  294. }
  295. break;
  296. case 0:
  297. default:
  298. port->dvb.frontend =
  299. dvb_attach(s5h1409_attach,
  300. &hauppauge_generic_config,
  301. &i2c_bus->i2c_adap);
  302. if (port->dvb.frontend != NULL)
  303. dvb_attach(mt2131_attach, port->dvb.frontend,
  304. &i2c_bus->i2c_adap,
  305. &hauppauge_generic_tunerconfig, 0);
  306. break;
  307. }
  308. break;
  309. case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
  310. i2c_bus = &dev->i2c_bus[0];
  311. port->dvb.frontend = dvb_attach(s5h1409_attach,
  312. &hauppauge_hvr1800lp_config,
  313. &i2c_bus->i2c_adap);
  314. if (port->dvb.frontend != NULL) {
  315. dvb_attach(mt2131_attach, port->dvb.frontend,
  316. &i2c_bus->i2c_adap,
  317. &hauppauge_generic_tunerconfig, 0);
  318. }
  319. break;
  320. case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
  321. i2c_bus = &dev->i2c_bus[0];
  322. port->dvb.frontend = dvb_attach(lgdt330x_attach,
  323. &fusionhdtv_5_express,
  324. &i2c_bus->i2c_adap);
  325. if (port->dvb.frontend != NULL) {
  326. dvb_attach(simple_tuner_attach, port->dvb.frontend,
  327. &i2c_bus->i2c_adap, 0x61,
  328. TUNER_LG_TDVS_H06XF);
  329. }
  330. break;
  331. case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
  332. i2c_bus = &dev->i2c_bus[1];
  333. port->dvb.frontend = dvb_attach(s5h1409_attach,
  334. &hauppauge_hvr1500q_config,
  335. &dev->i2c_bus[0].i2c_adap);
  336. if (port->dvb.frontend != NULL) {
  337. hauppauge_hvr1500q_tunerconfig.priv = i2c_bus;
  338. dvb_attach(xc5000_attach, port->dvb.frontend,
  339. &i2c_bus->i2c_adap,
  340. &hauppauge_hvr1500q_tunerconfig);
  341. }
  342. break;
  343. case CX23885_BOARD_HAUPPAUGE_HVR1500:
  344. i2c_bus = &dev->i2c_bus[1];
  345. port->dvb.frontend = dvb_attach(s5h1409_attach,
  346. &hauppauge_hvr1500_config,
  347. &dev->i2c_bus[0].i2c_adap);
  348. if (port->dvb.frontend != NULL) {
  349. struct dvb_frontend *fe;
  350. struct xc2028_config cfg = {
  351. .i2c_adap = &i2c_bus->i2c_adap,
  352. .i2c_addr = 0x61,
  353. .callback = cx23885_hvr1500_xc3028_callback,
  354. };
  355. static struct xc2028_ctrl ctl = {
  356. .fname = "xc3028-v27.fw",
  357. .max_len = 64,
  358. .scode_table = XC3028_FE_OREN538,
  359. };
  360. fe = dvb_attach(xc2028_attach,
  361. port->dvb.frontend, &cfg);
  362. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  363. fe->ops.tuner_ops.set_config(fe, &ctl);
  364. }
  365. break;
  366. case CX23885_BOARD_HAUPPAUGE_HVR1200:
  367. case CX23885_BOARD_HAUPPAUGE_HVR1700:
  368. i2c_bus = &dev->i2c_bus[0];
  369. port->dvb.frontend = dvb_attach(tda10048_attach,
  370. &hauppauge_hvr1200_config,
  371. &i2c_bus->i2c_adap);
  372. if (port->dvb.frontend != NULL) {
  373. dvb_attach(tda829x_attach, port->dvb.frontend,
  374. &dev->i2c_bus[1].i2c_adap, 0x42,
  375. &tda829x_no_probe);
  376. dvb_attach(tda18271_attach, port->dvb.frontend,
  377. 0x60, &dev->i2c_bus[1].i2c_adap,
  378. &hauppauge_hvr1200_tuner_config);
  379. }
  380. break;
  381. case CX23885_BOARD_HAUPPAUGE_HVR1400:
  382. i2c_bus = &dev->i2c_bus[0];
  383. port->dvb.frontend = dvb_attach(dib7000p_attach,
  384. &i2c_bus->i2c_adap,
  385. 0x12, &hauppauge_hvr1400_dib7000_config);
  386. if (port->dvb.frontend != NULL) {
  387. struct dvb_frontend *fe;
  388. struct xc2028_config cfg = {
  389. .i2c_adap = &dev->i2c_bus[1].i2c_adap,
  390. .i2c_addr = 0x64,
  391. .callback = cx23885_hvr1500_xc3028_callback,
  392. };
  393. static struct xc2028_ctrl ctl = {
  394. .fname = "xc3028L-v36.fw",
  395. .max_len = 64,
  396. .demod = 5000,
  397. .d2633 = 1
  398. };
  399. fe = dvb_attach(xc2028_attach,
  400. port->dvb.frontend, &cfg);
  401. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  402. fe->ops.tuner_ops.set_config(fe, &ctl);
  403. }
  404. break;
  405. default:
  406. printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
  407. dev->name);
  408. break;
  409. }
  410. if (NULL == port->dvb.frontend) {
  411. printk("%s: frontend initialization failed\n", dev->name);
  412. return -1;
  413. }
  414. /* Put the analog decoder in standby to keep it quiet */
  415. cx23885_call_i2c_clients(i2c_bus, TUNER_SET_STANDBY, NULL);
  416. if (port->dvb.frontend->ops.analog_ops.standby)
  417. port->dvb.frontend->ops.analog_ops.standby(port->dvb.frontend);
  418. /* register everything */
  419. return videobuf_dvb_register(&port->dvb, THIS_MODULE, port,
  420. &dev->pci->dev, adapter_nr);
  421. }
  422. int cx23885_dvb_register(struct cx23885_tsport *port)
  423. {
  424. struct cx23885_dev *dev = port->dev;
  425. int err;
  426. dprintk(1, "%s\n", __func__);
  427. dprintk(1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
  428. dev->board,
  429. dev->name,
  430. dev->pci_bus,
  431. dev->pci_slot);
  432. err = -ENODEV;
  433. /* dvb stuff */
  434. printk("%s: cx23885 based dvb card\n", dev->name);
  435. videobuf_queue_sg_init(&port->dvb.dvbq, &dvb_qops, &dev->pci->dev, &port->slock,
  436. V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
  437. sizeof(struct cx23885_buffer), port);
  438. err = dvb_register(port);
  439. if (err != 0)
  440. printk("%s() dvb_register failed err = %d\n", __func__, err);
  441. return err;
  442. }
  443. int cx23885_dvb_unregister(struct cx23885_tsport *port)
  444. {
  445. /* dvb */
  446. if(port->dvb.frontend)
  447. videobuf_dvb_unregister(&port->dvb);
  448. return 0;
  449. }
  450. /*
  451. * Local variables:
  452. * c-basic-offset: 8
  453. * End:
  454. * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
  455. */