📄 or51211.c
字号:
}static int or51211_read_snr(struct dvb_frontend* fe, u16* snr){ struct or51211_state* state = fe->demodulator_priv; u8 rec_buf[2]; u8 snd_buf[3]; /* SNR after Equalizer */ snd_buf[0] = 0x04; snd_buf[1] = 0x00; snd_buf[2] = 0x04; if (i2c_writebytes(state,state->config->demod_address,snd_buf,3)) { printk(KERN_WARNING "%s: error writing snr reg\n", __FUNCTION__); return -1; } if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) { printk(KERN_WARNING "%s: read_status read error\n", __FUNCTION__); return -1; } state->snr = calculate_snr(rec_buf[0], 89599047); *snr = (state->snr) >> 16; dprintk("%s: noise = 0x%02x, snr = %d.%02d dB\n", __FUNCTION__, rec_buf[0], state->snr >> 24, (((state->snr>>8) & 0xffff) * 100) >> 16); return 0;}static int or51211_read_signal_strength(struct dvb_frontend* fe, u16* strength){ /* Calculate Strength from SNR up to 35dB */ /* Even though the SNR can go higher than 35dB, there is some comfort */ /* factor in having a range of strong signals that can show at 100% */ struct or51211_state* state = (struct or51211_state*)fe->demodulator_priv; u16 snr; int ret; ret = fe->ops.read_snr(fe, &snr); if (ret != 0) return ret; /* Rather than use the 8.8 value snr, use state->snr which is 8.24 */ /* scale the range 0 - 35*2^24 into 0 - 65535 */ if (state->snr >= 8960 * 0x10000) *strength = 0xffff; else *strength = state->snr / 8960; return 0;}static int or51211_read_ber(struct dvb_frontend* fe, u32* ber){ *ber = -ENOSYS; return 0;}static int or51211_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks){ *ucblocks = -ENOSYS; return 0;}static int or51211_sleep(struct dvb_frontend* fe){ return 0;}static int or51211_init(struct dvb_frontend* fe){ struct or51211_state* state = fe->demodulator_priv; const struct or51211_config* config = state->config; const struct firmware* fw; unsigned char get_ver_buf[] = {0x04,0x00,0x30,0x00,0x00}; unsigned char rec_buf[14]; int ret,i; if (!state->initialized) { /* Request the firmware, this will block until it uploads */ printk(KERN_INFO "or51211: Waiting for firmware upload " "(%s)...\n", OR51211_DEFAULT_FIRMWARE); ret = config->request_firmware(fe, &fw, OR51211_DEFAULT_FIRMWARE); printk(KERN_INFO "or51211:Got Hotplug firmware\n"); if (ret) { printk(KERN_WARNING "or51211: No firmware uploaded " "(timeout or file not found?)\n"); return ret; } ret = or51211_load_firmware(fe, fw); release_firmware(fw); if (ret) { printk(KERN_WARNING "or51211: Writing firmware to " "device failed!\n"); return ret; } printk(KERN_INFO "or51211: Firmware upload complete.\n"); /* Set operation mode in Receiver 1 register; * type 1: * data 0x50h Automatic sets receiver channel conditions * Automatic NTSC rejection filter * Enable MPEG serial data output * MPEG2tr * High tuner phase noise * normal +/-150kHz Carrier acquisition range */ if (i2c_writebytes(state,state->config->demod_address, cmd_buf,3)) { printk(KERN_WARNING "or51211: Load DVR Error 5\n"); return -1; } /* Read back ucode version to besure we loaded correctly */ /* and are really up and running */ rec_buf[0] = 0x04; rec_buf[1] = 0x00; rec_buf[2] = 0x03; rec_buf[3] = 0x00; msleep(30); if (i2c_writebytes(state,state->config->demod_address, rec_buf,3)) { printk(KERN_WARNING "or51211: Load DVR Error A\n"); return -1; } msleep(3); if (i2c_readbytes(state,state->config->demod_address, &rec_buf[10],2)) { printk(KERN_WARNING "or51211: Load DVR Error B\n"); return -1; } rec_buf[0] = 0x04; rec_buf[1] = 0x00; rec_buf[2] = 0x01; rec_buf[3] = 0x00; msleep(20); if (i2c_writebytes(state,state->config->demod_address, rec_buf,3)) { printk(KERN_WARNING "or51211: Load DVR Error C\n"); return -1; } msleep(3); if (i2c_readbytes(state,state->config->demod_address, &rec_buf[12],2)) { printk(KERN_WARNING "or51211: Load DVR Error D\n"); return -1; } for (i = 0; i < 8; i++) rec_buf[i]=0xed; for (i = 0; i < 5; i++) { msleep(30); get_ver_buf[4] = i+1; if (i2c_writebytes(state,state->config->demod_address, get_ver_buf,5)) { printk(KERN_WARNING "or51211:Load DVR Error 6" " - %d\n",i); return -1; } msleep(3); if (i2c_readbytes(state,state->config->demod_address, &rec_buf[i*2],2)) { printk(KERN_WARNING "or51211:Load DVR Error 7" " - %d\n",i); return -1; } /* If we didn't receive the right index, try again */ if ((int)rec_buf[i*2+1]!=i+1){ i--; } } dprintk("read_fwbits %x %x %x %x %x %x %x %x %x %x\n", rec_buf[0], rec_buf[1], rec_buf[2], rec_buf[3], rec_buf[4], rec_buf[5], rec_buf[6], rec_buf[7], rec_buf[8], rec_buf[9]); printk(KERN_INFO "or51211: ver TU%02x%02x%02x VSB mode %02x" " Status %02x\n", rec_buf[2], rec_buf[4],rec_buf[6], rec_buf[12],rec_buf[10]); rec_buf[0] = 0x04; rec_buf[1] = 0x00; rec_buf[2] = 0x03; rec_buf[3] = 0x00; msleep(20); if (i2c_writebytes(state,state->config->demod_address, rec_buf,3)) { printk(KERN_WARNING "or51211: Load DVR Error 8\n"); return -1; } msleep(20); if (i2c_readbytes(state,state->config->demod_address, &rec_buf[8],2)) { printk(KERN_WARNING "or51211: Load DVR Error 9\n"); return -1; } state->initialized = 1; } return 0;}static int or51211_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings){ fesettings->min_delay_ms = 500; fesettings->step_size = 0; fesettings->max_drift = 0; return 0;}static void or51211_release(struct dvb_frontend* fe){ struct or51211_state* state = fe->demodulator_priv; state->config->sleep(fe); kfree(state);}static struct dvb_frontend_ops or51211_ops;struct dvb_frontend* or51211_attach(const struct or51211_config* config, struct i2c_adapter* i2c){ struct or51211_state* state = NULL; /* Allocate memory for the internal state */ state = kmalloc(sizeof(struct or51211_state), GFP_KERNEL); if (state == NULL) goto error; /* Setup the state */ state->config = config; state->i2c = i2c; state->initialized = 0; state->current_frequency = 0; /* Create dvb_frontend */ memcpy(&state->frontend.ops, &or51211_ops, sizeof(struct dvb_frontend_ops)); state->frontend.demodulator_priv = state; return &state->frontend;error: kfree(state); return NULL;}static struct dvb_frontend_ops or51211_ops = { .info = { .name = "Oren OR51211 VSB Frontend", .type = FE_ATSC, .frequency_min = 44000000, .frequency_max = 958000000, .frequency_stepsize = 166666, .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO | FE_CAN_8VSB }, .release = or51211_release, .init = or51211_init, .sleep = or51211_sleep, .set_frontend = or51211_set_parameters, .get_tune_settings = or51211_get_tune_settings, .read_status = or51211_read_status, .read_ber = or51211_read_ber, .read_signal_strength = or51211_read_signal_strength, .read_snr = or51211_read_snr, .read_ucblocks = or51211_read_ucblocks,};module_param(debug, int, 0644);MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");MODULE_DESCRIPTION("Oren OR51211 VSB [pcHDTV HD-2000] Demodulator Driver");MODULE_AUTHOR("Kirk Lapray");MODULE_LICENSE("GPL");EXPORT_SYMBOL(or51211_attach);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -