cx23885-dvb.c 29 KB

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