35 #include <linux/module.h>
36 #include <linux/device.h>
39 #include <linux/string.h>
40 #include <linux/slab.h>
67 #define dprintk(level,x...) if (level & debug) printk(x)
68 #define dbufout(b,l,m) {\
70 for (i = 0; i < l; i++) \
73 #define deb_info(args...) dprintk(0x01,args)
74 #define deb_i2c(args...) dprintk(0x02,args)
75 #define deb_hab(args...) dprintk(0x04,args)
82 struct i2c_msg msg = { .
addr = state->
config->demod_address, .flags = 0, .buf =
b, .len = len + 1 };
93 deb_info(
"%s: i2c write error (addr %02x, reg %02x, err == %i)\n",
94 __func__, state->
config->demod_address, reg, err);
104 { .addr = state->
config->demod_address, .flags = 0, .buf = &
reg, .len = 1 },
105 { .addr = state->
config->demod_address, .flags =
I2C_M_RD, .buf =
buf, .len = len }
112 deb_info(
"%s: i2c read error (addr %02x, reg %02x, err == %i)\n",
113 __func__, state->
config->demod_address, reg, err);
125 return bcm3510_writebytes(state,reg,&v.
raw,1);
130 return bcm3510_readbytes(state,reg,&v->
raw,1);
140 if ((ret = bcm3510_writeB(st,0xa6,v)) < 0)
143 for (i = 0; i <
len; i++) {
144 if ((ret = bcm3510_readB(st,0xa7,&v)) < 0)
151 static int bcm3510_hab_send_request(
struct bcm3510_state *st,
u8 *buf,
int len)
159 if ((ret = bcm3510_readB(st,0xa8,&v)) < 0)
162 deb_info(
"HAB is running already - clearing it.\n");
164 bcm3510_writeB(st,0xa8,v);
171 if ((ret = bcm3510_writeB(st,0xa6,hab)) < 0)
174 for (i = 0; i <
len; i++) {
176 if ((ret = bcm3510_writeB(st,0xa7,hab)) < 0)
183 if ((ret = bcm3510_writeB(st,0xa8,v)) < 0)
189 deb_info(
"waiting for HAB to complete\n");
191 if ((ret = bcm3510_readB(st,0xa8,&v)) < 0)
198 deb_info(
"send_request execution timed out.\n");
204 u8 ob[olen+2],ib[ilen+2];
218 if ((ret = bcm3510_hab_send_request(st, ob, olen+2)) < 0 ||
219 (ret = bcm3510_hab_get_response(st, ib, ilen+2)) < 0)
239 if ((ret = bcm3510_readB(st,0xa8,&hab)) < 0 ||
240 (ret = bcm3510_readB(st,0xa2,&ap) < 0))
257 if ((ret = bcm3510_readB(st,0xfa,&b)) < 0)
260 b.
BERCTL_fa.RESYNC = 0; bcm3510_writeB(st,0xfa,b);
261 b.
BERCTL_fa.RESYNC = 1; bcm3510_writeB(st,0xfa,b);
262 b.
BERCTL_fa.RESYNC = 0; bcm3510_writeB(st,0xfa,b);
282 bcm3510_refresh_state(st);
285 if (st->
status1.STATUS1.RECEIVER_LOCK)
288 if (st->
status1.STATUS1.FEC_LOCK)
291 if (st->
status1.STATUS1.OUT_PLL_LOCK)
299 deb_info(
"real_status: %02x\n",*status);
306 bcm3510_refresh_state(st);
315 bcm3510_refresh_state(st);
320 static int bcm3510_read_signal_strength(
struct dvb_frontend* fe,
u16* strength)
325 bcm3510_refresh_state(st);
336 *strength = (t << 8) | t;
343 bcm3510_refresh_state(st);
345 *snr = st->
status1.SNR_EST0*1000 + ((st->
status1.SNR_EST1*1000) >> 8);
362 c.TUNCTL_state = 0x40;
365 c.ctl_dat[0].ctrl.size =
BITS_8;
366 c.ctl_dat[0].data = 0x80 |
bc;
369 c.ctl_dat[1].ctrl.size =
BITS_8;
370 c.ctl_dat[1].data = 4;
373 c.ctl_dat[2].ctrl.size =
BITS_3;
374 c.ctl_dat[2].data = 0x20;
377 c.ctl_dat[3].ctrl.size =
BITS_3;
378 c.ctl_dat[3].ctrl.clk_off = 1;
379 c.ctl_dat[3].ctrl.cs0 = 1;
380 c.ctl_dat[3].data = 0x40;
383 c.ctl_dat[4].ctrl.size =
BITS_8;
384 c.ctl_dat[4].data = n >> 3;
387 c.ctl_dat[5].ctrl.size =
BITS_8;
388 c.ctl_dat[5].data = ((n & 0x7) << 5) | (a >> 2);
391 c.ctl_dat[6].ctrl.size =
BITS_3;
392 c.ctl_dat[6].data = (a << 6) & 0xdf;
395 c.ctl_dat[7].ctrl.size =
BITS_3;
396 c.ctl_dat[7].ctrl.clk_off = 1;
397 c.ctl_dat[7].ctrl.cs0 = 1;
398 c.ctl_dat[7].data = 0x40;
401 c.ctl_dat[8].ctrl.size =
BITS_8;
402 c.ctl_dat[8].data = 0x80;
405 c.ctl_dat[9].ctrl.size =
BITS_8;
406 c.ctl_dat[9].data = 0x10;
409 c.ctl_dat[10].ctrl.size =
BITS_3;
410 c.ctl_dat[10].data = 0x20;
413 c.ctl_dat[11].ctrl.size =
BITS_3;
414 c.ctl_dat[11].ctrl.clk_off = 1;
415 c.ctl_dat[11].ctrl.cs1 = 1;
416 c.ctl_dat[11].data = 0x40;
419 c.ctl_dat[12].ctrl.size =
BITS_8;
420 c.ctl_dat[12].data = 0x2a;
423 c.ctl_dat[13].ctrl.size =
BITS_8;
424 c.ctl_dat[13].data = 0x8e;
427 c.ctl_dat[14].ctrl.size =
BITS_3;
428 c.ctl_dat[14].data = 0;
431 c.ctl_dat[15].ctrl.size =
BITS_3;
432 c.ctl_dat[15].ctrl.clk_off = 1;
433 c.ctl_dat[15].ctrl.cs1 = 1;
434 c.ctl_dat[15].data = 0x40;
443 s32 YIntercept,Tfvco1;
451 else if (freq <= 378000)
456 if (freq >= 470000) {
459 }
else if (freq >= 90000) {
462 }
else if (freq >= 76000){
470 Tfvco1 = (((freq/6000)*60 + YIntercept)*4)/10;
475 deb_info(
" BC1_2_3_4: %x, N: %x A: %x\n", bc, n, a);
476 if (n >= 16 && n <= 2047)
477 return bcm3510_tuner_cmd(st,bc,n,a);
482 static int bcm3510_set_frontend(
struct dvb_frontend *fe)
490 memset(&cmd,0,
sizeof(cmd));
493 cmd.ACQUIRE0.MODE = 0x1;
494 cmd.ACQUIRE1.SYM_RATE = 0x1;
495 cmd.ACQUIRE1.IF_FREQ = 0x1;
498 cmd.ACQUIRE0.MODE = 0x2;
499 cmd.ACQUIRE1.SYM_RATE = 0x2;
500 cmd.ACQUIRE1.IF_FREQ = 0x1;
504 cmd.ACQUIRE0.MODE = 0x3;
507 cmd.ACQUIRE0.MODE = 0x4;
510 cmd.ACQUIRE0.MODE = 0x5;
513 cmd.ACQUIRE0.MODE = 0x6;
516 cmd.ACQUIRE0.MODE = 0x7;
520 cmd.ACQUIRE0.MODE = 0x8;
521 cmd.ACQUIRE1.SYM_RATE = 0x0;
522 cmd.ACQUIRE1.IF_FREQ = 0x0;
525 cmd.ACQUIRE0.MODE = 0x9;
526 cmd.ACQUIRE1.SYM_RATE = 0x0;
527 cmd.ACQUIRE1.IF_FREQ = 0x0;
531 cmd.ACQUIRE0.OFFSET = 0;
532 cmd.ACQUIRE0.NTSCSWEEP = 1;
555 bcm3510_bert_reset(st);
557 ret = bcm3510_set_freq(st, c->
frequency);
594 #define BCM3510_DEFAULT_FIRMWARE "dvb-fe-bcm3510-01.fw"
604 if ((ret = bcm3510_writeB(st,0xa9,vH)) < 0)
return ret;
605 if ((ret = bcm3510_writeB(st,0xaa,vL)) < 0)
return ret;
607 for (i = 0; i < len; i++) {
609 if ((ret = bcm3510_writeB(st,0xab,vD)) < 0)
616 static int bcm3510_download_firmware(
struct dvb_frontend* fe)
632 for (i = 0; i < fw->
size;) {
635 deb_info(
"firmware chunk, addr: 0x%04x, len: 0x%04x, total length: 0x%04zx\n",addr,len,fw->
size);
636 if ((ret = bcm3510_write_ram(st,addr,&b[i+4],len)) < 0) {
637 err(
"firmware download failed: %d\n",ret);
643 deb_info(
"firmware download successfully completed\n");
647 static int bcm3510_check_firmware_version(
struct bcm3510_state *st)
652 deb_info(
"Version information: 0x%02x 0x%02x 0x%02x 0x%02x\n",
653 ver.microcode_version,
ver.script_version,
ver.config_version,
ver.demod_version);
671 bcm3510_readB(st,0xa0,&v); v.
HCTL1_a0.RESET = 1;
672 if ((ret = bcm3510_writeB(st,0xa0,v)) < 0)
678 if ((ret = bcm3510_readB(st,0xa2,&v)) < 0)
695 if ((ret = bcm3510_writeB(st,0xa0,v)) < 0)
701 if ((ret = bcm3510_readB(st,0xa2,&v)) < 0)
708 deb_info(
"reset clear timed out\n");
718 if ((ret = bcm3510_readB(st,0xa2,&v)) < 0)
721 deb_info(
"AP is already running - firmware already loaded.\n");
726 if ((ret = bcm3510_reset(st)) < 0)
732 if ((ret = bcm3510_writeB(st,0x2e,v)) < 0)
736 if ((ret = bcm3510_download_firmware(&st->
frontend)) < 0 ||
737 (ret = bcm3510_clear_reset(st)) < 0)
752 if ((ret = bcm3510_readB(st,0xca,&j)) < 0)
759 deb_info(
"attempting to download firmware\n");
760 if ((ret = bcm3510_init_cold(st)) < 0)
764 bcm3510_check_firmware_version(st);
803 if ((ret = bcm3510_readB(state,0xe0,&v)) < 0)
814 bcm3510_reset(state);
827 .name =
"Broadcom BCM3510 VSB/QAM frontend",
828 .frequency_min = 54000000,
829 .frequency_max = 803000000,
831 .frequency_stepsize = 0,
839 .release = bcm3510_release,
841 .init = bcm3510_init,
842 .sleep = bcm3510_sleep,
844 .set_frontend = bcm3510_set_frontend,
845 .get_tune_settings = bcm3510_get_tune_settings,
847 .read_status = bcm3510_read_status,
848 .read_ber = bcm3510_read_ber,
849 .read_signal_strength = bcm3510_read_signal_strength,
850 .read_snr = bcm3510_read_snr,
851 .read_ucblocks = bcm3510_read_unc,
854 MODULE_DESCRIPTION(
"Broadcom BCM3510 ATSC (8VSB/16VSB & ITU J83 AnnexB FEC QAM64/256) demodulator driver");