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