summaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl/freescale/pinctrl-imx8ulp.c
blob: 5632c72851479f88628def3081ecf4c44015996a (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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright 2021 NXP
 */

#include <linux/err.h>
#include <linux/init.h>
#include <linux/io.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/pinctrl/pinctrl.h>
#include <linux/platform_device.h>

#include "pinctrl-imx.h"

enum imx8ulp_pads {
	IMX8ULP_PAD_PTD0 = 0,
	IMX8ULP_PAD_PTD1,
	IMX8ULP_PAD_PTD2,
	IMX8ULP_PAD_PTD3,
	IMX8ULP_PAD_PTD4,
	IMX8ULP_PAD_PTD5,
	IMX8ULP_PAD_PTD6,
	IMX8ULP_PAD_PTD7,
	IMX8ULP_PAD_PTD8,
	IMX8ULP_PAD_PTD9,
	IMX8ULP_PAD_PTD10,
	IMX8UL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_PAD_PTF5),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF6),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF7),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF8),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF9),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF10),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF11),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF12),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF13),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF14),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF15),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF16),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF17),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF18),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF19),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF20),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF21),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF22),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF23),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF24),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF25),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF26),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF27),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF28),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF29),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF30),
	IMX_PINCTRL_PIN(IMX8ULP_PAD_PTF31),
};

#define BM_OBE_ENABLED		BIT(17)
#define BM_IBE_ENABLED		BIT(16)
#define BM_MUX_MODE		0xf00
#define BP_MUX_MODE		8

static int imx8ulp_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
					  struct pinctrl_gpio_range *range,
					  unsigned offset, bool input)
{
	struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
	const struct imx_pin_reg *pin_reg;
	u32 reg;

	pin_reg = &ipctl->pin_regs[offset];
	if (pin_reg->mux_reg == -1)
		return -EINVAL;

	reg = readl(ipctl->base + pin_reg->mux_reg);
	if (input)
		reg = (reg & ~BM_OBE_ENABLED) | BM_IBE_ENABLED;
	else
		reg = (reg & ~BM_IBE_ENABLED) | BM_OBE_ENABLED;
	writel(reg, ipctl->base + pin_reg->mux_reg);

	return 0;
}

static const struct imx_pinctrl_soc_info imx8ulp_pinctrl_info = {
	.pins = imx8ulp_pinctrl_pads,
	.npins = ARRAY_SIZE(imx8ulp_pinctrl_pads),
	.flags = ZERO_OFFSET_VALID | SHARE_MUX_CONF_REG,
	.gpio_set_direction = imx8ulp_pmx_gpio_set_direction,
	.mux_mask = BM_MUX_MODE,
	.mux_shift = BP_MUX_MODE,
};

static const struct of_device_id imx8ulp_pinctrl_of_match[] = {
	{ .compatible = "fsl,imx8ulp-iomuxc1", },
	{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, imx8ulp_pinctrl_of_match);

static int imx8ulp_pinctrl_probe(struct platform_device *pdev)
{
	return imx_pinctrl_probe(pdev, &imx8ulp_pinctrl_info);
}

static struct platform_driver imx8ulp_pinctrl_driver = {
	.driver = {
		.name = "imx8ulp-pinctrl",
		.of_match_table = imx8ulp_pinctrl_of_match,
		.suppress_bind_attrs = true,
	},
	.probe = imx8ulp_pinctrl_probe,
};

static int __init imx8ulp_pinctrl_init(void)
{
	return platform_driver_register(&imx8ulp_pinctrl_driver);
}
arch_initcall(imx8ulp_pinctrl_init);

MODULE_AUTHOR("Jacky Bai <ping.bai@nxp.com>");
MODULE_DESCRIPTION("NXP i.MX8ULP pinctrl driver");
MODULE_LICENSE("GPL v2");