1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32#include <linux/kernel.h>
33#include <linux/module.h>
34#include <linux/init.h>
35#include <linux/delay.h>
36#include <linux/string.h>
37#include <linux/slab.h>
38#include <asm/byteorder.h>
39
40#include <media/dvb_frontend.h>
41#include <media/dvb_math.h>
42#include "lgdt330x_priv.h"
43#include "lgdt330x.h"
44
45
46
47
48static int debug;
49module_param(debug, int, 0644);
50MODULE_PARM_DESC(debug, "Turn on/off lgdt330x frontend debugging (default:off).");
51
52#define dprintk(state, fmt, arg...) do { \
53 if (debug) \
54 dev_printk(KERN_DEBUG, &state->client->dev, fmt, ##arg);\
55} while (0)
56
57struct lgdt330x_state {
58 struct i2c_client *client;
59
60
61 struct lgdt330x_config config;
62
63 struct dvb_frontend frontend;
64
65
66 enum fe_modulation current_modulation;
67 u32 snr;
68 u16 ucblocks;
69 unsigned long last_stats_time;
70
71
72 u32 current_frequency;
73};
74
75static int i2c_write_demod_bytes(struct lgdt330x_state *state,
76 const u8 *buf,
77 int len )
78{
79 int i;
80 int err;
81
82 for (i = 0; i < len - 1; i += 2) {
83 err = i2c_master_send(state->client, buf, 2);
84 if (err != 2) {
85 dev_warn(&state->client->dev,
86 "%s: error (addr %02x <- %02x, err = %i)\n",
87 __func__, buf[0], buf[1], err);
88 if (err < 0)
89 return err;
90 else
91 return -EREMOTEIO;
92 }
93 buf += 2;
94 }
95 return 0;
96}
97
98
99
100
101
102static int i2c_read_demod_bytes(struct lgdt330x_state *state,
103 enum I2C_REG reg, u8 *buf, int len)
104{
105 u8 wr[] = { reg };
106 struct i2c_msg msg[] = {
107 {
108 .addr = state->client->addr,
109 .flags = 0,
110 .buf = wr,
111 .len = 1
112 }, {
113 .addr = state->client->addr,
114 .flags = I2C_M_RD,
115 .buf = buf,
116 .len = len
117 },
118 };
119 int ret;
120
121 ret = i2c_transfer(state->client->adapter, msg, 2);
122 if (ret != 2) {
123 dev_warn(&state->client->dev,
124 "%s: addr 0x%02x select 0x%02x error (ret == %i)\n",
125 __func__, state->client->addr, reg, ret);
126 if (ret >= 0)
127 ret = -EIO;
128 } else {
129 ret = 0;
130 }
131 return ret;
132}
133
134
135static int lgdt3302_sw_reset(struct lgdt330x_state *state)
136{
137 u8 ret;
138 u8 reset[] = {
139 IRQ_MASK,
140
141
142
143
144 0x00
145 };
146
147 ret = i2c_write_demod_bytes(state,
148 reset, sizeof(reset));
149 if (ret == 0) {
150
151 reset[1] = 0x7f;
152 ret = i2c_write_demod_bytes(state,
153 reset, sizeof(reset));
154 }
155 return ret;
156}
157
158static int lgdt3303_sw_reset(struct lgdt330x_state *state)
159{
160 u8 ret;
161 u8 reset[] = {
162 0x02,
163 0x00
164 };
165
166 ret = i2c_write_demod_bytes(state,
167 reset, sizeof(reset));
168 if (ret == 0) {
169
170 reset[1] = 0x01;
171 ret = i2c_write_demod_bytes(state,
172 reset, sizeof(reset));
173 }
174 return ret;
175}
176
177static int lgdt330x_sw_reset(struct lgdt330x_state *state)
178{
179 switch (state->config.demod_chip) {
180 case LGDT3302:
181 return lgdt3302_sw_reset(state);
182 case LGDT3303:
183 return lgdt3303_sw_reset(state);
184 default:
185 return -ENODEV;
186 }
187}
188
189static int lgdt330x_init(struct dvb_frontend *fe)
190{
191 struct lgdt330x_state *state = fe->demodulator_priv;
192 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
193 char *chip_name;
194 int err;
195
196
197
198
199 static const u8 lgdt3302_init_data[] = {
200
201
202
203
204
205 VSB_CARRIER_FREQ0, 0x00,
206 VSB_CARRIER_FREQ1, 0x87,
207 VSB_CARRIER_FREQ2, 0x8e,
208 VSB_CARRIER_FREQ3, 0x01,
209
210
211
212
213 DEMUX_CONTROL, 0xfb,
214
215
216
217
218 AGC_RF_BANDWIDTH0, 0x40,
219 AGC_RF_BANDWIDTH1, 0x93,
220 AGC_RF_BANDWIDTH2, 0x00,
221
222
223
224
225 AGC_FUNC_CTRL2, 0xc6,
226
227
228
229
230 AGC_FUNC_CTRL3, 0x40,
231
232
233
234
235 AGC_DELAY0, 0x07,
236 AGC_DELAY2, 0xfe,
237
238
239
240
241 AGC_LOOP_BANDWIDTH0, 0x08,
242 AGC_LOOP_BANDWIDTH1, 0x9a
243 };
244 static const u8 lgdt3303_init_data[] = {
245 0x4c, 0x14
246 };
247 static const u8 flip_1_lgdt3303_init_data[] = {
248 0x4c, 0x14,
249 0x87, 0xf3
250 };
251 static const u8 flip_2_lgdt3303_init_data[] = {
252 0x4c, 0x14,
253 0x87, 0xda
254 };
255
256
257
258
259
260
261
262
263
264 switch (state->config.demod_chip) {
265 case LGDT3302:
266 chip_name = "LGDT3302";
267 err = i2c_write_demod_bytes(state, lgdt3302_init_data,
268 sizeof(lgdt3302_init_data));
269 break;
270 case LGDT3303:
271 chip_name = "LGDT3303";
272 switch (state->config.clock_polarity_flip) {
273 case 2:
274 err = i2c_write_demod_bytes(state,
275 flip_2_lgdt3303_init_data,
276 sizeof(flip_2_lgdt3303_init_data));
277 break;
278 case 1:
279 err = i2c_write_demod_bytes(state,
280 flip_1_lgdt3303_init_data,
281 sizeof(flip_1_lgdt3303_init_data));
282 break;
283 case 0:
284 default:
285 err = i2c_write_demod_bytes(state, lgdt3303_init_data,
286 sizeof(lgdt3303_init_data));
287 }
288 break;
289 default:
290 chip_name = "undefined";
291 dev_warn(&state->client->dev,
292 "Only LGDT3302 and LGDT3303 are supported chips.\n");
293 err = -ENODEV;
294 }
295 dprintk(state, "Initialized the %s chip\n", chip_name);
296 if (err < 0)
297 return err;
298
299 p->cnr.len = 1;
300 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
301 p->block_error.len = 1;
302 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
303 p->block_count.len = 1;
304 p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
305 state->last_stats_time = 0;
306
307 return lgdt330x_sw_reset(state);
308}
309
310static int lgdt330x_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
311{
312 struct lgdt330x_state *state = fe->demodulator_priv;
313
314 *ucblocks = state->ucblocks;
315
316 return 0;
317}
318
319static int lgdt330x_set_parameters(struct dvb_frontend *fe)
320{
321 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
322 struct lgdt330x_state *state = fe->demodulator_priv;
323
324
325
326
327 static const u8 lgdt3303_8vsb_44_data[] = {
328 0x04, 0x00,
329 0x0d, 0x40,
330 0x0e, 0x87,
331 0x0f, 0x8e,
332 0x10, 0x01,
333 0x47, 0x8b
334 };
335
336
337
338
339 static const u8 lgdt3303_qam_data[] = {
340 0x04, 0x00,
341 0x0d, 0x00,
342 0x0e, 0x00,
343 0x0f, 0x00,
344 0x10, 0x00,
345 0x51, 0x63,
346 0x47, 0x66,
347 0x48, 0x66,
348 0x4d, 0x1a,
349 0x49, 0x08,
350 0x4a, 0x9b
351 };
352 u8 top_ctrl_cfg[] = { TOP_CONTROL, 0x03 };
353
354 int err = 0;
355
356 if (state->current_modulation != p->modulation) {
357 switch (p->modulation) {
358 case VSB_8:
359 dprintk(state, "VSB_8 MODE\n");
360
361
362 top_ctrl_cfg[1] = 0x03;
363
364
365 if (state->config.pll_rf_set)
366 state->config.pll_rf_set(fe, 1);
367
368 if (state->config.demod_chip == LGDT3303) {
369 err = i2c_write_demod_bytes(state,
370 lgdt3303_8vsb_44_data,
371 sizeof(lgdt3303_8vsb_44_data));
372 }
373 break;
374
375 case QAM_64:
376 dprintk(state, "QAM_64 MODE\n");
377
378
379 top_ctrl_cfg[1] = 0x00;
380
381
382 if (state->config.pll_rf_set)
383 state->config.pll_rf_set(fe, 0);
384
385 if (state->config.demod_chip == LGDT3303) {
386 err = i2c_write_demod_bytes(state,
387 lgdt3303_qam_data,
388 sizeof(lgdt3303_qam_data));
389 }
390 break;
391
392 case QAM_256:
393 dprintk(state, "QAM_256 MODE\n");
394
395
396 top_ctrl_cfg[1] = 0x01;
397
398
399 if (state->config.pll_rf_set)
400 state->config.pll_rf_set(fe, 0);
401
402 if (state->config.demod_chip == LGDT3303) {
403 err = i2c_write_demod_bytes(state,
404 lgdt3303_qam_data,
405 sizeof(lgdt3303_qam_data));
406 }
407 break;
408 default:
409 dev_warn(&state->client->dev,
410 "%s: Modulation type(%d) UNSUPPORTED\n",
411 __func__, p->modulation);
412 return -1;
413 }
414 if (err < 0)
415 dev_warn(&state->client->dev,
416 "%s: error blasting bytes to lgdt3303 for modulation type(%d)\n",
417 __func__, p->modulation);
418
419
420
421
422
423
424 top_ctrl_cfg[1] |= state->config.serial_mpeg;
425
426
427 i2c_write_demod_bytes(state, top_ctrl_cfg,
428 sizeof(top_ctrl_cfg));
429 if (state->config.set_ts_params)
430 state->config.set_ts_params(fe, 0);
431 state->current_modulation = p->modulation;
432 }
433
434
435 if (fe->ops.tuner_ops.set_params) {
436 fe->ops.tuner_ops.set_params(fe);
437 if (fe->ops.i2c_gate_ctrl)
438 fe->ops.i2c_gate_ctrl(fe, 0);
439 }
440
441
442
443
444
445
446 state->current_frequency = p->frequency;
447
448 lgdt330x_sw_reset(state);
449 return 0;
450}
451
452static int lgdt330x_get_frontend(struct dvb_frontend *fe,
453 struct dtv_frontend_properties *p)
454{
455 struct lgdt330x_state *state = fe->demodulator_priv;
456
457 p->frequency = state->current_frequency;
458 return 0;
459}
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485static u32 calculate_snr(u32 mse, u32 c)
486{
487 if (mse == 0)
488 return 0;
489
490 mse = intlog10(mse);
491 if (mse > c) {
492
493
494
495
496
497 return 0;
498 }
499 return 10 * (c - mse);
500}
501
502static int lgdt3302_read_snr(struct dvb_frontend *fe)
503{
504 struct lgdt330x_state *state = fe->demodulator_priv;
505 u8 buf[5];
506 u32 noise;
507 u32 c;
508
509 switch (state->current_modulation) {
510 case VSB_8:
511 i2c_read_demod_bytes(state, LGDT3302_EQPH_ERR0, buf, 5);
512#ifdef USE_EQMSE
513
514
515 noise = ((buf[0] & 7) << 16) | (buf[1] << 8) | buf[2];
516 c = 69765745;
517#else
518
519
520 noise = ((buf[0] & 7 << 3) << 13) | (buf[3] << 8) | buf[4];
521 c = 73957994;
522#endif
523 break;
524 case QAM_64:
525 case QAM_256:
526 i2c_read_demod_bytes(state, CARRIER_MSEQAM1, buf, 2);
527 noise = ((buf[0] & 3) << 8) | buf[1];
528 c = state->current_modulation == QAM_64 ? 97939837 : 98026066;
529
530 break;
531 default:
532 dev_err(&state->client->dev,
533 "%s: Modulation set to unsupported value\n",
534 __func__);
535
536 state->snr = 0;
537
538 return -EREMOTEIO;
539 }
540
541 state->snr = calculate_snr(noise, c);
542
543 dprintk(state, "noise = 0x%08x, snr = %d.%02d dB\n", noise,
544 state->snr >> 24, (((state->snr >> 8) & 0xffff) * 100) >> 16);
545
546 return 0;
547}
548
549static int lgdt3303_read_snr(struct dvb_frontend *fe)
550{
551 struct lgdt330x_state *state = fe->demodulator_priv;
552 u8 buf[5];
553 u32 noise;
554 u32 c;
555
556 switch (state->current_modulation) {
557 case VSB_8:
558 i2c_read_demod_bytes(state, LGDT3303_EQPH_ERR0, buf, 5);
559#ifdef USE_EQMSE
560
561
562 noise = ((buf[0] & 0x78) << 13) | (buf[1] << 8) | buf[2];
563 c = 73957994;
564#else
565
566
567 noise = ((buf[0] & 7) << 16) | (buf[3] << 8) | buf[4];
568 c = 73957994;
569#endif
570 break;
571 case QAM_64:
572 case QAM_256:
573 i2c_read_demod_bytes(state, CARRIER_MSEQAM1, buf, 2);
574 noise = (buf[0] << 8) | buf[1];
575 c = state->current_modulation == QAM_64 ? 97939837 : 98026066;
576
577 break;
578 default:
579 dev_err(&state->client->dev,
580 "%s: Modulation set to unsupported value\n",
581 __func__);
582 state->snr = 0;
583 return -EREMOTEIO;
584 }
585
586 state->snr = calculate_snr(noise, c);
587
588 dprintk(state, "noise = 0x%08x, snr = %d.%02d dB\n", noise,
589 state->snr >> 24, (((state->snr >> 8) & 0xffff) * 100) >> 16);
590
591 return 0;
592}
593
594static int lgdt330x_read_snr(struct dvb_frontend *fe, u16 *snr)
595{
596 struct lgdt330x_state *state = fe->demodulator_priv;
597
598 *snr = (state->snr) >> 16;
599
600 return 0;
601}
602
603static int lgdt330x_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
604{
605
606
607
608
609
610 struct lgdt330x_state *state = fe->demodulator_priv;
611 u16 snr;
612 int ret;
613
614 ret = fe->ops.read_snr(fe, &snr);
615 if (ret != 0)
616 return ret;
617
618
619 if (state->snr >= 8960 * 0x10000)
620 *strength = 0xffff;
621 else
622 *strength = state->snr / 8960;
623
624 return 0;
625}
626
627
628static int lgdt3302_read_status(struct dvb_frontend *fe,
629 enum fe_status *status)
630{
631 struct lgdt330x_state *state = fe->demodulator_priv;
632 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
633 u8 buf[3];
634 int err;
635
636 *status = 0;
637
638
639 i2c_read_demod_bytes(state, AGC_STATUS, buf, 1);
640 dprintk(state, "AGC_STATUS = 0x%02x\n", buf[0]);
641 if ((buf[0] & 0x0c) == 0x8) {
642
643
644
645
646 *status |= FE_HAS_SIGNAL;
647 }
648
649
650
651
652
653
654
655
656 i2c_read_demod_bytes(state, TOP_CONTROL, buf, sizeof(buf));
657 dprintk(state,
658 "TOP_CONTROL = 0x%02x, IRO_MASK = 0x%02x, IRQ_STATUS = 0x%02x\n",
659 buf[0], buf[1], buf[2]);
660
661
662 if ((buf[2] & 0x03) == 0x01)
663 *status |= FE_HAS_SYNC;
664
665
666 if ((buf[2] & 0x0c) == 0x08)
667 *status |= FE_HAS_LOCK | FE_HAS_VITERBI;
668
669
670 i2c_read_demod_bytes(state, CARRIER_LOCK, buf, 1);
671 dprintk(state, "CARRIER_LOCK = 0x%02x\n", buf[0]);
672 switch (state->current_modulation) {
673 case QAM_256:
674 case QAM_64:
675
676 if ((buf[0] & 0x07) == 0x07)
677 *status |= FE_HAS_CARRIER;
678 break;
679 case VSB_8:
680 if ((buf[0] & 0x80) == 0x80)
681 *status |= FE_HAS_CARRIER;
682 break;
683 default:
684 dev_warn(&state->client->dev,
685 "%s: Modulation set to unsupported value\n",
686 __func__);
687 }
688
689 if (!(*status & FE_HAS_LOCK)) {
690 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
691 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
692 p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
693 return 0;
694 }
695
696 if (state->last_stats_time &&
697 time_is_after_jiffies(state->last_stats_time))
698 return 0;
699
700 state->last_stats_time = jiffies + msecs_to_jiffies(1000);
701
702 err = lgdt3302_read_snr(fe);
703 if (!err) {
704 p->cnr.stat[0].scale = FE_SCALE_DECIBEL;
705 p->cnr.stat[0].svalue = (((u64)state->snr) * 1000) >> 24;
706 } else {
707 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
708 }
709
710 err = i2c_read_demod_bytes(state, LGDT3302_PACKET_ERR_COUNTER1,
711 buf, sizeof(buf));
712 if (!err) {
713 state->ucblocks = (buf[0] << 8) | buf[1];
714
715 dprintk(state, "UCB = 0x%02x\n", state->ucblocks);
716
717 p->block_error.stat[0].uvalue += state->ucblocks;
718
719 p->block_count.stat[0].uvalue += 10000;
720
721 p->block_error.stat[0].scale = FE_SCALE_COUNTER;
722 p->block_count.stat[0].scale = FE_SCALE_COUNTER;
723 } else {
724 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
725 p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
726 }
727
728 return 0;
729}
730
731static int lgdt3303_read_status(struct dvb_frontend *fe,
732 enum fe_status *status)
733{
734 struct lgdt330x_state *state = fe->demodulator_priv;
735 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
736 u8 buf[3];
737 int err;
738
739 *status = 0;
740
741
742 err = i2c_read_demod_bytes(state, 0x58, buf, 1);
743 if (err < 0)
744 return err;
745
746 dprintk(state, "AGC_STATUS = 0x%02x\n", buf[0]);
747 if ((buf[0] & 0x21) == 0x01) {
748
749
750
751
752 *status |= FE_HAS_SIGNAL;
753 }
754
755
756 i2c_read_demod_bytes(state, CARRIER_LOCK, buf, 1);
757 dprintk(state, "CARRIER_LOCK = 0x%02x\n", buf[0]);
758 switch (state->current_modulation) {
759 case QAM_256:
760 case QAM_64:
761
762 if ((buf[0] & 0x07) == 0x07)
763 *status |= FE_HAS_CARRIER;
764 else
765 break;
766 i2c_read_demod_bytes(state, 0x8a, buf, 1);
767 dprintk(state, "QAM LOCK = 0x%02x\n", buf[0]);
768
769 if ((buf[0] & 0x04) == 0x04)
770 *status |= FE_HAS_SYNC;
771 if ((buf[0] & 0x01) == 0x01)
772 *status |= FE_HAS_LOCK;
773 if ((buf[0] & 0x08) == 0x08)
774 *status |= FE_HAS_VITERBI;
775 break;
776 case VSB_8:
777 if ((buf[0] & 0x80) == 0x80)
778 *status |= FE_HAS_CARRIER;
779 else
780 break;
781 i2c_read_demod_bytes(state, 0x38, buf, 1);
782 dprintk(state, "8-VSB LOCK = 0x%02x\n", buf[0]);
783
784 if ((buf[0] & 0x02) == 0x00)
785 *status |= FE_HAS_SYNC;
786 if ((buf[0] & 0xfd) == 0x01)
787 *status |= FE_HAS_VITERBI | FE_HAS_LOCK;
788 break;
789 default:
790 dev_warn(&state->client->dev,
791 "%s: Modulation set to unsupported value\n",
792 __func__);
793 }
794
795 if (!(*status & FE_HAS_LOCK)) {
796 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
797 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
798 p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
799 return 0;
800 }
801
802 if (state->last_stats_time &&
803 time_is_after_jiffies(state->last_stats_time))
804 return 0;
805
806 state->last_stats_time = jiffies + msecs_to_jiffies(1000);
807
808 err = lgdt3303_read_snr(fe);
809 if (!err) {
810 p->cnr.stat[0].scale = FE_SCALE_DECIBEL;
811 p->cnr.stat[0].svalue = (((u64)state->snr) * 1000) >> 24;
812 } else {
813 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
814 }
815
816 err = i2c_read_demod_bytes(state, LGDT3303_PACKET_ERR_COUNTER1,
817 buf, sizeof(buf));
818 if (!err) {
819 state->ucblocks = (buf[0] << 8) | buf[1];
820
821 dprintk(state, "UCB = 0x%02x\n", state->ucblocks);
822
823 p->block_error.stat[0].uvalue += state->ucblocks;
824
825 p->block_count.stat[0].uvalue += 10000;
826
827 p->block_error.stat[0].scale = FE_SCALE_COUNTER;
828 p->block_count.stat[0].scale = FE_SCALE_COUNTER;
829 } else {
830 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
831 p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
832 }
833
834 return 0;
835}
836
837static int
838lgdt330x_get_tune_settings(struct dvb_frontend *fe,
839 struct dvb_frontend_tune_settings *fe_tune_settings)
840{
841
842 fe_tune_settings->min_delay_ms = 500;
843 fe_tune_settings->step_size = 0;
844 fe_tune_settings->max_drift = 0;
845 return 0;
846}
847
848static void lgdt330x_release(struct dvb_frontend *fe)
849{
850 struct lgdt330x_state *state = fe->demodulator_priv;
851 struct i2c_client *client = state->client;
852
853 dev_dbg(&client->dev, "\n");
854
855 i2c_unregister_device(client);
856}
857
858static struct dvb_frontend *lgdt330x_get_dvb_frontend(struct i2c_client *client)
859{
860 struct lgdt330x_state *state = i2c_get_clientdata(client);
861
862 dev_dbg(&client->dev, "\n");
863
864 return &state->frontend;
865}
866
867static const struct dvb_frontend_ops lgdt3302_ops;
868static const struct dvb_frontend_ops lgdt3303_ops;
869
870static int lgdt330x_probe(struct i2c_client *client,
871 const struct i2c_device_id *id)
872{
873 struct lgdt330x_state *state = NULL;
874 u8 buf[1];
875
876
877 state = kzalloc(sizeof(*state), GFP_KERNEL);
878 if (!state)
879 goto error;
880
881
882 memcpy(&state->config, client->dev.platform_data,
883 sizeof(state->config));
884 i2c_set_clientdata(client, state);
885 state->client = client;
886
887
888 switch (state->config.demod_chip) {
889 case LGDT3302:
890 memcpy(&state->frontend.ops, &lgdt3302_ops,
891 sizeof(struct dvb_frontend_ops));
892 break;
893 case LGDT3303:
894 memcpy(&state->frontend.ops, &lgdt3303_ops,
895 sizeof(struct dvb_frontend_ops));
896 break;
897 default:
898 goto error;
899 }
900 state->frontend.demodulator_priv = state;
901
902
903 state->config.get_dvb_frontend = lgdt330x_get_dvb_frontend;
904
905
906 if (i2c_read_demod_bytes(state, 2, buf, 1))
907 goto error;
908
909 state->current_frequency = -1;
910 state->current_modulation = -1;
911
912 dev_info(&state->client->dev,
913 "Demod loaded for LGDT330%s chip\n",
914 state->config.demod_chip == LGDT3302 ? "2" : "3");
915
916 return 0;
917
918error:
919 kfree(state);
920 if (debug)
921 dev_printk(KERN_DEBUG, &client->dev, "Error loading lgdt330x driver\n");
922 return -ENODEV;
923}
924struct dvb_frontend *lgdt330x_attach(const struct lgdt330x_config *_config,
925 u8 demod_address,
926 struct i2c_adapter *i2c)
927{
928 struct i2c_client *client;
929 struct i2c_board_info board_info = {};
930 struct lgdt330x_config config = *_config;
931
932 strscpy(board_info.type, "lgdt330x", sizeof(board_info.type));
933 board_info.addr = demod_address;
934 board_info.platform_data = &config;
935 client = i2c_new_device(i2c, &board_info);
936 if (!client || !client->dev.driver)
937 return NULL;
938
939 return lgdt330x_get_dvb_frontend(client);
940}
941EXPORT_SYMBOL(lgdt330x_attach);
942
943static const struct dvb_frontend_ops lgdt3302_ops = {
944 .delsys = { SYS_ATSC, SYS_DVBC_ANNEX_B },
945 .info = {
946 .name = "LG Electronics LGDT3302 VSB/QAM Frontend",
947 .frequency_min_hz = 54 * MHz,
948 .frequency_max_hz = 858 * MHz,
949 .frequency_stepsize_hz = 62500,
950 .symbol_rate_min = 5056941,
951 .symbol_rate_max = 10762000,
952 .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
953 },
954 .init = lgdt330x_init,
955 .set_frontend = lgdt330x_set_parameters,
956 .get_frontend = lgdt330x_get_frontend,
957 .get_tune_settings = lgdt330x_get_tune_settings,
958 .read_status = lgdt3302_read_status,
959 .read_signal_strength = lgdt330x_read_signal_strength,
960 .read_snr = lgdt330x_read_snr,
961 .read_ucblocks = lgdt330x_read_ucblocks,
962 .release = lgdt330x_release,
963};
964
965static const struct dvb_frontend_ops lgdt3303_ops = {
966 .delsys = { SYS_ATSC, SYS_DVBC_ANNEX_B },
967 .info = {
968 .name = "LG Electronics LGDT3303 VSB/QAM Frontend",
969 .frequency_min_hz = 54 * MHz,
970 .frequency_max_hz = 858 * MHz,
971 .frequency_stepsize_hz = 62500,
972 .symbol_rate_min = 5056941,
973 .symbol_rate_max = 10762000,
974 .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
975 },
976 .init = lgdt330x_init,
977 .set_frontend = lgdt330x_set_parameters,
978 .get_frontend = lgdt330x_get_frontend,
979 .get_tune_settings = lgdt330x_get_tune_settings,
980 .read_status = lgdt3303_read_status,
981 .read_signal_strength = lgdt330x_read_signal_strength,
982 .read_snr = lgdt330x_read_snr,
983 .read_ucblocks = lgdt330x_read_ucblocks,
984 .release = lgdt330x_release,
985};
986
987static int lgdt330x_remove(struct i2c_client *client)
988{
989 struct lgdt330x_state *state = i2c_get_clientdata(client);
990
991 dev_dbg(&client->dev, "\n");
992
993 kfree(state);
994
995 return 0;
996}
997
998static const struct i2c_device_id lgdt330x_id_table[] = {
999 {"lgdt330x", 0},
1000 {}
1001};
1002MODULE_DEVICE_TABLE(i2c, lgdt330x_id_table);
1003
1004static struct i2c_driver lgdt330x_driver = {
1005 .driver = {
1006 .name = "lgdt330x",
1007 .suppress_bind_attrs = true,
1008 },
1009 .probe = lgdt330x_probe,
1010 .remove = lgdt330x_remove,
1011 .id_table = lgdt330x_id_table,
1012};
1013
1014module_i2c_driver(lgdt330x_driver);
1015
1016
1017MODULE_DESCRIPTION("LGDT330X (ATSC 8VSB & ITU-T J.83 AnnexB 64/256 QAM) Demodulator Driver");
1018MODULE_AUTHOR("Wilson Michaels");
1019MODULE_LICENSE("GPL");
1020