blob: 0492abd298cb0dab0ed59e3997c6084fc4a0ef00 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Jason Liudec11122011-11-25 00:18:02 +00002/*
3 * Based on Linux i.MX iomux-v3.h file:
4 * Copyright (C) 2009 by Jan Weitzel Phytec Messtechnik GmbH,
5 * <armlinux@phytec.de>
6 *
7 * Copyright (C) 2011 Freescale Semiconductor, Inc.
Jason Liudec11122011-11-25 00:18:02 +00008 */
9
10#ifndef __MACH_IOMUX_V3_H__
11#define __MACH_IOMUX_V3_H__
12
Simon Glass1e268642020-05-10 11:39:55 -060013#include <linux/types.h>
Benoît Thébaudeaua83d1c32013-04-26 01:34:44 +000014
Jason Liudec11122011-11-25 00:18:02 +000015/*
16 * build IOMUX_PAD structure
17 *
18 * This iomux scheme is based around pads, which are the physical balls
19 * on the processor.
20 *
21 * - Each pad has a pad control register (IOMUXC_SW_PAD_CTRL_x) which controls
22 * things like driving strength and pullup/pulldown.
23 * - Each pad can have but not necessarily does have an output routing register
24 * (IOMUXC_SW_MUX_CTL_PAD_x).
25 * - Each pad can have but not necessarily does have an input routing register
26 * (IOMUXC_x_SELECT_INPUT)
27 *
28 * The three register sets do not have a fixed offset to each other,
29 * hence we order this table by pad control registers (which all pads
30 * have) and put the optional i/o routing registers into additional
31 * fields.
32 *
33 * The naming convention for the pad modes is SOC_PAD_<padname>__<padmode>
34 * If <padname> or <padmode> refers to a GPIO, it is named GPIO_<unit>_<num>
35 *
36 * IOMUX/PAD Bit field definitions
37 *
38 * MUX_CTRL_OFS: 0..11 (12)
39 * PAD_CTRL_OFS: 12..23 (12)
40 * SEL_INPUT_OFS: 24..35 (12)
Peng Fan1fd3ea72016-09-18 16:28:28 +080041 * MUX_MODE + SION + LPSR: 36..41 (6)
42 * PAD_CTRL + NO_PAD_CTRL: 42..59 (18)
43 * SEL_INP: 60..63 (4)
Jason Liudec11122011-11-25 00:18:02 +000044*/
45
46typedef u64 iomux_v3_cfg_t;
47
48#define MUX_CTRL_OFS_SHIFT 0
49#define MUX_CTRL_OFS_MASK ((iomux_v3_cfg_t)0xfff << MUX_CTRL_OFS_SHIFT)
50#define MUX_PAD_CTRL_OFS_SHIFT 12
51#define MUX_PAD_CTRL_OFS_MASK ((iomux_v3_cfg_t)0xfff << \
52 MUX_PAD_CTRL_OFS_SHIFT)
53#define MUX_SEL_INPUT_OFS_SHIFT 24
54#define MUX_SEL_INPUT_OFS_MASK ((iomux_v3_cfg_t)0xfff << \
55 MUX_SEL_INPUT_OFS_SHIFT)
56
57#define MUX_MODE_SHIFT 36
Peng Fan1fd3ea72016-09-18 16:28:28 +080058#define MUX_MODE_MASK ((iomux_v3_cfg_t)0x3f << MUX_MODE_SHIFT)
59#define MUX_PAD_CTRL_SHIFT 42
Jason Liudec11122011-11-25 00:18:02 +000060#define MUX_PAD_CTRL_MASK ((iomux_v3_cfg_t)0x3ffff << MUX_PAD_CTRL_SHIFT)
Peng Fan1fd3ea72016-09-18 16:28:28 +080061#define MUX_SEL_INPUT_SHIFT 60
Jason Liudec11122011-11-25 00:18:02 +000062#define MUX_SEL_INPUT_MASK ((iomux_v3_cfg_t)0xf << MUX_SEL_INPUT_SHIFT)
63
Otavio Salvadoraa978d82013-12-16 20:44:00 -020064#define MUX_MODE_SION ((iomux_v3_cfg_t)IOMUX_CONFIG_SION << \
65 MUX_MODE_SHIFT)
Jason Liudec11122011-11-25 00:18:02 +000066#define MUX_PAD_CTRL(x) ((iomux_v3_cfg_t)(x) << MUX_PAD_CTRL_SHIFT)
67
68#define IOMUX_PAD(pad_ctrl_ofs, mux_ctrl_ofs, mux_mode, sel_input_ofs, \
69 sel_input, pad_ctrl) \
70 (((iomux_v3_cfg_t)(mux_ctrl_ofs) << MUX_CTRL_OFS_SHIFT) | \
71 ((iomux_v3_cfg_t)(mux_mode) << MUX_MODE_SHIFT) | \
72 ((iomux_v3_cfg_t)(pad_ctrl_ofs) << MUX_PAD_CTRL_OFS_SHIFT) | \
73 ((iomux_v3_cfg_t)(pad_ctrl) << MUX_PAD_CTRL_SHIFT) | \
74 ((iomux_v3_cfg_t)(sel_input_ofs) << MUX_SEL_INPUT_OFS_SHIFT)| \
75 ((iomux_v3_cfg_t)(sel_input) << MUX_SEL_INPUT_SHIFT))
76
Benoît Thébaudeau334bae62013-04-26 01:34:46 +000077#define NEW_PAD_CTRL(cfg, pad) (((cfg) & ~MUX_PAD_CTRL_MASK) | \
78 MUX_PAD_CTRL(pad))
79
Benoît Thébaudeaub89e4502013-04-26 01:34:45 +000080#define __NA_ 0x000
81#define NO_MUX_I 0
82#define NO_PAD_I 0
83
Jason Liudec11122011-11-25 00:18:02 +000084#define NO_PAD_CTRL (1 << 17)
Jason Liudec11122011-11-25 00:18:02 +000085
Peng Fan1fd3ea72016-09-18 16:28:28 +080086#define IOMUX_CONFIG_LPSR 0x20
Adrian Alonso5d18b182015-08-11 11:19:50 -050087#define MUX_MODE_LPSR ((iomux_v3_cfg_t)IOMUX_CONFIG_LPSR << \
88 MUX_MODE_SHIFT)
Peng Fanbbcd2c42022-07-26 16:40:39 +080089#ifdef CONFIG_IMX93
90#define PAD_CTL_FSEL2 (0x2 << 7)
91#define PAD_CTL_FSEL3 (0x3 << 7)
92#define PAD_CTL_PUE (0x1 << 9)
93#define PAD_CTL_PDE (0x1 << 10)
94#define PAD_CTL_ODE (0x1 << 11)
95#define PAD_CTL_HYS (0x1 << 12)
96#define PAD_CTL_DSE(x) (((x) << 1) & 0x7f)
97
98#elif defined(CONFIG_IMX8M)
Peng Fan62ebfc62018-01-10 13:20:28 +080099#define PAD_CTL_FSEL0 (0x0 << 3)
100#define PAD_CTL_FSEL1 (0x1 << 3)
101#define PAD_CTL_FSEL2 (0x2 << 3)
102#define PAD_CTL_FSEL3 (0x3 << 3)
103
104#define PAD_CTL_ODE (0x1 << 5)
105#define PAD_CTL_PUE (0x1 << 6)
106#define PAD_CTL_HYS (0x1 << 7)
Peng Fanaaee1502019-12-30 16:43:48 +0800107#if defined(CONFIG_IMX8MM) || defined(CONFIG_IMX8MN) || defined(CONFIG_IMX8MP)
Ye Li7e2ca9c2021-08-17 17:10:35 +0800108#define PAD_CTL_DSE1 (0x0 << 1)
109#define PAD_CTL_DSE2 (0x2 << 1)
110#define PAD_CTL_DSE4 (0x1 << 1)
111#define PAD_CTL_DSE6 (0x3 << 1)
Peng Fanf63b2762019-08-27 06:25:23 +0000112#define PAD_CTL_PE (0x1 << 8)
113#else
Ye Li7e2ca9c2021-08-17 17:10:35 +0800114#define PAD_CTL_DSE0 (0x0 << 0)
115#define PAD_CTL_DSE1 (0x1 << 0)
116#define PAD_CTL_DSE2 (0x2 << 0)
117#define PAD_CTL_DSE3 (0x3 << 0)
118#define PAD_CTL_DSE4 (0x4 << 0)
119#define PAD_CTL_DSE5 (0x5 << 0)
120#define PAD_CTL_DSE6 (0x6 << 0)
121#define PAD_CTL_DSE7 (0x7 << 0)
Peng Fan62ebfc62018-01-10 13:20:28 +0800122#define PAD_CTL_LVTTL (0x1 << 8)
Peng Fanf63b2762019-08-27 06:25:23 +0000123#endif
Peng Fan62ebfc62018-01-10 13:20:28 +0800124
125#elif defined CONFIG_MX7
Peng Fan1d5229a2016-08-11 14:02:51 +0800126
127#define IOMUX_LPSR_SEL_INPUT_OFS 0x70000
Adrian Alonso5d18b182015-08-11 11:19:50 -0500128
129#define PAD_CTL_DSE_1P8V_140OHM (0x0<<0)
130#define PAD_CTL_DSE_1P8V_35OHM (0x1<<0)
131#define PAD_CTL_DSE_1P8V_70OHM (0x2<<0)
132#define PAD_CTL_DSE_1P8V_23OHM (0x3<<0)
133
134#define PAD_CTL_DSE_3P3V_196OHM (0x0<<0)
135#define PAD_CTL_DSE_3P3V_49OHM (0x1<<0)
136#define PAD_CTL_DSE_3P3V_98OHM (0x2<<0)
137#define PAD_CTL_DSE_3P3V_32OHM (0x3<<0)
138
139#define PAD_CTL_SRE_FAST (0 << 2)
140#define PAD_CTL_SRE_SLOW (0x1 << 2)
141
142#define PAD_CTL_HYS (0x1 << 3)
143#define PAD_CTL_PUE (0x1 << 4)
144
145#define PAD_CTL_PUS_PD100KOHM ((0x0 << 5) | PAD_CTL_PUE)
146#define PAD_CTL_PUS_PU5KOHM ((0x1 << 5) | PAD_CTL_PUE)
147#define PAD_CTL_PUS_PU47KOHM ((0x2 << 5) | PAD_CTL_PUE)
148#define PAD_CTL_PUS_PU100KOHM ((0x3 << 5) | PAD_CTL_PUE)
149
150#else
151
Benoît Thébaudeaua83d1c32013-04-26 01:34:44 +0000152#ifdef CONFIG_MX6
153
Fabio Estevamebc89412013-04-10 09:32:56 +0000154#define PAD_CTL_HYS (1 << 16)
Benoît Thébaudeaub89e4502013-04-26 01:34:45 +0000155
Benoît Thébaudeau21670242013-04-26 01:34:47 +0000156#define PAD_CTL_PUS_100K_DOWN (0 << 14 | PAD_CTL_PUE)
157#define PAD_CTL_PUS_47K_UP (1 << 14 | PAD_CTL_PUE)
158#define PAD_CTL_PUS_100K_UP (2 << 14 | PAD_CTL_PUE)
159#define PAD_CTL_PUS_22K_UP (3 << 14 | PAD_CTL_PUE)
160#define PAD_CTL_PUE (1 << 13 | PAD_CTL_PKE)
Fabio Estevamebc89412013-04-10 09:32:56 +0000161#define PAD_CTL_PKE (1 << 12)
Benoît Thébaudeaub89e4502013-04-26 01:34:45 +0000162
Fabio Estevamebc89412013-04-10 09:32:56 +0000163#define PAD_CTL_ODE (1 << 11)
Benoît Thébaudeaub89e4502013-04-26 01:34:45 +0000164
Mark Jonasc5fa5c62018-04-16 18:11:50 +0200165#if defined(CONFIG_MX6SL)
Fabio Estevamebc89412013-04-10 09:32:56 +0000166#define PAD_CTL_SPEED_LOW (1 << 6)
Mark Jonasc5fa5c62018-04-16 18:11:50 +0200167#else
168#define PAD_CTL_SPEED_LOW (0 << 6)
Peng Fan80b24152015-07-20 19:28:30 +0800169#endif
Fabio Estevamebc89412013-04-10 09:32:56 +0000170#define PAD_CTL_SPEED_MED (2 << 6)
171#define PAD_CTL_SPEED_HIGH (3 << 6)
Benoît Thébaudeaub89e4502013-04-26 01:34:45 +0000172
Fabio Estevamebc89412013-04-10 09:32:56 +0000173#define PAD_CTL_DSE_DISABLE (0 << 3)
174#define PAD_CTL_DSE_240ohm (1 << 3)
175#define PAD_CTL_DSE_120ohm (2 << 3)
176#define PAD_CTL_DSE_80ohm (3 << 3)
177#define PAD_CTL_DSE_60ohm (4 << 3)
178#define PAD_CTL_DSE_48ohm (5 << 3)
179#define PAD_CTL_DSE_40ohm (6 << 3)
180#define PAD_CTL_DSE_34ohm (7 << 3)
Benoît Thébaudeaua83d1c32013-04-26 01:34:44 +0000181
Mark Jonasbd21a8e2018-06-28 15:56:18 +0200182#define PAD_CTL_DSE_260ohm (1 << 3)
183#define PAD_CTL_DSE_130ohm (2 << 3)
184#define PAD_CTL_DSE_88ohm (3 << 3)
185#define PAD_CTL_DSE_65ohm (4 << 3)
186#define PAD_CTL_DSE_52ohm (5 << 3)
187#define PAD_CTL_DSE_43ohm (6 << 3)
188#define PAD_CTL_DSE_37ohm (7 << 3)
189
Peng Fanc2038192016-12-11 19:24:24 +0800190/* i.MX6SL/SLL */
Fabio Estevamd3b17422014-04-29 10:15:46 -0300191#define PAD_CTL_LVE (1 << 1)
192#define PAD_CTL_LVE_BIT (1 << 22)
Peng Fanc2038192016-12-11 19:24:24 +0800193
194/* i.MX6SLL */
195#define PAD_CTL_IPD_BIT (1 << 27)
Fabio Estevamd3b17422014-04-29 10:15:46 -0300196
Alison Wang831beaf2013-05-27 22:55:41 +0000197#elif defined(CONFIG_VF610)
198
199#define PAD_MUX_MODE_SHIFT 20
200
Anthony Feliceaf0464f2014-09-06 19:47:06 +0200201#define PAD_CTL_INPUT_DIFFERENTIAL (1 << 16)
202
Alison Wang831beaf2013-05-27 22:55:41 +0000203#define PAD_CTL_SPEED_MED (1 << 12)
204#define PAD_CTL_SPEED_HIGH (3 << 12)
205
Stefan Agner0f527292014-08-06 10:59:35 +0200206#define PAD_CTL_SRE (1 << 11)
207
Albert ARIBAUD \(3ADEV\)40281ba2015-06-19 14:18:29 +0200208#define PAD_CTL_ODE (1 << 10)
209
Alison Wang2927a192014-05-06 09:13:02 +0800210#define PAD_CTL_DSE_150ohm (1 << 6)
Stefan Agner13011752017-04-11 11:12:14 +0530211#define PAD_CTL_DSE_75ohm (2 << 6)
Alison Wang831beaf2013-05-27 22:55:41 +0000212#define PAD_CTL_DSE_50ohm (3 << 6)
Stefan Agner13011752017-04-11 11:12:14 +0530213#define PAD_CTL_DSE_37ohm (4 << 6)
214#define PAD_CTL_DSE_30ohm (5 << 6)
Alison Wang831beaf2013-05-27 22:55:41 +0000215#define PAD_CTL_DSE_25ohm (6 << 6)
216#define PAD_CTL_DSE_20ohm (7 << 6)
217
218#define PAD_CTL_PUS_47K_UP (1 << 4 | PAD_CTL_PUE)
219#define PAD_CTL_PUS_100K_UP (2 << 4 | PAD_CTL_PUE)
Alison Wang2927a192014-05-06 09:13:02 +0800220#define PAD_CTL_PUS_22K_UP (3 << 4 | PAD_CTL_PUE)
Alison Wang831beaf2013-05-27 22:55:41 +0000221#define PAD_CTL_PKE (1 << 3)
222#define PAD_CTL_PUE (1 << 2 | PAD_CTL_PKE)
223
224#define PAD_CTL_OBE_IBE_ENABLE (3 << 0)
Stefan Agner0f527292014-08-06 10:59:35 +0200225#define PAD_CTL_OBE_ENABLE (1 << 1)
226#define PAD_CTL_IBE_ENABLE (1 << 0)
Alison Wang831beaf2013-05-27 22:55:41 +0000227
Benoît Thébaudeaua83d1c32013-04-26 01:34:44 +0000228#else
229
230#define PAD_CTL_DVS (1 << 13)
231#define PAD_CTL_INPUT_DDR (1 << 9)
232#define PAD_CTL_HYS (1 << 8)
233
234#define PAD_CTL_PKE (1 << 7)
235#define PAD_CTL_PUE (1 << 6 | PAD_CTL_PKE)
236#define PAD_CTL_PUS_100K_DOWN (0 << 4 | PAD_CTL_PUE)
237#define PAD_CTL_PUS_47K_UP (1 << 4 | PAD_CTL_PUE)
238#define PAD_CTL_PUS_100K_UP (2 << 4 | PAD_CTL_PUE)
239#define PAD_CTL_PUS_22K_UP (3 << 4 | PAD_CTL_PUE)
240
241#define PAD_CTL_ODE (1 << 3)
242
243#define PAD_CTL_DSE_LOW (0 << 1)
244#define PAD_CTL_DSE_MED (1 << 1)
245#define PAD_CTL_DSE_HIGH (2 << 1)
246#define PAD_CTL_DSE_MAX (3 << 1)
247
248#endif
249
Fabio Estevamebc89412013-04-10 09:32:56 +0000250#define PAD_CTL_SRE_SLOW (0 << 0)
Benoît Thébaudeaub89e4502013-04-26 01:34:45 +0000251#define PAD_CTL_SRE_FAST (1 << 0)
Fabio Estevamebc89412013-04-10 09:32:56 +0000252
Adrian Alonso5d18b182015-08-11 11:19:50 -0500253#endif
254
Angus Ainslie6ac768a2022-02-02 14:22:00 -0800255#define IMX_PAD_SION 0x40000000
Fabio Estevamebc89412013-04-10 09:32:56 +0000256#define IOMUX_CONFIG_SION 0x10
Benoît Thébaudeaub89e4502013-04-26 01:34:45 +0000257
258#define GPIO_PIN_MASK 0x1f
259#define GPIO_PORT_SHIFT 5
260#define GPIO_PORT_MASK (0x7 << GPIO_PORT_SHIFT)
261#define GPIO_PORTA (0 << GPIO_PORT_SHIFT)
262#define GPIO_PORTB (1 << GPIO_PORT_SHIFT)
263#define GPIO_PORTC (2 << GPIO_PORT_SHIFT)
264#define GPIO_PORTD (3 << GPIO_PORT_SHIFT)
265#define GPIO_PORTE (4 << GPIO_PORT_SHIFT)
266#define GPIO_PORTF (5 << GPIO_PORT_SHIFT)
Jason Liudec11122011-11-25 00:18:02 +0000267
Stefan Roese4982d9a2013-04-10 23:06:46 +0000268void imx_iomux_v3_setup_pad(iomux_v3_cfg_t pad);
269void imx_iomux_v3_setup_multiple_pads(iomux_v3_cfg_t const *pad_list,
Eric Nelson89110832012-10-03 07:26:37 +0000270 unsigned count);
Ye.Li700020e2014-10-30 18:53:49 +0800271/*
272* Set bits for general purpose registers
273*/
274void imx_iomux_set_gpr_register(int group, int start_bit,
275 int num_bits, int value);
Bhuvanchandra DV6d236aa2015-06-01 18:37:16 +0530276#ifdef CONFIG_IOMUX_SHARE_CONF_REG
277void imx_iomux_gpio_set_direction(unsigned int gpio,
278 unsigned int direction);
279void imx_iomux_gpio_get_function(unsigned int gpio,
280 u32 *gpio_state);
281#endif
Jason Liudec11122011-11-25 00:18:02 +0000282
Tim Harvey09a62332014-06-02 16:13:24 -0700283/* macros for declaring and using pinmux array */
284#if defined(CONFIG_MX6QDL)
285#define IOMUX_PADS(x) (MX6Q_##x), (MX6DL_##x)
286#define SETUP_IOMUX_PAD(def) \
Eran Matityahu13056022018-01-26 16:09:55 +0200287if (is_mx6dq() || is_mx6dqp()) { \
Tim Harvey09a62332014-06-02 16:13:24 -0700288 imx_iomux_v3_setup_pad(MX6Q_##def); \
289} else { \
290 imx_iomux_v3_setup_pad(MX6DL_##def); \
291}
292#define SETUP_IOMUX_PADS(x) \
293 imx_iomux_v3_setup_multiple_pads(x, ARRAY_SIZE(x)/2)
294#elif defined(CONFIG_MX6Q) || defined(CONFIG_MX6D)
295#define IOMUX_PADS(x) MX6Q_##x
296#define SETUP_IOMUX_PAD(def) \
297 imx_iomux_v3_setup_pad(MX6Q_##def);
298#define SETUP_IOMUX_PADS(x) \
299 imx_iomux_v3_setup_multiple_pads(x, ARRAY_SIZE(x))
Fabio Estevam1b691df2018-01-03 12:33:05 -0200300#elif defined(CONFIG_MX6UL) || defined(CONFIG_MX6ULL)
Jagan Teki89395642017-05-07 02:43:09 +0530301#define IOMUX_PADS(x) MX6_##x
302#define SETUP_IOMUX_PAD(def) \
303 imx_iomux_v3_setup_pad(MX6_##def);
304#define SETUP_IOMUX_PADS(x) \
305 imx_iomux_v3_setup_multiple_pads(x, ARRAY_SIZE(x))
Tim Harvey09a62332014-06-02 16:13:24 -0700306#else
307#define IOMUX_PADS(x) MX6DL_##x
308#define SETUP_IOMUX_PAD(def) \
309 imx_iomux_v3_setup_pad(MX6DL_##def);
310#define SETUP_IOMUX_PADS(x) \
311 imx_iomux_v3_setup_multiple_pads(x, ARRAY_SIZE(x))
312#endif
313
Jason Liudec11122011-11-25 00:18:02 +0000314#endif /* __MACH_IOMUX_V3_H__*/