提交 be44eb28 编写于 作者: M Mauro Carvalho Chehab

[media] drxk: Proper handle/propagate the error codes

This driver is very big and complex. An error happening in the middle
of any initialization may cause the frontend to not work. So, it
needs to properly propagate error codes internally and to userspace.

Also, printing the error codes at the places it happened helps to
discover were's a bug at the code.

Before this change, a do { } while (0) loop and lots of breaks inside
were used to propagate errors. While this works, if there are
loops inside other loops, it could be easy to forget to add another
break, causing the error to not abort the function.

Also, as not all functions were reporting errors, it is hard to
discover why something failed.
Signed-off-by: NMauro Carvalho Chehab <mchehab@redhat.com>
上级 f1fe1b75
...@@ -318,11 +318,13 @@ static int i2c_read1(struct i2c_adapter *adapter, u8 adr, u8 *val) ...@@ -318,11 +318,13 @@ static int i2c_read1(struct i2c_adapter *adapter, u8 adr, u8 *val)
struct i2c_msg msgs[1] = { {.addr = adr, .flags = I2C_M_RD, struct i2c_msg msgs[1] = { {.addr = adr, .flags = I2C_M_RD,
.buf = val, .len = 1} .buf = val, .len = 1}
}; };
return (i2c_transfer(adapter, msgs, 1) == 1) ? 0 : -1;
return i2c_transfer(adapter, msgs, 1);
} }
static int i2c_write(struct i2c_adapter *adap, u8 adr, u8 *data, int len) static int i2c_write(struct i2c_adapter *adap, u8 adr, u8 *data, int len)
{ {
int status;
struct i2c_msg msg = { struct i2c_msg msg = {
.addr = adr, .flags = 0, .buf = data, .len = len }; .addr = adr, .flags = 0, .buf = data, .len = len };
...@@ -333,16 +335,20 @@ static int i2c_write(struct i2c_adapter *adap, u8 adr, u8 *data, int len) ...@@ -333,16 +335,20 @@ static int i2c_write(struct i2c_adapter *adap, u8 adr, u8 *data, int len)
printk(KERN_CONT " %02x", data[i]); printk(KERN_CONT " %02x", data[i]);
printk(KERN_CONT "\n"); printk(KERN_CONT "\n");
} }
if (i2c_transfer(adap, &msg, 1) != 1) { status = i2c_transfer(adap, &msg, 1);
if (status >= 0 && status != 1)
status = -EIO;
if (status < 0)
printk(KERN_ERR "drxk: i2c write error at addr 0x%02x\n", adr); printk(KERN_ERR "drxk: i2c write error at addr 0x%02x\n", adr);
return -1;
} return status;
return 0;
} }
static int i2c_read(struct i2c_adapter *adap, static int i2c_read(struct i2c_adapter *adap,
u8 adr, u8 *msg, int len, u8 *answ, int alen) u8 adr, u8 *msg, int len, u8 *answ, int alen)
{ {
int status;
struct i2c_msg msgs[2] = { struct i2c_msg msgs[2] = {
{.addr = adr, .flags = 0, {.addr = adr, .flags = 0,
.buf = msg, .len = len}, .buf = msg, .len = len},
...@@ -356,12 +362,15 @@ static int i2c_read(struct i2c_adapter *adap, ...@@ -356,12 +362,15 @@ static int i2c_read(struct i2c_adapter *adap,
printk(KERN_CONT " %02x", msg[i]); printk(KERN_CONT " %02x", msg[i]);
printk(KERN_CONT "\n"); printk(KERN_CONT "\n");
} }
if (i2c_transfer(adap, msgs, 2) != 2) { status = i2c_transfer(adap, msgs, 2);
if (status != 2) {
if (debug > 2) if (debug > 2)
printk(KERN_CONT ": ERROR!\n"); printk(KERN_CONT ": ERROR!\n");
if (status >= 0)
status = -EIO;
printk(KERN_ERR "drxk: i2c read error at addr 0x%02x\n", adr); printk(KERN_ERR "drxk: i2c read error at addr 0x%02x\n", adr);
return -1; return status;
} }
if (debug > 2) { if (debug > 2) {
int i; int i;
...@@ -375,6 +384,7 @@ static int i2c_read(struct i2c_adapter *adap, ...@@ -375,6 +384,7 @@ static int i2c_read(struct i2c_adapter *adap,
static int read16_flags(struct drxk_state *state, u32 reg, u16 *data, u8 flags) static int read16_flags(struct drxk_state *state, u32 reg, u16 *data, u8 flags)
{ {
int status;
u8 adr = state->demod_address, mm1[4], mm2[2], len; u8 adr = state->demod_address, mm1[4], mm2[2], len;
if (state->single_master) if (state->single_master)
...@@ -392,8 +402,9 @@ static int read16_flags(struct drxk_state *state, u32 reg, u16 *data, u8 flags) ...@@ -392,8 +402,9 @@ static int read16_flags(struct drxk_state *state, u32 reg, u16 *data, u8 flags)
len = 2; len = 2;
} }
dprintk(2, "(0x%08x, 0x%02x)\n", reg, flags); dprintk(2, "(0x%08x, 0x%02x)\n", reg, flags);
if (i2c_read(state->i2c, adr, mm1, len, mm2, 2) < 0) status = i2c_read(state->i2c, adr, mm1, len, mm2, 2);
return -1; if (status < 0)
return status;
if (data) if (data)
*data = mm2[0] | (mm2[1] << 8); *data = mm2[0] | (mm2[1] << 8);
...@@ -407,6 +418,7 @@ static int read16(struct drxk_state *state, u32 reg, u16 *data) ...@@ -407,6 +418,7 @@ static int read16(struct drxk_state *state, u32 reg, u16 *data)
static int read32_flags(struct drxk_state *state, u32 reg, u32 *data, u8 flags) static int read32_flags(struct drxk_state *state, u32 reg, u32 *data, u8 flags)
{ {
int status;
u8 adr = state->demod_address, mm1[4], mm2[4], len; u8 adr = state->demod_address, mm1[4], mm2[4], len;
if (state->single_master) if (state->single_master)
...@@ -424,8 +436,9 @@ static int read32_flags(struct drxk_state *state, u32 reg, u32 *data, u8 flags) ...@@ -424,8 +436,9 @@ static int read32_flags(struct drxk_state *state, u32 reg, u32 *data, u8 flags)
len = 2; len = 2;
} }
dprintk(2, "(0x%08x, 0x%02x)\n", reg, flags); dprintk(2, "(0x%08x, 0x%02x)\n", reg, flags);
if (i2c_read(state->i2c, adr, mm1, len, mm2, 4) < 0) status = i2c_read(state->i2c, adr, mm1, len, mm2, 4);
return -1; if (status < 0)
return status;
if (data) if (data)
*data = mm2[0] | (mm2[1] << 8) | *data = mm2[0] | (mm2[1] << 8) |
(mm2[2] << 16) | (mm2[3] << 24); (mm2[2] << 16) | (mm2[3] << 24);
...@@ -459,9 +472,7 @@ static int write16_flags(struct drxk_state *state, u32 reg, u16 data, u8 flags) ...@@ -459,9 +472,7 @@ static int write16_flags(struct drxk_state *state, u32 reg, u16 data, u8 flags)
mm[len + 1] = (data >> 8) & 0xff; mm[len + 1] = (data >> 8) & 0xff;
dprintk(2, "(0x%08x, 0x%04x, 0x%02x)\n", reg, data, flags); dprintk(2, "(0x%08x, 0x%04x, 0x%02x)\n", reg, data, flags);
if (i2c_write(state->i2c, adr, mm, len + 2) < 0) return i2c_write(state->i2c, adr, mm, len + 2);
return -1;
return 0;
} }
static int write16(struct drxk_state *state, u32 reg, u16 data) static int write16(struct drxk_state *state, u32 reg, u16 data)
...@@ -491,9 +502,8 @@ static int write32_flags(struct drxk_state *state, u32 reg, u32 data, u8 flags) ...@@ -491,9 +502,8 @@ static int write32_flags(struct drxk_state *state, u32 reg, u32 data, u8 flags)
mm[len + 2] = (data >> 16) & 0xff; mm[len + 2] = (data >> 16) & 0xff;
mm[len + 3] = (data >> 24) & 0xff; mm[len + 3] = (data >> 24) & 0xff;
dprintk(2, "(0x%08x, 0x%08x, 0x%02x)\n", reg, data, flags); dprintk(2, "(0x%08x, 0x%08x, 0x%02x)\n", reg, data, flags);
if (i2c_write(state->i2c, adr, mm, len + 4) < 0)
return -1; return i2c_write(state->i2c, adr, mm, len + 4);
return 0;
} }
static int write32(struct drxk_state *state, u32 reg, u32 data) static int write32(struct drxk_state *state, u32 reg, u32 data)
...@@ -567,33 +577,41 @@ int PowerUpDevice(struct drxk_state *state) ...@@ -567,33 +577,41 @@ int PowerUpDevice(struct drxk_state *state)
dprintk(1, "\n"); dprintk(1, "\n");
status = i2c_read1(state->i2c, state->demod_address, &data); status = i2c_read1(state->i2c, state->demod_address, &data);
if (status < 0) if (status < 0) {
do { do {
data = 0; data = 0;
if (i2c_write(state->i2c, status = i2c_write(state->i2c, state->demod_address,
state->demod_address, &data, 1) < 0) &data, 1);
printk(KERN_ERR "drxk: powerup failed\n");
msleep(10); msleep(10);
retryCount++; retryCount++;
} while (i2c_read1(state->i2c, if (status < 0)
state->demod_address, &data) < 0 && continue;
status = i2c_read1(state->i2c, state->demod_address,
&data);
} while (status < 0 &&
(retryCount < DRXK_MAX_RETRIES_POWERUP)); (retryCount < DRXK_MAX_RETRIES_POWERUP));
if (retryCount >= DRXK_MAX_RETRIES_POWERUP) if (status < 0 && retryCount >= DRXK_MAX_RETRIES_POWERUP)
return -1; goto error;
do { }
/* Make sure all clk domains are active */ /* Make sure all clk domains are active */
status = write16(state, SIO_CC_PWD_MODE__A, SIO_CC_PWD_MODE_LEVEL_NONE); status = write16(state, SIO_CC_PWD_MODE__A, SIO_CC_PWD_MODE_LEVEL_NONE);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY); status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY);
if (status < 0) if (status < 0)
break; goto error;
/* Enable pll lock tests */ /* Enable pll lock tests */
status = write16(state, SIO_CC_PLL_LOCK__A, 1); status = write16(state, SIO_CC_PLL_LOCK__A, 1);
if (status < 0) if (status < 0)
break; goto error;
state->m_currentPowerMode = DRX_POWER_UP; state->m_currentPowerMode = DRX_POWER_UP;
} while (0);
error:
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -863,28 +881,27 @@ static int DRXX_Open(struct drxk_state *state) ...@@ -863,28 +881,27 @@ static int DRXX_Open(struct drxk_state *state)
u16 key = 0; u16 key = 0;
dprintk(1, "\n"); dprintk(1, "\n");
do {
/* stop lock indicator process */ /* stop lock indicator process */
status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE);
if (status < 0) if (status < 0)
break; goto error;
/* Check device id */ /* Check device id */
status = read16(state, SIO_TOP_COMM_KEY__A, &key); status = read16(state, SIO_TOP_COMM_KEY__A, &key);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY); status = write16(state, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY);
if (status < 0) if (status < 0)
break; goto error;
status = read32(state, SIO_TOP_JTAGID_LO__A, &jtag); status = read32(state, SIO_TOP_JTAGID_LO__A, &jtag);
if (status < 0) if (status < 0)
break; goto error;
status = read16(state, SIO_PDR_UIO_IN_HI__A, &bid); status = read16(state, SIO_PDR_UIO_IN_HI__A, &bid);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_TOP_COMM_KEY__A, key); status = write16(state, SIO_TOP_COMM_KEY__A, key);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
...@@ -895,22 +912,21 @@ static int GetDeviceCapabilities(struct drxk_state *state) ...@@ -895,22 +912,21 @@ static int GetDeviceCapabilities(struct drxk_state *state)
int status; int status;
dprintk(1, "\n"); dprintk(1, "\n");
do {
/* driver 0.9.0 */ /* driver 0.9.0 */
/* stop lock indicator process */ /* stop lock indicator process */
status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_TOP_COMM_KEY__A, 0xFABA); status = write16(state, SIO_TOP_COMM_KEY__A, 0xFABA);
if (status < 0) if (status < 0)
break; goto error;
status = read16(state, SIO_PDR_OHW_CFG__A, &sioPdrOhwCfg); status = read16(state, SIO_PDR_OHW_CFG__A, &sioPdrOhwCfg);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_TOP_COMM_KEY__A, 0x0000); status = write16(state, SIO_TOP_COMM_KEY__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
switch ((sioPdrOhwCfg & SIO_PDR_OHW_CFG_FREF_SEL__M)) { switch ((sioPdrOhwCfg & SIO_PDR_OHW_CFG_FREF_SEL__M)) {
case 0: case 0:
...@@ -929,7 +945,8 @@ static int GetDeviceCapabilities(struct drxk_state *state) ...@@ -929,7 +945,8 @@ static int GetDeviceCapabilities(struct drxk_state *state)
state->m_oscClockFreq = 20250; state->m_oscClockFreq = 20250;
break; break;
default: default:
return -1; printk(KERN_ERR "drxk: Clock Frequency is unkonwn\n");
return -EINVAL;
} }
/* /*
Determine device capabilities Determine device capabilities
...@@ -937,7 +954,7 @@ static int GetDeviceCapabilities(struct drxk_state *state) ...@@ -937,7 +954,7 @@ static int GetDeviceCapabilities(struct drxk_state *state)
*/ */
status = read32(state, SIO_TOP_JTAGID_LO__A, &sioTopJtagidLo); status = read32(state, SIO_TOP_JTAGID_LO__A, &sioTopJtagidLo);
if (status < 0) if (status < 0)
break; goto error;
/* driver 0.9.0 */ /* driver 0.9.0 */
switch ((sioTopJtagidLo >> 29) & 0xF) { switch ((sioTopJtagidLo >> 29) & 0xF) {
case 0: case 0:
...@@ -951,8 +968,9 @@ static int GetDeviceCapabilities(struct drxk_state *state) ...@@ -951,8 +968,9 @@ static int GetDeviceCapabilities(struct drxk_state *state)
break; break;
default: default:
state->m_deviceSpin = DRXK_SPIN_UNKNOWN; state->m_deviceSpin = DRXK_SPIN_UNKNOWN;
status = -1; status = -EINVAL;
break; printk(KERN_ERR "drxk: Spin unknown\n");
goto error2;
} }
switch ((sioTopJtagidLo >> 12) & 0xFF) { switch ((sioTopJtagidLo >> 12) & 0xFF) {
case 0x13: case 0x13:
...@@ -1062,10 +1080,15 @@ static int GetDeviceCapabilities(struct drxk_state *state) ...@@ -1062,10 +1080,15 @@ static int GetDeviceCapabilities(struct drxk_state *state)
default: default:
printk(KERN_ERR "drxk: DeviceID not supported = %02x\n", printk(KERN_ERR "drxk: DeviceID not supported = %02x\n",
((sioTopJtagidLo >> 12) & 0xFF)); ((sioTopJtagidLo >> 12) & 0xFF));
status = -1; status = -EINVAL;
break; goto error2;
} }
} while (0);
error:
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
error2:
return status; return status;
} }
...@@ -1079,7 +1102,7 @@ static int HI_Command(struct drxk_state *state, u16 cmd, u16 *pResult) ...@@ -1079,7 +1102,7 @@ static int HI_Command(struct drxk_state *state, u16 cmd, u16 *pResult)
/* Write command */ /* Write command */
status = write16(state, SIO_HI_RA_RAM_CMD__A, cmd); status = write16(state, SIO_HI_RA_RAM_CMD__A, cmd);
if (status < 0) if (status < 0)
return status; goto error;
if (cmd == SIO_HI_RA_RAM_CMD_RESET) if (cmd == SIO_HI_RA_RAM_CMD_RESET)
msleep(1); msleep(1);
...@@ -1100,11 +1123,14 @@ static int HI_Command(struct drxk_state *state, u16 cmd, u16 *pResult) ...@@ -1100,11 +1123,14 @@ static int HI_Command(struct drxk_state *state, u16 cmd, u16 *pResult)
&waitCmd); &waitCmd);
} while ((status < 0) && (retryCount < DRXK_MAX_RETRIES) } while ((status < 0) && (retryCount < DRXK_MAX_RETRIES)
&& (waitCmd != 0)); && (waitCmd != 0));
if (status < 0)
if (status == 0) goto error;
status = read16(state, SIO_HI_RA_RAM_RES__A, status = read16(state, SIO_HI_RA_RAM_RES__A, pResult);
pResult);
} }
error:
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -1115,32 +1141,34 @@ static int HI_CfgCommand(struct drxk_state *state) ...@@ -1115,32 +1141,34 @@ static int HI_CfgCommand(struct drxk_state *state)
dprintk(1, "\n"); dprintk(1, "\n");
mutex_lock(&state->mutex); mutex_lock(&state->mutex);
do {
status = write16(state, SIO_HI_RA_RAM_PAR_6__A, state->m_HICfgTimeout); status = write16(state, SIO_HI_RA_RAM_PAR_6__A, state->m_HICfgTimeout);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_HI_RA_RAM_PAR_5__A, state->m_HICfgCtrl); status = write16(state, SIO_HI_RA_RAM_PAR_5__A, state->m_HICfgCtrl);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_HI_RA_RAM_PAR_4__A, state->m_HICfgWakeUpKey); status = write16(state, SIO_HI_RA_RAM_PAR_4__A, state->m_HICfgWakeUpKey);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_HI_RA_RAM_PAR_3__A, state->m_HICfgBridgeDelay); status = write16(state, SIO_HI_RA_RAM_PAR_3__A, state->m_HICfgBridgeDelay);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_HI_RA_RAM_PAR_2__A, state->m_HICfgTimingDiv); status = write16(state, SIO_HI_RA_RAM_PAR_2__A, state->m_HICfgTimingDiv);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_HI_RA_RAM_PAR_1__A, SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY); status = write16(state, SIO_HI_RA_RAM_PAR_1__A, SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY);
if (status < 0) if (status < 0)
break; goto error;
status = HI_Command(state, SIO_HI_RA_RAM_CMD_CONFIG, 0); status = HI_Command(state, SIO_HI_RA_RAM_CMD_CONFIG, 0);
if (status < 0) if (status < 0)
break; goto error;
state->m_HICfgCtrl &= ~SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ; state->m_HICfgCtrl &= ~SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ;
} while (0); error:
mutex_unlock(&state->mutex); mutex_unlock(&state->mutex);
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -1152,6 +1180,7 @@ static int InitHI(struct drxk_state *state) ...@@ -1152,6 +1180,7 @@ static int InitHI(struct drxk_state *state)
state->m_HICfgTimeout = 0x96FF; state->m_HICfgTimeout = 0x96FF;
/* port/bridge/power down ctrl */ /* port/bridge/power down ctrl */
state->m_HICfgCtrl = SIO_HI_RA_RAM_PAR_5_CFG_SLV0_SLAVE; state->m_HICfgCtrl = SIO_HI_RA_RAM_PAR_5_CFG_SLV0_SLAVE;
return HI_CfgCommand(state); return HI_CfgCommand(state);
} }
...@@ -1162,55 +1191,55 @@ static int MPEGTSConfigurePins(struct drxk_state *state, bool mpegEnable) ...@@ -1162,55 +1191,55 @@ static int MPEGTSConfigurePins(struct drxk_state *state, bool mpegEnable)
u16 sioPdrMdxCfg = 0; u16 sioPdrMdxCfg = 0;
dprintk(1, "\n"); dprintk(1, "\n");
do {
/* stop lock indicator process */ /* stop lock indicator process */
status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE);
if (status < 0) if (status < 0)
break; goto error;
/* MPEG TS pad configuration */ /* MPEG TS pad configuration */
status = write16(state, SIO_TOP_COMM_KEY__A, 0xFABA); status = write16(state, SIO_TOP_COMM_KEY__A, 0xFABA);
if (status < 0) if (status < 0)
break; goto error;
if (mpegEnable == false) { if (mpegEnable == false) {
/* Set MPEG TS pads to inputmode */ /* Set MPEG TS pads to inputmode */
status = write16(state, SIO_PDR_MSTRT_CFG__A, 0x0000); status = write16(state, SIO_PDR_MSTRT_CFG__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MERR_CFG__A, 0x0000); status = write16(state, SIO_PDR_MERR_CFG__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MCLK_CFG__A, 0x0000); status = write16(state, SIO_PDR_MCLK_CFG__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MVAL_CFG__A, 0x0000); status = write16(state, SIO_PDR_MVAL_CFG__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MD0_CFG__A, 0x0000); status = write16(state, SIO_PDR_MD0_CFG__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MD1_CFG__A, 0x0000); status = write16(state, SIO_PDR_MD1_CFG__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MD2_CFG__A, 0x0000); status = write16(state, SIO_PDR_MD2_CFG__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MD3_CFG__A, 0x0000); status = write16(state, SIO_PDR_MD3_CFG__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MD4_CFG__A, 0x0000); status = write16(state, SIO_PDR_MD4_CFG__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MD5_CFG__A, 0x0000); status = write16(state, SIO_PDR_MD5_CFG__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MD6_CFG__A, 0x0000); status = write16(state, SIO_PDR_MD6_CFG__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MD7_CFG__A, 0x0000); status = write16(state, SIO_PDR_MD7_CFG__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
} else { } else {
/* Enable MPEG output */ /* Enable MPEG output */
sioPdrMdxCfg = sioPdrMdxCfg =
...@@ -1222,36 +1251,36 @@ static int MPEGTSConfigurePins(struct drxk_state *state, bool mpegEnable) ...@@ -1222,36 +1251,36 @@ static int MPEGTSConfigurePins(struct drxk_state *state, bool mpegEnable)
status = write16(state, SIO_PDR_MSTRT_CFG__A, sioPdrMdxCfg); status = write16(state, SIO_PDR_MSTRT_CFG__A, sioPdrMdxCfg);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MERR_CFG__A, 0x0000); /* Disable */ status = write16(state, SIO_PDR_MERR_CFG__A, 0x0000); /* Disable */
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MVAL_CFG__A, 0x0000); /* Disable */ status = write16(state, SIO_PDR_MVAL_CFG__A, 0x0000); /* Disable */
if (status < 0) if (status < 0)
break; goto error;
if (state->m_enableParallel == true) { if (state->m_enableParallel == true) {
/* paralel -> enable MD1 to MD7 */ /* paralel -> enable MD1 to MD7 */
status = write16(state, SIO_PDR_MD1_CFG__A, sioPdrMdxCfg); status = write16(state, SIO_PDR_MD1_CFG__A, sioPdrMdxCfg);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MD2_CFG__A, sioPdrMdxCfg); status = write16(state, SIO_PDR_MD2_CFG__A, sioPdrMdxCfg);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MD3_CFG__A, sioPdrMdxCfg); status = write16(state, SIO_PDR_MD3_CFG__A, sioPdrMdxCfg);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MD4_CFG__A, sioPdrMdxCfg); status = write16(state, SIO_PDR_MD4_CFG__A, sioPdrMdxCfg);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MD5_CFG__A, sioPdrMdxCfg); status = write16(state, SIO_PDR_MD5_CFG__A, sioPdrMdxCfg);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MD6_CFG__A, sioPdrMdxCfg); status = write16(state, SIO_PDR_MD6_CFG__A, sioPdrMdxCfg);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MD7_CFG__A, sioPdrMdxCfg); status = write16(state, SIO_PDR_MD7_CFG__A, sioPdrMdxCfg);
if (status < 0) if (status < 0)
break; goto error;
} else { } else {
sioPdrMdxCfg = ((state->m_TSDataStrength << sioPdrMdxCfg = ((state->m_TSDataStrength <<
SIO_PDR_MD0_CFG_DRIVE__B) SIO_PDR_MD0_CFG_DRIVE__B)
...@@ -1259,42 +1288,42 @@ static int MPEGTSConfigurePins(struct drxk_state *state, bool mpegEnable) ...@@ -1259,42 +1288,42 @@ static int MPEGTSConfigurePins(struct drxk_state *state, bool mpegEnable)
/* serial -> disable MD1 to MD7 */ /* serial -> disable MD1 to MD7 */
status = write16(state, SIO_PDR_MD1_CFG__A, 0x0000); status = write16(state, SIO_PDR_MD1_CFG__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MD2_CFG__A, 0x0000); status = write16(state, SIO_PDR_MD2_CFG__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MD3_CFG__A, 0x0000); status = write16(state, SIO_PDR_MD3_CFG__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MD4_CFG__A, 0x0000); status = write16(state, SIO_PDR_MD4_CFG__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MD5_CFG__A, 0x0000); status = write16(state, SIO_PDR_MD5_CFG__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MD6_CFG__A, 0x0000); status = write16(state, SIO_PDR_MD6_CFG__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MD7_CFG__A, 0x0000); status = write16(state, SIO_PDR_MD7_CFG__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
} }
status = write16(state, SIO_PDR_MCLK_CFG__A, sioPdrMclkCfg); status = write16(state, SIO_PDR_MCLK_CFG__A, sioPdrMclkCfg);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_PDR_MD0_CFG__A, sioPdrMdxCfg); status = write16(state, SIO_PDR_MD0_CFG__A, sioPdrMdxCfg);
if (status < 0) if (status < 0)
break; goto error;
} }
/* Enable MB output over MPEG pads and ctl input */ /* Enable MB output over MPEG pads and ctl input */
status = write16(state, SIO_PDR_MON_CFG__A, 0x0000); status = write16(state, SIO_PDR_MON_CFG__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
/* Write nomagic word to enable pdr reg write */ /* Write nomagic word to enable pdr reg write */
status = write16(state, SIO_TOP_COMM_KEY__A, 0x0000); status = write16(state, SIO_TOP_COMM_KEY__A, 0x0000);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
...@@ -1313,36 +1342,38 @@ static int BLChainCmd(struct drxk_state *state, ...@@ -1313,36 +1342,38 @@ static int BLChainCmd(struct drxk_state *state,
unsigned long end; unsigned long end;
dprintk(1, "\n"); dprintk(1, "\n");
mutex_lock(&state->mutex); mutex_lock(&state->mutex);
do {
status = write16(state, SIO_BL_MODE__A, SIO_BL_MODE_CHAIN); status = write16(state, SIO_BL_MODE__A, SIO_BL_MODE_CHAIN);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_BL_CHAIN_ADDR__A, romOffset); status = write16(state, SIO_BL_CHAIN_ADDR__A, romOffset);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_BL_CHAIN_LEN__A, nrOfElements); status = write16(state, SIO_BL_CHAIN_LEN__A, nrOfElements);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_BL_ENABLE__A, SIO_BL_ENABLE_ON); status = write16(state, SIO_BL_ENABLE__A, SIO_BL_ENABLE_ON);
if (status < 0) if (status < 0)
break; goto error;
end = jiffies + msecs_to_jiffies(timeOut);
end = jiffies + msecs_to_jiffies(timeOut);
do { do {
msleep(1); msleep(1);
status = read16(state, SIO_BL_STATUS__A, &blStatus); status = read16(state, SIO_BL_STATUS__A, &blStatus);
if (status < 0) if (status < 0)
break; goto error;
} while ((blStatus == 0x1) && } while ((blStatus == 0x1) &&
((time_is_after_jiffies(end)))); ((time_is_after_jiffies(end))));
if (blStatus == 0x1) { if (blStatus == 0x1) {
printk(KERN_ERR "drxk: SIO not ready\n"); printk(KERN_ERR "drxk: SIO not ready\n");
mutex_unlock(&state->mutex); status = -EINVAL;
return -1; goto error2;
} }
} while (0); error:
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
error2:
mutex_unlock(&state->mutex); mutex_unlock(&state->mutex);
return status; return status;
} }
...@@ -1421,25 +1452,24 @@ static int DVBTEnableOFDMTokenRing(struct drxk_state *state, bool enable) ...@@ -1421,25 +1452,24 @@ static int DVBTEnableOFDMTokenRing(struct drxk_state *state, bool enable)
desiredStatus = SIO_OFDM_SH_OFDM_RING_STATUS_DOWN; desiredStatus = SIO_OFDM_SH_OFDM_RING_STATUS_DOWN;
} }
status = (read16(state, SIO_OFDM_SH_OFDM_RING_STATUS__A, &data)); status = read16(state, SIO_OFDM_SH_OFDM_RING_STATUS__A, &data);
if (status >= 0 && data == desiredStatus) {
if (data == desiredStatus) {
/* tokenring already has correct status */ /* tokenring already has correct status */
return status; return status;
} }
/* Disable/enable dvbt tokenring bridge */ /* Disable/enable dvbt tokenring bridge */
status = status = write16(state, SIO_OFDM_SH_OFDM_RING_ENABLE__A, desiredCtrl);
write16(state, SIO_OFDM_SH_OFDM_RING_ENABLE__A, desiredCtrl);
end = jiffies + msecs_to_jiffies(DRXK_OFDM_TR_SHUTDOWN_TIMEOUT); end = jiffies + msecs_to_jiffies(DRXK_OFDM_TR_SHUTDOWN_TIMEOUT);
do { do {
status = read16(state, SIO_OFDM_SH_OFDM_RING_STATUS__A, &data); status = read16(state, SIO_OFDM_SH_OFDM_RING_STATUS__A, &data);
if (status < 0) if ((status >= 0 && data == desiredStatus) || time_is_after_jiffies(end))
break; break;
} while ((data != desiredStatus) && ((time_is_after_jiffies(end)))); msleep(1);
} while (1);
if (data != desiredStatus) { if (data != desiredStatus) {
printk(KERN_ERR "drxk: SIO not ready\n"); printk(KERN_ERR "drxk: SIO not ready\n");
return -1; return -EINVAL;
} }
return status; return status;
} }
...@@ -1452,25 +1482,26 @@ static int MPEGTSStop(struct drxk_state *state) ...@@ -1452,25 +1482,26 @@ static int MPEGTSStop(struct drxk_state *state)
dprintk(1, "\n"); dprintk(1, "\n");
do {
/* Gracefull shutdown (byte boundaries) */ /* Gracefull shutdown (byte boundaries) */
status = read16(state, FEC_OC_SNC_MODE__A, &fecOcSncMode); status = read16(state, FEC_OC_SNC_MODE__A, &fecOcSncMode);
if (status < 0) if (status < 0)
break; goto error;
fecOcSncMode |= FEC_OC_SNC_MODE_SHUTDOWN__M; fecOcSncMode |= FEC_OC_SNC_MODE_SHUTDOWN__M;
status = write16(state, FEC_OC_SNC_MODE__A, fecOcSncMode); status = write16(state, FEC_OC_SNC_MODE__A, fecOcSncMode);
if (status < 0) if (status < 0)
break; goto error;
/* Suppress MCLK during absence of data */ /* Suppress MCLK during absence of data */
status = read16(state, FEC_OC_IPR_MODE__A, &fecOcIprMode); status = read16(state, FEC_OC_IPR_MODE__A, &fecOcIprMode);
if (status < 0) if (status < 0)
break; goto error;
fecOcIprMode |= FEC_OC_IPR_MODE_MCLK_DIS_DAT_ABS__M; fecOcIprMode |= FEC_OC_IPR_MODE_MCLK_DIS_DAT_ABS__M;
status = write16(state, FEC_OC_IPR_MODE__A, fecOcIprMode); status = write16(state, FEC_OC_IPR_MODE__A, fecOcIprMode);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
...@@ -1482,22 +1513,21 @@ static int scu_command(struct drxk_state *state, ...@@ -1482,22 +1513,21 @@ static int scu_command(struct drxk_state *state,
#error DRXK register mapping no longer compatible with this routine! #error DRXK register mapping no longer compatible with this routine!
#endif #endif
u16 curCmd = 0; u16 curCmd = 0;
int status; int status = -EINVAL;
unsigned long end; unsigned long end;
u8 buffer[34];
int cnt = 0, ii;
dprintk(1, "\n"); dprintk(1, "\n");
if ((cmd == 0) || ((parameterLen > 0) && (parameter == NULL)) || if ((cmd == 0) || ((parameterLen > 0) && (parameter == NULL)) ||
((resultLen > 0) && (result == NULL))) ((resultLen > 0) && (result == NULL)))
return -1; goto error;
mutex_lock(&state->mutex); mutex_lock(&state->mutex);
do {
/* assume that the command register is ready /* assume that the command register is ready
since it is checked afterwards */ since it is checked afterwards */
u8 buffer[34];
int cnt = 0, ii;
for (ii = parameterLen - 1; ii >= 0; ii -= 1) { for (ii = parameterLen - 1; ii >= 0; ii -= 1) {
buffer[cnt++] = (parameter[ii] & 0xFF); buffer[cnt++] = (parameter[ii] & 0xFF);
buffer[cnt++] = ((parameter[ii] >> 8) & 0xFF); buffer[cnt++] = ((parameter[ii] >> 8) & 0xFF);
...@@ -1513,13 +1543,12 @@ static int scu_command(struct drxk_state *state, ...@@ -1513,13 +1543,12 @@ static int scu_command(struct drxk_state *state,
msleep(1); msleep(1);
status = read16(state, SCU_RAM_COMMAND__A, &curCmd); status = read16(state, SCU_RAM_COMMAND__A, &curCmd);
if (status < 0) if (status < 0)
break; goto error;
} while (!(curCmd == DRX_SCU_READY) } while (!(curCmd == DRX_SCU_READY) && (time_is_after_jiffies(end)));
&& (time_is_after_jiffies(end)));
if (curCmd != DRX_SCU_READY) { if (curCmd != DRX_SCU_READY) {
printk(KERN_ERR "drxk: SCU not ready\n"); printk(KERN_ERR "drxk: SCU not ready\n");
mutex_unlock(&state->mutex); status = -EIO;
return -1; goto error2;
} }
/* read results */ /* read results */
if ((resultLen > 0) && (result != NULL)) { if ((resultLen > 0) && (result != NULL)) {
...@@ -1529,35 +1558,38 @@ static int scu_command(struct drxk_state *state, ...@@ -1529,35 +1558,38 @@ static int scu_command(struct drxk_state *state,
for (ii = resultLen - 1; ii >= 0; ii -= 1) { for (ii = resultLen - 1; ii >= 0; ii -= 1) {
status = read16(state, SCU_RAM_PARAM_0__A - ii, &result[ii]); status = read16(state, SCU_RAM_PARAM_0__A - ii, &result[ii]);
if (status < 0) if (status < 0)
break; goto error;
} }
/* Check if an error was reported by SCU */ /* Check if an error was reported by SCU */
err = (s16) result[0]; err = (s16)result[0];
/* check a few fixed error codes */ /* check a few fixed error codes */
if (err == SCU_RESULT_UNKSTD) { if (err == SCU_RESULT_UNKSTD) {
printk(KERN_ERR "drxk: SCU_RESULT_UNKSTD\n"); printk(KERN_ERR "drxk: SCU_RESULT_UNKSTD\n");
mutex_unlock(&state->mutex); status = -EINVAL;
return -1; goto error2;
} else if (err == SCU_RESULT_UNKCMD) { } else if (err == SCU_RESULT_UNKCMD) {
printk(KERN_ERR "drxk: SCU_RESULT_UNKCMD\n"); printk(KERN_ERR "drxk: SCU_RESULT_UNKCMD\n");
mutex_unlock(&state->mutex); status = -EINVAL;
return -1; goto error2;
} } else if (err < 0) {
/* here it is assumed that negative means error, /*
and positive no error */ * here it is assumed that a nagative result means
else if (err < 0) { * error, and positive no error
printk(KERN_ERR "drxk: %s ERROR\n", __func__); */
mutex_unlock(&state->mutex); printk(KERN_ERR "drxk: %s ERROR: %d\n", __func__, err);
return -1; status = -EINVAL;
goto error2;
} }
} }
} while (0);
mutex_unlock(&state->mutex); error:
if (status < 0) if (status < 0)
printk(KERN_ERR "drxk: %s: status = %d\n", __func__, status); printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
error2:
mutex_unlock(&state->mutex);
return status; return status;
} }
...@@ -1568,19 +1600,18 @@ static int SetIqmAf(struct drxk_state *state, bool active) ...@@ -1568,19 +1600,18 @@ static int SetIqmAf(struct drxk_state *state, bool active)
dprintk(1, "\n"); dprintk(1, "\n");
do {
/* Configure IQM */ /* Configure IQM */
status = read16(state, IQM_AF_STDBY__A, &data); status = read16(state, IQM_AF_STDBY__A, &data);
if (status < 0) if (status < 0)
break; goto error;
if (!active) { if (!active) {
data |= (IQM_AF_STDBY_STDBY_ADC_STANDBY data |= (IQM_AF_STDBY_STDBY_ADC_STANDBY
| IQM_AF_STDBY_STDBY_AMP_STANDBY | IQM_AF_STDBY_STDBY_AMP_STANDBY
| IQM_AF_STDBY_STDBY_PD_STANDBY | IQM_AF_STDBY_STDBY_PD_STANDBY
| IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY | IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY
| IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY); | IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY);
} else { /* active */ } else {
data &= ((~IQM_AF_STDBY_STDBY_ADC_STANDBY) data &= ((~IQM_AF_STDBY_STDBY_ADC_STANDBY)
& (~IQM_AF_STDBY_STDBY_AMP_STANDBY) & (~IQM_AF_STDBY_STDBY_AMP_STANDBY)
& (~IQM_AF_STDBY_STDBY_PD_STANDBY) & (~IQM_AF_STDBY_STDBY_PD_STANDBY)
...@@ -1589,9 +1620,10 @@ static int SetIqmAf(struct drxk_state *state, bool active) ...@@ -1589,9 +1620,10 @@ static int SetIqmAf(struct drxk_state *state, bool active)
); );
} }
status = write16(state, IQM_AF_STDBY__A, data); status = write16(state, IQM_AF_STDBY__A, data);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
...@@ -1604,7 +1636,7 @@ static int CtrlPowerMode(struct drxk_state *state, enum DRXPowerMode *mode) ...@@ -1604,7 +1636,7 @@ static int CtrlPowerMode(struct drxk_state *state, enum DRXPowerMode *mode)
/* Check arguments */ /* Check arguments */
if (mode == NULL) if (mode == NULL)
return -1; return -EINVAL;
switch (*mode) { switch (*mode) {
case DRX_POWER_UP: case DRX_POWER_UP:
...@@ -1624,7 +1656,7 @@ static int CtrlPowerMode(struct drxk_state *state, enum DRXPowerMode *mode) ...@@ -1624,7 +1656,7 @@ static int CtrlPowerMode(struct drxk_state *state, enum DRXPowerMode *mode)
break; break;
default: default:
/* Unknow sleep mode */ /* Unknow sleep mode */
return -1; return -EINVAL;
break; break;
} }
...@@ -1634,14 +1666,12 @@ static int CtrlPowerMode(struct drxk_state *state, enum DRXPowerMode *mode) ...@@ -1634,14 +1666,12 @@ static int CtrlPowerMode(struct drxk_state *state, enum DRXPowerMode *mode)
/* For next steps make sure to start from DRX_POWER_UP mode */ /* For next steps make sure to start from DRX_POWER_UP mode */
if (state->m_currentPowerMode != DRX_POWER_UP) { if (state->m_currentPowerMode != DRX_POWER_UP) {
do {
status = PowerUpDevice(state); status = PowerUpDevice(state);
if (status < 0) if (status < 0)
break; goto error;
status = DVBTEnableOFDMTokenRing(state, true); status = DVBTEnableOFDMTokenRing(state, true);
if (status < 0) if (status < 0)
break; goto error;
} while (0);
} }
if (*mode == DRX_POWER_UP) { if (*mode == DRX_POWER_UP) {
...@@ -1656,48 +1686,51 @@ static int CtrlPowerMode(struct drxk_state *state, enum DRXPowerMode *mode) ...@@ -1656,48 +1686,51 @@ static int CtrlPowerMode(struct drxk_state *state, enum DRXPowerMode *mode)
/* Power down device */ /* Power down device */
/* stop all comm_exec */ /* stop all comm_exec */
/* Stop and power down previous standard */ /* Stop and power down previous standard */
do {
switch (state->m_OperationMode) { switch (state->m_OperationMode) {
case OM_DVBT: case OM_DVBT:
status = MPEGTSStop(state); status = MPEGTSStop(state);
if (status < 0) if (status < 0)
break; goto error;
status = PowerDownDVBT(state, false); status = PowerDownDVBT(state, false);
if (status < 0) if (status < 0)
break; goto error;
break; break;
case OM_QAM_ITU_A: case OM_QAM_ITU_A:
case OM_QAM_ITU_C: case OM_QAM_ITU_C:
status = MPEGTSStop(state); status = MPEGTSStop(state);
if (status < 0) if (status < 0)
break; goto error;
status = PowerDownQAM(state); status = PowerDownQAM(state);
if (status < 0) if (status < 0)
break; goto error;
break; break;
default: default:
break; break;
} }
status = DVBTEnableOFDMTokenRing(state, false); status = DVBTEnableOFDMTokenRing(state, false);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_CC_PWD_MODE__A, sioCcPwdMode); status = write16(state, SIO_CC_PWD_MODE__A, sioCcPwdMode);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY); status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY);
if (status < 0) if (status < 0)
break; goto error;
if (*mode != DRXK_POWER_DOWN_OFDM) { if (*mode != DRXK_POWER_DOWN_OFDM) {
state->m_HICfgCtrl |= state->m_HICfgCtrl |=
SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ; SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ;
status = HI_CfgCommand(state); status = HI_CfgCommand(state);
if (status < 0) if (status < 0)
break; goto error;
} }
} while (0);
} }
state->m_currentPowerMode = *mode; state->m_currentPowerMode = *mode;
error:
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -1710,44 +1743,45 @@ static int PowerDownDVBT(struct drxk_state *state, bool setPowerMode) ...@@ -1710,44 +1743,45 @@ static int PowerDownDVBT(struct drxk_state *state, bool setPowerMode)
dprintk(1, "\n"); dprintk(1, "\n");
do {
status = read16(state, SCU_COMM_EXEC__A, &data); status = read16(state, SCU_COMM_EXEC__A, &data);
if (status < 0) if (status < 0)
break; goto error;
if (data == SCU_COMM_EXEC_ACTIVE) { if (data == SCU_COMM_EXEC_ACTIVE) {
/* Send OFDM stop command */ /* Send OFDM stop command */
status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_STOP, 0, NULL, 1, &cmdResult); status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_STOP, 0, NULL, 1, &cmdResult);
if (status < 0) if (status < 0)
break; goto error;
/* Send OFDM reset command */ /* Send OFDM reset command */
status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_RESET, 0, NULL, 1, &cmdResult); status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_RESET, 0, NULL, 1, &cmdResult);
if (status < 0) if (status < 0)
break; goto error;
} }
/* Reset datapath for OFDM, processors first */ /* Reset datapath for OFDM, processors first */
status = write16(state, OFDM_SC_COMM_EXEC__A, OFDM_SC_COMM_EXEC_STOP); status = write16(state, OFDM_SC_COMM_EXEC__A, OFDM_SC_COMM_EXEC_STOP);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, OFDM_LC_COMM_EXEC__A, OFDM_LC_COMM_EXEC_STOP); status = write16(state, OFDM_LC_COMM_EXEC__A, OFDM_LC_COMM_EXEC_STOP);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_COMM_EXEC__A, IQM_COMM_EXEC_B_STOP); status = write16(state, IQM_COMM_EXEC__A, IQM_COMM_EXEC_B_STOP);
if (status < 0) if (status < 0)
break; goto error;
/* powerdown AFE */ /* powerdown AFE */
status = SetIqmAf(state, false); status = SetIqmAf(state, false);
if (status < 0) if (status < 0)
break; goto error;
/* powerdown to OFDM mode */ /* powerdown to OFDM mode */
if (setPowerMode) { if (setPowerMode) {
status = CtrlPowerMode(state, &powerMode); status = CtrlPowerMode(state, &powerMode);
if (status < 0) if (status < 0)
break; goto error;
} }
} while (0); error:
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -1762,11 +1796,11 @@ static int SetOperationMode(struct drxk_state *state, ...@@ -1762,11 +1796,11 @@ static int SetOperationMode(struct drxk_state *state,
TODO investigate total power down instead of partial TODO investigate total power down instead of partial
power down depending on "previous" standard. power down depending on "previous" standard.
*/ */
do {
/* disable HW lock indicator */ /* disable HW lock indicator */
status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE);
if (status < 0) if (status < 0)
break; goto error;
if (state->m_OperationMode != oMode) { if (state->m_OperationMode != oMode) {
switch (state->m_OperationMode) { switch (state->m_OperationMode) {
...@@ -1776,84 +1810,73 @@ static int SetOperationMode(struct drxk_state *state, ...@@ -1776,84 +1810,73 @@ static int SetOperationMode(struct drxk_state *state,
case OM_DVBT: case OM_DVBT:
status = MPEGTSStop(state); status = MPEGTSStop(state);
if (status < 0) if (status < 0)
break; goto error;
status = PowerDownDVBT(state, true); status = PowerDownDVBT(state, true);
if (status < 0) if (status < 0)
break; goto error;
state->m_OperationMode = OM_NONE; state->m_OperationMode = OM_NONE;
break; break;
case OM_QAM_ITU_B:
status = -1;
break;
case OM_QAM_ITU_A: /* fallthrough */ case OM_QAM_ITU_A: /* fallthrough */
case OM_QAM_ITU_C: case OM_QAM_ITU_C:
status = MPEGTSStop(state); status = MPEGTSStop(state);
if (status < 0) if (status < 0)
break; goto error;
status = PowerDownQAM(state); status = PowerDownQAM(state);
if (status < 0) if (status < 0)
break; goto error;
state->m_OperationMode = OM_NONE; state->m_OperationMode = OM_NONE;
break; break;
case OM_QAM_ITU_B:
default: default:
status = -1; status = -EINVAL;
goto error;
} }
status = status;
if (status < 0)
break;
/* /*
Power up new standard Power up new standard
*/ */
switch (oMode) { switch (oMode) {
case OM_DVBT: case OM_DVBT:
state->m_OperationMode = oMode;
status = SetDVBTStandard(state, oMode); status = SetDVBTStandard(state, oMode);
if (status < 0) if (status < 0)
break; goto error;
break; state->m_OperationMode = oMode;
case OM_QAM_ITU_B:
status = -1;
break; break;
case OM_QAM_ITU_A: /* fallthrough */ case OM_QAM_ITU_A: /* fallthrough */
case OM_QAM_ITU_C: case OM_QAM_ITU_C:
state->m_OperationMode = oMode;
status = SetQAMStandard(state, oMode); status = SetQAMStandard(state, oMode);
if (status < 0) if (status < 0)
goto error;
state->m_OperationMode = oMode;
break; break;
break; case OM_QAM_ITU_B:
default: default:
status = -1; status = -EINVAL;
} }
} }
status = status; error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0); return status;
return 0;
} }
static int Start(struct drxk_state *state, s32 offsetFreq, static int Start(struct drxk_state *state, s32 offsetFreq,
s32 IntermediateFrequency) s32 IntermediateFrequency)
{ {
int status = 0; int status = -EINVAL;
dprintk(1, "\n");
do {
u16 IFreqkHz; u16 IFreqkHz;
s32 OffsetkHz = offsetFreq / 1000; s32 OffsetkHz = offsetFreq / 1000;
dprintk(1, "\n");
if (state->m_DrxkState != DRXK_STOPPED && if (state->m_DrxkState != DRXK_STOPPED &&
state->m_DrxkState != DRXK_DTV_STARTED) { state->m_DrxkState != DRXK_DTV_STARTED)
status = -1; goto error;
break;
} state->m_bMirrorFreqSpect = (state->param.inversion == INVERSION_ON);
state->m_bMirrorFreqSpect =
(state->param.inversion == INVERSION_ON);
if (IntermediateFrequency < 0) { if (IntermediateFrequency < 0) {
state->m_bMirrorFreqSpect = state->m_bMirrorFreqSpect = !state->m_bMirrorFreqSpect;
!state->m_bMirrorFreqSpect;
IntermediateFrequency = -IntermediateFrequency; IntermediateFrequency = -IntermediateFrequency;
} }
...@@ -1863,26 +1886,28 @@ static int Start(struct drxk_state *state, s32 offsetFreq, ...@@ -1863,26 +1886,28 @@ static int Start(struct drxk_state *state, s32 offsetFreq,
IFreqkHz = (IntermediateFrequency / 1000); IFreqkHz = (IntermediateFrequency / 1000);
status = SetQAM(state, IFreqkHz, OffsetkHz); status = SetQAM(state, IFreqkHz, OffsetkHz);
if (status < 0) if (status < 0)
break; goto error;
state->m_DrxkState = DRXK_DTV_STARTED; state->m_DrxkState = DRXK_DTV_STARTED;
break; break;
case OM_DVBT: case OM_DVBT:
IFreqkHz = (IntermediateFrequency / 1000); IFreqkHz = (IntermediateFrequency / 1000);
status = MPEGTSStop(state); status = MPEGTSStop(state);
if (status < 0) if (status < 0)
break; goto error;
status = SetDVBT(state, IFreqkHz, OffsetkHz); status = SetDVBT(state, IFreqkHz, OffsetkHz);
if (status < 0) if (status < 0)
break; goto error;
status = DVBTStart(state); status = DVBTStart(state);
if (status < 0) if (status < 0)
break; goto error;
state->m_DrxkState = DRXK_DTV_STARTED; state->m_DrxkState = DRXK_DTV_STARTED;
break; break;
default: default:
break; break;
} }
} while (0); error:
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -1897,12 +1922,12 @@ static int ShutDown(struct drxk_state *state) ...@@ -1897,12 +1922,12 @@ static int ShutDown(struct drxk_state *state)
static int GetLockStatus(struct drxk_state *state, u32 *pLockStatus, static int GetLockStatus(struct drxk_state *state, u32 *pLockStatus,
u32 Time) u32 Time)
{ {
int status = 0; int status = -EINVAL;
dprintk(1, "\n"); dprintk(1, "\n");
if (pLockStatus == NULL) if (pLockStatus == NULL)
return -1; goto error;
*pLockStatus = NOT_LOCKED; *pLockStatus = NOT_LOCKED;
...@@ -1919,82 +1944,84 @@ static int GetLockStatus(struct drxk_state *state, u32 *pLockStatus, ...@@ -1919,82 +1944,84 @@ static int GetLockStatus(struct drxk_state *state, u32 *pLockStatus,
default: default:
break; break;
} }
error:
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
static int MPEGTSStart(struct drxk_state *state) static int MPEGTSStart(struct drxk_state *state)
{ {
int status = 0; int status;
u16 fecOcSncMode = 0; u16 fecOcSncMode = 0;
do {
/* Allow OC to sync again */ /* Allow OC to sync again */
status = read16(state, FEC_OC_SNC_MODE__A, &fecOcSncMode); status = read16(state, FEC_OC_SNC_MODE__A, &fecOcSncMode);
if (status < 0) if (status < 0)
break; goto error;
fecOcSncMode &= ~FEC_OC_SNC_MODE_SHUTDOWN__M; fecOcSncMode &= ~FEC_OC_SNC_MODE_SHUTDOWN__M;
status = write16(state, FEC_OC_SNC_MODE__A, fecOcSncMode); status = write16(state, FEC_OC_SNC_MODE__A, fecOcSncMode);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_OC_SNC_UNLOCK__A, 1); status = write16(state, FEC_OC_SNC_UNLOCK__A, 1);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
static int MPEGTSDtoInit(struct drxk_state *state) static int MPEGTSDtoInit(struct drxk_state *state)
{ {
int status = -1; int status;
dprintk(1, "\n"); dprintk(1, "\n");
do {
/* Rate integration settings */ /* Rate integration settings */
status = write16(state, FEC_OC_RCN_CTL_STEP_LO__A, 0x0000); status = write16(state, FEC_OC_RCN_CTL_STEP_LO__A, 0x0000);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_OC_RCN_CTL_STEP_HI__A, 0x000C); status = write16(state, FEC_OC_RCN_CTL_STEP_HI__A, 0x000C);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_OC_RCN_GAIN__A, 0x000A); status = write16(state, FEC_OC_RCN_GAIN__A, 0x000A);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_OC_AVR_PARM_A__A, 0x0008); status = write16(state, FEC_OC_AVR_PARM_A__A, 0x0008);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_OC_AVR_PARM_B__A, 0x0006); status = write16(state, FEC_OC_AVR_PARM_B__A, 0x0006);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_OC_TMD_HI_MARGIN__A, 0x0680); status = write16(state, FEC_OC_TMD_HI_MARGIN__A, 0x0680);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_OC_TMD_LO_MARGIN__A, 0x0080); status = write16(state, FEC_OC_TMD_LO_MARGIN__A, 0x0080);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_OC_TMD_COUNT__A, 0x03F4); status = write16(state, FEC_OC_TMD_COUNT__A, 0x03F4);
if (status < 0) if (status < 0)
break; goto error;
/* Additional configuration */ /* Additional configuration */
status = write16(state, FEC_OC_OCR_INVERT__A, 0); status = write16(state, FEC_OC_OCR_INVERT__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_OC_SNC_LWM__A, 2); status = write16(state, FEC_OC_SNC_LWM__A, 2);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_OC_SNC_HWM__A, 12); status = write16(state, FEC_OC_SNC_HWM__A, 12);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
static int MPEGTSDtoSetup(struct drxk_state *state, static int MPEGTSDtoSetup(struct drxk_state *state,
enum OperationMode oMode) enum OperationMode oMode)
{ {
int status = -1; int status;
u16 fecOcRegMode = 0; /* FEC_OC_MODE register value */ u16 fecOcRegMode = 0; /* FEC_OC_MODE register value */
u16 fecOcRegIprMode = 0; /* FEC_OC_IPR_MODE register value */ u16 fecOcRegIprMode = 0; /* FEC_OC_IPR_MODE register value */
...@@ -2010,14 +2037,13 @@ static int MPEGTSDtoSetup(struct drxk_state *state, ...@@ -2010,14 +2037,13 @@ static int MPEGTSDtoSetup(struct drxk_state *state,
dprintk(1, "\n"); dprintk(1, "\n");
do {
/* Check insertion of the Reed-Solomon parity bytes */ /* Check insertion of the Reed-Solomon parity bytes */
status = read16(state, FEC_OC_MODE__A, &fecOcRegMode); status = read16(state, FEC_OC_MODE__A, &fecOcRegMode);
if (status < 0) if (status < 0)
break; goto error;
status = read16(state, FEC_OC_IPR_MODE__A, &fecOcRegIprMode); status = read16(state, FEC_OC_IPR_MODE__A, &fecOcRegIprMode);
if (status < 0) if (status < 0)
break; goto error;
fecOcRegMode &= (~FEC_OC_MODE_PARITY__M); fecOcRegMode &= (~FEC_OC_MODE_PARITY__M);
fecOcRegIprMode &= (~FEC_OC_IPR_MODE_MVAL_DIS_PAR__M); fecOcRegIprMode &= (~FEC_OC_IPR_MODE_MVAL_DIS_PAR__M);
if (state->m_insertRSByte == true) { if (state->m_insertRSByte == true) {
...@@ -2051,11 +2077,10 @@ static int MPEGTSDtoSetup(struct drxk_state *state, ...@@ -2051,11 +2077,10 @@ static int MPEGTSDtoSetup(struct drxk_state *state,
staticCLK = state->m_DVBCStaticCLK; staticCLK = state->m_DVBCStaticCLK;
break; break;
default: default:
status = -1; status = -EINVAL;
} /* switch (standard) */ } /* switch (standard) */
status = status;
if (status < 0) if (status < 0)
break; goto error;
/* Configure DTO's */ /* Configure DTO's */
if (staticCLK) { if (staticCLK) {
...@@ -2098,44 +2123,41 @@ static int MPEGTSDtoSetup(struct drxk_state *state, ...@@ -2098,44 +2123,41 @@ static int MPEGTSDtoSetup(struct drxk_state *state,
/* Write appropriate registers with requested configuration */ /* Write appropriate registers with requested configuration */
status = write16(state, FEC_OC_DTO_BURST_LEN__A, fecOcDtoBurstLen); status = write16(state, FEC_OC_DTO_BURST_LEN__A, fecOcDtoBurstLen);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_OC_DTO_PERIOD__A, fecOcDtoPeriod); status = write16(state, FEC_OC_DTO_PERIOD__A, fecOcDtoPeriod);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_OC_DTO_MODE__A, fecOcDtoMode); status = write16(state, FEC_OC_DTO_MODE__A, fecOcDtoMode);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_OC_FCT_MODE__A, fecOcFctMode); status = write16(state, FEC_OC_FCT_MODE__A, fecOcFctMode);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_OC_MODE__A, fecOcRegMode); status = write16(state, FEC_OC_MODE__A, fecOcRegMode);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_OC_IPR_MODE__A, fecOcRegIprMode); status = write16(state, FEC_OC_IPR_MODE__A, fecOcRegIprMode);
if (status < 0) if (status < 0)
break; goto error;
/* Rate integration settings */ /* Rate integration settings */
status = write32(state, FEC_OC_RCN_CTL_RATE_LO__A, fecOcRcnCtlRate); status = write32(state, FEC_OC_RCN_CTL_RATE_LO__A, fecOcRcnCtlRate);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_OC_TMD_INT_UPD_RATE__A, fecOcTmdIntUpdRate); status = write16(state, FEC_OC_TMD_INT_UPD_RATE__A, fecOcTmdIntUpdRate);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_OC_TMD_MODE__A, fecOcTmdMode); status = write16(state, FEC_OC_TMD_MODE__A, fecOcTmdMode);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
static int MPEGTSConfigurePolarity(struct drxk_state *state) static int MPEGTSConfigurePolarity(struct drxk_state *state)
{ {
int status;
u16 fecOcRegIprInvert = 0; u16 fecOcRegIprInvert = 0;
dprintk(1, "\n");
/* Data mask for the output data byte */ /* Data mask for the output data byte */
u16 InvertDataMask = u16 InvertDataMask =
FEC_OC_IPR_INVERT_MD7__M | FEC_OC_IPR_INVERT_MD6__M | FEC_OC_IPR_INVERT_MD7__M | FEC_OC_IPR_INVERT_MD6__M |
...@@ -2143,6 +2165,8 @@ static int MPEGTSConfigurePolarity(struct drxk_state *state) ...@@ -2143,6 +2165,8 @@ static int MPEGTSConfigurePolarity(struct drxk_state *state)
FEC_OC_IPR_INVERT_MD3__M | FEC_OC_IPR_INVERT_MD2__M | FEC_OC_IPR_INVERT_MD3__M | FEC_OC_IPR_INVERT_MD2__M |
FEC_OC_IPR_INVERT_MD1__M | FEC_OC_IPR_INVERT_MD0__M; FEC_OC_IPR_INVERT_MD1__M | FEC_OC_IPR_INVERT_MD0__M;
dprintk(1, "\n");
/* Control selective inversion of output bits */ /* Control selective inversion of output bits */
fecOcRegIprInvert &= (~(InvertDataMask)); fecOcRegIprInvert &= (~(InvertDataMask));
if (state->m_invertDATA == true) if (state->m_invertDATA == true)
...@@ -2159,8 +2183,8 @@ static int MPEGTSConfigurePolarity(struct drxk_state *state) ...@@ -2159,8 +2183,8 @@ static int MPEGTSConfigurePolarity(struct drxk_state *state)
fecOcRegIprInvert &= (~(FEC_OC_IPR_INVERT_MCLK__M)); fecOcRegIprInvert &= (~(FEC_OC_IPR_INVERT_MCLK__M));
if (state->m_invertCLK == true) if (state->m_invertCLK == true)
fecOcRegIprInvert |= FEC_OC_IPR_INVERT_MCLK__M; fecOcRegIprInvert |= FEC_OC_IPR_INVERT_MCLK__M;
status = write16(state, FEC_OC_IPR_INVERT__A, fecOcRegIprInvert);
return status; return write16(state, FEC_OC_IPR_INVERT__A, fecOcRegIprInvert);
} }
#define SCU_RAM_AGC_KI_INV_RF_POL__M 0x4000 #define SCU_RAM_AGC_KI_INV_RF_POL__M 0x4000
...@@ -2168,32 +2192,28 @@ static int MPEGTSConfigurePolarity(struct drxk_state *state) ...@@ -2168,32 +2192,28 @@ static int MPEGTSConfigurePolarity(struct drxk_state *state)
static int SetAgcRf(struct drxk_state *state, static int SetAgcRf(struct drxk_state *state,
struct SCfgAgc *pAgcCfg, bool isDTV) struct SCfgAgc *pAgcCfg, bool isDTV)
{ {
int status = 0; int status = -EINVAL;
u16 data = 0;
struct SCfgAgc *pIfAgcSettings; struct SCfgAgc *pIfAgcSettings;
dprintk(1, "\n"); dprintk(1, "\n");
if (pAgcCfg == NULL) if (pAgcCfg == NULL)
return -1; goto error;
do {
u16 data = 0;
switch (pAgcCfg->ctrlMode) { switch (pAgcCfg->ctrlMode) {
case DRXK_AGC_CTRL_AUTO: case DRXK_AGC_CTRL_AUTO:
/* Enable RF AGC DAC */ /* Enable RF AGC DAC */
status = read16(state, IQM_AF_STDBY__A, &data); status = read16(state, IQM_AF_STDBY__A, &data);
if (status < 0) if (status < 0)
break; goto error;
data &= ~IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY; data &= ~IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY;
status = write16(state, IQM_AF_STDBY__A, data); status = write16(state, IQM_AF_STDBY__A, data);
if (status < 0) if (status < 0)
break; goto error;
status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); status = read16(state, SCU_RAM_AGC_CONFIG__A, &data);
if (status < 0) if (status < 0)
break; goto error;
/* Enable SCU RF AGC loop */ /* Enable SCU RF AGC loop */
data &= ~SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M; data &= ~SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M;
...@@ -2205,12 +2225,12 @@ static int SetAgcRf(struct drxk_state *state, ...@@ -2205,12 +2225,12 @@ static int SetAgcRf(struct drxk_state *state,
data &= ~SCU_RAM_AGC_CONFIG_INV_RF_POL__M; data &= ~SCU_RAM_AGC_CONFIG_INV_RF_POL__M;
status = write16(state, SCU_RAM_AGC_CONFIG__A, data); status = write16(state, SCU_RAM_AGC_CONFIG__A, data);
if (status < 0) if (status < 0)
break; goto error;
/* Set speed (using complementary reduction value) */ /* Set speed (using complementary reduction value) */
status = read16(state, SCU_RAM_AGC_KI_RED__A, &data); status = read16(state, SCU_RAM_AGC_KI_RED__A, &data);
if (status < 0) if (status < 0)
break; goto error;
data &= ~SCU_RAM_AGC_KI_RED_RAGC_RED__M; data &= ~SCU_RAM_AGC_KI_RED_RAGC_RED__M;
data |= (~(pAgcCfg->speed << data |= (~(pAgcCfg->speed <<
...@@ -2219,7 +2239,7 @@ static int SetAgcRf(struct drxk_state *state, ...@@ -2219,7 +2239,7 @@ static int SetAgcRf(struct drxk_state *state,
status = write16(state, SCU_RAM_AGC_KI_RED__A, data); status = write16(state, SCU_RAM_AGC_KI_RED__A, data);
if (status < 0) if (status < 0)
break; goto error;
if (IsDVBT(state)) if (IsDVBT(state))
pIfAgcSettings = &state->m_dvbtIfAgcCfg; pIfAgcSettings = &state->m_dvbtIfAgcCfg;
...@@ -2227,24 +2247,26 @@ static int SetAgcRf(struct drxk_state *state, ...@@ -2227,24 +2247,26 @@ static int SetAgcRf(struct drxk_state *state,
pIfAgcSettings = &state->m_qamIfAgcCfg; pIfAgcSettings = &state->m_qamIfAgcCfg;
else else
pIfAgcSettings = &state->m_atvIfAgcCfg; pIfAgcSettings = &state->m_atvIfAgcCfg;
if (pIfAgcSettings == NULL) if (pIfAgcSettings == NULL) {
return -1; status = -EINVAL;
goto error;
}
/* Set TOP, only if IF-AGC is in AUTO mode */ /* Set TOP, only if IF-AGC is in AUTO mode */
if (pIfAgcSettings->ctrlMode == DRXK_AGC_CTRL_AUTO) if (pIfAgcSettings->ctrlMode == DRXK_AGC_CTRL_AUTO)
status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, pAgcCfg->top); status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, pAgcCfg->top);
if (status < 0) if (status < 0)
break; goto error;
/* Cut-Off current */ /* Cut-Off current */
status = write16(state, SCU_RAM_AGC_RF_IACCU_HI_CO__A, pAgcCfg->cutOffCurrent); status = write16(state, SCU_RAM_AGC_RF_IACCU_HI_CO__A, pAgcCfg->cutOffCurrent);
if (status < 0) if (status < 0)
break; goto error;
/* Max. output level */ /* Max. output level */
status = write16(state, SCU_RAM_AGC_RF_MAX__A, pAgcCfg->maxOutputLevel); status = write16(state, SCU_RAM_AGC_RF_MAX__A, pAgcCfg->maxOutputLevel);
if (status < 0) if (status < 0)
break; goto error;
break; break;
...@@ -2252,16 +2274,16 @@ static int SetAgcRf(struct drxk_state *state, ...@@ -2252,16 +2274,16 @@ static int SetAgcRf(struct drxk_state *state,
/* Enable RF AGC DAC */ /* Enable RF AGC DAC */
status = read16(state, IQM_AF_STDBY__A, &data); status = read16(state, IQM_AF_STDBY__A, &data);
if (status < 0) if (status < 0)
break; goto error;
data &= ~IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY; data &= ~IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY;
status = write16(state, IQM_AF_STDBY__A, data); status = write16(state, IQM_AF_STDBY__A, data);
if (status < 0) if (status < 0)
break; goto error;
/* Disable SCU RF AGC loop */ /* Disable SCU RF AGC loop */
status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); status = read16(state, SCU_RAM_AGC_CONFIG__A, &data);
if (status < 0) if (status < 0)
break; goto error;
data |= SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M; data |= SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M;
if (state->m_RfAgcPol) if (state->m_RfAgcPol)
data |= SCU_RAM_AGC_CONFIG_INV_RF_POL__M; data |= SCU_RAM_AGC_CONFIG_INV_RF_POL__M;
...@@ -2269,44 +2291,46 @@ static int SetAgcRf(struct drxk_state *state, ...@@ -2269,44 +2291,46 @@ static int SetAgcRf(struct drxk_state *state,
data &= ~SCU_RAM_AGC_CONFIG_INV_RF_POL__M; data &= ~SCU_RAM_AGC_CONFIG_INV_RF_POL__M;
status = write16(state, SCU_RAM_AGC_CONFIG__A, data); status = write16(state, SCU_RAM_AGC_CONFIG__A, data);
if (status < 0) if (status < 0)
break; goto error;
/* SCU c.o.c. to 0, enabling full control range */ /* SCU c.o.c. to 0, enabling full control range */
status = write16(state, SCU_RAM_AGC_RF_IACCU_HI_CO__A, 0); status = write16(state, SCU_RAM_AGC_RF_IACCU_HI_CO__A, 0);
if (status < 0) if (status < 0)
break; goto error;
/* Write value to output pin */ /* Write value to output pin */
status = write16(state, SCU_RAM_AGC_RF_IACCU_HI__A, pAgcCfg->outputLevel); status = write16(state, SCU_RAM_AGC_RF_IACCU_HI__A, pAgcCfg->outputLevel);
if (status < 0) if (status < 0)
break; goto error;
break; break;
case DRXK_AGC_CTRL_OFF: case DRXK_AGC_CTRL_OFF:
/* Disable RF AGC DAC */ /* Disable RF AGC DAC */
status = read16(state, IQM_AF_STDBY__A, &data); status = read16(state, IQM_AF_STDBY__A, &data);
if (status < 0) if (status < 0)
break; goto error;
data |= IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY; data |= IQM_AF_STDBY_STDBY_TAGC_RF_STANDBY;
status = write16(state, IQM_AF_STDBY__A, data); status = write16(state, IQM_AF_STDBY__A, data);
if (status < 0) if (status < 0)
break; goto error;
/* Disable SCU RF AGC loop */ /* Disable SCU RF AGC loop */
status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); status = read16(state, SCU_RAM_AGC_CONFIG__A, &data);
if (status < 0) if (status < 0)
break; goto error;
data |= SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M; data |= SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M;
status = write16(state, SCU_RAM_AGC_CONFIG__A, data); status = write16(state, SCU_RAM_AGC_CONFIG__A, data);
if (status < 0) if (status < 0)
break; goto error;
break; break;
default: default:
return -1; status = -EINVAL;
} /* switch (agcsettings->ctrlMode) */ }
} while (0); error:
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -2321,22 +2345,21 @@ static int SetAgcIf(struct drxk_state *state, ...@@ -2321,22 +2345,21 @@ static int SetAgcIf(struct drxk_state *state,
dprintk(1, "\n"); dprintk(1, "\n");
do {
switch (pAgcCfg->ctrlMode) { switch (pAgcCfg->ctrlMode) {
case DRXK_AGC_CTRL_AUTO: case DRXK_AGC_CTRL_AUTO:
/* Enable IF AGC DAC */ /* Enable IF AGC DAC */
status = read16(state, IQM_AF_STDBY__A, &data); status = read16(state, IQM_AF_STDBY__A, &data);
if (status < 0) if (status < 0)
break; goto error;
data &= ~IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY; data &= ~IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY;
status = write16(state, IQM_AF_STDBY__A, data); status = write16(state, IQM_AF_STDBY__A, data);
if (status < 0) if (status < 0)
break; goto error;
status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); status = read16(state, SCU_RAM_AGC_CONFIG__A, &data);
if (status < 0) if (status < 0)
break; goto error;
/* Enable SCU IF AGC loop */ /* Enable SCU IF AGC loop */
data &= ~SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M; data &= ~SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M;
...@@ -2348,12 +2371,12 @@ static int SetAgcIf(struct drxk_state *state, ...@@ -2348,12 +2371,12 @@ static int SetAgcIf(struct drxk_state *state,
data &= ~SCU_RAM_AGC_CONFIG_INV_IF_POL__M; data &= ~SCU_RAM_AGC_CONFIG_INV_IF_POL__M;
status = write16(state, SCU_RAM_AGC_CONFIG__A, data); status = write16(state, SCU_RAM_AGC_CONFIG__A, data);
if (status < 0) if (status < 0)
break; goto error;
/* Set speed (using complementary reduction value) */ /* Set speed (using complementary reduction value) */
status = read16(state, SCU_RAM_AGC_KI_RED__A, &data); status = read16(state, SCU_RAM_AGC_KI_RED__A, &data);
if (status < 0) if (status < 0)
break; goto error;
data &= ~SCU_RAM_AGC_KI_RED_IAGC_RED__M; data &= ~SCU_RAM_AGC_KI_RED_IAGC_RED__M;
data |= (~(pAgcCfg->speed << data |= (~(pAgcCfg->speed <<
SCU_RAM_AGC_KI_RED_IAGC_RED__B) SCU_RAM_AGC_KI_RED_IAGC_RED__B)
...@@ -2361,7 +2384,7 @@ static int SetAgcIf(struct drxk_state *state, ...@@ -2361,7 +2384,7 @@ static int SetAgcIf(struct drxk_state *state,
status = write16(state, SCU_RAM_AGC_KI_RED__A, data); status = write16(state, SCU_RAM_AGC_KI_RED__A, data);
if (status < 0) if (status < 0)
break; goto error;
if (IsQAM(state)) if (IsQAM(state))
pRfAgcSettings = &state->m_qamRfAgcCfg; pRfAgcSettings = &state->m_qamRfAgcCfg;
...@@ -2372,7 +2395,7 @@ static int SetAgcIf(struct drxk_state *state, ...@@ -2372,7 +2395,7 @@ static int SetAgcIf(struct drxk_state *state,
/* Restore TOP */ /* Restore TOP */
status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, pRfAgcSettings->top); status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, pRfAgcSettings->top);
if (status < 0) if (status < 0)
break; goto error;
break; break;
case DRXK_AGC_CTRL_USER: case DRXK_AGC_CTRL_USER:
...@@ -2380,15 +2403,15 @@ static int SetAgcIf(struct drxk_state *state, ...@@ -2380,15 +2403,15 @@ static int SetAgcIf(struct drxk_state *state,
/* Enable IF AGC DAC */ /* Enable IF AGC DAC */
status = read16(state, IQM_AF_STDBY__A, &data); status = read16(state, IQM_AF_STDBY__A, &data);
if (status < 0) if (status < 0)
break; goto error;
data &= ~IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY; data &= ~IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY;
status = write16(state, IQM_AF_STDBY__A, data); status = write16(state, IQM_AF_STDBY__A, data);
if (status < 0) if (status < 0)
break; goto error;
status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); status = read16(state, SCU_RAM_AGC_CONFIG__A, &data);
if (status < 0) if (status < 0)
break; goto error;
/* Disable SCU IF AGC loop */ /* Disable SCU IF AGC loop */
data |= SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M; data |= SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M;
...@@ -2400,12 +2423,12 @@ static int SetAgcIf(struct drxk_state *state, ...@@ -2400,12 +2423,12 @@ static int SetAgcIf(struct drxk_state *state,
data &= ~SCU_RAM_AGC_CONFIG_INV_IF_POL__M; data &= ~SCU_RAM_AGC_CONFIG_INV_IF_POL__M;
status = write16(state, SCU_RAM_AGC_CONFIG__A, data); status = write16(state, SCU_RAM_AGC_CONFIG__A, data);
if (status < 0) if (status < 0)
break; goto error;
/* Write value to output pin */ /* Write value to output pin */
status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, pAgcCfg->outputLevel); status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, pAgcCfg->outputLevel);
if (status < 0) if (status < 0)
break; goto error;
break; break;
case DRXK_AGC_CTRL_OFF: case DRXK_AGC_CTRL_OFF:
...@@ -2413,52 +2436,55 @@ static int SetAgcIf(struct drxk_state *state, ...@@ -2413,52 +2436,55 @@ static int SetAgcIf(struct drxk_state *state,
/* Disable If AGC DAC */ /* Disable If AGC DAC */
status = read16(state, IQM_AF_STDBY__A, &data); status = read16(state, IQM_AF_STDBY__A, &data);
if (status < 0) if (status < 0)
break; goto error;
data |= IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY; data |= IQM_AF_STDBY_STDBY_TAGC_IF_STANDBY;
status = write16(state, IQM_AF_STDBY__A, data); status = write16(state, IQM_AF_STDBY__A, data);
if (status < 0) if (status < 0)
break; goto error;
/* Disable SCU IF AGC loop */ /* Disable SCU IF AGC loop */
status = read16(state, SCU_RAM_AGC_CONFIG__A, &data); status = read16(state, SCU_RAM_AGC_CONFIG__A, &data);
if (status < 0) if (status < 0)
break; goto error;
data |= SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M; data |= SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M;
status = write16(state, SCU_RAM_AGC_CONFIG__A, data); status = write16(state, SCU_RAM_AGC_CONFIG__A, data);
if (status < 0) if (status < 0)
break; goto error;
break; break;
} /* switch (agcSettingsIf->ctrlMode) */ } /* switch (agcSettingsIf->ctrlMode) */
/* always set the top to support /* always set the top to support
configurations without if-loop */ configurations without if-loop */
status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MIN__A, pAgcCfg->top); status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MIN__A, pAgcCfg->top);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
static int ReadIFAgc(struct drxk_state *state, u32 *pValue) static int ReadIFAgc(struct drxk_state *state, u32 *pValue)
{ {
u16 agcDacLvl; u16 agcDacLvl;
int status = read16(state, IQM_AF_AGC_IF__A, &agcDacLvl); int status;
u16 Level = 0;
dprintk(1, "\n"); dprintk(1, "\n");
status = read16(state, IQM_AF_AGC_IF__A, &agcDacLvl);
if (status < 0) {
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status;
}
*pValue = 0; *pValue = 0;
if (status == 0) {
u16 Level = 0;
if (agcDacLvl > DRXK_AGC_DAC_OFFSET) if (agcDacLvl > DRXK_AGC_DAC_OFFSET)
Level = agcDacLvl - DRXK_AGC_DAC_OFFSET; Level = agcDacLvl - DRXK_AGC_DAC_OFFSET;
if (Level < 14000) if (Level < 14000)
*pValue = (14000 - Level) / 4; *pValue = (14000 - Level) / 4;
else else
*pValue = 0; *pValue = 0;
}
return status; return status;
} }
...@@ -2466,21 +2492,22 @@ static int GetQAMSignalToNoise(struct drxk_state *state, ...@@ -2466,21 +2492,22 @@ static int GetQAMSignalToNoise(struct drxk_state *state,
s32 *pSignalToNoise) s32 *pSignalToNoise)
{ {
int status = 0; int status = 0;
dprintk(1, "\n");
do {
/* MER calculation */
u16 qamSlErrPower = 0; /* accum. error between u16 qamSlErrPower = 0; /* accum. error between
raw and sliced symbols */ raw and sliced symbols */
u32 qamSlSigPower = 0; /* used for MER, depends of u32 qamSlSigPower = 0; /* used for MER, depends of
QAM constellation */ QAM constellation */
u32 qamSlMer = 0; /* QAM MER */ u32 qamSlMer = 0; /* QAM MER */
dprintk(1, "\n");
/* MER calculation */
/* get the register value needed for MER */ /* get the register value needed for MER */
status = read16(state, QAM_SL_ERR_POWER__A, &qamSlErrPower); status = read16(state, QAM_SL_ERR_POWER__A, &qamSlErrPower);
if (status < 0) if (status < 0) {
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return -EINVAL;
}
switch (state->param.u.qam.modulation) { switch (state->param.u.qam.modulation) {
case QAM_16: case QAM_16:
...@@ -2506,15 +2533,14 @@ static int GetQAMSignalToNoise(struct drxk_state *state, ...@@ -2506,15 +2533,14 @@ static int GetQAMSignalToNoise(struct drxk_state *state,
Log10Times100((u32) qamSlErrPower); Log10Times100((u32) qamSlErrPower);
} }
*pSignalToNoise = qamSlMer; *pSignalToNoise = qamSlMer;
} while (0);
return status; return status;
} }
static int GetDVBTSignalToNoise(struct drxk_state *state, static int GetDVBTSignalToNoise(struct drxk_state *state,
s32 *pSignalToNoise) s32 *pSignalToNoise)
{ {
int status = 0; int status;
u16 regData = 0; u16 regData = 0;
u32 EqRegTdSqrErrI = 0; u32 EqRegTdSqrErrI = 0;
u32 EqRegTdSqrErrQ = 0; u32 EqRegTdSqrErrQ = 0;
...@@ -2530,19 +2556,19 @@ static int GetDVBTSignalToNoise(struct drxk_state *state, ...@@ -2530,19 +2556,19 @@ static int GetDVBTSignalToNoise(struct drxk_state *state,
u16 transmissionParams = 0; u16 transmissionParams = 0;
dprintk(1, "\n"); dprintk(1, "\n");
do {
status = read16(state, OFDM_EQ_TOP_TD_TPS_PWR_OFS__A, &EqRegTdTpsPwrOfs); status = read16(state, OFDM_EQ_TOP_TD_TPS_PWR_OFS__A, &EqRegTdTpsPwrOfs);
if (status < 0) if (status < 0)
break; goto error;
status = read16(state, OFDM_EQ_TOP_TD_REQ_SMB_CNT__A, &EqRegTdReqSmbCnt); status = read16(state, OFDM_EQ_TOP_TD_REQ_SMB_CNT__A, &EqRegTdReqSmbCnt);
if (status < 0) if (status < 0)
break; goto error;
status = read16(state, OFDM_EQ_TOP_TD_SQR_ERR_EXP__A, &EqRegTdSqrErrExp); status = read16(state, OFDM_EQ_TOP_TD_SQR_ERR_EXP__A, &EqRegTdSqrErrExp);
if (status < 0) if (status < 0)
break; goto error;
status = read16(state, OFDM_EQ_TOP_TD_SQR_ERR_I__A, &regData); status = read16(state, OFDM_EQ_TOP_TD_SQR_ERR_I__A, &regData);
if (status < 0) if (status < 0)
break; goto error;
/* Extend SQR_ERR_I operational range */ /* Extend SQR_ERR_I operational range */
EqRegTdSqrErrI = (u32) regData; EqRegTdSqrErrI = (u32) regData;
if ((EqRegTdSqrErrExp > 11) && if ((EqRegTdSqrErrExp > 11) &&
...@@ -2551,7 +2577,7 @@ static int GetDVBTSignalToNoise(struct drxk_state *state, ...@@ -2551,7 +2577,7 @@ static int GetDVBTSignalToNoise(struct drxk_state *state,
} }
status = read16(state, OFDM_EQ_TOP_TD_SQR_ERR_Q__A, &regData); status = read16(state, OFDM_EQ_TOP_TD_SQR_ERR_Q__A, &regData);
if (status < 0) if (status < 0)
break; goto error;
/* Extend SQR_ERR_Q operational range */ /* Extend SQR_ERR_Q operational range */
EqRegTdSqrErrQ = (u32) regData; EqRegTdSqrErrQ = (u32) regData;
if ((EqRegTdSqrErrExp > 11) && if ((EqRegTdSqrErrExp > 11) &&
...@@ -2560,7 +2586,7 @@ static int GetDVBTSignalToNoise(struct drxk_state *state, ...@@ -2560,7 +2586,7 @@ static int GetDVBTSignalToNoise(struct drxk_state *state,
status = read16(state, OFDM_SC_RA_RAM_OP_PARAM__A, &transmissionParams); status = read16(state, OFDM_SC_RA_RAM_OP_PARAM__A, &transmissionParams);
if (status < 0) if (status < 0)
break; goto error;
/* Check input data for MER */ /* Check input data for MER */
...@@ -2608,8 +2634,10 @@ static int GetDVBTSignalToNoise(struct drxk_state *state, ...@@ -2608,8 +2634,10 @@ static int GetDVBTSignalToNoise(struct drxk_state *state,
iMER = 0; iMER = 0;
} }
*pSignalToNoise = iMER; *pSignalToNoise = iMER;
} while (0);
error:
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -2775,50 +2803,54 @@ static int GetQuality(struct drxk_state *state, s32 *pQuality) ...@@ -2775,50 +2803,54 @@ static int GetQuality(struct drxk_state *state, s32 *pQuality)
static int ConfigureI2CBridge(struct drxk_state *state, bool bEnableBridge) static int ConfigureI2CBridge(struct drxk_state *state, bool bEnableBridge)
{ {
int status; int status = -EINVAL;
dprintk(1, "\n"); dprintk(1, "\n");
if (state->m_DrxkState == DRXK_UNINITIALIZED) if (state->m_DrxkState == DRXK_UNINITIALIZED)
return -1; goto error;
if (state->m_DrxkState == DRXK_POWERED_DOWN) if (state->m_DrxkState == DRXK_POWERED_DOWN)
return -1; goto error;
if (state->no_i2c_bridge) if (state->no_i2c_bridge)
return 0; return 0;
do {
status = write16(state, SIO_HI_RA_RAM_PAR_1__A, SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY); status = write16(state, SIO_HI_RA_RAM_PAR_1__A, SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY);
if (status < 0) if (status < 0)
break; goto error;
if (bEnableBridge) { if (bEnableBridge) {
status = write16(state, SIO_HI_RA_RAM_PAR_2__A, SIO_HI_RA_RAM_PAR_2_BRD_CFG_CLOSED); status = write16(state, SIO_HI_RA_RAM_PAR_2__A, SIO_HI_RA_RAM_PAR_2_BRD_CFG_CLOSED);
if (status < 0) if (status < 0)
break; goto error;
} else { } else {
status = write16(state, SIO_HI_RA_RAM_PAR_2__A, SIO_HI_RA_RAM_PAR_2_BRD_CFG_OPEN); status = write16(state, SIO_HI_RA_RAM_PAR_2__A, SIO_HI_RA_RAM_PAR_2_BRD_CFG_OPEN);
if (status < 0) if (status < 0)
break; goto error;
} }
status = HI_Command(state, SIO_HI_RA_RAM_CMD_BRDCTRL, 0); status = HI_Command(state, SIO_HI_RA_RAM_CMD_BRDCTRL, 0);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
static int SetPreSaw(struct drxk_state *state, static int SetPreSaw(struct drxk_state *state,
struct SCfgPreSaw *pPreSawCfg) struct SCfgPreSaw *pPreSawCfg)
{ {
int status; int status = -EINVAL;
dprintk(1, "\n"); dprintk(1, "\n");
if ((pPreSawCfg == NULL) if ((pPreSawCfg == NULL)
|| (pPreSawCfg->reference > IQM_AF_PDREF__M)) || (pPreSawCfg->reference > IQM_AF_PDREF__M))
return -1; goto error;
status = write16(state, IQM_AF_PDREF__A, pPreSawCfg->reference); status = write16(state, IQM_AF_PDREF__A, pPreSawCfg->reference);
error:
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -2834,38 +2866,40 @@ static int BLDirectCmd(struct drxk_state *state, u32 targetAddr, ...@@ -2834,38 +2866,40 @@ static int BLDirectCmd(struct drxk_state *state, u32 targetAddr,
dprintk(1, "\n"); dprintk(1, "\n");
mutex_lock(&state->mutex); mutex_lock(&state->mutex);
do {
status = write16(state, SIO_BL_MODE__A, SIO_BL_MODE_DIRECT); status = write16(state, SIO_BL_MODE__A, SIO_BL_MODE_DIRECT);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_BL_TGT_HDR__A, blockbank); status = write16(state, SIO_BL_TGT_HDR__A, blockbank);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_BL_TGT_ADDR__A, offset); status = write16(state, SIO_BL_TGT_ADDR__A, offset);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_BL_SRC_ADDR__A, romOffset); status = write16(state, SIO_BL_SRC_ADDR__A, romOffset);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_BL_SRC_LEN__A, nrOfElements); status = write16(state, SIO_BL_SRC_LEN__A, nrOfElements);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_BL_ENABLE__A, SIO_BL_ENABLE_ON); status = write16(state, SIO_BL_ENABLE__A, SIO_BL_ENABLE_ON);
if (status < 0) if (status < 0)
break; goto error;
end = jiffies + msecs_to_jiffies(timeOut); end = jiffies + msecs_to_jiffies(timeOut);
do { do {
status = read16(state, SIO_BL_STATUS__A, &blStatus); status = read16(state, SIO_BL_STATUS__A, &blStatus);
if (status < 0) if (status < 0)
break; goto error;
} while ((blStatus == 0x1) && time_is_after_jiffies(end)); } while ((blStatus == 0x1) && time_is_after_jiffies(end));
if (blStatus == 0x1) { if (blStatus == 0x1) {
printk(KERN_ERR "drxk: SIO not ready\n"); printk(KERN_ERR "drxk: SIO not ready\n");
mutex_unlock(&state->mutex); status = -EINVAL;
return -1; goto error2;
} }
} while (0); error:
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
error2:
mutex_unlock(&state->mutex); mutex_unlock(&state->mutex);
return status; return status;
...@@ -2878,32 +2912,34 @@ static int ADCSyncMeasurement(struct drxk_state *state, u16 *count) ...@@ -2878,32 +2912,34 @@ static int ADCSyncMeasurement(struct drxk_state *state, u16 *count)
dprintk(1, "\n"); dprintk(1, "\n");
do {
/* Start measurement */ /* Start measurement */
status = write16(state, IQM_AF_COMM_EXEC__A, IQM_AF_COMM_EXEC_ACTIVE); status = write16(state, IQM_AF_COMM_EXEC__A, IQM_AF_COMM_EXEC_ACTIVE);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_AF_START_LOCK__A, 1); status = write16(state, IQM_AF_START_LOCK__A, 1);
if (status < 0) if (status < 0)
break; goto error;
*count = 0; *count = 0;
status = read16(state, IQM_AF_PHASE0__A, &data); status = read16(state, IQM_AF_PHASE0__A, &data);
if (status < 0) if (status < 0)
break; goto error;
if (data == 127) if (data == 127)
*count = *count + 1; *count = *count + 1;
status = read16(state, IQM_AF_PHASE1__A, &data); status = read16(state, IQM_AF_PHASE1__A, &data);
if (status < 0) if (status < 0)
break; goto error;
if (data == 127) if (data == 127)
*count = *count + 1; *count = *count + 1;
status = read16(state, IQM_AF_PHASE2__A, &data); status = read16(state, IQM_AF_PHASE2__A, &data);
if (status < 0) if (status < 0)
break; goto error;
if (data == 127) if (data == 127)
*count = *count + 1; *count = *count + 1;
} while (0);
error:
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -2914,10 +2950,9 @@ static int ADCSynchronization(struct drxk_state *state) ...@@ -2914,10 +2950,9 @@ static int ADCSynchronization(struct drxk_state *state)
dprintk(1, "\n"); dprintk(1, "\n");
do {
status = ADCSyncMeasurement(state, &count); status = ADCSyncMeasurement(state, &count);
if (status < 0) if (status < 0)
break; goto error;
if (count == 1) { if (count == 1) {
/* Try sampling on a diffrent edge */ /* Try sampling on a diffrent edge */
...@@ -2925,7 +2960,7 @@ static int ADCSynchronization(struct drxk_state *state) ...@@ -2925,7 +2960,7 @@ static int ADCSynchronization(struct drxk_state *state)
status = read16(state, IQM_AF_CLKNEG__A, &clkNeg); status = read16(state, IQM_AF_CLKNEG__A, &clkNeg);
if (status < 0) if (status < 0)
break; goto error;
if ((clkNeg | IQM_AF_CLKNEG_CLKNEGDATA__M) == if ((clkNeg | IQM_AF_CLKNEG_CLKNEGDATA__M) ==
IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_POS) { IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_POS) {
clkNeg &= (~(IQM_AF_CLKNEG_CLKNEGDATA__M)); clkNeg &= (~(IQM_AF_CLKNEG_CLKNEGDATA__M));
...@@ -2938,15 +2973,17 @@ static int ADCSynchronization(struct drxk_state *state) ...@@ -2938,15 +2973,17 @@ static int ADCSynchronization(struct drxk_state *state)
} }
status = write16(state, IQM_AF_CLKNEG__A, clkNeg); status = write16(state, IQM_AF_CLKNEG__A, clkNeg);
if (status < 0) if (status < 0)
break; goto error;
status = ADCSyncMeasurement(state, &count); status = ADCSyncMeasurement(state, &count);
if (status < 0) if (status < 0)
break; goto error;
} }
if (count < 2) if (count < 2)
status = -1; status = -EINVAL;
} while (0); error:
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -3011,6 +3048,8 @@ static int SetFrequencyShifter(struct drxk_state *state, ...@@ -3011,6 +3048,8 @@ static int SetFrequencyShifter(struct drxk_state *state,
/* frequencyShift += tunerFreqOffset; TODO */ /* frequencyShift += tunerFreqOffset; TODO */
status = write32(state, IQM_FS_RATE_OFS_LO__A, status = write32(state, IQM_FS_RATE_OFS_LO__A,
state->m_IqmFsRateOfs); state->m_IqmFsRateOfs);
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -3037,7 +3076,6 @@ static int InitAGC(struct drxk_state *state, bool isDTV) ...@@ -3037,7 +3076,6 @@ static int InitAGC(struct drxk_state *state, bool isDTV)
dprintk(1, "\n"); dprintk(1, "\n");
do {
/* Common settings */ /* Common settings */
snsSumMax = 1023; snsSumMax = 1023;
ifIaccuHiTgtMin = 2047; ifIaccuHiTgtMin = 2047;
...@@ -3052,11 +3090,10 @@ static int InitAGC(struct drxk_state *state, bool isDTV) ...@@ -3052,11 +3090,10 @@ static int InitAGC(struct drxk_state *state, bool isDTV)
snsSumMin = 8; snsSumMin = 8;
snsDirTo = (u16) -9; snsDirTo = (u16) -9;
kiInnergainMin = (u16) -1030; kiInnergainMin = (u16) -1030;
} else } else {
status = -1; status = -EINVAL;
status = (status); goto error;
if (status < 0) }
break;
if (IsQAM(state)) { if (IsQAM(state)) {
ifIaccuHiTgtMax = 0x2380; ifIaccuHiTgtMax = 0x2380;
ifIaccuHiTgt = 0x2380; ifIaccuHiTgt = 0x2380;
...@@ -3076,127 +3113,127 @@ static int InitAGC(struct drxk_state *state, bool isDTV) ...@@ -3076,127 +3113,127 @@ static int InitAGC(struct drxk_state *state, bool isDTV)
} }
status = write16(state, SCU_RAM_AGC_FAST_CLP_CTRL_DELAY__A, fastClpCtrlDelay); status = write16(state, SCU_RAM_AGC_FAST_CLP_CTRL_DELAY__A, fastClpCtrlDelay);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_CLP_CTRL_MODE__A, clpCtrlMode); status = write16(state, SCU_RAM_AGC_CLP_CTRL_MODE__A, clpCtrlMode);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_INGAIN_TGT__A, ingainTgt); status = write16(state, SCU_RAM_AGC_INGAIN_TGT__A, ingainTgt);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MIN__A, ingainTgtMin); status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MIN__A, ingainTgtMin);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MAX__A, ingainTgtMax); status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MAX__A, ingainTgtMax);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MIN__A, ifIaccuHiTgtMin); status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MIN__A, ifIaccuHiTgtMin);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, ifIaccuHiTgtMax); status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, ifIaccuHiTgtMax);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_IF_IACCU_HI__A, 0); status = write16(state, SCU_RAM_AGC_IF_IACCU_HI__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_IF_IACCU_LO__A, 0); status = write16(state, SCU_RAM_AGC_IF_IACCU_LO__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_RF_IACCU_HI__A, 0); status = write16(state, SCU_RAM_AGC_RF_IACCU_HI__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_RF_IACCU_LO__A, 0); status = write16(state, SCU_RAM_AGC_RF_IACCU_LO__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_CLP_SUM_MAX__A, clpSumMax); status = write16(state, SCU_RAM_AGC_CLP_SUM_MAX__A, clpSumMax);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_SNS_SUM_MAX__A, snsSumMax); status = write16(state, SCU_RAM_AGC_SNS_SUM_MAX__A, snsSumMax);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_KI_INNERGAIN_MIN__A, kiInnergainMin); status = write16(state, SCU_RAM_AGC_KI_INNERGAIN_MIN__A, kiInnergainMin);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT__A, ifIaccuHiTgt); status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT__A, ifIaccuHiTgt);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_CLP_CYCLEN__A, clpCyclen); status = write16(state, SCU_RAM_AGC_CLP_CYCLEN__A, clpCyclen);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_RF_SNS_DEV_MAX__A, 1023); status = write16(state, SCU_RAM_AGC_RF_SNS_DEV_MAX__A, 1023);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_RF_SNS_DEV_MIN__A, (u16) -1023); status = write16(state, SCU_RAM_AGC_RF_SNS_DEV_MIN__A, (u16) -1023);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_FAST_SNS_CTRL_DELAY__A, 50); status = write16(state, SCU_RAM_AGC_FAST_SNS_CTRL_DELAY__A, 50);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_KI_MAXMINGAIN_TH__A, 20); status = write16(state, SCU_RAM_AGC_KI_MAXMINGAIN_TH__A, 20);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_CLP_SUM_MIN__A, clpSumMin); status = write16(state, SCU_RAM_AGC_CLP_SUM_MIN__A, clpSumMin);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_SNS_SUM_MIN__A, snsSumMin); status = write16(state, SCU_RAM_AGC_SNS_SUM_MIN__A, snsSumMin);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_CLP_DIR_TO__A, clpDirTo); status = write16(state, SCU_RAM_AGC_CLP_DIR_TO__A, clpDirTo);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_SNS_DIR_TO__A, snsDirTo); status = write16(state, SCU_RAM_AGC_SNS_DIR_TO__A, snsDirTo);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_KI_MINGAIN__A, 0x7fff); status = write16(state, SCU_RAM_AGC_KI_MINGAIN__A, 0x7fff);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_KI_MAXGAIN__A, 0x0); status = write16(state, SCU_RAM_AGC_KI_MAXGAIN__A, 0x0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_KI_MIN__A, 0x0117); status = write16(state, SCU_RAM_AGC_KI_MIN__A, 0x0117);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_KI_MAX__A, 0x0657); status = write16(state, SCU_RAM_AGC_KI_MAX__A, 0x0657);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_CLP_SUM__A, 0); status = write16(state, SCU_RAM_AGC_CLP_SUM__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_CLP_CYCCNT__A, 0); status = write16(state, SCU_RAM_AGC_CLP_CYCCNT__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_CLP_DIR_WD__A, 0); status = write16(state, SCU_RAM_AGC_CLP_DIR_WD__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_CLP_DIR_STP__A, 1); status = write16(state, SCU_RAM_AGC_CLP_DIR_STP__A, 1);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_SNS_SUM__A, 0); status = write16(state, SCU_RAM_AGC_SNS_SUM__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_SNS_CYCCNT__A, 0); status = write16(state, SCU_RAM_AGC_SNS_CYCCNT__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_SNS_DIR_WD__A, 0); status = write16(state, SCU_RAM_AGC_SNS_DIR_WD__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_SNS_DIR_STP__A, 1); status = write16(state, SCU_RAM_AGC_SNS_DIR_STP__A, 1);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_SNS_CYCLEN__A, 500); status = write16(state, SCU_RAM_AGC_SNS_CYCLEN__A, 500);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_KI_CYCLEN__A, 500); status = write16(state, SCU_RAM_AGC_KI_CYCLEN__A, 500);
if (status < 0) if (status < 0)
break; goto error;
/* Initialize inner-loop KI gain factors */ /* Initialize inner-loop KI gain factors */
status = read16(state, SCU_RAM_AGC_KI__A, &data); status = read16(state, SCU_RAM_AGC_KI__A, &data);
if (status < 0) if (status < 0)
break; goto error;
if (IsQAM(state)) { if (IsQAM(state)) {
data = 0x0657; data = 0x0657;
data &= ~SCU_RAM_AGC_KI_RF__M; data &= ~SCU_RAM_AGC_KI_RF__M;
...@@ -3205,9 +3242,9 @@ static int InitAGC(struct drxk_state *state, bool isDTV) ...@@ -3205,9 +3242,9 @@ static int InitAGC(struct drxk_state *state, bool isDTV)
data |= (DRXK_KI_IAGC_QAM << SCU_RAM_AGC_KI_IF__B); data |= (DRXK_KI_IAGC_QAM << SCU_RAM_AGC_KI_IF__B);
} }
status = write16(state, SCU_RAM_AGC_KI__A, data); status = write16(state, SCU_RAM_AGC_KI__A, data);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
...@@ -3216,17 +3253,12 @@ static int DVBTQAMGetAccPktErr(struct drxk_state *state, u16 *packetErr) ...@@ -3216,17 +3253,12 @@ static int DVBTQAMGetAccPktErr(struct drxk_state *state, u16 *packetErr)
int status; int status;
dprintk(1, "\n"); dprintk(1, "\n");
do { if (packetErr == NULL)
if (packetErr == NULL) {
status = write16(state, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, 0); status = write16(state, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, 0);
if (status < 0) else
break;
} else {
status = read16(state, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, packetErr); status = read16(state, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, packetErr);
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
}
} while (0);
return status; return status;
} }
...@@ -3245,8 +3277,10 @@ static int DVBTScCommand(struct drxk_state *state, ...@@ -3245,8 +3277,10 @@ static int DVBTScCommand(struct drxk_state *state,
status = read16(state, OFDM_SC_COMM_EXEC__A, &scExec); status = read16(state, OFDM_SC_COMM_EXEC__A, &scExec);
if (scExec != 1) { if (scExec != 1) {
/* SC is not running */ /* SC is not running */
return -1; status = -EINVAL;
} }
if (status < 0)
goto error;
/* Wait until sc is ready to receive command */ /* Wait until sc is ready to receive command */
retryCnt = 0; retryCnt = 0;
...@@ -3255,21 +3289,23 @@ static int DVBTScCommand(struct drxk_state *state, ...@@ -3255,21 +3289,23 @@ static int DVBTScCommand(struct drxk_state *state,
status = read16(state, OFDM_SC_RA_RAM_CMD__A, &curCmd); status = read16(state, OFDM_SC_RA_RAM_CMD__A, &curCmd);
retryCnt++; retryCnt++;
} while ((curCmd != 0) && (retryCnt < DRXK_MAX_RETRIES)); } while ((curCmd != 0) && (retryCnt < DRXK_MAX_RETRIES));
if (retryCnt >= DRXK_MAX_RETRIES) if (retryCnt >= DRXK_MAX_RETRIES && (status < 0))
return -1; goto error;
/* Write sub-command */ /* Write sub-command */
switch (cmd) { switch (cmd) {
/* All commands using sub-cmd */ /* All commands using sub-cmd */
case OFDM_SC_RA_RAM_CMD_PROC_START: case OFDM_SC_RA_RAM_CMD_PROC_START:
case OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM: case OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM:
case OFDM_SC_RA_RAM_CMD_PROGRAM_PARAM: case OFDM_SC_RA_RAM_CMD_PROGRAM_PARAM:
status = status = write16(state, OFDM_SC_RA_RAM_CMD_ADDR__A, subcmd);
write16(state, OFDM_SC_RA_RAM_CMD_ADDR__A, subcmd); if (status < 0)
goto error;
break; break;
default: default:
/* Do nothing */ /* Do nothing */
break; break;
} /* switch (cmd->cmd) */ }
/* Write needed parameters and the command */ /* Write needed parameters and the command */
switch (cmd) { switch (cmd) {
...@@ -3280,13 +3316,11 @@ static int DVBTScCommand(struct drxk_state *state, ...@@ -3280,13 +3316,11 @@ static int DVBTScCommand(struct drxk_state *state,
case OFDM_SC_RA_RAM_CMD_PROC_START: case OFDM_SC_RA_RAM_CMD_PROC_START:
case OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM: case OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM:
case OFDM_SC_RA_RAM_CMD_PROGRAM_PARAM: case OFDM_SC_RA_RAM_CMD_PROGRAM_PARAM:
status = status = write16(state, OFDM_SC_RA_RAM_PARAM1__A, param1);
write16(state, OFDM_SC_RA_RAM_PARAM1__A, param1);
/* All commands using 1 parameters */ /* All commands using 1 parameters */
case OFDM_SC_RA_RAM_CMD_SET_ECHO_TIMING: case OFDM_SC_RA_RAM_CMD_SET_ECHO_TIMING:
case OFDM_SC_RA_RAM_CMD_USER_IO: case OFDM_SC_RA_RAM_CMD_USER_IO:
status = status = write16(state, OFDM_SC_RA_RAM_PARAM0__A, param0);
write16(state, OFDM_SC_RA_RAM_PARAM0__A, param0);
/* All commands using 0 parameters */ /* All commands using 0 parameters */
case OFDM_SC_RA_RAM_CMD_GET_OP_PARAM: case OFDM_SC_RA_RAM_CMD_GET_OP_PARAM:
case OFDM_SC_RA_RAM_CMD_NULL: case OFDM_SC_RA_RAM_CMD_NULL:
...@@ -3295,8 +3329,10 @@ static int DVBTScCommand(struct drxk_state *state, ...@@ -3295,8 +3329,10 @@ static int DVBTScCommand(struct drxk_state *state,
break; break;
default: default:
/* Unknown command */ /* Unknown command */
return -EINVAL; status = -EINVAL;
} /* switch (cmd->cmd) */ }
if (status < 0)
goto error;
/* Wait until sc is ready processing command */ /* Wait until sc is ready processing command */
retryCnt = 0; retryCnt = 0;
...@@ -3305,15 +3341,17 @@ static int DVBTScCommand(struct drxk_state *state, ...@@ -3305,15 +3341,17 @@ static int DVBTScCommand(struct drxk_state *state,
status = read16(state, OFDM_SC_RA_RAM_CMD__A, &curCmd); status = read16(state, OFDM_SC_RA_RAM_CMD__A, &curCmd);
retryCnt++; retryCnt++;
} while ((curCmd != 0) && (retryCnt < DRXK_MAX_RETRIES)); } while ((curCmd != 0) && (retryCnt < DRXK_MAX_RETRIES));
if (retryCnt >= DRXK_MAX_RETRIES) if (retryCnt >= DRXK_MAX_RETRIES && (status < 0))
return -1; goto error;
/* Check for illegal cmd */ /* Check for illegal cmd */
status = read16(state, OFDM_SC_RA_RAM_CMD_ADDR__A, &errCode); status = read16(state, OFDM_SC_RA_RAM_CMD_ADDR__A, &errCode);
if (errCode == 0xFFFF) { if (errCode == 0xFFFF) {
/* illegal command */ /* illegal command */
return -EINVAL; status = -EINVAL;
} }
if (status < 0)
goto error;
/* Retreive results parameters from SC */ /* Retreive results parameters from SC */
switch (cmd) { switch (cmd) {
...@@ -3324,8 +3362,7 @@ static int DVBTScCommand(struct drxk_state *state, ...@@ -3324,8 +3362,7 @@ static int DVBTScCommand(struct drxk_state *state,
/* All commands yielding 1 result */ /* All commands yielding 1 result */
case OFDM_SC_RA_RAM_CMD_USER_IO: case OFDM_SC_RA_RAM_CMD_USER_IO:
case OFDM_SC_RA_RAM_CMD_GET_OP_PARAM: case OFDM_SC_RA_RAM_CMD_GET_OP_PARAM:
status = status = read16(state, OFDM_SC_RA_RAM_PARAM0__A, &(param0));
read16(state, OFDM_SC_RA_RAM_PARAM0__A, &(param0));
/* All commands yielding 0 results */ /* All commands yielding 0 results */
case OFDM_SC_RA_RAM_CMD_SET_ECHO_TIMING: case OFDM_SC_RA_RAM_CMD_SET_ECHO_TIMING:
case OFDM_SC_RA_RAM_CMD_SET_TIMER: case OFDM_SC_RA_RAM_CMD_SET_TIMER:
...@@ -3336,9 +3373,12 @@ static int DVBTScCommand(struct drxk_state *state, ...@@ -3336,9 +3373,12 @@ static int DVBTScCommand(struct drxk_state *state,
break; break;
default: default:
/* Unknown command */ /* Unknown command */
return -EINVAL; status = -EINVAL;
break; break;
} /* switch (cmd->cmd) */ } /* switch (cmd->cmd) */
error:
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -3348,11 +3388,9 @@ static int PowerUpDVBT(struct drxk_state *state) ...@@ -3348,11 +3388,9 @@ static int PowerUpDVBT(struct drxk_state *state)
int status; int status;
dprintk(1, "\n"); dprintk(1, "\n");
do {
status = CtrlPowerMode(state, &powerMode); status = CtrlPowerMode(state, &powerMode);
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
...@@ -3365,7 +3403,8 @@ static int DVBTCtrlSetIncEnable(struct drxk_state *state, bool *enabled) ...@@ -3365,7 +3403,8 @@ static int DVBTCtrlSetIncEnable(struct drxk_state *state, bool *enabled)
status = write16(state, IQM_CF_BYPASSDET__A, 0); status = write16(state, IQM_CF_BYPASSDET__A, 0);
else else
status = write16(state, IQM_CF_BYPASSDET__A, 1); status = write16(state, IQM_CF_BYPASSDET__A, 1);
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -3384,6 +3423,8 @@ static int DVBTCtrlSetFrEnable(struct drxk_state *state, bool *enabled) ...@@ -3384,6 +3423,8 @@ static int DVBTCtrlSetFrEnable(struct drxk_state *state, bool *enabled)
/* write mask to 0 */ /* write mask to 0 */
status = write16(state, OFDM_SC_RA_RAM_FR_THRES_8K__A, 0); status = write16(state, OFDM_SC_RA_RAM_FR_THRES_8K__A, 0);
} }
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -3395,43 +3436,39 @@ static int DVBTCtrlSetEchoThreshold(struct drxk_state *state, ...@@ -3395,43 +3436,39 @@ static int DVBTCtrlSetEchoThreshold(struct drxk_state *state,
int status; int status;
dprintk(1, "\n"); dprintk(1, "\n");
do {
status = read16(state, OFDM_SC_RA_RAM_ECHO_THRES__A, &data); status = read16(state, OFDM_SC_RA_RAM_ECHO_THRES__A, &data);
if (status < 0) if (status < 0)
break; goto error;
switch (echoThres->fftMode) { switch (echoThres->fftMode) {
case DRX_FFTMODE_2K: case DRX_FFTMODE_2K:
data &= ~OFDM_SC_RA_RAM_ECHO_THRES_2K__M; data &= ~OFDM_SC_RA_RAM_ECHO_THRES_2K__M;
data |= data |= ((echoThres->threshold <<
((echoThres->threshold <<
OFDM_SC_RA_RAM_ECHO_THRES_2K__B) OFDM_SC_RA_RAM_ECHO_THRES_2K__B)
& (OFDM_SC_RA_RAM_ECHO_THRES_2K__M)); & (OFDM_SC_RA_RAM_ECHO_THRES_2K__M));
break; goto error;
case DRX_FFTMODE_8K: case DRX_FFTMODE_8K:
data &= ~OFDM_SC_RA_RAM_ECHO_THRES_8K__M; data &= ~OFDM_SC_RA_RAM_ECHO_THRES_8K__M;
data |= data |= ((echoThres->threshold <<
((echoThres->threshold <<
OFDM_SC_RA_RAM_ECHO_THRES_8K__B) OFDM_SC_RA_RAM_ECHO_THRES_8K__B)
& (OFDM_SC_RA_RAM_ECHO_THRES_8K__M)); & (OFDM_SC_RA_RAM_ECHO_THRES_8K__M));
break; goto error;
default: default:
return -1; return -EINVAL;
break; goto error;
} }
status = write16(state, OFDM_SC_RA_RAM_ECHO_THRES__A, data); status = write16(state, OFDM_SC_RA_RAM_ECHO_THRES__A, data);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
static int DVBTCtrlSetSqiSpeed(struct drxk_state *state, static int DVBTCtrlSetSqiSpeed(struct drxk_state *state,
enum DRXKCfgDvbtSqiSpeed *speed) enum DRXKCfgDvbtSqiSpeed *speed)
{ {
int status; int status = -EINVAL;
dprintk(1, "\n"); dprintk(1, "\n");
...@@ -3441,10 +3478,13 @@ static int DVBTCtrlSetSqiSpeed(struct drxk_state *state, ...@@ -3441,10 +3478,13 @@ static int DVBTCtrlSetSqiSpeed(struct drxk_state *state,
case DRXK_DVBT_SQI_SPEED_SLOW: case DRXK_DVBT_SQI_SPEED_SLOW:
break; break;
default: default:
return -EINVAL; goto error;
} }
status = write16(state, SCU_RAM_FEC_PRE_RS_BER_FILTER_SH__A, status = write16(state, SCU_RAM_FEC_PRE_RS_BER_FILTER_SH__A,
(u16) *speed); (u16) *speed);
error:
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -3461,31 +3501,29 @@ static int DVBTCtrlSetSqiSpeed(struct drxk_state *state, ...@@ -3461,31 +3501,29 @@ static int DVBTCtrlSetSqiSpeed(struct drxk_state *state,
static int DVBTActivatePresets(struct drxk_state *state) static int DVBTActivatePresets(struct drxk_state *state)
{ {
int status; int status;
bool setincenable = false;
bool setfrenable = true;
struct DRXKCfgDvbtEchoThres_t echoThres2k = { 0, DRX_FFTMODE_2K }; struct DRXKCfgDvbtEchoThres_t echoThres2k = { 0, DRX_FFTMODE_2K };
struct DRXKCfgDvbtEchoThres_t echoThres8k = { 0, DRX_FFTMODE_8K }; struct DRXKCfgDvbtEchoThres_t echoThres8k = { 0, DRX_FFTMODE_8K };
dprintk(1, "\n"); dprintk(1, "\n");
do {
bool setincenable = false;
bool setfrenable = true;
status = DVBTCtrlSetIncEnable(state, &setincenable); status = DVBTCtrlSetIncEnable(state, &setincenable);
if (status < 0) if (status < 0)
break; goto error;
status = DVBTCtrlSetFrEnable(state, &setfrenable); status = DVBTCtrlSetFrEnable(state, &setfrenable);
if (status < 0) if (status < 0)
break; goto error;
status = DVBTCtrlSetEchoThreshold(state, &echoThres2k); status = DVBTCtrlSetEchoThreshold(state, &echoThres2k);
if (status < 0) if (status < 0)
break; goto error;
status = DVBTCtrlSetEchoThreshold(state, &echoThres8k); status = DVBTCtrlSetEchoThreshold(state, &echoThres8k);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MAX__A, state->m_dvbtIfAgcCfg.IngainTgtMax); status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MAX__A, state->m_dvbtIfAgcCfg.IngainTgtMax);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
...@@ -3509,192 +3547,189 @@ static int SetDVBTStandard(struct drxk_state *state, ...@@ -3509,192 +3547,189 @@ static int SetDVBTStandard(struct drxk_state *state,
dprintk(1, "\n"); dprintk(1, "\n");
PowerUpDVBT(state); PowerUpDVBT(state);
do {
/* added antenna switch */ /* added antenna switch */
SwitchAntennaToDVBT(state); SwitchAntennaToDVBT(state);
/* send OFDM reset command */ /* send OFDM reset command */
status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_RESET, 0, NULL, 1, &cmdResult); status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_RESET, 0, NULL, 1, &cmdResult);
if (status < 0) if (status < 0)
break; goto error;
/* send OFDM setenv command */ /* send OFDM setenv command */
status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_SET_ENV, 0, NULL, 1, &cmdResult); status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_SET_ENV, 0, NULL, 1, &cmdResult);
if (status < 0) if (status < 0)
break; goto error;
/* reset datapath for OFDM, processors first */ /* reset datapath for OFDM, processors first */
status = write16(state, OFDM_SC_COMM_EXEC__A, OFDM_SC_COMM_EXEC_STOP); status = write16(state, OFDM_SC_COMM_EXEC__A, OFDM_SC_COMM_EXEC_STOP);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, OFDM_LC_COMM_EXEC__A, OFDM_LC_COMM_EXEC_STOP); status = write16(state, OFDM_LC_COMM_EXEC__A, OFDM_LC_COMM_EXEC_STOP);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_COMM_EXEC__A, IQM_COMM_EXEC_B_STOP); status = write16(state, IQM_COMM_EXEC__A, IQM_COMM_EXEC_B_STOP);
if (status < 0) if (status < 0)
break; goto error;
/* IQM setup */ /* IQM setup */
/* synchronize on ofdstate->m_festart */ /* synchronize on ofdstate->m_festart */
status = write16(state, IQM_AF_UPD_SEL__A, 1); status = write16(state, IQM_AF_UPD_SEL__A, 1);
if (status < 0) if (status < 0)
break; goto error;
/* window size for clipping ADC detection */ /* window size for clipping ADC detection */
status = write16(state, IQM_AF_CLP_LEN__A, 0); status = write16(state, IQM_AF_CLP_LEN__A, 0);
if (status < 0) if (status < 0)
break; goto error;
/* window size for for sense pre-SAW detection */ /* window size for for sense pre-SAW detection */
status = write16(state, IQM_AF_SNS_LEN__A, 0); status = write16(state, IQM_AF_SNS_LEN__A, 0);
if (status < 0) if (status < 0)
break; goto error;
/* sense threshold for sense pre-SAW detection */ /* sense threshold for sense pre-SAW detection */
status = write16(state, IQM_AF_AMUX__A, IQM_AF_AMUX_SIGNAL2ADC); status = write16(state, IQM_AF_AMUX__A, IQM_AF_AMUX_SIGNAL2ADC);
if (status < 0) if (status < 0)
break; goto error;
status = SetIqmAf(state, true); status = SetIqmAf(state, true);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_AF_AGC_RF__A, 0); status = write16(state, IQM_AF_AGC_RF__A, 0);
if (status < 0) if (status < 0)
break; goto error;
/* Impulse noise cruncher setup */ /* Impulse noise cruncher setup */
status = write16(state, IQM_AF_INC_LCT__A, 0); /* crunch in IQM_CF */ status = write16(state, IQM_AF_INC_LCT__A, 0); /* crunch in IQM_CF */
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_CF_DET_LCT__A, 0); /* detect in IQM_CF */ status = write16(state, IQM_CF_DET_LCT__A, 0); /* detect in IQM_CF */
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_CF_WND_LEN__A, 3); /* peak detector window length */ status = write16(state, IQM_CF_WND_LEN__A, 3); /* peak detector window length */
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_RC_STRETCH__A, 16); status = write16(state, IQM_RC_STRETCH__A, 16);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_CF_OUT_ENA__A, 0x4); /* enable output 2 */ status = write16(state, IQM_CF_OUT_ENA__A, 0x4); /* enable output 2 */
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_CF_DS_ENA__A, 0x4); /* decimate output 2 */ status = write16(state, IQM_CF_DS_ENA__A, 0x4); /* decimate output 2 */
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_CF_SCALE__A, 1600); status = write16(state, IQM_CF_SCALE__A, 1600);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_CF_SCALE_SH__A, 0); status = write16(state, IQM_CF_SCALE_SH__A, 0);
if (status < 0) if (status < 0)
break; goto error;
/* virtual clipping threshold for clipping ADC detection */ /* virtual clipping threshold for clipping ADC detection */
status = write16(state, IQM_AF_CLP_TH__A, 448); status = write16(state, IQM_AF_CLP_TH__A, 448);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_CF_DATATH__A, 495); /* crunching threshold */ status = write16(state, IQM_CF_DATATH__A, 495); /* crunching threshold */
if (status < 0) if (status < 0)
break; goto error;
status = BLChainCmd(state, DRXK_BL_ROM_OFFSET_TAPS_DVBT, DRXK_BLCC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT); status = BLChainCmd(state, DRXK_BL_ROM_OFFSET_TAPS_DVBT, DRXK_BLCC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_CF_PKDTH__A, 2); /* peak detector threshold */ status = write16(state, IQM_CF_PKDTH__A, 2); /* peak detector threshold */
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_CF_POW_MEAS_LEN__A, 2); status = write16(state, IQM_CF_POW_MEAS_LEN__A, 2);
if (status < 0) if (status < 0)
break; goto error;
/* enable power measurement interrupt */ /* enable power measurement interrupt */
status = write16(state, IQM_CF_COMM_INT_MSK__A, 1); status = write16(state, IQM_CF_COMM_INT_MSK__A, 1);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_COMM_EXEC__A, IQM_COMM_EXEC_B_ACTIVE); status = write16(state, IQM_COMM_EXEC__A, IQM_COMM_EXEC_B_ACTIVE);
if (status < 0) if (status < 0)
break; goto error;
/* IQM will not be reset from here, sync ADC and update/init AGC */ /* IQM will not be reset from here, sync ADC and update/init AGC */
status = ADCSynchronization(state); status = ADCSynchronization(state);
if (status < 0) if (status < 0)
break; goto error;
status = SetPreSaw(state, &state->m_dvbtPreSawCfg); status = SetPreSaw(state, &state->m_dvbtPreSawCfg);
if (status < 0) if (status < 0)
break; goto error;
/* Halt SCU to enable safe non-atomic accesses */ /* Halt SCU to enable safe non-atomic accesses */
status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_HOLD); status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_HOLD);
if (status < 0) if (status < 0)
break; goto error;
status = SetAgcRf(state, &state->m_dvbtRfAgcCfg, true); status = SetAgcRf(state, &state->m_dvbtRfAgcCfg, true);
if (status < 0) if (status < 0)
break; goto error;
status = SetAgcIf(state, &state->m_dvbtIfAgcCfg, true); status = SetAgcIf(state, &state->m_dvbtIfAgcCfg, true);
if (status < 0) if (status < 0)
break; goto error;
/* Set Noise Estimation notch width and enable DC fix */ /* Set Noise Estimation notch width and enable DC fix */
status = read16(state, OFDM_SC_RA_RAM_CONFIG__A, &data); status = read16(state, OFDM_SC_RA_RAM_CONFIG__A, &data);
if (status < 0) if (status < 0)
break; goto error;
data |= OFDM_SC_RA_RAM_CONFIG_NE_FIX_ENABLE__M; data |= OFDM_SC_RA_RAM_CONFIG_NE_FIX_ENABLE__M;
status = write16(state, OFDM_SC_RA_RAM_CONFIG__A, data); status = write16(state, OFDM_SC_RA_RAM_CONFIG__A, data);
if (status < 0) if (status < 0)
break; goto error;
/* Activate SCU to enable SCU commands */ /* Activate SCU to enable SCU commands */
status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE);
if (status < 0) if (status < 0)
break; goto error;
if (!state->m_DRXK_A3_ROM_CODE) { if (!state->m_DRXK_A3_ROM_CODE) {
/* AGCInit() is not done for DVBT, so set agcFastClipCtrlDelay */ /* AGCInit() is not done for DVBT, so set agcFastClipCtrlDelay */
status = write16(state, SCU_RAM_AGC_FAST_CLP_CTRL_DELAY__A, state->m_dvbtIfAgcCfg.FastClipCtrlDelay); status = write16(state, SCU_RAM_AGC_FAST_CLP_CTRL_DELAY__A, state->m_dvbtIfAgcCfg.FastClipCtrlDelay);
if (status < 0) if (status < 0)
break; goto error;
} }
/* OFDM_SC setup */ /* OFDM_SC setup */
#ifdef COMPILE_FOR_NONRT #ifdef COMPILE_FOR_NONRT
status = write16(state, OFDM_SC_RA_RAM_BE_OPT_DELAY__A, 1); status = write16(state, OFDM_SC_RA_RAM_BE_OPT_DELAY__A, 1);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, OFDM_SC_RA_RAM_BE_OPT_INIT_DELAY__A, 2); status = write16(state, OFDM_SC_RA_RAM_BE_OPT_INIT_DELAY__A, 2);
if (status < 0) if (status < 0)
break; goto error;
#endif #endif
/* FEC setup */ /* FEC setup */
status = write16(state, FEC_DI_INPUT_CTL__A, 1); /* OFDM input */ status = write16(state, FEC_DI_INPUT_CTL__A, 1); /* OFDM input */
if (status < 0) if (status < 0)
break; goto error;
#ifdef COMPILE_FOR_NONRT #ifdef COMPILE_FOR_NONRT
status = write16(state, FEC_RS_MEASUREMENT_PERIOD__A, 0x400); status = write16(state, FEC_RS_MEASUREMENT_PERIOD__A, 0x400);
if (status < 0) if (status < 0)
break; goto error;
#else #else
status = write16(state, FEC_RS_MEASUREMENT_PERIOD__A, 0x1000); status = write16(state, FEC_RS_MEASUREMENT_PERIOD__A, 0x1000);
if (status < 0) if (status < 0)
break; goto error;
#endif #endif
status = write16(state, FEC_RS_MEASUREMENT_PRESCALE__A, 0x0001); status = write16(state, FEC_RS_MEASUREMENT_PRESCALE__A, 0x0001);
if (status < 0) if (status < 0)
break; goto error;
/* Setup MPEG bus */ /* Setup MPEG bus */
status = MPEGTSDtoSetup(state, OM_DVBT); status = MPEGTSDtoSetup(state, OM_DVBT);
if (status < 0) if (status < 0)
break; goto error;
/* Set DVBT Presets */ /* Set DVBT Presets */
status = DVBTActivatePresets(state); status = DVBTActivatePresets(state);
if (status < 0) if (status < 0)
break; goto error;
} while (0);
error:
if (status < 0) if (status < 0)
printk(KERN_ERR "drxk: %s status - %08x\n", __func__, status); printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -3713,19 +3748,20 @@ static int DVBTStart(struct drxk_state *state) ...@@ -3713,19 +3748,20 @@ static int DVBTStart(struct drxk_state *state)
dprintk(1, "\n"); dprintk(1, "\n");
/* Start correct processes to get in lock */ /* Start correct processes to get in lock */
/* DRXK: OFDM_SC_RA_RAM_PROC_LOCKTRACK is no longer in mapfile! */ /* DRXK: OFDM_SC_RA_RAM_PROC_LOCKTRACK is no longer in mapfile! */
do {
param1 = OFDM_SC_RA_RAM_LOCKTRACK_MIN; param1 = OFDM_SC_RA_RAM_LOCKTRACK_MIN;
status = DVBTScCommand(state, OFDM_SC_RA_RAM_CMD_PROC_START, 0, OFDM_SC_RA_RAM_SW_EVENT_RUN_NMASK__M, param1, 0, 0, 0); status = DVBTScCommand(state, OFDM_SC_RA_RAM_CMD_PROC_START, 0, OFDM_SC_RA_RAM_SW_EVENT_RUN_NMASK__M, param1, 0, 0, 0);
if (status < 0) if (status < 0)
break; goto error;
/* Start FEC OC */ /* Start FEC OC */
status = MPEGTSStart(state); status = MPEGTSStart(state);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_COMM_EXEC__A, FEC_COMM_EXEC_ACTIVE); status = write16(state, FEC_COMM_EXEC__A, FEC_COMM_EXEC_ACTIVE);
if (status < 0) if (status < 0)
break; goto error;
} while (0); error:
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -3749,31 +3785,30 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz, ...@@ -3749,31 +3785,30 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz,
u16 param1; u16 param1;
int status; int status;
dprintk(1, "\n"); dprintk(1, "IF =%d, TFO = %d\n", IntermediateFreqkHz, tunerFreqOffset);
/* printk(KERN_DEBUG "drxk: %s IF =%d, TFO = %d\n", __func__, IntermediateFreqkHz, tunerFreqOffset); */
do {
status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_STOP, 0, NULL, 1, &cmdResult); status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_STOP, 0, NULL, 1, &cmdResult);
if (status < 0) if (status < 0)
break; goto error;
/* Halt SCU to enable safe non-atomic accesses */ /* Halt SCU to enable safe non-atomic accesses */
status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_HOLD); status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_HOLD);
if (status < 0) if (status < 0)
break; goto error;
/* Stop processors */ /* Stop processors */
status = write16(state, OFDM_SC_COMM_EXEC__A, OFDM_SC_COMM_EXEC_STOP); status = write16(state, OFDM_SC_COMM_EXEC__A, OFDM_SC_COMM_EXEC_STOP);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, OFDM_LC_COMM_EXEC__A, OFDM_LC_COMM_EXEC_STOP); status = write16(state, OFDM_LC_COMM_EXEC__A, OFDM_LC_COMM_EXEC_STOP);
if (status < 0) if (status < 0)
break; goto error;
/* Mandatory fix, always stop CP, required to set spl offset back to /* Mandatory fix, always stop CP, required to set spl offset back to
hardware default (is set to 0 by ucode during pilot detection */ hardware default (is set to 0 by ucode during pilot detection */
status = write16(state, OFDM_CP_COMM_EXEC__A, OFDM_CP_COMM_EXEC_STOP); status = write16(state, OFDM_CP_COMM_EXEC__A, OFDM_CP_COMM_EXEC_STOP);
if (status < 0) if (status < 0)
break; goto error;
/*== Write channel settings to device =====================================*/ /*== Write channel settings to device =====================================*/
...@@ -3784,13 +3819,11 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz, ...@@ -3784,13 +3819,11 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz,
operationMode |= OFDM_SC_RA_RAM_OP_AUTO_MODE__M; operationMode |= OFDM_SC_RA_RAM_OP_AUTO_MODE__M;
/* fall through , try first guess DRX_FFTMODE_8K */ /* fall through , try first guess DRX_FFTMODE_8K */
case TRANSMISSION_MODE_8K: case TRANSMISSION_MODE_8K:
transmissionParams |= transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_MODE_8K;
OFDM_SC_RA_RAM_OP_PARAM_MODE_8K; goto error;
break;
case TRANSMISSION_MODE_2K: case TRANSMISSION_MODE_2K:
transmissionParams |= transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_MODE_2K;
OFDM_SC_RA_RAM_OP_PARAM_MODE_2K; goto error;
break;
} }
/* guard */ /* guard */
...@@ -3800,21 +3833,17 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz, ...@@ -3800,21 +3833,17 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz,
operationMode |= OFDM_SC_RA_RAM_OP_AUTO_GUARD__M; operationMode |= OFDM_SC_RA_RAM_OP_AUTO_GUARD__M;
/* fall through , try first guess DRX_GUARD_1DIV4 */ /* fall through , try first guess DRX_GUARD_1DIV4 */
case GUARD_INTERVAL_1_4: case GUARD_INTERVAL_1_4:
transmissionParams |= transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_GUARD_4;
OFDM_SC_RA_RAM_OP_PARAM_GUARD_4; goto error;
break;
case GUARD_INTERVAL_1_32: case GUARD_INTERVAL_1_32:
transmissionParams |= transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_GUARD_32;
OFDM_SC_RA_RAM_OP_PARAM_GUARD_32; goto error;
break;
case GUARD_INTERVAL_1_16: case GUARD_INTERVAL_1_16:
transmissionParams |= transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_GUARD_16;
OFDM_SC_RA_RAM_OP_PARAM_GUARD_16; goto error;
break;
case GUARD_INTERVAL_1_8: case GUARD_INTERVAL_1_8:
transmissionParams |= transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_GUARD_8;
OFDM_SC_RA_RAM_OP_PARAM_GUARD_8; goto error;
break;
} }
/* hierarchy */ /* hierarchy */
...@@ -3827,16 +3856,13 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz, ...@@ -3827,16 +3856,13 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz,
/* transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_HIER_NO; */ /* transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_HIER_NO; */
/* break; */ /* break; */
case HIERARCHY_1: case HIERARCHY_1:
transmissionParams |= transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_HIER_A1;
OFDM_SC_RA_RAM_OP_PARAM_HIER_A1;
break; break;
case HIERARCHY_2: case HIERARCHY_2:
transmissionParams |= transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_HIER_A2;
OFDM_SC_RA_RAM_OP_PARAM_HIER_A2;
break; break;
case HIERARCHY_4: case HIERARCHY_4:
transmissionParams |= transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_HIER_A4;
OFDM_SC_RA_RAM_OP_PARAM_HIER_A4;
break; break;
} }
...@@ -3848,16 +3874,13 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz, ...@@ -3848,16 +3874,13 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz,
operationMode |= OFDM_SC_RA_RAM_OP_AUTO_CONST__M; operationMode |= OFDM_SC_RA_RAM_OP_AUTO_CONST__M;
/* fall through , try first guess DRX_CONSTELLATION_QAM64 */ /* fall through , try first guess DRX_CONSTELLATION_QAM64 */
case QAM_64: case QAM_64:
transmissionParams |= transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_CONST_QAM64;
OFDM_SC_RA_RAM_OP_PARAM_CONST_QAM64;
break; break;
case QPSK: case QPSK:
transmissionParams |= transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_CONST_QPSK;
OFDM_SC_RA_RAM_OP_PARAM_CONST_QPSK;
break; break;
case QAM_16: case QAM_16:
transmissionParams |= transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_CONST_QAM16;
OFDM_SC_RA_RAM_OP_PARAM_CONST_QAM16;
break; break;
} }
#if 0 #if 0
...@@ -3865,28 +3888,26 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz, ...@@ -3865,28 +3888,26 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz,
/* Priority (only for hierarchical channels) */ /* Priority (only for hierarchical channels) */
switch (channel->priority) { switch (channel->priority) {
case DRX_PRIORITY_LOW: case DRX_PRIORITY_LOW:
transmissionParams |= transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_PRIO_LO;
OFDM_SC_RA_RAM_OP_PARAM_PRIO_LO;
WR16(devAddr, OFDM_EC_SB_PRIOR__A, WR16(devAddr, OFDM_EC_SB_PRIOR__A,
OFDM_EC_SB_PRIOR_LO); OFDM_EC_SB_PRIOR_LO);
break; break;
case DRX_PRIORITY_HIGH: case DRX_PRIORITY_HIGH:
transmissionParams |= transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_PRIO_HI;
OFDM_SC_RA_RAM_OP_PARAM_PRIO_HI;
WR16(devAddr, OFDM_EC_SB_PRIOR__A, WR16(devAddr, OFDM_EC_SB_PRIOR__A,
OFDM_EC_SB_PRIOR_HI)); OFDM_EC_SB_PRIOR_HI));
break; break;
case DRX_PRIORITY_UNKNOWN: /* fall through */ case DRX_PRIORITY_UNKNOWN: /* fall through */
default: default:
return DRX_STS_INVALID_ARG; status = -EINVAL;
break; goto error;
} }
#else #else
/* Set Priorty high */ /* Set Priorty high */
transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_PRIO_HI; transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_PRIO_HI;
status = write16(state, OFDM_EC_SB_PRIOR__A, OFDM_EC_SB_PRIOR_HI); status = write16(state, OFDM_EC_SB_PRIOR__A, OFDM_EC_SB_PRIOR_HI);
if (status < 0) if (status < 0)
break; goto error;
#endif #endif
/* coderate */ /* coderate */
...@@ -3896,24 +3917,19 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz, ...@@ -3896,24 +3917,19 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz,
operationMode |= OFDM_SC_RA_RAM_OP_AUTO_RATE__M; operationMode |= OFDM_SC_RA_RAM_OP_AUTO_RATE__M;
/* fall through , try first guess DRX_CODERATE_2DIV3 */ /* fall through , try first guess DRX_CODERATE_2DIV3 */
case FEC_2_3: case FEC_2_3:
transmissionParams |= transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_RATE_2_3;
OFDM_SC_RA_RAM_OP_PARAM_RATE_2_3;
break; break;
case FEC_1_2: case FEC_1_2:
transmissionParams |= transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_RATE_1_2;
OFDM_SC_RA_RAM_OP_PARAM_RATE_1_2;
break; break;
case FEC_3_4: case FEC_3_4:
transmissionParams |= transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_RATE_3_4;
OFDM_SC_RA_RAM_OP_PARAM_RATE_3_4;
break; break;
case FEC_5_6: case FEC_5_6:
transmissionParams |= transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_RATE_5_6;
OFDM_SC_RA_RAM_OP_PARAM_RATE_5_6;
break; break;
case FEC_7_8: case FEC_7_8:
transmissionParams |= transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_RATE_7_8;
OFDM_SC_RA_RAM_OP_PARAM_RATE_7_8;
break; break;
} }
...@@ -3930,61 +3946,62 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz, ...@@ -3930,61 +3946,62 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz,
bandwidth = DRXK_BANDWIDTH_8MHZ_IN_HZ; bandwidth = DRXK_BANDWIDTH_8MHZ_IN_HZ;
status = write16(state, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A, 3052); status = write16(state, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A, 3052);
if (status < 0) if (status < 0)
break; goto error;
/* cochannel protection for PAL 8 MHz */ /* cochannel protection for PAL 8 MHz */
status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A, 7); status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A, 7);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A, 7); status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A, 7);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A, 7); status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A, 7);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A, 1); status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A, 1);
if (status < 0) if (status < 0)
break; goto error;
break; break;
case BANDWIDTH_7_MHZ: case BANDWIDTH_7_MHZ:
bandwidth = DRXK_BANDWIDTH_7MHZ_IN_HZ; bandwidth = DRXK_BANDWIDTH_7MHZ_IN_HZ;
status = write16(state, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A, 3491); status = write16(state, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A, 3491);
if (status < 0) if (status < 0)
break; goto error;
/* cochannel protection for PAL 7 MHz */ /* cochannel protection for PAL 7 MHz */
status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A, 8); status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A, 8);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A, 8); status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A, 8);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A, 4); status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A, 4);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A, 1); status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A, 1);
if (status < 0) if (status < 0)
break; goto error;
break; break;
case BANDWIDTH_6_MHZ: case BANDWIDTH_6_MHZ:
bandwidth = DRXK_BANDWIDTH_6MHZ_IN_HZ; bandwidth = DRXK_BANDWIDTH_6MHZ_IN_HZ;
status = write16(state, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A, 4073); status = write16(state, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A, 4073);
if (status < 0) if (status < 0)
break; goto error;
/* cochannel protection for NTSC 6 MHz */ /* cochannel protection for NTSC 6 MHz */
status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A, 19); status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A, 19);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A, 19); status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A, 19);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A, 14); status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A, 14);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A, 1); status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A, 1);
if (status < 0) if (status < 0)
break; goto error;
break; break;
default: default:
return -EINVAL; status = -EINVAL;
goto error;
} }
if (iqmRcRateOfs == 0) { if (iqmRcRateOfs == 0) {
...@@ -4013,38 +4030,38 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz, ...@@ -4013,38 +4030,38 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz,
IQM_RC_RATE_OFS_LO__W) | IQM_RC_RATE_OFS_LO__M); IQM_RC_RATE_OFS_LO__W) | IQM_RC_RATE_OFS_LO__M);
status = write32(state, IQM_RC_RATE_OFS_LO__A, iqmRcRateOfs); status = write32(state, IQM_RC_RATE_OFS_LO__A, iqmRcRateOfs);
if (status < 0) if (status < 0)
break; goto error;
/* Bandwidth setting done */ /* Bandwidth setting done */
#if 0 #if 0
status = DVBTSetFrequencyShift(demod, channel, tunerOffset); status = DVBTSetFrequencyShift(demod, channel, tunerOffset);
if (status < 0) if (status < 0)
break; goto error;
#endif #endif
status = SetFrequencyShifter(state, IntermediateFreqkHz, tunerFreqOffset, true); status = SetFrequencyShifter(state, IntermediateFreqkHz, tunerFreqOffset, true);
if (status < 0) if (status < 0)
break; goto error;
/*== Start SC, write channel settings to SC ===============================*/ /*== Start SC, write channel settings to SC ===============================*/
/* Activate SCU to enable SCU commands */ /* Activate SCU to enable SCU commands */
status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE);
if (status < 0) if (status < 0)
break; goto error;
/* Enable SC after setting all other parameters */ /* Enable SC after setting all other parameters */
status = write16(state, OFDM_SC_COMM_STATE__A, 0); status = write16(state, OFDM_SC_COMM_STATE__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, OFDM_SC_COMM_EXEC__A, 1); status = write16(state, OFDM_SC_COMM_EXEC__A, 1);
if (status < 0) if (status < 0)
break; goto error;
status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_START, 0, NULL, 1, &cmdResult); status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_START, 0, NULL, 1, &cmdResult);
if (status < 0) if (status < 0)
break; goto error;
/* Write SC parameter registers, set all AUTO flags in operation mode */ /* Write SC parameter registers, set all AUTO flags in operation mode */
param1 = (OFDM_SC_RA_RAM_OP_AUTO_MODE__M | param1 = (OFDM_SC_RA_RAM_OP_AUTO_MODE__M |
...@@ -4052,15 +4069,16 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz, ...@@ -4052,15 +4069,16 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz,
OFDM_SC_RA_RAM_OP_AUTO_CONST__M | OFDM_SC_RA_RAM_OP_AUTO_CONST__M |
OFDM_SC_RA_RAM_OP_AUTO_HIER__M | OFDM_SC_RA_RAM_OP_AUTO_HIER__M |
OFDM_SC_RA_RAM_OP_AUTO_RATE__M); OFDM_SC_RA_RAM_OP_AUTO_RATE__M);
status = status = DVBTScCommand(state, OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM,
DVBTScCommand(state, OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM,
0, transmissionParams, param1, 0, 0, 0); 0, transmissionParams, param1, 0, 0, 0);
if (status < 0)
goto error;
if (!state->m_DRXK_A3_ROM_CODE) if (!state->m_DRXK_A3_ROM_CODE)
status = DVBTCtrlSetSqiSpeed(state, &state->m_sqiSpeed); status = DVBTCtrlSetSqiSpeed(state, &state->m_sqiSpeed);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
...@@ -4088,16 +4106,18 @@ static int GetDVBTLockStatus(struct drxk_state *state, u32 *pLockStatus) ...@@ -4088,16 +4106,18 @@ static int GetDVBTLockStatus(struct drxk_state *state, u32 *pLockStatus)
dprintk(1, "\n"); dprintk(1, "\n");
*pLockStatus = NOT_LOCKED;
/* driver 0.9.0 */ /* driver 0.9.0 */
/* Check if SC is running */ /* Check if SC is running */
status = read16(state, OFDM_SC_COMM_EXEC__A, &ScCommExec); status = read16(state, OFDM_SC_COMM_EXEC__A, &ScCommExec);
if (ScCommExec == OFDM_SC_COMM_EXEC_STOP) { if (status < 0)
/* SC not active; return DRX_NOT_LOCKED */ goto end;
*pLockStatus = NOT_LOCKED; if (ScCommExec == OFDM_SC_COMM_EXEC_STOP)
return status; goto end;
}
status = read16(state, OFDM_SC_RA_RAM_LOCK__A, &ScRaRamLock); status = read16(state, OFDM_SC_RA_RAM_LOCK__A, &ScRaRamLock);
if (status < 0)
goto end;
if ((ScRaRamLock & mpeg_lock_mask) == mpeg_lock_mask) if ((ScRaRamLock & mpeg_lock_mask) == mpeg_lock_mask)
*pLockStatus = MPEG_LOCK; *pLockStatus = MPEG_LOCK;
...@@ -4107,8 +4127,9 @@ static int GetDVBTLockStatus(struct drxk_state *state, u32 *pLockStatus) ...@@ -4107,8 +4127,9 @@ static int GetDVBTLockStatus(struct drxk_state *state, u32 *pLockStatus)
*pLockStatus = DEMOD_LOCK; *pLockStatus = DEMOD_LOCK;
else if (ScRaRamLock & OFDM_SC_RA_RAM_LOCK_NODVBT__M) else if (ScRaRamLock & OFDM_SC_RA_RAM_LOCK_NODVBT__M)
*pLockStatus = NEVER_LOCK; *pLockStatus = NEVER_LOCK;
else end:
*pLockStatus = NOT_LOCKED; if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -4116,15 +4137,12 @@ static int GetDVBTLockStatus(struct drxk_state *state, u32 *pLockStatus) ...@@ -4116,15 +4137,12 @@ static int GetDVBTLockStatus(struct drxk_state *state, u32 *pLockStatus)
static int PowerUpQAM(struct drxk_state *state) static int PowerUpQAM(struct drxk_state *state)
{ {
enum DRXPowerMode powerMode = DRXK_POWER_DOWN_OFDM; enum DRXPowerMode powerMode = DRXK_POWER_DOWN_OFDM;
int status = 0; int status;
dprintk(1, "\n"); dprintk(1, "\n");
do {
status = CtrlPowerMode(state, &powerMode); status = CtrlPowerMode(state, &powerMode);
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
...@@ -4138,10 +4156,9 @@ static int PowerDownQAM(struct drxk_state *state) ...@@ -4138,10 +4156,9 @@ static int PowerDownQAM(struct drxk_state *state)
int status = 0; int status = 0;
dprintk(1, "\n"); dprintk(1, "\n");
do {
status = read16(state, SCU_COMM_EXEC__A, &data); status = read16(state, SCU_COMM_EXEC__A, &data);
if (status < 0) if (status < 0)
break; goto error;
if (data == SCU_COMM_EXEC_ACTIVE) { if (data == SCU_COMM_EXEC_ACTIVE) {
/* /*
STOP demodulator STOP demodulator
...@@ -4150,16 +4167,17 @@ static int PowerDownQAM(struct drxk_state *state) ...@@ -4150,16 +4167,17 @@ static int PowerDownQAM(struct drxk_state *state)
/* stop all comstate->m_exec */ /* stop all comstate->m_exec */
status = write16(state, QAM_COMM_EXEC__A, QAM_COMM_EXEC_STOP); status = write16(state, QAM_COMM_EXEC__A, QAM_COMM_EXEC_STOP);
if (status < 0) if (status < 0)
break; goto error;
status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_STOP, 0, NULL, 1, &cmdResult); status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_STOP, 0, NULL, 1, &cmdResult);
if (status < 0) if (status < 0)
break; goto error;
} }
/* powerdown AFE */ /* powerdown AFE */
status = SetIqmAf(state, false); status = SetIqmAf(state, false);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
...@@ -4190,8 +4208,6 @@ static int SetQAMMeasurement(struct drxk_state *state, ...@@ -4190,8 +4208,6 @@ static int SetQAMMeasurement(struct drxk_state *state,
dprintk(1, "\n"); dprintk(1, "\n");
fecRsPrescale = 1; fecRsPrescale = 1;
do {
/* fecBitsDesired = symbolRate [kHz] * /* fecBitsDesired = symbolRate [kHz] *
FrameLenght [ms] * FrameLenght [ms] *
(constellation + 1) * (constellation + 1) *
...@@ -4217,9 +4233,8 @@ static int SetQAMMeasurement(struct drxk_state *state, ...@@ -4217,9 +4233,8 @@ static int SetQAMMeasurement(struct drxk_state *state,
default: default:
status = -EINVAL; status = -EINVAL;
} }
status = status;
if (status < 0) if (status < 0)
break; goto error;
fecBitsDesired /= 1000; /* symbolRate [Hz] -> symbolRate [kHz] */ fecBitsDesired /= 1000; /* symbolRate [Hz] -> symbolRate [kHz] */
fecBitsDesired *= 500; /* meas. period [ms] */ fecBitsDesired *= 500; /* meas. period [ms] */
...@@ -4232,11 +4247,10 @@ static int SetQAMMeasurement(struct drxk_state *state, ...@@ -4232,11 +4247,10 @@ static int SetQAMMeasurement(struct drxk_state *state,
fecRsPrescale = 1 + (u16) (fecRsPeriodTotal >> 16); fecRsPrescale = 1 + (u16) (fecRsPeriodTotal >> 16);
if (fecRsPrescale == 0) { if (fecRsPrescale == 0) {
/* Divide by zero (though impossible) */ /* Divide by zero (though impossible) */
status = -1; status = -EINVAL;
}
status = status;
if (status < 0) if (status < 0)
break; goto error;
}
fecRsPeriod = fecRsPeriod =
((u16) fecRsPeriodTotal + ((u16) fecRsPeriodTotal +
(fecRsPrescale >> 1)) / fecRsPrescale; (fecRsPrescale >> 1)) / fecRsPrescale;
...@@ -4244,19 +4258,14 @@ static int SetQAMMeasurement(struct drxk_state *state, ...@@ -4244,19 +4258,14 @@ static int SetQAMMeasurement(struct drxk_state *state,
/* write corresponding registers */ /* write corresponding registers */
status = write16(state, FEC_RS_MEASUREMENT_PERIOD__A, fecRsPeriod); status = write16(state, FEC_RS_MEASUREMENT_PERIOD__A, fecRsPeriod);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_RS_MEASUREMENT_PRESCALE__A, fecRsPrescale); status = write16(state, FEC_RS_MEASUREMENT_PRESCALE__A, fecRsPrescale);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_OC_SNC_FAIL_PERIOD__A, fecRsPeriod); status = write16(state, FEC_OC_SNC_FAIL_PERIOD__A, fecRsPeriod);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
if (status < 0)
printk(KERN_ERR "drxk: %s: status - %08x\n", __func__, status);
return status; return status;
} }
...@@ -4265,183 +4274,184 @@ static int SetQAM16(struct drxk_state *state) ...@@ -4265,183 +4274,184 @@ static int SetQAM16(struct drxk_state *state)
int status = 0; int status = 0;
dprintk(1, "\n"); dprintk(1, "\n");
do {
/* QAM Equalizer Setup */ /* QAM Equalizer Setup */
/* Equalizer */ /* Equalizer */
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 13517); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 13517);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD1__A, 13517); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD1__A, 13517);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD2__A, 13517); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD2__A, 13517);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD3__A, 13517); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD3__A, 13517);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD4__A, 13517); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD4__A, 13517);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 13517); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 13517);
if (status < 0) if (status < 0)
break; goto error;
/* Decision Feedback Equalizer */ /* Decision Feedback Equalizer */
status = write16(state, QAM_DQ_QUAL_FUN0__A, 2); status = write16(state, QAM_DQ_QUAL_FUN0__A, 2);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN1__A, 2); status = write16(state, QAM_DQ_QUAL_FUN1__A, 2);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN2__A, 2); status = write16(state, QAM_DQ_QUAL_FUN2__A, 2);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN3__A, 2); status = write16(state, QAM_DQ_QUAL_FUN3__A, 2);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN4__A, 2); status = write16(state, QAM_DQ_QUAL_FUN4__A, 2);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN5__A, 0); status = write16(state, QAM_DQ_QUAL_FUN5__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_SY_SYNC_HWM__A, 5); status = write16(state, QAM_SY_SYNC_HWM__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_SY_SYNC_AWM__A, 4); status = write16(state, QAM_SY_SYNC_AWM__A, 4);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_SY_SYNC_LWM__A, 3); status = write16(state, QAM_SY_SYNC_LWM__A, 3);
if (status < 0) if (status < 0)
break; goto error;
/* QAM Slicer Settings */ /* QAM Slicer Settings */
status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, DRXK_QAM_SL_SIG_POWER_QAM16); status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, DRXK_QAM_SL_SIG_POWER_QAM16);
if (status < 0) if (status < 0)
break; goto error;
/* QAM Loop Controller Coeficients */ /* QAM Loop Controller Coeficients */
status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15); status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CA_COARSE__A, 40); status = write16(state, SCU_RAM_QAM_LC_CA_COARSE__A, 40);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EP_FINE__A, 12); status = write16(state, SCU_RAM_QAM_LC_EP_FINE__A, 12);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24); status = write16(state, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EP_COARSE__A, 24); status = write16(state, SCU_RAM_QAM_LC_EP_COARSE__A, 24);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EI_FINE__A, 12); status = write16(state, SCU_RAM_QAM_LC_EI_FINE__A, 12);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16); status = write16(state, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16); status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5); status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CP_MEDIUM__A, 20); status = write16(state, SCU_RAM_QAM_LC_CP_MEDIUM__A, 20);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CP_COARSE__A, 80); status = write16(state, SCU_RAM_QAM_LC_CP_COARSE__A, 80);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CI_FINE__A, 5); status = write16(state, SCU_RAM_QAM_LC_CI_FINE__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CI_MEDIUM__A, 20); status = write16(state, SCU_RAM_QAM_LC_CI_MEDIUM__A, 20);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CI_COARSE__A, 50); status = write16(state, SCU_RAM_QAM_LC_CI_COARSE__A, 50);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF_FINE__A, 16); status = write16(state, SCU_RAM_QAM_LC_CF_FINE__A, 16);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF_MEDIUM__A, 16); status = write16(state, SCU_RAM_QAM_LC_CF_MEDIUM__A, 16);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF_COARSE__A, 32); status = write16(state, SCU_RAM_QAM_LC_CF_COARSE__A, 32);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF1_FINE__A, 5); status = write16(state, SCU_RAM_QAM_LC_CF1_FINE__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 10); status = write16(state, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 10);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 10); status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 10);
if (status < 0) if (status < 0)
break; goto error;
/* QAM State Machine (FSM) Thresholds */ /* QAM State Machine (FSM) Thresholds */
status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 140); status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 140);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_FTH__A, 50); status = write16(state, SCU_RAM_QAM_FSM_FTH__A, 50);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_CTH__A, 95); status = write16(state, SCU_RAM_QAM_FSM_CTH__A, 95);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_PTH__A, 120); status = write16(state, SCU_RAM_QAM_FSM_PTH__A, 120);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_QTH__A, 230); status = write16(state, SCU_RAM_QAM_FSM_QTH__A, 230);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 105); status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 105);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40); status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_COUNT_LIM__A, 4); status = write16(state, SCU_RAM_QAM_FSM_COUNT_LIM__A, 4);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 24); status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 24);
if (status < 0) if (status < 0)
break; goto error;
/* QAM FSM Tracking Parameters */ /* QAM FSM Tracking Parameters */
status = write16(state, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, (u16) 16); status = write16(state, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, (u16) 16);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, (u16) 220); status = write16(state, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, (u16) 220);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16) 25); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16) 25);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16) 6); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16) 6);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16) -24); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16) -24);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16) -65); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16) -65);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -127); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -127);
if (status < 0) if (status < 0)
break; goto error;
} while (0);
error:
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -4457,187 +4467,186 @@ static int SetQAM32(struct drxk_state *state) ...@@ -4457,187 +4467,186 @@ static int SetQAM32(struct drxk_state *state)
int status = 0; int status = 0;
dprintk(1, "\n"); dprintk(1, "\n");
do {
/* QAM Equalizer Setup */ /* QAM Equalizer Setup */
/* Equalizer */ /* Equalizer */
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 6707); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 6707);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD1__A, 6707); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD1__A, 6707);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD2__A, 6707); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD2__A, 6707);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD3__A, 6707); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD3__A, 6707);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD4__A, 6707); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD4__A, 6707);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 6707); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 6707);
if (status < 0) if (status < 0)
break; goto error;
/* Decision Feedback Equalizer */ /* Decision Feedback Equalizer */
status = write16(state, QAM_DQ_QUAL_FUN0__A, 3); status = write16(state, QAM_DQ_QUAL_FUN0__A, 3);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN1__A, 3); status = write16(state, QAM_DQ_QUAL_FUN1__A, 3);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN2__A, 3); status = write16(state, QAM_DQ_QUAL_FUN2__A, 3);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN3__A, 3); status = write16(state, QAM_DQ_QUAL_FUN3__A, 3);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN4__A, 3); status = write16(state, QAM_DQ_QUAL_FUN4__A, 3);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN5__A, 0); status = write16(state, QAM_DQ_QUAL_FUN5__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_SY_SYNC_HWM__A, 6); status = write16(state, QAM_SY_SYNC_HWM__A, 6);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_SY_SYNC_AWM__A, 5); status = write16(state, QAM_SY_SYNC_AWM__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_SY_SYNC_LWM__A, 3); status = write16(state, QAM_SY_SYNC_LWM__A, 3);
if (status < 0) if (status < 0)
break; goto error;
/* QAM Slicer Settings */ /* QAM Slicer Settings */
status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, DRXK_QAM_SL_SIG_POWER_QAM32); status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, DRXK_QAM_SL_SIG_POWER_QAM32);
if (status < 0) if (status < 0)
break; goto error;
/* QAM Loop Controller Coeficients */ /* QAM Loop Controller Coeficients */
status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15); status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CA_COARSE__A, 40); status = write16(state, SCU_RAM_QAM_LC_CA_COARSE__A, 40);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EP_FINE__A, 12); status = write16(state, SCU_RAM_QAM_LC_EP_FINE__A, 12);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24); status = write16(state, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EP_COARSE__A, 24); status = write16(state, SCU_RAM_QAM_LC_EP_COARSE__A, 24);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EI_FINE__A, 12); status = write16(state, SCU_RAM_QAM_LC_EI_FINE__A, 12);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16); status = write16(state, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16); status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5); status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CP_MEDIUM__A, 20); status = write16(state, SCU_RAM_QAM_LC_CP_MEDIUM__A, 20);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CP_COARSE__A, 80); status = write16(state, SCU_RAM_QAM_LC_CP_COARSE__A, 80);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CI_FINE__A, 5); status = write16(state, SCU_RAM_QAM_LC_CI_FINE__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CI_MEDIUM__A, 20); status = write16(state, SCU_RAM_QAM_LC_CI_MEDIUM__A, 20);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CI_COARSE__A, 50); status = write16(state, SCU_RAM_QAM_LC_CI_COARSE__A, 50);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF_FINE__A, 16); status = write16(state, SCU_RAM_QAM_LC_CF_FINE__A, 16);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF_MEDIUM__A, 16); status = write16(state, SCU_RAM_QAM_LC_CF_MEDIUM__A, 16);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF_COARSE__A, 16); status = write16(state, SCU_RAM_QAM_LC_CF_COARSE__A, 16);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF1_FINE__A, 5); status = write16(state, SCU_RAM_QAM_LC_CF1_FINE__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 10); status = write16(state, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 10);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 0); status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 0);
if (status < 0) if (status < 0)
break; goto error;
/* QAM State Machine (FSM) Thresholds */ /* QAM State Machine (FSM) Thresholds */
status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 90); status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 90);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_FTH__A, 50); status = write16(state, SCU_RAM_QAM_FSM_FTH__A, 50);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_CTH__A, 80); status = write16(state, SCU_RAM_QAM_FSM_CTH__A, 80);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_PTH__A, 100); status = write16(state, SCU_RAM_QAM_FSM_PTH__A, 100);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_QTH__A, 170); status = write16(state, SCU_RAM_QAM_FSM_QTH__A, 170);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 100); status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 100);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40); status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_COUNT_LIM__A, 4); status = write16(state, SCU_RAM_QAM_FSM_COUNT_LIM__A, 4);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 10); status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 10);
if (status < 0) if (status < 0)
break; goto error;
/* QAM FSM Tracking Parameters */ /* QAM FSM Tracking Parameters */
status = write16(state, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, (u16) 12); status = write16(state, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, (u16) 12);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, (u16) 140); status = write16(state, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, (u16) 140);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16) -8); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16) -8);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16) -16); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16) -16);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16) -26); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16) -26);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16) -56); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16) -56);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -86); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -86);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
...@@ -4653,185 +4662,184 @@ static int SetQAM64(struct drxk_state *state) ...@@ -4653,185 +4662,184 @@ static int SetQAM64(struct drxk_state *state)
int status = 0; int status = 0;
dprintk(1, "\n"); dprintk(1, "\n");
do {
/* QAM Equalizer Setup */ /* QAM Equalizer Setup */
/* Equalizer */ /* Equalizer */
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 13336); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 13336);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD1__A, 12618); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD1__A, 12618);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD2__A, 11988); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD2__A, 11988);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD3__A, 13809); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD3__A, 13809);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD4__A, 13809); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD4__A, 13809);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 15609); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 15609);
if (status < 0) if (status < 0)
break; goto error;
/* Decision Feedback Equalizer */ /* Decision Feedback Equalizer */
status = write16(state, QAM_DQ_QUAL_FUN0__A, 4); status = write16(state, QAM_DQ_QUAL_FUN0__A, 4);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN1__A, 4); status = write16(state, QAM_DQ_QUAL_FUN1__A, 4);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN2__A, 4); status = write16(state, QAM_DQ_QUAL_FUN2__A, 4);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN3__A, 4); status = write16(state, QAM_DQ_QUAL_FUN3__A, 4);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN4__A, 3); status = write16(state, QAM_DQ_QUAL_FUN4__A, 3);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN5__A, 0); status = write16(state, QAM_DQ_QUAL_FUN5__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_SY_SYNC_HWM__A, 5); status = write16(state, QAM_SY_SYNC_HWM__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_SY_SYNC_AWM__A, 4); status = write16(state, QAM_SY_SYNC_AWM__A, 4);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_SY_SYNC_LWM__A, 3); status = write16(state, QAM_SY_SYNC_LWM__A, 3);
if (status < 0) if (status < 0)
break; goto error;
/* QAM Slicer Settings */ /* QAM Slicer Settings */
status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, DRXK_QAM_SL_SIG_POWER_QAM64); status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, DRXK_QAM_SL_SIG_POWER_QAM64);
if (status < 0) if (status < 0)
break; goto error;
/* QAM Loop Controller Coeficients */ /* QAM Loop Controller Coeficients */
status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15); status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CA_COARSE__A, 40); status = write16(state, SCU_RAM_QAM_LC_CA_COARSE__A, 40);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EP_FINE__A, 12); status = write16(state, SCU_RAM_QAM_LC_EP_FINE__A, 12);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24); status = write16(state, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EP_COARSE__A, 24); status = write16(state, SCU_RAM_QAM_LC_EP_COARSE__A, 24);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EI_FINE__A, 12); status = write16(state, SCU_RAM_QAM_LC_EI_FINE__A, 12);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16); status = write16(state, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16); status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5); status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CP_MEDIUM__A, 30); status = write16(state, SCU_RAM_QAM_LC_CP_MEDIUM__A, 30);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CP_COARSE__A, 100); status = write16(state, SCU_RAM_QAM_LC_CP_COARSE__A, 100);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CI_FINE__A, 5); status = write16(state, SCU_RAM_QAM_LC_CI_FINE__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CI_MEDIUM__A, 30); status = write16(state, SCU_RAM_QAM_LC_CI_MEDIUM__A, 30);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CI_COARSE__A, 50); status = write16(state, SCU_RAM_QAM_LC_CI_COARSE__A, 50);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF_FINE__A, 16); status = write16(state, SCU_RAM_QAM_LC_CF_FINE__A, 16);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF_MEDIUM__A, 25); status = write16(state, SCU_RAM_QAM_LC_CF_MEDIUM__A, 25);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF_COARSE__A, 48); status = write16(state, SCU_RAM_QAM_LC_CF_COARSE__A, 48);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF1_FINE__A, 5); status = write16(state, SCU_RAM_QAM_LC_CF1_FINE__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 10); status = write16(state, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 10);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 10); status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 10);
if (status < 0) if (status < 0)
break; goto error;
/* QAM State Machine (FSM) Thresholds */ /* QAM State Machine (FSM) Thresholds */
status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 100); status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 100);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_FTH__A, 60); status = write16(state, SCU_RAM_QAM_FSM_FTH__A, 60);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_CTH__A, 80); status = write16(state, SCU_RAM_QAM_FSM_CTH__A, 80);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_PTH__A, 110); status = write16(state, SCU_RAM_QAM_FSM_PTH__A, 110);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_QTH__A, 200); status = write16(state, SCU_RAM_QAM_FSM_QTH__A, 200);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 95); status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 95);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40); status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_COUNT_LIM__A, 4); status = write16(state, SCU_RAM_QAM_FSM_COUNT_LIM__A, 4);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 15); status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 15);
if (status < 0) if (status < 0)
break; goto error;
/* QAM FSM Tracking Parameters */ /* QAM FSM Tracking Parameters */
status = write16(state, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, (u16) 12); status = write16(state, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, (u16) 12);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, (u16) 141); status = write16(state, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, (u16) 141);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16) 7); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16) 7);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16) 0); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16) 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16) -15); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16) -15);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16) -45); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16) -45);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -80); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -80);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
...@@ -4848,187 +4856,186 @@ static int SetQAM128(struct drxk_state *state) ...@@ -4848,187 +4856,186 @@ static int SetQAM128(struct drxk_state *state)
int status = 0; int status = 0;
dprintk(1, "\n"); dprintk(1, "\n");
do {
/* QAM Equalizer Setup */ /* QAM Equalizer Setup */
/* Equalizer */ /* Equalizer */
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 6564); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 6564);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD1__A, 6598); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD1__A, 6598);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD2__A, 6394); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD2__A, 6394);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD3__A, 6409); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD3__A, 6409);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD4__A, 6656); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD4__A, 6656);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 7238); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 7238);
if (status < 0) if (status < 0)
break; goto error;
/* Decision Feedback Equalizer */ /* Decision Feedback Equalizer */
status = write16(state, QAM_DQ_QUAL_FUN0__A, 6); status = write16(state, QAM_DQ_QUAL_FUN0__A, 6);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN1__A, 6); status = write16(state, QAM_DQ_QUAL_FUN1__A, 6);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN2__A, 6); status = write16(state, QAM_DQ_QUAL_FUN2__A, 6);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN3__A, 6); status = write16(state, QAM_DQ_QUAL_FUN3__A, 6);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN4__A, 5); status = write16(state, QAM_DQ_QUAL_FUN4__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN5__A, 0); status = write16(state, QAM_DQ_QUAL_FUN5__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_SY_SYNC_HWM__A, 6); status = write16(state, QAM_SY_SYNC_HWM__A, 6);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_SY_SYNC_AWM__A, 5); status = write16(state, QAM_SY_SYNC_AWM__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_SY_SYNC_LWM__A, 3); status = write16(state, QAM_SY_SYNC_LWM__A, 3);
if (status < 0) if (status < 0)
break; goto error;
/* QAM Slicer Settings */ /* QAM Slicer Settings */
status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, DRXK_QAM_SL_SIG_POWER_QAM128); status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, DRXK_QAM_SL_SIG_POWER_QAM128);
if (status < 0) if (status < 0)
break; goto error;
/* QAM Loop Controller Coeficients */ /* QAM Loop Controller Coeficients */
status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15); status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CA_COARSE__A, 40); status = write16(state, SCU_RAM_QAM_LC_CA_COARSE__A, 40);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EP_FINE__A, 12); status = write16(state, SCU_RAM_QAM_LC_EP_FINE__A, 12);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24); status = write16(state, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EP_COARSE__A, 24); status = write16(state, SCU_RAM_QAM_LC_EP_COARSE__A, 24);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EI_FINE__A, 12); status = write16(state, SCU_RAM_QAM_LC_EI_FINE__A, 12);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16); status = write16(state, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16); status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5); status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CP_MEDIUM__A, 40); status = write16(state, SCU_RAM_QAM_LC_CP_MEDIUM__A, 40);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CP_COARSE__A, 120); status = write16(state, SCU_RAM_QAM_LC_CP_COARSE__A, 120);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CI_FINE__A, 5); status = write16(state, SCU_RAM_QAM_LC_CI_FINE__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CI_MEDIUM__A, 40); status = write16(state, SCU_RAM_QAM_LC_CI_MEDIUM__A, 40);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CI_COARSE__A, 60); status = write16(state, SCU_RAM_QAM_LC_CI_COARSE__A, 60);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF_FINE__A, 16); status = write16(state, SCU_RAM_QAM_LC_CF_FINE__A, 16);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF_MEDIUM__A, 25); status = write16(state, SCU_RAM_QAM_LC_CF_MEDIUM__A, 25);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF_COARSE__A, 64); status = write16(state, SCU_RAM_QAM_LC_CF_COARSE__A, 64);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF1_FINE__A, 5); status = write16(state, SCU_RAM_QAM_LC_CF1_FINE__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 10); status = write16(state, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 10);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 0); status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 0);
if (status < 0) if (status < 0)
break; goto error;
/* QAM State Machine (FSM) Thresholds */ /* QAM State Machine (FSM) Thresholds */
status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 50); status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 50);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_FTH__A, 60); status = write16(state, SCU_RAM_QAM_FSM_FTH__A, 60);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_CTH__A, 80); status = write16(state, SCU_RAM_QAM_FSM_CTH__A, 80);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_PTH__A, 100); status = write16(state, SCU_RAM_QAM_FSM_PTH__A, 100);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_QTH__A, 140); status = write16(state, SCU_RAM_QAM_FSM_QTH__A, 140);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 100); status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 100);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40); status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_COUNT_LIM__A, 5); status = write16(state, SCU_RAM_QAM_FSM_COUNT_LIM__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 12); status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 12);
if (status < 0) if (status < 0)
break; goto error;
/* QAM FSM Tracking Parameters */ /* QAM FSM Tracking Parameters */
status = write16(state, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, (u16) 8); status = write16(state, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, (u16) 8);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, (u16) 65); status = write16(state, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, (u16) 65);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16) 5); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16) 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16) 3); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16) 3);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16) -1); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16) -1);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16) -12); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16) -12);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -23); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -23);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
...@@ -5045,187 +5052,185 @@ static int SetQAM256(struct drxk_state *state) ...@@ -5045,187 +5052,185 @@ static int SetQAM256(struct drxk_state *state)
int status = 0; int status = 0;
dprintk(1, "\n"); dprintk(1, "\n");
do {
/* QAM Equalizer Setup */ /* QAM Equalizer Setup */
/* Equalizer */ /* Equalizer */
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 11502); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD0__A, 11502);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD1__A, 12084); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD1__A, 12084);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD2__A, 12543); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD2__A, 12543);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD3__A, 12931); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD3__A, 12931);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD4__A, 13629); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD4__A, 13629);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 15385); status = write16(state, SCU_RAM_QAM_EQ_CMA_RAD5__A, 15385);
if (status < 0) if (status < 0)
break; goto error;
/* Decision Feedback Equalizer */ /* Decision Feedback Equalizer */
status = write16(state, QAM_DQ_QUAL_FUN0__A, 8); status = write16(state, QAM_DQ_QUAL_FUN0__A, 8);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN1__A, 8); status = write16(state, QAM_DQ_QUAL_FUN1__A, 8);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN2__A, 8); status = write16(state, QAM_DQ_QUAL_FUN2__A, 8);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN3__A, 8); status = write16(state, QAM_DQ_QUAL_FUN3__A, 8);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN4__A, 6); status = write16(state, QAM_DQ_QUAL_FUN4__A, 6);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_DQ_QUAL_FUN5__A, 0); status = write16(state, QAM_DQ_QUAL_FUN5__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_SY_SYNC_HWM__A, 5); status = write16(state, QAM_SY_SYNC_HWM__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_SY_SYNC_AWM__A, 4); status = write16(state, QAM_SY_SYNC_AWM__A, 4);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_SY_SYNC_LWM__A, 3); status = write16(state, QAM_SY_SYNC_LWM__A, 3);
if (status < 0) if (status < 0)
break; goto error;
/* QAM Slicer Settings */ /* QAM Slicer Settings */
status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, DRXK_QAM_SL_SIG_POWER_QAM256); status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, DRXK_QAM_SL_SIG_POWER_QAM256);
if (status < 0) if (status < 0)
break; goto error;
/* QAM Loop Controller Coeficients */ /* QAM Loop Controller Coeficients */
status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15); status = write16(state, SCU_RAM_QAM_LC_CA_FINE__A, 15);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CA_COARSE__A, 40); status = write16(state, SCU_RAM_QAM_LC_CA_COARSE__A, 40);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EP_FINE__A, 12); status = write16(state, SCU_RAM_QAM_LC_EP_FINE__A, 12);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24); status = write16(state, SCU_RAM_QAM_LC_EP_MEDIUM__A, 24);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EP_COARSE__A, 24); status = write16(state, SCU_RAM_QAM_LC_EP_COARSE__A, 24);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EI_FINE__A, 12); status = write16(state, SCU_RAM_QAM_LC_EI_FINE__A, 12);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16); status = write16(state, SCU_RAM_QAM_LC_EI_MEDIUM__A, 16);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16); status = write16(state, SCU_RAM_QAM_LC_EI_COARSE__A, 16);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5); status = write16(state, SCU_RAM_QAM_LC_CP_FINE__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CP_MEDIUM__A, 50); status = write16(state, SCU_RAM_QAM_LC_CP_MEDIUM__A, 50);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CP_COARSE__A, 250); status = write16(state, SCU_RAM_QAM_LC_CP_COARSE__A, 250);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CI_FINE__A, 5); status = write16(state, SCU_RAM_QAM_LC_CI_FINE__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CI_MEDIUM__A, 50); status = write16(state, SCU_RAM_QAM_LC_CI_MEDIUM__A, 50);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CI_COARSE__A, 125); status = write16(state, SCU_RAM_QAM_LC_CI_COARSE__A, 125);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF_FINE__A, 16); status = write16(state, SCU_RAM_QAM_LC_CF_FINE__A, 16);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF_MEDIUM__A, 25); status = write16(state, SCU_RAM_QAM_LC_CF_MEDIUM__A, 25);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF_COARSE__A, 48); status = write16(state, SCU_RAM_QAM_LC_CF_COARSE__A, 48);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF1_FINE__A, 5); status = write16(state, SCU_RAM_QAM_LC_CF1_FINE__A, 5);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 10); status = write16(state, SCU_RAM_QAM_LC_CF1_MEDIUM__A, 10);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 10); status = write16(state, SCU_RAM_QAM_LC_CF1_COARSE__A, 10);
if (status < 0) if (status < 0)
break; goto error;
/* QAM State Machine (FSM) Thresholds */ /* QAM State Machine (FSM) Thresholds */
status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 50); status = write16(state, SCU_RAM_QAM_FSM_RTH__A, 50);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_FTH__A, 60); status = write16(state, SCU_RAM_QAM_FSM_FTH__A, 60);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_CTH__A, 80); status = write16(state, SCU_RAM_QAM_FSM_CTH__A, 80);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_PTH__A, 100); status = write16(state, SCU_RAM_QAM_FSM_PTH__A, 100);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_QTH__A, 150); status = write16(state, SCU_RAM_QAM_FSM_QTH__A, 150);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 110); status = write16(state, SCU_RAM_QAM_FSM_MTH__A, 110);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40); status = write16(state, SCU_RAM_QAM_FSM_RATE_LIM__A, 40);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_COUNT_LIM__A, 4); status = write16(state, SCU_RAM_QAM_FSM_COUNT_LIM__A, 4);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 12); status = write16(state, SCU_RAM_QAM_FSM_FREQ_LIM__A, 12);
if (status < 0) if (status < 0)
break; goto error;
/* QAM FSM Tracking Parameters */ /* QAM FSM Tracking Parameters */
status = write16(state, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, (u16) 8); status = write16(state, SCU_RAM_QAM_FSM_MEDIAN_AV_MULT__A, (u16) 8);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, (u16) 74); status = write16(state, SCU_RAM_QAM_FSM_RADIUS_AV_LIMIT__A, (u16) 74);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16) 18); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET1__A, (u16) 18);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16) 13); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET2__A, (u16) 13);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16) 7); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET3__A, (u16) 7);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16) 0); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET4__A, (u16) 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -8); status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -8);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
...@@ -5243,18 +5248,15 @@ static int QAMResetQAM(struct drxk_state *state) ...@@ -5243,18 +5248,15 @@ static int QAMResetQAM(struct drxk_state *state)
u16 cmdResult; u16 cmdResult;
dprintk(1, "\n"); dprintk(1, "\n");
do {
/* Stop QAM comstate->m_exec */ /* Stop QAM comstate->m_exec */
status = write16(state, QAM_COMM_EXEC__A, QAM_COMM_EXEC_STOP); status = write16(state, QAM_COMM_EXEC__A, QAM_COMM_EXEC_STOP);
if (status < 0) if (status < 0)
break; goto error;
status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_RESET, 0, NULL, 1, &cmdResult); status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_RESET, 0, NULL, 1, &cmdResult);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
/* All done, all OK */
return status; return status;
} }
...@@ -5276,7 +5278,6 @@ static int QAMSetSymbolrate(struct drxk_state *state) ...@@ -5276,7 +5278,6 @@ static int QAMSetSymbolrate(struct drxk_state *state)
int status; int status;
dprintk(1, "\n"); dprintk(1, "\n");
do {
/* Select & calculate correct IQM rate */ /* Select & calculate correct IQM rate */
adcFrequency = (state->m_sysClockFreq * 1000) / 3; adcFrequency = (state->m_sysClockFreq * 1000) / 3;
ratesel = 0; ratesel = 0;
...@@ -5289,7 +5290,7 @@ static int QAMSetSymbolrate(struct drxk_state *state) ...@@ -5289,7 +5290,7 @@ static int QAMSetSymbolrate(struct drxk_state *state)
ratesel = 1; ratesel = 1;
status = write16(state, IQM_FD_RATESEL__A, ratesel); status = write16(state, IQM_FD_RATESEL__A, ratesel);
if (status < 0) if (status < 0)
break; goto error;
/* /*
IqmRcRate = ((Fadc / (symbolrate * (4<<ratesel))) - 1) * (1<<23) IqmRcRate = ((Fadc / (symbolrate * (4<<ratesel))) - 1) * (1<<23)
...@@ -5297,14 +5298,15 @@ static int QAMSetSymbolrate(struct drxk_state *state) ...@@ -5297,14 +5298,15 @@ static int QAMSetSymbolrate(struct drxk_state *state)
symbFreq = state->param.u.qam.symbol_rate * (1 << ratesel); symbFreq = state->param.u.qam.symbol_rate * (1 << ratesel);
if (symbFreq == 0) { if (symbFreq == 0) {
/* Divide by zero */ /* Divide by zero */
return -1; status = -EINVAL;
goto error;
} }
iqmRcRate = (adcFrequency / symbFreq) * (1 << 21) + iqmRcRate = (adcFrequency / symbFreq) * (1 << 21) +
(Frac28a((adcFrequency % symbFreq), symbFreq) >> 7) - (Frac28a((adcFrequency % symbFreq), symbFreq) >> 7) -
(1 << 23); (1 << 23);
status = write32(state, IQM_RC_RATE_OFS_LO__A, iqmRcRate); status = write32(state, IQM_RC_RATE_OFS_LO__A, iqmRcRate);
if (status < 0) if (status < 0)
break; goto error;
state->m_iqmRcRate = iqmRcRate; state->m_iqmRcRate = iqmRcRate;
/* /*
LcSymbFreq = round (.125 * symbolrate / adcFreq * (1<<15)) LcSymbFreq = round (.125 * symbolrate / adcFreq * (1<<15))
...@@ -5312,7 +5314,8 @@ static int QAMSetSymbolrate(struct drxk_state *state) ...@@ -5312,7 +5314,8 @@ static int QAMSetSymbolrate(struct drxk_state *state)
symbFreq = state->param.u.qam.symbol_rate; symbFreq = state->param.u.qam.symbol_rate;
if (adcFrequency == 0) { if (adcFrequency == 0) {
/* Divide by zero */ /* Divide by zero */
return -1; status = -EINVAL;
goto error;
} }
lcSymbRate = (symbFreq / adcFrequency) * (1 << 12) + lcSymbRate = (symbFreq / adcFrequency) * (1 << 12) +
(Frac28a((symbFreq % adcFrequency), adcFrequency) >> (Frac28a((symbFreq % adcFrequency), adcFrequency) >>
...@@ -5320,10 +5323,10 @@ static int QAMSetSymbolrate(struct drxk_state *state) ...@@ -5320,10 +5323,10 @@ static int QAMSetSymbolrate(struct drxk_state *state)
if (lcSymbRate > 511) if (lcSymbRate > 511)
lcSymbRate = 511; lcSymbRate = 511;
status = write16(state, QAM_LC_SYMBOL_FREQ__A, (u16) lcSymbRate); status = write16(state, QAM_LC_SYMBOL_FREQ__A, (u16) lcSymbRate);
if (status < 0)
break;
} while (0);
error:
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -5342,8 +5345,8 @@ static int GetQAMLockStatus(struct drxk_state *state, u32 *pLockStatus) ...@@ -5342,8 +5345,8 @@ static int GetQAMLockStatus(struct drxk_state *state, u32 *pLockStatus)
u16 Result[2] = { 0, 0 }; u16 Result[2] = { 0, 0 };
dprintk(1, "\n"); dprintk(1, "\n");
status = *pLockStatus = NOT_LOCKED;
scu_command(state, status = scu_command(state,
SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_STANDARD_QAM |
SCU_RAM_COMMAND_CMD_DEMOD_GET_LOCK, 0, NULL, 2, SCU_RAM_COMMAND_CMD_DEMOD_GET_LOCK, 0, NULL, 2,
Result); Result);
...@@ -5352,7 +5355,6 @@ static int GetQAMLockStatus(struct drxk_state *state, u32 *pLockStatus) ...@@ -5352,7 +5355,6 @@ static int GetQAMLockStatus(struct drxk_state *state, u32 *pLockStatus)
if (Result[1] < SCU_RAM_QAM_LOCKED_LOCKED_DEMOD_LOCKED) { if (Result[1] < SCU_RAM_QAM_LOCKED_LOCKED_DEMOD_LOCKED) {
/* 0x0000 NOT LOCKED */ /* 0x0000 NOT LOCKED */
*pLockStatus = NOT_LOCKED;
} else if (Result[1] < SCU_RAM_QAM_LOCKED_LOCKED_LOCKED) { } else if (Result[1] < SCU_RAM_QAM_LOCKED_LOCKED_LOCKED) {
/* 0x4000 DEMOD LOCKED */ /* 0x4000 DEMOD LOCKED */
*pLockStatus = DEMOD_LOCK; *pLockStatus = DEMOD_LOCK;
...@@ -5379,14 +5381,13 @@ static int GetQAMLockStatus(struct drxk_state *state, u32 *pLockStatus) ...@@ -5379,14 +5381,13 @@ static int GetQAMLockStatus(struct drxk_state *state, u32 *pLockStatus)
static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz, static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz,
s32 tunerFreqOffset) s32 tunerFreqOffset)
{ {
int status = 0; int status;
u8 parameterLen; u8 parameterLen;
u16 setEnvParameters[5]; u16 setEnvParameters[5];
u16 setParamParameters[4] = { 0, 0, 0, 0 }; u16 setParamParameters[4] = { 0, 0, 0, 0 };
u16 cmdResult; u16 cmdResult;
dprintk(1, "\n"); dprintk(1, "\n");
do {
/* /*
STEP 1: reset demodulator STEP 1: reset demodulator
resets FEC DI and FEC RS resets FEC DI and FEC RS
...@@ -5395,13 +5396,13 @@ static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz, ...@@ -5395,13 +5396,13 @@ static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz,
*/ */
status = write16(state, FEC_DI_COMM_EXEC__A, FEC_DI_COMM_EXEC_STOP); status = write16(state, FEC_DI_COMM_EXEC__A, FEC_DI_COMM_EXEC_STOP);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_RS_COMM_EXEC__A, FEC_RS_COMM_EXEC_STOP); status = write16(state, FEC_RS_COMM_EXEC__A, FEC_RS_COMM_EXEC_STOP);
if (status < 0) if (status < 0)
break; goto error;
status = QAMResetQAM(state); status = QAMResetQAM(state);
if (status < 0) if (status < 0)
break; goto error;
/* /*
STEP 2: configure demodulator STEP 2: configure demodulator
...@@ -5410,7 +5411,7 @@ static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz, ...@@ -5410,7 +5411,7 @@ static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz,
*/ */
status = QAMSetSymbolrate(state); status = QAMSetSymbolrate(state);
if (status < 0) if (status < 0)
break; goto error;
/* Env parameters */ /* Env parameters */
setEnvParameters[2] = QAM_TOP_ANNEX_A; /* Annex */ setEnvParameters[2] = QAM_TOP_ANNEX_A; /* Annex */
...@@ -5443,352 +5444,332 @@ static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz, ...@@ -5443,352 +5444,332 @@ static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz,
status = -EINVAL; status = -EINVAL;
break; break;
} }
status = status;
if (status < 0) if (status < 0)
break; goto error;
setParamParameters[0] = state->m_Constellation; /* constellation */ setParamParameters[0] = state->m_Constellation; /* constellation */
setParamParameters[1] = DRXK_QAM_I12_J17; /* interleave mode */ setParamParameters[1] = DRXK_QAM_I12_J17; /* interleave mode */
status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_SET_PARAM, 4, setParamParameters, 1, &cmdResult); status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_SET_PARAM, 4, setParamParameters, 1, &cmdResult);
if (status < 0) if (status < 0)
break; goto error;
/* STEP 3: enable the system in a mode where the ADC provides valid signal /* STEP 3: enable the system in a mode where the ADC provides valid signal
setup constellation independent registers */ setup constellation independent registers */
#if 0 #if 0
status = SetFrequency (channel, tunerFreqOffset)); status = SetFrequency(channel, tunerFreqOffset));
if (status < 0) if (status < 0)
break; goto error;
#endif #endif
status = SetFrequencyShifter(state, IntermediateFreqkHz, tunerFreqOffset, true); status = SetFrequencyShifter(state, IntermediateFreqkHz, tunerFreqOffset, true);
if (status < 0) if (status < 0)
break; goto error;
/* Setup BER measurement */ /* Setup BER measurement */
status = SetQAMMeasurement(state, state->m_Constellation, state->param.u. qam.symbol_rate); status = SetQAMMeasurement(state, state->m_Constellation, state->param.u. qam.symbol_rate);
if (status < 0) if (status < 0)
break; goto error;
/* Reset default values */ /* Reset default values */
status = write16(state, IQM_CF_SCALE_SH__A, IQM_CF_SCALE_SH__PRE); status = write16(state, IQM_CF_SCALE_SH__A, IQM_CF_SCALE_SH__PRE);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_SY_TIMEOUT__A, QAM_SY_TIMEOUT__PRE); status = write16(state, QAM_SY_TIMEOUT__A, QAM_SY_TIMEOUT__PRE);
if (status < 0) if (status < 0)
break; goto error;
/* Reset default LC values */ /* Reset default LC values */
status = write16(state, QAM_LC_RATE_LIMIT__A, 3); status = write16(state, QAM_LC_RATE_LIMIT__A, 3);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_LC_LPF_FACTORP__A, 4); status = write16(state, QAM_LC_LPF_FACTORP__A, 4);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_LC_LPF_FACTORI__A, 4); status = write16(state, QAM_LC_LPF_FACTORI__A, 4);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_LC_MODE__A, 7); status = write16(state, QAM_LC_MODE__A, 7);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_LC_QUAL_TAB0__A, 1); status = write16(state, QAM_LC_QUAL_TAB0__A, 1);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_LC_QUAL_TAB1__A, 1); status = write16(state, QAM_LC_QUAL_TAB1__A, 1);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_LC_QUAL_TAB2__A, 1); status = write16(state, QAM_LC_QUAL_TAB2__A, 1);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_LC_QUAL_TAB3__A, 1); status = write16(state, QAM_LC_QUAL_TAB3__A, 1);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_LC_QUAL_TAB4__A, 2); status = write16(state, QAM_LC_QUAL_TAB4__A, 2);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_LC_QUAL_TAB5__A, 2); status = write16(state, QAM_LC_QUAL_TAB5__A, 2);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_LC_QUAL_TAB6__A, 2); status = write16(state, QAM_LC_QUAL_TAB6__A, 2);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_LC_QUAL_TAB8__A, 2); status = write16(state, QAM_LC_QUAL_TAB8__A, 2);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_LC_QUAL_TAB9__A, 2); status = write16(state, QAM_LC_QUAL_TAB9__A, 2);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_LC_QUAL_TAB10__A, 2); status = write16(state, QAM_LC_QUAL_TAB10__A, 2);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_LC_QUAL_TAB12__A, 2); status = write16(state, QAM_LC_QUAL_TAB12__A, 2);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_LC_QUAL_TAB15__A, 3); status = write16(state, QAM_LC_QUAL_TAB15__A, 3);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_LC_QUAL_TAB16__A, 3); status = write16(state, QAM_LC_QUAL_TAB16__A, 3);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_LC_QUAL_TAB20__A, 4); status = write16(state, QAM_LC_QUAL_TAB20__A, 4);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_LC_QUAL_TAB25__A, 4); status = write16(state, QAM_LC_QUAL_TAB25__A, 4);
if (status < 0) if (status < 0)
break; goto error;
/* Mirroring, QAM-block starting point not inverted */ /* Mirroring, QAM-block starting point not inverted */
status = write16(state, QAM_SY_SP_INV__A, QAM_SY_SP_INV_SPECTRUM_INV_DIS); status = write16(state, QAM_SY_SP_INV__A, QAM_SY_SP_INV_SPECTRUM_INV_DIS);
if (status < 0) if (status < 0)
break; goto error;
/* Halt SCU to enable safe non-atomic accesses */ /* Halt SCU to enable safe non-atomic accesses */
status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_HOLD); status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_HOLD);
if (status < 0) if (status < 0)
break; goto error;
/* STEP 4: constellation specific setup */ /* STEP 4: constellation specific setup */
switch (state->param.u.qam.modulation) { switch (state->param.u.qam.modulation) {
case QAM_16: case QAM_16:
status = SetQAM16(state); status = SetQAM16(state);
if (status < 0)
break;
break; break;
case QAM_32: case QAM_32:
status = SetQAM32(state); status = SetQAM32(state);
if (status < 0)
break;
break; break;
case QAM_AUTO: case QAM_AUTO:
case QAM_64: case QAM_64:
status = SetQAM64(state); status = SetQAM64(state);
if (status < 0)
break;
break; break;
case QAM_128: case QAM_128:
status = SetQAM128(state); status = SetQAM128(state);
if (status < 0)
break;
break; break;
case QAM_256: case QAM_256:
status = SetQAM256(state); status = SetQAM256(state);
if (status < 0)
break;
break; break;
default: default:
return -1; status = -EINVAL;
break; break;
} /* switch */ }
if (status < 0)
goto error;
/* Activate SCU to enable SCU commands */ /* Activate SCU to enable SCU commands */
status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE);
if (status < 0) if (status < 0)
break; goto error;
/* Re-configure MPEG output, requires knowledge of channel bitrate */ /* Re-configure MPEG output, requires knowledge of channel bitrate */
/* extAttr->currentChannel.constellation = channel->constellation; */ /* extAttr->currentChannel.constellation = channel->constellation; */
/* extAttr->currentChannel.symbolrate = channel->symbolrate; */ /* extAttr->currentChannel.symbolrate = channel->symbolrate; */
status = MPEGTSDtoSetup(state, state->m_OperationMode); status = MPEGTSDtoSetup(state, state->m_OperationMode);
if (status < 0) if (status < 0)
break; goto error;
/* Start processes */ /* Start processes */
status = MPEGTSStart(state); status = MPEGTSStart(state);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, FEC_COMM_EXEC__A, FEC_COMM_EXEC_ACTIVE); status = write16(state, FEC_COMM_EXEC__A, FEC_COMM_EXEC_ACTIVE);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, QAM_COMM_EXEC__A, QAM_COMM_EXEC_ACTIVE); status = write16(state, QAM_COMM_EXEC__A, QAM_COMM_EXEC_ACTIVE);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_COMM_EXEC__A, IQM_COMM_EXEC_B_ACTIVE); status = write16(state, IQM_COMM_EXEC__A, IQM_COMM_EXEC_B_ACTIVE);
if (status < 0) if (status < 0)
break; goto error;
/* STEP 5: start QAM demodulator (starts FEC, QAM and IQM HW) */ /* STEP 5: start QAM demodulator (starts FEC, QAM and IQM HW) */
status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_START, 0, NULL, 1, &cmdResult); status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_START, 0, NULL, 1, &cmdResult);
if (status < 0) if (status < 0)
break; goto error;
/* update global DRXK data container */ /* update global DRXK data container */
/*? extAttr->qamInterleaveMode = DRXK_QAM_I12_J17; */ /*? extAttr->qamInterleaveMode = DRXK_QAM_I12_J17; */
/* All done, all OK */
} while (0);
error:
if (status < 0) if (status < 0)
printk(KERN_ERR "drxk: %s %d\n", __func__, status); printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
static int SetQAMStandard(struct drxk_state *state, static int SetQAMStandard(struct drxk_state *state,
enum OperationMode oMode) enum OperationMode oMode)
{ {
int status;
#ifdef DRXK_QAM_TAPS #ifdef DRXK_QAM_TAPS
#define DRXK_QAMA_TAPS_SELECT #define DRXK_QAMA_TAPS_SELECT
#include "drxk_filters.h" #include "drxk_filters.h"
#undef DRXK_QAMA_TAPS_SELECT #undef DRXK_QAMA_TAPS_SELECT
#else
int status;
#endif #endif
dprintk(1, "\n");
do {
/* added antenna switch */ /* added antenna switch */
SwitchAntennaToQAM(state); SwitchAntennaToQAM(state);
/* Ensure correct power-up mode */ /* Ensure correct power-up mode */
status = PowerUpQAM(state); status = PowerUpQAM(state);
if (status < 0) if (status < 0)
break; goto error;
/* Reset QAM block */ /* Reset QAM block */
status = QAMResetQAM(state); status = QAMResetQAM(state);
if (status < 0) if (status < 0)
break; goto error;
/* Setup IQM */ /* Setup IQM */
status = write16(state, IQM_COMM_EXEC__A, IQM_COMM_EXEC_B_STOP); status = write16(state, IQM_COMM_EXEC__A, IQM_COMM_EXEC_B_STOP);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_AF_AMUX__A, IQM_AF_AMUX_SIGNAL2ADC); status = write16(state, IQM_AF_AMUX__A, IQM_AF_AMUX_SIGNAL2ADC);
if (status < 0) if (status < 0)
break; goto error;
/* Upload IQM Channel Filter settings by /* Upload IQM Channel Filter settings by
boot loader from ROM table */ boot loader from ROM table */
switch (oMode) { switch (oMode) {
case OM_QAM_ITU_A: case OM_QAM_ITU_A:
status = BLChainCmd(state, DRXK_BL_ROM_OFFSET_TAPS_ITU_A, DRXK_BLCC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT); status = BLChainCmd(state, DRXK_BL_ROM_OFFSET_TAPS_ITU_A, DRXK_BLCC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT);
if (status < 0)
break;
break; break;
case OM_QAM_ITU_C: case OM_QAM_ITU_C:
status = BLDirectCmd(state, IQM_CF_TAP_RE0__A, DRXK_BL_ROM_OFFSET_TAPS_ITU_C, DRXK_BLDC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT); status = BLDirectCmd(state, IQM_CF_TAP_RE0__A, DRXK_BL_ROM_OFFSET_TAPS_ITU_C, DRXK_BLDC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT);
if (status < 0) if (status < 0)
break; goto error;
status = BLDirectCmd(state, IQM_CF_TAP_IM0__A, DRXK_BL_ROM_OFFSET_TAPS_ITU_C, DRXK_BLDC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT); status = BLDirectCmd(state, IQM_CF_TAP_IM0__A, DRXK_BL_ROM_OFFSET_TAPS_ITU_C, DRXK_BLDC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT);
if (status < 0)
break;
break; break;
default: default:
status = -EINVAL; status = -EINVAL;
} }
status = status;
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_CF_OUT_ENA__A, (1 << IQM_CF_OUT_ENA_QAM__B)); status = write16(state, IQM_CF_OUT_ENA__A, (1 << IQM_CF_OUT_ENA_QAM__B));
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_CF_SYMMETRIC__A, 0); status = write16(state, IQM_CF_SYMMETRIC__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_CF_MIDTAP__A, ((1 << IQM_CF_MIDTAP_RE__B) | (1 << IQM_CF_MIDTAP_IM__B))); status = write16(state, IQM_CF_MIDTAP__A, ((1 << IQM_CF_MIDTAP_RE__B) | (1 << IQM_CF_MIDTAP_IM__B)));
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_RC_STRETCH__A, 21); status = write16(state, IQM_RC_STRETCH__A, 21);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_AF_CLP_LEN__A, 0); status = write16(state, IQM_AF_CLP_LEN__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_AF_CLP_TH__A, 448); status = write16(state, IQM_AF_CLP_TH__A, 448);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_AF_SNS_LEN__A, 0); status = write16(state, IQM_AF_SNS_LEN__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_CF_POW_MEAS_LEN__A, 0); status = write16(state, IQM_CF_POW_MEAS_LEN__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_FS_ADJ_SEL__A, 1); status = write16(state, IQM_FS_ADJ_SEL__A, 1);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_RC_ADJ_SEL__A, 1); status = write16(state, IQM_RC_ADJ_SEL__A, 1);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_CF_ADJ_SEL__A, 1); status = write16(state, IQM_CF_ADJ_SEL__A, 1);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_AF_UPD_SEL__A, 0); status = write16(state, IQM_AF_UPD_SEL__A, 0);
if (status < 0) if (status < 0)
break; goto error;
/* IQM Impulse Noise Processing Unit */ /* IQM Impulse Noise Processing Unit */
status = write16(state, IQM_CF_CLP_VAL__A, 500); status = write16(state, IQM_CF_CLP_VAL__A, 500);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_CF_DATATH__A, 1000); status = write16(state, IQM_CF_DATATH__A, 1000);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_CF_BYPASSDET__A, 1); status = write16(state, IQM_CF_BYPASSDET__A, 1);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_CF_DET_LCT__A, 0); status = write16(state, IQM_CF_DET_LCT__A, 0);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_CF_WND_LEN__A, 1); status = write16(state, IQM_CF_WND_LEN__A, 1);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_CF_PKDTH__A, 1); status = write16(state, IQM_CF_PKDTH__A, 1);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_AF_INC_BYPASS__A, 1); status = write16(state, IQM_AF_INC_BYPASS__A, 1);
if (status < 0) if (status < 0)
break; goto error;
/* turn on IQMAF. Must be done before setAgc**() */ /* turn on IQMAF. Must be done before setAgc**() */
status = SetIqmAf(state, true); status = SetIqmAf(state, true);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, IQM_AF_START_LOCK__A, 0x01); status = write16(state, IQM_AF_START_LOCK__A, 0x01);
if (status < 0) if (status < 0)
break; goto error;
/* IQM will not be reset from here, sync ADC and update/init AGC */ /* IQM will not be reset from here, sync ADC and update/init AGC */
status = ADCSynchronization(state); status = ADCSynchronization(state);
if (status < 0) if (status < 0)
break; goto error;
/* Set the FSM step period */ /* Set the FSM step period */
status = write16(state, SCU_RAM_QAM_FSM_STEP_PERIOD__A, 2000); status = write16(state, SCU_RAM_QAM_FSM_STEP_PERIOD__A, 2000);
if (status < 0) if (status < 0)
break; goto error;
/* Halt SCU to enable safe non-atomic accesses */ /* Halt SCU to enable safe non-atomic accesses */
status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_HOLD); status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_HOLD);
if (status < 0) if (status < 0)
break; goto error;
/* No more resets of the IQM, current standard correctly set => /* No more resets of the IQM, current standard correctly set =>
now AGCs can be configured. */ now AGCs can be configured. */
status = InitAGC(state, true); status = InitAGC(state, true);
if (status < 0) if (status < 0)
break; goto error;
status = SetPreSaw(state, &(state->m_qamPreSawCfg)); status = SetPreSaw(state, &(state->m_qamPreSawCfg));
if (status < 0) if (status < 0)
break; goto error;
/* Configure AGC's */ /* Configure AGC's */
status = SetAgcRf(state, &(state->m_qamRfAgcCfg), true); status = SetAgcRf(state, &(state->m_qamRfAgcCfg), true);
if (status < 0) if (status < 0)
break; goto error;
status = SetAgcIf(state, &(state->m_qamIfAgcCfg), true); status = SetAgcIf(state, &(state->m_qamIfAgcCfg), true);
if (status < 0) if (status < 0)
break; goto error;
/* Activate SCU to enable SCU commands */ /* Activate SCU to enable SCU commands */
status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
...@@ -5798,27 +5779,26 @@ static int WriteGPIO(struct drxk_state *state) ...@@ -5798,27 +5779,26 @@ static int WriteGPIO(struct drxk_state *state)
u16 value = 0; u16 value = 0;
dprintk(1, "\n"); dprintk(1, "\n");
do {
/* stop lock indicator process */ /* stop lock indicator process */
status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE);
if (status < 0) if (status < 0)
break; goto error;
/* Write magic word to enable pdr reg write */ /* Write magic word to enable pdr reg write */
status = write16(state, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY); status = write16(state, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY);
if (status < 0) if (status < 0)
break; goto error;
if (state->m_hasSAWSW) { if (state->m_hasSAWSW) {
/* write to io pad configuration register - output mode */ /* write to io pad configuration register - output mode */
status = write16(state, SIO_PDR_SMA_TX_CFG__A, state->m_GPIOCfg); status = write16(state, SIO_PDR_SMA_TX_CFG__A, state->m_GPIOCfg);
if (status < 0) if (status < 0)
break; goto error;
/* use corresponding bit in io data output registar */ /* use corresponding bit in io data output registar */
status = read16(state, SIO_PDR_UIO_OUT_LO__A, &value); status = read16(state, SIO_PDR_UIO_OUT_LO__A, &value);
if (status < 0) if (status < 0)
break; goto error;
if (state->m_GPIO == 0) if (state->m_GPIO == 0)
value &= 0x7FFF; /* write zero to 15th bit - 1st UIO */ value &= 0x7FFF; /* write zero to 15th bit - 1st UIO */
else else
...@@ -5826,20 +5806,20 @@ static int WriteGPIO(struct drxk_state *state) ...@@ -5826,20 +5806,20 @@ static int WriteGPIO(struct drxk_state *state)
/* write back to io data output register */ /* write back to io data output register */
status = write16(state, SIO_PDR_UIO_OUT_LO__A, value); status = write16(state, SIO_PDR_UIO_OUT_LO__A, value);
if (status < 0) if (status < 0)
break; goto error;
} }
/* Write magic word to disable pdr reg write */ /* Write magic word to disable pdr reg write */
status = write16(state, SIO_TOP_COMM_KEY__A, 0x0000); status = write16(state, SIO_TOP_COMM_KEY__A, 0x0000);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
return status; return status;
} }
static int SwitchAntennaToQAM(struct drxk_state *state) static int SwitchAntennaToQAM(struct drxk_state *state)
{ {
int status = -1; int status = -EINVAL;
dprintk(1, "\n"); dprintk(1, "\n");
if (state->m_AntennaSwitchDVBTDVBC != 0) { if (state->m_AntennaSwitchDVBTDVBC != 0) {
...@@ -5848,12 +5828,14 @@ static int SwitchAntennaToQAM(struct drxk_state *state) ...@@ -5848,12 +5828,14 @@ static int SwitchAntennaToQAM(struct drxk_state *state)
status = WriteGPIO(state); status = WriteGPIO(state);
} }
} }
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
static int SwitchAntennaToDVBT(struct drxk_state *state) static int SwitchAntennaToDVBT(struct drxk_state *state)
{ {
int status = -1; int status = -EINVAL;
dprintk(1, "\n"); dprintk(1, "\n");
if (state->m_AntennaSwitchDVBTDVBC != 0) { if (state->m_AntennaSwitchDVBTDVBC != 0) {
...@@ -5862,6 +5844,8 @@ static int SwitchAntennaToDVBT(struct drxk_state *state) ...@@ -5862,6 +5844,8 @@ static int SwitchAntennaToDVBT(struct drxk_state *state)
status = WriteGPIO(state); status = WriteGPIO(state);
} }
} }
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return status; return status;
} }
...@@ -5877,34 +5861,30 @@ static int PowerDownDevice(struct drxk_state *state) ...@@ -5877,34 +5861,30 @@ static int PowerDownDevice(struct drxk_state *state)
int status; int status;
dprintk(1, "\n"); dprintk(1, "\n");
do {
if (state->m_bPDownOpenBridge) { if (state->m_bPDownOpenBridge) {
/* Open I2C bridge before power down of DRXK */ /* Open I2C bridge before power down of DRXK */
status = ConfigureI2CBridge(state, true); status = ConfigureI2CBridge(state, true);
if (status < 0) if (status < 0)
break; goto error;
} }
/* driver 0.9.0 */ /* driver 0.9.0 */
status = DVBTEnableOFDMTokenRing(state, false); status = DVBTEnableOFDMTokenRing(state, false);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_CC_PWD_MODE__A, SIO_CC_PWD_MODE_LEVEL_CLOCK); status = write16(state, SIO_CC_PWD_MODE__A, SIO_CC_PWD_MODE_LEVEL_CLOCK);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY); status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY);
if (status < 0) if (status < 0)
break; goto error;
state->m_HICfgCtrl |= SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ; state->m_HICfgCtrl |= SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ;
status = HI_CfgCommand(state); status = HI_CfgCommand(state);
error:
if (status < 0) if (status < 0)
break; printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
} while (0);
if (status < 0)
return -1;
return 0; return status;
} }
static int load_microcode(struct drxk_state *state, const char *mc_name) static int load_microcode(struct drxk_state *state, const char *mc_name)
...@@ -5929,32 +5909,31 @@ static int load_microcode(struct drxk_state *state, const char *mc_name) ...@@ -5929,32 +5909,31 @@ static int load_microcode(struct drxk_state *state, const char *mc_name)
static int init_drxk(struct drxk_state *state) static int init_drxk(struct drxk_state *state)
{ {
int status; int status = 0;
enum DRXPowerMode powerMode = DRXK_POWER_DOWN_OFDM; enum DRXPowerMode powerMode = DRXK_POWER_DOWN_OFDM;
u16 driverVersion; u16 driverVersion;
dprintk(1, "\n"); dprintk(1, "\n");
if ((state->m_DrxkState == DRXK_UNINITIALIZED)) { if ((state->m_DrxkState == DRXK_UNINITIALIZED)) {
do {
status = PowerUpDevice(state); status = PowerUpDevice(state);
if (status < 0) if (status < 0)
break; goto error;
status = DRXX_Open(state); status = DRXX_Open(state);
if (status < 0) if (status < 0)
break; goto error;
/* Soft reset of OFDM-, sys- and osc-clockdomain */ /* Soft reset of OFDM-, sys- and osc-clockdomain */
status = write16(state, SIO_CC_SOFT_RST__A, SIO_CC_SOFT_RST_OFDM__M | SIO_CC_SOFT_RST_SYS__M | SIO_CC_SOFT_RST_OSC__M); status = write16(state, SIO_CC_SOFT_RST__A, SIO_CC_SOFT_RST_OFDM__M | SIO_CC_SOFT_RST_SYS__M | SIO_CC_SOFT_RST_OSC__M);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY); status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY);
if (status < 0) if (status < 0)
break; goto error;
/* TODO is this needed, if yes how much delay in worst case scenario */ /* TODO is this needed, if yes how much delay in worst case scenario */
msleep(1); msleep(1);
state->m_DRXK_A3_PATCH_CODE = true; state->m_DRXK_A3_PATCH_CODE = true;
status = GetDeviceCapabilities(state); status = GetDeviceCapabilities(state);
if (status < 0) if (status < 0)
break; goto error;
/* Bridge delay, uses oscilator clock */ /* Bridge delay, uses oscilator clock */
/* Delay = (delay (nano seconds) * oscclk (kHz))/ 1000 */ /* Delay = (delay (nano seconds) * oscclk (kHz))/ 1000 */
...@@ -5975,7 +5954,7 @@ static int init_drxk(struct drxk_state *state) ...@@ -5975,7 +5954,7 @@ static int init_drxk(struct drxk_state *state)
status = InitHI(state); status = InitHI(state);
if (status < 0) if (status < 0)
break; goto error;
/* disable various processes */ /* disable various processes */
#if NOA1ROM #if NOA1ROM
if (!(state->m_DRXK_A1_ROM_CODE) if (!(state->m_DRXK_A1_ROM_CODE)
...@@ -5984,34 +5963,34 @@ static int init_drxk(struct drxk_state *state) ...@@ -5984,34 +5963,34 @@ static int init_drxk(struct drxk_state *state)
{ {
status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE);
if (status < 0) if (status < 0)
break; goto error;
} }
/* disable MPEG port */ /* disable MPEG port */
status = MPEGTSDisable(state); status = MPEGTSDisable(state);
if (status < 0) if (status < 0)
break; goto error;
/* Stop AUD and SCU */ /* Stop AUD and SCU */
status = write16(state, AUD_COMM_EXEC__A, AUD_COMM_EXEC_STOP); status = write16(state, AUD_COMM_EXEC__A, AUD_COMM_EXEC_STOP);
if (status < 0) if (status < 0)
break; goto error;
status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_STOP); status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_STOP);
if (status < 0) if (status < 0)
break; goto error;
/* enable token-ring bus through OFDM block for possible ucode upload */ /* enable token-ring bus through OFDM block for possible ucode upload */
status = write16(state, SIO_OFDM_SH_OFDM_RING_ENABLE__A, SIO_OFDM_SH_OFDM_RING_ENABLE_ON); status = write16(state, SIO_OFDM_SH_OFDM_RING_ENABLE__A, SIO_OFDM_SH_OFDM_RING_ENABLE_ON);
if (status < 0) if (status < 0)
break; goto error;
/* include boot loader section */ /* include boot loader section */
status = write16(state, SIO_BL_COMM_EXEC__A, SIO_BL_COMM_EXEC_ACTIVE); status = write16(state, SIO_BL_COMM_EXEC__A, SIO_BL_COMM_EXEC_ACTIVE);
if (status < 0) if (status < 0)
break; goto error;
status = BLChainCmd(state, 0, 6, 100); status = BLChainCmd(state, 0, 6, 100);
if (status < 0) if (status < 0)
break; goto error;
if (!state->microcode_name) if (!state->microcode_name)
load_microcode(state, "drxk_a3.mc"); load_microcode(state, "drxk_a3.mc");
...@@ -6021,22 +6000,22 @@ static int init_drxk(struct drxk_state *state) ...@@ -6021,22 +6000,22 @@ static int init_drxk(struct drxk_state *state)
/* disable token-ring bus through OFDM block for possible ucode upload */ /* disable token-ring bus through OFDM block for possible ucode upload */
status = write16(state, SIO_OFDM_SH_OFDM_RING_ENABLE__A, SIO_OFDM_SH_OFDM_RING_ENABLE_OFF); status = write16(state, SIO_OFDM_SH_OFDM_RING_ENABLE__A, SIO_OFDM_SH_OFDM_RING_ENABLE_OFF);
if (status < 0) if (status < 0)
break; goto error;
/* Run SCU for a little while to initialize microcode version numbers */ /* Run SCU for a little while to initialize microcode version numbers */
status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE);
if (status < 0) if (status < 0)
break; goto error;
status = DRXX_Open(state); status = DRXX_Open(state);
if (status < 0) if (status < 0)
break; goto error;
/* added for test */ /* added for test */
msleep(30); msleep(30);
powerMode = DRXK_POWER_DOWN_OFDM; powerMode = DRXK_POWER_DOWN_OFDM;
status = CtrlPowerMode(state, &powerMode); status = CtrlPowerMode(state, &powerMode);
if (status < 0) if (status < 0)
break; goto error;
/* Stamp driver version number in SCU data RAM in BCD code /* Stamp driver version number in SCU data RAM in BCD code
Done to enable field application engineers to retreive drxdriver version Done to enable field application engineers to retreive drxdriver version
...@@ -6051,7 +6030,7 @@ static int init_drxk(struct drxk_state *state) ...@@ -6051,7 +6030,7 @@ static int init_drxk(struct drxk_state *state)
(DRXK_VERSION_MINOR % 10); (DRXK_VERSION_MINOR % 10);
status = write16(state, SCU_RAM_DRIVER_VER_HI__A, driverVersion); status = write16(state, SCU_RAM_DRIVER_VER_HI__A, driverVersion);
if (status < 0) if (status < 0)
break; goto error;
driverVersion = driverVersion =
(((DRXK_VERSION_PATCH / 1000) % 10) << 12) + (((DRXK_VERSION_PATCH / 1000) % 10) << 12) +
(((DRXK_VERSION_PATCH / 100) % 10) << 8) + (((DRXK_VERSION_PATCH / 100) % 10) << 8) +
...@@ -6059,7 +6038,7 @@ static int init_drxk(struct drxk_state *state) ...@@ -6059,7 +6038,7 @@ static int init_drxk(struct drxk_state *state)
(DRXK_VERSION_PATCH % 10); (DRXK_VERSION_PATCH % 10);
status = write16(state, SCU_RAM_DRIVER_VER_LO__A, driverVersion); status = write16(state, SCU_RAM_DRIVER_VER_LO__A, driverVersion);
if (status < 0) if (status < 0)
break; goto error;
printk(KERN_INFO "DRXK driver version %d.%d.%d\n", printk(KERN_INFO "DRXK driver version %d.%d.%d\n",
DRXK_VERSION_MAJOR, DRXK_VERSION_MINOR, DRXK_VERSION_MAJOR, DRXK_VERSION_MINOR,
...@@ -6075,42 +6054,44 @@ static int init_drxk(struct drxk_state *state) ...@@ -6075,42 +6054,44 @@ static int init_drxk(struct drxk_state *state)
/* Reset driver debug flags to 0 */ /* Reset driver debug flags to 0 */
status = write16(state, SCU_RAM_DRIVER_DEBUG__A, 0); status = write16(state, SCU_RAM_DRIVER_DEBUG__A, 0);
if (status < 0) if (status < 0)
break; goto error;
/* driver 0.9.0 */ /* driver 0.9.0 */
/* Setup FEC OC: /* Setup FEC OC:
NOTE: No more full FEC resets allowed afterwards!! */ NOTE: No more full FEC resets allowed afterwards!! */
status = write16(state, FEC_COMM_EXEC__A, FEC_COMM_EXEC_STOP); status = write16(state, FEC_COMM_EXEC__A, FEC_COMM_EXEC_STOP);
if (status < 0) if (status < 0)
break; goto error;
/* MPEGTS functions are still the same */ /* MPEGTS functions are still the same */
status = MPEGTSDtoInit(state); status = MPEGTSDtoInit(state);
if (status < 0) if (status < 0)
break; goto error;
status = MPEGTSStop(state); status = MPEGTSStop(state);
if (status < 0) if (status < 0)
break; goto error;
status = MPEGTSConfigurePolarity(state); status = MPEGTSConfigurePolarity(state);
if (status < 0) if (status < 0)
break; goto error;
status = MPEGTSConfigurePins(state, state->m_enableMPEGOutput); status = MPEGTSConfigurePins(state, state->m_enableMPEGOutput);
if (status < 0) if (status < 0)
break; goto error;
/* added: configure GPIO */ /* added: configure GPIO */
status = WriteGPIO(state); status = WriteGPIO(state);
if (status < 0) if (status < 0)
break; goto error;
state->m_DrxkState = DRXK_STOPPED; state->m_DrxkState = DRXK_STOPPED;
if (state->m_bPowerDown) { if (state->m_bPowerDown) {
status = PowerDownDevice(state); status = PowerDownDevice(state);
if (status < 0) if (status < 0)
break; goto error;
state->m_DrxkState = DRXK_POWERED_DOWN; state->m_DrxkState = DRXK_POWERED_DOWN;
} else } else
state->m_DrxkState = DRXK_STOPPED; state->m_DrxkState = DRXK_STOPPED;
} while (0);
} }
error:
if (status < 0)
printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__);
return 0; return 0;
} }
...@@ -6210,7 +6191,7 @@ static int drxk_read_signal_strength(struct dvb_frontend *fe, ...@@ -6210,7 +6191,7 @@ static int drxk_read_signal_strength(struct dvb_frontend *fe,
u16 *strength) u16 *strength)
{ {
struct drxk_state *state = fe->demodulator_priv; struct drxk_state *state = fe->demodulator_priv;
u32 val; u32 val = 0;
dprintk(1, "\n"); dprintk(1, "\n");
ReadIFAgc(state, &val); ReadIFAgc(state, &val);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册