2007-03-29 19:42:30 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
|
|
|
|
cx88-i2c.c -- all the i2c code is here
|
|
|
|
|
|
|
|
Copyright (C) 1996,97,98 Ralph Metzler (rjkm@thp.uni-koeln.de)
|
2005-11-09 13:37:43 +08:00
|
|
|
& Marcus Metzler (mocm@thp.uni-koeln.de)
|
2005-04-17 06:20:36 +08:00
|
|
|
(c) 2002 Yurij Sysoev <yurij@naturesoft.net>
|
|
|
|
(c) 1999-2003 Gerd Knorr <kraxel@bytesex.org>
|
|
|
|
|
2006-08-21 20:04:14 +08:00
|
|
|
(c) 2005 Mauro Carvalho Chehab <mchehab@infradead.org>
|
|
|
|
- Multituner support and i2c address binding
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
|
|
|
|
#include "cx88.h"
|
2006-01-10 01:32:31 +08:00
|
|
|
#include <media/v4l2-common.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static unsigned int i2c_debug = 0;
|
|
|
|
module_param(i2c_debug, int, 0644);
|
|
|
|
MODULE_PARM_DESC(i2c_debug,"enable debug messages [i2c]");
|
|
|
|
|
|
|
|
static unsigned int i2c_scan = 0;
|
|
|
|
module_param(i2c_scan, int, 0444);
|
|
|
|
MODULE_PARM_DESC(i2c_scan,"scan i2c bus at insmod time");
|
|
|
|
|
2006-09-07 06:04:28 +08:00
|
|
|
static unsigned int i2c_udelay = 5;
|
|
|
|
module_param(i2c_udelay, int, 0644);
|
|
|
|
MODULE_PARM_DESC(i2c_udelay,"i2c delay at insmod time, in usecs "
|
|
|
|
"(should be 5 or higher). Lower value means higher bus speed.");
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#define dprintk(level,fmt, arg...) if (i2c_debug >= level) \
|
|
|
|
printk(KERN_DEBUG "%s: " fmt, core->name , ## arg)
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static int attach_inform(struct i2c_client *client)
|
|
|
|
{
|
2005-11-09 13:37:43 +08:00
|
|
|
struct tuner_setup tun_setup;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct cx88_core *core = i2c_get_adapdata(client->adapter);
|
|
|
|
|
2005-07-13 04:58:44 +08:00
|
|
|
dprintk(1, "%s i2c attach [addr=0x%x,client=%s]\n",
|
2005-11-27 03:43:39 +08:00
|
|
|
client->driver->driver.name, client->addr, client->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!client->driver->command)
|
|
|
|
return 0;
|
|
|
|
|
2007-08-16 01:41:57 +08:00
|
|
|
if (core->board.radio_type != UNSET) {
|
|
|
|
if ((core->board.radio_addr==ADDR_UNSET)||(core->board.radio_addr==client->addr)) {
|
2005-07-13 04:58:44 +08:00
|
|
|
tun_setup.mode_mask = T_RADIO;
|
2007-08-16 01:41:57 +08:00
|
|
|
tun_setup.type = core->board.radio_type;
|
|
|
|
tun_setup.addr = core->board.radio_addr;
|
2005-07-13 04:58:44 +08:00
|
|
|
|
|
|
|
client->driver->command (client, TUNER_SET_TYPE_ADDR, &tun_setup);
|
|
|
|
}
|
2005-11-09 13:37:43 +08:00
|
|
|
}
|
2007-08-16 01:41:57 +08:00
|
|
|
if (core->board.tuner_type != UNSET) {
|
|
|
|
if ((core->board.tuner_addr==ADDR_UNSET)||(core->board.tuner_addr==client->addr)) {
|
2005-07-13 04:58:44 +08:00
|
|
|
|
|
|
|
tun_setup.mode_mask = T_ANALOG_TV;
|
2007-08-16 01:41:57 +08:00
|
|
|
tun_setup.type = core->board.tuner_type;
|
|
|
|
tun_setup.addr = core->board.tuner_addr;
|
2005-07-13 04:58:44 +08:00
|
|
|
|
|
|
|
client->driver->command (client,TUNER_SET_TYPE_ADDR, &tun_setup);
|
|
|
|
}
|
2005-11-09 13:37:43 +08:00
|
|
|
}
|
2005-06-24 13:05:03 +08:00
|
|
|
|
2007-08-16 01:41:57 +08:00
|
|
|
if (core->board.tda9887_conf)
|
|
|
|
client->driver->command(client, TDA9887_SET_CONFIG, &core->board.tda9887_conf);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int detach_inform(struct i2c_client *client)
|
|
|
|
{
|
|
|
|
struct cx88_core *core = i2c_get_adapdata(client->adapter);
|
|
|
|
|
2005-08-16 01:57:04 +08:00
|
|
|
dprintk(1, "i2c detach [client=%s]\n", client->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cx88_call_i2c_clients(struct cx88_core *core, unsigned int cmd, void *arg)
|
|
|
|
{
|
|
|
|
if (0 != core->i2c_rc)
|
|
|
|
return;
|
2006-01-10 01:25:12 +08:00
|
|
|
|
2007-10-04 15:54:11 +08:00
|
|
|
#if defined(CONFIG_VIDEO_CX88_DVB) || defined(CONFIG_VIDEO_CX88_DVB_MODULE)
|
2006-09-27 12:16:50 +08:00
|
|
|
if ( (core->dvbdev) && (core->dvbdev->dvb.frontend) ) {
|
2006-05-14 16:01:31 +08:00
|
|
|
if (core->dvbdev->dvb.frontend->ops.i2c_gate_ctrl)
|
|
|
|
core->dvbdev->dvb.frontend->ops.i2c_gate_ctrl(core->dvbdev->dvb.frontend, 1);
|
2006-01-10 01:25:12 +08:00
|
|
|
|
|
|
|
i2c_clients_command(&core->i2c_adap, cmd, arg);
|
|
|
|
|
2006-05-14 16:01:31 +08:00
|
|
|
if (core->dvbdev->dvb.frontend->ops.i2c_gate_ctrl)
|
|
|
|
core->dvbdev->dvb.frontend->ops.i2c_gate_ctrl(core->dvbdev->dvb.frontend, 0);
|
2006-01-10 01:25:13 +08:00
|
|
|
} else
|
2007-01-31 10:26:01 +08:00
|
|
|
#endif
|
2006-01-10 01:25:13 +08:00
|
|
|
i2c_clients_command(&core->i2c_adap, cmd, arg);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static char *i2c_devs[128] = {
|
2005-07-28 02:46:00 +08:00
|
|
|
[ 0x1c >> 1 ] = "lgdt330x",
|
2005-04-17 06:20:36 +08:00
|
|
|
[ 0x86 >> 1 ] = "tda9887/cx22702",
|
|
|
|
[ 0xa0 >> 1 ] = "eeprom",
|
|
|
|
[ 0xc0 >> 1 ] = "tuner (analog)",
|
|
|
|
[ 0xc2 >> 1 ] = "tuner (analog/dvb)",
|
|
|
|
};
|
|
|
|
|
|
|
|
static void do_i2c_scan(char *name, struct i2c_client *c)
|
|
|
|
{
|
|
|
|
unsigned char buf;
|
|
|
|
int i,rc;
|
|
|
|
|
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;
|
|
|
|
rc = i2c_master_recv(c,&buf,0);
|
|
|
|
if (rc < 0)
|
|
|
|
continue;
|
|
|
|
printk("%s: i2c scan: found device @ 0x%x [%s]\n",
|
|
|
|
name, i << 1, i2c_devs[i] ? i2c_devs[i] : "???");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* init + register i2c algo-bit adapter */
|
|
|
|
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 */
|
|
|
|
if (i2c_udelay<5)
|
|
|
|
i2c_udelay=5;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
memcpy(&core->i2c_algo, &cx8800_i2c_algo_template,
|
|
|
|
sizeof(core->i2c_algo));
|
|
|
|
|
2007-08-16 01:41:57 +08:00
|
|
|
if (core->board.tuner_type != TUNER_ABSENT)
|
2005-04-17 06:20:36 +08:00
|
|
|
core->i2c_adap.class |= I2C_CLASS_TV_ANALOG;
|
2007-08-16 01:41:57 +08:00
|
|
|
if (core->board.mpeg & CX88_MPEG_DVB)
|
2005-04-17 06:20:36 +08:00
|
|
|
core->i2c_adap.class |= I2C_CLASS_TV_DIGITAL;
|
|
|
|
|
|
|
|
core->i2c_adap.dev.parent = &pci->dev;
|
|
|
|
strlcpy(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_adap.id = I2C_HW_B_CX2388x;
|
|
|
|
core->i2c_adap.client_register = attach_inform;
|
|
|
|
core->i2c_adap.client_unregister = detach_inform;
|
|
|
|
core->i2c_algo.udelay = i2c_udelay;
|
2005-11-09 13:37:43 +08:00
|
|
|
core->i2c_algo.data = core;
|
|
|
|
i2c_set_adapdata(&core->i2c_adap,core);
|
|
|
|
core->i2c_adap.algo_data = &core->i2c_algo;
|
|
|
|
core->i2c_client.adapter = &core->i2c_adap;
|
2007-07-02 05:37:51 +08:00
|
|
|
strlcpy(core->i2c_client.name, "cx88xx internal", I2C_NAME_SIZE);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
cx8800_bit_setscl(core,1);
|
|
|
|
cx8800_bit_setsda(core,1);
|
|
|
|
|
|
|
|
core->i2c_rc = i2c_bit_add_bus(&core->i2c_adap);
|
|
|
|
if (0 == core->i2c_rc) {
|
|
|
|
dprintk(1, "i2c register ok\n");
|
|
|
|
if (i2c_scan)
|
|
|
|
do_i2c_scan(core->name,&core->i2c_client);
|
|
|
|
} else
|
|
|
|
printk("%s: i2c register FAILED\n", core->name);
|
|
|
|
return core->i2c_rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(cx88_call_i2c_clients);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* End:
|
|
|
|
*/
|