flexcop-fe-tuner.c 16 KB

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