2 * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
6 * The code contained herein is licensed under the GNU General Public
7 * License. You may obtain a copy of the GNU General Public License
8 * Version 2 or later at the following locations:
10 * http://www.opensource.org/licenses/gpl-license.html
11 * http://www.gnu.org/copyleft/gpl.html
15 * @defgroup GPIO_MX25 Board GPIO and Muxing Setup
19 * @file mach-mx25/iomux.c
21 * @brief I/O Muxing control functions
27 #include <asm/arch/mx25.h>
28 #include <asm/arch/mx25_pins.h>
29 #include <asm/arch/iomux.h>
32 * IOMUX register (base) addresses
35 IOMUXGPR = IOMUXC_BASE,
36 /*!< General purpose */
37 IOMUXSW_MUX_CTL = IOMUXC_BASE + 0x008,
39 IOMUXSW_MUX_END = IOMUXC_BASE + 0x228,
40 /*!< last MUX control register */
41 IOMUXSW_PAD_CTL = IOMUXC_BASE + 0x22C,
43 IOMUXSW_PAD_END = IOMUXC_BASE + 0x414,
44 /*!< last Pad control register */
45 IOMUXSW_INPUT_CTL = IOMUXC_BASE + 0x460,
46 /*!< input select register */
47 IOMUXSW_INPUT_END = IOMUXC_BASE + 0x580,
48 /*!< last input select register */
51 #define MUX_PIN_NUM_MAX \
52 (((IOMUXSW_MUX_END - IOMUXSW_MUX_CTL) >> 2) + 1)
53 #define MUX_INPUT_NUM_MUX \
54 (((IOMUXSW_INPUT_END - IOMUXSW_INPUT_CTL) >> 2) + 1)
56 #define PIN_TO_IOMUX_INDEX(pin) (PIN_TO_IOMUX_MUX(pin) >> 2)
61 * This function is used to configure a pin through the IOMUX module.
62 * FIXED ME: for backward compatible. Will be static function!
63 * @param pin a pin number as defined in \b #iomux_pin_name_t
64 * @param cfg an output function as defined in \b #iomux_pin_cfg_t
66 * @return 0 if successful; Non-zero otherwise
68 static int iomux_config_mux(iomux_pin_name_t pin, iomux_pin_cfg_t cfg)
70 u32 mux_reg = PIN_TO_IOMUX_MUX(pin);
72 if (mux_reg != NON_MUX_I) {
81 * Request ownership for an IO pin. This function has to be the first one
82 * being called before that pin is used. The caller has to check the
83 * return value to make sure it returns 0.
85 * @param pin a name defined by \b iomux_pin_name_t
86 * @param cfg an input function as defined in \b #iomux_pin_cfg_t
88 * @return 0 if successful; Non-zero otherwise
90 int mxc_request_iomux(iomux_pin_name_t pin, iomux_pin_cfg_t cfg)
92 int ret = iomux_config_mux(pin, cfg);
97 * Release ownership for an IO pin
99 * @param pin a name defined by \b iomux_pin_name_t
100 * @param cfg an input function as defined in \b #iomux_pin_cfg_t
102 void mxc_free_iomux(iomux_pin_name_t pin, iomux_pin_cfg_t cfg)
107 * This function configures the pad value for a IOMUX pin.
109 * @param pin a pin number as defined in \b #iomux_pin_name_t
110 * @param config the ORed value of elements defined in \b #iomux_pad_config_t
112 void mxc_iomux_set_pad(iomux_pin_name_t pin, u32 config)
114 u32 pad_reg = IOMUXGPR + PIN_TO_IOMUX_PAD(pin);
116 __REG(pad_reg) = config;
120 * This function enables/disables the general purpose function for a particular
123 * @param gp one signal as defined in \b #iomux_gp_func_t
124 * @param en \b #true to enable; \b #false to disable
126 void mxc_iomux_set_gpr(iomux_gp_func_t gp, int en)
140 * This function configures input path.
142 * @param input index of input select register as defined in \b
143 * #iomux_input_select_t
144 * @param config the binary value of elements defined in \b
145 * #iomux_input_config_t
147 void mxc_iomux_set_input(iomux_input_select_t input, u32 config)
149 u32 reg = IOMUXSW_INPUT_CTL + (input << 2);