lgdt3302.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. /*
  2. * $Id: lgdt3302.c,v 1.2 2005/06/28 23:50:48 mkrufky Exp $
  3. *
  4. * Support for LGDT3302 (DViCO FustionHDTV 3 Gold) - VSB/QAM
  5. *
  6. * Copyright (C) 2005 Wilson Michaels <wilsonmichaels@earthlink.net>
  7. *
  8. * Based on code from Kirk Lapray <kirk_lapray@bigfoot.com>
  9. * Copyright (C) 2005
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. *
  25. */
  26. /*
  27. * NOTES ABOUT THIS DRIVER
  28. *
  29. * This driver supports DViCO FusionHDTV 3 Gold under Linux.
  30. *
  31. * TODO:
  32. * BER and signal strength always return 0.
  33. *
  34. */
  35. #include <linux/version.h>
  36. #include <linux/kernel.h>
  37. #include <linux/module.h>
  38. #include <linux/moduleparam.h>
  39. #include <linux/init.h>
  40. #include <linux/delay.h>
  41. #include <asm/byteorder.h>
  42. #include "dvb_frontend.h"
  43. #include "dvb-pll.h"
  44. #include "lgdt3302_priv.h"
  45. #include "lgdt3302.h"
  46. static int debug = 0;
  47. module_param(debug, int, 0644);
  48. MODULE_PARM_DESC(debug,"Turn on/off lgdt3302 frontend debugging (default:off).");
  49. #define dprintk(args...) \
  50. do { \
  51. if (debug) printk(KERN_DEBUG "lgdt3302: " args); \
  52. } while (0)
  53. struct lgdt3302_state
  54. {
  55. struct i2c_adapter* i2c;
  56. struct dvb_frontend_ops ops;
  57. /* Configuration settings */
  58. const struct lgdt3302_config* config;
  59. struct dvb_frontend frontend;
  60. /* Demodulator private data */
  61. fe_modulation_t current_modulation;
  62. /* Tuner private data */
  63. u32 current_frequency;
  64. };
  65. static int i2c_writebytes (struct lgdt3302_state* state,
  66. u8 addr, /* demod_address or pll_address */
  67. u8 *buf, /* data bytes to send */
  68. int len /* number of bytes to send */ )
  69. {
  70. if (addr == state->config->pll_address) {
  71. struct i2c_msg msg =
  72. { .addr = addr, .flags = 0, .buf = buf, .len = len };
  73. int err;
  74. if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
  75. printk(KERN_WARNING "lgdt3302: %s error (addr %02x <- %02x, err == %i)\n", __FUNCTION__, addr, buf[0], err);
  76. return -EREMOTEIO;
  77. }
  78. } else {
  79. u8 tmp[] = { buf[0], buf[1] };
  80. struct i2c_msg msg =
  81. { .addr = addr, .flags = 0, .buf = tmp, .len = 2 };
  82. int err;
  83. int i;
  84. for (i=1; i<len; i++) {
  85. tmp[1] = buf[i];
  86. if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
  87. printk(KERN_WARNING "lgdt3302: %s error (addr %02x <- %02x, err == %i)\n", __FUNCTION__, addr, buf[0], err);
  88. return -EREMOTEIO;
  89. }
  90. tmp[0]++;
  91. }
  92. }
  93. return 0;
  94. }
  95. static int i2c_readbytes (struct lgdt3302_state* state,
  96. u8 addr, /* demod_address or pll_address */
  97. u8 *buf, /* holds data bytes read */
  98. int len /* number of bytes to read */ )
  99. {
  100. struct i2c_msg msg =
  101. { .addr = addr, .flags = I2C_M_RD, .buf = buf, .len = len };
  102. int err;
  103. if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
  104. printk(KERN_WARNING "lgdt3302: %s error (addr %02x, err == %i)\n", __FUNCTION__, addr, err);
  105. return -EREMOTEIO;
  106. }
  107. return 0;
  108. }
  109. /*
  110. * This routine writes the register (reg) to the demod bus
  111. * then reads the data returned for (len) bytes.
  112. */
  113. static u8 i2c_selectreadbytes (struct lgdt3302_state* state,
  114. enum I2C_REG reg, u8* buf, int len)
  115. {
  116. u8 wr [] = { reg };
  117. struct i2c_msg msg [] = {
  118. { .addr = state->config->demod_address,
  119. .flags = 0, .buf = wr, .len = 1 },
  120. { .addr = state->config->demod_address,
  121. .flags = I2C_M_RD, .buf = buf, .len = len },
  122. };
  123. int ret;
  124. ret = i2c_transfer(state->i2c, msg, 2);
  125. if (ret != 2) {
  126. printk(KERN_WARNING "lgdt3302: %s: addr 0x%02x select 0x%02x error (ret == %i)\n", __FUNCTION__, state->config->demod_address, reg, ret);
  127. } else {
  128. ret = 0;
  129. }
  130. return ret;
  131. }
  132. /* Software reset */
  133. int lgdt3302_SwReset(struct lgdt3302_state* state)
  134. {
  135. u8 ret;
  136. u8 reset[] = {
  137. IRQ_MASK,
  138. 0x00 /* bit 6 is active low software reset
  139. * bits 5-0 are 1 to mask interrupts */
  140. };
  141. ret = i2c_writebytes(state,
  142. state->config->demod_address,
  143. reset, sizeof(reset));
  144. if (ret == 0) {
  145. /* spec says reset takes 100 ns why wait */
  146. /* mdelay(100); */ /* keep low for 100mS */
  147. reset[1] = 0x7f; /* force reset high (inactive)
  148. * and unmask interrupts */
  149. ret = i2c_writebytes(state,
  150. state->config->demod_address,
  151. reset, sizeof(reset));
  152. }
  153. /* Spec does not indicate a need for this either */
  154. /*mdelay(5); */ /* wait 5 msec before doing more */
  155. return ret;
  156. }
  157. static int lgdt3302_init(struct dvb_frontend* fe)
  158. {
  159. /* Hardware reset is done using gpio[0] of cx23880x chip.
  160. * I'd like to do it here, but don't know how to find chip address.
  161. * cx88-cards.c arranges for the reset bit to be inactive (high).
  162. * Maybe there needs to be a callable function in cx88-core or
  163. * the caller of this function needs to do it. */
  164. dprintk("%s entered\n", __FUNCTION__);
  165. return lgdt3302_SwReset((struct lgdt3302_state*) fe->demodulator_priv);
  166. }
  167. static int lgdt3302_read_ber(struct dvb_frontend* fe, u32* ber)
  168. {
  169. *ber = 0; /* Dummy out for now */
  170. return 0;
  171. }
  172. static int lgdt3302_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
  173. {
  174. struct lgdt3302_state* state = (struct lgdt3302_state*) fe->demodulator_priv;
  175. u8 buf[2];
  176. i2c_selectreadbytes(state, PACKET_ERR_COUNTER1, buf, sizeof(buf));
  177. *ucblocks = (buf[0] << 8) | buf[1];
  178. return 0;
  179. }
  180. static int lgdt3302_set_parameters(struct dvb_frontend* fe,
  181. struct dvb_frontend_parameters *param)
  182. {
  183. u8 buf[4];
  184. struct lgdt3302_state* state =
  185. (struct lgdt3302_state*) fe->demodulator_priv;
  186. #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,10)
  187. /* Use 50MHz parameter values from spec sheet since xtal is 50 */
  188. static u8 top_ctrl_cfg[] = { TOP_CONTROL, 0x03 };
  189. static u8 vsb_freq_cfg[] = { VSB_CARRIER_FREQ0, 0x00, 0x87, 0x8e, 0x01 };
  190. static u8 demux_ctrl_cfg[] = { DEMUX_CONTROL, 0xfb };
  191. static u8 agc_rf_cfg[] = { AGC_RF_BANDWIDTH0, 0x40, 0x93, 0x00 };
  192. static u8 agc_ctrl_cfg[] = { AGC_FUNC_CTRL2, 0xc6, 0x40 };
  193. static u8 agc_delay_cfg[] = { AGC_DELAY0, 0x00, 0x00, 0x00 };
  194. static u8 agc_loop_cfg[] = { AGC_LOOP_BANDWIDTH0, 0x08, 0x9a };
  195. /* Change only if we are actually changing the modulation */
  196. if (state->current_modulation != param->u.vsb.modulation) {
  197. switch(param->u.vsb.modulation) {
  198. case VSB_8:
  199. dprintk("%s: VSB_8 MODE\n", __FUNCTION__);
  200. /* Select VSB mode and serial MPEG interface */
  201. top_ctrl_cfg[1] = 0x07;
  202. break;
  203. case QAM_64:
  204. dprintk("%s: QAM_64 MODE\n", __FUNCTION__);
  205. /* Select QAM_64 mode and serial MPEG interface */
  206. top_ctrl_cfg[1] = 0x04;
  207. break;
  208. case QAM_256:
  209. dprintk("%s: QAM_256 MODE\n", __FUNCTION__);
  210. /* Select QAM_256 mode and serial MPEG interface */
  211. top_ctrl_cfg[1] = 0x05;
  212. break;
  213. default:
  214. printk(KERN_WARNING "lgdt3302: %s: Modulation type(%d) UNSUPPORTED\n", __FUNCTION__, param->u.vsb.modulation);
  215. return -1;
  216. }
  217. /* Initializations common to all modes */
  218. /* Select the requested mode */
  219. i2c_writebytes(state, state->config->demod_address,
  220. top_ctrl_cfg, sizeof(top_ctrl_cfg));
  221. /* Change the value of IFBW[11:0]
  222. of AGC IF/RF loop filter bandwidth register */
  223. i2c_writebytes(state, state->config->demod_address,
  224. agc_rf_cfg, sizeof(agc_rf_cfg));
  225. /* Change the value of bit 6, 'nINAGCBY' and
  226. 'NSSEL[1:0] of ACG function control register 2 */
  227. /* Change the value of bit 6 'RFFIX'
  228. of AGC function control register 3 */
  229. i2c_writebytes(state, state->config->demod_address,
  230. agc_ctrl_cfg, sizeof(agc_ctrl_cfg));
  231. /* Change the TPCLK pin polarity
  232. data is valid on falling clock */
  233. i2c_writebytes(state, state->config->demod_address,
  234. demux_ctrl_cfg, sizeof(demux_ctrl_cfg));
  235. if (param->u.vsb.modulation == VSB_8) {
  236. /* Initialization for VSB modes only */
  237. /* Change the value of NCOCTFV[25:0]of carrier
  238. recovery center frequency register for VSB */
  239. i2c_writebytes(state, state->config->demod_address,
  240. vsb_freq_cfg, sizeof(vsb_freq_cfg));
  241. } else {
  242. /* Initialization for QAM modes only */
  243. /* Set the value of 'INLVTHD' register 0x2a/0x2c
  244. to value from 'IFACC' register 0x39/0x3b -1 */
  245. int value;
  246. i2c_selectreadbytes(state, AGC_RFIF_ACC0,
  247. &agc_delay_cfg[1], 3);
  248. value = ((agc_delay_cfg[1] & 0x0f) << 8) | agc_delay_cfg[3];
  249. value = value -1;
  250. dprintk("%s IFACC -1 = 0x%03x\n", __FUNCTION__, value);
  251. agc_delay_cfg[1] = (value >> 8) & 0x0f;
  252. agc_delay_cfg[2] = 0x00;
  253. agc_delay_cfg[3] = value & 0xff;
  254. i2c_writebytes(state, state->config->demod_address,
  255. agc_delay_cfg, sizeof(agc_delay_cfg));
  256. /* Change the value of IAGCBW[15:8]
  257. of inner AGC loop filter bandwith */
  258. i2c_writebytes(state, state->config->demod_address,
  259. agc_loop_cfg, sizeof(agc_loop_cfg));
  260. }
  261. state->config->set_ts_params(fe, 0);
  262. lgdt3302_SwReset(state);
  263. state->current_modulation = param->u.vsb.modulation;
  264. }
  265. #else
  266. printk("lgdt3302: %s: you need a newer kernel for this, sorry\n",__FUNCTION__);
  267. #endif
  268. /* Change only if we are actually changing the channel */
  269. if (state->current_frequency != param->frequency) {
  270. dvb_pll_configure(state->config->pll_desc, buf,
  271. param->frequency, 0);
  272. dprintk("%s: tuner bytes: 0x%02x 0x%02x "
  273. "0x%02x 0x%02x\n", __FUNCTION__, buf[0],buf[1],buf[2],buf[3]);
  274. i2c_writebytes(state, state->config->pll_address ,buf, 4);
  275. /* Check the status of the tuner pll */
  276. i2c_readbytes(state, state->config->pll_address, buf, 1);
  277. dprintk("%s: tuner status byte = 0x%02x\n", __FUNCTION__, buf[0]);
  278. lgdt3302_SwReset(state);
  279. /* Update current frequency */
  280. state->current_frequency = param->frequency;
  281. }
  282. return 0;
  283. }
  284. static int lgdt3302_get_frontend(struct dvb_frontend* fe,
  285. struct dvb_frontend_parameters* param)
  286. {
  287. struct lgdt3302_state *state = fe->demodulator_priv;
  288. param->frequency = state->current_frequency;
  289. return 0;
  290. }
  291. static int lgdt3302_read_status(struct dvb_frontend* fe, fe_status_t* status)
  292. {
  293. struct lgdt3302_state* state = (struct lgdt3302_state*) fe->demodulator_priv;
  294. u8 buf[3];
  295. *status = 0; /* Reset status result */
  296. /* Check the status of the tuner pll */
  297. i2c_readbytes(state, state->config->pll_address, buf, 1);
  298. dprintk("%s: tuner status byte = 0x%02x\n", __FUNCTION__, buf[0]);
  299. if ((buf[0] & 0xc0) != 0x40)
  300. return 0; /* Tuner PLL not locked or not powered on */
  301. /*
  302. * You must set the Mask bits to 1 in the IRQ_MASK in order
  303. * to see that status bit in the IRQ_STATUS register.
  304. * This is done in SwReset();
  305. */
  306. /* signal status */
  307. i2c_selectreadbytes(state, TOP_CONTROL, buf, sizeof(buf));
  308. dprintk("%s: TOP_CONTROL = 0x%02x, IRO_MASK = 0x%02x, IRQ_STATUS = 0x%02x\n", __FUNCTION__, buf[0], buf[1], buf[2]);
  309. if ((buf[2] & 0x30) == 0x10)
  310. *status |= FE_HAS_SIGNAL;
  311. /* sync status */
  312. if ((buf[2] & 0x03) == 0x01) {
  313. *status |= FE_HAS_SYNC;
  314. }
  315. /* FEC error status */
  316. if ((buf[2] & 0x0c) == 0x08) {
  317. *status |= FE_HAS_LOCK;
  318. *status |= FE_HAS_VITERBI;
  319. }
  320. #if 0
  321. /* Alternative method to check for a signal */
  322. /* AGC status register */
  323. i2c_selectreadbytes(state, AGC_STATUS, buf, 1);
  324. dprintk("%s: AGC_STATUS = 0x%02x\n", __FUNCTION__, buf[0]);
  325. if ((buf[0] & 0x0c) == 0x80) /* Test signal does not exist flag */
  326. /* Test AGC lock flag */
  327. *status |= FE_HAS_SIGNAL;
  328. else
  329. return 0;
  330. /* Carrier Recovery Lock Status Register */
  331. i2c_selectreadbytes(state, CARRIER_LOCK, buf, 1);
  332. dprintk("%s: CARRIER_LOCK = 0x%02x\n", __FUNCTION__, buf[0]);
  333. switch (state->current_modulation) {
  334. case QAM_256:
  335. case QAM_64:
  336. /* Need to undestand why there are 3 lock levels here */
  337. if ((buf[0] & 0x07) == 0x07)
  338. *status |= FE_HAS_CARRIER;
  339. else
  340. return 0;
  341. break;
  342. #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,10)
  343. case VSB_8:
  344. if ((buf[0] & 0x80) == 0x80)
  345. *status |= FE_HAS_CARRIER;
  346. else
  347. return 0;
  348. break;
  349. #endif
  350. default:
  351. printk("KERN_WARNING lgdt3302: %s: Modulation set to unsupported value\n", __FUNCTION__);
  352. }
  353. #endif
  354. return 0;
  355. }
  356. static int lgdt3302_read_signal_strength(struct dvb_frontend* fe, u16* strength)
  357. {
  358. /* not directly available. */
  359. return 0;
  360. }
  361. static int lgdt3302_read_snr(struct dvb_frontend* fe, u16* snr)
  362. {
  363. #ifdef SNR_IN_DB
  364. /*
  365. * Spec sheet shows formula for SNR_EQ = 10 log10(25 * 24**2 / noise)
  366. * and SNR_PH = 10 log10(25 * 32**2 / noise) for equalizer and phase tracker
  367. * respectively. The following tables are built on these formulas.
  368. * The usual definition is SNR = 20 log10(signal/noise)
  369. * If the specification is wrong the value retuned is 1/2 the actual SNR in db.
  370. *
  371. * This table is a an ordered list of noise values computed by the
  372. * formula from the spec sheet such that the index into the table
  373. * starting at 43 or 45 is the SNR value in db. There are duplicate noise
  374. * value entries at the beginning because the SNR varies more than
  375. * 1 db for a change of 1 digit in noise at very small values of noise.
  376. *
  377. * Examples from SNR_EQ table:
  378. * noise SNR
  379. * 0 43
  380. * 1 42
  381. * 2 39
  382. * 3 37
  383. * 4 36
  384. * 5 35
  385. * 6 34
  386. * 7 33
  387. * 8 33
  388. * 9 32
  389. * 10 32
  390. * 11 31
  391. * 12 31
  392. * 13 30
  393. */
  394. static const u32 SNR_EQ[] =
  395. { 1, 2, 2, 2, 3, 3, 4, 4, 5, 7,
  396. 9, 11, 13, 17, 21, 26, 33, 41, 52, 65,
  397. 81, 102, 129, 162, 204, 257, 323, 406, 511, 644,
  398. 810, 1020, 1284, 1616, 2035, 2561, 3224, 4059, 5110, 6433,
  399. 8098, 10195, 12835, 16158, 20341, 25608, 32238, 40585, 51094, 64323,
  400. 80978, 101945, 128341, 161571, 203406, 256073, 0x40000
  401. };
  402. static const u32 SNR_PH[] =
  403. { 1, 2, 2, 2, 3, 3, 4, 5, 6, 8,
  404. 10, 12, 15, 19, 23, 29, 37, 46, 58, 73,
  405. 91, 115, 144, 182, 229, 288, 362, 456, 574, 722,
  406. 909, 1144, 1440, 1813, 2282, 2873, 3617, 4553, 5732, 7216,
  407. 9084, 11436, 14396, 18124, 22817, 28724, 36161, 45524, 57312, 72151,
  408. 90833, 114351, 143960, 181235, 228161, 0x040000
  409. };
  410. static u8 buf[5];/* read data buffer */
  411. static u32 noise; /* noise value */
  412. static u32 snr_db; /* index into SNR_EQ[] */
  413. struct lgdt3302_state* state = (struct lgdt3302_state*) fe->demodulator_priv;
  414. /* read both equalizer and pase tracker noise data */
  415. i2c_selectreadbytes(state, EQPH_ERR0, buf, sizeof(buf));
  416. if (state->current_modulation == VSB_8) {
  417. /* Equalizer Mean-Square Error Register for VSB */
  418. noise = ((buf[0] & 7) << 16) | (buf[1] << 8) | buf[2];
  419. /*
  420. * Look up noise value in table.
  421. * A better search algorithm could be used...
  422. * watch out there are duplicate entries.
  423. */
  424. for (snr_db = 0; snr_db < sizeof(SNR_EQ); snr_db++) {
  425. if (noise < SNR_EQ[snr_db]) {
  426. *snr = 43 - snr_db;
  427. break;
  428. }
  429. }
  430. } else {
  431. /* Phase Tracker Mean-Square Error Register for QAM */
  432. noise = ((buf[0] & 7<<3) << 13) | (buf[3] << 8) | buf[4];
  433. /* Look up noise value in table. */
  434. for (snr_db = 0; snr_db < sizeof(SNR_PH); snr_db++) {
  435. if (noise < SNR_PH[snr_db]) {
  436. *snr = 45 - snr_db;
  437. break;
  438. }
  439. }
  440. }
  441. #else
  442. /* Return the raw noise value */
  443. static u8 buf[5];/* read data buffer */
  444. static u32 noise; /* noise value */
  445. struct lgdt3302_state* state = (struct lgdt3302_state*) fe->demodulator_priv;
  446. /* read both equalizer and pase tracker noise data */
  447. i2c_selectreadbytes(state, EQPH_ERR0, buf, sizeof(buf));
  448. if (state->current_modulation == VSB_8) {
  449. /* Equalizer Mean-Square Error Register for VSB */
  450. noise = ((buf[0] & 7) << 16) | (buf[1] << 8) | buf[2];
  451. } else {
  452. /* Phase Tracker Mean-Square Error Register for QAM */
  453. noise = ((buf[0] & 7<<3) << 13) | (buf[3] << 8) | buf[4];
  454. }
  455. /* Small values for noise mean signal is better so invert noise */
  456. /* Noise is 19 bit value so discard 3 LSB*/
  457. *snr = ~noise>>3;
  458. #endif
  459. dprintk("%s: noise = 0x%05x, snr = %idb\n",__FUNCTION__, noise, *snr);
  460. return 0;
  461. }
  462. static int lgdt3302_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fe_tune_settings)
  463. {
  464. /* I have no idea about this - it may not be needed */
  465. fe_tune_settings->min_delay_ms = 500;
  466. fe_tune_settings->step_size = 0;
  467. fe_tune_settings->max_drift = 0;
  468. return 0;
  469. }
  470. static void lgdt3302_release(struct dvb_frontend* fe)
  471. {
  472. struct lgdt3302_state* state = (struct lgdt3302_state*) fe->demodulator_priv;
  473. kfree(state);
  474. }
  475. static struct dvb_frontend_ops lgdt3302_ops;
  476. struct dvb_frontend* lgdt3302_attach(const struct lgdt3302_config* config,
  477. struct i2c_adapter* i2c)
  478. {
  479. struct lgdt3302_state* state = NULL;
  480. u8 buf[1];
  481. /* Allocate memory for the internal state */
  482. state = (struct lgdt3302_state*) kmalloc(sizeof(struct lgdt3302_state), GFP_KERNEL);
  483. if (state == NULL)
  484. goto error;
  485. memset(state,0,sizeof(*state));
  486. /* Setup the state */
  487. state->config = config;
  488. state->i2c = i2c;
  489. memcpy(&state->ops, &lgdt3302_ops, sizeof(struct dvb_frontend_ops));
  490. /* Verify communication with demod chip */
  491. if (i2c_selectreadbytes(state, 2, buf, 1))
  492. goto error;
  493. state->current_frequency = -1;
  494. state->current_modulation = -1;
  495. /* Create dvb_frontend */
  496. state->frontend.ops = &state->ops;
  497. state->frontend.demodulator_priv = state;
  498. return &state->frontend;
  499. error:
  500. if (state)
  501. kfree(state);
  502. dprintk("%s: ERROR\n",__FUNCTION__);
  503. return NULL;
  504. }
  505. static struct dvb_frontend_ops lgdt3302_ops = {
  506. .info = {
  507. .name= "LG Electronics LGDT3302 VSB/QAM Frontend",
  508. .type = FE_ATSC,
  509. .frequency_min= 54000000,
  510. .frequency_max= 858000000,
  511. .frequency_stepsize= 62500,
  512. /* Symbol rate is for all VSB modes need to check QAM */
  513. .symbol_rate_min = 10762000,
  514. .symbol_rate_max = 10762000,
  515. .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
  516. },
  517. .init = lgdt3302_init,
  518. .set_frontend = lgdt3302_set_parameters,
  519. .get_frontend = lgdt3302_get_frontend,
  520. .get_tune_settings = lgdt3302_get_tune_settings,
  521. .read_status = lgdt3302_read_status,
  522. .read_ber = lgdt3302_read_ber,
  523. .read_signal_strength = lgdt3302_read_signal_strength,
  524. .read_snr = lgdt3302_read_snr,
  525. .read_ucblocks = lgdt3302_read_ucblocks,
  526. .release = lgdt3302_release,
  527. };
  528. MODULE_DESCRIPTION("LGDT3302 [DViCO FusionHDTV 3 Gold] (ATSC 8VSB & ITU-T J.83 AnnexB 64/256 QAM) Demodulator Driver");
  529. MODULE_AUTHOR("Wilson Michaels");
  530. MODULE_LICENSE("GPL");
  531. EXPORT_SYMBOL(lgdt3302_attach);
  532. /*
  533. * Local variables:
  534. * c-basic-offset: 8
  535. * compile-command: "make DVB=1"
  536. * End:
  537. */