gen2: add basic galileo gen2 detection
authorBrendan Le Foll <brendan.le.foll@intel.com>
Mon, 16 Jun 2014 17:45:59 +0000 (18:45 +0100)
committerBrendan Le Foll <brendan.le.foll@intel.com>
Mon, 16 Jun 2014 17:46:31 +0000 (18:46 +0100)
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
api/maa/common.h
include/intel_galileo_gen2.h [new file with mode: 0644]
src/CMakeLists.txt
src/intel_galileo_gen2.c [new file with mode: 0644]
src/maa.c

index 19ba2d3..2897498 100644 (file)
@@ -34,6 +34,16 @@ extern "C" {
 #endif
 
 /**
+ * MAA supported platform types
+ */
+typedef enum {
+    MAA_INTEL_GALILEO_GEN1 = 0, /**< The Generation 1 Galileo platform (RevD) */
+    MAA_INTEL_GALILEO_GEN2 = 1, /**< The Generation 2 Galileo platform (RevG/H) */
+
+    MAA_UNKNOWN_PLATFORM = 99 /**< An unknown platform type, typically will load INTEL_GALILEO_GEN1 */
+} maa_platform_t;
+
+/**
  * MAA return codes
  */
 typedef enum {
diff --git a/include/intel_galileo_gen2.h b/include/intel_galileo_gen2.h
new file mode 100644 (file)
index 0000000..03cee51
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Author: Brendan Le Foll <brendan.le.foll@intel.com>
+ * Copyright (c) 2014 Intel Corporation.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#pragma once
+
+#define MAA_INTEL_GALILEO_GEN_2_PINCOUNT 25
+
+maa_board_t*
+maa_intel_galileo_gen2();
index 366e1ce..8736bda 100644 (file)
@@ -13,6 +13,7 @@ set (maa_LIB_SRCS
   ${PROJECT_SOURCE_DIR}/src/spi/spi.c
   ${PROJECT_SOURCE_DIR}/src/aio/aio.c
   ${PROJECT_SOURCE_DIR}/src/intel_galileo_rev_d.c
+  ${PROJECT_SOURCE_DIR}/src/intel_galileo_gen2.c
 # autogenerated version file
   ${CMAKE_CURRENT_BINARY_DIR}/version.c
 )
diff --git a/src/intel_galileo_gen2.c b/src/intel_galileo_gen2.c
new file mode 100644 (file)
index 0000000..7aa4a44
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Author: Brendan Le Foll <brendan.le.foll@intel.com>
+ * Copyright (c) 2014 Intel Corporation.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "common.h"
+#include "intel_galileo_gen2.h"
+
+maa_board_t*
+maa_intel_galileo_gen2()
+{
+    maa_board_t* b = (maa_board_t*) malloc(sizeof(maa_board_t));
+    if (b == NULL)
+        return NULL;
+
+    b->phy_pin_count = 20;
+    b->gpio_count = 14;
+    b->aio_count = 6;
+
+    b->pins = (maa_pininfo_t*) malloc(sizeof(maa_pininfo_t)*MAA_INTEL_GALILEO_GEN_2_PINCOUNT);
+
+    //BUS DEFINITIONS
+    b->i2c_bus_count = 1;
+    b->def_i2c_bus = 0;
+    b->i2c_bus[0].bus_id = 0;
+    b->i2c_bus[0].sda = 18;
+    b->i2c_bus[0].scl = 19;
+
+    b->spi_bus_count = 1;
+    b->def_spi_bus = 0;
+    b->spi_bus[0].bus_id = 1;
+    b->spi_bus[0].slave_s = 0;
+    b->spi_bus[0].cs = 10;
+    b->spi_bus[0].mosi = 11;
+    b->spi_bus[0].miso = 12;
+    b->spi_bus[0].sclk = 13;
+
+    return b;
+}
index 609bbd7..8c9a106 100644 (file)
--- a/src/maa.c
+++ b/src/maa.c
@@ -30,6 +30,7 @@
 
 #include "maa_internal.h"
 #include "intel_galileo_rev_d.h"
+#include "intel_galileo_gen2.h"
 #include "gpio.h"
 #include "version.h"
 
@@ -62,7 +63,33 @@ maa_init()
     Py_InitializeEx(0);
     PyEval_InitThreads();
 #endif
-    plat = maa_intel_galileo_rev_d();
+    maa_platform_t platform_type = MAA_UNKNOWN_PLATFORM;
+
+    // detect a galileo gen2 board
+    char *line = NULL;
+    // let getline allocate memory for *line
+    size_t len = 0;
+    FILE *fh = fopen("/sys/devices/virtual/dmi/id/board_name", "r");
+    if (fh != NULL) {
+        if (getline(&line, &len, fh) != -1) {
+            if (strncmp(line, "GalileoGen2", 10) == 0) {
+                platform_type = MAA_INTEL_GALILEO_GEN2;
+            } else {
+                platform_type = MAA_INTEL_GALILEO_GEN1;
+            }
+        }
+    }
+    free(line);
+    fclose(fh);
+
+    switch(platform_type) {
+        case MAA_INTEL_GALILEO_GEN2:
+            plat = maa_intel_galileo_gen2();
+            break;
+        default:
+            plat = maa_intel_galileo_rev_d();
+    }
+
     return MAA_SUCCESS;
 }