You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

483 lines
17 KiB

  1. From 2c67c6f51ce5bab18c79f4304ccf42716f59f13c Mon Sep 17 00:00:00 2001
  2. From: John Crispin <blogic@openwrt.org>
  3. Date: Thu, 23 Jul 2015 13:21:25 +0200
  4. Subject: [PATCH 2/4] add mips support
  5. Signed-off-by: John Crispin <blogic@openwrt.org>
  6. ---
  7. include/mips/mediatek.h | 39 ++++++
  8. src/mips/CMakeLists.txt | 6 +
  9. src/mips/mediatek.c | 349 +++++++++++++++++++++++++++++++++++++++++++++++
  10. src/mips/mips.c | 60 ++++++++
  11. 4 files changed, 454 insertions(+)
  12. create mode 100644 include/mips/mediatek.h
  13. create mode 100644 src/mips/CMakeLists.txt
  14. create mode 100644 src/mips/mediatek.c
  15. create mode 100644 src/mips/mips.c
  16. --- /dev/null
  17. +++ b/include/mips/mediatek.h
  18. @@ -0,0 +1,39 @@
  19. +/*
  20. + * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
  21. + * Author: Michael Ring <mail@michael-ring.org>
  22. + * Copyright (c) 2014 Intel Corporation.
  23. + *
  24. + * Permission is hereby granted, free of charge, to any person obtaining
  25. + * a copy of this software and associated documentation files (the
  26. + * "Software"), to deal in the Software without restriction, including
  27. + * without limitation the rights to use, copy, modify, merge, publish,
  28. + * distribute, sublicense, and/or sell copies of the Software, and to
  29. + * permit persons to whom the Software is furnished to do so, subject to
  30. + * the following conditions:
  31. + *
  32. + * The above copyright notice and this permission notice shall be
  33. + * included in all copies or substantial portions of the Software.
  34. + *
  35. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  36. + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  37. + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  38. + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  39. + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  40. + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  41. + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  42. + */
  43. +
  44. +#pragma once
  45. +
  46. +#ifdef __cplusplus
  47. +extern "C" {
  48. +#endif
  49. +
  50. +#include "mraa_internal.h"
  51. +
  52. +mraa_board_t *
  53. + mraa_mtk_linkit();
  54. +
  55. +#ifdef __cplusplus
  56. +}
  57. +#endif
  58. --- /dev/null
  59. +++ b/src/mips/CMakeLists.txt
  60. @@ -0,0 +1,6 @@
  61. +message (INFO " - Adding MIPS platforms")
  62. +set (mraa_LIB_PLAT_SRCS_NOAUTO ${mraa_LIB_SRCS_NOAUTO}
  63. + ${PROJECT_SOURCE_DIR}/src/mips/mips.c
  64. + ${PROJECT_SOURCE_DIR}/src/mips/mediatek.c
  65. + PARENT_SCOPE
  66. +)
  67. --- /dev/null
  68. +++ b/src/mips/mediatek.c
  69. @@ -0,0 +1,349 @@
  70. +/*
  71. + * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
  72. + * Author: Michael Ring <mail@michael-ring.org>
  73. + * Copyright (c) 2014 Intel Corporation.
  74. + *
  75. + * Permission is hereby granted, free of charge, to any person obtaining
  76. + * a copy of this software and associated documentation files (the
  77. + * "Software"), to deal in the Software without restriction, including
  78. + * without limitation the rights to use, copy, modify, merge, publish,
  79. + * distribute, sublicense, and/or sell copies of the Software, and to
  80. + * permit persons to whom the Software is furnished to do so, subject to
  81. + * the following conditions:
  82. + *
  83. + * The above copyright notice and this permission notice shall be
  84. + * included in all copies or substantial portions of the Software.
  85. + *
  86. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  87. + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  88. + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  89. + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  90. + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  91. + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  92. + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  93. + */
  94. +
  95. +#include <stdio.h>
  96. +#include <stdint.h>
  97. +#include <stdlib.h>
  98. +#include <string.h>
  99. +#include <sys/mman.h>
  100. +#include <mraa/common.h>
  101. +
  102. +#include "mraa_internal.h"
  103. +
  104. +#include "common.h"
  105. +
  106. +#define PLATFORM_MEDIATEK_LINKIT 1
  107. +#define PLATFORM_MEDIATEK_LINKIT_AIR 2
  108. +#define MMAP_PATH "/dev/mem"
  109. +#define MT7628_GPIO_BASE 0x100
  110. +#define MT7628_BLOCK_SIZE (4 * 1024)
  111. +#define MT7628_GPIO_CTRL 0x00
  112. +#define MT7628_GPIO_DATA 0x20
  113. +#define MT7628_GPIO_SET 0x30
  114. +#define MT7628_GPIO_CLEAR 0x40
  115. +
  116. +#define MAX_SIZE 64
  117. +
  118. +// MMAP
  119. +static uint8_t* mmap_reg = NULL;
  120. +static int mmap_fd = 0;
  121. +static int mmap_size;
  122. +static unsigned int mmap_count = 0;
  123. +static int platform_detected = 0;
  124. +
  125. +mraa_result_t
  126. +mraa_mtk_linkit_mmap_write(mraa_gpio_context dev, int value)
  127. +{
  128. + volatile uint32_t* addr;
  129. + if (value) {
  130. + *(volatile uint32_t*) (mmap_reg + MT7628_GPIO_SET + (dev->pin / 32) * 4) =
  131. + (uint32_t)(1 << (dev->pin % 32));
  132. + } else {
  133. + *(volatile uint32_t*) (mmap_reg + MT7628_GPIO_CLEAR + (dev->pin / 32) * 4) =
  134. + (uint32_t)(1 << (dev->pin % 32));
  135. + }
  136. + return MRAA_SUCCESS;
  137. +}
  138. +
  139. +static mraa_result_t
  140. +mraa_mtk_linkit_mmap_unsetup()
  141. +{
  142. + if (mmap_reg == NULL) {
  143. + syslog(LOG_ERR, "linkit mmap: null register can't unsetup");
  144. + return MRAA_ERROR_INVALID_RESOURCE;
  145. + }
  146. + munmap(mmap_reg, mmap_size);
  147. + mmap_reg = NULL;
  148. + if (close(mmap_fd) != 0) {
  149. + return MRAA_ERROR_INVALID_RESOURCE;
  150. + }
  151. + return MRAA_SUCCESS;
  152. +}
  153. +
  154. +int
  155. +mraa_mtk_linkit_mmap_read(mraa_gpio_context dev)
  156. +{
  157. + uint32_t value = *(volatile uint32_t*) (mmap_reg + MT7628_GPIO_DATA + (dev->pin / 32) * 4);
  158. + if (value & (uint32_t)(1 << (dev->pin % 32))) {
  159. + return 1;
  160. + }
  161. + return 0;
  162. +}
  163. +
  164. +mraa_result_t
  165. +mraa_mtk_linkit_mmap_setup(mraa_gpio_context dev, mraa_boolean_t en)
  166. +{
  167. + if (dev == NULL) {
  168. + syslog(LOG_ERR, "linkit mmap: context not valid");
  169. + return MRAA_ERROR_INVALID_HANDLE;
  170. + }
  171. +
  172. + if (en == 0) {
  173. + if (dev->mmap_write == NULL && dev->mmap_read == NULL) {
  174. + syslog(LOG_ERR, "linkit mmap: can't disable disabled mmap gpio");
  175. + return MRAA_ERROR_INVALID_PARAMETER;
  176. + }
  177. + dev->mmap_write = NULL;
  178. + dev->mmap_read = NULL;
  179. + mmap_count--;
  180. + if (mmap_count == 0) {
  181. + return mraa_mtk_linkit_mmap_unsetup();
  182. + }
  183. + return MRAA_SUCCESS;
  184. + }
  185. +
  186. + if (dev->mmap_write != NULL && dev->mmap_read != NULL) {
  187. + syslog(LOG_ERR, "linkit mmap: can't enable enabled mmap gpio");
  188. + return MRAA_ERROR_INVALID_PARAMETER;
  189. + }
  190. +
  191. + // Might need to make some elements of this thread safe.
  192. + // For example only allow one thread to enter the following block
  193. + // to prevent mmap'ing twice.
  194. + if (mmap_reg == NULL) {
  195. + if ((mmap_fd = open(MMAP_PATH, O_RDWR)) < 0) {
  196. + syslog(LOG_ERR, "linkit map: unable to open resource0 file");
  197. + return MRAA_ERROR_INVALID_HANDLE;
  198. + }
  199. +
  200. + mmap_reg = (uint8_t*) mmap(NULL, MT7628_BLOCK_SIZE, PROT_READ | PROT_WRITE,
  201. + MAP_FILE | MAP_SHARED, mmap_fd, MT7628_GPIO_BASE);
  202. + if (mmap_reg == MAP_FAILED) {
  203. + syslog(LOG_ERR, "linkit mmap: failed to mmap");
  204. + mmap_reg = NULL;
  205. + close(mmap_fd);
  206. + return MRAA_ERROR_NO_RESOURCES;
  207. + }
  208. + }
  209. + dev->mmap_write = &mraa_mtk_linkit_mmap_write;
  210. + dev->mmap_read = &mraa_mtk_linkit_mmap_read;
  211. + mmap_count++;
  212. +
  213. + return MRAA_SUCCESS;
  214. +}
  215. +
  216. +mraa_board_t*
  217. +mraa_mtk_linkit()
  218. +{
  219. + mraa_board_t* b = (mraa_board_t*) malloc(sizeof(mraa_board_t));
  220. + if (b == NULL) {
  221. + return NULL;
  222. + }
  223. +
  224. + b->platform_name = "LINKIT";
  225. + platform_detected = PLATFORM_MEDIATEK_LINKIT;
  226. + b->phy_pin_count = 31;
  227. +
  228. + b->aio_count = 0;
  229. + b->adc_raw = 0;
  230. + b->adc_supported = 0;
  231. + b->pwm_default_period = 500;
  232. + b->pwm_max_period = 2147483;
  233. + b->pwm_min_period = 1;
  234. +
  235. + b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t) * b->phy_pin_count);
  236. +
  237. + advance_func->gpio_mmap_setup = &mraa_mtk_linkit_mmap_setup;
  238. +
  239. + strncpy(b->pins[0].name, "P0", MRAA_PIN_NAME_SIZE);
  240. + b->pins[0].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
  241. +
  242. + strncpy(b->pins[1].name, "P1", MRAA_PIN_NAME_SIZE);
  243. + b->pins[1].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
  244. +
  245. + strncpy(b->pins[2].name, "P2", MRAA_PIN_NAME_SIZE);
  246. + b->pins[2].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
  247. +
  248. + strncpy(b->pins[3].name, "P3", MRAA_PIN_NAME_SIZE);
  249. + b->pins[3].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
  250. +
  251. + strncpy(b->pins[4].name, "P4", MRAA_PIN_NAME_SIZE);
  252. + b->pins[4].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
  253. +
  254. + strncpy(b->pins[5].name, "P5", MRAA_PIN_NAME_SIZE);
  255. + b->pins[5].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
  256. +
  257. + strncpy(b->pins[6].name, "P6", MRAA_PIN_NAME_SIZE);
  258. + b->pins[6].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
  259. +
  260. + strncpy(b->pins[7].name, "P7", MRAA_PIN_NAME_SIZE);
  261. + b->pins[7].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
  262. +
  263. + strncpy(b->pins[8].name, "P8", MRAA_PIN_NAME_SIZE);
  264. + b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
  265. + b->pins[8].gpio.pinmap = 21;
  266. + b->pins[8].uart.parent_id = 2;
  267. + b->pins[8].uart.mux_total = 0;
  268. +
  269. + strncpy(b->pins[9].name, "P9", MRAA_PIN_NAME_SIZE);
  270. + b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
  271. + b->pins[9].gpio.pinmap = 20;
  272. + b->pins[9].uart.parent_id = 2;
  273. + b->pins[9].uart.mux_total = 0;
  274. +
  275. + strncpy(b->pins[10].name, "P10", MRAA_PIN_NAME_SIZE);
  276. + b->pins[10].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  277. + b->pins[10].gpio.pinmap = 2;
  278. +
  279. + strncpy(b->pins[11].name, "P11", MRAA_PIN_NAME_SIZE);
  280. + b->pins[11].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  281. + b->pins[11].gpio.pinmap = 3;
  282. +
  283. + strncpy(b->pins[12].name, "P12", MRAA_PIN_NAME_SIZE);
  284. + b->pins[12].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  285. + b->pins[12].gpio.pinmap = 0;
  286. +
  287. + strncpy(b->pins[13].name, "P13", MRAA_PIN_NAME_SIZE);
  288. + b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  289. + b->pins[13].gpio.pinmap = 1;
  290. +
  291. + strncpy(b->pins[14].name, "P14", MRAA_PIN_NAME_SIZE);
  292. + b->pins[14].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
  293. +
  294. + strncpy(b->pins[15].name, "P15", MRAA_PIN_NAME_SIZE);
  295. + b->pins[15].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  296. + b->pins[15].gpio.pinmap = 44;
  297. +
  298. + strncpy(b->pins[16].name, "P16", MRAA_PIN_NAME_SIZE);
  299. + b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
  300. + b->pins[16].gpio.pinmap = 46;
  301. + b->pins[16].uart.parent_id = 1;
  302. + b->pins[16].uart.mux_total = 0;
  303. +
  304. + strncpy(b->pins[17].name, "P17", MRAA_PIN_NAME_SIZE);
  305. + b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
  306. + b->pins[17].gpio.pinmap = 45;
  307. + b->pins[17].uart.parent_id = 1;
  308. + b->pins[17].uart.mux_total = 0;
  309. +
  310. + strncpy(b->pins[18].name, "P18", MRAA_PIN_NAME_SIZE);
  311. + b->pins[18].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
  312. + b->pins[18].gpio.pinmap = 13;
  313. + b->pins[18].uart.parent_id = 1;
  314. + b->pins[18].uart.mux_total = 0;
  315. +
  316. + strncpy(b->pins[19].name, "P19", MRAA_PIN_NAME_SIZE);
  317. + b->pins[19].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
  318. + b->pins[19].gpio.pinmap = 12;
  319. + b->pins[19].uart.parent_id = 0;
  320. + b->pins[19].uart.mux_total = 0;
  321. +
  322. + strncpy(b->pins[20].name, "P20", MRAA_PIN_NAME_SIZE);
  323. + b->pins[20].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
  324. + b->pins[20].gpio.pinmap = 5;
  325. + b->pins[20].i2c.pinmap = 0;
  326. + b->pins[20].i2c.mux_total = 0;
  327. +
  328. + strncpy(b->pins[21].name, "P21", MRAA_PIN_NAME_SIZE);
  329. + b->pins[21].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
  330. + b->pins[21].gpio.pinmap = 4;
  331. + b->pins[21].i2c.pinmap = 0;
  332. + b->pins[21].i2c.mux_total = 0;
  333. +
  334. + strncpy(b->pins[22].name, "P22", MRAA_PIN_NAME_SIZE);
  335. + b->pins[22].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
  336. + b->pins[22].gpio.pinmap = 8;
  337. + b->pins[22].spi.pinmap = 0;
  338. + b->pins[22].spi.mux_total = 0;
  339. +
  340. + strncpy(b->pins[23].name, "P23", MRAA_PIN_NAME_SIZE);
  341. + b->pins[23].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
  342. + b->pins[23].gpio.pinmap = 9;
  343. + b->pins[23].spi.pinmap = 0;
  344. + b->pins[23].spi.mux_total = 0;
  345. +
  346. + strncpy(b->pins[24].name, "P24", MRAA_PIN_NAME_SIZE);
  347. + b->pins[24].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
  348. + b->pins[24].gpio.pinmap = 7;
  349. + b->pins[24].spi.pinmap = 0;
  350. + b->pins[24].spi.mux_total = 0;
  351. +
  352. + strncpy(b->pins[25].name, "P25", MRAA_PIN_NAME_SIZE);
  353. + b->pins[25].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
  354. + b->pins[25].gpio.pinmap = 6;
  355. + b->pins[25].spi.pinmap = 0;
  356. + b->pins[25].spi.mux_total = 0;
  357. +
  358. + strncpy(b->pins[26].name, "P26", MRAA_PIN_NAME_SIZE);
  359. + b->pins[26].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
  360. + b->pins[26].gpio.pinmap = 18;
  361. +
  362. + strncpy(b->pins[27].name, "P27", MRAA_PIN_NAME_SIZE);
  363. + b->pins[27].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
  364. + b->pins[27].gpio.pinmap = 19;
  365. +
  366. + strncpy(b->pins[28].name, "P28", MRAA_PIN_NAME_SIZE);
  367. + b->pins[28].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  368. + b->pins[28].gpio.pinmap = 16;
  369. +
  370. + strncpy(b->pins[29].name, "P29", MRAA_PIN_NAME_SIZE);
  371. + b->pins[29].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  372. + b->pins[29].gpio.pinmap = 17;
  373. +
  374. + strncpy(b->pins[30].name, "P30", MRAA_PIN_NAME_SIZE);
  375. + b->pins[30].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  376. + b->pins[30].gpio.pinmap = 14;
  377. +
  378. + strncpy(b->pins[31].name, "P31", MRAA_PIN_NAME_SIZE);
  379. + b->pins[31].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  380. + b->pins[31].gpio.pinmap = 15;
  381. +
  382. + // BUS DEFINITIONS
  383. + b->i2c_bus_count = 1;
  384. + b->def_i2c_bus = 0;
  385. + b->i2c_bus[0].bus_id = 0;
  386. + b->i2c_bus[0].sda = 20;
  387. + b->i2c_bus[0].scl = 21;
  388. +
  389. + b->spi_bus_count = 1;
  390. + b->def_spi_bus = 0;
  391. + b->spi_bus[0].bus_id = 0;
  392. + b->spi_bus[0].slave_s = 0;
  393. + b->spi_bus[0].cs = 25;
  394. + b->spi_bus[0].mosi = 22;
  395. + b->spi_bus[0].miso = 23;
  396. + b->spi_bus[0].sclk = 21;
  397. +
  398. + b->uart_dev_count = 3;
  399. + b->def_uart_dev = 0;
  400. + b->uart_dev[0].rx = 18;
  401. + b->uart_dev[0].tx = 19;
  402. +
  403. + b->uart_dev[1].rx = 16;
  404. + b->uart_dev[1].tx = 17;
  405. +
  406. + b->uart_dev[2].rx = 9;
  407. + b->uart_dev[2].tx = 8;
  408. +
  409. + b->gpio_count = 0;
  410. + int i;
  411. + for (i = 0; i < b->phy_pin_count; i++) {
  412. + if (b->pins[i].capabilites.gpio) {
  413. + b->gpio_count++;
  414. + }
  415. + }
  416. +
  417. + return b;
  418. +}
  419. --- /dev/null
  420. +++ b/src/mips/mips.c
  421. @@ -0,0 +1,60 @@
  422. +/*
  423. + * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
  424. + * Author: Michael Ring <mail@michael-ring.org>
  425. + * Copyright (c) 2014 Intel Corporation.
  426. + *
  427. + * Permission is hereby granted, free of charge, to any person obtaining
  428. + * a copy of this software and associated documentation files (the
  429. + * "Software"), to deal in the Software without restriction, including
  430. + * without limitation the rights to use, copy, modify, merge, publish,
  431. + * distribute, sublicense, and/or sell copies of the Software, and to
  432. + * permit persons to whom the Software is furnished to do so, subject to
  433. + * the following conditions:
  434. + *
  435. + * The above copyright notice and this permission notice shall be
  436. + * included in all copies or substantial portions of the Software.
  437. + *
  438. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  439. + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  440. + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  441. + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  442. + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  443. + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  444. + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  445. + */
  446. +
  447. +#include <stdlib.h>
  448. +#include <string.h>
  449. +
  450. +#include "mraa_internal.h"
  451. +#include "mips/mediatek.h"
  452. +
  453. +mraa_platform_t
  454. +mraa_mips_platform()
  455. +{
  456. + mraa_platform_t platform_type = MRAA_UNKNOWN_PLATFORM;
  457. + size_t len = 100;
  458. + char* line = malloc(len);
  459. + FILE* fh = fopen("/proc/cpuinfo", "r");
  460. + if (fh != NULL) {
  461. + while (getline(&line, &len, fh) != -1) {
  462. + if (strncmp(line, "machine", 7) == 0) {
  463. + if (strstr(line, "MediaTek LinkIt Smart 7688")) {
  464. + platform_type = MRAA_MTK_LINKIT;
  465. + }
  466. + }
  467. + }
  468. + fclose(fh);
  469. + }
  470. + free(line);
  471. +
  472. + switch (platform_type) {
  473. + case MRAA_MTK_LINKIT:
  474. + plat = mraa_mtk_linkit();
  475. + break;
  476. + default:
  477. + plat = NULL;
  478. + syslog(LOG_ERR, "Unknown Platform, currently not supported by MRAA");
  479. + }
  480. + return platform_type;
  481. +}