Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2010-2013, NVIDIA CORPORATION. All rights reserved. |
| 3 | * Copyright (c) 2011 The Chromium OS Authors. |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <asm/arch/pinmux.h> |
| 11 | |
| 12 | /* return 1 if a pingrp is in range */ |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 13 | #define pmux_pingrp_isvalid(pin) (((pin) >= 0) && ((pin) < PMUX_PINGRP_COUNT)) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 14 | |
| 15 | /* return 1 if a pmux_func is in range */ |
| 16 | #define pmux_func_isvalid(func) \ |
Stephen Warren | 70b080f | 2014-03-21 15:58:03 -0600 | [diff] [blame] | 17 | (((func) >= 0) && ((func) < PMUX_FUNC_COUNT)) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 18 | |
| 19 | /* return 1 if a pin_pupd_is in range */ |
| 20 | #define pmux_pin_pupd_isvalid(pupd) \ |
| 21 | (((pupd) >= PMUX_PULL_NORMAL) && ((pupd) <= PMUX_PULL_UP)) |
| 22 | |
| 23 | /* return 1 if a pin_tristate_is in range */ |
| 24 | #define pmux_pin_tristate_isvalid(tristate) \ |
| 25 | (((tristate) >= PMUX_TRI_NORMAL) && ((tristate) <= PMUX_TRI_TRISTATE)) |
| 26 | |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 27 | #ifdef TEGRA_PMX_PINS_HAVE_E_INPUT |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 28 | /* return 1 if a pin_io_is in range */ |
| 29 | #define pmux_pin_io_isvalid(io) \ |
| 30 | (((io) >= PMUX_PIN_OUTPUT) && ((io) <= PMUX_PIN_INPUT)) |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 31 | #endif |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 32 | |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 33 | #ifdef TEGRA_PMX_PINS_HAVE_LOCK |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 34 | /* return 1 if a pin_lock is in range */ |
| 35 | #define pmux_pin_lock_isvalid(lock) \ |
| 36 | (((lock) >= PMUX_PIN_LOCK_DISABLE) && ((lock) <= PMUX_PIN_LOCK_ENABLE)) |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 37 | #endif |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 38 | |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 39 | #ifdef TEGRA_PMX_PINS_HAVE_OD |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 40 | /* return 1 if a pin_od is in range */ |
| 41 | #define pmux_pin_od_isvalid(od) \ |
| 42 | (((od) >= PMUX_PIN_OD_DISABLE) && ((od) <= PMUX_PIN_OD_ENABLE)) |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 43 | #endif |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 44 | |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 45 | #ifdef TEGRA_PMX_PINS_HAVE_IO_RESET |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 46 | /* return 1 if a pin_ioreset_is in range */ |
| 47 | #define pmux_pin_ioreset_isvalid(ioreset) \ |
| 48 | (((ioreset) >= PMUX_PIN_IO_RESET_DISABLE) && \ |
| 49 | ((ioreset) <= PMUX_PIN_IO_RESET_ENABLE)) |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 50 | #endif |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 51 | |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 52 | #ifdef TEGRA_PMX_PINS_HAVE_RCV_SEL |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 53 | /* return 1 if a pin_rcv_sel_is in range */ |
| 54 | #define pmux_pin_rcv_sel_isvalid(rcv_sel) \ |
| 55 | (((rcv_sel) >= PMUX_PIN_RCV_SEL_NORMAL) && \ |
| 56 | ((rcv_sel) <= PMUX_PIN_RCV_SEL_HIGH)) |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 57 | #endif |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 58 | |
Stephen Warren | 899a5cb | 2015-02-24 14:08:26 -0700 | [diff] [blame^] | 59 | #ifdef TEGRA_PMX_GRPS_HAVE_LPMD |
| 60 | #define pmux_lpmd_isvalid(lpm) \ |
| 61 | (((lpm) >= PMUX_LPMD_X8) && ((lpm) <= PMUX_LPMD_X)) |
| 62 | #endif |
| 63 | |
| 64 | #ifdef TEGRA_PMX_GRPS_HAVE_SCHMT |
| 65 | #define pmux_schmt_isvalid(schmt) \ |
| 66 | (((schmt) >= PMUX_SCHMT_DISABLE) && ((schmt) <= PMUX_SCHMT_ENABLE)) |
| 67 | #endif |
| 68 | |
| 69 | #ifdef TEGRA_PMX_GRPS_HAVE_HSM |
| 70 | #define pmux_hsm_isvalid(hsm) \ |
| 71 | (((hsm) >= PMUX_HSM_DISABLE) && ((hsm) <= PMUX_HSM_ENABLE)) |
| 72 | #endif |
| 73 | |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 74 | #define _R(offset) (u32 *)(NV_PA_APB_MISC_BASE + (offset)) |
| 75 | |
| 76 | #if defined(CONFIG_TEGRA20) |
| 77 | |
| 78 | #define MUX_REG(grp) _R(0x80 + ((tegra_soc_pingroups[grp].ctl_id / 16) * 4)) |
| 79 | #define MUX_SHIFT(grp) ((tegra_soc_pingroups[grp].ctl_id % 16) * 2) |
| 80 | |
| 81 | #define PULL_REG(grp) _R(0xa0 + ((tegra_soc_pingroups[grp].pull_id / 16) * 4)) |
| 82 | #define PULL_SHIFT(grp) ((tegra_soc_pingroups[grp].pull_id % 16) * 2) |
| 83 | |
| 84 | #define TRI_REG(grp) _R(0x14 + (((grp) / 32) * 4)) |
| 85 | #define TRI_SHIFT(grp) ((grp) % 32) |
| 86 | |
| 87 | #else |
| 88 | |
| 89 | #define REG(pin) _R(0x3000 + ((pin) * 4)) |
| 90 | |
| 91 | #define MUX_REG(pin) REG(pin) |
| 92 | #define MUX_SHIFT(pin) 0 |
| 93 | |
| 94 | #define PULL_REG(pin) REG(pin) |
| 95 | #define PULL_SHIFT(pin) 2 |
| 96 | |
| 97 | #define TRI_REG(pin) REG(pin) |
| 98 | #define TRI_SHIFT(pin) 4 |
| 99 | |
| 100 | #endif /* CONFIG_TEGRA20 */ |
| 101 | |
| 102 | #define DRV_REG(group) _R(0x868 + ((group) * 4)) |
| 103 | |
| 104 | #define IO_SHIFT 5 |
| 105 | #define OD_SHIFT 6 |
| 106 | #define LOCK_SHIFT 7 |
| 107 | #define IO_RESET_SHIFT 8 |
| 108 | #define RCV_SEL_SHIFT 9 |
| 109 | |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 110 | #ifdef TEGRA_PMX_SOC_HAS_IO_CLAMPING |
Stephen Warren | f53f108 | 2014-04-22 14:37:54 -0600 | [diff] [blame] | 111 | /* This register/field only exists on Tegra114 and later */ |
| 112 | #define APB_MISC_PP_PINMUX_GLOBAL_0 0x40 |
| 113 | #define CLAMP_INPUTS_WHEN_TRISTATED 1 |
| 114 | |
| 115 | void pinmux_set_tristate_input_clamping(void) |
| 116 | { |
| 117 | u32 *reg = _R(APB_MISC_PP_PINMUX_GLOBAL_0); |
Stephen Warren | db2937f | 2015-02-18 13:27:03 -0700 | [diff] [blame] | 118 | |
| 119 | setbits_le32(reg, CLAMP_INPUTS_WHEN_TRISTATED); |
| 120 | } |
| 121 | |
| 122 | void pinmux_clear_tristate_input_clamping(void) |
| 123 | { |
| 124 | u32 *reg = _R(APB_MISC_PP_PINMUX_GLOBAL_0); |
Stephen Warren | f53f108 | 2014-04-22 14:37:54 -0600 | [diff] [blame] | 125 | |
Stephen Warren | db2937f | 2015-02-18 13:27:03 -0700 | [diff] [blame] | 126 | clrbits_le32(reg, CLAMP_INPUTS_WHEN_TRISTATED); |
Stephen Warren | f53f108 | 2014-04-22 14:37:54 -0600 | [diff] [blame] | 127 | } |
| 128 | #endif |
| 129 | |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 130 | void pinmux_set_func(enum pmux_pingrp pin, enum pmux_func func) |
| 131 | { |
| 132 | u32 *reg = MUX_REG(pin); |
| 133 | int i, mux = -1; |
| 134 | u32 val; |
| 135 | |
Stephen Warren | 7d9fae5 | 2014-04-22 14:37:52 -0600 | [diff] [blame] | 136 | if (func == PMUX_FUNC_DEFAULT) |
| 137 | return; |
| 138 | |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 139 | /* Error check on pin and func */ |
| 140 | assert(pmux_pingrp_isvalid(pin)); |
| 141 | assert(pmux_func_isvalid(func)); |
| 142 | |
Stephen Warren | 70b080f | 2014-03-21 15:58:03 -0600 | [diff] [blame] | 143 | if (func >= PMUX_FUNC_RSVD1) { |
| 144 | mux = (func - PMUX_FUNC_RSVD1) & 3; |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 145 | } else { |
| 146 | /* Search for the appropriate function */ |
| 147 | for (i = 0; i < 4; i++) { |
| 148 | if (tegra_soc_pingroups[pin].funcs[i] == func) { |
| 149 | mux = i; |
| 150 | break; |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | assert(mux != -1); |
| 155 | |
| 156 | val = readl(reg); |
| 157 | val &= ~(3 << MUX_SHIFT(pin)); |
| 158 | val |= (mux << MUX_SHIFT(pin)); |
| 159 | writel(val, reg); |
| 160 | } |
| 161 | |
| 162 | void pinmux_set_pullupdown(enum pmux_pingrp pin, enum pmux_pull pupd) |
| 163 | { |
| 164 | u32 *reg = PULL_REG(pin); |
| 165 | u32 val; |
| 166 | |
| 167 | /* Error check on pin and pupd */ |
| 168 | assert(pmux_pingrp_isvalid(pin)); |
| 169 | assert(pmux_pin_pupd_isvalid(pupd)); |
| 170 | |
| 171 | val = readl(reg); |
| 172 | val &= ~(3 << PULL_SHIFT(pin)); |
| 173 | val |= (pupd << PULL_SHIFT(pin)); |
| 174 | writel(val, reg); |
| 175 | } |
| 176 | |
Stephen Warren | 51ed4ad | 2014-03-21 12:28:55 -0600 | [diff] [blame] | 177 | static void pinmux_set_tristate(enum pmux_pingrp pin, int tri) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 178 | { |
| 179 | u32 *reg = TRI_REG(pin); |
| 180 | u32 val; |
| 181 | |
| 182 | /* Error check on pin */ |
| 183 | assert(pmux_pingrp_isvalid(pin)); |
| 184 | assert(pmux_pin_tristate_isvalid(tri)); |
| 185 | |
| 186 | val = readl(reg); |
| 187 | if (tri == PMUX_TRI_TRISTATE) |
| 188 | val |= (1 << TRI_SHIFT(pin)); |
| 189 | else |
| 190 | val &= ~(1 << TRI_SHIFT(pin)); |
| 191 | writel(val, reg); |
| 192 | } |
| 193 | |
| 194 | void pinmux_tristate_enable(enum pmux_pingrp pin) |
| 195 | { |
| 196 | pinmux_set_tristate(pin, PMUX_TRI_TRISTATE); |
| 197 | } |
| 198 | |
| 199 | void pinmux_tristate_disable(enum pmux_pingrp pin) |
| 200 | { |
| 201 | pinmux_set_tristate(pin, PMUX_TRI_NORMAL); |
| 202 | } |
| 203 | |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 204 | #ifdef TEGRA_PMX_PINS_HAVE_E_INPUT |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 205 | void pinmux_set_io(enum pmux_pingrp pin, enum pmux_pin_io io) |
| 206 | { |
| 207 | u32 *reg = REG(pin); |
| 208 | u32 val; |
| 209 | |
| 210 | if (io == PMUX_PIN_NONE) |
| 211 | return; |
| 212 | |
| 213 | /* Error check on pin and io */ |
| 214 | assert(pmux_pingrp_isvalid(pin)); |
| 215 | assert(pmux_pin_io_isvalid(io)); |
| 216 | |
| 217 | val = readl(reg); |
| 218 | if (io == PMUX_PIN_INPUT) |
| 219 | val |= (io & 1) << IO_SHIFT; |
| 220 | else |
| 221 | val &= ~(1 << IO_SHIFT); |
| 222 | writel(val, reg); |
| 223 | } |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 224 | #endif |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 225 | |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 226 | #ifdef TEGRA_PMX_PINS_HAVE_LOCK |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 227 | static void pinmux_set_lock(enum pmux_pingrp pin, enum pmux_pin_lock lock) |
| 228 | { |
| 229 | u32 *reg = REG(pin); |
| 230 | u32 val; |
| 231 | |
| 232 | if (lock == PMUX_PIN_LOCK_DEFAULT) |
| 233 | return; |
| 234 | |
| 235 | /* Error check on pin and lock */ |
| 236 | assert(pmux_pingrp_isvalid(pin)); |
| 237 | assert(pmux_pin_lock_isvalid(lock)); |
| 238 | |
| 239 | val = readl(reg); |
| 240 | if (lock == PMUX_PIN_LOCK_ENABLE) { |
| 241 | val |= (1 << LOCK_SHIFT); |
| 242 | } else { |
| 243 | if (val & (1 << LOCK_SHIFT)) |
| 244 | printf("%s: Cannot clear LOCK bit!\n", __func__); |
| 245 | val &= ~(1 << LOCK_SHIFT); |
| 246 | } |
| 247 | writel(val, reg); |
| 248 | |
| 249 | return; |
| 250 | } |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 251 | #endif |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 252 | |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 253 | #ifdef TEGRA_PMX_PINS_HAVE_OD |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 254 | static void pinmux_set_od(enum pmux_pingrp pin, enum pmux_pin_od od) |
| 255 | { |
| 256 | u32 *reg = REG(pin); |
| 257 | u32 val; |
| 258 | |
| 259 | if (od == PMUX_PIN_OD_DEFAULT) |
| 260 | return; |
| 261 | |
| 262 | /* Error check on pin and od */ |
| 263 | assert(pmux_pingrp_isvalid(pin)); |
| 264 | assert(pmux_pin_od_isvalid(od)); |
| 265 | |
| 266 | val = readl(reg); |
| 267 | if (od == PMUX_PIN_OD_ENABLE) |
| 268 | val |= (1 << OD_SHIFT); |
| 269 | else |
| 270 | val &= ~(1 << OD_SHIFT); |
| 271 | writel(val, reg); |
| 272 | |
| 273 | return; |
| 274 | } |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 275 | #endif |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 276 | |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 277 | #ifdef TEGRA_PMX_PINS_HAVE_IO_RESET |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 278 | static void pinmux_set_ioreset(enum pmux_pingrp pin, |
| 279 | enum pmux_pin_ioreset ioreset) |
| 280 | { |
| 281 | u32 *reg = REG(pin); |
| 282 | u32 val; |
| 283 | |
| 284 | if (ioreset == PMUX_PIN_IO_RESET_DEFAULT) |
| 285 | return; |
| 286 | |
| 287 | /* Error check on pin and ioreset */ |
| 288 | assert(pmux_pingrp_isvalid(pin)); |
| 289 | assert(pmux_pin_ioreset_isvalid(ioreset)); |
| 290 | |
| 291 | val = readl(reg); |
| 292 | if (ioreset == PMUX_PIN_IO_RESET_ENABLE) |
| 293 | val |= (1 << IO_RESET_SHIFT); |
| 294 | else |
| 295 | val &= ~(1 << IO_RESET_SHIFT); |
| 296 | writel(val, reg); |
| 297 | |
| 298 | return; |
| 299 | } |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 300 | #endif |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 301 | |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 302 | #ifdef TEGRA_PMX_PINS_HAVE_RCV_SEL |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 303 | static void pinmux_set_rcv_sel(enum pmux_pingrp pin, |
| 304 | enum pmux_pin_rcv_sel rcv_sel) |
| 305 | { |
| 306 | u32 *reg = REG(pin); |
| 307 | u32 val; |
| 308 | |
| 309 | if (rcv_sel == PMUX_PIN_RCV_SEL_DEFAULT) |
| 310 | return; |
| 311 | |
| 312 | /* Error check on pin and rcv_sel */ |
| 313 | assert(pmux_pingrp_isvalid(pin)); |
| 314 | assert(pmux_pin_rcv_sel_isvalid(rcv_sel)); |
| 315 | |
| 316 | val = readl(reg); |
| 317 | if (rcv_sel == PMUX_PIN_RCV_SEL_HIGH) |
| 318 | val |= (1 << RCV_SEL_SHIFT); |
| 319 | else |
| 320 | val &= ~(1 << RCV_SEL_SHIFT); |
| 321 | writel(val, reg); |
| 322 | |
| 323 | return; |
| 324 | } |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 325 | #endif |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 326 | |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 327 | static void pinmux_config_pingrp(const struct pmux_pingrp_config *config) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 328 | { |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 329 | enum pmux_pingrp pin = config->pingrp; |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 330 | |
| 331 | pinmux_set_func(pin, config->func); |
| 332 | pinmux_set_pullupdown(pin, config->pull); |
| 333 | pinmux_set_tristate(pin, config->tristate); |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 334 | #ifdef TEGRA_PMX_PINS_HAVE_E_INPUT |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 335 | pinmux_set_io(pin, config->io); |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 336 | #endif |
| 337 | #ifdef TEGRA_PMX_PINS_HAVE_LOCK |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 338 | pinmux_set_lock(pin, config->lock); |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 339 | #endif |
| 340 | #ifdef TEGRA_PMX_PINS_HAVE_OD |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 341 | pinmux_set_od(pin, config->od); |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 342 | #endif |
| 343 | #ifdef TEGRA_PMX_PINS_HAVE_IO_RESET |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 344 | pinmux_set_ioreset(pin, config->ioreset); |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 345 | #endif |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 346 | #ifdef TEGRA_PMX_PINS_HAVE_RCV_SEL |
| 347 | pinmux_set_rcv_sel(pin, config->rcv_sel); |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 348 | #endif |
| 349 | } |
| 350 | |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 351 | void pinmux_config_pingrp_table(const struct pmux_pingrp_config *config, |
| 352 | int len) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 353 | { |
| 354 | int i; |
| 355 | |
| 356 | for (i = 0; i < len; i++) |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 357 | pinmux_config_pingrp(&config[i]); |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 358 | } |
| 359 | |
Stephen Warren | 22d57fe | 2015-02-24 14:08:24 -0700 | [diff] [blame] | 360 | #ifdef TEGRA_PMX_SOC_HAS_DRVGRPS |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 361 | |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 362 | #define pmux_drvgrp_isvalid(pd) (((pd) >= 0) && ((pd) < PMUX_DRVGRP_COUNT)) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 363 | |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 364 | #define pmux_slw_isvalid(slw) \ |
| 365 | (((slw) >= PMUX_SLWF_MIN) && ((slw) <= PMUX_SLWF_MAX)) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 366 | |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 367 | #define pmux_drv_isvalid(drv) \ |
| 368 | (((drv) >= PMUX_DRVUP_MIN) && ((drv) <= PMUX_DRVUP_MAX)) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 369 | |
Stephen Warren | 3e9fb7b | 2015-02-24 14:08:25 -0700 | [diff] [blame] | 370 | #ifdef TEGRA_PMX_GRPS_HAVE_HSM |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 371 | #define HSM_SHIFT 2 |
Stephen Warren | 3e9fb7b | 2015-02-24 14:08:25 -0700 | [diff] [blame] | 372 | #endif |
| 373 | #ifdef TEGRA_PMX_GRPS_HAVE_SCHMT |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 374 | #define SCHMT_SHIFT 3 |
Stephen Warren | 3e9fb7b | 2015-02-24 14:08:25 -0700 | [diff] [blame] | 375 | #endif |
| 376 | #ifdef TEGRA_PMX_GRPS_HAVE_LPMD |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 377 | #define LPMD_SHIFT 4 |
| 378 | #define LPMD_MASK (3 << LPMD_SHIFT) |
Stephen Warren | 3e9fb7b | 2015-02-24 14:08:25 -0700 | [diff] [blame] | 379 | #endif |
Stephen Warren | 21788e0 | 2015-02-24 14:08:23 -0700 | [diff] [blame] | 380 | /* |
| 381 | * Note that the following DRV* and SLW* defines are accurate for many drive |
| 382 | * groups on many SoCs. We really need a per-group data structure to solve |
| 383 | * this, since the fields are in different positions/sizes in different |
| 384 | * registers (for different groups). |
| 385 | * |
| 386 | * On Tegra30/114/124, the DRV*_SHIFT values vary. |
| 387 | * On Tegra30, the SLW*_SHIFT values vary. |
| 388 | * On Tegra30/114/124/210, the DRV*_MASK values vary, although the values |
| 389 | * below are wide enough to cover the widest fields, and hopefully don't |
| 390 | * interfere with any other fields. |
| 391 | * On Tegra30, the SLW*_MASK values vary, but we can't use a value that's |
| 392 | * wide enough to cover all cases, since that would cause the field to |
| 393 | * overlap with other fields in the narrower cases. |
| 394 | */ |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 395 | #define DRVDN_SHIFT 12 |
| 396 | #define DRVDN_MASK (0x7F << DRVDN_SHIFT) |
| 397 | #define DRVUP_SHIFT 20 |
| 398 | #define DRVUP_MASK (0x7F << DRVUP_SHIFT) |
| 399 | #define SLWR_SHIFT 28 |
| 400 | #define SLWR_MASK (3 << SLWR_SHIFT) |
| 401 | #define SLWF_SHIFT 30 |
| 402 | #define SLWF_MASK (3 << SLWF_SHIFT) |
| 403 | |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 404 | static void pinmux_set_drvup_slwf(enum pmux_drvgrp grp, int slwf) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 405 | { |
| 406 | u32 *reg = DRV_REG(grp); |
| 407 | u32 val; |
| 408 | |
| 409 | /* NONE means unspecified/do not change/use POR value */ |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 410 | if (slwf == PMUX_SLWF_NONE) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 411 | return; |
| 412 | |
| 413 | /* Error check on pad and slwf */ |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 414 | assert(pmux_drvgrp_isvalid(grp)); |
| 415 | assert(pmux_slw_isvalid(slwf)); |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 416 | |
| 417 | val = readl(reg); |
| 418 | val &= ~SLWF_MASK; |
| 419 | val |= (slwf << SLWF_SHIFT); |
| 420 | writel(val, reg); |
| 421 | |
| 422 | return; |
| 423 | } |
| 424 | |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 425 | static void pinmux_set_drvdn_slwr(enum pmux_drvgrp grp, int slwr) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 426 | { |
| 427 | u32 *reg = DRV_REG(grp); |
| 428 | u32 val; |
| 429 | |
| 430 | /* NONE means unspecified/do not change/use POR value */ |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 431 | if (slwr == PMUX_SLWR_NONE) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 432 | return; |
| 433 | |
| 434 | /* Error check on pad and slwr */ |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 435 | assert(pmux_drvgrp_isvalid(grp)); |
| 436 | assert(pmux_slw_isvalid(slwr)); |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 437 | |
| 438 | val = readl(reg); |
| 439 | val &= ~SLWR_MASK; |
| 440 | val |= (slwr << SLWR_SHIFT); |
| 441 | writel(val, reg); |
| 442 | |
| 443 | return; |
| 444 | } |
| 445 | |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 446 | static void pinmux_set_drvup(enum pmux_drvgrp grp, int drvup) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 447 | { |
| 448 | u32 *reg = DRV_REG(grp); |
| 449 | u32 val; |
| 450 | |
| 451 | /* NONE means unspecified/do not change/use POR value */ |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 452 | if (drvup == PMUX_DRVUP_NONE) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 453 | return; |
| 454 | |
| 455 | /* Error check on pad and drvup */ |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 456 | assert(pmux_drvgrp_isvalid(grp)); |
| 457 | assert(pmux_drv_isvalid(drvup)); |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 458 | |
| 459 | val = readl(reg); |
| 460 | val &= ~DRVUP_MASK; |
| 461 | val |= (drvup << DRVUP_SHIFT); |
| 462 | writel(val, reg); |
| 463 | |
| 464 | return; |
| 465 | } |
| 466 | |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 467 | static void pinmux_set_drvdn(enum pmux_drvgrp grp, int drvdn) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 468 | { |
| 469 | u32 *reg = DRV_REG(grp); |
| 470 | u32 val; |
| 471 | |
| 472 | /* NONE means unspecified/do not change/use POR value */ |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 473 | if (drvdn == PMUX_DRVDN_NONE) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 474 | return; |
| 475 | |
| 476 | /* Error check on pad and drvdn */ |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 477 | assert(pmux_drvgrp_isvalid(grp)); |
| 478 | assert(pmux_drv_isvalid(drvdn)); |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 479 | |
| 480 | val = readl(reg); |
| 481 | val &= ~DRVDN_MASK; |
| 482 | val |= (drvdn << DRVDN_SHIFT); |
| 483 | writel(val, reg); |
| 484 | |
| 485 | return; |
| 486 | } |
| 487 | |
Stephen Warren | 3e9fb7b | 2015-02-24 14:08:25 -0700 | [diff] [blame] | 488 | #ifdef TEGRA_PMX_GRPS_HAVE_LPMD |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 489 | static void pinmux_set_lpmd(enum pmux_drvgrp grp, enum pmux_lpmd lpmd) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 490 | { |
| 491 | u32 *reg = DRV_REG(grp); |
| 492 | u32 val; |
| 493 | |
| 494 | /* NONE means unspecified/do not change/use POR value */ |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 495 | if (lpmd == PMUX_LPMD_NONE) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 496 | return; |
| 497 | |
| 498 | /* Error check pad and lpmd value */ |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 499 | assert(pmux_drvgrp_isvalid(grp)); |
| 500 | assert(pmux_lpmd_isvalid(lpmd)); |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 501 | |
| 502 | val = readl(reg); |
| 503 | val &= ~LPMD_MASK; |
| 504 | val |= (lpmd << LPMD_SHIFT); |
| 505 | writel(val, reg); |
| 506 | |
| 507 | return; |
| 508 | } |
Stephen Warren | 3e9fb7b | 2015-02-24 14:08:25 -0700 | [diff] [blame] | 509 | #endif |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 510 | |
Stephen Warren | 3e9fb7b | 2015-02-24 14:08:25 -0700 | [diff] [blame] | 511 | #ifdef TEGRA_PMX_GRPS_HAVE_SCHMT |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 512 | static void pinmux_set_schmt(enum pmux_drvgrp grp, enum pmux_schmt schmt) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 513 | { |
| 514 | u32 *reg = DRV_REG(grp); |
| 515 | u32 val; |
| 516 | |
| 517 | /* NONE means unspecified/do not change/use POR value */ |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 518 | if (schmt == PMUX_SCHMT_NONE) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 519 | return; |
| 520 | |
| 521 | /* Error check pad */ |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 522 | assert(pmux_drvgrp_isvalid(grp)); |
| 523 | assert(pmux_schmt_isvalid(schmt)); |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 524 | |
| 525 | val = readl(reg); |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 526 | if (schmt == PMUX_SCHMT_ENABLE) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 527 | val |= (1 << SCHMT_SHIFT); |
| 528 | else |
| 529 | val &= ~(1 << SCHMT_SHIFT); |
| 530 | writel(val, reg); |
| 531 | |
| 532 | return; |
| 533 | } |
Stephen Warren | 3e9fb7b | 2015-02-24 14:08:25 -0700 | [diff] [blame] | 534 | #endif |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 535 | |
Stephen Warren | 3e9fb7b | 2015-02-24 14:08:25 -0700 | [diff] [blame] | 536 | #ifdef TEGRA_PMX_GRPS_HAVE_HSM |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 537 | static void pinmux_set_hsm(enum pmux_drvgrp grp, enum pmux_hsm hsm) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 538 | { |
| 539 | u32 *reg = DRV_REG(grp); |
| 540 | u32 val; |
| 541 | |
| 542 | /* NONE means unspecified/do not change/use POR value */ |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 543 | if (hsm == PMUX_HSM_NONE) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 544 | return; |
| 545 | |
| 546 | /* Error check pad */ |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 547 | assert(pmux_drvgrp_isvalid(grp)); |
| 548 | assert(pmux_hsm_isvalid(hsm)); |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 549 | |
| 550 | val = readl(reg); |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 551 | if (hsm == PMUX_HSM_ENABLE) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 552 | val |= (1 << HSM_SHIFT); |
| 553 | else |
| 554 | val &= ~(1 << HSM_SHIFT); |
| 555 | writel(val, reg); |
| 556 | |
| 557 | return; |
| 558 | } |
Stephen Warren | 3e9fb7b | 2015-02-24 14:08:25 -0700 | [diff] [blame] | 559 | #endif |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 560 | |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 561 | static void pinmux_config_drvgrp(const struct pmux_drvgrp_config *config) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 562 | { |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 563 | enum pmux_drvgrp grp = config->drvgrp; |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 564 | |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 565 | pinmux_set_drvup_slwf(grp, config->slwf); |
| 566 | pinmux_set_drvdn_slwr(grp, config->slwr); |
| 567 | pinmux_set_drvup(grp, config->drvup); |
| 568 | pinmux_set_drvdn(grp, config->drvdn); |
Stephen Warren | 3e9fb7b | 2015-02-24 14:08:25 -0700 | [diff] [blame] | 569 | #ifdef TEGRA_PMX_GRPS_HAVE_LPMD |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 570 | pinmux_set_lpmd(grp, config->lpmd); |
Stephen Warren | 3e9fb7b | 2015-02-24 14:08:25 -0700 | [diff] [blame] | 571 | #endif |
| 572 | #ifdef TEGRA_PMX_GRPS_HAVE_SCHMT |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 573 | pinmux_set_schmt(grp, config->schmt); |
Stephen Warren | 3e9fb7b | 2015-02-24 14:08:25 -0700 | [diff] [blame] | 574 | #endif |
| 575 | #ifdef TEGRA_PMX_GRPS_HAVE_HSM |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 576 | pinmux_set_hsm(grp, config->hsm); |
Stephen Warren | 3e9fb7b | 2015-02-24 14:08:25 -0700 | [diff] [blame] | 577 | #endif |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 578 | } |
| 579 | |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 580 | void pinmux_config_drvgrp_table(const struct pmux_drvgrp_config *config, |
| 581 | int len) |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 582 | { |
| 583 | int i; |
| 584 | |
| 585 | for (i = 0; i < len; i++) |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 586 | pinmux_config_drvgrp(&config[i]); |
Stephen Warren | 9026dfd | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 587 | } |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 588 | #endif /* TEGRA_PMX_HAS_DRVGRPS */ |