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> |
Stefano Babic | 5d2ad2b | 2014-06-25 12:48:06 +0200 | [diff] [blame] | 14 | #if !defined(CONFIG_MX25) && !defined(CONFIG_VF610) |
Tim Harvey | 5bf497e | 2014-06-02 16:13:24 -0700 | [diff] [blame] | 15 | #include <asm/arch/sys_proto.h> |
Stefano Babic | 67a04ab | 2014-06-06 10:58:47 +0200 | [diff] [blame] | 16 | #endif |
Troy Kisky | af2a35f | 2012-07-19 08:18:22 +0000 | [diff] [blame] | 17 | #include <asm/imx-common/iomux-v3.h> |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 18 | |
| 19 | static void *base = (void *)IOMUXC_BASE_ADDR; |
| 20 | |
| 21 | /* |
| 22 | * configures a single pad in the iomuxer |
| 23 | */ |
Stefan Roese | 59efa05 | 2013-04-10 23:06:46 +0000 | [diff] [blame] | 24 | void imx_iomux_v3_setup_pad(iomux_v3_cfg_t pad) |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 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 | |
Fabio Estevam | 98d2cff | 2014-04-29 10:15:46 -0300 | [diff] [blame] | 36 | #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 | |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 44 | if (mux_ctrl_ofs) |
| 45 | __raw_writel(mux_mode, base + mux_ctrl_ofs); |
| 46 | |
| 47 | if (sel_input_ofs) |
| 48 | __raw_writel(sel_input, base + sel_input_ofs); |
| 49 | |
Alison Wang | cfd701b | 2013-05-27 22:55:41 +0000 | [diff] [blame] | 50 | #ifdef CONFIG_IOMUX_SHARE_CONF_REG |
| 51 | if (!(pad_ctrl & NO_PAD_CTRL)) |
| 52 | __raw_writel((mux_mode << PAD_MUX_MODE_SHIFT) | pad_ctrl, |
| 53 | base + pad_ctrl_ofs); |
| 54 | #else |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 55 | if (!(pad_ctrl & NO_PAD_CTRL) && pad_ctrl_ofs) |
| 56 | __raw_writel(pad_ctrl, base + pad_ctrl_ofs); |
Alison Wang | cfd701b | 2013-05-27 22:55:41 +0000 | [diff] [blame] | 57 | #endif |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Tim Harvey | 5bf497e | 2014-06-02 16:13:24 -0700 | [diff] [blame] | 60 | /* configures a list of pads within declared with IOMUX_PADS macro */ |
Stefan Roese | 59efa05 | 2013-04-10 23:06:46 +0000 | [diff] [blame] | 61 | void imx_iomux_v3_setup_multiple_pads(iomux_v3_cfg_t const *pad_list, |
| 62 | unsigned count) |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 63 | { |
Eric Nelson | 5ae28d2 | 2012-10-03 07:26:37 +0000 | [diff] [blame] | 64 | iomux_v3_cfg_t const *p = pad_list; |
Tim Harvey | 5bf497e | 2014-06-02 16:13:24 -0700 | [diff] [blame] | 65 | int stride; |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 66 | int i; |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 67 | |
Tim Harvey | 5bf497e | 2014-06-02 16:13:24 -0700 | [diff] [blame] | 68 | #if defined(CONFIG_MX6QDL) |
| 69 | stride = 2; |
| 70 | if (!is_cpu_type(MXC_CPU_MX6Q) && !is_cpu_type(MXC_CPU_MX6D)) |
| 71 | p += 1; |
| 72 | #else |
| 73 | stride = 1; |
| 74 | #endif |
| 75 | for (i = 0; i < count; i++) { |
| 76 | imx_iomux_v3_setup_pad(*p); |
| 77 | p += stride; |
| 78 | } |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 79 | } |
Ye.Li | 8fe280f | 2014-10-30 18:53:49 +0800 | [diff] [blame] | 80 | |
| 81 | void imx_iomux_set_gpr_register(int group, int start_bit, |
| 82 | int num_bits, int value) |
| 83 | { |
| 84 | int i = 0; |
| 85 | u32 reg; |
| 86 | reg = readl(base + group * 4); |
| 87 | while (num_bits) { |
| 88 | reg &= ~(1<<(start_bit + i)); |
| 89 | i++; |
| 90 | num_bits--; |
| 91 | } |
| 92 | reg |= (value << start_bit); |
| 93 | writel(reg, base + group * 4); |
| 94 | } |
Bhuvanchandra DV | d348a94 | 2015-06-01 18:37:16 +0530 | [diff] [blame] | 95 | |
| 96 | #ifdef CONFIG_IOMUX_SHARE_CONF_REG |
| 97 | void imx_iomux_gpio_set_direction(unsigned int gpio, |
| 98 | unsigned int direction) |
| 99 | { |
| 100 | u32 reg; |
| 101 | /* |
| 102 | * Only on Vybrid the input/output buffer enable flags |
| 103 | * are part of the shared mux/conf register. |
| 104 | */ |
| 105 | reg = readl(base + (gpio << 2)); |
| 106 | |
| 107 | if (direction) |
| 108 | reg |= 0x2; |
| 109 | else |
| 110 | reg &= ~0x2; |
| 111 | |
| 112 | writel(reg, base + (gpio << 2)); |
| 113 | } |
| 114 | |
| 115 | void imx_iomux_gpio_get_function(unsigned int gpio, u32 *gpio_state) |
| 116 | { |
| 117 | *gpio_state = readl(base + (gpio << 2)) & |
| 118 | ((0X07 << PAD_MUX_MODE_SHIFT) | PAD_CTL_OBE_IBE_ENABLE); |
| 119 | } |
| 120 | #endif |