From 27624289ecb4e4d7f7cecb923c283234b8086dd2 Mon Sep 17 00:00:00 2001 From: Brendan Le Foll Date: Mon, 16 Jun 2014 18:45:59 +0100 Subject: [PATCH] gen2: add basic galileo gen2 detection Signed-off-by: Brendan Le Foll --- api/maa/common.h | 10 ++++++ include/intel_galileo_gen2.h | 30 ++++++++++++++++++ src/CMakeLists.txt | 1 + src/intel_galileo_gen2.c | 61 ++++++++++++++++++++++++++++++++++++ src/maa.c | 29 ++++++++++++++++- 5 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 include/intel_galileo_gen2.h create mode 100644 src/intel_galileo_gen2.c diff --git a/api/maa/common.h b/api/maa/common.h index 19ba2d3..2897498 100644 --- a/api/maa/common.h +++ b/api/maa/common.h @@ -33,6 +33,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 */ diff --git a/include/intel_galileo_gen2.h b/include/intel_galileo_gen2.h new file mode 100644 index 0000000..03cee51 --- /dev/null +++ b/include/intel_galileo_gen2.h @@ -0,0 +1,30 @@ +/* + * Author: Brendan Le Foll + * 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(); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 366e1ce..8736bda 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 index 0000000..7aa4a44 --- /dev/null +++ b/src/intel_galileo_gen2.c @@ -0,0 +1,61 @@ +/* + * Author: Brendan Le Foll + * 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 +#include + +#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; +} diff --git a/src/maa.c b/src/maa.c index 609bbd7..8c9a106 100644 --- 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; }