flexcop-fe-tuner.c 17 KB

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