cx23885-dvb.c 35 KB

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