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