blob: 912f65e98b06e999ad8101c29dd71e62fff5e229 [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 Warrenf4d7c9d2015-02-24 14:08:30 -070059#ifdef TEGRA_PMX_PINS_HAVE_E_IO_HV
60/* return 1 if a pin_e_io_hv is in range */
61#define pmux_pin_e_io_hv_isvalid(e_io_hv) \
62 (((e_io_hv) >= PMUX_PIN_E_IO_HV_NORMAL) && \
63 ((e_io_hv) <= PMUX_PIN_E_IO_HV_HIGH))
64#endif
65
Stephen Warrenbc134722015-02-24 14:08:26 -070066#ifdef TEGRA_PMX_GRPS_HAVE_LPMD
67#define pmux_lpmd_isvalid(lpm) \
68 (((lpm) >= PMUX_LPMD_X8) && ((lpm) <= PMUX_LPMD_X))
69#endif
70
Stephen Warrenf2c60ee2015-02-24 14:08:28 -070071#if defined(TEGRA_PMX_PINS_HAVE_SCHMT) || defined(TEGRA_PMX_GRPS_HAVE_SCHMT)
Stephen Warrenbc134722015-02-24 14:08:26 -070072#define pmux_schmt_isvalid(schmt) \
73 (((schmt) >= PMUX_SCHMT_DISABLE) && ((schmt) <= PMUX_SCHMT_ENABLE))
74#endif
75
Stephen Warrenf2c60ee2015-02-24 14:08:28 -070076#if defined(TEGRA_PMX_PINS_HAVE_HSM) || defined(TEGRA_PMX_GRPS_HAVE_HSM)
Stephen Warrenbc134722015-02-24 14:08:26 -070077#define pmux_hsm_isvalid(hsm) \
78 (((hsm) >= PMUX_HSM_DISABLE) && ((hsm) <= PMUX_HSM_ENABLE))
79#endif
80
Stephen Warrene2969952014-03-21 12:28:54 -060081#define _R(offset) (u32 *)(NV_PA_APB_MISC_BASE + (offset))
82
83#if defined(CONFIG_TEGRA20)
84
85#define MUX_REG(grp) _R(0x80 + ((tegra_soc_pingroups[grp].ctl_id / 16) * 4))
86#define MUX_SHIFT(grp) ((tegra_soc_pingroups[grp].ctl_id % 16) * 2)
87
88#define PULL_REG(grp) _R(0xa0 + ((tegra_soc_pingroups[grp].pull_id / 16) * 4))
89#define PULL_SHIFT(grp) ((tegra_soc_pingroups[grp].pull_id % 16) * 2)
90
91#define TRI_REG(grp) _R(0x14 + (((grp) / 32) * 4))
92#define TRI_SHIFT(grp) ((grp) % 32)
93
94#else
95
96#define REG(pin) _R(0x3000 + ((pin) * 4))
97
98#define MUX_REG(pin) REG(pin)
99#define MUX_SHIFT(pin) 0
100
101#define PULL_REG(pin) REG(pin)
102#define PULL_SHIFT(pin) 2
103
104#define TRI_REG(pin) REG(pin)
105#define TRI_SHIFT(pin) 4
106
107#endif /* CONFIG_TEGRA20 */
108
Stephen Warren790f7712015-02-24 14:08:29 -0700109#define DRV_REG(group) _R(TEGRA_PMX_SOC_DRV_GROUP_BASE_REG + ((group) * 4))
Stephen Warrene2969952014-03-21 12:28:54 -0600110
Stephen Warrenb2cd3d82015-02-24 14:08:27 -0700111/*
112 * We could force arch-tegraNN/pinmux.h to define all of these. However,
113 * that's a lot of defines, and for now it's manageable to just put a
114 * special case here. It's possible this decision will change with future
115 * SoCs.
116 */
117#ifdef CONFIG_TEGRA210
118#define IO_SHIFT 6
119#define LOCK_SHIFT 7
Stephen Warrenf2c60ee2015-02-24 14:08:28 -0700120#ifdef TEGRA_PMX_PINS_HAVE_HSM
121#define HSM_SHIFT 9
122#endif
Stephen Warrenf4d7c9d2015-02-24 14:08:30 -0700123#define E_IO_HV_SHIFT 10
Stephen Warrenb2cd3d82015-02-24 14:08:27 -0700124#define OD_SHIFT 11
Stephen Warrenf2c60ee2015-02-24 14:08:28 -0700125#ifdef TEGRA_PMX_PINS_HAVE_SCHMT
126#define SCHMT_SHIFT 12
127#endif
Stephen Warrenb2cd3d82015-02-24 14:08:27 -0700128#else
Stephen Warrene2969952014-03-21 12:28:54 -0600129#define IO_SHIFT 5
130#define OD_SHIFT 6
131#define LOCK_SHIFT 7
132#define IO_RESET_SHIFT 8
133#define RCV_SEL_SHIFT 9
Stephen Warrenb2cd3d82015-02-24 14:08:27 -0700134#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600135
Stephen Warren7a284412015-02-24 14:08:24 -0700136#ifdef TEGRA_PMX_SOC_HAS_IO_CLAMPING
Stephen Warrenbb144692014-04-22 14:37:54 -0600137/* This register/field only exists on Tegra114 and later */
138#define APB_MISC_PP_PINMUX_GLOBAL_0 0x40
139#define CLAMP_INPUTS_WHEN_TRISTATED 1
140
141void pinmux_set_tristate_input_clamping(void)
142{
143 u32 *reg = _R(APB_MISC_PP_PINMUX_GLOBAL_0);
Stephen Warrenbb144692014-04-22 14:37:54 -0600144
Stephen Warrenf799b032015-02-18 13:27:03 -0700145 setbits_le32(reg, CLAMP_INPUTS_WHEN_TRISTATED);
146}
147
148void pinmux_clear_tristate_input_clamping(void)
149{
150 u32 *reg = _R(APB_MISC_PP_PINMUX_GLOBAL_0);
151
152 clrbits_le32(reg, CLAMP_INPUTS_WHEN_TRISTATED);
Stephen Warrenbb144692014-04-22 14:37:54 -0600153}
154#endif
155
Stephen Warrene2969952014-03-21 12:28:54 -0600156void pinmux_set_func(enum pmux_pingrp pin, enum pmux_func func)
157{
158 u32 *reg = MUX_REG(pin);
159 int i, mux = -1;
160 u32 val;
161
Stephen Warren4a68d342014-04-22 14:37:52 -0600162 if (func == PMUX_FUNC_DEFAULT)
163 return;
164
Stephen Warrene2969952014-03-21 12:28:54 -0600165 /* Error check on pin and func */
166 assert(pmux_pingrp_isvalid(pin));
167 assert(pmux_func_isvalid(func));
168
Stephen Warrend3812942014-03-21 15:58:03 -0600169 if (func >= PMUX_FUNC_RSVD1) {
170 mux = (func - PMUX_FUNC_RSVD1) & 3;
Stephen Warrene2969952014-03-21 12:28:54 -0600171 } else {
172 /* Search for the appropriate function */
173 for (i = 0; i < 4; i++) {
174 if (tegra_soc_pingroups[pin].funcs[i] == func) {
175 mux = i;
176 break;
177 }
178 }
179 }
180 assert(mux != -1);
181
182 val = readl(reg);
183 val &= ~(3 << MUX_SHIFT(pin));
184 val |= (mux << MUX_SHIFT(pin));
185 writel(val, reg);
186}
187
188void pinmux_set_pullupdown(enum pmux_pingrp pin, enum pmux_pull pupd)
189{
190 u32 *reg = PULL_REG(pin);
191 u32 val;
192
193 /* Error check on pin and pupd */
194 assert(pmux_pingrp_isvalid(pin));
195 assert(pmux_pin_pupd_isvalid(pupd));
196
197 val = readl(reg);
198 val &= ~(3 << PULL_SHIFT(pin));
199 val |= (pupd << PULL_SHIFT(pin));
200 writel(val, reg);
201}
202
Stephen Warrena45fa432014-03-21 12:28:55 -0600203static void pinmux_set_tristate(enum pmux_pingrp pin, int tri)
Stephen Warrene2969952014-03-21 12:28:54 -0600204{
205 u32 *reg = TRI_REG(pin);
206 u32 val;
207
208 /* Error check on pin */
209 assert(pmux_pingrp_isvalid(pin));
210 assert(pmux_pin_tristate_isvalid(tri));
211
212 val = readl(reg);
213 if (tri == PMUX_TRI_TRISTATE)
214 val |= (1 << TRI_SHIFT(pin));
215 else
216 val &= ~(1 << TRI_SHIFT(pin));
217 writel(val, reg);
218}
219
220void pinmux_tristate_enable(enum pmux_pingrp pin)
221{
222 pinmux_set_tristate(pin, PMUX_TRI_TRISTATE);
223}
224
225void pinmux_tristate_disable(enum pmux_pingrp pin)
226{
227 pinmux_set_tristate(pin, PMUX_TRI_NORMAL);
228}
229
Stephen Warren7a284412015-02-24 14:08:24 -0700230#ifdef TEGRA_PMX_PINS_HAVE_E_INPUT
Stephen Warrene2969952014-03-21 12:28:54 -0600231void pinmux_set_io(enum pmux_pingrp pin, enum pmux_pin_io io)
232{
233 u32 *reg = REG(pin);
234 u32 val;
235
236 if (io == PMUX_PIN_NONE)
237 return;
238
239 /* Error check on pin and io */
240 assert(pmux_pingrp_isvalid(pin));
241 assert(pmux_pin_io_isvalid(io));
242
243 val = readl(reg);
244 if (io == PMUX_PIN_INPUT)
245 val |= (io & 1) << IO_SHIFT;
246 else
247 val &= ~(1 << IO_SHIFT);
248 writel(val, reg);
249}
Stephen Warren7a284412015-02-24 14:08:24 -0700250#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600251
Stephen Warren7a284412015-02-24 14:08:24 -0700252#ifdef TEGRA_PMX_PINS_HAVE_LOCK
Stephen Warrene2969952014-03-21 12:28:54 -0600253static void pinmux_set_lock(enum pmux_pingrp pin, enum pmux_pin_lock lock)
254{
255 u32 *reg = REG(pin);
256 u32 val;
257
258 if (lock == PMUX_PIN_LOCK_DEFAULT)
259 return;
260
261 /* Error check on pin and lock */
262 assert(pmux_pingrp_isvalid(pin));
263 assert(pmux_pin_lock_isvalid(lock));
264
265 val = readl(reg);
266 if (lock == PMUX_PIN_LOCK_ENABLE) {
267 val |= (1 << LOCK_SHIFT);
268 } else {
269 if (val & (1 << LOCK_SHIFT))
270 printf("%s: Cannot clear LOCK bit!\n", __func__);
271 val &= ~(1 << LOCK_SHIFT);
272 }
273 writel(val, reg);
274
275 return;
276}
Stephen Warren7a284412015-02-24 14:08:24 -0700277#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600278
Stephen Warren7a284412015-02-24 14:08:24 -0700279#ifdef TEGRA_PMX_PINS_HAVE_OD
Stephen Warrene2969952014-03-21 12:28:54 -0600280static void pinmux_set_od(enum pmux_pingrp pin, enum pmux_pin_od od)
281{
282 u32 *reg = REG(pin);
283 u32 val;
284
285 if (od == PMUX_PIN_OD_DEFAULT)
286 return;
287
288 /* Error check on pin and od */
289 assert(pmux_pingrp_isvalid(pin));
290 assert(pmux_pin_od_isvalid(od));
291
292 val = readl(reg);
293 if (od == PMUX_PIN_OD_ENABLE)
294 val |= (1 << OD_SHIFT);
295 else
296 val &= ~(1 << OD_SHIFT);
297 writel(val, reg);
298
299 return;
300}
Stephen Warren7a284412015-02-24 14:08:24 -0700301#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600302
Stephen Warren7a284412015-02-24 14:08:24 -0700303#ifdef TEGRA_PMX_PINS_HAVE_IO_RESET
Stephen Warrene2969952014-03-21 12:28:54 -0600304static void pinmux_set_ioreset(enum pmux_pingrp pin,
305 enum pmux_pin_ioreset ioreset)
306{
307 u32 *reg = REG(pin);
308 u32 val;
309
310 if (ioreset == PMUX_PIN_IO_RESET_DEFAULT)
311 return;
312
313 /* Error check on pin and ioreset */
314 assert(pmux_pingrp_isvalid(pin));
315 assert(pmux_pin_ioreset_isvalid(ioreset));
316
317 val = readl(reg);
318 if (ioreset == PMUX_PIN_IO_RESET_ENABLE)
319 val |= (1 << IO_RESET_SHIFT);
320 else
321 val &= ~(1 << IO_RESET_SHIFT);
322 writel(val, reg);
323
324 return;
325}
Stephen Warren7a284412015-02-24 14:08:24 -0700326#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600327
Stephen Warren7a284412015-02-24 14:08:24 -0700328#ifdef TEGRA_PMX_PINS_HAVE_RCV_SEL
Stephen Warrene2969952014-03-21 12:28:54 -0600329static void pinmux_set_rcv_sel(enum pmux_pingrp pin,
330 enum pmux_pin_rcv_sel rcv_sel)
331{
332 u32 *reg = REG(pin);
333 u32 val;
334
335 if (rcv_sel == PMUX_PIN_RCV_SEL_DEFAULT)
336 return;
337
338 /* Error check on pin and rcv_sel */
339 assert(pmux_pingrp_isvalid(pin));
340 assert(pmux_pin_rcv_sel_isvalid(rcv_sel));
341
342 val = readl(reg);
343 if (rcv_sel == PMUX_PIN_RCV_SEL_HIGH)
344 val |= (1 << RCV_SEL_SHIFT);
345 else
346 val &= ~(1 << RCV_SEL_SHIFT);
347 writel(val, reg);
348
349 return;
350}
Stephen Warren7a284412015-02-24 14:08:24 -0700351#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600352
Stephen Warrenf4d7c9d2015-02-24 14:08:30 -0700353#ifdef TEGRA_PMX_PINS_HAVE_E_IO_HV
354static void pinmux_set_e_io_hv(enum pmux_pingrp pin,
355 enum pmux_pin_e_io_hv e_io_hv)
356{
357 u32 *reg = REG(pin);
358 u32 val;
359
360 if (e_io_hv == PMUX_PIN_E_IO_HV_DEFAULT)
361 return;
362
363 /* Error check on pin and e_io_hv */
364 assert(pmux_pingrp_isvalid(pin));
365 assert(pmux_pin_e_io_hv_isvalid(e_io_hv));
366
367 val = readl(reg);
368 if (e_io_hv == PMUX_PIN_E_IO_HV_HIGH)
369 val |= (1 << E_IO_HV_SHIFT);
370 else
371 val &= ~(1 << E_IO_HV_SHIFT);
372 writel(val, reg);
373
374 return;
375}
376#endif
377
Stephen Warrenf2c60ee2015-02-24 14:08:28 -0700378#ifdef TEGRA_PMX_PINS_HAVE_SCHMT
379static void pinmux_set_schmt(enum pmux_pingrp pin, enum pmux_schmt schmt)
380{
381 u32 *reg = REG(grp);
382 u32 val;
383
384 /* NONE means unspecified/do not change/use POR value */
385 if (schmt == PMUX_SCHMT_NONE)
386 return;
387
388 /* Error check pad */
389 assert(pmux_pingrp_isvalid(pin));
390 assert(pmux_schmt_isvalid(schmt));
391
392 val = readl(reg);
393 if (schmt == PMUX_SCHMT_ENABLE)
394 val |= (1 << SCHMT_SHIFT);
395 else
396 val &= ~(1 << SCHMT_SHIFT);
397 writel(val, reg);
398
399 return;
400}
401#endif
402
403#ifdef TEGRA_PMX_PINS_HAVE_HSM
404static void pinmux_set_hsm(enum pmux_pingrp pin, enum pmux_hsm hsm)
405{
406 u32 *reg = REG(grp);
407 u32 val;
408
409 /* NONE means unspecified/do not change/use POR value */
410 if (hsm == PMUX_HSM_NONE)
411 return;
412
413 /* Error check pad */
414 assert(pmux_pingrp_isvalid(pin));
415 assert(pmux_hsm_isvalid(hsm));
416
417 val = readl(reg);
418 if (hsm == PMUX_HSM_ENABLE)
419 val |= (1 << HSM_SHIFT);
420 else
421 val &= ~(1 << HSM_SHIFT);
422 writel(val, reg);
423
424 return;
425}
426#endif
427
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600428static void pinmux_config_pingrp(const struct pmux_pingrp_config *config)
Stephen Warrene2969952014-03-21 12:28:54 -0600429{
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600430 enum pmux_pingrp pin = config->pingrp;
Stephen Warrene2969952014-03-21 12:28:54 -0600431
432 pinmux_set_func(pin, config->func);
433 pinmux_set_pullupdown(pin, config->pull);
434 pinmux_set_tristate(pin, config->tristate);
Stephen Warren7a284412015-02-24 14:08:24 -0700435#ifdef TEGRA_PMX_PINS_HAVE_E_INPUT
Stephen Warrene2969952014-03-21 12:28:54 -0600436 pinmux_set_io(pin, config->io);
Stephen Warrene2969952014-03-21 12:28:54 -0600437#endif
Stephen Warren7a284412015-02-24 14:08:24 -0700438#ifdef TEGRA_PMX_PINS_HAVE_LOCK
439 pinmux_set_lock(pin, config->lock);
440#endif
441#ifdef TEGRA_PMX_PINS_HAVE_OD
442 pinmux_set_od(pin, config->od);
443#endif
444#ifdef TEGRA_PMX_PINS_HAVE_IO_RESET
445 pinmux_set_ioreset(pin, config->ioreset);
446#endif
447#ifdef TEGRA_PMX_PINS_HAVE_RCV_SEL
448 pinmux_set_rcv_sel(pin, config->rcv_sel);
Stephen Warrene2969952014-03-21 12:28:54 -0600449#endif
Stephen Warrenf4d7c9d2015-02-24 14:08:30 -0700450#ifdef TEGRA_PMX_PINS_HAVE_E_IO_HV
451 pinmux_set_e_io_hv(pin, config->e_io_hv);
452#endif
Stephen Warrenf2c60ee2015-02-24 14:08:28 -0700453#ifdef TEGRA_PMX_PINS_HAVE_SCHMT
454 pinmux_set_schmt(pin, config->schmt);
455#endif
456#ifdef TEGRA_PMX_PINS_HAVE_HSM
457 pinmux_set_hsm(pin, config->hsm);
458#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600459}
460
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600461void pinmux_config_pingrp_table(const struct pmux_pingrp_config *config,
462 int len)
Stephen Warrene2969952014-03-21 12:28:54 -0600463{
464 int i;
465
466 for (i = 0; i < len; i++)
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600467 pinmux_config_pingrp(&config[i]);
Stephen Warrene2969952014-03-21 12:28:54 -0600468}
469
Stephen Warren7a284412015-02-24 14:08:24 -0700470#ifdef TEGRA_PMX_SOC_HAS_DRVGRPS
Stephen Warrene2969952014-03-21 12:28:54 -0600471
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600472#define pmux_drvgrp_isvalid(pd) (((pd) >= 0) && ((pd) < PMUX_DRVGRP_COUNT))
Stephen Warrene2969952014-03-21 12:28:54 -0600473
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600474#define pmux_slw_isvalid(slw) \
475 (((slw) >= PMUX_SLWF_MIN) && ((slw) <= PMUX_SLWF_MAX))
Stephen Warrene2969952014-03-21 12:28:54 -0600476
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600477#define pmux_drv_isvalid(drv) \
478 (((drv) >= PMUX_DRVUP_MIN) && ((drv) <= PMUX_DRVUP_MAX))
Stephen Warrene2969952014-03-21 12:28:54 -0600479
Stephen Warren439f5762015-02-24 14:08:25 -0700480#ifdef TEGRA_PMX_GRPS_HAVE_HSM
Stephen Warrene2969952014-03-21 12:28:54 -0600481#define HSM_SHIFT 2
Stephen Warren439f5762015-02-24 14:08:25 -0700482#endif
483#ifdef TEGRA_PMX_GRPS_HAVE_SCHMT
Stephen Warrene2969952014-03-21 12:28:54 -0600484#define SCHMT_SHIFT 3
Stephen Warren439f5762015-02-24 14:08:25 -0700485#endif
486#ifdef TEGRA_PMX_GRPS_HAVE_LPMD
Stephen Warrene2969952014-03-21 12:28:54 -0600487#define LPMD_SHIFT 4
488#define LPMD_MASK (3 << LPMD_SHIFT)
Stephen Warren439f5762015-02-24 14:08:25 -0700489#endif
Stephen Warren9f21c1a2015-02-24 14:08:23 -0700490/*
491 * Note that the following DRV* and SLW* defines are accurate for many drive
492 * groups on many SoCs. We really need a per-group data structure to solve
493 * this, since the fields are in different positions/sizes in different
494 * registers (for different groups).
495 *
496 * On Tegra30/114/124, the DRV*_SHIFT values vary.
497 * On Tegra30, the SLW*_SHIFT values vary.
498 * On Tegra30/114/124/210, the DRV*_MASK values vary, although the values
499 * below are wide enough to cover the widest fields, and hopefully don't
500 * interfere with any other fields.
501 * On Tegra30, the SLW*_MASK values vary, but we can't use a value that's
502 * wide enough to cover all cases, since that would cause the field to
503 * overlap with other fields in the narrower cases.
504 */
Stephen Warrene2969952014-03-21 12:28:54 -0600505#define DRVDN_SHIFT 12
506#define DRVDN_MASK (0x7F << DRVDN_SHIFT)
507#define DRVUP_SHIFT 20
508#define DRVUP_MASK (0x7F << DRVUP_SHIFT)
509#define SLWR_SHIFT 28
510#define SLWR_MASK (3 << SLWR_SHIFT)
511#define SLWF_SHIFT 30
512#define SLWF_MASK (3 << SLWF_SHIFT)
513
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600514static void pinmux_set_drvup_slwf(enum pmux_drvgrp grp, int slwf)
Stephen Warrene2969952014-03-21 12:28:54 -0600515{
516 u32 *reg = DRV_REG(grp);
517 u32 val;
518
519 /* NONE means unspecified/do not change/use POR value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600520 if (slwf == PMUX_SLWF_NONE)
Stephen Warrene2969952014-03-21 12:28:54 -0600521 return;
522
523 /* Error check on pad and slwf */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600524 assert(pmux_drvgrp_isvalid(grp));
525 assert(pmux_slw_isvalid(slwf));
Stephen Warrene2969952014-03-21 12:28:54 -0600526
527 val = readl(reg);
528 val &= ~SLWF_MASK;
529 val |= (slwf << SLWF_SHIFT);
530 writel(val, reg);
531
532 return;
533}
534
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600535static void pinmux_set_drvdn_slwr(enum pmux_drvgrp grp, int slwr)
Stephen Warrene2969952014-03-21 12:28:54 -0600536{
537 u32 *reg = DRV_REG(grp);
538 u32 val;
539
540 /* NONE means unspecified/do not change/use POR value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600541 if (slwr == PMUX_SLWR_NONE)
Stephen Warrene2969952014-03-21 12:28:54 -0600542 return;
543
544 /* Error check on pad and slwr */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600545 assert(pmux_drvgrp_isvalid(grp));
546 assert(pmux_slw_isvalid(slwr));
Stephen Warrene2969952014-03-21 12:28:54 -0600547
548 val = readl(reg);
549 val &= ~SLWR_MASK;
550 val |= (slwr << SLWR_SHIFT);
551 writel(val, reg);
552
553 return;
554}
555
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600556static void pinmux_set_drvup(enum pmux_drvgrp grp, int drvup)
Stephen Warrene2969952014-03-21 12:28:54 -0600557{
558 u32 *reg = DRV_REG(grp);
559 u32 val;
560
561 /* NONE means unspecified/do not change/use POR value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600562 if (drvup == PMUX_DRVUP_NONE)
Stephen Warrene2969952014-03-21 12:28:54 -0600563 return;
564
565 /* Error check on pad and drvup */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600566 assert(pmux_drvgrp_isvalid(grp));
567 assert(pmux_drv_isvalid(drvup));
Stephen Warrene2969952014-03-21 12:28:54 -0600568
569 val = readl(reg);
570 val &= ~DRVUP_MASK;
571 val |= (drvup << DRVUP_SHIFT);
572 writel(val, reg);
573
574 return;
575}
576
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600577static void pinmux_set_drvdn(enum pmux_drvgrp grp, int drvdn)
Stephen Warrene2969952014-03-21 12:28:54 -0600578{
579 u32 *reg = DRV_REG(grp);
580 u32 val;
581
582 /* NONE means unspecified/do not change/use POR value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600583 if (drvdn == PMUX_DRVDN_NONE)
Stephen Warrene2969952014-03-21 12:28:54 -0600584 return;
585
586 /* Error check on pad and drvdn */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600587 assert(pmux_drvgrp_isvalid(grp));
588 assert(pmux_drv_isvalid(drvdn));
Stephen Warrene2969952014-03-21 12:28:54 -0600589
590 val = readl(reg);
591 val &= ~DRVDN_MASK;
592 val |= (drvdn << DRVDN_SHIFT);
593 writel(val, reg);
594
595 return;
596}
597
Stephen Warren439f5762015-02-24 14:08:25 -0700598#ifdef TEGRA_PMX_GRPS_HAVE_LPMD
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600599static void pinmux_set_lpmd(enum pmux_drvgrp grp, enum pmux_lpmd lpmd)
Stephen Warrene2969952014-03-21 12:28:54 -0600600{
601 u32 *reg = DRV_REG(grp);
602 u32 val;
603
604 /* NONE means unspecified/do not change/use POR value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600605 if (lpmd == PMUX_LPMD_NONE)
Stephen Warrene2969952014-03-21 12:28:54 -0600606 return;
607
608 /* Error check pad and lpmd value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600609 assert(pmux_drvgrp_isvalid(grp));
610 assert(pmux_lpmd_isvalid(lpmd));
Stephen Warrene2969952014-03-21 12:28:54 -0600611
612 val = readl(reg);
613 val &= ~LPMD_MASK;
614 val |= (lpmd << LPMD_SHIFT);
615 writel(val, reg);
616
617 return;
618}
Stephen Warren439f5762015-02-24 14:08:25 -0700619#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600620
Stephen Warren439f5762015-02-24 14:08:25 -0700621#ifdef TEGRA_PMX_GRPS_HAVE_SCHMT
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600622static void pinmux_set_schmt(enum pmux_drvgrp grp, enum pmux_schmt schmt)
Stephen Warrene2969952014-03-21 12:28:54 -0600623{
624 u32 *reg = DRV_REG(grp);
625 u32 val;
626
627 /* NONE means unspecified/do not change/use POR value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600628 if (schmt == PMUX_SCHMT_NONE)
Stephen Warrene2969952014-03-21 12:28:54 -0600629 return;
630
631 /* Error check pad */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600632 assert(pmux_drvgrp_isvalid(grp));
633 assert(pmux_schmt_isvalid(schmt));
Stephen Warrene2969952014-03-21 12:28:54 -0600634
635 val = readl(reg);
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600636 if (schmt == PMUX_SCHMT_ENABLE)
Stephen Warrene2969952014-03-21 12:28:54 -0600637 val |= (1 << SCHMT_SHIFT);
638 else
639 val &= ~(1 << SCHMT_SHIFT);
640 writel(val, reg);
641
642 return;
643}
Stephen Warren439f5762015-02-24 14:08:25 -0700644#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600645
Stephen Warren439f5762015-02-24 14:08:25 -0700646#ifdef TEGRA_PMX_GRPS_HAVE_HSM
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600647static void pinmux_set_hsm(enum pmux_drvgrp grp, enum pmux_hsm hsm)
Stephen Warrene2969952014-03-21 12:28:54 -0600648{
649 u32 *reg = DRV_REG(grp);
650 u32 val;
651
652 /* NONE means unspecified/do not change/use POR value */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600653 if (hsm == PMUX_HSM_NONE)
Stephen Warrene2969952014-03-21 12:28:54 -0600654 return;
655
656 /* Error check pad */
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600657 assert(pmux_drvgrp_isvalid(grp));
658 assert(pmux_hsm_isvalid(hsm));
Stephen Warrene2969952014-03-21 12:28:54 -0600659
660 val = readl(reg);
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600661 if (hsm == PMUX_HSM_ENABLE)
Stephen Warrene2969952014-03-21 12:28:54 -0600662 val |= (1 << HSM_SHIFT);
663 else
664 val &= ~(1 << HSM_SHIFT);
665 writel(val, reg);
666
667 return;
668}
Stephen Warren439f5762015-02-24 14:08:25 -0700669#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600670
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600671static void pinmux_config_drvgrp(const struct pmux_drvgrp_config *config)
Stephen Warrene2969952014-03-21 12:28:54 -0600672{
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600673 enum pmux_drvgrp grp = config->drvgrp;
Stephen Warrene2969952014-03-21 12:28:54 -0600674
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600675 pinmux_set_drvup_slwf(grp, config->slwf);
676 pinmux_set_drvdn_slwr(grp, config->slwr);
677 pinmux_set_drvup(grp, config->drvup);
678 pinmux_set_drvdn(grp, config->drvdn);
Stephen Warren439f5762015-02-24 14:08:25 -0700679#ifdef TEGRA_PMX_GRPS_HAVE_LPMD
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600680 pinmux_set_lpmd(grp, config->lpmd);
Stephen Warren439f5762015-02-24 14:08:25 -0700681#endif
682#ifdef TEGRA_PMX_GRPS_HAVE_SCHMT
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600683 pinmux_set_schmt(grp, config->schmt);
Stephen Warren439f5762015-02-24 14:08:25 -0700684#endif
685#ifdef TEGRA_PMX_GRPS_HAVE_HSM
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600686 pinmux_set_hsm(grp, config->hsm);
Stephen Warren439f5762015-02-24 14:08:25 -0700687#endif
Stephen Warrene2969952014-03-21 12:28:54 -0600688}
689
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600690void pinmux_config_drvgrp_table(const struct pmux_drvgrp_config *config,
691 int len)
Stephen Warrene2969952014-03-21 12:28:54 -0600692{
693 int i;
694
695 for (i = 0; i < len; i++)
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600696 pinmux_config_drvgrp(&config[i]);
Stephen Warrene2969952014-03-21 12:28:54 -0600697}
Stephen Warrendfb42fc2014-03-21 12:28:56 -0600698#endif /* TEGRA_PMX_HAS_DRVGRPS */