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