flexcop-fe-tuner.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. /*
  2. * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
  3. * flexcop-fe-tuner.c - methods for frontend attachment and DiSEqC controlling
  4. * see flexcop.c for copyright information
  5. */
  6. #include <media/tuner.h>
  7. #include "flexcop.h"
  8. #include "mt312.h"
  9. #include "stv0299.h"
  10. #include "s5h1420.h"
  11. #include "itd1000.h"
  12. #include "cx24113.h"
  13. #include "cx24123.h"
  14. #include "isl6421.h"
  15. #include "cx24120.h"
  16. #include "mt352.h"
  17. #include "bcm3510.h"
  18. #include "nxt200x.h"
  19. #include "dvb-pll.h"
  20. #include "lgdt330x.h"
  21. #include "tuner-simple.h"
  22. #include "stv0297.h"
  23. /* Can we use the specified front-end? Remember that if we are compiled
  24. * into the kernel we can't call code that's in modules. */
  25. #define FE_SUPPORTED(fe) (defined(CONFIG_DVB_##fe) || \
  26. (defined(CONFIG_DVB_##fe##_MODULE) && defined(MODULE)))
  27. #if FE_SUPPORTED(BCM3510) || (FE_SUPPORTED(CX24120) && FE_SUPPORTED(ISL6421))
  28. static int flexcop_fe_request_firmware(struct dvb_frontend *fe,
  29. const struct firmware **fw, char *name)
  30. {
  31. struct flexcop_device *fc = fe->dvb->priv;
  32. return request_firmware(fw, name, fc->dev);
  33. }
  34. #endif
  35. /* lnb control */
  36. #if (FE_SUPPORTED(MT312) || FE_SUPPORTED(STV0299)) && FE_SUPPORTED(PLL)
  37. static int flexcop_set_voltage(struct dvb_frontend *fe,
  38. enum fe_sec_voltage voltage)
  39. {
  40. struct flexcop_device *fc = fe->dvb->priv;
  41. flexcop_ibi_value v;
  42. deb_tuner("polarity/voltage = %u\n", voltage);
  43. v = fc->read_ibi_reg(fc, misc_204);
  44. switch (voltage) {
  45. case SEC_VOLTAGE_OFF:
  46. v.misc_204.ACPI1_sig = 1;
  47. break;
  48. case SEC_VOLTAGE_13:
  49. v.misc_204.ACPI1_sig = 0;
  50. v.misc_204.LNB_L_H_sig = 0;
  51. break;
  52. case SEC_VOLTAGE_18:
  53. v.misc_204.ACPI1_sig = 0;
  54. v.misc_204.LNB_L_H_sig = 1;
  55. break;
  56. default:
  57. err("unknown SEC_VOLTAGE value");
  58. return -EINVAL;
  59. }
  60. return fc->write_ibi_reg(fc, misc_204, v);
  61. }
  62. #endif
  63. #if FE_SUPPORTED(S5H1420) || FE_SUPPORTED(STV0299) || FE_SUPPORTED(MT312)
  64. static int __maybe_unused flexcop_sleep(struct dvb_frontend* fe)
  65. {
  66. struct flexcop_device *fc = fe->dvb->priv;
  67. if (fc->fe_sleep)
  68. return fc->fe_sleep(fe);
  69. return 0;
  70. }
  71. #endif
  72. /* SkyStar2 DVB-S rev 2.3 */
  73. #if FE_SUPPORTED(MT312) && FE_SUPPORTED(PLL)
  74. static int flexcop_set_tone(struct dvb_frontend *fe, enum fe_sec_tone_mode tone)
  75. {
  76. /* u16 wz_half_period_for_45_mhz[] = { 0x01ff, 0x0154, 0x00ff, 0x00cc }; */
  77. struct flexcop_device *fc = fe->dvb->priv;
  78. flexcop_ibi_value v;
  79. u16 ax;
  80. v.raw = 0;
  81. deb_tuner("tone = %u\n",tone);
  82. switch (tone) {
  83. case SEC_TONE_ON:
  84. ax = 0x01ff;
  85. break;
  86. case SEC_TONE_OFF:
  87. ax = 0;
  88. break;
  89. default:
  90. err("unknown SEC_TONE value");
  91. return -EINVAL;
  92. }
  93. v.lnb_switch_freq_200.LNB_CTLPrescaler_sig = 1; /* divide by 2 */
  94. v.lnb_switch_freq_200.LNB_CTLHighCount_sig = ax;
  95. v.lnb_switch_freq_200.LNB_CTLLowCount_sig = ax == 0 ? 0x1ff : ax;
  96. return fc->write_ibi_reg(fc,lnb_switch_freq_200,v);
  97. }
  98. static void flexcop_diseqc_send_bit(struct dvb_frontend* fe, int data)
  99. {
  100. flexcop_set_tone(fe, SEC_TONE_ON);
  101. udelay(data ? 500 : 1000);
  102. flexcop_set_tone(fe, SEC_TONE_OFF);
  103. udelay(data ? 1000 : 500);
  104. }
  105. static void flexcop_diseqc_send_byte(struct dvb_frontend* fe, int data)
  106. {
  107. int i, par = 1, d;
  108. for (i = 7; i >= 0; i--) {
  109. d = (data >> i) & 1;
  110. par ^= d;
  111. flexcop_diseqc_send_bit(fe, d);
  112. }
  113. flexcop_diseqc_send_bit(fe, par);
  114. }
  115. static int flexcop_send_diseqc_msg(struct dvb_frontend *fe,
  116. int len, u8 *msg, unsigned long burst)
  117. {
  118. int i;
  119. flexcop_set_tone(fe, SEC_TONE_OFF);
  120. mdelay(16);
  121. for (i = 0; i < len; i++)
  122. flexcop_diseqc_send_byte(fe,msg[i]);
  123. mdelay(16);
  124. if (burst != -1) {
  125. if (burst)
  126. flexcop_diseqc_send_byte(fe, 0xff);
  127. else {
  128. flexcop_set_tone(fe, SEC_TONE_ON);
  129. mdelay(12);
  130. udelay(500);
  131. flexcop_set_tone(fe, SEC_TONE_OFF);
  132. }
  133. msleep(20);
  134. }
  135. return 0;
  136. }
  137. static int flexcop_diseqc_send_master_cmd(struct dvb_frontend *fe,
  138. struct dvb_diseqc_master_cmd *cmd)
  139. {
  140. return flexcop_send_diseqc_msg(fe, cmd->msg_len, cmd->msg, 0);
  141. }
  142. static int flexcop_diseqc_send_burst(struct dvb_frontend *fe,
  143. enum fe_sec_mini_cmd minicmd)
  144. {
  145. return flexcop_send_diseqc_msg(fe, 0, NULL, minicmd);
  146. }
  147. static struct mt312_config skystar23_samsung_tbdu18132_config = {
  148. .demod_address = 0x0e,
  149. };
  150. static int skystar2_rev23_attach(struct flexcop_device *fc,
  151. struct i2c_adapter *i2c)
  152. {
  153. struct dvb_frontend_ops *ops;
  154. fc->fe = dvb_attach(mt312_attach, &skystar23_samsung_tbdu18132_config, i2c);
  155. if (!fc->fe)
  156. return 0;
  157. if (!dvb_attach(dvb_pll_attach, fc->fe, 0x61, i2c,
  158. DVB_PLL_SAMSUNG_TBDU18132))
  159. return 0;
  160. ops = &fc->fe->ops;
  161. ops->diseqc_send_master_cmd = flexcop_diseqc_send_master_cmd;
  162. ops->diseqc_send_burst = flexcop_diseqc_send_burst;
  163. ops->set_tone = flexcop_set_tone;
  164. ops->set_voltage = flexcop_set_voltage;
  165. fc->fe_sleep = ops->sleep;
  166. ops->sleep = flexcop_sleep;
  167. return 1;
  168. }
  169. #else
  170. #define skystar2_rev23_attach NULL
  171. #endif
  172. /* SkyStar2 DVB-S rev 2.6 */
  173. #if FE_SUPPORTED(STV0299) && FE_SUPPORTED(PLL)
  174. static int samsung_tbmu24112_set_symbol_rate(struct dvb_frontend *fe,
  175. u32 srate, u32 ratio)
  176. {
  177. u8 aclk = 0;
  178. u8 bclk = 0;
  179. if (srate < 1500000) {
  180. aclk = 0xb7; bclk = 0x47;
  181. } else if (srate < 3000000) {
  182. aclk = 0xb7; bclk = 0x4b;
  183. } else if (srate < 7000000) {
  184. aclk = 0xb7; bclk = 0x4f;
  185. } else if (srate < 14000000) {
  186. aclk = 0xb7; bclk = 0x53;
  187. } else if (srate < 30000000) {
  188. aclk = 0xb6; bclk = 0x53;
  189. } else if (srate < 45000000) {
  190. aclk = 0xb4; bclk = 0x51;
  191. }
  192. stv0299_writereg(fe, 0x13, aclk);
  193. stv0299_writereg(fe, 0x14, bclk);
  194. stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
  195. stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
  196. stv0299_writereg(fe, 0x21, ratio & 0xf0);
  197. return 0;
  198. }
  199. static u8 samsung_tbmu24112_inittab[] = {
  200. 0x01, 0x15,
  201. 0x02, 0x30,
  202. 0x03, 0x00,
  203. 0x04, 0x7D,
  204. 0x05, 0x35,
  205. 0x06, 0x02,
  206. 0x07, 0x00,
  207. 0x08, 0xC3,
  208. 0x0C, 0x00,
  209. 0x0D, 0x81,
  210. 0x0E, 0x23,
  211. 0x0F, 0x12,
  212. 0x10, 0x7E,
  213. 0x11, 0x84,
  214. 0x12, 0xB9,
  215. 0x13, 0x88,
  216. 0x14, 0x89,
  217. 0x15, 0xC9,
  218. 0x16, 0x00,
  219. 0x17, 0x5C,
  220. 0x18, 0x00,
  221. 0x19, 0x00,
  222. 0x1A, 0x00,
  223. 0x1C, 0x00,
  224. 0x1D, 0x00,
  225. 0x1E, 0x00,
  226. 0x1F, 0x3A,
  227. 0x20, 0x2E,
  228. 0x21, 0x80,
  229. 0x22, 0xFF,
  230. 0x23, 0xC1,
  231. 0x28, 0x00,
  232. 0x29, 0x1E,
  233. 0x2A, 0x14,
  234. 0x2B, 0x0F,
  235. 0x2C, 0x09,
  236. 0x2D, 0x05,
  237. 0x31, 0x1F,
  238. 0x32, 0x19,
  239. 0x33, 0xFE,
  240. 0x34, 0x93,
  241. 0xff, 0xff,
  242. };
  243. static struct stv0299_config samsung_tbmu24112_config = {
  244. .demod_address = 0x68,
  245. .inittab = samsung_tbmu24112_inittab,
  246. .mclk = 88000000UL,
  247. .invert = 0,
  248. .skip_reinit = 0,
  249. .lock_output = STV0299_LOCKOUTPUT_LK,
  250. .volt13_op0_op1 = STV0299_VOLT13_OP1,
  251. .min_delay_ms = 100,
  252. .set_symbol_rate = samsung_tbmu24112_set_symbol_rate,
  253. };
  254. static int skystar2_rev26_attach(struct flexcop_device *fc,
  255. struct i2c_adapter *i2c)
  256. {
  257. fc->fe = dvb_attach(stv0299_attach, &samsung_tbmu24112_config, i2c);
  258. if (!fc->fe)
  259. return 0;
  260. if (!dvb_attach(dvb_pll_attach, fc->fe, 0x61, i2c,
  261. DVB_PLL_SAMSUNG_TBMU24112))
  262. return 0;
  263. fc->fe->ops.set_voltage = flexcop_set_voltage;
  264. fc->fe_sleep = fc->fe->ops.sleep;
  265. fc->fe->ops.sleep = flexcop_sleep;
  266. return 1;
  267. }
  268. #else
  269. #define skystar2_rev26_attach NULL
  270. #endif
  271. /* SkyStar2 DVB-S rev 2.7 */
  272. #if FE_SUPPORTED(S5H1420) && FE_SUPPORTED(ISL6421) && FE_SUPPORTED(TUNER_ITD1000)
  273. static struct s5h1420_config skystar2_rev2_7_s5h1420_config = {
  274. .demod_address = 0x53,
  275. .invert = 1,
  276. .repeated_start_workaround = 1,
  277. .serial_mpeg = 1,
  278. };
  279. static struct itd1000_config skystar2_rev2_7_itd1000_config = {
  280. .i2c_address = 0x61,
  281. };
  282. static int skystar2_rev27_attach(struct flexcop_device *fc,
  283. struct i2c_adapter *i2c)
  284. {
  285. flexcop_ibi_value r108;
  286. struct i2c_adapter *i2c_tuner;
  287. /* enable no_base_addr - no repeated start when reading */
  288. fc->fc_i2c_adap[0].no_base_addr = 1;
  289. fc->fe = dvb_attach(s5h1420_attach, &skystar2_rev2_7_s5h1420_config,
  290. i2c);
  291. if (!fc->fe)
  292. goto fail;
  293. i2c_tuner = s5h1420_get_tuner_i2c_adapter(fc->fe);
  294. if (!i2c_tuner)
  295. goto fail;
  296. fc->fe_sleep = fc->fe->ops.sleep;
  297. fc->fe->ops.sleep = flexcop_sleep;
  298. /* enable no_base_addr - no repeated start when reading */
  299. fc->fc_i2c_adap[2].no_base_addr = 1;
  300. if (!dvb_attach(isl6421_attach, fc->fe, &fc->fc_i2c_adap[2].i2c_adap,
  301. 0x08, 1, 1, false)) {
  302. err("ISL6421 could NOT be attached");
  303. goto fail_isl;
  304. }
  305. info("ISL6421 successfully attached");
  306. /* the ITD1000 requires a lower i2c clock - is it a problem ? */
  307. r108.raw = 0x00000506;
  308. fc->write_ibi_reg(fc, tw_sm_c_108, r108);
  309. if (!dvb_attach(itd1000_attach, fc->fe, i2c_tuner,
  310. &skystar2_rev2_7_itd1000_config)) {
  311. err("ITD1000 could NOT be attached");
  312. /* Should i2c clock be restored? */
  313. goto fail_isl;
  314. }
  315. info("ITD1000 successfully attached");
  316. return 1;
  317. fail_isl:
  318. fc->fc_i2c_adap[2].no_base_addr = 0;
  319. fail:
  320. /* for the next devices we need it again */
  321. fc->fc_i2c_adap[0].no_base_addr = 0;
  322. return 0;
  323. }
  324. #else
  325. #define skystar2_rev27_attach NULL
  326. #endif
  327. /* SkyStar2 rev 2.8 */
  328. #if FE_SUPPORTED(CX24123) && FE_SUPPORTED(ISL6421) && FE_SUPPORTED(TUNER_CX24113)
  329. static struct cx24123_config skystar2_rev2_8_cx24123_config = {
  330. .demod_address = 0x55,
  331. .dont_use_pll = 1,
  332. .agc_callback = cx24113_agc_callback,
  333. };
  334. static const struct cx24113_config skystar2_rev2_8_cx24113_config = {
  335. .i2c_addr = 0x54,
  336. .xtal_khz = 10111,
  337. };
  338. static int skystar2_rev28_attach(struct flexcop_device *fc,
  339. struct i2c_adapter *i2c)
  340. {
  341. struct i2c_adapter *i2c_tuner;
  342. fc->fe = dvb_attach(cx24123_attach, &skystar2_rev2_8_cx24123_config,
  343. i2c);
  344. if (!fc->fe)
  345. return 0;
  346. i2c_tuner = cx24123_get_tuner_i2c_adapter(fc->fe);
  347. if (!i2c_tuner)
  348. return 0;
  349. if (!dvb_attach(cx24113_attach, fc->fe, &skystar2_rev2_8_cx24113_config,
  350. i2c_tuner)) {
  351. err("CX24113 could NOT be attached");
  352. return 0;
  353. }
  354. info("CX24113 successfully attached");
  355. fc->fc_i2c_adap[2].no_base_addr = 1;
  356. if (!dvb_attach(isl6421_attach, fc->fe, &fc->fc_i2c_adap[2].i2c_adap,
  357. 0x08, 0, 0, false)) {
  358. err("ISL6421 could NOT be attached");
  359. fc->fc_i2c_adap[2].no_base_addr = 0;
  360. return 0;
  361. }
  362. info("ISL6421 successfully attached");
  363. /* TODO on i2c_adap[1] addr 0x11 (EEPROM) there seems to be an
  364. * IR-receiver (PIC16F818) - but the card has no input for that ??? */
  365. return 1;
  366. }
  367. #else
  368. #define skystar2_rev28_attach NULL
  369. #endif
  370. /* AirStar DVB-T */
  371. #if FE_SUPPORTED(MT352) && FE_SUPPORTED(PLL)
  372. static int samsung_tdtc9251dh0_demod_init(struct dvb_frontend *fe)
  373. {
  374. static u8 mt352_clock_config[] = { 0x89, 0x18, 0x2d };
  375. static u8 mt352_reset[] = { 0x50, 0x80 };
  376. static u8 mt352_adc_ctl_1_cfg[] = { 0x8E, 0x40 };
  377. static u8 mt352_agc_cfg[] = { 0x67, 0x28, 0xa1 };
  378. static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 };
  379. mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config));
  380. udelay(2000);
  381. mt352_write(fe, mt352_reset, sizeof(mt352_reset));
  382. mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg));
  383. mt352_write(fe, mt352_agc_cfg, sizeof(mt352_agc_cfg));
  384. mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg));
  385. return 0;
  386. }
  387. static struct mt352_config samsung_tdtc9251dh0_config = {
  388. .demod_address = 0x0f,
  389. .demod_init = samsung_tdtc9251dh0_demod_init,
  390. };
  391. static int airstar_dvbt_attach(struct flexcop_device *fc,
  392. struct i2c_adapter *i2c)
  393. {
  394. fc->fe = dvb_attach(mt352_attach, &samsung_tdtc9251dh0_config, i2c);
  395. if (!fc->fe)
  396. return 0;
  397. return !!dvb_attach(dvb_pll_attach, fc->fe, 0x61, NULL,
  398. DVB_PLL_SAMSUNG_TDTC9251DH0);
  399. }
  400. #else
  401. #define airstar_dvbt_attach NULL
  402. #endif
  403. /* AirStar ATSC 1st generation */
  404. #if FE_SUPPORTED(BCM3510)
  405. static struct bcm3510_config air2pc_atsc_first_gen_config = {
  406. .demod_address = 0x0f,
  407. .request_firmware = flexcop_fe_request_firmware,
  408. };
  409. static int airstar_atsc1_attach(struct flexcop_device *fc,
  410. struct i2c_adapter *i2c)
  411. {
  412. fc->fe = dvb_attach(bcm3510_attach, &air2pc_atsc_first_gen_config, i2c);
  413. return fc->fe != NULL;
  414. }
  415. #else
  416. #define airstar_atsc1_attach NULL
  417. #endif
  418. /* AirStar ATSC 2nd generation */
  419. #if FE_SUPPORTED(NXT200X) && FE_SUPPORTED(PLL)
  420. static struct nxt200x_config samsung_tbmv_config = {
  421. .demod_address = 0x0a,
  422. };
  423. static int airstar_atsc2_attach(struct flexcop_device *fc,
  424. struct i2c_adapter *i2c)
  425. {
  426. fc->fe = dvb_attach(nxt200x_attach, &samsung_tbmv_config, i2c);
  427. if (!fc->fe)
  428. return 0;
  429. return !!dvb_attach(dvb_pll_attach, fc->fe, 0x61, NULL,
  430. DVB_PLL_SAMSUNG_TBMV);
  431. }
  432. #else
  433. #define airstar_atsc2_attach NULL
  434. #endif
  435. /* AirStar ATSC 3rd generation */
  436. #if FE_SUPPORTED(LGDT330X)
  437. static struct lgdt330x_config air2pc_atsc_hd5000_config = {
  438. .demod_address = 0x59,
  439. .demod_chip = LGDT3303,
  440. .serial_mpeg = 0x04,
  441. .clock_polarity_flip = 1,
  442. };
  443. static int airstar_atsc3_attach(struct flexcop_device *fc,
  444. struct i2c_adapter *i2c)
  445. {
  446. fc->fe = dvb_attach(lgdt330x_attach, &air2pc_atsc_hd5000_config, i2c);
  447. if (!fc->fe)
  448. return 0;
  449. return !!dvb_attach(simple_tuner_attach, fc->fe, i2c, 0x61,
  450. TUNER_LG_TDVS_H06XF);
  451. }
  452. #else
  453. #define airstar_atsc3_attach NULL
  454. #endif
  455. /* CableStar2 DVB-C */
  456. #if FE_SUPPORTED(STV0297) && FE_SUPPORTED(PLL)
  457. static u8 alps_tdee4_stv0297_inittab[] = {
  458. 0x80, 0x01,
  459. 0x80, 0x00,
  460. 0x81, 0x01,
  461. 0x81, 0x00,
  462. 0x00, 0x48,
  463. 0x01, 0x58,
  464. 0x03, 0x00,
  465. 0x04, 0x00,
  466. 0x07, 0x00,
  467. 0x08, 0x00,
  468. 0x30, 0xff,
  469. 0x31, 0x9d,
  470. 0x32, 0xff,
  471. 0x33, 0x00,
  472. 0x34, 0x29,
  473. 0x35, 0x55,
  474. 0x36, 0x80,
  475. 0x37, 0x6e,
  476. 0x38, 0x9c,
  477. 0x40, 0x1a,
  478. 0x41, 0xfe,
  479. 0x42, 0x33,
  480. 0x43, 0x00,
  481. 0x44, 0xff,
  482. 0x45, 0x00,
  483. 0x46, 0x00,
  484. 0x49, 0x04,
  485. 0x4a, 0x51,
  486. 0x4b, 0xf8,
  487. 0x52, 0x30,
  488. 0x53, 0x06,
  489. 0x59, 0x06,
  490. 0x5a, 0x5e,
  491. 0x5b, 0x04,
  492. 0x61, 0x49,
  493. 0x62, 0x0a,
  494. 0x70, 0xff,
  495. 0x71, 0x04,
  496. 0x72, 0x00,
  497. 0x73, 0x00,
  498. 0x74, 0x0c,
  499. 0x80, 0x20,
  500. 0x81, 0x00,
  501. 0x82, 0x30,
  502. 0x83, 0x00,
  503. 0x84, 0x04,
  504. 0x85, 0x22,
  505. 0x86, 0x08,
  506. 0x87, 0x1b,
  507. 0x88, 0x00,
  508. 0x89, 0x00,
  509. 0x90, 0x00,
  510. 0x91, 0x04,
  511. 0xa0, 0x86,
  512. 0xa1, 0x00,
  513. 0xa2, 0x00,
  514. 0xb0, 0x91,
  515. 0xb1, 0x0b,
  516. 0xc0, 0x5b,
  517. 0xc1, 0x10,
  518. 0xc2, 0x12,
  519. 0xd0, 0x02,
  520. 0xd1, 0x00,
  521. 0xd2, 0x00,
  522. 0xd3, 0x00,
  523. 0xd4, 0x02,
  524. 0xd5, 0x00,
  525. 0xde, 0x00,
  526. 0xdf, 0x01,
  527. 0xff, 0xff,
  528. };
  529. static struct stv0297_config alps_tdee4_stv0297_config = {
  530. .demod_address = 0x1c,
  531. .inittab = alps_tdee4_stv0297_inittab,
  532. };
  533. static int cablestar2_attach(struct flexcop_device *fc,
  534. struct i2c_adapter *i2c)
  535. {
  536. fc->fc_i2c_adap[0].no_base_addr = 1;
  537. fc->fe = dvb_attach(stv0297_attach, &alps_tdee4_stv0297_config, i2c);
  538. if (!fc->fe)
  539. goto fail;
  540. /* This tuner doesn't use the stv0297's I2C gate, but instead the
  541. * tuner is connected to a different flexcop I2C adapter. */
  542. if (fc->fe->ops.i2c_gate_ctrl)
  543. fc->fe->ops.i2c_gate_ctrl(fc->fe, 0);
  544. fc->fe->ops.i2c_gate_ctrl = NULL;
  545. if (!dvb_attach(dvb_pll_attach, fc->fe, 0x61,
  546. &fc->fc_i2c_adap[2].i2c_adap, DVB_PLL_TDEE4))
  547. goto fail;
  548. return 1;
  549. fail:
  550. /* Reset for next frontend to try */
  551. fc->fc_i2c_adap[0].no_base_addr = 0;
  552. return 0;
  553. }
  554. #else
  555. #define cablestar2_attach NULL
  556. #endif
  557. /* SkyStar S2 PCI DVB-S/S2 card based on Conexant cx24120/cx24118 */
  558. #if FE_SUPPORTED(CX24120) && FE_SUPPORTED(ISL6421)
  559. static const struct cx24120_config skystar2_rev3_3_cx24120_config = {
  560. .i2c_addr = 0x55,
  561. .xtal_khz = 10111,
  562. .initial_mpeg_config = { 0xa1, 0x76, 0x07 },
  563. .request_firmware = flexcop_fe_request_firmware,
  564. .i2c_wr_max = 4,
  565. };
  566. static int skystarS2_rev33_attach(struct flexcop_device *fc,
  567. struct i2c_adapter *i2c)
  568. {
  569. fc->fe = dvb_attach(cx24120_attach,
  570. &skystar2_rev3_3_cx24120_config, i2c);
  571. if (!fc->fe)
  572. return 0;
  573. fc->dev_type = FC_SKYS2_REV33;
  574. fc->fc_i2c_adap[2].no_base_addr = 1;
  575. if (!dvb_attach(isl6421_attach, fc->fe, &fc->fc_i2c_adap[2].i2c_adap,
  576. 0x08, 0, 0, false)) {
  577. err("ISL6421 could NOT be attached!");
  578. fc->fc_i2c_adap[2].no_base_addr = 0;
  579. return 0;
  580. }
  581. info("ISL6421 successfully attached.");
  582. if (fc->has_32_hw_pid_filter)
  583. fc->skip_6_hw_pid_filter = 1;
  584. return 1;
  585. }
  586. #else
  587. #define skystarS2_rev33_attach NULL
  588. #endif
  589. static struct {
  590. flexcop_device_type_t type;
  591. int (*attach)(struct flexcop_device *, struct i2c_adapter *);
  592. } flexcop_frontends[] = {
  593. { FC_SKY_REV27, skystar2_rev27_attach },
  594. { FC_SKY_REV28, skystar2_rev28_attach },
  595. { FC_SKY_REV26, skystar2_rev26_attach },
  596. { FC_AIR_DVBT, airstar_dvbt_attach },
  597. { FC_AIR_ATSC2, airstar_atsc2_attach },
  598. { FC_AIR_ATSC3, airstar_atsc3_attach },
  599. { FC_AIR_ATSC1, airstar_atsc1_attach },
  600. { FC_CABLE, cablestar2_attach },
  601. { FC_SKY_REV23, skystar2_rev23_attach },
  602. { FC_SKYS2_REV33, skystarS2_rev33_attach },
  603. };
  604. /* try to figure out the frontend */
  605. int flexcop_frontend_init(struct flexcop_device *fc)
  606. {
  607. int i;
  608. for (i = 0; i < ARRAY_SIZE(flexcop_frontends); i++) {
  609. if (!flexcop_frontends[i].attach)
  610. continue;
  611. /* type needs to be set before, because of some workarounds
  612. * done based on the probed card type */
  613. fc->dev_type = flexcop_frontends[i].type;
  614. if (flexcop_frontends[i].attach(fc, &fc->fc_i2c_adap[0].i2c_adap))
  615. goto fe_found;
  616. /* Clean up partially attached frontend */
  617. if (fc->fe) {
  618. dvb_frontend_detach(fc->fe);
  619. fc->fe = NULL;
  620. }
  621. }
  622. fc->dev_type = FC_UNK;
  623. err("no frontend driver found for this B2C2/FlexCop adapter");
  624. return -ENODEV;
  625. fe_found:
  626. info("found '%s' .", fc->fe->ops.info.name);
  627. if (dvb_register_frontend(&fc->dvb_adapter, fc->fe)) {
  628. err("frontend registration failed!");
  629. dvb_frontend_detach(fc->fe);
  630. fc->fe = NULL;
  631. return -EINVAL;
  632. }
  633. fc->init_state |= FC_STATE_FE_INIT;
  634. return 0;
  635. }
  636. void flexcop_frontend_exit(struct flexcop_device *fc)
  637. {
  638. if (fc->init_state & FC_STATE_FE_INIT) {
  639. dvb_unregister_frontend(fc->fe);
  640. dvb_frontend_detach(fc->fe);
  641. }
  642. fc->init_state &= ~FC_STATE_FE_INIT;
  643. }