xref: /linux/drivers/pinctrl/spear/pinctrl-spear.c (revision 6396bb221514d2876fd6dc0aa2a1f240d99b37bb)
1deda8287SViresh Kumar /*
2deda8287SViresh Kumar  * Driver for the ST Microelectronics SPEAr pinmux
3deda8287SViresh Kumar  *
4deda8287SViresh Kumar  * Copyright (C) 2012 ST Microelectronics
5da89947bSViresh Kumar  * Viresh Kumar <vireshk@kernel.org>
6deda8287SViresh Kumar  *
7deda8287SViresh Kumar  * Inspired from:
8deda8287SViresh Kumar  * - U300 Pinctl drivers
9deda8287SViresh Kumar  * - Tegra Pinctl drivers
10deda8287SViresh Kumar  *
11deda8287SViresh Kumar  * This file is licensed under the terms of the GNU General Public
12deda8287SViresh Kumar  * License version 2. This program is licensed "as is" without any
13deda8287SViresh Kumar  * warranty of any kind, whether express or implied.
14deda8287SViresh Kumar  */
15deda8287SViresh Kumar 
16deda8287SViresh Kumar #include <linux/err.h>
17deda8287SViresh Kumar #include <linux/module.h>
18deda8287SViresh Kumar #include <linux/of.h>
19deda8287SViresh Kumar #include <linux/of_address.h>
20f4f8e563SViresh Kumar #include <linux/of_gpio.h>
21deda8287SViresh Kumar #include <linux/pinctrl/machine.h>
22deda8287SViresh Kumar #include <linux/pinctrl/pinctrl.h>
23deda8287SViresh Kumar #include <linux/pinctrl/pinmux.h>
24deda8287SViresh Kumar #include <linux/platform_device.h>
25deda8287SViresh Kumar #include <linux/slab.h>
26deda8287SViresh Kumar 
27deda8287SViresh Kumar #include "pinctrl-spear.h"
28deda8287SViresh Kumar 
29deda8287SViresh Kumar #define DRIVER_NAME "spear-pinmux"
30deda8287SViresh Kumar 
31f4f8e563SViresh Kumar static void muxregs_endisable(struct spear_pmx *pmx,
32f4f8e563SViresh Kumar 		struct spear_muxreg *muxregs, u8 count, bool enable)
33f4f8e563SViresh Kumar {
34f4f8e563SViresh Kumar 	struct spear_muxreg *muxreg;
35f4f8e563SViresh Kumar 	u32 val, temp, j;
36f4f8e563SViresh Kumar 
37f4f8e563SViresh Kumar 	for (j = 0; j < count; j++) {
38f4f8e563SViresh Kumar 		muxreg = &muxregs[j];
39f4f8e563SViresh Kumar 
40f4f8e563SViresh Kumar 		val = pmx_readl(pmx, muxreg->reg);
41f4f8e563SViresh Kumar 		val &= ~muxreg->mask;
42f4f8e563SViresh Kumar 
43f4f8e563SViresh Kumar 		if (enable)
44f4f8e563SViresh Kumar 			temp = muxreg->val;
45f4f8e563SViresh Kumar 		else
46f4f8e563SViresh Kumar 			temp = ~muxreg->val;
47f4f8e563SViresh Kumar 
48f4f8e563SViresh Kumar 		val |= muxreg->mask & temp;
49f4f8e563SViresh Kumar 		pmx_writel(pmx, val, muxreg->reg);
50f4f8e563SViresh Kumar 	}
51f4f8e563SViresh Kumar }
52f4f8e563SViresh Kumar 
53deda8287SViresh Kumar static int set_mode(struct spear_pmx *pmx, int mode)
54deda8287SViresh Kumar {
55deda8287SViresh Kumar 	struct spear_pmx_mode *pmx_mode = NULL;
56deda8287SViresh Kumar 	int i;
57deda8287SViresh Kumar 	u32 val;
58deda8287SViresh Kumar 
59deda8287SViresh Kumar 	if (!pmx->machdata->pmx_modes || !pmx->machdata->npmx_modes)
60deda8287SViresh Kumar 		return -EINVAL;
61deda8287SViresh Kumar 
62deda8287SViresh Kumar 	for (i = 0; i < pmx->machdata->npmx_modes; i++) {
63deda8287SViresh Kumar 		if (pmx->machdata->pmx_modes[i]->mode == (1 << mode)) {
64deda8287SViresh Kumar 			pmx_mode = pmx->machdata->pmx_modes[i];
65deda8287SViresh Kumar 			break;
66deda8287SViresh Kumar 		}
67deda8287SViresh Kumar 	}
68deda8287SViresh Kumar 
69deda8287SViresh Kumar 	if (!pmx_mode)
70deda8287SViresh Kumar 		return -EINVAL;
71deda8287SViresh Kumar 
72deda8287SViresh Kumar 	val = pmx_readl(pmx, pmx_mode->reg);
73deda8287SViresh Kumar 	val &= ~pmx_mode->mask;
74deda8287SViresh Kumar 	val |= pmx_mode->val;
75deda8287SViresh Kumar 	pmx_writel(pmx, val, pmx_mode->reg);
76deda8287SViresh Kumar 
77deda8287SViresh Kumar 	pmx->machdata->mode = pmx_mode->mode;
78deda8287SViresh Kumar 	dev_info(pmx->dev, "Configured Mode: %s with id: %x\n\n",
79deda8287SViresh Kumar 			pmx_mode->name ? pmx_mode->name : "no_name",
80deda8287SViresh Kumar 			pmx_mode->reg);
81deda8287SViresh Kumar 
82deda8287SViresh Kumar 	return 0;
83deda8287SViresh Kumar }
84deda8287SViresh Kumar 
85150632b0SGreg Kroah-Hartman void pmx_init_gpio_pingroup_addr(struct spear_gpio_pingroup *gpio_pingroup,
86f4f8e563SViresh Kumar 				 unsigned count, u16 reg)
87f4f8e563SViresh Kumar {
884484d0b1SAxel Lin 	int i, j;
89f4f8e563SViresh Kumar 
904484d0b1SAxel Lin 	for (i = 0; i < count; i++)
914484d0b1SAxel Lin 		for (j = 0; j < gpio_pingroup[i].nmuxregs; j++)
92f4f8e563SViresh Kumar 			gpio_pingroup[i].muxregs[j].reg = reg;
93f4f8e563SViresh Kumar }
94f4f8e563SViresh Kumar 
95150632b0SGreg Kroah-Hartman void pmx_init_addr(struct spear_pinctrl_machdata *machdata, u16 reg)
96deda8287SViresh Kumar {
97deda8287SViresh Kumar 	struct spear_pingroup *pgroup;
98deda8287SViresh Kumar 	struct spear_modemux *modemux;
99deda8287SViresh Kumar 	int i, j, group;
100deda8287SViresh Kumar 
101deda8287SViresh Kumar 	for (group = 0; group < machdata->ngroups; group++) {
102deda8287SViresh Kumar 		pgroup = machdata->groups[group];
103deda8287SViresh Kumar 
104deda8287SViresh Kumar 		for (i = 0; i < pgroup->nmodemuxs; i++) {
105deda8287SViresh Kumar 			modemux = &pgroup->modemuxs[i];
106deda8287SViresh Kumar 
107deda8287SViresh Kumar 			for (j = 0; j < modemux->nmuxregs; j++)
108deda8287SViresh Kumar 				if (modemux->muxregs[j].reg == 0xFFFF)
109deda8287SViresh Kumar 					modemux->muxregs[j].reg = reg;
110deda8287SViresh Kumar 		}
111deda8287SViresh Kumar 	}
112deda8287SViresh Kumar }
113deda8287SViresh Kumar 
114deda8287SViresh Kumar static int spear_pinctrl_get_groups_cnt(struct pinctrl_dev *pctldev)
115deda8287SViresh Kumar {
116deda8287SViresh Kumar 	struct spear_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
117deda8287SViresh Kumar 
118deda8287SViresh Kumar 	return pmx->machdata->ngroups;
119deda8287SViresh Kumar }
120deda8287SViresh Kumar 
121deda8287SViresh Kumar static const char *spear_pinctrl_get_group_name(struct pinctrl_dev *pctldev,
122deda8287SViresh Kumar 		unsigned group)
123deda8287SViresh Kumar {
124deda8287SViresh Kumar 	struct spear_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
125deda8287SViresh Kumar 
126deda8287SViresh Kumar 	return pmx->machdata->groups[group]->name;
127deda8287SViresh Kumar }
128deda8287SViresh Kumar 
129deda8287SViresh Kumar static int spear_pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
130deda8287SViresh Kumar 		unsigned group, const unsigned **pins, unsigned *num_pins)
131deda8287SViresh Kumar {
132deda8287SViresh Kumar 	struct spear_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
133deda8287SViresh Kumar 
134deda8287SViresh Kumar 	*pins = pmx->machdata->groups[group]->pins;
135deda8287SViresh Kumar 	*num_pins = pmx->machdata->groups[group]->npins;
136deda8287SViresh Kumar 
137deda8287SViresh Kumar 	return 0;
138deda8287SViresh Kumar }
139deda8287SViresh Kumar 
140deda8287SViresh Kumar static void spear_pinctrl_pin_dbg_show(struct pinctrl_dev *pctldev,
141deda8287SViresh Kumar 		struct seq_file *s, unsigned offset)
142deda8287SViresh Kumar {
143deda8287SViresh Kumar 	seq_printf(s, " " DRIVER_NAME);
144deda8287SViresh Kumar }
145deda8287SViresh Kumar 
1469b2b1740SAxel Lin static int spear_pinctrl_dt_node_to_map(struct pinctrl_dev *pctldev,
147deda8287SViresh Kumar 					struct device_node *np_config,
1489b2b1740SAxel Lin 					struct pinctrl_map **map,
1499b2b1740SAxel Lin 					unsigned *num_maps)
150deda8287SViresh Kumar {
151deda8287SViresh Kumar 	struct spear_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
152deda8287SViresh Kumar 	struct device_node *np;
153deda8287SViresh Kumar 	struct property *prop;
154deda8287SViresh Kumar 	const char *function, *group;
155deda8287SViresh Kumar 	int ret, index = 0, count = 0;
156deda8287SViresh Kumar 
157deda8287SViresh Kumar 	/* calculate number of maps required */
158deda8287SViresh Kumar 	for_each_child_of_node(np_config, np) {
159deda8287SViresh Kumar 		ret = of_property_read_string(np, "st,function", &function);
160deda8287SViresh Kumar 		if (ret < 0)
161deda8287SViresh Kumar 			return ret;
162deda8287SViresh Kumar 
163deda8287SViresh Kumar 		ret = of_property_count_strings(np, "st,pins");
164deda8287SViresh Kumar 		if (ret < 0)
165deda8287SViresh Kumar 			return ret;
166deda8287SViresh Kumar 
167deda8287SViresh Kumar 		count += ret;
168deda8287SViresh Kumar 	}
169deda8287SViresh Kumar 
170deda8287SViresh Kumar 	if (!count) {
171deda8287SViresh Kumar 		dev_err(pmx->dev, "No child nodes passed via DT\n");
172deda8287SViresh Kumar 		return -ENODEV;
173deda8287SViresh Kumar 	}
174deda8287SViresh Kumar 
175*6396bb22SKees Cook 	*map = kcalloc(count, sizeof(**map), GFP_KERNEL);
176deda8287SViresh Kumar 	if (!*map)
177deda8287SViresh Kumar 		return -ENOMEM;
178deda8287SViresh Kumar 
179deda8287SViresh Kumar 	for_each_child_of_node(np_config, np) {
180deda8287SViresh Kumar 		of_property_read_string(np, "st,function", &function);
181deda8287SViresh Kumar 		of_property_for_each_string(np, "st,pins", prop, group) {
182deda8287SViresh Kumar 			(*map)[index].type = PIN_MAP_TYPE_MUX_GROUP;
183deda8287SViresh Kumar 			(*map)[index].data.mux.group = group;
184deda8287SViresh Kumar 			(*map)[index].data.mux.function = function;
185deda8287SViresh Kumar 			index++;
186deda8287SViresh Kumar 		}
187deda8287SViresh Kumar 	}
188deda8287SViresh Kumar 
189deda8287SViresh Kumar 	*num_maps = count;
190deda8287SViresh Kumar 
191deda8287SViresh Kumar 	return 0;
192deda8287SViresh Kumar }
193deda8287SViresh Kumar 
1949b2b1740SAxel Lin static void spear_pinctrl_dt_free_map(struct pinctrl_dev *pctldev,
1959b2b1740SAxel Lin 				      struct pinctrl_map *map,
1969b2b1740SAxel Lin 				      unsigned num_maps)
197deda8287SViresh Kumar {
198deda8287SViresh Kumar 	kfree(map);
199deda8287SViresh Kumar }
200deda8287SViresh Kumar 
201022ab148SLaurent Pinchart static const struct pinctrl_ops spear_pinctrl_ops = {
202deda8287SViresh Kumar 	.get_groups_count = spear_pinctrl_get_groups_cnt,
203deda8287SViresh Kumar 	.get_group_name = spear_pinctrl_get_group_name,
204deda8287SViresh Kumar 	.get_group_pins = spear_pinctrl_get_group_pins,
205deda8287SViresh Kumar 	.pin_dbg_show = spear_pinctrl_pin_dbg_show,
206deda8287SViresh Kumar 	.dt_node_to_map = spear_pinctrl_dt_node_to_map,
207deda8287SViresh Kumar 	.dt_free_map = spear_pinctrl_dt_free_map,
208deda8287SViresh Kumar };
209deda8287SViresh Kumar 
210deda8287SViresh Kumar static int spear_pinctrl_get_funcs_count(struct pinctrl_dev *pctldev)
211deda8287SViresh Kumar {
212deda8287SViresh Kumar 	struct spear_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
213deda8287SViresh Kumar 
214deda8287SViresh Kumar 	return pmx->machdata->nfunctions;
215deda8287SViresh Kumar }
216deda8287SViresh Kumar 
217deda8287SViresh Kumar static const char *spear_pinctrl_get_func_name(struct pinctrl_dev *pctldev,
218deda8287SViresh Kumar 		unsigned function)
219deda8287SViresh Kumar {
220deda8287SViresh Kumar 	struct spear_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
221deda8287SViresh Kumar 
222deda8287SViresh Kumar 	return pmx->machdata->functions[function]->name;
223deda8287SViresh Kumar }
224deda8287SViresh Kumar 
225deda8287SViresh Kumar static int spear_pinctrl_get_func_groups(struct pinctrl_dev *pctldev,
226deda8287SViresh Kumar 		unsigned function, const char *const **groups,
227deda8287SViresh Kumar 		unsigned * const ngroups)
228deda8287SViresh Kumar {
229deda8287SViresh Kumar 	struct spear_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
230deda8287SViresh Kumar 
231deda8287SViresh Kumar 	*groups = pmx->machdata->functions[function]->groups;
232deda8287SViresh Kumar 	*ngroups = pmx->machdata->functions[function]->ngroups;
233deda8287SViresh Kumar 
234deda8287SViresh Kumar 	return 0;
235deda8287SViresh Kumar }
236deda8287SViresh Kumar 
237deda8287SViresh Kumar static int spear_pinctrl_endisable(struct pinctrl_dev *pctldev,
238deda8287SViresh Kumar 		unsigned function, unsigned group, bool enable)
239deda8287SViresh Kumar {
240deda8287SViresh Kumar 	struct spear_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
241deda8287SViresh Kumar 	const struct spear_pingroup *pgroup;
242deda8287SViresh Kumar 	const struct spear_modemux *modemux;
243f4f8e563SViresh Kumar 	int i;
244deda8287SViresh Kumar 	bool found = false;
245deda8287SViresh Kumar 
246deda8287SViresh Kumar 	pgroup = pmx->machdata->groups[group];
247deda8287SViresh Kumar 
248deda8287SViresh Kumar 	for (i = 0; i < pgroup->nmodemuxs; i++) {
249deda8287SViresh Kumar 		modemux = &pgroup->modemuxs[i];
250deda8287SViresh Kumar 
251deda8287SViresh Kumar 		/* SoC have any modes */
252deda8287SViresh Kumar 		if (pmx->machdata->modes_supported) {
253deda8287SViresh Kumar 			if (!(pmx->machdata->mode & modemux->modes))
254deda8287SViresh Kumar 				continue;
255deda8287SViresh Kumar 		}
256deda8287SViresh Kumar 
257deda8287SViresh Kumar 		found = true;
258f4f8e563SViresh Kumar 		muxregs_endisable(pmx, modemux->muxregs, modemux->nmuxregs,
259f4f8e563SViresh Kumar 				enable);
260deda8287SViresh Kumar 	}
261deda8287SViresh Kumar 
262deda8287SViresh Kumar 	if (!found) {
263deda8287SViresh Kumar 		dev_err(pmx->dev, "pinmux group: %s not supported\n",
264deda8287SViresh Kumar 				pgroup->name);
265deda8287SViresh Kumar 		return -ENODEV;
266deda8287SViresh Kumar 	}
267deda8287SViresh Kumar 
268deda8287SViresh Kumar 	return 0;
269deda8287SViresh Kumar }
270deda8287SViresh Kumar 
27103e9f0caSLinus Walleij static int spear_pinctrl_set_mux(struct pinctrl_dev *pctldev, unsigned function,
272deda8287SViresh Kumar 		unsigned group)
273deda8287SViresh Kumar {
274deda8287SViresh Kumar 	return spear_pinctrl_endisable(pctldev, function, group, true);
275deda8287SViresh Kumar }
276deda8287SViresh Kumar 
277f4f8e563SViresh Kumar /* gpio with pinmux */
278f4f8e563SViresh Kumar static struct spear_gpio_pingroup *get_gpio_pingroup(struct spear_pmx *pmx,
279f4f8e563SViresh Kumar 		unsigned pin)
280f4f8e563SViresh Kumar {
281f4f8e563SViresh Kumar 	struct spear_gpio_pingroup *gpio_pingroup;
2826f37b1b4SAxel Lin 	int i, j;
283f4f8e563SViresh Kumar 
284f4f8e563SViresh Kumar 	if (!pmx->machdata->gpio_pingroups)
285f4f8e563SViresh Kumar 		return NULL;
286f4f8e563SViresh Kumar 
2876f37b1b4SAxel Lin 	for (i = 0; i < pmx->machdata->ngpio_pingroups; i++) {
288f4f8e563SViresh Kumar 		gpio_pingroup = &pmx->machdata->gpio_pingroups[i];
289f4f8e563SViresh Kumar 
290f4f8e563SViresh Kumar 		for (j = 0; j < gpio_pingroup->npins; j++) {
291f4f8e563SViresh Kumar 			if (gpio_pingroup->pins[j] == pin)
292f4f8e563SViresh Kumar 				return gpio_pingroup;
293f4f8e563SViresh Kumar 		}
294f4f8e563SViresh Kumar 	}
295f4f8e563SViresh Kumar 
2966f37b1b4SAxel Lin 	return NULL;
297f4f8e563SViresh Kumar }
298f4f8e563SViresh Kumar 
299f4f8e563SViresh Kumar static int gpio_request_endisable(struct pinctrl_dev *pctldev,
300f4f8e563SViresh Kumar 		struct pinctrl_gpio_range *range, unsigned offset, bool enable)
301f4f8e563SViresh Kumar {
302f4f8e563SViresh Kumar 	struct spear_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
303826d6ca8SShiraz Hashim 	struct spear_pinctrl_machdata *machdata = pmx->machdata;
304f4f8e563SViresh Kumar 	struct spear_gpio_pingroup *gpio_pingroup;
305f4f8e563SViresh Kumar 
306826d6ca8SShiraz Hashim 	/*
307826d6ca8SShiraz Hashim 	 * Some SoC have configuration options applicable to group of pins,
308826d6ca8SShiraz Hashim 	 * rather than a single pin.
309826d6ca8SShiraz Hashim 	 */
310f4f8e563SViresh Kumar 	gpio_pingroup = get_gpio_pingroup(pmx, offset);
311f4f8e563SViresh Kumar 	if (gpio_pingroup)
312f4f8e563SViresh Kumar 		muxregs_endisable(pmx, gpio_pingroup->muxregs,
313f4f8e563SViresh Kumar 				gpio_pingroup->nmuxregs, enable);
314f4f8e563SViresh Kumar 
315826d6ca8SShiraz Hashim 	/*
316826d6ca8SShiraz Hashim 	 * SoC may need some extra configurations, or configurations for single
317826d6ca8SShiraz Hashim 	 * pin
318826d6ca8SShiraz Hashim 	 */
319826d6ca8SShiraz Hashim 	if (machdata->gpio_request_endisable)
320826d6ca8SShiraz Hashim 		machdata->gpio_request_endisable(pmx, offset, enable);
321826d6ca8SShiraz Hashim 
322f4f8e563SViresh Kumar 	return 0;
323f4f8e563SViresh Kumar }
324f4f8e563SViresh Kumar 
325f4f8e563SViresh Kumar static int gpio_request_enable(struct pinctrl_dev *pctldev,
326f4f8e563SViresh Kumar 		struct pinctrl_gpio_range *range, unsigned offset)
327f4f8e563SViresh Kumar {
328f4f8e563SViresh Kumar 	return gpio_request_endisable(pctldev, range, offset, true);
329f4f8e563SViresh Kumar }
330f4f8e563SViresh Kumar 
331f4f8e563SViresh Kumar static void gpio_disable_free(struct pinctrl_dev *pctldev,
332f4f8e563SViresh Kumar 		struct pinctrl_gpio_range *range, unsigned offset)
333f4f8e563SViresh Kumar {
334f4f8e563SViresh Kumar 	gpio_request_endisable(pctldev, range, offset, false);
335f4f8e563SViresh Kumar }
336f4f8e563SViresh Kumar 
337022ab148SLaurent Pinchart static const struct pinmux_ops spear_pinmux_ops = {
338deda8287SViresh Kumar 	.get_functions_count = spear_pinctrl_get_funcs_count,
339deda8287SViresh Kumar 	.get_function_name = spear_pinctrl_get_func_name,
340deda8287SViresh Kumar 	.get_function_groups = spear_pinctrl_get_func_groups,
34103e9f0caSLinus Walleij 	.set_mux = spear_pinctrl_set_mux,
342f4f8e563SViresh Kumar 	.gpio_request_enable = gpio_request_enable,
343f4f8e563SViresh Kumar 	.gpio_disable_free = gpio_disable_free,
344deda8287SViresh Kumar };
345deda8287SViresh Kumar 
346deda8287SViresh Kumar static struct pinctrl_desc spear_pinctrl_desc = {
347deda8287SViresh Kumar 	.name = DRIVER_NAME,
348deda8287SViresh Kumar 	.pctlops = &spear_pinctrl_ops,
349deda8287SViresh Kumar 	.pmxops = &spear_pinmux_ops,
350deda8287SViresh Kumar 	.owner = THIS_MODULE,
351deda8287SViresh Kumar };
352deda8287SViresh Kumar 
353150632b0SGreg Kroah-Hartman int spear_pinctrl_probe(struct platform_device *pdev,
354deda8287SViresh Kumar 			struct spear_pinctrl_machdata *machdata)
355deda8287SViresh Kumar {
356deda8287SViresh Kumar 	struct device_node *np = pdev->dev.of_node;
357deda8287SViresh Kumar 	struct resource *res;
358deda8287SViresh Kumar 	struct spear_pmx *pmx;
359deda8287SViresh Kumar 
360deda8287SViresh Kumar 	if (!machdata)
361deda8287SViresh Kumar 		return -ENODEV;
362deda8287SViresh Kumar 
363deda8287SViresh Kumar 	pmx = devm_kzalloc(&pdev->dev, sizeof(*pmx), GFP_KERNEL);
36451d7a036SMarkus Elfring 	if (!pmx)
365deda8287SViresh Kumar 		return -ENOMEM;
366deda8287SViresh Kumar 
367dff5a99cSAxel Lin 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
368dff5a99cSAxel Lin 	pmx->vbase = devm_ioremap_resource(&pdev->dev, res);
369dff5a99cSAxel Lin 	if (IS_ERR(pmx->vbase))
370dff5a99cSAxel Lin 		return PTR_ERR(pmx->vbase);
371deda8287SViresh Kumar 
372deda8287SViresh Kumar 	pmx->dev = &pdev->dev;
373deda8287SViresh Kumar 	pmx->machdata = machdata;
374deda8287SViresh Kumar 
375deda8287SViresh Kumar 	/* configure mode, if supported by SoC */
376deda8287SViresh Kumar 	if (machdata->modes_supported) {
377deda8287SViresh Kumar 		int mode = 0;
378deda8287SViresh Kumar 
379deda8287SViresh Kumar 		if (of_property_read_u32(np, "st,pinmux-mode", &mode)) {
380deda8287SViresh Kumar 			dev_err(&pdev->dev, "OF: pinmux mode not passed\n");
381deda8287SViresh Kumar 			return -EINVAL;
382deda8287SViresh Kumar 		}
383deda8287SViresh Kumar 
384deda8287SViresh Kumar 		if (set_mode(pmx, mode)) {
385deda8287SViresh Kumar 			dev_err(&pdev->dev, "OF: Couldn't configure mode: %x\n",
386deda8287SViresh Kumar 					mode);
387deda8287SViresh Kumar 			return -EINVAL;
388deda8287SViresh Kumar 		}
389deda8287SViresh Kumar 	}
390deda8287SViresh Kumar 
391deda8287SViresh Kumar 	platform_set_drvdata(pdev, pmx);
392deda8287SViresh Kumar 
393deda8287SViresh Kumar 	spear_pinctrl_desc.pins = machdata->pins;
394deda8287SViresh Kumar 	spear_pinctrl_desc.npins = machdata->npins;
395deda8287SViresh Kumar 
396d39de313SLaxman Dewangan 	pmx->pctl = devm_pinctrl_register(&pdev->dev, &spear_pinctrl_desc, pmx);
397323de9efSMasahiro Yamada 	if (IS_ERR(pmx->pctl)) {
398deda8287SViresh Kumar 		dev_err(&pdev->dev, "Couldn't register pinctrl driver\n");
399323de9efSMasahiro Yamada 		return PTR_ERR(pmx->pctl);
400deda8287SViresh Kumar 	}
401deda8287SViresh Kumar 
402deda8287SViresh Kumar 	return 0;
403deda8287SViresh Kumar }
404