cx23885-dvb.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  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 "dvb_ca_en50221.h"
  31. #include "s5h1409.h"
  32. #include "s5h1411.h"
  33. #include "mt2131.h"
  34. #include "tda8290.h"
  35. #include "tda18271.h"
  36. #include "lgdt330x.h"
  37. #include "xc5000.h"
  38. #include "tda10048.h"
  39. #include "tuner-xc2028.h"
  40. #include "tuner-simple.h"
  41. #include "dib7000p.h"
  42. #include "dibx000_common.h"
  43. #include "zl10353.h"
  44. #include "stv0900.h"
  45. #include "stv6110.h"
  46. #include "lnbh24.h"
  47. #include "cx24116.h"
  48. #include "cimax2.h"
  49. #include "netup-eeprom.h"
  50. #include "netup-init.h"
  51. static unsigned int debug;
  52. #define dprintk(level, fmt, arg...)\
  53. do { if (debug >= level)\
  54. printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
  55. } while (0)
  56. /* ------------------------------------------------------------------ */
  57. static unsigned int alt_tuner;
  58. module_param(alt_tuner, int, 0644);
  59. MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration");
  60. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  61. /* ------------------------------------------------------------------ */
  62. static int dvb_buf_setup(struct videobuf_queue *q,
  63. unsigned int *count, unsigned int *size)
  64. {
  65. struct cx23885_tsport *port = q->priv_data;
  66. port->ts_packet_size = 188 * 4;
  67. port->ts_packet_count = 32;
  68. *size = port->ts_packet_size * port->ts_packet_count;
  69. *count = 32;
  70. return 0;
  71. }
  72. static int dvb_buf_prepare(struct videobuf_queue *q,
  73. struct videobuf_buffer *vb, enum v4l2_field field)
  74. {
  75. struct cx23885_tsport *port = q->priv_data;
  76. return cx23885_buf_prepare(q, port, (struct cx23885_buffer *)vb, field);
  77. }
  78. static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
  79. {
  80. struct cx23885_tsport *port = q->priv_data;
  81. cx23885_buf_queue(port, (struct cx23885_buffer *)vb);
  82. }
  83. static void dvb_buf_release(struct videobuf_queue *q,
  84. struct videobuf_buffer *vb)
  85. {
  86. cx23885_free_buffer(q, (struct cx23885_buffer *)vb);
  87. }
  88. static struct videobuf_queue_ops dvb_qops = {
  89. .buf_setup = dvb_buf_setup,
  90. .buf_prepare = dvb_buf_prepare,
  91. .buf_queue = dvb_buf_queue,
  92. .buf_release = dvb_buf_release,
  93. };
  94. static struct s5h1409_config hauppauge_generic_config = {
  95. .demod_address = 0x32 >> 1,
  96. .output_mode = S5H1409_SERIAL_OUTPUT,
  97. .gpio = S5H1409_GPIO_ON,
  98. .qam_if = 44000,
  99. .inversion = S5H1409_INVERSION_OFF,
  100. .status_mode = S5H1409_DEMODLOCKING,
  101. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  102. };
  103. static struct tda10048_config hauppauge_hvr1200_config = {
  104. .demod_address = 0x10 >> 1,
  105. .output_mode = TDA10048_SERIAL_OUTPUT,
  106. .fwbulkwritelen = TDA10048_BULKWRITE_200,
  107. .inversion = TDA10048_INVERSION_ON
  108. };
  109. static struct s5h1409_config hauppauge_ezqam_config = {
  110. .demod_address = 0x32 >> 1,
  111. .output_mode = S5H1409_SERIAL_OUTPUT,
  112. .gpio = S5H1409_GPIO_OFF,
  113. .qam_if = 4000,
  114. .inversion = S5H1409_INVERSION_ON,
  115. .status_mode = S5H1409_DEMODLOCKING,
  116. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  117. };
  118. static struct s5h1409_config hauppauge_hvr1800lp_config = {
  119. .demod_address = 0x32 >> 1,
  120. .output_mode = S5H1409_SERIAL_OUTPUT,
  121. .gpio = S5H1409_GPIO_OFF,
  122. .qam_if = 44000,
  123. .inversion = S5H1409_INVERSION_OFF,
  124. .status_mode = S5H1409_DEMODLOCKING,
  125. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  126. };
  127. static struct s5h1409_config hauppauge_hvr1500_config = {
  128. .demod_address = 0x32 >> 1,
  129. .output_mode = S5H1409_SERIAL_OUTPUT,
  130. .gpio = S5H1409_GPIO_OFF,
  131. .inversion = S5H1409_INVERSION_OFF,
  132. .status_mode = S5H1409_DEMODLOCKING,
  133. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  134. };
  135. static struct mt2131_config hauppauge_generic_tunerconfig = {
  136. 0x61
  137. };
  138. static struct lgdt330x_config fusionhdtv_5_express = {
  139. .demod_address = 0x0e,
  140. .demod_chip = LGDT3303,
  141. .serial_mpeg = 0x40,
  142. };
  143. static struct s5h1409_config hauppauge_hvr1500q_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 s5h1409_config dvico_s5h1409_config = {
  153. .demod_address = 0x32 >> 1,
  154. .output_mode = S5H1409_SERIAL_OUTPUT,
  155. .gpio = S5H1409_GPIO_ON,
  156. .qam_if = 44000,
  157. .inversion = S5H1409_INVERSION_OFF,
  158. .status_mode = S5H1409_DEMODLOCKING,
  159. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  160. };
  161. static struct s5h1411_config dvico_s5h1411_config = {
  162. .output_mode = S5H1411_SERIAL_OUTPUT,
  163. .gpio = S5H1411_GPIO_ON,
  164. .qam_if = S5H1411_IF_44000,
  165. .vsb_if = S5H1411_IF_44000,
  166. .inversion = S5H1411_INVERSION_OFF,
  167. .status_mode = S5H1411_DEMODLOCKING,
  168. .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  169. };
  170. static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
  171. .i2c_address = 0x61,
  172. .if_khz = 5380,
  173. };
  174. static struct xc5000_config dvico_xc5000_tunerconfig = {
  175. .i2c_address = 0x64,
  176. .if_khz = 5380,
  177. };
  178. static struct tda829x_config tda829x_no_probe = {
  179. .probe_tuner = TDA829X_DONT_PROBE,
  180. };
  181. static struct tda18271_std_map hauppauge_tda18271_std_map = {
  182. .atsc_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3,
  183. .if_lvl = 6, .rfagc_top = 0x37 },
  184. .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,
  185. .if_lvl = 6, .rfagc_top = 0x37 },
  186. };
  187. static struct tda18271_config hauppauge_tda18271_config = {
  188. .std_map = &hauppauge_tda18271_std_map,
  189. .gate = TDA18271_GATE_ANALOG,
  190. };
  191. static struct tda18271_config hauppauge_hvr1200_tuner_config = {
  192. .gate = TDA18271_GATE_ANALOG,
  193. };
  194. static struct dibx000_agc_config xc3028_agc_config = {
  195. BAND_VHF | BAND_UHF, /* band_caps */
  196. /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=0,
  197. * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
  198. * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0,
  199. * P_agc_nb_est=2, P_agc_write=0
  200. */
  201. (0 << 15) | (0 << 14) | (0 << 11) | (0 << 10) | (0 << 9) | (0 << 8) |
  202. (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), /* setup */
  203. 712, /* inv_gain */
  204. 21, /* time_stabiliz */
  205. 0, /* alpha_level */
  206. 118, /* thlock */
  207. 0, /* wbd_inv */
  208. 2867, /* wbd_ref */
  209. 0, /* wbd_sel */
  210. 2, /* wbd_alpha */
  211. 0, /* agc1_max */
  212. 0, /* agc1_min */
  213. 39718, /* agc2_max */
  214. 9930, /* agc2_min */
  215. 0, /* agc1_pt1 */
  216. 0, /* agc1_pt2 */
  217. 0, /* agc1_pt3 */
  218. 0, /* agc1_slope1 */
  219. 0, /* agc1_slope2 */
  220. 0, /* agc2_pt1 */
  221. 128, /* agc2_pt2 */
  222. 29, /* agc2_slope1 */
  223. 29, /* agc2_slope2 */
  224. 17, /* alpha_mant */
  225. 27, /* alpha_exp */
  226. 23, /* beta_mant */
  227. 51, /* beta_exp */
  228. 1, /* perform_agc_softsplit */
  229. };
  230. /* PLL Configuration for COFDM BW_MHz = 8.000000
  231. * With external clock = 30.000000 */
  232. static struct dibx000_bandwidth_config xc3028_bw_config = {
  233. 60000, /* internal */
  234. 30000, /* sampling */
  235. 1, /* pll_cfg: prediv */
  236. 8, /* pll_cfg: ratio */
  237. 3, /* pll_cfg: range */
  238. 1, /* pll_cfg: reset */
  239. 0, /* pll_cfg: bypass */
  240. 0, /* misc: refdiv */
  241. 0, /* misc: bypclk_div */
  242. 1, /* misc: IO_CLK_en_core */
  243. 1, /* misc: ADClkSrc */
  244. 0, /* misc: modulo */
  245. (3 << 14) | (1 << 12) | (524 << 0), /* sad_cfg: refsel, sel, freq_15k */
  246. (1 << 25) | 5816102, /* ifreq = 5.200000 MHz */
  247. 20452225, /* timf */
  248. 30000000 /* xtal_hz */
  249. };
  250. static struct dib7000p_config hauppauge_hvr1400_dib7000_config = {
  251. .output_mpeg2_in_188_bytes = 1,
  252. .hostbus_diversity = 1,
  253. .tuner_is_baseband = 0,
  254. .update_lna = NULL,
  255. .agc_config_count = 1,
  256. .agc = &xc3028_agc_config,
  257. .bw = &xc3028_bw_config,
  258. .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
  259. .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
  260. .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
  261. .pwm_freq_div = 0,
  262. .agc_control = NULL,
  263. .spur_protect = 0,
  264. .output_mode = OUTMODE_MPEG2_SERIAL,
  265. };
  266. static struct zl10353_config dvico_fusionhdtv_xc3028 = {
  267. .demod_address = 0x0f,
  268. .if2 = 45600,
  269. .no_tuner = 1,
  270. };
  271. static struct stv0900_config netup_stv0900_config = {
  272. .demod_address = 0x68,
  273. .xtal = 27000000,
  274. .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
  275. .diseqc_mode = 2,/* 2/3 PWM */
  276. .path1_mode = 2,/*Serial continues clock */
  277. .path2_mode = 2,/*Serial continues clock */
  278. .tun1_maddress = 0,/* 0x60 */
  279. .tun2_maddress = 3,/* 0x63 */
  280. .tun1_adc = 1,/* 1 Vpp */
  281. .tun2_adc = 1,/* 1 Vpp */
  282. };
  283. static struct stv6110_config netup_stv6110_tunerconfig_a = {
  284. .i2c_address = 0x60,
  285. .mclk = 27000000,
  286. .iq_wiring = 0,
  287. };
  288. static struct stv6110_config netup_stv6110_tunerconfig_b = {
  289. .i2c_address = 0x63,
  290. .mclk = 27000000,
  291. .iq_wiring = 1,
  292. };
  293. static int tbs_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
  294. {
  295. struct cx23885_tsport *port = fe->dvb->priv;
  296. struct cx23885_dev *dev = port->dev;
  297. if (voltage == SEC_VOLTAGE_18)
  298. cx_write(MC417_RWD, 0x00001e00);/* GPIO-13 high */
  299. else if (voltage == SEC_VOLTAGE_13)
  300. cx_write(MC417_RWD, 0x00001a00);/* GPIO-13 low */
  301. else
  302. cx_write(MC417_RWD, 0x00001800);/* GPIO-12 low */
  303. return 0;
  304. }
  305. static struct cx24116_config tbs_cx24116_config = {
  306. .demod_address = 0x05,
  307. };
  308. static struct cx24116_config tevii_cx24116_config = {
  309. .demod_address = 0x55,
  310. };
  311. static struct cx24116_config dvbworld_cx24116_config = {
  312. .demod_address = 0x05,
  313. };
  314. static int dvb_register(struct cx23885_tsport *port)
  315. {
  316. struct cx23885_dev *dev = port->dev;
  317. struct cx23885_i2c *i2c_bus = NULL;
  318. struct videobuf_dvb_frontend *fe0;
  319. int ret;
  320. /* Get the first frontend */
  321. fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);
  322. if (!fe0)
  323. return -EINVAL;
  324. /* init struct videobuf_dvb */
  325. fe0->dvb.name = dev->name;
  326. /* init frontend */
  327. switch (dev->board) {
  328. case CX23885_BOARD_HAUPPAUGE_HVR1250:
  329. i2c_bus = &dev->i2c_bus[0];
  330. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  331. &hauppauge_generic_config,
  332. &i2c_bus->i2c_adap);
  333. if (fe0->dvb.frontend != NULL) {
  334. dvb_attach(mt2131_attach, fe0->dvb.frontend,
  335. &i2c_bus->i2c_adap,
  336. &hauppauge_generic_tunerconfig, 0);
  337. }
  338. break;
  339. case CX23885_BOARD_HAUPPAUGE_HVR1800:
  340. i2c_bus = &dev->i2c_bus[0];
  341. switch (alt_tuner) {
  342. case 1:
  343. fe0->dvb.frontend =
  344. dvb_attach(s5h1409_attach,
  345. &hauppauge_ezqam_config,
  346. &i2c_bus->i2c_adap);
  347. if (fe0->dvb.frontend != NULL) {
  348. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  349. &dev->i2c_bus[1].i2c_adap, 0x42,
  350. &tda829x_no_probe);
  351. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  352. 0x60, &dev->i2c_bus[1].i2c_adap,
  353. &hauppauge_tda18271_config);
  354. }
  355. break;
  356. case 0:
  357. default:
  358. fe0->dvb.frontend =
  359. dvb_attach(s5h1409_attach,
  360. &hauppauge_generic_config,
  361. &i2c_bus->i2c_adap);
  362. if (fe0->dvb.frontend != NULL)
  363. dvb_attach(mt2131_attach, fe0->dvb.frontend,
  364. &i2c_bus->i2c_adap,
  365. &hauppauge_generic_tunerconfig, 0);
  366. break;
  367. }
  368. break;
  369. case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
  370. i2c_bus = &dev->i2c_bus[0];
  371. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  372. &hauppauge_hvr1800lp_config,
  373. &i2c_bus->i2c_adap);
  374. if (fe0->dvb.frontend != NULL) {
  375. dvb_attach(mt2131_attach, fe0->dvb.frontend,
  376. &i2c_bus->i2c_adap,
  377. &hauppauge_generic_tunerconfig, 0);
  378. }
  379. break;
  380. case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
  381. i2c_bus = &dev->i2c_bus[0];
  382. fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
  383. &fusionhdtv_5_express,
  384. &i2c_bus->i2c_adap);
  385. if (fe0->dvb.frontend != NULL) {
  386. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  387. &i2c_bus->i2c_adap, 0x61,
  388. TUNER_LG_TDVS_H06XF);
  389. }
  390. break;
  391. case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
  392. i2c_bus = &dev->i2c_bus[1];
  393. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  394. &hauppauge_hvr1500q_config,
  395. &dev->i2c_bus[0].i2c_adap);
  396. if (fe0->dvb.frontend != NULL)
  397. dvb_attach(xc5000_attach, fe0->dvb.frontend,
  398. &i2c_bus->i2c_adap,
  399. &hauppauge_hvr1500q_tunerconfig);
  400. break;
  401. case CX23885_BOARD_HAUPPAUGE_HVR1500:
  402. i2c_bus = &dev->i2c_bus[1];
  403. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  404. &hauppauge_hvr1500_config,
  405. &dev->i2c_bus[0].i2c_adap);
  406. if (fe0->dvb.frontend != NULL) {
  407. struct dvb_frontend *fe;
  408. struct xc2028_config cfg = {
  409. .i2c_adap = &i2c_bus->i2c_adap,
  410. .i2c_addr = 0x61,
  411. };
  412. static struct xc2028_ctrl ctl = {
  413. .fname = XC2028_DEFAULT_FIRMWARE,
  414. .max_len = 64,
  415. .scode_table = XC3028_FE_OREN538,
  416. };
  417. fe = dvb_attach(xc2028_attach,
  418. fe0->dvb.frontend, &cfg);
  419. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  420. fe->ops.tuner_ops.set_config(fe, &ctl);
  421. }
  422. break;
  423. case CX23885_BOARD_HAUPPAUGE_HVR1200:
  424. case CX23885_BOARD_HAUPPAUGE_HVR1700:
  425. i2c_bus = &dev->i2c_bus[0];
  426. fe0->dvb.frontend = dvb_attach(tda10048_attach,
  427. &hauppauge_hvr1200_config,
  428. &i2c_bus->i2c_adap);
  429. if (fe0->dvb.frontend != NULL) {
  430. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  431. &dev->i2c_bus[1].i2c_adap, 0x42,
  432. &tda829x_no_probe);
  433. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  434. 0x60, &dev->i2c_bus[1].i2c_adap,
  435. &hauppauge_hvr1200_tuner_config);
  436. }
  437. break;
  438. case CX23885_BOARD_HAUPPAUGE_HVR1400:
  439. i2c_bus = &dev->i2c_bus[0];
  440. fe0->dvb.frontend = dvb_attach(dib7000p_attach,
  441. &i2c_bus->i2c_adap,
  442. 0x12, &hauppauge_hvr1400_dib7000_config);
  443. if (fe0->dvb.frontend != NULL) {
  444. struct dvb_frontend *fe;
  445. struct xc2028_config cfg = {
  446. .i2c_adap = &dev->i2c_bus[1].i2c_adap,
  447. .i2c_addr = 0x64,
  448. };
  449. static struct xc2028_ctrl ctl = {
  450. .fname = XC3028L_DEFAULT_FIRMWARE,
  451. .max_len = 64,
  452. .demod = 5000,
  453. /* This is true for all demods with
  454. v36 firmware? */
  455. .type = XC2028_D2633,
  456. };
  457. fe = dvb_attach(xc2028_attach,
  458. fe0->dvb.frontend, &cfg);
  459. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  460. fe->ops.tuner_ops.set_config(fe, &ctl);
  461. }
  462. break;
  463. case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:
  464. i2c_bus = &dev->i2c_bus[port->nr - 1];
  465. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  466. &dvico_s5h1409_config,
  467. &i2c_bus->i2c_adap);
  468. if (fe0->dvb.frontend == NULL)
  469. fe0->dvb.frontend = dvb_attach(s5h1411_attach,
  470. &dvico_s5h1411_config,
  471. &i2c_bus->i2c_adap);
  472. if (fe0->dvb.frontend != NULL)
  473. dvb_attach(xc5000_attach, fe0->dvb.frontend,
  474. &i2c_bus->i2c_adap,
  475. &dvico_xc5000_tunerconfig);
  476. break;
  477. case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP: {
  478. i2c_bus = &dev->i2c_bus[port->nr - 1];
  479. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  480. &dvico_fusionhdtv_xc3028,
  481. &i2c_bus->i2c_adap);
  482. if (fe0->dvb.frontend != NULL) {
  483. struct dvb_frontend *fe;
  484. struct xc2028_config cfg = {
  485. .i2c_adap = &i2c_bus->i2c_adap,
  486. .i2c_addr = 0x61,
  487. };
  488. static struct xc2028_ctrl ctl = {
  489. .fname = XC2028_DEFAULT_FIRMWARE,
  490. .max_len = 64,
  491. .demod = XC3028_FE_ZARLINK456,
  492. };
  493. fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
  494. &cfg);
  495. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  496. fe->ops.tuner_ops.set_config(fe, &ctl);
  497. }
  498. break;
  499. }
  500. case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
  501. case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
  502. i2c_bus = &dev->i2c_bus[0];
  503. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  504. &dvico_fusionhdtv_xc3028,
  505. &i2c_bus->i2c_adap);
  506. if (fe0->dvb.frontend != NULL) {
  507. struct dvb_frontend *fe;
  508. struct xc2028_config cfg = {
  509. .i2c_adap = &dev->i2c_bus[1].i2c_adap,
  510. .i2c_addr = 0x61,
  511. };
  512. static struct xc2028_ctrl ctl = {
  513. .fname = XC2028_DEFAULT_FIRMWARE,
  514. .max_len = 64,
  515. .demod = XC3028_FE_ZARLINK456,
  516. };
  517. fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
  518. &cfg);
  519. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  520. fe->ops.tuner_ops.set_config(fe, &ctl);
  521. }
  522. break;
  523. case CX23885_BOARD_TBS_6920:
  524. i2c_bus = &dev->i2c_bus[0];
  525. fe0->dvb.frontend = dvb_attach(cx24116_attach,
  526. &tbs_cx24116_config,
  527. &i2c_bus->i2c_adap);
  528. if (fe0->dvb.frontend != NULL)
  529. fe0->dvb.frontend->ops.set_voltage = tbs_set_voltage;
  530. break;
  531. case CX23885_BOARD_TEVII_S470:
  532. i2c_bus = &dev->i2c_bus[1];
  533. fe0->dvb.frontend = dvb_attach(cx24116_attach,
  534. &tevii_cx24116_config,
  535. &i2c_bus->i2c_adap);
  536. if (fe0->dvb.frontend != NULL)
  537. fe0->dvb.frontend->ops.set_voltage = tbs_set_voltage;
  538. break;
  539. case CX23885_BOARD_DVBWORLD_2005:
  540. i2c_bus = &dev->i2c_bus[1];
  541. fe0->dvb.frontend = dvb_attach(cx24116_attach,
  542. &dvbworld_cx24116_config,
  543. &i2c_bus->i2c_adap);
  544. break;
  545. case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
  546. i2c_bus = &dev->i2c_bus[0];
  547. switch (port->nr) {
  548. /* port B */
  549. case 1:
  550. fe0->dvb.frontend = dvb_attach(stv0900_attach,
  551. &netup_stv0900_config,
  552. &i2c_bus->i2c_adap, 0);
  553. if (fe0->dvb.frontend != NULL) {
  554. if (dvb_attach(stv6110_attach,
  555. fe0->dvb.frontend,
  556. &netup_stv6110_tunerconfig_a,
  557. &i2c_bus->i2c_adap)) {
  558. if (!dvb_attach(lnbh24_attach,
  559. fe0->dvb.frontend,
  560. &i2c_bus->i2c_adap,
  561. LNBH24_PCL, 0, 0x09))
  562. printk(KERN_ERR
  563. "No LNBH24 found!\n");
  564. }
  565. }
  566. break;
  567. /* port C */
  568. case 2:
  569. fe0->dvb.frontend = dvb_attach(stv0900_attach,
  570. &netup_stv0900_config,
  571. &i2c_bus->i2c_adap, 1);
  572. if (fe0->dvb.frontend != NULL) {
  573. if (dvb_attach(stv6110_attach,
  574. fe0->dvb.frontend,
  575. &netup_stv6110_tunerconfig_b,
  576. &i2c_bus->i2c_adap)) {
  577. if (!dvb_attach(lnbh24_attach,
  578. fe0->dvb.frontend,
  579. &i2c_bus->i2c_adap,
  580. LNBH24_PCL, 0, 0x0a))
  581. printk(KERN_ERR
  582. "No LNBH24 found!\n");
  583. }
  584. }
  585. break;
  586. }
  587. break;
  588. default:
  589. printk(KERN_INFO "%s: The frontend of your DVB/ATSC card "
  590. " isn't supported yet\n",
  591. dev->name);
  592. break;
  593. }
  594. if (NULL == fe0->dvb.frontend) {
  595. printk(KERN_ERR "%s: frontend initialization failed\n",
  596. dev->name);
  597. return -1;
  598. }
  599. /* define general-purpose callback pointer */
  600. fe0->dvb.frontend->callback = cx23885_tuner_callback;
  601. /* Put the analog decoder in standby to keep it quiet */
  602. call_all(dev, core, s_standby, 0);
  603. if (fe0->dvb.frontend->ops.analog_ops.standby)
  604. fe0->dvb.frontend->ops.analog_ops.standby(fe0->dvb.frontend);
  605. /* register everything */
  606. ret = videobuf_dvb_register_bus(&port->frontends, THIS_MODULE, port,
  607. &dev->pci->dev, adapter_nr, 0);
  608. /* init CI & MAC */
  609. switch (dev->board) {
  610. case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: {
  611. static struct netup_card_info cinfo;
  612. netup_get_card_info(&dev->i2c_bus[0].i2c_adap, &cinfo);
  613. memcpy(port->frontends.adapter.proposed_mac,
  614. cinfo.port[port->nr - 1].mac, 6);
  615. printk(KERN_INFO "NetUP Dual DVB-S2 CI card port%d MAC="
  616. "%02X:%02X:%02X:%02X:%02X:%02X\n",
  617. port->nr,
  618. port->frontends.adapter.proposed_mac[0],
  619. port->frontends.adapter.proposed_mac[1],
  620. port->frontends.adapter.proposed_mac[2],
  621. port->frontends.adapter.proposed_mac[3],
  622. port->frontends.adapter.proposed_mac[4],
  623. port->frontends.adapter.proposed_mac[5]);
  624. netup_ci_init(port);
  625. break;
  626. }
  627. }
  628. return ret;
  629. }
  630. int cx23885_dvb_register(struct cx23885_tsport *port)
  631. {
  632. struct videobuf_dvb_frontend *fe0;
  633. struct cx23885_dev *dev = port->dev;
  634. int err, i;
  635. /* Here we need to allocate the correct number of frontends,
  636. * as reflected in the cards struct. The reality is that currrently
  637. * no cx23885 boards support this - yet. But, if we don't modify this
  638. * code then the second frontend would never be allocated (later)
  639. * and fail with error before the attach in dvb_register().
  640. * Without these changes we risk an OOPS later. The changes here
  641. * are for safety, and should provide a good foundation for the
  642. * future addition of any multi-frontend cx23885 based boards.
  643. */
  644. printk(KERN_INFO "%s() allocating %d frontend(s)\n", __func__,
  645. port->num_frontends);
  646. for (i = 1; i <= port->num_frontends; i++) {
  647. if (videobuf_dvb_alloc_frontend(
  648. &port->frontends, i) == NULL) {
  649. printk(KERN_ERR "%s() failed to alloc\n", __func__);
  650. return -ENOMEM;
  651. }
  652. fe0 = videobuf_dvb_get_frontend(&port->frontends, i);
  653. if (!fe0)
  654. err = -EINVAL;
  655. dprintk(1, "%s\n", __func__);
  656. dprintk(1, " ->probed by Card=%d Name=%s, PCI %02x:%02x\n",
  657. dev->board,
  658. dev->name,
  659. dev->pci_bus,
  660. dev->pci_slot);
  661. err = -ENODEV;
  662. /* dvb stuff */
  663. /* We have to init the queue for each frontend on a port. */
  664. printk(KERN_INFO "%s: cx23885 based dvb card\n", dev->name);
  665. videobuf_queue_sg_init(&fe0->dvb.dvbq, &dvb_qops,
  666. &dev->pci->dev, &port->slock,
  667. V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
  668. sizeof(struct cx23885_buffer), port);
  669. }
  670. err = dvb_register(port);
  671. if (err != 0)
  672. printk(KERN_ERR "%s() dvb_register failed err = %d\n",
  673. __func__, err);
  674. return err;
  675. }
  676. int cx23885_dvb_unregister(struct cx23885_tsport *port)
  677. {
  678. struct videobuf_dvb_frontend *fe0;
  679. /* FIXME: in an error condition where the we have
  680. * an expected number of frontends (attach problem)
  681. * then this might not clean up correctly, if 1
  682. * is invalid.
  683. * This comment only applies to future boards IF they
  684. * implement MFE support.
  685. */
  686. fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);
  687. if (fe0->dvb.frontend)
  688. videobuf_dvb_unregister_bus(&port->frontends);
  689. switch (port->dev->board) {
  690. case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
  691. netup_ci_exit(port);
  692. break;
  693. }
  694. return 0;
  695. }