1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright 2004-2006 Freescale Semiconductor, Inc. All Rights Reserved.
4  * Copyright (C) 2008 by Sascha Hauer <kernel@pengutronix.de>
5  * Copyright (C) 2009 by Jan Weitzel Phytec Messtechnik GmbH,
6  *                       <armlinux@phytec.de>
7  */
8 #include <linux/errno.h>
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/string.h>
13 #include <linux/gpio.h>
14 
15 #include <asm/mach/map.h>
16 
17 #include "hardware.h"
18 #include "iomux-v3.h"
19 
20 static void __iomem *base;
21 
22 /*
23  * configures a single pad in the iomuxer
24  */
mxc_iomux_v3_setup_pad(iomux_v3_cfg_t pad)25 int mxc_iomux_v3_setup_pad(iomux_v3_cfg_t pad)
26 {
27 	u32 mux_ctrl_ofs = (pad & MUX_CTRL_OFS_MASK) >> MUX_CTRL_OFS_SHIFT;
28 	u32 mux_mode = (pad & MUX_MODE_MASK) >> MUX_MODE_SHIFT;
29 	u32 sel_input_ofs = (pad & MUX_SEL_INPUT_OFS_MASK) >> MUX_SEL_INPUT_OFS_SHIFT;
30 	u32 sel_input = (pad & MUX_SEL_INPUT_MASK) >> MUX_SEL_INPUT_SHIFT;
31 	u32 pad_ctrl_ofs = (pad & MUX_PAD_CTRL_OFS_MASK) >> MUX_PAD_CTRL_OFS_SHIFT;
32 	u32 pad_ctrl = (pad & MUX_PAD_CTRL_MASK) >> MUX_PAD_CTRL_SHIFT;
33 
34 	if (mux_ctrl_ofs)
35 		imx_writel(mux_mode, base + mux_ctrl_ofs);
36 
37 	if (sel_input_ofs)
38 		imx_writel(sel_input, base + sel_input_ofs);
39 
40 	if (!(pad_ctrl & NO_PAD_CTRL) && pad_ctrl_ofs)
41 		imx_writel(pad_ctrl, base + pad_ctrl_ofs);
42 
43 	return 0;
44 }
45 
mxc_iomux_v3_setup_multiple_pads(const iomux_v3_cfg_t * pad_list,unsigned count)46 int mxc_iomux_v3_setup_multiple_pads(const iomux_v3_cfg_t *pad_list,
47 		unsigned count)
48 {
49 	const iomux_v3_cfg_t *p = pad_list;
50 	int i;
51 	int ret;
52 
53 	for (i = 0; i < count; i++) {
54 		ret = mxc_iomux_v3_setup_pad(*p);
55 		if (ret)
56 			return ret;
57 		p++;
58 	}
59 	return 0;
60 }
61 
mxc_iomux_v3_init(void __iomem * iomux_v3_base)62 void mxc_iomux_v3_init(void __iomem *iomux_v3_base)
63 {
64 	base = iomux_v3_base;
65 }
66