1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright 2004-2006,2010 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
9 #include <common.h>
10 #include <linux/errno.h>
11 #include <asm/io.h>
12 #include <asm/arch/clock.h>
13 #include <asm/arch/iomux.h>
14 #include <asm/arch/imx-regs.h>
15
16 #if defined(CONFIG_MX23)
17 #define DRIVE_OFFSET 0x200
18 #define PULL_OFFSET 0x400
19 #elif defined(CONFIG_MX28)
20 #define DRIVE_OFFSET 0x300
21 #define PULL_OFFSET 0x600
22 #else
23 #error "Please select CONFIG_MX23 or CONFIG_MX28"
24 #endif
25
26 /*
27 * configures a single pad in the iomuxer
28 */
mxs_iomux_setup_pad(iomux_cfg_t pad)29 int mxs_iomux_setup_pad(iomux_cfg_t pad)
30 {
31 u32 reg, ofs, bp, bm;
32 void *iomux_base = (void *)MXS_PINCTRL_BASE;
33 struct mxs_register_32 *mxs_reg;
34
35 /* muxsel */
36 ofs = 0x100;
37 ofs += PAD_BANK(pad) * 0x20 + PAD_PIN(pad) / 16 * 0x10;
38 bp = PAD_PIN(pad) % 16 * 2;
39 bm = 0x3 << bp;
40 reg = readl(iomux_base + ofs);
41 reg &= ~bm;
42 reg |= PAD_MUXSEL(pad) << bp;
43 writel(reg, iomux_base + ofs);
44
45 /* drive */
46 ofs = DRIVE_OFFSET;
47 ofs += PAD_BANK(pad) * 0x40 + PAD_PIN(pad) / 8 * 0x10;
48 /* mA */
49 if (PAD_MA_VALID(pad)) {
50 bp = PAD_PIN(pad) % 8 * 4;
51 bm = 0x3 << bp;
52 reg = readl(iomux_base + ofs);
53 reg &= ~bm;
54 reg |= PAD_MA(pad) << bp;
55 writel(reg, iomux_base + ofs);
56 }
57 /* vol */
58 if (PAD_VOL_VALID(pad)) {
59 bp = PAD_PIN(pad) % 8 * 4 + 2;
60 mxs_reg = (struct mxs_register_32 *)(iomux_base + ofs);
61 if (PAD_VOL(pad))
62 writel(1 << bp, &mxs_reg->reg_set);
63 else
64 writel(1 << bp, &mxs_reg->reg_clr);
65 }
66
67 /* pull */
68 if (PAD_PULL_VALID(pad)) {
69 ofs = PULL_OFFSET;
70 ofs += PAD_BANK(pad) * 0x10;
71 bp = PAD_PIN(pad);
72 mxs_reg = (struct mxs_register_32 *)(iomux_base + ofs);
73 if (PAD_PULL(pad))
74 writel(1 << bp, &mxs_reg->reg_set);
75 else
76 writel(1 << bp, &mxs_reg->reg_clr);
77 }
78
79 return 0;
80 }
81
mxs_iomux_setup_multiple_pads(const iomux_cfg_t * pad_list,unsigned count)82 int mxs_iomux_setup_multiple_pads(const iomux_cfg_t *pad_list, unsigned count)
83 {
84 const iomux_cfg_t *p = pad_list;
85 int i;
86 int ret;
87
88 for (i = 0; i < count; i++) {
89 ret = mxs_iomux_setup_pad(*p);
90 if (ret)
91 return ret;
92 p++;
93 }
94
95 return 0;
96 }
97