tuner_e4k: add manual i/q correction

This commit is contained in:
Christian Daniel 2012-03-06 15:29:33 +01:00
parent 7abdbca85c
commit 4683c1c21a
3 changed files with 50 additions and 0 deletions

View File

@ -207,6 +207,8 @@ int sam3u_e4k_init(struct e4k_state *e4k, void *i2c, uint8_t slave_addr);
void sam3u_e4k_power(struct e4k_state *e4k, int on);
void sam3u_e4k_stby(struct e4k_state *e4k, int on);
int e4k_manual_dc_offset(struct e4k_state *e4k, int8_t iofs, int8_t irange, int8_t qofs, int8_t qrange);
int e4k_dc_offset_calibrate(struct e4k_state *e4k);
int e4k_dc_offset_gen_table(struct e4k_state *e4k);

View File

@ -313,6 +313,27 @@ static int cmd_tuner_commonmode(struct cmd_state *cs, enum cmd_op op,
return 0;
}
static int cmd_tuner_iqofs(struct cmd_state *cs, enum cmd_op op,
const char *cmd, int argc, char ** argv)
{
int iofs;
int qofs;
int irange;
int qrange;
if(op != CMD_OP_SET)
return -EINVAL;
if(argc < 4)
return -EINVAL;
iofs = strtol(argv[0], NULL, 10);
qofs = strtol(argv[1], NULL, 10);
irange = strtol(argv[2], NULL, 10);
qrange = strtol(argv[3], NULL, 10);
return e4k_manual_dc_offset(&e4k, iofs, irange, qofs, qrange);
}
static struct cmd cmds[] = {
{ "tuner.init", CMD_OP_EXEC, cmd_tuner_init,
"Initialize the tuner" },
@ -332,6 +353,8 @@ static struct cmd cmds[] = {
"Generate DC offset table" },
{ "tuner.commonmode", CMD_OP_SET, cmd_tuner_commonmode,
"Switch common mode voltage" },
{ "tuner.iqofs", CMD_OP_SET, cmd_tuner_iqofs,
"Manually set I/Q offset and correction range" },
{ "si570.freq", CMD_OP_SET|CMD_OP_GET, cmd_si570_freq,
"Change the SI570 clock frequency" },

View File

@ -727,6 +727,31 @@ int e4k_commonmode_set(struct e4k_state *e4k, int8_t value)
/***********************************************************************
* DC Offset */
int e4k_manual_dc_offset(struct e4k_state *e4k, int8_t iofs, int8_t irange, int8_t qofs, int8_t qrange)
{
int res;
if((iofs < 0x00) || (iofs > 0x3f))
return -EINVAL;
if((irange < 0x00) || (irange > 0x03))
return -EINVAL;
if((qofs < 0x00) || (qofs > 0x3f))
return -EINVAL;
if((qrange < 0x00) || (qrange > 0x03))
return -EINVAL;
res = e4k_reg_set_mask(e4k, E4K_REG_DC2, 0x3f, iofs);
if(res < 0)
return res;
res = e4k_reg_set_mask(e4k, E4K_REG_DC3, 0x3f, qofs);
if(res < 0)
return res;
res = e4k_reg_set_mask(e4k, E4K_REG_DC4, 0x33, (qrange << 4) | irange);
return res;
}
/*! \brief Perform a DC offset calibration right now
* \param[e4k] handle to the tuner chip
*/