galileo gen 2: port mmap to new structure
[contrib/mraa.git] / src / intel_de3815.c
1 /*
2  * Author: Thomas Ingleby <thomas.c.ingleby@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
28 #include "common.h"
29 #include "intel_de3815.h"
30
31 #define MAX_SIZE 64
32 #define SYSFS_CLASS_GPIO "/sys/class/gpio"
33
34 mraa_board_t*
35 mraa_intel_de3815()
36 {
37     mraa_board_t* b = (mraa_board_t*) malloc(sizeof(mraa_board_t));
38     if (b == NULL)
39         return NULL;
40
41     b->phy_pin_count = 18;
42     //b->gpio_count = 14;
43     b->aio_count = 0;
44     b->adc_raw = 0;
45     b->adc_supported = 0;
46     b->pwm_default_period = 500;
47     b->pwm_max_period = 2147483;
48     b->pwm_min_period = 1;
49
50     b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t)*MRAA_INTEL_DE3815_PINCOUNT);
51
52     strncpy(b->pins[0].name, "1.8v", 8);
53     b->pins[0].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
54
55     strncpy(b->pins[1].name, "GND", 8);
56     b->pins[1].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
57     strncpy(b->pins[2].name, "HDMIcec", 8);
58     b->pins[2].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
59     strncpy(b->pins[3].name, "DMICclk", 8);
60     b->pins[3].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
61     strncpy(b->pins[4].name, "3.3v", 8);
62     b->pins[4].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
63     strncpy(b->pins[5].name, "DMICda", 8);
64     b->pins[5].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
65     strncpy(b->pins[6].name, "Key", 8);
66     b->pins[6].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
67     strncpy(b->pins[7].name, "SMB-A", 8);
68     b->pins[7].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
69     strncpy(b->pins[8].name, "5v", 8);
70     b->pins[8].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
71     strncpy(b->pins[9].name, "SCI", 8);
72     b->pins[9].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
73
74     strncpy(b->pins[10].name, "PWM0", 8);
75     b->pins[10].capabilites = (mraa_pincapabilities_t) {1,0,1,0,0,0,0,0};
76     b->pins[10].pwm.pinmap = 0;
77     b->pins[10].pwm.parent_id = 0;
78     b->pins[10].pwm.mux_total = 0;
79
80     strncpy(b->pins[11].name, "PWM1", 8);
81     b->pins[11].capabilites = (mraa_pincapabilities_t) {1,0,1,0,0,0,0,0};
82     b->pins[11].pwm.pinmap = 0;
83     b->pins[11].pwm.parent_id = 1;
84     b->pins[11].pwm.mux_total = 0;
85
86     strncpy(b->pins[12].name, "I2C0-SCL", 8);
87     b->pins[12].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,1,0,0};
88     b->pins[12].i2c.pinmap = 1;
89     b->pins[12].i2c.mux_total = 0;
90
91     strncpy(b->pins[13].name, "I2C0-SDA", 8);
92     b->pins[13].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,1,0,0};
93     b->pins[13].i2c.pinmap = 1;
94     b->pins[13].i2c.mux_total = 0;
95
96     strncpy(b->pins[14].name, "I2C1-SCL", 8);
97     b->pins[14].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,1,0,0};
98     b->pins[14].i2c.pinmap = 1;
99     b->pins[14].i2c.mux_total = 0;
100
101     strncpy(b->pins[15].name, "I2C1-SDA", 8);
102     b->pins[15].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,1,0,0};
103     b->pins[15].i2c.pinmap = 1;
104     b->pins[15].i2c.mux_total = 0;
105
106     strncpy(b->pins[16].name, "SMB_CLK", 8);
107     b->pins[16].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
108     strncpy(b->pins[17].name, "SMB_SDA", 8);
109     b->pins[17].capabilites = (mraa_pincapabilities_t) {1,0,0,0,0,0,0,0};
110
111     //BUS DEFINITIONS
112     b->i2c_bus_count = 2;
113     b->def_i2c_bus = 0;
114     b->i2c_bus[0].bus_id = 0;
115     b->i2c_bus[0].sda = 12;
116     b->i2c_bus[0].scl = 13;
117
118     b->i2c_bus[1].bus_id = 1;
119     b->i2c_bus[1].sda = 14;
120     b->i2c_bus[1].scl = 15;
121
122     b->spi_bus_count = 1;
123     b->def_spi_bus = 0;
124     b->spi_bus[0].bus_id = 1;
125     b->spi_bus[0].slave_s = 0;
126     b->spi_bus[0].cs = 10;
127     b->spi_bus[0].mosi = 11;
128     b->spi_bus[0].miso = 12;
129     b->spi_bus[0].sclk = 13;
130
131     return b;
132 }