blob: 9b9cf58b75694d25a6564cf9960b28f82f519ffb [file] [log] [blame]
Jason Liudec11122011-11-25 00:18:02 +00001/*
2 * Based on the iomux-v3.c from Linux kernel:
3 * Copyright (C) 2008 by Sascha Hauer <kernel@pengutronix.de>
4 * Copyright (C) 2009 by Jan Weitzel Phytec Messtechnik GmbH,
5 * <armlinux@phytec.de>
6 *
7 * Copyright (C) 2004-2011 Freescale Semiconductor, Inc.
8 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
Jason Liudec11122011-11-25 00:18:02 +000010 */
11#include <common.h>
12#include <asm/io.h>
13#include <asm/arch/imx-regs.h>
Stefano Babic6f51ab12014-06-25 12:48:06 +020014#if !defined(CONFIG_MX25) && !defined(CONFIG_VF610)
Tim Harvey09a62332014-06-02 16:13:24 -070015#include <asm/arch/sys_proto.h>
Stefano Babic6d8a1bf2014-06-06 10:58:47 +020016#endif
Troy Kisky2714e172012-07-19 08:18:22 +000017#include <asm/imx-common/iomux-v3.h>
Jason Liudec11122011-11-25 00:18:02 +000018
19static void *base = (void *)IOMUXC_BASE_ADDR;
20
21/*
22 * configures a single pad in the iomuxer
23 */
Stefan Roese4982d9a2013-04-10 23:06:46 +000024void imx_iomux_v3_setup_pad(iomux_v3_cfg_t pad)
Jason Liudec11122011-11-25 00:18:02 +000025{
26 u32 mux_ctrl_ofs = (pad & MUX_CTRL_OFS_MASK) >> MUX_CTRL_OFS_SHIFT;
27 u32 mux_mode = (pad & MUX_MODE_MASK) >> MUX_MODE_SHIFT;
28 u32 sel_input_ofs =
29 (pad & MUX_SEL_INPUT_OFS_MASK) >> MUX_SEL_INPUT_OFS_SHIFT;
30 u32 sel_input =
31 (pad & MUX_SEL_INPUT_MASK) >> MUX_SEL_INPUT_SHIFT;
32 u32 pad_ctrl_ofs =
33 (pad & MUX_PAD_CTRL_OFS_MASK) >> MUX_PAD_CTRL_OFS_SHIFT;
34 u32 pad_ctrl = (pad & MUX_PAD_CTRL_MASK) >> MUX_PAD_CTRL_SHIFT;
35
Fabio Estevamd3b17422014-04-29 10:15:46 -030036#if defined CONFIG_MX6SL
37 /* Check whether LVE bit needs to be set */
38 if (pad_ctrl & PAD_CTL_LVE) {
39 pad_ctrl &= ~PAD_CTL_LVE;
40 pad_ctrl |= PAD_CTL_LVE_BIT;
41 }
42#endif
43
Adrian Alonso5d18b182015-08-11 11:19:50 -050044#ifdef CONFIG_IOMUX_LPSR
45 u32 lpsr = (pad & MUX_MODE_LPSR) >> MUX_MODE_SHIFT;
46
47 if (lpsr == IOMUX_CONFIG_LPSR) {
48 base = (void *)IOMUXC_LPSR_BASE_ADDR;
49 mux_mode &= ~IOMUX_CONFIG_LPSR;
50 /* set daisy chain sel_input */
51 if (sel_input_ofs)
52 sel_input_ofs += IOMUX_LPSR_SEL_INPUT_OFS;
53 }
54#endif
55
Peng Fan0d9f3302015-09-14 13:34:43 +080056 __raw_writel(mux_mode, base + mux_ctrl_ofs);
Jason Liudec11122011-11-25 00:18:02 +000057
58 if (sel_input_ofs)
59 __raw_writel(sel_input, base + sel_input_ofs);
60
Alison Wang831beaf2013-05-27 22:55:41 +000061#ifdef CONFIG_IOMUX_SHARE_CONF_REG
62 if (!(pad_ctrl & NO_PAD_CTRL))
63 __raw_writel((mux_mode << PAD_MUX_MODE_SHIFT) | pad_ctrl,
64 base + pad_ctrl_ofs);
65#else
Jason Liudec11122011-11-25 00:18:02 +000066 if (!(pad_ctrl & NO_PAD_CTRL) && pad_ctrl_ofs)
67 __raw_writel(pad_ctrl, base + pad_ctrl_ofs);
Alison Wang831beaf2013-05-27 22:55:41 +000068#endif
Adrian Alonso5d18b182015-08-11 11:19:50 -050069
70#ifdef CONFIG_IOMUX_LPSR
71 if (lpsr == IOMUX_CONFIG_LPSR)
72 base = (void *)IOMUXC_BASE_ADDR;
73#endif
74
Jason Liudec11122011-11-25 00:18:02 +000075}
76
Tim Harvey09a62332014-06-02 16:13:24 -070077/* configures a list of pads within declared with IOMUX_PADS macro */
Stefan Roese4982d9a2013-04-10 23:06:46 +000078void imx_iomux_v3_setup_multiple_pads(iomux_v3_cfg_t const *pad_list,
79 unsigned count)
Jason Liudec11122011-11-25 00:18:02 +000080{
Eric Nelson89110832012-10-03 07:26:37 +000081 iomux_v3_cfg_t const *p = pad_list;
Tim Harvey09a62332014-06-02 16:13:24 -070082 int stride;
Jason Liudec11122011-11-25 00:18:02 +000083 int i;
Jason Liudec11122011-11-25 00:18:02 +000084
Tim Harvey09a62332014-06-02 16:13:24 -070085#if defined(CONFIG_MX6QDL)
86 stride = 2;
87 if (!is_cpu_type(MXC_CPU_MX6Q) && !is_cpu_type(MXC_CPU_MX6D))
88 p += 1;
89#else
90 stride = 1;
91#endif
92 for (i = 0; i < count; i++) {
93 imx_iomux_v3_setup_pad(*p);
94 p += stride;
95 }
Jason Liudec11122011-11-25 00:18:02 +000096}
Ye.Li700020e2014-10-30 18:53:49 +080097
98void imx_iomux_set_gpr_register(int group, int start_bit,
99 int num_bits, int value)
100{
101 int i = 0;
102 u32 reg;
103 reg = readl(base + group * 4);
104 while (num_bits) {
105 reg &= ~(1<<(start_bit + i));
106 i++;
107 num_bits--;
108 }
109 reg |= (value << start_bit);
110 writel(reg, base + group * 4);
111}
Bhuvanchandra DV6d236aa2015-06-01 18:37:16 +0530112
113#ifdef CONFIG_IOMUX_SHARE_CONF_REG
114void imx_iomux_gpio_set_direction(unsigned int gpio,
115 unsigned int direction)
116{
117 u32 reg;
118 /*
119 * Only on Vybrid the input/output buffer enable flags
120 * are part of the shared mux/conf register.
121 */
122 reg = readl(base + (gpio << 2));
123
124 if (direction)
125 reg |= 0x2;
126 else
127 reg &= ~0x2;
128
129 writel(reg, base + (gpio << 2));
130}
131
132void imx_iomux_gpio_get_function(unsigned int gpio, u32 *gpio_state)
133{
134 *gpio_state = readl(base + (gpio << 2)) &
135 ((0X07 << PAD_MUX_MODE_SHIFT) | PAD_CTL_OBE_IBE_ENABLE);
136}
137#endif