Linux 5.7.7
[linux/fpc-iii.git] / arch / arm / mach-imx / iomux-v1.c
bloba4bec3b9b2b39469247bfa5204f5a03006c725bd
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
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
9 */
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>
20 #include "hardware.h"
21 #include "iomux-v1.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);
41 reg &= ~mask;
42 reg |= value;
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)
121 return -EINVAL;
123 /* Pullup enable */
124 imx_iomuxv1_set_puen(port, pin, gpio_mode & GPIO_PUEN);
126 /* Data direction */
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);
132 /* use as gpio? */
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);
141 return 0;
144 static int imx_iomuxv1_setup_multiple(const int *list, unsigned count)
146 size_t i;
147 int ret = 0;
149 for (i = 0; i < count; ++i) {
150 ret = mxc_gpio_mode(list[i]);
152 if (ret)
153 return ret;
156 return ret;
159 int mxc_gpio_setup_multiple_pins(const int *pin_list, unsigned count,
160 const char *label)
162 int ret;
164 ret = imx_iomuxv1_setup_multiple(pin_list, count);
165 return ret;
168 int __init imx_iomuxv1_init(void __iomem *base, int numports)
170 imx_iomuxv1_baseaddr = base;
171 imx_iomuxv1_numports = numports;
173 return 0;