]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - cpu/arm926ejs/mx25/iomux.c
imported Ka-Ro specific additions to U-Boot 2009.08 for TX28
[karo-tx-uboot.git] / cpu / arm926ejs / mx25 / iomux.c
1 /*
2  * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
3  */
4
5 /*
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:
9  *
10  * http://www.opensource.org/licenses/gpl-license.html
11  * http://www.gnu.org/copyleft/gpl.html
12  */
13
14 /*!
15  * @defgroup GPIO_MX25 Board GPIO and Muxing Setup
16  * @ingroup MSL_MX25
17  */
18 /*!
19  * @file mach-mx25/iomux.c
20  *
21  * @brief I/O Muxing control functions
22  *
23  * @ingroup GPIO_MX25
24  */
25
26 #include <common.h>
27 #include <asm/arch/mx25.h>
28 #include <asm/arch/mx25_pins.h>
29 #include <asm/arch/iomux.h>
30
31 /*!
32  * IOMUX register (base) addresses
33  */
34 enum iomux_reg_addr {
35         IOMUXGPR = IOMUXC_BASE,
36         /*!< General purpose */
37         IOMUXSW_MUX_CTL = IOMUXC_BASE + 0x008,
38         /*!< MUX control */
39         IOMUXSW_MUX_END = IOMUXC_BASE + 0x228,
40         /*!< last MUX control register */
41         IOMUXSW_PAD_CTL = IOMUXC_BASE + 0x22C,
42         /*!< Pad control */
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 */
49 };
50
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)
55
56 #define PIN_TO_IOMUX_INDEX(pin) (PIN_TO_IOMUX_MUX(pin) >> 2)
57
58 #define MUX_USED 0x80
59
60 /*!
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
65  *
66  * @return              0 if successful; Non-zero otherwise
67  */
68 static int iomux_config_mux(iomux_pin_name_t pin, iomux_pin_cfg_t cfg)
69 {
70         u32 mux_reg = PIN_TO_IOMUX_MUX(pin);
71
72         if (mux_reg != NON_MUX_I) {
73                 mux_reg += IOMUXGPR;
74                 __REG(mux_reg) = cfg;
75         }
76
77         return 0;
78 }
79
80 /*!
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.
84  *
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
87  *
88  * @return              0 if successful; Non-zero otherwise
89  */
90 int mxc_request_iomux(iomux_pin_name_t pin, iomux_pin_cfg_t cfg)
91 {
92         int ret = iomux_config_mux(pin, cfg);
93         return ret;
94 }
95
96 /*!
97  * Release ownership for an IO pin
98  *
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
101  */
102 void mxc_free_iomux(iomux_pin_name_t pin, iomux_pin_cfg_t cfg)
103 {
104 }
105
106 /*!
107  * This function configures the pad value for a IOMUX pin.
108  *
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
111  */
112 void mxc_iomux_set_pad(iomux_pin_name_t pin, u32 config)
113 {
114         u32 pad_reg = IOMUXGPR + PIN_TO_IOMUX_PAD(pin);
115
116         __REG(pad_reg) = config;
117 }
118
119 /*!
120  * This function enables/disables the general purpose function for a particular
121  * signal.
122  *
123  * @param  gp   one signal as defined in \b #iomux_gp_func_t
124  * @param  en   \b #true to enable; \b #false to disable
125  */
126 void mxc_iomux_set_gpr(iomux_gp_func_t gp, int en)
127 {
128         u32 l;
129
130         l = __REG(IOMUXGPR);
131         if (en)
132                 l |= gp;
133         else
134                 l &= ~gp;
135
136         __REG(IOMUXGPR) = l;
137 }
138
139 /*!
140  * This function configures input path.
141  *
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
146  */
147 void mxc_iomux_set_input(iomux_input_select_t input, u32 config)
148 {
149         u32 reg = IOMUXSW_INPUT_CTL + (input << 2);
150
151         __REG(reg) = config;
152 }
153