top.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * (C) Copyright 2008 Stefan Roese <sr@denx.de>, DENX Software Engineering
  3. *
  4. * Copyright (C) 2006 Micronas GmbH
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  19. * MA 02111-1307 USA
  20. */
  21. #include <common.h>
  22. #include "vct.h"
  23. typedef union _TOP_PINMUX_t
  24. {
  25. u32 reg;
  26. struct {
  27. u32 res : 24; /* reserved */
  28. u32 drive : 2; /* Driver strength */
  29. u32 slew : 1; /* Slew rate */
  30. u32 strig : 1; /* Schmitt trigger input*/
  31. u32 pu_pd : 2; /* Pull up/ pull down */
  32. u32 funsel : 2; /* Pin function */
  33. } Bits;
  34. } TOP_PINMUX_t;
  35. #if defined(CONFIG_VCT_PREMIUM) || defined(CONFIG_VCT_PLATINUM)
  36. static TOP_PINMUX_t top_read_pin(int pin)
  37. {
  38. TOP_PINMUX_t reg;
  39. switch (pin) {
  40. case 2:
  41. case 3:
  42. case 6:
  43. case 9:
  44. reg.reg = 0xdeadbeef;
  45. break;
  46. case 4:
  47. reg.reg = reg_read(FWSRAM_TOP_SCL_CFG(FWSRAM_BASE));
  48. break;
  49. case 5:
  50. reg.reg = reg_read(FWSRAM_TOP_SDA_CFG(FWSRAM_BASE));
  51. break;
  52. case 7:
  53. reg.reg = reg_read(FWSRAM_TOP_TDO_CFG(FWSRAM_BASE));
  54. break;
  55. case 8:
  56. reg.reg = reg_read(FWSRAM_TOP_GPIO2_0_CFG(FWSRAM_BASE));
  57. break;
  58. case 10:
  59. case 11:
  60. case 12:
  61. case 13:
  62. case 14:
  63. case 15:
  64. case 16:
  65. reg.reg = reg_read(FWSRAM_BASE + FWSRAM_TOP_GPIO2_1_CFG_OFFS +
  66. ((pin - 10) * 4));
  67. break;
  68. default:
  69. reg.reg = reg_read(TOP_BASE + (pin * 4));
  70. break;
  71. }
  72. return reg;
  73. }
  74. static void top_write_pin(int pin, TOP_PINMUX_t reg)
  75. {
  76. switch (pin) {
  77. case 4:
  78. reg_write(FWSRAM_TOP_SCL_CFG(FWSRAM_BASE), reg.reg);
  79. break;
  80. case 5:
  81. reg_write(FWSRAM_TOP_SDA_CFG(FWSRAM_BASE), reg.reg);
  82. break;
  83. case 7:
  84. reg_write(FWSRAM_TOP_TDO_CFG(FWSRAM_BASE), reg.reg);
  85. break;
  86. case 8:
  87. reg_write(FWSRAM_TOP_GPIO2_0_CFG(FWSRAM_BASE), reg.reg);
  88. break;
  89. case 10:
  90. case 11:
  91. case 12:
  92. case 13:
  93. case 14:
  94. case 15:
  95. case 16:
  96. reg_write(FWSRAM_BASE + FWSRAM_TOP_GPIO2_1_CFG_OFFS +
  97. ((pin - 10) * 4), reg.reg);
  98. break;
  99. default:
  100. reg_write(TOP_BASE + (pin * 4), reg.reg);
  101. break;
  102. }
  103. }
  104. int top_set_pin(int pin, int func)
  105. {
  106. TOP_PINMUX_t reg;
  107. /* check global range */
  108. if ((pin < 0) || (pin > 170) || (func < 0) || (func > 3))
  109. return -1; /* pin number or function out of valid range */
  110. /* check undefined values; */
  111. if ((pin == 2) || (pin == 3) || (pin == 6) || (pin == 9))
  112. return -1; /* pin number out of valid range */
  113. reg = top_read_pin(pin);
  114. reg.Bits.funsel = func;
  115. top_write_pin(pin, reg);
  116. return 0;
  117. }
  118. #endif
  119. #if defined(CONFIG_VCT_PLATINUMAVC)
  120. int top_set_pin(int pin, int func)
  121. {
  122. TOP_PINMUX_t reg;
  123. /* check global range */
  124. if ((pin < 0) || (pin > 158))
  125. return -1; /* pin number or function out of valid range */
  126. reg.reg = reg_read(TOP_BASE + (pin * 4));
  127. reg.Bits.funsel = func;
  128. reg_write(TOP_BASE + (pin * 4), reg.reg);
  129. return 0;
  130. }
  131. #endif
  132. void vct_pin_mux_initialize(void)
  133. {
  134. #if defined(CONFIG_VCT_PREMIUM) || defined(CONFIG_VCT_PLATINUM)
  135. top_set_pin(34, 01); /* EBI_CS0 */
  136. top_set_pin(33, 01); /* EBI_CS1 */
  137. top_set_pin(32, 01); /* EBI_CS2 */
  138. top_set_pin(100, 02); /* EBI_CS3 */
  139. top_set_pin(101, 02); /* EBI_CS4 */
  140. top_set_pin(102, 02); /* EBI_CS5 */
  141. top_set_pin(103, 02); /* EBI_CS6 */
  142. top_set_pin(104, 02); /* EBI_CS7 top_set_pin(104,03); EBI_GENIO3 */
  143. top_set_pin(35, 01); /* EBI_ALE */
  144. top_set_pin(36, 01); /* EBI_ADDR15 */
  145. top_set_pin(37, 01); /* EBI_ADDR14 top_set_pin(78,03); EBI_ADDR14 */
  146. top_set_pin(38, 01); /* EBI_ADDR13 */
  147. top_set_pin(39, 01); /* EBI_ADDR12 */
  148. top_set_pin(40, 01); /* EBI_ADDR11 */
  149. top_set_pin(41, 01); /* EBI_ADDR10 */
  150. top_set_pin(42, 01); /* EBI_ADDR9 */
  151. top_set_pin(43, 01); /* EBI_ADDR8 */
  152. top_set_pin(44, 01); /* EBI_ADDR7 */
  153. top_set_pin(45, 01); /* EBI_ADDR6 */
  154. top_set_pin(46, 01); /* EBI_ADDR5 */
  155. top_set_pin(47, 01); /* EBI_ADDR4 */
  156. top_set_pin(48, 01); /* EBI_ADDR3 */
  157. top_set_pin(49, 01); /* EBI_ADDR2 */
  158. top_set_pin(50, 01); /* EBI_ADDR1 */
  159. top_set_pin(51, 01); /* EBI_ADDR0 */
  160. top_set_pin(52, 01); /* EBI_DIR */
  161. top_set_pin(53, 01); /* EBI_DAT15 top_set_pin(81,01); EBI_DAT15 */
  162. top_set_pin(54, 01); /* EBI_DAT14 top_set_pin(82,01); EBI_DAT14 */
  163. top_set_pin(55, 01); /* EBI_DAT13 top_set_pin(83,01); EBI_DAT13 */
  164. top_set_pin(56, 01); /* EBI_DAT12 top_set_pin(84,01); EBI_DAT12 */
  165. top_set_pin(57, 01); /* EBI_DAT11 top_set_pin(85,01); EBI_DAT11 */
  166. top_set_pin(58, 01); /* EBI_DAT10 top_set_pin(86,01); EBI_DAT10 */
  167. top_set_pin(59, 01); /* EBI_DAT9 top_set_pin(87,01); EBI_DAT9 */
  168. top_set_pin(60, 01); /* EBI_DAT8 top_set_pin(88,01); EBI_DAT8 */
  169. top_set_pin(61, 01); /* EBI_DAT7 */
  170. top_set_pin(62, 01); /* EBI_DAT6 */
  171. top_set_pin(63, 01); /* EBI_DAT5 */
  172. top_set_pin(64, 01); /* EBI_DAT4 */
  173. top_set_pin(65, 01); /* EBI_DAT3 */
  174. top_set_pin(66, 01); /* EBI_DAT2 */
  175. top_set_pin(67, 01); /* EBI_DAT1 */
  176. top_set_pin(68, 01); /* EBI_DAT0 */
  177. top_set_pin(69, 01); /* EBI_IORD */
  178. top_set_pin(70, 01); /* EBI_IOWR */
  179. top_set_pin(71, 01); /* EBI_WE */
  180. top_set_pin(72, 01); /* EBI_OE */
  181. top_set_pin(73, 01); /* EBI_IORDY */
  182. top_set_pin(95, 02); /* EBI_EBI_DMACK*/
  183. top_set_pin(112, 02); /* EBI_IRQ0 */
  184. top_set_pin(111, 02); /* EBI_IRQ1 top_set_pin(111,03); EBI_DMARQ */
  185. top_set_pin(107, 02); /* EBI_IRQ2 */
  186. top_set_pin(108, 02); /* EBI_IRQ3 */
  187. top_set_pin(30, 01); /* EBI_GENIO1 top_set_pin(99,03); EBI_GENIO1 */
  188. top_set_pin(31, 01); /* EBI_GENIO2 top_set_pin(98,03); EBI_GENIO2 */
  189. top_set_pin(105, 02); /* EBI_GENIO3 top_set_pin(104,03); EBI_GENIO3 */
  190. top_set_pin(106, 02); /* EBI_GENIO4 top_set_pin(144,02); EBI_GENIO4 */
  191. top_set_pin(109, 02); /* EBI_GENIO5 top_set_pin(142,02); EBI_GENIO5 */
  192. top_set_pin(110, 02); /* EBI_BURST_CLK */
  193. #endif
  194. #if defined(CONFIG_VCT_PLATINUMAVC)
  195. top_set_pin(19, 01); /* EBI_CS0 */
  196. top_set_pin(18, 01); /* EBI_CS1 */
  197. top_set_pin(17, 01); /* EBI_CS2 */
  198. top_set_pin(92, 02); /* EBI_CS3 */
  199. top_set_pin(93, 02); /* EBI_CS4 */
  200. top_set_pin(95, 02); /* EBI_CS6 */
  201. top_set_pin(96, 02); /* EBI_CS7 top_set_pin(104,03); EBI_GENIO3 */
  202. top_set_pin(20, 01); /* EBI_ALE */
  203. top_set_pin(21, 01); /* EBI_ADDR15 */
  204. top_set_pin(22, 01); /* EBI_ADDR14 top_set_pin(78,03); EBI_ADDR14 */
  205. top_set_pin(23, 01); /* EBI_ADDR13 */
  206. top_set_pin(24, 01); /* EBI_ADDR12 */
  207. top_set_pin(25, 01); /* EBI_ADDR11 */
  208. top_set_pin(26, 01); /* EBI_ADDR10 */
  209. top_set_pin(27, 01); /* EBI_ADDR9 */
  210. top_set_pin(28, 01); /* EBI_ADDR8 */
  211. top_set_pin(29, 01); /* EBI_ADDR7 */
  212. top_set_pin(30, 01); /* EBI_ADDR6 */
  213. top_set_pin(31, 01); /* EBI_ADDR5 */
  214. top_set_pin(32, 01); /* EBI_ADDR4 */
  215. top_set_pin(33, 01); /* EBI_ADDR3 */
  216. top_set_pin(34, 01); /* EBI_ADDR2 */
  217. top_set_pin(35, 01); /* EBI_ADDR1 */
  218. top_set_pin(36, 01); /* EBI_ADDR0 */
  219. top_set_pin(37, 01); /* EBI_DIR */
  220. top_set_pin(38, 01); /* EBI_DAT15 top_set_pin(81,01); EBI_DAT15 */
  221. top_set_pin(39, 01); /* EBI_DAT14 top_set_pin(82,01); EBI_DAT14 */
  222. top_set_pin(40, 01); /* EBI_DAT13 top_set_pin(83,01); EBI_DAT13 */
  223. top_set_pin(41, 01); /* EBI_DAT12 top_set_pin(84,01); EBI_DAT12 */
  224. top_set_pin(42, 01); /* EBI_DAT11 top_set_pin(85,01); EBI_DAT11 */
  225. top_set_pin(43, 01); /* EBI_DAT10 top_set_pin(86,01); EBI_DAT10 */
  226. top_set_pin(44, 01); /* EBI_DAT9 top_set_pin(87,01); EBI_DAT9 */
  227. top_set_pin(45, 01); /* EBI_DAT8 top_set_pin(88,01); EBI_DAT8 */
  228. top_set_pin(46, 01); /* EBI_DAT7 */
  229. top_set_pin(47, 01); /* EBI_DAT6 */
  230. top_set_pin(48, 01); /* EBI_DAT5 */
  231. top_set_pin(49, 01); /* EBI_DAT4 */
  232. top_set_pin(50, 01); /* EBI_DAT3 */
  233. top_set_pin(51, 01); /* EBI_DAT2 */
  234. top_set_pin(52, 01); /* EBI_DAT1 */
  235. top_set_pin(53, 01); /* EBI_DAT0 */
  236. top_set_pin(54, 01); /* EBI_IORD */
  237. top_set_pin(55, 01); /* EBI_IOWR */
  238. top_set_pin(56, 01); /* EBI_WE */
  239. top_set_pin(57, 01); /* EBI_OE */
  240. top_set_pin(58, 01); /* EBI_IORDY */
  241. top_set_pin(87, 02); /* EBI_EBI_DMACK*/
  242. top_set_pin(106, 02); /* EBI_IRQ0 */
  243. top_set_pin(105, 02); /* EBI_IRQ1 top_set_pin(111,03); EBI_DMARQ */
  244. top_set_pin(101, 02); /* EBI_IRQ2 */
  245. top_set_pin(102, 02); /* EBI_IRQ3 */
  246. top_set_pin(15, 01); /* EBI_GENIO1 top_set_pin(99,03); EBI_GENIO1 */
  247. top_set_pin(16, 01); /* EBI_GENIO2 top_set_pin(98,03); EBI_GENIO2 */
  248. top_set_pin(99, 02); /* EBI_GENIO3 top_set_pin(104,03); EBI_GENIO3 */
  249. top_set_pin(100, 02); /* EBI_GENIO4 top_set_pin(144,02); EBI_GENIO4 */
  250. top_set_pin(103, 02); /* EBI_GENIO5 top_set_pin(142,02); EBI_GENIO5 */
  251. top_set_pin(104, 02); /* EBI_BURST_CLK */
  252. #endif
  253. /* I2C: Configure I2C-2 as GPIO to enable soft-i2c */
  254. top_set_pin(0, 2); /* SCL2 on GPIO 11 */
  255. top_set_pin(1, 2); /* SDA2 on GPIO 10 */
  256. /* UART pins */
  257. #if defined(CONFIG_VCT_PREMIUM) || defined(CONFIG_VCT_PLATINUM)
  258. top_set_pin(141, 1);
  259. top_set_pin(143, 1);
  260. #endif
  261. #if defined(CONFIG_VCT_PLATINUMAVC)
  262. top_set_pin(107, 1);
  263. top_set_pin(109, 1);
  264. #endif
  265. }