34 #define OR51132_VSB_FIRMWARE "dvb-fe-or51132-vsb.fw"
35 #define OR51132_QAM_FIRMWARE "dvb-fe-or51132-qam.fw"
37 #include <linux/kernel.h>
38 #include <linux/module.h>
41 #include <linux/string.h>
42 #include <linux/slab.h>
43 #include <asm/byteorder.h>
50 #define dprintk(args...) \
52 if (debug) printk(KERN_DEBUG "or51132: " args); \
79 .flags = 0, .buf = (
u8*)buf, .len = len };
93 #define or51132_writebytes(state, data...) \
94 ({ static const u8 _data[] = {data}; \
95 or51132_writebuf(state, _data, sizeof(_data)); })
98 static int or51132_readbuf(
struct or51132_state *state,
u8 *buf,
int len)
116 u8 buf[2] = { 0x04, reg };
118 {.
addr = state->
config->demod_address, .flags = 0,
119 .buf =
buf, .len = 2 },
121 .buf =
buf, .len = 2 }};
129 return buf[0] | (buf[1] << 8);
135 static const u8 run_buf[] = {0x7F,0x01};
137 u32 firmwareAsize, firmwareBsize;
144 dprintk(
"FirmwareA is %i bytes\n",firmwareAsize);
146 dprintk(
"FirmwareB is %i bytes\n",firmwareBsize);
149 if ((ret = or51132_writebuf(state, &fw->
data[8], firmwareAsize))) {
153 if ((ret = or51132_writebuf(state, &fw->
data[8+firmwareAsize],
159 if ((ret = or51132_writebuf(state, run_buf, 2))) {
163 if ((ret = or51132_writebuf(state, run_buf, 2))) {
191 if ((ret = or51132_readbuf(state, &rec_buf[i*2], 2))) {
193 "or51132: load_firmware error d - %d\n",i);
199 "or51132: Version: %02X%02X%02X%02X-%02X%02X%02X%02X (%02X%01X-%01X-%02X%01X-%01X)\n",
200 rec_buf[1],rec_buf[0],rec_buf[3],rec_buf[2],
201 rec_buf[5],rec_buf[4],rec_buf[7],rec_buf[6],
202 rec_buf[3],rec_buf[2]>>4,rec_buf[2]&0x0f,
203 rec_buf[5],rec_buf[4]>>4,rec_buf[4]&0x0f);
223 static int or51132_read_ucblocks(
struct dvb_frontend* fe,
u32* ucblocks)
237 u8 cmd_buf1[3] = {0x04, 0x01, 0x5f};
238 u8 cmd_buf2[3] = {0x1c, 0x00, 0 };
268 "or51132: setmode: Modulation set to unsupported value (%d)\n",
274 if (or51132_writebuf(state, cmd_buf1, 3)) {
278 dprintk(
"set #1 to %02x\n", cmd_buf1[2]);
281 if (or51132_writebuf(state, cmd_buf2, 3)) {
285 dprintk(
"set #6 to 0x%02x%02x\n", cmd_buf2[1], cmd_buf2[2]);
292 #define MOD_FWCLASS_UNKNOWN 0
293 #define MOD_FWCLASS_VSB 1
294 #define MOD_FWCLASS_QAM 2
309 static int or51132_set_parameters(
struct dvb_frontend *fe)
323 dprintk(
"set_parameters VSB MODE\n");
330 dprintk(
"set_parameters QAM MODE\n");
337 printk(
"or51132: Modulation type(%d) UNSUPPORTED\n",
341 printk(
"or51132: Waiting for firmware upload(%s)...\n",
346 "loaded(timeout or file not found?)\n");
349 ret = or51132_load_firmware(fe, fw);
356 printk(
"or51132: Firmware upload complete.\n");
357 state->
config->set_ts_params(fe, clock_mode);
365 if (fe->
ops.tuner_ops.set_params) {
366 fe->
ops.tuner_ops.set_params(fe);
367 if (fe->
ops.i2c_gate_ctrl) fe->
ops.i2c_gate_ctrl(fe, 0);
378 static int or51132_get_parameters(
struct dvb_frontend* fe)
387 if ((status = or51132_readreg(state, 0x00)) < 0) {
391 switch(status&0xff) {
424 if ((reg = or51132_readreg(state, 0x00)) < 0) {
425 printk(
KERN_WARNING "or51132: read_status: error reading receiver status: %d\n", reg);
429 dprintk(
"%s: read_status %04x\n", __func__, reg);
484 noise = or51132_readreg(state, 0x02);
489 dprintk(
"read_snr noise (%d)\n", noise);
493 reg = or51132_readreg(state, 0x00);
501 if (reg & 0x1000) usK = 3 << 24;
511 if (retry--)
goto start;
514 dprintk(
"%s: modulation %02x, NTSC rej O%s\n", __func__,
515 reg&0xff, reg&0x1000?
"n":
"ff");
518 state->
snr = calculate_snr(noise, c) - usK;
519 *snr = (state->
snr) >> 16;
521 dprintk(
"%s: noise = 0x%08x, snr = %d.%02d dB\n", __func__, noise,
522 state->
snr >> 24, (((state->
snr>>8) & 0xffff) * 100) >> 16);
527 static int or51132_read_signal_strength(
struct dvb_frontend* fe,
u16* strength)
536 ret = fe->
ops.read_snr(fe, &snr);
541 if (state->
snr >= 8960 * 0x10000)
544 *strength = state->
snr / 8960;
591 .name =
"Oren OR51132 VSB/QAM Frontend",
592 .frequency_min = 44000000,
593 .frequency_max = 958000000,
594 .frequency_stepsize = 166666,
601 .release = or51132_release,
603 .init = or51132_init,
604 .sleep = or51132_sleep,
606 .set_frontend = or51132_set_parameters,
607 .get_frontend = or51132_get_parameters,
608 .get_tune_settings = or51132_get_tune_settings,
610 .read_status = or51132_read_status,
611 .read_ber = or51132_read_ber,
612 .read_signal_strength = or51132_read_signal_strength,
613 .read_snr = or51132_read_snr,
614 .read_ucblocks = or51132_read_ucblocks,
620 MODULE_DESCRIPTION(
"OR51132 ATSC [pcHDTV HD-3000] (8VSB & ITU J83 AnnexB FEC QAM64/256) Demodulator Driver");