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.

666 lines
21 KiB

  1. From 3c34e5f87a741ec2fc7809fc8c169a832275d32c Mon Sep 17 00:00:00 2001
  2. From: John Crispin <blogic@openwrt.org>
  3. Date: Thu, 23 Jul 2015 18:19:32 +0200
  4. Subject: [PATCH 4/4] fixes
  5. ---
  6. src/mips/mediatek.c | 6 +++++-
  7. 1 file changed, 5 insertions(+), 1 deletion(-)
  8. --- a/src/mips/mediatek.c
  9. +++ b/src/mips/mediatek.c
  10. @@ -37,12 +37,12 @@
  11. #define PLATFORM_MEDIATEK_LINKIT 1
  12. #define PLATFORM_MEDIATEK_LINKIT_AIR 2
  13. #define MMAP_PATH "/dev/mem"
  14. -#define MT7628_GPIO_BASE 0x100
  15. -#define MT7628_BLOCK_SIZE (4 * 1024)
  16. -#define MT7628_GPIO_CTRL 0x00
  17. -#define MT7628_GPIO_DATA 0x20
  18. -#define MT7628_GPIO_SET 0x30
  19. -#define MT7628_GPIO_CLEAR 0x40
  20. +#define MT7628_GPIOMODE_BASE 0x10000000
  21. +#define MT7628_BLOCK_SIZE 0x1000
  22. +#define MT7628_GPIO_CTRL 0x600
  23. +#define MT7628_GPIO_DATA 0x620
  24. +#define MT7628_GPIO_SET 0x630
  25. +#define MT7628_GPIO_CLEAR 0x640
  26. #define MAX_SIZE 64
  27. @@ -50,6 +50,9 @@
  28. static uint8_t* mmap_reg = NULL;
  29. static int mmap_fd = 0;
  30. static int mmap_size;
  31. +static uint8_t* gpio_mmap_reg = NULL;
  32. +static int gpio_mmap_fd = 0;
  33. +static int gpio_mmap_size;
  34. static unsigned int mmap_count = 0;
  35. static int platform_detected = 0;
  36. @@ -129,9 +132,10 @@
  37. }
  38. mmap_reg = (uint8_t*) mmap(NULL, MT7628_BLOCK_SIZE, PROT_READ | PROT_WRITE,
  39. - MAP_FILE | MAP_SHARED, mmap_fd, MT7628_GPIO_BASE);
  40. + MAP_FILE | MAP_SHARED, mmap_fd, 0x10000000);
  41. if (mmap_reg == MAP_FAILED) {
  42. - syslog(LOG_ERR, "linkit mmap: failed to mmap");
  43. + perror("foo");
  44. + syslog(LOG_ERR, "linkit mmap: failed to mmap");
  45. mmap_reg = NULL;
  46. close(mmap_fd);
  47. return MRAA_ERROR_NO_RESOURCES;
  48. @@ -144,201 +148,442 @@
  49. return MRAA_SUCCESS;
  50. }
  51. +static int mmap_gpiomode(void)
  52. +{
  53. + if ((gpio_mmap_fd = open(MMAP_PATH, O_RDWR)) < 0) {
  54. + syslog(LOG_ERR, "linkit map: unable to open resource0 file");
  55. + return MRAA_ERROR_INVALID_HANDLE;
  56. + }
  57. +
  58. + gpio_mmap_reg = (uint8_t*) mmap(NULL, MT7628_BLOCK_SIZE, PROT_READ | PROT_WRITE,
  59. + MAP_FILE | MAP_SHARED, gpio_mmap_fd, MT7628_GPIOMODE_BASE);
  60. + if (gpio_mmap_reg == MAP_FAILED) {
  61. + syslog(LOG_ERR, "linkit gpio_mmap: failed to mmap");
  62. + gpio_mmap_reg = NULL;
  63. + close(gpio_mmap_fd);
  64. + return MRAA_ERROR_NO_RESOURCES;
  65. + }
  66. + return 0;
  67. +}
  68. +
  69. +static void set_gpiomode(unsigned int mask, unsigned int shift, unsigned int val)
  70. +{
  71. + unsigned int reg;
  72. + unsigned int offset = 0x60;
  73. +
  74. + if (shift >= 32) {
  75. + shift -= 32;
  76. + offset += 4;
  77. + }
  78. +
  79. + reg = *(volatile uint32_t*) (gpio_mmap_reg + offset);
  80. +
  81. + reg &= ~(mask << shift);
  82. + reg |= (val << shift);
  83. + *(volatile uint32_t*) (gpio_mmap_reg + offset) = reg;
  84. +}
  85. +
  86. +enum {
  87. + MUX_GPIO = 0,
  88. + MUX_SPI_S,
  89. + MUX_SPI_CS1,
  90. + MUX_I2S,
  91. + MUX_UART0,
  92. + MUX_I2C,
  93. + MUX_UART1,
  94. + MUX_UART2,
  95. + MUX_PWM0,
  96. + MUX_PWM1,
  97. + MUX_EPHY,
  98. + MUX_WLED,
  99. + __MUX_MAX,
  100. +};
  101. +
  102. +static unsigned char gpio_mux_groups[64];
  103. +static struct pinmux {
  104. + char *name;
  105. + char *func[4];
  106. + unsigned int shift;
  107. + unsigned int mask;
  108. +} mt7688_mux[] = {
  109. + {
  110. + .name = "refclk",
  111. + .func = { "refclk", "gpio", NULL, NULL },
  112. + .shift = 18,
  113. + .mask = 0x1,
  114. + }, {
  115. + .name = "spi_s",
  116. + .func = { "spi_s", "gpio", "utif", "pwm" },
  117. + .shift = 2,
  118. + .mask = 0x3,
  119. + }, {
  120. + .name = "spi_cs1",
  121. + .func = { "spi_cs1", "gpio", NULL, "refclk" },
  122. + .shift = 4,
  123. + .mask = 0x3,
  124. + }, {
  125. + .name = "i2s",
  126. + .func = { "i2s", "gpio", "pcm", NULL },
  127. + .shift = 6,
  128. + .mask = 0x3,
  129. + }, {
  130. + .name = "uart0",
  131. + .func = { "uart", "gpio", NULL, NULL },
  132. + .shift = 8,
  133. + .mask = 0x3,
  134. + }, {
  135. + .name = "i2c",
  136. + .func = { "i2c", "gpio", NULL, NULL },
  137. + .shift = 20,
  138. + .mask = 0x3,
  139. + }, {
  140. + .name = "uart1",
  141. + .func = { "uart", "gpio", NULL, NULL },
  142. + .shift = 24,
  143. + .mask = 0x3,
  144. + }, {
  145. + .name = "uart2",
  146. + .func = { "uart", "gpio", "pwm", NULL },
  147. + .shift = 26,
  148. + .mask = 0x3,
  149. + }, {
  150. + .name = "pwm0",
  151. + .func = { "pwm", "gpio", NULL, NULL },
  152. + .shift = 28,
  153. + .mask = 0x3,
  154. + }, {
  155. + .name = "pwm1",
  156. + .func = { "pwm", "gpio", NULL, NULL },
  157. + .shift = 30,
  158. + .mask = 0x3,
  159. + }, {
  160. + .name = "ephy",
  161. + .func = { "ephy", "gpio", NULL, NULL },
  162. + .shift = 34,
  163. + .mask = 0x3,
  164. + }, {
  165. + .name = "wled",
  166. + .func = { "wled", "gpio", NULL, NULL },
  167. + .shift = 32,
  168. + .mask = 0x3,
  169. + },
  170. +};
  171. +
  172. +mraa_result_t gpio_init_pre(int pin)
  173. +{
  174. + struct pinmux *m = &mt7688_mux[gpio_mux_groups[pin]];
  175. +
  176. + set_gpiomode(m->mask, m->shift, 1);
  177. +
  178. + return 0;
  179. +}
  180. +
  181. +static void gpiomode_set(unsigned int id, char *name)
  182. +{
  183. + int i;
  184. +
  185. + if (id >= __MUX_MAX)
  186. + return;
  187. +
  188. + for (i = 0; i < 4; i++) {
  189. + if (!mt7688_mux[id].func[i] || strcmp(mt7688_mux[id].func[i], name))
  190. + continue;
  191. + set_gpiomode(mt7688_mux[id].mask, mt7688_mux[id].shift, i);
  192. + syslog(0, "mraa: set pinmux %s -> %s\n", mt7688_mux[id].name, name);
  193. + return;
  194. + }
  195. +}
  196. +
  197. +mraa_result_t i2c_init_pre(unsigned int bus)
  198. +{
  199. + gpiomode_set(MUX_I2C, "i2c");
  200. + return 0;
  201. +}
  202. +
  203. +mraa_result_t
  204. +pwm_init_post(mraa_pwm_context pwm)
  205. +{
  206. + switch(pwm->pin) {
  207. + case 0:
  208. + gpiomode_set(MUX_PWM0, "pwm");
  209. + break;
  210. + case 1:
  211. + gpiomode_set(MUX_PWM1, "pwm");
  212. + break;
  213. + case 2:
  214. + case 3:
  215. + gpiomode_set(MUX_UART2, "pwm");
  216. + break;
  217. + }
  218. + return 0;
  219. +}
  220. +
  221. +mraa_result_t spi_init_pre(int bus)
  222. +{
  223. + gpiomode_set(MUX_SPI_CS1, "spi_cs1");
  224. + return 0;
  225. +}
  226. +
  227. +mraa_result_t uart_init_pre(int index)
  228. +{
  229. + switch(index) {
  230. + case 0:
  231. + gpiomode_set(MUX_UART0, "uart");
  232. + break;
  233. + case 1:
  234. + gpiomode_set(MUX_UART1, "uart");
  235. + break;
  236. + case 2:
  237. + gpiomode_set(MUX_UART2, "uart");
  238. + break;
  239. + }
  240. + return 0;
  241. +}
  242. +
  243. +mraa_result_t
  244. +i2c_freq(mraa_i2c_context dev, mraa_i2c_mode_t mode)
  245. +{
  246. + switch (mode) {
  247. + case MRAA_I2C_STD:
  248. + break;
  249. + default:
  250. + syslog(LOG_ERR, "Invalid i2c frequency");
  251. + break;
  252. + }
  253. + return MRAA_SUCCESS;
  254. +}
  255. +
  256. +
  257. mraa_board_t*
  258. mraa_mtk_linkit()
  259. {
  260. + int i;
  261. +
  262. + if (mmap_gpiomode())
  263. + return NULL;
  264. +
  265. mraa_board_t* b = (mraa_board_t*) malloc(sizeof(mraa_board_t));
  266. if (b == NULL) {
  267. return NULL;
  268. }
  269. - b->platform_name = "LINKIT";
  270. + memset(b, 0, sizeof(mraa_board_t));
  271. +
  272. + b->platform_name = "LinkIt Smart 7688";
  273. platform_detected = PLATFORM_MEDIATEK_LINKIT;
  274. - b->phy_pin_count = 31;
  275. + b->phy_pin_count = 64;
  276. b->aio_count = 0;
  277. b->adc_raw = 0;
  278. b->adc_supported = 0;
  279. b->pwm_default_period = 500;
  280. - b->pwm_max_period = 2147483;
  281. + b->pwm_max_period = 1000000;
  282. b->pwm_min_period = 1;
  283. - b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t) * b->phy_pin_count);
  284. -
  285. - advance_func->gpio_mmap_setup = &mraa_mtk_linkit_mmap_setup;
  286. -
  287. - strncpy(b->pins[0].name, "P0", MRAA_PIN_NAME_SIZE);
  288. - b->pins[0].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
  289. -
  290. - strncpy(b->pins[1].name, "P1", MRAA_PIN_NAME_SIZE);
  291. - b->pins[1].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
  292. -
  293. - strncpy(b->pins[2].name, "P2", MRAA_PIN_NAME_SIZE);
  294. - b->pins[2].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
  295. -
  296. - strncpy(b->pins[3].name, "P3", MRAA_PIN_NAME_SIZE);
  297. - b->pins[3].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
  298. -
  299. - strncpy(b->pins[4].name, "P4", MRAA_PIN_NAME_SIZE);
  300. - b->pins[4].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
  301. -
  302. - strncpy(b->pins[5].name, "P5", MRAA_PIN_NAME_SIZE);
  303. - b->pins[5].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
  304. -
  305. - strncpy(b->pins[6].name, "P6", MRAA_PIN_NAME_SIZE);
  306. - b->pins[6].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
  307. -
  308. - strncpy(b->pins[7].name, "P7", MRAA_PIN_NAME_SIZE);
  309. - b->pins[7].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
  310. -
  311. - strncpy(b->pins[8].name, "P8", MRAA_PIN_NAME_SIZE);
  312. - b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
  313. - b->pins[8].gpio.pinmap = 21;
  314. - b->pins[8].uart.parent_id = 2;
  315. - b->pins[8].uart.mux_total = 0;
  316. + b->adv_func = (mraa_adv_func_t*) calloc(1, sizeof(mraa_adv_func_t));
  317. + if (b->adv_func == NULL) {
  318. + return NULL;
  319. + }
  320. - strncpy(b->pins[9].name, "P9", MRAA_PIN_NAME_SIZE);
  321. - b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
  322. - b->pins[9].gpio.pinmap = 20;
  323. - b->pins[9].uart.parent_id = 2;
  324. - b->pins[9].uart.mux_total = 0;
  325. + b->adv_func->i2c_init_pre = i2c_init_pre;
  326. + b->adv_func->pwm_init_post = pwm_init_post;
  327. + b->adv_func->spi_init_pre = spi_init_pre;
  328. + b->adv_func->uart_init_pre = uart_init_pre;
  329. + b->adv_func->gpio_init_pre = gpio_init_pre;
  330. + b->adv_func->i2c_set_frequency_replace = &i2c_freq;
  331. - strncpy(b->pins[10].name, "P10", MRAA_PIN_NAME_SIZE);
  332. - b->pins[10].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  333. - b->pins[10].gpio.pinmap = 2;
  334. + b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t) * b->phy_pin_count);
  335. - strncpy(b->pins[11].name, "P11", MRAA_PIN_NAME_SIZE);
  336. - b->pins[11].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  337. - b->pins[11].gpio.pinmap = 3;
  338. + memset(b->pins, 0, sizeof(mraa_pininfo_t) * b->phy_pin_count);
  339. + memset(gpio_mux_groups, -1, sizeof(gpio_mux_groups));
  340. - strncpy(b->pins[12].name, "P12", MRAA_PIN_NAME_SIZE);
  341. - b->pins[12].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  342. - b->pins[12].gpio.pinmap = 0;
  343. + b->adv_func->gpio_mmap_setup = &mraa_mtk_linkit_mmap_setup;
  344. - strncpy(b->pins[13].name, "P13", MRAA_PIN_NAME_SIZE);
  345. - b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  346. - b->pins[13].gpio.pinmap = 1;
  347. + for (i = 0; i < b->phy_pin_count; i++) {
  348. + snprintf(b->pins[i].name, MRAA_PIN_NAME_SIZE, "GPIO%d", i);
  349. + b->pins[i].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
  350. + }
  351. - strncpy(b->pins[14].name, "P14", MRAA_PIN_NAME_SIZE);
  352. - b->pins[14].capabilites = (mraa_pincapabilities_t){ 0, 0, 0, 0, 0, 0, 0, 0 };
  353. + strncpy(b->pins[43].name, "GPIO43", MRAA_PIN_NAME_SIZE);
  354. + b->pins[43].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  355. + b->pins[43].gpio.pinmap = 43;
  356. + gpio_mux_groups[43] = MUX_EPHY;
  357. +
  358. + strncpy(b->pins[20].name, "GPIO20", MRAA_PIN_NAME_SIZE);
  359. + b->pins[20].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 1 };
  360. + b->pins[20].gpio.pinmap = 20;
  361. + b->pins[20].uart.parent_id = 2;
  362. + b->pins[20].uart.mux_total = 0;
  363. + b->pins[20].pwm.parent_id = 0;
  364. + b->pins[20].pwm.pinmap = 2;
  365. + gpio_mux_groups[20] = MUX_UART2;
  366. +
  367. + strncpy(b->pins[21].name, "GPIO21", MRAA_PIN_NAME_SIZE);
  368. + b->pins[21].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 1 };
  369. + b->pins[21].gpio.pinmap = 21;
  370. + b->pins[21].uart.parent_id = 2;
  371. + b->pins[21].uart.mux_total = 0;
  372. + b->pins[21].pwm.parent_id = 0;
  373. + b->pins[21].pwm.pinmap = 3;
  374. + gpio_mux_groups[21] = MUX_UART2;
  375. +
  376. + strncpy(b->pins[2].name, "GPIO2", MRAA_PIN_NAME_SIZE);
  377. + b->pins[2].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  378. + b->pins[2].gpio.pinmap = 2;
  379. + gpio_mux_groups[2] = MUX_I2S;
  380. +
  381. + strncpy(b->pins[3].name, "GPIO3", MRAA_PIN_NAME_SIZE);
  382. + b->pins[3].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  383. + b->pins[3].gpio.pinmap = 3;
  384. + gpio_mux_groups[3] = MUX_I2S;
  385. +
  386. + strncpy(b->pins[0].name, "GPIO0", MRAA_PIN_NAME_SIZE);
  387. + b->pins[0].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  388. + b->pins[0].gpio.pinmap = 0;
  389. + gpio_mux_groups[0] = MUX_I2S;
  390. +
  391. + strncpy(b->pins[1].name, "GPIO1", MRAA_PIN_NAME_SIZE);
  392. + b->pins[1].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  393. + b->pins[1].gpio.pinmap = 1;
  394. + gpio_mux_groups[1] = MUX_I2S;
  395. +
  396. + strncpy(b->pins[37].name, "GPIO37", MRAA_PIN_NAME_SIZE);
  397. + b->pins[37].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  398. + b->pins[37].gpio.pinmap = 37;
  399. + gpio_mux_groups[37] = MUX_GPIO;
  400. +
  401. + strncpy(b->pins[44].name, "GPIO44", MRAA_PIN_NAME_SIZE);
  402. + b->pins[44].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  403. + b->pins[44].gpio.pinmap = 44;
  404. + gpio_mux_groups[44] = MUX_WLED;
  405. +
  406. + strncpy(b->pins[46].name, "GPIO46", MRAA_PIN_NAME_SIZE);
  407. + b->pins[46].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
  408. + b->pins[46].gpio.pinmap = 46;
  409. + b->pins[46].uart.parent_id = 1;
  410. + b->pins[46].uart.mux_total = 0;
  411. + gpio_mux_groups[46] = MUX_UART1;
  412. +
  413. + strncpy(b->pins[45].name, "GPIO45", MRAA_PIN_NAME_SIZE);
  414. + b->pins[45].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
  415. + b->pins[45].gpio.pinmap = 45;
  416. + b->pins[45].uart.parent_id = 1;
  417. + b->pins[45].uart.mux_total = 0;
  418. + gpio_mux_groups[45] = MUX_UART1;
  419. +
  420. + strncpy(b->pins[13].name, "GPIO13", MRAA_PIN_NAME_SIZE);
  421. + b->pins[13].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
  422. + b->pins[13].gpio.pinmap = 13;
  423. + b->pins[13].uart.parent_id = 1;
  424. + b->pins[13].uart.mux_total = 0;
  425. + gpio_mux_groups[13] = MUX_UART0;
  426. +
  427. + strncpy(b->pins[12].name, "GPIO12", MRAA_PIN_NAME_SIZE);
  428. + b->pins[12].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
  429. + b->pins[12].gpio.pinmap = 12;
  430. + b->pins[12].uart.parent_id = 0;
  431. + b->pins[12].uart.mux_total = 0;
  432. + gpio_mux_groups[12] = MUX_UART0;
  433. +
  434. + strncpy(b->pins[5].name, "GPIO5", MRAA_PIN_NAME_SIZE);
  435. + b->pins[5].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
  436. + b->pins[5].gpio.pinmap = 5;
  437. + b->pins[5].i2c.pinmap = 0;
  438. + b->pins[5].i2c.mux_total = 0;
  439. + gpio_mux_groups[5] = MUX_I2C;
  440. +
  441. + strncpy(b->pins[4].name, "GPIO4", MRAA_PIN_NAME_SIZE);
  442. + b->pins[4].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
  443. + b->pins[4].gpio.pinmap = 4;
  444. + b->pins[4].i2c.pinmap = 0;
  445. + b->pins[4].i2c.mux_total = 0;
  446. + gpio_mux_groups[4] = MUX_I2C;
  447. +
  448. + strncpy(b->pins[6].name, "GPIO6", MRAA_PIN_NAME_SIZE);
  449. + b->pins[6].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
  450. + b->pins[6].gpio.pinmap = 6;
  451. + b->pins[6].spi.pinmap = 0;
  452. + b->pins[6].spi.mux_total = 0;
  453. + gpio_mux_groups[6] = MUX_SPI_CS1;
  454. +
  455. + strncpy(b->pins[7].name, "GPIO7", MRAA_PIN_NAME_SIZE);
  456. + b->pins[7].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
  457. + b->pins[7].spi.pinmap = 0;
  458. + b->pins[7].spi.mux_total = 0;
  459. +
  460. + strncpy(b->pins[8].name, "GPIO8", MRAA_PIN_NAME_SIZE);
  461. + b->pins[8].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
  462. + b->pins[8].spi.pinmap = 0;
  463. + b->pins[8].spi.mux_total = 0;
  464. +
  465. + strncpy(b->pins[9].name, "GPIO9", MRAA_PIN_NAME_SIZE);
  466. + b->pins[9].capabilites = (mraa_pincapabilities_t){ 1, 0, 0, 0, 1, 0, 0, 0 };
  467. + b->pins[9].spi.pinmap = 0;
  468. + b->pins[9].spi.mux_total = 0;
  469. +
  470. + strncpy(b->pins[18].name, "GPIO18", MRAA_PIN_NAME_SIZE);
  471. + b->pins[18].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
  472. + b->pins[18].gpio.pinmap = 18;
  473. + b->pins[18].pwm.parent_id = 0;
  474. + b->pins[18].pwm.pinmap = 0;
  475. + gpio_mux_groups[18] = MUX_PWM0;
  476. +
  477. + strncpy(b->pins[19].name, "GPIO19", MRAA_PIN_NAME_SIZE);
  478. + b->pins[19].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
  479. + b->pins[19].gpio.pinmap = 19;
  480. + b->pins[19].pwm.parent_id = 0;
  481. + b->pins[19].pwm.pinmap = 1;
  482. + gpio_mux_groups[19] = MUX_PWM1;
  483. +
  484. + strncpy(b->pins[16].name, "GPIO16", MRAA_PIN_NAME_SIZE);
  485. + b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  486. + b->pins[16].gpio.pinmap = 16;
  487. + gpio_mux_groups[16] = MUX_SPI_S;
  488. +
  489. + strncpy(b->pins[17].name, "GPIO17", MRAA_PIN_NAME_SIZE);
  490. + b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  491. + b->pins[17].gpio.pinmap = 17;
  492. + gpio_mux_groups[17] = MUX_SPI_S;
  493. +
  494. + strncpy(b->pins[14].name, "GPIO14", MRAA_PIN_NAME_SIZE);
  495. + b->pins[14].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  496. + b->pins[14].gpio.pinmap = 14;
  497. + gpio_mux_groups[14] = MUX_SPI_S;
  498. - strncpy(b->pins[15].name, "P15", MRAA_PIN_NAME_SIZE);
  499. + strncpy(b->pins[15].name, "GPIO15", MRAA_PIN_NAME_SIZE);
  500. b->pins[15].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  501. - b->pins[15].gpio.pinmap = 44;
  502. -
  503. - strncpy(b->pins[16].name, "P16", MRAA_PIN_NAME_SIZE);
  504. - b->pins[16].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
  505. - b->pins[16].gpio.pinmap = 46;
  506. - b->pins[16].uart.parent_id = 1;
  507. - b->pins[16].uart.mux_total = 0;
  508. -
  509. - strncpy(b->pins[17].name, "P17", MRAA_PIN_NAME_SIZE);
  510. - b->pins[17].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
  511. - b->pins[17].gpio.pinmap = 45;
  512. - b->pins[17].uart.parent_id = 1;
  513. - b->pins[17].uart.mux_total = 0;
  514. -
  515. - strncpy(b->pins[18].name, "P18", MRAA_PIN_NAME_SIZE);
  516. - b->pins[18].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
  517. - b->pins[18].gpio.pinmap = 13;
  518. - b->pins[18].uart.parent_id = 1;
  519. - b->pins[18].uart.mux_total = 0;
  520. -
  521. - strncpy(b->pins[19].name, "P19", MRAA_PIN_NAME_SIZE);
  522. - b->pins[19].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 1 };
  523. - b->pins[19].gpio.pinmap = 12;
  524. - b->pins[19].uart.parent_id = 0;
  525. - b->pins[19].uart.mux_total = 0;
  526. -
  527. - strncpy(b->pins[20].name, "P20", MRAA_PIN_NAME_SIZE);
  528. - b->pins[20].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
  529. - b->pins[20].gpio.pinmap = 5;
  530. - b->pins[20].i2c.pinmap = 0;
  531. - b->pins[20].i2c.mux_total = 0;
  532. -
  533. - strncpy(b->pins[21].name, "P21", MRAA_PIN_NAME_SIZE);
  534. - b->pins[21].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
  535. - b->pins[21].gpio.pinmap = 4;
  536. - b->pins[21].i2c.pinmap = 0;
  537. - b->pins[21].i2c.mux_total = 0;
  538. -
  539. - strncpy(b->pins[22].name, "P22", MRAA_PIN_NAME_SIZE);
  540. - b->pins[22].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
  541. - b->pins[22].gpio.pinmap = 8;
  542. - b->pins[22].spi.pinmap = 0;
  543. - b->pins[22].spi.mux_total = 0;
  544. -
  545. - strncpy(b->pins[23].name, "P23", MRAA_PIN_NAME_SIZE);
  546. - b->pins[23].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
  547. - b->pins[23].gpio.pinmap = 9;
  548. - b->pins[23].spi.pinmap = 0;
  549. - b->pins[23].spi.mux_total = 0;
  550. -
  551. - strncpy(b->pins[24].name, "P24", MRAA_PIN_NAME_SIZE);
  552. - b->pins[24].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
  553. - b->pins[24].gpio.pinmap = 7;
  554. - b->pins[24].spi.pinmap = 0;
  555. - b->pins[24].spi.mux_total = 0;
  556. -
  557. - strncpy(b->pins[25].name, "P25", MRAA_PIN_NAME_SIZE);
  558. - b->pins[25].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 1, 0, 0, 0 };
  559. - b->pins[25].gpio.pinmap = 6;
  560. - b->pins[25].spi.pinmap = 0;
  561. - b->pins[25].spi.mux_total = 0;
  562. -
  563. - strncpy(b->pins[26].name, "P26", MRAA_PIN_NAME_SIZE);
  564. - b->pins[26].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
  565. - b->pins[26].gpio.pinmap = 18;
  566. -
  567. - strncpy(b->pins[27].name, "P27", MRAA_PIN_NAME_SIZE);
  568. - b->pins[27].capabilites = (mraa_pincapabilities_t){ 1, 1, 1, 0, 0, 0, 0, 0 };
  569. - b->pins[27].gpio.pinmap = 19;
  570. -
  571. - strncpy(b->pins[28].name, "P28", MRAA_PIN_NAME_SIZE);
  572. - b->pins[28].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  573. - b->pins[28].gpio.pinmap = 16;
  574. -
  575. - strncpy(b->pins[29].name, "P29", MRAA_PIN_NAME_SIZE);
  576. - b->pins[29].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  577. - b->pins[29].gpio.pinmap = 17;
  578. -
  579. - strncpy(b->pins[30].name, "P30", MRAA_PIN_NAME_SIZE);
  580. - b->pins[30].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  581. - b->pins[30].gpio.pinmap = 14;
  582. -
  583. - strncpy(b->pins[31].name, "P31", MRAA_PIN_NAME_SIZE);
  584. - b->pins[31].capabilites = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
  585. - b->pins[31].gpio.pinmap = 15;
  586. + b->pins[15].gpio.pinmap = 15;
  587. + gpio_mux_groups[15] = MUX_SPI_S;
  588. // BUS DEFINITIONS
  589. b->i2c_bus_count = 1;
  590. b->def_i2c_bus = 0;
  591. - b->i2c_bus[0].bus_id = 0;
  592. - b->i2c_bus[0].sda = 20;
  593. - b->i2c_bus[0].scl = 21;
  594. + b->i2c_bus[0].bus_id = 0;
  595. + b->i2c_bus[0].sda = 5;
  596. + b->i2c_bus[0].scl = 4;
  597. b->spi_bus_count = 1;
  598. b->def_spi_bus = 0;
  599. - b->spi_bus[0].bus_id = 0;
  600. - b->spi_bus[0].slave_s = 0;
  601. - b->spi_bus[0].cs = 25;
  602. - b->spi_bus[0].mosi = 22;
  603. - b->spi_bus[0].miso = 23;
  604. - b->spi_bus[0].sclk = 21;
  605. + b->spi_bus[0].bus_id = 32766;
  606. + b->spi_bus[0].slave_s = 1;
  607. + b->spi_bus[0].cs = 6;
  608. + b->spi_bus[0].mosi = 8;
  609. + b->spi_bus[0].miso = 9;
  610. + b->spi_bus[0].sclk = 7;
  611. b->uart_dev_count = 3;
  612. b->def_uart_dev = 0;
  613. - b->uart_dev[0].rx = 18;
  614. - b->uart_dev[0].tx = 19;
  615. -
  616. - b->uart_dev[1].rx = 16;
  617. - b->uart_dev[1].tx = 17;
  618. -
  619. - b->uart_dev[2].rx = 9;
  620. - b->uart_dev[2].tx = 8;
  621. + b->uart_dev[0].rx = 13;
  622. + b->uart_dev[0].tx = 12;
  623. + b->uart_dev[0].device_path = "/dev/ttyS0";
  624. + b->uart_dev[1].rx = 46;
  625. + b->uart_dev[1].tx = 45;
  626. + b->uart_dev[1].device_path = "/dev/ttyS1";
  627. + b->uart_dev[2].rx = 21;
  628. + b->uart_dev[2].tx = 20;
  629. + b->uart_dev[2].device_path = "/dev/ttyS2";
  630. b->gpio_count = 0;
  631. - int i;
  632. for (i = 0; i < b->phy_pin_count; i++) {
  633. if (b->pins[i].capabilites.gpio) {
  634. b->gpio_count++;
  635. --- a/src/gpio/gpio.c
  636. +++ b/src/gpio/gpio.c
  637. @@ -113,6 +113,8 @@
  638. close(export);
  639. }
  640. + mraa_gpio_use_mmaped(dev, 1);
  641. +
  642. init_internal_cleanup:
  643. if (status != MRAA_SUCCESS) {
  644. if (dev != NULL)