blob: 2e499681cfcbeb1dd5123db34bd7c82c101481b7 [file] [log] [blame]
Jason Liudec11122011-11-25 00:18:02 +00001/*
2 * Based on Linux i.MX iomux-v3.h file:
3 * Copyright (C) 2009 by Jan Weitzel Phytec Messtechnik GmbH,
4 * <armlinux@phytec.de>
5 *
6 * Copyright (C) 2011 Freescale Semiconductor, Inc.
7 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Jason Liudec11122011-11-25 00:18:02 +00009 */
10
11#ifndef __MACH_IOMUX_V3_H__
12#define __MACH_IOMUX_V3_H__
13
Benoît Thébaudeaua83d1c32013-04-26 01:34:44 +000014#include <common.h>
15
Jason Liudec11122011-11-25 00:18:02 +000016/*
17 * build IOMUX_PAD structure
18 *
19 * This iomux scheme is based around pads, which are the physical balls
20 * on the processor.
21 *
22 * - Each pad has a pad control register (IOMUXC_SW_PAD_CTRL_x) which controls
23 * things like driving strength and pullup/pulldown.
24 * - Each pad can have but not necessarily does have an output routing register
25 * (IOMUXC_SW_MUX_CTL_PAD_x).
26 * - Each pad can have but not necessarily does have an input routing register
27 * (IOMUXC_x_SELECT_INPUT)
28 *
29 * The three register sets do not have a fixed offset to each other,
30 * hence we order this table by pad control registers (which all pads
31 * have) and put the optional i/o routing registers into additional
32 * fields.
33 *
34 * The naming convention for the pad modes is SOC_PAD_<padname>__<padmode>
35 * If <padname> or <padmode> refers to a GPIO, it is named GPIO_<unit>_<num>
36 *
37 * IOMUX/PAD Bit field definitions
38 *
39 * MUX_CTRL_OFS: 0..11 (12)
40 * PAD_CTRL_OFS: 12..23 (12)
41 * SEL_INPUT_OFS: 24..35 (12)
42 * MUX_MODE + SION: 36..40 (5)
43 * PAD_CTRL + NO_PAD_CTRL: 41..58 (18)
44 * SEL_INP: 59..62 (4)
45 * reserved: 63 (1)
46*/
47
48typedef u64 iomux_v3_cfg_t;
49
50#define MUX_CTRL_OFS_SHIFT 0
51#define MUX_CTRL_OFS_MASK ((iomux_v3_cfg_t)0xfff << MUX_CTRL_OFS_SHIFT)
52#define MUX_PAD_CTRL_OFS_SHIFT 12
53#define MUX_PAD_CTRL_OFS_MASK ((iomux_v3_cfg_t)0xfff << \
54 MUX_PAD_CTRL_OFS_SHIFT)
55#define MUX_SEL_INPUT_OFS_SHIFT 24
56#define MUX_SEL_INPUT_OFS_MASK ((iomux_v3_cfg_t)0xfff << \
57 MUX_SEL_INPUT_OFS_SHIFT)
58
59#define MUX_MODE_SHIFT 36
60#define MUX_MODE_MASK ((iomux_v3_cfg_t)0x1f << MUX_MODE_SHIFT)
61#define MUX_PAD_CTRL_SHIFT 41
62#define MUX_PAD_CTRL_MASK ((iomux_v3_cfg_t)0x3ffff << MUX_PAD_CTRL_SHIFT)
63#define MUX_SEL_INPUT_SHIFT 59
64#define MUX_SEL_INPUT_MASK ((iomux_v3_cfg_t)0xf << MUX_SEL_INPUT_SHIFT)
65
Otavio Salvadoraa978d82013-12-16 20:44:00 -020066#define MUX_MODE_SION ((iomux_v3_cfg_t)IOMUX_CONFIG_SION << \
67 MUX_MODE_SHIFT)
Jason Liudec11122011-11-25 00:18:02 +000068#define MUX_PAD_CTRL(x) ((iomux_v3_cfg_t)(x) << MUX_PAD_CTRL_SHIFT)
69
70#define IOMUX_PAD(pad_ctrl_ofs, mux_ctrl_ofs, mux_mode, sel_input_ofs, \
71 sel_input, pad_ctrl) \
72 (((iomux_v3_cfg_t)(mux_ctrl_ofs) << MUX_CTRL_OFS_SHIFT) | \
73 ((iomux_v3_cfg_t)(mux_mode) << MUX_MODE_SHIFT) | \
74 ((iomux_v3_cfg_t)(pad_ctrl_ofs) << MUX_PAD_CTRL_OFS_SHIFT) | \
75 ((iomux_v3_cfg_t)(pad_ctrl) << MUX_PAD_CTRL_SHIFT) | \
76 ((iomux_v3_cfg_t)(sel_input_ofs) << MUX_SEL_INPUT_OFS_SHIFT)| \
77 ((iomux_v3_cfg_t)(sel_input) << MUX_SEL_INPUT_SHIFT))
78
Benoît Thébaudeau334bae62013-04-26 01:34:46 +000079#define NEW_PAD_CTRL(cfg, pad) (((cfg) & ~MUX_PAD_CTRL_MASK) | \
80 MUX_PAD_CTRL(pad))
81
Benoît Thébaudeaub89e4502013-04-26 01:34:45 +000082#define __NA_ 0x000
83#define NO_MUX_I 0
84#define NO_PAD_I 0
85
Jason Liudec11122011-11-25 00:18:02 +000086#define NO_PAD_CTRL (1 << 17)
Jason Liudec11122011-11-25 00:18:02 +000087
Adrian Alonso5d18b182015-08-11 11:19:50 -050088#ifdef CONFIG_MX7
89
90#define IOMUX_LPSR_SEL_INPUT_OFS 0x70000
91#define IOMUX_CONFIG_LPSR 0x8
92#define MUX_MODE_LPSR ((iomux_v3_cfg_t)IOMUX_CONFIG_LPSR << \
93 MUX_MODE_SHIFT)
94
95#define PAD_CTL_DSE_1P8V_140OHM (0x0<<0)
96#define PAD_CTL_DSE_1P8V_35OHM (0x1<<0)
97#define PAD_CTL_DSE_1P8V_70OHM (0x2<<0)
98#define PAD_CTL_DSE_1P8V_23OHM (0x3<<0)
99
100#define PAD_CTL_DSE_3P3V_196OHM (0x0<<0)
101#define PAD_CTL_DSE_3P3V_49OHM (0x1<<0)
102#define PAD_CTL_DSE_3P3V_98OHM (0x2<<0)
103#define PAD_CTL_DSE_3P3V_32OHM (0x3<<0)
104
105#define PAD_CTL_SRE_FAST (0 << 2)
106#define PAD_CTL_SRE_SLOW (0x1 << 2)
107
108#define PAD_CTL_HYS (0x1 << 3)
109#define PAD_CTL_PUE (0x1 << 4)
110
111#define PAD_CTL_PUS_PD100KOHM ((0x0 << 5) | PAD_CTL_PUE)
112#define PAD_CTL_PUS_PU5KOHM ((0x1 << 5) | PAD_CTL_PUE)
113#define PAD_CTL_PUS_PU47KOHM ((0x2 << 5) | PAD_CTL_PUE)
114#define PAD_CTL_PUS_PU100KOHM ((0x3 << 5) | PAD_CTL_PUE)
115
116#else
117
Benoît Thébaudeaua83d1c32013-04-26 01:34:44 +0000118#ifdef CONFIG_MX6
119
Fabio Estevamebc89412013-04-10 09:32:56 +0000120#define PAD_CTL_HYS (1 << 16)
Benoît Thébaudeaub89e4502013-04-26 01:34:45 +0000121
Benoît Thébaudeau21670242013-04-26 01:34:47 +0000122#define PAD_CTL_PUS_100K_DOWN (0 << 14 | PAD_CTL_PUE)
123#define PAD_CTL_PUS_47K_UP (1 << 14 | PAD_CTL_PUE)
124#define PAD_CTL_PUS_100K_UP (2 << 14 | PAD_CTL_PUE)
125#define PAD_CTL_PUS_22K_UP (3 << 14 | PAD_CTL_PUE)
126#define PAD_CTL_PUE (1 << 13 | PAD_CTL_PKE)
Fabio Estevamebc89412013-04-10 09:32:56 +0000127#define PAD_CTL_PKE (1 << 12)
Benoît Thébaudeaub89e4502013-04-26 01:34:45 +0000128
Fabio Estevamebc89412013-04-10 09:32:56 +0000129#define PAD_CTL_ODE (1 << 11)
Benoît Thébaudeaub89e4502013-04-26 01:34:45 +0000130
Peng Fan80b24152015-07-20 19:28:30 +0800131#if defined(CONFIG_MX6SX) || defined(CONFIG_MX6UL)
132#define PAD_CTL_SPEED_LOW (0 << 6)
133#else
Fabio Estevamebc89412013-04-10 09:32:56 +0000134#define PAD_CTL_SPEED_LOW (1 << 6)
Peng Fan80b24152015-07-20 19:28:30 +0800135#endif
Fabio Estevamebc89412013-04-10 09:32:56 +0000136#define PAD_CTL_SPEED_MED (2 << 6)
137#define PAD_CTL_SPEED_HIGH (3 << 6)
Benoît Thébaudeaub89e4502013-04-26 01:34:45 +0000138
Fabio Estevamebc89412013-04-10 09:32:56 +0000139#define PAD_CTL_DSE_DISABLE (0 << 3)
140#define PAD_CTL_DSE_240ohm (1 << 3)
141#define PAD_CTL_DSE_120ohm (2 << 3)
142#define PAD_CTL_DSE_80ohm (3 << 3)
143#define PAD_CTL_DSE_60ohm (4 << 3)
144#define PAD_CTL_DSE_48ohm (5 << 3)
145#define PAD_CTL_DSE_40ohm (6 << 3)
146#define PAD_CTL_DSE_34ohm (7 << 3)
Benoît Thébaudeaua83d1c32013-04-26 01:34:44 +0000147
Fabio Estevamd3b17422014-04-29 10:15:46 -0300148#if defined CONFIG_MX6SL
149#define PAD_CTL_LVE (1 << 1)
150#define PAD_CTL_LVE_BIT (1 << 22)
151#endif
152
Alison Wang831beaf2013-05-27 22:55:41 +0000153#elif defined(CONFIG_VF610)
154
155#define PAD_MUX_MODE_SHIFT 20
156
Anthony Feliceaf0464f2014-09-06 19:47:06 +0200157#define PAD_CTL_INPUT_DIFFERENTIAL (1 << 16)
158
Alison Wang831beaf2013-05-27 22:55:41 +0000159#define PAD_CTL_SPEED_MED (1 << 12)
160#define PAD_CTL_SPEED_HIGH (3 << 12)
161
Stefan Agner0f527292014-08-06 10:59:35 +0200162#define PAD_CTL_SRE (1 << 11)
163
Albert ARIBAUD \(3ADEV\)40281ba2015-06-19 14:18:29 +0200164#define PAD_CTL_ODE (1 << 10)
165
Alison Wang2927a192014-05-06 09:13:02 +0800166#define PAD_CTL_DSE_150ohm (1 << 6)
Alison Wang831beaf2013-05-27 22:55:41 +0000167#define PAD_CTL_DSE_50ohm (3 << 6)
168#define PAD_CTL_DSE_25ohm (6 << 6)
169#define PAD_CTL_DSE_20ohm (7 << 6)
170
171#define PAD_CTL_PUS_47K_UP (1 << 4 | PAD_CTL_PUE)
172#define PAD_CTL_PUS_100K_UP (2 << 4 | PAD_CTL_PUE)
Alison Wang2927a192014-05-06 09:13:02 +0800173#define PAD_CTL_PUS_22K_UP (3 << 4 | PAD_CTL_PUE)
Alison Wang831beaf2013-05-27 22:55:41 +0000174#define PAD_CTL_PKE (1 << 3)
175#define PAD_CTL_PUE (1 << 2 | PAD_CTL_PKE)
176
177#define PAD_CTL_OBE_IBE_ENABLE (3 << 0)
Stefan Agner0f527292014-08-06 10:59:35 +0200178#define PAD_CTL_OBE_ENABLE (1 << 1)
179#define PAD_CTL_IBE_ENABLE (1 << 0)
Alison Wang831beaf2013-05-27 22:55:41 +0000180
Benoît Thébaudeaua83d1c32013-04-26 01:34:44 +0000181#else
182
183#define PAD_CTL_DVS (1 << 13)
184#define PAD_CTL_INPUT_DDR (1 << 9)
185#define PAD_CTL_HYS (1 << 8)
186
187#define PAD_CTL_PKE (1 << 7)
188#define PAD_CTL_PUE (1 << 6 | PAD_CTL_PKE)
189#define PAD_CTL_PUS_100K_DOWN (0 << 4 | PAD_CTL_PUE)
190#define PAD_CTL_PUS_47K_UP (1 << 4 | PAD_CTL_PUE)
191#define PAD_CTL_PUS_100K_UP (2 << 4 | PAD_CTL_PUE)
192#define PAD_CTL_PUS_22K_UP (3 << 4 | PAD_CTL_PUE)
193
194#define PAD_CTL_ODE (1 << 3)
195
196#define PAD_CTL_DSE_LOW (0 << 1)
197#define PAD_CTL_DSE_MED (1 << 1)
198#define PAD_CTL_DSE_HIGH (2 << 1)
199#define PAD_CTL_DSE_MAX (3 << 1)
200
201#endif
202
Fabio Estevamebc89412013-04-10 09:32:56 +0000203#define PAD_CTL_SRE_SLOW (0 << 0)
Benoît Thébaudeaub89e4502013-04-26 01:34:45 +0000204#define PAD_CTL_SRE_FAST (1 << 0)
Fabio Estevamebc89412013-04-10 09:32:56 +0000205
Adrian Alonso5d18b182015-08-11 11:19:50 -0500206#endif
207
Fabio Estevamebc89412013-04-10 09:32:56 +0000208#define IOMUX_CONFIG_SION 0x10
Benoît Thébaudeaub89e4502013-04-26 01:34:45 +0000209
210#define GPIO_PIN_MASK 0x1f
211#define GPIO_PORT_SHIFT 5
212#define GPIO_PORT_MASK (0x7 << GPIO_PORT_SHIFT)
213#define GPIO_PORTA (0 << GPIO_PORT_SHIFT)
214#define GPIO_PORTB (1 << GPIO_PORT_SHIFT)
215#define GPIO_PORTC (2 << GPIO_PORT_SHIFT)
216#define GPIO_PORTD (3 << GPIO_PORT_SHIFT)
217#define GPIO_PORTE (4 << GPIO_PORT_SHIFT)
218#define GPIO_PORTF (5 << GPIO_PORT_SHIFT)
Jason Liudec11122011-11-25 00:18:02 +0000219
Stefan Roese4982d9a2013-04-10 23:06:46 +0000220void imx_iomux_v3_setup_pad(iomux_v3_cfg_t pad);
221void imx_iomux_v3_setup_multiple_pads(iomux_v3_cfg_t const *pad_list,
Eric Nelson89110832012-10-03 07:26:37 +0000222 unsigned count);
Ye.Li700020e2014-10-30 18:53:49 +0800223/*
224* Set bits for general purpose registers
225*/
226void imx_iomux_set_gpr_register(int group, int start_bit,
227 int num_bits, int value);
Bhuvanchandra DV6d236aa2015-06-01 18:37:16 +0530228#ifdef CONFIG_IOMUX_SHARE_CONF_REG
229void imx_iomux_gpio_set_direction(unsigned int gpio,
230 unsigned int direction);
231void imx_iomux_gpio_get_function(unsigned int gpio,
232 u32 *gpio_state);
233#endif
Jason Liudec11122011-11-25 00:18:02 +0000234
Tim Harvey09a62332014-06-02 16:13:24 -0700235/* macros for declaring and using pinmux array */
236#if defined(CONFIG_MX6QDL)
237#define IOMUX_PADS(x) (MX6Q_##x), (MX6DL_##x)
238#define SETUP_IOMUX_PAD(def) \
Otavio Salvador90c2d712015-11-19 19:02:37 -0200239if (is_cpu_type(MXC_CPU_MX6Q) || is_cpu_type(MXC_CPU_MX6D)) { \
Tim Harvey09a62332014-06-02 16:13:24 -0700240 imx_iomux_v3_setup_pad(MX6Q_##def); \
241} else { \
242 imx_iomux_v3_setup_pad(MX6DL_##def); \
243}
244#define SETUP_IOMUX_PADS(x) \
245 imx_iomux_v3_setup_multiple_pads(x, ARRAY_SIZE(x)/2)
246#elif defined(CONFIG_MX6Q) || defined(CONFIG_MX6D)
247#define IOMUX_PADS(x) MX6Q_##x
248#define SETUP_IOMUX_PAD(def) \
249 imx_iomux_v3_setup_pad(MX6Q_##def);
250#define SETUP_IOMUX_PADS(x) \
251 imx_iomux_v3_setup_multiple_pads(x, ARRAY_SIZE(x))
252#else
253#define IOMUX_PADS(x) MX6DL_##x
254#define SETUP_IOMUX_PAD(def) \
255 imx_iomux_v3_setup_pad(MX6DL_##def);
256#define SETUP_IOMUX_PADS(x) \
257 imx_iomux_v3_setup_multiple_pads(x, ARRAY_SIZE(x))
258#endif
259
Jason Liudec11122011-11-25 00:18:02 +0000260#endif /* __MACH_IOMUX_V3_H__*/