cx23885-dvb.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. /*
  2. * Driver for the Conexant CX23885 PCIe bridge
  3. *
  4. * Copyright (c) 2006 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 <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 "s5h1411.h"
  32. #include "mt2131.h"
  33. #include "tda8290.h"
  34. #include "tda18271.h"
  35. #include "lgdt330x.h"
  36. #include "xc5000.h"
  37. #include "tda10048.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 s5h1409_config dvico_s5h1409_config = {
  144. .demod_address = 0x32 >> 1,
  145. .output_mode = S5H1409_SERIAL_OUTPUT,
  146. .gpio = S5H1409_GPIO_ON,
  147. .qam_if = 44000,
  148. .inversion = S5H1409_INVERSION_OFF,
  149. .status_mode = S5H1409_DEMODLOCKING,
  150. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  151. };
  152. static struct s5h1411_config dvico_s5h1411_config = {
  153. .output_mode = S5H1411_SERIAL_OUTPUT,
  154. .gpio = S5H1411_GPIO_ON,
  155. .qam_if = S5H1411_IF_44000,
  156. .vsb_if = S5H1411_IF_44000,
  157. .inversion = S5H1411_INVERSION_OFF,
  158. .status_mode = S5H1411_DEMODLOCKING,
  159. .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  160. };
  161. static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
  162. .i2c_address = 0x61,
  163. .if_khz = 5380,
  164. .tuner_callback = cx23885_xc5000_tuner_callback,
  165. };
  166. static struct xc5000_config dvico_xc5000_tunerconfig = {
  167. .i2c_address = 0x64,
  168. .if_khz = 5380,
  169. .tuner_callback = cx23885_xc5000_tuner_callback,
  170. };
  171. static struct tda829x_config tda829x_no_probe = {
  172. .probe_tuner = TDA829X_DONT_PROBE,
  173. };
  174. static struct tda18271_std_map hauppauge_tda18271_std_map = {
  175. .atsc_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3,
  176. .if_lvl = 6, .rfagc_top = 0x37 },
  177. .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,
  178. .if_lvl = 6, .rfagc_top = 0x37 },
  179. };
  180. static struct tda18271_config hauppauge_tda18271_config = {
  181. .std_map = &hauppauge_tda18271_std_map,
  182. .gate = TDA18271_GATE_ANALOG,
  183. };
  184. static struct tda18271_config hauppauge_hvr1200_tuner_config = {
  185. .gate = TDA18271_GATE_ANALOG,
  186. };
  187. static struct dibx000_agc_config xc3028_agc_config = {
  188. BAND_VHF | BAND_UHF, /* band_caps */
  189. /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=0,
  190. * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
  191. * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0,
  192. * P_agc_nb_est=2, P_agc_write=0
  193. */
  194. (0 << 15) | (0 << 14) | (0 << 11) | (0 << 10) | (0 << 9) | (0 << 8) |
  195. (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), /* setup */
  196. 712, /* inv_gain */
  197. 21, /* time_stabiliz */
  198. 0, /* alpha_level */
  199. 118, /* thlock */
  200. 0, /* wbd_inv */
  201. 2867, /* wbd_ref */
  202. 0, /* wbd_sel */
  203. 2, /* wbd_alpha */
  204. 0, /* agc1_max */
  205. 0, /* agc1_min */
  206. 39718, /* agc2_max */
  207. 9930, /* agc2_min */
  208. 0, /* agc1_pt1 */
  209. 0, /* agc1_pt2 */
  210. 0, /* agc1_pt3 */
  211. 0, /* agc1_slope1 */
  212. 0, /* agc1_slope2 */
  213. 0, /* agc2_pt1 */
  214. 128, /* agc2_pt2 */
  215. 29, /* agc2_slope1 */
  216. 29, /* agc2_slope2 */
  217. 17, /* alpha_mant */
  218. 27, /* alpha_exp */
  219. 23, /* beta_mant */
  220. 51, /* beta_exp */
  221. 1, /* perform_agc_softsplit */
  222. };
  223. /* PLL Configuration for COFDM BW_MHz = 8.000000
  224. * With external clock = 30.000000 */
  225. static struct dibx000_bandwidth_config xc3028_bw_config = {
  226. 60000, /* internal */
  227. 30000, /* sampling */
  228. 1, /* pll_cfg: prediv */
  229. 8, /* pll_cfg: ratio */
  230. 3, /* pll_cfg: range */
  231. 1, /* pll_cfg: reset */
  232. 0, /* pll_cfg: bypass */
  233. 0, /* misc: refdiv */
  234. 0, /* misc: bypclk_div */
  235. 1, /* misc: IO_CLK_en_core */
  236. 1, /* misc: ADClkSrc */
  237. 0, /* misc: modulo */
  238. (3 << 14) | (1 << 12) | (524 << 0), /* sad_cfg: refsel, sel, freq_15k */
  239. (1 << 25) | 5816102, /* ifreq = 5.200000 MHz */
  240. 20452225, /* timf */
  241. 30000000 /* xtal_hz */
  242. };
  243. static struct dib7000p_config hauppauge_hvr1400_dib7000_config = {
  244. .output_mpeg2_in_188_bytes = 1,
  245. .hostbus_diversity = 1,
  246. .tuner_is_baseband = 0,
  247. .update_lna = NULL,
  248. .agc_config_count = 1,
  249. .agc = &xc3028_agc_config,
  250. .bw = &xc3028_bw_config,
  251. .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
  252. .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
  253. .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
  254. .pwm_freq_div = 0,
  255. .agc_control = NULL,
  256. .spur_protect = 0,
  257. .output_mode = OUTMODE_MPEG2_SERIAL,
  258. };
  259. static int dvb_register(struct cx23885_tsport *port)
  260. {
  261. struct cx23885_dev *dev = port->dev;
  262. struct cx23885_i2c *i2c_bus = NULL;
  263. /* init struct videobuf_dvb */
  264. port->dvb.name = dev->name;
  265. /* init frontend */
  266. switch (dev->board) {
  267. case CX23885_BOARD_HAUPPAUGE_HVR1250:
  268. i2c_bus = &dev->i2c_bus[0];
  269. port->dvb.frontend = dvb_attach(s5h1409_attach,
  270. &hauppauge_generic_config,
  271. &i2c_bus->i2c_adap);
  272. if (port->dvb.frontend != NULL) {
  273. dvb_attach(mt2131_attach, port->dvb.frontend,
  274. &i2c_bus->i2c_adap,
  275. &hauppauge_generic_tunerconfig, 0);
  276. }
  277. break;
  278. case CX23885_BOARD_HAUPPAUGE_HVR1800:
  279. i2c_bus = &dev->i2c_bus[0];
  280. switch (alt_tuner) {
  281. case 1:
  282. port->dvb.frontend =
  283. dvb_attach(s5h1409_attach,
  284. &hauppauge_ezqam_config,
  285. &i2c_bus->i2c_adap);
  286. if (port->dvb.frontend != NULL) {
  287. dvb_attach(tda829x_attach, port->dvb.frontend,
  288. &dev->i2c_bus[1].i2c_adap, 0x42,
  289. &tda829x_no_probe);
  290. dvb_attach(tda18271_attach, port->dvb.frontend,
  291. 0x60, &dev->i2c_bus[1].i2c_adap,
  292. &hauppauge_tda18271_config);
  293. }
  294. break;
  295. case 0:
  296. default:
  297. port->dvb.frontend =
  298. dvb_attach(s5h1409_attach,
  299. &hauppauge_generic_config,
  300. &i2c_bus->i2c_adap);
  301. if (port->dvb.frontend != NULL)
  302. dvb_attach(mt2131_attach, port->dvb.frontend,
  303. &i2c_bus->i2c_adap,
  304. &hauppauge_generic_tunerconfig, 0);
  305. break;
  306. }
  307. break;
  308. case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
  309. i2c_bus = &dev->i2c_bus[0];
  310. port->dvb.frontend = dvb_attach(s5h1409_attach,
  311. &hauppauge_hvr1800lp_config,
  312. &i2c_bus->i2c_adap);
  313. if (port->dvb.frontend != NULL) {
  314. dvb_attach(mt2131_attach, port->dvb.frontend,
  315. &i2c_bus->i2c_adap,
  316. &hauppauge_generic_tunerconfig, 0);
  317. }
  318. break;
  319. case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
  320. i2c_bus = &dev->i2c_bus[0];
  321. port->dvb.frontend = dvb_attach(lgdt330x_attach,
  322. &fusionhdtv_5_express,
  323. &i2c_bus->i2c_adap);
  324. if (port->dvb.frontend != NULL) {
  325. dvb_attach(simple_tuner_attach, port->dvb.frontend,
  326. &i2c_bus->i2c_adap, 0x61,
  327. TUNER_LG_TDVS_H06XF);
  328. }
  329. break;
  330. case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
  331. i2c_bus = &dev->i2c_bus[1];
  332. port->dvb.frontend = dvb_attach(s5h1409_attach,
  333. &hauppauge_hvr1500q_config,
  334. &dev->i2c_bus[0].i2c_adap);
  335. if (port->dvb.frontend != NULL)
  336. dvb_attach(xc5000_attach, port->dvb.frontend,
  337. &i2c_bus->i2c_adap,
  338. &hauppauge_hvr1500q_tunerconfig, i2c_bus);
  339. break;
  340. case CX23885_BOARD_HAUPPAUGE_HVR1500:
  341. i2c_bus = &dev->i2c_bus[1];
  342. port->dvb.frontend = dvb_attach(s5h1409_attach,
  343. &hauppauge_hvr1500_config,
  344. &dev->i2c_bus[0].i2c_adap);
  345. if (port->dvb.frontend != NULL) {
  346. struct dvb_frontend *fe;
  347. struct xc2028_config cfg = {
  348. .i2c_adap = &i2c_bus->i2c_adap,
  349. .i2c_addr = 0x61,
  350. .callback = cx23885_xc3028_tuner_callback,
  351. };
  352. static struct xc2028_ctrl ctl = {
  353. .fname = "xc3028-v27.fw",
  354. .max_len = 64,
  355. .scode_table = XC3028_FE_OREN538,
  356. };
  357. fe = dvb_attach(xc2028_attach,
  358. port->dvb.frontend, &cfg);
  359. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  360. fe->ops.tuner_ops.set_config(fe, &ctl);
  361. }
  362. break;
  363. case CX23885_BOARD_HAUPPAUGE_HVR1200:
  364. case CX23885_BOARD_HAUPPAUGE_HVR1700:
  365. i2c_bus = &dev->i2c_bus[0];
  366. port->dvb.frontend = dvb_attach(tda10048_attach,
  367. &hauppauge_hvr1200_config,
  368. &i2c_bus->i2c_adap);
  369. if (port->dvb.frontend != NULL) {
  370. dvb_attach(tda829x_attach, port->dvb.frontend,
  371. &dev->i2c_bus[1].i2c_adap, 0x42,
  372. &tda829x_no_probe);
  373. dvb_attach(tda18271_attach, port->dvb.frontend,
  374. 0x60, &dev->i2c_bus[1].i2c_adap,
  375. &hauppauge_hvr1200_tuner_config);
  376. }
  377. break;
  378. case CX23885_BOARD_HAUPPAUGE_HVR1400:
  379. i2c_bus = &dev->i2c_bus[0];
  380. port->dvb.frontend = dvb_attach(dib7000p_attach,
  381. &i2c_bus->i2c_adap,
  382. 0x12, &hauppauge_hvr1400_dib7000_config);
  383. if (port->dvb.frontend != NULL) {
  384. struct dvb_frontend *fe;
  385. struct xc2028_config cfg = {
  386. .i2c_adap = &dev->i2c_bus[1].i2c_adap,
  387. .i2c_addr = 0x64,
  388. .callback = cx23885_xc3028_tuner_callback,
  389. };
  390. static struct xc2028_ctrl ctl = {
  391. .fname = "xc3028L-v36.fw",
  392. .max_len = 64,
  393. .demod = 5000,
  394. .d2633 = 1
  395. };
  396. fe = dvb_attach(xc2028_attach,
  397. port->dvb.frontend, &cfg);
  398. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  399. fe->ops.tuner_ops.set_config(fe, &ctl);
  400. }
  401. break;
  402. case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:
  403. i2c_bus = &dev->i2c_bus[port->nr - 1];
  404. port->dvb.frontend = dvb_attach(s5h1409_attach,
  405. &dvico_s5h1409_config,
  406. &i2c_bus->i2c_adap);
  407. if (port->dvb.frontend == NULL)
  408. port->dvb.frontend = dvb_attach(s5h1411_attach,
  409. &dvico_s5h1411_config,
  410. &i2c_bus->i2c_adap);
  411. if (port->dvb.frontend != NULL)
  412. dvb_attach(xc5000_attach, port->dvb.frontend,
  413. &i2c_bus->i2c_adap,
  414. &dvico_xc5000_tunerconfig, i2c_bus);
  415. break;
  416. default:
  417. printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
  418. dev->name);
  419. break;
  420. }
  421. if (NULL == port->dvb.frontend) {
  422. printk("%s: frontend initialization failed\n", dev->name);
  423. return -1;
  424. }
  425. /* Put the analog decoder in standby to keep it quiet */
  426. cx23885_call_i2c_clients(i2c_bus, TUNER_SET_STANDBY, NULL);
  427. if (port->dvb.frontend->ops.analog_ops.standby)
  428. port->dvb.frontend->ops.analog_ops.standby(port->dvb.frontend);
  429. /* register everything */
  430. return videobuf_dvb_register(&port->dvb, THIS_MODULE, port,
  431. &dev->pci->dev, adapter_nr);
  432. }
  433. int cx23885_dvb_register(struct cx23885_tsport *port)
  434. {
  435. struct cx23885_dev *dev = port->dev;
  436. int err;
  437. dprintk(1, "%s\n", __func__);
  438. dprintk(1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
  439. dev->board,
  440. dev->name,
  441. dev->pci_bus,
  442. dev->pci_slot);
  443. err = -ENODEV;
  444. /* dvb stuff */
  445. printk("%s: cx23885 based dvb card\n", dev->name);
  446. videobuf_queue_sg_init(&port->dvb.dvbq, &dvb_qops, &dev->pci->dev, &port->slock,
  447. V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
  448. sizeof(struct cx23885_buffer), port);
  449. err = dvb_register(port);
  450. if (err != 0)
  451. printk("%s() dvb_register failed err = %d\n", __func__, err);
  452. return err;
  453. }
  454. int cx23885_dvb_unregister(struct cx23885_tsport *port)
  455. {
  456. /* dvb */
  457. if(port->dvb.frontend)
  458. videobuf_dvb_unregister(&port->dvb);
  459. return 0;
  460. }
  461. /*
  462. * Local variables:
  463. * c-basic-offset: 8
  464. * End:
  465. * 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
  466. */