blob: 381264b8a18d24a783f70989aed6e73b4f3ccaea [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marek Vasutb473ec52011-11-08 23:18:11 +00002/*
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>
Marek Vasutb473ec52011-11-08 23:18:11 +00007 */
8
Tom Riniabb9a042024-05-18 20:20:43 -06009#include <common.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090010#include <linux/errno.h>
Marek Vasutb473ec52011-11-08 23:18:11 +000011#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 */
29int mxs_iomux_setup_pad(iomux_cfg_t pad)
30{
31 u32 reg, ofs, bp, bm;
32 void *iomux_base = (void *)MXS_PINCTRL_BASE;
Otavio Salvador5309b002012-08-05 09:05:30 +000033 struct mxs_register_32 *mxs_reg;
Marek Vasutb473ec52011-11-08 23:18:11 +000034
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;
Otavio Salvador5309b002012-08-05 09:05:30 +000060 mxs_reg = (struct mxs_register_32 *)(iomux_base + ofs);
Marek Vasutb473ec52011-11-08 23:18:11 +000061 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);
Otavio Salvador5309b002012-08-05 09:05:30 +000072 mxs_reg = (struct mxs_register_32 *)(iomux_base + ofs);
Marek Vasutb473ec52011-11-08 23:18:11 +000073 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
82int 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}