2019-05-27 14:55:06 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2007-03-29 19:42:30 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2016-11-16 16:59:49 +08:00
|
|
|
*
|
|
|
|
* cx88-i2c.c -- all the i2c code is here
|
|
|
|
*
|
|
|
|
* Copyright (C) 1996,97,98 Ralph Metzler (rjkm@thp.uni-koeln.de)
|
|
|
|
* & Marcus Metzler (mocm@thp.uni-koeln.de)
|
|
|
|
* (c) 2002 Yurij Sysoev <yurij@naturesoft.net>
|
|
|
|
* (c) 1999-2003 Gerd Knorr <kraxel@bytesex.org>
|
|
|
|
*
|
MAINTAINERS & files: Canonize the e-mails I use at files
From now on, I'll start using my @kernel.org as my development e-mail.
As such, let's remove the entries that point to the old
mchehab@s-opensource.com at MAINTAINERS file.
For the files written with a copyright with mchehab@s-opensource,
let's keep Samsung on their names, using mchehab+samsung@kernel.org,
in order to keep pointing to my employer, with sponsors the work.
For the files written before I join Samsung (on July, 4 2013),
let's just use mchehab@kernel.org.
For bug reports, we can simply point to just kernel.org, as
this will reach my mchehab+samsung inbox anyway.
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Signed-off-by: Brian Warner <brian.warner@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
2018-04-25 17:34:48 +08:00
|
|
|
* (c) 2005 Mauro Carvalho Chehab <mchehab@kernel.org>
|
2016-11-16 16:59:49 +08:00
|
|
|
* - Multituner support and i2c address binding
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-11-13 20:07:38 +08:00
|
|
|
#include "cx88.h"
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/init.h>
|
[media] cx88: make checkpatch.pl happy
Usually, I don't like fixing coding style issues on non-staging
drivers, as it could be a mess pretty easy, and could become like
a snow ball. That's the case of recent changes on two changesets:
they disalign some statements. Yet, a care a lot with cx88 driver,
as it was the first driver I touched at the Kernel, and I've been
maintaining it since 2005. So, several of the coding style issues
were due to my code.
Per Andrey's suggestion, I ran checkpatch.pl in strict mode, with
fixed several other issues, did some function alinments, but broke
other alinments.
So, I had to manually apply another round of manual fixes to make
sure that everything is ok, and to make checkpatch happy with
this patch.
With this patch, checkpatch.pl is now happy when called with:
./scripts/checkpatch.pl -f --max-line-length=998 --ignore PREFER_PR_LEVEL
Also, the 80-cols violations that made sense were fixed.
Checkpatch would be happier if we convert it to use dev_foo(),
but this is a more complex change.
NOTE: there are some places with msleep(1). As this driver was
written at the time that the default was to sleep at least 10ms
on such calls (e. g. CONFIG_HZ=100), I replaced those calls by
usleep_range(10000, 20000), with should be safe to avoid breakages.
Fixes: 65bc2fe86e66 ("[media] cx88: convert it to use pr_foo() macros")
Fixes: 7b61ba8ff838 ("[media] cx88: make checkpatch happier")
Suggested-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Reviewed-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-11-20 05:27:30 +08:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/module.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-10 01:32:31 +08:00
|
|
|
#include <media/v4l2-common.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-23 01:41:48 +08:00
|
|
|
static unsigned int i2c_debug;
|
2005-04-17 06:20:36 +08:00
|
|
|
module_param(i2c_debug, int, 0644);
|
2016-11-16 16:59:49 +08:00
|
|
|
MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-23 01:41:48 +08:00
|
|
|
static unsigned int i2c_scan;
|
2005-04-17 06:20:36 +08:00
|
|
|
module_param(i2c_scan, int, 0444);
|
2016-11-16 16:59:49 +08:00
|
|
|
MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-09-07 06:04:28 +08:00
|
|
|
static unsigned int i2c_udelay = 5;
|
|
|
|
module_param(i2c_udelay, int, 0644);
|
[media] cx88: make checkpatch.pl happy
Usually, I don't like fixing coding style issues on non-staging
drivers, as it could be a mess pretty easy, and could become like
a snow ball. That's the case of recent changes on two changesets:
they disalign some statements. Yet, a care a lot with cx88 driver,
as it was the first driver I touched at the Kernel, and I've been
maintaining it since 2005. So, several of the coding style issues
were due to my code.
Per Andrey's suggestion, I ran checkpatch.pl in strict mode, with
fixed several other issues, did some function alinments, but broke
other alinments.
So, I had to manually apply another round of manual fixes to make
sure that everything is ok, and to make checkpatch happy with
this patch.
With this patch, checkpatch.pl is now happy when called with:
./scripts/checkpatch.pl -f --max-line-length=998 --ignore PREFER_PR_LEVEL
Also, the 80-cols violations that made sense were fixed.
Checkpatch would be happier if we convert it to use dev_foo(),
but this is a more complex change.
NOTE: there are some places with msleep(1). As this driver was
written at the time that the default was to sleep at least 10ms
on such calls (e. g. CONFIG_HZ=100), I replaced those calls by
usleep_range(10000, 20000), with should be safe to avoid breakages.
Fixes: 65bc2fe86e66 ("[media] cx88: convert it to use pr_foo() macros")
Fixes: 7b61ba8ff838 ("[media] cx88: make checkpatch happier")
Suggested-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Reviewed-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-11-20 05:27:30 +08:00
|
|
|
MODULE_PARM_DESC(i2c_udelay,
|
|
|
|
"i2c delay at insmod time, in usecs (should be 5 or higher). Lower value means higher bus speed.");
|
2006-09-07 06:04:28 +08:00
|
|
|
|
2016-11-13 20:07:38 +08:00
|
|
|
#define dprintk(level, fmt, arg...) do { \
|
|
|
|
if (i2c_debug >= level) \
|
|
|
|
printk(KERN_DEBUG pr_fmt("%s: i2c:" fmt), \
|
|
|
|
__func__, ##arg); \
|
|
|
|
} while (0)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
|
2005-05-01 23:59:29 +08:00
|
|
|
static void cx8800_bit_setscl(void *data, int state)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct cx88_core *core = data;
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
core->i2c_state |= 0x02;
|
|
|
|
else
|
|
|
|
core->i2c_state &= ~0x02;
|
|
|
|
cx_write(MO_I2C, core->i2c_state);
|
|
|
|
cx_read(MO_I2C);
|
|
|
|
}
|
|
|
|
|
2005-05-01 23:59:29 +08:00
|
|
|
static void cx8800_bit_setsda(void *data, int state)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct cx88_core *core = data;
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
core->i2c_state |= 0x01;
|
|
|
|
else
|
|
|
|
core->i2c_state &= ~0x01;
|
|
|
|
cx_write(MO_I2C, core->i2c_state);
|
|
|
|
cx_read(MO_I2C);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cx8800_bit_getscl(void *data)
|
|
|
|
{
|
|
|
|
struct cx88_core *core = data;
|
|
|
|
u32 state;
|
|
|
|
|
|
|
|
state = cx_read(MO_I2C);
|
|
|
|
return state & 0x02 ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cx8800_bit_getsda(void *data)
|
|
|
|
{
|
|
|
|
struct cx88_core *core = data;
|
|
|
|
u32 state;
|
|
|
|
|
|
|
|
state = cx_read(MO_I2C);
|
|
|
|
return state & 0x01;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
|
2007-07-02 05:37:51 +08:00
|
|
|
static const struct i2c_algo_bit_data cx8800_i2c_algo_template = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.setsda = cx8800_bit_setsda,
|
|
|
|
.setscl = cx8800_bit_setscl,
|
|
|
|
.getsda = cx8800_bit_getsda,
|
|
|
|
.getscl = cx8800_bit_getscl,
|
|
|
|
.udelay = 16,
|
|
|
|
.timeout = 200,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
|
2010-08-25 20:50:20 +08:00
|
|
|
static const char * const i2c_devs[128] = {
|
2016-11-16 16:59:49 +08:00
|
|
|
[0x1c >> 1] = "lgdt330x",
|
|
|
|
[0x86 >> 1] = "tda9887/cx22702",
|
|
|
|
[0xa0 >> 1] = "eeprom",
|
|
|
|
[0xc0 >> 1] = "tuner (analog)",
|
|
|
|
[0xc2 >> 1] = "tuner (analog/dvb)",
|
|
|
|
[0xc8 >> 1] = "xc5000",
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2010-08-25 20:50:20 +08:00
|
|
|
static void do_i2c_scan(const char *name, struct i2c_client *c)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned char buf;
|
2016-11-16 16:59:49 +08:00
|
|
|
int i, rc;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-03-29 19:42:30 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(i2c_devs); i++) {
|
2005-04-17 06:20:36 +08:00
|
|
|
c->addr = i;
|
2016-11-16 16:59:49 +08:00
|
|
|
rc = i2c_master_recv(c, &buf, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (rc < 0)
|
|
|
|
continue;
|
2016-11-13 20:07:38 +08:00
|
|
|
pr_info("i2c scan: found device @ 0x%x [%s]\n",
|
|
|
|
i << 1, i2c_devs[i] ? i2c_devs[i] : "???");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-10 00:27:53 +08:00
|
|
|
/* init + register i2c adapter */
|
2005-04-17 06:20:36 +08:00
|
|
|
int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci)
|
|
|
|
{
|
2006-09-07 06:04:28 +08:00
|
|
|
/* Prevents usage of invalid delay values */
|
2016-11-16 16:59:49 +08:00
|
|
|
if (i2c_udelay < 5)
|
|
|
|
i2c_udelay = 5;
|
2006-09-07 06:04:28 +08:00
|
|
|
|
2012-10-24 02:57:19 +08:00
|
|
|
core->i2c_algo = cx8800_i2c_algo_template;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
core->i2c_adap.dev.parent = &pci->dev;
|
2018-09-10 20:19:14 +08:00
|
|
|
strscpy(core->i2c_adap.name, core->name, sizeof(core->i2c_adap.name));
|
2007-07-02 05:37:51 +08:00
|
|
|
core->i2c_adap.owner = THIS_MODULE;
|
|
|
|
core->i2c_algo.udelay = i2c_udelay;
|
2005-11-09 13:37:43 +08:00
|
|
|
core->i2c_algo.data = core;
|
2009-03-14 23:40:51 +08:00
|
|
|
i2c_set_adapdata(&core->i2c_adap, &core->v4l2_dev);
|
2005-11-09 13:37:43 +08:00
|
|
|
core->i2c_adap.algo_data = &core->i2c_algo;
|
|
|
|
core->i2c_client.adapter = &core->i2c_adap;
|
2018-09-10 20:19:14 +08:00
|
|
|
strscpy(core->i2c_client.name, "cx88xx internal", I2C_NAME_SIZE);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-11-16 16:59:49 +08:00
|
|
|
cx8800_bit_setscl(core, 1);
|
|
|
|
cx8800_bit_setsda(core, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
core->i2c_rc = i2c_bit_add_bus(&core->i2c_adap);
|
2016-11-16 16:59:49 +08:00
|
|
|
if (core->i2c_rc == 0) {
|
|
|
|
static u8 tuner_data[] = {
|
|
|
|
0x0b, 0xdc, 0x86, 0x52 };
|
|
|
|
static struct i2c_msg tuner_msg = {
|
|
|
|
.flags = 0,
|
|
|
|
.addr = 0xc2 >> 1,
|
|
|
|
.buf = tuner_data,
|
|
|
|
.len = 4
|
|
|
|
};
|
2008-09-22 12:46:26 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
dprintk(1, "i2c register ok\n");
|
2016-11-16 16:59:49 +08:00
|
|
|
switch (core->boardnr) {
|
[media] cx88: make checkpatch.pl happy
Usually, I don't like fixing coding style issues on non-staging
drivers, as it could be a mess pretty easy, and could become like
a snow ball. That's the case of recent changes on two changesets:
they disalign some statements. Yet, a care a lot with cx88 driver,
as it was the first driver I touched at the Kernel, and I've been
maintaining it since 2005. So, several of the coding style issues
were due to my code.
Per Andrey's suggestion, I ran checkpatch.pl in strict mode, with
fixed several other issues, did some function alinments, but broke
other alinments.
So, I had to manually apply another round of manual fixes to make
sure that everything is ok, and to make checkpatch happy with
this patch.
With this patch, checkpatch.pl is now happy when called with:
./scripts/checkpatch.pl -f --max-line-length=998 --ignore PREFER_PR_LEVEL
Also, the 80-cols violations that made sense were fixed.
Checkpatch would be happier if we convert it to use dev_foo(),
but this is a more complex change.
NOTE: there are some places with msleep(1). As this driver was
written at the time that the default was to sleep at least 10ms
on such calls (e. g. CONFIG_HZ=100), I replaced those calls by
usleep_range(10000, 20000), with should be safe to avoid breakages.
Fixes: 65bc2fe86e66 ("[media] cx88: convert it to use pr_foo() macros")
Fixes: 7b61ba8ff838 ("[media] cx88: make checkpatch happier")
Suggested-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Reviewed-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-11-20 05:27:30 +08:00
|
|
|
case CX88_BOARD_HAUPPAUGE_HVR1300:
|
|
|
|
case CX88_BOARD_HAUPPAUGE_HVR3000:
|
|
|
|
case CX88_BOARD_HAUPPAUGE_HVR4000:
|
|
|
|
pr_info("i2c init: enabling analog demod on HVR1300/3000/4000 tuner\n");
|
|
|
|
i2c_transfer(core->i2c_client.adapter, &tuner_msg, 1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2008-09-22 12:46:26 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
if (i2c_scan)
|
2016-11-16 16:59:49 +08:00
|
|
|
do_i2c_scan(core->name, &core->i2c_client);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else
|
2016-11-13 20:07:38 +08:00
|
|
|
pr_err("i2c register FAILED\n");
|
2009-05-14 03:48:50 +08:00
|
|
|
|
2010-06-28 23:55:43 +08:00
|
|
|
return core->i2c_rc;
|
|
|
|
}
|