flexcop-fe-tuner.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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 int skystar2_rev23_attach(struct flexcop_device *fc,
  159. struct i2c_adapter *i2c)
  160. {
  161. fc->fe = dvb_attach(mt312_attach, &skystar23_samsung_tbdu18132_config, i2c);
  162. if (fc->fe != NULL) {
  163. struct dvb_frontend_ops *ops = &fc->fe->ops;
  164. ops->tuner_ops.set_params =
  165. skystar23_samsung_tbdu18132_tuner_set_params;
  166. ops->diseqc_send_master_cmd = flexcop_diseqc_send_master_cmd;
  167. ops->diseqc_send_burst = flexcop_diseqc_send_burst;
  168. ops->set_tone = flexcop_set_tone;
  169. ops->set_voltage = flexcop_set_voltage;
  170. fc->fe_sleep = ops->sleep;
  171. ops->sleep = flexcop_sleep;
  172. return 1;
  173. }
  174. return 0;
  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 int 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. return 1;
  291. }
  292. return 0;
  293. }
  294. #endif
  295. /* SkyStar2 DVB-S rev 2.7 */
  296. #if defined(CONFIG_DVB_S5H1420_MODULE)
  297. static struct s5h1420_config skystar2_rev2_7_s5h1420_config = {
  298. .demod_address = 0x53,
  299. .invert = 1,
  300. .repeated_start_workaround = 1,
  301. .serial_mpeg = 1,
  302. };
  303. static struct itd1000_config skystar2_rev2_7_itd1000_config = {
  304. .i2c_address = 0x61,
  305. };
  306. static int skystar2_rev27_attach(struct flexcop_device *fc,
  307. struct i2c_adapter *i2c)
  308. {
  309. flexcop_ibi_value r108;
  310. struct i2c_adapter *i2c_tuner;
  311. /* enable no_base_addr - no repeated start when reading */
  312. fc->fc_i2c_adap[0].no_base_addr = 1;
  313. fc->fe = dvb_attach(s5h1420_attach, &skystar2_rev2_7_s5h1420_config,
  314. i2c);
  315. if (!fc->fe)
  316. goto fail;
  317. i2c_tuner = s5h1420_get_tuner_i2c_adapter(fc->fe);
  318. if (!i2c_tuner)
  319. goto fail;
  320. fc->fe_sleep = fc->fe->ops.sleep;
  321. fc->fe->ops.sleep = flexcop_sleep;
  322. /* enable no_base_addr - no repeated start when reading */
  323. fc->fc_i2c_adap[2].no_base_addr = 1;
  324. if (!dvb_attach(isl6421_attach, fc->fe, &fc->fc_i2c_adap[2].i2c_adap,
  325. 0x08, 1, 1)) {
  326. err("ISL6421 could NOT be attached");
  327. goto fail_isl;
  328. }
  329. info("ISL6421 successfully attached");
  330. /* the ITD1000 requires a lower i2c clock - is it a problem ? */
  331. r108.raw = 0x00000506;
  332. fc->write_ibi_reg(fc, tw_sm_c_108, r108);
  333. if (!dvb_attach(itd1000_attach, fc->fe, i2c_tuner,
  334. &skystar2_rev2_7_itd1000_config)) {
  335. err("ITD1000 could NOT be attached");
  336. /* Should i2c clock be restored? */
  337. goto fail_isl;
  338. }
  339. info("ITD1000 successfully attached");
  340. return 1;
  341. fail_isl:
  342. fc->fc_i2c_adap[2].no_base_addr = 0;
  343. fail:
  344. /* for the next devices we need it again */
  345. fc->fc_i2c_adap[0].no_base_addr = 0;
  346. return 0;
  347. }
  348. #endif
  349. /* SkyStar2 rev 2.8 */
  350. #if defined(CONFIG_DVB_CX24123_MODULE)
  351. static struct cx24123_config skystar2_rev2_8_cx24123_config = {
  352. .demod_address = 0x55,
  353. .dont_use_pll = 1,
  354. .agc_callback = cx24113_agc_callback,
  355. };
  356. static const struct cx24113_config skystar2_rev2_8_cx24113_config = {
  357. .i2c_addr = 0x54,
  358. .xtal_khz = 10111,
  359. };
  360. static int skystar2_rev28_attach(struct flexcop_device *fc,
  361. struct i2c_adapter *i2c)
  362. {
  363. struct i2c_adapter *i2c_tuner;
  364. fc->fe = dvb_attach(cx24123_attach, &skystar2_rev2_8_cx24123_config,
  365. i2c);
  366. if (!fc->fe)
  367. return 0;
  368. i2c_tuner = cx24123_get_tuner_i2c_adapter(fc->fe);;
  369. if (!i2c_tuner)
  370. return 0;
  371. if (!dvb_attach(cx24113_attach, fc->fe, &skystar2_rev2_8_cx24113_config,
  372. i2c_tuner)) {
  373. err("CX24113 could NOT be attached");
  374. return 0;
  375. }
  376. info("CX24113 successfully attached");
  377. fc->fc_i2c_adap[2].no_base_addr = 1;
  378. if (!dvb_attach(isl6421_attach, fc->fe, &fc->fc_i2c_adap[2].i2c_adap,
  379. 0x08, 0, 0)) {
  380. err("ISL6421 could NOT be attached");
  381. fc->fc_i2c_adap[2].no_base_addr = 0;
  382. return 0;
  383. }
  384. info("ISL6421 successfully attached");
  385. /* TODO on i2c_adap[1] addr 0x11 (EEPROM) there seems to be an
  386. * IR-receiver (PIC16F818) - but the card has no input for that ??? */
  387. return 1;
  388. }
  389. #endif
  390. /* AirStar DVB-T */
  391. #if defined(CONFIG_DVB_MT352_MODULE)
  392. static int samsung_tdtc9251dh0_demod_init(struct dvb_frontend *fe)
  393. {
  394. static u8 mt352_clock_config[] = { 0x89, 0x18, 0x2d };
  395. static u8 mt352_reset[] = { 0x50, 0x80 };
  396. static u8 mt352_adc_ctl_1_cfg[] = { 0x8E, 0x40 };
  397. static u8 mt352_agc_cfg[] = { 0x67, 0x28, 0xa1 };
  398. static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 };
  399. mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config));
  400. udelay(2000);
  401. mt352_write(fe, mt352_reset, sizeof(mt352_reset));
  402. mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg));
  403. mt352_write(fe, mt352_agc_cfg, sizeof(mt352_agc_cfg));
  404. mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg));
  405. return 0;
  406. }
  407. static int samsung_tdtc9251dh0_calc_regs(struct dvb_frontend *fe,
  408. struct dvb_frontend_parameters *params, u8* pllbuf, int buf_len)
  409. {
  410. u32 div;
  411. unsigned char bs = 0;
  412. if (buf_len < 5)
  413. return -EINVAL;
  414. #define IF_FREQUENCYx6 217 /* 6 * 36.16666666667MHz */
  415. div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6;
  416. if (params->frequency >= 48000000 && params->frequency <= 154000000) \
  417. bs = 0x09;
  418. if (params->frequency >= 161000000 && params->frequency <= 439000000) \
  419. bs = 0x0a;
  420. if (params->frequency >= 447000000 && params->frequency <= 863000000) \
  421. bs = 0x08;
  422. pllbuf[0] = 0x61;
  423. pllbuf[1] = div >> 8;
  424. pllbuf[2] = div & 0xff;
  425. pllbuf[3] = 0xcc;
  426. pllbuf[4] = bs;
  427. return 5;
  428. }
  429. static struct mt352_config samsung_tdtc9251dh0_config = {
  430. .demod_address = 0x0f,
  431. .demod_init = samsung_tdtc9251dh0_demod_init,
  432. };
  433. static int airstar_dvbt_attach(struct flexcop_device *fc,
  434. struct i2c_adapter *i2c)
  435. {
  436. fc->fe = dvb_attach(mt352_attach, &samsung_tdtc9251dh0_config, i2c);
  437. if (fc->fe != NULL) {
  438. fc->fe->ops.tuner_ops.calc_regs = samsung_tdtc9251dh0_calc_regs;
  439. return 1;
  440. }
  441. return 0;
  442. }
  443. #endif
  444. /* AirStar ATSC 1st generation */
  445. #if defined(CONFIG_DVB_BCM3510_MODULE)
  446. static int flexcop_fe_request_firmware(struct dvb_frontend *fe,
  447. const struct firmware **fw, char* name)
  448. {
  449. struct flexcop_device *fc = fe->dvb->priv;
  450. return request_firmware(fw, name, fc->dev);
  451. }
  452. static struct bcm3510_config air2pc_atsc_first_gen_config = {
  453. .demod_address = 0x0f,
  454. .request_firmware = flexcop_fe_request_firmware,
  455. };
  456. static int airstar_atsc1_attach(struct flexcop_device *fc,
  457. struct i2c_adapter *i2c)
  458. {
  459. fc->fe = dvb_attach(bcm3510_attach, &air2pc_atsc_first_gen_config, i2c);
  460. return fc->fe != NULL;
  461. }
  462. #endif
  463. /* AirStar ATSC 2nd generation */
  464. #if defined(CONFIG_DVB_NXT200X_MODULE)
  465. static struct nxt200x_config samsung_tbmv_config = {
  466. .demod_address = 0x0a,
  467. };
  468. static int airstar_atsc2_attach(struct flexcop_device *fc,
  469. struct i2c_adapter *i2c)
  470. {
  471. fc->fe = dvb_attach(nxt200x_attach, &samsung_tbmv_config, i2c);
  472. if (!fc->fe)
  473. return 0;
  474. return !!dvb_attach(dvb_pll_attach, fc->fe, 0x61, NULL,
  475. DVB_PLL_SAMSUNG_TBMV);
  476. }
  477. #endif
  478. /* AirStar ATSC 3rd generation */
  479. #if defined(CONFIG_DVB_LGDT330X_MODULE)
  480. static struct lgdt330x_config air2pc_atsc_hd5000_config = {
  481. .demod_address = 0x59,
  482. .demod_chip = LGDT3303,
  483. .serial_mpeg = 0x04,
  484. .clock_polarity_flip = 1,
  485. };
  486. static int airstar_atsc3_attach(struct flexcop_device *fc,
  487. struct i2c_adapter *i2c)
  488. {
  489. fc->fe = dvb_attach(lgdt330x_attach, &air2pc_atsc_hd5000_config, i2c);
  490. if (!fc->fe)
  491. return 0;
  492. return !!dvb_attach(simple_tuner_attach, fc->fe, i2c, 0x61,
  493. TUNER_LG_TDVS_H06XF);
  494. }
  495. #endif
  496. /* CableStar2 DVB-C */
  497. #if defined(CONFIG_DVB_STV0297_MODULE)
  498. static int alps_tdee4_stv0297_tuner_set_params(struct dvb_frontend* fe,
  499. struct dvb_frontend_parameters *fep)
  500. {
  501. struct flexcop_device *fc = fe->dvb->priv;
  502. u8 buf[4];
  503. u16 div;
  504. int ret;
  505. /* 62.5 kHz * 10 */
  506. #define REF_FREQ 625
  507. #define FREQ_OFFSET 36125
  508. div = ((fep->frequency/1000 + FREQ_OFFSET) * 10) / REF_FREQ;
  509. /* 4 MHz = 4000 KHz */
  510. buf[0] = (u8)( div >> 8) & 0x7f;
  511. buf[1] = (u8) div & 0xff;
  512. /* F(osc) = N * Reference Freq. (62.5 kHz)
  513. * byte 2 : 0 N14 N13 N12 N11 N10 N9 N8
  514. * byte 3 : N7 N6 N5 N4 N3 N2 N1 N0
  515. * byte 4 : 1 * * AGD R3 R2 R1 R0
  516. * byte 5 : C1 * RE RTS BS4 BS3 BS2 BS1
  517. * AGD = 1, R3 R2 R1 R0 = 0 1 0 1 => byte 4 = 1**10101 = 0x95 */
  518. buf[2] = 0x95;
  519. /* Range(MHz) C1 * RE RTS BS4 BS3 BS2 BS1 Byte 5
  520. * 47 - 153 0 * 0 0 0 0 0 1 0x01
  521. * 153 - 430 0 * 0 0 0 0 1 0 0x02
  522. * 430 - 822 0 * 0 0 1 0 0 0 0x08
  523. * 822 - 862 1 * 0 0 1 0 0 0 0x88 */
  524. if (fep->frequency <= 153000000) buf[3] = 0x01;
  525. else if (fep->frequency <= 430000000) buf[3] = 0x02;
  526. else if (fep->frequency <= 822000000) buf[3] = 0x08;
  527. else buf[3] = 0x88;
  528. if (fe->ops.i2c_gate_ctrl)
  529. fe->ops.i2c_gate_ctrl(fe, 0);
  530. deb_tuner("tuner buffer for %d Hz: %x %x %x %x\n", fep->frequency,
  531. buf[0], buf[1], buf[2], buf[3]);
  532. ret = fc->i2c_request(&fc->fc_i2c_adap[2],
  533. FC_WRITE, 0x61, buf[0], &buf[1], 3);
  534. deb_tuner("tuner write returned: %d\n",ret);
  535. return ret;
  536. }
  537. static u8 alps_tdee4_stv0297_inittab[] = {
  538. 0x80, 0x01,
  539. 0x80, 0x00,
  540. 0x81, 0x01,
  541. 0x81, 0x00,
  542. 0x00, 0x48,
  543. 0x01, 0x58,
  544. 0x03, 0x00,
  545. 0x04, 0x00,
  546. 0x07, 0x00,
  547. 0x08, 0x00,
  548. 0x30, 0xff,
  549. 0x31, 0x9d,
  550. 0x32, 0xff,
  551. 0x33, 0x00,
  552. 0x34, 0x29,
  553. 0x35, 0x55,
  554. 0x36, 0x80,
  555. 0x37, 0x6e,
  556. 0x38, 0x9c,
  557. 0x40, 0x1a,
  558. 0x41, 0xfe,
  559. 0x42, 0x33,
  560. 0x43, 0x00,
  561. 0x44, 0xff,
  562. 0x45, 0x00,
  563. 0x46, 0x00,
  564. 0x49, 0x04,
  565. 0x4a, 0x51,
  566. 0x4b, 0xf8,
  567. 0x52, 0x30,
  568. 0x53, 0x06,
  569. 0x59, 0x06,
  570. 0x5a, 0x5e,
  571. 0x5b, 0x04,
  572. 0x61, 0x49,
  573. 0x62, 0x0a,
  574. 0x70, 0xff,
  575. 0x71, 0x04,
  576. 0x72, 0x00,
  577. 0x73, 0x00,
  578. 0x74, 0x0c,
  579. 0x80, 0x20,
  580. 0x81, 0x00,
  581. 0x82, 0x30,
  582. 0x83, 0x00,
  583. 0x84, 0x04,
  584. 0x85, 0x22,
  585. 0x86, 0x08,
  586. 0x87, 0x1b,
  587. 0x88, 0x00,
  588. 0x89, 0x00,
  589. 0x90, 0x00,
  590. 0x91, 0x04,
  591. 0xa0, 0x86,
  592. 0xa1, 0x00,
  593. 0xa2, 0x00,
  594. 0xb0, 0x91,
  595. 0xb1, 0x0b,
  596. 0xc0, 0x5b,
  597. 0xc1, 0x10,
  598. 0xc2, 0x12,
  599. 0xd0, 0x02,
  600. 0xd1, 0x00,
  601. 0xd2, 0x00,
  602. 0xd3, 0x00,
  603. 0xd4, 0x02,
  604. 0xd5, 0x00,
  605. 0xde, 0x00,
  606. 0xdf, 0x01,
  607. 0xff, 0xff,
  608. };
  609. static struct stv0297_config alps_tdee4_stv0297_config = {
  610. .demod_address = 0x1c,
  611. .inittab = alps_tdee4_stv0297_inittab,
  612. };
  613. static int cablestar2_attach(struct flexcop_device *fc,
  614. struct i2c_adapter *i2c)
  615. {
  616. fc->fc_i2c_adap[0].no_base_addr = 1;
  617. fc->fe = dvb_attach(stv0297_attach, &alps_tdee4_stv0297_config, i2c);
  618. if (!fc->fe) {
  619. /* Reset for next frontend to try */
  620. fc->fc_i2c_adap[0].no_base_addr = 0;
  621. return 0;
  622. }
  623. fc->fe->ops.tuner_ops.set_params = alps_tdee4_stv0297_tuner_set_params;
  624. return 1;
  625. }
  626. #endif
  627. static struct {
  628. flexcop_device_type_t type;
  629. int (*attach)(struct flexcop_device *, struct i2c_adapter *);
  630. } flexcop_frontends[] = {
  631. #if defined(CONFIG_DVB_S5H1420_MODULE)
  632. { FC_SKY_REV27, skystar2_rev27_attach },
  633. #endif
  634. #if defined(CONFIG_DVB_CX24123_MODULE)
  635. { FC_SKY_REV28, skystar2_rev28_attach },
  636. #endif
  637. #if defined(CONFIG_DVB_STV0299_MODULE)
  638. { FC_SKY_REV26, skystar2_rev26_attach },
  639. #endif
  640. #if defined(CONFIG_DVB_MT352_MODULE)
  641. { FC_AIR_DVBT, airstar_dvbt_attach },
  642. #endif
  643. #if defined(CONFIG_DVB_NXT200X_MODULE)
  644. { FC_AIR_ATSC2, airstar_atsc2_attach },
  645. #endif
  646. #if defined(CONFIG_DVB_LGDT330X_MODULE)
  647. { FC_AIR_ATSC3, airstar_atsc3_attach },
  648. #endif
  649. #if defined(CONFIG_DVB_BCM3510_MODULE)
  650. { FC_AIR_ATSC1, airstar_atsc1_attach },
  651. #endif
  652. #if defined(CONFIG_DVB_STV0297_MODULE)
  653. { FC_CABLE, cablestar2_attach },
  654. #endif
  655. #if defined(CONFIG_DVB_MT312_MODULE)
  656. { FC_SKY_REV23, skystar2_rev23_attach },
  657. #endif
  658. };
  659. /* try to figure out the frontend */
  660. int flexcop_frontend_init(struct flexcop_device *fc)
  661. {
  662. int i;
  663. for (i = 0; i < ARRAY_SIZE(flexcop_frontends); i++) {
  664. /* type needs to be set before, because of some workarounds
  665. * done based on the probed card type */
  666. fc->dev_type = flexcop_frontends[i].type;
  667. if (flexcop_frontends[i].attach(fc, &fc->fc_i2c_adap[0].i2c_adap))
  668. goto fe_found;
  669. /* Clean up partially attached frontend */
  670. if (fc->fe) {
  671. dvb_frontend_detach(fc->fe);
  672. fc->fe = NULL;
  673. }
  674. }
  675. fc->dev_type = FC_UNK;
  676. err("no frontend driver found for this B2C2/FlexCop adapter");
  677. return -ENODEV;
  678. fe_found:
  679. info("found '%s' .", fc->fe->ops.info.name);
  680. if (dvb_register_frontend(&fc->dvb_adapter, fc->fe)) {
  681. err("frontend registration failed!");
  682. dvb_frontend_detach(fc->fe);
  683. fc->fe = NULL;
  684. return -EINVAL;
  685. }
  686. fc->init_state |= FC_STATE_FE_INIT;
  687. return 0;
  688. }
  689. void flexcop_frontend_exit(struct flexcop_device *fc)
  690. {
  691. if (fc->init_state & FC_STATE_FE_INIT) {
  692. dvb_unregister_frontend(fc->fe);
  693. dvb_frontend_detach(fc->fe);
  694. }
  695. fc->init_state &= ~FC_STATE_FE_INIT;
  696. }