iopin.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * (C) Copyright 2008
  3. * Martha J Marx, Silicon Turnkey Express, mmarx@silicontkx.com
  4. * mpc512x I/O pin/pad initialization for the ADS5121 board
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <linux/types.h>
  9. #include <asm/io.h>
  10. void iopin_initialize(iopin_t *ioregs_init, int len)
  11. {
  12. short i, j, p;
  13. u32 *reg;
  14. immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  15. reg = (u32 *)&(im->io_ctrl);
  16. if (sizeof(ioregs_init) == 0)
  17. return;
  18. for (i = 0; i < len; i++) {
  19. for (p = 0, j = ioregs_init[i].p_offset / sizeof(u_long);
  20. p < ioregs_init[i].nr_pins; p++, j++) {
  21. if (ioregs_init[i].bit_or)
  22. setbits_be32(reg + j, ioregs_init[i].val);
  23. else
  24. out_be32 (reg + j, ioregs_init[i].val);
  25. }
  26. }
  27. return;
  28. }
  29. void iopin_initialize_bits(iopin_t *ioregs_init, int len)
  30. {
  31. short i, j, p;
  32. u32 *reg, mask;
  33. immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  34. reg = (u32 *)&(im->io_ctrl);
  35. /* iterate over table entries */
  36. for (i = 0; i < len; i++) {
  37. /* iterate over pins within a table entry */
  38. for (p = 0, j = ioregs_init[i].p_offset / sizeof(u_long);
  39. p < ioregs_init[i].nr_pins; p++, j++) {
  40. if (ioregs_init[i].bit_or & IO_PIN_OVER_EACH) {
  41. /* replace all settings at once */
  42. out_be32(reg + j, ioregs_init[i].val);
  43. } else {
  44. /*
  45. * only replace individual parts, but
  46. * REPLACE them instead of just ORing
  47. * them in and "inheriting" previously
  48. * set bits which we don't want
  49. */
  50. mask = 0;
  51. if (ioregs_init[i].bit_or & IO_PIN_OVER_FMUX)
  52. mask |= IO_PIN_FMUX(3);
  53. if (ioregs_init[i].bit_or & IO_PIN_OVER_HOLD)
  54. mask |= IO_PIN_HOLD(3);
  55. if (ioregs_init[i].bit_or & IO_PIN_OVER_PULL)
  56. mask |= IO_PIN_PUD(1) | IO_PIN_PUE(1);
  57. if (ioregs_init[i].bit_or & IO_PIN_OVER_STRIG)
  58. mask |= IO_PIN_ST(1);
  59. if (ioregs_init[i].bit_or & IO_PIN_OVER_DRVSTR)
  60. mask |= IO_PIN_DS(3);
  61. /*
  62. * DON'T do the "mask, then insert"
  63. * in place on the register, it may
  64. * break access to external hardware
  65. * (like boot ROMs) when configuring
  66. * LPB related pins, while the code to
  67. * configure the pin is read from this
  68. * very address region
  69. */
  70. clrsetbits_be32(reg + j, mask,
  71. ioregs_init[i].val & mask);
  72. }
  73. }
  74. }
  75. }