Merge branch 'fix/pcm-hwptr' into for-linus
[linux/fpc-iii.git] / drivers / media / dvb / frontends / lgs8gxx.c
blobfde27645bbed67918aca946c1f551dee7a961cea
1 /*
2 * Support for Legend Silicon DMB-TH demodulator
3 * LGS8913, LGS8GL5
4 * experimental support LGS8G42, LGS8G52
6 * Copyright (C) 2007,2008 David T.L. Wong <davidtlwong@gmail.com>
7 * Copyright (C) 2008 Sirius International (Hong Kong) Limited
8 * Timothy Lee <timothy.lee@siriushk.com> (for initial work on LGS8GL5)
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <asm/div64.h>
28 #include "dvb_frontend.h"
30 #include "lgs8gxx.h"
31 #include "lgs8gxx_priv.h"
33 #define dprintk(args...) \
34 do { \
35 if (debug) \
36 printk(KERN_DEBUG "lgs8gxx: " args); \
37 } while (0)
39 static int debug;
40 static int fake_signal_str = 1;
42 module_param(debug, int, 0644);
43 MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
45 module_param(fake_signal_str, int, 0644);
46 MODULE_PARM_DESC(fake_signal_str, "fake signal strength for LGS8913."
47 "Signal strength calculation is slow.(default:on).");
49 /* LGS8GXX internal helper functions */
51 static int lgs8gxx_write_reg(struct lgs8gxx_state *priv, u8 reg, u8 data)
53 int ret;
54 u8 buf[] = { reg, data };
55 struct i2c_msg msg = { .flags = 0, .buf = buf, .len = 2 };
57 msg.addr = priv->config->demod_address;
58 if (reg >= 0xC0)
59 msg.addr += 0x02;
61 if (debug >= 2)
62 printk(KERN_DEBUG "%s: reg=0x%02X, data=0x%02X\n",
63 __func__, reg, data);
65 ret = i2c_transfer(priv->i2c, &msg, 1);
67 if (ret != 1)
68 dprintk(KERN_DEBUG "%s: error reg=0x%x, data=0x%x, ret=%i\n",
69 __func__, reg, data, ret);
71 return (ret != 1) ? -1 : 0;
74 static int lgs8gxx_read_reg(struct lgs8gxx_state *priv, u8 reg, u8 *p_data)
76 int ret;
77 u8 dev_addr;
79 u8 b0[] = { reg };
80 u8 b1[] = { 0 };
81 struct i2c_msg msg[] = {
82 { .flags = 0, .buf = b0, .len = 1 },
83 { .flags = I2C_M_RD, .buf = b1, .len = 1 },
86 dev_addr = priv->config->demod_address;
87 if (reg >= 0xC0)
88 dev_addr += 0x02;
89 msg[1].addr = msg[0].addr = dev_addr;
91 ret = i2c_transfer(priv->i2c, msg, 2);
92 if (ret != 2) {
93 dprintk(KERN_DEBUG "%s: error reg=0x%x, ret=%i\n",
94 __func__, reg, ret);
95 return -1;
98 *p_data = b1[0];
99 if (debug >= 2)
100 printk(KERN_DEBUG "%s: reg=0x%02X, data=0x%02X\n",
101 __func__, reg, b1[0]);
102 return 0;
105 static int lgs8gxx_soft_reset(struct lgs8gxx_state *priv)
107 lgs8gxx_write_reg(priv, 0x02, 0x00);
108 msleep(1);
109 lgs8gxx_write_reg(priv, 0x02, 0x01);
110 msleep(100);
112 return 0;
115 static int lgs8gxx_set_ad_mode(struct lgs8gxx_state *priv)
117 const struct lgs8gxx_config *config = priv->config;
118 u8 if_conf;
120 if_conf = 0x10; /* AGC output on; */
122 if_conf |=
123 ((config->ext_adc) ? 0x80 : 0x00) |
124 ((config->if_neg_center) ? 0x04 : 0x00) |
125 ((config->if_freq == 0) ? 0x08 : 0x00) | /* Baseband */
126 ((config->ext_adc && config->adc_signed) ? 0x02 : 0x00) |
127 ((config->ext_adc && config->if_neg_edge) ? 0x01 : 0x00);
129 if (config->ext_adc &&
130 (config->prod == LGS8GXX_PROD_LGS8G52)) {
131 lgs8gxx_write_reg(priv, 0xBA, 0x40);
134 lgs8gxx_write_reg(priv, 0x07, if_conf);
136 return 0;
139 static int lgs8gxx_set_if_freq(struct lgs8gxx_state *priv, u32 freq /*in kHz*/)
141 u64 val;
142 u32 v32;
143 u32 if_clk;
145 if_clk = priv->config->if_clk_freq;
147 val = freq;
148 if (freq != 0) {
149 val *= (u64)1 << 32;
150 if (if_clk != 0)
151 do_div(val, if_clk);
152 v32 = val & 0xFFFFFFFF;
153 dprintk("Set IF Freq to %dkHz\n", freq);
154 } else {
155 v32 = 0;
156 dprintk("Set IF Freq to baseband\n");
158 dprintk("AFC_INIT_FREQ = 0x%08X\n", v32);
160 lgs8gxx_write_reg(priv, 0x09, 0xFF & (v32));
161 lgs8gxx_write_reg(priv, 0x0A, 0xFF & (v32 >> 8));
162 lgs8gxx_write_reg(priv, 0x0B, 0xFF & (v32 >> 16));
163 lgs8gxx_write_reg(priv, 0x0C, 0xFF & (v32 >> 24));
165 return 0;
168 static int lgs8gxx_set_mode_auto(struct lgs8gxx_state *priv)
170 u8 t;
172 if (priv->config->prod == LGS8GXX_PROD_LGS8913)
173 lgs8gxx_write_reg(priv, 0xC6, 0x01);
175 lgs8gxx_read_reg(priv, 0x7E, &t);
176 lgs8gxx_write_reg(priv, 0x7E, t | 0x01);
178 /* clear FEC self reset */
179 lgs8gxx_read_reg(priv, 0xC5, &t);
180 lgs8gxx_write_reg(priv, 0xC5, t & 0xE0);
182 if (priv->config->prod == LGS8GXX_PROD_LGS8913) {
183 /* FEC auto detect */
184 lgs8gxx_write_reg(priv, 0xC1, 0x03);
186 lgs8gxx_read_reg(priv, 0x7C, &t);
187 t = (t & 0x8C) | 0x03;
188 lgs8gxx_write_reg(priv, 0x7C, t);
192 if (priv->config->prod == LGS8GXX_PROD_LGS8913) {
193 /* BER test mode */
194 lgs8gxx_read_reg(priv, 0xC3, &t);
195 t = (t & 0xEF) | 0x10;
196 lgs8gxx_write_reg(priv, 0xC3, t);
199 if (priv->config->prod == LGS8GXX_PROD_LGS8G52)
200 lgs8gxx_write_reg(priv, 0xD9, 0x40);
202 return 0;
205 static int lgs8gxx_set_mode_manual(struct lgs8gxx_state *priv)
207 int ret = 0;
208 u8 t;
210 /* turn off auto-detect; manual settings */
211 lgs8gxx_write_reg(priv, 0x7E, 0);
212 if (priv->config->prod == LGS8GXX_PROD_LGS8913)
213 lgs8gxx_write_reg(priv, 0xC1, 0);
215 ret = lgs8gxx_read_reg(priv, 0xC5, &t);
216 t = (t & 0xE0) | 0x06;
217 lgs8gxx_write_reg(priv, 0xC5, t);
219 lgs8gxx_soft_reset(priv);
221 return 0;
224 static int lgs8gxx_is_locked(struct lgs8gxx_state *priv, u8 *locked)
226 int ret = 0;
227 u8 t;
229 ret = lgs8gxx_read_reg(priv, 0x4B, &t);
230 if (ret != 0)
231 return ret;
233 *locked = ((t & 0xC0) == 0xC0) ? 1 : 0;
234 return 0;
237 static int lgs8gxx_is_autodetect_finished(struct lgs8gxx_state *priv,
238 u8 *finished)
240 int ret = 0;
241 u8 t;
243 ret = lgs8gxx_read_reg(priv, 0xA4, &t);
244 if (ret != 0)
245 return ret;
247 *finished = ((t & 0x3) == 0x1) ? 1 : 0;
249 return 0;
252 static int lgs8gxx_autolock_gi(struct lgs8gxx_state *priv, u8 gi, u8 *locked)
254 int err;
255 u8 ad_fini = 0;
257 if (gi == GI_945)
258 dprintk("try GI 945\n");
259 else if (gi == GI_595)
260 dprintk("try GI 595\n");
261 else if (gi == GI_420)
262 dprintk("try GI 420\n");
263 lgs8gxx_write_reg(priv, 0x04, gi);
264 lgs8gxx_soft_reset(priv);
265 msleep(50);
266 err = lgs8gxx_is_autodetect_finished(priv, &ad_fini);
267 if (err != 0)
268 return err;
269 if (ad_fini) {
270 err = lgs8gxx_is_locked(priv, locked);
271 if (err != 0)
272 return err;
275 return 0;
278 static int lgs8gxx_auto_detect(struct lgs8gxx_state *priv,
279 u8 *detected_param, u8 *gi)
281 int i, j;
282 int err = 0;
283 u8 locked = 0, tmp_gi;
285 dprintk("%s\n", __func__);
287 lgs8gxx_set_mode_auto(priv);
288 /* Guard Interval */
289 lgs8gxx_write_reg(priv, 0x03, 00);
291 for (i = 0; i < 2; i++) {
292 for (j = 0; j < 2; j++) {
293 tmp_gi = GI_945;
294 err = lgs8gxx_autolock_gi(priv, GI_945, &locked);
295 if (err)
296 goto out;
297 if (locked)
298 goto locked;
300 for (j = 0; j < 2; j++) {
301 tmp_gi = GI_420;
302 err = lgs8gxx_autolock_gi(priv, GI_420, &locked);
303 if (err)
304 goto out;
305 if (locked)
306 goto locked;
308 tmp_gi = GI_595;
309 err = lgs8gxx_autolock_gi(priv, GI_595, &locked);
310 if (err)
311 goto out;
312 if (locked)
313 goto locked;
316 locked:
317 if ((err == 0) && (locked == 1)) {
318 u8 t;
320 lgs8gxx_read_reg(priv, 0xA2, &t);
321 *detected_param = t;
323 if (tmp_gi == GI_945)
324 dprintk("GI 945 locked\n");
325 else if (tmp_gi == GI_595)
326 dprintk("GI 595 locked\n");
327 else if (tmp_gi == GI_420)
328 dprintk("GI 420 locked\n");
329 *gi = tmp_gi;
331 if (!locked)
332 err = -1;
334 out:
335 return err;
338 static void lgs8gxx_auto_lock(struct lgs8gxx_state *priv)
340 s8 err;
341 u8 gi = 0x2;
342 u8 detected_param = 0;
344 err = lgs8gxx_auto_detect(priv, &detected_param, &gi);
346 if (err != 0) {
347 dprintk("lgs8gxx_auto_detect failed\n");
350 /* Apply detected parameters */
351 if (priv->config->prod == LGS8GXX_PROD_LGS8913) {
352 u8 inter_leave_len = detected_param & TIM_MASK ;
353 inter_leave_len = (inter_leave_len == TIM_LONG) ? 0x60 : 0x40;
354 detected_param &= CF_MASK | SC_MASK | LGS_FEC_MASK;
355 detected_param |= inter_leave_len;
357 lgs8gxx_write_reg(priv, 0x7D, detected_param);
358 if (priv->config->prod == LGS8GXX_PROD_LGS8913)
359 lgs8gxx_write_reg(priv, 0xC0, detected_param);
360 /* lgs8gxx_soft_reset(priv); */
362 /* Enter manual mode */
363 lgs8gxx_set_mode_manual(priv);
365 switch (gi) {
366 case GI_945:
367 priv->curr_gi = 945; break;
368 case GI_595:
369 priv->curr_gi = 595; break;
370 case GI_420:
371 priv->curr_gi = 420; break;
372 default:
373 priv->curr_gi = 945; break;
377 static int lgs8gxx_set_mpeg_mode(struct lgs8gxx_state *priv,
378 u8 serial, u8 clk_pol, u8 clk_gated)
380 int ret = 0;
381 u8 t;
383 ret = lgs8gxx_read_reg(priv, 0xC2, &t);
384 if (ret != 0)
385 return ret;
387 t &= 0xF8;
388 t |= serial ? TS_SERIAL : TS_PARALLEL;
389 t |= clk_pol ? TS_CLK_INVERTED : TS_CLK_NORMAL;
390 t |= clk_gated ? TS_CLK_GATED : TS_CLK_FREERUN;
392 ret = lgs8gxx_write_reg(priv, 0xC2, t);
393 if (ret != 0)
394 return ret;
396 return 0;
400 /* LGS8913 demod frontend functions */
402 static int lgs8913_init(struct lgs8gxx_state *priv)
404 u8 t;
406 /* LGS8913 specific */
407 lgs8gxx_write_reg(priv, 0xc1, 0x3);
409 lgs8gxx_read_reg(priv, 0x7c, &t);
410 lgs8gxx_write_reg(priv, 0x7c, (t&0x8c) | 0x3);
412 /* LGS8913 specific */
413 lgs8gxx_read_reg(priv, 0xc3, &t);
414 lgs8gxx_write_reg(priv, 0xc3, t&0x10);
417 return 0;
420 static int lgs8gxx_init(struct dvb_frontend *fe)
422 struct lgs8gxx_state *priv =
423 (struct lgs8gxx_state *)fe->demodulator_priv;
424 const struct lgs8gxx_config *config = priv->config;
425 u8 data = 0;
426 s8 err;
427 dprintk("%s\n", __func__);
429 lgs8gxx_read_reg(priv, 0, &data);
430 dprintk("reg 0 = 0x%02X\n", data);
432 /* Setup MPEG output format */
433 err = lgs8gxx_set_mpeg_mode(priv, config->serial_ts,
434 config->ts_clk_pol,
435 config->ts_clk_gated);
436 if (err != 0)
437 return -EIO;
439 if (config->prod == LGS8GXX_PROD_LGS8913)
440 lgs8913_init(priv);
441 lgs8gxx_set_if_freq(priv, priv->config->if_freq);
442 if (config->prod != LGS8GXX_PROD_LGS8913)
443 lgs8gxx_set_ad_mode(priv);
445 return 0;
448 static void lgs8gxx_release(struct dvb_frontend *fe)
450 struct lgs8gxx_state *state = fe->demodulator_priv;
451 dprintk("%s\n", __func__);
453 kfree(state);
457 static int lgs8gxx_write(struct dvb_frontend *fe, u8 *buf, int len)
459 struct lgs8gxx_state *priv = fe->demodulator_priv;
461 if (len != 2)
462 return -EINVAL;
464 return lgs8gxx_write_reg(priv, buf[0], buf[1]);
467 static int lgs8gxx_set_fe(struct dvb_frontend *fe,
468 struct dvb_frontend_parameters *fe_params)
470 struct lgs8gxx_state *priv = fe->demodulator_priv;
472 dprintk("%s\n", __func__);
474 /* set frequency */
475 if (fe->ops.tuner_ops.set_params) {
476 fe->ops.tuner_ops.set_params(fe, fe_params);
477 if (fe->ops.i2c_gate_ctrl)
478 fe->ops.i2c_gate_ctrl(fe, 0);
481 /* start auto lock */
482 lgs8gxx_auto_lock(priv);
484 msleep(10);
486 return 0;
489 static int lgs8gxx_get_fe(struct dvb_frontend *fe,
490 struct dvb_frontend_parameters *fe_params)
492 struct lgs8gxx_state *priv = fe->demodulator_priv;
493 u8 t;
495 dprintk("%s\n", __func__);
497 /* TODO: get real readings from device */
498 /* inversion status */
499 fe_params->inversion = INVERSION_OFF;
501 /* bandwidth */
502 fe_params->u.ofdm.bandwidth = BANDWIDTH_8_MHZ;
505 lgs8gxx_read_reg(priv, 0x7D, &t);
506 fe_params->u.ofdm.code_rate_HP = FEC_AUTO;
507 fe_params->u.ofdm.code_rate_LP = FEC_AUTO;
509 /* constellation */
510 switch (t & SC_MASK) {
511 case SC_QAM64:
512 fe_params->u.ofdm.constellation = QAM_64;
513 break;
514 case SC_QAM32:
515 fe_params->u.ofdm.constellation = QAM_32;
516 break;
517 case SC_QAM16:
518 fe_params->u.ofdm.constellation = QAM_16;
519 break;
520 case SC_QAM4:
521 case SC_QAM4NR:
522 fe_params->u.ofdm.constellation = QPSK;
523 break;
524 default:
525 fe_params->u.ofdm.constellation = QAM_64;
528 /* transmission mode */
529 fe_params->u.ofdm.transmission_mode = TRANSMISSION_MODE_AUTO;
531 /* guard interval */
532 fe_params->u.ofdm.guard_interval = GUARD_INTERVAL_AUTO;
534 /* hierarchy */
535 fe_params->u.ofdm.hierarchy_information = HIERARCHY_NONE;
537 return 0;
540 static
541 int lgs8gxx_get_tune_settings(struct dvb_frontend *fe,
542 struct dvb_frontend_tune_settings *fesettings)
544 /* FIXME: copy from tda1004x.c */
545 fesettings->min_delay_ms = 800;
546 fesettings->step_size = 0;
547 fesettings->max_drift = 0;
548 return 0;
551 static int lgs8gxx_read_status(struct dvb_frontend *fe, fe_status_t *fe_status)
553 struct lgs8gxx_state *priv = fe->demodulator_priv;
554 s8 ret;
555 u8 t;
557 dprintk("%s\n", __func__);
559 ret = lgs8gxx_read_reg(priv, 0x4B, &t);
560 if (ret != 0)
561 return -EIO;
563 dprintk("Reg 0x4B: 0x%02X\n", t);
565 *fe_status = 0;
566 if (priv->config->prod == LGS8GXX_PROD_LGS8913) {
567 if ((t & 0x40) == 0x40)
568 *fe_status |= FE_HAS_SIGNAL | FE_HAS_CARRIER;
569 if ((t & 0x80) == 0x80)
570 *fe_status |= FE_HAS_VITERBI | FE_HAS_SYNC |
571 FE_HAS_LOCK;
572 } else {
573 if ((t & 0x80) == 0x80)
574 *fe_status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
575 FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
578 /* success */
579 dprintk("%s: fe_status=0x%x\n", __func__, *fe_status);
580 return 0;
583 static int lgs8gxx_read_signal_agc(struct lgs8gxx_state *priv, u16 *signal)
585 u16 v;
586 u8 agc_lvl[2], cat;
588 dprintk("%s()\n", __func__);
589 lgs8gxx_read_reg(priv, 0x3F, &agc_lvl[0]);
590 lgs8gxx_read_reg(priv, 0x3E, &agc_lvl[1]);
592 v = agc_lvl[0];
593 v <<= 8;
594 v |= agc_lvl[1];
596 dprintk("agc_lvl: 0x%04X\n", v);
598 if (v < 0x100)
599 cat = 0;
600 else if (v < 0x190)
601 cat = 5;
602 else if (v < 0x2A8)
603 cat = 4;
604 else if (v < 0x381)
605 cat = 3;
606 else if (v < 0x400)
607 cat = 2;
608 else if (v == 0x400)
609 cat = 1;
610 else
611 cat = 0;
613 *signal = cat * 65535 / 5;
615 return 0;
618 static int lgs8913_read_signal_strength(struct lgs8gxx_state *priv, u16 *signal)
620 u8 t; s8 ret;
621 s16 max_strength = 0;
622 u8 str;
623 u16 i, gi = priv->curr_gi;
625 dprintk("%s\n", __func__);
627 ret = lgs8gxx_read_reg(priv, 0x4B, &t);
628 if (ret != 0)
629 return -EIO;
631 if (fake_signal_str) {
632 if ((t & 0xC0) == 0xC0) {
633 dprintk("Fake signal strength\n");
634 *signal = 0x7FFF;
635 } else
636 *signal = 0;
637 return 0;
640 dprintk("gi = %d\n", gi);
641 for (i = 0; i < gi; i++) {
643 if ((i & 0xFF) == 0)
644 lgs8gxx_write_reg(priv, 0x84, 0x03 & (i >> 8));
645 lgs8gxx_write_reg(priv, 0x83, i & 0xFF);
647 lgs8gxx_read_reg(priv, 0x94, &str);
648 if (max_strength < str)
649 max_strength = str;
652 *signal = max_strength;
653 dprintk("%s: signal=0x%02X\n", __func__, *signal);
655 lgs8gxx_read_reg(priv, 0x95, &t);
656 dprintk("%s: AVG Noise=0x%02X\n", __func__, t);
658 return 0;
661 static int lgs8gxx_read_signal_strength(struct dvb_frontend *fe, u16 *signal)
663 struct lgs8gxx_state *priv = fe->demodulator_priv;
665 if (priv->config->prod == LGS8GXX_PROD_LGS8913)
666 return lgs8913_read_signal_strength(priv, signal);
667 else
668 return lgs8gxx_read_signal_agc(priv, signal);
671 static int lgs8gxx_read_snr(struct dvb_frontend *fe, u16 *snr)
673 struct lgs8gxx_state *priv = fe->demodulator_priv;
674 u8 t;
675 *snr = 0;
677 lgs8gxx_read_reg(priv, 0x95, &t);
678 dprintk("AVG Noise=0x%02X\n", t);
679 *snr = 256 - t;
680 *snr <<= 8;
681 dprintk("snr=0x%x\n", *snr);
683 return 0;
686 static int lgs8gxx_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
688 *ucblocks = 0;
689 dprintk("%s: ucblocks=0x%x\n", __func__, *ucblocks);
690 return 0;
693 static int lgs8gxx_read_ber(struct dvb_frontend *fe, u32 *ber)
695 struct lgs8gxx_state *priv = fe->demodulator_priv;
696 u8 r0, r1, r2, r3;
697 u32 total_cnt, err_cnt;
699 dprintk("%s\n", __func__);
701 lgs8gxx_write_reg(priv, 0xc6, 0x01);
702 lgs8gxx_write_reg(priv, 0xc6, 0x41);
703 lgs8gxx_write_reg(priv, 0xc6, 0x01);
705 msleep(200);
707 lgs8gxx_write_reg(priv, 0xc6, 0x81);
708 lgs8gxx_read_reg(priv, 0xd0, &r0);
709 lgs8gxx_read_reg(priv, 0xd1, &r1);
710 lgs8gxx_read_reg(priv, 0xd2, &r2);
711 lgs8gxx_read_reg(priv, 0xd3, &r3);
712 total_cnt = (r3 << 24) | (r2 << 16) | (r1 << 8) | (r0);
713 lgs8gxx_read_reg(priv, 0xd4, &r0);
714 lgs8gxx_read_reg(priv, 0xd5, &r1);
715 lgs8gxx_read_reg(priv, 0xd6, &r2);
716 lgs8gxx_read_reg(priv, 0xd7, &r3);
717 err_cnt = (r3 << 24) | (r2 << 16) | (r1 << 8) | (r0);
718 dprintk("error=%d total=%d\n", err_cnt, total_cnt);
720 if (total_cnt == 0)
721 *ber = 0;
722 else
723 *ber = err_cnt * 100 / total_cnt;
725 dprintk("%s: ber=0x%x\n", __func__, *ber);
726 return 0;
729 static int lgs8gxx_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
731 struct lgs8gxx_state *priv = fe->demodulator_priv;
733 if (priv->config->tuner_address == 0)
734 return 0;
735 if (enable) {
736 u8 v = 0x80 | priv->config->tuner_address;
737 return lgs8gxx_write_reg(priv, 0x01, v);
739 return lgs8gxx_write_reg(priv, 0x01, 0);
742 static struct dvb_frontend_ops lgs8gxx_ops = {
743 .info = {
744 .name = "Legend Silicon LGS8913/LGS8GXX DMB-TH",
745 .type = FE_OFDM,
746 .frequency_min = 474000000,
747 .frequency_max = 858000000,
748 .frequency_stepsize = 10000,
749 .caps =
750 FE_CAN_FEC_AUTO |
751 FE_CAN_QAM_AUTO |
752 FE_CAN_TRANSMISSION_MODE_AUTO |
753 FE_CAN_GUARD_INTERVAL_AUTO
756 .release = lgs8gxx_release,
758 .init = lgs8gxx_init,
759 .write = lgs8gxx_write,
760 .i2c_gate_ctrl = lgs8gxx_i2c_gate_ctrl,
762 .set_frontend = lgs8gxx_set_fe,
763 .get_frontend = lgs8gxx_get_fe,
764 .get_tune_settings = lgs8gxx_get_tune_settings,
766 .read_status = lgs8gxx_read_status,
767 .read_ber = lgs8gxx_read_ber,
768 .read_signal_strength = lgs8gxx_read_signal_strength,
769 .read_snr = lgs8gxx_read_snr,
770 .read_ucblocks = lgs8gxx_read_ucblocks,
773 struct dvb_frontend *lgs8gxx_attach(const struct lgs8gxx_config *config,
774 struct i2c_adapter *i2c)
776 struct lgs8gxx_state *priv = NULL;
777 u8 data = 0;
779 dprintk("%s()\n", __func__);
781 if (config == NULL || i2c == NULL)
782 return NULL;
784 priv = kzalloc(sizeof(struct lgs8gxx_state), GFP_KERNEL);
785 if (priv == NULL)
786 goto error_out;
788 priv->config = config;
789 priv->i2c = i2c;
791 /* check if the demod is there */
792 if (lgs8gxx_read_reg(priv, 0, &data) != 0) {
793 dprintk("%s lgs8gxx not found at i2c addr 0x%02X\n",
794 __func__, priv->config->demod_address);
795 goto error_out;
798 lgs8gxx_read_reg(priv, 1, &data);
800 memcpy(&priv->frontend.ops, &lgs8gxx_ops,
801 sizeof(struct dvb_frontend_ops));
802 priv->frontend.demodulator_priv = priv;
804 return &priv->frontend;
806 error_out:
807 dprintk("%s() error_out\n", __func__);
808 kfree(priv);
809 return NULL;
812 EXPORT_SYMBOL(lgs8gxx_attach);
814 MODULE_DESCRIPTION("Legend Silicon LGS8913/LGS8GXX DMB-TH demodulator driver");
815 MODULE_AUTHOR("David T. L. Wong <davidtlwong@gmail.com>");
816 MODULE_LICENSE("GPL");