blob: d4e3bbb4379ad8dd21d95e52bdc7add4f6c78618 [file] [log] [blame]
Stefano Babic64fdf452010-01-20 18:19:32 +01001/*
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
23#include <common.h>
24#include <asm/io.h>
25#include <asm/arch/imx-regs.h>
Jason Liuff9f4752010-10-18 11:09:26 +080026#include <asm/arch/mx5x_pins.h>
Stefano Babic64fdf452010-01-20 18:19:32 +010027#include <asm/arch/iomux.h>
Stefano Babice4d34492010-03-05 17:54:37 +010028#include <asm/arch/sys_proto.h>
Stefano Babic64fdf452010-01-20 18:19:32 +010029
30/* IOMUX register (base) addresses */
31enum iomux_reg_addr {
32 IOMUXGPR0 = IOMUXC_BASE_ADDR,
33 IOMUXGPR1 = IOMUXC_BASE_ADDR + 0x004,
34 IOMUXSW_MUX_CTL = IOMUXC_BASE_ADDR,
35 IOMUXSW_MUX_END = IOMUXC_BASE_ADDR + MUX_I_END,
36 IOMUXSW_PAD_CTL = IOMUXC_BASE_ADDR + PAD_I_START,
Liu Hui-R64343595f3e52011-01-03 22:27:35 +000037 IOMUXSW_INPUT_CTL = IOMUXC_BASE_ADDR + INPUT_CTL_START,
Stefano Babic64fdf452010-01-20 18:19:32 +010038};
39
40#define MUX_PIN_NUM_MAX (((MUX_I_END - MUX_I_START) >> 2) + 1)
41
42/* Get the iomux register address of this pin */
43static inline u32 get_mux_reg(iomux_pin_name_t pin)
44{
45 u32 mux_reg = PIN_TO_IOMUX_MUX(pin);
46
Liu Hui-R64343595f3e52011-01-03 22:27:35 +000047#if defined(CONFIG_MX51)
Stefano Babic64fdf452010-01-20 18:19:32 +010048 if (is_soc_rev(CHIP_REV_2_0) < 0) {
49 /*
50 * Fixup register address:
Liu Hui-R64343595f3e52011-01-03 22:27:35 +000051 * i.MX51 TO1 has offset with the register
52 * which is define as TO2.
Stefano Babic64fdf452010-01-20 18:19:32 +010053 */
54 if ((pin == MX51_PIN_NANDF_RB5) ||
55 (pin == MX51_PIN_NANDF_RB6) ||
56 (pin == MX51_PIN_NANDF_RB7))
57 ; /* Do nothing */
58 else if (mux_reg >= 0x2FC)
59 mux_reg += 8;
60 else if (mux_reg >= 0x130)
61 mux_reg += 0xC;
62 }
Liu Hui-R64343595f3e52011-01-03 22:27:35 +000063#endif
Stefano Babic64fdf452010-01-20 18:19:32 +010064 mux_reg += IOMUXSW_MUX_CTL;
65 return mux_reg;
66}
67
68/* Get the pad register address of this pin */
69static inline u32 get_pad_reg(iomux_pin_name_t pin)
70{
71 u32 pad_reg = PIN_TO_IOMUX_PAD(pin);
72
Liu Hui-R64343595f3e52011-01-03 22:27:35 +000073#if defined(CONFIG_MX51)
Stefano Babic64fdf452010-01-20 18:19:32 +010074 if (is_soc_rev(CHIP_REV_2_0) < 0) {
75 /*
76 * Fixup register address:
Liu Hui-R64343595f3e52011-01-03 22:27:35 +000077 * i.MX51 TO1 has offset with the register
78 * which is define as TO2.
Stefano Babic64fdf452010-01-20 18:19:32 +010079 */
80 if ((pin == MX51_PIN_NANDF_RB5) ||
81 (pin == MX51_PIN_NANDF_RB6) ||
82 (pin == MX51_PIN_NANDF_RB7))
83 ; /* Do nothing */
84 else if (pad_reg == 0x4D0 - PAD_I_START)
85 pad_reg += 0x4C;
86 else if (pad_reg == 0x860 - PAD_I_START)
87 pad_reg += 0x9C;
88 else if (pad_reg >= 0x804 - PAD_I_START)
89 pad_reg += 0xB0;
90 else if (pad_reg >= 0x7FC - PAD_I_START)
91 pad_reg += 0xB4;
92 else if (pad_reg >= 0x4E4 - PAD_I_START)
93 pad_reg += 0xCC;
94 else
95 pad_reg += 8;
96 }
Liu Hui-R64343595f3e52011-01-03 22:27:35 +000097#endif
Stefano Babic64fdf452010-01-20 18:19:32 +010098 pad_reg += IOMUXSW_PAD_CTL;
99 return pad_reg;
100}
101
102/* Get the last iomux register address */
103static inline u32 get_mux_end(void)
104{
Liu Hui-R64343595f3e52011-01-03 22:27:35 +0000105#if defined(CONFIG_MX51)
Stefano Babic64fdf452010-01-20 18:19:32 +0100106 if (is_soc_rev(CHIP_REV_2_0) < 0)
107 return IOMUXC_BASE_ADDR + (0x3F8 - 4);
108 else
109 return IOMUXC_BASE_ADDR + (0x3F0 - 4);
Liu Hui-R64343595f3e52011-01-03 22:27:35 +0000110#endif
111 return IOMUXSW_MUX_END;
Stefano Babic64fdf452010-01-20 18:19:32 +0100112}
113
114/*
115 * This function is used to configure a pin through the IOMUX module.
116 * @param pin a pin number as defined in iomux_pin_name_t
117 * @param cfg an output function as defined in iomux_pin_cfg_t
118 *
119 * @return 0 if successful; Non-zero otherwise
120 */
121static void iomux_config_mux(iomux_pin_name_t pin, iomux_pin_cfg_t cfg)
122{
123 u32 mux_reg = get_mux_reg(pin);
124
125 if ((mux_reg > get_mux_end()) || (mux_reg < IOMUXSW_MUX_CTL))
126 return ;
127 if (cfg == IOMUX_CONFIG_GPIO)
128 writel(PIN_TO_ALT_GPIO(pin), mux_reg);
129 else
130 writel(cfg, mux_reg);
131}
132
133/*
134 * Request ownership for an IO pin. This function has to be the first one
135 * being called before that pin is used. The caller has to check the
136 * return value to make sure it returns 0.
137 *
138 * @param pin a name defined by iomux_pin_name_t
139 * @param cfg an input function as defined in iomux_pin_cfg_t
140 *
141 */
142void mxc_request_iomux(iomux_pin_name_t pin, iomux_pin_cfg_t cfg)
143{
144 iomux_config_mux(pin, cfg);
145}
146
147/*
148 * Release ownership for an IO pin
149 *
150 * @param pin a name defined by iomux_pin_name_t
151 * @param cfg an input function as defined in iomux_pin_cfg_t
152 */
153void mxc_free_iomux(iomux_pin_name_t pin, iomux_pin_cfg_t cfg)
154{
155}
156
157/*
158 * This function configures the pad value for a IOMUX pin.
159 *
160 * @param pin a pin number as defined in iomux_pin_name_t
161 * @param config the ORed value of elements defined in iomux_pad_config_t
162 */
163void mxc_iomux_set_pad(iomux_pin_name_t pin, u32 config)
164{
165 u32 pad_reg = get_pad_reg(pin);
166 writel(config, pad_reg);
167}
168
169unsigned int mxc_iomux_get_pad(iomux_pin_name_t pin)
170{
171 u32 pad_reg = get_pad_reg(pin);
172 return readl(pad_reg);
173}
Liu Hui-R64343595f3e52011-01-03 22:27:35 +0000174
175/*
176 * This function configures daisy-chain
177 *
178 * @param input index of input select register
179 * @param config the binary value of elements
180 */
181void mxc_iomux_set_input(iomux_input_select_t input, u32 config)
182{
183 u32 reg = IOMUXSW_INPUT_CTL + (input << 2);
184
185 writel(config, reg);
186}