diff options
author | Johannes Stezenbach <devnull@localhost> | 2005-02-19 21:19:56 +0000 |
---|---|---|
committer | Johannes Stezenbach <devnull@localhost> | 2005-02-19 21:19:56 +0000 |
commit | eae07280356edbf1ba4568c9fc2bdb7fb87eac64 (patch) | |
tree | b3578ef48cb1c6b6c2ab43c7533aab15200d27bf /linux/drivers/media | |
parent | fb04b1e717d9cc37f23f37a5b3544a564494c83f (diff) | |
download | mediapointer-dvb-s2-eae07280356edbf1ba4568c9fc2bdb7fb87eac64.tar.gz mediapointer-dvb-s2-eae07280356edbf1ba4568c9fc2bdb7fb87eac64.tar.bz2 |
clean up patch by Rusty Scott
Diffstat (limited to 'linux/drivers/media')
-rw-r--r-- | linux/drivers/media/dvb/frontends/or51211.c | 248 |
1 files changed, 141 insertions, 107 deletions
diff --git a/linux/drivers/media/dvb/frontends/or51211.c b/linux/drivers/media/dvb/frontends/or51211.c index 0dea1c4dc..b9153c7a6 100644 --- a/linux/drivers/media/dvb/frontends/or51211.c +++ b/linux/drivers/media/dvb/frontends/or51211.c @@ -66,7 +66,8 @@ struct or51211_state { u32 current_frequency; }; -static int i2c_writebytes (struct or51211_state* state, u8 reg, u8 *buf, int len) +static int i2c_writebytes (struct or51211_state* state, u8 reg, u8 *buf, + int len) { int err; struct i2c_msg msg; @@ -76,7 +77,8 @@ static int i2c_writebytes (struct or51211_state* state, u8 reg, u8 *buf, int len msg.buf = buf; if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) { - printk(KERN_WARNING "or51211: i2c_writebytes error (addr %02x, err == %i)\n", reg, err); + printk(KERN_WARNING "or51211: i2c_writebytes error " + "(addr %02x, err == %i)\n", reg, err); return -EREMOTEIO; } @@ -93,16 +95,18 @@ static u8 i2c_readbytes (struct or51211_state* state, u8 reg, u8* buf, int len) msg.buf = buf; if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) { - printk(KERN_WARNING "or51211: i2c_readbytes error (addr %02x, err == %i)\n", reg, err); + printk(KERN_WARNING "or51211: i2c_readbytes error " + "(addr %02x, err == %i)\n", reg, err); return -EREMOTEIO; } return 0; } -static int or51211_load_firmware (struct dvb_frontend* fe, const struct firmware *fw) +static int or51211_load_firmware (struct dvb_frontend* fe, + const struct firmware *fw) { - struct or51211_state* state = (struct or51211_state*) fe->demodulator_priv; + struct or51211_state* state = fe->demodulator_priv; u8 tudata[585]; int i; @@ -110,22 +114,21 @@ static int or51211_load_firmware (struct dvb_frontend* fe, const struct firmware /* Get eprom data */ tudata[0] = 17; - if(i2c_writebytes(state,0x50,tudata,1)) { - printk(KERN_WARNING "or51211: load_firmware error eprom addr\n"); + if (i2c_writebytes(state,0x50,tudata,1)) { + printk(KERN_WARNING "or51211:load_firmware error eprom addr\n"); return -1; } - if(i2c_readbytes(state,0x50,&tudata[145],192)) { + if (i2c_readbytes(state,0x50,&tudata[145],192)) { printk(KERN_WARNING "or51211: load_firmware error eprom\n"); return -1; } /* Create firmware buffer */ - for (i = 0; i < 145; i++) { - tudata[i] = fw->data[i]; - } - for (i = 0; i < 248; i++) { + for (i = 0; i < 145; i++) + tudata[i] = fw->data[i]; + + for (i = 0; i < 248; i++) tudata[i+337] = fw->data[145+i]; - } /* RESET DEVICE * reset is controled by GPIO-0 @@ -136,39 +139,44 @@ static int or51211_load_firmware (struct dvb_frontend* fe, const struct firmware * have been reset by a power on. When the driver is unloaded * reset set to 0 so if reloaded we have been reset. */ - i = bttv_gpio_enable(state->bt->bttv_nr, 0x001F, 0x001F); /* reset & PRM1,2&4 are outputs */ - if(i != 0) { - printk(KERN_WARNING "or51211: Init Error - Can't Reset DVR (%i)\n",i); + /* reset & PRM1,2&4 are outputs */ + i = bttv_gpio_enable(state->bt->bttv_nr, 0x001F, 0x001F); + if (i != 0) { + printk(KERN_WARNING "or51211: Init Error - Can't Reset DVR " + "(%i)\n",i); } bttv_write_gpio(state->bt->bttv_nr, 0x001F, 0x0000); /* Reset */ - msleep(20); /* Reset for 20ms */ - bttv_write_gpio(state->bt->bttv_nr, 0x0001F, 0x0001); /* Now set for normal operation */ - msleep(500); /* 500ms for operation to begin */ + msleep(20); + /* Now set for normal operation */ + bttv_write_gpio(state->bt->bttv_nr, 0x0001F, 0x0001); + /* wait for operation to begin */ + msleep(500); - if(i2c_writebytes(state,state->config->demod_address,tudata,585)) { + if (i2c_writebytes(state,state->config->demod_address,tudata,585)) { printk(KERN_WARNING "or51211: load_firmware error 1\n"); return -1; } - msleep(1); /* 1ms */ + msleep(1); - if(i2c_writebytes(state,state->config->demod_address,&fw->data[393],8125)) { + if (i2c_writebytes(state,state->config->demod_address, + &fw->data[393],8125)) { printk(KERN_WARNING "or51211: load_firmware error 2\n"); return -1; } - msleep(1); /* 1ms */ + msleep(1); - if(i2c_writebytes(state,state->config->demod_address,run_buf,2)) { + if (i2c_writebytes(state,state->config->demod_address,run_buf,2)) { printk(KERN_WARNING "or51211: load_firmware error 3\n"); return -1; } /* Wait at least 5 msec */ - msleep(10); /* 10ms */ - if(i2c_writebytes(state,state->config->demod_address,run_buf,2)) { + msleep(10); + if (i2c_writebytes(state,state->config->demod_address,run_buf,2)) { printk(KERN_WARNING "or51211: load_firmware error 4\n"); return -1; } - msleep(10); /* 10ms */ + msleep(10); printk("or51211: Done.\n"); return 0; @@ -176,25 +184,25 @@ static int or51211_load_firmware (struct dvb_frontend* fe, const struct firmware static int or51211_setmode(struct dvb_frontend* fe, int mode) { - struct or51211_state* state = (struct or51211_state*) fe->demodulator_priv; + struct or51211_state* state = fe->demodulator_priv; u8 rec_buf[14]; bttv_write_gpio(state->bt->bttv_nr, 0x0002, mode); /* Reset */ - msleep(20); /* Reset for 20ms */ + msleep(20); - if(i2c_writebytes(state,state->config->demod_address,run_buf,2)) { + if (i2c_writebytes(state,state->config->demod_address,run_buf,2)) { printk(KERN_WARNING "or51211: setmode error 1\n"); return -1; } /* Wait at least 5 msec */ - msleep(10); /* 20ms */ - if(i2c_writebytes(state,state->config->demod_address,run_buf,2)) { + msleep(10); + if (i2c_writebytes(state,state->config->demod_address,run_buf,2)) { printk(KERN_WARNING "or51211: setmode error 2\n"); return -1; } - msleep(10); /* 20ms */ + msleep(10); /* Set operation mode in Receiver 1 register; * type 1: @@ -205,7 +213,7 @@ static int or51211_setmode(struct dvb_frontend* fe, int mode) * High tuner phase noise * normal +/-150kHz Carrier acquisition range */ - if(i2c_writebytes(state,state->config->demod_address,cmd_buf,3)) { + if (i2c_writebytes(state,state->config->demod_address,cmd_buf,3)) { printk(KERN_WARNING "or51211: setmode error 3\n"); return -1; } @@ -214,12 +222,12 @@ static int or51211_setmode(struct dvb_frontend* fe, int mode) rec_buf[1] = 0x00; rec_buf[2] = 0x03; rec_buf[3] = 0x00; - msleep(20); /* 20ms */ - if(i2c_writebytes(state,state->config->demod_address,rec_buf,3)) { + msleep(20); + if (i2c_writebytes(state,state->config->demod_address,rec_buf,3)) { printk(KERN_WARNING "or51211: setmode error 5\n"); } - msleep(3); /* 3ms */ - if(i2c_readbytes(state,state->config->demod_address,&rec_buf[10],2)) { + msleep(3); + if (i2c_readbytes(state,state->config->demod_address,&rec_buf[10],2)) { printk(KERN_WARNING "or51211: setmode error 6"); return -1; } @@ -228,19 +236,21 @@ static int or51211_setmode(struct dvb_frontend* fe, int mode) return 0; } -static int or51211_set_parameters(struct dvb_frontend* fe,struct dvb_frontend_parameters *param) +static int or51211_set_parameters(struct dvb_frontend* fe, + struct dvb_frontend_parameters *param) { - struct or51211_state* state = (struct or51211_state*) fe->demodulator_priv; + struct or51211_state* state = fe->demodulator_priv; u32 freq = 0; u16 tunerfreq = 0; u8 buf[4]; /* Change only if we are actually changing the channel */ - if(state->current_frequency != param->frequency) { + if (state->current_frequency != param->frequency) { freq = 44000 + (param->frequency/1000); tunerfreq = freq * 16/1000; - dprintk("set_parameters frequency = %d (tunerfreq = %d)\n",param->frequency,tunerfreq); + dprintk("set_parameters frequency = %d (tunerfreq = %d)\n", + param->frequency,tunerfreq); buf[0] = (tunerfreq >> 8) & 0x7F; buf[1] = (tunerfreq & 0xFF); @@ -248,18 +258,20 @@ static int or51211_set_parameters(struct dvb_frontend* fe,struct dvb_frontend_pa if (param->frequency < 157250000) { buf[3] = 0xA0; - dprintk(KERN_WARNING "set_parameters VHF low range\n"); + dprintk("set_parameters VHF low range\n"); } else if (param->frequency < 454000000) { buf[3] = 0x90; - dprintk(KERN_WARNING "set_parameters VHF high range\n"); + dprintk("set_parameters VHF high range\n"); } else { buf[3] = 0x30; - dprintk(KERN_WARNING "set_parameters UHF range\n"); + dprintk("set_parameters UHF range\n"); } - dprintk("set_parameters tuner bytes: 0x%02x 0x%02x 0x%02x 0x%02x\n",buf[0],buf[1],buf[2],buf[3]); + dprintk("set_parameters tuner bytes: 0x%02x 0x%02x " + "0x%02x 0x%02x\n",buf[0],buf[1],buf[2],buf[3]); - if(i2c_writebytes(state,0xC2>>1,buf,4)) - printk(KERN_WARNING "or51211: set_parameters error writing to tuner\n"); + if (i2c_writebytes(state,0xC2>>1,buf,4)) + printk(KERN_WARNING "or51211:set_parameters error " + "writing to tuner\n"); /* Set to ATSC mode */ or51211_setmode(fe,0); @@ -272,24 +284,24 @@ static int or51211_set_parameters(struct dvb_frontend* fe,struct dvb_frontend_pa static int or51211_read_status(struct dvb_frontend* fe, fe_status_t* status) { - struct or51211_state* state = (struct or51211_state*) fe->demodulator_priv; + struct or51211_state* state = fe->demodulator_priv; unsigned char rec_buf[2]; unsigned char snd_buf[] = {0x04,0x00,0x03,0x00}; *status = 0; /* Receiver Status */ - if(i2c_writebytes(state,state->config->demod_address,snd_buf,3)) { + if (i2c_writebytes(state,state->config->demod_address,snd_buf,3)) { printk(KERN_WARNING "or51132: read_status write error\n"); return -1; } - msleep(3); /* 3ms */ - if(i2c_readbytes(state,state->config->demod_address,rec_buf,2)) { + msleep(3); + if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) { printk(KERN_WARNING "or51132: read_status read error\n"); return -1; } dprintk("read_status %x %x\n",rec_buf[0],rec_buf[1]); - if(rec_buf[0] & 0x01) { /* Receiver Lock */ + if (rec_buf[0] & 0x01) { /* Receiver Lock */ *status |= FE_HAS_SIGNAL; *status |= FE_HAS_CARRIER; *status |= FE_HAS_VITERBI; @@ -334,7 +346,7 @@ unsigned int i20Log10(unsigned short val) while(tmp > 100) {tmp /= 100; exp++;} val = (2 * val)/denom[exp]; - if(exp > 1) rntval = 2000*exp; + if (exp > 1) rntval = 2000*exp; rntval += i100x20log10[val]; return rntval; @@ -342,7 +354,7 @@ unsigned int i20Log10(unsigned short val) static int or51211_read_signal_strength(struct dvb_frontend* fe, u16* strength) { - struct or51211_state* state = (struct or51211_state*) fe->demodulator_priv; + struct or51211_state* state = fe->demodulator_priv; u8 rec_buf[2]; u8 snd_buf[4]; u8 snr_equ; @@ -353,12 +365,12 @@ static int or51211_read_signal_strength(struct dvb_frontend* fe, u16* strength) snd_buf[2] = 0x04; snd_buf[3] = 0x00; - if(i2c_writebytes(state,state->config->demod_address,snd_buf,3)) { + if (i2c_writebytes(state,state->config->demod_address,snd_buf,3)) { printk(KERN_WARNING "or51211: read_status write error\n"); return -1; } - msleep(3); /* 3ms */ - if(i2c_readbytes(state,state->config->demod_address,rec_buf,2)) { + msleep(3); + if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) { printk(KERN_WARNING "or51211: read_status read error\n"); return -1; } @@ -374,7 +386,7 @@ static int or51211_read_signal_strength(struct dvb_frontend* fe, u16* strength) static int or51211_read_snr(struct dvb_frontend* fe, u16* snr) { - struct or51211_state* state = (struct or51211_state*) fe->demodulator_priv; + struct or51211_state* state = fe->demodulator_priv; u8 rec_buf[2]; u8 snd_buf[4]; @@ -384,12 +396,12 @@ static int or51211_read_snr(struct dvb_frontend* fe, u16* snr) snd_buf[2] = 0x04; snd_buf[3] = 0x00; - if(i2c_writebytes(state,state->config->demod_address,snd_buf,3)) { + if (i2c_writebytes(state,state->config->demod_address,snd_buf,3)) { printk(KERN_WARNING "or51211: read_status write error\n"); return -1; } - msleep(3); /* 30ms */ - if(i2c_readbytes(state,state->config->demod_address,rec_buf,2)) { + msleep(3); + if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) { printk(KERN_WARNING "or51211: read_status read error\n"); return -1; } @@ -419,29 +431,34 @@ static int or51211_sleep(struct dvb_frontend* fe) static int or51211_init(struct dvb_frontend* fe) { - struct or51211_state* state = (struct or51211_state*) fe->demodulator_priv; - const struct firmware *fw; + 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 someone uploads it */ - printk(KERN_WARNING "or51211: Waiting for firmware upload (%s)...\n", OR51211_DEFAULT_FIRMWARE); - ret = state->config->request_firmware(fe, &fw, OR51211_DEFAULT_FIRMWARE); - printk(KERN_WARNING "or51211: Waiting for firmware upload(2)...\n"); + /* 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"); + 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"); + printk(KERN_WARNING "or51211: Writing firmware to " + "device failed!\n"); release_firmware(fw); return ret; } - printk("or51211: Firmware upload complete.\n"); + printk(KERN_INFO "or51211: Firmware upload complete.\n"); /* Set operation mode in Receiver 1 register; * type 1: @@ -452,23 +469,27 @@ static int or51211_init(struct dvb_frontend* fe) * High tuner phase noise * normal +/-150kHz Carrier acquisition range */ - if(i2c_writebytes(state,state->config->demod_address,cmd_buf,3)) { + 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 */ + /* 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); /* 20ms */ - if(i2c_writebytes(state,state->config->demod_address,rec_buf,3)) { + 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); /* 3ms */ - if(i2c_readbytes(state,state->config->demod_address,&rec_buf[10],2)) { + 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; } @@ -477,35 +498,41 @@ static int or51211_init(struct dvb_frontend* fe) rec_buf[1] = 0x00; rec_buf[2] = 0x01; rec_buf[3] = 0x00; - msleep(20); /* 20ms */ - if(i2c_writebytes(state,state->config->demod_address,rec_buf,3)) { + 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); /* 3ms */ - if(i2c_readbytes(state,state->config->demod_address,&rec_buf[12],2)) { + 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++) { + for (i = 0; i < 8; i++) rec_buf[i]=0xed; - } - for(i = 0; i < 5; i++) { - msleep(30); /* 20ms */ + 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); + 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); /* 3ms */ + 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); + 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((int)rec_buf[i*2+1]!=i+1){ + /* If we didn't receive the right index, try again */ + if ((int)rec_buf[i*2+1]!=i+1){ i--; } } @@ -514,20 +541,24 @@ static int or51211_init(struct dvb_frontend* fe) rec_buf[4], rec_buf[5], rec_buf[6], rec_buf[7], rec_buf[8], rec_buf[9]); - printk(KERN_WARNING "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]); + 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); /* 20ms */ - if(i2c_writebytes(state,state->config->demod_address,rec_buf,3)) { + 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); /* 20ms */ - if(i2c_readbytes(state,state->config->demod_address,&rec_buf[8],2)) { + 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; } @@ -537,7 +568,8 @@ static int or51211_init(struct dvb_frontend* fe) return 0; } -static int or51211_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings) +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; @@ -547,9 +579,10 @@ static int or51211_get_tune_settings(struct dvb_frontend* fe, struct dvb_fronten static void or51211_release(struct dvb_frontend* fe) { - struct or51211_state* state = (struct or51211_state*) fe->demodulator_priv; + struct or51211_state* state = fe->demodulator_priv; - bttv_write_gpio(state->bt->bttv_nr, 0x0001, 0x0000); /* Now in reset condition */ + /* Now in reset condition */ + bttv_write_gpio(state->bt->bttv_nr, 0x0001, 0x0000); kfree(state); } @@ -562,8 +595,9 @@ struct dvb_frontend* or51211_attach(const struct or51211_config* config, struct or51211_state* state = NULL; /* Allocate memory for the internal state */ - state = (struct or51211_state*) kmalloc(sizeof(struct or51211_state), GFP_KERNEL); - if (state == NULL) goto error; + state = kmalloc(sizeof(struct or51211_state), GFP_KERNEL); + if (state == NULL) + goto error; /* Setup the state */ state->config = config; @@ -586,11 +620,11 @@ error: 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, + .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 |