blob: 5862c4ac3dc6f719d868790657356fc833b7436d [file] [log] [blame]
Stephen Warren9026dfd2014-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 Warrenf4df6052014-03-21 12:28:56 -060013#define pmux_pingrp_isvalid(pin) (((pin) >= 0) && ((pin) < PMUX_PINGRP_COUNT))
Stephen Warren9026dfd2014-03-21 12:28:54 -060014
15/* return 1 if a pmux_func is in range */
16#define pmux_func_isvalid(func) \
Stephen Warren70b080f2014-03-21 15:58:03 -060017 (((func) >= 0) && ((func) < PMUX_FUNC_COUNT))
Stephen Warren9026dfd2014-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 Warren22d57fe2015-02-24 14:08:24 -070027#ifdef TEGRA_PMX_PINS_HAVE_E_INPUT
Stephen Warren9026dfd2014-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 Warren22d57fe2015-02-24 14:08:24 -070031#endif
Stephen Warren9026dfd2014-03-21 12:28:54 -060032
Stephen Warren22d57fe2015-02-24 14:08:24 -070033#ifdef TEGRA_PMX_PINS_HAVE_LOCK
Stephen Warren9026dfd2014-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 Warren22d57fe2015-02-24 14:08:24 -070037#endif
Stephen Warren9026dfd2014-03-21 12:28:54 -060038
Stephen Warren22d57fe2015-02-24 14:08:24 -070039#ifdef TEGRA_PMX_PINS_HAVE_OD
Stephen Warren9026dfd2014-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 Warren22d57fe2015-02-24 14:08:24 -070043#endif
Stephen Warren9026dfd2014-03-21 12:28:54 -060044
Stephen Warren22d57fe2015-02-24 14:08:24 -070045#ifdef TEGRA_PMX_PINS_HAVE_IO_RESET
Stephen Warren9026dfd2014-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 Warren22d57fe2015-02-24 14:08:24 -070050#endif
Stephen Warren9026dfd2014-03-21 12:28:54 -060051
Stephen Warren22d57fe2015-02-24 14:08:24 -070052#ifdef TEGRA_PMX_PINS_HAVE_RCV_SEL
Stephen Warren9026dfd2014-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 Warren22d57fe2015-02-24 14:08:24 -070057#endif
Stephen Warren9026dfd2014-03-21 12:28:54 -060058
Stephen Warrend9f8def2015-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 Warren899a5cb2015-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 Warren97f9c682015-02-24 14:08:28 -070071#if defined(TEGRA_PMX_PINS_HAVE_SCHMT) || defined(TEGRA_PMX_GRPS_HAVE_SCHMT)
Stephen Warren899a5cb2015-02-24 14:08:26 -070072#define pmux_schmt_isvalid(schmt) \
73 (((schmt) >= PMUX_SCHMT_DISABLE) && ((schmt) <= PMUX_SCHMT_ENABLE))
74#endif
75
Stephen Warren97f9c682015-02-24 14:08:28 -070076#if defined(TEGRA_PMX_PINS_HAVE_HSM) || defined(TEGRA_PMX_GRPS_HAVE_HSM)
Stephen Warren899a5cb2015-02-24 14:08:26 -070077#define pmux_hsm_isvalid(hsm) \
78 (((hsm) >= PMUX_HSM_DISABLE) && ((hsm) <= PMUX_HSM_ENABLE))
79#endif
80
Thierry Reding8264d1f2015-07-22 15:58:05 -060081#define _R(offset) (u32 *)((unsigned long)NV_PA_APB_MISC_BASE + (offset))
Stephen Warren9026dfd2014-03-21 12:28:54 -060082
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 Warren51f9e722015-02-24 14:08:29 -0700109#define DRV_REG(group) _R(TEGRA_PMX_SOC_DRV_GROUP_BASE_REG + ((group) * 4))
Stephen Warren9026dfd2014-03-21 12:28:54 -0600110
Stephen Warren8ec10882015-03-25 12:04:36 -0600111#define MIPIPADCTRL_REG(group) _R(TEGRA_PMX_SOC_MIPIPADCTRL_BASE_REG + ((group) * 4))
112
Stephen Warren9b9a75a2015-02-24 14:08:27 -0700113/*
114 * We could force arch-tegraNN/pinmux.h to define all of these. However,
115 * that's a lot of defines, and for now it's manageable to just put a
116 * special case here. It's possible this decision will change with future
117 * SoCs.
118 */
119#ifdef CONFIG_TEGRA210
120#define IO_SHIFT 6
121#define LOCK_SHIFT 7
Stephen Warren97f9c682015-02-24 14:08:28 -0700122#ifdef TEGRA_PMX_PINS_HAVE_HSM
123#define HSM_SHIFT 9
124#endif
Stephen Warrend9f8def2015-02-24 14:08:30 -0700125#define E_IO_HV_SHIFT 10
Stephen Warren9b9a75a2015-02-24 14:08:27 -0700126#define OD_SHIFT 11
Stephen Warren97f9c682015-02-24 14:08:28 -0700127#ifdef TEGRA_PMX_PINS_HAVE_SCHMT
128#define SCHMT_SHIFT 12
129#endif
Stephen Warren9b9a75a2015-02-24 14:08:27 -0700130#else
Stephen Warren9026dfd2014-03-21 12:28:54 -0600131#define IO_SHIFT 5
132#define OD_SHIFT 6
133#define LOCK_SHIFT 7
134#define IO_RESET_SHIFT 8
135#define RCV_SEL_SHIFT 9
Stephen Warren9b9a75a2015-02-24 14:08:27 -0700136#endif
Stephen Warren9026dfd2014-03-21 12:28:54 -0600137
Stephen Warren22d57fe2015-02-24 14:08:24 -0700138#ifdef TEGRA_PMX_SOC_HAS_IO_CLAMPING
Stephen Warrenf53f1082014-04-22 14:37:54 -0600139/* This register/field only exists on Tegra114 and later */
140#define APB_MISC_PP_PINMUX_GLOBAL_0 0x40
141#define CLAMP_INPUTS_WHEN_TRISTATED 1
142
143void pinmux_set_tristate_input_clamping(void)
144{
145 u32 *reg = _R(APB_MISC_PP_PINMUX_GLOBAL_0);
Stephen Warrendb2937f2015-02-18 13:27:03 -0700146
147 setbits_le32(reg, CLAMP_INPUTS_WHEN_TRISTATED);
148}
149
150void pinmux_clear_tristate_input_clamping(void)
151{
152 u32 *reg = _R(APB_MISC_PP_PINMUX_GLOBAL_0);
Stephen Warrenf53f1082014-04-22 14:37:54 -0600153
Stephen Warrendb2937f2015-02-18 13:27:03 -0700154 clrbits_le32(reg, CLAMP_INPUTS_WHEN_TRISTATED);
Stephen Warrenf53f1082014-04-22 14:37:54 -0600155}
156#endif
157
Stephen Warren9026dfd2014-03-21 12:28:54 -0600158void pinmux_set_func(enum pmux_pingrp pin, enum pmux_func func)
159{
160 u32 *reg = MUX_REG(pin);
161 int i, mux = -1;
162 u32 val;
163
Stephen Warren7d9fae52014-04-22 14:37:52 -0600164 if (func == PMUX_FUNC_DEFAULT)
165 return;
166
Stephen Warren9026dfd2014-03-21 12:28:54 -0600167 /* Error check on pin and func */
168 assert(pmux_pingrp_isvalid(pin));
169 assert(pmux_func_isvalid(func));
170
Stephen Warren70b080f2014-03-21 15:58:03 -0600171 if (func >= PMUX_FUNC_RSVD1) {
172 mux = (func - PMUX_FUNC_RSVD1) & 3;
Stephen Warren9026dfd2014-03-21 12:28:54 -0600173 } else {
174 /* Search for the appropriate function */
175 for (i = 0; i < 4; i++) {
176 if (tegra_soc_pingroups[pin].funcs[i] == func) {
177 mux = i;
178 break;
179 }
180 }
181 }
182 assert(mux != -1);
183
184 val = readl(reg);
185 val &= ~(3 << MUX_SHIFT(pin));
186 val |= (mux << MUX_SHIFT(pin));
187 writel(val, reg);
188}
189
190void pinmux_set_pullupdown(enum pmux_pingrp pin, enum pmux_pull pupd)
191{
192 u32 *reg = PULL_REG(pin);
193 u32 val;
194
195 /* Error check on pin and pupd */
196 assert(pmux_pingrp_isvalid(pin));
197 assert(pmux_pin_pupd_isvalid(pupd));
198
199 val = readl(reg);
200 val &= ~(3 << PULL_SHIFT(pin));
201 val |= (pupd << PULL_SHIFT(pin));
202 writel(val, reg);
203}
204
Stephen Warren51ed4ad2014-03-21 12:28:55 -0600205static void pinmux_set_tristate(enum pmux_pingrp pin, int tri)
Stephen Warren9026dfd2014-03-21 12:28:54 -0600206{
207 u32 *reg = TRI_REG(pin);
208 u32 val;
209
210 /* Error check on pin */
211 assert(pmux_pingrp_isvalid(pin));
212 assert(pmux_pin_tristate_isvalid(tri));
213
214 val = readl(reg);
215 if (tri == PMUX_TRI_TRISTATE)
216 val |= (1 << TRI_SHIFT(pin));
217 else
218 val &= ~(1 << TRI_SHIFT(pin));
219 writel(val, reg);
220}
221
222void pinmux_tristate_enable(enum pmux_pingrp pin)
223{
224 pinmux_set_tristate(pin, PMUX_TRI_TRISTATE);
225}
226
227void pinmux_tristate_disable(enum pmux_pingrp pin)
228{
229 pinmux_set_tristate(pin, PMUX_TRI_NORMAL);
230}
231
Stephen Warren22d57fe2015-02-24 14:08:24 -0700232#ifdef TEGRA_PMX_PINS_HAVE_E_INPUT
Stephen Warren9026dfd2014-03-21 12:28:54 -0600233void pinmux_set_io(enum pmux_pingrp pin, enum pmux_pin_io io)
234{
235 u32 *reg = REG(pin);
236 u32 val;
237
238 if (io == PMUX_PIN_NONE)
239 return;
240
241 /* Error check on pin and io */
242 assert(pmux_pingrp_isvalid(pin));
243 assert(pmux_pin_io_isvalid(io));
244
245 val = readl(reg);
246 if (io == PMUX_PIN_INPUT)
247 val |= (io & 1) << IO_SHIFT;
248 else
249 val &= ~(1 << IO_SHIFT);
250 writel(val, reg);
251}
Stephen Warren22d57fe2015-02-24 14:08:24 -0700252#endif
Stephen Warren9026dfd2014-03-21 12:28:54 -0600253
Stephen Warren22d57fe2015-02-24 14:08:24 -0700254#ifdef TEGRA_PMX_PINS_HAVE_LOCK
Stephen Warren9026dfd2014-03-21 12:28:54 -0600255static void pinmux_set_lock(enum pmux_pingrp pin, enum pmux_pin_lock lock)
256{
257 u32 *reg = REG(pin);
258 u32 val;
259
260 if (lock == PMUX_PIN_LOCK_DEFAULT)
261 return;
262
263 /* Error check on pin and lock */
264 assert(pmux_pingrp_isvalid(pin));
265 assert(pmux_pin_lock_isvalid(lock));
266
267 val = readl(reg);
268 if (lock == PMUX_PIN_LOCK_ENABLE) {
269 val |= (1 << LOCK_SHIFT);
270 } else {
271 if (val & (1 << LOCK_SHIFT))
272 printf("%s: Cannot clear LOCK bit!\n", __func__);
273 val &= ~(1 << LOCK_SHIFT);
274 }
275 writel(val, reg);
276
277 return;
278}
Stephen Warren22d57fe2015-02-24 14:08:24 -0700279#endif
Stephen Warren9026dfd2014-03-21 12:28:54 -0600280
Stephen Warren22d57fe2015-02-24 14:08:24 -0700281#ifdef TEGRA_PMX_PINS_HAVE_OD
Stephen Warren9026dfd2014-03-21 12:28:54 -0600282static void pinmux_set_od(enum pmux_pingrp pin, enum pmux_pin_od od)
283{
284 u32 *reg = REG(pin);
285 u32 val;
286
287 if (od == PMUX_PIN_OD_DEFAULT)
288 return;
289
290 /* Error check on pin and od */
291 assert(pmux_pingrp_isvalid(pin));
292 assert(pmux_pin_od_isvalid(od));
293
294 val = readl(reg);
295 if (od == PMUX_PIN_OD_ENABLE)
296 val |= (1 << OD_SHIFT);
297 else
298 val &= ~(1 << OD_SHIFT);
299 writel(val, reg);
300
301 return;
302}
Stephen Warren22d57fe2015-02-24 14:08:24 -0700303#endif
Stephen Warren9026dfd2014-03-21 12:28:54 -0600304
Stephen Warren22d57fe2015-02-24 14:08:24 -0700305#ifdef TEGRA_PMX_PINS_HAVE_IO_RESET
Stephen Warren9026dfd2014-03-21 12:28:54 -0600306static void pinmux_set_ioreset(enum pmux_pingrp pin,
307 enum pmux_pin_ioreset ioreset)
308{
309 u32 *reg = REG(pin);
310 u32 val;
311
312 if (ioreset == PMUX_PIN_IO_RESET_DEFAULT)
313 return;
314
315 /* Error check on pin and ioreset */
316 assert(pmux_pingrp_isvalid(pin));
317 assert(pmux_pin_ioreset_isvalid(ioreset));
318
319 val = readl(reg);
320 if (ioreset == PMUX_PIN_IO_RESET_ENABLE)
321 val |= (1 << IO_RESET_SHIFT);
322 else
323 val &= ~(1 << IO_RESET_SHIFT);
324 writel(val, reg);
325
326 return;
327}
Stephen Warren22d57fe2015-02-24 14:08:24 -0700328#endif
Stephen Warren9026dfd2014-03-21 12:28:54 -0600329
Stephen Warren22d57fe2015-02-24 14:08:24 -0700330#ifdef TEGRA_PMX_PINS_HAVE_RCV_SEL
Stephen Warren9026dfd2014-03-21 12:28:54 -0600331static void pinmux_set_rcv_sel(enum pmux_pingrp pin,
332 enum pmux_pin_rcv_sel rcv_sel)
333{
334 u32 *reg = REG(pin);
335 u32 val;
336
337 if (rcv_sel == PMUX_PIN_RCV_SEL_DEFAULT)
338 return;
339
340 /* Error check on pin and rcv_sel */
341 assert(pmux_pingrp_isvalid(pin));
342 assert(pmux_pin_rcv_sel_isvalid(rcv_sel));
343
344 val = readl(reg);
345 if (rcv_sel == PMUX_PIN_RCV_SEL_HIGH)
346 val |= (1 << RCV_SEL_SHIFT);
347 else
348 val &= ~(1 << RCV_SEL_SHIFT);
349 writel(val, reg);
350
351 return;
352}
Stephen Warren22d57fe2015-02-24 14:08:24 -0700353#endif
Stephen Warren9026dfd2014-03-21 12:28:54 -0600354
Stephen Warrend9f8def2015-02-24 14:08:30 -0700355#ifdef TEGRA_PMX_PINS_HAVE_E_IO_HV
356static void pinmux_set_e_io_hv(enum pmux_pingrp pin,
357 enum pmux_pin_e_io_hv e_io_hv)
358{
359 u32 *reg = REG(pin);
360 u32 val;
361
362 if (e_io_hv == PMUX_PIN_E_IO_HV_DEFAULT)
363 return;
364
365 /* Error check on pin and e_io_hv */
366 assert(pmux_pingrp_isvalid(pin));
367 assert(pmux_pin_e_io_hv_isvalid(e_io_hv));
368
369 val = readl(reg);
370 if (e_io_hv == PMUX_PIN_E_IO_HV_HIGH)
371 val |= (1 << E_IO_HV_SHIFT);
372 else
373 val &= ~(1 << E_IO_HV_SHIFT);
374 writel(val, reg);
375
376 return;
377}
378#endif
379
Stephen Warren97f9c682015-02-24 14:08:28 -0700380#ifdef TEGRA_PMX_PINS_HAVE_SCHMT
381static void pinmux_set_schmt(enum pmux_pingrp pin, enum pmux_schmt schmt)
382{
383 u32 *reg = REG(grp);
384 u32 val;
385
386 /* NONE means unspecified/do not change/use POR value */
387 if (schmt == PMUX_SCHMT_NONE)
388 return;
389
390 /* Error check pad */
391 assert(pmux_pingrp_isvalid(pin));
392 assert(pmux_schmt_isvalid(schmt));
393
394 val = readl(reg);
395 if (schmt == PMUX_SCHMT_ENABLE)
396 val |= (1 << SCHMT_SHIFT);
397 else
398 val &= ~(1 << SCHMT_SHIFT);
399 writel(val, reg);
400
401 return;
402}
403#endif
404
405#ifdef TEGRA_PMX_PINS_HAVE_HSM
406static void pinmux_set_hsm(enum pmux_pingrp pin, enum pmux_hsm hsm)
407{
408 u32 *reg = REG(grp);
409 u32 val;
410
411 /* NONE means unspecified/do not change/use POR value */
412 if (hsm == PMUX_HSM_NONE)
413 return;
414
415 /* Error check pad */
416 assert(pmux_pingrp_isvalid(pin));
417 assert(pmux_hsm_isvalid(hsm));
418
419 val = readl(reg);
420 if (hsm == PMUX_HSM_ENABLE)
421 val |= (1 << HSM_SHIFT);
422 else
423 val &= ~(1 << HSM_SHIFT);
424 writel(val, reg);
425
426 return;
427}
428#endif
429
Stephen Warrenf4df6052014-03-21 12:28:56 -0600430static void pinmux_config_pingrp(const struct pmux_pingrp_config *config)
Stephen Warren9026dfd2014-03-21 12:28:54 -0600431{
Stephen Warrenf4df6052014-03-21 12:28:56 -0600432 enum pmux_pingrp pin = config->pingrp;
Stephen Warren9026dfd2014-03-21 12:28:54 -0600433
434 pinmux_set_func(pin, config->func);
435 pinmux_set_pullupdown(pin, config->pull);
436 pinmux_set_tristate(pin, config->tristate);
Stephen Warren22d57fe2015-02-24 14:08:24 -0700437#ifdef TEGRA_PMX_PINS_HAVE_E_INPUT
Stephen Warren9026dfd2014-03-21 12:28:54 -0600438 pinmux_set_io(pin, config->io);
Stephen Warren22d57fe2015-02-24 14:08:24 -0700439#endif
440#ifdef TEGRA_PMX_PINS_HAVE_LOCK
Stephen Warren9026dfd2014-03-21 12:28:54 -0600441 pinmux_set_lock(pin, config->lock);
Stephen Warren22d57fe2015-02-24 14:08:24 -0700442#endif
443#ifdef TEGRA_PMX_PINS_HAVE_OD
Stephen Warren9026dfd2014-03-21 12:28:54 -0600444 pinmux_set_od(pin, config->od);
Stephen Warren22d57fe2015-02-24 14:08:24 -0700445#endif
446#ifdef TEGRA_PMX_PINS_HAVE_IO_RESET
Stephen Warren9026dfd2014-03-21 12:28:54 -0600447 pinmux_set_ioreset(pin, config->ioreset);
Stephen Warren9026dfd2014-03-21 12:28:54 -0600448#endif
Stephen Warren22d57fe2015-02-24 14:08:24 -0700449#ifdef TEGRA_PMX_PINS_HAVE_RCV_SEL
450 pinmux_set_rcv_sel(pin, config->rcv_sel);
Stephen Warren9026dfd2014-03-21 12:28:54 -0600451#endif
Stephen Warrend9f8def2015-02-24 14:08:30 -0700452#ifdef TEGRA_PMX_PINS_HAVE_E_IO_HV
453 pinmux_set_e_io_hv(pin, config->e_io_hv);
454#endif
Stephen Warren97f9c682015-02-24 14:08:28 -0700455#ifdef TEGRA_PMX_PINS_HAVE_SCHMT
456 pinmux_set_schmt(pin, config->schmt);
457#endif
458#ifdef TEGRA_PMX_PINS_HAVE_HSM
459 pinmux_set_hsm(pin, config->hsm);
460#endif
Stephen Warren9026dfd2014-03-21 12:28:54 -0600461}
462
Stephen Warrenf4df6052014-03-21 12:28:56 -0600463void pinmux_config_pingrp_table(const struct pmux_pingrp_config *config,
464 int len)
Stephen Warren9026dfd2014-03-21 12:28:54 -0600465{
466 int i;
467
468 for (i = 0; i < len; i++)
Stephen Warrenf4df6052014-03-21 12:28:56 -0600469 pinmux_config_pingrp(&config[i]);
Stephen Warren9026dfd2014-03-21 12:28:54 -0600470}
471
Stephen Warren22d57fe2015-02-24 14:08:24 -0700472#ifdef TEGRA_PMX_SOC_HAS_DRVGRPS
Stephen Warren9026dfd2014-03-21 12:28:54 -0600473
Stephen Warrenf4df6052014-03-21 12:28:56 -0600474#define pmux_drvgrp_isvalid(pd) (((pd) >= 0) && ((pd) < PMUX_DRVGRP_COUNT))
Stephen Warren9026dfd2014-03-21 12:28:54 -0600475
Stephen Warrenf4df6052014-03-21 12:28:56 -0600476#define pmux_slw_isvalid(slw) \
477 (((slw) >= PMUX_SLWF_MIN) && ((slw) <= PMUX_SLWF_MAX))
Stephen Warren9026dfd2014-03-21 12:28:54 -0600478
Stephen Warrenf4df6052014-03-21 12:28:56 -0600479#define pmux_drv_isvalid(drv) \
480 (((drv) >= PMUX_DRVUP_MIN) && ((drv) <= PMUX_DRVUP_MAX))
Stephen Warren9026dfd2014-03-21 12:28:54 -0600481
Stephen Warren3e9fb7b2015-02-24 14:08:25 -0700482#ifdef TEGRA_PMX_GRPS_HAVE_HSM
Stephen Warren9026dfd2014-03-21 12:28:54 -0600483#define HSM_SHIFT 2
Stephen Warren3e9fb7b2015-02-24 14:08:25 -0700484#endif
485#ifdef TEGRA_PMX_GRPS_HAVE_SCHMT
Stephen Warren9026dfd2014-03-21 12:28:54 -0600486#define SCHMT_SHIFT 3
Stephen Warren3e9fb7b2015-02-24 14:08:25 -0700487#endif
488#ifdef TEGRA_PMX_GRPS_HAVE_LPMD
Stephen Warren9026dfd2014-03-21 12:28:54 -0600489#define LPMD_SHIFT 4
490#define LPMD_MASK (3 << LPMD_SHIFT)
Stephen Warren3e9fb7b2015-02-24 14:08:25 -0700491#endif
Stephen Warren21788e02015-02-24 14:08:23 -0700492/*
493 * Note that the following DRV* and SLW* defines are accurate for many drive
494 * groups on many SoCs. We really need a per-group data structure to solve
495 * this, since the fields are in different positions/sizes in different
496 * registers (for different groups).
497 *
498 * On Tegra30/114/124, the DRV*_SHIFT values vary.
499 * On Tegra30, the SLW*_SHIFT values vary.
500 * On Tegra30/114/124/210, the DRV*_MASK values vary, although the values
501 * below are wide enough to cover the widest fields, and hopefully don't
502 * interfere with any other fields.
503 * On Tegra30, the SLW*_MASK values vary, but we can't use a value that's
504 * wide enough to cover all cases, since that would cause the field to
505 * overlap with other fields in the narrower cases.
506 */
Stephen Warren9026dfd2014-03-21 12:28:54 -0600507#define DRVDN_SHIFT 12
508#define DRVDN_MASK (0x7F << DRVDN_SHIFT)
509#define DRVUP_SHIFT 20
510#define DRVUP_MASK (0x7F << DRVUP_SHIFT)
511#define SLWR_SHIFT 28
512#define SLWR_MASK (3 << SLWR_SHIFT)
513#define SLWF_SHIFT 30
514#define SLWF_MASK (3 << SLWF_SHIFT)
515
Stephen Warrenf4df6052014-03-21 12:28:56 -0600516static void pinmux_set_drvup_slwf(enum pmux_drvgrp grp, int slwf)
Stephen Warren9026dfd2014-03-21 12:28:54 -0600517{
518 u32 *reg = DRV_REG(grp);
519 u32 val;
520
521 /* NONE means unspecified/do not change/use POR value */
Stephen Warrenf4df6052014-03-21 12:28:56 -0600522 if (slwf == PMUX_SLWF_NONE)
Stephen Warren9026dfd2014-03-21 12:28:54 -0600523 return;
524
525 /* Error check on pad and slwf */
Stephen Warrenf4df6052014-03-21 12:28:56 -0600526 assert(pmux_drvgrp_isvalid(grp));
527 assert(pmux_slw_isvalid(slwf));
Stephen Warren9026dfd2014-03-21 12:28:54 -0600528
529 val = readl(reg);
530 val &= ~SLWF_MASK;
531 val |= (slwf << SLWF_SHIFT);
532 writel(val, reg);
533
534 return;
535}
536
Stephen Warrenf4df6052014-03-21 12:28:56 -0600537static void pinmux_set_drvdn_slwr(enum pmux_drvgrp grp, int slwr)
Stephen Warren9026dfd2014-03-21 12:28:54 -0600538{
539 u32 *reg = DRV_REG(grp);
540 u32 val;
541
542 /* NONE means unspecified/do not change/use POR value */
Stephen Warrenf4df6052014-03-21 12:28:56 -0600543 if (slwr == PMUX_SLWR_NONE)
Stephen Warren9026dfd2014-03-21 12:28:54 -0600544 return;
545
546 /* Error check on pad and slwr */
Stephen Warrenf4df6052014-03-21 12:28:56 -0600547 assert(pmux_drvgrp_isvalid(grp));
548 assert(pmux_slw_isvalid(slwr));
Stephen Warren9026dfd2014-03-21 12:28:54 -0600549
550 val = readl(reg);
551 val &= ~SLWR_MASK;
552 val |= (slwr << SLWR_SHIFT);
553 writel(val, reg);
554
555 return;
556}
557
Stephen Warrenf4df6052014-03-21 12:28:56 -0600558static void pinmux_set_drvup(enum pmux_drvgrp grp, int drvup)
Stephen Warren9026dfd2014-03-21 12:28:54 -0600559{
560 u32 *reg = DRV_REG(grp);
561 u32 val;
562
563 /* NONE means unspecified/do not change/use POR value */
Stephen Warrenf4df6052014-03-21 12:28:56 -0600564 if (drvup == PMUX_DRVUP_NONE)
Stephen Warren9026dfd2014-03-21 12:28:54 -0600565 return;
566
567 /* Error check on pad and drvup */
Stephen Warrenf4df6052014-03-21 12:28:56 -0600568 assert(pmux_drvgrp_isvalid(grp));
569 assert(pmux_drv_isvalid(drvup));
Stephen Warren9026dfd2014-03-21 12:28:54 -0600570
571 val = readl(reg);
572 val &= ~DRVUP_MASK;
573 val |= (drvup << DRVUP_SHIFT);
574 writel(val, reg);
575
576 return;
577}
578
Stephen Warrenf4df6052014-03-21 12:28:56 -0600579static void pinmux_set_drvdn(enum pmux_drvgrp grp, int drvdn)
Stephen Warren9026dfd2014-03-21 12:28:54 -0600580{
581 u32 *reg = DRV_REG(grp);
582 u32 val;
583
584 /* NONE means unspecified/do not change/use POR value */
Stephen Warrenf4df6052014-03-21 12:28:56 -0600585 if (drvdn == PMUX_DRVDN_NONE)
Stephen Warren9026dfd2014-03-21 12:28:54 -0600586 return;
587
588 /* Error check on pad and drvdn */
Stephen Warrenf4df6052014-03-21 12:28:56 -0600589 assert(pmux_drvgrp_isvalid(grp));
590 assert(pmux_drv_isvalid(drvdn));
Stephen Warren9026dfd2014-03-21 12:28:54 -0600591
592 val = readl(reg);
593 val &= ~DRVDN_MASK;
594 val |= (drvdn << DRVDN_SHIFT);
595 writel(val, reg);
596
597 return;
598}
599
Stephen Warren3e9fb7b2015-02-24 14:08:25 -0700600#ifdef TEGRA_PMX_GRPS_HAVE_LPMD
Stephen Warrenf4df6052014-03-21 12:28:56 -0600601static void pinmux_set_lpmd(enum pmux_drvgrp grp, enum pmux_lpmd lpmd)
Stephen Warren9026dfd2014-03-21 12:28:54 -0600602{
603 u32 *reg = DRV_REG(grp);
604 u32 val;
605
606 /* NONE means unspecified/do not change/use POR value */
Stephen Warrenf4df6052014-03-21 12:28:56 -0600607 if (lpmd == PMUX_LPMD_NONE)
Stephen Warren9026dfd2014-03-21 12:28:54 -0600608 return;
609
610 /* Error check pad and lpmd value */
Stephen Warrenf4df6052014-03-21 12:28:56 -0600611 assert(pmux_drvgrp_isvalid(grp));
612 assert(pmux_lpmd_isvalid(lpmd));
Stephen Warren9026dfd2014-03-21 12:28:54 -0600613
614 val = readl(reg);
615 val &= ~LPMD_MASK;
616 val |= (lpmd << LPMD_SHIFT);
617 writel(val, reg);
618
619 return;
620}
Stephen Warren3e9fb7b2015-02-24 14:08:25 -0700621#endif
Stephen Warren9026dfd2014-03-21 12:28:54 -0600622
Stephen Warren3e9fb7b2015-02-24 14:08:25 -0700623#ifdef TEGRA_PMX_GRPS_HAVE_SCHMT
Stephen Warrenf4df6052014-03-21 12:28:56 -0600624static void pinmux_set_schmt(enum pmux_drvgrp grp, enum pmux_schmt schmt)
Stephen Warren9026dfd2014-03-21 12:28:54 -0600625{
626 u32 *reg = DRV_REG(grp);
627 u32 val;
628
629 /* NONE means unspecified/do not change/use POR value */
Stephen Warrenf4df6052014-03-21 12:28:56 -0600630 if (schmt == PMUX_SCHMT_NONE)
Stephen Warren9026dfd2014-03-21 12:28:54 -0600631 return;
632
633 /* Error check pad */
Stephen Warrenf4df6052014-03-21 12:28:56 -0600634 assert(pmux_drvgrp_isvalid(grp));
635 assert(pmux_schmt_isvalid(schmt));
Stephen Warren9026dfd2014-03-21 12:28:54 -0600636
637 val = readl(reg);
Stephen Warrenf4df6052014-03-21 12:28:56 -0600638 if (schmt == PMUX_SCHMT_ENABLE)
Stephen Warren9026dfd2014-03-21 12:28:54 -0600639 val |= (1 << SCHMT_SHIFT);
640 else
641 val &= ~(1 << SCHMT_SHIFT);
642 writel(val, reg);
643
644 return;
645}
Stephen Warren3e9fb7b2015-02-24 14:08:25 -0700646#endif
Stephen Warren9026dfd2014-03-21 12:28:54 -0600647
Stephen Warren3e9fb7b2015-02-24 14:08:25 -0700648#ifdef TEGRA_PMX_GRPS_HAVE_HSM
Stephen Warrenf4df6052014-03-21 12:28:56 -0600649static void pinmux_set_hsm(enum pmux_drvgrp grp, enum pmux_hsm hsm)
Stephen Warren9026dfd2014-03-21 12:28:54 -0600650{
651 u32 *reg = DRV_REG(grp);
652 u32 val;
653
654 /* NONE means unspecified/do not change/use POR value */
Stephen Warrenf4df6052014-03-21 12:28:56 -0600655 if (hsm == PMUX_HSM_NONE)
Stephen Warren9026dfd2014-03-21 12:28:54 -0600656 return;
657
658 /* Error check pad */
Stephen Warrenf4df6052014-03-21 12:28:56 -0600659 assert(pmux_drvgrp_isvalid(grp));
660 assert(pmux_hsm_isvalid(hsm));
Stephen Warren9026dfd2014-03-21 12:28:54 -0600661
662 val = readl(reg);
Stephen Warrenf4df6052014-03-21 12:28:56 -0600663 if (hsm == PMUX_HSM_ENABLE)
Stephen Warren9026dfd2014-03-21 12:28:54 -0600664 val |= (1 << HSM_SHIFT);
665 else
666 val &= ~(1 << HSM_SHIFT);
667 writel(val, reg);
668
669 return;
670}
Stephen Warren3e9fb7b2015-02-24 14:08:25 -0700671#endif
Stephen Warren9026dfd2014-03-21 12:28:54 -0600672
Stephen Warrenf4df6052014-03-21 12:28:56 -0600673static void pinmux_config_drvgrp(const struct pmux_drvgrp_config *config)
Stephen Warren9026dfd2014-03-21 12:28:54 -0600674{
Stephen Warrenf4df6052014-03-21 12:28:56 -0600675 enum pmux_drvgrp grp = config->drvgrp;
Stephen Warren9026dfd2014-03-21 12:28:54 -0600676
Stephen Warrenf4df6052014-03-21 12:28:56 -0600677 pinmux_set_drvup_slwf(grp, config->slwf);
678 pinmux_set_drvdn_slwr(grp, config->slwr);
679 pinmux_set_drvup(grp, config->drvup);
680 pinmux_set_drvdn(grp, config->drvdn);
Stephen Warren3e9fb7b2015-02-24 14:08:25 -0700681#ifdef TEGRA_PMX_GRPS_HAVE_LPMD
Stephen Warrenf4df6052014-03-21 12:28:56 -0600682 pinmux_set_lpmd(grp, config->lpmd);
Stephen Warren3e9fb7b2015-02-24 14:08:25 -0700683#endif
684#ifdef TEGRA_PMX_GRPS_HAVE_SCHMT
Stephen Warrenf4df6052014-03-21 12:28:56 -0600685 pinmux_set_schmt(grp, config->schmt);
Stephen Warren3e9fb7b2015-02-24 14:08:25 -0700686#endif
687#ifdef TEGRA_PMX_GRPS_HAVE_HSM
Stephen Warrenf4df6052014-03-21 12:28:56 -0600688 pinmux_set_hsm(grp, config->hsm);
Stephen Warren3e9fb7b2015-02-24 14:08:25 -0700689#endif
Stephen Warren9026dfd2014-03-21 12:28:54 -0600690}
691
Stephen Warrenf4df6052014-03-21 12:28:56 -0600692void pinmux_config_drvgrp_table(const struct pmux_drvgrp_config *config,
693 int len)
Stephen Warren9026dfd2014-03-21 12:28:54 -0600694{
695 int i;
696
697 for (i = 0; i < len; i++)
Stephen Warrenf4df6052014-03-21 12:28:56 -0600698 pinmux_config_drvgrp(&config[i]);
Stephen Warren9026dfd2014-03-21 12:28:54 -0600699}
Stephen Warren1a1f10f2015-03-25 12:04:35 -0600700#endif /* TEGRA_PMX_SOC_HAS_DRVGRPS */
Stephen Warren8ec10882015-03-25 12:04:36 -0600701
702#ifdef TEGRA_PMX_SOC_HAS_MIPI_PAD_CTRL_GRPS
703
704#define pmux_mipipadctrlgrp_isvalid(pd) (((pd) >= 0) && ((pd) < PMUX_MIPIPADCTRLGRP_COUNT))
705
706static void pinmux_mipipadctrl_set_func(enum pmux_mipipadctrlgrp grp,
707 enum pmux_func func)
708{
709 u32 *reg = MIPIPADCTRL_REG(grp);
710 int i, mux = -1;
711 u32 val;
712
713 if (func == PMUX_FUNC_DEFAULT)
714 return;
715
716 /* Error check grp and func */
717 assert(pmux_mipipadctrlgrp_isvalid(grp));
718 assert(pmux_func_isvalid(func));
719
720 if (func >= PMUX_FUNC_RSVD1) {
721 mux = (func - PMUX_FUNC_RSVD1) & 1;
722 } else {
723 /* Search for the appropriate function */
724 for (i = 0; i < 2; i++) {
725 if (tegra_soc_mipipadctrl_groups[grp].funcs[i]
726 == func) {
727 mux = i;
728 break;
729 }
730 }
731 }
732 assert(mux != -1);
733
734 val = readl(reg);
735 val &= ~(1 << 1);
736 val |= (mux << 1);
737 writel(val, reg);
738}
739
740static void pinmux_config_mipipadctrlgrp(const struct pmux_mipipadctrlgrp_config *config)
741{
742 enum pmux_mipipadctrlgrp grp = config->grp;
743
744 pinmux_mipipadctrl_set_func(grp, config->func);
745}
746
747void pinmux_config_mipipadctrlgrp_table(
748 const struct pmux_mipipadctrlgrp_config *config, int len)
749{
750 int i;
751
752 for (i = 0; i < len; i++)
753 pinmux_config_mipipadctrlgrp(&config[i]);
754}
755#endif /* TEGRA_PMX_SOC_HAS_MIPI_PAD_CTRL_GRPS */