blob: 8c68655399f811459cb5bcaa10bbb14005c53abc [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peng Fan0a25e8b2017-02-22 16:21:41 +08002/*
3 * Copyright (C) 2016 Freescale Semiconductor, Inc.
Peng Fan0a25e8b2017-02-22 16:21:41 +08004 */
5#include <common.h>
6#include <asm/io.h>
7#include <asm/arch/imx-regs.h>
8#include <asm/arch/iomux.h>
9
10static void *base = (void *)IOMUXC_BASE_ADDR;
11
12/*
13 * iomuxc0 base address. In imx7ulp-pins.h,
14 * the offsets of pins in iomuxc0 are from 0xD000,
15 * so we set the base address to (0x4103D000 - 0xD000 = 0x41030000)
16 */
17static void *base_mports = (void *)(AIPS0_BASE + 0x30000);
18
19/*
20 * configures a single pad in the iomuxer
21 */
22void mx7ulp_iomux_setup_pad(iomux_cfg_t pad)
23{
24 u32 mux_ctrl_ofs = (pad & MUX_CTRL_OFS_MASK) >> MUX_CTRL_OFS_SHIFT;
25 u32 mux_mode = (pad & MUX_MODE_MASK) >> MUX_MODE_SHIFT;
26 u32 sel_input_ofs =
27 (pad & MUX_SEL_INPUT_OFS_MASK) >> MUX_SEL_INPUT_OFS_SHIFT;
28 u32 sel_input =
29 (pad & MUX_SEL_INPUT_MASK) >> MUX_SEL_INPUT_SHIFT;
30 u32 pad_ctrl_ofs = mux_ctrl_ofs;
31 u32 pad_ctrl = (pad & MUX_PAD_CTRL_MASK) >> MUX_PAD_CTRL_SHIFT;
32
33 debug("[PAD CFG] = 0x%16llX \r\n\tmux_ctl = 0x%X(0x%X) sel_input = 0x%X(0x%X) pad_ctrl = 0x%X(0x%X)\r\n",
34 pad, mux_ctrl_ofs, mux_mode, sel_input_ofs, sel_input,
35 pad_ctrl_ofs, pad_ctrl);
36
37 if (mux_mode & IOMUX_CONFIG_MPORTS) {
38 mux_mode &= ~IOMUX_CONFIG_MPORTS;
39 base = base_mports;
40 } else {
41 base = (void *)IOMUXC_BASE_ADDR;
42 }
43
44 __raw_writel(((mux_mode << IOMUXC_PCR_MUX_ALT_SHIFT) &
45 IOMUXC_PCR_MUX_ALT_MASK), base + mux_ctrl_ofs);
46
47 if (sel_input_ofs)
48 __raw_writel((sel_input << IOMUXC_PSMI_IMUX_ALT_SHIFT),
49 base + sel_input_ofs);
50
51 if (!(pad_ctrl & NO_PAD_CTRL))
52 __raw_writel(((mux_mode << IOMUXC_PCR_MUX_ALT_SHIFT) &
53 IOMUXC_PCR_MUX_ALT_MASK) |
54 (pad_ctrl & (~IOMUXC_PCR_MUX_ALT_MASK)),
55 base + pad_ctrl_ofs);
56}
57
58/* configures a list of pads within declared with IOMUX_PADS macro */
59void mx7ulp_iomux_setup_multiple_pads(iomux_cfg_t const *pad_list,
60 unsigned count)
61{
62 iomux_cfg_t const *p = pad_list;
63 int i;
64
65 for (i = 0; i < count; i++) {
66 mx7ulp_iomux_setup_pad(*p);
67 p++;
68 }
69}