struct it913x_dev {
struct i2c_client *client;
+ struct regmap *regmap;
struct dvb_frontend *fe;
u8 chip_ver;
u8 firmware_ver;
u32 tun_fn_min;
};
-/* read multiple registers */
-static int it913x_rd_regs(struct it913x_dev *dev,
- u32 reg, u8 *data, u8 count)
-{
- int ret;
- u8 b[3];
- struct i2c_msg msg[2] = {
- { .addr = dev->client->addr, .flags = 0,
- .buf = b, .len = sizeof(b) },
- { .addr = dev->client->addr, .flags = I2C_M_RD,
- .buf = data, .len = count }
- };
-
- b[0] = (u8)(reg >> 16) & 0xff;
- b[1] = (u8)(reg >> 8) & 0xff;
- b[2] = (u8) reg & 0xff;
-
- ret = i2c_transfer(dev->client->adapter, msg, 2);
-
- return ret;
-}
-
-/* read single register */
-static int it913x_rd_reg(struct it913x_dev *dev, u32 reg, u8 *val)
-{
- int ret;
- u8 b[1];
-
- ret = it913x_rd_regs(dev, reg, &b[0], sizeof(b));
- if (ret < 0)
- return -ENODEV;
- *val = b[0];
- return 0;
-}
-
-/* write multiple registers */
-static int it913x_wr_regs(struct it913x_dev *dev,
- u32 reg, u8 buf[], u8 count)
-{
- u8 b[256];
- struct i2c_msg msg[1] = {
- { .addr = dev->client->addr, .flags = 0,
- .buf = b, .len = 3 + count }
- };
- int ret;
-
- b[0] = (u8)(reg >> 16) & 0xff;
- b[1] = (u8)(reg >> 8) & 0xff;
- b[2] = (u8) reg & 0xff;
- memcpy(&b[3], buf, count);
-
- ret = i2c_transfer(dev->client->adapter, msg, 1);
-
- if (ret < 0)
- return -EIO;
-
- return 0;
-}
-
-/* write single register */
-static int it913x_wr_reg(struct it913x_dev *dev,
- u32 reg, u32 data)
-{
- int ret;
- u8 b[4];
- u8 len;
-
- b[0] = data >> 24;
- b[1] = (data >> 16) & 0xff;
- b[2] = (data >> 8) & 0xff;
- b[3] = data & 0xff;
- /* expand write as needed */
- if (data < 0x100)
- len = 3;
- else if (data < 0x1000)
- len = 2;
- else if (data < 0x100000)
- len = 1;
- else
- len = 0;
-
- ret = it913x_wr_regs(dev, reg, &b[len], sizeof(b) - len);
-
- return ret;
-}
-
static int it913x_script_loader(struct it913x_dev *dev,
struct it913xset *loadscript)
{
for (i = 0; i < 1000; ++i) {
if (loadscript[i].address == 0x000000)
break;
- ret = it913x_wr_regs(dev,
- loadscript[i].address,
+ ret = regmap_bulk_write(dev->regmap, loadscript[i].address,
loadscript[i].reg, loadscript[i].count);
if (ret < 0)
return -ENODEV;
{
struct it913x_dev *dev = fe->tuner_priv;
int ret, i;
- u8 reg = 0;
+ unsigned int reg;
u8 val, nv_val;
u8 nv[] = {48, 32, 24, 16, 12, 8, 6, 4, 2};
u8 b[2];
- ret = it913x_rd_reg(dev, 0x80ec86, ®);
+ ret = regmap_read(dev->regmap, 0x80ec86, ®);
switch (reg) {
case 0:
dev->tun_clk_mode = reg;
break;
}
- ret = it913x_rd_reg(dev, 0x80ed03, ®);
+ ret = regmap_read(dev->regmap, 0x80ed03, ®);
if (reg < 0)
return -ENODEV;
nv_val = 2;
for (i = 0; i < 50; i++) {
- ret = it913x_rd_regs(dev, 0x80ed23, &b[0], sizeof(b));
+ ret = regmap_bulk_read(dev->regmap, 0x80ed23, &b[0], sizeof(b));
reg = (b[1] << 8) + b[0];
if (reg > 0)
break;
- if (ret < 0)
+ if (ret)
return -ENODEV;
udelay(2000);
}
msleep(50);
else {
for (i = 0; i < 50; i++) {
- ret = it913x_rd_reg(dev, 0x80ec82, ®);
+ ret = regmap_read(dev->regmap, 0x80ec82, ®);
if (ret < 0)
return -ENODEV;
if (reg > 0)
}
/* Power Up Tuner - common all versions */
- ret = it913x_wr_reg(dev, 0x80ec40, 0x1);
- ret |= it913x_wr_reg(dev, 0x80ec57, 0x0);
- ret |= it913x_wr_reg(dev, 0x80ec58, 0x0);
+ ret = regmap_write(dev->regmap, 0x80ec40, 0x1);
+ ret |= regmap_write(dev->regmap, 0x80ec57, 0x0);
+ ret |= regmap_write(dev->regmap, 0x80ec58, 0x0);
- return it913x_wr_reg(dev, 0x80ed81, val);
+ return regmap_write(dev->regmap, 0x80ed81, val);
}
static int it9137_set_params(struct dvb_frontend *fe)
u32 bandwidth = p->bandwidth_hz;
u32 frequency_m = p->frequency;
int ret;
- u8 reg = 0;
+ unsigned int reg;
u32 frequency = frequency_m / 1000;
u32 freq, temp_f, tmp;
u16 iqik_m_cal;
} else
return -EINVAL;
- ret = it913x_rd_reg(dev, 0x80ed81, ®);
+ ret = regmap_read(dev->regmap, 0x80ed81, ®);
iqik_m_cal = (u16)reg * n_div;
if (reg < 0x20) {
struct it913x_dev *dev;
int ret;
char *chip_ver_str;
+ static const struct regmap_config regmap_config = {
+ .reg_bits = 24,
+ .val_bits = 8,
+ };
dev = kzalloc(sizeof(struct it913x_dev), GFP_KERNEL);
if (dev == NULL) {
dev->fe = cfg->fe;
dev->chip_ver = cfg->chip_ver;
dev->firmware_ver = 1;
+ dev->regmap = regmap_init_i2c(client, ®map_config);
+ if (IS_ERR(dev->regmap)) {
+ ret = PTR_ERR(dev->regmap);
+ goto err_kfree;
+ }
/* tuner RF initial */
- ret = it913x_wr_reg(dev, 0x80ec4c, 0x68);
- if (ret < 0)
- goto err;
+ ret = regmap_write(dev->regmap, 0x80ec4c, 0x68);
+ if (ret)
+ goto err_regmap_exit;
fe->tuner_priv = dev;
memcpy(&fe->ops.tuner_ops, &it913x_tuner_ops,
chip_ver_str);
dev_dbg(&dev->client->dev, "chip_ver=%02x\n", dev->chip_ver);
return 0;
+
+err_regmap_exit:
+ regmap_exit(dev->regmap);
+err_kfree:
+ kfree(dev);
err:
dev_dbg(&client->dev, "failed %d\n", ret);
- kfree(dev);
-
return ret;
}
memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops));
fe->tuner_priv = NULL;
+ regmap_exit(dev->regmap);
kfree(dev);
return 0;