Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 9 | * SPDX-License-Identifier: GPL-2.0+ |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 10 | */ |
| 11 | #include <common.h> |
| 12 | #include <asm/io.h> |
| 13 | #include <asm/arch/imx-regs.h> |
Troy Kisky | 2714e17 | 2012-07-19 08:18:22 +0000 | [diff] [blame] | 14 | #include <asm/imx-common/iomux-v3.h> |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 15 | |
| 16 | static void *base = (void *)IOMUXC_BASE_ADDR; |
| 17 | |
| 18 | /* |
| 19 | * configures a single pad in the iomuxer |
| 20 | */ |
Stefan Roese | 4982d9a | 2013-04-10 23:06:46 +0000 | [diff] [blame] | 21 | void imx_iomux_v3_setup_pad(iomux_v3_cfg_t pad) |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 22 | { |
| 23 | u32 mux_ctrl_ofs = (pad & MUX_CTRL_OFS_MASK) >> MUX_CTRL_OFS_SHIFT; |
| 24 | u32 mux_mode = (pad & MUX_MODE_MASK) >> MUX_MODE_SHIFT; |
| 25 | u32 sel_input_ofs = |
| 26 | (pad & MUX_SEL_INPUT_OFS_MASK) >> MUX_SEL_INPUT_OFS_SHIFT; |
| 27 | u32 sel_input = |
| 28 | (pad & MUX_SEL_INPUT_MASK) >> MUX_SEL_INPUT_SHIFT; |
| 29 | u32 pad_ctrl_ofs = |
| 30 | (pad & MUX_PAD_CTRL_OFS_MASK) >> MUX_PAD_CTRL_OFS_SHIFT; |
| 31 | u32 pad_ctrl = (pad & MUX_PAD_CTRL_MASK) >> MUX_PAD_CTRL_SHIFT; |
| 32 | |
Fabio Estevam | d3b1742 | 2014-04-29 10:15:46 -0300 | [diff] [blame] | 33 | #if defined CONFIG_MX6SL |
| 34 | /* Check whether LVE bit needs to be set */ |
| 35 | if (pad_ctrl & PAD_CTL_LVE) { |
| 36 | pad_ctrl &= ~PAD_CTL_LVE; |
| 37 | pad_ctrl |= PAD_CTL_LVE_BIT; |
| 38 | } |
| 39 | #endif |
| 40 | |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 41 | if (mux_ctrl_ofs) |
| 42 | __raw_writel(mux_mode, base + mux_ctrl_ofs); |
| 43 | |
| 44 | if (sel_input_ofs) |
| 45 | __raw_writel(sel_input, base + sel_input_ofs); |
| 46 | |
Alison Wang | 831beaf | 2013-05-27 22:55:41 +0000 | [diff] [blame] | 47 | #ifdef CONFIG_IOMUX_SHARE_CONF_REG |
| 48 | if (!(pad_ctrl & NO_PAD_CTRL)) |
| 49 | __raw_writel((mux_mode << PAD_MUX_MODE_SHIFT) | pad_ctrl, |
| 50 | base + pad_ctrl_ofs); |
| 51 | #else |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 52 | if (!(pad_ctrl & NO_PAD_CTRL) && pad_ctrl_ofs) |
| 53 | __raw_writel(pad_ctrl, base + pad_ctrl_ofs); |
Alison Wang | 831beaf | 2013-05-27 22:55:41 +0000 | [diff] [blame] | 54 | #endif |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Stefan Roese | 4982d9a | 2013-04-10 23:06:46 +0000 | [diff] [blame] | 57 | void imx_iomux_v3_setup_multiple_pads(iomux_v3_cfg_t const *pad_list, |
| 58 | unsigned count) |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 59 | { |
Eric Nelson | 8911083 | 2012-10-03 07:26:37 +0000 | [diff] [blame] | 60 | iomux_v3_cfg_t const *p = pad_list; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 61 | int i; |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 62 | |
Stefan Roese | 4982d9a | 2013-04-10 23:06:46 +0000 | [diff] [blame] | 63 | for (i = 0; i < count; i++) |
| 64 | imx_iomux_v3_setup_pad(*p++); |
Jason Liu | dec1112 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 65 | } |