qe_io.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (C) 2006 Freescale Semiconductor, Inc.
  3. *
  4. * Dave Liu <daveliu@freescale.com>
  5. * based on source code of Shlomi Gridish
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include "common.h"
  23. #include "asm/errno.h"
  24. #include "asm/io.h"
  25. #include "asm/immap_83xx.h"
  26. #define NUM_OF_PINS 32
  27. void qe_config_iopin(u8 port, u8 pin, int dir, int open_drain, int assign)
  28. {
  29. u32 pin_2bit_mask;
  30. u32 pin_2bit_dir;
  31. u32 pin_2bit_assign;
  32. u32 pin_1bit_mask;
  33. u32 tmp_val;
  34. volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR;
  35. volatile qepio83xx_t *par_io = (volatile qepio83xx_t *)&im->qepio;
  36. /* Caculate pin location and 2bit mask and dir */
  37. pin_2bit_mask = (u32)(0x3 << (NUM_OF_PINS-(pin%(NUM_OF_PINS/2)+1)*2));
  38. pin_2bit_dir = (u32)(dir << (NUM_OF_PINS-(pin%(NUM_OF_PINS/2)+1)*2));
  39. /* Setup the direction */
  40. tmp_val = (pin > (NUM_OF_PINS/2) - 1) ? \
  41. in_be32(&par_io->ioport[port].dir2) :
  42. in_be32(&par_io->ioport[port].dir1);
  43. if (pin > (NUM_OF_PINS/2) -1) {
  44. out_be32(&par_io->ioport[port].dir2, ~pin_2bit_mask & tmp_val);
  45. out_be32(&par_io->ioport[port].dir2, pin_2bit_dir | tmp_val);
  46. } else {
  47. out_be32(&par_io->ioport[port].dir1, ~pin_2bit_mask & tmp_val);
  48. out_be32(&par_io->ioport[port].dir1, pin_2bit_dir | tmp_val);
  49. }
  50. /* Calculate pin location for 1bit mask */
  51. pin_1bit_mask = (u32)(1 << (NUM_OF_PINS - (pin+1)));
  52. /* Setup the open drain */
  53. tmp_val = in_be32(&par_io->ioport[port].podr);
  54. if (open_drain) {
  55. out_be32(&par_io->ioport[port].podr, pin_1bit_mask | tmp_val);
  56. } else {
  57. out_be32(&par_io->ioport[port].podr, ~pin_1bit_mask & tmp_val);
  58. }
  59. /* Setup the assignment */
  60. tmp_val = (pin > (NUM_OF_PINS/2) - 1) ?
  61. in_be32(&par_io->ioport[port].ppar2):
  62. in_be32(&par_io->ioport[port].ppar1);
  63. pin_2bit_assign = (u32)(assign
  64. << (NUM_OF_PINS - (pin%(NUM_OF_PINS/2)+1)*2));
  65. /* Clear and set 2 bits mask */
  66. if (pin > (NUM_OF_PINS/2) - 1) {
  67. out_be32(&par_io->ioport[port].ppar2, ~pin_2bit_mask & tmp_val);
  68. out_be32(&par_io->ioport[port].ppar2, pin_2bit_assign | tmp_val);
  69. } else {
  70. out_be32(&par_io->ioport[port].ppar1, ~pin_2bit_mask & tmp_val);
  71. out_be32(&par_io->ioport[port].ppar1, pin_2bit_assign | tmp_val);
  72. }
  73. }