cx23885-dvb.c 14 KB

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