Jason Liu | 23608e2 | 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 | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 9 | * SPDX-License-Identifier: GPL-2.0+ |
Jason Liu | 23608e2 | 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 | af2a35f | 2012-07-19 08:18:22 +0000 | [diff] [blame] | 14 | #include <asm/imx-common/iomux-v3.h> |
Jason Liu | 23608e2 | 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 | 59efa05 | 2013-04-10 23:06:46 +0000 | [diff] [blame] | 21 | void imx_iomux_v3_setup_pad(iomux_v3_cfg_t pad) |
Jason Liu | 23608e2 | 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 | |
| 33 | if (mux_ctrl_ofs) |
| 34 | __raw_writel(mux_mode, base + mux_ctrl_ofs); |
| 35 | |
| 36 | if (sel_input_ofs) |
| 37 | __raw_writel(sel_input, base + sel_input_ofs); |
| 38 | |
Alison Wang | cfd701b | 2013-05-27 22:55:41 +0000 | [diff] [blame] | 39 | #ifdef CONFIG_IOMUX_SHARE_CONF_REG |
| 40 | if (!(pad_ctrl & NO_PAD_CTRL)) |
| 41 | __raw_writel((mux_mode << PAD_MUX_MODE_SHIFT) | pad_ctrl, |
| 42 | base + pad_ctrl_ofs); |
| 43 | #else |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 44 | if (!(pad_ctrl & NO_PAD_CTRL) && pad_ctrl_ofs) |
| 45 | __raw_writel(pad_ctrl, base + pad_ctrl_ofs); |
Alison Wang | cfd701b | 2013-05-27 22:55:41 +0000 | [diff] [blame] | 46 | #endif |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Stefan Roese | 59efa05 | 2013-04-10 23:06:46 +0000 | [diff] [blame] | 49 | void imx_iomux_v3_setup_multiple_pads(iomux_v3_cfg_t const *pad_list, |
| 50 | unsigned count) |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 51 | { |
Eric Nelson | 5ae28d2 | 2012-10-03 07:26:37 +0000 | [diff] [blame] | 52 | iomux_v3_cfg_t const *p = pad_list; |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 53 | int i; |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 54 | |
Stefan Roese | 59efa05 | 2013-04-10 23:06:46 +0000 | [diff] [blame] | 55 | for (i = 0; i < count; i++) |
| 56 | imx_iomux_v3_setup_pad(*p++); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 57 | } |