flexcop-fe-tuner.c 18 KB

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