Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Based on the iomux-v3.c from Linux kernel: |
| 4 | * Copyright (C) 2008 by Sascha Hauer <kernel@pengutronix.de> |
| 5 | * Copyright (C) 2009 by Jan Weitzel Phytec Messtechnik GmbH, |
| 6 | * <armlinux@phytec.de> |
| 7 | * |
| 8 | * Copyright (C) 2004-2011 Freescale Semiconductor, Inc. |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 9 | */ |
| 10 | #include <common.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <asm/arch/imx-regs.h> |
Stefano Babic | 552a848 | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 13 | #include <asm/mach-imx/iomux-v3.h> |
| 14 | #include <asm/mach-imx/sys_proto.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 | |
Peng Fan | 40913fb | 2016-12-11 19:24:24 +0800 | [diff] [blame] | 33 | #if defined(CONFIG_MX6SL) || defined(CONFIG_MX6SLL) |
Fabio Estevam | 98d2cff | 2014-04-29 10:15:46 -0300 | [diff] [blame] | 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 | |
Adrian Alonso | 03f0e4c | 2015-08-11 11:19:50 -0500 | [diff] [blame] | 41 | #ifdef CONFIG_IOMUX_LPSR |
| 42 | u32 lpsr = (pad & MUX_MODE_LPSR) >> MUX_MODE_SHIFT; |
| 43 | |
Peng Fan | 07e1c0a | 2016-08-11 14:02:51 +0800 | [diff] [blame] | 44 | #ifdef CONFIG_MX7 |
Adrian Alonso | 03f0e4c | 2015-08-11 11:19:50 -0500 | [diff] [blame] | 45 | if (lpsr == IOMUX_CONFIG_LPSR) { |
| 46 | base = (void *)IOMUXC_LPSR_BASE_ADDR; |
| 47 | mux_mode &= ~IOMUX_CONFIG_LPSR; |
| 48 | /* set daisy chain sel_input */ |
| 49 | if (sel_input_ofs) |
| 50 | sel_input_ofs += IOMUX_LPSR_SEL_INPUT_OFS; |
| 51 | } |
Peng Fan | 07e1c0a | 2016-08-11 14:02:51 +0800 | [diff] [blame] | 52 | #else |
Peng Fan | 40913fb | 2016-12-11 19:24:24 +0800 | [diff] [blame] | 53 | if (is_mx6ull() || is_mx6sll()) { |
Peng Fan | 07e1c0a | 2016-08-11 14:02:51 +0800 | [diff] [blame] | 54 | if (lpsr == IOMUX_CONFIG_LPSR) { |
| 55 | base = (void *)IOMUXC_SNVS_BASE_ADDR; |
| 56 | mux_mode &= ~IOMUX_CONFIG_LPSR; |
| 57 | } |
| 58 | } |
| 59 | #endif |
Adrian Alonso | 03f0e4c | 2015-08-11 11:19:50 -0500 | [diff] [blame] | 60 | #endif |
| 61 | |
Peng Fan | 40913fb | 2016-12-11 19:24:24 +0800 | [diff] [blame] | 62 | if (is_mx7() || is_mx6ull() || is_mx6sll() || mux_ctrl_ofs) |
Peng Fan | cf226d9 | 2015-09-23 11:13:28 +0800 | [diff] [blame] | 63 | __raw_writel(mux_mode, base + mux_ctrl_ofs); |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 64 | |
| 65 | if (sel_input_ofs) |
| 66 | __raw_writel(sel_input, base + sel_input_ofs); |
| 67 | |
Alison Wang | cfd701b | 2013-05-27 22:55:41 +0000 | [diff] [blame] | 68 | #ifdef CONFIG_IOMUX_SHARE_CONF_REG |
| 69 | if (!(pad_ctrl & NO_PAD_CTRL)) |
| 70 | __raw_writel((mux_mode << PAD_MUX_MODE_SHIFT) | pad_ctrl, |
| 71 | base + pad_ctrl_ofs); |
| 72 | #else |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 73 | if (!(pad_ctrl & NO_PAD_CTRL) && pad_ctrl_ofs) |
| 74 | __raw_writel(pad_ctrl, base + pad_ctrl_ofs); |
Peng Fan | 40913fb | 2016-12-11 19:24:24 +0800 | [diff] [blame] | 75 | #if defined(CONFIG_MX6SLL) |
| 76 | else if ((pad_ctrl & NO_PAD_CTRL) && pad_ctrl_ofs) |
| 77 | clrbits_le32(base + pad_ctrl_ofs, PAD_CTL_IPD_BIT); |
| 78 | #endif |
Alison Wang | cfd701b | 2013-05-27 22:55:41 +0000 | [diff] [blame] | 79 | #endif |
Adrian Alonso | 03f0e4c | 2015-08-11 11:19:50 -0500 | [diff] [blame] | 80 | |
| 81 | #ifdef CONFIG_IOMUX_LPSR |
| 82 | if (lpsr == IOMUX_CONFIG_LPSR) |
| 83 | base = (void *)IOMUXC_BASE_ADDR; |
| 84 | #endif |
| 85 | |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Tim Harvey | 5bf497e | 2014-06-02 16:13:24 -0700 | [diff] [blame] | 88 | /* configures a list of pads within declared with IOMUX_PADS macro */ |
Stefan Roese | 59efa05 | 2013-04-10 23:06:46 +0000 | [diff] [blame] | 89 | void imx_iomux_v3_setup_multiple_pads(iomux_v3_cfg_t const *pad_list, |
| 90 | unsigned count) |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 91 | { |
Eric Nelson | 5ae28d2 | 2012-10-03 07:26:37 +0000 | [diff] [blame] | 92 | iomux_v3_cfg_t const *p = pad_list; |
Tim Harvey | 5bf497e | 2014-06-02 16:13:24 -0700 | [diff] [blame] | 93 | int stride; |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 94 | int i; |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 95 | |
Tim Harvey | 5bf497e | 2014-06-02 16:13:24 -0700 | [diff] [blame] | 96 | #if defined(CONFIG_MX6QDL) |
| 97 | stride = 2; |
Filip Brozovic | 514a0f4 | 2016-09-14 13:50:39 +0200 | [diff] [blame] | 98 | if (!is_mx6dq() && !is_mx6dqp()) |
Tim Harvey | 5bf497e | 2014-06-02 16:13:24 -0700 | [diff] [blame] | 99 | p += 1; |
| 100 | #else |
| 101 | stride = 1; |
| 102 | #endif |
| 103 | for (i = 0; i < count; i++) { |
| 104 | imx_iomux_v3_setup_pad(*p); |
| 105 | p += stride; |
| 106 | } |
Jason Liu | 23608e2 | 2011-11-25 00:18:02 +0000 | [diff] [blame] | 107 | } |
Ye.Li | 8fe280f | 2014-10-30 18:53:49 +0800 | [diff] [blame] | 108 | |
| 109 | void imx_iomux_set_gpr_register(int group, int start_bit, |
| 110 | int num_bits, int value) |
| 111 | { |
| 112 | int i = 0; |
| 113 | u32 reg; |
| 114 | reg = readl(base + group * 4); |
| 115 | while (num_bits) { |
| 116 | reg &= ~(1<<(start_bit + i)); |
| 117 | i++; |
| 118 | num_bits--; |
| 119 | } |
| 120 | reg |= (value << start_bit); |
| 121 | writel(reg, base + group * 4); |
| 122 | } |
Bhuvanchandra DV | d348a94 | 2015-06-01 18:37:16 +0530 | [diff] [blame] | 123 | |
| 124 | #ifdef CONFIG_IOMUX_SHARE_CONF_REG |
| 125 | void imx_iomux_gpio_set_direction(unsigned int gpio, |
| 126 | unsigned int direction) |
| 127 | { |
| 128 | u32 reg; |
| 129 | /* |
| 130 | * Only on Vybrid the input/output buffer enable flags |
| 131 | * are part of the shared mux/conf register. |
| 132 | */ |
| 133 | reg = readl(base + (gpio << 2)); |
| 134 | |
| 135 | if (direction) |
| 136 | reg |= 0x2; |
| 137 | else |
| 138 | reg &= ~0x2; |
| 139 | |
| 140 | writel(reg, base + (gpio << 2)); |
| 141 | } |
| 142 | |
| 143 | void imx_iomux_gpio_get_function(unsigned int gpio, u32 *gpio_state) |
| 144 | { |
| 145 | *gpio_state = readl(base + (gpio << 2)) & |
| 146 | ((0X07 << PAD_MUX_MODE_SHIFT) | PAD_CTL_OBE_IBE_ENABLE); |
| 147 | } |
| 148 | #endif |