Commit 0485a708 authored by Antti Palosaari's avatar Antti Palosaari Committed by Mauro Carvalho Chehab

[media] rtl2830: correct I2C functionality

Implement I2C functionality according to real RTL2830 demod.

Do not send register page in first byte of each I2C write, instead
use logic to set page using own write when needed. Page register is
physical register 0 as generally used.
Signed-off-by: default avatarAntti Palosaari <crope@iki.fi>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 34ec2933
...@@ -31,45 +31,43 @@ int rtl2830_debug; ...@@ -31,45 +31,43 @@ int rtl2830_debug;
module_param_named(debug, rtl2830_debug, int, 0644); module_param_named(debug, rtl2830_debug, int, 0644);
MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off)."); MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
/* write multiple registers */ /* write multiple hardware registers */
static int rtl2830_wr_regs(struct rtl2830_priv *priv, u16 reg, u8 *val, int len) static int rtl2830_wr(struct rtl2830_priv *priv, u8 reg, u8 *val, int len)
{ {
int ret; int ret;
u8 buf[2+len]; u8 buf[1+len];
struct i2c_msg msg[1] = { struct i2c_msg msg[1] = {
{ {
.addr = priv->cfg.i2c_addr, .addr = priv->cfg.i2c_addr,
.flags = 0, .flags = 0,
.len = sizeof(buf), .len = 1+len,
.buf = buf, .buf = buf,
} }
}; };
buf[0] = (reg >> 8) & 0xff; buf[0] = reg;
buf[1] = (reg >> 0) & 0xff; memcpy(&buf[1], val, len);
memcpy(&buf[2], val, len);
ret = i2c_transfer(priv->i2c, msg, 1); ret = i2c_transfer(priv->i2c, msg, 1);
if (ret == 1) { if (ret == 1) {
ret = 0; ret = 0;
} else { } else {
warn("i2c wr failed=%d reg=%04x len=%d", ret, reg, len); warn("i2c wr failed=%d reg=%02x len=%d", ret, reg, len);
ret = -EREMOTEIO; ret = -EREMOTEIO;
} }
return ret; return ret;
} }
/* read multiple registers */ /* read multiple hardware registers */
static int rtl2830_rd_regs(struct rtl2830_priv *priv, u16 reg, u8 *val, int len) static int rtl2830_rd(struct rtl2830_priv *priv, u8 reg, u8 *val, int len)
{ {
int ret; int ret;
u8 buf[2];
struct i2c_msg msg[2] = { struct i2c_msg msg[2] = {
{ {
.addr = priv->cfg.i2c_addr, .addr = priv->cfg.i2c_addr,
.flags = 0, .flags = 0,
.len = sizeof(buf), .len = 1,
.buf = buf, .buf = &reg,
}, { }, {
.addr = priv->cfg.i2c_addr, .addr = priv->cfg.i2c_addr,
.flags = I2C_M_RD, .flags = I2C_M_RD,
...@@ -78,19 +76,54 @@ static int rtl2830_rd_regs(struct rtl2830_priv *priv, u16 reg, u8 *val, int len) ...@@ -78,19 +76,54 @@ static int rtl2830_rd_regs(struct rtl2830_priv *priv, u16 reg, u8 *val, int len)
} }
}; };
buf[0] = (reg >> 8) & 0xff;
buf[1] = (reg >> 0) & 0xff;
ret = i2c_transfer(priv->i2c, msg, 2); ret = i2c_transfer(priv->i2c, msg, 2);
if (ret == 2) { if (ret == 2) {
ret = 0; ret = 0;
} else { } else {
warn("i2c rd failed=%d reg=%04x len=%d", ret, reg, len); warn("i2c rd failed=%d reg=%02x len=%d", ret, reg, len);
ret = -EREMOTEIO; ret = -EREMOTEIO;
} }
return ret; return ret;
} }
/* write multiple registers */
static int rtl2830_wr_regs(struct rtl2830_priv *priv, u16 reg, u8 *val, int len)
{
int ret;
u8 reg2 = (reg >> 0) & 0xff;
u8 page = (reg >> 8) & 0xff;
/* switch bank if needed */
if (page != priv->page) {
ret = rtl2830_wr(priv, 0x00, &page, 1);
if (ret)
return ret;
priv->page = page;
}
return rtl2830_wr(priv, reg2, val, len);
}
/* read multiple registers */
static int rtl2830_rd_regs(struct rtl2830_priv *priv, u16 reg, u8 *val, int len)
{
int ret;
u8 reg2 = (reg >> 0) & 0xff;
u8 page = (reg >> 8) & 0xff;
/* switch bank if needed */
if (page != priv->page) {
ret = rtl2830_wr(priv, 0x00, &page, 1);
if (ret)
return ret;
priv->page = page;
}
return rtl2830_rd(priv, reg2, val, len);
}
#if 0 /* currently not used */ #if 0 /* currently not used */
/* write single register */ /* write single register */
static int rtl2830_wr_reg(struct rtl2830_priv *priv, u16 reg, u8 val) static int rtl2830_wr_reg(struct rtl2830_priv *priv, u16 reg, u8 val)
......
...@@ -42,6 +42,8 @@ struct rtl2830_priv { ...@@ -42,6 +42,8 @@ struct rtl2830_priv {
struct dvb_frontend fe; struct dvb_frontend fe;
struct rtl2830_config cfg; struct rtl2830_config cfg;
struct i2c_adapter tuner_i2c_adapter; struct i2c_adapter tuner_i2c_adapter;
u8 page; /* active register page */
}; };
struct rtl2830_reg_val_mask { struct rtl2830_reg_val_mask {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment