From c0dfb712375b9817e311e35decc2b77ba7e7d315 Mon Sep 17 00:00:00 2001 From: Srinivas Kandagatla Date: Fri, 11 Dec 2015 16:28:35 +0000 Subject: [PATCH] 96boards: add support to 96boards (https://www.96boards.org/) This patch adds support to 96boards. 96boards is an open platform specification. This spec strandardizes the pins on the external connectors like Low speed and High speed. Given these pins are standard across multiple boards, I think adding a generic 96boards made sense to me. The idea behind adding this generic board file is to make mraa work on most of the 96boards with minimal changes to board support in libmraa. This patch adds support to the LS expansion connector which has got 12 gpio pins + 2 i2c + 1 spi and 2 uarts. For now I have added Dragaon board DB401c support as part of this patch and is tested. More info about board @ https://www.96boards.org/products/ce/dragonboard410c/ Long term plan is to get all this configuration from the /sys and populate the board specifics dynamically, which is bit easy with 96boards specs in-place. Signed-off-by: Srinivas Kandagatla Signed-off-by: Brendan Le Foll --- api/mraa/types.h | 1 + include/arm/96boards.h | 47 +++++++++++++++++++ src/CMakeLists.txt | 1 + src/arm/96boards.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++++ src/arm/arm.c | 13 ++++++ 5 files changed, 182 insertions(+) create mode 100644 include/arm/96boards.h create mode 100644 src/arm/96boards.c diff --git a/api/mraa/types.h b/api/mraa/types.h index 5d42eac..12ebce2 100644 --- a/api/mraa/types.h +++ b/api/mraa/types.h @@ -46,6 +46,7 @@ typedef enum { MRAA_BEAGLEBONE = 6, /**< The different BeagleBone Black Modes B/C */ MRAA_BANANA = 7, /**< Allwinner A20 based Banana Pi and Banana Pro */ MRAA_INTEL_NUC5 = 8, /**< The Intel 5th generations Broadwell NUCs */ + MRAA_96BOARDS = 9, /**< Linaro 96boards */ // USB platform extenders start at 256 MRAA_FTDI_FT4222 = 256, /**< FTDI FT4222 USB to i2c bridge */ diff --git a/include/arm/96boards.h b/include/arm/96boards.h new file mode 100644 index 0000000..6c0dae5 --- /dev/null +++ b/include/arm/96boards.h @@ -0,0 +1,47 @@ +/* + * Author: Srinivas Kandagatla + * Copyright (c) 2015 Linaro Limited. + * Copyright (c) 2014 Intel Corporation. + * + * Copied from include/arm/banana.h + * + * 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 + +#ifdef __cplusplus +extern "C" { +#endif + +#include "mraa_internal.h" + +#define MRAA_96BOARDS_LS_GPIO_COUNT 12 +#define MRAA_96BOARDS_LS_I2C_COUNT 2 +#define MRAA_96BOARDS_LS_SPI_COUNT 1 +#define MRAA_96BOARDS_LS_UART_COUNT 2 + +#define DB410C_PINCOUNT 122 + +mraa_board_t* mraa_96boards(); + +#ifdef __cplusplus +} +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 177bce5..e3c3e9c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,6 +54,7 @@ endif () set (mraa_LIB_ARM_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/arm/arm.c + ${PROJECT_SOURCE_DIR}/src/arm/96boards.c ${PROJECT_SOURCE_DIR}/src/arm/raspberry_pi.c ${PROJECT_SOURCE_DIR}/src/arm/beaglebone.c ${PROJECT_SOURCE_DIR}/src/arm/banana.c diff --git a/src/arm/96boards.c b/src/arm/96boards.c new file mode 100644 index 0000000..9844042 --- /dev/null +++ b/src/arm/96boards.c @@ -0,0 +1,120 @@ +/* + * Author: Srinivas Kandagatla + * Copyright (c) 2014 Intel Corporation. + * Copyright (c) 2015 Linaro Limited. + * + * Copied from src/arm/banana.c + * + * 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 +#include + +#include "common.h" +#include "arm/96boards.h" + +#define DT_BASE "/sys/firmware/devicetree/base" + +#define PLATFORM_NAME_DB410C "DB410C" + +int db410c_ls_gpio_pins[MRAA_96BOARDS_LS_GPIO_COUNT] = { + 36, 12, 13, 69, 115, 4, 24, 25, 35, 34, 28, 33, +}; + +const char* db410c_serialdev[MRAA_96BOARDS_LS_UART_COUNT] = { "/dev/ttyMSM0", "/dev/ttyMSM1"}; + +mraa_board_t* mraa_96boards() +{ + int i, pin; + int *ls_gpio_pins; + char ch; + char name[MRAA_PIN_NAME_SIZE]; + + mraa_board_t* b = (mraa_board_t*) malloc(sizeof(mraa_board_t)); + if (b == NULL) { + return NULL; + } + + // pin mux for buses are setup by default by kernel so tell mraa to ignore them + b->no_bus_mux = 1; + + if (mraa_file_exist(DT_BASE "/model")) { + // We are on a modern kernel, great!!!! + if (mraa_file_contains(DT_BASE "/model", "Qualcomm Technologies, Inc. APQ 8016 SBC")) { + b->platform_name = PLATFORM_NAME_DB410C; + b->phy_pin_count = DB410C_PINCOUNT; + ls_gpio_pins = db410c_ls_gpio_pins; + b->uart_dev[0].device_path = db410c_serialdev[0]; + b->uart_dev[1].device_path = db410c_serialdev[1]; + } + } + + //UART + b->uart_dev_count = MRAA_96BOARDS_LS_UART_COUNT; + b->def_uart_dev = 0; + + //I2C + b->i2c_bus_count = MRAA_96BOARDS_LS_I2C_COUNT; + b->def_i2c_bus = 0; + b->i2c_bus[0].bus_id = 0; + b->i2c_bus[1].bus_id= 1; + + //SPI + b->spi_bus_count = MRAA_96BOARDS_LS_SPI_COUNT; + b->spi_bus[0].bus_id = 0; + b->def_spi_bus = 0; + + b->adv_func = (mraa_adv_func_t*) calloc(1, sizeof(mraa_adv_func_t)); + if (b->adv_func == NULL) { + free(b); + return NULL; + } + + b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t) * b->phy_pin_count); + if (b->pins == NULL) { + free(b->adv_func); + free(b); + return NULL; + } + + // gpio lable starts from GPIO-A to GPIO-F + ch = 'A'; + for (i = 0; i < MRAA_96BOARDS_LS_GPIO_COUNT; i++) + { + pin = ls_gpio_pins[i]; + sprintf(name, "GPIO-%c", ch++); + strncpy(b->pins[pin].name, name, MRAA_PIN_NAME_SIZE); + b->pins[pin].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }; + b->pins[pin].gpio.pinmap = pin; + b->pins[pin].gpio.mux_total = 0; + } + + b->gpio_count = MRAA_96BOARDS_LS_GPIO_COUNT; + + b->aio_count = 0; + b->adc_raw = 0; + b->adc_supported = 0; + b->gpio_count = 0; + + return b; +} diff --git a/src/arm/arm.c b/src/arm/arm.c index e74e1cc..4ed4a9b 100644 --- a/src/arm/arm.c +++ b/src/arm/arm.c @@ -30,6 +30,8 @@ #include "arm/raspberry_pi.h" #include "arm/beaglebone.h" #include "arm/banana.h" +#include "arm/96boards.h" + mraa_platform_t mraa_arm_platform() @@ -38,6 +40,7 @@ mraa_arm_platform() size_t len = 100; char* line = malloc(len); FILE* fh = fopen("/proc/cpuinfo", "r"); + if (fh != NULL) { while (getline(&line, &len, fh) != -1) { if (strncmp(line, "Hardware", 8) == 0) { @@ -63,11 +66,18 @@ mraa_arm_platform() } } } + } fclose(fh); } free(line); + /* Get compatible string from Device tree for boards that dont have enough info in /proc/cpuinfo */ + if (platform_type == MRAA_UNKNOWN_PLATFORM) { + if (mraa_file_contains("/sys/firmware/devicetree/base/compatible", "qcom,apq8016-sbc")) + platform_type = MRAA_96BOARDS; + } + switch (platform_type) { case MRAA_RASPBERRY_PI: plat = mraa_raspberry_pi(); @@ -78,6 +88,9 @@ mraa_arm_platform() case MRAA_BANANA: plat = mraa_banana(); break; + case MRAA_96BOARDS: + plat = mraa_96boards(); + break; default: plat = NULL; syslog(LOG_ERR, "Unknown Platform, currently not supported by MRAA"); -- 2.7.4