xref: /linux/drivers/pinctrl/pinctrl-at91-pio4.c (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
19c92ab61SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
277618084SLudovic Desroches /*
377618084SLudovic Desroches  * Driver for the Atmel PIO4 controller
477618084SLudovic Desroches  *
577618084SLudovic Desroches  * Copyright (C) 2015 Atmel,
677618084SLudovic Desroches  *               2015 Ludovic Desroches <ludovic.desroches@atmel.com>
777618084SLudovic Desroches  */
877618084SLudovic Desroches 
9ff10e353SLudovic Desroches #include <dt-bindings/pinctrl/at91.h>
109ace1002SAndy Shevchenko 
1177618084SLudovic Desroches #include <linux/clk.h>
1280036f88SLinus Walleij #include <linux/gpio/driver.h>
139ace1002SAndy Shevchenko #include <linux/init.h>
14de4e882fSLudovic Desroches #include <linux/interrupt.h>
1577618084SLudovic Desroches #include <linux/io.h>
1677618084SLudovic Desroches #include <linux/of.h>
1777618084SLudovic Desroches #include <linux/platform_device.h>
189ace1002SAndy Shevchenko #include <linux/seq_file.h>
199ace1002SAndy Shevchenko #include <linux/slab.h>
209ace1002SAndy Shevchenko 
2177618084SLudovic Desroches #include <linux/pinctrl/pinconf-generic.h>
229ace1002SAndy Shevchenko #include <linux/pinctrl/pinconf.h>
2377618084SLudovic Desroches #include <linux/pinctrl/pinctrl.h>
2477618084SLudovic Desroches #include <linux/pinctrl/pinmux.h>
259ace1002SAndy Shevchenko 
2677618084SLudovic Desroches #include "core.h"
2777618084SLudovic Desroches #include "pinconf.h"
2877618084SLudovic Desroches #include "pinctrl-utils.h"
2977618084SLudovic Desroches 
3077618084SLudovic Desroches /*
3177618084SLudovic Desroches  * Warning:
3277618084SLudovic Desroches  * In order to not introduce confusion between Atmel PIO groups and pinctrl
3377618084SLudovic Desroches  * framework groups, Atmel PIO groups will be called banks, line is kept to
3477618084SLudovic Desroches  * designed the pin id into this bank.
3577618084SLudovic Desroches  */
3677618084SLudovic Desroches 
3777618084SLudovic Desroches #define ATMEL_PIO_MSKR		0x0000
3877618084SLudovic Desroches #define ATMEL_PIO_CFGR		0x0004
3977618084SLudovic Desroches #define		ATMEL_PIO_CFGR_FUNC_MASK	GENMASK(2, 0)
4077618084SLudovic Desroches #define		ATMEL_PIO_DIR_MASK		BIT(8)
4177618084SLudovic Desroches #define		ATMEL_PIO_PUEN_MASK		BIT(9)
4277618084SLudovic Desroches #define		ATMEL_PIO_PDEN_MASK		BIT(10)
43c709135eSClaudiu Beznea #define		ATMEL_PIO_SR_MASK		BIT(11)
4477618084SLudovic Desroches #define		ATMEL_PIO_IFEN_MASK		BIT(12)
4577618084SLudovic Desroches #define		ATMEL_PIO_IFSCEN_MASK		BIT(13)
4677618084SLudovic Desroches #define		ATMEL_PIO_OPD_MASK		BIT(14)
4777618084SLudovic Desroches #define		ATMEL_PIO_SCHMITT_MASK		BIT(15)
48ff10e353SLudovic Desroches #define		ATMEL_PIO_DRVSTR_MASK		GENMASK(17, 16)
49ff10e353SLudovic Desroches #define		ATMEL_PIO_DRVSTR_OFFSET		16
5077618084SLudovic Desroches #define		ATMEL_PIO_CFGR_EVTSEL_MASK	GENMASK(26, 24)
5177618084SLudovic Desroches #define		ATMEL_PIO_CFGR_EVTSEL_FALLING	(0 << 24)
5277618084SLudovic Desroches #define		ATMEL_PIO_CFGR_EVTSEL_RISING	(1 << 24)
5377618084SLudovic Desroches #define		ATMEL_PIO_CFGR_EVTSEL_BOTH	(2 << 24)
5477618084SLudovic Desroches #define		ATMEL_PIO_CFGR_EVTSEL_LOW	(3 << 24)
5577618084SLudovic Desroches #define		ATMEL_PIO_CFGR_EVTSEL_HIGH	(4 << 24)
5677618084SLudovic Desroches #define ATMEL_PIO_PDSR		0x0008
5777618084SLudovic Desroches #define ATMEL_PIO_LOCKSR	0x000C
5877618084SLudovic Desroches #define ATMEL_PIO_SODR		0x0010
5977618084SLudovic Desroches #define ATMEL_PIO_CODR		0x0014
6077618084SLudovic Desroches #define ATMEL_PIO_ODSR		0x0018
6177618084SLudovic Desroches #define ATMEL_PIO_IER		0x0020
6277618084SLudovic Desroches #define ATMEL_PIO_IDR		0x0024
6377618084SLudovic Desroches #define ATMEL_PIO_IMR		0x0028
6477618084SLudovic Desroches #define ATMEL_PIO_ISR		0x002C
6577618084SLudovic Desroches #define ATMEL_PIO_IOFR		0x003C
6677618084SLudovic Desroches 
6777618084SLudovic Desroches #define ATMEL_PIO_NPINS_PER_BANK	32
6877618084SLudovic Desroches #define ATMEL_PIO_BANK(pin_id)		(pin_id / ATMEL_PIO_NPINS_PER_BANK)
6977618084SLudovic Desroches #define ATMEL_PIO_LINE(pin_id)		(pin_id % ATMEL_PIO_NPINS_PER_BANK)
7077618084SLudovic Desroches #define ATMEL_PIO_BANK_OFFSET		0x40
7177618084SLudovic Desroches 
7277618084SLudovic Desroches #define ATMEL_GET_PIN_NO(pinfunc)	((pinfunc) & 0xff)
7377618084SLudovic Desroches #define ATMEL_GET_PIN_FUNC(pinfunc)	((pinfunc >> 16) & 0xf)
7477618084SLudovic Desroches #define ATMEL_GET_PIN_IOSET(pinfunc)	((pinfunc >> 20) & 0xf)
7577618084SLudovic Desroches 
76ff10e353SLudovic Desroches /* Custom pinconf parameters */
77ff10e353SLudovic Desroches #define ATMEL_PIN_CONFIG_DRIVE_STRENGTH	(PIN_CONFIG_END + 1)
78ff10e353SLudovic Desroches 
79b6071c89SEugen Hristev /**
80b6071c89SEugen Hristev  * struct atmel_pioctrl_data - Atmel PIO controller (pinmux + gpio) data struct
81b6071c89SEugen Hristev  * @nbanks: number of PIO banks
82b6071c89SEugen Hristev  * @last_bank_count: number of lines in the last bank (can be less than
83b6071c89SEugen Hristev  *	the rest of the banks).
84c709135eSClaudiu Beznea  * @slew_rate_support: slew rate support
85b6071c89SEugen Hristev  */
8677618084SLudovic Desroches struct atmel_pioctrl_data {
87b4435b42SClaudiu Beznea 	unsigned int nbanks;
88b4435b42SClaudiu Beznea 	unsigned int last_bank_count;
89c709135eSClaudiu Beznea 	unsigned int slew_rate_support;
9077618084SLudovic Desroches };
9177618084SLudovic Desroches 
9277618084SLudovic Desroches struct atmel_group {
9377618084SLudovic Desroches 	const char *name;
9477618084SLudovic Desroches 	u32 pin;
9577618084SLudovic Desroches };
9677618084SLudovic Desroches 
9777618084SLudovic Desroches struct atmel_pin {
98b4435b42SClaudiu Beznea 	unsigned int pin_id;
99b4435b42SClaudiu Beznea 	unsigned int mux;
100b4435b42SClaudiu Beznea 	unsigned int ioset;
101b4435b42SClaudiu Beznea 	unsigned int bank;
102b4435b42SClaudiu Beznea 	unsigned int line;
10377618084SLudovic Desroches 	const char *device;
10477618084SLudovic Desroches };
10577618084SLudovic Desroches 
10677618084SLudovic Desroches /**
10777618084SLudovic Desroches  * struct atmel_pioctrl - Atmel PIO controller (pinmux + gpio)
10877618084SLudovic Desroches  * @reg_base: base address of the controller.
10977618084SLudovic Desroches  * @clk: clock of the controller.
11077618084SLudovic Desroches  * @nbanks: number of PIO groups, it can vary depending on the SoC.
11177618084SLudovic Desroches  * @pinctrl_dev: pinctrl device registered.
11277618084SLudovic Desroches  * @groups: groups table to provide group name and pin in the group to pinctrl.
11377618084SLudovic Desroches  * @group_names: group names table to provide all the group/pin names to
11477618084SLudovic Desroches  *     pinctrl or gpio.
11577618084SLudovic Desroches  * @pins: pins table used for both pinctrl and gpio. pin_id, bank and line
11677618084SLudovic Desroches  *     fields are set at probe time. Other ones are set when parsing dt
11777618084SLudovic Desroches  *     pinctrl.
11877618084SLudovic Desroches  * @npins: number of pins.
11977618084SLudovic Desroches  * @gpio_chip: gpio chip registered.
12077618084SLudovic Desroches  * @irq_domain: irq domain for the gpio controller.
12177618084SLudovic Desroches  * @irqs: table containing the hw irq number of the bank. The index of the
12277618084SLudovic Desroches  *     table is the bank id.
123898503eeSLee Jones  * @pm_wakeup_sources: bitmap of wakeup sources (lines)
124898503eeSLee Jones  * @pm_suspend_backup: backup/restore register values on suspend/resume
12577618084SLudovic Desroches  * @dev: device entry for the Atmel PIO controller.
12677618084SLudovic Desroches  * @node: node of the Atmel PIO controller.
127c709135eSClaudiu Beznea  * @slew_rate_support: slew rate support
12877618084SLudovic Desroches  */
12977618084SLudovic Desroches struct atmel_pioctrl {
13077618084SLudovic Desroches 	void __iomem		*reg_base;
13177618084SLudovic Desroches 	struct clk		*clk;
132b4435b42SClaudiu Beznea 	unsigned int		nbanks;
13377618084SLudovic Desroches 	struct pinctrl_dev	*pinctrl_dev;
13477618084SLudovic Desroches 	struct atmel_group	*groups;
13577618084SLudovic Desroches 	const char * const	*group_names;
13677618084SLudovic Desroches 	struct atmel_pin	**pins;
137b4435b42SClaudiu Beznea 	unsigned int		npins;
13877618084SLudovic Desroches 	struct gpio_chip	*gpio_chip;
13977618084SLudovic Desroches 	struct irq_domain	*irq_domain;
14077618084SLudovic Desroches 	int			*irqs;
141b4435b42SClaudiu Beznea 	unsigned int		*pm_wakeup_sources;
142ba9e7f27SAlexandre Belloni 	struct {
143ba9e7f27SAlexandre Belloni 		u32		imr;
144ba9e7f27SAlexandre Belloni 		u32		odsr;
145ba9e7f27SAlexandre Belloni 		u32		cfgr[ATMEL_PIO_NPINS_PER_BANK];
146ba9e7f27SAlexandre Belloni 	} *pm_suspend_backup;
14777618084SLudovic Desroches 	struct device		*dev;
14877618084SLudovic Desroches 	struct device_node	*node;
149c709135eSClaudiu Beznea 	unsigned int		slew_rate_support;
15077618084SLudovic Desroches };
15177618084SLudovic Desroches 
15277618084SLudovic Desroches static const char * const atmel_functions[] = {
15377618084SLudovic Desroches 	"GPIO", "A", "B", "C", "D", "E", "F", "G"
15477618084SLudovic Desroches };
15577618084SLudovic Desroches 
156ff10e353SLudovic Desroches static const struct pinconf_generic_params atmel_custom_bindings[] = {
157ff10e353SLudovic Desroches 	{"atmel,drive-strength", ATMEL_PIN_CONFIG_DRIVE_STRENGTH, 0},
158ff10e353SLudovic Desroches };
159ff10e353SLudovic Desroches 
16077618084SLudovic Desroches /* --- GPIO --- */
atmel_gpio_read(struct atmel_pioctrl * atmel_pioctrl,unsigned int bank,unsigned int reg)16177618084SLudovic Desroches static unsigned int atmel_gpio_read(struct atmel_pioctrl *atmel_pioctrl,
16277618084SLudovic Desroches 				    unsigned int bank, unsigned int reg)
16377618084SLudovic Desroches {
16477618084SLudovic Desroches 	return readl_relaxed(atmel_pioctrl->reg_base
16577618084SLudovic Desroches 			     + ATMEL_PIO_BANK_OFFSET * bank + reg);
16677618084SLudovic Desroches }
16777618084SLudovic Desroches 
atmel_gpio_write(struct atmel_pioctrl * atmel_pioctrl,unsigned int bank,unsigned int reg,unsigned int val)16877618084SLudovic Desroches static void atmel_gpio_write(struct atmel_pioctrl *atmel_pioctrl,
16977618084SLudovic Desroches 			     unsigned int bank, unsigned int reg,
17077618084SLudovic Desroches 			     unsigned int val)
17177618084SLudovic Desroches {
17277618084SLudovic Desroches 	writel_relaxed(val, atmel_pioctrl->reg_base
17377618084SLudovic Desroches 		       + ATMEL_PIO_BANK_OFFSET * bank + reg);
17477618084SLudovic Desroches }
17577618084SLudovic Desroches 
atmel_gpio_irq_ack(struct irq_data * d)17677618084SLudovic Desroches static void atmel_gpio_irq_ack(struct irq_data *d)
17777618084SLudovic Desroches {
17877618084SLudovic Desroches 	/*
17977618084SLudovic Desroches 	 * Nothing to do, interrupt is cleared when reading the status
18077618084SLudovic Desroches 	 * register.
18177618084SLudovic Desroches 	 */
18277618084SLudovic Desroches }
18377618084SLudovic Desroches 
atmel_gpio_irq_set_type(struct irq_data * d,unsigned int type)184b4435b42SClaudiu Beznea static int atmel_gpio_irq_set_type(struct irq_data *d, unsigned int type)
18577618084SLudovic Desroches {
18677618084SLudovic Desroches 	struct atmel_pioctrl *atmel_pioctrl = irq_data_get_irq_chip_data(d);
18777618084SLudovic Desroches 	struct atmel_pin *pin = atmel_pioctrl->pins[d->hwirq];
188b4435b42SClaudiu Beznea 	unsigned int reg;
18977618084SLudovic Desroches 
19077618084SLudovic Desroches 	atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_MSKR,
19177618084SLudovic Desroches 			 BIT(pin->line));
19277618084SLudovic Desroches 	reg = atmel_gpio_read(atmel_pioctrl, pin->bank, ATMEL_PIO_CFGR);
19377618084SLudovic Desroches 	reg &= (~ATMEL_PIO_CFGR_EVTSEL_MASK);
19477618084SLudovic Desroches 
19577618084SLudovic Desroches 	switch (type) {
19677618084SLudovic Desroches 	case IRQ_TYPE_EDGE_RISING:
1973fd550c6SLudovic Desroches 		irq_set_handler_locked(d, handle_edge_irq);
19877618084SLudovic Desroches 		reg |= ATMEL_PIO_CFGR_EVTSEL_RISING;
19977618084SLudovic Desroches 		break;
20077618084SLudovic Desroches 	case IRQ_TYPE_EDGE_FALLING:
2013fd550c6SLudovic Desroches 		irq_set_handler_locked(d, handle_edge_irq);
20277618084SLudovic Desroches 		reg |= ATMEL_PIO_CFGR_EVTSEL_FALLING;
20377618084SLudovic Desroches 		break;
20477618084SLudovic Desroches 	case IRQ_TYPE_EDGE_BOTH:
2053fd550c6SLudovic Desroches 		irq_set_handler_locked(d, handle_edge_irq);
20677618084SLudovic Desroches 		reg |= ATMEL_PIO_CFGR_EVTSEL_BOTH;
20777618084SLudovic Desroches 		break;
20877618084SLudovic Desroches 	case IRQ_TYPE_LEVEL_LOW:
2093fd550c6SLudovic Desroches 		irq_set_handler_locked(d, handle_level_irq);
21077618084SLudovic Desroches 		reg |= ATMEL_PIO_CFGR_EVTSEL_LOW;
21177618084SLudovic Desroches 		break;
21277618084SLudovic Desroches 	case IRQ_TYPE_LEVEL_HIGH:
2133fd550c6SLudovic Desroches 		irq_set_handler_locked(d, handle_level_irq);
21477618084SLudovic Desroches 		reg |= ATMEL_PIO_CFGR_EVTSEL_HIGH;
21577618084SLudovic Desroches 		break;
21677618084SLudovic Desroches 	case IRQ_TYPE_NONE:
21777618084SLudovic Desroches 	default:
21877618084SLudovic Desroches 		return -EINVAL;
21977618084SLudovic Desroches 	}
22077618084SLudovic Desroches 
22177618084SLudovic Desroches 	atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_CFGR, reg);
22277618084SLudovic Desroches 
22377618084SLudovic Desroches 	return 0;
22477618084SLudovic Desroches }
22577618084SLudovic Desroches 
atmel_gpio_irq_mask(struct irq_data * d)22677618084SLudovic Desroches static void atmel_gpio_irq_mask(struct irq_data *d)
22777618084SLudovic Desroches {
22877618084SLudovic Desroches 	struct atmel_pioctrl *atmel_pioctrl = irq_data_get_irq_chip_data(d);
22977618084SLudovic Desroches 	struct atmel_pin *pin = atmel_pioctrl->pins[d->hwirq];
23077618084SLudovic Desroches 
23177618084SLudovic Desroches 	atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_IDR,
23277618084SLudovic Desroches 			 BIT(pin->line));
23377618084SLudovic Desroches }
23477618084SLudovic Desroches 
atmel_gpio_irq_unmask(struct irq_data * d)23577618084SLudovic Desroches static void atmel_gpio_irq_unmask(struct irq_data *d)
23677618084SLudovic Desroches {
23777618084SLudovic Desroches 	struct atmel_pioctrl *atmel_pioctrl = irq_data_get_irq_chip_data(d);
23877618084SLudovic Desroches 	struct atmel_pin *pin = atmel_pioctrl->pins[d->hwirq];
23977618084SLudovic Desroches 
24077618084SLudovic Desroches 	atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_IER,
24177618084SLudovic Desroches 			 BIT(pin->line));
24277618084SLudovic Desroches }
24377618084SLudovic Desroches 
atmel_gpio_irq_set_wake(struct irq_data * d,unsigned int on)244de4e882fSLudovic Desroches static int atmel_gpio_irq_set_wake(struct irq_data *d, unsigned int on)
245de4e882fSLudovic Desroches {
246de4e882fSLudovic Desroches 	struct atmel_pioctrl *atmel_pioctrl = irq_data_get_irq_chip_data(d);
247de4e882fSLudovic Desroches 	int bank = ATMEL_PIO_BANK(d->hwirq);
248de4e882fSLudovic Desroches 	int line = ATMEL_PIO_LINE(d->hwirq);
249de4e882fSLudovic Desroches 
250de4e882fSLudovic Desroches 	/* The gpio controller has one interrupt line per bank. */
251de4e882fSLudovic Desroches 	irq_set_irq_wake(atmel_pioctrl->irqs[bank], on);
252de4e882fSLudovic Desroches 
253de4e882fSLudovic Desroches 	if (on)
254de4e882fSLudovic Desroches 		atmel_pioctrl->pm_wakeup_sources[bank] |= BIT(line);
255de4e882fSLudovic Desroches 	else
256de4e882fSLudovic Desroches 		atmel_pioctrl->pm_wakeup_sources[bank] &= ~(BIT(line));
257de4e882fSLudovic Desroches 
258de4e882fSLudovic Desroches 	return 0;
259de4e882fSLudovic Desroches }
260de4e882fSLudovic Desroches 
26177618084SLudovic Desroches static struct irq_chip atmel_gpio_irq_chip = {
26277618084SLudovic Desroches 	.name		= "GPIO",
26377618084SLudovic Desroches 	.irq_ack	= atmel_gpio_irq_ack,
26477618084SLudovic Desroches 	.irq_mask	= atmel_gpio_irq_mask,
26577618084SLudovic Desroches 	.irq_unmask	= atmel_gpio_irq_unmask,
26677618084SLudovic Desroches 	.irq_set_type	= atmel_gpio_irq_set_type,
267cc701e18SClaudiu Beznea 	.irq_set_wake	= pm_sleep_ptr(atmel_gpio_irq_set_wake),
26877618084SLudovic Desroches };
26977618084SLudovic Desroches 
atmel_gpio_to_irq(struct gpio_chip * chip,unsigned int offset)270b4435b42SClaudiu Beznea static int atmel_gpio_to_irq(struct gpio_chip *chip, unsigned int offset)
271e897b386SLinus Walleij {
272e897b386SLinus Walleij 	struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip);
273e897b386SLinus Walleij 
274e897b386SLinus Walleij 	return irq_find_mapping(atmel_pioctrl->irq_domain, offset);
275e897b386SLinus Walleij }
276e897b386SLinus Walleij 
atmel_gpio_irq_handler(struct irq_desc * desc)27789092fb0SLudovic Desroches static void atmel_gpio_irq_handler(struct irq_desc *desc)
27877618084SLudovic Desroches {
27989092fb0SLudovic Desroches 	unsigned int irq = irq_desc_get_irq(desc);
28089092fb0SLudovic Desroches 	struct atmel_pioctrl *atmel_pioctrl = irq_desc_get_handler_data(desc);
28177618084SLudovic Desroches 	struct irq_chip *chip = irq_desc_get_chip(desc);
28277618084SLudovic Desroches 	unsigned long isr;
28377618084SLudovic Desroches 	int n, bank = -1;
28477618084SLudovic Desroches 
28577618084SLudovic Desroches 	/* Find from which bank is the irq received. */
28677618084SLudovic Desroches 	for (n = 0; n < atmel_pioctrl->nbanks; n++) {
28777618084SLudovic Desroches 		if (atmel_pioctrl->irqs[n] == irq) {
28877618084SLudovic Desroches 			bank = n;
28977618084SLudovic Desroches 			break;
29077618084SLudovic Desroches 		}
29177618084SLudovic Desroches 	}
29277618084SLudovic Desroches 
29377618084SLudovic Desroches 	if (bank < 0) {
29477618084SLudovic Desroches 		dev_err(atmel_pioctrl->dev,
29577618084SLudovic Desroches 			"no bank associated to irq %u\n", irq);
29677618084SLudovic Desroches 		return;
29777618084SLudovic Desroches 	}
29877618084SLudovic Desroches 
29977618084SLudovic Desroches 	chained_irq_enter(chip, desc);
30077618084SLudovic Desroches 
30177618084SLudovic Desroches 	for (;;) {
30277618084SLudovic Desroches 		isr = (unsigned long)atmel_gpio_read(atmel_pioctrl, bank,
30377618084SLudovic Desroches 						     ATMEL_PIO_ISR);
30477618084SLudovic Desroches 		isr &= (unsigned long)atmel_gpio_read(atmel_pioctrl, bank,
30577618084SLudovic Desroches 						      ATMEL_PIO_IMR);
30677618084SLudovic Desroches 		if (!isr)
30777618084SLudovic Desroches 			break;
30877618084SLudovic Desroches 
30977618084SLudovic Desroches 		for_each_set_bit(n, &isr, BITS_PER_LONG)
310e897b386SLinus Walleij 			generic_handle_irq(atmel_gpio_to_irq(
311e897b386SLinus Walleij 					atmel_pioctrl->gpio_chip,
312e897b386SLinus Walleij 					bank * ATMEL_PIO_NPINS_PER_BANK + n));
31377618084SLudovic Desroches 	}
31477618084SLudovic Desroches 
31577618084SLudovic Desroches 	chained_irq_exit(chip, desc);
31677618084SLudovic Desroches }
31777618084SLudovic Desroches 
atmel_gpio_direction_input(struct gpio_chip * chip,unsigned int offset)318b4435b42SClaudiu Beznea static int atmel_gpio_direction_input(struct gpio_chip *chip,
319b4435b42SClaudiu Beznea 				      unsigned int offset)
32077618084SLudovic Desroches {
32180036f88SLinus Walleij 	struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip);
32277618084SLudovic Desroches 	struct atmel_pin *pin = atmel_pioctrl->pins[offset];
323b4435b42SClaudiu Beznea 	unsigned int reg;
32477618084SLudovic Desroches 
32577618084SLudovic Desroches 	atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_MSKR,
32677618084SLudovic Desroches 			 BIT(pin->line));
32777618084SLudovic Desroches 	reg = atmel_gpio_read(atmel_pioctrl, pin->bank, ATMEL_PIO_CFGR);
32877618084SLudovic Desroches 	reg &= ~ATMEL_PIO_DIR_MASK;
32977618084SLudovic Desroches 	atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_CFGR, reg);
33077618084SLudovic Desroches 
33177618084SLudovic Desroches 	return 0;
33277618084SLudovic Desroches }
33377618084SLudovic Desroches 
atmel_gpio_get(struct gpio_chip * chip,unsigned int offset)334b4435b42SClaudiu Beznea static int atmel_gpio_get(struct gpio_chip *chip, unsigned int offset)
33577618084SLudovic Desroches {
33680036f88SLinus Walleij 	struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip);
33777618084SLudovic Desroches 	struct atmel_pin *pin = atmel_pioctrl->pins[offset];
338b4435b42SClaudiu Beznea 	unsigned int reg;
33977618084SLudovic Desroches 
34077618084SLudovic Desroches 	reg = atmel_gpio_read(atmel_pioctrl, pin->bank, ATMEL_PIO_PDSR);
34177618084SLudovic Desroches 
34277618084SLudovic Desroches 	return !!(reg & BIT(pin->line));
34377618084SLudovic Desroches }
34477618084SLudovic Desroches 
atmel_gpio_get_multiple(struct gpio_chip * chip,unsigned long * mask,unsigned long * bits)34509107a51SAlexandre Belloni static int atmel_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask,
34609107a51SAlexandre Belloni 				   unsigned long *bits)
34709107a51SAlexandre Belloni {
34809107a51SAlexandre Belloni 	struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip);
34909107a51SAlexandre Belloni 	unsigned int bank;
35009107a51SAlexandre Belloni 
35109107a51SAlexandre Belloni 	bitmap_zero(bits, atmel_pioctrl->npins);
35209107a51SAlexandre Belloni 
35309107a51SAlexandre Belloni 	for (bank = 0; bank < atmel_pioctrl->nbanks; bank++) {
35409107a51SAlexandre Belloni 		unsigned int word = bank;
35509107a51SAlexandre Belloni 		unsigned int offset = 0;
35609107a51SAlexandre Belloni 		unsigned int reg;
35709107a51SAlexandre Belloni 
35809107a51SAlexandre Belloni #if ATMEL_PIO_NPINS_PER_BANK != BITS_PER_LONG
35909107a51SAlexandre Belloni 		word = BIT_WORD(bank * ATMEL_PIO_NPINS_PER_BANK);
36009107a51SAlexandre Belloni 		offset = bank * ATMEL_PIO_NPINS_PER_BANK % BITS_PER_LONG;
36109107a51SAlexandre Belloni #endif
36209107a51SAlexandre Belloni 		if (!mask[word])
36309107a51SAlexandre Belloni 			continue;
36409107a51SAlexandre Belloni 
36509107a51SAlexandre Belloni 		reg = atmel_gpio_read(atmel_pioctrl, bank, ATMEL_PIO_PDSR);
36609107a51SAlexandre Belloni 		bits[word] |= mask[word] & (reg << offset);
36709107a51SAlexandre Belloni 	}
36809107a51SAlexandre Belloni 
36909107a51SAlexandre Belloni 	return 0;
37009107a51SAlexandre Belloni }
37109107a51SAlexandre Belloni 
atmel_gpio_direction_output(struct gpio_chip * chip,unsigned int offset,int value)372b4435b42SClaudiu Beznea static int atmel_gpio_direction_output(struct gpio_chip *chip,
373b4435b42SClaudiu Beznea 				       unsigned int offset,
37477618084SLudovic Desroches 				       int value)
37577618084SLudovic Desroches {
37680036f88SLinus Walleij 	struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip);
37777618084SLudovic Desroches 	struct atmel_pin *pin = atmel_pioctrl->pins[offset];
378b4435b42SClaudiu Beznea 	unsigned int reg;
37977618084SLudovic Desroches 
38077618084SLudovic Desroches 	atmel_gpio_write(atmel_pioctrl, pin->bank,
38177618084SLudovic Desroches 			 value ? ATMEL_PIO_SODR : ATMEL_PIO_CODR,
38277618084SLudovic Desroches 			 BIT(pin->line));
38377618084SLudovic Desroches 
38477618084SLudovic Desroches 	atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_MSKR,
38577618084SLudovic Desroches 			 BIT(pin->line));
38677618084SLudovic Desroches 	reg = atmel_gpio_read(atmel_pioctrl, pin->bank, ATMEL_PIO_CFGR);
38777618084SLudovic Desroches 	reg |= ATMEL_PIO_DIR_MASK;
38877618084SLudovic Desroches 	atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_CFGR, reg);
38977618084SLudovic Desroches 
39077618084SLudovic Desroches 	return 0;
39177618084SLudovic Desroches }
39277618084SLudovic Desroches 
atmel_gpio_set(struct gpio_chip * chip,unsigned int offset,int val)393b4435b42SClaudiu Beznea static void atmel_gpio_set(struct gpio_chip *chip, unsigned int offset, int val)
39477618084SLudovic Desroches {
39580036f88SLinus Walleij 	struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip);
39677618084SLudovic Desroches 	struct atmel_pin *pin = atmel_pioctrl->pins[offset];
39777618084SLudovic Desroches 
39877618084SLudovic Desroches 	atmel_gpio_write(atmel_pioctrl, pin->bank,
39977618084SLudovic Desroches 			 val ? ATMEL_PIO_SODR : ATMEL_PIO_CODR,
40077618084SLudovic Desroches 			 BIT(pin->line));
40177618084SLudovic Desroches }
40277618084SLudovic Desroches 
atmel_gpio_set_multiple(struct gpio_chip * chip,unsigned long * mask,unsigned long * bits)40309107a51SAlexandre Belloni static void atmel_gpio_set_multiple(struct gpio_chip *chip, unsigned long *mask,
40409107a51SAlexandre Belloni 				    unsigned long *bits)
40509107a51SAlexandre Belloni {
40609107a51SAlexandre Belloni 	struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip);
40709107a51SAlexandre Belloni 	unsigned int bank;
40809107a51SAlexandre Belloni 
40909107a51SAlexandre Belloni 	for (bank = 0; bank < atmel_pioctrl->nbanks; bank++) {
41009107a51SAlexandre Belloni 		unsigned int bitmask;
41109107a51SAlexandre Belloni 		unsigned int word = bank;
41209107a51SAlexandre Belloni 
41309107a51SAlexandre Belloni /*
41409107a51SAlexandre Belloni  * On a 64-bit platform, BITS_PER_LONG is 64 so it is necessary to iterate over
41509107a51SAlexandre Belloni  * two 32bit words to handle the whole  bitmask
41609107a51SAlexandre Belloni  */
41709107a51SAlexandre Belloni #if ATMEL_PIO_NPINS_PER_BANK != BITS_PER_LONG
41809107a51SAlexandre Belloni 		word = BIT_WORD(bank * ATMEL_PIO_NPINS_PER_BANK);
41909107a51SAlexandre Belloni #endif
42009107a51SAlexandre Belloni 		if (!mask[word])
42109107a51SAlexandre Belloni 			continue;
42209107a51SAlexandre Belloni 
42309107a51SAlexandre Belloni 		bitmask = mask[word] & bits[word];
42409107a51SAlexandre Belloni 		atmel_gpio_write(atmel_pioctrl, bank, ATMEL_PIO_SODR, bitmask);
42509107a51SAlexandre Belloni 
42609107a51SAlexandre Belloni 		bitmask = mask[word] & ~bits[word];
42709107a51SAlexandre Belloni 		atmel_gpio_write(atmel_pioctrl, bank, ATMEL_PIO_CODR, bitmask);
42809107a51SAlexandre Belloni 
42909107a51SAlexandre Belloni #if ATMEL_PIO_NPINS_PER_BANK != BITS_PER_LONG
43009107a51SAlexandre Belloni 		mask[word] >>= ATMEL_PIO_NPINS_PER_BANK;
43109107a51SAlexandre Belloni 		bits[word] >>= ATMEL_PIO_NPINS_PER_BANK;
43209107a51SAlexandre Belloni #endif
43309107a51SAlexandre Belloni 	}
43409107a51SAlexandre Belloni }
43509107a51SAlexandre Belloni 
43677618084SLudovic Desroches static struct gpio_chip atmel_gpio_chip = {
43777618084SLudovic Desroches 	.direction_input        = atmel_gpio_direction_input,
43877618084SLudovic Desroches 	.get                    = atmel_gpio_get,
43909107a51SAlexandre Belloni 	.get_multiple           = atmel_gpio_get_multiple,
44077618084SLudovic Desroches 	.direction_output       = atmel_gpio_direction_output,
44177618084SLudovic Desroches 	.set                    = atmel_gpio_set,
44209107a51SAlexandre Belloni 	.set_multiple           = atmel_gpio_set_multiple,
44377618084SLudovic Desroches 	.to_irq                 = atmel_gpio_to_irq,
44477618084SLudovic Desroches 	.base                   = 0,
44577618084SLudovic Desroches };
44677618084SLudovic Desroches 
44777618084SLudovic Desroches /* --- PINCTRL --- */
atmel_pin_config_read(struct pinctrl_dev * pctldev,unsigned int pin_id)44877618084SLudovic Desroches static unsigned int atmel_pin_config_read(struct pinctrl_dev *pctldev,
449b4435b42SClaudiu Beznea 					  unsigned int pin_id)
45077618084SLudovic Desroches {
45177618084SLudovic Desroches 	struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
452b4435b42SClaudiu Beznea 	unsigned int bank = atmel_pioctrl->pins[pin_id]->bank;
453b4435b42SClaudiu Beznea 	unsigned int line = atmel_pioctrl->pins[pin_id]->line;
45477618084SLudovic Desroches 	void __iomem *addr = atmel_pioctrl->reg_base
45577618084SLudovic Desroches 			     + bank * ATMEL_PIO_BANK_OFFSET;
45677618084SLudovic Desroches 
45777618084SLudovic Desroches 	writel_relaxed(BIT(line), addr + ATMEL_PIO_MSKR);
45877618084SLudovic Desroches 	/* Have to set MSKR first, to access the right pin CFGR. */
45977618084SLudovic Desroches 	wmb();
46077618084SLudovic Desroches 
46177618084SLudovic Desroches 	return readl_relaxed(addr + ATMEL_PIO_CFGR);
46277618084SLudovic Desroches }
46377618084SLudovic Desroches 
atmel_pin_config_write(struct pinctrl_dev * pctldev,unsigned int pin_id,u32 conf)46477618084SLudovic Desroches static void atmel_pin_config_write(struct pinctrl_dev *pctldev,
465b4435b42SClaudiu Beznea 				   unsigned int pin_id, u32 conf)
46677618084SLudovic Desroches {
46777618084SLudovic Desroches 	struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
468b4435b42SClaudiu Beznea 	unsigned int bank = atmel_pioctrl->pins[pin_id]->bank;
469b4435b42SClaudiu Beznea 	unsigned int line = atmel_pioctrl->pins[pin_id]->line;
47077618084SLudovic Desroches 	void __iomem *addr = atmel_pioctrl->reg_base
47177618084SLudovic Desroches 			     + bank * ATMEL_PIO_BANK_OFFSET;
47277618084SLudovic Desroches 
47377618084SLudovic Desroches 	writel_relaxed(BIT(line), addr + ATMEL_PIO_MSKR);
47477618084SLudovic Desroches 	/* Have to set MSKR first, to access the right pin CFGR. */
47577618084SLudovic Desroches 	wmb();
47677618084SLudovic Desroches 	writel_relaxed(conf, addr + ATMEL_PIO_CFGR);
47777618084SLudovic Desroches }
47877618084SLudovic Desroches 
atmel_pctl_get_groups_count(struct pinctrl_dev * pctldev)47977618084SLudovic Desroches static int atmel_pctl_get_groups_count(struct pinctrl_dev *pctldev)
48077618084SLudovic Desroches {
48177618084SLudovic Desroches 	struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
48277618084SLudovic Desroches 
48377618084SLudovic Desroches 	return atmel_pioctrl->npins;
48477618084SLudovic Desroches }
48577618084SLudovic Desroches 
atmel_pctl_get_group_name(struct pinctrl_dev * pctldev,unsigned int selector)48677618084SLudovic Desroches static const char *atmel_pctl_get_group_name(struct pinctrl_dev *pctldev,
487b4435b42SClaudiu Beznea 					     unsigned int selector)
48877618084SLudovic Desroches {
48977618084SLudovic Desroches 	struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
49077618084SLudovic Desroches 
49177618084SLudovic Desroches 	return atmel_pioctrl->groups[selector].name;
49277618084SLudovic Desroches }
49377618084SLudovic Desroches 
atmel_pctl_get_group_pins(struct pinctrl_dev * pctldev,unsigned int selector,const unsigned int ** pins,unsigned int * num_pins)49477618084SLudovic Desroches static int atmel_pctl_get_group_pins(struct pinctrl_dev *pctldev,
495b4435b42SClaudiu Beznea 				     unsigned int selector,
496b4435b42SClaudiu Beznea 				     const unsigned int **pins,
497b4435b42SClaudiu Beznea 				     unsigned int *num_pins)
49877618084SLudovic Desroches {
49977618084SLudovic Desroches 	struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
50077618084SLudovic Desroches 
501b4435b42SClaudiu Beznea 	*pins = (unsigned int *)&atmel_pioctrl->groups[selector].pin;
50277618084SLudovic Desroches 	*num_pins = 1;
50377618084SLudovic Desroches 
50477618084SLudovic Desroches 	return 0;
50577618084SLudovic Desroches }
50677618084SLudovic Desroches 
507682d68b8SBen Dooks static struct atmel_group *
atmel_pctl_find_group_by_pin(struct pinctrl_dev * pctldev,unsigned int pin)508b4435b42SClaudiu Beznea atmel_pctl_find_group_by_pin(struct pinctrl_dev *pctldev, unsigned int pin)
50977618084SLudovic Desroches {
51077618084SLudovic Desroches 	struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
51177618084SLudovic Desroches 	int i;
51277618084SLudovic Desroches 
51377618084SLudovic Desroches 	for (i = 0; i < atmel_pioctrl->npins; i++) {
51477618084SLudovic Desroches 		struct atmel_group *grp = atmel_pioctrl->groups + i;
51577618084SLudovic Desroches 
51677618084SLudovic Desroches 		if (grp->pin == pin)
51777618084SLudovic Desroches 			return grp;
51877618084SLudovic Desroches 	}
51977618084SLudovic Desroches 
52077618084SLudovic Desroches 	return NULL;
52177618084SLudovic Desroches }
52277618084SLudovic Desroches 
atmel_pctl_xlate_pinfunc(struct pinctrl_dev * pctldev,struct device_node * np,u32 pinfunc,const char ** grp_name,const char ** func_name)52377618084SLudovic Desroches static int atmel_pctl_xlate_pinfunc(struct pinctrl_dev *pctldev,
52477618084SLudovic Desroches 				    struct device_node *np,
52577618084SLudovic Desroches 				    u32 pinfunc, const char **grp_name,
52677618084SLudovic Desroches 				    const char **func_name)
52777618084SLudovic Desroches {
52877618084SLudovic Desroches 	struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
529b4435b42SClaudiu Beznea 	unsigned int pin_id, func_id;
53077618084SLudovic Desroches 	struct atmel_group *grp;
53177618084SLudovic Desroches 
53277618084SLudovic Desroches 	pin_id = ATMEL_GET_PIN_NO(pinfunc);
53377618084SLudovic Desroches 	func_id = ATMEL_GET_PIN_FUNC(pinfunc);
53477618084SLudovic Desroches 
53577618084SLudovic Desroches 	if (func_id >= ARRAY_SIZE(atmel_functions))
53677618084SLudovic Desroches 		return -EINVAL;
53777618084SLudovic Desroches 
53877618084SLudovic Desroches 	*func_name = atmel_functions[func_id];
53977618084SLudovic Desroches 
54077618084SLudovic Desroches 	grp = atmel_pctl_find_group_by_pin(pctldev, pin_id);
54177618084SLudovic Desroches 	if (!grp)
54277618084SLudovic Desroches 		return -EINVAL;
54377618084SLudovic Desroches 	*grp_name = grp->name;
54477618084SLudovic Desroches 
54577618084SLudovic Desroches 	atmel_pioctrl->pins[pin_id]->mux = func_id;
54677618084SLudovic Desroches 	atmel_pioctrl->pins[pin_id]->ioset = ATMEL_GET_PIN_IOSET(pinfunc);
54777618084SLudovic Desroches 	/* Want the device name not the group one. */
54877618084SLudovic Desroches 	if (np->parent == atmel_pioctrl->node)
54977618084SLudovic Desroches 		atmel_pioctrl->pins[pin_id]->device = np->name;
55077618084SLudovic Desroches 	else
55177618084SLudovic Desroches 		atmel_pioctrl->pins[pin_id]->device = np->parent->name;
55277618084SLudovic Desroches 
55377618084SLudovic Desroches 	return 0;
55477618084SLudovic Desroches }
55577618084SLudovic Desroches 
atmel_pctl_dt_subnode_to_map(struct pinctrl_dev * pctldev,struct device_node * np,struct pinctrl_map ** map,unsigned int * reserved_maps,unsigned int * num_maps)55677618084SLudovic Desroches static int atmel_pctl_dt_subnode_to_map(struct pinctrl_dev *pctldev,
55777618084SLudovic Desroches 					struct device_node *np,
55877618084SLudovic Desroches 					struct pinctrl_map **map,
559b4435b42SClaudiu Beznea 					unsigned int *reserved_maps,
560b4435b42SClaudiu Beznea 					unsigned int *num_maps)
56177618084SLudovic Desroches {
562b4435b42SClaudiu Beznea 	unsigned int num_pins, num_configs, reserve;
56377618084SLudovic Desroches 	unsigned long *configs;
56477618084SLudovic Desroches 	struct property	*pins;
56577618084SLudovic Desroches 	u32 pinfunc;
56677618084SLudovic Desroches 	int ret, i;
56777618084SLudovic Desroches 
56877618084SLudovic Desroches 	pins = of_find_property(np, "pinmux", NULL);
56977618084SLudovic Desroches 	if (!pins)
57077618084SLudovic Desroches 		return -EINVAL;
57177618084SLudovic Desroches 
57277618084SLudovic Desroches 	ret = pinconf_generic_parse_dt_config(np, pctldev, &configs,
57377618084SLudovic Desroches 					      &num_configs);
57477618084SLudovic Desroches 	if (ret < 0) {
575f5292d06SRob Herring 		dev_err(pctldev->dev, "%pOF: could not parse node property\n",
576f5292d06SRob Herring 			np);
57777618084SLudovic Desroches 		return ret;
57877618084SLudovic Desroches 	}
57977618084SLudovic Desroches 
58077618084SLudovic Desroches 	num_pins = pins->length / sizeof(u32);
58177618084SLudovic Desroches 	if (!num_pins) {
582f5292d06SRob Herring 		dev_err(pctldev->dev, "no pins found in node %pOF\n", np);
583e43d2b75SLudovic Desroches 		ret = -EINVAL;
584e43d2b75SLudovic Desroches 		goto exit;
58577618084SLudovic Desroches 	}
58677618084SLudovic Desroches 
58777618084SLudovic Desroches 	/*
58877618084SLudovic Desroches 	 * Reserve maps, at least there is a mux map and an optional conf
58977618084SLudovic Desroches 	 * map for each pin.
59077618084SLudovic Desroches 	 */
59177618084SLudovic Desroches 	reserve = 1;
592b97760aeSDan Carpenter 	if (num_configs)
59377618084SLudovic Desroches 		reserve++;
59477618084SLudovic Desroches 	reserve *= num_pins;
59577618084SLudovic Desroches 	ret = pinctrl_utils_reserve_map(pctldev, map, reserved_maps, num_maps,
59677618084SLudovic Desroches 					reserve);
59777618084SLudovic Desroches 	if (ret < 0)
598e43d2b75SLudovic Desroches 		goto exit;
59977618084SLudovic Desroches 
60077618084SLudovic Desroches 	for (i = 0; i < num_pins; i++) {
60177618084SLudovic Desroches 		const char *group, *func;
60277618084SLudovic Desroches 
60377618084SLudovic Desroches 		ret = of_property_read_u32_index(np, "pinmux", i, &pinfunc);
60477618084SLudovic Desroches 		if (ret)
605e43d2b75SLudovic Desroches 			goto exit;
60677618084SLudovic Desroches 
60777618084SLudovic Desroches 		ret = atmel_pctl_xlate_pinfunc(pctldev, np, pinfunc, &group,
60877618084SLudovic Desroches 					       &func);
60977618084SLudovic Desroches 		if (ret)
610e43d2b75SLudovic Desroches 			goto exit;
61177618084SLudovic Desroches 
61277618084SLudovic Desroches 		pinctrl_utils_add_map_mux(pctldev, map, reserved_maps, num_maps,
61377618084SLudovic Desroches 					  group, func);
61477618084SLudovic Desroches 
615b97760aeSDan Carpenter 		if (num_configs) {
61677618084SLudovic Desroches 			ret = pinctrl_utils_add_map_configs(pctldev, map,
61777618084SLudovic Desroches 					reserved_maps, num_maps, group,
61877618084SLudovic Desroches 					configs, num_configs,
61977618084SLudovic Desroches 					PIN_MAP_TYPE_CONFIGS_GROUP);
62077618084SLudovic Desroches 			if (ret < 0)
621e43d2b75SLudovic Desroches 				goto exit;
62277618084SLudovic Desroches 		}
62377618084SLudovic Desroches 	}
62477618084SLudovic Desroches 
625e43d2b75SLudovic Desroches exit:
626e43d2b75SLudovic Desroches 	kfree(configs);
627e43d2b75SLudovic Desroches 	return ret;
62877618084SLudovic Desroches }
62977618084SLudovic Desroches 
atmel_pctl_dt_node_to_map(struct pinctrl_dev * pctldev,struct device_node * np_config,struct pinctrl_map ** map,unsigned int * num_maps)63077618084SLudovic Desroches static int atmel_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
63177618084SLudovic Desroches 				     struct device_node *np_config,
63277618084SLudovic Desroches 				     struct pinctrl_map **map,
633b4435b42SClaudiu Beznea 				     unsigned int *num_maps)
63477618084SLudovic Desroches {
635b4435b42SClaudiu Beznea 	unsigned int reserved_maps;
63677618084SLudovic Desroches 	int ret;
63777618084SLudovic Desroches 
63877618084SLudovic Desroches 	*map = NULL;
63977618084SLudovic Desroches 	*num_maps = 0;
64077618084SLudovic Desroches 	reserved_maps = 0;
64177618084SLudovic Desroches 
64277618084SLudovic Desroches 	/*
64377618084SLudovic Desroches 	 * If all the pins of a device have the same configuration (or no one),
64477618084SLudovic Desroches 	 * it is useless to add a subnode, so directly parse node referenced by
64577618084SLudovic Desroches 	 * phandle.
64677618084SLudovic Desroches 	 */
64777618084SLudovic Desroches 	ret = atmel_pctl_dt_subnode_to_map(pctldev, np_config, map,
64877618084SLudovic Desroches 					   &reserved_maps, num_maps);
64977618084SLudovic Desroches 	if (ret) {
650*7c2aabb5SPeng Fan 		for_each_child_of_node_scoped(np_config, np) {
65177618084SLudovic Desroches 			ret = atmel_pctl_dt_subnode_to_map(pctldev, np, map,
65277618084SLudovic Desroches 						    &reserved_maps, num_maps);
653*7c2aabb5SPeng Fan 			if (ret < 0)
65477618084SLudovic Desroches 				break;
65577618084SLudovic Desroches 		}
65677618084SLudovic Desroches 	}
65777618084SLudovic Desroches 
65877618084SLudovic Desroches 	if (ret < 0) {
659d32f7fd3SIrina Tirdea 		pinctrl_utils_free_map(pctldev, *map, *num_maps);
660f5292d06SRob Herring 		dev_err(pctldev->dev, "can't create maps for node %pOF\n",
661f5292d06SRob Herring 			np_config);
66277618084SLudovic Desroches 	}
66377618084SLudovic Desroches 
66477618084SLudovic Desroches 	return ret;
66577618084SLudovic Desroches }
66677618084SLudovic Desroches 
66777618084SLudovic Desroches static const struct pinctrl_ops atmel_pctlops = {
66877618084SLudovic Desroches 	.get_groups_count	= atmel_pctl_get_groups_count,
66977618084SLudovic Desroches 	.get_group_name		= atmel_pctl_get_group_name,
67077618084SLudovic Desroches 	.get_group_pins		= atmel_pctl_get_group_pins,
67177618084SLudovic Desroches 	.dt_node_to_map		= atmel_pctl_dt_node_to_map,
672d32f7fd3SIrina Tirdea 	.dt_free_map		= pinctrl_utils_free_map,
67377618084SLudovic Desroches };
67477618084SLudovic Desroches 
atmel_pmx_get_functions_count(struct pinctrl_dev * pctldev)67577618084SLudovic Desroches static int atmel_pmx_get_functions_count(struct pinctrl_dev *pctldev)
67677618084SLudovic Desroches {
67777618084SLudovic Desroches 	return ARRAY_SIZE(atmel_functions);
67877618084SLudovic Desroches }
67977618084SLudovic Desroches 
atmel_pmx_get_function_name(struct pinctrl_dev * pctldev,unsigned int selector)68077618084SLudovic Desroches static const char *atmel_pmx_get_function_name(struct pinctrl_dev *pctldev,
681b4435b42SClaudiu Beznea 					       unsigned int selector)
68277618084SLudovic Desroches {
68377618084SLudovic Desroches 	return atmel_functions[selector];
68477618084SLudovic Desroches }
68577618084SLudovic Desroches 
atmel_pmx_get_function_groups(struct pinctrl_dev * pctldev,unsigned int selector,const char * const ** groups,unsigned * const num_groups)68677618084SLudovic Desroches static int atmel_pmx_get_function_groups(struct pinctrl_dev *pctldev,
687b4435b42SClaudiu Beznea 					 unsigned int selector,
68877618084SLudovic Desroches 					 const char * const **groups,
68977618084SLudovic Desroches 					 unsigned * const num_groups)
69077618084SLudovic Desroches {
69177618084SLudovic Desroches 	struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
69277618084SLudovic Desroches 
69377618084SLudovic Desroches 	*groups = atmel_pioctrl->group_names;
69477618084SLudovic Desroches 	*num_groups = atmel_pioctrl->npins;
69577618084SLudovic Desroches 
69677618084SLudovic Desroches 	return 0;
69777618084SLudovic Desroches }
69877618084SLudovic Desroches 
atmel_pmx_set_mux(struct pinctrl_dev * pctldev,unsigned int function,unsigned int group)69977618084SLudovic Desroches static int atmel_pmx_set_mux(struct pinctrl_dev *pctldev,
700b4435b42SClaudiu Beznea 			     unsigned int function,
701b4435b42SClaudiu Beznea 			     unsigned int group)
70277618084SLudovic Desroches {
70377618084SLudovic Desroches 	struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
704b4435b42SClaudiu Beznea 	unsigned int pin;
70577618084SLudovic Desroches 	u32 conf;
70677618084SLudovic Desroches 
70777618084SLudovic Desroches 	dev_dbg(pctldev->dev, "enable function %s group %s\n",
70877618084SLudovic Desroches 		atmel_functions[function], atmel_pioctrl->groups[group].name);
70977618084SLudovic Desroches 
71077618084SLudovic Desroches 	pin = atmel_pioctrl->groups[group].pin;
71177618084SLudovic Desroches 	conf = atmel_pin_config_read(pctldev, pin);
71277618084SLudovic Desroches 	conf &= (~ATMEL_PIO_CFGR_FUNC_MASK);
71377618084SLudovic Desroches 	conf |= (function & ATMEL_PIO_CFGR_FUNC_MASK);
71477618084SLudovic Desroches 	dev_dbg(pctldev->dev, "pin: %u, conf: 0x%08x\n", pin, conf);
71577618084SLudovic Desroches 	atmel_pin_config_write(pctldev, pin, conf);
71677618084SLudovic Desroches 
71777618084SLudovic Desroches 	return 0;
71877618084SLudovic Desroches }
71977618084SLudovic Desroches 
72077618084SLudovic Desroches static const struct pinmux_ops atmel_pmxops = {
72177618084SLudovic Desroches 	.get_functions_count	= atmel_pmx_get_functions_count,
72277618084SLudovic Desroches 	.get_function_name	= atmel_pmx_get_function_name,
72377618084SLudovic Desroches 	.get_function_groups	= atmel_pmx_get_function_groups,
72477618084SLudovic Desroches 	.set_mux		= atmel_pmx_set_mux,
72577618084SLudovic Desroches };
72677618084SLudovic Desroches 
atmel_conf_pin_config_group_get(struct pinctrl_dev * pctldev,unsigned int group,unsigned long * config)72777618084SLudovic Desroches static int atmel_conf_pin_config_group_get(struct pinctrl_dev *pctldev,
728b4435b42SClaudiu Beznea 					   unsigned int group,
72977618084SLudovic Desroches 					   unsigned long *config)
73077618084SLudovic Desroches {
73177618084SLudovic Desroches 	struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
732b4435b42SClaudiu Beznea 	unsigned int param = pinconf_to_config_param(*config), arg = 0;
73377618084SLudovic Desroches 	struct atmel_group *grp = atmel_pioctrl->groups + group;
734b4435b42SClaudiu Beznea 	unsigned int pin_id = grp->pin;
73577618084SLudovic Desroches 	u32 res;
73677618084SLudovic Desroches 
73777618084SLudovic Desroches 	res = atmel_pin_config_read(pctldev, pin_id);
73877618084SLudovic Desroches 
73977618084SLudovic Desroches 	switch (param) {
74077618084SLudovic Desroches 	case PIN_CONFIG_BIAS_PULL_UP:
74177618084SLudovic Desroches 		if (!(res & ATMEL_PIO_PUEN_MASK))
74277618084SLudovic Desroches 			return -EINVAL;
74377618084SLudovic Desroches 		arg = 1;
74477618084SLudovic Desroches 		break;
74577618084SLudovic Desroches 	case PIN_CONFIG_BIAS_PULL_DOWN:
74677618084SLudovic Desroches 		if ((res & ATMEL_PIO_PUEN_MASK) ||
74777618084SLudovic Desroches 		    (!(res & ATMEL_PIO_PDEN_MASK)))
74877618084SLudovic Desroches 			return -EINVAL;
74977618084SLudovic Desroches 		arg = 1;
75077618084SLudovic Desroches 		break;
75177618084SLudovic Desroches 	case PIN_CONFIG_BIAS_DISABLE:
75277618084SLudovic Desroches 		if ((res & ATMEL_PIO_PUEN_MASK) ||
75377618084SLudovic Desroches 		    ((res & ATMEL_PIO_PDEN_MASK)))
75477618084SLudovic Desroches 			return -EINVAL;
75577618084SLudovic Desroches 		arg = 1;
75677618084SLudovic Desroches 		break;
75777618084SLudovic Desroches 	case PIN_CONFIG_DRIVE_OPEN_DRAIN:
75877618084SLudovic Desroches 		if (!(res & ATMEL_PIO_OPD_MASK))
75977618084SLudovic Desroches 			return -EINVAL;
76077618084SLudovic Desroches 		arg = 1;
76177618084SLudovic Desroches 		break;
762772be1daSRyan Wanner 	case PIN_CONFIG_DRIVE_PUSH_PULL:
763772be1daSRyan Wanner 		if (res & ATMEL_PIO_OPD_MASK)
764772be1daSRyan Wanner 			return -EINVAL;
765772be1daSRyan Wanner 		arg = 1;
766772be1daSRyan Wanner 		break;
76777618084SLudovic Desroches 	case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
76877618084SLudovic Desroches 		if (!(res & ATMEL_PIO_SCHMITT_MASK))
76977618084SLudovic Desroches 			return -EINVAL;
77077618084SLudovic Desroches 		arg = 1;
77177618084SLudovic Desroches 		break;
772c709135eSClaudiu Beznea 	case PIN_CONFIG_SLEW_RATE:
773c709135eSClaudiu Beznea 		if (!atmel_pioctrl->slew_rate_support)
774c709135eSClaudiu Beznea 			return -EOPNOTSUPP;
775c709135eSClaudiu Beznea 		if (!(res & ATMEL_PIO_SR_MASK))
776c709135eSClaudiu Beznea 			return -EINVAL;
777c709135eSClaudiu Beznea 		arg = 1;
778c709135eSClaudiu Beznea 		break;
779ff10e353SLudovic Desroches 	case ATMEL_PIN_CONFIG_DRIVE_STRENGTH:
780ff10e353SLudovic Desroches 		if (!(res & ATMEL_PIO_DRVSTR_MASK))
781ff10e353SLudovic Desroches 			return -EINVAL;
782ff10e353SLudovic Desroches 		arg = (res & ATMEL_PIO_DRVSTR_MASK) >> ATMEL_PIO_DRVSTR_OFFSET;
783ff10e353SLudovic Desroches 		break;
784eaa4c8f9SRyan Wanner 	case PIN_CONFIG_PERSIST_STATE:
785eaa4c8f9SRyan Wanner 		return -ENOTSUPP;
78677618084SLudovic Desroches 	default:
78777618084SLudovic Desroches 		return -ENOTSUPP;
78877618084SLudovic Desroches 	}
78977618084SLudovic Desroches 
79077618084SLudovic Desroches 	*config = pinconf_to_config_packed(param, arg);
79177618084SLudovic Desroches 	return 0;
79277618084SLudovic Desroches }
79377618084SLudovic Desroches 
atmel_conf_pin_config_group_set(struct pinctrl_dev * pctldev,unsigned int group,unsigned long * configs,unsigned int num_configs)79477618084SLudovic Desroches static int atmel_conf_pin_config_group_set(struct pinctrl_dev *pctldev,
795b4435b42SClaudiu Beznea 					   unsigned int group,
79677618084SLudovic Desroches 					   unsigned long *configs,
797b4435b42SClaudiu Beznea 					   unsigned int num_configs)
79877618084SLudovic Desroches {
79977618084SLudovic Desroches 	struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
80077618084SLudovic Desroches 	struct atmel_group *grp = atmel_pioctrl->groups + group;
801b4435b42SClaudiu Beznea 	unsigned int bank, pin, pin_id = grp->pin;
80277618084SLudovic Desroches 	u32 mask, conf = 0;
80377618084SLudovic Desroches 	int i;
80477618084SLudovic Desroches 
80577618084SLudovic Desroches 	conf = atmel_pin_config_read(pctldev, pin_id);
80677618084SLudovic Desroches 
807cbde6c82STudor Ambarus 	/* Keep slew rate enabled by default. */
808cbde6c82STudor Ambarus 	if (atmel_pioctrl->slew_rate_support)
809cbde6c82STudor Ambarus 		conf |= ATMEL_PIO_SR_MASK;
810cbde6c82STudor Ambarus 
81177618084SLudovic Desroches 	for (i = 0; i < num_configs; i++) {
812b4435b42SClaudiu Beznea 		unsigned int param = pinconf_to_config_param(configs[i]);
813b4435b42SClaudiu Beznea 		unsigned int arg = pinconf_to_config_argument(configs[i]);
81477618084SLudovic Desroches 
81577618084SLudovic Desroches 		dev_dbg(pctldev->dev, "%s: pin=%u, config=0x%lx\n",
81677618084SLudovic Desroches 			__func__, pin_id, configs[i]);
81777618084SLudovic Desroches 
81877618084SLudovic Desroches 		switch (param) {
81977618084SLudovic Desroches 		case PIN_CONFIG_BIAS_DISABLE:
82077618084SLudovic Desroches 			conf &= (~ATMEL_PIO_PUEN_MASK);
82177618084SLudovic Desroches 			conf &= (~ATMEL_PIO_PDEN_MASK);
82277618084SLudovic Desroches 			break;
82377618084SLudovic Desroches 		case PIN_CONFIG_BIAS_PULL_UP:
82477618084SLudovic Desroches 			conf |= ATMEL_PIO_PUEN_MASK;
8255305a7b7SLudovic Desroches 			conf &= (~ATMEL_PIO_PDEN_MASK);
82677618084SLudovic Desroches 			break;
82777618084SLudovic Desroches 		case PIN_CONFIG_BIAS_PULL_DOWN:
82877618084SLudovic Desroches 			conf |= ATMEL_PIO_PDEN_MASK;
8295305a7b7SLudovic Desroches 			conf &= (~ATMEL_PIO_PUEN_MASK);
83077618084SLudovic Desroches 			break;
83177618084SLudovic Desroches 		case PIN_CONFIG_DRIVE_OPEN_DRAIN:
83277618084SLudovic Desroches 			conf |= ATMEL_PIO_OPD_MASK;
83377618084SLudovic Desroches 			break;
834772be1daSRyan Wanner 		case PIN_CONFIG_DRIVE_PUSH_PULL:
835772be1daSRyan Wanner 			conf &= ~ATMEL_PIO_OPD_MASK;
836772be1daSRyan Wanner 			break;
83777618084SLudovic Desroches 		case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
83877618084SLudovic Desroches 			if (arg == 0)
83977618084SLudovic Desroches 				conf |= ATMEL_PIO_SCHMITT_MASK;
84077618084SLudovic Desroches 			else
84177618084SLudovic Desroches 				conf &= (~ATMEL_PIO_SCHMITT_MASK);
84277618084SLudovic Desroches 			break;
84377618084SLudovic Desroches 		case PIN_CONFIG_INPUT_DEBOUNCE:
84477618084SLudovic Desroches 			if (arg == 0) {
84577618084SLudovic Desroches 				conf &= (~ATMEL_PIO_IFEN_MASK);
84677618084SLudovic Desroches 				conf &= (~ATMEL_PIO_IFSCEN_MASK);
84777618084SLudovic Desroches 			} else {
84877618084SLudovic Desroches 				/*
84977618084SLudovic Desroches 				 * We don't care about the debounce value for several reasons:
85077618084SLudovic Desroches 				 * - can't have different debounce periods inside a same group,
85177618084SLudovic Desroches 				 * - the register to configure this period is a secure register.
85277618084SLudovic Desroches 				 * The debouncing filter can filter a pulse with a duration of less
85377618084SLudovic Desroches 				 * than 1/2 slow clock period.
85477618084SLudovic Desroches 				 */
85577618084SLudovic Desroches 				conf |= ATMEL_PIO_IFEN_MASK;
85677618084SLudovic Desroches 				conf |= ATMEL_PIO_IFSCEN_MASK;
85777618084SLudovic Desroches 			}
85877618084SLudovic Desroches 			break;
85977618084SLudovic Desroches 		case PIN_CONFIG_OUTPUT:
86077618084SLudovic Desroches 			conf |= ATMEL_PIO_DIR_MASK;
86177618084SLudovic Desroches 			bank = ATMEL_PIO_BANK(pin_id);
86277618084SLudovic Desroches 			pin = ATMEL_PIO_LINE(pin_id);
86377618084SLudovic Desroches 			mask = 1 << pin;
86477618084SLudovic Desroches 
86577618084SLudovic Desroches 			if (arg == 0) {
86677618084SLudovic Desroches 				writel_relaxed(mask, atmel_pioctrl->reg_base +
86777618084SLudovic Desroches 					bank * ATMEL_PIO_BANK_OFFSET +
86877618084SLudovic Desroches 					ATMEL_PIO_CODR);
86977618084SLudovic Desroches 			} else {
87077618084SLudovic Desroches 				writel_relaxed(mask, atmel_pioctrl->reg_base +
87177618084SLudovic Desroches 					bank * ATMEL_PIO_BANK_OFFSET +
87277618084SLudovic Desroches 					ATMEL_PIO_SODR);
87377618084SLudovic Desroches 			}
87477618084SLudovic Desroches 			break;
875c709135eSClaudiu Beznea 		case PIN_CONFIG_SLEW_RATE:
876c709135eSClaudiu Beznea 			if (!atmel_pioctrl->slew_rate_support)
877c709135eSClaudiu Beznea 				break;
878c709135eSClaudiu Beznea 			/* And remove it if explicitly requested. */
879c709135eSClaudiu Beznea 			if (arg == 0)
880c709135eSClaudiu Beznea 				conf &= ~ATMEL_PIO_SR_MASK;
881c709135eSClaudiu Beznea 			break;
882ff10e353SLudovic Desroches 		case ATMEL_PIN_CONFIG_DRIVE_STRENGTH:
883ff10e353SLudovic Desroches 			switch (arg) {
884ff10e353SLudovic Desroches 			case ATMEL_PIO_DRVSTR_LO:
885ff10e353SLudovic Desroches 			case ATMEL_PIO_DRVSTR_ME:
886ff10e353SLudovic Desroches 			case ATMEL_PIO_DRVSTR_HI:
887ff10e353SLudovic Desroches 				conf &= (~ATMEL_PIO_DRVSTR_MASK);
888ff10e353SLudovic Desroches 				conf |= arg << ATMEL_PIO_DRVSTR_OFFSET;
889ff10e353SLudovic Desroches 				break;
890ff10e353SLudovic Desroches 			default:
891ff10e353SLudovic Desroches 				dev_warn(pctldev->dev, "drive strength not updated (incorrect value)\n");
892ff10e353SLudovic Desroches 			}
893ff10e353SLudovic Desroches 			break;
894eaa4c8f9SRyan Wanner 		case PIN_CONFIG_PERSIST_STATE:
895eaa4c8f9SRyan Wanner 			return -ENOTSUPP;
89677618084SLudovic Desroches 		default:
89777618084SLudovic Desroches 			dev_warn(pctldev->dev,
89877618084SLudovic Desroches 				 "unsupported configuration parameter: %u\n",
89977618084SLudovic Desroches 				 param);
90077618084SLudovic Desroches 			continue;
90177618084SLudovic Desroches 		}
90277618084SLudovic Desroches 	}
90377618084SLudovic Desroches 
90477618084SLudovic Desroches 	dev_dbg(pctldev->dev, "%s: reg=0x%08x\n", __func__, conf);
90577618084SLudovic Desroches 	atmel_pin_config_write(pctldev, pin_id, conf);
90677618084SLudovic Desroches 
90777618084SLudovic Desroches 	return 0;
90877618084SLudovic Desroches }
90977618084SLudovic Desroches 
atmel_conf_pin_config_set(struct pinctrl_dev * pctldev,unsigned pin,unsigned long * configs,unsigned num_configs)910fcd76317SRyan Wanner static int atmel_conf_pin_config_set(struct pinctrl_dev *pctldev,
911fcd76317SRyan Wanner 				     unsigned pin,
912fcd76317SRyan Wanner 				     unsigned long *configs,
913fcd76317SRyan Wanner 				     unsigned num_configs)
914fcd76317SRyan Wanner {
915fcd76317SRyan Wanner 	struct atmel_group *grp = atmel_pctl_find_group_by_pin(pctldev, pin);
916fcd76317SRyan Wanner 
917fcd76317SRyan Wanner 	return atmel_conf_pin_config_group_set(pctldev, grp->pin, configs, num_configs);
918fcd76317SRyan Wanner }
919fcd76317SRyan Wanner 
atmel_conf_pin_config_get(struct pinctrl_dev * pctldev,unsigned pin,unsigned long * configs)920fcd76317SRyan Wanner static int atmel_conf_pin_config_get(struct pinctrl_dev *pctldev,
921fcd76317SRyan Wanner 				     unsigned pin,
922fcd76317SRyan Wanner 				     unsigned long *configs)
923fcd76317SRyan Wanner {
924fcd76317SRyan Wanner 	struct atmel_group *grp = atmel_pctl_find_group_by_pin(pctldev, pin);
925fcd76317SRyan Wanner 
926fcd76317SRyan Wanner 	return atmel_conf_pin_config_group_get(pctldev, grp->pin, configs);
927fcd76317SRyan Wanner }
928fcd76317SRyan Wanner 
atmel_conf_pin_config_dbg_show(struct pinctrl_dev * pctldev,struct seq_file * s,unsigned int pin_id)92977618084SLudovic Desroches static void atmel_conf_pin_config_dbg_show(struct pinctrl_dev *pctldev,
930b4435b42SClaudiu Beznea 					   struct seq_file *s,
931b4435b42SClaudiu Beznea 					   unsigned int pin_id)
93277618084SLudovic Desroches {
93377618084SLudovic Desroches 	struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
93477618084SLudovic Desroches 	u32 conf;
93577618084SLudovic Desroches 
93677618084SLudovic Desroches 	if (!atmel_pioctrl->pins[pin_id]->device)
93777618084SLudovic Desroches 		return;
93877618084SLudovic Desroches 
93977618084SLudovic Desroches 	seq_printf(s, " (%s, ioset %u) ",
94077618084SLudovic Desroches 		   atmel_pioctrl->pins[pin_id]->device,
94177618084SLudovic Desroches 		   atmel_pioctrl->pins[pin_id]->ioset);
94277618084SLudovic Desroches 
94377618084SLudovic Desroches 	conf = atmel_pin_config_read(pctldev, pin_id);
94477618084SLudovic Desroches 	if (conf & ATMEL_PIO_PUEN_MASK)
94577618084SLudovic Desroches 		seq_printf(s, "%s ", "pull-up");
94677618084SLudovic Desroches 	if (conf & ATMEL_PIO_PDEN_MASK)
94777618084SLudovic Desroches 		seq_printf(s, "%s ", "pull-down");
94877618084SLudovic Desroches 	if (conf & ATMEL_PIO_IFEN_MASK)
94977618084SLudovic Desroches 		seq_printf(s, "%s ", "debounce");
95077618084SLudovic Desroches 	if (conf & ATMEL_PIO_OPD_MASK)
95177618084SLudovic Desroches 		seq_printf(s, "%s ", "open-drain");
952772be1daSRyan Wanner 	else
953772be1daSRyan Wanner 		seq_printf(s, "%s ", "push-pull");
95477618084SLudovic Desroches 	if (conf & ATMEL_PIO_SCHMITT_MASK)
95577618084SLudovic Desroches 		seq_printf(s, "%s ", "schmitt");
956c709135eSClaudiu Beznea 	if (atmel_pioctrl->slew_rate_support && (conf & ATMEL_PIO_SR_MASK))
957c709135eSClaudiu Beznea 		seq_printf(s, "%s ", "slew-rate");
958ff10e353SLudovic Desroches 	if (conf & ATMEL_PIO_DRVSTR_MASK) {
959ff10e353SLudovic Desroches 		switch ((conf & ATMEL_PIO_DRVSTR_MASK) >> ATMEL_PIO_DRVSTR_OFFSET) {
960ff10e353SLudovic Desroches 		case ATMEL_PIO_DRVSTR_ME:
961ff10e353SLudovic Desroches 			seq_printf(s, "%s ", "medium-drive");
962ff10e353SLudovic Desroches 			break;
963ff10e353SLudovic Desroches 		case ATMEL_PIO_DRVSTR_HI:
964ff10e353SLudovic Desroches 			seq_printf(s, "%s ", "high-drive");
965ff10e353SLudovic Desroches 			break;
966ff10e353SLudovic Desroches 		/* ATMEL_PIO_DRVSTR_LO and 0 which is the default value at reset */
967ff10e353SLudovic Desroches 		default:
968ff10e353SLudovic Desroches 			seq_printf(s, "%s ", "low-drive");
969ff10e353SLudovic Desroches 		}
970ff10e353SLudovic Desroches 	}
97177618084SLudovic Desroches }
97277618084SLudovic Desroches 
97377618084SLudovic Desroches static const struct pinconf_ops atmel_confops = {
97477618084SLudovic Desroches 	.pin_config_group_get	= atmel_conf_pin_config_group_get,
97577618084SLudovic Desroches 	.pin_config_group_set	= atmel_conf_pin_config_group_set,
97677618084SLudovic Desroches 	.pin_config_dbg_show	= atmel_conf_pin_config_dbg_show,
977fcd76317SRyan Wanner 	.pin_config_set	        = atmel_conf_pin_config_set,
978fcd76317SRyan Wanner 	.pin_config_get	        = atmel_conf_pin_config_get,
97977618084SLudovic Desroches };
98077618084SLudovic Desroches 
98177618084SLudovic Desroches static struct pinctrl_desc atmel_pinctrl_desc = {
98277618084SLudovic Desroches 	.name		= "atmel_pinctrl",
98377618084SLudovic Desroches 	.confops	= &atmel_confops,
98477618084SLudovic Desroches 	.pctlops	= &atmel_pctlops,
98577618084SLudovic Desroches 	.pmxops		= &atmel_pmxops,
98677618084SLudovic Desroches };
98777618084SLudovic Desroches 
atmel_pctrl_suspend(struct device * dev)9886be2a3a0SArnd Bergmann static int __maybe_unused atmel_pctrl_suspend(struct device *dev)
989de4e882fSLudovic Desroches {
9901ccb0426SWolfram Sang 	struct atmel_pioctrl *atmel_pioctrl = dev_get_drvdata(dev);
991ba9e7f27SAlexandre Belloni 	int i, j;
992de4e882fSLudovic Desroches 
993de4e882fSLudovic Desroches 	/*
994de4e882fSLudovic Desroches 	 * For each bank, save IMR to restore it later and disable all GPIO
995de4e882fSLudovic Desroches 	 * interrupts excepting the ones marked as wakeup sources.
996de4e882fSLudovic Desroches 	 */
997de4e882fSLudovic Desroches 	for (i = 0; i < atmel_pioctrl->nbanks; i++) {
998ba9e7f27SAlexandre Belloni 		atmel_pioctrl->pm_suspend_backup[i].imr =
999de4e882fSLudovic Desroches 			atmel_gpio_read(atmel_pioctrl, i, ATMEL_PIO_IMR);
1000de4e882fSLudovic Desroches 		atmel_gpio_write(atmel_pioctrl, i, ATMEL_PIO_IDR,
1001de4e882fSLudovic Desroches 				 ~atmel_pioctrl->pm_wakeup_sources[i]);
1002ba9e7f27SAlexandre Belloni 		atmel_pioctrl->pm_suspend_backup[i].odsr =
1003ba9e7f27SAlexandre Belloni 			atmel_gpio_read(atmel_pioctrl, i, ATMEL_PIO_ODSR);
1004ba9e7f27SAlexandre Belloni 		for (j = 0; j < ATMEL_PIO_NPINS_PER_BANK; j++) {
1005ba9e7f27SAlexandre Belloni 			atmel_gpio_write(atmel_pioctrl, i,
1006ba9e7f27SAlexandre Belloni 					 ATMEL_PIO_MSKR, BIT(j));
1007ba9e7f27SAlexandre Belloni 			atmel_pioctrl->pm_suspend_backup[i].cfgr[j] =
1008ba9e7f27SAlexandre Belloni 				atmel_gpio_read(atmel_pioctrl, i,
1009ba9e7f27SAlexandre Belloni 						ATMEL_PIO_CFGR);
1010ba9e7f27SAlexandre Belloni 		}
1011de4e882fSLudovic Desroches 	}
1012de4e882fSLudovic Desroches 
1013de4e882fSLudovic Desroches 	return 0;
1014de4e882fSLudovic Desroches }
1015de4e882fSLudovic Desroches 
atmel_pctrl_resume(struct device * dev)10166be2a3a0SArnd Bergmann static int __maybe_unused atmel_pctrl_resume(struct device *dev)
1017de4e882fSLudovic Desroches {
10181ccb0426SWolfram Sang 	struct atmel_pioctrl *atmel_pioctrl = dev_get_drvdata(dev);
1019ba9e7f27SAlexandre Belloni 	int i, j;
1020de4e882fSLudovic Desroches 
1021ba9e7f27SAlexandre Belloni 	for (i = 0; i < atmel_pioctrl->nbanks; i++) {
1022de4e882fSLudovic Desroches 		atmel_gpio_write(atmel_pioctrl, i, ATMEL_PIO_IER,
1023ba9e7f27SAlexandre Belloni 				 atmel_pioctrl->pm_suspend_backup[i].imr);
1024ba9e7f27SAlexandre Belloni 		atmel_gpio_write(atmel_pioctrl, i, ATMEL_PIO_SODR,
1025ba9e7f27SAlexandre Belloni 				 atmel_pioctrl->pm_suspend_backup[i].odsr);
1026ba9e7f27SAlexandre Belloni 		for (j = 0; j < ATMEL_PIO_NPINS_PER_BANK; j++) {
1027ba9e7f27SAlexandre Belloni 			atmel_gpio_write(atmel_pioctrl, i,
1028ba9e7f27SAlexandre Belloni 					 ATMEL_PIO_MSKR, BIT(j));
1029ba9e7f27SAlexandre Belloni 			atmel_gpio_write(atmel_pioctrl, i, ATMEL_PIO_CFGR,
1030ba9e7f27SAlexandre Belloni 					 atmel_pioctrl->pm_suspend_backup[i].cfgr[j]);
1031ba9e7f27SAlexandre Belloni 		}
1032ba9e7f27SAlexandre Belloni 	}
1033de4e882fSLudovic Desroches 
1034de4e882fSLudovic Desroches 	return 0;
1035de4e882fSLudovic Desroches }
1036de4e882fSLudovic Desroches 
1037de4e882fSLudovic Desroches static const struct dev_pm_ops atmel_pctrl_pm_ops = {
1038de4e882fSLudovic Desroches 	SET_SYSTEM_SLEEP_PM_OPS(atmel_pctrl_suspend, atmel_pctrl_resume)
1039de4e882fSLudovic Desroches };
1040de4e882fSLudovic Desroches 
104177618084SLudovic Desroches /*
104277618084SLudovic Desroches  * The number of banks can be different from a SoC to another one.
104377618084SLudovic Desroches  * We can have up to 16 banks.
104477618084SLudovic Desroches  */
104577618084SLudovic Desroches static const struct atmel_pioctrl_data atmel_sama5d2_pioctrl_data = {
104677618084SLudovic Desroches 	.nbanks			= 4,
1047b6071c89SEugen Hristev 	.last_bank_count	= ATMEL_PIO_NPINS_PER_BANK,
104877618084SLudovic Desroches };
104977618084SLudovic Desroches 
1050737894d2SEugen Hristev static const struct atmel_pioctrl_data microchip_sama7g5_pioctrl_data = {
1051737894d2SEugen Hristev 	.nbanks			= 5,
1052b6071c89SEugen Hristev 	.last_bank_count	= 8, /* sama7g5 has only PE0 to PE7 */
1053c709135eSClaudiu Beznea 	.slew_rate_support	= 1,
1054737894d2SEugen Hristev };
1055737894d2SEugen Hristev 
105677618084SLudovic Desroches static const struct of_device_id atmel_pctrl_of_match[] = {
105777618084SLudovic Desroches 	{
105877618084SLudovic Desroches 		.compatible = "atmel,sama5d2-pinctrl",
105977618084SLudovic Desroches 		.data = &atmel_sama5d2_pioctrl_data,
106077618084SLudovic Desroches 	}, {
1061737894d2SEugen Hristev 		.compatible = "microchip,sama7g5-pinctrl",
1062737894d2SEugen Hristev 		.data = &microchip_sama7g5_pioctrl_data,
1063737894d2SEugen Hristev 	}, {
106477618084SLudovic Desroches 		/* sentinel */
106577618084SLudovic Desroches 	}
106677618084SLudovic Desroches };
106777618084SLudovic Desroches 
106814694179SAlexis Lothoré /*
106914694179SAlexis Lothoré  * This lock class allows to tell lockdep that parent IRQ and children IRQ do
107014694179SAlexis Lothoré  * not share the same class so it does not raise false positive
107114694179SAlexis Lothoré  */
107214694179SAlexis Lothoré static struct lock_class_key atmel_lock_key;
107314694179SAlexis Lothoré static struct lock_class_key atmel_request_key;
107414694179SAlexis Lothoré 
atmel_pinctrl_probe(struct platform_device * pdev)107577618084SLudovic Desroches static int atmel_pinctrl_probe(struct platform_device *pdev)
107677618084SLudovic Desroches {
107777618084SLudovic Desroches 	struct device *dev = &pdev->dev;
107877618084SLudovic Desroches 	struct pinctrl_pin_desc	*pin_desc;
107977618084SLudovic Desroches 	const char **group_names;
108077618084SLudovic Desroches 	int i, ret;
108177618084SLudovic Desroches 	struct atmel_pioctrl *atmel_pioctrl;
10828b74c7d3SJulia Lawall 	const struct atmel_pioctrl_data *atmel_pioctrl_data;
108377618084SLudovic Desroches 
108477618084SLudovic Desroches 	atmel_pioctrl = devm_kzalloc(dev, sizeof(*atmel_pioctrl), GFP_KERNEL);
108577618084SLudovic Desroches 	if (!atmel_pioctrl)
108677618084SLudovic Desroches 		return -ENOMEM;
108777618084SLudovic Desroches 	atmel_pioctrl->dev = dev;
108877618084SLudovic Desroches 	atmel_pioctrl->node = dev->of_node;
108977618084SLudovic Desroches 	platform_set_drvdata(pdev, atmel_pioctrl);
109077618084SLudovic Desroches 
10911ffd07c6SClaudiu Beznea 	atmel_pioctrl_data = device_get_match_data(dev);
1092f03fff55SClaudiu Beznea 	if (!atmel_pioctrl_data)
1093f03fff55SClaudiu Beznea 		return dev_err_probe(dev, -ENODEV, "Invalid device data\n");
1094f03fff55SClaudiu Beznea 
109577618084SLudovic Desroches 	atmel_pioctrl->nbanks = atmel_pioctrl_data->nbanks;
109677618084SLudovic Desroches 	atmel_pioctrl->npins = atmel_pioctrl->nbanks * ATMEL_PIO_NPINS_PER_BANK;
1097b6071c89SEugen Hristev 	/* if last bank has limited number of pins, adjust accordingly */
1098b6071c89SEugen Hristev 	if (atmel_pioctrl_data->last_bank_count != ATMEL_PIO_NPINS_PER_BANK) {
1099b6071c89SEugen Hristev 		atmel_pioctrl->npins -= ATMEL_PIO_NPINS_PER_BANK;
1100b6071c89SEugen Hristev 		atmel_pioctrl->npins += atmel_pioctrl_data->last_bank_count;
1101b6071c89SEugen Hristev 	}
1102c709135eSClaudiu Beznea 	atmel_pioctrl->slew_rate_support = atmel_pioctrl_data->slew_rate_support;
110377618084SLudovic Desroches 
11044b024225SYueHaibing 	atmel_pioctrl->reg_base = devm_platform_ioremap_resource(pdev, 0);
110577618084SLudovic Desroches 	if (IS_ERR(atmel_pioctrl->reg_base))
1106b5d9ff10STiezhu Yang 		return PTR_ERR(atmel_pioctrl->reg_base);
110777618084SLudovic Desroches 
11088d35039dSClaudiu Beznea 	atmel_pioctrl->clk = devm_clk_get_enabled(dev, NULL);
1109f03fff55SClaudiu Beznea 	if (IS_ERR(atmel_pioctrl->clk))
1110f03fff55SClaudiu Beznea 		return dev_err_probe(dev, PTR_ERR(atmel_pioctrl->clk), "failed to get clock\n");
111177618084SLudovic Desroches 
1112a86854d0SKees Cook 	atmel_pioctrl->pins = devm_kcalloc(dev,
1113a86854d0SKees Cook 					   atmel_pioctrl->npins,
1114a86854d0SKees Cook 					   sizeof(*atmel_pioctrl->pins),
1115a86854d0SKees Cook 					   GFP_KERNEL);
111677618084SLudovic Desroches 	if (!atmel_pioctrl->pins)
111777618084SLudovic Desroches 		return -ENOMEM;
111877618084SLudovic Desroches 
1119a86854d0SKees Cook 	pin_desc = devm_kcalloc(dev, atmel_pioctrl->npins, sizeof(*pin_desc),
1120a86854d0SKees Cook 				GFP_KERNEL);
112177618084SLudovic Desroches 	if (!pin_desc)
112277618084SLudovic Desroches 		return -ENOMEM;
112377618084SLudovic Desroches 	atmel_pinctrl_desc.pins = pin_desc;
112477618084SLudovic Desroches 	atmel_pinctrl_desc.npins = atmel_pioctrl->npins;
1125ff10e353SLudovic Desroches 	atmel_pinctrl_desc.num_custom_params = ARRAY_SIZE(atmel_custom_bindings);
1126ff10e353SLudovic Desroches 	atmel_pinctrl_desc.custom_params = atmel_custom_bindings;
112777618084SLudovic Desroches 
112877618084SLudovic Desroches 	/* One pin is one group since a pin can achieve all functions. */
1129a86854d0SKees Cook 	group_names = devm_kcalloc(dev,
1130a86854d0SKees Cook 				   atmel_pioctrl->npins, sizeof(*group_names),
1131a86854d0SKees Cook 				   GFP_KERNEL);
113277618084SLudovic Desroches 	if (!group_names)
113377618084SLudovic Desroches 		return -ENOMEM;
113477618084SLudovic Desroches 	atmel_pioctrl->group_names = group_names;
113577618084SLudovic Desroches 
1136a86854d0SKees Cook 	atmel_pioctrl->groups = devm_kcalloc(&pdev->dev,
1137a86854d0SKees Cook 			atmel_pioctrl->npins, sizeof(*atmel_pioctrl->groups),
113877618084SLudovic Desroches 			GFP_KERNEL);
113977618084SLudovic Desroches 	if (!atmel_pioctrl->groups)
114077618084SLudovic Desroches 		return -ENOMEM;
114177618084SLudovic Desroches 	for (i = 0 ; i < atmel_pioctrl->npins; i++) {
114277618084SLudovic Desroches 		struct atmel_group *group = atmel_pioctrl->groups + i;
1143b4435b42SClaudiu Beznea 		unsigned int bank = ATMEL_PIO_BANK(i);
1144b4435b42SClaudiu Beznea 		unsigned int line = ATMEL_PIO_LINE(i);
114577618084SLudovic Desroches 
114677618084SLudovic Desroches 		atmel_pioctrl->pins[i] = devm_kzalloc(dev,
114777618084SLudovic Desroches 				sizeof(**atmel_pioctrl->pins), GFP_KERNEL);
114877618084SLudovic Desroches 		if (!atmel_pioctrl->pins[i])
114977618084SLudovic Desroches 			return -ENOMEM;
115077618084SLudovic Desroches 
115177618084SLudovic Desroches 		atmel_pioctrl->pins[i]->pin_id = i;
115277618084SLudovic Desroches 		atmel_pioctrl->pins[i]->bank = bank;
115377618084SLudovic Desroches 		atmel_pioctrl->pins[i]->line = line;
115477618084SLudovic Desroches 
115577618084SLudovic Desroches 		pin_desc[i].number = i;
115677618084SLudovic Desroches 		/* Pin naming convention: P(bank_name)(bank_pin_number). */
11575a8f9cf2SClaudiu Beznea 		pin_desc[i].name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "P%c%u",
115877618084SLudovic Desroches 						  bank + 'A', line);
1159f6fd5d4fSClaudiu Beznea 		if (!pin_desc[i].name)
1160f6fd5d4fSClaudiu Beznea 			return -ENOMEM;
116177618084SLudovic Desroches 
116277618084SLudovic Desroches 		group->name = group_names[i] = pin_desc[i].name;
116377618084SLudovic Desroches 		group->pin = pin_desc[i].number;
116477618084SLudovic Desroches 
116577618084SLudovic Desroches 		dev_dbg(dev, "pin_id=%u, bank=%u, line=%u", i, bank, line);
116677618084SLudovic Desroches 	}
116777618084SLudovic Desroches 
116877618084SLudovic Desroches 	atmel_pioctrl->gpio_chip = &atmel_gpio_chip;
116977618084SLudovic Desroches 	atmel_pioctrl->gpio_chip->ngpio = atmel_pioctrl->npins;
117077618084SLudovic Desroches 	atmel_pioctrl->gpio_chip->label = dev_name(dev);
117158383c78SLinus Walleij 	atmel_pioctrl->gpio_chip->parent = dev;
117277618084SLudovic Desroches 	atmel_pioctrl->gpio_chip->names = atmel_pioctrl->group_names;
1173fcd76317SRyan Wanner 	atmel_pioctrl->gpio_chip->set_config = gpiochip_generic_config;
117477618084SLudovic Desroches 
1175a86854d0SKees Cook 	atmel_pioctrl->pm_wakeup_sources = devm_kcalloc(dev,
1176a86854d0SKees Cook 			atmel_pioctrl->nbanks,
1177a86854d0SKees Cook 			sizeof(*atmel_pioctrl->pm_wakeup_sources),
1178a86854d0SKees Cook 			GFP_KERNEL);
1179de4e882fSLudovic Desroches 	if (!atmel_pioctrl->pm_wakeup_sources)
1180de4e882fSLudovic Desroches 		return -ENOMEM;
1181de4e882fSLudovic Desroches 
1182a86854d0SKees Cook 	atmel_pioctrl->pm_suspend_backup = devm_kcalloc(dev,
1183a86854d0SKees Cook 			atmel_pioctrl->nbanks,
1184a86854d0SKees Cook 			sizeof(*atmel_pioctrl->pm_suspend_backup),
1185a86854d0SKees Cook 			GFP_KERNEL);
1186de4e882fSLudovic Desroches 	if (!atmel_pioctrl->pm_suspend_backup)
1187de4e882fSLudovic Desroches 		return -ENOMEM;
1188de4e882fSLudovic Desroches 
1189a86854d0SKees Cook 	atmel_pioctrl->irqs = devm_kcalloc(dev,
1190a86854d0SKees Cook 					   atmel_pioctrl->nbanks,
1191a86854d0SKees Cook 					   sizeof(*atmel_pioctrl->irqs),
1192a86854d0SKees Cook 					   GFP_KERNEL);
119377618084SLudovic Desroches 	if (!atmel_pioctrl->irqs)
119477618084SLudovic Desroches 		return -ENOMEM;
119577618084SLudovic Desroches 
119677618084SLudovic Desroches 	/* There is one controller but each bank has its own irq line. */
119777618084SLudovic Desroches 	for (i = 0; i < atmel_pioctrl->nbanks; i++) {
1198c00cdc32SLad Prabhakar 		ret = platform_get_irq(pdev, i);
1199c00cdc32SLad Prabhakar 		if (ret < 0) {
1200c00cdc32SLad Prabhakar 			dev_dbg(dev, "missing irq resource for group %c\n",
120177618084SLudovic Desroches 				'A' + i);
1202c00cdc32SLad Prabhakar 			return ret;
120377618084SLudovic Desroches 		}
1204c00cdc32SLad Prabhakar 		atmel_pioctrl->irqs[i] = ret;
1205c00cdc32SLad Prabhakar 		irq_set_chained_handler_and_data(ret, atmel_gpio_irq_handler, atmel_pioctrl);
1206c00cdc32SLad Prabhakar 		dev_dbg(dev, "bank %i: irq=%d\n", i, ret);
120777618084SLudovic Desroches 	}
120877618084SLudovic Desroches 
120977618084SLudovic Desroches 	atmel_pioctrl->irq_domain = irq_domain_add_linear(dev->of_node,
121077618084SLudovic Desroches 			atmel_pioctrl->gpio_chip->ngpio,
121177618084SLudovic Desroches 			&irq_domain_simple_ops, NULL);
1212f03fff55SClaudiu Beznea 	if (!atmel_pioctrl->irq_domain)
1213f03fff55SClaudiu Beznea 		return dev_err_probe(dev, -ENODEV, "can't add the irq domain\n");
121477618084SLudovic Desroches 
121577618084SLudovic Desroches 	for (i = 0; i < atmel_pioctrl->npins; i++) {
121677618084SLudovic Desroches 		int irq = irq_create_mapping(atmel_pioctrl->irq_domain, i);
121777618084SLudovic Desroches 
121877618084SLudovic Desroches 		irq_set_chip_and_handler(irq, &atmel_gpio_irq_chip,
121977618084SLudovic Desroches 					 handle_simple_irq);
122077618084SLudovic Desroches 		irq_set_chip_data(irq, atmel_pioctrl);
122114694179SAlexis Lothoré 		irq_set_lockdep_class(irq, &atmel_lock_key, &atmel_request_key);
122277618084SLudovic Desroches 		dev_dbg(dev,
122377618084SLudovic Desroches 			"atmel gpio irq domain: hwirq: %d, linux irq: %d\n",
122477618084SLudovic Desroches 			i, irq);
122577618084SLudovic Desroches 	}
122677618084SLudovic Desroches 
12275d3fc884SLaxman Dewangan 	atmel_pioctrl->pinctrl_dev = devm_pinctrl_register(&pdev->dev,
12285d3fc884SLaxman Dewangan 							   &atmel_pinctrl_desc,
122977618084SLudovic Desroches 							   atmel_pioctrl);
12305d3fc884SLaxman Dewangan 	if (IS_ERR(atmel_pioctrl->pinctrl_dev)) {
12315d3fc884SLaxman Dewangan 		ret = PTR_ERR(atmel_pioctrl->pinctrl_dev);
123277618084SLudovic Desroches 		dev_err(dev, "pinctrl registration failed\n");
12338d35039dSClaudiu Beznea 		goto irq_domain_remove_error;
123477618084SLudovic Desroches 	}
123577618084SLudovic Desroches 
123680036f88SLinus Walleij 	ret = gpiochip_add_data(atmel_pioctrl->gpio_chip, atmel_pioctrl);
123777618084SLudovic Desroches 	if (ret) {
123877618084SLudovic Desroches 		dev_err(dev, "failed to add gpiochip\n");
12398d35039dSClaudiu Beznea 		goto irq_domain_remove_error;
124077618084SLudovic Desroches 	}
124177618084SLudovic Desroches 
124277618084SLudovic Desroches 	ret = gpiochip_add_pin_range(atmel_pioctrl->gpio_chip, dev_name(dev),
124377618084SLudovic Desroches 				     0, 0, atmel_pioctrl->gpio_chip->ngpio);
124477618084SLudovic Desroches 	if (ret) {
124577618084SLudovic Desroches 		dev_err(dev, "failed to add gpio pin range\n");
124677618084SLudovic Desroches 		goto gpiochip_add_pin_range_error;
124777618084SLudovic Desroches 	}
124877618084SLudovic Desroches 
124977618084SLudovic Desroches 	dev_info(&pdev->dev, "atmel pinctrl initialized\n");
125077618084SLudovic Desroches 
125177618084SLudovic Desroches 	return 0;
125277618084SLudovic Desroches 
125377618084SLudovic Desroches gpiochip_add_pin_range_error:
125477618084SLudovic Desroches 	gpiochip_remove(atmel_pioctrl->gpio_chip);
125577618084SLudovic Desroches 
12568d35039dSClaudiu Beznea irq_domain_remove_error:
12575d3fc884SLaxman Dewangan 	irq_domain_remove(atmel_pioctrl->irq_domain);
12585d3fc884SLaxman Dewangan 
125977618084SLudovic Desroches 	return ret;
126077618084SLudovic Desroches }
126177618084SLudovic Desroches 
126277618084SLudovic Desroches static struct platform_driver atmel_pinctrl_driver = {
126377618084SLudovic Desroches 	.driver = {
126477618084SLudovic Desroches 		.name = "pinctrl-at91-pio4",
126577618084SLudovic Desroches 		.of_match_table = atmel_pctrl_of_match,
1266de4e882fSLudovic Desroches 		.pm = &atmel_pctrl_pm_ops,
1267f703851aSPaul Gortmaker 		.suppress_bind_attrs = true,
126877618084SLudovic Desroches 	},
126977618084SLudovic Desroches 	.probe = atmel_pinctrl_probe,
127077618084SLudovic Desroches };
1271f703851aSPaul Gortmaker builtin_platform_driver(atmel_pinctrl_driver);
1272