2017-11-29 06:33:45 -07:00
|
|
|
/*
|
2006-09-05 14:53:06 -06:00
|
|
|
* Driver for Infineon tua6100 pll.
|
|
|
|
*
|
|
|
|
* (c) 2006 Andrew de Quincey
|
|
|
|
*
|
|
|
|
* Based on code found in budget-av.c, which has the following:
|
|
|
|
* Compiled from various sources by Michael Hunold <michael@mihu.de>
|
|
|
|
*
|
|
|
|
* CI interface support (c) 2004 Olivier Gournet <ogournet@anevia.com> &
|
|
|
|
* Andrew de Quincey <adq_dvb@lidskialf.net>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Ralph Metzler <rjkm@metzlerbros.de>
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999-2002 Ralph Metzler
|
|
|
|
* & Marcus Metzler for convergence integrated media GmbH
|
|
|
|
* 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 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 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2006-09-05 14:53:06 -06:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/dvb/frontend.h>
|
|
|
|
#include <asm/types.h>
|
|
|
|
|
|
|
|
#include "tua6100.h"
|
|
|
|
|
|
|
|
struct tua6100_priv {
|
|
|
|
/* i2c details */
|
|
|
|
int i2c_address;
|
|
|
|
struct i2c_adapter *i2c;
|
|
|
|
u32 frequency;
|
|
|
|
};
|
|
|
|
|
2016-11-18 15:30:51 -07:00
|
|
|
static void tua6100_release(struct dvb_frontend *fe)
|
|
|
|
{
|
|
|
|
kfree(fe->tuner_priv);
|
|
|
|
fe->tuner_priv = NULL;
|
|
|
|
}
|
|
|
|
|
2006-09-05 14:53:06 -06:00
|
|
|
static int tua6100_sleep(struct dvb_frontend *fe)
|
|
|
|
{
|
|
|
|
struct tua6100_priv *priv = fe->tuner_priv;
|
|
|
|
int ret;
|
|
|
|
u8 reg0[] = { 0x00, 0x00 };
|
|
|
|
struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = reg0, .len = 2 };
|
|
|
|
|
|
|
|
if (fe->ops.i2c_gate_ctrl)
|
|
|
|
fe->ops.i2c_gate_ctrl(fe, 1);
|
|
|
|
if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) {
|
2008-04-08 20:20:00 -06:00
|
|
|
printk("%s: i2c error\n", __func__);
|
2006-09-05 14:53:06 -06:00
|
|
|
}
|
|
|
|
if (fe->ops.i2c_gate_ctrl)
|
|
|
|
fe->ops.i2c_gate_ctrl(fe, 0);
|
|
|
|
|
|
|
|
return (ret == 1) ? 0 : ret;
|
|
|
|
}
|
|
|
|
|
2011-12-24 08:24:33 -07:00
|
|
|
static int tua6100_set_params(struct dvb_frontend *fe)
|
2006-09-05 14:53:06 -06:00
|
|
|
{
|
2011-12-23 13:56:57 -07:00
|
|
|
struct dtv_frontend_properties *c = &fe->dtv_property_cache;
|
2006-09-05 14:53:06 -06:00
|
|
|
struct tua6100_priv *priv = fe->tuner_priv;
|
|
|
|
u32 div;
|
|
|
|
u32 prediv;
|
|
|
|
u8 reg0[] = { 0x00, 0x00 };
|
|
|
|
u8 reg1[] = { 0x01, 0x00, 0x00, 0x00 };
|
|
|
|
u8 reg2[] = { 0x02, 0x00, 0x00 };
|
|
|
|
struct i2c_msg msg0 = { .addr = priv->i2c_address, .flags = 0, .buf = reg0, .len = 2 };
|
|
|
|
struct i2c_msg msg1 = { .addr = priv->i2c_address, .flags = 0, .buf = reg1, .len = 4 };
|
|
|
|
struct i2c_msg msg2 = { .addr = priv->i2c_address, .flags = 0, .buf = reg2, .len = 3 };
|
|
|
|
|
|
|
|
#define _R 4
|
|
|
|
#define _P 32
|
|
|
|
#define _ri 4000000
|
|
|
|
|
|
|
|
// setup register 0
|
2011-12-23 13:56:57 -07:00
|
|
|
if (c->frequency < 2000000)
|
2006-09-05 14:53:06 -06:00
|
|
|
reg0[1] = 0x03;
|
2011-12-23 13:56:57 -07:00
|
|
|
else
|
2006-09-05 14:53:06 -06:00
|
|
|
reg0[1] = 0x07;
|
|
|
|
|
|
|
|
// setup register 1
|
2011-12-23 13:56:57 -07:00
|
|
|
if (c->frequency < 1630000)
|
2006-09-05 14:53:06 -06:00
|
|
|
reg1[1] = 0x2c;
|
2011-12-23 13:56:57 -07:00
|
|
|
else
|
2006-09-05 14:53:06 -06:00
|
|
|
reg1[1] = 0x0c;
|
2011-12-23 13:56:57 -07:00
|
|
|
|
2006-09-05 14:53:06 -06:00
|
|
|
if (_P == 64)
|
|
|
|
reg1[1] |= 0x40;
|
2011-12-23 13:56:57 -07:00
|
|
|
if (c->frequency >= 1525000)
|
2006-09-05 14:53:06 -06:00
|
|
|
reg1[1] |= 0x80;
|
|
|
|
|
|
|
|
// register 2
|
|
|
|
reg2[1] = (_R >> 8) & 0x03;
|
|
|
|
reg2[2] = _R;
|
2011-12-23 13:56:57 -07:00
|
|
|
if (c->frequency < 1455000)
|
2006-09-05 14:53:06 -06:00
|
|
|
reg2[1] |= 0x1c;
|
2011-12-23 13:56:57 -07:00
|
|
|
else if (c->frequency < 1630000)
|
2006-09-05 14:53:06 -06:00
|
|
|
reg2[1] |= 0x0c;
|
2011-12-23 13:56:57 -07:00
|
|
|
else
|
2006-09-05 14:53:06 -06:00
|
|
|
reg2[1] |= 0x1c;
|
|
|
|
|
2011-12-23 13:56:57 -07:00
|
|
|
/*
|
|
|
|
* The N divisor ratio (note: c->frequency is in kHz, but we
|
|
|
|
* need it in Hz)
|
|
|
|
*/
|
|
|
|
prediv = (c->frequency * _R) / (_ri / 1000);
|
2006-09-05 14:53:06 -06:00
|
|
|
div = prediv / _P;
|
|
|
|
reg1[1] |= (div >> 9) & 0x03;
|
|
|
|
reg1[2] = div >> 1;
|
|
|
|
reg1[3] = (div << 7);
|
|
|
|
priv->frequency = ((div * _P) * (_ri / 1000)) / _R;
|
|
|
|
|
|
|
|
// Finally, calculate and store the value for A
|
|
|
|
reg1[3] |= (prediv - (div*_P)) & 0x7f;
|
|
|
|
|
|
|
|
#undef _R
|
|
|
|
#undef _P
|
|
|
|
#undef _ri
|
|
|
|
|
|
|
|
if (fe->ops.i2c_gate_ctrl)
|
|
|
|
fe->ops.i2c_gate_ctrl(fe, 1);
|
|
|
|
if (i2c_transfer(priv->i2c, &msg0, 1) != 1)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
if (fe->ops.i2c_gate_ctrl)
|
|
|
|
fe->ops.i2c_gate_ctrl(fe, 1);
|
|
|
|
if (i2c_transfer(priv->i2c, &msg2, 1) != 1)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
if (fe->ops.i2c_gate_ctrl)
|
|
|
|
fe->ops.i2c_gate_ctrl(fe, 1);
|
|
|
|
if (i2c_transfer(priv->i2c, &msg1, 1) != 1)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
if (fe->ops.i2c_gate_ctrl)
|
|
|
|
fe->ops.i2c_gate_ctrl(fe, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tua6100_get_frequency(struct dvb_frontend *fe, u32 *frequency)
|
|
|
|
{
|
|
|
|
struct tua6100_priv *priv = fe->tuner_priv;
|
|
|
|
*frequency = priv->frequency;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-11 08:44:12 -06:00
|
|
|
static const struct dvb_tuner_ops tua6100_tuner_ops = {
|
2006-09-05 14:53:06 -06:00
|
|
|
.info = {
|
|
|
|
.name = "Infineon TUA6100",
|
|
|
|
.frequency_min = 950000,
|
|
|
|
.frequency_max = 2150000,
|
|
|
|
.frequency_step = 1000,
|
|
|
|
},
|
2016-11-18 15:30:51 -07:00
|
|
|
.release = tua6100_release,
|
2006-09-05 14:53:06 -06:00
|
|
|
.sleep = tua6100_sleep,
|
|
|
|
.set_params = tua6100_set_params,
|
|
|
|
.get_frequency = tua6100_get_frequency,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct dvb_frontend *tua6100_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c)
|
|
|
|
{
|
|
|
|
struct tua6100_priv *priv = NULL;
|
|
|
|
u8 b1 [] = { 0x80 };
|
|
|
|
u8 b2 [] = { 0x00 };
|
|
|
|
struct i2c_msg msg [] = { { .addr = addr, .flags = 0, .buf = b1, .len = 1 },
|
|
|
|
{ .addr = addr, .flags = I2C_M_RD, .buf = b2, .len = 1 } };
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (fe->ops.i2c_gate_ctrl)
|
|
|
|
fe->ops.i2c_gate_ctrl(fe, 1);
|
|
|
|
ret = i2c_transfer (i2c, msg, 2);
|
|
|
|
if (fe->ops.i2c_gate_ctrl)
|
|
|
|
fe->ops.i2c_gate_ctrl(fe, 0);
|
|
|
|
|
|
|
|
if (ret != 2)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
priv = kzalloc(sizeof(struct tua6100_priv), GFP_KERNEL);
|
|
|
|
if (priv == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
priv->i2c_address = addr;
|
|
|
|
priv->i2c = i2c;
|
|
|
|
|
|
|
|
memcpy(&fe->ops.tuner_ops, &tua6100_tuner_ops, sizeof(struct dvb_tuner_ops));
|
|
|
|
fe->tuner_priv = priv;
|
|
|
|
return fe;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(tua6100_attach);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("DVB tua6100 driver");
|
|
|
|
MODULE_AUTHOR("Andrew de Quincey");
|
|
|
|
MODULE_LICENSE("GPL");
|