96boards: add support to 96boards (https://www.96boards.org/)
[contrib/mraa.git] / src / arm / 96boards.c
1 /*
2  * Author: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
3  * Copyright (c) 2014 Intel Corporation.
4  * Copyright (c) 2015 Linaro Limited.
5  *
6  * Copied from src/arm/banana.c
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27
28 #include <stdlib.h>
29 #include <string.h>
30 #include <sys/mman.h>
31 #include <mraa/common.h>
32
33 #include "common.h"
34 #include "arm/96boards.h"
35
36 #define DT_BASE "/sys/firmware/devicetree/base"
37
38 #define PLATFORM_NAME_DB410C "DB410C"
39
40 int db410c_ls_gpio_pins[MRAA_96BOARDS_LS_GPIO_COUNT] = {
41   36, 12, 13, 69, 115, 4, 24, 25, 35, 34, 28, 33,
42 };
43
44 const char* db410c_serialdev[MRAA_96BOARDS_LS_UART_COUNT] = { "/dev/ttyMSM0", "/dev/ttyMSM1"};
45
46 mraa_board_t* mraa_96boards()
47 {
48    int i, pin;
49    int *ls_gpio_pins;
50    char ch;
51    char name[MRAA_PIN_NAME_SIZE];
52
53    mraa_board_t* b = (mraa_board_t*) malloc(sizeof(mraa_board_t));
54    if (b == NULL) {
55       return NULL;
56    }
57
58    // pin mux for buses are setup by default by kernel so tell mraa to ignore them
59    b->no_bus_mux = 1;
60
61    if (mraa_file_exist(DT_BASE "/model")) {
62         // We are on a modern kernel, great!!!!
63         if (mraa_file_contains(DT_BASE "/model", "Qualcomm Technologies, Inc. APQ 8016 SBC")) {
64             b->platform_name = PLATFORM_NAME_DB410C;
65             b->phy_pin_count = DB410C_PINCOUNT;
66             ls_gpio_pins = db410c_ls_gpio_pins;
67             b->uart_dev[0].device_path = db410c_serialdev[0];
68             b->uart_dev[1].device_path = db410c_serialdev[1];
69         }
70    }
71
72    //UART
73    b->uart_dev_count = MRAA_96BOARDS_LS_UART_COUNT;
74    b->def_uart_dev = 0;
75
76    //I2C
77    b->i2c_bus_count = MRAA_96BOARDS_LS_I2C_COUNT;
78    b->def_i2c_bus = 0;
79    b->i2c_bus[0].bus_id = 0;
80    b->i2c_bus[1].bus_id= 1;
81
82    //SPI
83    b->spi_bus_count = MRAA_96BOARDS_LS_SPI_COUNT;
84    b->spi_bus[0].bus_id = 0;
85    b->def_spi_bus = 0;
86
87    b->adv_func = (mraa_adv_func_t*) calloc(1, sizeof(mraa_adv_func_t));
88    if (b->adv_func == NULL) {
89       free(b);
90       return NULL;
91    }
92
93    b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t) * b->phy_pin_count);
94    if (b->pins == NULL) {
95       free(b->adv_func);
96       free(b);
97       return NULL;
98    }
99
100    // gpio lable starts from GPIO-A to GPIO-F
101    ch = 'A';
102    for (i = 0; i < MRAA_96BOARDS_LS_GPIO_COUNT; i++)
103    {
104       pin = ls_gpio_pins[i];
105       sprintf(name, "GPIO-%c", ch++);
106       strncpy(b->pins[pin].name, name, MRAA_PIN_NAME_SIZE);
107       b->pins[pin].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
108       b->pins[pin].gpio.pinmap = pin;
109       b->pins[pin].gpio.mux_total = 0;
110    }
111
112    b->gpio_count = MRAA_96BOARDS_LS_GPIO_COUNT;
113
114    b->aio_count = 0;
115    b->adc_raw = 0;
116    b->adc_supported = 0;
117    b->gpio_count = 0;
118
119    return b;
120 }