lg2160.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458
  1. /*
  2. * Support for LG2160 - ATSC/MH
  3. *
  4. * Copyright (C) 2010 Michael Krufky <mkrufky@linuxtv.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. *
  20. */
  21. #include <linux/jiffies.h>
  22. #include <linux/dvb/frontend.h>
  23. #include "lg2160.h"
  24. static int debug;
  25. module_param(debug, int, 0644);
  26. MODULE_PARM_DESC(debug, "set debug level (info=1, reg=2 (or-able))");
  27. #define DBG_INFO 1
  28. #define DBG_REG 2
  29. #define lg_printk(kern, fmt, arg...) \
  30. printk(kern "%s: " fmt, __func__, ##arg)
  31. #define lg_info(fmt, arg...) printk(KERN_INFO "lg2160: " fmt, ##arg)
  32. #define lg_warn(fmt, arg...) lg_printk(KERN_WARNING, fmt, ##arg)
  33. #define lg_err(fmt, arg...) lg_printk(KERN_ERR, fmt, ##arg)
  34. #define lg_dbg(fmt, arg...) if (debug & DBG_INFO) \
  35. lg_printk(KERN_DEBUG, fmt, ##arg)
  36. #define lg_reg(fmt, arg...) if (debug & DBG_REG) \
  37. lg_printk(KERN_DEBUG, fmt, ##arg)
  38. #define lg_fail(ret) \
  39. ({ \
  40. int __ret; \
  41. __ret = (ret < 0); \
  42. if (__ret) \
  43. lg_err("error %d on line %d\n", ret, __LINE__); \
  44. __ret; \
  45. })
  46. struct lg216x_state {
  47. struct i2c_adapter *i2c_adap;
  48. const struct lg2160_config *cfg;
  49. struct dvb_frontend frontend;
  50. u32 current_frequency;
  51. u8 parade_id;
  52. u8 fic_ver;
  53. unsigned int last_reset;
  54. };
  55. /* ------------------------------------------------------------------------ */
  56. static int lg216x_write_reg(struct lg216x_state *state, u16 reg, u8 val)
  57. {
  58. int ret;
  59. u8 buf[] = { reg >> 8, reg & 0xff, val };
  60. struct i2c_msg msg = {
  61. .addr = state->cfg->i2c_addr, .flags = 0,
  62. .buf = buf, .len = 3,
  63. };
  64. lg_reg("reg: 0x%04x, val: 0x%02x\n", reg, val);
  65. ret = i2c_transfer(state->i2c_adap, &msg, 1);
  66. if (ret != 1) {
  67. lg_err("error (addr %02x %02x <- %02x, err = %i)\n",
  68. msg.buf[0], msg.buf[1], msg.buf[2], ret);
  69. if (ret < 0)
  70. return ret;
  71. else
  72. return -EREMOTEIO;
  73. }
  74. return 0;
  75. }
  76. static int lg216x_read_reg(struct lg216x_state *state, u16 reg, u8 *val)
  77. {
  78. int ret;
  79. u8 reg_buf[] = { reg >> 8, reg & 0xff };
  80. struct i2c_msg msg[] = {
  81. { .addr = state->cfg->i2c_addr,
  82. .flags = 0, .buf = reg_buf, .len = 2 },
  83. { .addr = state->cfg->i2c_addr,
  84. .flags = I2C_M_RD, .buf = val, .len = 1 },
  85. };
  86. lg_reg("reg: 0x%04x\n", reg);
  87. ret = i2c_transfer(state->i2c_adap, msg, 2);
  88. if (ret != 2) {
  89. lg_err("error (addr %02x reg %04x error (ret == %i)\n",
  90. state->cfg->i2c_addr, reg, ret);
  91. if (ret < 0)
  92. return ret;
  93. else
  94. return -EREMOTEIO;
  95. }
  96. return 0;
  97. }
  98. struct lg216x_reg {
  99. u16 reg;
  100. u8 val;
  101. };
  102. static int lg216x_write_regs(struct lg216x_state *state,
  103. struct lg216x_reg *regs, int len)
  104. {
  105. int i, ret;
  106. lg_reg("writing %d registers...\n", len);
  107. for (i = 0; i < len; i++) {
  108. ret = lg216x_write_reg(state, regs[i].reg, regs[i].val);
  109. if (lg_fail(ret))
  110. return ret;
  111. }
  112. return 0;
  113. }
  114. static int lg216x_set_reg_bit(struct lg216x_state *state,
  115. u16 reg, int bit, int onoff)
  116. {
  117. u8 val;
  118. int ret;
  119. lg_reg("reg: 0x%04x, bit: %d, level: %d\n", reg, bit, onoff);
  120. ret = lg216x_read_reg(state, reg, &val);
  121. if (lg_fail(ret))
  122. goto fail;
  123. val &= ~(1 << bit);
  124. val |= (onoff & 1) << bit;
  125. ret = lg216x_write_reg(state, reg, val);
  126. lg_fail(ret);
  127. fail:
  128. return ret;
  129. }
  130. /* ------------------------------------------------------------------------ */
  131. static int lg216x_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
  132. {
  133. struct lg216x_state *state = fe->demodulator_priv;
  134. int ret;
  135. if (state->cfg->deny_i2c_rptr)
  136. return 0;
  137. lg_dbg("(%d)\n", enable);
  138. ret = lg216x_set_reg_bit(state, 0x0000, 0, enable ? 0 : 1);
  139. msleep(1);
  140. return ret;
  141. }
  142. static int lg216x_soft_reset(struct lg216x_state *state)
  143. {
  144. int ret;
  145. lg_dbg("\n");
  146. ret = lg216x_write_reg(state, 0x0002, 0x00);
  147. if (lg_fail(ret))
  148. goto fail;
  149. msleep(20);
  150. ret = lg216x_write_reg(state, 0x0002, 0x01);
  151. if (lg_fail(ret))
  152. goto fail;
  153. state->last_reset = jiffies_to_msecs(jiffies);
  154. fail:
  155. return ret;
  156. }
  157. static int lg216x_initialize(struct lg216x_state *state)
  158. {
  159. int ret;
  160. static struct lg216x_reg lg2160_init[] = {
  161. #if 0
  162. { .reg = 0x0015, .val = 0xe6 },
  163. #else
  164. { .reg = 0x0015, .val = 0xf7 },
  165. { .reg = 0x001b, .val = 0x52 },
  166. { .reg = 0x0208, .val = 0x00 },
  167. { .reg = 0x0209, .val = 0x82 },
  168. { .reg = 0x0210, .val = 0xf9 },
  169. { .reg = 0x020a, .val = 0x00 },
  170. { .reg = 0x020b, .val = 0x82 },
  171. { .reg = 0x020d, .val = 0x28 },
  172. { .reg = 0x020f, .val = 0x14 },
  173. #endif
  174. };
  175. static struct lg216x_reg lg2161_init[] = {
  176. { .reg = 0x0000, .val = 0x41 },
  177. { .reg = 0x0001, .val = 0xfb },
  178. { .reg = 0x0216, .val = 0x00 },
  179. { .reg = 0x0219, .val = 0x00 },
  180. { .reg = 0x021b, .val = 0x55 },
  181. { .reg = 0x0606, .val = 0x0a },
  182. };
  183. switch (state->cfg->lg_chip) {
  184. case LG2160:
  185. ret = lg216x_write_regs(state,
  186. lg2160_init, ARRAY_SIZE(lg2160_init));
  187. break;
  188. case LG2161:
  189. ret = lg216x_write_regs(state,
  190. lg2161_init, ARRAY_SIZE(lg2161_init));
  191. break;
  192. default:
  193. ret = -EINVAL;
  194. break;
  195. }
  196. if (lg_fail(ret))
  197. goto fail;
  198. ret = lg216x_soft_reset(state);
  199. lg_fail(ret);
  200. fail:
  201. return ret;
  202. }
  203. /* ------------------------------------------------------------------------ */
  204. static int lg216x_set_if(struct lg216x_state *state)
  205. {
  206. u8 val;
  207. int ret;
  208. lg_dbg("%d KHz\n", state->cfg->if_khz);
  209. ret = lg216x_read_reg(state, 0x0132, &val);
  210. if (lg_fail(ret))
  211. goto fail;
  212. val &= 0xfb;
  213. val |= (0 == state->cfg->if_khz) ? 0x04 : 0x00;
  214. ret = lg216x_write_reg(state, 0x0132, val);
  215. lg_fail(ret);
  216. /* if NOT zero IF, 6 MHz is the default */
  217. fail:
  218. return ret;
  219. }
  220. /* ------------------------------------------------------------------------ */
  221. static int lg2160_agc_fix(struct lg216x_state *state,
  222. int if_agc_fix, int rf_agc_fix)
  223. {
  224. u8 val;
  225. int ret;
  226. ret = lg216x_read_reg(state, 0x0100, &val);
  227. if (lg_fail(ret))
  228. goto fail;
  229. val &= 0xf3;
  230. val |= (if_agc_fix) ? 0x08 : 0x00;
  231. val |= (rf_agc_fix) ? 0x04 : 0x00;
  232. ret = lg216x_write_reg(state, 0x0100, val);
  233. lg_fail(ret);
  234. fail:
  235. return ret;
  236. }
  237. #if 0
  238. static int lg2160_agc_freeze(struct lg216x_state *state,
  239. int if_agc_freeze, int rf_agc_freeze)
  240. {
  241. u8 val;
  242. int ret;
  243. ret = lg216x_read_reg(state, 0x0100, &val);
  244. if (lg_fail(ret))
  245. goto fail;
  246. val &= 0xcf;
  247. val |= (if_agc_freeze) ? 0x20 : 0x00;
  248. val |= (rf_agc_freeze) ? 0x10 : 0x00;
  249. ret = lg216x_write_reg(state, 0x0100, val);
  250. lg_fail(ret);
  251. fail:
  252. return ret;
  253. }
  254. #endif
  255. static int lg2160_agc_polarity(struct lg216x_state *state,
  256. int if_agc_polarity, int rf_agc_polarity)
  257. {
  258. u8 val;
  259. int ret;
  260. ret = lg216x_read_reg(state, 0x0100, &val);
  261. if (lg_fail(ret))
  262. goto fail;
  263. val &= 0xfc;
  264. val |= (if_agc_polarity) ? 0x02 : 0x00;
  265. val |= (rf_agc_polarity) ? 0x01 : 0x00;
  266. ret = lg216x_write_reg(state, 0x0100, val);
  267. lg_fail(ret);
  268. fail:
  269. return ret;
  270. }
  271. static int lg2160_tuner_pwr_save_polarity(struct lg216x_state *state,
  272. int polarity)
  273. {
  274. u8 val;
  275. int ret;
  276. ret = lg216x_read_reg(state, 0x0008, &val);
  277. if (lg_fail(ret))
  278. goto fail;
  279. val &= 0xfe;
  280. val |= (polarity) ? 0x01 : 0x00;
  281. ret = lg216x_write_reg(state, 0x0008, val);
  282. lg_fail(ret);
  283. fail:
  284. return ret;
  285. }
  286. static int lg2160_spectrum_polarity(struct lg216x_state *state,
  287. int inverted)
  288. {
  289. u8 val;
  290. int ret;
  291. ret = lg216x_read_reg(state, 0x0132, &val);
  292. if (lg_fail(ret))
  293. goto fail;
  294. val &= 0xfd;
  295. val |= (inverted) ? 0x02 : 0x00;
  296. ret = lg216x_write_reg(state, 0x0132, val);
  297. lg_fail(ret);
  298. fail:
  299. return lg216x_soft_reset(state);
  300. }
  301. static int lg2160_tuner_pwr_save(struct lg216x_state *state, int onoff)
  302. {
  303. u8 val;
  304. int ret;
  305. ret = lg216x_read_reg(state, 0x0007, &val);
  306. if (lg_fail(ret))
  307. goto fail;
  308. val &= 0xbf;
  309. val |= (onoff) ? 0x40 : 0x00;
  310. ret = lg216x_write_reg(state, 0x0007, val);
  311. lg_fail(ret);
  312. fail:
  313. return ret;
  314. }
  315. static int lg216x_set_parade(struct lg216x_state *state, int id)
  316. {
  317. int ret;
  318. ret = lg216x_write_reg(state, 0x013e, id & 0x7f);
  319. if (lg_fail(ret))
  320. goto fail;
  321. state->parade_id = id & 0x7f;
  322. fail:
  323. return ret;
  324. }
  325. static int lg216x_set_ensemble(struct lg216x_state *state, int id)
  326. {
  327. int ret;
  328. u16 reg;
  329. u8 val;
  330. switch (state->cfg->lg_chip) {
  331. case LG2160:
  332. reg = 0x0400;
  333. break;
  334. case LG2161:
  335. default:
  336. reg = 0x0500;
  337. break;
  338. }
  339. ret = lg216x_read_reg(state, reg, &val);
  340. if (lg_fail(ret))
  341. goto fail;
  342. val &= 0xfe;
  343. val |= (id) ? 0x01 : 0x00;
  344. ret = lg216x_write_reg(state, reg, val);
  345. lg_fail(ret);
  346. fail:
  347. return ret;
  348. }
  349. static int lg2160_set_spi_clock(struct lg216x_state *state)
  350. {
  351. u8 val;
  352. int ret;
  353. ret = lg216x_read_reg(state, 0x0014, &val);
  354. if (lg_fail(ret))
  355. goto fail;
  356. val &= 0xf3;
  357. val |= (state->cfg->spi_clock << 2);
  358. ret = lg216x_write_reg(state, 0x0014, val);
  359. lg_fail(ret);
  360. fail:
  361. return ret;
  362. }
  363. static int lg2161_set_output_interface(struct lg216x_state *state)
  364. {
  365. u8 val;
  366. int ret;
  367. ret = lg216x_read_reg(state, 0x0014, &val);
  368. if (lg_fail(ret))
  369. goto fail;
  370. val &= ~0x07;
  371. val |= state->cfg->output_if; /* FIXME: needs sanity check */
  372. ret = lg216x_write_reg(state, 0x0014, val);
  373. lg_fail(ret);
  374. fail:
  375. return ret;
  376. }
  377. static int lg216x_enable_fic(struct lg216x_state *state, int onoff)
  378. {
  379. int ret;
  380. ret = lg216x_write_reg(state, 0x0017, 0x23);
  381. if (lg_fail(ret))
  382. goto fail;
  383. ret = lg216x_write_reg(state, 0x0016, 0xfc);
  384. if (lg_fail(ret))
  385. goto fail;
  386. switch (state->cfg->lg_chip) {
  387. case LG2160:
  388. ret = lg216x_write_reg(state, 0x0016,
  389. 0xfc | ((onoff) ? 0x02 : 0x00));
  390. break;
  391. case LG2161:
  392. ret = lg216x_write_reg(state, 0x0016, (onoff) ? 0x10 : 0x00);
  393. break;
  394. }
  395. if (lg_fail(ret))
  396. goto fail;
  397. ret = lg216x_initialize(state);
  398. if (lg_fail(ret))
  399. goto fail;
  400. if (onoff) {
  401. ret = lg216x_write_reg(state, 0x0017, 0x03);
  402. lg_fail(ret);
  403. }
  404. fail:
  405. return ret;
  406. }
  407. /* ------------------------------------------------------------------------ */
  408. static int lg216x_get_fic_version(struct lg216x_state *state, u8 *ficver)
  409. {
  410. u8 val;
  411. int ret;
  412. *ficver = 0xff; /* invalid value */
  413. ret = lg216x_read_reg(state, 0x0128, &val);
  414. if (lg_fail(ret))
  415. goto fail;
  416. *ficver = (val >> 3) & 0x1f;
  417. fail:
  418. return ret;
  419. }
  420. #if 0
  421. static int lg2160_get_parade_id(struct lg216x_state *state, u8 *id)
  422. {
  423. u8 val;
  424. int ret;
  425. *id = 0xff; /* invalid value */
  426. ret = lg216x_read_reg(state, 0x0123, &val);
  427. if (lg_fail(ret))
  428. goto fail;
  429. *id = val & 0x7f;
  430. fail:
  431. return ret;
  432. }
  433. #endif
  434. static int lg216x_get_nog(struct lg216x_state *state, u8 *nog)
  435. {
  436. u8 val;
  437. int ret;
  438. *nog = 0xff; /* invalid value */
  439. ret = lg216x_read_reg(state, 0x0124, &val);
  440. if (lg_fail(ret))
  441. goto fail;
  442. *nog = ((val >> 4) & 0x07) + 1;
  443. fail:
  444. return ret;
  445. }
  446. static int lg216x_get_tnog(struct lg216x_state *state, u8 *tnog)
  447. {
  448. u8 val;
  449. int ret;
  450. *tnog = 0xff; /* invalid value */
  451. ret = lg216x_read_reg(state, 0x0125, &val);
  452. if (lg_fail(ret))
  453. goto fail;
  454. *tnog = val & 0x1f;
  455. fail:
  456. return ret;
  457. }
  458. static int lg216x_get_sgn(struct lg216x_state *state, u8 *sgn)
  459. {
  460. u8 val;
  461. int ret;
  462. *sgn = 0xff; /* invalid value */
  463. ret = lg216x_read_reg(state, 0x0124, &val);
  464. if (lg_fail(ret))
  465. goto fail;
  466. *sgn = val & 0x0f;
  467. fail:
  468. return ret;
  469. }
  470. static int lg216x_get_prc(struct lg216x_state *state, u8 *prc)
  471. {
  472. u8 val;
  473. int ret;
  474. *prc = 0xff; /* invalid value */
  475. ret = lg216x_read_reg(state, 0x0125, &val);
  476. if (lg_fail(ret))
  477. goto fail;
  478. *prc = ((val >> 5) & 0x07) + 1;
  479. fail:
  480. return ret;
  481. }
  482. /* ------------------------------------------------------------------------ */
  483. static int lg216x_get_rs_frame_mode(struct lg216x_state *state,
  484. enum atscmh_rs_frame_mode *rs_framemode)
  485. {
  486. u8 val;
  487. int ret;
  488. switch (state->cfg->lg_chip) {
  489. case LG2160:
  490. ret = lg216x_read_reg(state, 0x0410, &val);
  491. break;
  492. case LG2161:
  493. ret = lg216x_read_reg(state, 0x0513, &val);
  494. break;
  495. default:
  496. ret = -EINVAL;
  497. }
  498. if (lg_fail(ret))
  499. goto fail;
  500. switch ((val >> 4) & 0x03) {
  501. #if 1
  502. default:
  503. #endif
  504. case 0x00:
  505. *rs_framemode = ATSCMH_RSFRAME_PRI_ONLY;
  506. break;
  507. case 0x01:
  508. *rs_framemode = ATSCMH_RSFRAME_PRI_SEC;
  509. break;
  510. #if 0
  511. default:
  512. *rs_framemode = ATSCMH_RSFRAME_RES;
  513. break;
  514. #endif
  515. }
  516. fail:
  517. return ret;
  518. }
  519. static
  520. int lg216x_get_rs_frame_ensemble(struct lg216x_state *state,
  521. enum atscmh_rs_frame_ensemble *rs_frame_ens)
  522. {
  523. u8 val;
  524. int ret;
  525. switch (state->cfg->lg_chip) {
  526. case LG2160:
  527. ret = lg216x_read_reg(state, 0x0400, &val);
  528. break;
  529. case LG2161:
  530. ret = lg216x_read_reg(state, 0x0500, &val);
  531. break;
  532. default:
  533. ret = -EINVAL;
  534. }
  535. if (lg_fail(ret))
  536. goto fail;
  537. val &= 0x01;
  538. *rs_frame_ens = (enum atscmh_rs_frame_ensemble) val;
  539. fail:
  540. return ret;
  541. }
  542. static int lg216x_get_rs_code_mode(struct lg216x_state *state,
  543. enum atscmh_rs_code_mode *rs_code_pri,
  544. enum atscmh_rs_code_mode *rs_code_sec)
  545. {
  546. u8 val;
  547. int ret;
  548. switch (state->cfg->lg_chip) {
  549. case LG2160:
  550. ret = lg216x_read_reg(state, 0x0410, &val);
  551. break;
  552. case LG2161:
  553. ret = lg216x_read_reg(state, 0x0513, &val);
  554. break;
  555. default:
  556. ret = -EINVAL;
  557. }
  558. if (lg_fail(ret))
  559. goto fail;
  560. *rs_code_pri = (enum atscmh_rs_code_mode) ((val >> 2) & 0x03);
  561. *rs_code_sec = (enum atscmh_rs_code_mode) (val & 0x03);
  562. fail:
  563. return ret;
  564. }
  565. static int lg216x_get_sccc_block_mode(struct lg216x_state *state,
  566. enum atscmh_sccc_block_mode *sccc_block)
  567. {
  568. u8 val;
  569. int ret;
  570. switch (state->cfg->lg_chip) {
  571. case LG2160:
  572. ret = lg216x_read_reg(state, 0x0315, &val);
  573. break;
  574. case LG2161:
  575. ret = lg216x_read_reg(state, 0x0511, &val);
  576. break;
  577. default:
  578. ret = -EINVAL;
  579. }
  580. if (lg_fail(ret))
  581. goto fail;
  582. switch (val & 0x03) {
  583. case 0x00:
  584. *sccc_block = ATSCMH_SCCC_BLK_SEP;
  585. break;
  586. case 0x01:
  587. *sccc_block = ATSCMH_SCCC_BLK_COMB;
  588. break;
  589. default:
  590. *sccc_block = ATSCMH_SCCC_BLK_RES;
  591. break;
  592. }
  593. fail:
  594. return ret;
  595. }
  596. static int lg216x_get_sccc_code_mode(struct lg216x_state *state,
  597. enum atscmh_sccc_code_mode *mode_a,
  598. enum atscmh_sccc_code_mode *mode_b,
  599. enum atscmh_sccc_code_mode *mode_c,
  600. enum atscmh_sccc_code_mode *mode_d)
  601. {
  602. u8 val;
  603. int ret;
  604. switch (state->cfg->lg_chip) {
  605. case LG2160:
  606. ret = lg216x_read_reg(state, 0x0316, &val);
  607. break;
  608. case LG2161:
  609. ret = lg216x_read_reg(state, 0x0512, &val);
  610. break;
  611. default:
  612. ret = -EINVAL;
  613. }
  614. if (lg_fail(ret))
  615. goto fail;
  616. switch ((val >> 6) & 0x03) {
  617. case 0x00:
  618. *mode_a = ATSCMH_SCCC_CODE_HLF;
  619. break;
  620. case 0x01:
  621. *mode_a = ATSCMH_SCCC_CODE_QTR;
  622. break;
  623. default:
  624. *mode_a = ATSCMH_SCCC_CODE_RES;
  625. break;
  626. }
  627. switch ((val >> 4) & 0x03) {
  628. case 0x00:
  629. *mode_b = ATSCMH_SCCC_CODE_HLF;
  630. break;
  631. case 0x01:
  632. *mode_b = ATSCMH_SCCC_CODE_QTR;
  633. break;
  634. default:
  635. *mode_b = ATSCMH_SCCC_CODE_RES;
  636. break;
  637. }
  638. switch ((val >> 2) & 0x03) {
  639. case 0x00:
  640. *mode_c = ATSCMH_SCCC_CODE_HLF;
  641. break;
  642. case 0x01:
  643. *mode_c = ATSCMH_SCCC_CODE_QTR;
  644. break;
  645. default:
  646. *mode_c = ATSCMH_SCCC_CODE_RES;
  647. break;
  648. }
  649. switch (val & 0x03) {
  650. case 0x00:
  651. *mode_d = ATSCMH_SCCC_CODE_HLF;
  652. break;
  653. case 0x01:
  654. *mode_d = ATSCMH_SCCC_CODE_QTR;
  655. break;
  656. default:
  657. *mode_d = ATSCMH_SCCC_CODE_RES;
  658. break;
  659. }
  660. fail:
  661. return ret;
  662. }
  663. /* ------------------------------------------------------------------------ */
  664. #if 0
  665. static int lg216x_read_fic_err_count(struct lg216x_state *state, u8 *err)
  666. {
  667. u8 fic_err;
  668. int ret;
  669. *err = 0;
  670. switch (state->cfg->lg_chip) {
  671. case LG2160:
  672. ret = lg216x_read_reg(state, 0x0012, &fic_err);
  673. break;
  674. case LG2161:
  675. ret = lg216x_read_reg(state, 0x001e, &fic_err);
  676. break;
  677. }
  678. if (lg_fail(ret))
  679. goto fail;
  680. *err = fic_err;
  681. fail:
  682. return ret;
  683. }
  684. static int lg2160_read_crc_err_count(struct lg216x_state *state, u16 *err)
  685. {
  686. u8 crc_err1, crc_err2;
  687. int ret;
  688. *err = 0;
  689. ret = lg216x_read_reg(state, 0x0411, &crc_err1);
  690. if (lg_fail(ret))
  691. goto fail;
  692. ret = lg216x_read_reg(state, 0x0412, &crc_err2);
  693. if (lg_fail(ret))
  694. goto fail;
  695. *err = (u16)(((crc_err2 & 0x0f) << 8) | crc_err1);
  696. fail:
  697. return ret;
  698. }
  699. static int lg2161_read_crc_err_count(struct lg216x_state *state, u16 *err)
  700. {
  701. u8 crc_err;
  702. int ret;
  703. *err = 0;
  704. ret = lg216x_read_reg(state, 0x0612, &crc_err);
  705. if (lg_fail(ret))
  706. goto fail;
  707. *err = (u16)crc_err;
  708. fail:
  709. return ret;
  710. }
  711. static int lg216x_read_crc_err_count(struct lg216x_state *state, u16 *err)
  712. {
  713. int ret;
  714. switch (state->cfg->lg_chip) {
  715. case LG2160:
  716. ret = lg2160_read_crc_err_count(state, err);
  717. break;
  718. case LG2161:
  719. ret = lg2161_read_crc_err_count(state, err);
  720. break;
  721. default:
  722. ret = -EINVAL;
  723. break;
  724. }
  725. return ret;
  726. }
  727. static int lg2160_read_rs_err_count(struct lg216x_state *state, u16 *err)
  728. {
  729. u8 rs_err1, rs_err2;
  730. int ret;
  731. *err = 0;
  732. ret = lg216x_read_reg(state, 0x0413, &rs_err1);
  733. if (lg_fail(ret))
  734. goto fail;
  735. ret = lg216x_read_reg(state, 0x0414, &rs_err2);
  736. if (lg_fail(ret))
  737. goto fail;
  738. *err = (u16)(((rs_err2 & 0x0f) << 8) | rs_err1);
  739. fail:
  740. return ret;
  741. }
  742. static int lg2161_read_rs_err_count(struct lg216x_state *state, u16 *err)
  743. {
  744. u8 rs_err1, rs_err2;
  745. int ret;
  746. *err = 0;
  747. ret = lg216x_read_reg(state, 0x0613, &rs_err1);
  748. if (lg_fail(ret))
  749. goto fail;
  750. ret = lg216x_read_reg(state, 0x0614, &rs_err2);
  751. if (lg_fail(ret))
  752. goto fail;
  753. *err = (u16)((rs_err1 << 8) | rs_err2);
  754. fail:
  755. return ret;
  756. }
  757. static int lg216x_read_rs_err_count(struct lg216x_state *state, u16 *err)
  758. {
  759. int ret;
  760. switch (state->cfg->lg_chip) {
  761. case LG2160:
  762. ret = lg2160_read_rs_err_count(state, err);
  763. break;
  764. case LG2161:
  765. ret = lg2161_read_rs_err_count(state, err);
  766. break;
  767. default:
  768. ret = -EINVAL;
  769. break;
  770. }
  771. return ret;
  772. }
  773. #endif
  774. /* ------------------------------------------------------------------------ */
  775. static int lg216x_get_frontend(struct dvb_frontend *fe)
  776. {
  777. struct lg216x_state *state = fe->demodulator_priv;
  778. int ret;
  779. lg_dbg("\n");
  780. fe->dtv_property_cache.modulation = VSB_8;
  781. fe->dtv_property_cache.frequency = state->current_frequency;
  782. fe->dtv_property_cache.delivery_system = SYS_ATSCMH;
  783. ret = lg216x_get_fic_version(state,
  784. &fe->dtv_property_cache.atscmh_fic_ver);
  785. if (lg_fail(ret))
  786. goto fail;
  787. if (state->fic_ver != fe->dtv_property_cache.atscmh_fic_ver) {
  788. state->fic_ver = fe->dtv_property_cache.atscmh_fic_ver;
  789. #if 0
  790. ret = lg2160_get_parade_id(state,
  791. &fe->dtv_property_cache.atscmh_parade_id);
  792. if (lg_fail(ret))
  793. goto fail;
  794. /* #else */
  795. fe->dtv_property_cache.atscmh_parade_id = state->parade_id;
  796. #endif
  797. ret = lg216x_get_nog(state,
  798. &fe->dtv_property_cache.atscmh_nog);
  799. if (lg_fail(ret))
  800. goto fail;
  801. ret = lg216x_get_tnog(state,
  802. &fe->dtv_property_cache.atscmh_tnog);
  803. if (lg_fail(ret))
  804. goto fail;
  805. ret = lg216x_get_sgn(state,
  806. &fe->dtv_property_cache.atscmh_sgn);
  807. if (lg_fail(ret))
  808. goto fail;
  809. ret = lg216x_get_prc(state,
  810. &fe->dtv_property_cache.atscmh_prc);
  811. if (lg_fail(ret))
  812. goto fail;
  813. ret = lg216x_get_rs_frame_mode(state,
  814. (enum atscmh_rs_frame_mode *)
  815. &fe->dtv_property_cache.atscmh_rs_frame_mode);
  816. if (lg_fail(ret))
  817. goto fail;
  818. ret = lg216x_get_rs_frame_ensemble(state,
  819. (enum atscmh_rs_frame_ensemble *)
  820. &fe->dtv_property_cache.atscmh_rs_frame_ensemble);
  821. if (lg_fail(ret))
  822. goto fail;
  823. ret = lg216x_get_rs_code_mode(state,
  824. (enum atscmh_rs_code_mode *)
  825. &fe->dtv_property_cache.atscmh_rs_code_mode_pri,
  826. (enum atscmh_rs_code_mode *)
  827. &fe->dtv_property_cache.atscmh_rs_code_mode_sec);
  828. if (lg_fail(ret))
  829. goto fail;
  830. ret = lg216x_get_sccc_block_mode(state,
  831. (enum atscmh_sccc_block_mode *)
  832. &fe->dtv_property_cache.atscmh_sccc_block_mode);
  833. if (lg_fail(ret))
  834. goto fail;
  835. ret = lg216x_get_sccc_code_mode(state,
  836. (enum atscmh_sccc_code_mode *)
  837. &fe->dtv_property_cache.atscmh_sccc_code_mode_a,
  838. (enum atscmh_sccc_code_mode *)
  839. &fe->dtv_property_cache.atscmh_sccc_code_mode_b,
  840. (enum atscmh_sccc_code_mode *)
  841. &fe->dtv_property_cache.atscmh_sccc_code_mode_c,
  842. (enum atscmh_sccc_code_mode *)
  843. &fe->dtv_property_cache.atscmh_sccc_code_mode_d);
  844. if (lg_fail(ret))
  845. goto fail;
  846. }
  847. #if 0
  848. ret = lg216x_read_fic_err_count(state,
  849. (u8 *)&fe->dtv_property_cache.atscmh_fic_err);
  850. if (lg_fail(ret))
  851. goto fail;
  852. ret = lg216x_read_crc_err_count(state,
  853. &fe->dtv_property_cache.atscmh_crc_err);
  854. if (lg_fail(ret))
  855. goto fail;
  856. ret = lg216x_read_rs_err_count(state,
  857. &fe->dtv_property_cache.atscmh_rs_err);
  858. if (lg_fail(ret))
  859. goto fail;
  860. switch (state->cfg->lg_chip) {
  861. case LG2160:
  862. if (((fe->dtv_property_cache.atscmh_rs_err >= 240) &&
  863. (fe->dtv_property_cache.atscmh_crc_err >= 240)) &&
  864. ((jiffies_to_msecs(jiffies) - state->last_reset) > 6000))
  865. ret = lg216x_soft_reset(state);
  866. break;
  867. case LG2161:
  868. /* no fix needed here (as far as we know) */
  869. ret = 0;
  870. break;
  871. }
  872. lg_fail(ret);
  873. #endif
  874. fail:
  875. return ret;
  876. }
  877. static int lg216x_get_property(struct dvb_frontend *fe,
  878. struct dtv_property *tvp)
  879. {
  880. return (DTV_ATSCMH_FIC_VER == tvp->cmd) ?
  881. lg216x_get_frontend(fe) : 0;
  882. }
  883. static int lg2160_set_frontend(struct dvb_frontend *fe)
  884. {
  885. struct lg216x_state *state = fe->demodulator_priv;
  886. int ret;
  887. lg_dbg("(%d)\n", fe->dtv_property_cache.frequency);
  888. if (fe->ops.tuner_ops.set_params) {
  889. ret = fe->ops.tuner_ops.set_params(fe);
  890. if (fe->ops.i2c_gate_ctrl)
  891. fe->ops.i2c_gate_ctrl(fe, 0);
  892. if (lg_fail(ret))
  893. goto fail;
  894. state->current_frequency = fe->dtv_property_cache.frequency;
  895. }
  896. ret = lg2160_agc_fix(state, 0, 0);
  897. if (lg_fail(ret))
  898. goto fail;
  899. ret = lg2160_agc_polarity(state, 0, 0);
  900. if (lg_fail(ret))
  901. goto fail;
  902. ret = lg2160_tuner_pwr_save_polarity(state, 1);
  903. if (lg_fail(ret))
  904. goto fail;
  905. ret = lg216x_set_if(state);
  906. if (lg_fail(ret))
  907. goto fail;
  908. ret = lg2160_spectrum_polarity(state, state->cfg->spectral_inversion);
  909. if (lg_fail(ret))
  910. goto fail;
  911. /* be tuned before this point */
  912. ret = lg216x_soft_reset(state);
  913. if (lg_fail(ret))
  914. goto fail;
  915. ret = lg2160_tuner_pwr_save(state, 0);
  916. if (lg_fail(ret))
  917. goto fail;
  918. switch (state->cfg->lg_chip) {
  919. case LG2160:
  920. ret = lg2160_set_spi_clock(state);
  921. if (lg_fail(ret))
  922. goto fail;
  923. break;
  924. case LG2161:
  925. ret = lg2161_set_output_interface(state);
  926. if (lg_fail(ret))
  927. goto fail;
  928. break;
  929. }
  930. ret = lg216x_set_parade(state, fe->dtv_property_cache.atscmh_parade_id);
  931. if (lg_fail(ret))
  932. goto fail;
  933. ret = lg216x_set_ensemble(state,
  934. fe->dtv_property_cache.atscmh_rs_frame_ensemble);
  935. if (lg_fail(ret))
  936. goto fail;
  937. ret = lg216x_initialize(state);
  938. if (lg_fail(ret))
  939. goto fail;
  940. ret = lg216x_enable_fic(state, 1);
  941. lg_fail(ret);
  942. lg216x_get_frontend(fe);
  943. fail:
  944. return ret;
  945. }
  946. /* ------------------------------------------------------------------------ */
  947. static int lg2160_read_lock_status(struct lg216x_state *state,
  948. int *acq_lock, int *sync_lock)
  949. {
  950. u8 val;
  951. int ret;
  952. *acq_lock = 0;
  953. *sync_lock = 0;
  954. ret = lg216x_read_reg(state, 0x011b, &val);
  955. if (lg_fail(ret))
  956. goto fail;
  957. *sync_lock = (val & 0x20) ? 0 : 1;
  958. *acq_lock = (val & 0x40) ? 0 : 1;
  959. fail:
  960. return ret;
  961. }
  962. #ifdef USE_LG2161_LOCK_BITS
  963. static int lg2161_read_lock_status(struct lg216x_state *state,
  964. int *acq_lock, int *sync_lock)
  965. {
  966. u8 val;
  967. int ret;
  968. *acq_lock = 0;
  969. *sync_lock = 0;
  970. ret = lg216x_read_reg(state, 0x0304, &val);
  971. if (lg_fail(ret))
  972. goto fail;
  973. *sync_lock = (val & 0x80) ? 0 : 1;
  974. ret = lg216x_read_reg(state, 0x011b, &val);
  975. if (lg_fail(ret))
  976. goto fail;
  977. *acq_lock = (val & 0x40) ? 0 : 1;
  978. fail:
  979. return ret;
  980. }
  981. #endif
  982. static int lg216x_read_lock_status(struct lg216x_state *state,
  983. int *acq_lock, int *sync_lock)
  984. {
  985. #ifdef USE_LG2161_LOCK_BITS
  986. int ret;
  987. switch (state->cfg->lg_chip) {
  988. case LG2160:
  989. ret = lg2160_read_lock_status(state, acq_lock, sync_lock);
  990. break;
  991. case LG2161:
  992. ret = lg2161_read_lock_status(state, acq_lock, sync_lock);
  993. break;
  994. default:
  995. ret = -EINVAL;
  996. break;
  997. }
  998. return ret;
  999. #else
  1000. return lg2160_read_lock_status(state, acq_lock, sync_lock);
  1001. #endif
  1002. }
  1003. static int lg216x_read_status(struct dvb_frontend *fe, enum fe_status *status)
  1004. {
  1005. struct lg216x_state *state = fe->demodulator_priv;
  1006. int ret, acq_lock, sync_lock;
  1007. *status = 0;
  1008. ret = lg216x_read_lock_status(state, &acq_lock, &sync_lock);
  1009. if (lg_fail(ret))
  1010. goto fail;
  1011. lg_dbg("%s%s\n",
  1012. acq_lock ? "SIGNALEXIST " : "",
  1013. sync_lock ? "SYNCLOCK" : "");
  1014. if (acq_lock)
  1015. *status |= FE_HAS_SIGNAL;
  1016. if (sync_lock)
  1017. *status |= FE_HAS_SYNC;
  1018. if (*status)
  1019. *status |= FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_LOCK;
  1020. fail:
  1021. return ret;
  1022. }
  1023. /* ------------------------------------------------------------------------ */
  1024. static int lg2160_read_snr(struct dvb_frontend *fe, u16 *snr)
  1025. {
  1026. struct lg216x_state *state = fe->demodulator_priv;
  1027. u8 snr1, snr2;
  1028. int ret;
  1029. *snr = 0;
  1030. ret = lg216x_read_reg(state, 0x0202, &snr1);
  1031. if (lg_fail(ret))
  1032. goto fail;
  1033. ret = lg216x_read_reg(state, 0x0203, &snr2);
  1034. if (lg_fail(ret))
  1035. goto fail;
  1036. if ((snr1 == 0xba) || (snr2 == 0xdf))
  1037. *snr = 0;
  1038. else
  1039. #if 1
  1040. *snr = ((snr1 >> 4) * 100) + ((snr1 & 0x0f) * 10) + (snr2 >> 4);
  1041. #else /* BCD */
  1042. *snr = (snr2 | (snr1 << 8));
  1043. #endif
  1044. fail:
  1045. return ret;
  1046. }
  1047. static int lg2161_read_snr(struct dvb_frontend *fe, u16 *snr)
  1048. {
  1049. struct lg216x_state *state = fe->demodulator_priv;
  1050. u8 snr1, snr2;
  1051. int ret;
  1052. *snr = 0;
  1053. ret = lg216x_read_reg(state, 0x0302, &snr1);
  1054. if (lg_fail(ret))
  1055. goto fail;
  1056. ret = lg216x_read_reg(state, 0x0303, &snr2);
  1057. if (lg_fail(ret))
  1058. goto fail;
  1059. if ((snr1 == 0xba) || (snr2 == 0xfd))
  1060. *snr = 0;
  1061. else
  1062. *snr = ((snr1 >> 4) * 100) + ((snr1 & 0x0f) * 10) + (snr2 & 0x0f);
  1063. fail:
  1064. return ret;
  1065. }
  1066. static int lg216x_read_signal_strength(struct dvb_frontend *fe,
  1067. u16 *strength)
  1068. {
  1069. #if 0
  1070. /* borrowed from lgdt330x.c
  1071. *
  1072. * Calculate strength from SNR up to 35dB
  1073. * Even though the SNR can go higher than 35dB,
  1074. * there is some comfort factor in having a range of
  1075. * strong signals that can show at 100%
  1076. */
  1077. struct lg216x_state *state = fe->demodulator_priv;
  1078. u16 snr;
  1079. int ret;
  1080. #endif
  1081. *strength = 0;
  1082. #if 0
  1083. ret = fe->ops.read_snr(fe, &snr);
  1084. if (lg_fail(ret))
  1085. goto fail;
  1086. /* Rather than use the 8.8 value snr, use state->snr which is 8.24 */
  1087. /* scale the range 0 - 35*2^24 into 0 - 65535 */
  1088. if (state->snr >= 8960 * 0x10000)
  1089. *strength = 0xffff;
  1090. else
  1091. *strength = state->snr / 8960;
  1092. fail:
  1093. return ret;
  1094. #else
  1095. return 0;
  1096. #endif
  1097. }
  1098. /* ------------------------------------------------------------------------ */
  1099. static int lg216x_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
  1100. {
  1101. #if 0
  1102. struct lg216x_state *state = fe->demodulator_priv;
  1103. int ret;
  1104. ret = lg216x_read_rs_err_count(state,
  1105. &fe->dtv_property_cache.atscmh_rs_err);
  1106. if (lg_fail(ret))
  1107. goto fail;
  1108. *ucblocks = fe->dtv_property_cache.atscmh_rs_err;
  1109. fail:
  1110. #else
  1111. *ucblocks = 0;
  1112. #endif
  1113. return 0;
  1114. }
  1115. static int lg216x_get_tune_settings(struct dvb_frontend *fe,
  1116. struct dvb_frontend_tune_settings
  1117. *fe_tune_settings)
  1118. {
  1119. fe_tune_settings->min_delay_ms = 500;
  1120. lg_dbg("\n");
  1121. return 0;
  1122. }
  1123. static void lg216x_release(struct dvb_frontend *fe)
  1124. {
  1125. struct lg216x_state *state = fe->demodulator_priv;
  1126. lg_dbg("\n");
  1127. kfree(state);
  1128. }
  1129. static struct dvb_frontend_ops lg2160_ops = {
  1130. .delsys = { SYS_ATSCMH },
  1131. .info = {
  1132. .name = "LG Electronics LG2160 ATSC/MH Frontend",
  1133. .frequency_min = 54000000,
  1134. .frequency_max = 858000000,
  1135. .frequency_stepsize = 62500,
  1136. },
  1137. .i2c_gate_ctrl = lg216x_i2c_gate_ctrl,
  1138. #if 0
  1139. .init = lg216x_init,
  1140. .sleep = lg216x_sleep,
  1141. #endif
  1142. .get_property = lg216x_get_property,
  1143. .set_frontend = lg2160_set_frontend,
  1144. .get_frontend = lg216x_get_frontend,
  1145. .get_tune_settings = lg216x_get_tune_settings,
  1146. .read_status = lg216x_read_status,
  1147. #if 0
  1148. .read_ber = lg216x_read_ber,
  1149. #endif
  1150. .read_signal_strength = lg216x_read_signal_strength,
  1151. .read_snr = lg2160_read_snr,
  1152. .read_ucblocks = lg216x_read_ucblocks,
  1153. .release = lg216x_release,
  1154. };
  1155. static struct dvb_frontend_ops lg2161_ops = {
  1156. .delsys = { SYS_ATSCMH },
  1157. .info = {
  1158. .name = "LG Electronics LG2161 ATSC/MH Frontend",
  1159. .frequency_min = 54000000,
  1160. .frequency_max = 858000000,
  1161. .frequency_stepsize = 62500,
  1162. },
  1163. .i2c_gate_ctrl = lg216x_i2c_gate_ctrl,
  1164. #if 0
  1165. .init = lg216x_init,
  1166. .sleep = lg216x_sleep,
  1167. #endif
  1168. .get_property = lg216x_get_property,
  1169. .set_frontend = lg2160_set_frontend,
  1170. .get_frontend = lg216x_get_frontend,
  1171. .get_tune_settings = lg216x_get_tune_settings,
  1172. .read_status = lg216x_read_status,
  1173. #if 0
  1174. .read_ber = lg216x_read_ber,
  1175. #endif
  1176. .read_signal_strength = lg216x_read_signal_strength,
  1177. .read_snr = lg2161_read_snr,
  1178. .read_ucblocks = lg216x_read_ucblocks,
  1179. .release = lg216x_release,
  1180. };
  1181. struct dvb_frontend *lg2160_attach(const struct lg2160_config *config,
  1182. struct i2c_adapter *i2c_adap)
  1183. {
  1184. struct lg216x_state *state = NULL;
  1185. lg_dbg("(%d-%04x)\n",
  1186. i2c_adap ? i2c_adapter_id(i2c_adap) : 0,
  1187. config ? config->i2c_addr : 0);
  1188. state = kzalloc(sizeof(struct lg216x_state), GFP_KERNEL);
  1189. if (!state)
  1190. return NULL;
  1191. state->cfg = config;
  1192. state->i2c_adap = i2c_adap;
  1193. state->fic_ver = 0xff;
  1194. state->parade_id = 0xff;
  1195. switch (config->lg_chip) {
  1196. default:
  1197. lg_warn("invalid chip requested, defaulting to LG2160");
  1198. /* fall-thru */
  1199. case LG2160:
  1200. memcpy(&state->frontend.ops, &lg2160_ops,
  1201. sizeof(struct dvb_frontend_ops));
  1202. break;
  1203. case LG2161:
  1204. memcpy(&state->frontend.ops, &lg2161_ops,
  1205. sizeof(struct dvb_frontend_ops));
  1206. break;
  1207. }
  1208. state->frontend.demodulator_priv = state;
  1209. state->current_frequency = -1;
  1210. /* parade 1 by default */
  1211. state->frontend.dtv_property_cache.atscmh_parade_id = 1;
  1212. return &state->frontend;
  1213. }
  1214. EXPORT_SYMBOL(lg2160_attach);
  1215. MODULE_DESCRIPTION("LG Electronics LG216x ATSC/MH Demodulator Driver");
  1216. MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
  1217. MODULE_LICENSE("GPL");
  1218. MODULE_VERSION("0.3");