i2c: internal setup function properly works
authorThomas Ingleby <thomas.c.ingleby@intel.com>
Wed, 21 May 2014 12:57:30 +0000 (13:57 +0100)
committerThomas Ingleby <thomas.c.ingleby@intel.com>
Wed, 21 May 2014 13:01:22 +0000 (14:01 +0100)
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
include/maa_internal.h
src/maa.c

index a3944ca..428132d 100644 (file)
@@ -46,7 +46,7 @@ unsigned int maa_setup_aio(int pin);
  *
  * @return unsigned int if using /dev/i2c-2 returned would be 2
  */
-unsigned int maa_setup_i2c();
+unsigned int maa_setup_i2c(int bus);
 
 /** Setup spi interface, sets up multiplexer on device.
  *
index 215687c..0170564 100644 (file)
--- a/src/maa.c
+++ b/src/maa.c
@@ -121,7 +121,7 @@ maa_setup_aio(int aio)
 }
 
 unsigned int
-maa_setup_i2c(int bus_s)
+maa_setup_i2c(int bus)
 {
     if (plat == NULL)
         return -3;
@@ -130,7 +130,10 @@ maa_setup_i2c(int bus_s)
         fprintf(stderr, "No i2c buses defined in platform");
         return -1;
     }
-    int bus = 0;
+    if (bus >= plat->i2c_bus_count) {
+        fprintf(stderr, "Above i2c bus count");
+        return -1;
+    }
 
     int pos = plat->i2c_bus[bus].sda;
     if (plat->pins[pos].i2c.mux_total > 0)