spi-pinmap: added spi checking functions.
authorThomas Ingleby <thomas.c.ingleby@intel.com>
Wed, 14 May 2014 15:06:57 +0000 (16:06 +0100)
committerBrendan Le Foll <brendan.le.foll@intel.com>
Fri, 16 May 2014 13:31:40 +0000 (14:31 +0100)
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
api/maa.h
src/maa.c

index fbd37c4..3bd5efc 100644 (file)
--- a/api/maa.h
+++ b/api/maa.h
@@ -205,6 +205,12 @@ unsigned int maa_check_aio(int pin);
  */
 unsigned int maa_check_i2c();
 
+/** Check spi interface, sets up multiplexer on device.
+ *
+ * @return unsigned int if using /dev/spi-1.0 returned would be 1.0
+ */
+double maa_check_spi();
+
 /** Check PWM
  *
  * Will check input is valid for pwm and will also setup required multiplexers.
index d1b199a..9ab9322 100644 (file)
--- a/src/maa.c
+++ b/src/maa.c
@@ -143,6 +143,36 @@ maa_check_i2c(int bus_s)
     return plat->i2c_bus[bus].bus_id;
 }
 
+double
+maa_check_spi(int bus_s)
+{
+    if (plat == NULL)
+        return -3;
+
+    if (plat->i2c_bus_count >! 0) {
+        fprintf(stderr, "No spi buses defined in platform");
+        return -1;
+    }
+    int bus = 0;
+
+    int pos = plat->spi_bus[0].sclk;
+    if (plat->pins[pos].spi.mux_total > 0)
+        if (maa_setup_mux_mapped(plat->pins[pos].spi) != MAA_SUCCESS)
+             return -2;
+
+    pos = plat->spi_bus[0].mosi;
+    if (plat->pins[pos].spi.mux_total > 0)
+        if (maa_setup_mux_mapped(plat->pins[pos].spi) != MAA_SUCCESS)
+             return -2;
+
+    pos = plat->spi_bus[0].miso;
+    if (plat->pins[pos].spi.mux_total > 0)
+        if (maa_setup_mux_mapped(plat->pins[pos].spi) != MAA_SUCCESS)
+             return -2;
+
+    return plat->spi_bus[bus].bus_id;
+}
+
 maa_pin_t*
 maa_check_pwm(int pin)
 {