[media] af9033: convert to regmap api
Use regmap to cover I2C register operations. Signed-off-by: Antti Palosaari <crope@iki.fi> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
This commit is contained in:
Родитель
09bfd96ca3
Коммит
bc85d5e2fa
|
@ -852,6 +852,7 @@ config DVB_M88RS2000
|
||||||
config DVB_AF9033
|
config DVB_AF9033
|
||||||
tristate "Afatech AF9033 DVB-T demodulator"
|
tristate "Afatech AF9033 DVB-T demodulator"
|
||||||
depends on DVB_CORE && I2C
|
depends on DVB_CORE && I2C
|
||||||
|
select REGMAP_I2C
|
||||||
default m if !MEDIA_SUBDRV_AUTOSELECT
|
default m if !MEDIA_SUBDRV_AUTOSELECT
|
||||||
|
|
||||||
config DVB_HORUS3A
|
config DVB_HORUS3A
|
||||||
|
|
|
@ -21,11 +21,9 @@
|
||||||
|
|
||||||
#include "af9033_priv.h"
|
#include "af9033_priv.h"
|
||||||
|
|
||||||
/* Max transfer size done by I2C transfer functions */
|
|
||||||
#define MAX_XFER_SIZE 64
|
|
||||||
|
|
||||||
struct af9033_dev {
|
struct af9033_dev {
|
||||||
struct i2c_client *client;
|
struct i2c_client *client;
|
||||||
|
struct regmap *regmap;
|
||||||
struct dvb_frontend fe;
|
struct dvb_frontend fe;
|
||||||
struct af9033_config cfg;
|
struct af9033_config cfg;
|
||||||
bool is_af9035;
|
bool is_af9035;
|
||||||
|
@ -43,134 +41,6 @@ struct af9033_dev {
|
||||||
u64 total_block_count;
|
u64 total_block_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* write multiple registers */
|
|
||||||
static int af9033_wr_regs(struct af9033_dev *dev, u32 reg, const u8 *val,
|
|
||||||
int len)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
u8 buf[MAX_XFER_SIZE];
|
|
||||||
struct i2c_msg msg[1] = {
|
|
||||||
{
|
|
||||||
.addr = dev->client->addr,
|
|
||||||
.flags = 0,
|
|
||||||
.len = 3 + len,
|
|
||||||
.buf = buf,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (3 + len > sizeof(buf)) {
|
|
||||||
dev_warn(&dev->client->dev,
|
|
||||||
"i2c wr reg=%04x: len=%d is too big!\n",
|
|
||||||
reg, len);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf[0] = (reg >> 16) & 0xff;
|
|
||||||
buf[1] = (reg >> 8) & 0xff;
|
|
||||||
buf[2] = (reg >> 0) & 0xff;
|
|
||||||
memcpy(&buf[3], val, len);
|
|
||||||
|
|
||||||
ret = i2c_transfer(dev->client->adapter, msg, 1);
|
|
||||||
if (ret == 1) {
|
|
||||||
ret = 0;
|
|
||||||
} else {
|
|
||||||
dev_warn(&dev->client->dev, "i2c wr failed=%d reg=%06x len=%d\n",
|
|
||||||
ret, reg, len);
|
|
||||||
ret = -EREMOTEIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* read multiple registers */
|
|
||||||
static int af9033_rd_regs(struct af9033_dev *dev, u32 reg, u8 *val, int len)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
u8 buf[3] = { (reg >> 16) & 0xff, (reg >> 8) & 0xff,
|
|
||||||
(reg >> 0) & 0xff };
|
|
||||||
struct i2c_msg msg[2] = {
|
|
||||||
{
|
|
||||||
.addr = dev->client->addr,
|
|
||||||
.flags = 0,
|
|
||||||
.len = sizeof(buf),
|
|
||||||
.buf = buf
|
|
||||||
}, {
|
|
||||||
.addr = dev->client->addr,
|
|
||||||
.flags = I2C_M_RD,
|
|
||||||
.len = len,
|
|
||||||
.buf = val
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ret = i2c_transfer(dev->client->adapter, msg, 2);
|
|
||||||
if (ret == 2) {
|
|
||||||
ret = 0;
|
|
||||||
} else {
|
|
||||||
dev_warn(&dev->client->dev, "i2c rd failed=%d reg=%06x len=%d\n",
|
|
||||||
ret, reg, len);
|
|
||||||
ret = -EREMOTEIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* write single register */
|
|
||||||
static int af9033_wr_reg(struct af9033_dev *dev, u32 reg, u8 val)
|
|
||||||
{
|
|
||||||
return af9033_wr_regs(dev, reg, &val, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* read single register */
|
|
||||||
static int af9033_rd_reg(struct af9033_dev *dev, u32 reg, u8 *val)
|
|
||||||
{
|
|
||||||
return af9033_rd_regs(dev, reg, val, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* write single register with mask */
|
|
||||||
static int af9033_wr_reg_mask(struct af9033_dev *dev, u32 reg, u8 val,
|
|
||||||
u8 mask)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
u8 tmp;
|
|
||||||
|
|
||||||
/* no need for read if whole reg is written */
|
|
||||||
if (mask != 0xff) {
|
|
||||||
ret = af9033_rd_regs(dev, reg, &tmp, 1);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
val &= mask;
|
|
||||||
tmp &= ~mask;
|
|
||||||
val |= tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
return af9033_wr_regs(dev, reg, &val, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* read single register with mask */
|
|
||||||
static int af9033_rd_reg_mask(struct af9033_dev *dev, u32 reg, u8 *val,
|
|
||||||
u8 mask)
|
|
||||||
{
|
|
||||||
int ret, i;
|
|
||||||
u8 tmp;
|
|
||||||
|
|
||||||
ret = af9033_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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* write reg val table using reg addr auto increment */
|
/* write reg val table using reg addr auto increment */
|
||||||
static int af9033_wr_reg_val_tab(struct af9033_dev *dev,
|
static int af9033_wr_reg_val_tab(struct af9033_dev *dev,
|
||||||
const struct reg_val *tab, int tab_len)
|
const struct reg_val *tab, int tab_len)
|
||||||
|
@ -190,8 +60,9 @@ static int af9033_wr_reg_val_tab(struct af9033_dev *dev,
|
||||||
buf[j] = tab[i].val;
|
buf[j] = tab[i].val;
|
||||||
|
|
||||||
if (i == tab_len - 1 || tab[i].reg != tab[i + 1].reg - 1) {
|
if (i == tab_len - 1 || tab[i].reg != tab[i + 1].reg - 1) {
|
||||||
ret = af9033_wr_regs(dev, tab[i].reg - j, buf, j + 1);
|
ret = regmap_bulk_write(dev->regmap, tab[i].reg - j,
|
||||||
if (ret < 0)
|
buf, j + 1);
|
||||||
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
j = 0;
|
j = 0;
|
||||||
|
@ -281,8 +152,8 @@ static int af9033_init(struct dvb_frontend *fe)
|
||||||
dev_dbg(&dev->client->dev, "clock=%d clock_cw=%08x\n",
|
dev_dbg(&dev->client->dev, "clock=%d clock_cw=%08x\n",
|
||||||
dev->cfg.clock, clock_cw);
|
dev->cfg.clock, clock_cw);
|
||||||
|
|
||||||
ret = af9033_wr_regs(dev, 0x800025, buf, 4);
|
ret = regmap_bulk_write(dev->regmap, 0x800025, buf, 4);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
/* program ADC control */
|
/* program ADC control */
|
||||||
|
@ -305,41 +176,39 @@ static int af9033_init(struct dvb_frontend *fe)
|
||||||
dev_dbg(&dev->client->dev, "adc=%d adc_cw=%06x\n",
|
dev_dbg(&dev->client->dev, "adc=%d adc_cw=%06x\n",
|
||||||
clock_adc_lut[i].adc, adc_cw);
|
clock_adc_lut[i].adc, adc_cw);
|
||||||
|
|
||||||
ret = af9033_wr_regs(dev, 0x80f1cd, buf, 3);
|
ret = regmap_bulk_write(dev->regmap, 0x80f1cd, buf, 3);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
/* program register table */
|
/* program register table */
|
||||||
for (i = 0; i < ARRAY_SIZE(tab); i++) {
|
for (i = 0; i < ARRAY_SIZE(tab); i++) {
|
||||||
ret = af9033_wr_reg_mask(dev, tab[i].reg, tab[i].val,
|
ret = regmap_update_bits(dev->regmap, tab[i].reg, tab[i].mask,
|
||||||
tab[i].mask);
|
tab[i].val);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clock output */
|
/* clock output */
|
||||||
if (dev->cfg.dyn0_clk) {
|
if (dev->cfg.dyn0_clk) {
|
||||||
ret = af9033_wr_reg(dev, 0x80fba8, 0x00);
|
ret = regmap_write(dev->regmap, 0x80fba8, 0x00);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* settings for TS interface */
|
/* settings for TS interface */
|
||||||
if (dev->cfg.ts_mode == AF9033_TS_MODE_USB) {
|
if (dev->cfg.ts_mode == AF9033_TS_MODE_USB) {
|
||||||
ret = af9033_wr_reg_mask(dev, 0x80f9a5, 0x00, 0x01);
|
ret = regmap_update_bits(dev->regmap, 0x80f9a5, 0x01, 0x00);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
ret = regmap_update_bits(dev->regmap, 0x80f9b5, 0x01, 0x01);
|
||||||
ret = af9033_wr_reg_mask(dev, 0x80f9b5, 0x01, 0x01);
|
if (ret)
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
goto err;
|
||||||
} else {
|
} else {
|
||||||
ret = af9033_wr_reg_mask(dev, 0x80f990, 0x00, 0x01);
|
ret = regmap_update_bits(dev->regmap, 0x80f990, 0x01, 0x00);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
ret = regmap_update_bits(dev->regmap, 0x80f9b5, 0x01, 0x00);
|
||||||
ret = af9033_wr_reg_mask(dev, 0x80f9b5, 0x00, 0x01);
|
if (ret)
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,7 +234,7 @@ static int af9033_init(struct dvb_frontend *fe)
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = af9033_wr_reg_val_tab(dev, init, len);
|
ret = af9033_wr_reg_val_tab(dev, init, len);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
/* load tuner specific settings */
|
/* load tuner specific settings */
|
||||||
|
@ -427,20 +296,18 @@ static int af9033_init(struct dvb_frontend *fe)
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = af9033_wr_reg_val_tab(dev, init, len);
|
ret = af9033_wr_reg_val_tab(dev, init, len);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
if (dev->cfg.ts_mode == AF9033_TS_MODE_SERIAL) {
|
if (dev->cfg.ts_mode == AF9033_TS_MODE_SERIAL) {
|
||||||
ret = af9033_wr_reg_mask(dev, 0x00d91c, 0x01, 0x01);
|
ret = regmap_update_bits(dev->regmap, 0x00d91c, 0x01, 0x01);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
ret = regmap_update_bits(dev->regmap, 0x00d917, 0x01, 0x00);
|
||||||
ret = af9033_wr_reg_mask(dev, 0x00d917, 0x00, 0x01);
|
if (ret)
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
goto err;
|
||||||
|
ret = regmap_update_bits(dev->regmap, 0x00d916, 0x01, 0x00);
|
||||||
ret = af9033_wr_reg_mask(dev, 0x00d916, 0x00, 0x01);
|
if (ret)
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,8 +315,8 @@ static int af9033_init(struct dvb_frontend *fe)
|
||||||
case AF9033_TUNER_IT9135_60:
|
case AF9033_TUNER_IT9135_60:
|
||||||
case AF9033_TUNER_IT9135_61:
|
case AF9033_TUNER_IT9135_61:
|
||||||
case AF9033_TUNER_IT9135_62:
|
case AF9033_TUNER_IT9135_62:
|
||||||
ret = af9033_wr_reg(dev, 0x800000, 0x01);
|
ret = regmap_write(dev->regmap, 0x800000, 0x01);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,45 +346,31 @@ err:
|
||||||
static int af9033_sleep(struct dvb_frontend *fe)
|
static int af9033_sleep(struct dvb_frontend *fe)
|
||||||
{
|
{
|
||||||
struct af9033_dev *dev = fe->demodulator_priv;
|
struct af9033_dev *dev = fe->demodulator_priv;
|
||||||
int ret, i;
|
int ret;
|
||||||
u8 tmp;
|
unsigned int utmp;
|
||||||
|
|
||||||
ret = af9033_wr_reg(dev, 0x80004c, 1);
|
ret = regmap_write(dev->regmap, 0x80004c, 0x01);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
ret = regmap_write(dev->regmap, 0x800000, 0x00);
|
||||||
ret = af9033_wr_reg(dev, 0x800000, 0);
|
if (ret)
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
goto err;
|
||||||
|
ret = regmap_read_poll_timeout(dev->regmap, 0x80004c, utmp, utmp == 0,
|
||||||
for (i = 100, tmp = 1; i && tmp; i--) {
|
5000, 1000000);
|
||||||
ret = af9033_rd_reg(dev, 0x80004c, &tmp);
|
if (ret)
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
usleep_range(200, 10000);
|
|
||||||
}
|
|
||||||
|
|
||||||
dev_dbg(&dev->client->dev, "loop=%d\n", i);
|
|
||||||
|
|
||||||
if (i == 0) {
|
|
||||||
ret = -ETIMEDOUT;
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
ret = regmap_update_bits(dev->regmap, 0x80fb24, 0x08, 0x08);
|
||||||
|
if (ret)
|
||||||
ret = af9033_wr_reg_mask(dev, 0x80fb24, 0x08, 0x08);
|
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
/* prevent current leak (?) */
|
/* prevent current leak (?) */
|
||||||
if (dev->cfg.ts_mode == AF9033_TS_MODE_SERIAL) {
|
if (dev->cfg.ts_mode == AF9033_TS_MODE_SERIAL) {
|
||||||
/* enable parallel TS */
|
/* enable parallel TS */
|
||||||
ret = af9033_wr_reg_mask(dev, 0x00d917, 0x00, 0x01);
|
ret = regmap_update_bits(dev->regmap, 0x00d917, 0x01, 0x00);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
ret = regmap_update_bits(dev->regmap, 0x00d916, 0x01, 0x01);
|
||||||
ret = af9033_wr_reg_mask(dev, 0x00d916, 0x01, 0x01);
|
if (ret)
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -588,8 +441,10 @@ static int af9033_set_frontend(struct dvb_frontend *fe)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = af9033_wr_regs(dev, 0x800001,
|
ret = regmap_bulk_write(dev->regmap, 0x800001, coeff_lut[i].val,
|
||||||
coeff_lut[i].val, sizeof(coeff_lut[i].val));
|
sizeof(coeff_lut[i].val));
|
||||||
|
if (ret)
|
||||||
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* program frequency control */
|
/* program frequency control */
|
||||||
|
@ -641,27 +496,25 @@ static int af9033_set_frontend(struct dvb_frontend *fe)
|
||||||
if (if_frequency == 0)
|
if (if_frequency == 0)
|
||||||
buf[2] = 0;
|
buf[2] = 0;
|
||||||
|
|
||||||
ret = af9033_wr_regs(dev, 0x800029, buf, 3);
|
ret = regmap_bulk_write(dev->regmap, 0x800029, buf, 3);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
dev->bandwidth_hz = c->bandwidth_hz;
|
dev->bandwidth_hz = c->bandwidth_hz;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = af9033_wr_reg_mask(dev, 0x80f904, bandwidth_reg_val, 0x03);
|
ret = regmap_update_bits(dev->regmap, 0x80f904, 0x03,
|
||||||
if (ret < 0)
|
bandwidth_reg_val);
|
||||||
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
ret = regmap_write(dev->regmap, 0x800040, 0x00);
|
||||||
ret = af9033_wr_reg(dev, 0x800040, 0x00);
|
if (ret)
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
goto err;
|
||||||
|
ret = regmap_write(dev->regmap, 0x800047, 0x00);
|
||||||
ret = af9033_wr_reg(dev, 0x800047, 0x00);
|
if (ret)
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
goto err;
|
||||||
|
ret = regmap_update_bits(dev->regmap, 0x80f999, 0x01, 0x00);
|
||||||
ret = af9033_wr_reg_mask(dev, 0x80f999, 0x00, 0x01);
|
if (ret)
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
if (c->frequency <= 230000000)
|
if (c->frequency <= 230000000)
|
||||||
|
@ -669,12 +522,11 @@ static int af9033_set_frontend(struct dvb_frontend *fe)
|
||||||
else
|
else
|
||||||
tmp = 0x01; /* UHF */
|
tmp = 0x01; /* UHF */
|
||||||
|
|
||||||
ret = af9033_wr_reg(dev, 0x80004b, tmp);
|
ret = regmap_write(dev->regmap, 0x80004b, tmp);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
ret = regmap_write(dev->regmap, 0x800000, 0x00);
|
||||||
ret = af9033_wr_reg(dev, 0x800000, 0x00);
|
if (ret)
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -695,8 +547,8 @@ static int af9033_get_frontend(struct dvb_frontend *fe,
|
||||||
dev_dbg(&dev->client->dev, "\n");
|
dev_dbg(&dev->client->dev, "\n");
|
||||||
|
|
||||||
/* read all needed registers */
|
/* read all needed registers */
|
||||||
ret = af9033_rd_regs(dev, 0x80f900, buf, sizeof(buf));
|
ret = regmap_bulk_read(dev->regmap, 0x80f900, buf, 8);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
switch ((buf[0] >> 0) & 3) {
|
switch ((buf[0] >> 0) & 3) {
|
||||||
|
@ -817,37 +669,38 @@ static int af9033_read_status(struct dvb_frontend *fe, enum fe_status *status)
|
||||||
struct af9033_dev *dev = fe->demodulator_priv;
|
struct af9033_dev *dev = fe->demodulator_priv;
|
||||||
struct dtv_frontend_properties *c = &fe->dtv_property_cache;
|
struct dtv_frontend_properties *c = &fe->dtv_property_cache;
|
||||||
int ret, i, tmp = 0;
|
int ret, i, tmp = 0;
|
||||||
u8 u8tmp, buf[7];
|
u8 buf[7];
|
||||||
|
unsigned int utmp;
|
||||||
|
|
||||||
dev_dbg(&dev->client->dev, "\n");
|
dev_dbg(&dev->client->dev, "\n");
|
||||||
|
|
||||||
*status = 0;
|
*status = 0;
|
||||||
|
|
||||||
/* radio channel status, 0=no result, 1=has signal, 2=no signal */
|
/* radio channel status, 0=no result, 1=has signal, 2=no signal */
|
||||||
ret = af9033_rd_reg(dev, 0x800047, &u8tmp);
|
ret = regmap_read(dev->regmap, 0x800047, &utmp);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
/* has signal */
|
/* has signal */
|
||||||
if (u8tmp == 0x01)
|
if (utmp == 0x01)
|
||||||
*status |= FE_HAS_SIGNAL;
|
*status |= FE_HAS_SIGNAL;
|
||||||
|
|
||||||
if (u8tmp != 0x02) {
|
if (utmp != 0x02) {
|
||||||
/* TPS lock */
|
/* TPS lock */
|
||||||
ret = af9033_rd_reg_mask(dev, 0x80f5a9, &u8tmp, 0x01);
|
ret = regmap_read(dev->regmap, 0x80f5a9, &utmp);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
if (u8tmp)
|
if ((utmp >> 0) & 0x01)
|
||||||
*status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
|
*status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
|
||||||
FE_HAS_VITERBI;
|
FE_HAS_VITERBI;
|
||||||
|
|
||||||
/* full lock */
|
/* full lock */
|
||||||
ret = af9033_rd_reg_mask(dev, 0x80f999, &u8tmp, 0x01);
|
ret = regmap_read(dev->regmap, 0x80f999, &utmp);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
if (u8tmp)
|
if ((utmp >> 0) & 0x01)
|
||||||
*status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
|
*status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
|
||||||
FE_HAS_VITERBI | FE_HAS_SYNC |
|
FE_HAS_VITERBI | FE_HAS_SYNC |
|
||||||
FE_HAS_LOCK;
|
FE_HAS_LOCK;
|
||||||
|
@ -858,15 +711,15 @@ static int af9033_read_status(struct dvb_frontend *fe, enum fe_status *status)
|
||||||
/* signal strength */
|
/* signal strength */
|
||||||
if (dev->fe_status & FE_HAS_SIGNAL) {
|
if (dev->fe_status & FE_HAS_SIGNAL) {
|
||||||
if (dev->is_af9035) {
|
if (dev->is_af9035) {
|
||||||
ret = af9033_rd_reg(dev, 0x80004a, &u8tmp);
|
ret = regmap_read(dev->regmap, 0x80004a, &utmp);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
tmp = -u8tmp * 1000;
|
tmp = -utmp * 1000;
|
||||||
} else {
|
} else {
|
||||||
ret = af9033_rd_reg(dev, 0x8000f7, &u8tmp);
|
ret = regmap_read(dev->regmap, 0x8000f7, &utmp);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
tmp = (u8tmp - 100) * 1000;
|
tmp = (utmp - 100) * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
c->strength.len = 1;
|
c->strength.len = 1;
|
||||||
|
@ -883,26 +736,26 @@ static int af9033_read_status(struct dvb_frontend *fe, enum fe_status *status)
|
||||||
const struct val_snr *snr_lut = NULL;
|
const struct val_snr *snr_lut = NULL;
|
||||||
|
|
||||||
/* read value */
|
/* read value */
|
||||||
ret = af9033_rd_regs(dev, 0x80002c, buf, 3);
|
ret = regmap_bulk_read(dev->regmap, 0x80002c, buf, 3);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
snr_val = (buf[2] << 16) | (buf[1] << 8) | (buf[0] << 0);
|
snr_val = (buf[2] << 16) | (buf[1] << 8) | (buf[0] << 0);
|
||||||
|
|
||||||
/* read superframe number */
|
/* read superframe number */
|
||||||
ret = af9033_rd_reg(dev, 0x80f78b, &u8tmp);
|
ret = regmap_read(dev->regmap, 0x80f78b, &utmp);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
if (u8tmp)
|
if (utmp)
|
||||||
snr_val /= u8tmp;
|
snr_val /= utmp;
|
||||||
|
|
||||||
/* read current transmission mode */
|
/* read current transmission mode */
|
||||||
ret = af9033_rd_reg(dev, 0x80f900, &u8tmp);
|
ret = regmap_read(dev->regmap, 0x80f900, &utmp);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
switch ((u8tmp >> 0) & 3) {
|
switch ((utmp >> 0) & 3) {
|
||||||
case 0:
|
case 0:
|
||||||
snr_val *= 4;
|
snr_val *= 4;
|
||||||
break;
|
break;
|
||||||
|
@ -918,11 +771,11 @@ static int af9033_read_status(struct dvb_frontend *fe, enum fe_status *status)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read current modulation */
|
/* read current modulation */
|
||||||
ret = af9033_rd_reg(dev, 0x80f903, &u8tmp);
|
ret = regmap_read(dev->regmap, 0x80f903, &utmp);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
switch ((u8tmp >> 0) & 3) {
|
switch ((utmp >> 0) & 3) {
|
||||||
case 0:
|
case 0:
|
||||||
snr_lut_size = ARRAY_SIZE(qpsk_snr_lut);
|
snr_lut_size = ARRAY_SIZE(qpsk_snr_lut);
|
||||||
snr_lut = qpsk_snr_lut;
|
snr_lut = qpsk_snr_lut;
|
||||||
|
@ -967,7 +820,7 @@ static int af9033_read_status(struct dvb_frontend *fe, enum fe_status *status)
|
||||||
* (rsd_packet_count). Maybe it should be increased?
|
* (rsd_packet_count). Maybe it should be increased?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ret = af9033_rd_regs(dev, 0x800032, buf, 7);
|
ret = regmap_bulk_read(dev->regmap, 0x800032, buf, 7);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
@ -1010,7 +863,7 @@ static int af9033_read_snr(struct dvb_frontend *fe, u16 *snr)
|
||||||
struct af9033_dev *dev = fe->demodulator_priv;
|
struct af9033_dev *dev = fe->demodulator_priv;
|
||||||
struct dtv_frontend_properties *c = &dev->fe.dtv_property_cache;
|
struct dtv_frontend_properties *c = &dev->fe.dtv_property_cache;
|
||||||
int ret;
|
int ret;
|
||||||
u8 u8tmp;
|
unsigned int utmp;
|
||||||
|
|
||||||
/* use DVBv5 CNR */
|
/* use DVBv5 CNR */
|
||||||
if (c->cnr.stat[0].scale == FE_SCALE_DECIBEL) {
|
if (c->cnr.stat[0].scale == FE_SCALE_DECIBEL) {
|
||||||
|
@ -1023,12 +876,12 @@ static int af9033_read_snr(struct dvb_frontend *fe, u16 *snr)
|
||||||
*snr = div_s64(c->cnr.stat[0].svalue, 1000);
|
*snr = div_s64(c->cnr.stat[0].svalue, 1000);
|
||||||
|
|
||||||
/* read current modulation */
|
/* read current modulation */
|
||||||
ret = af9033_rd_reg(dev, 0x80f903, &u8tmp);
|
ret = regmap_read(dev->regmap, 0x80f903, &utmp);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
/* scale value to 0x0000-0xffff */
|
/* scale value to 0x0000-0xffff */
|
||||||
switch ((u8tmp >> 0) & 3) {
|
switch ((utmp >> 0) & 3) {
|
||||||
case 0:
|
case 0:
|
||||||
*snr = *snr * 0xffff / 23;
|
*snr = *snr * 0xffff / 23;
|
||||||
break;
|
break;
|
||||||
|
@ -1059,23 +912,24 @@ static int af9033_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
|
||||||
struct af9033_dev *dev = fe->demodulator_priv;
|
struct af9033_dev *dev = fe->demodulator_priv;
|
||||||
struct dtv_frontend_properties *c = &dev->fe.dtv_property_cache;
|
struct dtv_frontend_properties *c = &dev->fe.dtv_property_cache;
|
||||||
int ret, tmp, power_real;
|
int ret, tmp, power_real;
|
||||||
u8 u8tmp, gain_offset, buf[7];
|
unsigned int utmp;
|
||||||
|
u8 gain_offset, buf[7];
|
||||||
|
|
||||||
if (dev->is_af9035) {
|
if (dev->is_af9035) {
|
||||||
/* read signal strength of 0-100 scale */
|
/* read signal strength of 0-100 scale */
|
||||||
ret = af9033_rd_reg(dev, 0x800048, &u8tmp);
|
ret = regmap_read(dev->regmap, 0x800048, &utmp);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
/* scale value to 0x0000-0xffff */
|
/* scale value to 0x0000-0xffff */
|
||||||
*strength = u8tmp * 0xffff / 100;
|
*strength = utmp * 0xffff / 100;
|
||||||
} else {
|
} else {
|
||||||
ret = af9033_rd_reg(dev, 0x8000f7, &u8tmp);
|
ret = regmap_read(dev->regmap, 0x8000f7, &utmp);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
ret = af9033_rd_regs(dev, 0x80f900, buf, 7);
|
ret = regmap_bulk_read(dev->regmap, 0x80f900, buf, 7);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
if (c->frequency <= 300000000)
|
if (c->frequency <= 300000000)
|
||||||
|
@ -1083,7 +937,7 @@ static int af9033_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
|
||||||
else
|
else
|
||||||
gain_offset = 4; /* UHF */
|
gain_offset = 4; /* UHF */
|
||||||
|
|
||||||
power_real = (u8tmp - 100 - gain_offset) -
|
power_real = (utmp - 100 - gain_offset) -
|
||||||
power_reference[((buf[3] >> 0) & 3)][((buf[6] >> 0) & 7)];
|
power_reference[((buf[3] >> 0) & 3)][((buf[6] >> 0) & 7)];
|
||||||
|
|
||||||
if (power_real < -15)
|
if (power_real < -15)
|
||||||
|
@ -1134,8 +988,8 @@ static int af9033_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
|
||||||
|
|
||||||
dev_dbg(&dev->client->dev, "enable=%d\n", enable);
|
dev_dbg(&dev->client->dev, "enable=%d\n", enable);
|
||||||
|
|
||||||
ret = af9033_wr_reg_mask(dev, 0x00fa04, enable, 0x01);
|
ret = regmap_update_bits(dev->regmap, 0x00fa04, 0x01, enable);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1153,8 +1007,8 @@ static int af9033_pid_filter_ctrl(struct dvb_frontend *fe, int onoff)
|
||||||
|
|
||||||
dev_dbg(&dev->client->dev, "onoff=%d\n", onoff);
|
dev_dbg(&dev->client->dev, "onoff=%d\n", onoff);
|
||||||
|
|
||||||
ret = af9033_wr_reg_mask(dev, 0x80f993, onoff, 0x01);
|
ret = regmap_update_bits(dev->regmap, 0x80f993, 0x01, onoff);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1178,16 +1032,14 @@ static int af9033_pid_filter(struct dvb_frontend *fe, int index, u16 pid,
|
||||||
if (pid > 0x1fff)
|
if (pid > 0x1fff)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ret = af9033_wr_regs(dev, 0x80f996, wbuf, 2);
|
ret = regmap_bulk_write(dev->regmap, 0x80f996, wbuf, 2);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
ret = regmap_write(dev->regmap, 0x80f994, onoff);
|
||||||
ret = af9033_wr_reg(dev, 0x80f994, onoff);
|
if (ret)
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
goto err;
|
||||||
|
ret = regmap_write(dev->regmap, 0x80f995, index);
|
||||||
ret = af9033_wr_reg(dev, 0x80f995, index);
|
if (ret)
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1247,6 +1099,11 @@ static int af9033_probe(struct i2c_client *client,
|
||||||
int ret;
|
int ret;
|
||||||
u8 buf[8];
|
u8 buf[8];
|
||||||
u32 reg;
|
u32 reg;
|
||||||
|
static const struct regmap_config regmap_config = {
|
||||||
|
.reg_bits = 24,
|
||||||
|
.val_bits = 8,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/* allocate memory for the internal state */
|
/* allocate memory for the internal state */
|
||||||
dev = kzalloc(sizeof(struct af9033_dev), GFP_KERNEL);
|
dev = kzalloc(sizeof(struct af9033_dev), GFP_KERNEL);
|
||||||
|
@ -1268,6 +1125,13 @@ static int af9033_probe(struct i2c_client *client,
|
||||||
goto err_kfree;
|
goto err_kfree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Create regmap */
|
||||||
|
dev->regmap = regmap_init_i2c(client, ®map_config);
|
||||||
|
if (IS_ERR(dev->regmap)) {
|
||||||
|
ret = PTR_ERR(dev->regmap);
|
||||||
|
goto err_kfree;
|
||||||
|
}
|
||||||
|
|
||||||
/* firmware version */
|
/* firmware version */
|
||||||
switch (dev->cfg.tuner) {
|
switch (dev->cfg.tuner) {
|
||||||
case AF9033_TUNER_IT9135_38:
|
case AF9033_TUNER_IT9135_38:
|
||||||
|
@ -1285,13 +1149,12 @@ static int af9033_probe(struct i2c_client *client,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = af9033_rd_regs(dev, reg, &buf[0], 4);
|
ret = regmap_bulk_read(dev->regmap, reg, &buf[0], 4);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err_kfree;
|
goto err_regmap_exit;
|
||||||
|
ret = regmap_bulk_read(dev->regmap, 0x804191, &buf[4], 4);
|
||||||
ret = af9033_rd_regs(dev, 0x804191, &buf[4], 4);
|
if (ret)
|
||||||
if (ret < 0)
|
goto err_regmap_exit;
|
||||||
goto err_kfree;
|
|
||||||
|
|
||||||
dev_info(&dev->client->dev,
|
dev_info(&dev->client->dev,
|
||||||
"firmware version: LINK %d.%d.%d.%d - OFDM %d.%d.%d.%d\n",
|
"firmware version: LINK %d.%d.%d.%d - OFDM %d.%d.%d.%d\n",
|
||||||
|
@ -1309,13 +1172,12 @@ static int af9033_probe(struct i2c_client *client,
|
||||||
/* IT9135 did not like to sleep at that early */
|
/* IT9135 did not like to sleep at that early */
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ret = af9033_wr_reg(dev, 0x80004c, 1);
|
ret = regmap_write(dev->regmap, 0x80004c, 0x01);
|
||||||
if (ret < 0)
|
if (ret)
|
||||||
goto err_kfree;
|
goto err_regmap_exit;
|
||||||
|
ret = regmap_write(dev->regmap, 0x800000, 0x00);
|
||||||
ret = af9033_wr_reg(dev, 0x800000, 0);
|
if (ret)
|
||||||
if (ret < 0)
|
goto err_regmap_exit;
|
||||||
goto err_kfree;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* configure internal TS mode */
|
/* configure internal TS mode */
|
||||||
|
@ -1344,6 +1206,8 @@ static int af9033_probe(struct i2c_client *client,
|
||||||
|
|
||||||
dev_info(&dev->client->dev, "Afatech AF9033 successfully attached\n");
|
dev_info(&dev->client->dev, "Afatech AF9033 successfully attached\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
err_regmap_exit:
|
||||||
|
regmap_exit(dev->regmap);
|
||||||
err_kfree:
|
err_kfree:
|
||||||
kfree(dev);
|
kfree(dev);
|
||||||
err:
|
err:
|
||||||
|
@ -1357,6 +1221,8 @@ static int af9033_remove(struct i2c_client *client)
|
||||||
|
|
||||||
dev_dbg(&dev->client->dev, "\n");
|
dev_dbg(&dev->client->dev, "\n");
|
||||||
|
|
||||||
|
regmap_exit(dev->regmap);
|
||||||
|
|
||||||
dev->fe.ops.release = NULL;
|
dev->fe.ops.release = NULL;
|
||||||
dev->fe.demodulator_priv = NULL;
|
dev->fe.demodulator_priv = NULL;
|
||||||
kfree(dev);
|
kfree(dev);
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "dvb_frontend.h"
|
#include "dvb_frontend.h"
|
||||||
#include "af9033.h"
|
#include "af9033.h"
|
||||||
#include <linux/math64.h>
|
#include <linux/math64.h>
|
||||||
|
#include <linux/regmap.h>
|
||||||
|
|
||||||
struct reg_val {
|
struct reg_val {
|
||||||
u32 reg;
|
u32 reg;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче