summaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl/imx-iomux-v2.c
blob: 0c985a69d33529d6060887cbae21beecde74e54f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
 *  (C) 2007, Sascha Hauer <sha@pengutronix.de>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 *
 */

#include <common.h>
#include <io.h>
#include <init.h>
#include <linux/err.h>
#include <mach/iomux-mx31.h>

/*
 * IOMUX register (base) addresses
 */
#define IOMUXINT_OBS1	0x000
#define IOMUXINT_OBS2	0x004
#define IOMUXGPR	0x008
#define IOMUXSW_MUX_CTL	0x00C
#define IOMUXSW_PAD_CTL	0x154

#define IOMUX_REG_MASK (IOMUX_PADNUM_MASK & ~0x3)

static void __iomem *base;

/*
 * set the mode for a IOMUX pin.
 */
int imx_iomux_mode(unsigned int pin_mode)
{
	u32 field, l, mode, ret = 0;
	void __iomem *reg;

	if (!base)
		return -EINVAL;

	reg = base + IOMUXSW_MUX_CTL + (pin_mode & IOMUX_REG_MASK);
	field = pin_mode & 0x3;
	mode = (pin_mode & IOMUX_MODE_MASK) >> IOMUX_MODE_SHIFT;

	pr_debug("%s: reg offset = 0x%x field = %d mode = 0x%02x\n",
			__func__, (pin_mode & IOMUX_REG_MASK), field, mode);

	l = readl(reg);
	l &= ~(0xff << (field * 8));
	l |= mode << (field * 8);
	writel(l, reg);

	return ret;
}
EXPORT_SYMBOL(imx_iomux_mode);

/*
 * This function configures the pad value for a IOMUX pin.
 */
void imx_iomux_set_pad(enum iomux_pins pin, u32 config)
{
	u32 field, l;
	void __iomem *reg;

	if (!base)
		return;

	pin &= IOMUX_PADNUM_MASK;
	reg = base + IOMUXSW_PAD_CTL + (pin + 2) / 3 * 4;
	field = (pin + 2) % 3;

	pr_debug("%s: reg offset = 0x%x, field = %d\n",
			__func__, (pin + 2) / 3, field);

	l = readl(reg);
	l &= ~(0x1ff << (field * 10));
	l |= config << (field * 10);
	writel(l, reg);
}
EXPORT_SYMBOL(imx_iomux_set_pad);

/*
 * This function enables/disables the general purpose function for a particular
 * signal.
 */
void imx_iomux_set_gpr(enum iomux_gp_func gp, bool en)
{
	u32 l;

	if (!base)
		return;

	l = readl(base + IOMUXGPR);
	if (en)
		l |= gp;
	else
		l &= ~gp;

	writel(l, base + IOMUXGPR);
}
EXPORT_SYMBOL(imx_iomux_set_gpr);

int imx_iomux_setup_multiple_pins(const unsigned int *pin_list, unsigned count)
{
	int i;

	for (i = 0; i < count; i++)
		imx_iomux_mode(pin_list[i]);

	return 0;
}

static int imx_iomux_probe(struct device_d *dev)
{
	struct resource *iores;
	iores = dev_request_mem_resource(dev, 0);
	if (IS_ERR(iores))
		return PTR_ERR(iores);
	base = IOMEM(iores->start);

	return 0;
}

static __maybe_unused struct of_device_id imx_iomux_dt_ids[] = {
	{
		.compatible = "fsl,imx31-iomux",
	}, {
		/* sentinel */
	}
};

static struct platform_device_id imx_iomux_ids[] = {
	{
		.name = "imx31-iomux",
	}, {
		/* sentinel */
	},
};

static struct driver_d imx_iomux_driver = {
	.name = "imx-iomuxv2",
	.probe = imx_iomux_probe,
	.of_compatible = DRV_OF_COMPAT(imx_iomux_dt_ids),
	.id_table = imx_iomux_ids,
};

static int imx_iomux_init(void)
{
	return platform_driver_register(&imx_iomux_driver);
}
postcore_initcall(imx_iomux_init);