iomux.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * (C) Copyright 2009 Freescale Semiconductor, Inc.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  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/io.h>
  24. #include <asm/arch/imx-regs.h>
  25. #include <asm/arch/mx51_pins.h>
  26. #include <asm/arch/iomux.h>
  27. /* IOMUX register (base) addresses */
  28. enum iomux_reg_addr {
  29. IOMUXGPR0 = IOMUXC_BASE_ADDR,
  30. IOMUXGPR1 = IOMUXC_BASE_ADDR + 0x004,
  31. IOMUXSW_MUX_CTL = IOMUXC_BASE_ADDR,
  32. IOMUXSW_MUX_END = IOMUXC_BASE_ADDR + MUX_I_END,
  33. IOMUXSW_PAD_CTL = IOMUXC_BASE_ADDR + PAD_I_START,
  34. IOMUXSW_INPUT_CTL = IOMUXC_BASE_ADDR,
  35. };
  36. #define MUX_PIN_NUM_MAX (((MUX_I_END - MUX_I_START) >> 2) + 1)
  37. /* Get the iomux register address of this pin */
  38. static inline u32 get_mux_reg(iomux_pin_name_t pin)
  39. {
  40. u32 mux_reg = PIN_TO_IOMUX_MUX(pin);
  41. if (is_soc_rev(CHIP_REV_2_0) < 0) {
  42. /*
  43. * Fixup register address:
  44. * i.MX51 TO1 has offset with the register
  45. * which is define as TO2.
  46. */
  47. if ((pin == MX51_PIN_NANDF_RB5) ||
  48. (pin == MX51_PIN_NANDF_RB6) ||
  49. (pin == MX51_PIN_NANDF_RB7))
  50. ; /* Do nothing */
  51. else if (mux_reg >= 0x2FC)
  52. mux_reg += 8;
  53. else if (mux_reg >= 0x130)
  54. mux_reg += 0xC;
  55. }
  56. mux_reg += IOMUXSW_MUX_CTL;
  57. return mux_reg;
  58. }
  59. /* Get the pad register address of this pin */
  60. static inline u32 get_pad_reg(iomux_pin_name_t pin)
  61. {
  62. u32 pad_reg = PIN_TO_IOMUX_PAD(pin);
  63. if (is_soc_rev(CHIP_REV_2_0) < 0) {
  64. /*
  65. * Fixup register address:
  66. * i.MX51 TO1 has offset with the register
  67. * which is define as TO2.
  68. */
  69. if ((pin == MX51_PIN_NANDF_RB5) ||
  70. (pin == MX51_PIN_NANDF_RB6) ||
  71. (pin == MX51_PIN_NANDF_RB7))
  72. ; /* Do nothing */
  73. else if (pad_reg == 0x4D0 - PAD_I_START)
  74. pad_reg += 0x4C;
  75. else if (pad_reg == 0x860 - PAD_I_START)
  76. pad_reg += 0x9C;
  77. else if (pad_reg >= 0x804 - PAD_I_START)
  78. pad_reg += 0xB0;
  79. else if (pad_reg >= 0x7FC - PAD_I_START)
  80. pad_reg += 0xB4;
  81. else if (pad_reg >= 0x4E4 - PAD_I_START)
  82. pad_reg += 0xCC;
  83. else
  84. pad_reg += 8;
  85. }
  86. pad_reg += IOMUXSW_PAD_CTL;
  87. return pad_reg;
  88. }
  89. /* Get the last iomux register address */
  90. static inline u32 get_mux_end(void)
  91. {
  92. if (is_soc_rev(CHIP_REV_2_0) < 0)
  93. return IOMUXC_BASE_ADDR + (0x3F8 - 4);
  94. else
  95. return IOMUXC_BASE_ADDR + (0x3F0 - 4);
  96. }
  97. /*
  98. * This function is used to configure a pin through the IOMUX module.
  99. * @param pin a pin number as defined in iomux_pin_name_t
  100. * @param cfg an output function as defined in iomux_pin_cfg_t
  101. *
  102. * @return 0 if successful; Non-zero otherwise
  103. */
  104. static void iomux_config_mux(iomux_pin_name_t pin, iomux_pin_cfg_t cfg)
  105. {
  106. u32 mux_reg = get_mux_reg(pin);
  107. if ((mux_reg > get_mux_end()) || (mux_reg < IOMUXSW_MUX_CTL))
  108. return ;
  109. if (cfg == IOMUX_CONFIG_GPIO)
  110. writel(PIN_TO_ALT_GPIO(pin), mux_reg);
  111. else
  112. writel(cfg, mux_reg);
  113. }
  114. /*
  115. * Request ownership for an IO pin. This function has to be the first one
  116. * being called before that pin is used. The caller has to check the
  117. * return value to make sure it returns 0.
  118. *
  119. * @param pin a name defined by iomux_pin_name_t
  120. * @param cfg an input function as defined in iomux_pin_cfg_t
  121. *
  122. */
  123. void mxc_request_iomux(iomux_pin_name_t pin, iomux_pin_cfg_t cfg)
  124. {
  125. iomux_config_mux(pin, cfg);
  126. }
  127. /*
  128. * Release ownership for an IO pin
  129. *
  130. * @param pin a name defined by iomux_pin_name_t
  131. * @param cfg an input function as defined in iomux_pin_cfg_t
  132. */
  133. void mxc_free_iomux(iomux_pin_name_t pin, iomux_pin_cfg_t cfg)
  134. {
  135. }
  136. /*
  137. * This function configures the pad value for a IOMUX pin.
  138. *
  139. * @param pin a pin number as defined in iomux_pin_name_t
  140. * @param config the ORed value of elements defined in iomux_pad_config_t
  141. */
  142. void mxc_iomux_set_pad(iomux_pin_name_t pin, u32 config)
  143. {
  144. u32 pad_reg = get_pad_reg(pin);
  145. writel(config, pad_reg);
  146. }
  147. unsigned int mxc_iomux_get_pad(iomux_pin_name_t pin)
  148. {
  149. u32 pad_reg = get_pad_reg(pin);
  150. return readl(pad_reg);
  151. }