cx23885-dvb.c 25 KB

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