cx23885-dvb.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  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. .xtal = 8000000,
  348. .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
  349. .diseqc_mode = 2,/* 2/3 PWM */
  350. .ts_config_regs = stv0900_ts_regs,
  351. .tun1_maddress = 0,/* 0x60 */
  352. .tun2_maddress = 3,/* 0x63 */
  353. .tun1_adc = 1,/* 1 Vpp */
  354. .tun2_adc = 1,/* 1 Vpp */
  355. };
  356. static struct stv6110_config netup_stv6110_tunerconfig_a = {
  357. .i2c_address = 0x60,
  358. .mclk = 16000000,
  359. .clk_div = 1,
  360. };
  361. static struct stv6110_config netup_stv6110_tunerconfig_b = {
  362. .i2c_address = 0x63,
  363. .mclk = 16000000,
  364. .clk_div = 1,
  365. };
  366. static int tbs_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
  367. {
  368. struct cx23885_tsport *port = fe->dvb->priv;
  369. struct cx23885_dev *dev = port->dev;
  370. if (voltage == SEC_VOLTAGE_18)
  371. cx_write(MC417_RWD, 0x00001e00);/* GPIO-13 high */
  372. else if (voltage == SEC_VOLTAGE_13)
  373. cx_write(MC417_RWD, 0x00001a00);/* GPIO-13 low */
  374. else
  375. cx_write(MC417_RWD, 0x00001800);/* GPIO-12 low */
  376. return 0;
  377. }
  378. static struct cx24116_config tbs_cx24116_config = {
  379. .demod_address = 0x05,
  380. };
  381. static struct cx24116_config tevii_cx24116_config = {
  382. .demod_address = 0x55,
  383. };
  384. static struct cx24116_config dvbworld_cx24116_config = {
  385. .demod_address = 0x05,
  386. };
  387. static struct lgs8gxx_config mygica_x8506_lgs8gl5_config = {
  388. .prod = LGS8GXX_PROD_LGS8GL5,
  389. .demod_address = 0x19,
  390. .serial_ts = 0,
  391. .ts_clk_pol = 1,
  392. .ts_clk_gated = 1,
  393. .if_clk_freq = 30400, /* 30.4 MHz */
  394. .if_freq = 5380, /* 5.38 MHz */
  395. .if_neg_center = 1,
  396. .ext_adc = 0,
  397. .adc_signed = 0,
  398. .if_neg_edge = 0,
  399. };
  400. static struct xc5000_config mygica_x8506_xc5000_config = {
  401. .i2c_address = 0x61,
  402. .if_khz = 5380,
  403. };
  404. static int cx23885_dvb_set_frontend(struct dvb_frontend *fe,
  405. struct dvb_frontend_parameters *param)
  406. {
  407. struct cx23885_tsport *port = fe->dvb->priv;
  408. struct cx23885_dev *dev = port->dev;
  409. switch (dev->board) {
  410. case CX23885_BOARD_HAUPPAUGE_HVR1275:
  411. switch (param->u.vsb.modulation) {
  412. case VSB_8:
  413. cx23885_gpio_clear(dev, GPIO_5);
  414. break;
  415. case QAM_64:
  416. case QAM_256:
  417. default:
  418. cx23885_gpio_set(dev, GPIO_5);
  419. break;
  420. }
  421. break;
  422. case CX23885_BOARD_MYGICA_X8506:
  423. case CX23885_BOARD_MAGICPRO_PROHDTVE2:
  424. /* Select Digital TV */
  425. cx23885_gpio_set(dev, GPIO_0);
  426. break;
  427. }
  428. return 0;
  429. }
  430. static int cx23885_dvb_fe_ioctl_override(struct dvb_frontend *fe,
  431. unsigned int cmd, void *parg,
  432. unsigned int stage)
  433. {
  434. int err = 0;
  435. switch (stage) {
  436. case DVB_FE_IOCTL_PRE:
  437. switch (cmd) {
  438. case FE_SET_FRONTEND:
  439. err = cx23885_dvb_set_frontend(fe,
  440. (struct dvb_frontend_parameters *) parg);
  441. break;
  442. }
  443. break;
  444. case DVB_FE_IOCTL_POST:
  445. /* no post-ioctl handling required */
  446. break;
  447. }
  448. return err;
  449. };
  450. static struct lgs8gxx_config magicpro_prohdtve2_lgs8g75_config = {
  451. .prod = LGS8GXX_PROD_LGS8G75,
  452. .demod_address = 0x19,
  453. .serial_ts = 0,
  454. .ts_clk_pol = 1,
  455. .ts_clk_gated = 1,
  456. .if_clk_freq = 30400, /* 30.4 MHz */
  457. .if_freq = 6500, /* 6.50 MHz */
  458. .if_neg_center = 1,
  459. .ext_adc = 0,
  460. .adc_signed = 1,
  461. .adc_vpp = 2, /* 1.6 Vpp */
  462. .if_neg_edge = 1,
  463. };
  464. static struct xc5000_config magicpro_prohdtve2_xc5000_config = {
  465. .i2c_address = 0x61,
  466. .if_khz = 6500,
  467. };
  468. static int dvb_register(struct cx23885_tsport *port)
  469. {
  470. struct cx23885_dev *dev = port->dev;
  471. struct cx23885_i2c *i2c_bus = NULL, *i2c_bus2 = NULL;
  472. struct videobuf_dvb_frontend *fe0;
  473. int ret;
  474. /* Get the first frontend */
  475. fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);
  476. if (!fe0)
  477. return -EINVAL;
  478. /* init struct videobuf_dvb */
  479. fe0->dvb.name = dev->name;
  480. /* init frontend */
  481. switch (dev->board) {
  482. case CX23885_BOARD_HAUPPAUGE_HVR1250:
  483. i2c_bus = &dev->i2c_bus[0];
  484. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  485. &hauppauge_generic_config,
  486. &i2c_bus->i2c_adap);
  487. if (fe0->dvb.frontend != NULL) {
  488. dvb_attach(mt2131_attach, fe0->dvb.frontend,
  489. &i2c_bus->i2c_adap,
  490. &hauppauge_generic_tunerconfig, 0);
  491. }
  492. break;
  493. case CX23885_BOARD_HAUPPAUGE_HVR1270:
  494. case CX23885_BOARD_HAUPPAUGE_HVR1275:
  495. i2c_bus = &dev->i2c_bus[0];
  496. fe0->dvb.frontend = dvb_attach(lgdt3305_attach,
  497. &hauppauge_lgdt3305_config,
  498. &i2c_bus->i2c_adap);
  499. if (fe0->dvb.frontend != NULL) {
  500. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  501. 0x60, &dev->i2c_bus[1].i2c_adap,
  502. &hauppauge_hvr127x_config);
  503. }
  504. break;
  505. case CX23885_BOARD_HAUPPAUGE_HVR1255:
  506. i2c_bus = &dev->i2c_bus[0];
  507. fe0->dvb.frontend = dvb_attach(s5h1411_attach,
  508. &hcw_s5h1411_config,
  509. &i2c_bus->i2c_adap);
  510. if (fe0->dvb.frontend != NULL) {
  511. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  512. 0x60, &dev->i2c_bus[1].i2c_adap,
  513. &hauppauge_tda18271_config);
  514. }
  515. break;
  516. case CX23885_BOARD_HAUPPAUGE_HVR1800:
  517. i2c_bus = &dev->i2c_bus[0];
  518. switch (alt_tuner) {
  519. case 1:
  520. fe0->dvb.frontend =
  521. dvb_attach(s5h1409_attach,
  522. &hauppauge_ezqam_config,
  523. &i2c_bus->i2c_adap);
  524. if (fe0->dvb.frontend != NULL) {
  525. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  526. &dev->i2c_bus[1].i2c_adap, 0x42,
  527. &tda829x_no_probe);
  528. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  529. 0x60, &dev->i2c_bus[1].i2c_adap,
  530. &hauppauge_tda18271_config);
  531. }
  532. break;
  533. case 0:
  534. default:
  535. fe0->dvb.frontend =
  536. dvb_attach(s5h1409_attach,
  537. &hauppauge_generic_config,
  538. &i2c_bus->i2c_adap);
  539. if (fe0->dvb.frontend != NULL)
  540. dvb_attach(mt2131_attach, fe0->dvb.frontend,
  541. &i2c_bus->i2c_adap,
  542. &hauppauge_generic_tunerconfig, 0);
  543. break;
  544. }
  545. break;
  546. case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
  547. i2c_bus = &dev->i2c_bus[0];
  548. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  549. &hauppauge_hvr1800lp_config,
  550. &i2c_bus->i2c_adap);
  551. if (fe0->dvb.frontend != NULL) {
  552. dvb_attach(mt2131_attach, fe0->dvb.frontend,
  553. &i2c_bus->i2c_adap,
  554. &hauppauge_generic_tunerconfig, 0);
  555. }
  556. break;
  557. case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
  558. i2c_bus = &dev->i2c_bus[0];
  559. fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
  560. &fusionhdtv_5_express,
  561. &i2c_bus->i2c_adap);
  562. if (fe0->dvb.frontend != NULL) {
  563. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  564. &i2c_bus->i2c_adap, 0x61,
  565. TUNER_LG_TDVS_H06XF);
  566. }
  567. break;
  568. case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
  569. i2c_bus = &dev->i2c_bus[1];
  570. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  571. &hauppauge_hvr1500q_config,
  572. &dev->i2c_bus[0].i2c_adap);
  573. if (fe0->dvb.frontend != NULL)
  574. dvb_attach(xc5000_attach, fe0->dvb.frontend,
  575. &i2c_bus->i2c_adap,
  576. &hauppauge_hvr1500q_tunerconfig);
  577. break;
  578. case CX23885_BOARD_HAUPPAUGE_HVR1500:
  579. i2c_bus = &dev->i2c_bus[1];
  580. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  581. &hauppauge_hvr1500_config,
  582. &dev->i2c_bus[0].i2c_adap);
  583. if (fe0->dvb.frontend != NULL) {
  584. struct dvb_frontend *fe;
  585. struct xc2028_config cfg = {
  586. .i2c_adap = &i2c_bus->i2c_adap,
  587. .i2c_addr = 0x61,
  588. };
  589. static struct xc2028_ctrl ctl = {
  590. .fname = XC2028_DEFAULT_FIRMWARE,
  591. .max_len = 64,
  592. .demod = XC3028_FE_OREN538,
  593. };
  594. fe = dvb_attach(xc2028_attach,
  595. fe0->dvb.frontend, &cfg);
  596. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  597. fe->ops.tuner_ops.set_config(fe, &ctl);
  598. }
  599. break;
  600. case CX23885_BOARD_HAUPPAUGE_HVR1200:
  601. case CX23885_BOARD_HAUPPAUGE_HVR1700:
  602. i2c_bus = &dev->i2c_bus[0];
  603. fe0->dvb.frontend = dvb_attach(tda10048_attach,
  604. &hauppauge_hvr1200_config,
  605. &i2c_bus->i2c_adap);
  606. if (fe0->dvb.frontend != NULL) {
  607. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  608. &dev->i2c_bus[1].i2c_adap, 0x42,
  609. &tda829x_no_probe);
  610. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  611. 0x60, &dev->i2c_bus[1].i2c_adap,
  612. &hauppauge_hvr1200_tuner_config);
  613. }
  614. break;
  615. case CX23885_BOARD_HAUPPAUGE_HVR1210:
  616. i2c_bus = &dev->i2c_bus[0];
  617. fe0->dvb.frontend = dvb_attach(tda10048_attach,
  618. &hauppauge_hvr1210_config,
  619. &i2c_bus->i2c_adap);
  620. if (fe0->dvb.frontend != NULL) {
  621. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  622. 0x60, &dev->i2c_bus[1].i2c_adap,
  623. &hauppauge_hvr1210_tuner_config);
  624. }
  625. break;
  626. case CX23885_BOARD_HAUPPAUGE_HVR1400:
  627. i2c_bus = &dev->i2c_bus[0];
  628. fe0->dvb.frontend = dvb_attach(dib7000p_attach,
  629. &i2c_bus->i2c_adap,
  630. 0x12, &hauppauge_hvr1400_dib7000_config);
  631. if (fe0->dvb.frontend != NULL) {
  632. struct dvb_frontend *fe;
  633. struct xc2028_config cfg = {
  634. .i2c_adap = &dev->i2c_bus[1].i2c_adap,
  635. .i2c_addr = 0x64,
  636. };
  637. static struct xc2028_ctrl ctl = {
  638. .fname = XC3028L_DEFAULT_FIRMWARE,
  639. .max_len = 64,
  640. .demod = 5000,
  641. /* This is true for all demods with
  642. v36 firmware? */
  643. .type = XC2028_D2633,
  644. };
  645. fe = dvb_attach(xc2028_attach,
  646. fe0->dvb.frontend, &cfg);
  647. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  648. fe->ops.tuner_ops.set_config(fe, &ctl);
  649. }
  650. break;
  651. case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:
  652. i2c_bus = &dev->i2c_bus[port->nr - 1];
  653. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  654. &dvico_s5h1409_config,
  655. &i2c_bus->i2c_adap);
  656. if (fe0->dvb.frontend == NULL)
  657. fe0->dvb.frontend = dvb_attach(s5h1411_attach,
  658. &dvico_s5h1411_config,
  659. &i2c_bus->i2c_adap);
  660. if (fe0->dvb.frontend != NULL)
  661. dvb_attach(xc5000_attach, fe0->dvb.frontend,
  662. &i2c_bus->i2c_adap,
  663. &dvico_xc5000_tunerconfig);
  664. break;
  665. case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP: {
  666. i2c_bus = &dev->i2c_bus[port->nr - 1];
  667. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  668. &dvico_fusionhdtv_xc3028,
  669. &i2c_bus->i2c_adap);
  670. if (fe0->dvb.frontend != NULL) {
  671. struct dvb_frontend *fe;
  672. struct xc2028_config cfg = {
  673. .i2c_adap = &i2c_bus->i2c_adap,
  674. .i2c_addr = 0x61,
  675. };
  676. static struct xc2028_ctrl ctl = {
  677. .fname = XC2028_DEFAULT_FIRMWARE,
  678. .max_len = 64,
  679. .demod = XC3028_FE_ZARLINK456,
  680. };
  681. fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
  682. &cfg);
  683. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  684. fe->ops.tuner_ops.set_config(fe, &ctl);
  685. }
  686. break;
  687. }
  688. case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
  689. case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
  690. case CX23885_BOARD_COMPRO_VIDEOMATE_E800:
  691. i2c_bus = &dev->i2c_bus[0];
  692. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  693. &dvico_fusionhdtv_xc3028,
  694. &i2c_bus->i2c_adap);
  695. if (fe0->dvb.frontend != NULL) {
  696. struct dvb_frontend *fe;
  697. struct xc2028_config cfg = {
  698. .i2c_adap = &dev->i2c_bus[1].i2c_adap,
  699. .i2c_addr = 0x61,
  700. };
  701. static struct xc2028_ctrl ctl = {
  702. .fname = XC2028_DEFAULT_FIRMWARE,
  703. .max_len = 64,
  704. .demod = XC3028_FE_ZARLINK456,
  705. };
  706. fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
  707. &cfg);
  708. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  709. fe->ops.tuner_ops.set_config(fe, &ctl);
  710. }
  711. break;
  712. case CX23885_BOARD_TBS_6920:
  713. i2c_bus = &dev->i2c_bus[0];
  714. fe0->dvb.frontend = dvb_attach(cx24116_attach,
  715. &tbs_cx24116_config,
  716. &i2c_bus->i2c_adap);
  717. if (fe0->dvb.frontend != NULL)
  718. fe0->dvb.frontend->ops.set_voltage = tbs_set_voltage;
  719. break;
  720. case CX23885_BOARD_TEVII_S470:
  721. i2c_bus = &dev->i2c_bus[1];
  722. fe0->dvb.frontend = dvb_attach(cx24116_attach,
  723. &tevii_cx24116_config,
  724. &i2c_bus->i2c_adap);
  725. if (fe0->dvb.frontend != NULL)
  726. fe0->dvb.frontend->ops.set_voltage = tbs_set_voltage;
  727. break;
  728. case CX23885_BOARD_DVBWORLD_2005:
  729. i2c_bus = &dev->i2c_bus[1];
  730. fe0->dvb.frontend = dvb_attach(cx24116_attach,
  731. &dvbworld_cx24116_config,
  732. &i2c_bus->i2c_adap);
  733. break;
  734. case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
  735. i2c_bus = &dev->i2c_bus[0];
  736. switch (port->nr) {
  737. /* port B */
  738. case 1:
  739. fe0->dvb.frontend = dvb_attach(stv0900_attach,
  740. &netup_stv0900_config,
  741. &i2c_bus->i2c_adap, 0);
  742. if (fe0->dvb.frontend != NULL) {
  743. if (dvb_attach(stv6110_attach,
  744. fe0->dvb.frontend,
  745. &netup_stv6110_tunerconfig_a,
  746. &i2c_bus->i2c_adap)) {
  747. if (!dvb_attach(lnbh24_attach,
  748. fe0->dvb.frontend,
  749. &i2c_bus->i2c_adap,
  750. LNBH24_PCL,
  751. LNBH24_TTX, 0x09))
  752. printk(KERN_ERR
  753. "No LNBH24 found!\n");
  754. }
  755. }
  756. break;
  757. /* port C */
  758. case 2:
  759. fe0->dvb.frontend = dvb_attach(stv0900_attach,
  760. &netup_stv0900_config,
  761. &i2c_bus->i2c_adap, 1);
  762. if (fe0->dvb.frontend != NULL) {
  763. if (dvb_attach(stv6110_attach,
  764. fe0->dvb.frontend,
  765. &netup_stv6110_tunerconfig_b,
  766. &i2c_bus->i2c_adap)) {
  767. if (!dvb_attach(lnbh24_attach,
  768. fe0->dvb.frontend,
  769. &i2c_bus->i2c_adap,
  770. LNBH24_PCL,
  771. LNBH24_TTX, 0x0a))
  772. printk(KERN_ERR
  773. "No LNBH24 found!\n");
  774. }
  775. }
  776. break;
  777. }
  778. break;
  779. case CX23885_BOARD_MYGICA_X8506:
  780. i2c_bus = &dev->i2c_bus[0];
  781. i2c_bus2 = &dev->i2c_bus[1];
  782. fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
  783. &mygica_x8506_lgs8gl5_config,
  784. &i2c_bus->i2c_adap);
  785. if (fe0->dvb.frontend != NULL) {
  786. dvb_attach(xc5000_attach,
  787. fe0->dvb.frontend,
  788. &i2c_bus2->i2c_adap,
  789. &mygica_x8506_xc5000_config);
  790. }
  791. break;
  792. case CX23885_BOARD_MAGICPRO_PROHDTVE2:
  793. i2c_bus = &dev->i2c_bus[0];
  794. i2c_bus2 = &dev->i2c_bus[1];
  795. fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
  796. &magicpro_prohdtve2_lgs8g75_config,
  797. &i2c_bus->i2c_adap);
  798. if (fe0->dvb.frontend != NULL) {
  799. dvb_attach(xc5000_attach,
  800. fe0->dvb.frontend,
  801. &i2c_bus2->i2c_adap,
  802. &magicpro_prohdtve2_xc5000_config);
  803. }
  804. break;
  805. case CX23885_BOARD_HAUPPAUGE_HVR1850:
  806. i2c_bus = &dev->i2c_bus[0];
  807. fe0->dvb.frontend = dvb_attach(s5h1411_attach,
  808. &hcw_s5h1411_config,
  809. &i2c_bus->i2c_adap);
  810. if (fe0->dvb.frontend != NULL)
  811. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  812. 0x60, &dev->i2c_bus[0].i2c_adap,
  813. &hauppauge_tda18271_config);
  814. break;
  815. default:
  816. printk(KERN_INFO "%s: The frontend of your DVB/ATSC card "
  817. " isn't supported yet\n",
  818. dev->name);
  819. break;
  820. }
  821. if (NULL == fe0->dvb.frontend) {
  822. printk(KERN_ERR "%s: frontend initialization failed\n",
  823. dev->name);
  824. return -1;
  825. }
  826. /* define general-purpose callback pointer */
  827. fe0->dvb.frontend->callback = cx23885_tuner_callback;
  828. /* Put the analog decoder in standby to keep it quiet */
  829. call_all(dev, core, s_power, 0);
  830. if (fe0->dvb.frontend->ops.analog_ops.standby)
  831. fe0->dvb.frontend->ops.analog_ops.standby(fe0->dvb.frontend);
  832. /* register everything */
  833. ret = videobuf_dvb_register_bus(&port->frontends, THIS_MODULE, port,
  834. &dev->pci->dev, adapter_nr, 0,
  835. cx23885_dvb_fe_ioctl_override);
  836. /* init CI & MAC */
  837. switch (dev->board) {
  838. case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: {
  839. static struct netup_card_info cinfo;
  840. netup_get_card_info(&dev->i2c_bus[0].i2c_adap, &cinfo);
  841. memcpy(port->frontends.adapter.proposed_mac,
  842. cinfo.port[port->nr - 1].mac, 6);
  843. printk(KERN_INFO "NetUP Dual DVB-S2 CI card port%d MAC="
  844. "%02X:%02X:%02X:%02X:%02X:%02X\n",
  845. port->nr,
  846. port->frontends.adapter.proposed_mac[0],
  847. port->frontends.adapter.proposed_mac[1],
  848. port->frontends.adapter.proposed_mac[2],
  849. port->frontends.adapter.proposed_mac[3],
  850. port->frontends.adapter.proposed_mac[4],
  851. port->frontends.adapter.proposed_mac[5]);
  852. netup_ci_init(port);
  853. break;
  854. }
  855. }
  856. return ret;
  857. }
  858. int cx23885_dvb_register(struct cx23885_tsport *port)
  859. {
  860. struct videobuf_dvb_frontend *fe0;
  861. struct cx23885_dev *dev = port->dev;
  862. int err, i;
  863. /* Here we need to allocate the correct number of frontends,
  864. * as reflected in the cards struct. The reality is that currrently
  865. * no cx23885 boards support this - yet. But, if we don't modify this
  866. * code then the second frontend would never be allocated (later)
  867. * and fail with error before the attach in dvb_register().
  868. * Without these changes we risk an OOPS later. The changes here
  869. * are for safety, and should provide a good foundation for the
  870. * future addition of any multi-frontend cx23885 based boards.
  871. */
  872. printk(KERN_INFO "%s() allocating %d frontend(s)\n", __func__,
  873. port->num_frontends);
  874. for (i = 1; i <= port->num_frontends; i++) {
  875. if (videobuf_dvb_alloc_frontend(
  876. &port->frontends, i) == NULL) {
  877. printk(KERN_ERR "%s() failed to alloc\n", __func__);
  878. return -ENOMEM;
  879. }
  880. fe0 = videobuf_dvb_get_frontend(&port->frontends, i);
  881. if (!fe0)
  882. err = -EINVAL;
  883. dprintk(1, "%s\n", __func__);
  884. dprintk(1, " ->probed by Card=%d Name=%s, PCI %02x:%02x\n",
  885. dev->board,
  886. dev->name,
  887. dev->pci_bus,
  888. dev->pci_slot);
  889. err = -ENODEV;
  890. /* dvb stuff */
  891. /* We have to init the queue for each frontend on a port. */
  892. printk(KERN_INFO "%s: cx23885 based dvb card\n", dev->name);
  893. videobuf_queue_sg_init(&fe0->dvb.dvbq, &dvb_qops,
  894. &dev->pci->dev, &port->slock,
  895. V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
  896. sizeof(struct cx23885_buffer), port);
  897. }
  898. err = dvb_register(port);
  899. if (err != 0)
  900. printk(KERN_ERR "%s() dvb_register failed err = %d\n",
  901. __func__, err);
  902. return err;
  903. }
  904. int cx23885_dvb_unregister(struct cx23885_tsport *port)
  905. {
  906. struct videobuf_dvb_frontend *fe0;
  907. /* FIXME: in an error condition where the we have
  908. * an expected number of frontends (attach problem)
  909. * then this might not clean up correctly, if 1
  910. * is invalid.
  911. * This comment only applies to future boards IF they
  912. * implement MFE support.
  913. */
  914. fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);
  915. if (fe0->dvb.frontend)
  916. videobuf_dvb_unregister_bus(&port->frontends);
  917. switch (port->dev->board) {
  918. case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
  919. netup_ci_exit(port);
  920. break;
  921. }
  922. return 0;
  923. }