2008-09-16 02:01:52 +08:00
|
|
|
/*
|
2010-06-18 08:19:13 +08:00
|
|
|
* Afatech AF9013 demodulator driver
|
2008-09-16 02:01:52 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
|
2011-11-29 07:58:11 +08:00
|
|
|
* Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
|
2008-09-16 02:01:52 +08:00
|
|
|
*
|
|
|
|
* Thanks to Afatech who kindly provided information.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "af9013_priv.h"
|
|
|
|
|
2013-11-02 16:11:47 +08:00
|
|
|
/* Max transfer size done by I2C transfer functions */
|
|
|
|
#define MAX_XFER_SIZE 64
|
|
|
|
|
2008-09-16 02:01:52 +08:00
|
|
|
struct af9013_state {
|
2017-06-11 07:53:42 +08:00
|
|
|
struct i2c_client *client;
|
2011-11-29 07:58:11 +08:00
|
|
|
struct dvb_frontend fe;
|
2017-06-11 06:24:34 +08:00
|
|
|
u32 clk;
|
|
|
|
u8 tuner;
|
|
|
|
u32 if_frequency;
|
|
|
|
u8 ts_mode;
|
|
|
|
bool spec_inv;
|
|
|
|
u8 api_version[4];
|
|
|
|
u8 gpio[4];
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2010-10-08 03:34:55 +08:00
|
|
|
/* tuner/demod RF and IF AGC limits used for signal strength calc */
|
|
|
|
u8 signal_strength_en, rf_50, rf_80, if_50, if_80;
|
2008-09-16 02:01:52 +08:00
|
|
|
u16 signal_strength;
|
|
|
|
u32 ber;
|
|
|
|
u32 ucblocks;
|
|
|
|
u16 snr;
|
2011-11-29 07:58:11 +08:00
|
|
|
u32 bandwidth_hz;
|
2015-06-08 01:53:52 +08:00
|
|
|
enum fe_status fe_status;
|
2011-11-29 07:58:11 +08:00
|
|
|
unsigned long set_frontend_jiffies;
|
|
|
|
unsigned long read_status_jiffies;
|
|
|
|
bool first_tune;
|
|
|
|
bool i2c_gate_state;
|
|
|
|
unsigned int statistics_step:3;
|
|
|
|
struct delayed_work statistics_work;
|
2008-09-16 02:01:52 +08:00
|
|
|
};
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
/* write multiple registers */
|
|
|
|
static int af9013_wr_regs_i2c(struct af9013_state *priv, u8 mbox, u16 reg,
|
|
|
|
const u8 *val, int len)
|
2008-09-16 02:01:52 +08:00
|
|
|
{
|
2011-11-29 07:58:11 +08:00
|
|
|
int ret;
|
2013-11-02 16:11:47 +08:00
|
|
|
u8 buf[MAX_XFER_SIZE];
|
2011-11-29 07:58:11 +08:00
|
|
|
struct i2c_msg msg[1] = {
|
|
|
|
{
|
2017-06-11 07:53:42 +08:00
|
|
|
.addr = priv->client->addr,
|
2011-11-29 07:58:11 +08:00
|
|
|
.flags = 0,
|
2013-11-02 16:11:47 +08:00
|
|
|
.len = 3 + len,
|
2011-11-29 07:58:11 +08:00
|
|
|
.buf = buf,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-02 16:11:47 +08:00
|
|
|
if (3 + len > sizeof(buf)) {
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_warn(&priv->client->dev,
|
2013-11-02 16:11:47 +08:00
|
|
|
"%s: i2c wr reg=%04x: len=%d is too big!\n",
|
|
|
|
KBUILD_MODNAME, reg, len);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
buf[0] = (reg >> 8) & 0xff;
|
|
|
|
buf[1] = (reg >> 0) & 0xff;
|
2008-09-16 02:01:52 +08:00
|
|
|
buf[2] = mbox;
|
|
|
|
memcpy(&buf[3], val, len);
|
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
ret = i2c_transfer(priv->client->adapter, msg, 1);
|
2011-11-29 07:58:11 +08:00
|
|
|
if (ret == 1) {
|
|
|
|
ret = 0;
|
|
|
|
} else {
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_warn(&priv->client->dev, "%s: i2c wr failed=%d reg=%04x " \
|
2012-09-13 07:23:43 +08:00
|
|
|
"len=%d\n", KBUILD_MODNAME, ret, reg, len);
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = -EREMOTEIO;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
2011-11-29 07:58:11 +08:00
|
|
|
return ret;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
/* read multiple registers */
|
|
|
|
static int af9013_rd_regs_i2c(struct af9013_state *priv, u8 mbox, u16 reg,
|
|
|
|
u8 *val, int len)
|
2008-09-16 02:01:52 +08:00
|
|
|
{
|
2011-11-29 07:58:11 +08:00
|
|
|
int ret;
|
|
|
|
u8 buf[3];
|
|
|
|
struct i2c_msg msg[2] = {
|
|
|
|
{
|
2017-06-11 07:53:42 +08:00
|
|
|
.addr = priv->client->addr,
|
2011-11-29 07:58:11 +08:00
|
|
|
.flags = 0,
|
|
|
|
.len = 3,
|
|
|
|
.buf = buf,
|
|
|
|
}, {
|
2017-06-11 07:53:42 +08:00
|
|
|
.addr = priv->client->addr,
|
2011-11-29 07:58:11 +08:00
|
|
|
.flags = I2C_M_RD,
|
|
|
|
.len = len,
|
|
|
|
.buf = val,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
buf[0] = (reg >> 8) & 0xff;
|
|
|
|
buf[1] = (reg >> 0) & 0xff;
|
|
|
|
buf[2] = mbox;
|
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
ret = i2c_transfer(priv->client->adapter, msg, 2);
|
2011-11-29 07:58:11 +08:00
|
|
|
if (ret == 2) {
|
|
|
|
ret = 0;
|
|
|
|
} else {
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_warn(&priv->client->dev, "%s: i2c rd failed=%d reg=%04x " \
|
2012-09-13 07:23:43 +08:00
|
|
|
"len=%d\n", KBUILD_MODNAME, ret, reg, len);
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = -EREMOTEIO;
|
|
|
|
}
|
|
|
|
return ret;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
/* write multiple registers */
|
|
|
|
static int af9013_wr_regs(struct af9013_state *priv, u16 reg, const u8 *val,
|
|
|
|
int len)
|
2008-09-16 02:01:52 +08:00
|
|
|
{
|
2011-11-29 07:58:11 +08:00
|
|
|
int ret, i;
|
|
|
|
u8 mbox = (0 << 7)|(0 << 6)|(1 << 1)|(1 << 0);
|
|
|
|
|
2017-06-11 06:24:34 +08:00
|
|
|
if ((priv->ts_mode == AF9013_TS_USB) &&
|
2012-01-05 13:23:28 +08:00
|
|
|
((reg & 0xff00) != 0xff00) && ((reg & 0xff00) != 0xae00)) {
|
2011-11-29 07:58:11 +08:00
|
|
|
mbox |= ((len - 1) << 2);
|
|
|
|
ret = af9013_wr_regs_i2c(priv, mbox, reg, val, len);
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
ret = af9013_wr_regs_i2c(priv, mbox, reg+i, val+i, 1);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read multiple registers */
|
|
|
|
static int af9013_rd_regs(struct af9013_state *priv, u16 reg, u8 *val, int len)
|
|
|
|
{
|
|
|
|
int ret, i;
|
|
|
|
u8 mbox = (0 << 7)|(0 << 6)|(1 << 1)|(0 << 0);
|
|
|
|
|
2017-06-11 06:24:34 +08:00
|
|
|
if ((priv->ts_mode == AF9013_TS_USB) &&
|
2012-01-05 13:23:28 +08:00
|
|
|
((reg & 0xff00) != 0xff00) && ((reg & 0xff00) != 0xae00)) {
|
2011-11-29 07:58:11 +08:00
|
|
|
mbox |= ((len - 1) << 2);
|
|
|
|
ret = af9013_rd_regs_i2c(priv, mbox, reg, val, len);
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
ret = af9013_rd_regs_i2c(priv, mbox, reg+i, val+i, 1);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err:
|
|
|
|
return 0;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* write single register */
|
2011-11-29 07:58:11 +08:00
|
|
|
static int af9013_wr_reg(struct af9013_state *priv, u16 reg, u8 val)
|
2008-09-16 02:01:52 +08:00
|
|
|
{
|
2011-11-29 07:58:11 +08:00
|
|
|
return af9013_wr_regs(priv, reg, &val, 1);
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* read single register */
|
2011-11-29 07:58:11 +08:00
|
|
|
static int af9013_rd_reg(struct af9013_state *priv, u16 reg, u8 *val)
|
2008-09-16 02:01:52 +08:00
|
|
|
{
|
2011-11-29 07:58:11 +08:00
|
|
|
return af9013_rd_regs(priv, reg, val, 1);
|
|
|
|
}
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
static int af9013_write_ofsm_regs(struct af9013_state *state, u16 reg, u8 *val,
|
|
|
|
u8 len)
|
|
|
|
{
|
|
|
|
u8 mbox = (1 << 7)|(1 << 6)|((len - 1) << 2)|(1 << 1)|(1 << 0);
|
|
|
|
return af9013_wr_regs_i2c(state, mbox, reg, val, len);
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
static int af9013_wr_reg_bits(struct af9013_state *state, u16 reg, int pos,
|
|
|
|
int len, u8 val)
|
2008-09-16 02:01:52 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
u8 tmp, mask;
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
/* no need for read if whole reg is written */
|
|
|
|
if (len != 8) {
|
|
|
|
ret = af9013_rd_reg(state, reg, &tmp);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
mask = (0xff >> (8 - len)) << pos;
|
|
|
|
val <<= pos;
|
|
|
|
tmp &= ~mask;
|
|
|
|
val |= tmp;
|
|
|
|
}
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
return af9013_wr_reg(state, reg, val);
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
static int af9013_rd_reg_bits(struct af9013_state *state, u16 reg, int pos,
|
|
|
|
int len, u8 *val)
|
2008-09-16 02:01:52 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
u8 tmp;
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = af9013_rd_reg(state, reg, &tmp);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2011-11-29 07:58:11 +08:00
|
|
|
|
|
|
|
*val = (tmp >> pos);
|
|
|
|
*val &= (0xff >> (8 - len));
|
|
|
|
|
2008-09-16 02:01:52 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int af9013_set_gpio(struct af9013_state *state, u8 gpio, u8 gpioval)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
u8 pos;
|
|
|
|
u16 addr;
|
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: gpio=%d gpioval=%02x\n",
|
2012-09-13 07:23:43 +08:00
|
|
|
__func__, gpio, gpioval);
|
2011-11-29 07:58:11 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* GPIO0 & GPIO1 0xd735
|
|
|
|
* GPIO2 & GPIO3 0xd736
|
|
|
|
*/
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
switch (gpio) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
addr = 0xd735;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
addr = 0xd736;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_err(&state->client->dev, "%s: invalid gpio=%d\n",
|
2012-09-13 07:23:43 +08:00
|
|
|
KBUILD_MODNAME, gpio);
|
2008-09-16 02:01:52 +08:00
|
|
|
ret = -EINVAL;
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
2012-09-28 16:37:22 +08:00
|
|
|
}
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
switch (gpio) {
|
|
|
|
case 0:
|
|
|
|
case 2:
|
|
|
|
pos = 0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 3:
|
|
|
|
default:
|
|
|
|
pos = 4;
|
|
|
|
break;
|
2012-09-28 16:37:22 +08:00
|
|
|
}
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = af9013_wr_reg_bits(state, addr, pos, 4, gpioval);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
return ret;
|
|
|
|
err:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
|
2008-09-16 02:01:52 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
static int af9013_power_ctrl(struct af9013_state *state, u8 onoff)
|
2008-09-16 02:01:52 +08:00
|
|
|
{
|
2011-11-29 07:58:11 +08:00
|
|
|
int ret, i;
|
|
|
|
u8 tmp;
|
2010-09-13 07:48:58 +08:00
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: onoff=%d\n", __func__, onoff);
|
2011-11-29 07:58:11 +08:00
|
|
|
|
|
|
|
/* enable reset */
|
|
|
|
ret = af9013_wr_reg_bits(state, 0xd417, 4, 1, 1);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* start reset mechanism */
|
|
|
|
ret = af9013_wr_reg(state, 0xaeff, 1);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* wait reset performs */
|
|
|
|
for (i = 0; i < 150; i++) {
|
|
|
|
ret = af9013_rd_reg_bits(state, 0xd417, 1, 1, &tmp);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (tmp)
|
|
|
|
break; /* reset done */
|
|
|
|
|
|
|
|
usleep_range(5000, 25000);
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
if (!tmp)
|
|
|
|
return -ETIMEDOUT;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
if (onoff) {
|
|
|
|
/* clear reset */
|
|
|
|
ret = af9013_wr_reg_bits(state, 0xd417, 1, 1, 0);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* disable reset */
|
|
|
|
ret = af9013_wr_reg_bits(state, 0xd417, 4, 1, 0);
|
|
|
|
|
|
|
|
/* power on */
|
|
|
|
ret = af9013_wr_reg_bits(state, 0xd73a, 3, 1, 0);
|
|
|
|
} else {
|
|
|
|
/* power off */
|
|
|
|
ret = af9013_wr_reg_bits(state, 0xd73a, 3, 1, 1);
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
return ret;
|
|
|
|
err:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
|
2008-09-16 02:01:52 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
static int af9013_statistics_ber_unc_start(struct dvb_frontend *fe)
|
2008-09-16 02:01:52 +08:00
|
|
|
{
|
2011-11-29 07:58:11 +08:00
|
|
|
struct af9013_state *state = fe->demodulator_priv;
|
2008-09-16 02:01:52 +08:00
|
|
|
int ret;
|
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s:\n", __func__);
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
/* reset and start BER counter */
|
|
|
|
ret = af9013_wr_reg_bits(state, 0xd391, 4, 1, 1);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
err:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
|
2011-11-29 07:58:11 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int af9013_statistics_ber_unc_result(struct dvb_frontend *fe)
|
|
|
|
{
|
|
|
|
struct af9013_state *state = fe->demodulator_priv;
|
|
|
|
int ret;
|
|
|
|
u8 buf[5];
|
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s:\n", __func__);
|
2011-11-29 07:58:11 +08:00
|
|
|
|
|
|
|
/* check if error bit count is ready */
|
|
|
|
ret = af9013_rd_reg_bits(state, 0xd391, 4, 1, &buf[0]);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (!buf[0]) {
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: not ready\n", __func__);
|
2011-11-29 07:58:11 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = af9013_rd_regs(state, 0xd387, buf, 5);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
state->ber = (buf[2] << 16) | (buf[1] << 8) | buf[0];
|
|
|
|
state->ucblocks += (buf[4] << 8) | buf[3];
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
err:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
|
2011-11-29 07:58:11 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int af9013_statistics_snr_start(struct dvb_frontend *fe)
|
|
|
|
{
|
|
|
|
struct af9013_state *state = fe->demodulator_priv;
|
|
|
|
int ret;
|
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s:\n", __func__);
|
2011-11-29 07:58:11 +08:00
|
|
|
|
|
|
|
/* start SNR meas */
|
|
|
|
ret = af9013_wr_reg_bits(state, 0xd2e1, 3, 1, 1);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
err:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
|
2011-11-29 07:58:11 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int af9013_statistics_snr_result(struct dvb_frontend *fe)
|
|
|
|
{
|
|
|
|
struct af9013_state *state = fe->demodulator_priv;
|
|
|
|
int ret, i, len;
|
|
|
|
u8 buf[3], tmp;
|
|
|
|
u32 snr_val;
|
|
|
|
const struct af9013_snr *uninitialized_var(snr_lut);
|
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s:\n", __func__);
|
2011-11-29 07:58:11 +08:00
|
|
|
|
|
|
|
/* check if SNR ready */
|
|
|
|
ret = af9013_rd_reg_bits(state, 0xd2e1, 3, 1, &tmp);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (!tmp) {
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: not ready\n", __func__);
|
2011-11-29 07:58:11 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read value */
|
|
|
|
ret = af9013_rd_regs(state, 0xd2e3, buf, 3);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
snr_val = (buf[2] << 16) | (buf[1] << 8) | buf[0];
|
|
|
|
|
|
|
|
/* read current modulation */
|
|
|
|
ret = af9013_rd_reg(state, 0xd3c1, &tmp);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
switch ((tmp >> 6) & 3) {
|
|
|
|
case 0:
|
|
|
|
len = ARRAY_SIZE(qpsk_snr_lut);
|
|
|
|
snr_lut = qpsk_snr_lut;
|
2008-09-16 02:01:52 +08:00
|
|
|
break;
|
2011-11-29 07:58:11 +08:00
|
|
|
case 1:
|
|
|
|
len = ARRAY_SIZE(qam16_snr_lut);
|
|
|
|
snr_lut = qam16_snr_lut;
|
2008-09-16 02:01:52 +08:00
|
|
|
break;
|
2011-11-29 07:58:11 +08:00
|
|
|
case 2:
|
|
|
|
len = ARRAY_SIZE(qam64_snr_lut);
|
|
|
|
snr_lut = qam64_snr_lut;
|
2008-09-16 02:01:52 +08:00
|
|
|
break;
|
|
|
|
default:
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
tmp = snr_lut[i].snr;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
if (snr_val < snr_lut[i].val)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
state->snr = tmp * 10; /* dB/10 */
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
return ret;
|
|
|
|
err:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
|
2011-11-29 07:58:11 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
static int af9013_statistics_signal_strength(struct dvb_frontend *fe)
|
|
|
|
{
|
|
|
|
struct af9013_state *state = fe->demodulator_priv;
|
|
|
|
int ret = 0;
|
|
|
|
u8 buf[2], rf_gain, if_gain;
|
|
|
|
int signal_strength;
|
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s:\n", __func__);
|
2011-11-29 07:58:11 +08:00
|
|
|
|
|
|
|
if (!state->signal_strength_en)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = af9013_rd_regs(state, 0xd07c, buf, 2);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
rf_gain = buf[0];
|
|
|
|
if_gain = buf[1];
|
|
|
|
|
|
|
|
signal_strength = (0xffff / \
|
|
|
|
(9 * (state->rf_50 + state->if_50) - \
|
|
|
|
11 * (state->rf_80 + state->if_80))) * \
|
|
|
|
(10 * (rf_gain + if_gain) - \
|
|
|
|
11 * (state->rf_80 + state->if_80));
|
|
|
|
if (signal_strength < 0)
|
|
|
|
signal_strength = 0;
|
|
|
|
else if (signal_strength > 0xffff)
|
|
|
|
signal_strength = 0xffff;
|
|
|
|
|
|
|
|
state->signal_strength = signal_strength;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
err:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
|
2008-09-16 02:01:52 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
static void af9013_statistics_work(struct work_struct *work)
|
2008-09-16 02:01:52 +08:00
|
|
|
{
|
2011-11-29 07:58:11 +08:00
|
|
|
struct af9013_state *state = container_of(work,
|
|
|
|
struct af9013_state, statistics_work.work);
|
|
|
|
unsigned int next_msec;
|
|
|
|
|
|
|
|
/* update only signal strength when demod is not locked */
|
|
|
|
if (!(state->fe_status & FE_HAS_LOCK)) {
|
|
|
|
state->statistics_step = 0;
|
|
|
|
state->ber = 0;
|
|
|
|
state->snr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (state->statistics_step) {
|
|
|
|
default:
|
|
|
|
state->statistics_step = 0;
|
2017-05-18 19:13:28 +08:00
|
|
|
/* fall-through */
|
2011-11-29 07:58:11 +08:00
|
|
|
case 0:
|
2012-04-20 19:04:48 +08:00
|
|
|
af9013_statistics_signal_strength(&state->fe);
|
2011-11-29 07:58:11 +08:00
|
|
|
state->statistics_step++;
|
|
|
|
next_msec = 300;
|
|
|
|
break;
|
|
|
|
case 1:
|
2012-04-20 19:04:48 +08:00
|
|
|
af9013_statistics_snr_start(&state->fe);
|
2011-11-29 07:58:11 +08:00
|
|
|
state->statistics_step++;
|
|
|
|
next_msec = 200;
|
|
|
|
break;
|
|
|
|
case 2:
|
2012-04-20 19:04:48 +08:00
|
|
|
af9013_statistics_ber_unc_start(&state->fe);
|
2011-11-29 07:58:11 +08:00
|
|
|
state->statistics_step++;
|
|
|
|
next_msec = 1000;
|
|
|
|
break;
|
|
|
|
case 3:
|
2012-04-20 19:04:48 +08:00
|
|
|
af9013_statistics_snr_result(&state->fe);
|
2011-11-29 07:58:11 +08:00
|
|
|
state->statistics_step++;
|
|
|
|
next_msec = 400;
|
|
|
|
break;
|
|
|
|
case 4:
|
2012-04-20 19:04:48 +08:00
|
|
|
af9013_statistics_ber_unc_result(&state->fe);
|
2011-11-29 07:58:11 +08:00
|
|
|
state->statistics_step++;
|
|
|
|
next_msec = 100;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
schedule_delayed_work(&state->statistics_work,
|
|
|
|
msecs_to_jiffies(next_msec));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int af9013_get_tune_settings(struct dvb_frontend *fe,
|
|
|
|
struct dvb_frontend_tune_settings *fesettings)
|
|
|
|
{
|
|
|
|
fesettings->min_delay_ms = 800;
|
|
|
|
fesettings->step_size = 0;
|
|
|
|
fesettings->max_drift = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-31 09:25:27 +08:00
|
|
|
static int af9013_set_frontend(struct dvb_frontend *fe)
|
2011-11-29 07:58:11 +08:00
|
|
|
{
|
|
|
|
struct af9013_state *state = fe->demodulator_priv;
|
|
|
|
struct dtv_frontend_properties *c = &fe->dtv_property_cache;
|
|
|
|
int ret, i, sampling_freq;
|
|
|
|
bool auto_mode, spec_inv;
|
|
|
|
u8 buf[6];
|
|
|
|
u32 if_frequency, freq_cw;
|
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: frequency=%d bandwidth_hz=%d\n",
|
2012-09-13 07:23:43 +08:00
|
|
|
__func__, c->frequency, c->bandwidth_hz);
|
2011-11-29 07:58:11 +08:00
|
|
|
|
|
|
|
/* program tuner */
|
|
|
|
if (fe->ops.tuner_ops.set_params)
|
2011-12-24 23:24:33 +08:00
|
|
|
fe->ops.tuner_ops.set_params(fe);
|
2011-11-29 07:58:11 +08:00
|
|
|
|
|
|
|
/* program CFOE coefficients */
|
|
|
|
if (c->bandwidth_hz != state->bandwidth_hz) {
|
|
|
|
for (i = 0; i < ARRAY_SIZE(coeff_lut); i++) {
|
2017-06-11 06:24:34 +08:00
|
|
|
if (coeff_lut[i].clock == state->clk &&
|
2011-11-29 07:58:11 +08:00
|
|
|
coeff_lut[i].bandwidth_hz == c->bandwidth_hz) {
|
|
|
|
break;
|
|
|
|
}
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
2015-04-29 06:02:19 +08:00
|
|
|
/* Return an error if can't find bandwidth or the right clock */
|
|
|
|
if (i == ARRAY_SIZE(coeff_lut))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = af9013_wr_regs(state, 0xae00, coeff_lut[i].val,
|
|
|
|
sizeof(coeff_lut[i].val));
|
2017-06-16 04:42:44 +08:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
2011-11-29 07:58:11 +08:00
|
|
|
}
|
2011-11-13 11:26:17 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
/* program frequency control */
|
|
|
|
if (c->bandwidth_hz != state->bandwidth_hz || state->first_tune) {
|
2011-11-13 11:26:17 +08:00
|
|
|
/* get used IF frequency */
|
|
|
|
if (fe->ops.tuner_ops.get_if_frequency)
|
2011-11-29 07:58:11 +08:00
|
|
|
fe->ops.tuner_ops.get_if_frequency(fe, &if_frequency);
|
2011-11-13 11:26:17 +08:00
|
|
|
else
|
2017-06-11 06:24:34 +08:00
|
|
|
if_frequency = state->if_frequency;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: if_frequency=%d\n",
|
2012-09-13 07:23:43 +08:00
|
|
|
__func__, if_frequency);
|
2012-09-03 05:47:25 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
sampling_freq = if_frequency;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2017-06-11 06:24:34 +08:00
|
|
|
while (sampling_freq > (state->clk / 2))
|
|
|
|
sampling_freq -= state->clk;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
if (sampling_freq < 0) {
|
|
|
|
sampling_freq *= -1;
|
2017-06-11 06:24:34 +08:00
|
|
|
spec_inv = state->spec_inv;
|
2011-11-29 07:58:11 +08:00
|
|
|
} else {
|
2017-06-11 06:24:34 +08:00
|
|
|
spec_inv = !state->spec_inv;
|
2011-11-29 07:58:11 +08:00
|
|
|
}
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2017-06-11 08:12:14 +08:00
|
|
|
freq_cw = DIV_ROUND_CLOSEST_ULL((u64)sampling_freq * 0x800000,
|
|
|
|
state->clk);
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
if (spec_inv)
|
|
|
|
freq_cw = 0x800000 - freq_cw;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
buf[0] = (freq_cw >> 0) & 0xff;
|
|
|
|
buf[1] = (freq_cw >> 8) & 0xff;
|
|
|
|
buf[2] = (freq_cw >> 16) & 0x7f;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
freq_cw = 0x800000 - freq_cw;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
buf[3] = (freq_cw >> 0) & 0xff;
|
|
|
|
buf[4] = (freq_cw >> 8) & 0xff;
|
|
|
|
buf[5] = (freq_cw >> 16) & 0x7f;
|
|
|
|
|
|
|
|
ret = af9013_wr_regs(state, 0xd140, buf, 3);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
ret = af9013_wr_regs(state, 0x9be7, buf, 6);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
/* clear TPS lock flag */
|
|
|
|
ret = af9013_wr_reg_bits(state, 0xd330, 3, 1, 1);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
/* clear MPEG2 lock flag */
|
|
|
|
ret = af9013_wr_reg_bits(state, 0xd507, 6, 1, 0);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
2009-07-11 07:03:43 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
/* empty channel function */
|
|
|
|
ret = af9013_wr_reg_bits(state, 0x9bfe, 0, 1, 0);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* empty DVB-T channel function */
|
|
|
|
ret = af9013_wr_reg_bits(state, 0x9bc2, 0, 1, 0);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* transmission parameters */
|
|
|
|
auto_mode = false;
|
|
|
|
memset(buf, 0, 3);
|
|
|
|
|
|
|
|
switch (c->transmission_mode) {
|
2008-09-16 02:01:52 +08:00
|
|
|
case TRANSMISSION_MODE_AUTO:
|
2014-09-04 02:20:50 +08:00
|
|
|
auto_mode = true;
|
2011-11-29 07:58:11 +08:00
|
|
|
break;
|
2008-09-16 02:01:52 +08:00
|
|
|
case TRANSMISSION_MODE_2K:
|
|
|
|
break;
|
|
|
|
case TRANSMISSION_MODE_8K:
|
|
|
|
buf[0] |= (1 << 0);
|
|
|
|
break;
|
|
|
|
default:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: invalid transmission_mode\n",
|
2012-09-13 07:23:43 +08:00
|
|
|
__func__);
|
2014-09-04 02:20:50 +08:00
|
|
|
auto_mode = true;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
switch (c->guard_interval) {
|
2008-09-16 02:01:52 +08:00
|
|
|
case GUARD_INTERVAL_AUTO:
|
2014-09-04 02:20:50 +08:00
|
|
|
auto_mode = true;
|
2011-11-29 07:58:11 +08:00
|
|
|
break;
|
2008-09-16 02:01:52 +08:00
|
|
|
case GUARD_INTERVAL_1_32:
|
|
|
|
break;
|
|
|
|
case GUARD_INTERVAL_1_16:
|
|
|
|
buf[0] |= (1 << 2);
|
|
|
|
break;
|
|
|
|
case GUARD_INTERVAL_1_8:
|
|
|
|
buf[0] |= (2 << 2);
|
|
|
|
break;
|
|
|
|
case GUARD_INTERVAL_1_4:
|
|
|
|
buf[0] |= (3 << 2);
|
|
|
|
break;
|
|
|
|
default:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: invalid guard_interval\n",
|
2012-09-13 07:23:43 +08:00
|
|
|
__func__);
|
2014-09-04 02:20:50 +08:00
|
|
|
auto_mode = true;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
switch (c->hierarchy) {
|
2008-09-16 02:01:52 +08:00
|
|
|
case HIERARCHY_AUTO:
|
2014-09-04 02:20:50 +08:00
|
|
|
auto_mode = true;
|
2011-11-29 07:58:11 +08:00
|
|
|
break;
|
2008-09-16 02:01:52 +08:00
|
|
|
case HIERARCHY_NONE:
|
|
|
|
break;
|
|
|
|
case HIERARCHY_1:
|
|
|
|
buf[0] |= (1 << 4);
|
|
|
|
break;
|
|
|
|
case HIERARCHY_2:
|
|
|
|
buf[0] |= (2 << 4);
|
|
|
|
break;
|
|
|
|
case HIERARCHY_4:
|
|
|
|
buf[0] |= (3 << 4);
|
|
|
|
break;
|
|
|
|
default:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: invalid hierarchy\n", __func__);
|
2014-09-04 02:20:50 +08:00
|
|
|
auto_mode = true;
|
2012-09-28 16:37:22 +08:00
|
|
|
}
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
switch (c->modulation) {
|
2008-09-16 02:01:52 +08:00
|
|
|
case QAM_AUTO:
|
2014-09-04 02:20:50 +08:00
|
|
|
auto_mode = true;
|
2011-11-29 07:58:11 +08:00
|
|
|
break;
|
2008-09-16 02:01:52 +08:00
|
|
|
case QPSK:
|
|
|
|
break;
|
|
|
|
case QAM_16:
|
|
|
|
buf[1] |= (1 << 6);
|
|
|
|
break;
|
|
|
|
case QAM_64:
|
|
|
|
buf[1] |= (2 << 6);
|
|
|
|
break;
|
|
|
|
default:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: invalid modulation\n", __func__);
|
2014-09-04 02:20:50 +08:00
|
|
|
auto_mode = true;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Use HP. How and which case we can switch to LP? */
|
|
|
|
buf[1] |= (1 << 4);
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
switch (c->code_rate_HP) {
|
2008-09-16 02:01:52 +08:00
|
|
|
case FEC_AUTO:
|
2014-09-04 02:20:50 +08:00
|
|
|
auto_mode = true;
|
2011-11-29 07:58:11 +08:00
|
|
|
break;
|
2008-09-16 02:01:52 +08:00
|
|
|
case FEC_1_2:
|
|
|
|
break;
|
|
|
|
case FEC_2_3:
|
|
|
|
buf[2] |= (1 << 0);
|
|
|
|
break;
|
|
|
|
case FEC_3_4:
|
|
|
|
buf[2] |= (2 << 0);
|
|
|
|
break;
|
|
|
|
case FEC_5_6:
|
|
|
|
buf[2] |= (3 << 0);
|
|
|
|
break;
|
|
|
|
case FEC_7_8:
|
|
|
|
buf[2] |= (4 << 0);
|
|
|
|
break;
|
|
|
|
default:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: invalid code_rate_HP\n",
|
2012-09-13 07:23:43 +08:00
|
|
|
__func__);
|
2014-09-04 02:20:50 +08:00
|
|
|
auto_mode = true;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
switch (c->code_rate_LP) {
|
2008-09-16 02:01:52 +08:00
|
|
|
case FEC_AUTO:
|
2014-09-04 02:20:50 +08:00
|
|
|
auto_mode = true;
|
2011-11-29 07:58:11 +08:00
|
|
|
break;
|
2008-09-16 02:01:52 +08:00
|
|
|
case FEC_1_2:
|
|
|
|
break;
|
|
|
|
case FEC_2_3:
|
|
|
|
buf[2] |= (1 << 3);
|
|
|
|
break;
|
|
|
|
case FEC_3_4:
|
|
|
|
buf[2] |= (2 << 3);
|
|
|
|
break;
|
|
|
|
case FEC_5_6:
|
|
|
|
buf[2] |= (3 << 3);
|
|
|
|
break;
|
|
|
|
case FEC_7_8:
|
|
|
|
buf[2] |= (4 << 3);
|
|
|
|
break;
|
|
|
|
case FEC_NONE:
|
2011-11-29 07:58:11 +08:00
|
|
|
break;
|
2008-09-16 02:01:52 +08:00
|
|
|
default:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: invalid code_rate_LP\n",
|
2012-09-13 07:23:43 +08:00
|
|
|
__func__);
|
2014-09-04 02:20:50 +08:00
|
|
|
auto_mode = true;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
switch (c->bandwidth_hz) {
|
|
|
|
case 6000000:
|
2008-09-16 02:01:52 +08:00
|
|
|
break;
|
2011-11-29 07:58:11 +08:00
|
|
|
case 7000000:
|
2008-09-16 02:01:52 +08:00
|
|
|
buf[1] |= (1 << 2);
|
|
|
|
break;
|
2011-11-29 07:58:11 +08:00
|
|
|
case 8000000:
|
2008-09-16 02:01:52 +08:00
|
|
|
buf[1] |= (2 << 2);
|
|
|
|
break;
|
|
|
|
default:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: invalid bandwidth_hz\n",
|
2012-09-13 07:23:43 +08:00
|
|
|
__func__);
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = af9013_wr_regs(state, 0xd3c0, buf, 3);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
if (auto_mode) {
|
|
|
|
/* clear easy mode flag */
|
|
|
|
ret = af9013_wr_reg(state, 0xaefd, 0);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: auto params\n", __func__);
|
2008-09-16 02:01:52 +08:00
|
|
|
} else {
|
2011-11-29 07:58:11 +08:00
|
|
|
/* set easy mode flag */
|
|
|
|
ret = af9013_wr_reg(state, 0xaefd, 1);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = af9013_wr_reg(state, 0xaefe, 0);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: manual params\n", __func__);
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
/* tune */
|
|
|
|
ret = af9013_wr_reg(state, 0xffff, 0);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
state->bandwidth_hz = c->bandwidth_hz;
|
|
|
|
state->set_frontend_jiffies = jiffies;
|
|
|
|
state->first_tune = false;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
return ret;
|
|
|
|
err:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
|
2008-09-16 02:01:52 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-02-04 22:58:30 +08:00
|
|
|
static int af9013_get_frontend(struct dvb_frontend *fe,
|
|
|
|
struct dtv_frontend_properties *c)
|
2008-09-16 02:01:52 +08:00
|
|
|
{
|
|
|
|
struct af9013_state *state = fe->demodulator_priv;
|
|
|
|
int ret;
|
2011-11-29 07:58:11 +08:00
|
|
|
u8 buf[3];
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s:\n", __func__);
|
2011-11-29 07:58:11 +08:00
|
|
|
|
|
|
|
ret = af9013_rd_regs(state, 0xd3c0, buf, 3);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
switch ((buf[1] >> 6) & 3) {
|
|
|
|
case 0:
|
2011-11-29 07:58:11 +08:00
|
|
|
c->modulation = QPSK;
|
2008-09-16 02:01:52 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2011-11-29 07:58:11 +08:00
|
|
|
c->modulation = QAM_16;
|
2008-09-16 02:01:52 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2011-11-29 07:58:11 +08:00
|
|
|
c->modulation = QAM_64;
|
2008-09-16 02:01:52 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ((buf[0] >> 0) & 3) {
|
|
|
|
case 0:
|
2011-11-29 07:58:11 +08:00
|
|
|
c->transmission_mode = TRANSMISSION_MODE_2K;
|
2008-09-16 02:01:52 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2011-11-29 07:58:11 +08:00
|
|
|
c->transmission_mode = TRANSMISSION_MODE_8K;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch ((buf[0] >> 2) & 3) {
|
|
|
|
case 0:
|
2012-01-04 00:47:35 +08:00
|
|
|
c->guard_interval = GUARD_INTERVAL_1_32;
|
2008-09-16 02:01:52 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2012-01-04 00:47:35 +08:00
|
|
|
c->guard_interval = GUARD_INTERVAL_1_16;
|
2008-09-16 02:01:52 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2012-01-04 00:47:35 +08:00
|
|
|
c->guard_interval = GUARD_INTERVAL_1_8;
|
2008-09-16 02:01:52 +08:00
|
|
|
break;
|
|
|
|
case 3:
|
2012-01-04 00:47:35 +08:00
|
|
|
c->guard_interval = GUARD_INTERVAL_1_4;
|
2008-09-16 02:01:52 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ((buf[0] >> 4) & 7) {
|
|
|
|
case 0:
|
2011-11-29 07:58:11 +08:00
|
|
|
c->hierarchy = HIERARCHY_NONE;
|
2008-09-16 02:01:52 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2011-11-29 07:58:11 +08:00
|
|
|
c->hierarchy = HIERARCHY_1;
|
2008-09-16 02:01:52 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2011-11-29 07:58:11 +08:00
|
|
|
c->hierarchy = HIERARCHY_2;
|
2008-09-16 02:01:52 +08:00
|
|
|
break;
|
|
|
|
case 3:
|
2011-11-29 07:58:11 +08:00
|
|
|
c->hierarchy = HIERARCHY_4;
|
2008-09-16 02:01:52 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ((buf[2] >> 0) & 7) {
|
|
|
|
case 0:
|
2011-11-29 07:58:11 +08:00
|
|
|
c->code_rate_HP = FEC_1_2;
|
2008-09-16 02:01:52 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2011-11-29 07:58:11 +08:00
|
|
|
c->code_rate_HP = FEC_2_3;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
c->code_rate_HP = FEC_3_4;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
c->code_rate_HP = FEC_5_6;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
c->code_rate_HP = FEC_7_8;
|
|
|
|
break;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
switch ((buf[2] >> 3) & 7) {
|
|
|
|
case 0:
|
|
|
|
c->code_rate_LP = FEC_1_2;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
c->code_rate_LP = FEC_2_3;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
c->code_rate_LP = FEC_3_4;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
c->code_rate_LP = FEC_5_6;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
c->code_rate_LP = FEC_7_8;
|
|
|
|
break;
|
|
|
|
}
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
switch ((buf[1] >> 2) & 3) {
|
|
|
|
case 0:
|
|
|
|
c->bandwidth_hz = 6000000;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
c->bandwidth_hz = 7000000;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
c->bandwidth_hz = 8000000;
|
|
|
|
break;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2011-11-29 07:58:11 +08:00
|
|
|
err:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
|
2008-09-16 02:01:52 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-06-08 01:53:52 +08:00
|
|
|
static int af9013_read_status(struct dvb_frontend *fe, enum fe_status *status)
|
2008-09-16 02:01:52 +08:00
|
|
|
{
|
|
|
|
struct af9013_state *state = fe->demodulator_priv;
|
2011-11-29 07:58:11 +08:00
|
|
|
int ret;
|
2008-09-16 02:01:52 +08:00
|
|
|
u8 tmp;
|
2011-11-29 07:58:11 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return status from the cache if it is younger than 2000ms with the
|
|
|
|
* exception of last tune is done during 4000ms.
|
|
|
|
*/
|
|
|
|
if (time_is_after_jiffies(
|
|
|
|
state->read_status_jiffies + msecs_to_jiffies(2000)) &&
|
|
|
|
time_is_before_jiffies(
|
|
|
|
state->set_frontend_jiffies + msecs_to_jiffies(4000))
|
|
|
|
) {
|
|
|
|
*status = state->fe_status;
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
*status = 0;
|
|
|
|
}
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
/* MPEG2 lock */
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = af9013_rd_reg_bits(state, 0xd507, 6, 1, &tmp);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
|
|
|
|
2008-09-16 02:01:52 +08:00
|
|
|
if (tmp)
|
2010-06-18 07:56:27 +08:00
|
|
|
*status |= FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI |
|
|
|
|
FE_HAS_SYNC | FE_HAS_LOCK;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2010-06-18 07:56:27 +08:00
|
|
|
if (!*status) {
|
|
|
|
/* TPS lock */
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = af9013_rd_reg_bits(state, 0xd330, 3, 1, &tmp);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
|
|
|
|
2008-09-16 02:01:52 +08:00
|
|
|
if (tmp)
|
2010-06-18 07:56:27 +08:00
|
|
|
*status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
|
|
|
|
FE_HAS_VITERBI;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
state->fe_status = *status;
|
|
|
|
state->read_status_jiffies = jiffies;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
return ret;
|
|
|
|
err:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
|
2008-09-16 02:01:52 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
static int af9013_read_snr(struct dvb_frontend *fe, u16 *snr)
|
2008-09-16 02:01:52 +08:00
|
|
|
{
|
|
|
|
struct af9013_state *state = fe->demodulator_priv;
|
2011-11-29 07:58:11 +08:00
|
|
|
*snr = state->snr;
|
|
|
|
return 0;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int af9013_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
|
|
|
|
{
|
|
|
|
struct af9013_state *state = fe->demodulator_priv;
|
|
|
|
*strength = state->signal_strength;
|
2011-11-29 07:58:11 +08:00
|
|
|
return 0;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
static int af9013_read_ber(struct dvb_frontend *fe, u32 *ber)
|
2008-09-16 02:01:52 +08:00
|
|
|
{
|
|
|
|
struct af9013_state *state = fe->demodulator_priv;
|
2011-11-29 07:58:11 +08:00
|
|
|
*ber = state->ber;
|
|
|
|
return 0;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int af9013_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
|
|
|
|
{
|
|
|
|
struct af9013_state *state = fe->demodulator_priv;
|
|
|
|
*ucblocks = state->ucblocks;
|
2011-11-29 07:58:11 +08:00
|
|
|
return 0;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int af9013_init(struct dvb_frontend *fe)
|
|
|
|
{
|
|
|
|
struct af9013_state *state = fe->demodulator_priv;
|
|
|
|
int ret, i, len;
|
2011-11-29 07:58:11 +08:00
|
|
|
u8 buf[3], tmp;
|
|
|
|
u32 adc_cw;
|
|
|
|
const struct af9013_reg_bit *init;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s:\n", __func__);
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
/* power on */
|
|
|
|
ret = af9013_power_ctrl(state, 1);
|
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
/* enable ADC */
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = af9013_wr_reg(state, 0xd73a, 0xa4);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
/* write API version to firmware */
|
2017-06-11 06:24:34 +08:00
|
|
|
ret = af9013_wr_regs(state, 0x9bf2, state->api_version, 4);
|
2011-11-29 07:58:11 +08:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
/* program ADC control */
|
2017-06-11 06:24:34 +08:00
|
|
|
switch (state->clk) {
|
2011-11-29 07:58:11 +08:00
|
|
|
case 28800000: /* 28.800 MHz */
|
|
|
|
tmp = 0;
|
|
|
|
break;
|
|
|
|
case 20480000: /* 20.480 MHz */
|
|
|
|
tmp = 1;
|
|
|
|
break;
|
|
|
|
case 28000000: /* 28.000 MHz */
|
|
|
|
tmp = 2;
|
|
|
|
break;
|
|
|
|
case 25000000: /* 25.000 MHz */
|
|
|
|
tmp = 3;
|
|
|
|
break;
|
|
|
|
default:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_err(&state->client->dev, "%s: invalid clock\n",
|
2012-09-13 07:23:43 +08:00
|
|
|
KBUILD_MODNAME);
|
2011-11-29 07:58:11 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-06-11 08:12:14 +08:00
|
|
|
adc_cw = div_u64((u64)state->clk * 0x80000, 1000000);
|
2011-11-29 07:58:11 +08:00
|
|
|
buf[0] = (adc_cw >> 0) & 0xff;
|
|
|
|
buf[1] = (adc_cw >> 8) & 0xff;
|
|
|
|
buf[2] = (adc_cw >> 16) & 0xff;
|
|
|
|
ret = af9013_wr_regs(state, 0xd180, buf, 3);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
ret = af9013_wr_reg_bits(state, 0x9bd2, 0, 4, tmp);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
/* set I2C master clock */
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = af9013_wr_reg(state, 0xd416, 0x14);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
/* set 16 embx */
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = af9013_wr_reg_bits(state, 0xd700, 1, 1, 1);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
/* set no trigger */
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = af9013_wr_reg_bits(state, 0xd700, 2, 1, 0);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
/* set read-update bit for constellation */
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = af9013_wr_reg_bits(state, 0xd371, 1, 1, 1);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
/* settings for mp2if */
|
2017-06-11 06:24:34 +08:00
|
|
|
if (state->ts_mode == AF9013_TS_USB) {
|
2011-11-29 07:58:11 +08:00
|
|
|
/* AF9015 split PSB to 1.5k + 0.5k */
|
|
|
|
ret = af9013_wr_reg_bits(state, 0xd50b, 2, 1, 1);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
} else {
|
|
|
|
/* AF9013 change the output bit to data7 */
|
|
|
|
ret = af9013_wr_reg_bits(state, 0xd500, 3, 1, 1);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* AF9013 set mpeg to full speed */
|
|
|
|
ret = af9013_wr_reg_bits(state, 0xd502, 4, 1, 1);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = af9013_wr_reg_bits(state, 0xd520, 4, 1, 1);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
/* load OFSM settings */
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: load ofsm settings\n", __func__);
|
2008-09-16 02:01:52 +08:00
|
|
|
len = ARRAY_SIZE(ofsm_init);
|
|
|
|
init = ofsm_init;
|
|
|
|
for (i = 0; i < len; i++) {
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = af9013_wr_reg_bits(state, init[i].addr, init[i].pos,
|
2008-09-16 02:01:52 +08:00
|
|
|
init[i].len, init[i].val);
|
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* load tuner specific settings */
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: load tuner specific settings\n",
|
2012-09-13 07:23:43 +08:00
|
|
|
__func__);
|
2017-06-11 06:24:34 +08:00
|
|
|
switch (state->tuner) {
|
2008-09-16 02:01:52 +08:00
|
|
|
case AF9013_TUNER_MXL5003D:
|
|
|
|
len = ARRAY_SIZE(tuner_init_mxl5003d);
|
|
|
|
init = tuner_init_mxl5003d;
|
|
|
|
break;
|
|
|
|
case AF9013_TUNER_MXL5005D:
|
|
|
|
case AF9013_TUNER_MXL5005R:
|
2010-09-10 01:53:59 +08:00
|
|
|
case AF9013_TUNER_MXL5007T:
|
2008-09-16 02:01:52 +08:00
|
|
|
len = ARRAY_SIZE(tuner_init_mxl5005);
|
|
|
|
init = tuner_init_mxl5005;
|
|
|
|
break;
|
|
|
|
case AF9013_TUNER_ENV77H11D5:
|
|
|
|
len = ARRAY_SIZE(tuner_init_env77h11d5);
|
|
|
|
init = tuner_init_env77h11d5;
|
|
|
|
break;
|
|
|
|
case AF9013_TUNER_MT2060:
|
|
|
|
len = ARRAY_SIZE(tuner_init_mt2060);
|
|
|
|
init = tuner_init_mt2060;
|
|
|
|
break;
|
|
|
|
case AF9013_TUNER_MC44S803:
|
|
|
|
len = ARRAY_SIZE(tuner_init_mc44s803);
|
|
|
|
init = tuner_init_mc44s803;
|
|
|
|
break;
|
|
|
|
case AF9013_TUNER_QT1010:
|
|
|
|
case AF9013_TUNER_QT1010A:
|
|
|
|
len = ARRAY_SIZE(tuner_init_qt1010);
|
|
|
|
init = tuner_init_qt1010;
|
|
|
|
break;
|
|
|
|
case AF9013_TUNER_MT2060_2:
|
|
|
|
len = ARRAY_SIZE(tuner_init_mt2060_2);
|
|
|
|
init = tuner_init_mt2060_2;
|
|
|
|
break;
|
|
|
|
case AF9013_TUNER_TDA18271:
|
2010-08-13 14:49:24 +08:00
|
|
|
case AF9013_TUNER_TDA18218:
|
2008-09-16 02:01:52 +08:00
|
|
|
len = ARRAY_SIZE(tuner_init_tda18271);
|
|
|
|
init = tuner_init_tda18271;
|
|
|
|
break;
|
|
|
|
case AF9013_TUNER_UNKNOWN:
|
|
|
|
default:
|
|
|
|
len = ARRAY_SIZE(tuner_init_unknown);
|
|
|
|
init = tuner_init_unknown;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = af9013_wr_reg_bits(state, init[i].addr, init[i].pos,
|
2008-09-16 02:01:52 +08:00
|
|
|
init[i].len, init[i].val);
|
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
/* TS mode */
|
2017-06-11 06:24:34 +08:00
|
|
|
ret = af9013_wr_reg_bits(state, 0xd500, 1, 2, state->ts_mode);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
/* enable lock led */
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = af9013_wr_reg_bits(state, 0xd730, 0, 1, 1);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
/* check if we support signal strength */
|
|
|
|
if (!state->signal_strength_en) {
|
|
|
|
ret = af9013_rd_reg_bits(state, 0x9bee, 0, 1,
|
|
|
|
&state->signal_strength_en);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
}
|
2010-10-08 03:34:55 +08:00
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
/* read values needed for signal strength calculation */
|
|
|
|
if (state->signal_strength_en && !state->rf_50) {
|
|
|
|
ret = af9013_rd_reg(state, 0x9bbd, &state->rf_50);
|
2010-10-08 03:34:55 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
ret = af9013_rd_reg(state, 0x9bd0, &state->rf_80);
|
2010-10-08 03:34:55 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
ret = af9013_rd_reg(state, 0x9be2, &state->if_50);
|
2010-10-08 03:34:55 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
ret = af9013_rd_reg(state, 0x9be4, &state->if_80);
|
2010-10-08 03:34:55 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
2010-10-08 03:34:55 +08:00
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
/* SNR */
|
|
|
|
ret = af9013_wr_reg(state, 0xd2e2, 1);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* BER / UCB */
|
|
|
|
buf[0] = (10000 >> 0) & 0xff;
|
|
|
|
buf[1] = (10000 >> 8) & 0xff;
|
|
|
|
ret = af9013_wr_regs(state, 0xd385, buf, 2);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* enable FEC monitor */
|
|
|
|
ret = af9013_wr_reg_bits(state, 0xd392, 1, 1, 1);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
state->first_tune = true;
|
|
|
|
schedule_delayed_work(&state->statistics_work, msecs_to_jiffies(400));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
err:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
|
2011-11-29 07:58:11 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int af9013_sleep(struct dvb_frontend *fe)
|
|
|
|
{
|
|
|
|
struct af9013_state *state = fe->demodulator_priv;
|
|
|
|
int ret;
|
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s:\n", __func__);
|
2011-11-29 07:58:11 +08:00
|
|
|
|
|
|
|
/* stop statistics polling */
|
|
|
|
cancel_delayed_work_sync(&state->statistics_work);
|
|
|
|
|
|
|
|
/* disable lock led */
|
|
|
|
ret = af9013_wr_reg_bits(state, 0xd730, 0, 1, 0);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* power off */
|
|
|
|
ret = af9013_power_ctrl(state, 0);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
err:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
|
2011-11-29 07:58:11 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int af9013_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct af9013_state *state = fe->demodulator_priv;
|
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: enable=%d\n", __func__, enable);
|
2011-11-29 07:58:11 +08:00
|
|
|
|
|
|
|
/* gate already open or close */
|
|
|
|
if (state->i2c_gate_state == enable)
|
|
|
|
return 0;
|
|
|
|
|
2017-06-11 06:24:34 +08:00
|
|
|
if (state->ts_mode == AF9013_TS_USB)
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = af9013_wr_reg_bits(state, 0xd417, 3, 1, enable);
|
|
|
|
else
|
|
|
|
ret = af9013_wr_reg_bits(state, 0xd607, 2, 1, enable);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
state->i2c_gate_state = enable;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
err:
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: failed=%d\n", __func__, ret);
|
2008-09-16 02:01:52 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
static void af9013_release(struct dvb_frontend *fe)
|
|
|
|
{
|
|
|
|
struct af9013_state *state = fe->demodulator_priv;
|
2017-06-11 07:53:42 +08:00
|
|
|
struct i2c_client *client = state->client;
|
2016-01-10 04:18:45 +08:00
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
i2c_unregister_device(client);
|
2011-11-29 07:58:11 +08:00
|
|
|
}
|
|
|
|
|
2016-08-10 05:32:21 +08:00
|
|
|
static const struct dvb_frontend_ops af9013_ops;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
static int af9013_download_firmware(struct af9013_state *state)
|
|
|
|
{
|
2011-03-20 05:02:22 +08:00
|
|
|
int i, len, remaining, ret;
|
2008-09-16 02:01:52 +08:00
|
|
|
const struct firmware *fw;
|
|
|
|
u16 checksum = 0;
|
|
|
|
u8 val;
|
|
|
|
u8 fw_params[4];
|
2012-09-12 22:37:28 +08:00
|
|
|
u8 *fw_file = AF9013_FIRMWARE;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
msleep(100);
|
|
|
|
/* check whether firmware is already running */
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = af9013_rd_reg(state, 0x98be, &val);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
else
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: firmware status=%02x\n",
|
2012-09-13 07:23:43 +08:00
|
|
|
__func__, val);
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
if (val == 0x0c) /* fw is running, no need for download */
|
|
|
|
goto exit;
|
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_info(&state->client->dev, "%s: found a '%s' in cold state, will try " \
|
2012-09-13 07:23:43 +08:00
|
|
|
"to load a firmware\n",
|
|
|
|
KBUILD_MODNAME, af9013_ops.info.name);
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
/* request the firmware, this will block and timeout */
|
2017-06-11 07:53:42 +08:00
|
|
|
ret = request_firmware(&fw, fw_file, &state->client->dev);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret) {
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_info(&state->client->dev, "%s: did not find the firmware " \
|
2012-09-13 07:23:43 +08:00
|
|
|
"file. (%s) Please see linux/Documentation/dvb/ for " \
|
|
|
|
"more details on firmware-problems. (%d)\n",
|
|
|
|
KBUILD_MODNAME, fw_file, ret);
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_info(&state->client->dev, "%s: downloading firmware from file '%s'\n",
|
2012-09-13 07:23:43 +08:00
|
|
|
KBUILD_MODNAME, fw_file);
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
/* calc checksum */
|
|
|
|
for (i = 0; i < fw->size; i++)
|
|
|
|
checksum += fw->data[i];
|
|
|
|
|
|
|
|
fw_params[0] = checksum >> 8;
|
|
|
|
fw_params[1] = checksum & 0xff;
|
|
|
|
fw_params[2] = fw->size >> 8;
|
|
|
|
fw_params[3] = fw->size & 0xff;
|
|
|
|
|
|
|
|
/* write fw checksum & size */
|
|
|
|
ret = af9013_write_ofsm_regs(state, 0x50fc,
|
|
|
|
fw_params, sizeof(fw_params));
|
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err_release;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-03-20 05:02:22 +08:00
|
|
|
#define FW_ADDR 0x5100 /* firmware start address */
|
|
|
|
#define LEN_MAX 16 /* max packet size */
|
|
|
|
for (remaining = fw->size; remaining > 0; remaining -= LEN_MAX) {
|
|
|
|
len = remaining;
|
|
|
|
if (len > LEN_MAX)
|
|
|
|
len = LEN_MAX;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2011-03-20 05:02:22 +08:00
|
|
|
ret = af9013_write_ofsm_regs(state,
|
|
|
|
FW_ADDR + fw->size - remaining,
|
|
|
|
(u8 *) &fw->data[fw->size - remaining], len);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret) {
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_err(&state->client->dev,
|
2012-09-13 07:23:43 +08:00
|
|
|
"%s: firmware download failed=%d\n",
|
|
|
|
KBUILD_MODNAME, ret);
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err_release;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* request boot firmware */
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = af9013_wr_reg(state, 0xe205, 1);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err_release;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 15; i++) {
|
|
|
|
msleep(100);
|
|
|
|
|
|
|
|
/* check firmware status */
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = af9013_rd_reg(state, 0x98be, &val);
|
2008-09-16 02:01:52 +08:00
|
|
|
if (ret)
|
2011-11-29 07:58:11 +08:00
|
|
|
goto err_release;
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_dbg(&state->client->dev, "%s: firmware status=%02x\n",
|
2012-09-13 07:23:43 +08:00
|
|
|
__func__, val);
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
if (val == 0x0c || val == 0x04) /* success or fail */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (val == 0x04) {
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_err(&state->client->dev, "%s: firmware did not run\n",
|
2012-09-13 07:23:43 +08:00
|
|
|
KBUILD_MODNAME);
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = -ENODEV;
|
2008-09-16 02:01:52 +08:00
|
|
|
} else if (val != 0x0c) {
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_err(&state->client->dev, "%s: firmware boot timeout\n",
|
2012-09-13 07:23:43 +08:00
|
|
|
KBUILD_MODNAME);
|
2011-11-29 07:58:11 +08:00
|
|
|
ret = -ENODEV;
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
err_release:
|
2008-09-16 02:01:52 +08:00
|
|
|
release_firmware(fw);
|
2011-11-29 07:58:11 +08:00
|
|
|
err:
|
2008-09-16 02:01:52 +08:00
|
|
|
exit:
|
|
|
|
if (!ret)
|
2017-06-11 07:53:42 +08:00
|
|
|
dev_info(&state->client->dev, "%s: found a '%s' in warm state\n",
|
2012-09-13 07:23:43 +08:00
|
|
|
KBUILD_MODNAME, af9013_ops.info.name);
|
2008-09-16 02:01:52 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
/*
|
|
|
|
* XXX: That is wrapper to af9013_probe() via driver core in order to provide
|
|
|
|
* proper I2C client for legacy media attach binding.
|
|
|
|
* New users must use I2C client binding directly!
|
|
|
|
*/
|
2008-09-16 02:01:52 +08:00
|
|
|
struct dvb_frontend *af9013_attach(const struct af9013_config *config,
|
2017-06-11 07:53:42 +08:00
|
|
|
struct i2c_adapter *i2c)
|
2008-09-16 02:01:52 +08:00
|
|
|
{
|
2017-06-11 07:53:42 +08:00
|
|
|
struct i2c_client *client;
|
|
|
|
struct i2c_board_info board_info;
|
|
|
|
struct af9013_platform_data pdata;
|
|
|
|
|
|
|
|
pdata.clk = config->clock;
|
|
|
|
pdata.tuner = config->tuner;
|
|
|
|
pdata.if_frequency = config->if_frequency;
|
|
|
|
pdata.ts_mode = config->ts_mode;
|
|
|
|
pdata.spec_inv = config->spec_inv;
|
|
|
|
memcpy(&pdata.api_version, config->api_version, sizeof(pdata.api_version));
|
|
|
|
memcpy(&pdata.gpio, config->gpio, sizeof(pdata.gpio));
|
|
|
|
pdata.attach_in_use = true;
|
|
|
|
|
|
|
|
memset(&board_info, 0, sizeof(board_info));
|
|
|
|
strlcpy(board_info.type, "af9013", sizeof(board_info.type));
|
|
|
|
board_info.addr = config->i2c_addr;
|
|
|
|
board_info.platform_data = &pdata;
|
|
|
|
client = i2c_new_device(i2c, &board_info);
|
|
|
|
if (!client || !client->dev.driver)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return pdata.get_dvb_frontend(client);
|
2008-09-16 02:01:52 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(af9013_attach);
|
|
|
|
|
2016-08-10 05:32:21 +08:00
|
|
|
static const struct dvb_frontend_ops af9013_ops = {
|
2011-12-31 09:25:27 +08:00
|
|
|
.delsys = { SYS_DVBT },
|
2008-09-16 02:01:52 +08:00
|
|
|
.info = {
|
2011-11-29 07:58:11 +08:00
|
|
|
.name = "Afatech AF9013",
|
2008-09-16 02:01:52 +08:00
|
|
|
.frequency_min = 174000000,
|
|
|
|
.frequency_max = 862000000,
|
|
|
|
.frequency_stepsize = 250000,
|
|
|
|
.frequency_tolerance = 0,
|
2011-11-29 07:58:11 +08:00
|
|
|
.caps = FE_CAN_FEC_1_2 |
|
|
|
|
FE_CAN_FEC_2_3 |
|
|
|
|
FE_CAN_FEC_3_4 |
|
|
|
|
FE_CAN_FEC_5_6 |
|
|
|
|
FE_CAN_FEC_7_8 |
|
|
|
|
FE_CAN_FEC_AUTO |
|
|
|
|
FE_CAN_QPSK |
|
|
|
|
FE_CAN_QAM_16 |
|
|
|
|
FE_CAN_QAM_64 |
|
|
|
|
FE_CAN_QAM_AUTO |
|
2008-09-16 02:01:52 +08:00
|
|
|
FE_CAN_TRANSMISSION_MODE_AUTO |
|
|
|
|
FE_CAN_GUARD_INTERVAL_AUTO |
|
|
|
|
FE_CAN_HIERARCHY_AUTO |
|
|
|
|
FE_CAN_RECOVER |
|
|
|
|
FE_CAN_MUTE_TS
|
|
|
|
},
|
|
|
|
|
|
|
|
.release = af9013_release,
|
2011-11-29 07:58:11 +08:00
|
|
|
|
2008-09-16 02:01:52 +08:00
|
|
|
.init = af9013_init,
|
|
|
|
.sleep = af9013_sleep,
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
.get_tune_settings = af9013_get_tune_settings,
|
2011-12-31 09:25:27 +08:00
|
|
|
.set_frontend = af9013_set_frontend,
|
|
|
|
.get_frontend = af9013_get_frontend,
|
2008-09-16 02:01:52 +08:00
|
|
|
|
|
|
|
.read_status = af9013_read_status,
|
|
|
|
.read_snr = af9013_read_snr,
|
2011-11-29 07:58:11 +08:00
|
|
|
.read_signal_strength = af9013_read_signal_strength,
|
|
|
|
.read_ber = af9013_read_ber,
|
2008-09-16 02:01:52 +08:00
|
|
|
.read_ucblocks = af9013_read_ucblocks,
|
|
|
|
|
2011-11-29 07:58:11 +08:00
|
|
|
.i2c_gate_ctrl = af9013_i2c_gate_ctrl,
|
|
|
|
};
|
2008-09-16 02:01:52 +08:00
|
|
|
|
2017-06-11 07:53:42 +08:00
|
|
|
static struct dvb_frontend *af9013_get_dvb_frontend(struct i2c_client *client)
|
|
|
|
{
|
|
|
|
struct af9013_state *state = i2c_get_clientdata(client);
|
|
|
|
|
|
|
|
dev_dbg(&client->dev, "\n");
|
|
|
|
|
|
|
|
return &state->fe;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int af9013_probe(struct i2c_client *client,
|
|
|
|
const struct i2c_device_id *id)
|
|
|
|
{
|
|
|
|
struct af9013_state *state;
|
|
|
|
struct af9013_platform_data *pdata = client->dev.platform_data;
|
|
|
|
int ret, i;
|
|
|
|
u8 firmware_version[4];
|
|
|
|
|
|
|
|
state = kzalloc(sizeof(*state), GFP_KERNEL);
|
|
|
|
if (!state) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup the state */
|
|
|
|
state->client = client;
|
|
|
|
i2c_set_clientdata(client, state);
|
|
|
|
state->clk = pdata->clk;
|
|
|
|
state->tuner = pdata->tuner;
|
|
|
|
state->if_frequency = pdata->if_frequency;
|
|
|
|
state->ts_mode = pdata->ts_mode;
|
|
|
|
state->spec_inv = pdata->spec_inv;
|
|
|
|
memcpy(&state->api_version, pdata->api_version, sizeof(state->api_version));
|
|
|
|
memcpy(&state->gpio, pdata->gpio, sizeof(state->gpio));
|
|
|
|
INIT_DELAYED_WORK(&state->statistics_work, af9013_statistics_work);
|
|
|
|
|
|
|
|
/* Download firmware */
|
|
|
|
if (state->ts_mode != AF9013_TS_USB) {
|
|
|
|
ret = af9013_download_firmware(state);
|
|
|
|
if (ret)
|
|
|
|
goto err_kfree;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Firmware version */
|
|
|
|
ret = af9013_rd_regs(state, 0x5103, firmware_version,
|
|
|
|
sizeof(firmware_version));
|
|
|
|
if (ret)
|
|
|
|
goto err_kfree;
|
|
|
|
|
|
|
|
/* Set GPIOs */
|
|
|
|
for (i = 0; i < sizeof(state->gpio); i++) {
|
|
|
|
ret = af9013_set_gpio(state, i, state->gpio[i]);
|
|
|
|
if (ret)
|
|
|
|
goto err_kfree;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create dvb frontend */
|
|
|
|
memcpy(&state->fe.ops, &af9013_ops, sizeof(state->fe.ops));
|
|
|
|
if (!pdata->attach_in_use)
|
|
|
|
state->fe.ops.release = NULL;
|
|
|
|
state->fe.demodulator_priv = state;
|
|
|
|
|
|
|
|
/* Setup callbacks */
|
|
|
|
pdata->get_dvb_frontend = af9013_get_dvb_frontend;
|
|
|
|
|
|
|
|
dev_info(&client->dev, "Afatech AF9013 successfully attached\n");
|
|
|
|
dev_info(&client->dev, "firmware version: %d.%d.%d.%d\n",
|
|
|
|
firmware_version[0], firmware_version[1],
|
|
|
|
firmware_version[2], firmware_version[3]);
|
|
|
|
return 0;
|
|
|
|
err_kfree:
|
|
|
|
kfree(state);
|
|
|
|
err:
|
|
|
|
dev_dbg(&client->dev, "failed %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int af9013_remove(struct i2c_client *client)
|
|
|
|
{
|
|
|
|
struct af9013_state *state = i2c_get_clientdata(client);
|
|
|
|
|
|
|
|
dev_dbg(&client->dev, "\n");
|
|
|
|
|
|
|
|
/* Stop statistics polling */
|
|
|
|
cancel_delayed_work_sync(&state->statistics_work);
|
|
|
|
|
|
|
|
kfree(state);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_device_id af9013_id_table[] = {
|
|
|
|
{"af9013", 0},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, af9013_id_table);
|
|
|
|
|
|
|
|
static struct i2c_driver af9013_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "af9013",
|
|
|
|
.suppress_bind_attrs = true,
|
|
|
|
},
|
|
|
|
.probe = af9013_probe,
|
|
|
|
.remove = af9013_remove,
|
|
|
|
.id_table = af9013_id_table,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_i2c_driver(af9013_driver);
|
|
|
|
|
2008-09-16 02:01:52 +08:00
|
|
|
MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
|
|
|
|
MODULE_DESCRIPTION("Afatech AF9013 DVB-T demodulator driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
2012-09-12 22:37:28 +08:00
|
|
|
MODULE_FIRMWARE(AF9013_FIRMWARE);
|