Home | History | Annotate | Download | only in x86
      1 /*
      2  * Author: Thomas Ingleby <thomas.c.ingleby (at) intel.com>
      3  * Copyright (c) 2014 Intel Corporation.
      4  *
      5  * Permission is hereby granted, free of charge, to any person obtaining
      6  * a copy of this software and associated documentation files (the
      7  * "Software"), to deal in the Software without restriction, including
      8  * without limitation the rights to use, copy, modify, merge, publish,
      9  * distribute, sublicense, and/or sell copies of the Software, and to
     10  * permit persons to whom the Software is furnished to do so, subject to
     11  * the following conditions:
     12  *
     13  * The above copyright notice and this permission notice shall be
     14  * included in all copies or substantial portions of the Software.
     15  *
     16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
     20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
     21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
     22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     23  */
     24 
     25 #include <stdlib.h>
     26 #include <string.h>
     27 #include <sys/types.h>
     28 #include <sys/stat.h>
     29 #include <fcntl.h>
     30 
     31 #include "common.h"
     32 #include "x86/intel_de3815.h"
     33 
     34 #define PLATFORM_NAME "Intel DE3815"
     35 #define SYSFS_CLASS_GPIO "/sys/class/gpio"
     36 #define I2CNAME "designware"
     37 
     38 mraa_board_t*
     39 mraa_intel_de3815()
     40 {
     41     mraa_board_t* b = (mraa_board_t*) calloc(1, sizeof(mraa_board_t));
     42     if (b == NULL) {
     43         return NULL;
     44     }
     45 
     46     b->platform_name = PLATFORM_NAME;
     47     b->phy_pin_count = MRAA_INTEL_DE3815_PINCOUNT;
     48     b->aio_count = 0;
     49     b->adc_raw = 0;
     50     b->adc_supported = 0;
     51     b->pwm_default_period = 500;
     52     b->pwm_max_period = 2147483;
     53     b->pwm_min_period = 1;
     54 
     55     b->pins = (mraa_pininfo_t*) calloc(MRAA_INTEL_DE3815_PINCOUNT,sizeof(mraa_pininfo_t));
     56     if (b->pins == NULL) {
     57         goto error;
     58     }
     59 
     60     b->adv_func = (mraa_adv_func_t*) calloc(1, sizeof(mraa_adv_func_t));
     61     if (b->adv_func == NULL) {
     62         free(b->pins);
     63         goto error;
     64     }
     65 
     66     strncpy(b->pins[0].name, "1.8v", 8);
     67     b->pins[0].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
     68 
     69     strncpy(b->pins[1].name, "GND", 8);
     70     b->pins[1].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
     71     strncpy(b->pins[2].name, "HDMIcec", 8);
     72     b->pins[2].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
     73     strncpy(b->pins[3].name, "DMICclk", 8);
     74     b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
     75     strncpy(b->pins[4].name, "3.3v", 8);
     76     b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
     77     strncpy(b->pins[5].name, "DMICda", 8);
     78     b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
     79     strncpy(b->pins[6].name, "Key", 8);
     80     b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
     81     strncpy(b->pins[7].name, "SMB-A", 8);
     82     b->pins[7].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
     83     strncpy(b->pins[8].name, "5v", 8);
     84     b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
     85     strncpy(b->pins[9].name, "SCI", 8);
     86     b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
     87 
     88     strncpy(b->pins[10].name, "PWM0", 8);
     89     b->pins[10].capabilites = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
     90     b->pins[10].pwm.pinmap = 0;
     91     b->pins[10].pwm.parent_id = 0;
     92     b->pins[10].pwm.mux_total = 0;
     93 
     94     strncpy(b->pins[11].name, "PWM1", 8);
     95     b->pins[11].capabilites = (mraa_pincapabilities_t){ 1, 0, 1, 0, 0, 0, 0, 0 };
     96     b->pins[11].pwm.pinmap = 0;
     97     b->pins[11].pwm.parent_id = 1;
     98     b->pins[11].pwm.mux_total = 0;
     99 
    100     strncpy(b->pins[12].name, "I2C0SCL", 8);
    101     b->pins[12].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
    102     b->pins[12].i2c.pinmap = 1;
    103     b->pins[12].i2c.mux_total = 0;
    104 
    105     strncpy(b->pins[13].name, "I2C0SDA", 8);
    106     b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
    107     b->pins[13].i2c.pinmap = 1;
    108     b->pins[13].i2c.mux_total = 0;
    109 
    110     strncpy(b->pins[14].name, "I2C1SCL", 8);
    111     b->pins[14].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
    112     b->pins[14].i2c.pinmap = 1;
    113     b->pins[14].i2c.mux_total = 0;
    114 
    115     strncpy(b->pins[15].name, "I2C1SDA", 8);
    116     b->pins[15].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
    117     b->pins[15].i2c.pinmap = 1;
    118     b->pins[15].i2c.mux_total = 0;
    119 
    120     strncpy(b->pins[16].name, "SMB_CLK", 8);
    121     b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
    122     strncpy(b->pins[17].name, "SMB_SDA", 8);
    123     b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
    124 
    125     b->i2c_bus_count = 0;
    126     int i2c_num = -1;
    127     int i;
    128     for (i = 0; i < 2; i++) {
    129         i2c_num = mraa_find_i2c_bus(I2CNAME, i2c_num + 1);
    130         if (i2c_num == -1) {
    131             break;
    132         }
    133         b->i2c_bus_count++;
    134         b->i2c_bus[i].bus_id = i2c_num;
    135         b->i2c_bus[i].sda = 12 + i;
    136         b->i2c_bus[i].scl = 13 + i;
    137     }
    138 
    139     if (b->i2c_bus_count > 0) {
    140         b->def_i2c_bus = b->i2c_bus[0].bus_id;
    141     }
    142 
    143 
    144     b->spi_bus_count = 1;
    145     b->def_spi_bus = 0;
    146     b->spi_bus[0].bus_id = 1;
    147     b->spi_bus[0].slave_s = 0;
    148     b->spi_bus[0].cs = 10;
    149     b->spi_bus[0].mosi = 11;
    150     b->spi_bus[0].miso = 12;
    151     b->spi_bus[0].sclk = 13;
    152 
    153     b->uart_dev_count = 0;
    154 
    155     return b;
    156 error:
    157     syslog(LOG_CRIT, "de3815: Platform failed to initialise");
    158     free(b);
    159     return NULL;
    160 }
    161