2014-10-17 17:29:20 +01:00
|
|
|
/*
|
|
|
|
|
* Author: Thomas Ingleby <thomas.c.ingleby@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.
|
|
|
|
|
*/
|
|
|
|
|
|
2015-06-30 14:33:22 +01:00
|
|
|
#define _GNU_SOURCE
|
2014-10-17 17:29:20 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2015-06-30 14:33:22 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <fcntl.h>
|
2014-10-17 17:29:20 +01:00
|
|
|
|
|
|
|
|
#include "common.h"
|
2014-11-21 00:07:33 +00:00
|
|
|
#include "x86/intel_de3815.h"
|
2014-10-17 17:29:20 +01:00
|
|
|
|
2014-11-26 15:15:55 +00:00
|
|
|
#define PLATFORM_NAME "Intel DE3815"
|
2014-10-17 17:29:20 +01:00
|
|
|
#define MAX_SIZE 64
|
|
|
|
|
#define SYSFS_CLASS_GPIO "/sys/class/gpio"
|
2015-06-30 14:33:22 +01:00
|
|
|
#define I2CNAME "designware"
|
2014-10-17 17:29:20 +01:00
|
|
|
|
|
|
|
|
mraa_board_t*
|
|
|
|
|
mraa_intel_de3815()
|
|
|
|
|
{
|
|
|
|
|
mraa_board_t* b = (mraa_board_t*) malloc(sizeof(mraa_board_t));
|
2014-12-08 11:32:54 +00:00
|
|
|
if (b == NULL) {
|
2014-10-17 17:29:20 +01:00
|
|
|
return NULL;
|
2014-12-08 11:32:54 +00:00
|
|
|
}
|
2014-10-17 17:29:20 +01:00
|
|
|
|
2015-01-21 15:35:54 +00:00
|
|
|
b->platform_name = PLATFORM_NAME;
|
2014-10-17 17:29:20 +01:00
|
|
|
b->phy_pin_count = 18;
|
2015-03-23 14:39:12 +00:00
|
|
|
// b->gpio_count = 14;
|
2014-10-17 17:29:20 +01:00
|
|
|
b->aio_count = 0;
|
|
|
|
|
b->adc_raw = 0;
|
|
|
|
|
b->adc_supported = 0;
|
2014-10-30 12:03:24 +00:00
|
|
|
b->pwm_default_period = 500;
|
|
|
|
|
b->pwm_max_period = 2147483;
|
|
|
|
|
b->pwm_min_period = 1;
|
2014-10-17 17:29:20 +01:00
|
|
|
|
2015-03-23 14:39:12 +00:00
|
|
|
b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t) * MRAA_INTEL_DE3815_PINCOUNT);
|
2014-12-08 11:32:54 +00:00
|
|
|
if (b->pins == NULL) {
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2014-10-17 17:29:20 +01:00
|
|
|
|
|
|
|
|
strncpy(b->pins[0].name, "1.8v", 8);
|
2015-03-23 14:39:12 +00:00
|
|
|
b->pins[0].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
2014-10-17 17:29:20 +01:00
|
|
|
|
|
|
|
|
strncpy(b->pins[1].name, "GND", 8);
|
2015-03-23 14:39:12 +00:00
|
|
|
b->pins[1].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
2014-10-17 17:29:20 +01:00
|
|
|
strncpy(b->pins[2].name, "HDMIcec", 8);
|
2015-03-23 14:39:12 +00:00
|
|
|
b->pins[2].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
2014-10-17 17:29:20 +01:00
|
|
|
strncpy(b->pins[3].name, "DMICclk", 8);
|
2015-03-23 14:39:12 +00:00
|
|
|
b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
2014-10-17 17:29:20 +01:00
|
|
|
strncpy(b->pins[4].name, "3.3v", 8);
|
2015-03-23 14:39:12 +00:00
|
|
|
b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
2014-10-17 17:29:20 +01:00
|
|
|
strncpy(b->pins[5].name, "DMICda", 8);
|
2015-03-23 14:39:12 +00:00
|
|
|
b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
2014-10-17 17:29:20 +01:00
|
|
|
strncpy(b->pins[6].name, "Key", 8);
|
2015-03-23 14:39:12 +00:00
|
|
|
b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
2014-10-17 17:29:20 +01:00
|
|
|
strncpy(b->pins[7].name, "SMB-A", 8);
|
2015-03-23 14:39:12 +00:00
|
|
|
b->pins[7].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
2014-10-17 17:29:20 +01:00
|
|
|
strncpy(b->pins[8].name, "5v", 8);
|
2015-03-23 14:39:12 +00:00
|
|
|
b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
2014-10-17 17:29:20 +01:00
|
|
|
strncpy(b->pins[9].name, "SCI", 8);
|
2015-03-23 14:39:12 +00:00
|
|
|
b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
2014-10-21 23:59:53 +01:00
|
|
|
|
2014-10-17 17:29:20 +01:00
|
|
|
strncpy(b->pins[10].name, "PWM0", 8);
|
2015-03-23 14:39:12 +00:00
|
|
|
b->pins[10].capabilites = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
|
2014-10-21 23:59:53 +01:00
|
|
|
b->pins[10].pwm.pinmap = 0;
|
|
|
|
|
b->pins[10].pwm.parent_id = 0;
|
|
|
|
|
b->pins[10].pwm.mux_total = 0;
|
|
|
|
|
|
2014-10-17 17:29:20 +01:00
|
|
|
strncpy(b->pins[11].name, "PWM1", 8);
|
2015-03-23 14:39:12 +00:00
|
|
|
b->pins[11].capabilites = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
|
2014-10-21 23:59:53 +01:00
|
|
|
b->pins[11].pwm.pinmap = 0;
|
|
|
|
|
b->pins[11].pwm.parent_id = 1;
|
|
|
|
|
b->pins[11].pwm.mux_total = 0;
|
2014-10-17 17:29:20 +01:00
|
|
|
|
2014-11-26 13:59:01 +00:00
|
|
|
strncpy(b->pins[12].name, "I2C0SCL", 8);
|
2015-03-23 14:39:12 +00:00
|
|
|
b->pins[12].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
|
2014-10-17 17:29:20 +01:00
|
|
|
b->pins[12].i2c.pinmap = 1;
|
|
|
|
|
b->pins[12].i2c.mux_total = 0;
|
|
|
|
|
|
2014-11-26 13:59:01 +00:00
|
|
|
strncpy(b->pins[13].name, "I2C0SDA", 8);
|
2015-03-23 14:39:12 +00:00
|
|
|
b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
|
2014-10-17 17:29:20 +01:00
|
|
|
b->pins[13].i2c.pinmap = 1;
|
|
|
|
|
b->pins[13].i2c.mux_total = 0;
|
|
|
|
|
|
2014-11-26 13:59:01 +00:00
|
|
|
strncpy(b->pins[14].name, "I2C1SCL", 8);
|
2015-03-23 14:39:12 +00:00
|
|
|
b->pins[14].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
|
2014-10-17 17:29:20 +01:00
|
|
|
b->pins[14].i2c.pinmap = 1;
|
|
|
|
|
b->pins[14].i2c.mux_total = 0;
|
|
|
|
|
|
2014-11-26 13:59:01 +00:00
|
|
|
strncpy(b->pins[15].name, "I2C1SDA", 8);
|
2015-03-23 14:39:12 +00:00
|
|
|
b->pins[15].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
|
2014-10-17 17:29:20 +01:00
|
|
|
b->pins[15].i2c.pinmap = 1;
|
|
|
|
|
b->pins[15].i2c.mux_total = 0;
|
|
|
|
|
|
|
|
|
|
strncpy(b->pins[16].name, "SMB_CLK", 8);
|
2015-03-23 14:39:12 +00:00
|
|
|
b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
2014-10-17 17:29:20 +01:00
|
|
|
strncpy(b->pins[17].name, "SMB_SDA", 8);
|
2015-03-23 14:39:12 +00:00
|
|
|
b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
|
2014-10-17 17:29:20 +01:00
|
|
|
|
2015-03-23 14:39:12 +00:00
|
|
|
// BUS DEFINITIONS
|
2015-06-30 14:33:22 +01:00
|
|
|
int fd;
|
|
|
|
|
if (mraa_file_exist("/dev/i2c-0")) {
|
|
|
|
|
b->i2c_bus_count = 2;
|
|
|
|
|
int i = 0;
|
|
|
|
|
int suc = 0;
|
2015-07-08 09:39:30 +01:00
|
|
|
for (i = 0; i < 9; i++) {
|
2015-06-30 14:33:22 +01:00
|
|
|
char path[MAX_SIZE];
|
|
|
|
|
snprintf(path, MAX_SIZE, "/sys/class/i2c-dev/i2c-%u/name", i);
|
|
|
|
|
fd = open(path, O_RDONLY);
|
2015-07-08 09:39:52 +01:00
|
|
|
if (fd < 0) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-06-30 14:33:22 +01:00
|
|
|
off_t size = lseek(fd, 0, SEEK_END);
|
|
|
|
|
char value[MAX_SIZE];
|
|
|
|
|
lseek(fd, 0, SEEK_SET);
|
|
|
|
|
ssize_t r = read(fd, value, size);
|
|
|
|
|
if (r > 0) {
|
|
|
|
|
if (strcasestr(value, I2CNAME) != NULL) {
|
|
|
|
|
suc = 1;
|
|
|
|
|
b->i2c_bus_count = 2;
|
|
|
|
|
b->def_i2c_bus = 0;
|
|
|
|
|
b->i2c_bus[0].bus_id = i;
|
|
|
|
|
b->i2c_bus[0].sda = 12;
|
|
|
|
|
b->i2c_bus[0].scl = 13;
|
|
|
|
|
|
|
|
|
|
b->i2c_bus[1].bus_id = i+1;
|
|
|
|
|
b->i2c_bus[1].sda = 14;
|
|
|
|
|
b->i2c_bus[1].scl = 15;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
syslog(LOG_ERR, "mraa: sysfs i2cdev failed");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
close(fd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!suc) {
|
|
|
|
|
syslog(LOG_WARNING, "mraa: no i2c-dev detected, load i2c-dev");
|
|
|
|
|
b->i2c_bus_count = 0;
|
|
|
|
|
b->def_i2c_bus = 0;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
syslog(LOG_WARNING, "mraa: no i2c-dev detected, load i2c-dev");
|
|
|
|
|
b->i2c_bus_count = 0;
|
|
|
|
|
b->def_i2c_bus = 0;
|
|
|
|
|
}
|
|
|
|
|
close(fd);
|
2014-10-17 17:29:20 +01:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2015-01-20 15:10:47 +00:00
|
|
|
b->uart_dev_count = 0;
|
|
|
|
|
|
2014-10-17 17:29:20 +01:00
|
|
|
return b;
|
2014-12-08 11:32:54 +00:00
|
|
|
error:
|
|
|
|
|
syslog(LOG_CRIT, "de3815: Platform failed to initialise");
|
|
|
|
|
free(b);
|
|
|
|
|
return NULL;
|
2014-10-17 17:29:20 +01:00
|
|
|
}
|