blob: 1730d20312b0778048e0e299466611d8d54fc267 [file] [log] [blame]
Stephen Warrene2969952014-03-21 12:28:54 -06001/*
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 Warrendfb42fc2014-03-21 12:28:56 -060013#define pmux_pingrp_isvalid(pin) (((pin) >= 0) && ((pin) < PMUX_PINGRP_COUNT))
Stephen Warrene2969952014-03-21 12:28:54 -060014
15/* return 1 if a pmux_func is in range */
16#define pmux_func_isvalid(func) \
Stephen Warrend3812942014-03-21 15:58:03 -060017 (((func) >= 0) && ((func) < PMUX_FUNC_COUNT))
Stephen Warrene2969952014-03-21 12:28:54 -060018
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 Warren7a284412015-02-24 14:08:24 -070027#ifdef TEGRA_PMX_PINS_HAVE_E_INPUT
Stephen Warrene2969952014-03-21 12:28:54 -060028/* 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 Warren7a284412015-02-24 14:08:24 -070031#endif
Stephen Warrene2969952014-03-21 12:28:54 -060032
Stephen Warren7a284412015-02-24 14:08:24 -070033#ifdef TEGRA_PMX_PINS_HAVE_LOCK
Stephen Warrene2969952014-03-21 12:28:54 -060034/* 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 Warren7a284412015-02-24 14:08:24 -070037#endif
Stephen Warrene2969952014-03-21 12:28:54 -060038
Stephen Warren7a284412015-02-24 14:08:24 -070039#ifdef TEGRA_PMX_PINS_HAVE_OD
Stephen Warrene2969952014-03-21 12:28:54 -060040/* 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 Warren7a284412015-02-24 14:08:24 -070043#endif
Stephen Warrene2969952014-03-21 12:28:54 -060044
Stephen Warren7a284412015-02-24 14:08:24 -070045#ifdef TEGRA_PMX_PINS_HAVE_IO_RESET
Stephen Warrene2969952014-03-21 12:28:54 -060046/* 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 Warren7a284412015-02-24 14:08:24 -070050#endif
Stephen Warrene2969952014-03-21 12:28:54 -060051
Stephen Warren7a284412015-02-24 14:08:24 -070052#ifdef TEGRA_PMX_PINS_HAVE_RCV_SEL
Stephen Warrene2969952014-03-21 12:28:54 -060053/* 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 Warren7a284412015-02-24 14:08:24 -070057#endif
Stephen Warrene2969952014-03-21 12:28:54 -060058
Stephen Warrenbc134722015-02-24 14:08:26 -070059#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 Warrene2969952014-03-21 12:28:54 -060074#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 Warrenb2cd3d82015-02-24 14:08:27 -0700104/*
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 Warrene2969952014-03-21 12:28:54 -0600115#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 Warrenb2cd3d82015-02-24 14:08:27 -0700120#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600121
Stephen Warren7a284412015-02-24 14:08:24 -0700122#ifdef TEGRA_PMX_SOC_HAS_IO_CLAMPING
Stephen Warrenbb144692014-04-22 14:37:54 -0600123/* 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
127void pinmux_set_tristate_input_clamping(void)
128{
129 u32 *reg = _R(APB_MISC_PP_PINMUX_GLOBAL_0);
Stephen Warrenbb144692014-04-22 14:37:54 -0600130
Stephen Warrenf799b032015-02-18 13:27:03 -0700131 setbits_le32(reg, CLAMP_INPUTS_WHEN_TRISTATED);
132}
133
134void 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 Warrenbb144692014-04-22 14:37:54 -0600139}
140#endif
141
Stephen Warrene2969952014-03-21 12:28:54 -0600142void 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 Warren4a68d342014-04-22 14:37:52 -0600148 if (func == PMUX_FUNC_DEFAULT)
149 return;
150
Stephen Warrene2969952014-03-21 12:28:54 -0600151 /* Error check on pin and func */
152 assert(pmux_pingrp_isvalid(pin));
153 assert(pmux_func_isvalid(func));
154
Stephen Warrend3812942014-03-21 15:58:03 -0600155 if (func >= PMUX_FUNC_RSVD1) {
156 mux = (func - PMUX_FUNC_RSVD1) & 3;
Stephen Warrene2969952014-03-21 12:28:54 -0600157 } 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
174void 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 Warrena45fa432014-03-21 12:28:55 -0600189static void pinmux_set_tristate(enum pmux_pingrp pin, int tri)
Stephen Warrene2969952014-03-21 12:28:54 -0600190{
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
206void pinmux_tristate_enable(enum pmux_pingrp pin)
207{
208 pinmux_set_tristate(pin, PMUX_TRI_TRISTATE);
209}
210
211void pinmux_tristate_disable(enum pmux_pingrp pin)
212{
213 pinmux_set_tristate(pin, PMUX_TRI_NORMAL);
214}
215
Stephen Warren7a284412015-02-24 14:08:24 -0700216#ifdef TEGRA_PMX_PINS_HAVE_E_INPUT
Stephen Warrene2969952014-03-21 12:28:54 -0600217void 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 Warren7a284412015-02-24 14:08:24 -0700236#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600237
Stephen Warren7a284412015-02-24 14:08:24 -0700238#ifdef TEGRA_PMX_PINS_HAVE_LOCK
Stephen Warrene2969952014-03-21 12:28:54 -0600239static 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 Warren7a284412015-02-24 14:08:24 -0700263#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600264
Stephen Warren7a284412015-02-24 14:08:24 -0700265#ifdef TEGRA_PMX_PINS_HAVE_OD
Stephen Warrene2969952014-03-21 12:28:54 -0600266static 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 Warren7a284412015-02-24 14:08:24 -0700287#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600288
Stephen Warren7a284412015-02-24 14:08:24 -0700289#ifdef TEGRA_PMX_PINS_HAVE_IO_RESET
Stephen Warrene2969952014-03-21 12:28:54 -0600290static 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 Warren7a284412015-02-24 14:08:24 -0700312#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600313
Stephen Warren7a284412015-02-24 14:08:24 -0700314#ifdef TEGRA_PMX_PINS_HAVE_RCV_SEL
Stephen Warrene2969952014-03-21 12:28:54 -0600315static 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 Warren7a284412015-02-24 14:08:24 -0700337#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600338
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600339static void pinmux_config_pingrp(const struct pmux_pingrp_config *config)
Stephen Warrene2969952014-03-21 12:28:54 -0600340{
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600341 enum pmux_pingrp pin = config->pingrp;
Stephen Warrene2969952014-03-21 12:28:54 -0600342
343 pinmux_set_func(pin, config->func);
344 pinmux_set_pullupdown(pin, config->pull);
345 pinmux_set_tristate(pin, config->tristate);
Stephen Warren7a284412015-02-24 14:08:24 -0700346#ifdef TEGRA_PMX_PINS_HAVE_E_INPUT
Stephen Warrene2969952014-03-21 12:28:54 -0600347 pinmux_set_io(pin, config->io);
Stephen Warrene2969952014-03-21 12:28:54 -0600348#endif
Stephen Warren7a284412015-02-24 14:08:24 -0700349#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 Warrene2969952014-03-21 12:28:54 -0600360#endif
361}
362
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600363void pinmux_config_pingrp_table(const struct pmux_pingrp_config *config,
364 int len)
Stephen Warrene2969952014-03-21 12:28:54 -0600365{
366 int i;
367
368 for (i = 0; i < len; i++)
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600369 pinmux_config_pingrp(&config[i]);
Stephen Warrene2969952014-03-21 12:28:54 -0600370}
371
Stephen Warren7a284412015-02-24 14:08:24 -0700372#ifdef TEGRA_PMX_SOC_HAS_DRVGRPS
Stephen Warrene2969952014-03-21 12:28:54 -0600373
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600374#define pmux_drvgrp_isvalid(pd) (((pd) >= 0) && ((pd) < PMUX_DRVGRP_COUNT))
Stephen Warrene2969952014-03-21 12:28:54 -0600375
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600376#define pmux_slw_isvalid(slw) \
377 (((slw) >= PMUX_SLWF_MIN) && ((slw) <= PMUX_SLWF_MAX))
Stephen Warrene2969952014-03-21 12:28:54 -0600378
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600379#define pmux_drv_isvalid(drv) \
380 (((drv) >= PMUX_DRVUP_MIN) && ((drv) <= PMUX_DRVUP_MAX))
Stephen Warrene2969952014-03-21 12:28:54 -0600381
Stephen Warren439f5762015-02-24 14:08:25 -0700382#ifdef TEGRA_PMX_GRPS_HAVE_HSM
Stephen Warrene2969952014-03-21 12:28:54 -0600383#define HSM_SHIFT 2
Stephen Warren439f5762015-02-24 14:08:25 -0700384#endif
385#ifdef TEGRA_PMX_GRPS_HAVE_SCHMT
Stephen Warrene2969952014-03-21 12:28:54 -0600386#define SCHMT_SHIFT 3
Stephen Warren439f5762015-02-24 14:08:25 -0700387#endif
388#ifdef TEGRA_PMX_GRPS_HAVE_LPMD
Stephen Warrene2969952014-03-21 12:28:54 -0600389#define LPMD_SHIFT 4
390#define LPMD_MASK (3 << LPMD_SHIFT)
Stephen Warren439f5762015-02-24 14:08:25 -0700391#endif
Stephen Warren9f21c1a2015-02-24 14:08:23 -0700392/*
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 Warrene2969952014-03-21 12:28:54 -0600407#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 Warrendfb42fc2014-03-21 12:28:56 -0600416static void pinmux_set_drvup_slwf(enum pmux_drvgrp grp, int slwf)
Stephen Warrene2969952014-03-21 12:28:54 -0600417{
418 u32 *reg = DRV_REG(grp);
419 u32 val;
420
421 /* NONE means unspecified/do not change/use POR value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600422 if (slwf == PMUX_SLWF_NONE)
Stephen Warrene2969952014-03-21 12:28:54 -0600423 return;
424
425 /* Error check on pad and slwf */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600426 assert(pmux_drvgrp_isvalid(grp));
427 assert(pmux_slw_isvalid(slwf));
Stephen Warrene2969952014-03-21 12:28:54 -0600428
429 val = readl(reg);
430 val &= ~SLWF_MASK;
431 val |= (slwf << SLWF_SHIFT);
432 writel(val, reg);
433
434 return;
435}
436
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600437static void pinmux_set_drvdn_slwr(enum pmux_drvgrp grp, int slwr)
Stephen Warrene2969952014-03-21 12:28:54 -0600438{
439 u32 *reg = DRV_REG(grp);
440 u32 val;
441
442 /* NONE means unspecified/do not change/use POR value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600443 if (slwr == PMUX_SLWR_NONE)
Stephen Warrene2969952014-03-21 12:28:54 -0600444 return;
445
446 /* Error check on pad and slwr */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600447 assert(pmux_drvgrp_isvalid(grp));
448 assert(pmux_slw_isvalid(slwr));
Stephen Warrene2969952014-03-21 12:28:54 -0600449
450 val = readl(reg);
451 val &= ~SLWR_MASK;
452 val |= (slwr << SLWR_SHIFT);
453 writel(val, reg);
454
455 return;
456}
457
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600458static void pinmux_set_drvup(enum pmux_drvgrp grp, int drvup)
Stephen Warrene2969952014-03-21 12:28:54 -0600459{
460 u32 *reg = DRV_REG(grp);
461 u32 val;
462
463 /* NONE means unspecified/do not change/use POR value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600464 if (drvup == PMUX_DRVUP_NONE)
Stephen Warrene2969952014-03-21 12:28:54 -0600465 return;
466
467 /* Error check on pad and drvup */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600468 assert(pmux_drvgrp_isvalid(grp));
469 assert(pmux_drv_isvalid(drvup));
Stephen Warrene2969952014-03-21 12:28:54 -0600470
471 val = readl(reg);
472 val &= ~DRVUP_MASK;
473 val |= (drvup << DRVUP_SHIFT);
474 writel(val, reg);
475
476 return;
477}
478
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600479static void pinmux_set_drvdn(enum pmux_drvgrp grp, int drvdn)
Stephen Warrene2969952014-03-21 12:28:54 -0600480{
481 u32 *reg = DRV_REG(grp);
482 u32 val;
483
484 /* NONE means unspecified/do not change/use POR value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600485 if (drvdn == PMUX_DRVDN_NONE)
Stephen Warrene2969952014-03-21 12:28:54 -0600486 return;
487
488 /* Error check on pad and drvdn */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600489 assert(pmux_drvgrp_isvalid(grp));
490 assert(pmux_drv_isvalid(drvdn));
Stephen Warrene2969952014-03-21 12:28:54 -0600491
492 val = readl(reg);
493 val &= ~DRVDN_MASK;
494 val |= (drvdn << DRVDN_SHIFT);
495 writel(val, reg);
496
497 return;
498}
499
Stephen Warren439f5762015-02-24 14:08:25 -0700500#ifdef TEGRA_PMX_GRPS_HAVE_LPMD
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600501static void pinmux_set_lpmd(enum pmux_drvgrp grp, enum pmux_lpmd lpmd)
Stephen Warrene2969952014-03-21 12:28:54 -0600502{
503 u32 *reg = DRV_REG(grp);
504 u32 val;
505
506 /* NONE means unspecified/do not change/use POR value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600507 if (lpmd == PMUX_LPMD_NONE)
Stephen Warrene2969952014-03-21 12:28:54 -0600508 return;
509
510 /* Error check pad and lpmd value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600511 assert(pmux_drvgrp_isvalid(grp));
512 assert(pmux_lpmd_isvalid(lpmd));
Stephen Warrene2969952014-03-21 12:28:54 -0600513
514 val = readl(reg);
515 val &= ~LPMD_MASK;
516 val |= (lpmd << LPMD_SHIFT);
517 writel(val, reg);
518
519 return;
520}
Stephen Warren439f5762015-02-24 14:08:25 -0700521#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600522
Stephen Warren439f5762015-02-24 14:08:25 -0700523#ifdef TEGRA_PMX_GRPS_HAVE_SCHMT
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600524static void pinmux_set_schmt(enum pmux_drvgrp grp, enum pmux_schmt schmt)
Stephen Warrene2969952014-03-21 12:28:54 -0600525{
526 u32 *reg = DRV_REG(grp);
527 u32 val;
528
529 /* NONE means unspecified/do not change/use POR value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600530 if (schmt == PMUX_SCHMT_NONE)
Stephen Warrene2969952014-03-21 12:28:54 -0600531 return;
532
533 /* Error check pad */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600534 assert(pmux_drvgrp_isvalid(grp));
535 assert(pmux_schmt_isvalid(schmt));
Stephen Warrene2969952014-03-21 12:28:54 -0600536
537 val = readl(reg);
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600538 if (schmt == PMUX_SCHMT_ENABLE)
Stephen Warrene2969952014-03-21 12:28:54 -0600539 val |= (1 << SCHMT_SHIFT);
540 else
541 val &= ~(1 << SCHMT_SHIFT);
542 writel(val, reg);
543
544 return;
545}
Stephen Warren439f5762015-02-24 14:08:25 -0700546#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600547
Stephen Warren439f5762015-02-24 14:08:25 -0700548#ifdef TEGRA_PMX_GRPS_HAVE_HSM
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600549static void pinmux_set_hsm(enum pmux_drvgrp grp, enum pmux_hsm hsm)
Stephen Warrene2969952014-03-21 12:28:54 -0600550{
551 u32 *reg = DRV_REG(grp);
552 u32 val;
553
554 /* NONE means unspecified/do not change/use POR value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600555 if (hsm == PMUX_HSM_NONE)
Stephen Warrene2969952014-03-21 12:28:54 -0600556 return;
557
558 /* Error check pad */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600559 assert(pmux_drvgrp_isvalid(grp));
560 assert(pmux_hsm_isvalid(hsm));
Stephen Warrene2969952014-03-21 12:28:54 -0600561
562 val = readl(reg);
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600563 if (hsm == PMUX_HSM_ENABLE)
Stephen Warrene2969952014-03-21 12:28:54 -0600564 val |= (1 << HSM_SHIFT);
565 else
566 val &= ~(1 << HSM_SHIFT);
567 writel(val, reg);
568
569 return;
570}
Stephen Warren439f5762015-02-24 14:08:25 -0700571#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600572
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600573static void pinmux_config_drvgrp(const struct pmux_drvgrp_config *config)
Stephen Warrene2969952014-03-21 12:28:54 -0600574{
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600575 enum pmux_drvgrp grp = config->drvgrp;
Stephen Warrene2969952014-03-21 12:28:54 -0600576
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600577 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 Warren439f5762015-02-24 14:08:25 -0700581#ifdef TEGRA_PMX_GRPS_HAVE_LPMD
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600582 pinmux_set_lpmd(grp, config->lpmd);
Stephen Warren439f5762015-02-24 14:08:25 -0700583#endif
584#ifdef TEGRA_PMX_GRPS_HAVE_SCHMT
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600585 pinmux_set_schmt(grp, config->schmt);
Stephen Warren439f5762015-02-24 14:08:25 -0700586#endif
587#ifdef TEGRA_PMX_GRPS_HAVE_HSM
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600588 pinmux_set_hsm(grp, config->hsm);
Stephen Warren439f5762015-02-24 14:08:25 -0700589#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600590}
591
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600592void pinmux_config_drvgrp_table(const struct pmux_drvgrp_config *config,
593 int len)
Stephen Warrene2969952014-03-21 12:28:54 -0600594{
595 int i;
596
597 for (i = 0; i < len; i++)
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600598 pinmux_config_drvgrp(&config[i]);
Stephen Warrene2969952014-03-21 12:28:54 -0600599}
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600600#endif /* TEGRA_PMX_HAS_DRVGRPS */