blob: 9bf30869712e7dde8e1e29cbc7689ba5a0ce0317 [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
Stephen Warrenf2c60ee2015-02-24 14:08:28 -070064#if defined(TEGRA_PMX_PINS_HAVE_SCHMT) || defined(TEGRA_PMX_GRPS_HAVE_SCHMT)
Stephen Warrenbc134722015-02-24 14:08:26 -070065#define pmux_schmt_isvalid(schmt) \
66 (((schmt) >= PMUX_SCHMT_DISABLE) && ((schmt) <= PMUX_SCHMT_ENABLE))
67#endif
68
Stephen Warrenf2c60ee2015-02-24 14:08:28 -070069#if defined(TEGRA_PMX_PINS_HAVE_HSM) || defined(TEGRA_PMX_GRPS_HAVE_HSM)
Stephen Warrenbc134722015-02-24 14:08:26 -070070#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
Stephen Warren790f7712015-02-24 14:08:29 -0700102#define DRV_REG(group) _R(TEGRA_PMX_SOC_DRV_GROUP_BASE_REG + ((group) * 4))
Stephen Warrene2969952014-03-21 12:28:54 -0600103
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
Stephen Warrenf2c60ee2015-02-24 14:08:28 -0700113#ifdef TEGRA_PMX_PINS_HAVE_HSM
114#define HSM_SHIFT 9
115#endif
Stephen Warrenb2cd3d82015-02-24 14:08:27 -0700116#define OD_SHIFT 11
Stephen Warrenf2c60ee2015-02-24 14:08:28 -0700117#ifdef TEGRA_PMX_PINS_HAVE_SCHMT
118#define SCHMT_SHIFT 12
119#endif
Stephen Warrenb2cd3d82015-02-24 14:08:27 -0700120#else
Stephen Warrene2969952014-03-21 12:28:54 -0600121#define IO_SHIFT 5
122#define OD_SHIFT 6
123#define LOCK_SHIFT 7
124#define IO_RESET_SHIFT 8
125#define RCV_SEL_SHIFT 9
Stephen Warrenb2cd3d82015-02-24 14:08:27 -0700126#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600127
Stephen Warren7a284412015-02-24 14:08:24 -0700128#ifdef TEGRA_PMX_SOC_HAS_IO_CLAMPING
Stephen Warrenbb144692014-04-22 14:37:54 -0600129/* This register/field only exists on Tegra114 and later */
130#define APB_MISC_PP_PINMUX_GLOBAL_0 0x40
131#define CLAMP_INPUTS_WHEN_TRISTATED 1
132
133void pinmux_set_tristate_input_clamping(void)
134{
135 u32 *reg = _R(APB_MISC_PP_PINMUX_GLOBAL_0);
Stephen Warrenbb144692014-04-22 14:37:54 -0600136
Stephen Warrenf799b032015-02-18 13:27:03 -0700137 setbits_le32(reg, CLAMP_INPUTS_WHEN_TRISTATED);
138}
139
140void pinmux_clear_tristate_input_clamping(void)
141{
142 u32 *reg = _R(APB_MISC_PP_PINMUX_GLOBAL_0);
143
144 clrbits_le32(reg, CLAMP_INPUTS_WHEN_TRISTATED);
Stephen Warrenbb144692014-04-22 14:37:54 -0600145}
146#endif
147
Stephen Warrene2969952014-03-21 12:28:54 -0600148void pinmux_set_func(enum pmux_pingrp pin, enum pmux_func func)
149{
150 u32 *reg = MUX_REG(pin);
151 int i, mux = -1;
152 u32 val;
153
Stephen Warren4a68d342014-04-22 14:37:52 -0600154 if (func == PMUX_FUNC_DEFAULT)
155 return;
156
Stephen Warrene2969952014-03-21 12:28:54 -0600157 /* Error check on pin and func */
158 assert(pmux_pingrp_isvalid(pin));
159 assert(pmux_func_isvalid(func));
160
Stephen Warrend3812942014-03-21 15:58:03 -0600161 if (func >= PMUX_FUNC_RSVD1) {
162 mux = (func - PMUX_FUNC_RSVD1) & 3;
Stephen Warrene2969952014-03-21 12:28:54 -0600163 } else {
164 /* Search for the appropriate function */
165 for (i = 0; i < 4; i++) {
166 if (tegra_soc_pingroups[pin].funcs[i] == func) {
167 mux = i;
168 break;
169 }
170 }
171 }
172 assert(mux != -1);
173
174 val = readl(reg);
175 val &= ~(3 << MUX_SHIFT(pin));
176 val |= (mux << MUX_SHIFT(pin));
177 writel(val, reg);
178}
179
180void pinmux_set_pullupdown(enum pmux_pingrp pin, enum pmux_pull pupd)
181{
182 u32 *reg = PULL_REG(pin);
183 u32 val;
184
185 /* Error check on pin and pupd */
186 assert(pmux_pingrp_isvalid(pin));
187 assert(pmux_pin_pupd_isvalid(pupd));
188
189 val = readl(reg);
190 val &= ~(3 << PULL_SHIFT(pin));
191 val |= (pupd << PULL_SHIFT(pin));
192 writel(val, reg);
193}
194
Stephen Warrena45fa432014-03-21 12:28:55 -0600195static void pinmux_set_tristate(enum pmux_pingrp pin, int tri)
Stephen Warrene2969952014-03-21 12:28:54 -0600196{
197 u32 *reg = TRI_REG(pin);
198 u32 val;
199
200 /* Error check on pin */
201 assert(pmux_pingrp_isvalid(pin));
202 assert(pmux_pin_tristate_isvalid(tri));
203
204 val = readl(reg);
205 if (tri == PMUX_TRI_TRISTATE)
206 val |= (1 << TRI_SHIFT(pin));
207 else
208 val &= ~(1 << TRI_SHIFT(pin));
209 writel(val, reg);
210}
211
212void pinmux_tristate_enable(enum pmux_pingrp pin)
213{
214 pinmux_set_tristate(pin, PMUX_TRI_TRISTATE);
215}
216
217void pinmux_tristate_disable(enum pmux_pingrp pin)
218{
219 pinmux_set_tristate(pin, PMUX_TRI_NORMAL);
220}
221
Stephen Warren7a284412015-02-24 14:08:24 -0700222#ifdef TEGRA_PMX_PINS_HAVE_E_INPUT
Stephen Warrene2969952014-03-21 12:28:54 -0600223void pinmux_set_io(enum pmux_pingrp pin, enum pmux_pin_io io)
224{
225 u32 *reg = REG(pin);
226 u32 val;
227
228 if (io == PMUX_PIN_NONE)
229 return;
230
231 /* Error check on pin and io */
232 assert(pmux_pingrp_isvalid(pin));
233 assert(pmux_pin_io_isvalid(io));
234
235 val = readl(reg);
236 if (io == PMUX_PIN_INPUT)
237 val |= (io & 1) << IO_SHIFT;
238 else
239 val &= ~(1 << IO_SHIFT);
240 writel(val, reg);
241}
Stephen Warren7a284412015-02-24 14:08:24 -0700242#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600243
Stephen Warren7a284412015-02-24 14:08:24 -0700244#ifdef TEGRA_PMX_PINS_HAVE_LOCK
Stephen Warrene2969952014-03-21 12:28:54 -0600245static void pinmux_set_lock(enum pmux_pingrp pin, enum pmux_pin_lock lock)
246{
247 u32 *reg = REG(pin);
248 u32 val;
249
250 if (lock == PMUX_PIN_LOCK_DEFAULT)
251 return;
252
253 /* Error check on pin and lock */
254 assert(pmux_pingrp_isvalid(pin));
255 assert(pmux_pin_lock_isvalid(lock));
256
257 val = readl(reg);
258 if (lock == PMUX_PIN_LOCK_ENABLE) {
259 val |= (1 << LOCK_SHIFT);
260 } else {
261 if (val & (1 << LOCK_SHIFT))
262 printf("%s: Cannot clear LOCK bit!\n", __func__);
263 val &= ~(1 << LOCK_SHIFT);
264 }
265 writel(val, reg);
266
267 return;
268}
Stephen Warren7a284412015-02-24 14:08:24 -0700269#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600270
Stephen Warren7a284412015-02-24 14:08:24 -0700271#ifdef TEGRA_PMX_PINS_HAVE_OD
Stephen Warrene2969952014-03-21 12:28:54 -0600272static void pinmux_set_od(enum pmux_pingrp pin, enum pmux_pin_od od)
273{
274 u32 *reg = REG(pin);
275 u32 val;
276
277 if (od == PMUX_PIN_OD_DEFAULT)
278 return;
279
280 /* Error check on pin and od */
281 assert(pmux_pingrp_isvalid(pin));
282 assert(pmux_pin_od_isvalid(od));
283
284 val = readl(reg);
285 if (od == PMUX_PIN_OD_ENABLE)
286 val |= (1 << OD_SHIFT);
287 else
288 val &= ~(1 << OD_SHIFT);
289 writel(val, reg);
290
291 return;
292}
Stephen Warren7a284412015-02-24 14:08:24 -0700293#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600294
Stephen Warren7a284412015-02-24 14:08:24 -0700295#ifdef TEGRA_PMX_PINS_HAVE_IO_RESET
Stephen Warrene2969952014-03-21 12:28:54 -0600296static void pinmux_set_ioreset(enum pmux_pingrp pin,
297 enum pmux_pin_ioreset ioreset)
298{
299 u32 *reg = REG(pin);
300 u32 val;
301
302 if (ioreset == PMUX_PIN_IO_RESET_DEFAULT)
303 return;
304
305 /* Error check on pin and ioreset */
306 assert(pmux_pingrp_isvalid(pin));
307 assert(pmux_pin_ioreset_isvalid(ioreset));
308
309 val = readl(reg);
310 if (ioreset == PMUX_PIN_IO_RESET_ENABLE)
311 val |= (1 << IO_RESET_SHIFT);
312 else
313 val &= ~(1 << IO_RESET_SHIFT);
314 writel(val, reg);
315
316 return;
317}
Stephen Warren7a284412015-02-24 14:08:24 -0700318#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600319
Stephen Warren7a284412015-02-24 14:08:24 -0700320#ifdef TEGRA_PMX_PINS_HAVE_RCV_SEL
Stephen Warrene2969952014-03-21 12:28:54 -0600321static void pinmux_set_rcv_sel(enum pmux_pingrp pin,
322 enum pmux_pin_rcv_sel rcv_sel)
323{
324 u32 *reg = REG(pin);
325 u32 val;
326
327 if (rcv_sel == PMUX_PIN_RCV_SEL_DEFAULT)
328 return;
329
330 /* Error check on pin and rcv_sel */
331 assert(pmux_pingrp_isvalid(pin));
332 assert(pmux_pin_rcv_sel_isvalid(rcv_sel));
333
334 val = readl(reg);
335 if (rcv_sel == PMUX_PIN_RCV_SEL_HIGH)
336 val |= (1 << RCV_SEL_SHIFT);
337 else
338 val &= ~(1 << RCV_SEL_SHIFT);
339 writel(val, reg);
340
341 return;
342}
Stephen Warren7a284412015-02-24 14:08:24 -0700343#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600344
Stephen Warrenf2c60ee2015-02-24 14:08:28 -0700345#ifdef TEGRA_PMX_PINS_HAVE_SCHMT
346static void pinmux_set_schmt(enum pmux_pingrp pin, enum pmux_schmt schmt)
347{
348 u32 *reg = REG(grp);
349 u32 val;
350
351 /* NONE means unspecified/do not change/use POR value */
352 if (schmt == PMUX_SCHMT_NONE)
353 return;
354
355 /* Error check pad */
356 assert(pmux_pingrp_isvalid(pin));
357 assert(pmux_schmt_isvalid(schmt));
358
359 val = readl(reg);
360 if (schmt == PMUX_SCHMT_ENABLE)
361 val |= (1 << SCHMT_SHIFT);
362 else
363 val &= ~(1 << SCHMT_SHIFT);
364 writel(val, reg);
365
366 return;
367}
368#endif
369
370#ifdef TEGRA_PMX_PINS_HAVE_HSM
371static void pinmux_set_hsm(enum pmux_pingrp pin, enum pmux_hsm hsm)
372{
373 u32 *reg = REG(grp);
374 u32 val;
375
376 /* NONE means unspecified/do not change/use POR value */
377 if (hsm == PMUX_HSM_NONE)
378 return;
379
380 /* Error check pad */
381 assert(pmux_pingrp_isvalid(pin));
382 assert(pmux_hsm_isvalid(hsm));
383
384 val = readl(reg);
385 if (hsm == PMUX_HSM_ENABLE)
386 val |= (1 << HSM_SHIFT);
387 else
388 val &= ~(1 << HSM_SHIFT);
389 writel(val, reg);
390
391 return;
392}
393#endif
394
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600395static void pinmux_config_pingrp(const struct pmux_pingrp_config *config)
Stephen Warrene2969952014-03-21 12:28:54 -0600396{
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600397 enum pmux_pingrp pin = config->pingrp;
Stephen Warrene2969952014-03-21 12:28:54 -0600398
399 pinmux_set_func(pin, config->func);
400 pinmux_set_pullupdown(pin, config->pull);
401 pinmux_set_tristate(pin, config->tristate);
Stephen Warren7a284412015-02-24 14:08:24 -0700402#ifdef TEGRA_PMX_PINS_HAVE_E_INPUT
Stephen Warrene2969952014-03-21 12:28:54 -0600403 pinmux_set_io(pin, config->io);
Stephen Warrene2969952014-03-21 12:28:54 -0600404#endif
Stephen Warren7a284412015-02-24 14:08:24 -0700405#ifdef TEGRA_PMX_PINS_HAVE_LOCK
406 pinmux_set_lock(pin, config->lock);
407#endif
408#ifdef TEGRA_PMX_PINS_HAVE_OD
409 pinmux_set_od(pin, config->od);
410#endif
411#ifdef TEGRA_PMX_PINS_HAVE_IO_RESET
412 pinmux_set_ioreset(pin, config->ioreset);
413#endif
414#ifdef TEGRA_PMX_PINS_HAVE_RCV_SEL
415 pinmux_set_rcv_sel(pin, config->rcv_sel);
Stephen Warrene2969952014-03-21 12:28:54 -0600416#endif
Stephen Warrenf2c60ee2015-02-24 14:08:28 -0700417#ifdef TEGRA_PMX_PINS_HAVE_SCHMT
418 pinmux_set_schmt(pin, config->schmt);
419#endif
420#ifdef TEGRA_PMX_PINS_HAVE_HSM
421 pinmux_set_hsm(pin, config->hsm);
422#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600423}
424
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600425void pinmux_config_pingrp_table(const struct pmux_pingrp_config *config,
426 int len)
Stephen Warrene2969952014-03-21 12:28:54 -0600427{
428 int i;
429
430 for (i = 0; i < len; i++)
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600431 pinmux_config_pingrp(&config[i]);
Stephen Warrene2969952014-03-21 12:28:54 -0600432}
433
Stephen Warren7a284412015-02-24 14:08:24 -0700434#ifdef TEGRA_PMX_SOC_HAS_DRVGRPS
Stephen Warrene2969952014-03-21 12:28:54 -0600435
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600436#define pmux_drvgrp_isvalid(pd) (((pd) >= 0) && ((pd) < PMUX_DRVGRP_COUNT))
Stephen Warrene2969952014-03-21 12:28:54 -0600437
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600438#define pmux_slw_isvalid(slw) \
439 (((slw) >= PMUX_SLWF_MIN) && ((slw) <= PMUX_SLWF_MAX))
Stephen Warrene2969952014-03-21 12:28:54 -0600440
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600441#define pmux_drv_isvalid(drv) \
442 (((drv) >= PMUX_DRVUP_MIN) && ((drv) <= PMUX_DRVUP_MAX))
Stephen Warrene2969952014-03-21 12:28:54 -0600443
Stephen Warren439f5762015-02-24 14:08:25 -0700444#ifdef TEGRA_PMX_GRPS_HAVE_HSM
Stephen Warrene2969952014-03-21 12:28:54 -0600445#define HSM_SHIFT 2
Stephen Warren439f5762015-02-24 14:08:25 -0700446#endif
447#ifdef TEGRA_PMX_GRPS_HAVE_SCHMT
Stephen Warrene2969952014-03-21 12:28:54 -0600448#define SCHMT_SHIFT 3
Stephen Warren439f5762015-02-24 14:08:25 -0700449#endif
450#ifdef TEGRA_PMX_GRPS_HAVE_LPMD
Stephen Warrene2969952014-03-21 12:28:54 -0600451#define LPMD_SHIFT 4
452#define LPMD_MASK (3 << LPMD_SHIFT)
Stephen Warren439f5762015-02-24 14:08:25 -0700453#endif
Stephen Warren9f21c1a2015-02-24 14:08:23 -0700454/*
455 * Note that the following DRV* and SLW* defines are accurate for many drive
456 * groups on many SoCs. We really need a per-group data structure to solve
457 * this, since the fields are in different positions/sizes in different
458 * registers (for different groups).
459 *
460 * On Tegra30/114/124, the DRV*_SHIFT values vary.
461 * On Tegra30, the SLW*_SHIFT values vary.
462 * On Tegra30/114/124/210, the DRV*_MASK values vary, although the values
463 * below are wide enough to cover the widest fields, and hopefully don't
464 * interfere with any other fields.
465 * On Tegra30, the SLW*_MASK values vary, but we can't use a value that's
466 * wide enough to cover all cases, since that would cause the field to
467 * overlap with other fields in the narrower cases.
468 */
Stephen Warrene2969952014-03-21 12:28:54 -0600469#define DRVDN_SHIFT 12
470#define DRVDN_MASK (0x7F << DRVDN_SHIFT)
471#define DRVUP_SHIFT 20
472#define DRVUP_MASK (0x7F << DRVUP_SHIFT)
473#define SLWR_SHIFT 28
474#define SLWR_MASK (3 << SLWR_SHIFT)
475#define SLWF_SHIFT 30
476#define SLWF_MASK (3 << SLWF_SHIFT)
477
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600478static void pinmux_set_drvup_slwf(enum pmux_drvgrp grp, int slwf)
Stephen Warrene2969952014-03-21 12:28:54 -0600479{
480 u32 *reg = DRV_REG(grp);
481 u32 val;
482
483 /* NONE means unspecified/do not change/use POR value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600484 if (slwf == PMUX_SLWF_NONE)
Stephen Warrene2969952014-03-21 12:28:54 -0600485 return;
486
487 /* Error check on pad and slwf */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600488 assert(pmux_drvgrp_isvalid(grp));
489 assert(pmux_slw_isvalid(slwf));
Stephen Warrene2969952014-03-21 12:28:54 -0600490
491 val = readl(reg);
492 val &= ~SLWF_MASK;
493 val |= (slwf << SLWF_SHIFT);
494 writel(val, reg);
495
496 return;
497}
498
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600499static void pinmux_set_drvdn_slwr(enum pmux_drvgrp grp, int slwr)
Stephen Warrene2969952014-03-21 12:28:54 -0600500{
501 u32 *reg = DRV_REG(grp);
502 u32 val;
503
504 /* NONE means unspecified/do not change/use POR value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600505 if (slwr == PMUX_SLWR_NONE)
Stephen Warrene2969952014-03-21 12:28:54 -0600506 return;
507
508 /* Error check on pad and slwr */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600509 assert(pmux_drvgrp_isvalid(grp));
510 assert(pmux_slw_isvalid(slwr));
Stephen Warrene2969952014-03-21 12:28:54 -0600511
512 val = readl(reg);
513 val &= ~SLWR_MASK;
514 val |= (slwr << SLWR_SHIFT);
515 writel(val, reg);
516
517 return;
518}
519
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600520static void pinmux_set_drvup(enum pmux_drvgrp grp, int drvup)
Stephen Warrene2969952014-03-21 12:28:54 -0600521{
522 u32 *reg = DRV_REG(grp);
523 u32 val;
524
525 /* NONE means unspecified/do not change/use POR value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600526 if (drvup == PMUX_DRVUP_NONE)
Stephen Warrene2969952014-03-21 12:28:54 -0600527 return;
528
529 /* Error check on pad and drvup */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600530 assert(pmux_drvgrp_isvalid(grp));
531 assert(pmux_drv_isvalid(drvup));
Stephen Warrene2969952014-03-21 12:28:54 -0600532
533 val = readl(reg);
534 val &= ~DRVUP_MASK;
535 val |= (drvup << DRVUP_SHIFT);
536 writel(val, reg);
537
538 return;
539}
540
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600541static void pinmux_set_drvdn(enum pmux_drvgrp grp, int drvdn)
Stephen Warrene2969952014-03-21 12:28:54 -0600542{
543 u32 *reg = DRV_REG(grp);
544 u32 val;
545
546 /* NONE means unspecified/do not change/use POR value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600547 if (drvdn == PMUX_DRVDN_NONE)
Stephen Warrene2969952014-03-21 12:28:54 -0600548 return;
549
550 /* Error check on pad and drvdn */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600551 assert(pmux_drvgrp_isvalid(grp));
552 assert(pmux_drv_isvalid(drvdn));
Stephen Warrene2969952014-03-21 12:28:54 -0600553
554 val = readl(reg);
555 val &= ~DRVDN_MASK;
556 val |= (drvdn << DRVDN_SHIFT);
557 writel(val, reg);
558
559 return;
560}
561
Stephen Warren439f5762015-02-24 14:08:25 -0700562#ifdef TEGRA_PMX_GRPS_HAVE_LPMD
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600563static void pinmux_set_lpmd(enum pmux_drvgrp grp, enum pmux_lpmd lpmd)
Stephen Warrene2969952014-03-21 12:28:54 -0600564{
565 u32 *reg = DRV_REG(grp);
566 u32 val;
567
568 /* NONE means unspecified/do not change/use POR value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600569 if (lpmd == PMUX_LPMD_NONE)
Stephen Warrene2969952014-03-21 12:28:54 -0600570 return;
571
572 /* Error check pad and lpmd value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600573 assert(pmux_drvgrp_isvalid(grp));
574 assert(pmux_lpmd_isvalid(lpmd));
Stephen Warrene2969952014-03-21 12:28:54 -0600575
576 val = readl(reg);
577 val &= ~LPMD_MASK;
578 val |= (lpmd << LPMD_SHIFT);
579 writel(val, reg);
580
581 return;
582}
Stephen Warren439f5762015-02-24 14:08:25 -0700583#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600584
Stephen Warren439f5762015-02-24 14:08:25 -0700585#ifdef TEGRA_PMX_GRPS_HAVE_SCHMT
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600586static void pinmux_set_schmt(enum pmux_drvgrp grp, enum pmux_schmt schmt)
Stephen Warrene2969952014-03-21 12:28:54 -0600587{
588 u32 *reg = DRV_REG(grp);
589 u32 val;
590
591 /* NONE means unspecified/do not change/use POR value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600592 if (schmt == PMUX_SCHMT_NONE)
Stephen Warrene2969952014-03-21 12:28:54 -0600593 return;
594
595 /* Error check pad */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600596 assert(pmux_drvgrp_isvalid(grp));
597 assert(pmux_schmt_isvalid(schmt));
Stephen Warrene2969952014-03-21 12:28:54 -0600598
599 val = readl(reg);
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600600 if (schmt == PMUX_SCHMT_ENABLE)
Stephen Warrene2969952014-03-21 12:28:54 -0600601 val |= (1 << SCHMT_SHIFT);
602 else
603 val &= ~(1 << SCHMT_SHIFT);
604 writel(val, reg);
605
606 return;
607}
Stephen Warren439f5762015-02-24 14:08:25 -0700608#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600609
Stephen Warren439f5762015-02-24 14:08:25 -0700610#ifdef TEGRA_PMX_GRPS_HAVE_HSM
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600611static void pinmux_set_hsm(enum pmux_drvgrp grp, enum pmux_hsm hsm)
Stephen Warrene2969952014-03-21 12:28:54 -0600612{
613 u32 *reg = DRV_REG(grp);
614 u32 val;
615
616 /* NONE means unspecified/do not change/use POR value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600617 if (hsm == PMUX_HSM_NONE)
Stephen Warrene2969952014-03-21 12:28:54 -0600618 return;
619
620 /* Error check pad */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600621 assert(pmux_drvgrp_isvalid(grp));
622 assert(pmux_hsm_isvalid(hsm));
Stephen Warrene2969952014-03-21 12:28:54 -0600623
624 val = readl(reg);
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600625 if (hsm == PMUX_HSM_ENABLE)
Stephen Warrene2969952014-03-21 12:28:54 -0600626 val |= (1 << HSM_SHIFT);
627 else
628 val &= ~(1 << HSM_SHIFT);
629 writel(val, reg);
630
631 return;
632}
Stephen Warren439f5762015-02-24 14:08:25 -0700633#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600634
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600635static void pinmux_config_drvgrp(const struct pmux_drvgrp_config *config)
Stephen Warrene2969952014-03-21 12:28:54 -0600636{
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600637 enum pmux_drvgrp grp = config->drvgrp;
Stephen Warrene2969952014-03-21 12:28:54 -0600638
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600639 pinmux_set_drvup_slwf(grp, config->slwf);
640 pinmux_set_drvdn_slwr(grp, config->slwr);
641 pinmux_set_drvup(grp, config->drvup);
642 pinmux_set_drvdn(grp, config->drvdn);
Stephen Warren439f5762015-02-24 14:08:25 -0700643#ifdef TEGRA_PMX_GRPS_HAVE_LPMD
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600644 pinmux_set_lpmd(grp, config->lpmd);
Stephen Warren439f5762015-02-24 14:08:25 -0700645#endif
646#ifdef TEGRA_PMX_GRPS_HAVE_SCHMT
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600647 pinmux_set_schmt(grp, config->schmt);
Stephen Warren439f5762015-02-24 14:08:25 -0700648#endif
649#ifdef TEGRA_PMX_GRPS_HAVE_HSM
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600650 pinmux_set_hsm(grp, config->hsm);
Stephen Warren439f5762015-02-24 14:08:25 -0700651#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600652}
653
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600654void pinmux_config_drvgrp_table(const struct pmux_drvgrp_config *config,
655 int len)
Stephen Warrene2969952014-03-21 12:28:54 -0600656{
657 int i;
658
659 for (i = 0; i < len; i++)
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600660 pinmux_config_drvgrp(&config[i]);
Stephen Warrene2969952014-03-21 12:28:54 -0600661}
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600662#endif /* TEGRA_PMX_HAS_DRVGRPS */