📄 or51211.c
字号:
static unsigned int i20Log10(unsigned short val){ unsigned int rntval = 100; unsigned int tmp = val; unsigned int exp = 1; while(tmp > 100) {tmp /= 100; exp++;} val = (2 * val)/denom[exp]; if (exp > 1) rntval = 2000*exp; rntval += i100x20log10[val]; return rntval;}static int or51211_read_signal_strength(struct dvb_frontend* fe, u16* strength){ struct or51211_state* state = fe->demodulator_priv; u8 rec_buf[2]; u8 snd_buf[4]; u8 snr_equ; u32 signal_strength; /* SNR after Equalizer */ snd_buf[0] = 0x04; snd_buf[1] = 0x00; snd_buf[2] = 0x04; snd_buf[3] = 0x00; if (i2c_writebytes(state,state->config->demod_address,snd_buf,3)) { printk(KERN_WARNING "or51211: read_status write error\n"); return -1; } msleep(3); if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) { printk(KERN_WARNING "or51211: read_status read error\n"); return -1; } snr_equ = rec_buf[0] & 0xff; /* The value reported back from the frontend will be FFFF=100% 0000=0% */ signal_strength = (((5334 - i20Log10(snr_equ))/3+5)*65535)/1000; if (signal_strength > 0xffff) *strength = 0xffff; else *strength = signal_strength; dprintk("read_signal_strength %i\n",*strength); return 0;}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[4]; /* SNR after Equalizer */ snd_buf[0] = 0x04; snd_buf[1] = 0x00; snd_buf[2] = 0x04; snd_buf[3] = 0x00; if (i2c_writebytes(state,state->config->demod_address,snd_buf,3)) { printk(KERN_WARNING "or51211: read_status write error\n"); return -1; } msleep(3); if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) { printk(KERN_WARNING "or51211: read_status read error\n"); return -1; } *snr = rec_buf[0] & 0xff; dprintk("read_snr %i\n",*snr); 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); if (ret) { printk(KERN_WARNING "or51211: Writing firmware to " "device failed!\n"); release_firmware(fw); 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; memcpy(&state->ops, &or51211_ops, sizeof(struct dvb_frontend_ops)); state->initialized = 0; state->current_frequency = 0; /* Create dvb_frontend */ state->frontend.ops = &state->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 + -