ioport.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. * PA1 fpgaCoreVoltageFailLow In Low N/A
  44. */
  45. { /* conf ppar psor pdir podr pdat pint function */
  46. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* No pin */
  47. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* No pin */
  48. /* PA15 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  49. /* PA14 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  50. /* PA13 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  51. /* PA12 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  52. /* PA11 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  53. /* PA10 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  54. /* PA9 */ { 1, 0, 0, 1, 0, 0, 0 }, /* grn bicolor LED 1*/
  55. /* PA8 */ { 1, 0, 0, 1, 0, 0, 0 }, /* red bicolor LED 1*/
  56. /* PA7 */ { 1, 0, 0, 1, 0, 1, 0 }, /* fpgaProgramLow */
  57. /* PA6 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  58. /* PA5 */ { 1, 0, 0, 1, 0, 0, 0 }, /* grn bicolor LED 0*/
  59. /* PA4 */ { 1, 0, 0, 1, 0, 0, 0 }, /* red bicolor LED 0*/
  60. /* PA3 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  61. /* PA2 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  62. #if !defined(CONFIG_SC)
  63. /* PA1 */ { 1, 0, 0, 0, 0, 0, 0 }, /* fpgaCoreVoltageFail*/
  64. #else
  65. /* PA1 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  66. #endif
  67. /* PA0 */ { 0, 0, 0, 0, 0, 0, 0 } /* */
  68. },
  69. /*
  70. * Port B configuration
  71. * Pin Signal Type Active Initial state
  72. * PB14 docBusyLowIn In Low X
  73. * PB15 gpio1Sig Out High Low
  74. * PB16 fpgaDoneBi In High X
  75. * PB17 swBitOkLowOut Out Low High
  76. * PB19 speakerVolSig Out/Hi-Z High/Low High (Hi-Z)
  77. * PB22 fpgaInitLowBi In Low X
  78. * PB23 batteryOkSig In High X
  79. * PB31 pulseCatcherClr Out High 0
  80. */
  81. { /* conf ppar psor pdir podr pdat pint function */
  82. #if !defined(CONFIG_SC)
  83. /* PB31 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  84. #else
  85. /* PB31 */ { 1, 0, 0, 1, 0, 0, 0 }, /* pulseCatcherClr */
  86. #endif
  87. /* PB30 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  88. /* PB29 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  89. /* PB28 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  90. /* PB27 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  91. /* PB26 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  92. /* PB25 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  93. /* PB24 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  94. #if !defined(CONFIG_SC)
  95. /* PB23 */ { 1, 0, 0, 0, 0, 0, 0 }, /* batteryOk */
  96. #else
  97. /* PB23 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  98. #endif
  99. /* PB22 */ { 1, 0, 0, 0, 0, 0, 0 }, /* fpgaInitLowBi */
  100. /* PB21 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  101. /* PB20 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  102. #if !defined(CONFIG_SC)
  103. /* PB19 */ { 1, 0, 0, 1, 1, 1, 0 }, /* speakerVol */
  104. #else
  105. /* PB19 */ { 0, 0, 0, 1, 1, 1, 0 }, /* */
  106. #endif
  107. /* PB18 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  108. /* PB17 */ { 1, 0, 0, 1, 0, 1, 0 }, /* swBitOkLow */
  109. /* PB16 */ { 1, 0, 0, 0, 0, 0, 0 }, /* fpgaDone */
  110. /* PB15 */ { 1, 0, 0, 1, 0, 0, 0 }, /* gpio1 */
  111. #if !defined(CONFIG_SC)
  112. /* PB14 */ { 1, 0, 0, 0, 0, 0, 0 } /* docBusyLow */
  113. #else
  114. /* PB14 */ { 0, 0, 0, 0, 0, 0, 0 } /* */
  115. #endif
  116. },
  117. /*
  118. * Port C configuration
  119. * Pin Signal Type Active Initial state
  120. * PC4 i2cBus1EnSig Out High High
  121. * PC5 i2cBus2EnSig Out High High
  122. * PC6 gpio0Sig Out High Low
  123. * PC8 i2cBus3EnSig Out High High
  124. * PC10 i2cBus4EnSig Out High High
  125. * PC11 fpgaResetLowOut Out Low High
  126. * PC12 systemBitOkIn In High X
  127. * PC15 selfDreqLow In Low X
  128. */
  129. { /* conf ppar psor pdir podr pdat pint function */
  130. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  131. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  132. /* PC15 */ { 1, 0, 0, 0, 0, 0, 0 }, /* selfDreqLowIn */
  133. /* PC14 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  134. /* PC13 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  135. #if !defined(CONFIG_SC)
  136. /* PC12 */ { 1, 0, 0, 0, 0, 0, 0 }, /* systemBitOkIn */
  137. #else
  138. /* PC12 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  139. #endif
  140. /* PC11 */ { 1, 0, 0, 1, 0, 1, 0 }, /* fpgaResetLowOut */
  141. #if !defined(CONFIG_SC)
  142. /* PC10 */ { 1, 0, 0, 1, 0, 1, 0 }, /* i2cBus4EnSig */
  143. #else
  144. /* PC10 */ { 0, 0, 0, 1, 0, 1, 0 }, /* */
  145. #endif
  146. /* PC9 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  147. #if !defined(CONFIG_SC)
  148. /* PC8 */ { 1, 0, 0, 1, 0, 1, 0 }, /* i2cBus3EnSig */
  149. #else
  150. /* PC8 */ { 0, 0, 0, 1, 0, 1, 0 }, /* */
  151. #endif
  152. /* PC7 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  153. /* PC6 */ { 1, 0, 0, 1, 0, 1, 0 }, /* gpio0 */
  154. #if !defined(CONFIG_SC)
  155. /* PC5 */ { 1, 0, 0, 1, 0, 1, 0 }, /* i2cBus2EnSig */
  156. /* PC4 */ { 1, 0, 0, 1, 0, 1, 0 }, /* i2cBus1EnSig */
  157. #else
  158. /* PC5 */ { 0, 0, 0, 1, 0, 1, 0 }, /* */
  159. /* PC4 */ { 0, 0, 0, 1, 0, 1, 0 }, /* */
  160. #endif
  161. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  162. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  163. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  164. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 } /* */
  165. },
  166. /*
  167. * Port D configuration
  168. */
  169. { /* conf ppar psor pdir podr pdat pint function */
  170. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  171. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  172. /* PD15 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  173. /* PD14 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  174. /* PD13 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  175. /* PD12 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  176. /* PD11 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  177. /* PD10 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  178. /* PD9 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  179. /* PD8 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  180. /* PD7 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  181. /* PD6 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  182. /* PD5 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  183. /* PD4 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  184. /* PD3 */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  185. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  186. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 }, /* */
  187. /* N/A */ { 0, 0, 0, 0, 0, 0, 0 } /* */
  188. }
  189. };
  190. /*
  191. * Configure the MPC8XX I/O ports per the ioport configuration table
  192. * (taken from ./cpu/mpc8260/cpu_init.c)
  193. */
  194. void config_mpc8xx_ioports (volatile immap_t * immr)
  195. {
  196. int portnum;
  197. for (portnum = 0; portnum < NUM_PORTS; portnum++) {
  198. uint pmsk = 0, ppar = 0, psor = 0, pdir = 0;
  199. uint podr = 0, pdat = 0, pint = 0;
  200. uint msk = 1;
  201. mpc8xx_iop_conf_t *iopc =
  202. (mpc8xx_iop_conf_t *) & iop_conf_tab[portnum][0];
  203. mpc8xx_iop_conf_t *eiopc = iopc + PORT_BITS;
  204. /*
  205. * For all ports except port B, ignore the two don't care entries
  206. * in the configuration tables.
  207. */
  208. if (portnum != 1) {
  209. iopc = (mpc8xx_iop_conf_t *) &
  210. iop_conf_tab[portnum][2];
  211. }
  212. /*
  213. * NOTE: index 0 refers to pin 17, index 17 refers to pin 0
  214. */
  215. while (iopc < eiopc) {
  216. if (iopc->conf) {
  217. pmsk |= msk;
  218. if (iopc->ppar)
  219. ppar |= msk;
  220. if (iopc->psor)
  221. psor |= msk;
  222. if (iopc->pdir)
  223. pdir |= msk;
  224. if (iopc->podr)
  225. podr |= msk;
  226. if (iopc->pdat)
  227. pdat |= msk;
  228. if (iopc->pint)
  229. pint |= msk;
  230. }
  231. msk <<= 1;
  232. iopc++;
  233. }
  234. PRINTF ("%s:%d:\n portnum=%d ", __FUNCTION__, __LINE__,
  235. portnum);
  236. #ifdef IOPORT_DEBUG
  237. switch (portnum) {
  238. case 0:
  239. printf ("(A)\n");
  240. break;
  241. case 1:
  242. printf ("(B)\n");
  243. break;
  244. case 2:
  245. printf ("(C)\n");
  246. break;
  247. case 3:
  248. printf ("(D)\n");
  249. break;
  250. default:
  251. printf ("(?)\n");
  252. break;
  253. }
  254. #endif
  255. PRINTF (" ppar=0x%.8x pdir=0x%.8x podr=0x%.8x\n"
  256. " pdat=0x%.8x psor=0x%.8x pint=0x%.8x pmsk=0x%.8x\n",
  257. ppar, pdir, podr, pdat, psor, pint, pmsk);
  258. /*
  259. * Have to handle the ioports on a port-by-port basis since there
  260. * are three different flavors.
  261. */
  262. if (pmsk != 0) {
  263. uint tpmsk = ~pmsk;
  264. if (0 == portnum) { /* port A */
  265. immr->im_ioport.iop_papar &= tpmsk;
  266. immr->im_ioport.iop_padat =
  267. (immr->im_ioport.
  268. iop_padat & tpmsk) | pdat;
  269. immr->im_ioport.iop_padir =
  270. (immr->im_ioport.
  271. iop_padir & tpmsk) | pdir;
  272. immr->im_ioport.iop_paodr =
  273. (immr->im_ioport.
  274. iop_paodr & tpmsk) | podr;
  275. immr->im_ioport.iop_papar |= ppar;
  276. } else if (1 == portnum) { /* port B */
  277. immr->im_cpm.cp_pbpar &= tpmsk;
  278. immr->im_cpm.cp_pbdat =
  279. (immr->im_cpm.
  280. cp_pbdat & tpmsk) | pdat;
  281. immr->im_cpm.cp_pbdir =
  282. (immr->im_cpm.
  283. cp_pbdir & tpmsk) | pdir;
  284. immr->im_cpm.cp_pbodr =
  285. (immr->im_cpm.
  286. cp_pbodr & tpmsk) | podr;
  287. immr->im_cpm.cp_pbpar |= ppar;
  288. } else if (2 == portnum) { /* port C */
  289. immr->im_ioport.iop_pcpar &= tpmsk;
  290. immr->im_ioport.iop_pcdat =
  291. (immr->im_ioport.
  292. iop_pcdat & tpmsk) | pdat;
  293. immr->im_ioport.iop_pcdir =
  294. (immr->im_ioport.
  295. iop_pcdir & tpmsk) | pdir;
  296. immr->im_ioport.iop_pcint =
  297. (immr->im_ioport.
  298. iop_pcint & tpmsk) | pint;
  299. immr->im_ioport.iop_pcso =
  300. (immr->im_ioport.
  301. iop_pcso & tpmsk) | psor;
  302. immr->im_ioport.iop_pcpar |= ppar;
  303. } else if (3 == portnum) { /* port D */
  304. immr->im_ioport.iop_pdpar &= tpmsk;
  305. immr->im_ioport.iop_pddat =
  306. (immr->im_ioport.
  307. iop_pddat & tpmsk) | pdat;
  308. immr->im_ioport.iop_pddir =
  309. (immr->im_ioport.
  310. iop_pddir & tpmsk) | pdir;
  311. immr->im_ioport.iop_pdpar |= ppar;
  312. }
  313. }
  314. }
  315. PRINTF ("%s:%d: Port A:\n papar=0x%.4x padir=0x%.4x"
  316. " paodr=0x%.4x\n padat=0x%.4x\n", __FUNCTION__, __LINE__,
  317. immr->im_ioport.iop_papar, immr->im_ioport.iop_padir,
  318. immr->im_ioport.iop_paodr, immr->im_ioport.iop_padat);
  319. PRINTF ("%s:%d: Port B:\n pbpar=0x%.8x pbdir=0x%.8x"
  320. " pbodr=0x%.8x\n pbdat=0x%.8x\n", __FUNCTION__, __LINE__,
  321. immr->im_cpm.cp_pbpar, immr->im_cpm.cp_pbdir,
  322. immr->im_cpm.cp_pbodr, immr->im_cpm.cp_pbdat);
  323. PRINTF ("%s:%d: Port C:\n pcpar=0x%.4x pcdir=0x%.4x"
  324. " pcdat=0x%.4x\n pcso=0x%.4x pcint=0x%.4x\n ",
  325. __FUNCTION__, __LINE__, immr->im_ioport.iop_pcpar,
  326. immr->im_ioport.iop_pcdir, immr->im_ioport.iop_pcdat,
  327. immr->im_ioport.iop_pcso, immr->im_ioport.iop_pcint);
  328. PRINTF ("%s:%d: Port D:\n pdpar=0x%.4x pddir=0x%.4x"
  329. " pddat=0x%.4x\n", __FUNCTION__, __LINE__,
  330. immr->im_ioport.iop_pdpar, immr->im_ioport.iop_pddir,
  331. immr->im_ioport.iop_pddat);
  332. }