summaryrefslogtreecommitdiff
path: root/linux/drivers/media/video/usbvision/usbvision-i2c.c
diff options
context:
space:
mode:
authorThierry MERLE <thierry.merle@free.fr>2007-04-14 21:23:49 +0200
committerThierry MERLE <thierry.merle@free.fr>2007-04-14 21:23:49 +0200
commit22e817a32eb6749a62cb77aa429be23a76875650 (patch)
tree369a9cf258537251f4354843e16f51af2c8da50d /linux/drivers/media/video/usbvision/usbvision-i2c.c
parentea4dd59f09799234a2b807e318e83059b24863a1 (diff)
downloadmediapointer-dvb-s2-22e817a32eb6749a62cb77aa429be23a76875650.tar.gz
mediapointer-dvb-s2-22e817a32eb6749a62cb77aa429be23a76875650.tar.bz2
usbvision: i2c function cleanups
From: Thierry MERLE <thierry.merle@free.fr> usbvision-i2c function renamings, code cleanup Signed-off-by: Thierry MERLE <thierry.merle@free.fr>
Diffstat (limited to 'linux/drivers/media/video/usbvision/usbvision-i2c.c')
-rw-r--r--linux/drivers/media/video/usbvision/usbvision-i2c.c143
1 files changed, 57 insertions, 86 deletions
diff --git a/linux/drivers/media/video/usbvision/usbvision-i2c.c b/linux/drivers/media/video/usbvision/usbvision-i2c.c
index e942b1bf2..507f1c1c4 100644
--- a/linux/drivers/media/video/usbvision/usbvision-i2c.c
+++ b/linux/drivers/media/video/usbvision/usbvision-i2c.c
@@ -1,8 +1,8 @@
/*
- * I2C_ALGO_USB.C
+ * usbvision_i2c.c
* i2c algorithm for USB-I2C Bridges
*
- * Copyright (c) 1999-2005 Joerg Heckenbach <joerg@heckenbach-aw.de>
+ * Copyright (c) 1999-2007 Joerg Heckenbach <joerg@heckenbach-aw.de>
* Dwaine Garden <dwainegarden@rogers.com>
*
* This module is part of usbvision driver project.
@@ -42,7 +42,6 @@
#include "usbvision.h"
#define DBG_I2C 1<<0
-#define DBG_ALGO 1<<1
static int i2c_debug = 0;
@@ -52,22 +51,22 @@ MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
#define PDEBUG(level, fmt, args...) \
if (i2c_debug & (level)) info("[%s:%d] " fmt, __PRETTY_FUNCTION__, __LINE__ , ## args)
-static int usbvision_i2c_write(void *data, unsigned char addr, char *buf,
+static int usbvision_i2c_write(struct usb_usbvision *usbvision, unsigned char addr, char *buf,
short len);
-static int usbvision_i2c_read(void *data, unsigned char addr, char *buf,
+static int usbvision_i2c_read(struct usb_usbvision *usbvision, unsigned char addr, char *buf,
short len);
static inline int try_write_address(struct i2c_adapter *i2c_adap,
unsigned char addr, int retries)
{
- void *data;
+ struct usb_usbvision *usbvision;
int i, ret = -1;
char buf[4];
- data = i2c_get_adapdata(i2c_adap);
+ usbvision = i2c_get_adapdata(i2c_adap);
buf[0] = 0x00;
for (i = 0; i <= retries; i++) {
- ret = (usbvision_i2c_write(data, addr, buf, 1));
+ ret = (usbvision_i2c_write(usbvision, addr, buf, 1));
if (ret == 1)
break; /* success! */
udelay(5);
@@ -76,8 +75,8 @@ static inline int try_write_address(struct i2c_adapter *i2c_adap,
udelay(10);
}
if (i) {
- PDEBUG(DBG_ALGO,"Needed %d retries for address %#2x", i, addr);
- PDEBUG(DBG_ALGO,"Maybe there's no device at this address");
+ PDEBUG(DBG_I2C,"Needed %d retries for address %#2x", i, addr);
+ PDEBUG(DBG_I2C,"Maybe there's no device at this address");
}
return ret;
}
@@ -85,13 +84,13 @@ static inline int try_write_address(struct i2c_adapter *i2c_adap,
static inline int try_read_address(struct i2c_adapter *i2c_adap,
unsigned char addr, int retries)
{
- void *data;
+ struct usb_usbvision *usbvision;
int i, ret = -1;
char buf[4];
- data = i2c_get_adapdata(i2c_adap);
+ usbvision = i2c_get_adapdata(i2c_adap);
for (i = 0; i <= retries; i++) {
- ret = (usbvision_i2c_read(data, addr, buf, 1));
+ ret = (usbvision_i2c_read(usbvision, addr, buf, 1));
if (ret == 1)
break; /* success! */
udelay(5);
@@ -100,8 +99,8 @@ static inline int try_read_address(struct i2c_adapter *i2c_adap,
udelay(10);
}
if (i) {
- PDEBUG(DBG_ALGO,"Needed %d retries for address %#2x", i, addr);
- PDEBUG(DBG_ALGO,"Maybe there's no device at this address");
+ PDEBUG(DBG_I2C,"Needed %d retries for address %#2x", i, addr);
+ PDEBUG(DBG_I2C,"Maybe there's no device at this address");
}
return ret;
}
@@ -155,32 +154,31 @@ static inline int usb_find_address(struct i2c_adapter *i2c_adap,
}
static int
-usb_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num)
+usbvision_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num)
{
struct i2c_msg *pmsg;
- void *data;
+ struct usb_usbvision *usbvision;
int i, ret;
unsigned char addr;
- data = i2c_get_adapdata(i2c_adap);
-
+ usbvision = i2c_get_adapdata(i2c_adap);
for (i = 0; i < num; i++) {
pmsg = &msgs[i];
ret = usb_find_address(i2c_adap, pmsg, i2c_adap->retries, &addr);
if (ret != 0) {
- PDEBUG(DBG_ALGO,"got NAK from device, message #%d", i);
+ PDEBUG(DBG_I2C,"got NAK from device, message #%d", i);
return (ret < 0) ? ret : -EREMOTEIO;
}
if (pmsg->flags & I2C_M_RD) {
/* read bytes into buffer */
- ret = (usbvision_i2c_read(data, addr, pmsg->buf, pmsg->len));
+ ret = (usbvision_i2c_read(usbvision, addr, pmsg->buf, pmsg->len));
if (ret < pmsg->len) {
return (ret < 0) ? ret : -EREMOTEIO;
}
} else {
/* write bytes from buffer */
- ret = (usbvision_i2c_write(data, addr, pmsg->buf, pmsg->len));
+ ret = (usbvision_i2c_write(usbvision, addr, pmsg->buf, pmsg->len));
if (ret < pmsg->len) {
return (ret < 0) ? ret : -EREMOTEIO;
}
@@ -194,7 +192,7 @@ static int algo_control(struct i2c_adapter *adapter, unsigned int cmd, unsigned
return 0;
}
-static u32 usb_func(struct i2c_adapter *adap)
+static u32 functionality(struct i2c_adapter *adap)
{
return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING;
}
@@ -213,7 +211,7 @@ static void dec_use(struct i2c_adapter *adap)
/* -----exported algorithm data: ------------------------------------- */
-static struct i2c_algorithm i2c_usb_algo = {
+static struct i2c_algorithm usbvision_algo = {
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)) && (LINUX_VERSION_CODE > KERNEL_VERSION(2,4,30))
.owner = THIS_MODULE,
#endif
@@ -221,75 +219,43 @@ static struct i2c_algorithm i2c_usb_algo = {
.name = "USB algorithm",
.id = I2C_ALGO_BIT, /* FIXME */
#endif
- .master_xfer = usb_xfer,
+ .master_xfer = usbvision_i2c_xfer,
.smbus_xfer = NULL,
.algo_control = algo_control,
- .functionality = usb_func,
+ .functionality = functionality,
};
-/*
- * registering functions to load algorithms at runtime
- */
-static int usbvision_i2c_usb_add_bus(struct i2c_adapter *adap)
-{
- PDEBUG(DBG_I2C, "I2C debugging is enabled [i2c]");
- PDEBUG(DBG_ALGO, "ALGO debugging is enabled [i2c]");
-
- /* register new adapter to i2c module... */
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
- adap->id |= i2c_usb_algo.id;
-#endif
- adap->algo = &i2c_usb_algo;
-
- adap->timeout = 100; /* default values, should */
- adap->retries = 3; /* be replaced by defines */
-
- i2c_add_adapter(adap);
-
- PDEBUG(DBG_ALGO,"i2c bus for %s registered", adap->name);
-
- return 0;
-}
-
-
-int usbvision_i2c_usb_del_bus(struct i2c_adapter *adap)
-{
-
- i2c_del_adapter(adap);
-
- PDEBUG(DBG_ALGO,"i2c bus for %s unregistered", adap->name);
-
- return 0;
-}
-
-
/* ----------------------------------------------------------------------- */
/* usbvision specific I2C functions */
/* ----------------------------------------------------------------------- */
static struct i2c_adapter i2c_adap_template;
static struct i2c_client i2c_client_template;
-int usbvision_init_i2c(struct usb_usbvision *usbvision)
+int usbvision_i2c_register(struct usb_usbvision *usbvision)
{
- memcpy(&usbvision->i2c_adap, &i2c_adap_template,
- sizeof(struct i2c_adapter));
- memcpy(&usbvision->i2c_client, &i2c_client_template,
- sizeof(struct i2c_client));
+ int ret;
- sprintf(usbvision->i2c_adap.name + strlen(usbvision->i2c_adap.name),
- " #%d", usbvision->vdev->minor & 0x1f);
- PDEBUG(DBG_I2C,"Adaptername: %s", usbvision->i2c_adap.name);
+ usbvision->i2c_adap = i2c_adap_template;
usbvision->i2c_adap.dev.parent = &usbvision->dev->dev;
- i2c_set_adapdata(&usbvision->i2c_adap, usbvision);
- i2c_set_clientdata(&usbvision->i2c_client, usbvision);
+ PDEBUG(DBG_I2C, "I2C debugging is enabled [i2c]");
+
+ sprintf(usbvision->i2c_adap.name + strlen(usbvision->i2c_adap.name),
+ " #%d", usbvision->vdev->minor & 0x1f);
+ PDEBUG(DBG_I2C,"I2C Registering adaptername: %s", usbvision->i2c_adap.name);
+ i2c_set_adapdata(&usbvision->i2c_adap,usbvision);
+ if ((ret = i2c_add_adapter(&usbvision->i2c_adap)) < 0) {
+ PDEBUG(DBG_I2C,"could not add I2C adapter %s", usbvision->i2c_adap.name);
+ return ret;
+ }
+ /* TODO: use i2c_client for eeprom detection as an example... */
+ usbvision->i2c_client = i2c_client_template;
usbvision->i2c_client.adapter = &usbvision->i2c_adap;
if (usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_IIC_LRNACK) < 0) {
- printk(KERN_ERR "usbvision_init_i2c: can't write reg\n");
+ printk(KERN_ERR "usbvision_i2c_register: can't write reg\n");
return -EBUSY;
}
@@ -308,7 +274,17 @@ int usbvision_init_i2c(struct usb_usbvision *usbvision)
}
#endif
- return usbvision_i2c_usb_add_bus(&usbvision->i2c_adap);
+ return 0;
+}
+
+int usbvision_i2c_unregister(struct usb_usbvision *usbvision)
+{
+
+ i2c_del_adapter(&(usbvision->i2c_adap));
+
+ PDEBUG(DBG_I2C,"i2c bus for %s unregistered", usbvision->i2c_adap.name);
+
+ return 0;
}
void call_i2c_clients(struct usb_usbvision *usbvision, unsigned int cmd,
@@ -321,8 +297,7 @@ static int attach_inform(struct i2c_client *client)
{
struct usb_usbvision *usbvision;
- usbvision = (struct usb_usbvision *)i2c_get_adapdata(client->adapter);
-
+ usbvision = i2c_get_adapdata(client->adapter);
switch (client->addr << 1) {
case 0x43:
case 0x4b:
@@ -373,11 +348,7 @@ static int detach_inform(struct i2c_client *client)
{
struct usb_usbvision *usbvision;
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
- usbvision = (struct usb_usbvision *)client->adapter->data;
-#else
- usbvision = (struct usb_usbvision *)i2c_get_adapdata(client->adapter);
-#endif
+ usbvision = i2c_get_adapdata(client->adapter);
PDEBUG(DBG_I2C,"usbvision[%d] detaches %s", usbvision->nr, client->name);
return 0;
@@ -508,7 +479,7 @@ static int usbvision_i2c_write_max4(struct usb_usbvision *usbvision,
return len;
}
-static int usbvision_i2c_write(void *data, unsigned char addr, char *buf,
+static int usbvision_i2c_write(struct usb_usbvision *usbvision, unsigned char addr, char *buf,
short len)
{
char *bufPtr = buf;
@@ -516,7 +487,6 @@ static int usbvision_i2c_write(void *data, unsigned char addr, char *buf,
int wrcount = 0;
int count;
int maxLen = 4;
- struct usb_usbvision *usbvision = (struct usb_usbvision *) data;
while (len > 0) {
count = (len > maxLen) ? maxLen : len;
@@ -531,14 +501,13 @@ static int usbvision_i2c_write(void *data, unsigned char addr, char *buf,
return wrcount;
}
-static int usbvision_i2c_read(void *data, unsigned char addr, char *buf,
+static int usbvision_i2c_read(struct usb_usbvision *usbvision, unsigned char addr, char *buf,
short len)
{
char temp[4];
int retval, i;
int rdcount = 0;
int count;
- struct usb_usbvision *usbvision = (struct usb_usbvision *) data;
while (len > 0) {
count = (len > 3) ? 4 : len;
@@ -563,6 +532,8 @@ static struct i2c_adapter i2c_adap_template = {
#endif
.name = "usbvision",
.id = I2C_HW_B_BT848, /* FIXME */
+ .algo = &usbvision_algo,
+ .algo_data = NULL,
.client_register = attach_inform,
.client_unregister = detach_inform,
#ifdef I2C_ADAP_CLASS_TV_ANALOG