]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - cpu/arm1136/mx35/iomux.c
applied patches from Freescale and Ka-Ro
[karo-tx-uboot.git] / cpu / arm1136 / mx35 / 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_MX35 Board GPIO and Muxing Setup
16  * @ingroup MSL_MX35
17  */
18 /*!
19  * @file mach-mx35/iomux.c
20  *
21  * @brief I/O Muxing control functions
22  *
23  * @ingroup GPIO_MX35
24  */
25 #include <common.h>
26 #include <asm/arch/mx35.h>
27 #include <asm/arch/mx35_pins.h>
28 #include <asm/arch/iomux.h>
29
30 /*!
31  * IOMUX register (base) addresses
32  */
33 enum iomux_reg_addr {
34         IOMUXGPR = IOMUXC_BASE_ADDR,
35         /*!< General purpose */
36         IOMUXSW_MUX_CTL = IOMUXC_BASE_ADDR + 4,
37         /*!< MUX control */
38         IOMUXSW_MUX_END = IOMUXC_BASE_ADDR + 0x324,
39         /*!< last MUX control register */
40         IOMUXSW_PAD_CTL = IOMUXC_BASE_ADDR + 0x328,
41         /*!< Pad control */
42         IOMUXSW_PAD_END = IOMUXC_BASE_ADDR + 0x794,
43         /*!< last Pad control register */
44         IOMUXSW_INPUT_CTL = IOMUXC_BASE_ADDR + 0x7AC,
45         /*!< input select register */
46         IOMUXSW_INPUT_END = IOMUXC_BASE_ADDR + 0x9F4,
47         /*!< last input select register */
48 };
49
50 #define MUX_PIN_NUM_MAX         \
51                 (((IOMUXSW_PAD_END - IOMUXSW_PAD_CTL) >> 2) + 1)
52 #define MUX_INPUT_NUM_MUX       \
53                 (((IOMUXSW_INPUT_END - IOMUXSW_INPUT_CTL) >> 2) + 1)
54
55 #define PIN_TO_IOMUX_INDEX(pin) ((PIN_TO_IOMUX_PAD(pin) - 0x328) >> 2)
56
57 /*!
58  * This function is used to configure a pin through the IOMUX module.
59  * FIXED ME: for backward compatible. Will be static function!
60  * @param  pin          a pin number as defined in \b #iomux_pin_name_t
61  * @param  cfg          an output function as defined in \b #iomux_pin_cfg_t
62  *
63  * @return              0 if successful; Non-zero otherwise
64  */
65 static int iomux_config_mux(iomux_pin_name_t pin, iomux_pin_cfg_t cfg)
66 {
67         u32 mux_reg = PIN_TO_IOMUX_MUX(pin);
68
69         if (mux_reg != NON_MUX_I) {
70                 mux_reg += IOMUXGPR;
71                 __REG(mux_reg) = cfg;
72         }
73
74         return 0;
75 }
76
77 /*!
78  * Request ownership for an IO pin. This function has to be the first one
79  * being called before that pin is used. The caller has to check the
80  * return value to make sure it returns 0.
81  *
82  * @param  pin          a name defined by \b iomux_pin_name_t
83  * @param  cfg          an input function as defined in \b #iomux_pin_cfg_t
84  *
85  * @return              0 if successful; Non-zero otherwise
86  */
87 int mxc_request_iomux(iomux_pin_name_t pin, iomux_pin_cfg_t cfg)
88 {
89         int ret = iomux_config_mux(pin, cfg);
90         return ret;
91 }
92
93 /*!
94  * Release ownership for an IO pin
95  *
96  * @param  pin          a name defined by \b iomux_pin_name_t
97  * @param  cfg          an input function as defined in \b #iomux_pin_cfg_t
98  */
99 void mxc_free_iomux(iomux_pin_name_t pin, iomux_pin_cfg_t cfg)
100 {
101 }
102
103 /*!
104  * This function configures the pad value for a IOMUX pin.
105  *
106  * @param  pin     a pin number as defined in \b #iomux_pin_name_t
107  * @param  config  the ORed value of elements defined in \b #iomux_pad_config_t
108  */
109 void mxc_iomux_set_pad(iomux_pin_name_t pin, u32 config)
110 {
111         u32 pad_reg = IOMUXGPR + PIN_TO_IOMUX_PAD(pin);
112
113         __REG(pad_reg) = config;
114 }
115
116 /*!
117  * This function enables/disables the general purpose function for a particular
118  * signal.
119  *
120  * @param  gp   one signal as defined in \b #iomux_gp_func_t
121  * @param  en   \b #true to enable; \b #false to disable
122  */
123 void mxc_iomux_set_gpr(iomux_gp_func_t gp, int en)
124 {
125         u32 l;
126
127         l = __REG(IOMUXGPR);
128         if (en)
129                 l |= gp;
130         else
131                 l &= ~gp;
132
133         __REG(IOMUXGPR) = l;
134 }
135
136 /*!
137  * This function configures input path.
138  *
139  * @param input index of input select register as defined in \b
140  *                      #iomux_input_select_t
141  * @param config the binary value of elements defined in \b
142  *                      #iomux_input_config_t
143  */
144 void mxc_iomux_set_input(iomux_input_select_t input, u32 config)
145 {
146         u32 reg = IOMUXSW_INPUT_CTL + (input << 2);
147
148         __REG(reg) = config;
149 }