31 #define OR51211_DEFAULT_FIRMWARE "dvb-fe-or51211.fw"
33 #include <linux/kernel.h>
34 #include <linux/module.h>
35 #include <linux/device.h>
37 #include <linux/string.h>
38 #include <linux/slab.h>
39 #include <asm/byteorder.h>
46 #define dprintk(args...) \
48 if (debug) printk(KERN_DEBUG "or51211: " args); \
51 static u8 run_buf[] = {0x7f,0x01};
52 static u8 cmd_buf[] = {0x04,0x01,0x50,0x80,0x06};
84 "(addr %02x, err == %i)\n", reg, err);
102 "(addr %02x, err == %i)\n", reg, err);
109 static int or51211_load_firmware (
struct dvb_frontend* fe,
120 if (i2c_writebytes(state,0x50,tudata,1)) {
124 if (i2c_readbytes(state,0x50,&tudata[145],192)) {
130 for (i = 0; i < 145; i++)
131 tudata[i] = fw->
data[i];
133 for (i = 0; i < 248; i++)
134 tudata[i+337] = fw->
data[145+i];
138 if (i2c_writebytes(state,state->
config->demod_address,tudata,585)) {
144 if (i2c_writebytes(state,state->
config->demod_address,
145 &fw->
data[393],8125)) {
151 if (i2c_writebytes(state,state->
config->demod_address,run_buf,2)) {
158 if (i2c_writebytes(state,state->
config->demod_address,run_buf,2)) {
164 printk(
"or51211: Done.\n");
173 state->
config->setmode(fe, mode);
175 if (i2c_writebytes(state,state->
config->demod_address,run_buf,2)) {
182 if (i2c_writebytes(state,state->
config->demod_address,run_buf,2)) {
198 if (i2c_writebytes(state,state->
config->demod_address,
cmd_buf,3)) {
208 if (i2c_writebytes(state,state->
config->demod_address,rec_buf,3)) {
212 if (i2c_readbytes(state,state->
config->demod_address,&rec_buf[10],2)) {
216 dprintk(
"setmode rec status %02x %02x\n",rec_buf[10],rec_buf[11]);
221 static int or51211_set_parameters(
struct dvb_frontend *fe)
228 if (fe->
ops.tuner_ops.set_params) {
229 fe->
ops.tuner_ops.set_params(fe);
230 if (fe->
ops.i2c_gate_ctrl) fe->
ops.i2c_gate_ctrl(fe, 0);
234 or51211_setmode(fe,0);
245 unsigned char rec_buf[2];
246 unsigned char snd_buf[] = {0x04,0x00,0x03,0x00};
250 if (i2c_writebytes(state,state->
config->demod_address,snd_buf,3)) {
255 if (i2c_readbytes(state,state->
config->demod_address,rec_buf,2)) {
259 dprintk(
"read_status %x %x\n",rec_buf[0],rec_buf[1]);
261 if (rec_buf[0] & 0x01) {
308 if (i2c_writebytes(state,state->
config->demod_address,snd_buf,3)) {
313 if (i2c_readbytes(state,state->
config->demod_address,rec_buf,2)) {
319 state->
snr = calculate_snr(rec_buf[0], 89599047);
320 *snr = (state->
snr) >> 16;
322 dprintk(
"%s: noise = 0x%02x, snr = %d.%02d dB\n", __func__, rec_buf[0],
323 state->
snr >> 24, (((state->
snr>>8) & 0xffff) * 100) >> 16);
328 static int or51211_read_signal_strength(
struct dvb_frontend* fe,
u16* strength)
337 ret = fe->
ops.read_snr(fe, &snr);
342 if (state->
snr >= 8960 * 0x10000)
345 *strength = state->
snr / 8960;
356 static int or51211_read_ucblocks(
struct dvb_frontend* fe,
u32* ucblocks)
372 unsigned char get_ver_buf[] = {0x04,0x00,0x30,0x00,0x00};
373 unsigned char rec_buf[14];
385 "(timeout or file not found?)\n");
389 ret = or51211_load_firmware(fe, fw);
407 if (i2c_writebytes(state,state->
config->demod_address,
420 if (i2c_writebytes(state,state->
config->demod_address,
426 if (i2c_readbytes(state,state->
config->demod_address,
437 if (i2c_writebytes(state,state->
config->demod_address,
443 if (i2c_readbytes(state,state->
config->demod_address,
449 for (i = 0; i < 8; i++)
452 for (i = 0; i < 5; i++) {
454 get_ver_buf[4] = i+1;
455 if (i2c_writebytes(state,state->
config->demod_address,
463 if (i2c_readbytes(state,state->
config->demod_address,
470 if ((
int)rec_buf[i*2+1]!=i+1){
474 dprintk(
"read_fwbits %x %x %x %x %x %x %x %x %x %x\n",
475 rec_buf[0], rec_buf[1], rec_buf[2], rec_buf[3],
476 rec_buf[4], rec_buf[5], rec_buf[6], rec_buf[7],
477 rec_buf[8], rec_buf[9]);
481 rec_buf[2], rec_buf[4],rec_buf[6],
482 rec_buf[12],rec_buf[10]);
489 if (i2c_writebytes(state,state->
config->demod_address,
495 if (i2c_readbytes(state,state->
config->demod_address,
506 static int or51211_get_tune_settings(
struct dvb_frontend* fe,
549 .name =
"Oren OR51211 VSB Frontend",
550 .frequency_min = 44000000,
551 .frequency_max = 958000000,
552 .frequency_stepsize = 166666,
558 .release = or51211_release,
560 .init = or51211_init,
561 .sleep = or51211_sleep,
563 .set_frontend = or51211_set_parameters,
564 .get_tune_settings = or51211_get_tune_settings,
566 .read_status = or51211_read_status,
567 .read_ber = or51211_read_ber,
568 .read_signal_strength = or51211_read_signal_strength,
569 .read_snr = or51211_read_snr,
570 .read_ucblocks = or51211_read_ucblocks,