pinctrl.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. #include "FreeRTOS.h"
  2. #include "board.h"
  3. #include "chip.h"
  4. #define PINCTL_REG_BASE REGS_SYSCTL_BASE
  5. #define MAX_PINS_PER_GROUP 32
  6. #define MAX_PIN_MUX_GROUP 4
  7. typedef struct {
  8. short muxio;
  9. short pinval;
  10. int drive;
  11. } xPin_t;
  12. typedef struct _pin_mux{
  13. uint32_t mux_reg;
  14. uint32_t mux_offset;
  15. uint32_t mux_mask;
  16. uint32_t mux_val;
  17. }pin_mux_t;
  18. typedef struct {
  19. int groupid;
  20. short pin_mux_num;
  21. pin_mux_t pin_mux[MAX_PIN_MUX_GROUP];
  22. short pins_num;
  23. xPin_t pins[MAX_PINS_PER_GROUP];
  24. } xPinGroup_t;
  25. /* typedef struct {
  26. } xPinFunction_t; */
  27. typedef struct {
  28. int reg;
  29. int offset;
  30. int mask;
  31. } xPinmap_t;
  32. static const xPinmap_t amt630hv160_pin_map[] = {
  33. {0xc0, 0, 0x3}, // gpio0
  34. {0xc0, 2, 0x3},
  35. {0xc0, 4, 0x3},
  36. {0xc0, 6, 0x3},
  37. {0xc0, 8, 0x3},
  38. {0xc0, 10, 0x3},
  39. {0xc0, 12, 0x3},
  40. {0xc0, 14, 0x3},
  41. {0xc0, 16, 0x3},
  42. {0xc0, 18, 0x3},
  43. {0xc0, 20, 0x3},
  44. {0xc0, 22, 0x3},
  45. {0xc0, 24, 0x3},
  46. {0xc0, 26, 0x3},
  47. {0xc0, 28, 0x3},
  48. {0xc0, 30, 0x3}, // gpio15
  49. {0xc4, 0, 0x3}, // gpio16
  50. {0xc4, 2, 0x3},
  51. {0xc4, 4, 0x3},
  52. {0xc4, 6, 0x3},
  53. {0xc4, 8, 0x3},
  54. {0xc4, 10, 0x3},
  55. {0xc4, 12, 0x3},
  56. {0xc4, 14, 0x3},
  57. {0xc4, 16, 0x3},
  58. {0xc4, 18, 0x3},
  59. {0xc4, 20, 0x3},
  60. {0xc4, 22, 0x3},
  61. {0xc4, 24, 0x3},
  62. {0xc4, 26, 0x3},
  63. {0xc4, 28, 0x3},
  64. {0xc4, 30, 0x3}, // gpio31
  65. {0xc8, 0, 0x3}, // gpio32
  66. {0xc8, 2, 0x3},
  67. {0xc8, 4, 0x3},
  68. {0xc8, 6, 0x3},
  69. {0xc8, 8, 0x3},
  70. {0xc8, 10, 0x3},
  71. {0xc8, 12, 0x3},
  72. {0xc8, 14, 0x3},
  73. {0xe4, 0, 0x3},
  74. {0xe4, 2, 0x3},
  75. {0xe4, 4, 0x3},
  76. {0xe4, 6, 0x3},
  77. {0xe4, 8, 0x3},
  78. {0xe4, 10, 0x3},
  79. {0xe4, 12, 0x3},
  80. {0xe4, 14, 0x3}, // gpio47
  81. {0xe4, 20, 0x3}, // gpio48
  82. {0xe4, 22, 0x3},
  83. {0xe4, 24, 0x3},
  84. {0xe4, 26, 0x3},
  85. {0xe4, 28, 0x3},
  86. {0xe4, 30, 0x3},
  87. {0xe8, 16, 0x3},
  88. {0xe8, 18, 0x3},
  89. {0xe8, 20, 0x3},
  90. {0xe8, 22, 0x3},
  91. {0xc8, 16, 0x3},
  92. {0xc8, 18, 0x3},
  93. {0xc8, 20, 0x3},
  94. {0xc8, 22, 0x3},
  95. {0xc8, 24, 0x3},
  96. {0xc8, 26, 0x3}, // gpio63
  97. {0xc8, 28, 0x3}, // gpio64
  98. {0xc8, 30, 0x3},
  99. {0xcc, 0, 0x3},
  100. {0xcc, 24, 0x3},
  101. {0xcc, 26, 0x3},
  102. {0xcc, 28, 0x3},
  103. {0xcc, 30, 0x3},
  104. {0xd0, 0, 0x3},
  105. {0xd0, 2, 0x3},
  106. {0xd0, 4, 0x3},
  107. {0xd0, 6, 0x3},
  108. {0xd0, 18, 0x3},
  109. {0xd0, 20, 0x3},
  110. {0xd0, 22, 0x3},
  111. {0xd0, 24, 0x3},
  112. {0xd0, 26, 0x3}, // gpio79
  113. {0xd4, 8, 0x3}, // gpio80
  114. {0xd4, 10, 0x3},
  115. {0xd4, 12, 0x3},
  116. {0xd4, 14, 0x3},
  117. {0xd4, 16, 0x3},
  118. {0xd4, 18, 0x3},
  119. {0xd4, 20, 0x3},
  120. {0xd4, 22, 0x3},
  121. {0xd4, 24, 0x3},
  122. {0xd4, 26, 0x3},
  123. {0xd8, 20, 0x3},
  124. {0xd8, 22, 0x3},
  125. {0xd8, 24, 0x3},
  126. {0xd8, 26, 0x3},
  127. {0xd8, 28, 0x3},
  128. {0xd8, 30, 0x3}, // gpio95
  129. {0xdc, 10, 0x3}, // gpio96
  130. {0xdc, 12, 0x3},
  131. {0xdc, 14, 0x3},
  132. {0xdc, 16, 0x3},
  133. {0xdc, 18, 0x3},
  134. {0xdc, 20, 0x3},
  135. {0xdc, 22, 0x3},
  136. {0xdc, 24, 0x3},
  137. {0xdc, 26, 0x3},
  138. {0xdc, 28, 0x3},
  139. {0xdc, 30, 0x3},
  140. {0xe0, 0, 0x3},
  141. {0xe0, 2, 0x3},
  142. {0xe0, 4, 0x3},
  143. {0xe0, 6, 0x3},
  144. {0xec, 0, 0x3}, // gpio111
  145. {0xec, 2, 0x3}, // gpio112
  146. {0xec, 4, 0x3},
  147. {0xec, 6, 0x3},
  148. {0xec, 8, 0x3},
  149. {0xec, 10, 0x3},
  150. {0xec, 12, 0x3},
  151. {0xec, 14, 0x3},
  152. {0xec, 16, 0x3},
  153. {0xec, 18, 0x3},
  154. {0xec, 20, 0x3},
  155. {0xec, 22, 0x3},
  156. {0xec, 24, 0x3},
  157. {0xec, 26, 0x3},
  158. {0xec, 28, 0x3},
  159. {0xec, 30, 0x3},
  160. {0xd0, 28, 0x3},// gpio127
  161. {0xF8, 0, 0x3},// gpio128
  162. {0xF8, 2, 0x3},
  163. {0xF8, 4, 0x3},
  164. {0xF8, 6, 0x3},
  165. {0xF8, 8, 0x3},
  166. {0xF8, 10, 0x3},
  167. {0xF8, 12, 0x3},
  168. {0xF8, 14, 0x3},
  169. {0xF8, 16, 0x3},
  170. {0xF8, 18, 0x3},
  171. {0xF8, 20, 0x3},
  172. {0xF8, 22, 0x3},
  173. {0xF8, 24, 0x3},
  174. {0xF8, 26, 0x3},
  175. {0xF8, 28, 0x3},
  176. {0xF8, 30, 0x3}, // gpio143
  177. };
  178. #define PIN_NUM ARRAY_SIZE(amt630hv160_pin_map)
  179. static const xPinmap_t amt630hv160_mcu_pin_map[] = {
  180. {0xc0, 0, 0x3}, // gpio0
  181. {0xc0, 2, 0x3},
  182. {0xc0, 4, 0x3},
  183. {0xc0, 6, 0x3},
  184. {0xc0, 8, 0x3},
  185. {0xc0, 10, 0x3},
  186. {0xc0, 12, 0x3},
  187. {0xc0, 14, 0x3},
  188. {0xc0, 16, 0x3},
  189. {0xc0, 18, 0x3},
  190. {0xc0, 20, 0x3},
  191. {0xc0, 22, 0x3},
  192. {0xc0, 24, 0x3},
  193. {0xc0, 26, 0x3},
  194. {0xc0, 28, 0x3},
  195. {0xc0, 30, 0x3}, // gpio15
  196. {0xc4, 0, 0x3}, // gpio16
  197. {0xc4, 2, 0x3},
  198. {0xc4, 4, 0x3},
  199. {0xc4, 6, 0x3},
  200. {0xc4, 8, 0x3},
  201. {0xc4, 10, 0x3},
  202. {0xc4, 12, 0x3},
  203. {0xc4, 14, 0x3},
  204. {0xc4, 16, 0x3},
  205. {0xc4, 18, 0x3},
  206. {0xc4, 20, 0x3},
  207. {0xc4, 22, 0x3},
  208. {0xc4, 24, 0x3},
  209. {0xc4, 26, 0x3},
  210. {0xc4, 28, 0x3},
  211. {0xc4, 30, 0x3}, // gpio31
  212. {0xc8, 0, 0x3}, // gpio32
  213. {0xc8, 2, 0x3},
  214. {0xc8, 4, 0x3},
  215. {0xc8, 6, 0x3},
  216. {0xc8, 8, 0x3},
  217. {0xc8, 10, 0x3},
  218. {0xc8, 12, 0x3},
  219. {0xc8, 14, 0x3},
  220. {0xe4, 0, 0x3},
  221. {0xe4, 2, 0x3},
  222. {0xe4, 4, 0x3},
  223. {0xe4, 6, 0x3},
  224. {0xe4, 8, 0x3},
  225. {0xe4, 10, 0x3},
  226. {0xe4, 12, 0x3},
  227. {0xe4, 14, 0x3}, // gpio47
  228. {0xe4, 20, 0x3}, // gpio48
  229. {0xe4, 22, 0x3},
  230. {0xe4, 24, 0x3},
  231. {0xe4, 26, 0x3},
  232. {0xe4, 28, 0x3},
  233. {0xe4, 30, 0x3},
  234. {0xe8, 16, 0x3},
  235. {0xe8, 18, 0x3},
  236. {0xe8, 20, 0x3},
  237. {0xe8, 22, 0x3},
  238. {0xc8, 16, 0x3},
  239. {0xc8, 18, 0x3},
  240. {0xc8, 20, 0x3},
  241. {0xc8, 22, 0x3},
  242. {0xc8, 24, 0x3},
  243. {0xc8, 26, 0x3}, // gpio63
  244. {0xc8, 28, 0x3}, // gpio64
  245. {0xc8, 30, 0x3},
  246. {0xcc, 0, 0x3},
  247. {0xcc, 2, 0x3},
  248. {0xcc, 4, 0x3},
  249. {0xcc, 6, 0x3},
  250. {0xcc, 8, 0x3},
  251. {0xcc, 10, 0x3},
  252. {0xcc, 12, 0x3},
  253. {0xcc, 14, 0x3},
  254. {0xcc, 16, 0x3},
  255. {0xcc, 18, 0x3},
  256. {0xcc, 20, 0x3},
  257. {0xcc, 22, 0x3},
  258. {0xd0, 8, 0x3},
  259. {0xd0, 10, 0x3}, // gpio79
  260. {0xd0, 12, 0x3}, // gpio80
  261. {0xd0, 14, 0x3},
  262. {0xd0, 16, 0x3},
  263. {0xd0, 28, 0x3},
  264. {0xd0, 30, 0x3},
  265. {0xd4, 0, 0x3},
  266. {0xd4, 2, 0x3},
  267. {0xd4, 4, 0x3},
  268. {0xd4, 6, 0x3},
  269. {0xd4, 28, 0x3},
  270. {0xd4, 30, 0x3},
  271. {0xd8, 0, 0x3},
  272. {0xd8, 2, 0x3},
  273. {0xd8, 4, 0x3},
  274. {0xd8, 6, 0x3},
  275. {0xd8, 8, 0x3},// gpio95
  276. {0xd8, 10, 0x3}, // gpio96
  277. {0xd8, 12, 0x3},
  278. {0xd8, 14, 0x3},
  279. {0xd8, 16, 0x3},
  280. {0xd8, 18, 0x3},
  281. {0xe4, 16, 0x3},
  282. {0xe4, 18, 0x3},
  283. {0xe8, 0, 0x3},
  284. {0xe8, 2, 0x3},
  285. {0xe8, 4, 0x3},
  286. {0xe8, 6, 0x3},
  287. {0xe8, 8, 0x3},
  288. {0xe8, 10, 0x3},
  289. {0xe8, 12, 0x3},
  290. {0xe8, 14, 0x3},
  291. {0xf0, 0, 0x3}, // gpio111
  292. {0xf0, 2, 0x3}, // gpio112
  293. {0xf0, 4, 0x3},
  294. {0xf0, 6, 0x3},
  295. {0xf0, 8, 0x3},
  296. {0xf0, 10, 0x3},
  297. {0xf0, 12, 0x3},
  298. {0xf0, 14, 0x3},
  299. {0xdc, 0, 0x3},
  300. {0xdc, 2, 0x3},
  301. {0xdc, 4, 0x3},
  302. {0xdc, 6, 0x3},
  303. {0xdc, 8, 0x3},
  304. {0Xd4, 8, 0x3},
  305. {0Xd4, 20, 0x3},// gpio125
  306. {0, 0, 0}, // reserved
  307. {0, 0, 0}, // reserved
  308. {0xF8, 0, 0x3},// gpio128
  309. {0xF8, 2, 0x3},
  310. {0xF8, 4, 0x3},
  311. {0xF8, 6, 0x3},
  312. {0xF8, 8, 0x3},
  313. {0xF8, 10, 0x3},
  314. {0xF8, 12, 0x3},
  315. {0xF8, 14, 0x3},
  316. {0xF8, 16, 0x3},
  317. {0xF8, 18, 0x3},
  318. {0xF8, 20, 0x3},
  319. {0xF8, 22, 0x3},
  320. {0xF8, 24, 0x3},
  321. {0xF8, 26, 0x3},
  322. {0xF8, 28, 0x3},
  323. {0xF8, 30, 0x3}, // gpio143
  324. };
  325. #define MCU_PIN_NUM ARRAY_SIZE(amt630hv160_mcu_pin_map)
  326. static const xPinGroup_t pin_groups[] = {
  327. {.groupid = PGRP_UART1, .pins_num = 2, .pins = {{67, 2}, {68, 2}}},
  328. {.groupid = PGRP_UART2, .pins_num = 2, .pins = {{69, 2}, {70, 2}}},
  329. {.groupid = PGRP_UART3, .pins_num = 2, .pins = {{71, 2}, {72, 2}}},
  330. {.groupid = PGRP_SDMMC1, .pins_num = 7, .pins = {{58, 2}, {59, 2}, {60, 2}, {61, 2}, {62, 2}, {63, 2},{64, 2}}},
  331. {.groupid = PGRP_ETH, .pins_num = 15, .pins = {
  332. #if ETH_TXC_PAD_DIR_OUTPUT
  333. {0, 3},
  334. #else
  335. {0, 2},
  336. #endif
  337. {1, 2}, {2, 2}, {3, 2}, {4, 2}, {5, 2},{6, 2},
  338. {7, 2},{8, 2},{9, 2},{10, 2},{11, 2},{12, 2},{13, 2},{14, 2}}},
  339. {.groupid = PGRP_SPI1, .pins_num = 4, .pins = {{86, 1}, {87, 2}, {88, 2}, {89, 2}}},
  340. {.groupid = PGRP_SPI2, .pins_num = 6, .pins = {{80, 1}, {81, 2}, {82, 2}, {83, 2}, {84, 2}, {85, 2}}},
  341. {.groupid = PGRP_I2C0, .pins_num = 2, .pins = {{97, 2},{98, 2}}},
  342. {.groupid = PGRP_I2C1, .pins_num = 2, .pins = {{65, 2},{66, 2}}},
  343. {.groupid = PGRP_I2S1_PLAY, .pins_num = 5, .pins = {{75, 2}, {76, 2}, {77, 2}, {78, 2}, {79 ,2}},\
  344. .pin_mux_num = 1,.pin_mux = {\
  345. {.mux_reg = PINCTL_REG_BASE + 0xF4,.mux_offset = 6,.mux_mask = 0x3,.mux_val = 0x3}, // GPIO78 -> I2S1_OUT0
  346. }
  347. },
  348. {.groupid = PGRP_I2S1_RECORD, .pins_num = 5, .pins = {{75, 2}, {76, 2}, {77, 2}, {78, 2}, {79 ,2}},\
  349. .pin_mux_num = 2,.pin_mux = {\
  350. {.mux_reg = PINCTL_REG_BASE + 0xF4,.mux_offset = 7,.mux_mask = 0x1,.mux_val = 0x0}, // i2s1_sdin_oe = 0
  351. {.mux_reg = PINCTL_REG_BASE + 0xF4,.mux_offset = 2,.mux_mask = 0x1,.mux_val = 0x1}, // i2s1_sadata_in sel = 1
  352. }
  353. },
  354. {.groupid = PGRP_RCRT, .pins_num = 1, .pins = {{96, 2}}},
  355. {.groupid = PGRP_PWM6, .pins_num = 1, .pins = {{90, 2}}},
  356. {.groupid = PGRP_PWM7, .pins_num = 1, .pins = {{91, 2}}},
  357. {.groupid = PGRP_PWM0_IN, .pins_num = 1, .pins = {{92, 2}}},
  358. {.groupid = PGRP_PWM1_IN, .pins_num = 1, .pins = {{93, 2}}},
  359. {.groupid = PGRP_PWM2_IN, .pins_num = 1, .pins = {{94, 2}}},
  360. {.groupid = PGRP_PWM3_IN, .pins_num = 1, .pins = {{95, 2}}},
  361. {.groupid = PGRP_ITU_CH0,.pins_num = 11, .pins = {{99,2},{100,2},{101,2},{102,2},{103,2},{104,2},{105,2},{106,2},{107,2},{108,2},{109,2}}},
  362. {.groupid = PGRP_ITU_CH0_MIPI,.pins_num = 11, .pins = {{99,1},{100,1},{101,1},{102,1},{103,1},{104,1},{105,1},{106,1},{107,1},{108,1},{109,1}}},
  363. };
  364. #define GROUP_NUM ARRAY_SIZE(pin_groups)
  365. static xPinGroup_t mcu_pin_groups[] = {
  366. {.groupid = PGRP_UART0, .pins_num = 2, .pins = {{74, 2}, {75, 2}}},
  367. {.groupid = PGRP_LCD_TTL_CH0, .pins_num = 28,
  368. /* de clk vynsc hsync */
  369. .pins = {{54, 2}, {55, 2, PAD_DRIVE_4MA}, {56, 2}, {57, 2},
  370. {40, 2}, {41, 2}, {42, 2}, {43, 2}, {44, 2}, {45, 2}, {46, 2}, {47, 2},
  371. {101, 2}, {102, 2}, {48, 2}, {49, 2}, {50, 2}, {51, 2}, {52, 2}, {53, 2},
  372. {103, 2}, {104, 2}, {105, 2}, {106, 2}, {107, 2}, {108, 2}, {109, 2}, {110, 2},}},
  373. {.groupid = PGRP_SPI0, .pins_num = 5, .pins = {{84, 2}, {85, 2}, {86, 2}, {87, 2}, {88, 2}}},
  374. {.groupid = PGRP_SDMMC0, .pins_num = 7, .pins = {{67, 2}, {68, 2}, {69, 2}, {70, 2}, {71, 2}, {72, 2}, {73, 2}},.pin_mux_num = 0},
  375. {.groupid = PGRP_I2S0_PLAY, .pins_num = 5, .pins = {{78, 2}, {79, 2}, {80, 2}, {81, 2}, {82, 2}},\
  376. .pin_mux_num = 1,.pin_mux = {\
  377. {.mux_reg = PINCTL_REG_BASE + 0xF4,.mux_offset = 4,.mux_mask = 0x3,.mux_val = 0x3}, // MCU-GPIO81 -> I2S0_OUT0
  378. }
  379. },
  380. {.groupid = PGRP_I2S0_RECORD, .pins_num = 5, .pins = {{78, 2}, {79, 2}, {80, 2}, {81, 2}, {82, 2}},\
  381. .pin_mux_num = 1,.pin_mux = {\
  382. {.mux_reg = PINCTL_REG_BASE + 0xF4,.mux_offset = 4,.mux_mask = 0x3,.mux_val = 0x0}, // MCU-GPIO81 -> I2S0_IN0
  383. }
  384. },
  385. {.groupid = PGRP_PWM0, .pins_num = 1, .pins = {{95, 2}}},
  386. {.groupid = PGRP_PWM1, .pins_num = 1, .pins = {{96, 2}}},
  387. {.groupid = PGRP_PWM2, .pins_num = 1, .pins = {{97, 2}}},
  388. {.groupid = PGRP_PWM3, .pins_num = 1, .pins = {{98, 2}}},
  389. {.groupid = PGRP_PWM4, .pins_num = 1, .pins = {{99, 2}}},
  390. {.groupid = PGRP_PWM5, .pins_num = 1, .pins = {{100, 2}}},
  391. };
  392. #define MCU_GROUP_NUM ARRAY_SIZE(mcu_pin_groups)
  393. static __INLINE void pinctrl_set_pin(int npin, int val, int drive)
  394. {
  395. const xPinmap_t *pctrl;
  396. uint32_t reg;
  397. if (npin >= PIN_NUM)
  398. return;
  399. pctrl = &amt630hv160_pin_map[npin];
  400. reg = readl(PINCTL_REG_BASE + pctrl->reg);
  401. reg &= ~(pctrl->mask << pctrl->offset);
  402. reg |= val << pctrl->offset;
  403. writel(reg, PINCTL_REG_BASE + pctrl->reg);
  404. if (drive != PAD_DRIVE_DEFAULT) {
  405. uint32_t drv_reg = SYS_IO_DRIVER00 + pctrl->reg - SYS_PAD_CTRL00;
  406. vSysctlConfigure(drv_reg, pctrl->offset, 3, drive - 1);
  407. }
  408. }
  409. static __INLINE void mcu_pinctrl_set_pin(int npin, int val, int drive)
  410. {
  411. const xPinmap_t *pctrl;
  412. uint32_t reg;
  413. if (npin >= MCU_PIN_NUM)
  414. return;
  415. pctrl = &amt630hv160_mcu_pin_map[npin];
  416. reg = readl(PINCTL_REG_BASE + pctrl->reg);
  417. reg &= ~(pctrl->mask << pctrl->offset);
  418. reg |= val << pctrl->offset;
  419. writel(reg, PINCTL_REG_BASE + pctrl->reg);
  420. if (drive != PAD_DRIVE_DEFAULT) {
  421. uint32_t drv_reg = SYS_IO_DRIVER00 + pctrl->reg - SYS_PAD_CTRL00;
  422. vSysctlConfigure(drv_reg, pctrl->offset, 3, drive - 1);
  423. }
  424. }
  425. void pinctrl_gpio_request(int gpio)
  426. {
  427. pinctrl_set_pin(gpio, 1, PAD_DRIVE_DEFAULT);
  428. }
  429. void pinctrl_set_group(int groupid)
  430. {
  431. int i, j;
  432. const xPinGroup_t *pgrp;
  433. uint32_t reg;
  434. for (i = 0; i < GROUP_NUM; i++) {
  435. pgrp = &pin_groups[i];
  436. if (pgrp->groupid == groupid) {
  437. configASSERT(pgrp->pins_num <= MAX_PINS_PER_GROUP);
  438. for (j = 0; j < pgrp->pins_num; j++){
  439. pinctrl_set_pin(pgrp->pins[j].muxio, pgrp->pins[j].pinval,
  440. pgrp->pins[j].drive);
  441. }
  442. configASSERT(pgrp->pin_mux_num <= MAX_PIN_MUX_GROUP);
  443. for(j = 0; j < pgrp->pin_mux_num; j++){
  444. if (pgrp->pin_mux[j].mux_reg) {
  445. reg = readl(pgrp->pin_mux[j].mux_reg);
  446. reg &= ~(pgrp->pin_mux[j].mux_mask << pgrp->pin_mux[j].mux_offset);
  447. reg |= pgrp->pin_mux[j].mux_val << pgrp->pin_mux[j].mux_offset;
  448. writel(reg, pgrp->pin_mux[j].mux_reg);
  449. }
  450. }
  451. break;
  452. }
  453. }
  454. for (i = 0; i < MCU_GROUP_NUM; i++) {
  455. pgrp = &mcu_pin_groups[i];
  456. if (pgrp->groupid == groupid) {
  457. configASSERT(pgrp->pins_num <= MAX_PINS_PER_GROUP);
  458. for (j = 0; j < pgrp->pins_num; j++){
  459. mcu_pinctrl_set_pin(pgrp->pins[j].muxio, pgrp->pins[j].pinval,
  460. pgrp->pins[j].drive);
  461. }
  462. configASSERT(pgrp->pin_mux_num <= MAX_PIN_MUX_GROUP);
  463. for(j = 0; j < pgrp->pin_mux_num; j++){
  464. if (pgrp->pin_mux[j].mux_reg) {
  465. reg = readl(pgrp->pin_mux[j].mux_reg);
  466. reg &= ~(pgrp->pin_mux[j].mux_mask << pgrp->pin_mux[j].mux_offset);
  467. reg |= pgrp->pin_mux[j].mux_val << pgrp->pin_mux[j].mux_offset;
  468. writel(reg, pgrp->pin_mux[j].mux_reg);
  469. }
  470. }
  471. break;
  472. }
  473. }
  474. }
  475. void vPinctrlSetup(void)
  476. {
  477. #ifdef SDMMC0_SUPPORT
  478. pinctrl_set_group(PGRP_SDMMC0);
  479. #endif
  480. #ifdef SDMMC1_SUPPORT
  481. pinctrl_set_group(PGRP_SDMMC1);
  482. #endif
  483. #ifdef DW_I2C0_SUPPORT
  484. pinctrl_set_group(PGRP_I2C0);
  485. #endif
  486. #ifdef DW_I2C1_SUPPORT
  487. pinctrl_set_group(PGRP_I2C1);
  488. #endif
  489. #ifdef PWM_CAP_SUPPORT
  490. pinctrl_set_group(PGRP_PWM2_IN);
  491. #endif
  492. #ifdef DW_SPI0_SUPPORT
  493. pinctrl_set_group(PGRP_SPI0);
  494. #endif
  495. #ifdef DW_SPI2_SUPPORT
  496. pinctrl_set_group(PGRP_SPI2);
  497. #endif
  498. #ifdef EC_SPI1_SUPPORT
  499. pinctrl_set_group(PGRP_SPI1);
  500. #endif
  501. #ifdef REMOTE_SUPPORT
  502. pinctrl_set_group(PGRP_RCRT);
  503. #endif
  504. #if LCD_INTERFACE_TYPE == LCD_INTERFACE_TTL
  505. pinctrl_set_group(PGRP_LCD_TTL_CH0);
  506. #endif
  507. #ifdef VIDEO_DECODER_MIPI
  508. pinctrl_set_group(PGRP_ITU_CH0_MIPI);
  509. #else
  510. pinctrl_set_group(PGRP_ITU_CH0);
  511. #endif
  512. #ifdef AUDIO_REPLAY
  513. #if (AUDIO_REPLAY_I2S == I2S_ID1)
  514. pinctrl_set_group(PGRP_I2S1_PLAY);
  515. #else
  516. pinctrl_set_group(PGRP_I2S0_PLAY);
  517. #endif
  518. #endif
  519. #ifdef AUDIO_RECORD
  520. #if (AUDIO_RECORD_I2S == I2S_ID1)
  521. pinctrl_set_group(PGRP_I2S1_RECORD);
  522. #else
  523. pinctrl_set_group(PGRP_I2S0_RECORD);
  524. #endif
  525. #endif
  526. if(UART_DEBUG_PORT == UART_ID0)
  527. pinctrl_set_group(PGRP_UART0);
  528. else if (UART_DEBUG_PORT == UART_ID1)
  529. pinctrl_set_group(PGRP_UART1);
  530. else if (UART_DEBUG_PORT == UART_ID2)
  531. pinctrl_set_group(PGRP_UART2);
  532. else if (UART_DEBUG_PORT == UART_ID3)
  533. pinctrl_set_group(PGRP_UART3);
  534. #ifdef ETH_SUPPORT
  535. pinctrl_set_group(PGRP_ETH);
  536. #endif
  537. }