]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/imx-common/iomux-v3.c
Merge branch 'karo-tx-uboot' into kc-merge
[karo-tx-uboot.git] / arch / arm / imx-common / iomux-v3.c
1 /*
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  *
9  * SPDX-License-Identifier:     GPL-2.0+
10  */
11 #include <common.h>
12 #include <asm/io.h>
13 #include <asm/arch/imx-regs.h>
14 #if !defined(CONFIG_SOC_MX25) && !defined(CONFIG_SOC_VF610)
15 #include <asm/arch/sys_proto.h>
16 #endif
17 #include <asm/imx-common/iomux-v3.h>
18
19 static void *base = (void *)IOMUXC_BASE_ADDR;
20
21 /*
22  * configures a single pad in the iomuxer
23  */
24 void imx_iomux_v3_setup_pad(iomux_v3_cfg_t pad)
25 {
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
36 #if defined CONFIG_SOC_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 #ifdef DEBUG
44         printf("PAD[%2d]=%016llx mux[%03x]=%02x pad[%03x]=%05x%c inp[%03x]=%d\n",
45                 i, pad, mux_ctrl_ofs, mux_mode, pad_ctrl_ofs, pad_ctrl,
46                 pad & PAD_CTRL_VALID ? ' ' : '!', sel_input_ofs, sel_input);
47 #endif
48
49         if (mux_ctrl_ofs)
50                 __raw_writel(mux_mode, base + mux_ctrl_ofs);
51
52         if (sel_input_ofs)
53                 __raw_writel(sel_input, base + sel_input_ofs);
54
55 #ifdef CONFIG_IOMUX_SHARE_CONF_REG
56         if (pad & PAD_CTRL_VALID)
57                 __raw_writel((mux_mode << PAD_MUX_MODE_SHIFT) | pad_ctrl,
58                         base + pad_ctrl_ofs);
59 #else
60         if ((pad & PAD_CTRL_VALID) && pad_ctrl_ofs)
61                 __raw_writel(pad_ctrl, base + pad_ctrl_ofs);
62 #endif
63 }
64
65 /* configures a list of pads within declared with IOMUX_PADS macro */
66 void imx_iomux_v3_setup_multiple_pads(iomux_v3_cfg_t const *pad_list,
67                                       unsigned count)
68 {
69         iomux_v3_cfg_t const *p = pad_list;
70         int stride;
71         int i;
72
73 #if defined(CONFIG_SOC_MX6QDL)
74         stride = 2;
75         if (!is_cpu_type(MXC_CPU_MX6Q) && !is_cpu_type(MXC_CPU_MX6D))
76                 p += 1;
77 #else
78         stride = 1;
79 #endif
80         for (i = 0; i < count; i++) {
81                 imx_iomux_v3_setup_pad(*p);
82                 p += stride;
83         }
84 }
85
86 void imx_iomux_set_gpr_register(int group, int start_bit,
87                                 int num_bits, int value)
88 {
89         u32 reg = readl(base + group * 4);
90
91         reg &= ~(((1 << num_bits) - 1) << start_bit);
92         reg |= value << start_bit;
93         writel(reg, base + group * 4);
94 }