blob: c134e95ed78059fda725c65eb5f8cbed4deaa79d [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 the iomux-v3.c from Linux kernel:
4 * Copyright (C) 2008 by Sascha Hauer <kernel@pengutronix.de>
5 * Copyright (C) 2009 by Jan Weitzel Phytec Messtechnik GmbH,
6 * <armlinux@phytec.de>
7 *
8 * Copyright (C) 2004-2011 Freescale Semiconductor, Inc.
Jason Liudec11122011-11-25 00:18:02 +00009 */
Jason Liudec11122011-11-25 00:18:02 +000010#include <asm/io.h>
11#include <asm/arch/imx-regs.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020012#include <asm/mach-imx/iomux-v3.h>
13#include <asm/mach-imx/sys_proto.h>
Jason Liudec11122011-11-25 00:18:02 +000014
15static void *base = (void *)IOMUXC_BASE_ADDR;
16
17/*
18 * configures a single pad in the iomuxer
19 */
Stefan Roese4982d9a2013-04-10 23:06:46 +000020void imx_iomux_v3_setup_pad(iomux_v3_cfg_t pad)
Jason Liudec11122011-11-25 00:18:02 +000021{
22 u32 mux_ctrl_ofs = (pad & MUX_CTRL_OFS_MASK) >> MUX_CTRL_OFS_SHIFT;
23 u32 mux_mode = (pad & MUX_MODE_MASK) >> MUX_MODE_SHIFT;
24 u32 sel_input_ofs =
25 (pad & MUX_SEL_INPUT_OFS_MASK) >> MUX_SEL_INPUT_OFS_SHIFT;
26 u32 sel_input =
27 (pad & MUX_SEL_INPUT_MASK) >> MUX_SEL_INPUT_SHIFT;
28 u32 pad_ctrl_ofs =
29 (pad & MUX_PAD_CTRL_OFS_MASK) >> MUX_PAD_CTRL_OFS_SHIFT;
30 u32 pad_ctrl = (pad & MUX_PAD_CTRL_MASK) >> MUX_PAD_CTRL_SHIFT;
31
Peng Fanc2038192016-12-11 19:24:24 +080032#if defined(CONFIG_MX6SL) || defined(CONFIG_MX6SLL)
Fabio Estevamd3b17422014-04-29 10:15:46 -030033 /* Check whether LVE bit needs to be set */
34 if (pad_ctrl & PAD_CTL_LVE) {
35 pad_ctrl &= ~PAD_CTL_LVE;
36 pad_ctrl |= PAD_CTL_LVE_BIT;
37 }
38#endif
39
Adrian Alonso5d18b182015-08-11 11:19:50 -050040#ifdef CONFIG_IOMUX_LPSR
41 u32 lpsr = (pad & MUX_MODE_LPSR) >> MUX_MODE_SHIFT;
42
Peng Fan1d5229a2016-08-11 14:02:51 +080043#ifdef CONFIG_MX7
Adrian Alonso5d18b182015-08-11 11:19:50 -050044 if (lpsr == IOMUX_CONFIG_LPSR) {
45 base = (void *)IOMUXC_LPSR_BASE_ADDR;
46 mux_mode &= ~IOMUX_CONFIG_LPSR;
47 /* set daisy chain sel_input */
48 if (sel_input_ofs)
49 sel_input_ofs += IOMUX_LPSR_SEL_INPUT_OFS;
50 }
Peng Fan1d5229a2016-08-11 14:02:51 +080051#else
Peng Fanc2038192016-12-11 19:24:24 +080052 if (is_mx6ull() || is_mx6sll()) {
Peng Fan1d5229a2016-08-11 14:02:51 +080053 if (lpsr == IOMUX_CONFIG_LPSR) {
54 base = (void *)IOMUXC_SNVS_BASE_ADDR;
55 mux_mode &= ~IOMUX_CONFIG_LPSR;
56 }
57 }
58#endif
Adrian Alonso5d18b182015-08-11 11:19:50 -050059#endif
60
Peng Fanc2038192016-12-11 19:24:24 +080061 if (is_mx7() || is_mx6ull() || is_mx6sll() || mux_ctrl_ofs)
Peng Fanaaf6e092015-09-23 11:13:28 +080062 __raw_writel(mux_mode, base + mux_ctrl_ofs);
Jason Liudec11122011-11-25 00:18:02 +000063
64 if (sel_input_ofs)
65 __raw_writel(sel_input, base + sel_input_ofs);
66
Alison Wang831beaf2013-05-27 22:55:41 +000067#ifdef CONFIG_IOMUX_SHARE_CONF_REG
68 if (!(pad_ctrl & NO_PAD_CTRL))
69 __raw_writel((mux_mode << PAD_MUX_MODE_SHIFT) | pad_ctrl,
70 base + pad_ctrl_ofs);
71#else
Jason Liudec11122011-11-25 00:18:02 +000072 if (!(pad_ctrl & NO_PAD_CTRL) && pad_ctrl_ofs)
73 __raw_writel(pad_ctrl, base + pad_ctrl_ofs);
Peng Fanc2038192016-12-11 19:24:24 +080074#if defined(CONFIG_MX6SLL)
75 else if ((pad_ctrl & NO_PAD_CTRL) && pad_ctrl_ofs)
76 clrbits_le32(base + pad_ctrl_ofs, PAD_CTL_IPD_BIT);
77#endif
Alison Wang831beaf2013-05-27 22:55:41 +000078#endif
Adrian Alonso5d18b182015-08-11 11:19:50 -050079
80#ifdef CONFIG_IOMUX_LPSR
81 if (lpsr == IOMUX_CONFIG_LPSR)
82 base = (void *)IOMUXC_BASE_ADDR;
83#endif
84
Jason Liudec11122011-11-25 00:18:02 +000085}
86
Tim Harvey09a62332014-06-02 16:13:24 -070087/* configures a list of pads within declared with IOMUX_PADS macro */
Stefan Roese4982d9a2013-04-10 23:06:46 +000088void imx_iomux_v3_setup_multiple_pads(iomux_v3_cfg_t const *pad_list,
89 unsigned count)
Jason Liudec11122011-11-25 00:18:02 +000090{
Eric Nelson89110832012-10-03 07:26:37 +000091 iomux_v3_cfg_t const *p = pad_list;
Tim Harvey09a62332014-06-02 16:13:24 -070092 int stride;
Jason Liudec11122011-11-25 00:18:02 +000093 int i;
Jason Liudec11122011-11-25 00:18:02 +000094
Tim Harvey09a62332014-06-02 16:13:24 -070095#if defined(CONFIG_MX6QDL)
96 stride = 2;
Filip Brozovicb6e09182016-09-14 13:50:39 +020097 if (!is_mx6dq() && !is_mx6dqp())
Tim Harvey09a62332014-06-02 16:13:24 -070098 p += 1;
99#else
100 stride = 1;
101#endif
102 for (i = 0; i < count; i++) {
103 imx_iomux_v3_setup_pad(*p);
104 p += stride;
105 }
Jason Liudec11122011-11-25 00:18:02 +0000106}
Ye.Li700020e2014-10-30 18:53:49 +0800107
108void imx_iomux_set_gpr_register(int group, int start_bit,
109 int num_bits, int value)
110{
111 int i = 0;
112 u32 reg;
113 reg = readl(base + group * 4);
114 while (num_bits) {
115 reg &= ~(1<<(start_bit + i));
116 i++;
117 num_bits--;
118 }
119 reg |= (value << start_bit);
120 writel(reg, base + group * 4);
121}
Bhuvanchandra DV6d236aa2015-06-01 18:37:16 +0530122
123#ifdef CONFIG_IOMUX_SHARE_CONF_REG
124void imx_iomux_gpio_set_direction(unsigned int gpio,
125 unsigned int direction)
126{
127 u32 reg;
128 /*
129 * Only on Vybrid the input/output buffer enable flags
130 * are part of the shared mux/conf register.
131 */
132 reg = readl(base + (gpio << 2));
133
134 if (direction)
135 reg |= 0x2;
136 else
137 reg &= ~0x2;
138
139 writel(reg, base + (gpio << 2));
140}
141
142void imx_iomux_gpio_get_function(unsigned int gpio, u32 *gpio_state)
143{
144 *gpio_state = readl(base + (gpio << 2)) &
145 ((0X07 << PAD_MUX_MODE_SHIFT) | PAD_CTL_OBE_IBE_ENABLE);
146}
147#endif