Marek Vasut | b473ec5 | 2011-11-08 23:18:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 by Jan Weitzel Phytec Messtechnik GmbH, |
| 3 | * <armlinux@phytec.de> |
| 4 | * Copyright (C) 2010 Freescale Semiconductor, Inc. All Rights Reserved. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version 2 |
| 9 | * of the License, or (at your option) any later version. |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| 18 | * MA 02110-1301, USA. |
| 19 | */ |
| 20 | |
| 21 | #ifndef __MACH_MXS_IOMUX_H__ |
| 22 | #define __MACH_MXS_IOMUX_H__ |
| 23 | |
| 24 | /* |
| 25 | * IOMUX/PAD Bit field definitions |
| 26 | * |
| 27 | * PAD_BANK: 0..2 (3) |
| 28 | * PAD_PIN: 3..7 (5) |
| 29 | * PAD_MUXSEL: 8..9 (2) |
| 30 | * PAD_MA: 10..11 (2) |
| 31 | * PAD_MA_VALID: 12 (1) |
| 32 | * PAD_VOL: 13 (1) |
| 33 | * PAD_VOL_VALID: 14 (1) |
| 34 | * PAD_PULL: 15 (1) |
| 35 | * PAD_PULL_VALID: 16 (1) |
| 36 | * RESERVED: 17..31 (15) |
| 37 | */ |
| 38 | typedef u32 iomux_cfg_t; |
| 39 | |
| 40 | #define MXS_PAD_BANK_SHIFT 0 |
| 41 | #define MXS_PAD_BANK_MASK ((iomux_cfg_t)0x7 << MXS_PAD_BANK_SHIFT) |
| 42 | #define MXS_PAD_PIN_SHIFT 3 |
| 43 | #define MXS_PAD_PIN_MASK ((iomux_cfg_t)0x1f << MXS_PAD_PIN_SHIFT) |
| 44 | #define MXS_PAD_MUXSEL_SHIFT 8 |
| 45 | #define MXS_PAD_MUXSEL_MASK ((iomux_cfg_t)0x3 << MXS_PAD_MUXSEL_SHIFT) |
| 46 | #define MXS_PAD_MA_SHIFT 10 |
| 47 | #define MXS_PAD_MA_MASK ((iomux_cfg_t)0x3 << MXS_PAD_MA_SHIFT) |
| 48 | #define MXS_PAD_MA_VALID_SHIFT 12 |
| 49 | #define MXS_PAD_MA_VALID_MASK ((iomux_cfg_t)0x1 << MXS_PAD_MA_VALID_SHIFT) |
| 50 | #define MXS_PAD_VOL_SHIFT 13 |
| 51 | #define MXS_PAD_VOL_MASK ((iomux_cfg_t)0x1 << MXS_PAD_VOL_SHIFT) |
| 52 | #define MXS_PAD_VOL_VALID_SHIFT 14 |
| 53 | #define MXS_PAD_VOL_VALID_MASK ((iomux_cfg_t)0x1 << MXS_PAD_VOL_VALID_SHIFT) |
| 54 | #define MXS_PAD_PULL_SHIFT 15 |
| 55 | #define MXS_PAD_PULL_MASK ((iomux_cfg_t)0x1 << MXS_PAD_PULL_SHIFT) |
| 56 | #define MXS_PAD_PULL_VALID_SHIFT 16 |
| 57 | #define MXS_PAD_PULL_VALID_MASK ((iomux_cfg_t)0x1 << MXS_PAD_PULL_VALID_SHIFT) |
| 58 | |
| 59 | #define PAD_MUXSEL_0 0 |
| 60 | #define PAD_MUXSEL_1 1 |
| 61 | #define PAD_MUXSEL_2 2 |
| 62 | #define PAD_MUXSEL_GPIO 3 |
| 63 | |
| 64 | #define PAD_4MA 0 |
| 65 | #define PAD_8MA 1 |
| 66 | #define PAD_12MA 2 |
| 67 | #define PAD_16MA 3 |
| 68 | |
| 69 | #define PAD_1V8 0 |
| 70 | #define PAD_3V3 1 |
| 71 | |
| 72 | #define PAD_NOPULL 0 |
| 73 | #define PAD_PULLUP 1 |
| 74 | |
| 75 | #define MXS_PAD_4MA ((PAD_4MA << MXS_PAD_MA_SHIFT) | \ |
| 76 | MXS_PAD_MA_VALID_MASK) |
| 77 | #define MXS_PAD_8MA ((PAD_8MA << MXS_PAD_MA_SHIFT) | \ |
| 78 | MXS_PAD_MA_VALID_MASK) |
| 79 | #define MXS_PAD_12MA ((PAD_12MA << MXS_PAD_MA_SHIFT) | \ |
| 80 | MXS_PAD_MA_VALID_MASK) |
| 81 | #define MXS_PAD_16MA ((PAD_16MA << MXS_PAD_MA_SHIFT) | \ |
| 82 | MXS_PAD_MA_VALID_MASK) |
| 83 | |
| 84 | #define MXS_PAD_1V8 ((PAD_1V8 << MXS_PAD_VOL_SHIFT) | \ |
| 85 | MXS_PAD_VOL_VALID_MASK) |
| 86 | #define MXS_PAD_3V3 ((PAD_3V3 << MXS_PAD_VOL_SHIFT) | \ |
| 87 | MXS_PAD_VOL_VALID_MASK) |
| 88 | |
| 89 | #define MXS_PAD_NOPULL ((PAD_NOPULL << MXS_PAD_PULL_SHIFT) | \ |
| 90 | MXS_PAD_PULL_VALID_MASK) |
| 91 | #define MXS_PAD_PULLUP ((PAD_PULLUP << MXS_PAD_PULL_SHIFT) | \ |
| 92 | MXS_PAD_PULL_VALID_MASK) |
| 93 | |
| 94 | /* generic pad control used in most cases */ |
| 95 | #define MXS_PAD_CTRL (MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL) |
| 96 | |
| 97 | #define MXS_IOMUX_PAD(_bank, _pin, _muxsel, _ma, _vol, _pull) \ |
| 98 | (((iomux_cfg_t)(_bank) << MXS_PAD_BANK_SHIFT) | \ |
| 99 | ((iomux_cfg_t)(_pin) << MXS_PAD_PIN_SHIFT) | \ |
| 100 | ((iomux_cfg_t)(_muxsel) << MXS_PAD_MUXSEL_SHIFT) | \ |
| 101 | ((iomux_cfg_t)(_ma) << MXS_PAD_MA_SHIFT) | \ |
| 102 | ((iomux_cfg_t)(_vol) << MXS_PAD_VOL_SHIFT) | \ |
| 103 | ((iomux_cfg_t)(_pull) << MXS_PAD_PULL_SHIFT)) |
| 104 | |
| 105 | /* |
| 106 | * A pad becomes naked, when none of mA, vol or pull |
| 107 | * validity bits is set. |
| 108 | */ |
| 109 | #define MXS_IOMUX_PAD_NAKED(_bank, _pin, _muxsel) \ |
| 110 | MXS_IOMUX_PAD(_bank, _pin, _muxsel, 0, 0, 0) |
| 111 | |
| 112 | static inline unsigned int PAD_BANK(iomux_cfg_t pad) |
| 113 | { |
| 114 | return (pad & MXS_PAD_BANK_MASK) >> MXS_PAD_BANK_SHIFT; |
| 115 | } |
| 116 | |
| 117 | static inline unsigned int PAD_PIN(iomux_cfg_t pad) |
| 118 | { |
| 119 | return (pad & MXS_PAD_PIN_MASK) >> MXS_PAD_PIN_SHIFT; |
| 120 | } |
| 121 | |
| 122 | static inline unsigned int PAD_MUXSEL(iomux_cfg_t pad) |
| 123 | { |
| 124 | return (pad & MXS_PAD_MUXSEL_MASK) >> MXS_PAD_MUXSEL_SHIFT; |
| 125 | } |
| 126 | |
| 127 | static inline unsigned int PAD_MA(iomux_cfg_t pad) |
| 128 | { |
| 129 | return (pad & MXS_PAD_MA_MASK) >> MXS_PAD_MA_SHIFT; |
| 130 | } |
| 131 | |
| 132 | static inline unsigned int PAD_MA_VALID(iomux_cfg_t pad) |
| 133 | { |
| 134 | return (pad & MXS_PAD_MA_VALID_MASK) >> MXS_PAD_MA_VALID_SHIFT; |
| 135 | } |
| 136 | |
| 137 | static inline unsigned int PAD_VOL(iomux_cfg_t pad) |
| 138 | { |
| 139 | return (pad & MXS_PAD_VOL_MASK) >> MXS_PAD_VOL_SHIFT; |
| 140 | } |
| 141 | |
| 142 | static inline unsigned int PAD_VOL_VALID(iomux_cfg_t pad) |
| 143 | { |
| 144 | return (pad & MXS_PAD_VOL_VALID_MASK) >> MXS_PAD_VOL_VALID_SHIFT; |
| 145 | } |
| 146 | |
| 147 | static inline unsigned int PAD_PULL(iomux_cfg_t pad) |
| 148 | { |
| 149 | return (pad & MXS_PAD_PULL_MASK) >> MXS_PAD_PULL_SHIFT; |
| 150 | } |
| 151 | |
| 152 | static inline unsigned int PAD_PULL_VALID(iomux_cfg_t pad) |
| 153 | { |
| 154 | return (pad & MXS_PAD_PULL_VALID_MASK) >> MXS_PAD_PULL_VALID_SHIFT; |
| 155 | } |
| 156 | |
| 157 | /* |
| 158 | * configures a single pad in the iomuxer |
| 159 | */ |
| 160 | int mxs_iomux_setup_pad(iomux_cfg_t pad); |
| 161 | |
| 162 | /* |
| 163 | * configures multiple pads |
| 164 | * convenient way to call the above function with tables |
| 165 | */ |
| 166 | int mxs_iomux_setup_multiple_pads(const iomux_cfg_t *pad_list, unsigned count); |
| 167 | |
| 168 | #endif /* __MACH_MXS_IOMUX_H__*/ |