cx23885-dvb.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345
  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 "xc4000.h"
  38. #include "xc5000.h"
  39. #include "max2165.h"
  40. #include "tda10048.h"
  41. #include "tuner-xc2028.h"
  42. #include "tuner-simple.h"
  43. #include "dib7000p.h"
  44. #include "dibx000_common.h"
  45. #include "zl10353.h"
  46. #include "stv0900.h"
  47. #include "stv0900_reg.h"
  48. #include "stv6110.h"
  49. #include "lnbh24.h"
  50. #include "cx24116.h"
  51. #include "cimax2.h"
  52. #include "lgs8gxx.h"
  53. #include "netup-eeprom.h"
  54. #include "netup-init.h"
  55. #include "lgdt3305.h"
  56. #include "atbm8830.h"
  57. #include "ds3000.h"
  58. #include "cx23885-f300.h"
  59. #include "altera-ci.h"
  60. #include "stv0367.h"
  61. #include "drxk.h"
  62. #include "mt2063.h"
  63. static unsigned int debug;
  64. #define dprintk(level, fmt, arg...)\
  65. do { if (debug >= level)\
  66. printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
  67. } while (0)
  68. /* ------------------------------------------------------------------ */
  69. static unsigned int alt_tuner;
  70. module_param(alt_tuner, int, 0644);
  71. MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration");
  72. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  73. /* ------------------------------------------------------------------ */
  74. static int dvb_buf_setup(struct videobuf_queue *q,
  75. unsigned int *count, unsigned int *size)
  76. {
  77. struct cx23885_tsport *port = q->priv_data;
  78. port->ts_packet_size = 188 * 4;
  79. port->ts_packet_count = 32;
  80. *size = port->ts_packet_size * port->ts_packet_count;
  81. *count = 32;
  82. return 0;
  83. }
  84. static int dvb_buf_prepare(struct videobuf_queue *q,
  85. struct videobuf_buffer *vb, enum v4l2_field field)
  86. {
  87. struct cx23885_tsport *port = q->priv_data;
  88. return cx23885_buf_prepare(q, port, (struct cx23885_buffer *)vb, field);
  89. }
  90. static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
  91. {
  92. struct cx23885_tsport *port = q->priv_data;
  93. cx23885_buf_queue(port, (struct cx23885_buffer *)vb);
  94. }
  95. static void dvb_buf_release(struct videobuf_queue *q,
  96. struct videobuf_buffer *vb)
  97. {
  98. cx23885_free_buffer(q, (struct cx23885_buffer *)vb);
  99. }
  100. static int cx23885_dvb_set_frontend(struct dvb_frontend *fe);
  101. static void cx23885_dvb_gate_ctrl(struct cx23885_tsport *port, int open)
  102. {
  103. struct videobuf_dvb_frontends *f;
  104. struct videobuf_dvb_frontend *fe;
  105. f = &port->frontends;
  106. if (f->gate <= 1) /* undefined or fe0 */
  107. fe = videobuf_dvb_get_frontend(f, 1);
  108. else
  109. fe = videobuf_dvb_get_frontend(f, f->gate);
  110. if (fe && fe->dvb.frontend && fe->dvb.frontend->ops.i2c_gate_ctrl)
  111. fe->dvb.frontend->ops.i2c_gate_ctrl(fe->dvb.frontend, open);
  112. /*
  113. * FIXME: Improve this path to avoid calling the
  114. * cx23885_dvb_set_frontend() every time it passes here.
  115. */
  116. cx23885_dvb_set_frontend(fe->dvb.frontend);
  117. }
  118. static struct videobuf_queue_ops dvb_qops = {
  119. .buf_setup = dvb_buf_setup,
  120. .buf_prepare = dvb_buf_prepare,
  121. .buf_queue = dvb_buf_queue,
  122. .buf_release = dvb_buf_release,
  123. };
  124. static struct s5h1409_config hauppauge_generic_config = {
  125. .demod_address = 0x32 >> 1,
  126. .output_mode = S5H1409_SERIAL_OUTPUT,
  127. .gpio = S5H1409_GPIO_ON,
  128. .qam_if = 44000,
  129. .inversion = S5H1409_INVERSION_OFF,
  130. .status_mode = S5H1409_DEMODLOCKING,
  131. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  132. };
  133. static struct tda10048_config hauppauge_hvr1200_config = {
  134. .demod_address = 0x10 >> 1,
  135. .output_mode = TDA10048_SERIAL_OUTPUT,
  136. .fwbulkwritelen = TDA10048_BULKWRITE_200,
  137. .inversion = TDA10048_INVERSION_ON,
  138. .dtv6_if_freq_khz = TDA10048_IF_3300,
  139. .dtv7_if_freq_khz = TDA10048_IF_3800,
  140. .dtv8_if_freq_khz = TDA10048_IF_4300,
  141. .clk_freq_khz = TDA10048_CLK_16000,
  142. };
  143. static struct tda10048_config hauppauge_hvr1210_config = {
  144. .demod_address = 0x10 >> 1,
  145. .output_mode = TDA10048_SERIAL_OUTPUT,
  146. .fwbulkwritelen = TDA10048_BULKWRITE_200,
  147. .inversion = TDA10048_INVERSION_ON,
  148. .dtv6_if_freq_khz = TDA10048_IF_3300,
  149. .dtv7_if_freq_khz = TDA10048_IF_3500,
  150. .dtv8_if_freq_khz = TDA10048_IF_4000,
  151. .clk_freq_khz = TDA10048_CLK_16000,
  152. };
  153. static struct s5h1409_config hauppauge_ezqam_config = {
  154. .demod_address = 0x32 >> 1,
  155. .output_mode = S5H1409_SERIAL_OUTPUT,
  156. .gpio = S5H1409_GPIO_OFF,
  157. .qam_if = 4000,
  158. .inversion = S5H1409_INVERSION_ON,
  159. .status_mode = S5H1409_DEMODLOCKING,
  160. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  161. };
  162. static struct s5h1409_config hauppauge_hvr1800lp_config = {
  163. .demod_address = 0x32 >> 1,
  164. .output_mode = S5H1409_SERIAL_OUTPUT,
  165. .gpio = S5H1409_GPIO_OFF,
  166. .qam_if = 44000,
  167. .inversion = S5H1409_INVERSION_OFF,
  168. .status_mode = S5H1409_DEMODLOCKING,
  169. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  170. };
  171. static struct s5h1409_config hauppauge_hvr1500_config = {
  172. .demod_address = 0x32 >> 1,
  173. .output_mode = S5H1409_SERIAL_OUTPUT,
  174. .gpio = S5H1409_GPIO_OFF,
  175. .inversion = S5H1409_INVERSION_OFF,
  176. .status_mode = S5H1409_DEMODLOCKING,
  177. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  178. };
  179. static struct mt2131_config hauppauge_generic_tunerconfig = {
  180. 0x61
  181. };
  182. static struct lgdt330x_config fusionhdtv_5_express = {
  183. .demod_address = 0x0e,
  184. .demod_chip = LGDT3303,
  185. .serial_mpeg = 0x40,
  186. };
  187. static struct s5h1409_config hauppauge_hvr1500q_config = {
  188. .demod_address = 0x32 >> 1,
  189. .output_mode = S5H1409_SERIAL_OUTPUT,
  190. .gpio = S5H1409_GPIO_ON,
  191. .qam_if = 44000,
  192. .inversion = S5H1409_INVERSION_OFF,
  193. .status_mode = S5H1409_DEMODLOCKING,
  194. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  195. };
  196. static struct s5h1409_config dvico_s5h1409_config = {
  197. .demod_address = 0x32 >> 1,
  198. .output_mode = S5H1409_SERIAL_OUTPUT,
  199. .gpio = S5H1409_GPIO_ON,
  200. .qam_if = 44000,
  201. .inversion = S5H1409_INVERSION_OFF,
  202. .status_mode = S5H1409_DEMODLOCKING,
  203. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  204. };
  205. static struct s5h1411_config dvico_s5h1411_config = {
  206. .output_mode = S5H1411_SERIAL_OUTPUT,
  207. .gpio = S5H1411_GPIO_ON,
  208. .qam_if = S5H1411_IF_44000,
  209. .vsb_if = S5H1411_IF_44000,
  210. .inversion = S5H1411_INVERSION_OFF,
  211. .status_mode = S5H1411_DEMODLOCKING,
  212. .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  213. };
  214. static struct s5h1411_config hcw_s5h1411_config = {
  215. .output_mode = S5H1411_SERIAL_OUTPUT,
  216. .gpio = S5H1411_GPIO_OFF,
  217. .vsb_if = S5H1411_IF_44000,
  218. .qam_if = S5H1411_IF_4000,
  219. .inversion = S5H1411_INVERSION_ON,
  220. .status_mode = S5H1411_DEMODLOCKING,
  221. .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  222. };
  223. static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
  224. .i2c_address = 0x61,
  225. .if_khz = 5380,
  226. };
  227. static struct xc5000_config dvico_xc5000_tunerconfig = {
  228. .i2c_address = 0x64,
  229. .if_khz = 5380,
  230. };
  231. static struct tda829x_config tda829x_no_probe = {
  232. .probe_tuner = TDA829X_DONT_PROBE,
  233. };
  234. static struct tda18271_std_map hauppauge_tda18271_std_map = {
  235. .atsc_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3,
  236. .if_lvl = 6, .rfagc_top = 0x37 },
  237. .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,
  238. .if_lvl = 6, .rfagc_top = 0x37 },
  239. };
  240. static struct tda18271_std_map hauppauge_hvr1200_tda18271_std_map = {
  241. .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4,
  242. .if_lvl = 1, .rfagc_top = 0x37, },
  243. .dvbt_7 = { .if_freq = 3800, .agc_mode = 3, .std = 5,
  244. .if_lvl = 1, .rfagc_top = 0x37, },
  245. .dvbt_8 = { .if_freq = 4300, .agc_mode = 3, .std = 6,
  246. .if_lvl = 1, .rfagc_top = 0x37, },
  247. };
  248. static struct tda18271_config hauppauge_tda18271_config = {
  249. .std_map = &hauppauge_tda18271_std_map,
  250. .gate = TDA18271_GATE_ANALOG,
  251. .output_opt = TDA18271_OUTPUT_LT_OFF,
  252. };
  253. static struct tda18271_config hauppauge_hvr1200_tuner_config = {
  254. .std_map = &hauppauge_hvr1200_tda18271_std_map,
  255. .gate = TDA18271_GATE_ANALOG,
  256. .output_opt = TDA18271_OUTPUT_LT_OFF,
  257. };
  258. static struct tda18271_config hauppauge_hvr1210_tuner_config = {
  259. .gate = TDA18271_GATE_DIGITAL,
  260. .output_opt = TDA18271_OUTPUT_LT_OFF,
  261. };
  262. static struct tda18271_std_map hauppauge_hvr127x_std_map = {
  263. .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4,
  264. .if_lvl = 1, .rfagc_top = 0x58 },
  265. .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5,
  266. .if_lvl = 1, .rfagc_top = 0x58 },
  267. };
  268. static struct tda18271_config hauppauge_hvr127x_config = {
  269. .std_map = &hauppauge_hvr127x_std_map,
  270. .output_opt = TDA18271_OUTPUT_LT_OFF,
  271. };
  272. static struct lgdt3305_config hauppauge_lgdt3305_config = {
  273. .i2c_addr = 0x0e,
  274. .mpeg_mode = LGDT3305_MPEG_SERIAL,
  275. .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
  276. .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
  277. .deny_i2c_rptr = 1,
  278. .spectral_inversion = 1,
  279. .qam_if_khz = 4000,
  280. .vsb_if_khz = 3250,
  281. };
  282. static struct dibx000_agc_config xc3028_agc_config = {
  283. BAND_VHF | BAND_UHF, /* band_caps */
  284. /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=0,
  285. * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
  286. * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0,
  287. * P_agc_nb_est=2, P_agc_write=0
  288. */
  289. (0 << 15) | (0 << 14) | (0 << 11) | (0 << 10) | (0 << 9) | (0 << 8) |
  290. (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), /* setup */
  291. 712, /* inv_gain */
  292. 21, /* time_stabiliz */
  293. 0, /* alpha_level */
  294. 118, /* thlock */
  295. 0, /* wbd_inv */
  296. 2867, /* wbd_ref */
  297. 0, /* wbd_sel */
  298. 2, /* wbd_alpha */
  299. 0, /* agc1_max */
  300. 0, /* agc1_min */
  301. 39718, /* agc2_max */
  302. 9930, /* agc2_min */
  303. 0, /* agc1_pt1 */
  304. 0, /* agc1_pt2 */
  305. 0, /* agc1_pt3 */
  306. 0, /* agc1_slope1 */
  307. 0, /* agc1_slope2 */
  308. 0, /* agc2_pt1 */
  309. 128, /* agc2_pt2 */
  310. 29, /* agc2_slope1 */
  311. 29, /* agc2_slope2 */
  312. 17, /* alpha_mant */
  313. 27, /* alpha_exp */
  314. 23, /* beta_mant */
  315. 51, /* beta_exp */
  316. 1, /* perform_agc_softsplit */
  317. };
  318. /* PLL Configuration for COFDM BW_MHz = 8.000000
  319. * With external clock = 30.000000 */
  320. static struct dibx000_bandwidth_config xc3028_bw_config = {
  321. 60000, /* internal */
  322. 30000, /* sampling */
  323. 1, /* pll_cfg: prediv */
  324. 8, /* pll_cfg: ratio */
  325. 3, /* pll_cfg: range */
  326. 1, /* pll_cfg: reset */
  327. 0, /* pll_cfg: bypass */
  328. 0, /* misc: refdiv */
  329. 0, /* misc: bypclk_div */
  330. 1, /* misc: IO_CLK_en_core */
  331. 1, /* misc: ADClkSrc */
  332. 0, /* misc: modulo */
  333. (3 << 14) | (1 << 12) | (524 << 0), /* sad_cfg: refsel, sel, freq_15k */
  334. (1 << 25) | 5816102, /* ifreq = 5.200000 MHz */
  335. 20452225, /* timf */
  336. 30000000 /* xtal_hz */
  337. };
  338. static struct dib7000p_config hauppauge_hvr1400_dib7000_config = {
  339. .output_mpeg2_in_188_bytes = 1,
  340. .hostbus_diversity = 1,
  341. .tuner_is_baseband = 0,
  342. .update_lna = NULL,
  343. .agc_config_count = 1,
  344. .agc = &xc3028_agc_config,
  345. .bw = &xc3028_bw_config,
  346. .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
  347. .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
  348. .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
  349. .pwm_freq_div = 0,
  350. .agc_control = NULL,
  351. .spur_protect = 0,
  352. .output_mode = OUTMODE_MPEG2_SERIAL,
  353. };
  354. static struct zl10353_config dvico_fusionhdtv_xc3028 = {
  355. .demod_address = 0x0f,
  356. .if2 = 45600,
  357. .no_tuner = 1,
  358. .disable_i2c_gate_ctrl = 1,
  359. };
  360. static struct stv0900_reg stv0900_ts_regs[] = {
  361. { R0900_TSGENERAL, 0x00 },
  362. { R0900_P1_TSSPEED, 0x40 },
  363. { R0900_P2_TSSPEED, 0x40 },
  364. { R0900_P1_TSCFGM, 0xc0 },
  365. { R0900_P2_TSCFGM, 0xc0 },
  366. { R0900_P1_TSCFGH, 0xe0 },
  367. { R0900_P2_TSCFGH, 0xe0 },
  368. { R0900_P1_TSCFGL, 0x20 },
  369. { R0900_P2_TSCFGL, 0x20 },
  370. { 0xffff, 0xff }, /* terminate */
  371. };
  372. static struct stv0900_config netup_stv0900_config = {
  373. .demod_address = 0x68,
  374. .demod_mode = 1, /* dual */
  375. .xtal = 8000000,
  376. .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
  377. .diseqc_mode = 2,/* 2/3 PWM */
  378. .ts_config_regs = stv0900_ts_regs,
  379. .tun1_maddress = 0,/* 0x60 */
  380. .tun2_maddress = 3,/* 0x63 */
  381. .tun1_adc = 1,/* 1 Vpp */
  382. .tun2_adc = 1,/* 1 Vpp */
  383. };
  384. static struct stv6110_config netup_stv6110_tunerconfig_a = {
  385. .i2c_address = 0x60,
  386. .mclk = 16000000,
  387. .clk_div = 1,
  388. .gain = 8, /* +16 dB - maximum gain */
  389. };
  390. static struct stv6110_config netup_stv6110_tunerconfig_b = {
  391. .i2c_address = 0x63,
  392. .mclk = 16000000,
  393. .clk_div = 1,
  394. .gain = 8, /* +16 dB - maximum gain */
  395. };
  396. static struct cx24116_config tbs_cx24116_config = {
  397. .demod_address = 0x55,
  398. };
  399. static struct ds3000_config tevii_ds3000_config = {
  400. .demod_address = 0x68,
  401. };
  402. static struct cx24116_config dvbworld_cx24116_config = {
  403. .demod_address = 0x05,
  404. };
  405. static struct lgs8gxx_config mygica_x8506_lgs8gl5_config = {
  406. .prod = LGS8GXX_PROD_LGS8GL5,
  407. .demod_address = 0x19,
  408. .serial_ts = 0,
  409. .ts_clk_pol = 1,
  410. .ts_clk_gated = 1,
  411. .if_clk_freq = 30400, /* 30.4 MHz */
  412. .if_freq = 5380, /* 5.38 MHz */
  413. .if_neg_center = 1,
  414. .ext_adc = 0,
  415. .adc_signed = 0,
  416. .if_neg_edge = 0,
  417. };
  418. static struct xc5000_config mygica_x8506_xc5000_config = {
  419. .i2c_address = 0x61,
  420. .if_khz = 5380,
  421. };
  422. static int cx23885_dvb_set_frontend(struct dvb_frontend *fe)
  423. {
  424. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  425. struct cx23885_tsport *port = fe->dvb->priv;
  426. struct cx23885_dev *dev = port->dev;
  427. switch (dev->board) {
  428. case CX23885_BOARD_HAUPPAUGE_HVR1275:
  429. switch (p->modulation) {
  430. case VSB_8:
  431. cx23885_gpio_clear(dev, GPIO_5);
  432. break;
  433. case QAM_64:
  434. case QAM_256:
  435. default:
  436. cx23885_gpio_set(dev, GPIO_5);
  437. break;
  438. }
  439. break;
  440. case CX23885_BOARD_MYGICA_X8506:
  441. case CX23885_BOARD_MAGICPRO_PROHDTVE2:
  442. /* Select Digital TV */
  443. cx23885_gpio_set(dev, GPIO_0);
  444. break;
  445. }
  446. return 0;
  447. }
  448. static struct lgs8gxx_config magicpro_prohdtve2_lgs8g75_config = {
  449. .prod = LGS8GXX_PROD_LGS8G75,
  450. .demod_address = 0x19,
  451. .serial_ts = 0,
  452. .ts_clk_pol = 1,
  453. .ts_clk_gated = 1,
  454. .if_clk_freq = 30400, /* 30.4 MHz */
  455. .if_freq = 6500, /* 6.50 MHz */
  456. .if_neg_center = 1,
  457. .ext_adc = 0,
  458. .adc_signed = 1,
  459. .adc_vpp = 2, /* 1.6 Vpp */
  460. .if_neg_edge = 1,
  461. };
  462. static struct xc5000_config magicpro_prohdtve2_xc5000_config = {
  463. .i2c_address = 0x61,
  464. .if_khz = 6500,
  465. };
  466. static struct atbm8830_config mygica_x8558pro_atbm8830_cfg1 = {
  467. .prod = ATBM8830_PROD_8830,
  468. .demod_address = 0x44,
  469. .serial_ts = 0,
  470. .ts_sampling_edge = 1,
  471. .ts_clk_gated = 0,
  472. .osc_clk_freq = 30400, /* in kHz */
  473. .if_freq = 0, /* zero IF */
  474. .zif_swap_iq = 1,
  475. .agc_min = 0x2E,
  476. .agc_max = 0xFF,
  477. .agc_hold_loop = 0,
  478. };
  479. static struct max2165_config mygic_x8558pro_max2165_cfg1 = {
  480. .i2c_address = 0x60,
  481. .osc_clk = 20
  482. };
  483. static struct atbm8830_config mygica_x8558pro_atbm8830_cfg2 = {
  484. .prod = ATBM8830_PROD_8830,
  485. .demod_address = 0x44,
  486. .serial_ts = 1,
  487. .ts_sampling_edge = 1,
  488. .ts_clk_gated = 0,
  489. .osc_clk_freq = 30400, /* in kHz */
  490. .if_freq = 0, /* zero IF */
  491. .zif_swap_iq = 1,
  492. .agc_min = 0x2E,
  493. .agc_max = 0xFF,
  494. .agc_hold_loop = 0,
  495. };
  496. static struct max2165_config mygic_x8558pro_max2165_cfg2 = {
  497. .i2c_address = 0x60,
  498. .osc_clk = 20
  499. };
  500. static struct stv0367_config netup_stv0367_config[] = {
  501. {
  502. .demod_address = 0x1c,
  503. .xtal = 27000000,
  504. .if_khz = 4500,
  505. .if_iq_mode = 0,
  506. .ts_mode = 1,
  507. .clk_pol = 0,
  508. }, {
  509. .demod_address = 0x1d,
  510. .xtal = 27000000,
  511. .if_khz = 4500,
  512. .if_iq_mode = 0,
  513. .ts_mode = 1,
  514. .clk_pol = 0,
  515. },
  516. };
  517. static struct xc5000_config netup_xc5000_config[] = {
  518. {
  519. .i2c_address = 0x61,
  520. .if_khz = 4500,
  521. }, {
  522. .i2c_address = 0x64,
  523. .if_khz = 4500,
  524. },
  525. };
  526. static struct drxk_config terratec_drxk_config[] = {
  527. {
  528. .adr = 0x29,
  529. .no_i2c_bridge = 1,
  530. }, {
  531. .adr = 0x2a,
  532. .no_i2c_bridge = 1,
  533. },
  534. };
  535. static struct mt2063_config terratec_mt2063_config[] = {
  536. {
  537. .tuner_address = 0x60,
  538. }, {
  539. .tuner_address = 0x67,
  540. },
  541. };
  542. int netup_altera_fpga_rw(void *device, int flag, int data, int read)
  543. {
  544. struct cx23885_dev *dev = (struct cx23885_dev *)device;
  545. unsigned long timeout = jiffies + msecs_to_jiffies(1);
  546. uint32_t mem = 0;
  547. mem = cx_read(MC417_RWD);
  548. if (read)
  549. cx_set(MC417_OEN, ALT_DATA);
  550. else {
  551. cx_clear(MC417_OEN, ALT_DATA);/* D0-D7 out */
  552. mem &= ~ALT_DATA;
  553. mem |= (data & ALT_DATA);
  554. }
  555. if (flag)
  556. mem |= ALT_AD_RG;
  557. else
  558. mem &= ~ALT_AD_RG;
  559. mem &= ~ALT_CS;
  560. if (read)
  561. mem = (mem & ~ALT_RD) | ALT_WR;
  562. else
  563. mem = (mem & ~ALT_WR) | ALT_RD;
  564. cx_write(MC417_RWD, mem); /* start RW cycle */
  565. for (;;) {
  566. mem = cx_read(MC417_RWD);
  567. if ((mem & ALT_RDY) == 0)
  568. break;
  569. if (time_after(jiffies, timeout))
  570. break;
  571. udelay(1);
  572. }
  573. cx_set(MC417_RWD, ALT_RD | ALT_WR | ALT_CS);
  574. if (read)
  575. return mem & ALT_DATA;
  576. return 0;
  577. };
  578. static int dvb_register(struct cx23885_tsport *port)
  579. {
  580. struct cx23885_dev *dev = port->dev;
  581. struct cx23885_i2c *i2c_bus = NULL, *i2c_bus2 = NULL;
  582. struct videobuf_dvb_frontend *fe0, *fe1 = NULL;
  583. int mfe_shared = 0; /* bus not shared by default */
  584. int ret;
  585. /* Get the first frontend */
  586. fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);
  587. if (!fe0)
  588. return -EINVAL;
  589. /* init struct videobuf_dvb */
  590. fe0->dvb.name = dev->name;
  591. /* multi-frontend gate control is undefined or defaults to fe0 */
  592. port->frontends.gate = 0;
  593. /* Sets the gate control callback to be used by i2c command calls */
  594. port->gate_ctrl = cx23885_dvb_gate_ctrl;
  595. /* init frontend */
  596. switch (dev->board) {
  597. case CX23885_BOARD_HAUPPAUGE_HVR1250:
  598. i2c_bus = &dev->i2c_bus[0];
  599. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  600. &hauppauge_generic_config,
  601. &i2c_bus->i2c_adap);
  602. if (fe0->dvb.frontend != NULL) {
  603. dvb_attach(mt2131_attach, fe0->dvb.frontend,
  604. &i2c_bus->i2c_adap,
  605. &hauppauge_generic_tunerconfig, 0);
  606. }
  607. break;
  608. case CX23885_BOARD_HAUPPAUGE_HVR1270:
  609. case CX23885_BOARD_HAUPPAUGE_HVR1275:
  610. i2c_bus = &dev->i2c_bus[0];
  611. fe0->dvb.frontend = dvb_attach(lgdt3305_attach,
  612. &hauppauge_lgdt3305_config,
  613. &i2c_bus->i2c_adap);
  614. if (fe0->dvb.frontend != NULL) {
  615. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  616. 0x60, &dev->i2c_bus[1].i2c_adap,
  617. &hauppauge_hvr127x_config);
  618. }
  619. break;
  620. case CX23885_BOARD_HAUPPAUGE_HVR1255:
  621. i2c_bus = &dev->i2c_bus[0];
  622. fe0->dvb.frontend = dvb_attach(s5h1411_attach,
  623. &hcw_s5h1411_config,
  624. &i2c_bus->i2c_adap);
  625. if (fe0->dvb.frontend != NULL) {
  626. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  627. 0x60, &dev->i2c_bus[1].i2c_adap,
  628. &hauppauge_tda18271_config);
  629. }
  630. break;
  631. case CX23885_BOARD_HAUPPAUGE_HVR1800:
  632. i2c_bus = &dev->i2c_bus[0];
  633. switch (alt_tuner) {
  634. case 1:
  635. fe0->dvb.frontend =
  636. dvb_attach(s5h1409_attach,
  637. &hauppauge_ezqam_config,
  638. &i2c_bus->i2c_adap);
  639. if (fe0->dvb.frontend != NULL) {
  640. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  641. &dev->i2c_bus[1].i2c_adap, 0x42,
  642. &tda829x_no_probe);
  643. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  644. 0x60, &dev->i2c_bus[1].i2c_adap,
  645. &hauppauge_tda18271_config);
  646. }
  647. break;
  648. case 0:
  649. default:
  650. fe0->dvb.frontend =
  651. dvb_attach(s5h1409_attach,
  652. &hauppauge_generic_config,
  653. &i2c_bus->i2c_adap);
  654. if (fe0->dvb.frontend != NULL)
  655. dvb_attach(mt2131_attach, fe0->dvb.frontend,
  656. &i2c_bus->i2c_adap,
  657. &hauppauge_generic_tunerconfig, 0);
  658. break;
  659. }
  660. break;
  661. case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
  662. i2c_bus = &dev->i2c_bus[0];
  663. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  664. &hauppauge_hvr1800lp_config,
  665. &i2c_bus->i2c_adap);
  666. if (fe0->dvb.frontend != NULL) {
  667. dvb_attach(mt2131_attach, fe0->dvb.frontend,
  668. &i2c_bus->i2c_adap,
  669. &hauppauge_generic_tunerconfig, 0);
  670. }
  671. break;
  672. case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
  673. i2c_bus = &dev->i2c_bus[0];
  674. fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
  675. &fusionhdtv_5_express,
  676. &i2c_bus->i2c_adap);
  677. if (fe0->dvb.frontend != NULL) {
  678. dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  679. &i2c_bus->i2c_adap, 0x61,
  680. TUNER_LG_TDVS_H06XF);
  681. }
  682. break;
  683. case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
  684. i2c_bus = &dev->i2c_bus[1];
  685. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  686. &hauppauge_hvr1500q_config,
  687. &dev->i2c_bus[0].i2c_adap);
  688. if (fe0->dvb.frontend != NULL)
  689. dvb_attach(xc5000_attach, fe0->dvb.frontend,
  690. &i2c_bus->i2c_adap,
  691. &hauppauge_hvr1500q_tunerconfig);
  692. break;
  693. case CX23885_BOARD_HAUPPAUGE_HVR1500:
  694. i2c_bus = &dev->i2c_bus[1];
  695. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  696. &hauppauge_hvr1500_config,
  697. &dev->i2c_bus[0].i2c_adap);
  698. if (fe0->dvb.frontend != NULL) {
  699. struct dvb_frontend *fe;
  700. struct xc2028_config cfg = {
  701. .i2c_adap = &i2c_bus->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_OREN538,
  708. };
  709. fe = dvb_attach(xc2028_attach,
  710. fe0->dvb.frontend, &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_HAUPPAUGE_HVR1200:
  716. case CX23885_BOARD_HAUPPAUGE_HVR1700:
  717. i2c_bus = &dev->i2c_bus[0];
  718. fe0->dvb.frontend = dvb_attach(tda10048_attach,
  719. &hauppauge_hvr1200_config,
  720. &i2c_bus->i2c_adap);
  721. if (fe0->dvb.frontend != NULL) {
  722. dvb_attach(tda829x_attach, fe0->dvb.frontend,
  723. &dev->i2c_bus[1].i2c_adap, 0x42,
  724. &tda829x_no_probe);
  725. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  726. 0x60, &dev->i2c_bus[1].i2c_adap,
  727. &hauppauge_hvr1200_tuner_config);
  728. }
  729. break;
  730. case CX23885_BOARD_HAUPPAUGE_HVR1210:
  731. i2c_bus = &dev->i2c_bus[0];
  732. fe0->dvb.frontend = dvb_attach(tda10048_attach,
  733. &hauppauge_hvr1210_config,
  734. &i2c_bus->i2c_adap);
  735. if (fe0->dvb.frontend != NULL) {
  736. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  737. 0x60, &dev->i2c_bus[1].i2c_adap,
  738. &hauppauge_hvr1210_tuner_config);
  739. }
  740. break;
  741. case CX23885_BOARD_HAUPPAUGE_HVR1400:
  742. i2c_bus = &dev->i2c_bus[0];
  743. fe0->dvb.frontend = dvb_attach(dib7000p_attach,
  744. &i2c_bus->i2c_adap,
  745. 0x12, &hauppauge_hvr1400_dib7000_config);
  746. if (fe0->dvb.frontend != NULL) {
  747. struct dvb_frontend *fe;
  748. struct xc2028_config cfg = {
  749. .i2c_adap = &dev->i2c_bus[1].i2c_adap,
  750. .i2c_addr = 0x64,
  751. };
  752. static struct xc2028_ctrl ctl = {
  753. .fname = XC3028L_DEFAULT_FIRMWARE,
  754. .max_len = 64,
  755. .demod = XC3028_FE_DIBCOM52,
  756. /* This is true for all demods with
  757. v36 firmware? */
  758. .type = XC2028_D2633,
  759. };
  760. fe = dvb_attach(xc2028_attach,
  761. fe0->dvb.frontend, &cfg);
  762. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  763. fe->ops.tuner_ops.set_config(fe, &ctl);
  764. }
  765. break;
  766. case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:
  767. i2c_bus = &dev->i2c_bus[port->nr - 1];
  768. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  769. &dvico_s5h1409_config,
  770. &i2c_bus->i2c_adap);
  771. if (fe0->dvb.frontend == NULL)
  772. fe0->dvb.frontend = dvb_attach(s5h1411_attach,
  773. &dvico_s5h1411_config,
  774. &i2c_bus->i2c_adap);
  775. if (fe0->dvb.frontend != NULL)
  776. dvb_attach(xc5000_attach, fe0->dvb.frontend,
  777. &i2c_bus->i2c_adap,
  778. &dvico_xc5000_tunerconfig);
  779. break;
  780. case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP: {
  781. i2c_bus = &dev->i2c_bus[port->nr - 1];
  782. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  783. &dvico_fusionhdtv_xc3028,
  784. &i2c_bus->i2c_adap);
  785. if (fe0->dvb.frontend != NULL) {
  786. struct dvb_frontend *fe;
  787. struct xc2028_config cfg = {
  788. .i2c_adap = &i2c_bus->i2c_adap,
  789. .i2c_addr = 0x61,
  790. };
  791. static struct xc2028_ctrl ctl = {
  792. .fname = XC2028_DEFAULT_FIRMWARE,
  793. .max_len = 64,
  794. .demod = XC3028_FE_ZARLINK456,
  795. };
  796. fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
  797. &cfg);
  798. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  799. fe->ops.tuner_ops.set_config(fe, &ctl);
  800. }
  801. break;
  802. }
  803. case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
  804. case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
  805. case CX23885_BOARD_COMPRO_VIDEOMATE_E800:
  806. i2c_bus = &dev->i2c_bus[0];
  807. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  808. &dvico_fusionhdtv_xc3028,
  809. &i2c_bus->i2c_adap);
  810. if (fe0->dvb.frontend != NULL) {
  811. struct dvb_frontend *fe;
  812. struct xc2028_config cfg = {
  813. .i2c_adap = &dev->i2c_bus[1].i2c_adap,
  814. .i2c_addr = 0x61,
  815. };
  816. static struct xc2028_ctrl ctl = {
  817. .fname = XC2028_DEFAULT_FIRMWARE,
  818. .max_len = 64,
  819. .demod = XC3028_FE_ZARLINK456,
  820. };
  821. fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
  822. &cfg);
  823. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  824. fe->ops.tuner_ops.set_config(fe, &ctl);
  825. }
  826. break;
  827. case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000:
  828. i2c_bus = &dev->i2c_bus[0];
  829. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  830. &dvico_fusionhdtv_xc3028,
  831. &i2c_bus->i2c_adap);
  832. if (fe0->dvb.frontend != NULL) {
  833. struct dvb_frontend *fe;
  834. struct xc4000_config cfg = {
  835. .i2c_address = 0x61,
  836. .default_pm = 0,
  837. .dvb_amplitude = 134,
  838. .set_smoothedcvbs = 1,
  839. .if_khz = 4560
  840. };
  841. fe = dvb_attach(xc4000_attach, fe0->dvb.frontend,
  842. &dev->i2c_bus[1].i2c_adap, &cfg);
  843. if (!fe) {
  844. printk(KERN_ERR "%s/2: xc4000 attach failed\n",
  845. dev->name);
  846. goto frontend_detach;
  847. }
  848. }
  849. break;
  850. case CX23885_BOARD_TBS_6920:
  851. i2c_bus = &dev->i2c_bus[1];
  852. fe0->dvb.frontend = dvb_attach(cx24116_attach,
  853. &tbs_cx24116_config,
  854. &i2c_bus->i2c_adap);
  855. if (fe0->dvb.frontend != NULL)
  856. fe0->dvb.frontend->ops.set_voltage = f300_set_voltage;
  857. break;
  858. case CX23885_BOARD_TEVII_S470:
  859. i2c_bus = &dev->i2c_bus[1];
  860. fe0->dvb.frontend = dvb_attach(ds3000_attach,
  861. &tevii_ds3000_config,
  862. &i2c_bus->i2c_adap);
  863. if (fe0->dvb.frontend != NULL)
  864. fe0->dvb.frontend->ops.set_voltage = f300_set_voltage;
  865. break;
  866. case CX23885_BOARD_DVBWORLD_2005:
  867. i2c_bus = &dev->i2c_bus[1];
  868. fe0->dvb.frontend = dvb_attach(cx24116_attach,
  869. &dvbworld_cx24116_config,
  870. &i2c_bus->i2c_adap);
  871. break;
  872. case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
  873. i2c_bus = &dev->i2c_bus[0];
  874. switch (port->nr) {
  875. /* port B */
  876. case 1:
  877. fe0->dvb.frontend = dvb_attach(stv0900_attach,
  878. &netup_stv0900_config,
  879. &i2c_bus->i2c_adap, 0);
  880. if (fe0->dvb.frontend != NULL) {
  881. if (dvb_attach(stv6110_attach,
  882. fe0->dvb.frontend,
  883. &netup_stv6110_tunerconfig_a,
  884. &i2c_bus->i2c_adap)) {
  885. if (!dvb_attach(lnbh24_attach,
  886. fe0->dvb.frontend,
  887. &i2c_bus->i2c_adap,
  888. LNBH24_PCL | LNBH24_TTX,
  889. LNBH24_TEN, 0x09))
  890. printk(KERN_ERR
  891. "No LNBH24 found!\n");
  892. }
  893. }
  894. break;
  895. /* port C */
  896. case 2:
  897. fe0->dvb.frontend = dvb_attach(stv0900_attach,
  898. &netup_stv0900_config,
  899. &i2c_bus->i2c_adap, 1);
  900. if (fe0->dvb.frontend != NULL) {
  901. if (dvb_attach(stv6110_attach,
  902. fe0->dvb.frontend,
  903. &netup_stv6110_tunerconfig_b,
  904. &i2c_bus->i2c_adap)) {
  905. if (!dvb_attach(lnbh24_attach,
  906. fe0->dvb.frontend,
  907. &i2c_bus->i2c_adap,
  908. LNBH24_PCL | LNBH24_TTX,
  909. LNBH24_TEN, 0x0a))
  910. printk(KERN_ERR
  911. "No LNBH24 found!\n");
  912. }
  913. }
  914. break;
  915. }
  916. break;
  917. case CX23885_BOARD_MYGICA_X8506:
  918. i2c_bus = &dev->i2c_bus[0];
  919. i2c_bus2 = &dev->i2c_bus[1];
  920. fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
  921. &mygica_x8506_lgs8gl5_config,
  922. &i2c_bus->i2c_adap);
  923. if (fe0->dvb.frontend != NULL) {
  924. dvb_attach(xc5000_attach,
  925. fe0->dvb.frontend,
  926. &i2c_bus2->i2c_adap,
  927. &mygica_x8506_xc5000_config);
  928. }
  929. break;
  930. case CX23885_BOARD_MAGICPRO_PROHDTVE2:
  931. i2c_bus = &dev->i2c_bus[0];
  932. i2c_bus2 = &dev->i2c_bus[1];
  933. fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
  934. &magicpro_prohdtve2_lgs8g75_config,
  935. &i2c_bus->i2c_adap);
  936. if (fe0->dvb.frontend != NULL) {
  937. dvb_attach(xc5000_attach,
  938. fe0->dvb.frontend,
  939. &i2c_bus2->i2c_adap,
  940. &magicpro_prohdtve2_xc5000_config);
  941. }
  942. break;
  943. case CX23885_BOARD_HAUPPAUGE_HVR1850:
  944. i2c_bus = &dev->i2c_bus[0];
  945. fe0->dvb.frontend = dvb_attach(s5h1411_attach,
  946. &hcw_s5h1411_config,
  947. &i2c_bus->i2c_adap);
  948. if (fe0->dvb.frontend != NULL)
  949. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  950. 0x60, &dev->i2c_bus[0].i2c_adap,
  951. &hauppauge_tda18271_config);
  952. tda18271_attach(&dev->ts1.analog_fe,
  953. 0x60, &dev->i2c_bus[1].i2c_adap,
  954. &hauppauge_tda18271_config);
  955. break;
  956. case CX23885_BOARD_HAUPPAUGE_HVR1290:
  957. i2c_bus = &dev->i2c_bus[0];
  958. fe0->dvb.frontend = dvb_attach(s5h1411_attach,
  959. &hcw_s5h1411_config,
  960. &i2c_bus->i2c_adap);
  961. if (fe0->dvb.frontend != NULL)
  962. dvb_attach(tda18271_attach, fe0->dvb.frontend,
  963. 0x60, &dev->i2c_bus[0].i2c_adap,
  964. &hauppauge_tda18271_config);
  965. break;
  966. case CX23885_BOARD_MYGICA_X8558PRO:
  967. switch (port->nr) {
  968. /* port B */
  969. case 1:
  970. i2c_bus = &dev->i2c_bus[0];
  971. fe0->dvb.frontend = dvb_attach(atbm8830_attach,
  972. &mygica_x8558pro_atbm8830_cfg1,
  973. &i2c_bus->i2c_adap);
  974. if (fe0->dvb.frontend != NULL) {
  975. dvb_attach(max2165_attach,
  976. fe0->dvb.frontend,
  977. &i2c_bus->i2c_adap,
  978. &mygic_x8558pro_max2165_cfg1);
  979. }
  980. break;
  981. /* port C */
  982. case 2:
  983. i2c_bus = &dev->i2c_bus[1];
  984. fe0->dvb.frontend = dvb_attach(atbm8830_attach,
  985. &mygica_x8558pro_atbm8830_cfg2,
  986. &i2c_bus->i2c_adap);
  987. if (fe0->dvb.frontend != NULL) {
  988. dvb_attach(max2165_attach,
  989. fe0->dvb.frontend,
  990. &i2c_bus->i2c_adap,
  991. &mygic_x8558pro_max2165_cfg2);
  992. }
  993. break;
  994. }
  995. break;
  996. case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF:
  997. i2c_bus = &dev->i2c_bus[0];
  998. mfe_shared = 1;/* MFE */
  999. port->frontends.gate = 0;/* not clear for me yet */
  1000. /* ports B, C */
  1001. /* MFE frontend 1 DVB-T */
  1002. fe0->dvb.frontend = dvb_attach(stv0367ter_attach,
  1003. &netup_stv0367_config[port->nr - 1],
  1004. &i2c_bus->i2c_adap);
  1005. if (fe0->dvb.frontend != NULL) {
  1006. if (NULL == dvb_attach(xc5000_attach,
  1007. fe0->dvb.frontend,
  1008. &i2c_bus->i2c_adap,
  1009. &netup_xc5000_config[port->nr - 1]))
  1010. goto frontend_detach;
  1011. /* load xc5000 firmware */
  1012. fe0->dvb.frontend->ops.tuner_ops.init(fe0->dvb.frontend);
  1013. }
  1014. /* MFE frontend 2 */
  1015. fe1 = videobuf_dvb_get_frontend(&port->frontends, 2);
  1016. if (fe1 == NULL)
  1017. goto frontend_detach;
  1018. /* DVB-C init */
  1019. fe1->dvb.frontend = dvb_attach(stv0367cab_attach,
  1020. &netup_stv0367_config[port->nr - 1],
  1021. &i2c_bus->i2c_adap);
  1022. if (fe1->dvb.frontend != NULL) {
  1023. fe1->dvb.frontend->id = 1;
  1024. if (NULL == dvb_attach(xc5000_attach,
  1025. fe1->dvb.frontend,
  1026. &i2c_bus->i2c_adap,
  1027. &netup_xc5000_config[port->nr - 1]))
  1028. goto frontend_detach;
  1029. }
  1030. break;
  1031. case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
  1032. i2c_bus = &dev->i2c_bus[0];
  1033. i2c_bus2 = &dev->i2c_bus[1];
  1034. switch (port->nr) {
  1035. /* port b */
  1036. case 1:
  1037. fe0->dvb.frontend = dvb_attach(drxk_attach,
  1038. &terratec_drxk_config[0],
  1039. &i2c_bus->i2c_adap);
  1040. if (fe0->dvb.frontend != NULL) {
  1041. if (!dvb_attach(mt2063_attach,
  1042. fe0->dvb.frontend,
  1043. &terratec_mt2063_config[0],
  1044. &i2c_bus2->i2c_adap))
  1045. goto frontend_detach;
  1046. }
  1047. break;
  1048. /* port c */
  1049. case 2:
  1050. fe0->dvb.frontend = dvb_attach(drxk_attach,
  1051. &terratec_drxk_config[1],
  1052. &i2c_bus->i2c_adap);
  1053. if (fe0->dvb.frontend != NULL) {
  1054. if (!dvb_attach(mt2063_attach,
  1055. fe0->dvb.frontend,
  1056. &terratec_mt2063_config[1],
  1057. &i2c_bus2->i2c_adap))
  1058. goto frontend_detach;
  1059. }
  1060. break;
  1061. }
  1062. break;
  1063. default:
  1064. printk(KERN_INFO "%s: The frontend of your DVB/ATSC card "
  1065. " isn't supported yet\n",
  1066. dev->name);
  1067. break;
  1068. }
  1069. if ((NULL == fe0->dvb.frontend) || (fe1 && NULL == fe1->dvb.frontend)) {
  1070. printk(KERN_ERR "%s: frontend initialization failed\n",
  1071. dev->name);
  1072. goto frontend_detach;
  1073. }
  1074. /* define general-purpose callback pointer */
  1075. fe0->dvb.frontend->callback = cx23885_tuner_callback;
  1076. if (fe1)
  1077. fe1->dvb.frontend->callback = cx23885_tuner_callback;
  1078. #if 0
  1079. /* Ensure all frontends negotiate bus access */
  1080. fe0->dvb.frontend->ops.ts_bus_ctrl = cx23885_dvb_bus_ctrl;
  1081. if (fe1)
  1082. fe1->dvb.frontend->ops.ts_bus_ctrl = cx23885_dvb_bus_ctrl;
  1083. #endif
  1084. /* Put the analog decoder in standby to keep it quiet */
  1085. call_all(dev, core, s_power, 0);
  1086. if (fe0->dvb.frontend->ops.analog_ops.standby)
  1087. fe0->dvb.frontend->ops.analog_ops.standby(fe0->dvb.frontend);
  1088. /* register everything */
  1089. ret = videobuf_dvb_register_bus(&port->frontends, THIS_MODULE, port,
  1090. &dev->pci->dev, adapter_nr, mfe_shared,
  1091. NULL);
  1092. if (ret)
  1093. goto frontend_detach;
  1094. /* init CI & MAC */
  1095. switch (dev->board) {
  1096. case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: {
  1097. static struct netup_card_info cinfo;
  1098. netup_get_card_info(&dev->i2c_bus[0].i2c_adap, &cinfo);
  1099. memcpy(port->frontends.adapter.proposed_mac,
  1100. cinfo.port[port->nr - 1].mac, 6);
  1101. printk(KERN_INFO "NetUP Dual DVB-S2 CI card port%d MAC=%pM\n",
  1102. port->nr, port->frontends.adapter.proposed_mac);
  1103. netup_ci_init(port);
  1104. break;
  1105. }
  1106. case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF: {
  1107. struct altera_ci_config netup_ci_cfg = {
  1108. .dev = dev,/* magic number to identify*/
  1109. .adapter = &port->frontends.adapter,/* for CI */
  1110. .demux = &fe0->dvb.demux,/* for hw pid filter */
  1111. .fpga_rw = netup_altera_fpga_rw,
  1112. };
  1113. altera_ci_init(&netup_ci_cfg, port->nr);
  1114. break;
  1115. }
  1116. case CX23885_BOARD_TEVII_S470: {
  1117. u8 eeprom[256]; /* 24C02 i2c eeprom */
  1118. if (port->nr != 1)
  1119. break;
  1120. /* Read entire EEPROM */
  1121. dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
  1122. tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, sizeof(eeprom));
  1123. printk(KERN_INFO "TeVii S470 MAC= %pM\n", eeprom + 0xa0);
  1124. memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xa0, 6);
  1125. break;
  1126. }
  1127. }
  1128. return ret;
  1129. frontend_detach:
  1130. port->gate_ctrl = NULL;
  1131. videobuf_dvb_dealloc_frontends(&port->frontends);
  1132. return -EINVAL;
  1133. }
  1134. int cx23885_dvb_register(struct cx23885_tsport *port)
  1135. {
  1136. struct videobuf_dvb_frontend *fe0;
  1137. struct cx23885_dev *dev = port->dev;
  1138. int err, i;
  1139. /* Here we need to allocate the correct number of frontends,
  1140. * as reflected in the cards struct. The reality is that currently
  1141. * no cx23885 boards support this - yet. But, if we don't modify this
  1142. * code then the second frontend would never be allocated (later)
  1143. * and fail with error before the attach in dvb_register().
  1144. * Without these changes we risk an OOPS later. The changes here
  1145. * are for safety, and should provide a good foundation for the
  1146. * future addition of any multi-frontend cx23885 based boards.
  1147. */
  1148. printk(KERN_INFO "%s() allocating %d frontend(s)\n", __func__,
  1149. port->num_frontends);
  1150. for (i = 1; i <= port->num_frontends; i++) {
  1151. if (videobuf_dvb_alloc_frontend(
  1152. &port->frontends, i) == NULL) {
  1153. printk(KERN_ERR "%s() failed to alloc\n", __func__);
  1154. return -ENOMEM;
  1155. }
  1156. fe0 = videobuf_dvb_get_frontend(&port->frontends, i);
  1157. if (!fe0)
  1158. err = -EINVAL;
  1159. dprintk(1, "%s\n", __func__);
  1160. dprintk(1, " ->probed by Card=%d Name=%s, PCI %02x:%02x\n",
  1161. dev->board,
  1162. dev->name,
  1163. dev->pci_bus,
  1164. dev->pci_slot);
  1165. err = -ENODEV;
  1166. /* dvb stuff */
  1167. /* We have to init the queue for each frontend on a port. */
  1168. printk(KERN_INFO "%s: cx23885 based dvb card\n", dev->name);
  1169. videobuf_queue_sg_init(&fe0->dvb.dvbq, &dvb_qops,
  1170. &dev->pci->dev, &port->slock,
  1171. V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
  1172. sizeof(struct cx23885_buffer), port, NULL);
  1173. }
  1174. err = dvb_register(port);
  1175. if (err != 0)
  1176. printk(KERN_ERR "%s() dvb_register failed err = %d\n",
  1177. __func__, err);
  1178. return err;
  1179. }
  1180. int cx23885_dvb_unregister(struct cx23885_tsport *port)
  1181. {
  1182. struct videobuf_dvb_frontend *fe0;
  1183. /* FIXME: in an error condition where the we have
  1184. * an expected number of frontends (attach problem)
  1185. * then this might not clean up correctly, if 1
  1186. * is invalid.
  1187. * This comment only applies to future boards IF they
  1188. * implement MFE support.
  1189. */
  1190. fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);
  1191. if (fe0 && fe0->dvb.frontend)
  1192. videobuf_dvb_unregister_bus(&port->frontends);
  1193. switch (port->dev->board) {
  1194. case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
  1195. netup_ci_exit(port);
  1196. break;
  1197. case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF:
  1198. altera_ci_release(port->dev, port->nr);
  1199. break;
  1200. }
  1201. port->gate_ctrl = NULL;
  1202. return 0;
  1203. }