#include "mn88473_priv.h"
-static struct dvb_frontend_ops mn88473_ops;
-
-/* write multiple registers */
-static int mn88473_wregs(struct mn88473_dev *dev, u16 reg, const u8 *val, int len)
-{
-#define MAX_WR_LEN 21
-#define MAX_WR_XFER_LEN (MAX_WR_LEN + 1)
- int ret;
- u8 buf[MAX_WR_XFER_LEN];
- struct i2c_msg msg[1] = {
- {
- .addr = (reg >> 8) & 0xff,
- .flags = 0,
- .len = 1 + len,
- .buf = buf,
- }
- };
-
- if (WARN_ON(len > MAX_WR_LEN))
- return -EINVAL;
-
- buf[0] = (reg >> 0) & 0xff;
- memcpy(&buf[1], val, len);
-
- ret = i2c_transfer(dev->client[0]->adapter, msg, 1);
- if (ret == 1) {
- ret = 0;
- } else {
- dev_warn(&dev->client[0]->dev,
- "i2c wr failed=%d reg=%02x len=%d\n",
- ret, reg, len);
- ret = -EREMOTEIO;
- }
-
- return ret;
-}
-
-/* read multiple registers */
-static int mn88473_rregs(struct mn88473_dev *dev, u16 reg, u8 *val, int len)
-{
-#define MAX_RD_LEN 2
-#define MAX_RD_XFER_LEN (MAX_RD_LEN)
- int ret;
- u8 buf[MAX_RD_XFER_LEN];
- struct i2c_msg msg[2] = {
- {
- .addr = (reg >> 8) & 0xff,
- .flags = 0,
- .len = 1,
- .buf = buf,
- }, {
- .addr = (reg >> 8) & 0xff,
- .flags = I2C_M_RD,
- .len = len,
- .buf = buf,
- }
- };
-
- if (WARN_ON(len > MAX_RD_LEN))
- return -EINVAL;
-
- buf[0] = (reg >> 0) & 0xff;
-
- ret = i2c_transfer(dev->client[0]->adapter, msg, 2);
- if (ret == 2) {
- memcpy(val, buf, len);
- ret = 0;
- } else {
- dev_warn(&dev->client[0]->dev,
- "i2c rd failed=%d reg=%02x len=%d\n",
- ret, reg, len);
- ret = -EREMOTEIO;
- }
-
- return ret;
-}
-
-/* write single register */
-static int mn88473_wreg(struct mn88473_dev *dev, u16 reg, u8 val)
-{
- return mn88473_wregs(dev, reg, &val, 1);
-}
-
-/* read single register */
-static int mn88473_rreg(struct mn88473_dev *dev, u16 reg, u8 *val)
-{
- return mn88473_rregs(dev, reg, val, 1);
-}
-
static int mn88473_get_tune_settings(struct dvb_frontend *fe,
struct dvb_frontend_tune_settings *s)
{
goto err;
}
- ret = mn88473_wregs(dev, 0x1c05, "\x00", 1);
- ret = mn88473_wregs(dev, 0x1cfb, "\x13", 1);
- ret = mn88473_wregs(dev, 0x1cef, "\x13", 1);
- ret = mn88473_wregs(dev, 0x1cf9, "\x13", 1);
- ret = mn88473_wregs(dev, 0x1c00, "\x18", 1);
- ret = mn88473_wregs(dev, 0x1c01, "\x01", 1);
- ret = mn88473_wregs(dev, 0x1c02, "\x21", 1);
- ret = mn88473_wreg(dev, 0x1c03, delivery_system_val);
- ret = mn88473_wregs(dev, 0x1c0b, "\x00", 1);
+ ret = regmap_write(dev->regmap[2], 0x05, 0x00);
+ ret = regmap_write(dev->regmap[2], 0xfb, 0x13);
+ ret = regmap_write(dev->regmap[2], 0xef, 0x13);
+ ret = regmap_write(dev->regmap[2], 0xf9, 0x13);
+ ret = regmap_write(dev->regmap[2], 0x00, 0x18);
+ ret = regmap_write(dev->regmap[2], 0x01, 0x01);
+ ret = regmap_write(dev->regmap[2], 0x02, 0x21);
+ ret = regmap_write(dev->regmap[2], 0x03, delivery_system_val);
+ ret = regmap_write(dev->regmap[2], 0x0b, 0x00);
for (i = 0; i < sizeof(if_val); i++) {
- ret = mn88473_wreg(dev, 0x1c10 + i, if_val[i]);
+ ret = regmap_write(dev->regmap[2], 0x10 + i, if_val[i]);
if (ret)
goto err;
}
for (i = 0; i < sizeof(bw_val); i++) {
- ret = mn88473_wreg(dev, 0x1c13 + i, bw_val[i]);
+ ret = regmap_write(dev->regmap[2], 0x13 + i, bw_val[i]);
if (ret)
goto err;
}
- ret = mn88473_wregs(dev, 0x1c2d, "\x3b", 1);
- ret = mn88473_wregs(dev, 0x1c2e, "\x00", 1);
- ret = mn88473_wregs(dev, 0x1c56, "\x0d", 1);
- ret = mn88473_wregs(dev, 0x1801, "\xba", 1);
- ret = mn88473_wregs(dev, 0x1802, "\x13", 1);
- ret = mn88473_wregs(dev, 0x1803, "\x80", 1);
- ret = mn88473_wregs(dev, 0x1804, "\xba", 1);
- ret = mn88473_wregs(dev, 0x1805, "\x91", 1);
- ret = mn88473_wregs(dev, 0x1807, "\xe7", 1);
- ret = mn88473_wregs(dev, 0x1808, "\x28", 1);
- ret = mn88473_wregs(dev, 0x180a, "\x1a", 1);
- ret = mn88473_wregs(dev, 0x1813, "\x1f", 1);
- ret = mn88473_wregs(dev, 0x1819, "\x03", 1);
- ret = mn88473_wregs(dev, 0x181d, "\xb0", 1);
- ret = mn88473_wregs(dev, 0x182a, "\x72", 1);
- ret = mn88473_wregs(dev, 0x182d, "\x00", 1);
- ret = mn88473_wregs(dev, 0x183c, "\x00", 1);
- ret = mn88473_wregs(dev, 0x183f, "\xf8", 1);
- ret = mn88473_wregs(dev, 0x1840, "\xf4", 1);
- ret = mn88473_wregs(dev, 0x1841, "\x08", 1);
- ret = mn88473_wregs(dev, 0x18d2, "\x29", 1);
- ret = mn88473_wregs(dev, 0x18d4, "\x55", 1);
- ret = mn88473_wregs(dev, 0x1a10, "\x10", 1);
- ret = mn88473_wregs(dev, 0x1a11, "\xab", 1);
- ret = mn88473_wregs(dev, 0x1a12, "\x0d", 1);
- ret = mn88473_wregs(dev, 0x1a13, "\xae", 1);
- ret = mn88473_wregs(dev, 0x1a14, "\x1d", 1);
- ret = mn88473_wregs(dev, 0x1a15, "\x9d", 1);
- ret = mn88473_wregs(dev, 0x1abe, "\x08", 1);
- ret = mn88473_wregs(dev, 0x1c09, "\x08", 1);
- ret = mn88473_wregs(dev, 0x1c08, "\x1d", 1);
- ret = mn88473_wregs(dev, 0x18b2, "\x37", 1);
- ret = mn88473_wregs(dev, 0x18d7, "\x04", 1);
- ret = mn88473_wregs(dev, 0x1c32, "\x80", 1);
- ret = mn88473_wregs(dev, 0x1c36, "\x00", 1);
- ret = mn88473_wregs(dev, 0x1cf8, "\x9f", 1);
+ ret = regmap_write(dev->regmap[2], 0x2d, 0x3b);
+ ret = regmap_write(dev->regmap[2], 0x2e, 0x00);
+ ret = regmap_write(dev->regmap[2], 0x56, 0x0d);
+ ret = regmap_write(dev->regmap[0], 0x01, 0xba);
+ ret = regmap_write(dev->regmap[0], 0x02, 0x13);
+ ret = regmap_write(dev->regmap[0], 0x03, 0x80);
+ ret = regmap_write(dev->regmap[0], 0x04, 0xba);
+ ret = regmap_write(dev->regmap[0], 0x05, 0x91);
+ ret = regmap_write(dev->regmap[0], 0x07, 0xe7);
+ ret = regmap_write(dev->regmap[0], 0x08, 0x28);
+ ret = regmap_write(dev->regmap[0], 0x0a, 0x1a);
+ ret = regmap_write(dev->regmap[0], 0x13, 0x1f);
+ ret = regmap_write(dev->regmap[0], 0x19, 0x03);
+ ret = regmap_write(dev->regmap[0], 0x1d, 0xb0);
+ ret = regmap_write(dev->regmap[0], 0x2a, 0x72);
+ ret = regmap_write(dev->regmap[0], 0x2d, 0x00);
+ ret = regmap_write(dev->regmap[0], 0x3c, 0x00);
+ ret = regmap_write(dev->regmap[0], 0x3f, 0xf8);
+ ret = regmap_write(dev->regmap[0], 0x40, 0xf4);
+ ret = regmap_write(dev->regmap[0], 0x41, 0x08);
+ ret = regmap_write(dev->regmap[0], 0xd2, 0x29);
+ ret = regmap_write(dev->regmap[0], 0xd4, 0x55);
+ ret = regmap_write(dev->regmap[1], 0x10, 0x10);
+ ret = regmap_write(dev->regmap[1], 0x11, 0xab);
+ ret = regmap_write(dev->regmap[1], 0x12, 0x0d);
+ ret = regmap_write(dev->regmap[1], 0x13, 0xae);
+ ret = regmap_write(dev->regmap[1], 0x14, 0x1d);
+ ret = regmap_write(dev->regmap[1], 0x15, 0x9d);
+ ret = regmap_write(dev->regmap[1], 0xbe, 0x08);
+ ret = regmap_write(dev->regmap[2], 0x09, 0x08);
+ ret = regmap_write(dev->regmap[2], 0x08, 0x1d);
+ ret = regmap_write(dev->regmap[0], 0xb2, 0x37);
+ ret = regmap_write(dev->regmap[0], 0xd7, 0x04);
+ ret = regmap_write(dev->regmap[2], 0x32, 0x80);
+ ret = regmap_write(dev->regmap[2], 0x36, 0x00);
+ ret = regmap_write(dev->regmap[2], 0xf8, 0x9f);
if (ret)
goto err;
dev_info(&client->dev, "downloading firmware from file '%s'\n",
fw_file);
- ret = mn88473_wreg(dev, 0x18f5, 0x03);
+ ret = regmap_write(dev->regmap[0], 0xf5, 0x03);
if (ret)
goto err;
if (len > (dev->i2c_wr_max - 1))
len = (dev->i2c_wr_max - 1);
- ret = mn88473_wregs(dev, 0x18f6,
+ ret = regmap_bulk_write(dev->regmap[0], 0xf6,
&fw->data[fw->size - remaining], len);
if (ret) {
dev_err(&client->dev, "firmware download failed=%d\n",
}
}
- ret = mn88473_wreg(dev, 0x18f5, 0x00);
+ ret = regmap_write(dev->regmap[0], 0xf5, 0x00);
if (ret)
goto err;
dev_dbg(&client->dev, "\n");
- ret = mn88473_wreg(dev, 0x1c05, 0x3e);
+ ret = regmap_write(dev->regmap[2], 0x05, 0x3e);
if (ret)
goto err;
struct mn88473_config *config = client->dev.platform_data;
struct mn88473_dev *dev;
int ret;
- u8 u8tmp;
+ unsigned int utmp;
+ static const struct regmap_config regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ };
dev_dbg(&client->dev, "\n");
goto err;
}
- dev->client[0] = client;
dev->i2c_wr_max = config->i2c_wr_max;
+ dev->client[0] = client;
+ dev->regmap[0] = regmap_init_i2c(dev->client[0], ®map_config);
+ if (IS_ERR(dev->regmap[0])) {
+ ret = PTR_ERR(dev->regmap[0]);
+ goto err_kfree;
+ }
/* check demod answers to I2C */
- ret = mn88473_rreg(dev, 0x1c00, &u8tmp);
+ ret = regmap_read(dev->regmap[0], 0x00, &utmp);
if (ret)
- goto err_kfree;
+ goto err_regmap_0_regmap_exit;
/*
* Chip has three I2C addresses for different register pages. Used
ret = -ENODEV;
dev_err(&client->dev, "I2C registration failed\n");
if (ret)
- goto err_kfree;
+ goto err_regmap_0_regmap_exit;
+ }
+ dev->regmap[1] = regmap_init_i2c(dev->client[1], ®map_config);
+ if (IS_ERR(dev->regmap[1])) {
+ ret = PTR_ERR(dev->regmap[1]);
+ goto err_client_1_i2c_unregister_device;
}
i2c_set_clientdata(dev->client[1], dev);
ret = -ENODEV;
dev_err(&client->dev, "2nd I2C registration failed\n");
if (ret)
- goto err_client_1_i2c_unregister_device;
+ goto err_regmap_1_regmap_exit;
+ }
+ dev->regmap[2] = regmap_init_i2c(dev->client[2], ®map_config);
+ if (IS_ERR(dev->regmap[2])) {
+ ret = PTR_ERR(dev->regmap[2]);
+ goto err_client_2_i2c_unregister_device;
}
i2c_set_clientdata(dev->client[2], dev);
dev_info(&dev->client[0]->dev, "Panasonic MN88473 successfully attached\n");
return 0;
+err_client_2_i2c_unregister_device:
+ i2c_unregister_device(dev->client[2]);
+err_regmap_1_regmap_exit:
+ regmap_exit(dev->regmap[1]);
err_client_1_i2c_unregister_device:
i2c_unregister_device(dev->client[1]);
+err_regmap_0_regmap_exit:
+ regmap_exit(dev->regmap[0]);
err_kfree:
kfree(dev);
err:
dev_dbg(&client->dev, "\n");
+ regmap_exit(dev->regmap[2]);
i2c_unregister_device(dev->client[2]);
+
+ regmap_exit(dev->regmap[1]);
i2c_unregister_device(dev->client[1]);
+ regmap_exit(dev->regmap[0]);
+
kfree(dev);
return 0;