iomux.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
  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/mx35_pins.h>
  26. #include <asm/arch/iomux.h>
  27. /*
  28. * IOMUX register (base) addresses
  29. */
  30. enum iomux_reg_addr {
  31. IOMUXGPR = IOMUXC_BASE_ADDR, /* General purpose */
  32. IOMUXSW_MUX_CTL = IOMUXC_BASE_ADDR + 4, /* MUX control */
  33. IOMUXSW_MUX_END = IOMUXC_BASE_ADDR + 0x324, /* last MUX control */
  34. IOMUXSW_PAD_CTL = IOMUXC_BASE_ADDR + 0x328, /* Pad control */
  35. IOMUXSW_PAD_END = IOMUXC_BASE_ADDR + 0x794, /* last Pad control */
  36. IOMUXSW_INPUT_CTL = IOMUXC_BASE_ADDR + 0x7AC, /* input select */
  37. IOMUXSW_INPUT_END = IOMUXC_BASE_ADDR + 0x9F4, /* last input select */
  38. };
  39. #define MUX_PIN_NUM_MAX \
  40. (((IOMUXSW_PAD_END - IOMUXSW_PAD_CTL) >> 2) + 1)
  41. #define MUX_INPUT_NUM_MUX \
  42. (((IOMUXSW_INPUT_END - IOMUXSW_INPUT_CTL) >> 2) + 1)
  43. #define PIN_TO_IOMUX_INDEX(pin) ((PIN_TO_IOMUX_PAD(pin) - 0x328) >> 2)
  44. /*
  45. * Request ownership for an IO pin. This function has to be the first one
  46. * being called before that pin is used.
  47. */
  48. void mxc_request_iomux(iomux_pin_name_t pin, iomux_pin_cfg_t cfg)
  49. {
  50. u32 mux_reg = PIN_TO_IOMUX_MUX(pin);
  51. if (mux_reg != NON_MUX_I) {
  52. mux_reg += IOMUXGPR;
  53. writel(cfg, mux_reg);
  54. }
  55. }
  56. /*
  57. * Release ownership for an IO pin
  58. */
  59. void mxc_free_iomux(iomux_pin_name_t pin, iomux_pin_cfg_t cfg)
  60. {
  61. }
  62. /*
  63. * This function configures the pad value for a IOMUX pin.
  64. *
  65. * @param pin a pin number as defined in iomux_pin_name_t
  66. * @param config the ORed value of elements defined in iomux_pad_config_t
  67. */
  68. void mxc_iomux_set_pad(iomux_pin_name_t pin, u32 config)
  69. {
  70. u32 pad_reg = IOMUXGPR + PIN_TO_IOMUX_PAD(pin);
  71. writel(config, pad_reg);
  72. }
  73. /*
  74. * This function enables/disables the general purpose function for a particular
  75. * signal.
  76. *
  77. * @param gp one signal as defined in iomux_gp_func_t
  78. * @param en enable/disable
  79. */
  80. void mxc_iomux_set_gpr(iomux_gp_func_t gp, int en)
  81. {
  82. u32 l;
  83. l = readl(IOMUXGPR);
  84. if (en)
  85. l |= gp;
  86. else
  87. l &= ~gp;
  88. writel(l, IOMUXGPR);
  89. }
  90. /*
  91. * This function configures input path.
  92. *
  93. * @param input index of input select register as defined in
  94. * iomux_input_select_t
  95. * @param config the binary value of elements defined in
  96. * iomux_input_config_t
  97. */
  98. void mxc_iomux_set_input(iomux_input_select_t input, u32 config)
  99. {
  100. u32 reg = IOMUXSW_INPUT_CTL + (input << 2);
  101. writel(config, reg);
  102. }