#include "tda10071_priv.h"
-/* Max transfer size done by I2C transfer functions */
-#define MAX_XFER_SIZE 64
-
static struct dvb_frontend_ops tda10071_ops;
-/* write multiple registers */
-static int tda10071_wr_regs(struct tda10071_dev *dev, u8 reg, u8 *val,
- int len)
-{
- struct i2c_client *client = dev->client;
- int ret;
- u8 buf[MAX_XFER_SIZE];
- struct i2c_msg msg[1] = {
- {
- .addr = client->addr,
- .flags = 0,
- .len = 1 + len,
- .buf = buf,
- }
- };
-
- if (1 + len > sizeof(buf)) {
- dev_warn(&client->dev, "i2c wr reg=%04x: len=%d is too big!\n",
- reg, len);
- return -EINVAL;
- }
-
- buf[0] = reg;
- memcpy(&buf[1], val, len);
-
- ret = i2c_transfer(client->adapter, msg, 1);
- if (ret == 1) {
- ret = 0;
- } else {
- dev_warn(&client->dev, "i2c wr failed=%d reg=%02x len=%d\n",
- ret, reg, len);
- ret = -EREMOTEIO;
- }
- return ret;
-}
-
-/* read multiple registers */
-static int tda10071_rd_regs(struct tda10071_dev *dev, u8 reg, u8 *val,
- int len)
-{
- struct i2c_client *client = dev->client;
- int ret;
- u8 buf[MAX_XFER_SIZE];
- struct i2c_msg msg[2] = {
- {
- .addr = client->addr,
- .flags = 0,
- .len = 1,
- .buf = ®,
- }, {
- .addr = client->addr,
- .flags = I2C_M_RD,
- .len = len,
- .buf = buf,
- }
- };
-
- if (len > sizeof(buf)) {
- dev_warn(&client->dev, "i2c wr reg=%04x: len=%d is too big!\n",
- reg, len);
- return -EINVAL;
- }
-
- ret = i2c_transfer(client->adapter, msg, 2);
- if (ret == 2) {
- memcpy(val, buf, len);
- ret = 0;
- } else {
- dev_warn(&client->dev, "i2c rd failed=%d reg=%02x len=%d\n",
- ret, reg, len);
- ret = -EREMOTEIO;
- }
- return ret;
-}
-
-/* write single register */
-static int tda10071_wr_reg(struct tda10071_dev *dev, u8 reg, u8 val)
-{
- return tda10071_wr_regs(dev, reg, &val, 1);
-}
-
-/* read single register */
-static int tda10071_rd_reg(struct tda10071_dev *dev, u8 reg, u8 *val)
-{
- return tda10071_rd_regs(dev, reg, val, 1);
-}
-
+/*
+ * XXX: regmap_update_bits() does not fit our needs as it does not support
+ * partially volatile registers. Also it performs register read even mask is as
+ * wide as register value.
+ */
/* write single register with mask */
static int tda10071_wr_reg_mask(struct tda10071_dev *dev,
u8 reg, u8 val, u8 mask)
/* no need for read if whole reg is written */
if (mask != 0xff) {
- ret = tda10071_rd_regs(dev, reg, &tmp, 1);
+ ret = regmap_bulk_read(dev->regmap, reg, &tmp, 1);
if (ret)
return ret;
val |= tmp;
}
- return tda10071_wr_regs(dev, reg, &val, 1);
-}
-
-/* read single register with mask */
-static int tda10071_rd_reg_mask(struct tda10071_dev *dev,
- u8 reg, u8 *val, u8 mask)
-{
- int ret, i;
- u8 tmp;
-
- ret = tda10071_rd_regs(dev, reg, &tmp, 1);
- if (ret)
- return ret;
-
- tmp &= mask;
-
- /* find position of the first bit */
- for (i = 0; i < 8; i++) {
- if ((mask >> i) & 0x01)
- break;
- }
- *val = tmp >> i;
-
- return 0;
+ return regmap_bulk_write(dev->regmap, reg, &val, 1);
}
/* execute firmware command */
{
struct i2c_client *client = dev->client;
int ret, i;
- u8 tmp;
+ unsigned int uitmp;
if (!dev->warm) {
ret = -EFAULT;
}
/* write cmd and args for firmware */
- ret = tda10071_wr_regs(dev, 0x00, cmd->args, cmd->len);
+ ret = regmap_bulk_write(dev->regmap, 0x00, cmd->args, cmd->len);
if (ret)
goto error;
/* start cmd execution */
- ret = tda10071_wr_reg(dev, 0x1f, 1);
+ ret = regmap_write(dev->regmap, 0x1f, 1);
if (ret)
goto error;
/* wait cmd execution terminate */
- for (i = 1000, tmp = 1; i && tmp; i--) {
- ret = tda10071_rd_reg(dev, 0x1f, &tmp);
+ for (i = 1000, uitmp = 1; i && uitmp; i--) {
+ ret = regmap_read(dev->regmap, 0x1f, &uitmp);
if (ret)
goto error;
struct i2c_client *client = dev->client;
struct tda10071_cmd cmd;
int ret, i;
- u8 tmp;
+ unsigned int uitmp;
if (!dev->warm) {
ret = -EFAULT;
}
/* wait LNB TX */
- for (i = 500, tmp = 0; i && !tmp; i--) {
- ret = tda10071_rd_reg_mask(dev, 0x47, &tmp, 0x01);
+ for (i = 500, uitmp = 0; i && !uitmp; i--) {
+ ret = regmap_read(dev->regmap, 0x47, &uitmp);
if (ret)
goto error;
-
+ uitmp = (uitmp >> 0) & 1;
usleep_range(10000, 20000);
}
goto error;
}
- ret = tda10071_wr_reg_mask(dev, 0x47, 0x00, 0x01);
+ ret = regmap_update_bits(dev->regmap, 0x47, 0x01, 0x00);
if (ret)
goto error;
struct i2c_client *client = dev->client;
struct tda10071_cmd cmd;
int ret, i;
- u8 tmp;
+ unsigned int uitmp;
if (!dev->warm) {
ret = -EFAULT;
dev_dbg(&client->dev, "\n");
/* wait LNB RX */
- for (i = 500, tmp = 0; i && !tmp; i--) {
- ret = tda10071_rd_reg_mask(dev, 0x47, &tmp, 0x02);
+ for (i = 500, uitmp = 0; i && !uitmp; i--) {
+ ret = regmap_read(dev->regmap, 0x47, &uitmp);
if (ret)
goto error;
-
+ uitmp = (uitmp >> 1) & 1;
usleep_range(10000, 20000);
}
}
/* reply len */
- ret = tda10071_rd_reg(dev, 0x46, &tmp);
+ ret = regmap_read(dev->regmap, 0x46, &uitmp);
if (ret)
goto error;
- reply->msg_len = tmp & 0x1f; /* [4:0] */
+ reply->msg_len = uitmp & 0x1f; /* [4:0] */
if (reply->msg_len > sizeof(reply->msg))
reply->msg_len = sizeof(reply->msg); /* truncate API max */
if (ret)
goto error;
- ret = tda10071_rd_regs(dev, cmd.len, reply->msg, reply->msg_len);
+ ret = regmap_bulk_read(dev->regmap, cmd.len, reply->msg,
+ reply->msg_len);
if (ret)
goto error;
struct i2c_client *client = dev->client;
struct tda10071_cmd cmd;
int ret, i;
- u8 tmp, burst;
+ unsigned int uitmp;
+ u8 burst;
if (!dev->warm) {
ret = -EFAULT;
}
/* wait LNB TX */
- for (i = 500, tmp = 0; i && !tmp; i--) {
- ret = tda10071_rd_reg_mask(dev, 0x47, &tmp, 0x01);
+ for (i = 500, uitmp = 0; i && !uitmp; i--) {
+ ret = regmap_read(dev->regmap, 0x47, &uitmp);
if (ret)
goto error;
-
+ uitmp = (uitmp >> 0) & 1;
usleep_range(10000, 20000);
}
goto error;
}
- ret = tda10071_wr_reg_mask(dev, 0x47, 0x00, 0x01);
+ ret = regmap_update_bits(dev->regmap, 0x47, 0x01, 0x00);
if (ret)
goto error;
struct tda10071_dev *dev = fe->demodulator_priv;
struct i2c_client *client = dev->client;
int ret;
- u8 tmp;
+ unsigned int uitmp;
*status = 0;
goto error;
}
- ret = tda10071_rd_reg(dev, 0x39, &tmp);
+ ret = regmap_read(dev->regmap, 0x39, &uitmp);
if (ret)
goto error;
/* 0x39[0] tuner PLL */
- if (tmp & 0x02) /* demod PLL */
+ if (uitmp & 0x02) /* demod PLL */
*status |= FE_HAS_SIGNAL | FE_HAS_CARRIER;
- if (tmp & 0x04) /* viterbi or LDPC*/
+ if (uitmp & 0x04) /* viterbi or LDPC*/
*status |= FE_HAS_VITERBI;
- if (tmp & 0x08) /* RS or BCH */
+ if (uitmp & 0x08) /* RS or BCH */
*status |= FE_HAS_SYNC | FE_HAS_LOCK;
dev->fe_status = *status;
goto error;
}
- ret = tda10071_rd_regs(dev, 0x3a, buf, 2);
+ ret = regmap_bulk_read(dev->regmap, 0x3a, buf, 2);
if (ret)
goto error;
struct i2c_client *client = dev->client;
struct tda10071_cmd cmd;
int ret;
- u8 tmp;
+ unsigned int uitmp;
if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) {
*strength = 0;
goto error;
/* input power estimate dBm */
- ret = tda10071_rd_reg(dev, 0x50, &tmp);
+ ret = regmap_read(dev->regmap, 0x50, &uitmp);
if (ret)
goto error;
- if (tmp < 181)
- tmp = 181; /* -75 dBm */
- else if (tmp > 236)
- tmp = 236; /* -20 dBm */
+ if (uitmp < 181)
+ uitmp = 181; /* -75 dBm */
+ else if (uitmp > 236)
+ uitmp = 236; /* -20 dBm */
/* scale value to 0x0000-0xffff */
- *strength = (tmp-181) * 0xffff / (236-181);
+ *strength = (uitmp-181) * 0xffff / (236-181);
return ret;
error:
struct i2c_client *client = dev->client;
struct tda10071_cmd cmd;
int ret, i, len;
- u8 tmp, reg, buf[8];
+ unsigned int uitmp;
+ u8 reg, buf[8];
if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) {
*ber = dev->ber = 0;
return 0;
}
- ret = tda10071_rd_reg(dev, reg, &tmp);
+ ret = regmap_read(dev->regmap, reg, &uitmp);
if (ret)
goto error;
- if (dev->meas_count[i] == tmp) {
- dev_dbg(&client->dev, "meas not ready=%02x\n", tmp);
+ if (dev->meas_count[i] == uitmp) {
+ dev_dbg(&client->dev, "meas not ready=%02x\n", uitmp);
*ber = dev->ber;
return 0;
} else {
- dev->meas_count[i] = tmp;
+ dev->meas_count[i] = uitmp;
}
cmd.args[0] = CMD_BER_UPDATE_COUNTERS;
if (ret)
goto error;
- ret = tda10071_rd_regs(dev, cmd.len, buf, len);
+ ret = regmap_bulk_read(dev->regmap, cmd.len, buf, len);
if (ret)
goto error;
else
div = 4;
- ret = tda10071_wr_reg(dev, 0x81, div);
+ ret = regmap_write(dev->regmap, 0x81, div);
if (ret)
goto error;
- ret = tda10071_wr_reg(dev, 0xe3, div);
+ ret = regmap_write(dev->regmap, 0xe3, div);
if (ret)
goto error;
goto error;
}
- ret = tda10071_rd_regs(dev, 0x30, buf, 5);
+ ret = regmap_bulk_read(dev->regmap, 0x30, buf, 5);
if (ret)
goto error;
c->frequency = (buf[2] << 16) | (buf[3] << 8) | (buf[4] << 0);
- ret = tda10071_rd_regs(dev, 0x52, buf, 3);
+ ret = regmap_bulk_read(dev->regmap, 0x52, buf, 3);
if (ret)
goto error;
struct i2c_client *client = dev->client;
struct tda10071_cmd cmd;
int ret, i, len, remaining, fw_size;
+ unsigned int uitmp;
const struct firmware *fw;
u8 *fw_file = TDA10071_FIRMWARE;
u8 tmp, buf[4];
}
/* download firmware */
- ret = tda10071_wr_reg(dev, 0xe0, 0x7f);
+ ret = regmap_write(dev->regmap, 0xe0, 0x7f);
if (ret)
goto error_release_firmware;
- ret = tda10071_wr_reg(dev, 0xf7, 0x81);
+ ret = regmap_write(dev->regmap, 0xf7, 0x81);
if (ret)
goto error_release_firmware;
- ret = tda10071_wr_reg(dev, 0xf8, 0x00);
+ ret = regmap_write(dev->regmap, 0xf8, 0x00);
if (ret)
goto error_release_firmware;
- ret = tda10071_wr_reg(dev, 0xf9, 0x00);
+ ret = regmap_write(dev->regmap, 0xf9, 0x00);
if (ret)
goto error_release_firmware;
if (len > (dev->i2c_wr_max - 1))
len = (dev->i2c_wr_max - 1);
- ret = tda10071_wr_regs(dev, 0xfa,
+ ret = regmap_bulk_write(dev->regmap, 0xfa,
(u8 *) &fw->data[fw_size - remaining], len);
if (ret) {
dev_err(&client->dev,
}
release_firmware(fw);
- ret = tda10071_wr_reg(dev, 0xf7, 0x0c);
+ ret = regmap_write(dev->regmap, 0xf7, 0x0c);
if (ret)
goto error;
- ret = tda10071_wr_reg(dev, 0xe0, 0x00);
+ ret = regmap_write(dev->regmap, 0xe0, 0x00);
if (ret)
goto error;
msleep(250);
/* firmware status */
- ret = tda10071_rd_reg(dev, 0x51, &tmp);
+ ret = regmap_read(dev->regmap, 0x51, &uitmp);
if (ret)
goto error;
- if (tmp) {
+ if (uitmp) {
dev_info(&client->dev, "firmware did not run\n");
ret = -EFAULT;
goto error;
if (ret)
goto error;
- ret = tda10071_rd_regs(dev, cmd.len, buf, 4);
+ ret = regmap_bulk_read(dev->regmap, cmd.len, buf, 4);
if (ret)
goto error;
dev_info(&client->dev, "found a '%s' in warm state\n",
tda10071_ops.info.name);
- ret = tda10071_rd_regs(dev, 0x81, buf, 2);
+ ret = regmap_bulk_read(dev->regmap, 0x81, buf, 2);
if (ret)
goto error;
if (ret)
goto error;
- ret = tda10071_wr_reg_mask(dev, 0xf0, 0x01, 0x01);
+ ret = regmap_update_bits(dev->regmap, 0xf0, 0x01, 0x01);
if (ret)
goto error;
struct tda10071_dev *dev;
struct tda10071_platform_data *pdata = client->dev.platform_data;
int ret;
- u8 u8tmp;
+ unsigned int uitmp;
+ static const struct regmap_config regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ };
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev) {
dev->spec_inv = pdata->spec_inv;
dev->pll_multiplier = pdata->pll_multiplier;
dev->tuner_i2c_addr = pdata->tuner_i2c_addr;
+ dev->regmap = devm_regmap_init_i2c(client, ®map_config);
+ if (IS_ERR(dev->regmap)) {
+ ret = PTR_ERR(dev->regmap);
+ goto err_kfree;
+ }
/* chip ID */
- ret = tda10071_rd_reg(dev, 0xff, &u8tmp);
+ ret = regmap_read(dev->regmap, 0xff, &uitmp);
if (ret)
goto err_kfree;
- if (u8tmp != 0x0f) {
+ if (uitmp != 0x0f) {
ret = -ENODEV;
goto err_kfree;
}
/* chip type */
- ret = tda10071_rd_reg(dev, 0xdd, &u8tmp);
+ ret = regmap_read(dev->regmap, 0xdd, &uitmp);
if (ret)
goto err_kfree;
- if (u8tmp != 0x00) {
+ if (uitmp != 0x00) {
ret = -ENODEV;
goto err_kfree;
}
/* chip version */
- ret = tda10071_rd_reg(dev, 0xfe, &u8tmp);
+ ret = regmap_read(dev->regmap, 0xfe, &uitmp);
if (ret)
goto err_kfree;
- if (u8tmp != 0x01) {
+ if (uitmp != 0x01) {
ret = -ENODEV;
goto err_kfree;
}