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) \ |
| 17 | ((((func) >= 0) && ((func) < PMUX_FUNC_COUNT)) || \ |
| 18 | (((func) >= PMUX_FUNC_RSVD1) && ((func) <= PMUX_FUNC_RSVD4))) |
| 19 | |
| 20 | /* return 1 if a pin_pupd_is in range */ |
| 21 | #define pmux_pin_pupd_isvalid(pupd) \ |
| 22 | (((pupd) >= PMUX_PULL_NORMAL) && ((pupd) <= PMUX_PULL_UP)) |
| 23 | |
| 24 | /* return 1 if a pin_tristate_is in range */ |
| 25 | #define pmux_pin_tristate_isvalid(tristate) \ |
| 26 | (((tristate) >= PMUX_TRI_NORMAL) && ((tristate) <= PMUX_TRI_TRISTATE)) |
| 27 | |
| 28 | #ifdef TEGRA_PMX_HAS_PIN_IO_BIT_ETC |
| 29 | /* return 1 if a pin_io_is in range */ |
| 30 | #define pmux_pin_io_isvalid(io) \ |
| 31 | (((io) >= PMUX_PIN_OUTPUT) && ((io) <= PMUX_PIN_INPUT)) |
| 32 | |
| 33 | /* return 1 if a pin_lock is in range */ |
| 34 | #define pmux_pin_lock_isvalid(lock) \ |
| 35 | (((lock) >= PMUX_PIN_LOCK_DISABLE) && ((lock) <= PMUX_PIN_LOCK_ENABLE)) |
| 36 | |
| 37 | /* return 1 if a pin_od is in range */ |
| 38 | #define pmux_pin_od_isvalid(od) \ |
| 39 | (((od) >= PMUX_PIN_OD_DISABLE) && ((od) <= PMUX_PIN_OD_ENABLE)) |
| 40 | |
| 41 | /* return 1 if a pin_ioreset_is in range */ |
| 42 | #define pmux_pin_ioreset_isvalid(ioreset) \ |
| 43 | (((ioreset) >= PMUX_PIN_IO_RESET_DISABLE) && \ |
| 44 | ((ioreset) <= PMUX_PIN_IO_RESET_ENABLE)) |
| 45 | |
| 46 | #ifdef TEGRA_PMX_HAS_RCV_SEL |
| 47 | /* return 1 if a pin_rcv_sel_is in range */ |
| 48 | #define pmux_pin_rcv_sel_isvalid(rcv_sel) \ |
| 49 | (((rcv_sel) >= PMUX_PIN_RCV_SEL_NORMAL) && \ |
| 50 | ((rcv_sel) <= PMUX_PIN_RCV_SEL_HIGH)) |
| 51 | #endif /* TEGRA_PMX_HAS_RCV_SEL */ |
| 52 | #endif /* TEGRA_PMX_HAS_PIN_IO_BIT_ETC */ |
| 53 | |
| 54 | #define _R(offset) (u32 *)(NV_PA_APB_MISC_BASE + (offset)) |
| 55 | |
| 56 | #if defined(CONFIG_TEGRA20) |
| 57 | |
| 58 | #define MUX_REG(grp) _R(0x80 + ((tegra_soc_pingroups[grp].ctl_id / 16) * 4)) |
| 59 | #define MUX_SHIFT(grp) ((tegra_soc_pingroups[grp].ctl_id % 16) * 2) |
| 60 | |
| 61 | #define PULL_REG(grp) _R(0xa0 + ((tegra_soc_pingroups[grp].pull_id / 16) * 4)) |
| 62 | #define PULL_SHIFT(grp) ((tegra_soc_pingroups[grp].pull_id % 16) * 2) |
| 63 | |
| 64 | #define TRI_REG(grp) _R(0x14 + (((grp) / 32) * 4)) |
| 65 | #define TRI_SHIFT(grp) ((grp) % 32) |
| 66 | |
| 67 | #else |
| 68 | |
| 69 | #define REG(pin) _R(0x3000 + ((pin) * 4)) |
| 70 | |
| 71 | #define MUX_REG(pin) REG(pin) |
| 72 | #define MUX_SHIFT(pin) 0 |
| 73 | |
| 74 | #define PULL_REG(pin) REG(pin) |
| 75 | #define PULL_SHIFT(pin) 2 |
| 76 | |
| 77 | #define TRI_REG(pin) REG(pin) |
| 78 | #define TRI_SHIFT(pin) 4 |
| 79 | |
| 80 | #endif /* CONFIG_TEGRA20 */ |
| 81 | |
| 82 | #define DRV_REG(group) _R(0x868 + ((group) * 4)) |
| 83 | |
| 84 | #define IO_SHIFT 5 |
| 85 | #define OD_SHIFT 6 |
| 86 | #define LOCK_SHIFT 7 |
| 87 | #define IO_RESET_SHIFT 8 |
| 88 | #define RCV_SEL_SHIFT 9 |
| 89 | |
| 90 | void pinmux_set_func(enum pmux_pingrp pin, enum pmux_func func) |
| 91 | { |
| 92 | u32 *reg = MUX_REG(pin); |
| 93 | int i, mux = -1; |
| 94 | u32 val; |
| 95 | |
| 96 | /* Error check on pin and func */ |
| 97 | assert(pmux_pingrp_isvalid(pin)); |
| 98 | assert(pmux_func_isvalid(func)); |
| 99 | |
| 100 | if (func & PMUX_FUNC_RSVD1) { |
| 101 | mux = func & 3; |
| 102 | } else { |
| 103 | /* Search for the appropriate function */ |
| 104 | for (i = 0; i < 4; i++) { |
| 105 | if (tegra_soc_pingroups[pin].funcs[i] == func) { |
| 106 | mux = i; |
| 107 | break; |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | assert(mux != -1); |
| 112 | |
| 113 | val = readl(reg); |
| 114 | val &= ~(3 << MUX_SHIFT(pin)); |
| 115 | val |= (mux << MUX_SHIFT(pin)); |
| 116 | writel(val, reg); |
| 117 | } |
| 118 | |
| 119 | void pinmux_set_pullupdown(enum pmux_pingrp pin, enum pmux_pull pupd) |
| 120 | { |
| 121 | u32 *reg = PULL_REG(pin); |
| 122 | u32 val; |
| 123 | |
| 124 | /* Error check on pin and pupd */ |
| 125 | assert(pmux_pingrp_isvalid(pin)); |
| 126 | assert(pmux_pin_pupd_isvalid(pupd)); |
| 127 | |
| 128 | val = readl(reg); |
| 129 | val &= ~(3 << PULL_SHIFT(pin)); |
| 130 | val |= (pupd << PULL_SHIFT(pin)); |
| 131 | writel(val, reg); |
| 132 | } |
| 133 | |
Stephen Warren | a45fa43 | 2014-03-21 12:28:55 -0600 | [diff] [blame] | 134 | static void pinmux_set_tristate(enum pmux_pingrp pin, int tri) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 135 | { |
| 136 | u32 *reg = TRI_REG(pin); |
| 137 | u32 val; |
| 138 | |
| 139 | /* Error check on pin */ |
| 140 | assert(pmux_pingrp_isvalid(pin)); |
| 141 | assert(pmux_pin_tristate_isvalid(tri)); |
| 142 | |
| 143 | val = readl(reg); |
| 144 | if (tri == PMUX_TRI_TRISTATE) |
| 145 | val |= (1 << TRI_SHIFT(pin)); |
| 146 | else |
| 147 | val &= ~(1 << TRI_SHIFT(pin)); |
| 148 | writel(val, reg); |
| 149 | } |
| 150 | |
| 151 | void pinmux_tristate_enable(enum pmux_pingrp pin) |
| 152 | { |
| 153 | pinmux_set_tristate(pin, PMUX_TRI_TRISTATE); |
| 154 | } |
| 155 | |
| 156 | void pinmux_tristate_disable(enum pmux_pingrp pin) |
| 157 | { |
| 158 | pinmux_set_tristate(pin, PMUX_TRI_NORMAL); |
| 159 | } |
| 160 | |
| 161 | #ifdef TEGRA_PMX_HAS_PIN_IO_BIT_ETC |
| 162 | void pinmux_set_io(enum pmux_pingrp pin, enum pmux_pin_io io) |
| 163 | { |
| 164 | u32 *reg = REG(pin); |
| 165 | u32 val; |
| 166 | |
| 167 | if (io == PMUX_PIN_NONE) |
| 168 | return; |
| 169 | |
| 170 | /* Error check on pin and io */ |
| 171 | assert(pmux_pingrp_isvalid(pin)); |
| 172 | assert(pmux_pin_io_isvalid(io)); |
| 173 | |
| 174 | val = readl(reg); |
| 175 | if (io == PMUX_PIN_INPUT) |
| 176 | val |= (io & 1) << IO_SHIFT; |
| 177 | else |
| 178 | val &= ~(1 << IO_SHIFT); |
| 179 | writel(val, reg); |
| 180 | } |
| 181 | |
| 182 | static void pinmux_set_lock(enum pmux_pingrp pin, enum pmux_pin_lock lock) |
| 183 | { |
| 184 | u32 *reg = REG(pin); |
| 185 | u32 val; |
| 186 | |
| 187 | if (lock == PMUX_PIN_LOCK_DEFAULT) |
| 188 | return; |
| 189 | |
| 190 | /* Error check on pin and lock */ |
| 191 | assert(pmux_pingrp_isvalid(pin)); |
| 192 | assert(pmux_pin_lock_isvalid(lock)); |
| 193 | |
| 194 | val = readl(reg); |
| 195 | if (lock == PMUX_PIN_LOCK_ENABLE) { |
| 196 | val |= (1 << LOCK_SHIFT); |
| 197 | } else { |
| 198 | if (val & (1 << LOCK_SHIFT)) |
| 199 | printf("%s: Cannot clear LOCK bit!\n", __func__); |
| 200 | val &= ~(1 << LOCK_SHIFT); |
| 201 | } |
| 202 | writel(val, reg); |
| 203 | |
| 204 | return; |
| 205 | } |
| 206 | |
| 207 | static void pinmux_set_od(enum pmux_pingrp pin, enum pmux_pin_od od) |
| 208 | { |
| 209 | u32 *reg = REG(pin); |
| 210 | u32 val; |
| 211 | |
| 212 | if (od == PMUX_PIN_OD_DEFAULT) |
| 213 | return; |
| 214 | |
| 215 | /* Error check on pin and od */ |
| 216 | assert(pmux_pingrp_isvalid(pin)); |
| 217 | assert(pmux_pin_od_isvalid(od)); |
| 218 | |
| 219 | val = readl(reg); |
| 220 | if (od == PMUX_PIN_OD_ENABLE) |
| 221 | val |= (1 << OD_SHIFT); |
| 222 | else |
| 223 | val &= ~(1 << OD_SHIFT); |
| 224 | writel(val, reg); |
| 225 | |
| 226 | return; |
| 227 | } |
| 228 | |
| 229 | static void pinmux_set_ioreset(enum pmux_pingrp pin, |
| 230 | enum pmux_pin_ioreset ioreset) |
| 231 | { |
| 232 | u32 *reg = REG(pin); |
| 233 | u32 val; |
| 234 | |
| 235 | if (ioreset == PMUX_PIN_IO_RESET_DEFAULT) |
| 236 | return; |
| 237 | |
| 238 | /* Error check on pin and ioreset */ |
| 239 | assert(pmux_pingrp_isvalid(pin)); |
| 240 | assert(pmux_pin_ioreset_isvalid(ioreset)); |
| 241 | |
| 242 | val = readl(reg); |
| 243 | if (ioreset == PMUX_PIN_IO_RESET_ENABLE) |
| 244 | val |= (1 << IO_RESET_SHIFT); |
| 245 | else |
| 246 | val &= ~(1 << IO_RESET_SHIFT); |
| 247 | writel(val, reg); |
| 248 | |
| 249 | return; |
| 250 | } |
| 251 | |
| 252 | #ifdef TEGRA_PMX_HAS_RCV_SEL |
| 253 | static void pinmux_set_rcv_sel(enum pmux_pingrp pin, |
| 254 | enum pmux_pin_rcv_sel rcv_sel) |
| 255 | { |
| 256 | u32 *reg = REG(pin); |
| 257 | u32 val; |
| 258 | |
| 259 | if (rcv_sel == PMUX_PIN_RCV_SEL_DEFAULT) |
| 260 | return; |
| 261 | |
| 262 | /* Error check on pin and rcv_sel */ |
| 263 | assert(pmux_pingrp_isvalid(pin)); |
| 264 | assert(pmux_pin_rcv_sel_isvalid(rcv_sel)); |
| 265 | |
| 266 | val = readl(reg); |
| 267 | if (rcv_sel == PMUX_PIN_RCV_SEL_HIGH) |
| 268 | val |= (1 << RCV_SEL_SHIFT); |
| 269 | else |
| 270 | val &= ~(1 << RCV_SEL_SHIFT); |
| 271 | writel(val, reg); |
| 272 | |
| 273 | return; |
| 274 | } |
| 275 | #endif /* TEGRA_PMX_HAS_RCV_SEL */ |
| 276 | #endif /* TEGRA_PMX_HAS_PIN_IO_BIT_ETC */ |
| 277 | |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 278 | static void pinmux_config_pingrp(const struct pmux_pingrp_config *config) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 279 | { |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 280 | enum pmux_pingrp pin = config->pingrp; |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 281 | |
| 282 | pinmux_set_func(pin, config->func); |
| 283 | pinmux_set_pullupdown(pin, config->pull); |
| 284 | pinmux_set_tristate(pin, config->tristate); |
| 285 | #ifdef TEGRA_PMX_HAS_PIN_IO_BIT_ETC |
| 286 | pinmux_set_io(pin, config->io); |
| 287 | pinmux_set_lock(pin, config->lock); |
| 288 | pinmux_set_od(pin, config->od); |
| 289 | pinmux_set_ioreset(pin, config->ioreset); |
| 290 | #ifdef TEGRA_PMX_HAS_RCV_SEL |
| 291 | pinmux_set_rcv_sel(pin, config->rcv_sel); |
| 292 | #endif |
| 293 | #endif |
| 294 | } |
| 295 | |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 296 | void pinmux_config_pingrp_table(const struct pmux_pingrp_config *config, |
| 297 | int len) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 298 | { |
| 299 | int i; |
| 300 | |
| 301 | for (i = 0; i < len; i++) |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 302 | pinmux_config_pingrp(&config[i]); |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 303 | } |
| 304 | |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 305 | #ifdef TEGRA_PMX_HAS_DRVGRPS |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 306 | |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 307 | #define pmux_drvgrp_isvalid(pd) (((pd) >= 0) && ((pd) < PMUX_DRVGRP_COUNT)) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 308 | |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 309 | #define pmux_slw_isvalid(slw) \ |
| 310 | (((slw) >= PMUX_SLWF_MIN) && ((slw) <= PMUX_SLWF_MAX)) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 311 | |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 312 | #define pmux_drv_isvalid(drv) \ |
| 313 | (((drv) >= PMUX_DRVUP_MIN) && ((drv) <= PMUX_DRVUP_MAX)) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 314 | |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 315 | #define pmux_lpmd_isvalid(lpm) \ |
| 316 | (((lpm) >= PMUX_LPMD_X8) && ((lpm) <= PMUX_LPMD_X)) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 317 | |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 318 | #define pmux_schmt_isvalid(schmt) \ |
| 319 | (((schmt) >= PMUX_SCHMT_DISABLE) && ((schmt) <= PMUX_SCHMT_ENABLE)) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 320 | |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 321 | #define pmux_hsm_isvalid(hsm) \ |
| 322 | (((hsm) >= PMUX_HSM_DISABLE) && ((hsm) <= PMUX_HSM_ENABLE)) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 323 | |
| 324 | #define HSM_SHIFT 2 |
| 325 | #define SCHMT_SHIFT 3 |
| 326 | #define LPMD_SHIFT 4 |
| 327 | #define LPMD_MASK (3 << LPMD_SHIFT) |
| 328 | #define DRVDN_SHIFT 12 |
| 329 | #define DRVDN_MASK (0x7F << DRVDN_SHIFT) |
| 330 | #define DRVUP_SHIFT 20 |
| 331 | #define DRVUP_MASK (0x7F << DRVUP_SHIFT) |
| 332 | #define SLWR_SHIFT 28 |
| 333 | #define SLWR_MASK (3 << SLWR_SHIFT) |
| 334 | #define SLWF_SHIFT 30 |
| 335 | #define SLWF_MASK (3 << SLWF_SHIFT) |
| 336 | |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 337 | static void pinmux_set_drvup_slwf(enum pmux_drvgrp grp, int slwf) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 338 | { |
| 339 | u32 *reg = DRV_REG(grp); |
| 340 | u32 val; |
| 341 | |
| 342 | /* NONE means unspecified/do not change/use POR value */ |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 343 | if (slwf == PMUX_SLWF_NONE) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 344 | return; |
| 345 | |
| 346 | /* Error check on pad and slwf */ |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 347 | assert(pmux_drvgrp_isvalid(grp)); |
| 348 | assert(pmux_slw_isvalid(slwf)); |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 349 | |
| 350 | val = readl(reg); |
| 351 | val &= ~SLWF_MASK; |
| 352 | val |= (slwf << SLWF_SHIFT); |
| 353 | writel(val, reg); |
| 354 | |
| 355 | return; |
| 356 | } |
| 357 | |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 358 | static void pinmux_set_drvdn_slwr(enum pmux_drvgrp grp, int slwr) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 359 | { |
| 360 | u32 *reg = DRV_REG(grp); |
| 361 | u32 val; |
| 362 | |
| 363 | /* NONE means unspecified/do not change/use POR value */ |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 364 | if (slwr == PMUX_SLWR_NONE) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 365 | return; |
| 366 | |
| 367 | /* Error check on pad and slwr */ |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 368 | assert(pmux_drvgrp_isvalid(grp)); |
| 369 | assert(pmux_slw_isvalid(slwr)); |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 370 | |
| 371 | val = readl(reg); |
| 372 | val &= ~SLWR_MASK; |
| 373 | val |= (slwr << SLWR_SHIFT); |
| 374 | writel(val, reg); |
| 375 | |
| 376 | return; |
| 377 | } |
| 378 | |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 379 | static void pinmux_set_drvup(enum pmux_drvgrp grp, int drvup) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 380 | { |
| 381 | u32 *reg = DRV_REG(grp); |
| 382 | u32 val; |
| 383 | |
| 384 | /* NONE means unspecified/do not change/use POR value */ |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 385 | if (drvup == PMUX_DRVUP_NONE) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 386 | return; |
| 387 | |
| 388 | /* Error check on pad and drvup */ |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 389 | assert(pmux_drvgrp_isvalid(grp)); |
| 390 | assert(pmux_drv_isvalid(drvup)); |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 391 | |
| 392 | val = readl(reg); |
| 393 | val &= ~DRVUP_MASK; |
| 394 | val |= (drvup << DRVUP_SHIFT); |
| 395 | writel(val, reg); |
| 396 | |
| 397 | return; |
| 398 | } |
| 399 | |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 400 | static void pinmux_set_drvdn(enum pmux_drvgrp grp, int drvdn) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 401 | { |
| 402 | u32 *reg = DRV_REG(grp); |
| 403 | u32 val; |
| 404 | |
| 405 | /* NONE means unspecified/do not change/use POR value */ |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 406 | if (drvdn == PMUX_DRVDN_NONE) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 407 | return; |
| 408 | |
| 409 | /* Error check on pad and drvdn */ |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 410 | assert(pmux_drvgrp_isvalid(grp)); |
| 411 | assert(pmux_drv_isvalid(drvdn)); |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 412 | |
| 413 | val = readl(reg); |
| 414 | val &= ~DRVDN_MASK; |
| 415 | val |= (drvdn << DRVDN_SHIFT); |
| 416 | writel(val, reg); |
| 417 | |
| 418 | return; |
| 419 | } |
| 420 | |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 421 | 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] | 422 | { |
| 423 | u32 *reg = DRV_REG(grp); |
| 424 | u32 val; |
| 425 | |
| 426 | /* NONE means unspecified/do not change/use POR value */ |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 427 | if (lpmd == PMUX_LPMD_NONE) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 428 | return; |
| 429 | |
| 430 | /* Error check pad and lpmd value */ |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 431 | assert(pmux_drvgrp_isvalid(grp)); |
| 432 | assert(pmux_lpmd_isvalid(lpmd)); |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 433 | |
| 434 | val = readl(reg); |
| 435 | val &= ~LPMD_MASK; |
| 436 | val |= (lpmd << LPMD_SHIFT); |
| 437 | writel(val, reg); |
| 438 | |
| 439 | return; |
| 440 | } |
| 441 | |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 442 | 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] | 443 | { |
| 444 | u32 *reg = DRV_REG(grp); |
| 445 | u32 val; |
| 446 | |
| 447 | /* NONE means unspecified/do not change/use POR value */ |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 448 | if (schmt == PMUX_SCHMT_NONE) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 449 | return; |
| 450 | |
| 451 | /* Error check pad */ |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 452 | assert(pmux_drvgrp_isvalid(grp)); |
| 453 | assert(pmux_schmt_isvalid(schmt)); |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 454 | |
| 455 | val = readl(reg); |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 456 | if (schmt == PMUX_SCHMT_ENABLE) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 457 | val |= (1 << SCHMT_SHIFT); |
| 458 | else |
| 459 | val &= ~(1 << SCHMT_SHIFT); |
| 460 | writel(val, reg); |
| 461 | |
| 462 | return; |
| 463 | } |
| 464 | |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 465 | 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] | 466 | { |
| 467 | u32 *reg = DRV_REG(grp); |
| 468 | u32 val; |
| 469 | |
| 470 | /* NONE means unspecified/do not change/use POR value */ |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 471 | if (hsm == PMUX_HSM_NONE) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 472 | return; |
| 473 | |
| 474 | /* Error check pad */ |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 475 | assert(pmux_drvgrp_isvalid(grp)); |
| 476 | assert(pmux_hsm_isvalid(hsm)); |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 477 | |
| 478 | val = readl(reg); |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 479 | if (hsm == PMUX_HSM_ENABLE) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 480 | val |= (1 << HSM_SHIFT); |
| 481 | else |
| 482 | val &= ~(1 << HSM_SHIFT); |
| 483 | writel(val, reg); |
| 484 | |
| 485 | return; |
| 486 | } |
| 487 | |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 488 | static void pinmux_config_drvgrp(const struct pmux_drvgrp_config *config) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 489 | { |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 490 | enum pmux_drvgrp grp = config->drvgrp; |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 491 | |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 492 | pinmux_set_drvup_slwf(grp, config->slwf); |
| 493 | pinmux_set_drvdn_slwr(grp, config->slwr); |
| 494 | pinmux_set_drvup(grp, config->drvup); |
| 495 | pinmux_set_drvdn(grp, config->drvdn); |
| 496 | pinmux_set_lpmd(grp, config->lpmd); |
| 497 | pinmux_set_schmt(grp, config->schmt); |
| 498 | pinmux_set_hsm(grp, config->hsm); |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 499 | } |
| 500 | |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 501 | void pinmux_config_drvgrp_table(const struct pmux_drvgrp_config *config, |
| 502 | int len) |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 503 | { |
| 504 | int i; |
| 505 | |
| 506 | for (i = 0; i < len; i++) |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 507 | pinmux_config_drvgrp(&config[i]); |
Stephen Warren | e296995 | 2014-03-21 12:28:54 -0600 | [diff] [blame] | 508 | } |
Stephen Warren | dfb42fc | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 509 | #endif /* TEGRA_PMX_HAS_DRVGRPS */ |