2014-11-13 13:55:58 -08:00
|
|
|
/*
|
|
|
|
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
2015-09-15 15:35:26 +01:00
|
|
|
* Evan Steele <evan.steele@intel.com>
|
2014-11-13 13:55:58 -08:00
|
|
|
* 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>
|
2015-01-08 16:22:49 -08:00
|
|
|
#include <sys/utsname.h>
|
2015-01-20 17:14:51 +00:00
|
|
|
#include <ctype.h>
|
2014-11-13 13:55:58 -08:00
|
|
|
|
|
|
|
|
#include "common.h"
|
2015-09-15 15:35:26 +01:00
|
|
|
#include "x86/intel_minnow_byt_compatible.h"
|
2014-11-13 13:55:58 -08:00
|
|
|
|
2014-11-26 15:15:55 +00:00
|
|
|
#define PLATFORM_NAME "MinnowBoard MAX"
|
2014-11-13 13:55:58 -08:00
|
|
|
#define I2C_BUS_DEFAULT 7
|
2015-07-06 13:41:39 +01:00
|
|
|
#define MAX_LENGTH 8
|
2015-07-10 17:52:50 +01:00
|
|
|
#define I2CNAME "designware"
|
2014-11-13 13:55:58 -08:00
|
|
|
|
2015-01-09 12:05:34 +00:00
|
|
|
int arch_nr_gpios_adjust = 0x100;
|
|
|
|
|
|
2014-11-20 17:13:58 -08:00
|
|
|
mraa_result_t
|
2015-03-23 14:39:12 +00:00
|
|
|
mraa_set_pininfo(mraa_board_t* board, int mraa_index, char* name, mraa_pincapabilities_t caps, int sysfs_pin)
|
2014-11-13 13:55:58 -08:00
|
|
|
{
|
|
|
|
|
if (mraa_index < board->phy_pin_count) {
|
2015-01-09 12:05:34 +00:00
|
|
|
// adjust mraa_index for ARCH_NR_GPIOS value
|
2015-01-09 12:46:09 +00:00
|
|
|
mraa_pininfo_t* pin_info = &board->pins[mraa_index];
|
2015-07-06 13:41:39 +01:00
|
|
|
strncpy(pin_info->name, name, MAX_LENGTH);
|
2014-11-13 13:55:58 -08:00
|
|
|
pin_info->capabilites = caps;
|
2015-01-27 14:11:59 +00:00
|
|
|
if (caps.gpio) {
|
2015-01-09 12:46:09 +00:00
|
|
|
pin_info->gpio.pinmap = sysfs_pin | arch_nr_gpios_adjust;
|
2015-01-27 14:11:59 +00:00
|
|
|
pin_info->gpio.mux_total = 0;
|
|
|
|
|
}
|
2014-11-13 13:55:58 -08:00
|
|
|
if (caps.i2c) {
|
|
|
|
|
pin_info->i2c.pinmap = 1;
|
|
|
|
|
pin_info->i2c.mux_total = 0;
|
|
|
|
|
}
|
|
|
|
|
if (caps.pwm) {
|
|
|
|
|
int controller = 0;
|
|
|
|
|
if (strncmp(name, "PWM", 3) == 0 && strlen(name) > 3 && isdigit(name[3]))
|
|
|
|
|
controller = name[3] - '0';
|
|
|
|
|
pin_info->pwm.parent_id = controller;
|
|
|
|
|
pin_info->pwm.pinmap = 0;
|
|
|
|
|
pin_info->pwm.mux_total = 0;
|
|
|
|
|
}
|
2015-03-13 16:29:33 +00:00
|
|
|
if (caps.spi) {
|
|
|
|
|
pin_info->spi.mux_total = 0;
|
|
|
|
|
}
|
2014-11-13 13:55:58 -08:00
|
|
|
return MRAA_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
return MRAA_ERROR_INVALID_RESOURCE;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-20 17:13:58 -08:00
|
|
|
mraa_result_t
|
2015-03-23 14:39:12 +00:00
|
|
|
mraa_get_pin_index(mraa_board_t* board, char* name, int* pin_index)
|
|
|
|
|
{
|
2014-11-13 13:55:58 -08:00
|
|
|
int i;
|
|
|
|
|
for (i = 0; i < board->phy_pin_count; ++i) {
|
2015-07-06 13:41:39 +01:00
|
|
|
if (strncmp(name, board->pins[i].name, MAX_LENGTH) == 0) {
|
2014-11-13 13:55:58 -08:00
|
|
|
*pin_index = i;
|
|
|
|
|
return MRAA_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return MRAA_ERROR_INVALID_RESOURCE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mraa_board_t*
|
2016-01-20 15:58:06 +00:00
|
|
|
mraa_intel_minnowboard_byt_compatible(mraa_boolean_t turbot)
|
2014-11-13 13:55:58 -08:00
|
|
|
{
|
2015-07-02 17:56:24 -07:00
|
|
|
mraa_board_t* b = (mraa_board_t*) calloc(1, sizeof(mraa_board_t));
|
2015-01-08 16:22:49 -08:00
|
|
|
|
|
|
|
|
struct utsname running_uname;
|
|
|
|
|
int uname_major, uname_minor, max_pins[27];
|
|
|
|
|
|
2014-12-08 11:33:15 +00:00
|
|
|
if (b == NULL) {
|
2014-11-13 13:55:58 -08:00
|
|
|
return NULL;
|
2014-12-08 11:33:15 +00:00
|
|
|
}
|
2014-11-13 13:55:58 -08:00
|
|
|
|
2015-01-21 15:35:54 +00:00
|
|
|
b->platform_name = PLATFORM_NAME;
|
2016-01-20 15:58:06 +00:00
|
|
|
if (turbot) {
|
|
|
|
|
b->platform_version = "Turbot";
|
|
|
|
|
} else {
|
|
|
|
|
b->platform_version = "Ax";
|
|
|
|
|
}
|
2014-11-13 13:55:58 -08:00
|
|
|
b->phy_pin_count = MRAA_INTEL_MINNOW_MAX_PINCOUNT;
|
2015-01-09 12:04:37 +00:00
|
|
|
b->gpio_count = MRAA_INTEL_MINNOW_MAX_PINCOUNT;
|
2014-11-13 13:55:58 -08:00
|
|
|
|
mraa: Prefer calloc over malloc
Switch to using calloc on all calls to malloc where the memory isn't
initialized. For things like the mraa_board_t, not allocating all to zero
causes issues such as with the sub_platform member, where if that's not zero
mraa_get_platform_type will try to dereference a random memory location for the
sub_platform->platform_name, which can result in segmentation faults and other
issues.
Note that in some places where immediately after the malloc call is a copy
operation, there is no need for calloc, as all the memory gets overwritten
anyways, but in cases where there may or may not be memory written to (such as
in mraa_file_contains, with reading from a file), even though in most cases the
memory is overwritten, it could be the case that the read operation does
nothing, but the memory still has non-zero values, by virtue of the fact it
wasn't overwritten.
Signed-off-by: Ian Johnson <ijohnson@wolfram.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2016-01-17 09:39:45 -06:00
|
|
|
b->pins = (mraa_pininfo_t*) calloc(MRAA_INTEL_MINNOW_MAX_PINCOUNT, sizeof(mraa_pininfo_t));
|
2014-12-08 11:33:15 +00:00
|
|
|
if (b->pins == NULL) {
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2015-01-08 16:22:49 -08:00
|
|
|
|
2015-09-03 15:28:36 +01:00
|
|
|
b->adv_func = (mraa_adv_func_t*) calloc(1, sizeof(mraa_adv_func_t));
|
|
|
|
|
if (b->adv_func == NULL) {
|
|
|
|
|
free(b->pins);
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-08 16:22:49 -08:00
|
|
|
if (uname(&running_uname) != 0) {
|
2015-09-03 15:28:36 +01:00
|
|
|
free(b->pins);
|
|
|
|
|
free(b->adv_func);
|
2015-01-08 16:22:49 -08:00
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sscanf(running_uname.release, "%d.%d", &uname_major, &uname_minor);
|
|
|
|
|
|
|
|
|
|
/* if we are on Linux 3.17 or lower they use a 256 max and number the GPIOs down
|
|
|
|
|
* if we are on 3.18 or higher (ea584595fc85e65796335033dfca25ed655cd0ed) (for now)
|
|
|
|
|
* they start at 512 and number down, at some point this is going to change again when
|
|
|
|
|
* GPIO moves to a radix.
|
|
|
|
|
*/
|
2015-03-23 14:39:12 +00:00
|
|
|
if (uname_major <= 3 && uname_minor <= 17) {
|
2015-01-09 12:05:34 +00:00
|
|
|
arch_nr_gpios_adjust = 0;
|
2015-01-08 16:22:49 -08:00
|
|
|
}
|
|
|
|
|
|
2015-03-23 14:39:12 +00:00
|
|
|
mraa_set_pininfo(b, 0, "INVALID", (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 }, -1);
|
|
|
|
|
mraa_set_pininfo(b, 1, "GND", (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 }, -1);
|
|
|
|
|
mraa_set_pininfo(b, 2, "GND", (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 }, -1);
|
|
|
|
|
mraa_set_pininfo(b, 3, "5v", (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 }, -1);
|
|
|
|
|
mraa_set_pininfo(b, 4, "3.3v", (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 }, -1);
|
|
|
|
|
mraa_set_pininfo(b, 5, "SPI_CS", (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 }, 220);
|
|
|
|
|
mraa_set_pininfo(b, 6, "UART1TX", (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 1 }, 225);
|
|
|
|
|
mraa_set_pininfo(b, 7, "SPIMISO", (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 }, 221);
|
|
|
|
|
mraa_set_pininfo(b, 8, "UART1RX", (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 1 }, 224);
|
|
|
|
|
mraa_set_pininfo(b, 9, "SPIMOSI", (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 }, 222);
|
|
|
|
|
mraa_set_pininfo(b, 10, "UART1CT", (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }, 227);
|
2015-07-06 11:48:44 +01:00
|
|
|
mraa_set_pininfo(b, 11, "SPI_CLK", (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 }, 223);
|
2015-03-23 14:39:12 +00:00
|
|
|
mraa_set_pininfo(b, 12, "UART1RT", (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }, 226);
|
|
|
|
|
mraa_set_pininfo(b, 13, "I2C_SCL", (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 }, 243);
|
|
|
|
|
mraa_set_pininfo(b, 14, "I2S_CLK", (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }, 216);
|
|
|
|
|
mraa_set_pininfo(b, 15, "I2C_SDA", (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 }, 242);
|
|
|
|
|
mraa_set_pininfo(b, 16, "I2S_FRM", (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }, 217);
|
|
|
|
|
mraa_set_pininfo(b, 17, "UART2TX", (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 1 }, 229);
|
|
|
|
|
mraa_set_pininfo(b, 18, "I2S_DO", (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }, 219);
|
|
|
|
|
mraa_set_pininfo(b, 19, "UART2RX", (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 1 }, 228);
|
|
|
|
|
mraa_set_pininfo(b, 20, "I2S_DI", (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }, 218);
|
|
|
|
|
mraa_set_pininfo(b, 21, "S5_0", (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }, 82);
|
|
|
|
|
mraa_set_pininfo(b, 22, "PWM0", (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 },
|
|
|
|
|
248); // Assume BIOS configured for PWM
|
|
|
|
|
mraa_set_pininfo(b, 23, "S5_1", (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }, 83);
|
|
|
|
|
mraa_set_pininfo(b, 24, "PWM1", (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 },
|
|
|
|
|
249); // Assume BIOS configured for PWM
|
|
|
|
|
mraa_set_pininfo(b, 25, "S5_4", (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }, 84);
|
|
|
|
|
mraa_set_pininfo(b, 26, "IBL8254", (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }, 208);
|
2014-11-13 13:55:58 -08:00
|
|
|
|
2015-07-10 17:52:50 +01:00
|
|
|
// Set number of i2c adaptors usable from userspace
|
2015-08-25 10:55:30 +01:00
|
|
|
b->i2c_bus_count = 1;
|
2014-11-13 13:55:58 -08:00
|
|
|
|
|
|
|
|
// Configure i2c adaptor #7 and make it the default
|
|
|
|
|
int pin_index_sda, pin_index_scl;
|
|
|
|
|
if (mraa_get_pin_index(b, "I2C_SDA", &pin_index_sda) == MRAA_SUCCESS &&
|
|
|
|
|
mraa_get_pin_index(b, "I2C_SCL", &pin_index_scl) == MRAA_SUCCESS) {
|
2015-07-10 17:52:50 +01:00
|
|
|
int bus = mraa_find_i2c_bus(I2CNAME, 0);
|
|
|
|
|
if (bus == -1) {
|
|
|
|
|
b->i2c_bus_count = 0;
|
|
|
|
|
} else {
|
|
|
|
|
b->def_i2c_bus = bus;
|
2015-08-20 23:12:37 +01:00
|
|
|
b->i2c_bus[0].bus_id = b->def_i2c_bus;
|
|
|
|
|
b->i2c_bus[0].sda = pin_index_sda;
|
|
|
|
|
b->i2c_bus[0].scl = pin_index_scl;
|
2015-07-10 17:52:50 +01:00
|
|
|
}
|
2014-11-13 13:55:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Configure PWM
|
|
|
|
|
b->pwm_default_period = 500;
|
|
|
|
|
b->pwm_max_period = 1000000000;
|
|
|
|
|
b->pwm_min_period = 1;
|
|
|
|
|
|
|
|
|
|
b->spi_bus_count = 1;
|
|
|
|
|
b->def_spi_bus = 0;
|
|
|
|
|
b->spi_bus[0].bus_id = 0;
|
|
|
|
|
b->spi_bus[0].slave_s = 0;
|
|
|
|
|
b->spi_bus[0].cs = 5;
|
|
|
|
|
b->spi_bus[0].mosi = 9;
|
|
|
|
|
b->spi_bus[0].miso = 7;
|
|
|
|
|
b->spi_bus[0].sclk = 11;
|
|
|
|
|
|
2015-09-01 10:31:12 +01:00
|
|
|
b->uart_dev_count = 1;
|
|
|
|
|
b->def_uart_dev = 0;
|
|
|
|
|
b->uart_dev[0].rx = -1;
|
|
|
|
|
b->uart_dev[0].tx = -1;
|
|
|
|
|
b->uart_dev[0].device_path = "/dev/ttyS0";
|
2015-01-20 15:10:47 +00:00
|
|
|
|
2014-11-13 13:55:58 -08:00
|
|
|
return b;
|
2014-12-08 11:33:15 +00:00
|
|
|
error:
|
|
|
|
|
syslog(LOG_CRIT, "minnowmax: Platform failed to initialise");
|
|
|
|
|
free(b);
|
|
|
|
|
return NULL;
|
2014-11-13 13:55:58 -08:00
|
|
|
}
|