2019-05-20 15:19:02 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-04-07 02:45:20 +08:00
|
|
|
/*
|
|
|
|
STV6110(A) Silicon tuner driver
|
|
|
|
|
|
|
|
Copyright (C) Manu Abraham <abraham.manu@gmail.com>
|
|
|
|
|
|
|
|
Copyright (C) ST Microelectronics
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-04-07 02:45:20 +08:00
|
|
|
#include <linux/string.h>
|
|
|
|
|
2017-12-29 02:03:51 +08:00
|
|
|
#include <media/dvb_frontend.h>
|
2009-04-07 02:45:20 +08:00
|
|
|
|
|
|
|
#include "stv6110x_reg.h"
|
|
|
|
#include "stv6110x.h"
|
|
|
|
#include "stv6110x_priv.h"
|
|
|
|
|
2013-11-02 16:05:18 +08:00
|
|
|
/* Max transfer size done by I2C transfer functions */
|
|
|
|
#define MAX_XFER_SIZE 64
|
|
|
|
|
2009-04-07 02:45:20 +08:00
|
|
|
static unsigned int verbose;
|
|
|
|
module_param(verbose, int, 0644);
|
|
|
|
MODULE_PARM_DESC(verbose, "Set Verbosity level");
|
|
|
|
|
|
|
|
static int stv6110x_read_reg(struct stv6110x_state *stv6110x, u8 reg, u8 *data)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
const struct stv6110x_config *config = stv6110x->config;
|
|
|
|
u8 b0[] = { reg };
|
|
|
|
u8 b1[] = { 0 };
|
|
|
|
struct i2c_msg msg[] = {
|
2018-01-05 02:08:56 +08:00
|
|
|
{ .addr = config->addr, .flags = 0, .buf = b0, .len = 1 },
|
2009-04-07 02:45:20 +08:00
|
|
|
{ .addr = config->addr, .flags = I2C_M_RD, .buf = b1, .len = 1 }
|
|
|
|
};
|
|
|
|
|
|
|
|
ret = i2c_transfer(stv6110x->i2c, msg, 2);
|
|
|
|
if (ret != 2) {
|
|
|
|
dprintk(FE_ERROR, 1, "I/O Error");
|
|
|
|
return -EREMOTEIO;
|
|
|
|
}
|
2009-04-16 19:38:46 +08:00
|
|
|
*data = b1[0];
|
2009-04-07 02:45:20 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-06 06:22:45 +08:00
|
|
|
static int stv6110x_write_regs(struct stv6110x_state *stv6110x, int start, u8 data[], int len)
|
2009-04-07 02:45:20 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
const struct stv6110x_config *config = stv6110x->config;
|
2013-11-02 16:05:18 +08:00
|
|
|
u8 buf[MAX_XFER_SIZE];
|
|
|
|
|
2010-01-06 06:22:45 +08:00
|
|
|
struct i2c_msg msg = {
|
|
|
|
.addr = config->addr,
|
|
|
|
.flags = 0,
|
|
|
|
.buf = buf,
|
|
|
|
.len = len + 1
|
|
|
|
};
|
|
|
|
|
2013-11-02 16:05:18 +08:00
|
|
|
if (1 + len > sizeof(buf)) {
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"%s: i2c wr: len=%d is too big!\n",
|
|
|
|
KBUILD_MODNAME, len);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-01-06 06:22:45 +08:00
|
|
|
if (start + len > 8)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
buf[0] = start;
|
|
|
|
memcpy(&buf[1], data, len);
|
2009-04-07 02:45:20 +08:00
|
|
|
|
|
|
|
ret = i2c_transfer(stv6110x->i2c, &msg, 1);
|
|
|
|
if (ret != 1) {
|
|
|
|
dprintk(FE_ERROR, 1, "I/O Error");
|
|
|
|
return -EREMOTEIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-06 06:22:45 +08:00
|
|
|
static int stv6110x_write_reg(struct stv6110x_state *stv6110x, u8 reg, u8 data)
|
|
|
|
{
|
2017-12-01 00:55:46 +08:00
|
|
|
u8 tmp = data; /* see gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */
|
|
|
|
|
|
|
|
return stv6110x_write_regs(stv6110x, reg, &tmp, 1);
|
2010-01-06 06:22:45 +08:00
|
|
|
}
|
|
|
|
|
2009-04-07 02:45:20 +08:00
|
|
|
static int stv6110x_init(struct dvb_frontend *fe)
|
|
|
|
{
|
|
|
|
struct stv6110x_state *stv6110x = fe->tuner_priv;
|
|
|
|
int ret;
|
|
|
|
|
2010-01-06 06:23:13 +08:00
|
|
|
ret = stv6110x_write_regs(stv6110x, 0, stv6110x->regs,
|
|
|
|
ARRAY_SIZE(stv6110x->regs));
|
2010-01-06 06:22:45 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
dprintk(FE_ERROR, 1, "Initialization failed");
|
|
|
|
return -1;
|
2009-04-07 02:45:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stv6110x_set_frequency(struct dvb_frontend *fe, u32 frequency)
|
|
|
|
{
|
|
|
|
struct stv6110x_state *stv6110x = fe->tuner_priv;
|
|
|
|
u32 rDiv, divider;
|
2009-11-14 05:22:02 +08:00
|
|
|
s32 pVal, pCalc, rDivOpt = 0, pCalcOpt = 1000;
|
2009-04-07 02:45:20 +08:00
|
|
|
u8 i;
|
|
|
|
|
2010-01-06 06:23:13 +08:00
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_K, (REFCLOCK_MHz - 16));
|
2009-04-07 02:45:20 +08:00
|
|
|
|
|
|
|
if (frequency <= 1023000) {
|
2010-01-06 06:23:13 +08:00
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_DIV4SEL, 1);
|
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_PRESC32_ON, 0);
|
2009-04-07 02:45:20 +08:00
|
|
|
pVal = 40;
|
|
|
|
} else if (frequency <= 1300000) {
|
2010-01-06 06:23:13 +08:00
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_DIV4SEL, 1);
|
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_PRESC32_ON, 1);
|
2009-04-07 02:45:20 +08:00
|
|
|
pVal = 40;
|
|
|
|
} else if (frequency <= 2046000) {
|
2010-01-06 06:23:13 +08:00
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_DIV4SEL, 0);
|
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_PRESC32_ON, 0);
|
2009-04-07 02:45:20 +08:00
|
|
|
pVal = 20;
|
|
|
|
} else {
|
2010-01-06 06:23:13 +08:00
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_DIV4SEL, 0);
|
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_PRESC32_ON, 1);
|
2009-04-07 02:45:20 +08:00
|
|
|
pVal = 20;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (rDiv = 0; rDiv <= 3; rDiv++) {
|
|
|
|
pCalc = (REFCLOCK_kHz / 100) / R_DIV(rDiv);
|
|
|
|
|
2009-11-14 05:22:02 +08:00
|
|
|
if ((abs((s32)(pCalc - pVal))) < (abs((s32)(pCalcOpt - pVal))))
|
2009-04-07 02:45:20 +08:00
|
|
|
rDivOpt = rDiv;
|
2009-11-14 05:22:02 +08:00
|
|
|
|
|
|
|
pCalcOpt = (REFCLOCK_kHz / 100) / R_DIV(rDivOpt);
|
2009-04-07 02:45:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
divider = (frequency * R_DIV(rDivOpt) * pVal) / REFCLOCK_kHz;
|
|
|
|
divider = (divider + 5) / 10;
|
|
|
|
|
2010-01-06 06:23:13 +08:00
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_R_DIV, rDivOpt);
|
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_N_DIV_11_8, MSB(divider));
|
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG0], TNG0_N_DIV_7_0, LSB(divider));
|
2009-04-07 02:45:20 +08:00
|
|
|
|
|
|
|
/* VCO Auto calibration */
|
2010-01-06 06:23:13 +08:00
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_STAT1], STAT1_CALVCO_STRT, 1);
|
2009-04-07 02:45:20 +08:00
|
|
|
|
2010-01-06 06:23:13 +08:00
|
|
|
stv6110x_write_reg(stv6110x, STV6110x_CTRL1, stv6110x->regs[STV6110x_CTRL1]);
|
|
|
|
stv6110x_write_reg(stv6110x, STV6110x_TNG1, stv6110x->regs[STV6110x_TNG1]);
|
|
|
|
stv6110x_write_reg(stv6110x, STV6110x_TNG0, stv6110x->regs[STV6110x_TNG0]);
|
|
|
|
stv6110x_write_reg(stv6110x, STV6110x_STAT1, stv6110x->regs[STV6110x_STAT1]);
|
2009-04-07 02:45:20 +08:00
|
|
|
|
|
|
|
for (i = 0; i < TRIALS; i++) {
|
2010-01-06 06:23:13 +08:00
|
|
|
stv6110x_read_reg(stv6110x, STV6110x_STAT1, &stv6110x->regs[STV6110x_STAT1]);
|
|
|
|
if (!STV6110x_GETFIELD(STAT1_CALVCO_STRT, stv6110x->regs[STV6110x_STAT1]))
|
2009-04-07 02:45:20 +08:00
|
|
|
break;
|
|
|
|
msleep(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stv6110x_get_frequency(struct dvb_frontend *fe, u32 *frequency)
|
|
|
|
{
|
|
|
|
struct stv6110x_state *stv6110x = fe->tuner_priv;
|
|
|
|
|
2010-01-06 06:23:13 +08:00
|
|
|
stv6110x_read_reg(stv6110x, STV6110x_TNG1, &stv6110x->regs[STV6110x_TNG1]);
|
|
|
|
stv6110x_read_reg(stv6110x, STV6110x_TNG0, &stv6110x->regs[STV6110x_TNG0]);
|
2009-04-07 02:45:20 +08:00
|
|
|
|
2010-01-06 06:23:13 +08:00
|
|
|
*frequency = (MAKEWORD16(STV6110x_GETFIELD(TNG1_N_DIV_11_8, stv6110x->regs[STV6110x_TNG1]),
|
|
|
|
STV6110x_GETFIELD(TNG0_N_DIV_7_0, stv6110x->regs[STV6110x_TNG0]))) * REFCLOCK_kHz;
|
2009-04-07 02:45:20 +08:00
|
|
|
|
2010-01-06 06:23:13 +08:00
|
|
|
*frequency /= (1 << (STV6110x_GETFIELD(TNG1_R_DIV, stv6110x->regs[STV6110x_TNG1]) +
|
|
|
|
STV6110x_GETFIELD(TNG1_DIV4SEL, stv6110x->regs[STV6110x_TNG1])));
|
2009-04-07 02:45:20 +08:00
|
|
|
|
|
|
|
*frequency >>= 2;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stv6110x_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth)
|
|
|
|
{
|
|
|
|
struct stv6110x_state *stv6110x = fe->tuner_priv;
|
|
|
|
u32 halfbw;
|
|
|
|
u8 i;
|
|
|
|
|
|
|
|
halfbw = bandwidth >> 1;
|
|
|
|
|
|
|
|
if (halfbw > 36000000)
|
2010-01-06 06:23:13 +08:00
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL3], CTRL3_CF, 31); /* LPF */
|
2009-04-07 02:45:20 +08:00
|
|
|
else if (halfbw < 5000000)
|
2010-01-06 06:23:13 +08:00
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL3], CTRL3_CF, 0); /* LPF */
|
2009-04-07 02:45:20 +08:00
|
|
|
else
|
2010-01-06 06:23:13 +08:00
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL3], CTRL3_CF, ((halfbw / 1000000) - 5)); /* LPF */
|
2009-04-07 02:45:20 +08:00
|
|
|
|
|
|
|
|
2010-01-06 06:23:13 +08:00
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL3], CTRL3_RCCLK_OFF, 0x0); /* cal. clk activated */
|
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_STAT1], STAT1_CALRC_STRT, 0x1); /* LPF auto cal */
|
2009-04-07 02:45:20 +08:00
|
|
|
|
2010-01-06 06:23:13 +08:00
|
|
|
stv6110x_write_reg(stv6110x, STV6110x_CTRL3, stv6110x->regs[STV6110x_CTRL3]);
|
|
|
|
stv6110x_write_reg(stv6110x, STV6110x_STAT1, stv6110x->regs[STV6110x_STAT1]);
|
2009-04-07 02:45:20 +08:00
|
|
|
|
|
|
|
for (i = 0; i < TRIALS; i++) {
|
2010-01-06 06:23:13 +08:00
|
|
|
stv6110x_read_reg(stv6110x, STV6110x_STAT1, &stv6110x->regs[STV6110x_STAT1]);
|
|
|
|
if (!STV6110x_GETFIELD(STAT1_CALRC_STRT, stv6110x->regs[STV6110x_STAT1]))
|
2009-04-07 02:45:20 +08:00
|
|
|
break;
|
|
|
|
msleep(1);
|
|
|
|
}
|
2010-01-06 06:23:13 +08:00
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL3], CTRL3_RCCLK_OFF, 0x1); /* cal. done */
|
|
|
|
stv6110x_write_reg(stv6110x, STV6110x_CTRL3, stv6110x->regs[STV6110x_CTRL3]);
|
2009-04-07 02:45:20 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stv6110x_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
|
|
|
|
{
|
|
|
|
struct stv6110x_state *stv6110x = fe->tuner_priv;
|
|
|
|
|
2010-01-06 06:23:13 +08:00
|
|
|
stv6110x_read_reg(stv6110x, STV6110x_CTRL3, &stv6110x->regs[STV6110x_CTRL3]);
|
|
|
|
*bandwidth = (STV6110x_GETFIELD(CTRL3_CF, stv6110x->regs[STV6110x_CTRL3]) + 5) * 2000000;
|
2009-04-07 02:45:20 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stv6110x_set_refclock(struct dvb_frontend *fe, u32 refclock)
|
|
|
|
{
|
|
|
|
struct stv6110x_state *stv6110x = fe->tuner_priv;
|
|
|
|
|
|
|
|
/* setup divider */
|
|
|
|
switch (refclock) {
|
|
|
|
default:
|
|
|
|
case 1:
|
2010-01-06 06:23:13 +08:00
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 0);
|
2009-04-07 02:45:20 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2010-01-06 06:23:13 +08:00
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 1);
|
2009-04-07 02:45:20 +08:00
|
|
|
break;
|
|
|
|
case 4:
|
2010-01-06 06:23:13 +08:00
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 2);
|
2009-04-07 02:45:20 +08:00
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
case 0:
|
2010-01-06 06:23:13 +08:00
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 3);
|
2009-04-07 02:45:20 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-01-06 06:23:13 +08:00
|
|
|
stv6110x_write_reg(stv6110x, STV6110x_CTRL2, stv6110x->regs[STV6110x_CTRL2]);
|
2009-04-07 02:45:20 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stv6110x_get_bbgain(struct dvb_frontend *fe, u32 *gain)
|
|
|
|
{
|
|
|
|
struct stv6110x_state *stv6110x = fe->tuner_priv;
|
|
|
|
|
2010-01-06 06:23:13 +08:00
|
|
|
stv6110x_read_reg(stv6110x, STV6110x_CTRL2, &stv6110x->regs[STV6110x_CTRL2]);
|
|
|
|
*gain = 2 * STV6110x_GETFIELD(CTRL2_BBGAIN, stv6110x->regs[STV6110x_CTRL2]);
|
2009-04-07 02:45:20 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stv6110x_set_bbgain(struct dvb_frontend *fe, u32 gain)
|
|
|
|
{
|
|
|
|
struct stv6110x_state *stv6110x = fe->tuner_priv;
|
|
|
|
|
2010-01-06 06:23:13 +08:00
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_BBGAIN, gain / 2);
|
|
|
|
stv6110x_write_reg(stv6110x, STV6110x_CTRL2, stv6110x->regs[STV6110x_CTRL2]);
|
2009-04-07 02:45:20 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stv6110x_set_mode(struct dvb_frontend *fe, enum tuner_mode mode)
|
|
|
|
{
|
|
|
|
struct stv6110x_state *stv6110x = fe->tuner_priv;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case TUNER_SLEEP:
|
2010-01-06 06:23:13 +08:00
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_SYN, 0);
|
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_RX, 0);
|
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_LPT, 0);
|
2009-04-07 02:45:20 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TUNER_WAKE:
|
2010-01-06 06:23:13 +08:00
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_SYN, 1);
|
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_RX, 1);
|
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_LPT, 1);
|
2009-04-07 02:45:20 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-01-06 06:23:13 +08:00
|
|
|
ret = stv6110x_write_reg(stv6110x, STV6110x_CTRL1, stv6110x->regs[STV6110x_CTRL1]);
|
2009-04-07 02:45:20 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
dprintk(FE_ERROR, 1, "I/O Error");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stv6110x_sleep(struct dvb_frontend *fe)
|
|
|
|
{
|
V4L/DVB: stv6110x: Fix kernel null pointer deref
The following OOPS happened when plugging two TT s2-1600:
[ 96.521023] saa7146: register extension 'budget dvb'.
[ 96.521052] budget dvb 0000:05:00.0: PCI INT A -> GSI 16 (level, low) -> IRQ 16
[ 96.521070] IRQ 16/: IRQF_DISABLED is not guaranteed on shared IRQs
[ 96.521076] saa7146: found saa7146 @ mem ffffc90011182c00 (revision 1, irq 16) (0x13c2,0x101c).
[ 96.521080] saa7146 (0): dma buffer size 192512
[ 96.521081] DVB: registering new adapter (TT-Budget S2-1600 PCI)
[ 96.539929] adapter has MAC addr = 00:d0:5c:cc:b0:a2
[ 96.890149] stv6110x_attach: Attaching STV6110x
[ 96.912516] DVB: registering adapter 0 frontend 0 (STV090x Multistandard)...
[ 96.912600] budget dvb 0000:05:01.0: PCI INT A -> GSI 17 (level, low) -> IRQ 17
[ 96.912639] IRQ 17/: IRQF_DISABLED is not guaranteed on shared IRQs
[ 96.912667] saa7146: found saa7146 @ mem ffffc90011314800 (revision 1, irq 17) (0x13c2,0x101c).
[ 96.912673] saa7146 (1): dma buffer size 192512
[ 96.912676] DVB: registering new adapter (TT-Budget S2-1600 PCI)
[ 96.930893] adapter has MAC addr = 00:d0:5c:cc:b0:a3
[ 97.233478] BUG: unable to handle kernel NULL pointer dereference at 0000000000000010
[ 97.233647] IP: [<ffffffffa029c450>] stv6110x_set_mode+0x70/0x80 [stv6110x]
[ 97.233753] PGD 3c16f067 PUD 3c383067 PMD 0
[ 97.234147] CPU 0
[ 97.234246] Pid: 5200, comm: modprobe Not tainted 2.6.33.2 #1 P5QSE/P5Q SE
[ 97.234317] RIP: 0010:[<ffffffffa029c450>] [<ffffffffa029c450>] stv6110x_set_mode+0x70/0x80 [stv6110x]
[ 97.234456] RSP: 0018:ffff88003c125c98 EFLAGS: 00010246
[ 97.234461] RAX: ffffffffa029c460 RBX: ffff88003f84d800 RCX: ffff88003a19e140
[ 97.234461] RDX: 0000000000000000 RSI: 0000000000000001 RDI: 0000000000000000
[ 97.234461] RBP: ffff88003f84d828 R08: 0000000000000002 R09: 0000000000000004
[ 97.234461] R10: 0000000000000003 R11: 0000000000000010 R12: ffff88003f84d800
[ 97.234461] R13: ffff88003f84d828 R14: ffff88003f84d828 R15: 0000000000000001
[ 97.234461] FS: 00007f9f7253e6f0(0000) GS:ffff880001800000(0000) knlGS:0000000000000000
[ 97.234461] CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b
[ 97.234461] CR2: 0000000000000010 CR3: 000000003c382000 CR4: 00000000000006b0
[ 97.234461] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 97.234461] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
[ 97.234461] Process modprobe (pid: 5200, threadinfo ffff88003c124000, task ffff88003e893ac0)
[ 97.234461] ffff88003f84d800 ffff88003f84d828 ffff88003f84d800 ffffffffa0292343
[ 97.234461] <0> ffff88003f84d828 ffff88003ef70ae0 ffffffffa0280800 ffffffffa02934d2
[ 97.234461] <0> ffffffffa0295260 0000000000000000 ffffffffa02948b0 ffff88003df79800
[ 97.234461] [<ffffffffa0292343>] ? stv090x_sleep+0x33/0x120 [stv090x]
[ 97.234461] [<ffffffffa02934d2>] ? stv090x_attach+0x1e2/0x73c [stv090x]
[ 97.234461] [<ffffffff81007cc5>] ? dma_generic_alloc_coherent+0xa5/0x160
[ 97.234461] [<ffffffffa026e1f5>] ? saa7146_init_one+0x7d5/0x910 [saa7146]
[ 97.234461] [<ffffffff811b84b2>] ? local_pci_probe+0x12/0x20
[ 97.234461] [<ffffffff811b87d0>] ? pci_device_probe+0x110/0x120
[ 97.234461] [<ffffffff81221788>] ? driver_probe_device+0x98/0x1b0
[ 97.234461] [<ffffffff81221933>] ? __driver_attach+0x93/0xa0
[ 97.234461] [<ffffffff812218a0>] ? __driver_attach+0x0/0xa0
[ 97.234461] [<ffffffff81220f18>] ? bus_for_each_dev+0x58/0x80
[ 97.234461] [<ffffffff8122079d>] ? bus_add_driver+0x14d/0x280
[ 97.234461] [<ffffffffa0284000>] ? budget_init+0x0/0xc [budget]
[ 97.234461] [<ffffffff81221c29>] ? driver_register+0x79/0x170
[ 97.234461] [<ffffffffa0284000>] ? budget_init+0x0/0xc [budget]
[ 97.234461] [<ffffffff811b8a48>] ? __pci_register_driver+0x58/0xe0
[ 97.234461] [<ffffffffa0284000>] ? budget_init+0x0/0xc [budget]
[ 97.234461] [<ffffffff810001d5>] ? do_one_initcall+0x35/0x190
[ 97.234461] [<ffffffff81063d37>] ? sys_init_module+0xe7/0x260
[ 97.234461] [<ffffffff8100256b>] ? system_call_fastpath+0x16/0x1b
[ 97.234461] RIP [<ffffffffa029c450>] stv6110x_set_mode+0x70/0x80 [stv6110x]
[ 97.234461] RSP <ffff88003c125c98>
[ 97.240074] ---[ end trace b53ecbbbbef15e99 ]---
Prevents calling stv6110x_set_mode() if fe->tuner_priv is not defined,
in order to avoid the above bug.
Signed-off-by: Guy Martin <gmsoft@tuxicoman.be>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2010-05-07 15:34:40 +08:00
|
|
|
if (fe->tuner_priv)
|
|
|
|
return stv6110x_set_mode(fe, TUNER_SLEEP);
|
|
|
|
|
|
|
|
return 0;
|
2009-04-07 02:45:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int stv6110x_get_status(struct dvb_frontend *fe, u32 *status)
|
|
|
|
{
|
|
|
|
struct stv6110x_state *stv6110x = fe->tuner_priv;
|
|
|
|
|
2010-01-06 06:23:13 +08:00
|
|
|
stv6110x_read_reg(stv6110x, STV6110x_STAT1, &stv6110x->regs[STV6110x_STAT1]);
|
2009-04-07 02:45:20 +08:00
|
|
|
|
2010-01-06 06:23:13 +08:00
|
|
|
if (STV6110x_GETFIELD(STAT1_LOCK, stv6110x->regs[STV6110x_STAT1]))
|
2009-04-07 02:45:20 +08:00
|
|
|
*status = TUNER_PHASELOCKED;
|
|
|
|
else
|
|
|
|
*status = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-19 06:30:51 +08:00
|
|
|
static void stv6110x_release(struct dvb_frontend *fe)
|
|
|
|
{
|
|
|
|
struct stv6110x_state *stv6110x = fe->tuner_priv;
|
|
|
|
|
|
|
|
fe->tuner_priv = NULL;
|
|
|
|
kfree(stv6110x);
|
|
|
|
}
|
|
|
|
|
2019-05-30 00:56:33 +08:00
|
|
|
static void st6110x_init_regs(struct stv6110x_state *stv6110x)
|
|
|
|
{
|
|
|
|
u8 default_regs[] = {0x07, 0x11, 0xdc, 0x85, 0x17, 0x01, 0xe6, 0x1e};
|
|
|
|
|
|
|
|
memcpy(stv6110x->regs, default_regs, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stv6110x_setup_divider(struct stv6110x_state *stv6110x)
|
|
|
|
{
|
|
|
|
switch (stv6110x->config->clk_div) {
|
|
|
|
default:
|
|
|
|
case 1:
|
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2],
|
|
|
|
CTRL2_CO_DIV,
|
|
|
|
0);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2],
|
|
|
|
CTRL2_CO_DIV,
|
|
|
|
1);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2],
|
|
|
|
CTRL2_CO_DIV,
|
|
|
|
2);
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
case 0:
|
|
|
|
STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2],
|
|
|
|
CTRL2_CO_DIV,
|
|
|
|
3);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-11 22:44:12 +08:00
|
|
|
static const struct dvb_tuner_ops stv6110x_ops = {
|
2009-04-07 02:45:20 +08:00
|
|
|
.info = {
|
2018-07-06 06:59:35 +08:00
|
|
|
.name = "STV6110(A) Silicon Tuner",
|
|
|
|
.frequency_min_hz = 950 * MHz,
|
|
|
|
.frequency_max_hz = 2150 * MHz,
|
2009-04-07 02:45:20 +08:00
|
|
|
},
|
2016-11-19 06:30:51 +08:00
|
|
|
.release = stv6110x_release
|
2009-04-07 02:45:20 +08:00
|
|
|
};
|
|
|
|
|
2019-05-30 00:56:33 +08:00
|
|
|
static struct stv6110x_devctl stv6110x_ctl = {
|
2009-04-07 02:45:20 +08:00
|
|
|
.tuner_init = stv6110x_init,
|
2010-01-23 16:49:08 +08:00
|
|
|
.tuner_sleep = stv6110x_sleep,
|
2009-04-07 02:45:20 +08:00
|
|
|
.tuner_set_mode = stv6110x_set_mode,
|
|
|
|
.tuner_set_frequency = stv6110x_set_frequency,
|
|
|
|
.tuner_get_frequency = stv6110x_get_frequency,
|
|
|
|
.tuner_set_bandwidth = stv6110x_set_bandwidth,
|
|
|
|
.tuner_get_bandwidth = stv6110x_get_bandwidth,
|
|
|
|
.tuner_set_bbgain = stv6110x_set_bbgain,
|
|
|
|
.tuner_get_bbgain = stv6110x_get_bbgain,
|
|
|
|
.tuner_set_refclk = stv6110x_set_refclock,
|
|
|
|
.tuner_get_status = stv6110x_get_status,
|
|
|
|
};
|
|
|
|
|
2019-05-30 00:56:33 +08:00
|
|
|
static void stv6110x_set_frontend_opts(struct stv6110x_state *stv6110x)
|
|
|
|
{
|
|
|
|
stv6110x->frontend->tuner_priv = stv6110x;
|
|
|
|
stv6110x->frontend->ops.tuner_ops = stv6110x_ops;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct stv6110x_devctl *stv6110x_get_devctl(struct i2c_client *client)
|
|
|
|
{
|
|
|
|
struct stv6110x_state *stv6110x = i2c_get_clientdata(client);
|
|
|
|
|
|
|
|
dev_dbg(&client->dev, "\n");
|
|
|
|
|
|
|
|
return stv6110x->devctl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stv6110x_probe(struct i2c_client *client,
|
|
|
|
const struct i2c_device_id *id)
|
|
|
|
{
|
|
|
|
struct stv6110x_config *config = client->dev.platform_data;
|
|
|
|
|
|
|
|
struct stv6110x_state *stv6110x;
|
|
|
|
|
|
|
|
stv6110x = kzalloc(sizeof(*stv6110x), GFP_KERNEL);
|
|
|
|
if (!stv6110x)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
stv6110x->frontend = config->frontend;
|
|
|
|
stv6110x->i2c = client->adapter;
|
|
|
|
stv6110x->config = config;
|
|
|
|
stv6110x->devctl = &stv6110x_ctl;
|
|
|
|
|
|
|
|
st6110x_init_regs(stv6110x);
|
|
|
|
stv6110x_setup_divider(stv6110x);
|
|
|
|
stv6110x_set_frontend_opts(stv6110x);
|
|
|
|
|
|
|
|
dev_info(&stv6110x->i2c->dev, "Probed STV6110x\n");
|
|
|
|
|
|
|
|
i2c_set_clientdata(client, stv6110x);
|
|
|
|
|
|
|
|
/* setup callbacks */
|
|
|
|
config->get_devctl = stv6110x_get_devctl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stv6110x_remove(struct i2c_client *client)
|
|
|
|
{
|
|
|
|
struct stv6110x_state *stv6110x = i2c_get_clientdata(client);
|
|
|
|
|
|
|
|
stv6110x_release(stv6110x->frontend);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-06 23:34:26 +08:00
|
|
|
const struct stv6110x_devctl *stv6110x_attach(struct dvb_frontend *fe,
|
2009-04-07 02:45:20 +08:00
|
|
|
const struct stv6110x_config *config,
|
|
|
|
struct i2c_adapter *i2c)
|
|
|
|
{
|
|
|
|
struct stv6110x_state *stv6110x;
|
|
|
|
|
2019-05-30 00:56:33 +08:00
|
|
|
stv6110x = kzalloc(sizeof(*stv6110x), GFP_KERNEL);
|
2010-05-05 13:58:18 +08:00
|
|
|
if (!stv6110x)
|
|
|
|
return NULL;
|
2009-04-07 02:45:20 +08:00
|
|
|
|
2019-05-30 00:56:33 +08:00
|
|
|
stv6110x->frontend = fe;
|
2009-04-07 02:45:20 +08:00
|
|
|
stv6110x->i2c = i2c;
|
|
|
|
stv6110x->config = config;
|
|
|
|
stv6110x->devctl = &stv6110x_ctl;
|
|
|
|
|
2019-05-30 00:56:33 +08:00
|
|
|
st6110x_init_regs(stv6110x);
|
|
|
|
stv6110x_setup_divider(stv6110x);
|
|
|
|
stv6110x_set_frontend_opts(stv6110x);
|
2010-01-06 06:24:10 +08:00
|
|
|
|
2009-04-07 02:45:20 +08:00
|
|
|
fe->tuner_priv = stv6110x;
|
|
|
|
fe->ops.tuner_ops = stv6110x_ops;
|
|
|
|
|
2019-05-30 00:56:33 +08:00
|
|
|
dev_info(&stv6110x->i2c->dev, "Attaching STV6110x\n");
|
2009-04-07 02:45:20 +08:00
|
|
|
return stv6110x->devctl;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(stv6110x_attach);
|
|
|
|
|
2019-05-30 00:56:33 +08:00
|
|
|
static const struct i2c_device_id stv6110x_id_table[] = {
|
|
|
|
{"stv6110x", 0},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, stv6110x_id_table);
|
|
|
|
|
|
|
|
static struct i2c_driver stv6110x_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "stv6110x",
|
|
|
|
.suppress_bind_attrs = true,
|
|
|
|
},
|
|
|
|
.probe = stv6110x_probe,
|
|
|
|
.remove = stv6110x_remove,
|
|
|
|
.id_table = stv6110x_id_table,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_i2c_driver(stv6110x_driver);
|
|
|
|
|
2009-04-07 02:45:20 +08:00
|
|
|
MODULE_AUTHOR("Manu Abraham");
|
|
|
|
MODULE_DESCRIPTION("STV6110x Silicon tuner");
|
|
|
|
MODULE_LICENSE("GPL");
|