1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * arch/arm/plat-mxc/iomux-v1.c
5 * Copyright (C) 2004 Sascha Hauer, Synertronixx GmbH
6 * Copyright (C) 2009 Uwe Kleine-Koenig, Pengutronix
8 * Common code for i.MX1, i.MX21 and i.MX27
11 #include <linux/errno.h>
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/string.h>
16 #include <linux/gpio.h>
18 #include <asm/mach/map.h>
23 static void __iomem
*imx_iomuxv1_baseaddr
;
24 static unsigned imx_iomuxv1_numports
;
26 static inline unsigned long imx_iomuxv1_readl(unsigned offset
)
28 return imx_readl(imx_iomuxv1_baseaddr
+ offset
);
31 static inline void imx_iomuxv1_writel(unsigned long val
, unsigned offset
)
33 imx_writel(val
, imx_iomuxv1_baseaddr
+ offset
);
36 static inline void imx_iomuxv1_rmwl(unsigned offset
,
37 unsigned long mask
, unsigned long value
)
39 unsigned long reg
= imx_iomuxv1_readl(offset
);
44 imx_iomuxv1_writel(reg
, offset
);
47 static inline void imx_iomuxv1_set_puen(
48 unsigned int port
, unsigned int pin
, int on
)
50 unsigned long mask
= 1 << pin
;
52 imx_iomuxv1_rmwl(MXC_PUEN(port
), mask
, on
? mask
: 0);
55 static inline void imx_iomuxv1_set_ddir(
56 unsigned int port
, unsigned int pin
, int out
)
58 unsigned long mask
= 1 << pin
;
60 imx_iomuxv1_rmwl(MXC_DDIR(port
), mask
, out
? mask
: 0);
63 static inline void imx_iomuxv1_set_gpr(
64 unsigned int port
, unsigned int pin
, int af
)
66 unsigned long mask
= 1 << pin
;
68 imx_iomuxv1_rmwl(MXC_GPR(port
), mask
, af
? mask
: 0);
71 static inline void imx_iomuxv1_set_gius(
72 unsigned int port
, unsigned int pin
, int inuse
)
74 unsigned long mask
= 1 << pin
;
76 imx_iomuxv1_rmwl(MXC_GIUS(port
), mask
, inuse
? mask
: 0);
79 static inline void imx_iomuxv1_set_ocr(
80 unsigned int port
, unsigned int pin
, unsigned int ocr
)
82 unsigned long shift
= (pin
& 0xf) << 1;
83 unsigned long mask
= 3 << shift
;
84 unsigned long value
= ocr
<< shift
;
85 unsigned long offset
= pin
< 16 ? MXC_OCR1(port
) : MXC_OCR2(port
);
87 imx_iomuxv1_rmwl(offset
, mask
, value
);
90 static inline void imx_iomuxv1_set_iconfa(
91 unsigned int port
, unsigned int pin
, unsigned int aout
)
93 unsigned long shift
= (pin
& 0xf) << 1;
94 unsigned long mask
= 3 << shift
;
95 unsigned long value
= aout
<< shift
;
96 unsigned long offset
= pin
< 16 ? MXC_ICONFA1(port
) : MXC_ICONFA2(port
);
98 imx_iomuxv1_rmwl(offset
, mask
, value
);
101 static inline void imx_iomuxv1_set_iconfb(
102 unsigned int port
, unsigned int pin
, unsigned int bout
)
104 unsigned long shift
= (pin
& 0xf) << 1;
105 unsigned long mask
= 3 << shift
;
106 unsigned long value
= bout
<< shift
;
107 unsigned long offset
= pin
< 16 ? MXC_ICONFB1(port
) : MXC_ICONFB2(port
);
109 imx_iomuxv1_rmwl(offset
, mask
, value
);
112 int mxc_gpio_mode(int gpio_mode
)
114 unsigned int pin
= gpio_mode
& GPIO_PIN_MASK
;
115 unsigned int port
= (gpio_mode
& GPIO_PORT_MASK
) >> GPIO_PORT_SHIFT
;
116 unsigned int ocr
= (gpio_mode
& GPIO_OCR_MASK
) >> GPIO_OCR_SHIFT
;
117 unsigned int aout
= (gpio_mode
>> GPIO_AOUT_SHIFT
) & 3;
118 unsigned int bout
= (gpio_mode
>> GPIO_BOUT_SHIFT
) & 3;
120 if (port
>= imx_iomuxv1_numports
)
124 imx_iomuxv1_set_puen(port
, pin
, gpio_mode
& GPIO_PUEN
);
127 imx_iomuxv1_set_ddir(port
, pin
, gpio_mode
& GPIO_OUT
);
129 /* Primary / alternate function */
130 imx_iomuxv1_set_gpr(port
, pin
, gpio_mode
& GPIO_AF
);
133 imx_iomuxv1_set_gius(port
, pin
, !(gpio_mode
& (GPIO_PF
| GPIO_AF
)));
135 imx_iomuxv1_set_ocr(port
, pin
, ocr
);
137 imx_iomuxv1_set_iconfa(port
, pin
, aout
);
139 imx_iomuxv1_set_iconfb(port
, pin
, bout
);
144 static int imx_iomuxv1_setup_multiple(const int *list
, unsigned count
)
149 for (i
= 0; i
< count
; ++i
) {
150 ret
= mxc_gpio_mode(list
[i
]);
159 int mxc_gpio_setup_multiple_pins(const int *pin_list
, unsigned count
,
164 ret
= imx_iomuxv1_setup_multiple(pin_list
, count
);
168 int __init
imx_iomuxv1_init(void __iomem
*base
, int numports
)
170 imx_iomuxv1_baseaddr
= base
;
171 imx_iomuxv1_numports
= numports
;