1 /*
2 * Author: Brendan Le Foll <brendan.le.foll@intel.com>
3 * Copyright (c) 2015 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_nuc5.h"
33
34 #define PLATFORM_NAME "Intel NUC5"
35 #define SYSFS_CLASS_GPIO "/sys/class/gpio"
36 #define I2CNAME "designware"
37
38 mraa_board_t*
mraa_intel_nuc5()39 mraa_intel_nuc5()
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_NUC5_PINCOUNT;
48
49 b->adv_func = (mraa_adv_func_t*) calloc(1, sizeof(mraa_adv_func_t));
50 if (b->adv_func == NULL) {
51 goto error;
52 }
53
54 b->pins = (mraa_pininfo_t*) calloc(MRAA_INTEL_NUC5_PINCOUNT,sizeof(mraa_pininfo_t));
55 if (b->pins == NULL) {
56 free(b->adv_func);
57 goto error;
58 }
59
60 strncpy(b->pins[0].name, "1.8v", 8);
61 b->pins[0].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
62
63 strncpy(b->pins[1].name, "GND", 8);
64 b->pins[1].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
65 strncpy(b->pins[2].name, "HDMIcec", 8);
66 b->pins[2].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
67 strncpy(b->pins[3].name, "DMICclk", 8);
68 b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
69 strncpy(b->pins[4].name, "3.3v", 8);
70 b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
71 strncpy(b->pins[5].name, "DMICda", 8);
72 b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
73 strncpy(b->pins[6].name, "Key", 8);
74 b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
75 strncpy(b->pins[7].name, "SMB-A", 8);
76 b->pins[7].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
77 strncpy(b->pins[8].name, "5v", 8);
78 b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
79 strncpy(b->pins[9].name, "SCI", 8);
80 b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
81
82 strncpy(b->pins[10].name, "PWM0", 8);
83 b->pins[10].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
84 b->pins[10].pwm.pinmap = 0;
85 b->pins[10].pwm.parent_id = 0;
86 b->pins[10].pwm.mux_total = 0;
87
88 strncpy(b->pins[11].name, "PWM1", 8);
89 b->pins[11].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
90 b->pins[11].pwm.pinmap = 0;
91 b->pins[11].pwm.parent_id = 1;
92 b->pins[11].pwm.mux_total = 0;
93
94 strncpy(b->pins[12].name, "I2C0SCL", 8);
95 b->pins[12].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
96 b->pins[12].i2c.pinmap = 1;
97 b->pins[12].i2c.mux_total = 0;
98
99 strncpy(b->pins[13].name, "I2C0SDA", 8);
100 b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
101 b->pins[13].i2c.pinmap = 1;
102 b->pins[13].i2c.mux_total = 0;
103
104 strncpy(b->pins[14].name, "I2C1SCL", 8);
105 b->pins[14].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
106 b->pins[14].i2c.pinmap = 1;
107 b->pins[14].i2c.mux_total = 0;
108
109 strncpy(b->pins[15].name, "I2C1SDA", 8);
110 b->pins[15].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 1, 0, 0 };
111 b->pins[15].i2c.pinmap = 1;
112 b->pins[15].i2c.mux_total = 0;
113
114 strncpy(b->pins[16].name, "SMB_CLK", 8);
115 b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
116 strncpy(b->pins[17].name, "SMB_SDA", 8);
117 b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 0, 0, 0, 0 };
118
119 b->i2c_bus_count = 0;
120 int i2c_num = -1;
121 int i;
122 for (i = 0; i < 2; i++) {
123 i2c_num = mraa_find_i2c_bus(I2CNAME, i2c_num + 1);
124 if (i2c_num == -1) {
125 break;
126 }
127 b->i2c_bus_count++;
128 b->i2c_bus[i].bus_id = i2c_num;
129 b->i2c_bus[i].sda = 12 + i;
130 b->i2c_bus[i].scl = 13 + i;
131 }
132
133 if (b->i2c_bus_count > 0) {
134 b->def_i2c_bus = b->i2c_bus[0].bus_id;
135 }
136
137 return b;
138 error:
139 syslog(LOG_CRIT, "nuc5: Platform failed to initialise");
140 free(b);
141 return NULL;
142 }
143