1 /*
2  * K2G: Pinmux configuration
3  *
4  * (C) Copyright 2015
5  *     Texas Instruments Incorporated, <www.ti.com>
6  *
7  * SPDX-License-Identifier:     GPL-2.0+
8  */
9 
10 #ifndef __ASM_ARCH_MUX_K2G_H
11 #define __ASM_ARCH_MUX_K2G_H
12 
13 #include <common.h>
14 #include <asm/io.h>
15 
16 #define K2G_PADCFG_REG	(KS2_DEVICE_STATE_CTRL_BASE + 0x1000)
17 
18 /*
19  * 20:19 - buffer class RW fixed
20  * 18    - rxactive (Input enabled for the pad ) 0 - Di; 1 - En;
21  * 17    - pulltypesel (0 - PULLDOWN; 1 - PULLUP);
22  * 16    - pulluden (0 - PULLUP/DOWN EN; 1 - DI);
23  * 3:0   - muxmode (available modes 0:5)
24  */
25 
26 #define PIN_IEN	(1 << 18) /* pin input enabled */
27 #define PIN_PDIS	(1 << 16) /* pull up/down disabled */
28 #define PIN_PTU	(1 << 17) /* pull up */
29 #define PIN_PTD	(0 << 17) /* pull down */
30 
31 #define MODE(m)	((m) & 0x7)
32 #define MAX_PIN_N	260
33 
34 #define MUX_CFG(value, index)  \
35 	__raw_writel(\
36 		     (value) | \
37 		     (__raw_readl(K2G_PADCFG_REG + (index << 2)) & \
38 		      (0x3 << 19)),\
39 		     (K2G_PADCFG_REG + (index << 2))\
40 		    );
41 
42 struct pin_cfg {
43 	int	reg_inx;
44 	u32	val;
45 };
46 
47 static inline void configure_pin_mux(struct pin_cfg *pin_mux)
48 {
49 	if (!pin_mux)
50 		return;
51 
52 	while ((pin_mux->reg_inx >= 0) && (pin_mux->reg_inx < MAX_PIN_N)) {
53 		MUX_CFG(pin_mux->val, pin_mux->reg_inx);
54 		pin_mux++;
55 	}
56 }
57 
58 #endif /* __ASM_ARCH_MUX_K2G_H */
59