ioport.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * (C) Copyright 2000
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <mpc8xx.h>
  25. #include <asm/8xx_immap.h>
  26. #include "ioport.h"
  27. #if 0
  28. #define IOPORT_DEBUG
  29. #endif
  30. #ifdef IOPORT_DEBUG
  31. #define PRINTF(fmt,args...) printf (fmt ,##args)
  32. #else
  33. #define PRINTF(fmt,args...)
  34. #endif
  35. /*
  36. * The ioport configuration table.
  37. */
  38. const mpc8xx_iop_conf_t iop_conf_tab[NUM_PORTS][PORT_BITS] = {
  39. /*
  40. * Port A configuration
  41. * Pin Signal Type Active Initial state
  42. * PA7 fpgaProgramLowOut Out Low High
  43. */
  44. { /* conf ppar psor pdir podr pdat pint function */
  45. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* No pin */
  46. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* No pin */
  47. /* PA15 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  48. /* PA14 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  49. /* PA13 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  50. /* PA12 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  51. /* PA11 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  52. /* PA10 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  53. /* PA9 */ { 1, 0, 0, 1, 0, 0, 0 }, /* grn bicolor LED 1*/
  54. /* PA8 */ { 1, 0, 0, 1, 0, 0, 0 }, /* red bicolor LED 1*/
  55. /* PA7 */ { 1, 0, 0, 1, 0, 1, 0 }, /* fpgaProgramLow */
  56. /* PA6 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  57. /* PA5 */ { 1, 0, 0, 1, 0, 0, 0 }, /* grn bicolor LED 0*/
  58. /* PA4 */ { 1, 0, 0, 1, 0, 0, 0 }, /* red bicolor LED 0*/
  59. /* PA3 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  60. /* PA2 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  61. /* PA1 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  62. /* PA0 */ { 0, 0, 0, 0, 0, 0, 0 } /* */
  63. },
  64. /*
  65. * Pin Signal Type Active Initial state
  66. * PB14 docBusyLowIn In Low X
  67. * PB15 gpio1Sig Out High Low
  68. * PB16 fpgaDoneBi In High X
  69. * PB17 swBitOkLowOut Out Low Low
  70. * PB19 speakerVolSig Out/Hi-Z High/Low High (Hi-Z)
  71. * PB22 fpgaInitLowBi In Low X
  72. * PB23 batteryOkSig In High X
  73. */
  74. { /* conf ppar psor pdir podr pdat pint function */
  75. /* PB31 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  76. /* PB30 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  77. /* PB29 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  78. /* PB28 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  79. /* PB27 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  80. /* PB26 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  81. /* PB25 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  82. /* PB24 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  83. /* PB23 */ { 1, 0, 0, 0, 0, 0, 0 }, /* batteryOk */
  84. /* PB22 */ { 1, 0, 0, 0, 0, 0, 0 }, /* fpgaInitLowBi */
  85. /* PB21 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  86. /* PB20 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  87. /* PB19 */ { 1, 0, 0, 1, 1, 1, 0 }, /* speakerVol */
  88. /* PB18 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  89. /* PB17 */ { 1, 0, 0, 1, 0, 0, 0 }, /* swBitOkLow */
  90. /* PB16 */ { 1, 0, 0, 0, 0, 0, 0 }, /* fpgaDone */
  91. /* PB15 */ { 1, 0, 0, 1, 0, 0, 0 }, /* gpio1 */
  92. /* PB14 */ { 1, 0, 0, 0, 0, 0, 0 } /* docBusyLow */
  93. },
  94. /*
  95. * Pin Signal Type Active Initial state
  96. * PC4 i2cBus1EnSig Out High High
  97. * PC5 i2cBus2EnSig Out High High
  98. * PC6 gpio0Sig Out High Low
  99. * PC8 i2cBus3EnSig Out High High
  100. * PC10 i2cBus4EnSig Out High High
  101. * PC11 fpgaResetLowOut Out Low High
  102. * PC12 systemBitOkIn In High X
  103. * PC15 selfDreqLow In Low X
  104. */
  105. { /* conf ppar psor pdir podr pdat pint function */
  106. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  107. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  108. /* PC15 */ { 1, 0, 0, 0, 0, 0, 0 }, /* selfDreqLowIn */
  109. /* PC14 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  110. /* PC13 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  111. /* PC12 */ { 1, 0, 0, 0, 0, 0, 0 }, /* systemBitOkIn */
  112. /* PC11 */ { 1, 0, 0, 1, 0, 1, 0 }, /* fpgaResetLowOut */
  113. /* PC10 */ { 1, 0, 0, 1, 0, 1, 0 }, /* i2cBus4EnSig */
  114. /* PC9 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  115. /* PC8 */ { 1, 0, 0, 1, 0, 1, 0 }, /* i2cBus3EnSig */
  116. /* PC7 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  117. /* PC6 */ { 1, 0, 0, 1, 0, 1, 0 }, /* gpio0 */
  118. /* PC5 */ { 1, 0, 0, 1, 0, 1, 0 }, /* i2cBus2EnSig */
  119. /* PC4 */ { 1, 0, 0, 1, 0, 1, 0 }, /* i2cBus1EnSig */
  120. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  121. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  122. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  123. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 } /* */
  124. },
  125. /* Port D configuration */
  126. { /* conf ppar psor pdir podr pdat pint function */
  127. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  128. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  129. /* PD15 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  130. /* PD14 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  131. /* PD13 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  132. /* PD12 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  133. /* PD11 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  134. /* PD10 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  135. /* PD9 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  136. /* PD8 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  137. /* PD7 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  138. /* PD6 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  139. /* PD5 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  140. /* PD4 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  141. /* PD3 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  142. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  143. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  144. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 } /* */
  145. }
  146. };
  147. /*
  148. * Configure the MPC8XX I/O ports per the ioport configuration table
  149. * (taken from ./cpu/mpc8260/cpu_init.c)
  150. */
  151. void
  152. config_mpc8xx_ioports(volatile immap_t *immr)
  153. {
  154. int portnum;
  155. for (portnum = 0; portnum < NUM_PORTS; portnum++) {
  156. uint pmsk = 0, ppar = 0, psor = 0, pdir = 0;
  157. uint podr = 0, pdat = 0, pint = 0;
  158. uint msk = 1;
  159. mpc8xx_iop_conf_t *iopc = (mpc8xx_iop_conf_t *)&iop_conf_tab[portnum][0];
  160. mpc8xx_iop_conf_t *eiopc = iopc + PORT_BITS;
  161. /*
  162. * For all ports except port B, ignore the two don't care entries
  163. * in the configuration tables.
  164. */
  165. if (portnum != 1) {
  166. iopc = (mpc8xx_iop_conf_t *)&iop_conf_tab[portnum][2];
  167. }
  168. /*
  169. * NOTE: index 0 refers to pin 17, index 17 refers to pin 0
  170. */
  171. while (iopc < eiopc) {
  172. if (iopc->conf) {
  173. pmsk |= msk;
  174. if (iopc->ppar) ppar |= msk;
  175. if (iopc->psor) psor |= msk;
  176. if (iopc->pdir) pdir |= msk;
  177. if (iopc->podr) podr |= msk;
  178. if (iopc->pdat) pdat |= msk;
  179. if (iopc->pint) pint |= msk;
  180. }
  181. msk <<= 1;
  182. iopc++;
  183. }
  184. PRINTF("%s:%d:\n portnum=%d ", __FUNCTION__, __LINE__, portnum);
  185. #ifdef IOPORT_DEBUG
  186. switch(portnum) {
  187. case 0: printf("(A)\n"); break;
  188. case 1: printf("(B)\n"); break;
  189. case 2: printf("(C)\n"); break;
  190. case 3: printf("(D)\n"); break;
  191. default: printf("(?)\n"); break;
  192. }
  193. #endif
  194. PRINTF(" ppar=0x%.8x pdir=0x%.8x podr=0x%.8x\n"
  195. " pdat=0x%.8x psor=0x%.8x pint=0x%.8x pmsk=0x%.8x\n",
  196. ppar, pdir, podr, pdat, psor, pint, pmsk);
  197. /*
  198. * Have to handle the ioports on a port-by-port basis since there
  199. * are three different flavors.
  200. */
  201. if (pmsk != 0) {
  202. uint tpmsk = ~pmsk;
  203. if (0 == portnum) { /* port A */
  204. immr->im_ioport.iop_papar &= tpmsk;
  205. immr->im_ioport.iop_padat =
  206. (immr->im_ioport.iop_padat & tpmsk) | pdat;
  207. immr->im_ioport.iop_padir =
  208. (immr->im_ioport.iop_padir & tpmsk) | pdir;
  209. immr->im_ioport.iop_paodr =
  210. (immr->im_ioport.iop_paodr & tpmsk) | podr;
  211. immr->im_ioport.iop_papar |= ppar;
  212. }
  213. else if (1 == portnum) { /* port B */
  214. immr->im_cpm.cp_pbpar &= tpmsk;
  215. immr->im_cpm.cp_pbdat = (immr->im_cpm.cp_pbdat & tpmsk) | pdat;
  216. immr->im_cpm.cp_pbdir = (immr->im_cpm.cp_pbdir & tpmsk) | pdir;
  217. immr->im_cpm.cp_pbodr = (immr->im_cpm.cp_pbodr & tpmsk) | podr;
  218. immr->im_cpm.cp_pbpar |= ppar;
  219. }
  220. else if (2 == portnum) { /* port C */
  221. immr->im_ioport.iop_pcpar &= tpmsk;
  222. immr->im_ioport.iop_pcdat =
  223. (immr->im_ioport.iop_pcdat & tpmsk) | pdat;
  224. immr->im_ioport.iop_pcdir =
  225. (immr->im_ioport.iop_pcdir & tpmsk) | pdir;
  226. immr->im_ioport.iop_pcint =
  227. (immr->im_ioport.iop_pcint & tpmsk) | pint;
  228. immr->im_ioport.iop_pcso =
  229. (immr->im_ioport.iop_pcso & tpmsk) | psor;
  230. immr->im_ioport.iop_pcpar |= ppar;
  231. }
  232. else if (3 == portnum) { /* port D */
  233. immr->im_ioport.iop_pdpar &= tpmsk;
  234. immr->im_ioport.iop_pddat =
  235. (immr->im_ioport.iop_pddat & tpmsk) | pdat;
  236. immr->im_ioport.iop_pddir =
  237. (immr->im_ioport.iop_pddir & tpmsk) | pdir;
  238. immr->im_ioport.iop_pdpar |= ppar;
  239. }
  240. }
  241. }
  242. PRINTF("%s:%d: Port A:\n papar=0x%.4x padir=0x%.4x"
  243. " paodr=0x%.4x\n padat=0x%.4x\n", __FUNCTION__, __LINE__,
  244. immr->im_ioport.iop_papar, immr->im_ioport.iop_padir,
  245. immr->im_ioport.iop_paodr, immr->im_ioport.iop_padat);
  246. PRINTF("%s:%d: Port B:\n pbpar=0x%.8x pbdir=0x%.8x"
  247. " pbodr=0x%.8x\n pbdat=0x%.8x\n", __FUNCTION__, __LINE__,
  248. immr->im_cpm.cp_pbpar, immr->im_cpm.cp_pbdir,
  249. immr->im_cpm.cp_pbodr, immr->im_cpm.cp_pbdat);
  250. PRINTF("%s:%d: Port C:\n pcpar=0x%.4x pcdir=0x%.4x"
  251. " pcdat=0x%.4x\n pcso=0x%.4x pcint=0x%.4x\n ",
  252. __FUNCTION__, __LINE__, immr->im_ioport.iop_pcpar,
  253. immr->im_ioport.iop_pcdir, immr->im_ioport.iop_pcdat,
  254. immr->im_ioport.iop_pcso, immr->im_ioport.iop_pcint);
  255. PRINTF("%s:%d: Port D:\n pdpar=0x%.4x pddir=0x%.4x"
  256. " pddat=0x%.4x\n", __FUNCTION__, __LINE__,
  257. immr->im_ioport.iop_pdpar, immr->im_ioport.iop_pddir,
  258. immr->im_ioport.iop_pddat);
  259. }
  260. /* vim: set ts=4 sw=4 tw=78: */