flexcop-fe-tuner.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  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)
  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 skystar23_samsung_tbdu18132_tuner_set_params(struct dvb_frontend *fe,
  141. struct dvb_frontend_parameters *params)
  142. {
  143. u8 buf[4];
  144. u32 div;
  145. struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf,
  146. .len = sizeof(buf) };
  147. struct flexcop_device *fc = fe->dvb->priv;
  148. div = (params->frequency + (125/2)) / 125;
  149. buf[0] = (div >> 8) & 0x7f;
  150. buf[1] = (div >> 0) & 0xff;
  151. buf[2] = 0x84 | ((div >> 10) & 0x60);
  152. buf[3] = 0x80;
  153. if (params->frequency < 1550000)
  154. buf[3] |= 0x02;
  155. if (fe->ops.i2c_gate_ctrl)
  156. fe->ops.i2c_gate_ctrl(fe, 1);
  157. if (i2c_transfer(&fc->fc_i2c_adap[0].i2c_adap, &msg, 1) != 1)
  158. return -EIO;
  159. return 0;
  160. }
  161. static int skystar2_rev23_attach(struct flexcop_device *fc,
  162. struct i2c_adapter *i2c)
  163. {
  164. fc->fe = dvb_attach(mt312_attach, &skystar23_samsung_tbdu18132_config, i2c);
  165. if (fc->fe != NULL) {
  166. struct dvb_frontend_ops *ops = &fc->fe->ops;
  167. ops->tuner_ops.set_params =
  168. skystar23_samsung_tbdu18132_tuner_set_params;
  169. ops->diseqc_send_master_cmd = flexcop_diseqc_send_master_cmd;
  170. ops->diseqc_send_burst = flexcop_diseqc_send_burst;
  171. ops->set_tone = flexcop_set_tone;
  172. ops->set_voltage = flexcop_set_voltage;
  173. fc->fe_sleep = ops->sleep;
  174. ops->sleep = flexcop_sleep;
  175. return 1;
  176. }
  177. return 0;
  178. }
  179. #else
  180. #define skystar2_rev23_attach NULL
  181. #endif
  182. /* SkyStar2 DVB-S rev 2.6 */
  183. #if FE_SUPPORTED(STV0299)
  184. static int samsung_tbmu24112_set_symbol_rate(struct dvb_frontend *fe,
  185. u32 srate, u32 ratio)
  186. {
  187. u8 aclk = 0;
  188. u8 bclk = 0;
  189. if (srate < 1500000) {
  190. aclk = 0xb7; bclk = 0x47;
  191. } else if (srate < 3000000) {
  192. aclk = 0xb7; bclk = 0x4b;
  193. } else if (srate < 7000000) {
  194. aclk = 0xb7; bclk = 0x4f;
  195. } else if (srate < 14000000) {
  196. aclk = 0xb7; bclk = 0x53;
  197. } else if (srate < 30000000) {
  198. aclk = 0xb6; bclk = 0x53;
  199. } else if (srate < 45000000) {
  200. aclk = 0xb4; bclk = 0x51;
  201. }
  202. stv0299_writereg(fe, 0x13, aclk);
  203. stv0299_writereg(fe, 0x14, bclk);
  204. stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
  205. stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
  206. stv0299_writereg(fe, 0x21, ratio & 0xf0);
  207. return 0;
  208. }
  209. static int samsung_tbmu24112_tuner_set_params(struct dvb_frontend *fe,
  210. struct dvb_frontend_parameters *params)
  211. {
  212. u8 buf[4];
  213. u32 div;
  214. struct i2c_msg msg = {
  215. .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
  216. struct flexcop_device *fc = fe->dvb->priv;
  217. div = params->frequency / 125;
  218. buf[0] = (div >> 8) & 0x7f;
  219. buf[1] = div & 0xff;
  220. buf[2] = 0x84; /* 0xC4 */
  221. buf[3] = 0x08;
  222. if (params->frequency < 1500000)
  223. buf[3] |= 0x10;
  224. if (fe->ops.i2c_gate_ctrl)
  225. fe->ops.i2c_gate_ctrl(fe, 1);
  226. if (i2c_transfer(&fc->fc_i2c_adap[0].i2c_adap, &msg, 1) != 1)
  227. return -EIO;
  228. return 0;
  229. }
  230. static u8 samsung_tbmu24112_inittab[] = {
  231. 0x01, 0x15,
  232. 0x02, 0x30,
  233. 0x03, 0x00,
  234. 0x04, 0x7D,
  235. 0x05, 0x35,
  236. 0x06, 0x02,
  237. 0x07, 0x00,
  238. 0x08, 0xC3,
  239. 0x0C, 0x00,
  240. 0x0D, 0x81,
  241. 0x0E, 0x23,
  242. 0x0F, 0x12,
  243. 0x10, 0x7E,
  244. 0x11, 0x84,
  245. 0x12, 0xB9,
  246. 0x13, 0x88,
  247. 0x14, 0x89,
  248. 0x15, 0xC9,
  249. 0x16, 0x00,
  250. 0x17, 0x5C,
  251. 0x18, 0x00,
  252. 0x19, 0x00,
  253. 0x1A, 0x00,
  254. 0x1C, 0x00,
  255. 0x1D, 0x00,
  256. 0x1E, 0x00,
  257. 0x1F, 0x3A,
  258. 0x20, 0x2E,
  259. 0x21, 0x80,
  260. 0x22, 0xFF,
  261. 0x23, 0xC1,
  262. 0x28, 0x00,
  263. 0x29, 0x1E,
  264. 0x2A, 0x14,
  265. 0x2B, 0x0F,
  266. 0x2C, 0x09,
  267. 0x2D, 0x05,
  268. 0x31, 0x1F,
  269. 0x32, 0x19,
  270. 0x33, 0xFE,
  271. 0x34, 0x93,
  272. 0xff, 0xff,
  273. };
  274. static struct stv0299_config samsung_tbmu24112_config = {
  275. .demod_address = 0x68,
  276. .inittab = samsung_tbmu24112_inittab,
  277. .mclk = 88000000UL,
  278. .invert = 0,
  279. .skip_reinit = 0,
  280. .lock_output = STV0299_LOCKOUTPUT_LK,
  281. .volt13_op0_op1 = STV0299_VOLT13_OP1,
  282. .min_delay_ms = 100,
  283. .set_symbol_rate = samsung_tbmu24112_set_symbol_rate,
  284. };
  285. static int skystar2_rev26_attach(struct flexcop_device *fc,
  286. struct i2c_adapter *i2c)
  287. {
  288. fc->fe = dvb_attach(stv0299_attach, &samsung_tbmu24112_config, i2c);
  289. if (fc->fe != NULL) {
  290. struct dvb_frontend_ops *ops = &fc->fe->ops;
  291. ops->tuner_ops.set_params = samsung_tbmu24112_tuner_set_params;
  292. ops->set_voltage = flexcop_set_voltage;
  293. fc->fe_sleep = ops->sleep;
  294. ops->sleep = flexcop_sleep;
  295. return 1;
  296. }
  297. return 0;
  298. }
  299. #else
  300. #define skystar2_rev26_attach NULL
  301. #endif
  302. /* SkyStar2 DVB-S rev 2.7 */
  303. #if FE_SUPPORTED(S5H1420) && FE_SUPPORTED(ISL6421) && FE_SUPPORTED(TUNER_ITD1000)
  304. static struct s5h1420_config skystar2_rev2_7_s5h1420_config = {
  305. .demod_address = 0x53,
  306. .invert = 1,
  307. .repeated_start_workaround = 1,
  308. .serial_mpeg = 1,
  309. };
  310. static struct itd1000_config skystar2_rev2_7_itd1000_config = {
  311. .i2c_address = 0x61,
  312. };
  313. static int skystar2_rev27_attach(struct flexcop_device *fc,
  314. struct i2c_adapter *i2c)
  315. {
  316. flexcop_ibi_value r108;
  317. struct i2c_adapter *i2c_tuner;
  318. /* enable no_base_addr - no repeated start when reading */
  319. fc->fc_i2c_adap[0].no_base_addr = 1;
  320. fc->fe = dvb_attach(s5h1420_attach, &skystar2_rev2_7_s5h1420_config,
  321. i2c);
  322. if (!fc->fe)
  323. goto fail;
  324. i2c_tuner = s5h1420_get_tuner_i2c_adapter(fc->fe);
  325. if (!i2c_tuner)
  326. goto fail;
  327. fc->fe_sleep = fc->fe->ops.sleep;
  328. fc->fe->ops.sleep = flexcop_sleep;
  329. /* enable no_base_addr - no repeated start when reading */
  330. fc->fc_i2c_adap[2].no_base_addr = 1;
  331. if (!dvb_attach(isl6421_attach, fc->fe, &fc->fc_i2c_adap[2].i2c_adap,
  332. 0x08, 1, 1)) {
  333. err("ISL6421 could NOT be attached");
  334. goto fail_isl;
  335. }
  336. info("ISL6421 successfully attached");
  337. /* the ITD1000 requires a lower i2c clock - is it a problem ? */
  338. r108.raw = 0x00000506;
  339. fc->write_ibi_reg(fc, tw_sm_c_108, r108);
  340. if (!dvb_attach(itd1000_attach, fc->fe, i2c_tuner,
  341. &skystar2_rev2_7_itd1000_config)) {
  342. err("ITD1000 could NOT be attached");
  343. /* Should i2c clock be restored? */
  344. goto fail_isl;
  345. }
  346. info("ITD1000 successfully attached");
  347. return 1;
  348. fail_isl:
  349. fc->fc_i2c_adap[2].no_base_addr = 0;
  350. fail:
  351. /* for the next devices we need it again */
  352. fc->fc_i2c_adap[0].no_base_addr = 0;
  353. return 0;
  354. }
  355. #else
  356. #define skystar2_rev27_attach NULL
  357. #endif
  358. /* SkyStar2 rev 2.8 */
  359. #if FE_SUPPORTED(CX24123) && FE_SUPPORTED(ISL6421) && FE_SUPPORTED(TUNER_CX24113)
  360. static struct cx24123_config skystar2_rev2_8_cx24123_config = {
  361. .demod_address = 0x55,
  362. .dont_use_pll = 1,
  363. .agc_callback = cx24113_agc_callback,
  364. };
  365. static const struct cx24113_config skystar2_rev2_8_cx24113_config = {
  366. .i2c_addr = 0x54,
  367. .xtal_khz = 10111,
  368. };
  369. static int skystar2_rev28_attach(struct flexcop_device *fc,
  370. struct i2c_adapter *i2c)
  371. {
  372. struct i2c_adapter *i2c_tuner;
  373. fc->fe = dvb_attach(cx24123_attach, &skystar2_rev2_8_cx24123_config,
  374. i2c);
  375. if (!fc->fe)
  376. return 0;
  377. i2c_tuner = cx24123_get_tuner_i2c_adapter(fc->fe);
  378. if (!i2c_tuner)
  379. return 0;
  380. if (!dvb_attach(cx24113_attach, fc->fe, &skystar2_rev2_8_cx24113_config,
  381. i2c_tuner)) {
  382. err("CX24113 could NOT be attached");
  383. return 0;
  384. }
  385. info("CX24113 successfully attached");
  386. fc->fc_i2c_adap[2].no_base_addr = 1;
  387. if (!dvb_attach(isl6421_attach, fc->fe, &fc->fc_i2c_adap[2].i2c_adap,
  388. 0x08, 0, 0)) {
  389. err("ISL6421 could NOT be attached");
  390. fc->fc_i2c_adap[2].no_base_addr = 0;
  391. return 0;
  392. }
  393. info("ISL6421 successfully attached");
  394. /* TODO on i2c_adap[1] addr 0x11 (EEPROM) there seems to be an
  395. * IR-receiver (PIC16F818) - but the card has no input for that ??? */
  396. return 1;
  397. }
  398. #else
  399. #define skystar2_rev28_attach NULL
  400. #endif
  401. /* AirStar DVB-T */
  402. #if FE_SUPPORTED(MT352)
  403. static int samsung_tdtc9251dh0_demod_init(struct dvb_frontend *fe)
  404. {
  405. static u8 mt352_clock_config[] = { 0x89, 0x18, 0x2d };
  406. static u8 mt352_reset[] = { 0x50, 0x80 };
  407. static u8 mt352_adc_ctl_1_cfg[] = { 0x8E, 0x40 };
  408. static u8 mt352_agc_cfg[] = { 0x67, 0x28, 0xa1 };
  409. static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 };
  410. mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config));
  411. udelay(2000);
  412. mt352_write(fe, mt352_reset, sizeof(mt352_reset));
  413. mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg));
  414. mt352_write(fe, mt352_agc_cfg, sizeof(mt352_agc_cfg));
  415. mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg));
  416. return 0;
  417. }
  418. static int samsung_tdtc9251dh0_calc_regs(struct dvb_frontend *fe,
  419. struct dvb_frontend_parameters *params, u8* pllbuf, int buf_len)
  420. {
  421. u32 div;
  422. unsigned char bs = 0;
  423. if (buf_len < 5)
  424. return -EINVAL;
  425. #define IF_FREQUENCYx6 217 /* 6 * 36.16666666667MHz */
  426. div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6;
  427. if (params->frequency >= 48000000 && params->frequency <= 154000000) \
  428. bs = 0x09;
  429. if (params->frequency >= 161000000 && params->frequency <= 439000000) \
  430. bs = 0x0a;
  431. if (params->frequency >= 447000000 && params->frequency <= 863000000) \
  432. bs = 0x08;
  433. pllbuf[0] = 0x61;
  434. pllbuf[1] = div >> 8;
  435. pllbuf[2] = div & 0xff;
  436. pllbuf[3] = 0xcc;
  437. pllbuf[4] = bs;
  438. return 5;
  439. }
  440. static struct mt352_config samsung_tdtc9251dh0_config = {
  441. .demod_address = 0x0f,
  442. .demod_init = samsung_tdtc9251dh0_demod_init,
  443. };
  444. static int airstar_dvbt_attach(struct flexcop_device *fc,
  445. struct i2c_adapter *i2c)
  446. {
  447. fc->fe = dvb_attach(mt352_attach, &samsung_tdtc9251dh0_config, i2c);
  448. if (fc->fe != NULL) {
  449. fc->fe->ops.tuner_ops.calc_regs = samsung_tdtc9251dh0_calc_regs;
  450. return 1;
  451. }
  452. return 0;
  453. }
  454. #else
  455. #define airstar_dvbt_attach NULL
  456. #endif
  457. /* AirStar ATSC 1st generation */
  458. #if FE_SUPPORTED(BCM3510)
  459. static int flexcop_fe_request_firmware(struct dvb_frontend *fe,
  460. const struct firmware **fw, char* name)
  461. {
  462. struct flexcop_device *fc = fe->dvb->priv;
  463. return request_firmware(fw, name, fc->dev);
  464. }
  465. static struct bcm3510_config air2pc_atsc_first_gen_config = {
  466. .demod_address = 0x0f,
  467. .request_firmware = flexcop_fe_request_firmware,
  468. };
  469. static int airstar_atsc1_attach(struct flexcop_device *fc,
  470. struct i2c_adapter *i2c)
  471. {
  472. fc->fe = dvb_attach(bcm3510_attach, &air2pc_atsc_first_gen_config, i2c);
  473. return fc->fe != NULL;
  474. }
  475. #else
  476. #define airstar_atsc1_attach NULL
  477. #endif
  478. /* AirStar ATSC 2nd generation */
  479. #if FE_SUPPORTED(NXT200X) && FE_SUPPORTED(PLL)
  480. static struct nxt200x_config samsung_tbmv_config = {
  481. .demod_address = 0x0a,
  482. };
  483. static int airstar_atsc2_attach(struct flexcop_device *fc,
  484. struct i2c_adapter *i2c)
  485. {
  486. fc->fe = dvb_attach(nxt200x_attach, &samsung_tbmv_config, i2c);
  487. if (!fc->fe)
  488. return 0;
  489. return !!dvb_attach(dvb_pll_attach, fc->fe, 0x61, NULL,
  490. DVB_PLL_SAMSUNG_TBMV);
  491. }
  492. #else
  493. #define airstar_atsc2_attach NULL
  494. #endif
  495. /* AirStar ATSC 3rd generation */
  496. #if FE_SUPPORTED(LGDT330X)
  497. static struct lgdt330x_config air2pc_atsc_hd5000_config = {
  498. .demod_address = 0x59,
  499. .demod_chip = LGDT3303,
  500. .serial_mpeg = 0x04,
  501. .clock_polarity_flip = 1,
  502. };
  503. static int airstar_atsc3_attach(struct flexcop_device *fc,
  504. struct i2c_adapter *i2c)
  505. {
  506. fc->fe = dvb_attach(lgdt330x_attach, &air2pc_atsc_hd5000_config, i2c);
  507. if (!fc->fe)
  508. return 0;
  509. return !!dvb_attach(simple_tuner_attach, fc->fe, i2c, 0x61,
  510. TUNER_LG_TDVS_H06XF);
  511. }
  512. #else
  513. #define airstar_atsc3_attach NULL
  514. #endif
  515. /* CableStar2 DVB-C */
  516. #if FE_SUPPORTED(STV0297)
  517. static int alps_tdee4_stv0297_tuner_set_params(struct dvb_frontend* fe,
  518. struct dvb_frontend_parameters *fep)
  519. {
  520. struct flexcop_device *fc = fe->dvb->priv;
  521. u8 buf[4];
  522. u16 div;
  523. int ret;
  524. /* 62.5 kHz * 10 */
  525. #define REF_FREQ 625
  526. #define FREQ_OFFSET 36125
  527. div = ((fep->frequency/1000 + FREQ_OFFSET) * 10) / REF_FREQ;
  528. /* 4 MHz = 4000 KHz */
  529. buf[0] = (u8)( div >> 8) & 0x7f;
  530. buf[1] = (u8) div & 0xff;
  531. /* F(osc) = N * Reference Freq. (62.5 kHz)
  532. * byte 2 : 0 N14 N13 N12 N11 N10 N9 N8
  533. * byte 3 : N7 N6 N5 N4 N3 N2 N1 N0
  534. * byte 4 : 1 * * AGD R3 R2 R1 R0
  535. * byte 5 : C1 * RE RTS BS4 BS3 BS2 BS1
  536. * AGD = 1, R3 R2 R1 R0 = 0 1 0 1 => byte 4 = 1**10101 = 0x95 */
  537. buf[2] = 0x95;
  538. /* Range(MHz) C1 * RE RTS BS4 BS3 BS2 BS1 Byte 5
  539. * 47 - 153 0 * 0 0 0 0 0 1 0x01
  540. * 153 - 430 0 * 0 0 0 0 1 0 0x02
  541. * 430 - 822 0 * 0 0 1 0 0 0 0x08
  542. * 822 - 862 1 * 0 0 1 0 0 0 0x88 */
  543. if (fep->frequency <= 153000000) buf[3] = 0x01;
  544. else if (fep->frequency <= 430000000) buf[3] = 0x02;
  545. else if (fep->frequency <= 822000000) buf[3] = 0x08;
  546. else buf[3] = 0x88;
  547. if (fe->ops.i2c_gate_ctrl)
  548. fe->ops.i2c_gate_ctrl(fe, 0);
  549. deb_tuner("tuner buffer for %d Hz: %x %x %x %x\n", fep->frequency,
  550. buf[0], buf[1], buf[2], buf[3]);
  551. ret = fc->i2c_request(&fc->fc_i2c_adap[2],
  552. FC_WRITE, 0x61, buf[0], &buf[1], 3);
  553. deb_tuner("tuner write returned: %d\n",ret);
  554. return ret;
  555. }
  556. static u8 alps_tdee4_stv0297_inittab[] = {
  557. 0x80, 0x01,
  558. 0x80, 0x00,
  559. 0x81, 0x01,
  560. 0x81, 0x00,
  561. 0x00, 0x48,
  562. 0x01, 0x58,
  563. 0x03, 0x00,
  564. 0x04, 0x00,
  565. 0x07, 0x00,
  566. 0x08, 0x00,
  567. 0x30, 0xff,
  568. 0x31, 0x9d,
  569. 0x32, 0xff,
  570. 0x33, 0x00,
  571. 0x34, 0x29,
  572. 0x35, 0x55,
  573. 0x36, 0x80,
  574. 0x37, 0x6e,
  575. 0x38, 0x9c,
  576. 0x40, 0x1a,
  577. 0x41, 0xfe,
  578. 0x42, 0x33,
  579. 0x43, 0x00,
  580. 0x44, 0xff,
  581. 0x45, 0x00,
  582. 0x46, 0x00,
  583. 0x49, 0x04,
  584. 0x4a, 0x51,
  585. 0x4b, 0xf8,
  586. 0x52, 0x30,
  587. 0x53, 0x06,
  588. 0x59, 0x06,
  589. 0x5a, 0x5e,
  590. 0x5b, 0x04,
  591. 0x61, 0x49,
  592. 0x62, 0x0a,
  593. 0x70, 0xff,
  594. 0x71, 0x04,
  595. 0x72, 0x00,
  596. 0x73, 0x00,
  597. 0x74, 0x0c,
  598. 0x80, 0x20,
  599. 0x81, 0x00,
  600. 0x82, 0x30,
  601. 0x83, 0x00,
  602. 0x84, 0x04,
  603. 0x85, 0x22,
  604. 0x86, 0x08,
  605. 0x87, 0x1b,
  606. 0x88, 0x00,
  607. 0x89, 0x00,
  608. 0x90, 0x00,
  609. 0x91, 0x04,
  610. 0xa0, 0x86,
  611. 0xa1, 0x00,
  612. 0xa2, 0x00,
  613. 0xb0, 0x91,
  614. 0xb1, 0x0b,
  615. 0xc0, 0x5b,
  616. 0xc1, 0x10,
  617. 0xc2, 0x12,
  618. 0xd0, 0x02,
  619. 0xd1, 0x00,
  620. 0xd2, 0x00,
  621. 0xd3, 0x00,
  622. 0xd4, 0x02,
  623. 0xd5, 0x00,
  624. 0xde, 0x00,
  625. 0xdf, 0x01,
  626. 0xff, 0xff,
  627. };
  628. static struct stv0297_config alps_tdee4_stv0297_config = {
  629. .demod_address = 0x1c,
  630. .inittab = alps_tdee4_stv0297_inittab,
  631. };
  632. static int cablestar2_attach(struct flexcop_device *fc,
  633. struct i2c_adapter *i2c)
  634. {
  635. fc->fc_i2c_adap[0].no_base_addr = 1;
  636. fc->fe = dvb_attach(stv0297_attach, &alps_tdee4_stv0297_config, i2c);
  637. if (!fc->fe) {
  638. /* Reset for next frontend to try */
  639. fc->fc_i2c_adap[0].no_base_addr = 0;
  640. return 0;
  641. }
  642. fc->fe->ops.tuner_ops.set_params = alps_tdee4_stv0297_tuner_set_params;
  643. return 1;
  644. }
  645. #else
  646. #define cablestar2_attach NULL
  647. #endif
  648. static struct {
  649. flexcop_device_type_t type;
  650. int (*attach)(struct flexcop_device *, struct i2c_adapter *);
  651. } flexcop_frontends[] = {
  652. { FC_SKY_REV27, skystar2_rev27_attach },
  653. { FC_SKY_REV28, skystar2_rev28_attach },
  654. { FC_SKY_REV26, skystar2_rev26_attach },
  655. { FC_AIR_DVBT, airstar_dvbt_attach },
  656. { FC_AIR_ATSC2, airstar_atsc2_attach },
  657. { FC_AIR_ATSC3, airstar_atsc3_attach },
  658. { FC_AIR_ATSC1, airstar_atsc1_attach },
  659. { FC_CABLE, cablestar2_attach },
  660. { FC_SKY_REV23, skystar2_rev23_attach },
  661. };
  662. /* try to figure out the frontend */
  663. int flexcop_frontend_init(struct flexcop_device *fc)
  664. {
  665. int i;
  666. for (i = 0; i < ARRAY_SIZE(flexcop_frontends); i++) {
  667. if (!flexcop_frontends[i].attach)
  668. continue;
  669. /* type needs to be set before, because of some workarounds
  670. * done based on the probed card type */
  671. fc->dev_type = flexcop_frontends[i].type;
  672. if (flexcop_frontends[i].attach(fc, &fc->fc_i2c_adap[0].i2c_adap))
  673. goto fe_found;
  674. /* Clean up partially attached frontend */
  675. if (fc->fe) {
  676. dvb_frontend_detach(fc->fe);
  677. fc->fe = NULL;
  678. }
  679. }
  680. fc->dev_type = FC_UNK;
  681. err("no frontend driver found for this B2C2/FlexCop adapter");
  682. return -ENODEV;
  683. fe_found:
  684. info("found '%s' .", fc->fe->ops.info.name);
  685. if (dvb_register_frontend(&fc->dvb_adapter, fc->fe)) {
  686. err("frontend registration failed!");
  687. dvb_frontend_detach(fc->fe);
  688. fc->fe = NULL;
  689. return -EINVAL;
  690. }
  691. fc->init_state |= FC_STATE_FE_INIT;
  692. return 0;
  693. }
  694. void flexcop_frontend_exit(struct flexcop_device *fc)
  695. {
  696. if (fc->init_state & FC_STATE_FE_INIT) {
  697. dvb_unregister_frontend(fc->fe);
  698. dvb_frontend_detach(fc->fe);
  699. }
  700. fc->init_state &= ~FC_STATE_FE_INIT;
  701. }