aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlfcorreia <lfcorreia@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2006-07-29 21:04:43 +0000
committerlfcorreia <lfcorreia@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2006-07-29 21:04:43 +0000
commit0c8256185a9f46c725e8574b05de0165fc1e657a (patch)
tree1985b05ded7220a9722cdc2e5e4455ee667bcea2
parentda69730d294e0afb01e3f0cda58c0586dfc4c735 (diff)
downloadlcd4linux-0c8256185a9f46c725e8574b05de0165fc1e657a.tar.gz
[lcd4linux @ 2006-07-29 21:04:43 by lfcorreia]
Better error handling, add proper I2C SLAVE device detection (not 100% finished) git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@676 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
-rw-r--r--drv_generic_i2c.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/drv_generic_i2c.c b/drv_generic_i2c.c
index 5f0851f..343ea80 100644
--- a/drv_generic_i2c.c
+++ b/drv_generic_i2c.c
@@ -1,4 +1,4 @@
-/* $Id: drv_generic_i2c.c,v 1.5 2005/06/01 12:50:25 reinelt Exp $
+/* $Id: drv_generic_i2c.c,v 1.6 2006/07/29 21:04:43 lfcorreia Exp $
*
* generic driver helper for i2c displays
*
@@ -23,6 +23,9 @@
*
*
* $Log: drv_generic_i2c.c,v $
+ * Revision 1.6 2006/07/29 21:04:43 lfcorreia
+ * Better error handling, add proper I2C SLAVE device detection (not 100% finished)
+ *
* Revision 1.5 2005/06/01 12:50:25 reinelt
* ifdef'ed unused function to avoid compiler warning
*
@@ -125,25 +128,29 @@ int drv_generic_i2c_open(const char *section, const char *driver)
device = cfg_get(Section, "Device", NULL);
dev = atoi(device);
info("%s: initializing I2C bus %s", Driver, bus);
- info("device %d", dev);
if ((i2c_device = open(bus, O_WRONLY)) < 0) {
error("%s: I2C bus %s open failed !\n", Driver, bus);
- return -1;
+ goto exit_error;
}
- info("%s: initializing I2C slave device 0x%x", Driver, dev);
+ info("%s: selecting slave device 0x%x", Driver, dev);
if (ioctl(i2c_device, I2C_SLAVE, dev) < 0) {
- error("%s: error initializing device 0x%x\n", Driver, dev);
- close(i2c_device);
- return -1;
+ error("%s: error selecting slave device 0x%x\n", Driver, dev);
+ goto exit_error;
}
- return 0;
-}
+ info("%s: initializing I2C slave device 0x%x", Driver, dev);
+ if (i2c_smbus_write_quick(i2c_device, I2C_SMBUS_WRITE) < 0 ){
+ error("%s: error initializing device 0x%x\n", Driver, dev);
+ close(i2c_device);
+ }
-int drv_generic_i2c_close(void)
-{
- close(i2c_device);
return 0;
+
+ exit_error:
+ free(bus);
+ free(device);
+ close(i2c_device);
+ return -1;
}