3051b9b30387b3ff3845dfdad08b297cd50a1fb3
[linux-3.10.git] / arch / arm / mach-tegra / board-laguna-pinmux.c
1 /*
2  * arch/arm/mach-tegra/board-laguna-pinmux.c
3  *
4  * Copyright (c) 2013, NVIDIA Corporation. All rights reserved.
5  *
6  * This software is licensed under the terms of the GNU General Public
7  * License version 2, as published by the Free Software Foundation, and
8  * may be copied, distributed, and modified under those terms.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  */
16
17 #include <linux/kernel.h>
18 #include <linux/init.h>
19 #include <linux/gpio.h>
20 #include <mach/pinmux.h>
21 #include <mach/gpio-tegra.h>
22
23 #include "board.h"
24 #include "board-laguna.h"
25 #include "devices.h"
26 #include "gpio-names.h"
27
28 #ifdef CONFIG_ARCH_TEGRA_11x_SOC
29 #include <mach/pinmux-t11.h>
30 #else
31 #include <mach/pinmux-t12.h>
32 #endif
33
34 #define DEFAULT_DRIVE(_name)                                    \
35         {                                                       \
36                 .pingroup = TEGRA_DRIVE_PINGROUP_##_name,       \
37                 .hsm = TEGRA_HSM_DISABLE,                       \
38                 .schmitt = TEGRA_SCHMITT_ENABLE,                \
39                 .drive = TEGRA_DRIVE_DIV_1,                     \
40                 .pull_down = TEGRA_PULL_31,                     \
41                 .pull_up = TEGRA_PULL_31,                       \
42                 .slew_rising = TEGRA_SLEW_SLOWEST,              \
43                 .slew_falling = TEGRA_SLEW_SLOWEST,             \
44         }
45 /* Setting the drive strength of pins
46  * hsm: Enable High speed mode (ENABLE/DISABLE)
47  * Schimit: Enable/disable schimit (ENABLE/DISABLE)
48  * drive: low power mode (DIV_1, DIV_2, DIV_4, DIV_8)
49  * pulldn_drive - drive down (falling edge) - Driver Output Pull-Down drive
50  *                strength code. Value from 0 to 31.
51  * pullup_drive - drive up (rising edge)  - Driver Output Pull-Up drive
52  *                strength code. Value from 0 to 31.
53  * pulldn_slew -  Driver Output Pull-Up slew control code  - 2bit code
54  *                code 11 is least slewing of signal. code 00 is highest
55  *                slewing of the signal.
56  *                Value - FASTEST, FAST, SLOW, SLOWEST
57  * pullup_slew -  Driver Output Pull-Down slew control code -
58  *                code 11 is least slewing of signal. code 00 is highest
59  *                slewing of the signal.
60  *                Value - FASTEST, FAST, SLOW, SLOWEST
61  */
62 #define SET_DRIVE(_name, _hsm, _schmitt, _drive, _pulldn_drive,\
63                 _pullup_drive, _pulldn_slew, _pullup_slew) \
64         {                                               \
65                 .pingroup = TEGRA_DRIVE_PINGROUP_##_name,   \
66                 .hsm = TEGRA_HSM_##_hsm,                    \
67                 .schmitt = TEGRA_SCHMITT_##_schmitt,        \
68                 .drive = TEGRA_DRIVE_##_drive,              \
69                 .pull_down = TEGRA_PULL_##_pulldn_drive,    \
70                 .pull_up = TEGRA_PULL_##_pullup_drive,          \
71                 .slew_rising = TEGRA_SLEW_##_pulldn_slew,   \
72                 .slew_falling = TEGRA_SLEW_##_pullup_slew,      \
73         }
74
75 /* Setting the drive strength of pins
76  * hsm: Enable High speed mode (ENABLE/DISABLE)
77  * Schimit: Enable/disable schimit (ENABLE/DISABLE)
78  * drive: low power mode (DIV_1, DIV_2, DIV_4, DIV_8)
79  * pulldn_drive - drive down (falling edge) - Driver Output Pull-Down drive
80  *                strength code. Value from 0 to 31.
81  * pullup_drive - drive up (rising edge)  - Driver Output Pull-Up drive
82  *                strength code. Value from 0 to 31.
83  * pulldn_slew -  Driver Output Pull-Up slew control code  - 2bit code
84  *                code 11 is least slewing of signal. code 00 is highest
85  *                slewing of the signal.
86  *                Value - FASTEST, FAST, SLOW, SLOWEST
87  * pullup_slew -  Driver Output Pull-Down slew control code -
88  *                code 11 is least slewing of signal. code 00 is highest
89  *                slewing of the signal.
90  *                Value - FASTEST, FAST, SLOW, SLOWEST
91  * drive_type - Drive type to be used depending on the resistors.
92  */
93
94 #define SET_DRIVE_WITH_TYPE(_name, _hsm, _schmitt, _drive, _pulldn_drive,\
95                 _pullup_drive, _pulldn_slew, _pullup_slew, _drive_type) \
96         {                                                               \
97                 .pingroup = TEGRA_DRIVE_PINGROUP_##_name,               \
98                 .hsm = TEGRA_HSM_##_hsm,                                \
99                 .schmitt = TEGRA_SCHMITT_##_schmitt,                    \
100                 .drive = TEGRA_DRIVE_##_drive,                          \
101                 .pull_down = TEGRA_PULL_##_pulldn_drive,                \
102                 .pull_up = TEGRA_PULL_##_pullup_drive,                  \
103                 .slew_rising = TEGRA_SLEW_##_pulldn_slew,               \
104                 .slew_falling = TEGRA_SLEW_##_pullup_slew,              \
105                 .drive_type = TEGRA_DRIVE_TYPE_##_drive_type,           \
106         }
107
108 #define DEFAULT_PINMUX(_pingroup, _mux, _pupd, _tri, _io)       \
109         {                                                       \
110                 .pingroup       = TEGRA_PINGROUP_##_pingroup,   \
111                 .func           = TEGRA_MUX_##_mux,             \
112                 .pupd           = TEGRA_PUPD_##_pupd,           \
113                 .tristate       = TEGRA_TRI_##_tri,             \
114                 .io             = TEGRA_PIN_##_io,              \
115                 .lock           = TEGRA_PIN_LOCK_DEFAULT,       \
116                 .od             = TEGRA_PIN_OD_DEFAULT,         \
117                 .ioreset        = TEGRA_PIN_IO_RESET_DEFAULT,   \
118         }
119
120 #define I2C_PINMUX(_pingroup, _mux, _pupd, _tri, _io, _lock, _od) \
121         {                                                       \
122                 .pingroup       = TEGRA_PINGROUP_##_pingroup,   \
123                 .func           = TEGRA_MUX_##_mux,             \
124                 .pupd           = TEGRA_PUPD_##_pupd,           \
125                 .tristate       = TEGRA_TRI_##_tri,             \
126                 .io             = TEGRA_PIN_##_io,              \
127                 .lock           = TEGRA_PIN_LOCK_##_lock,       \
128                 .od             = TEGRA_PIN_OD_##_od,           \
129                 .ioreset        = TEGRA_PIN_IO_RESET_DEFAULT,   \
130         }
131
132 #define DDC_PINMUX(_pingroup, _mux, _pupd, _tri, _io, _lock, _rcv_sel) \
133         {                                                       \
134                 .pingroup       = TEGRA_PINGROUP_##_pingroup,   \
135                 .func           = TEGRA_MUX_##_mux,             \
136                 .pupd           = TEGRA_PUPD_##_pupd,           \
137                 .tristate       = TEGRA_TRI_##_tri,             \
138                 .io             = TEGRA_PIN_##_io,              \
139                 .lock           = TEGRA_PIN_LOCK_##_lock,       \
140                 .rcv_sel        = TEGRA_PIN_RCV_SEL_##_rcv_sel,         \
141                 .ioreset        = TEGRA_PIN_IO_RESET_DEFAULT,   \
142         }
143
144 #define VI_PINMUX(_pingroup, _mux, _pupd, _tri, _io, _lock, _ioreset) \
145         {                                                       \
146                 .pingroup       = TEGRA_PINGROUP_##_pingroup,   \
147                 .func           = TEGRA_MUX_##_mux,             \
148                 .pupd           = TEGRA_PUPD_##_pupd,           \
149                 .tristate       = TEGRA_TRI_##_tri,             \
150                 .io             = TEGRA_PIN_##_io,              \
151                 .lock           = TEGRA_PIN_LOCK_##_lock,       \
152                 .od             = TEGRA_PIN_OD_DEFAULT,         \
153                 .ioreset        = TEGRA_PIN_IO_RESET_##_ioreset \
154         }
155
156 #define CEC_PINMUX(_pingroup, _mux, _pupd, _tri, _io, _lock, _od)   \
157         {                                                               \
158                 .pingroup   = TEGRA_PINGROUP_##_pingroup,                   \
159                 .func       = TEGRA_MUX_##_mux,                             \
160                 .pupd       = TEGRA_PUPD_##_pupd,                           \
161                 .tristate   = TEGRA_TRI_##_tri,                             \
162                 .io         = TEGRA_PIN_##_io,                              \
163                 .lock       = TEGRA_PIN_LOCK_##_lock,                       \
164                 .od         = TEGRA_PIN_OD_##_od,                           \
165                 .ioreset    = TEGRA_PIN_IO_RESET_DEFAULT,                   \
166         }
167
168 #define USB_PINMUX CEC_PINMUX
169
170 #define GPIO_INIT_PIN_MODE(_gpio, _is_input, _value)    \
171         {                                       \
172                 .gpio_nr        = _gpio,        \
173                 .is_input       = _is_input,    \
174                 .value          = _value,       \
175         }
176 #define GPIO_PINMUX(_pingroup, _pupd, _tri, _io, _od)   \
177         {                                                   \
178                 .pingroup   = TEGRA_PINGROUP_##_pingroup,       \
179                 .func       = TEGRA_MUX_SAFE,                   \
180                 .pupd       = TEGRA_PUPD_##_pupd,               \
181                 .tristate   = TEGRA_TRI_##_tri,                 \
182                 .io         = TEGRA_PIN_##_io,                  \
183                 .lock       = TEGRA_PIN_LOCK_DEFAULT,           \
184                 .od         = TEGRA_PIN_OD_##_od,               \
185                 .ioreset    = TEGRA_PIN_IO_RESET_DEFAULT,       \
186         }
187 #define UNUSED_PINMUX(_pingroup)                    \
188         {                                               \
189                 .pingroup   = TEGRA_PINGROUP_##_pingroup,   \
190                 .func       = TEGRA_MUX_SAFE,               \
191                 .pupd       = TEGRA_PUPD_PULL_DOWN,         \
192                 .tristate   = TEGRA_TRI_TRISTATE,           \
193                 .io         = TEGRA_PIN_OUTPUT,             \
194                 .lock       = TEGRA_PIN_LOCK_DEFAULT,       \
195                 .od         = TEGRA_PIN_OD_DEFAULT,         \
196                 .ioreset    = TEGRA_PIN_IO_RESET_DEFAULT,   \
197         }
198
199 static __initdata struct tegra_drive_pingroup_config laguna_drive_pinmux[] = {
200 #ifdef CONFIG_ARCH_TEGRA_11x_SOC
201         /* DEFAULT_DRIVE(<pin_group>), */
202         /* SDMMC1 */
203         SET_DRIVE(SDIO1, ENABLE, DISABLE, DIV_1, 36, 20, SLOW, SLOW),
204
205         /* SDMMC3 */
206         SET_DRIVE(SDIO3, ENABLE, DISABLE, DIV_1, 22, 36, FASTEST, FASTEST),
207
208         /* SDMMC4 */
209         SET_DRIVE_WITH_TYPE(GMA, ENABLE, DISABLE, DIV_1, 2, 1, FASTEST,
210                                                                 FASTEST, 1),
211 #else
212         /* FIXME: update settings for t124 laguna */
213         SET_DRIVE(SDIO1, ENABLE, DISABLE, DIV_1, 36, 20, SLOW, SLOW),
214
215         /* SDMMC3 */
216         SET_DRIVE(SDIO3, ENABLE, DISABLE, DIV_1, 22, 36, FASTEST, FASTEST),
217
218         /* SDMMC4 */
219         SET_DRIVE_WITH_TYPE(GMA, ENABLE, DISABLE, DIV_1, 2, 1, FASTEST,
220                                                                 FASTEST, 1),
221 #endif
222 };
223 #if 0
224 /* Initially setting all used GPIO's to non-TRISTATE */
225 static __initdata struct tegra_pingroup_config laguna_pinmux_set_nontristate[] = {
226 #ifdef CONFIG_ARCH_TEGRA_11x_SOC
227         DEFAULT_PINMUX(GPIO_X4_AUD,     RSVD,   PULL_DOWN,    NORMAL,    OUTPUT),
228         DEFAULT_PINMUX(GPIO_X5_AUD,     RSVD,   PULL_UP,      NORMAL,    INPUT),
229         DEFAULT_PINMUX(GPIO_X6_AUD,     RSVD3,  PULL_UP,      NORMAL,    INPUT),
230         DEFAULT_PINMUX(GPIO_X7_AUD,     RSVD,   PULL_DOWN,    NORMAL,    OUTPUT),
231         DEFAULT_PINMUX(GPIO_W2_AUD,     RSVD1,  PULL_UP,      NORMAL,    INPUT),
232         DEFAULT_PINMUX(GPIO_W3_AUD,     SPI6,   PULL_UP,      NORMAL,    INPUT),
233         DEFAULT_PINMUX(GPIO_X1_AUD,     RSVD3,  PULL_DOWN,    NORMAL,    INPUT),
234         DEFAULT_PINMUX(GPIO_X3_AUD,     RSVD3,  PULL_UP,      NORMAL,    INPUT),
235
236         DEFAULT_PINMUX(DAP3_FS,         I2S2,   PULL_DOWN,    NORMAL,    OUTPUT),
237         DEFAULT_PINMUX(DAP3_DIN,        I2S2,   PULL_DOWN,    NORMAL,    OUTPUT),
238         DEFAULT_PINMUX(DAP3_DOUT,       I2S2,   PULL_DOWN,    NORMAL,    OUTPUT),
239         DEFAULT_PINMUX(DAP3_SCLK,       I2S2,   PULL_DOWN,    NORMAL,    OUTPUT),
240         DEFAULT_PINMUX(GPIO_PV0,        RSVD3,  NORMAL,       NORMAL,    INPUT),
241         DEFAULT_PINMUX(GPIO_PV1,        RSVD,   NORMAL,       NORMAL,    INPUT),
242
243         DEFAULT_PINMUX(GPIO_PBB3,       RSVD3,  PULL_DOWN,    NORMAL,    OUTPUT),
244         DEFAULT_PINMUX(GPIO_PBB5,       RSVD3,  PULL_DOWN,    NORMAL,    OUTPUT),
245         DEFAULT_PINMUX(GPIO_PBB6,       RSVD3,  PULL_DOWN,    NORMAL,    OUTPUT),
246         DEFAULT_PINMUX(GPIO_PBB7,       RSVD3,  PULL_DOWN,    NORMAL,    OUTPUT),
247         DEFAULT_PINMUX(GPIO_PCC1,       RSVD3,  PULL_DOWN,    NORMAL,    INPUT),
248         DEFAULT_PINMUX(GPIO_PCC2,       RSVD3,  PULL_DOWN,    NORMAL,    INPUT),
249
250         DEFAULT_PINMUX(GMI_AD0,         GMI,    NORMAL,       NORMAL,    OUTPUT),
251         DEFAULT_PINMUX(GMI_AD1,         GMI,    NORMAL,       NORMAL,    OUTPUT),
252         DEFAULT_PINMUX(GMI_AD10,        GMI,    PULL_DOWN,    NORMAL,    OUTPUT),
253         DEFAULT_PINMUX(GMI_AD11,        GMI,    PULL_DOWN,    NORMAL,    OUTPUT),
254         DEFAULT_PINMUX(GMI_AD12,        GMI,    PULL_UP,      NORMAL,    INPUT),
255         DEFAULT_PINMUX(GMI_AD13,        GMI,    PULL_DOWN,    NORMAL,    OUTPUT),
256         DEFAULT_PINMUX(GMI_AD2,         GMI,    NORMAL,       NORMAL,    INPUT),
257         DEFAULT_PINMUX(GMI_AD3,         GMI,    NORMAL,       NORMAL,    INPUT),
258         DEFAULT_PINMUX(GMI_AD8,         GMI,    PULL_DOWN,    NORMAL,    OUTPUT),
259         DEFAULT_PINMUX(GMI_ADV_N,       GMI,    PULL_UP,      NORMAL,    INPUT),
260         DEFAULT_PINMUX(GMI_CLK,         GMI,    PULL_DOWN,    NORMAL,    OUTPUT),
261         DEFAULT_PINMUX(GMI_CS0_N,       GMI,    PULL_UP,      NORMAL,    INPUT),
262         DEFAULT_PINMUX(GMI_CS2_N,       GMI,    PULL_UP,      NORMAL,    INPUT),
263         DEFAULT_PINMUX(GMI_CS3_N,       GMI,    PULL_UP,      NORMAL,    OUTPUT),
264         DEFAULT_PINMUX(GMI_CS4_N,       GMI,    PULL_UP,      NORMAL,    INPUT),
265         DEFAULT_PINMUX(GMI_CS7_N,       GMI,    PULL_UP,      NORMAL,    INPUT),
266         DEFAULT_PINMUX(GMI_DQS_P,       GMI,    PULL_UP,      NORMAL,    INPUT),
267         DEFAULT_PINMUX(GMI_IORDY,       GMI,    PULL_UP,      NORMAL,    INPUT),
268         DEFAULT_PINMUX(GMI_WP_N,        GMI,    PULL_UP,      NORMAL,    INPUT),
269
270         DEFAULT_PINMUX(SDMMC1_WP_N,     SPI4,   PULL_UP,      NORMAL,    OUTPUT),
271         DEFAULT_PINMUX(CLK2_REQ,        RSVD3,  NORMAL,       NORMAL,    OUTPUT),
272
273         DEFAULT_PINMUX(KB_COL3,         KBC,    PULL_UP,      NORMAL,    OUTPUT),
274         DEFAULT_PINMUX(KB_COL5,         KBC,    PULL_UP,      NORMAL,    INPUT),
275         DEFAULT_PINMUX(KB_COL6,         KBC,    PULL_UP,      NORMAL,    OUTPUT),
276         DEFAULT_PINMUX(KB_COL7,         KBC,    PULL_UP,      NORMAL,    OUTPUT),
277         DEFAULT_PINMUX(KB_ROW3,         KBC,    PULL_DOWN,    NORMAL,    INPUT),
278         DEFAULT_PINMUX(KB_ROW4,         KBC,    PULL_DOWN,    NORMAL,    INPUT),
279         DEFAULT_PINMUX(KB_ROW6,         KBC,    PULL_DOWN,    NORMAL,    INPUT),
280         DEFAULT_PINMUX(KB_ROW7,         KBC,    PULL_UP,      NORMAL,    INPUT),
281         DEFAULT_PINMUX(KB_ROW8,         KBC,    PULL_UP,      NORMAL,    INPUT),
282
283         DEFAULT_PINMUX(CLK3_REQ,        RSVD3,  NORMAL,      NORMAL,    OUTPUT),
284         DEFAULT_PINMUX(GPIO_PU4,        PWM1,  NORMAL,      NORMAL,    OUTPUT),
285         DEFAULT_PINMUX(GPIO_PU5,        PWM2,  NORMAL,      NORMAL,    INPUT),
286         DEFAULT_PINMUX(GPIO_PU6,        PWM3,  NORMAL,      NORMAL,    INPUT),
287
288         DEFAULT_PINMUX(HDMI_INT,        RSVD,   PULL_DOWN,    NORMAL,    INPUT),
289
290         DEFAULT_PINMUX(GMI_AD9,         PWM1,   NORMAL,    NORMAL,     OUTPUT),
291 #else
292         /* TODO: update for t124 laguna */
293 #endif
294 };
295 #endif
296
297 #ifdef CONFIG_ARCH_TEGRA_11x_SOC
298 #include "board-laguna-pinmux-t11x.h"
299 #else
300 #include "board-laguna-pinmux-t12x.h"
301 #endif
302
303 static void __init laguna_gpio_init_configure(void)
304 {
305         int len;
306         int i;
307         struct gpio_init_pin_info *pins_info;
308
309         len = ARRAY_SIZE(init_gpio_mode_laguna_common);
310         pins_info = init_gpio_mode_laguna_common;
311
312         for (i = 0; i < len; ++i) {
313                 tegra_gpio_init_configure(pins_info->gpio_nr,
314                         pins_info->is_input, pins_info->value);
315                 pins_info++;
316         }
317 }
318
319 int __init laguna_pinmux_init(void)
320 {
321 #if 0
322         tegra_pinmux_config_table(laguna_pinmux_set_nontristate,
323                                         ARRAY_SIZE(laguna_pinmux_set_nontristate));
324 #endif
325         laguna_gpio_init_configure();
326
327         tegra_pinmux_config_table(laguna_pinmux_common, ARRAY_SIZE(laguna_pinmux_common));
328         tegra_drive_pinmux_config_table(laguna_drive_pinmux,
329                                         ARRAY_SIZE(laguna_drive_pinmux));
330         tegra_pinmux_config_table(unused_pins_lowpower,
331                 ARRAY_SIZE(unused_pins_lowpower));
332
333         return 0;
334 }