xref: /openbmc/linux/drivers/gpio/gpio-tegra186.c (revision c1e01cdbe0312d95b8c1542abd67fe786b534f57)
1ac1dc6b2SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
25b2b135aSThierry Reding /*
310e4afd6SDipen Patel  * Copyright (c) 2016-2022 NVIDIA Corporation
45b2b135aSThierry Reding  *
55b2b135aSThierry Reding  * Author: Thierry Reding <treding@nvidia.com>
610e4afd6SDipen Patel  *	   Dipen Patel <dpatel@nvidia.com>
75b2b135aSThierry Reding  */
85b2b135aSThierry Reding 
95b2b135aSThierry Reding #include <linux/gpio/driver.h>
1027bb5fefSAndy Shevchenko #include <linux/hte.h>
115b2b135aSThierry Reding #include <linux/interrupt.h>
125b2b135aSThierry Reding #include <linux/irq.h>
135b2b135aSThierry Reding #include <linux/module.h>
14e91d0f05SRob Herring #include <linux/of.h>
155b2b135aSThierry Reding #include <linux/platform_device.h>
1627bb5fefSAndy Shevchenko #include <linux/seq_file.h>
175b2b135aSThierry Reding 
185b2b135aSThierry Reding #include <dt-bindings/gpio/tegra186-gpio.h>
19bac5c3b8SMikko Perttunen #include <dt-bindings/gpio/tegra194-gpio.h>
201db9b241SPrathamesh Shete #include <dt-bindings/gpio/tegra234-gpio.h>
21d1056b77SAkhil R #include <dt-bindings/gpio/tegra241-gpio.h>
225b2b135aSThierry Reding 
2322635ed8SThierry Reding /* security registers */
2422635ed8SThierry Reding #define TEGRA186_GPIO_CTL_SCR 0x0c
2522635ed8SThierry Reding #define  TEGRA186_GPIO_CTL_SCR_SEC_WEN BIT(28)
2622635ed8SThierry Reding #define  TEGRA186_GPIO_CTL_SCR_SEC_REN BIT(27)
2722635ed8SThierry Reding 
2822635ed8SThierry Reding #define TEGRA186_GPIO_INT_ROUTE_MAPPING(p, x) (0x14 + (p) * 0x20 + (x) * 4)
2922635ed8SThierry Reding 
30b2b56a16SPrathamesh Shete #define  TEGRA186_GPIO_VM			0x00
31b2b56a16SPrathamesh Shete #define  TEGRA186_GPIO_VM_RW_MASK		0x03
32b2b56a16SPrathamesh Shete #define  TEGRA186_GPIO_SCR			0x04
33b2b56a16SPrathamesh Shete #define  TEGRA186_GPIO_SCR_PIN_SIZE		0x08
34b2b56a16SPrathamesh Shete #define  TEGRA186_GPIO_SCR_PORT_SIZE		0x40
35b2b56a16SPrathamesh Shete #define  TEGRA186_GPIO_SCR_SEC_WEN		BIT(28)
36b2b56a16SPrathamesh Shete #define  TEGRA186_GPIO_SCR_SEC_REN		BIT(27)
37b2b56a16SPrathamesh Shete #define  TEGRA186_GPIO_SCR_SEC_G1W		BIT(9)
38b2b56a16SPrathamesh Shete #define  TEGRA186_GPIO_SCR_SEC_G1R		BIT(1)
39b2b56a16SPrathamesh Shete 
4022635ed8SThierry Reding /* control registers */
415b2b135aSThierry Reding #define TEGRA186_GPIO_ENABLE_CONFIG 0x00
425b2b135aSThierry Reding #define  TEGRA186_GPIO_ENABLE_CONFIG_ENABLE BIT(0)
435b2b135aSThierry Reding #define  TEGRA186_GPIO_ENABLE_CONFIG_OUT BIT(1)
445b2b135aSThierry Reding #define  TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_NONE (0x0 << 2)
455b2b135aSThierry Reding #define  TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_LEVEL (0x1 << 2)
465b2b135aSThierry Reding #define  TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE (0x2 << 2)
475b2b135aSThierry Reding #define  TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_DOUBLE_EDGE (0x3 << 2)
485b2b135aSThierry Reding #define  TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_MASK (0x3 << 2)
495b2b135aSThierry Reding #define  TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL BIT(4)
50adce1183SThierry Reding #define  TEGRA186_GPIO_ENABLE_CONFIG_DEBOUNCE BIT(5)
515b2b135aSThierry Reding #define  TEGRA186_GPIO_ENABLE_CONFIG_INTERRUPT BIT(6)
5210e4afd6SDipen Patel #define  TEGRA186_GPIO_ENABLE_CONFIG_TIMESTAMP_FUNC BIT(7)
535b2b135aSThierry Reding 
545b2b135aSThierry Reding #define TEGRA186_GPIO_DEBOUNCE_CONTROL 0x04
555b2b135aSThierry Reding #define  TEGRA186_GPIO_DEBOUNCE_CONTROL_THRESHOLD(x) ((x) & 0xff)
565b2b135aSThierry Reding 
575b2b135aSThierry Reding #define TEGRA186_GPIO_INPUT 0x08
585b2b135aSThierry Reding #define  TEGRA186_GPIO_INPUT_HIGH BIT(0)
595b2b135aSThierry Reding 
605b2b135aSThierry Reding #define TEGRA186_GPIO_OUTPUT_CONTROL 0x0c
615b2b135aSThierry Reding #define  TEGRA186_GPIO_OUTPUT_CONTROL_FLOATED BIT(0)
625b2b135aSThierry Reding 
635b2b135aSThierry Reding #define TEGRA186_GPIO_OUTPUT_VALUE 0x10
645b2b135aSThierry Reding #define  TEGRA186_GPIO_OUTPUT_VALUE_HIGH BIT(0)
655b2b135aSThierry Reding 
665b2b135aSThierry Reding #define TEGRA186_GPIO_INTERRUPT_CLEAR 0x14
675b2b135aSThierry Reding 
685b2b135aSThierry Reding #define TEGRA186_GPIO_INTERRUPT_STATUS(x) (0x100 + (x) * 4)
695b2b135aSThierry Reding 
705b2b135aSThierry Reding struct tegra_gpio_port {
715b2b135aSThierry Reding 	const char *name;
7213a62a56SThierry Reding 	unsigned int bank;
7313a62a56SThierry Reding 	unsigned int port;
745b2b135aSThierry Reding 	unsigned int pins;
755b2b135aSThierry Reding };
765b2b135aSThierry Reding 
77b64d6c9aSThierry Reding struct tegra186_pin_range {
78b64d6c9aSThierry Reding 	unsigned int offset;
79b64d6c9aSThierry Reding 	const char *group;
80b64d6c9aSThierry Reding };
81b64d6c9aSThierry Reding 
825b2b135aSThierry Reding struct tegra_gpio_soc {
835b2b135aSThierry Reding 	const struct tegra_gpio_port *ports;
845b2b135aSThierry Reding 	unsigned int num_ports;
855b2b135aSThierry Reding 	const char *name;
862a365505SThierry Reding 	unsigned int instance;
87b64d6c9aSThierry Reding 
8821038680SThierry Reding 	unsigned int num_irqs_per_bank;
8921038680SThierry Reding 
90b64d6c9aSThierry Reding 	const struct tegra186_pin_range *pin_ranges;
91b64d6c9aSThierry Reding 	unsigned int num_pin_ranges;
92b64d6c9aSThierry Reding 	const char *pinmux;
9310e4afd6SDipen Patel 	bool has_gte;
94b2b56a16SPrathamesh Shete 	bool has_vm_support;
955b2b135aSThierry Reding };
965b2b135aSThierry Reding 
975b2b135aSThierry Reding struct tegra_gpio {
985b2b135aSThierry Reding 	struct gpio_chip gpio;
995b2b135aSThierry Reding 	unsigned int num_irq;
1005b2b135aSThierry Reding 	unsigned int *irq;
1015b2b135aSThierry Reding 
1025b2b135aSThierry Reding 	const struct tegra_gpio_soc *soc;
103ca038748SThierry Reding 	unsigned int num_irqs_per_bank;
104ca038748SThierry Reding 	unsigned int num_banks;
1055b2b135aSThierry Reding 
10622635ed8SThierry Reding 	void __iomem *secure;
1075b2b135aSThierry Reding 	void __iomem *base;
1085b2b135aSThierry Reding };
1095b2b135aSThierry Reding 
1105b2b135aSThierry Reding static const struct tegra_gpio_port *
tegra186_gpio_get_port(struct tegra_gpio * gpio,unsigned int * pin)1115b2b135aSThierry Reding tegra186_gpio_get_port(struct tegra_gpio *gpio, unsigned int *pin)
1125b2b135aSThierry Reding {
1135b2b135aSThierry Reding 	unsigned int start = 0, i;
1145b2b135aSThierry Reding 
1155b2b135aSThierry Reding 	for (i = 0; i < gpio->soc->num_ports; i++) {
1165b2b135aSThierry Reding 		const struct tegra_gpio_port *port = &gpio->soc->ports[i];
1175b2b135aSThierry Reding 
1185b2b135aSThierry Reding 		if (*pin >= start && *pin < start + port->pins) {
1195b2b135aSThierry Reding 			*pin -= start;
1205b2b135aSThierry Reding 			return port;
1215b2b135aSThierry Reding 		}
1225b2b135aSThierry Reding 
1235b2b135aSThierry Reding 		start += port->pins;
1245b2b135aSThierry Reding 	}
1255b2b135aSThierry Reding 
1265b2b135aSThierry Reding 	return NULL;
1275b2b135aSThierry Reding }
1285b2b135aSThierry Reding 
tegra186_gpio_get_base(struct tegra_gpio * gpio,unsigned int pin)1295b2b135aSThierry Reding static void __iomem *tegra186_gpio_get_base(struct tegra_gpio *gpio,
1305b2b135aSThierry Reding 					    unsigned int pin)
1315b2b135aSThierry Reding {
1325b2b135aSThierry Reding 	const struct tegra_gpio_port *port;
13313a62a56SThierry Reding 	unsigned int offset;
1345b2b135aSThierry Reding 
1355b2b135aSThierry Reding 	port = tegra186_gpio_get_port(gpio, &pin);
1365b2b135aSThierry Reding 	if (!port)
1375b2b135aSThierry Reding 		return NULL;
1385b2b135aSThierry Reding 
13913a62a56SThierry Reding 	offset = port->bank * 0x1000 + port->port * 0x200;
14013a62a56SThierry Reding 
14113a62a56SThierry Reding 	return gpio->base + offset + pin * 0x20;
1425b2b135aSThierry Reding }
1435b2b135aSThierry Reding 
tegra186_gpio_get_secure_base(struct tegra_gpio * gpio,unsigned int pin)144b2b56a16SPrathamesh Shete static void __iomem *tegra186_gpio_get_secure_base(struct tegra_gpio *gpio,
145b2b56a16SPrathamesh Shete 						   unsigned int pin)
146b2b56a16SPrathamesh Shete {
147b2b56a16SPrathamesh Shete 	const struct tegra_gpio_port *port;
148b2b56a16SPrathamesh Shete 	unsigned int offset;
149b2b56a16SPrathamesh Shete 
150b2b56a16SPrathamesh Shete 	port = tegra186_gpio_get_port(gpio, &pin);
151b2b56a16SPrathamesh Shete 	if (!port)
152b2b56a16SPrathamesh Shete 		return NULL;
153b2b56a16SPrathamesh Shete 
154b2b56a16SPrathamesh Shete 	offset = port->bank * 0x1000 + port->port * TEGRA186_GPIO_SCR_PORT_SIZE;
155b2b56a16SPrathamesh Shete 
156b2b56a16SPrathamesh Shete 	return gpio->secure + offset + pin * TEGRA186_GPIO_SCR_PIN_SIZE;
157b2b56a16SPrathamesh Shete }
158b2b56a16SPrathamesh Shete 
tegra186_gpio_is_accessible(struct tegra_gpio * gpio,unsigned int pin)159b2b56a16SPrathamesh Shete static inline bool tegra186_gpio_is_accessible(struct tegra_gpio *gpio, unsigned int pin)
160b2b56a16SPrathamesh Shete {
161b2b56a16SPrathamesh Shete 	void __iomem *secure;
162b2b56a16SPrathamesh Shete 	u32 value;
163b2b56a16SPrathamesh Shete 
164b2b56a16SPrathamesh Shete 	secure = tegra186_gpio_get_secure_base(gpio, pin);
165b2b56a16SPrathamesh Shete 
166b2b56a16SPrathamesh Shete 	if (gpio->soc->has_vm_support) {
167b2b56a16SPrathamesh Shete 		value = readl(secure + TEGRA186_GPIO_VM);
168b2b56a16SPrathamesh Shete 		if ((value & TEGRA186_GPIO_VM_RW_MASK) != TEGRA186_GPIO_VM_RW_MASK)
169b2b56a16SPrathamesh Shete 			return false;
170b2b56a16SPrathamesh Shete 	}
171b2b56a16SPrathamesh Shete 
172b2b56a16SPrathamesh Shete 	value = __raw_readl(secure + TEGRA186_GPIO_SCR);
173b2b56a16SPrathamesh Shete 
174*e4ce6ebcSPrathamesh Shete 	/*
175*e4ce6ebcSPrathamesh Shete 	 * When SCR_SEC_[R|W]EN is unset, then we have full read/write access to all the
176*e4ce6ebcSPrathamesh Shete 	 * registers for given GPIO pin.
177*e4ce6ebcSPrathamesh Shete 	 * When SCR_SEC[R|W]EN is set, then there is need to further check the accompanying
178*e4ce6ebcSPrathamesh Shete 	 * SCR_SEC_G1[R|W] bit to determine read/write access to all the registers for given
179*e4ce6ebcSPrathamesh Shete 	 * GPIO pin.
180*e4ce6ebcSPrathamesh Shete 	 */
181b2b56a16SPrathamesh Shete 
182*e4ce6ebcSPrathamesh Shete 	if (((value & TEGRA186_GPIO_SCR_SEC_REN) == 0 ||
183*e4ce6ebcSPrathamesh Shete 	     ((value & TEGRA186_GPIO_SCR_SEC_REN) && (value & TEGRA186_GPIO_SCR_SEC_G1R))) &&
184*e4ce6ebcSPrathamesh Shete 	     ((value & TEGRA186_GPIO_SCR_SEC_WEN) == 0 ||
185*e4ce6ebcSPrathamesh Shete 	     ((value & TEGRA186_GPIO_SCR_SEC_WEN) && (value & TEGRA186_GPIO_SCR_SEC_G1W))))
186b2b56a16SPrathamesh Shete 		return true;
187b2b56a16SPrathamesh Shete 
188b2b56a16SPrathamesh Shete 	return false;
189b2b56a16SPrathamesh Shete }
190b2b56a16SPrathamesh Shete 
tegra186_init_valid_mask(struct gpio_chip * chip,unsigned long * valid_mask,unsigned int ngpios)191b2b56a16SPrathamesh Shete static int tegra186_init_valid_mask(struct gpio_chip *chip,
192b2b56a16SPrathamesh Shete 				    unsigned long *valid_mask, unsigned int ngpios)
193b2b56a16SPrathamesh Shete {
194b2b56a16SPrathamesh Shete 	struct tegra_gpio *gpio = gpiochip_get_data(chip);
195b2b56a16SPrathamesh Shete 	unsigned int j;
196b2b56a16SPrathamesh Shete 
197b2b56a16SPrathamesh Shete 	for (j = 0; j < ngpios; j++) {
198b2b56a16SPrathamesh Shete 		if (!tegra186_gpio_is_accessible(gpio, j))
199b2b56a16SPrathamesh Shete 			clear_bit(j, valid_mask);
200b2b56a16SPrathamesh Shete 	}
201b2b56a16SPrathamesh Shete 	return 0;
202b2b56a16SPrathamesh Shete }
203b2b56a16SPrathamesh Shete 
tegra186_gpio_get_direction(struct gpio_chip * chip,unsigned int offset)2045b2b135aSThierry Reding static int tegra186_gpio_get_direction(struct gpio_chip *chip,
2055b2b135aSThierry Reding 				       unsigned int offset)
2065b2b135aSThierry Reding {
2075b2b135aSThierry Reding 	struct tegra_gpio *gpio = gpiochip_get_data(chip);
2085b2b135aSThierry Reding 	void __iomem *base;
2095b2b135aSThierry Reding 	u32 value;
2105b2b135aSThierry Reding 
2115b2b135aSThierry Reding 	base = tegra186_gpio_get_base(gpio, offset);
2125b2b135aSThierry Reding 	if (WARN_ON(base == NULL))
2135b2b135aSThierry Reding 		return -ENODEV;
2145b2b135aSThierry Reding 
2155b2b135aSThierry Reding 	value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
2165b2b135aSThierry Reding 	if (value & TEGRA186_GPIO_ENABLE_CONFIG_OUT)
217e42615ecSMatti Vaittinen 		return GPIO_LINE_DIRECTION_OUT;
2185b2b135aSThierry Reding 
219e42615ecSMatti Vaittinen 	return GPIO_LINE_DIRECTION_IN;
2205b2b135aSThierry Reding }
2215b2b135aSThierry Reding 
tegra186_gpio_direction_input(struct gpio_chip * chip,unsigned int offset)2225b2b135aSThierry Reding static int tegra186_gpio_direction_input(struct gpio_chip *chip,
2235b2b135aSThierry Reding 					 unsigned int offset)
2245b2b135aSThierry Reding {
2255b2b135aSThierry Reding 	struct tegra_gpio *gpio = gpiochip_get_data(chip);
2265b2b135aSThierry Reding 	void __iomem *base;
2275b2b135aSThierry Reding 	u32 value;
2285b2b135aSThierry Reding 
2295b2b135aSThierry Reding 	base = tegra186_gpio_get_base(gpio, offset);
2305b2b135aSThierry Reding 	if (WARN_ON(base == NULL))
2315b2b135aSThierry Reding 		return -ENODEV;
2325b2b135aSThierry Reding 
2335b2b135aSThierry Reding 	value = readl(base + TEGRA186_GPIO_OUTPUT_CONTROL);
2345b2b135aSThierry Reding 	value |= TEGRA186_GPIO_OUTPUT_CONTROL_FLOATED;
2355b2b135aSThierry Reding 	writel(value, base + TEGRA186_GPIO_OUTPUT_CONTROL);
2365b2b135aSThierry Reding 
2375b2b135aSThierry Reding 	value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
2385b2b135aSThierry Reding 	value |= TEGRA186_GPIO_ENABLE_CONFIG_ENABLE;
2395b2b135aSThierry Reding 	value &= ~TEGRA186_GPIO_ENABLE_CONFIG_OUT;
2405b2b135aSThierry Reding 	writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
2415b2b135aSThierry Reding 
2425b2b135aSThierry Reding 	return 0;
2435b2b135aSThierry Reding }
2445b2b135aSThierry Reding 
tegra186_gpio_direction_output(struct gpio_chip * chip,unsigned int offset,int level)2455b2b135aSThierry Reding static int tegra186_gpio_direction_output(struct gpio_chip *chip,
2465b2b135aSThierry Reding 					  unsigned int offset, int level)
2475b2b135aSThierry Reding {
2485b2b135aSThierry Reding 	struct tegra_gpio *gpio = gpiochip_get_data(chip);
2495b2b135aSThierry Reding 	void __iomem *base;
2505b2b135aSThierry Reding 	u32 value;
2515b2b135aSThierry Reding 
2525b2b135aSThierry Reding 	/* configure output level first */
2535b2b135aSThierry Reding 	chip->set(chip, offset, level);
2545b2b135aSThierry Reding 
2555b2b135aSThierry Reding 	base = tegra186_gpio_get_base(gpio, offset);
2565b2b135aSThierry Reding 	if (WARN_ON(base == NULL))
2575b2b135aSThierry Reding 		return -EINVAL;
2585b2b135aSThierry Reding 
2595b2b135aSThierry Reding 	/* set the direction */
2605b2b135aSThierry Reding 	value = readl(base + TEGRA186_GPIO_OUTPUT_CONTROL);
2615b2b135aSThierry Reding 	value &= ~TEGRA186_GPIO_OUTPUT_CONTROL_FLOATED;
2625b2b135aSThierry Reding 	writel(value, base + TEGRA186_GPIO_OUTPUT_CONTROL);
2635b2b135aSThierry Reding 
2645b2b135aSThierry Reding 	value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
2655b2b135aSThierry Reding 	value |= TEGRA186_GPIO_ENABLE_CONFIG_ENABLE;
2665b2b135aSThierry Reding 	value |= TEGRA186_GPIO_ENABLE_CONFIG_OUT;
2675b2b135aSThierry Reding 	writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
2685b2b135aSThierry Reding 
2695b2b135aSThierry Reding 	return 0;
2705b2b135aSThierry Reding }
2715b2b135aSThierry Reding 
27210e4afd6SDipen Patel #define HTE_BOTH_EDGES	(HTE_RISING_EDGE_TS | HTE_FALLING_EDGE_TS)
27310e4afd6SDipen Patel 
tegra186_gpio_en_hw_ts(struct gpio_chip * gc,u32 offset,unsigned long flags)27410e4afd6SDipen Patel static int tegra186_gpio_en_hw_ts(struct gpio_chip *gc, u32 offset,
27510e4afd6SDipen Patel 				  unsigned long flags)
27610e4afd6SDipen Patel {
27710e4afd6SDipen Patel 	struct tegra_gpio *gpio;
27810e4afd6SDipen Patel 	void __iomem *base;
27910e4afd6SDipen Patel 	int value;
28010e4afd6SDipen Patel 
28110e4afd6SDipen Patel 	if (!gc)
28210e4afd6SDipen Patel 		return -EINVAL;
28310e4afd6SDipen Patel 
28410e4afd6SDipen Patel 	gpio = gpiochip_get_data(gc);
28510e4afd6SDipen Patel 	if (!gpio)
28610e4afd6SDipen Patel 		return -ENODEV;
28710e4afd6SDipen Patel 
28810e4afd6SDipen Patel 	base = tegra186_gpio_get_base(gpio, offset);
28910e4afd6SDipen Patel 	if (WARN_ON(base == NULL))
29010e4afd6SDipen Patel 		return -EINVAL;
29110e4afd6SDipen Patel 
29210e4afd6SDipen Patel 	value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
29310e4afd6SDipen Patel 	value |= TEGRA186_GPIO_ENABLE_CONFIG_TIMESTAMP_FUNC;
29410e4afd6SDipen Patel 
29510e4afd6SDipen Patel 	if (flags == HTE_BOTH_EDGES) {
29610e4afd6SDipen Patel 		value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_DOUBLE_EDGE;
29710e4afd6SDipen Patel 	} else if (flags == HTE_RISING_EDGE_TS) {
29810e4afd6SDipen Patel 		value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE;
29910e4afd6SDipen Patel 		value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL;
30010e4afd6SDipen Patel 	} else if (flags == HTE_FALLING_EDGE_TS) {
30110e4afd6SDipen Patel 		value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE;
30210e4afd6SDipen Patel 	}
30310e4afd6SDipen Patel 
30410e4afd6SDipen Patel 	writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
30510e4afd6SDipen Patel 
30610e4afd6SDipen Patel 	return 0;
30710e4afd6SDipen Patel }
30810e4afd6SDipen Patel 
tegra186_gpio_dis_hw_ts(struct gpio_chip * gc,u32 offset,unsigned long flags)30910e4afd6SDipen Patel static int tegra186_gpio_dis_hw_ts(struct gpio_chip *gc, u32 offset,
31010e4afd6SDipen Patel 				   unsigned long flags)
31110e4afd6SDipen Patel {
31210e4afd6SDipen Patel 	struct tegra_gpio *gpio;
31310e4afd6SDipen Patel 	void __iomem *base;
31410e4afd6SDipen Patel 	int value;
31510e4afd6SDipen Patel 
31610e4afd6SDipen Patel 	if (!gc)
31710e4afd6SDipen Patel 		return -EINVAL;
31810e4afd6SDipen Patel 
31910e4afd6SDipen Patel 	gpio = gpiochip_get_data(gc);
32010e4afd6SDipen Patel 	if (!gpio)
32110e4afd6SDipen Patel 		return -ENODEV;
32210e4afd6SDipen Patel 
32310e4afd6SDipen Patel 	base = tegra186_gpio_get_base(gpio, offset);
32410e4afd6SDipen Patel 	if (WARN_ON(base == NULL))
32510e4afd6SDipen Patel 		return -EINVAL;
32610e4afd6SDipen Patel 
32710e4afd6SDipen Patel 	value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
32810e4afd6SDipen Patel 	value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TIMESTAMP_FUNC;
32910e4afd6SDipen Patel 	if (flags == HTE_BOTH_EDGES) {
33010e4afd6SDipen Patel 		value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_DOUBLE_EDGE;
33110e4afd6SDipen Patel 	} else if (flags == HTE_RISING_EDGE_TS) {
33210e4afd6SDipen Patel 		value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE;
33310e4afd6SDipen Patel 		value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL;
33410e4afd6SDipen Patel 	} else if (flags == HTE_FALLING_EDGE_TS) {
33510e4afd6SDipen Patel 		value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE;
33610e4afd6SDipen Patel 	}
33710e4afd6SDipen Patel 	writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
33810e4afd6SDipen Patel 
33910e4afd6SDipen Patel 	return 0;
34010e4afd6SDipen Patel }
34110e4afd6SDipen Patel 
tegra186_gpio_get(struct gpio_chip * chip,unsigned int offset)3425b2b135aSThierry Reding static int tegra186_gpio_get(struct gpio_chip *chip, unsigned int offset)
3435b2b135aSThierry Reding {
3445b2b135aSThierry Reding 	struct tegra_gpio *gpio = gpiochip_get_data(chip);
3455b2b135aSThierry Reding 	void __iomem *base;
3465b2b135aSThierry Reding 	u32 value;
3475b2b135aSThierry Reding 
3485b2b135aSThierry Reding 	base = tegra186_gpio_get_base(gpio, offset);
3495b2b135aSThierry Reding 	if (WARN_ON(base == NULL))
3505b2b135aSThierry Reding 		return -ENODEV;
3515b2b135aSThierry Reding 
3525b2b135aSThierry Reding 	value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
3535b2b135aSThierry Reding 	if (value & TEGRA186_GPIO_ENABLE_CONFIG_OUT)
3545b2b135aSThierry Reding 		value = readl(base + TEGRA186_GPIO_OUTPUT_VALUE);
3555b2b135aSThierry Reding 	else
3565b2b135aSThierry Reding 		value = readl(base + TEGRA186_GPIO_INPUT);
3575b2b135aSThierry Reding 
3585b2b135aSThierry Reding 	return value & BIT(0);
3595b2b135aSThierry Reding }
3605b2b135aSThierry Reding 
tegra186_gpio_set(struct gpio_chip * chip,unsigned int offset,int level)3615b2b135aSThierry Reding static void tegra186_gpio_set(struct gpio_chip *chip, unsigned int offset,
3625b2b135aSThierry Reding 			      int level)
3635b2b135aSThierry Reding {
3645b2b135aSThierry Reding 	struct tegra_gpio *gpio = gpiochip_get_data(chip);
3655b2b135aSThierry Reding 	void __iomem *base;
3665b2b135aSThierry Reding 	u32 value;
3675b2b135aSThierry Reding 
3685b2b135aSThierry Reding 	base = tegra186_gpio_get_base(gpio, offset);
3695b2b135aSThierry Reding 	if (WARN_ON(base == NULL))
3705b2b135aSThierry Reding 		return;
3715b2b135aSThierry Reding 
3725b2b135aSThierry Reding 	value = readl(base + TEGRA186_GPIO_OUTPUT_VALUE);
3735b2b135aSThierry Reding 	if (level == 0)
3745b2b135aSThierry Reding 		value &= ~TEGRA186_GPIO_OUTPUT_VALUE_HIGH;
3755b2b135aSThierry Reding 	else
3765b2b135aSThierry Reding 		value |= TEGRA186_GPIO_OUTPUT_VALUE_HIGH;
3775b2b135aSThierry Reding 
3785b2b135aSThierry Reding 	writel(value, base + TEGRA186_GPIO_OUTPUT_VALUE);
3795b2b135aSThierry Reding }
3805b2b135aSThierry Reding 
tegra186_gpio_set_config(struct gpio_chip * chip,unsigned int offset,unsigned long config)381adce1183SThierry Reding static int tegra186_gpio_set_config(struct gpio_chip *chip,
382adce1183SThierry Reding 				    unsigned int offset,
383adce1183SThierry Reding 				    unsigned long config)
384adce1183SThierry Reding {
385adce1183SThierry Reding 	struct tegra_gpio *gpio = gpiochip_get_data(chip);
386adce1183SThierry Reding 	u32 debounce, value;
387adce1183SThierry Reding 	void __iomem *base;
388adce1183SThierry Reding 
389adce1183SThierry Reding 	base = tegra186_gpio_get_base(gpio, offset);
390adce1183SThierry Reding 	if (base == NULL)
391adce1183SThierry Reding 		return -ENXIO;
392adce1183SThierry Reding 
393adce1183SThierry Reding 	if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
394adce1183SThierry Reding 		return -ENOTSUPP;
395adce1183SThierry Reding 
396adce1183SThierry Reding 	debounce = pinconf_to_config_argument(config);
397adce1183SThierry Reding 
398adce1183SThierry Reding 	/*
399adce1183SThierry Reding 	 * The Tegra186 GPIO controller supports a maximum of 255 ms debounce
400adce1183SThierry Reding 	 * time.
401adce1183SThierry Reding 	 */
402adce1183SThierry Reding 	if (debounce > 255000)
403adce1183SThierry Reding 		return -EINVAL;
404adce1183SThierry Reding 
405adce1183SThierry Reding 	debounce = DIV_ROUND_UP(debounce, USEC_PER_MSEC);
406adce1183SThierry Reding 
407adce1183SThierry Reding 	value = TEGRA186_GPIO_DEBOUNCE_CONTROL_THRESHOLD(debounce);
408adce1183SThierry Reding 	writel(value, base + TEGRA186_GPIO_DEBOUNCE_CONTROL);
409adce1183SThierry Reding 
410adce1183SThierry Reding 	value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
411adce1183SThierry Reding 	value |= TEGRA186_GPIO_ENABLE_CONFIG_DEBOUNCE;
412adce1183SThierry Reding 	writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
413adce1183SThierry Reding 
414adce1183SThierry Reding 	return 0;
415adce1183SThierry Reding }
416adce1183SThierry Reding 
tegra186_gpio_add_pin_ranges(struct gpio_chip * chip)417b64d6c9aSThierry Reding static int tegra186_gpio_add_pin_ranges(struct gpio_chip *chip)
418b64d6c9aSThierry Reding {
419b64d6c9aSThierry Reding 	struct tegra_gpio *gpio = gpiochip_get_data(chip);
420b64d6c9aSThierry Reding 	struct pinctrl_dev *pctldev;
421b64d6c9aSThierry Reding 	struct device_node *np;
422b64d6c9aSThierry Reding 	unsigned int i, j;
423b64d6c9aSThierry Reding 	int err;
424b64d6c9aSThierry Reding 
425b64d6c9aSThierry Reding 	if (!gpio->soc->pinmux || gpio->soc->num_pin_ranges == 0)
426b64d6c9aSThierry Reding 		return 0;
427b64d6c9aSThierry Reding 
428b64d6c9aSThierry Reding 	np = of_find_compatible_node(NULL, NULL, gpio->soc->pinmux);
429b64d6c9aSThierry Reding 	if (!np)
430b64d6c9aSThierry Reding 		return -ENODEV;
431b64d6c9aSThierry Reding 
432b64d6c9aSThierry Reding 	pctldev = of_pinctrl_get(np);
433b64d6c9aSThierry Reding 	of_node_put(np);
434b64d6c9aSThierry Reding 	if (!pctldev)
435b64d6c9aSThierry Reding 		return -EPROBE_DEFER;
436b64d6c9aSThierry Reding 
437b64d6c9aSThierry Reding 	for (i = 0; i < gpio->soc->num_pin_ranges; i++) {
438b64d6c9aSThierry Reding 		unsigned int pin = gpio->soc->pin_ranges[i].offset, port;
439b64d6c9aSThierry Reding 		const char *group = gpio->soc->pin_ranges[i].group;
440b64d6c9aSThierry Reding 
441b64d6c9aSThierry Reding 		port = pin / 8;
442b64d6c9aSThierry Reding 		pin = pin % 8;
443b64d6c9aSThierry Reding 
444b64d6c9aSThierry Reding 		if (port >= gpio->soc->num_ports) {
445b64d6c9aSThierry Reding 			dev_warn(chip->parent, "invalid port %u for %s\n",
446b64d6c9aSThierry Reding 				 port, group);
447b64d6c9aSThierry Reding 			continue;
448b64d6c9aSThierry Reding 		}
449b64d6c9aSThierry Reding 
450b64d6c9aSThierry Reding 		for (j = 0; j < port; j++)
451b64d6c9aSThierry Reding 			pin += gpio->soc->ports[j].pins;
452b64d6c9aSThierry Reding 
453b64d6c9aSThierry Reding 		err = gpiochip_add_pingroup_range(chip, pctldev, pin, group);
454b64d6c9aSThierry Reding 		if (err < 0)
455b64d6c9aSThierry Reding 			return err;
456b64d6c9aSThierry Reding 	}
457b64d6c9aSThierry Reding 
458b64d6c9aSThierry Reding 	return 0;
459b64d6c9aSThierry Reding }
460b64d6c9aSThierry Reding 
tegra186_gpio_of_xlate(struct gpio_chip * chip,const struct of_phandle_args * spec,u32 * flags)4615b2b135aSThierry Reding static int tegra186_gpio_of_xlate(struct gpio_chip *chip,
4625b2b135aSThierry Reding 				  const struct of_phandle_args *spec,
4635b2b135aSThierry Reding 				  u32 *flags)
4645b2b135aSThierry Reding {
4655b2b135aSThierry Reding 	struct tegra_gpio *gpio = gpiochip_get_data(chip);
4665b2b135aSThierry Reding 	unsigned int port, pin, i, offset = 0;
4675b2b135aSThierry Reding 
4685b2b135aSThierry Reding 	if (WARN_ON(chip->of_gpio_n_cells < 2))
4695b2b135aSThierry Reding 		return -EINVAL;
4705b2b135aSThierry Reding 
4715b2b135aSThierry Reding 	if (WARN_ON(spec->args_count < chip->of_gpio_n_cells))
4725b2b135aSThierry Reding 		return -EINVAL;
4735b2b135aSThierry Reding 
4745b2b135aSThierry Reding 	port = spec->args[0] / 8;
4755b2b135aSThierry Reding 	pin = spec->args[0] % 8;
4765b2b135aSThierry Reding 
4775b2b135aSThierry Reding 	if (port >= gpio->soc->num_ports) {
4785b2b135aSThierry Reding 		dev_err(chip->parent, "invalid port number: %u\n", port);
4795b2b135aSThierry Reding 		return -EINVAL;
4805b2b135aSThierry Reding 	}
4815b2b135aSThierry Reding 
4825b2b135aSThierry Reding 	for (i = 0; i < port; i++)
4835b2b135aSThierry Reding 		offset += gpio->soc->ports[i].pins;
4845b2b135aSThierry Reding 
4855b2b135aSThierry Reding 	if (flags)
4865b2b135aSThierry Reding 		*flags = spec->args[1];
4875b2b135aSThierry Reding 
4885b2b135aSThierry Reding 	return offset + pin;
4895b2b135aSThierry Reding }
4905b2b135aSThierry Reding 
491d1e972acSMarc Zyngier #define to_tegra_gpio(x) container_of((x), struct tegra_gpio, gpio)
492d1e972acSMarc Zyngier 
tegra186_irq_ack(struct irq_data * data)4935b2b135aSThierry Reding static void tegra186_irq_ack(struct irq_data *data)
4945b2b135aSThierry Reding {
495d1e972acSMarc Zyngier 	struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
496d1e972acSMarc Zyngier 	struct tegra_gpio *gpio = to_tegra_gpio(gc);
4975b2b135aSThierry Reding 	void __iomem *base;
4985b2b135aSThierry Reding 
4995b2b135aSThierry Reding 	base = tegra186_gpio_get_base(gpio, data->hwirq);
5005b2b135aSThierry Reding 	if (WARN_ON(base == NULL))
5015b2b135aSThierry Reding 		return;
5025b2b135aSThierry Reding 
5035b2b135aSThierry Reding 	writel(1, base + TEGRA186_GPIO_INTERRUPT_CLEAR);
5045b2b135aSThierry Reding }
5055b2b135aSThierry Reding 
tegra186_irq_mask(struct irq_data * data)5065b2b135aSThierry Reding static void tegra186_irq_mask(struct irq_data *data)
5075b2b135aSThierry Reding {
508d1e972acSMarc Zyngier 	struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
509d1e972acSMarc Zyngier 	struct tegra_gpio *gpio = to_tegra_gpio(gc);
5105b2b135aSThierry Reding 	void __iomem *base;
5115b2b135aSThierry Reding 	u32 value;
5125b2b135aSThierry Reding 
5135b2b135aSThierry Reding 	base = tegra186_gpio_get_base(gpio, data->hwirq);
5145b2b135aSThierry Reding 	if (WARN_ON(base == NULL))
5155b2b135aSThierry Reding 		return;
5165b2b135aSThierry Reding 
5175b2b135aSThierry Reding 	value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
5185b2b135aSThierry Reding 	value &= ~TEGRA186_GPIO_ENABLE_CONFIG_INTERRUPT;
5195b2b135aSThierry Reding 	writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
520bba00555SMarc Zyngier 
521bba00555SMarc Zyngier 	gpiochip_disable_irq(&gpio->gpio, data->hwirq);
5225b2b135aSThierry Reding }
5235b2b135aSThierry Reding 
tegra186_irq_unmask(struct irq_data * data)5245b2b135aSThierry Reding static void tegra186_irq_unmask(struct irq_data *data)
5255b2b135aSThierry Reding {
526d1e972acSMarc Zyngier 	struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
527d1e972acSMarc Zyngier 	struct tegra_gpio *gpio = to_tegra_gpio(gc);
5285b2b135aSThierry Reding 	void __iomem *base;
5295b2b135aSThierry Reding 	u32 value;
5305b2b135aSThierry Reding 
5315b2b135aSThierry Reding 	base = tegra186_gpio_get_base(gpio, data->hwirq);
5325b2b135aSThierry Reding 	if (WARN_ON(base == NULL))
5335b2b135aSThierry Reding 		return;
5345b2b135aSThierry Reding 
535bba00555SMarc Zyngier 	gpiochip_enable_irq(&gpio->gpio, data->hwirq);
536bba00555SMarc Zyngier 
5375b2b135aSThierry Reding 	value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
5385b2b135aSThierry Reding 	value |= TEGRA186_GPIO_ENABLE_CONFIG_INTERRUPT;
5395b2b135aSThierry Reding 	writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
5405b2b135aSThierry Reding }
5415b2b135aSThierry Reding 
tegra186_irq_set_type(struct irq_data * data,unsigned int type)5423a2fa906SThierry Reding static int tegra186_irq_set_type(struct irq_data *data, unsigned int type)
5435b2b135aSThierry Reding {
544d1e972acSMarc Zyngier 	struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
545d1e972acSMarc Zyngier 	struct tegra_gpio *gpio = to_tegra_gpio(gc);
5465b2b135aSThierry Reding 	void __iomem *base;
5475b2b135aSThierry Reding 	u32 value;
5485b2b135aSThierry Reding 
5495b2b135aSThierry Reding 	base = tegra186_gpio_get_base(gpio, data->hwirq);
5505b2b135aSThierry Reding 	if (WARN_ON(base == NULL))
5515b2b135aSThierry Reding 		return -ENODEV;
5525b2b135aSThierry Reding 
5535b2b135aSThierry Reding 	value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
5545b2b135aSThierry Reding 	value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_MASK;
5555b2b135aSThierry Reding 	value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL;
5565b2b135aSThierry Reding 
5573a2fa906SThierry Reding 	switch (type & IRQ_TYPE_SENSE_MASK) {
5585b2b135aSThierry Reding 	case IRQ_TYPE_NONE:
5595b2b135aSThierry Reding 		break;
5605b2b135aSThierry Reding 
5615b2b135aSThierry Reding 	case IRQ_TYPE_EDGE_RISING:
5625b2b135aSThierry Reding 		value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE;
5635b2b135aSThierry Reding 		value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL;
5645b2b135aSThierry Reding 		break;
5655b2b135aSThierry Reding 
5665b2b135aSThierry Reding 	case IRQ_TYPE_EDGE_FALLING:
5675b2b135aSThierry Reding 		value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE;
5685b2b135aSThierry Reding 		break;
5695b2b135aSThierry Reding 
5705b2b135aSThierry Reding 	case IRQ_TYPE_EDGE_BOTH:
5715b2b135aSThierry Reding 		value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_DOUBLE_EDGE;
5725b2b135aSThierry Reding 		break;
5735b2b135aSThierry Reding 
5745b2b135aSThierry Reding 	case IRQ_TYPE_LEVEL_HIGH:
5755b2b135aSThierry Reding 		value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_LEVEL;
5765b2b135aSThierry Reding 		value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL;
5775b2b135aSThierry Reding 		break;
5785b2b135aSThierry Reding 
5795b2b135aSThierry Reding 	case IRQ_TYPE_LEVEL_LOW:
5805b2b135aSThierry Reding 		value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_LEVEL;
5815b2b135aSThierry Reding 		break;
5825b2b135aSThierry Reding 
5835b2b135aSThierry Reding 	default:
5845b2b135aSThierry Reding 		return -EINVAL;
5855b2b135aSThierry Reding 	}
5865b2b135aSThierry Reding 
5875b2b135aSThierry Reding 	writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
5885b2b135aSThierry Reding 
5893a2fa906SThierry Reding 	if ((type & IRQ_TYPE_EDGE_BOTH) == 0)
5905b2b135aSThierry Reding 		irq_set_handler_locked(data, handle_level_irq);
5915b2b135aSThierry Reding 	else
5925b2b135aSThierry Reding 		irq_set_handler_locked(data, handle_edge_irq);
5935b2b135aSThierry Reding 
594986ec63dSMarc Zyngier 	if (data->parent_data)
5952a365505SThierry Reding 		return irq_chip_set_type_parent(data, type);
596986ec63dSMarc Zyngier 
597986ec63dSMarc Zyngier 	return 0;
598986ec63dSMarc Zyngier }
599986ec63dSMarc Zyngier 
tegra186_irq_set_wake(struct irq_data * data,unsigned int on)600986ec63dSMarc Zyngier static int tegra186_irq_set_wake(struct irq_data *data, unsigned int on)
601986ec63dSMarc Zyngier {
602986ec63dSMarc Zyngier 	if (data->parent_data)
603986ec63dSMarc Zyngier 		return irq_chip_set_wake_parent(data, on);
604986ec63dSMarc Zyngier 
605986ec63dSMarc Zyngier 	return 0;
6065b2b135aSThierry Reding }
6075b2b135aSThierry Reding 
tegra186_irq_print_chip(struct irq_data * data,struct seq_file * p)608bba00555SMarc Zyngier static void tegra186_irq_print_chip(struct irq_data *data, struct seq_file *p)
609bba00555SMarc Zyngier {
610bba00555SMarc Zyngier 	struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
611bba00555SMarc Zyngier 
612bba00555SMarc Zyngier 	seq_printf(p, dev_name(gc->parent));
613bba00555SMarc Zyngier }
614bba00555SMarc Zyngier 
615bba00555SMarc Zyngier static const struct irq_chip tegra186_gpio_irq_chip = {
616bba00555SMarc Zyngier 	.irq_ack		= tegra186_irq_ack,
617bba00555SMarc Zyngier 	.irq_mask		= tegra186_irq_mask,
618bba00555SMarc Zyngier 	.irq_unmask		= tegra186_irq_unmask,
619bba00555SMarc Zyngier 	.irq_set_type		= tegra186_irq_set_type,
620bba00555SMarc Zyngier 	.irq_set_wake		= tegra186_irq_set_wake,
621bba00555SMarc Zyngier 	.irq_print_chip		= tegra186_irq_print_chip,
622bba00555SMarc Zyngier 	.flags			= IRQCHIP_IMMUTABLE,
623bba00555SMarc Zyngier 	GPIOCHIP_IRQ_RESOURCE_HELPERS,
624bba00555SMarc Zyngier };
625bba00555SMarc Zyngier 
tegra186_gpio_irq(struct irq_desc * desc)6265b2b135aSThierry Reding static void tegra186_gpio_irq(struct irq_desc *desc)
6275b2b135aSThierry Reding {
6285b2b135aSThierry Reding 	struct tegra_gpio *gpio = irq_desc_get_handler_data(desc);
6295b2b135aSThierry Reding 	struct irq_domain *domain = gpio->gpio.irq.domain;
6305b2b135aSThierry Reding 	struct irq_chip *chip = irq_desc_get_chip(desc);
6315b2b135aSThierry Reding 	unsigned int parent = irq_desc_get_irq(desc);
63221038680SThierry Reding 	unsigned int i, j, offset = 0;
6335b2b135aSThierry Reding 
6345b2b135aSThierry Reding 	chained_irq_enter(chip, desc);
6355b2b135aSThierry Reding 
6365b2b135aSThierry Reding 	for (i = 0; i < gpio->soc->num_ports; i++) {
6375b2b135aSThierry Reding 		const struct tegra_gpio_port *port = &gpio->soc->ports[i];
638dbd1c54fSMarc Zyngier 		unsigned int pin;
6395b2b135aSThierry Reding 		unsigned long value;
64013a62a56SThierry Reding 		void __iomem *base;
6415b2b135aSThierry Reding 
64213a62a56SThierry Reding 		base = gpio->base + port->bank * 0x1000 + port->port * 0x200;
64313a62a56SThierry Reding 
64413a62a56SThierry Reding 		/* skip ports that are not associated with this bank */
64521038680SThierry Reding 		for (j = 0; j < gpio->num_irqs_per_bank; j++) {
64621038680SThierry Reding 			if (parent == gpio->irq[port->bank * gpio->num_irqs_per_bank + j])
64721038680SThierry Reding 				break;
64821038680SThierry Reding 		}
64921038680SThierry Reding 
65021038680SThierry Reding 		if (j == gpio->num_irqs_per_bank)
6515b2b135aSThierry Reding 			goto skip;
6525b2b135aSThierry Reding 
6535b2b135aSThierry Reding 		value = readl(base + TEGRA186_GPIO_INTERRUPT_STATUS(1));
6545b2b135aSThierry Reding 
6555b2b135aSThierry Reding 		for_each_set_bit(pin, &value, port->pins) {
656dbd1c54fSMarc Zyngier 			int ret = generic_handle_domain_irq(domain, offset + pin);
657dbd1c54fSMarc Zyngier 			WARN_RATELIMIT(ret, "hwirq = %d", offset + pin);
6585b2b135aSThierry Reding 		}
6595b2b135aSThierry Reding 
6605b2b135aSThierry Reding skip:
6615b2b135aSThierry Reding 		offset += port->pins;
6625b2b135aSThierry Reding 	}
6635b2b135aSThierry Reding 
6645b2b135aSThierry Reding 	chained_irq_exit(chip, desc);
6655b2b135aSThierry Reding }
6665b2b135aSThierry Reding 
tegra186_gpio_irq_domain_translate(struct irq_domain * domain,struct irq_fwspec * fwspec,unsigned long * hwirq,unsigned int * type)6672a365505SThierry Reding static int tegra186_gpio_irq_domain_translate(struct irq_domain *domain,
6682a365505SThierry Reding 					      struct irq_fwspec *fwspec,
6695b2b135aSThierry Reding 					      unsigned long *hwirq,
6705b2b135aSThierry Reding 					      unsigned int *type)
6715b2b135aSThierry Reding {
6725b2b135aSThierry Reding 	struct tegra_gpio *gpio = gpiochip_get_data(domain->host_data);
6735b2b135aSThierry Reding 	unsigned int port, pin, i, offset = 0;
6745b2b135aSThierry Reding 
6752a365505SThierry Reding 	if (WARN_ON(gpio->gpio.of_gpio_n_cells < 2))
6765b2b135aSThierry Reding 		return -EINVAL;
6775b2b135aSThierry Reding 
6782a365505SThierry Reding 	if (WARN_ON(fwspec->param_count < gpio->gpio.of_gpio_n_cells))
6795b2b135aSThierry Reding 		return -EINVAL;
6802a365505SThierry Reding 
6812a365505SThierry Reding 	port = fwspec->param[0] / 8;
6822a365505SThierry Reding 	pin = fwspec->param[0] % 8;
6832a365505SThierry Reding 
6842a365505SThierry Reding 	if (port >= gpio->soc->num_ports)
6852a365505SThierry Reding 		return -EINVAL;
6865b2b135aSThierry Reding 
6875b2b135aSThierry Reding 	for (i = 0; i < port; i++)
6885b2b135aSThierry Reding 		offset += gpio->soc->ports[i].pins;
6895b2b135aSThierry Reding 
6902a365505SThierry Reding 	*type = fwspec->param[1] & IRQ_TYPE_SENSE_MASK;
6915b2b135aSThierry Reding 	*hwirq = offset + pin;
6925b2b135aSThierry Reding 
6935b2b135aSThierry Reding 	return 0;
6945b2b135aSThierry Reding }
6955b2b135aSThierry Reding 
tegra186_gpio_populate_parent_fwspec(struct gpio_chip * chip,union gpio_irq_fwspec * gfwspec,unsigned int parent_hwirq,unsigned int parent_type)69691a29af4SMarc Zyngier static int tegra186_gpio_populate_parent_fwspec(struct gpio_chip *chip,
69791a29af4SMarc Zyngier 						union gpio_irq_fwspec *gfwspec,
6982a365505SThierry Reding 						unsigned int parent_hwirq,
6992a365505SThierry Reding 						unsigned int parent_type)
7002a365505SThierry Reding {
7012a365505SThierry Reding 	struct tegra_gpio *gpio = gpiochip_get_data(chip);
70291a29af4SMarc Zyngier 	struct irq_fwspec *fwspec = &gfwspec->fwspec;
70324258761SKevin Hao 
70424258761SKevin Hao 	fwspec->fwnode = chip->irq.parent_domain->fwnode;
7052a365505SThierry Reding 	fwspec->param_count = 3;
7062a365505SThierry Reding 	fwspec->param[0] = gpio->soc->instance;
7072a365505SThierry Reding 	fwspec->param[1] = parent_hwirq;
7082a365505SThierry Reding 	fwspec->param[2] = parent_type;
70924258761SKevin Hao 
71091a29af4SMarc Zyngier 	return 0;
7112a365505SThierry Reding }
7122a365505SThierry Reding 
tegra186_gpio_child_to_parent_hwirq(struct gpio_chip * chip,unsigned int hwirq,unsigned int type,unsigned int * parent_hwirq,unsigned int * parent_type)7132a365505SThierry Reding static int tegra186_gpio_child_to_parent_hwirq(struct gpio_chip *chip,
7142a365505SThierry Reding 					       unsigned int hwirq,
7152a365505SThierry Reding 					       unsigned int type,
7162a365505SThierry Reding 					       unsigned int *parent_hwirq,
7172a365505SThierry Reding 					       unsigned int *parent_type)
7182a365505SThierry Reding {
7192a365505SThierry Reding 	*parent_hwirq = chip->irq.child_offset_to_irq(chip, hwirq);
7202a365505SThierry Reding 	*parent_type = type;
7212a365505SThierry Reding 
7222a365505SThierry Reding 	return 0;
7232a365505SThierry Reding }
7242a365505SThierry Reding 
tegra186_gpio_child_offset_to_irq(struct gpio_chip * chip,unsigned int offset)7252a365505SThierry Reding static unsigned int tegra186_gpio_child_offset_to_irq(struct gpio_chip *chip,
7262a365505SThierry Reding 						      unsigned int offset)
7272a365505SThierry Reding {
7282a365505SThierry Reding 	struct tegra_gpio *gpio = gpiochip_get_data(chip);
7292a365505SThierry Reding 	unsigned int i;
7302a365505SThierry Reding 
7312a365505SThierry Reding 	for (i = 0; i < gpio->soc->num_ports; i++) {
7322a365505SThierry Reding 		if (offset < gpio->soc->ports[i].pins)
7332a365505SThierry Reding 			break;
7342a365505SThierry Reding 
7352a365505SThierry Reding 		offset -= gpio->soc->ports[i].pins;
7362a365505SThierry Reding 	}
7372a365505SThierry Reding 
7382a365505SThierry Reding 	return offset + i * 8;
7392a365505SThierry Reding }
7402a365505SThierry Reding 
7412a365505SThierry Reding static const struct of_device_id tegra186_pmc_of_match[] = {
7422a365505SThierry Reding 	{ .compatible = "nvidia,tegra186-pmc" },
7432a365505SThierry Reding 	{ .compatible = "nvidia,tegra194-pmc" },
7440c27537aSPrathamesh Shete 	{ .compatible = "nvidia,tegra234-pmc" },
7452a365505SThierry Reding 	{ /* sentinel */ }
7465b2b135aSThierry Reding };
7475b2b135aSThierry Reding 
tegra186_gpio_init_route_mapping(struct tegra_gpio * gpio)74822635ed8SThierry Reding static void tegra186_gpio_init_route_mapping(struct tegra_gpio *gpio)
74922635ed8SThierry Reding {
75021038680SThierry Reding 	struct device *dev = gpio->gpio.parent;
7512e539b73STom Rix 	unsigned int i;
75222635ed8SThierry Reding 	u32 value;
75322635ed8SThierry Reding 
75422635ed8SThierry Reding 	for (i = 0; i < gpio->soc->num_ports; i++) {
75522635ed8SThierry Reding 		const struct tegra_gpio_port *port = &gpio->soc->ports[i];
75622635ed8SThierry Reding 		unsigned int offset, p = port->port;
75722635ed8SThierry Reding 		void __iomem *base;
75822635ed8SThierry Reding 
75922635ed8SThierry Reding 		base = gpio->secure + port->bank * 0x1000 + 0x800;
76022635ed8SThierry Reding 
76122635ed8SThierry Reding 		value = readl(base + TEGRA186_GPIO_CTL_SCR);
76222635ed8SThierry Reding 
76322635ed8SThierry Reding 		/*
76422635ed8SThierry Reding 		 * For controllers that haven't been locked down yet, make
76522635ed8SThierry Reding 		 * sure to program the default interrupt route mapping.
76622635ed8SThierry Reding 		 */
76722635ed8SThierry Reding 		if ((value & TEGRA186_GPIO_CTL_SCR_SEC_REN) == 0 &&
76822635ed8SThierry Reding 		    (value & TEGRA186_GPIO_CTL_SCR_SEC_WEN) == 0) {
76921038680SThierry Reding 			/*
77021038680SThierry Reding 			 * On Tegra194 and later, each pin can be routed to one or more
77121038680SThierry Reding 			 * interrupts.
77221038680SThierry Reding 			 */
77321038680SThierry Reding 			dev_dbg(dev, "programming default interrupt routing for port %s\n",
77421038680SThierry Reding 				port->name);
77521038680SThierry Reding 
7762e539b73STom Rix 			offset = TEGRA186_GPIO_INT_ROUTE_MAPPING(p, 0);
77722635ed8SThierry Reding 
77821038680SThierry Reding 			/*
77921038680SThierry Reding 			 * By default we only want to route GPIO pins to IRQ 0. This works
78021038680SThierry Reding 			 * only under the assumption that we're running as the host kernel
78121038680SThierry Reding 			 * and hence all GPIO pins are owned by Linux.
78221038680SThierry Reding 			 *
78321038680SThierry Reding 			 * For cases where Linux is the guest OS, the hypervisor will have
78421038680SThierry Reding 			 * to configure the interrupt routing and pass only the valid
78521038680SThierry Reding 			 * interrupts via device tree.
78621038680SThierry Reding 			 */
78722635ed8SThierry Reding 			value = readl(base + offset);
78822635ed8SThierry Reding 			value = BIT(port->pins) - 1;
78922635ed8SThierry Reding 			writel(value, base + offset);
79022635ed8SThierry Reding 		}
79122635ed8SThierry Reding 	}
79222635ed8SThierry Reding }
79322635ed8SThierry Reding 
tegra186_gpio_irqs_per_bank(struct tegra_gpio * gpio)794ca038748SThierry Reding static unsigned int tegra186_gpio_irqs_per_bank(struct tegra_gpio *gpio)
795ca038748SThierry Reding {
796ca038748SThierry Reding 	struct device *dev = gpio->gpio.parent;
797ca038748SThierry Reding 
798ca038748SThierry Reding 	if (gpio->num_irq > gpio->num_banks) {
799ca038748SThierry Reding 		if (gpio->num_irq % gpio->num_banks != 0)
800ca038748SThierry Reding 			goto error;
801ca038748SThierry Reding 	}
802ca038748SThierry Reding 
803ca038748SThierry Reding 	if (gpio->num_irq < gpio->num_banks)
804ca038748SThierry Reding 		goto error;
805ca038748SThierry Reding 
806ca038748SThierry Reding 	gpio->num_irqs_per_bank = gpio->num_irq / gpio->num_banks;
807ca038748SThierry Reding 
80821038680SThierry Reding 	if (gpio->num_irqs_per_bank > gpio->soc->num_irqs_per_bank)
80921038680SThierry Reding 		goto error;
81021038680SThierry Reding 
811ca038748SThierry Reding 	return 0;
812ca038748SThierry Reding 
813ca038748SThierry Reding error:
814ca038748SThierry Reding 	dev_err(dev, "invalid number of interrupts (%u) for %u banks\n",
815ca038748SThierry Reding 		gpio->num_irq, gpio->num_banks);
816ca038748SThierry Reding 	return -EINVAL;
817ca038748SThierry Reding }
818ca038748SThierry Reding 
tegra186_gpio_probe(struct platform_device * pdev)8195b2b135aSThierry Reding static int tegra186_gpio_probe(struct platform_device *pdev)
8205b2b135aSThierry Reding {
8215b2b135aSThierry Reding 	unsigned int i, j, offset;
8225b2b135aSThierry Reding 	struct gpio_irq_chip *irq;
8235b2b135aSThierry Reding 	struct tegra_gpio *gpio;
8242a365505SThierry Reding 	struct device_node *np;
8255b2b135aSThierry Reding 	char **names;
8265b2b135aSThierry Reding 	int err;
8275b2b135aSThierry Reding 
8285b2b135aSThierry Reding 	gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
8295b2b135aSThierry Reding 	if (!gpio)
8305b2b135aSThierry Reding 		return -ENOMEM;
8315b2b135aSThierry Reding 
8322606e7c9SAkhil R 	gpio->soc = device_get_match_data(&pdev->dev);
833ca038748SThierry Reding 	gpio->gpio.label = gpio->soc->name;
834ca038748SThierry Reding 	gpio->gpio.parent = &pdev->dev;
8355b2b135aSThierry Reding 
836ca038748SThierry Reding 	/* count the number of banks in the controller */
837ca038748SThierry Reding 	for (i = 0; i < gpio->soc->num_ports; i++)
838ca038748SThierry Reding 		if (gpio->soc->ports[i].bank > gpio->num_banks)
839ca038748SThierry Reding 			gpio->num_banks = gpio->soc->ports[i].bank;
840ca038748SThierry Reding 
841ca038748SThierry Reding 	gpio->num_banks++;
842ca038748SThierry Reding 
843ca038748SThierry Reding 	/* get register apertures */
84422635ed8SThierry Reding 	gpio->secure = devm_platform_ioremap_resource_byname(pdev, "security");
8452606e7c9SAkhil R 	if (IS_ERR(gpio->secure)) {
8462606e7c9SAkhil R 		gpio->secure = devm_platform_ioremap_resource(pdev, 0);
84722635ed8SThierry Reding 		if (IS_ERR(gpio->secure))
84822635ed8SThierry Reding 			return PTR_ERR(gpio->secure);
8492606e7c9SAkhil R 	}
85022635ed8SThierry Reding 
851cc4c8318SBartosz Golaszewski 	gpio->base = devm_platform_ioremap_resource_byname(pdev, "gpio");
8522606e7c9SAkhil R 	if (IS_ERR(gpio->base)) {
8532606e7c9SAkhil R 		gpio->base = devm_platform_ioremap_resource(pdev, 1);
8545b2b135aSThierry Reding 		if (IS_ERR(gpio->base))
8555b2b135aSThierry Reding 			return PTR_ERR(gpio->base);
8562606e7c9SAkhil R 	}
8575b2b135aSThierry Reding 
8585b2b135aSThierry Reding 	err = platform_irq_count(pdev);
8595b2b135aSThierry Reding 	if (err < 0)
8605b2b135aSThierry Reding 		return err;
8615b2b135aSThierry Reding 
8625b2b135aSThierry Reding 	gpio->num_irq = err;
8635b2b135aSThierry Reding 
864ca038748SThierry Reding 	err = tegra186_gpio_irqs_per_bank(gpio);
865ca038748SThierry Reding 	if (err < 0)
866ca038748SThierry Reding 		return err;
867ca038748SThierry Reding 
8685b2b135aSThierry Reding 	gpio->irq = devm_kcalloc(&pdev->dev, gpio->num_irq, sizeof(*gpio->irq),
8695b2b135aSThierry Reding 				 GFP_KERNEL);
8705b2b135aSThierry Reding 	if (!gpio->irq)
8715b2b135aSThierry Reding 		return -ENOMEM;
8725b2b135aSThierry Reding 
8735b2b135aSThierry Reding 	for (i = 0; i < gpio->num_irq; i++) {
8745b2b135aSThierry Reding 		err = platform_get_irq(pdev, i);
8755b2b135aSThierry Reding 		if (err < 0)
8765b2b135aSThierry Reding 			return err;
8775b2b135aSThierry Reding 
8785b2b135aSThierry Reding 		gpio->irq[i] = err;
8795b2b135aSThierry Reding 	}
8805b2b135aSThierry Reding 
881b64d6c9aSThierry Reding 	gpio->gpio.request = gpiochip_generic_request;
882b64d6c9aSThierry Reding 	gpio->gpio.free = gpiochip_generic_free;
8835b2b135aSThierry Reding 	gpio->gpio.get_direction = tegra186_gpio_get_direction;
8845b2b135aSThierry Reding 	gpio->gpio.direction_input = tegra186_gpio_direction_input;
8855b2b135aSThierry Reding 	gpio->gpio.direction_output = tegra186_gpio_direction_output;
8867de2e5fcSZheng Yongjun 	gpio->gpio.get = tegra186_gpio_get;
8875b2b135aSThierry Reding 	gpio->gpio.set = tegra186_gpio_set;
888adce1183SThierry Reding 	gpio->gpio.set_config = tegra186_gpio_set_config;
889b64d6c9aSThierry Reding 	gpio->gpio.add_pin_ranges = tegra186_gpio_add_pin_ranges;
890b2b56a16SPrathamesh Shete 	gpio->gpio.init_valid_mask = tegra186_init_valid_mask;
89110e4afd6SDipen Patel 	if (gpio->soc->has_gte) {
89210e4afd6SDipen Patel 		gpio->gpio.en_hw_timestamp = tegra186_gpio_en_hw_ts;
89310e4afd6SDipen Patel 		gpio->gpio.dis_hw_timestamp = tegra186_gpio_dis_hw_ts;
89410e4afd6SDipen Patel 	}
8955b2b135aSThierry Reding 
8965b2b135aSThierry Reding 	gpio->gpio.base = -1;
8975b2b135aSThierry Reding 
8985b2b135aSThierry Reding 	for (i = 0; i < gpio->soc->num_ports; i++)
8995b2b135aSThierry Reding 		gpio->gpio.ngpio += gpio->soc->ports[i].pins;
9005b2b135aSThierry Reding 
9015b2b135aSThierry Reding 	names = devm_kcalloc(gpio->gpio.parent, gpio->gpio.ngpio,
9025b2b135aSThierry Reding 			     sizeof(*names), GFP_KERNEL);
9035b2b135aSThierry Reding 	if (!names)
9045b2b135aSThierry Reding 		return -ENOMEM;
9055b2b135aSThierry Reding 
9065b2b135aSThierry Reding 	for (i = 0, offset = 0; i < gpio->soc->num_ports; i++) {
9075b2b135aSThierry Reding 		const struct tegra_gpio_port *port = &gpio->soc->ports[i];
9085b2b135aSThierry Reding 		char *name;
9095b2b135aSThierry Reding 
9105b2b135aSThierry Reding 		for (j = 0; j < port->pins; j++) {
9115b2b135aSThierry Reding 			name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL,
9125b2b135aSThierry Reding 					      "P%s.%02x", port->name, j);
9135b2b135aSThierry Reding 			if (!name)
9145b2b135aSThierry Reding 				return -ENOMEM;
9155b2b135aSThierry Reding 
9165b2b135aSThierry Reding 			names[offset + j] = name;
9175b2b135aSThierry Reding 		}
9185b2b135aSThierry Reding 
9195b2b135aSThierry Reding 		offset += port->pins;
9205b2b135aSThierry Reding 	}
9215b2b135aSThierry Reding 
9225b2b135aSThierry Reding 	gpio->gpio.names = (const char * const *)names;
9235b2b135aSThierry Reding 
9242606e7c9SAkhil R #if defined(CONFIG_OF_GPIO)
9255b2b135aSThierry Reding 	gpio->gpio.of_gpio_n_cells = 2;
9265b2b135aSThierry Reding 	gpio->gpio.of_xlate = tegra186_gpio_of_xlate;
9272606e7c9SAkhil R #endif /* CONFIG_OF_GPIO */
9285b2b135aSThierry Reding 
9295b2b135aSThierry Reding 	irq = &gpio->gpio.irq;
930bba00555SMarc Zyngier 	gpio_irq_chip_set_chip(irq, &tegra186_gpio_irq_chip);
9312a365505SThierry Reding 	irq->fwnode = of_node_to_fwnode(pdev->dev.of_node);
9322a365505SThierry Reding 	irq->child_to_parent_hwirq = tegra186_gpio_child_to_parent_hwirq;
93324258761SKevin Hao 	irq->populate_parent_alloc_arg = tegra186_gpio_populate_parent_fwspec;
9342a365505SThierry Reding 	irq->child_offset_to_irq = tegra186_gpio_child_offset_to_irq;
9352a365505SThierry Reding 	irq->child_irq_domain_ops.translate = tegra186_gpio_irq_domain_translate;
9365b2b135aSThierry Reding 	irq->handler = handle_simple_irq;
9375b2b135aSThierry Reding 	irq->default_type = IRQ_TYPE_NONE;
9385b2b135aSThierry Reding 	irq->parent_handler = tegra186_gpio_irq;
9395b2b135aSThierry Reding 	irq->parent_handler_data = gpio;
9405b2b135aSThierry Reding 	irq->num_parents = gpio->num_irq;
941ca038748SThierry Reding 
942ca038748SThierry Reding 	/*
943ca038748SThierry Reding 	 * To simplify things, use a single interrupt per bank for now. Some
944ca038748SThierry Reding 	 * chips support up to 8 interrupts per bank, which can be useful to
945ca038748SThierry Reding 	 * distribute the load and decrease the processing latency for GPIOs
946ca038748SThierry Reding 	 * but it also requires a more complicated interrupt routing than we
947ca038748SThierry Reding 	 * currently program.
948ca038748SThierry Reding 	 */
949ca038748SThierry Reding 	if (gpio->num_irqs_per_bank > 1) {
950ca038748SThierry Reding 		irq->parents = devm_kcalloc(&pdev->dev, gpio->num_banks,
951ca038748SThierry Reding 					    sizeof(*irq->parents), GFP_KERNEL);
952ca038748SThierry Reding 		if (!irq->parents)
953ca038748SThierry Reding 			return -ENOMEM;
954ca038748SThierry Reding 
955ca038748SThierry Reding 		for (i = 0; i < gpio->num_banks; i++)
956ca038748SThierry Reding 			irq->parents[i] = gpio->irq[i * gpio->num_irqs_per_bank];
957ca038748SThierry Reding 
958ca038748SThierry Reding 		irq->num_parents = gpio->num_banks;
959ca038748SThierry Reding 	} else {
960ca038748SThierry Reding 		irq->num_parents = gpio->num_irq;
9615b2b135aSThierry Reding 		irq->parents = gpio->irq;
962ca038748SThierry Reding 	}
963ca038748SThierry Reding 
96421038680SThierry Reding 	if (gpio->soc->num_irqs_per_bank > 1)
965ca038748SThierry Reding 		tegra186_gpio_init_route_mapping(gpio);
9665b2b135aSThierry Reding 
9672a365505SThierry Reding 	np = of_find_matching_node(NULL, tegra186_pmc_of_match);
9682a365505SThierry Reding 	if (np) {
9695cc9525bSPrathamesh Shete 		if (of_device_is_available(np)) {
9702a365505SThierry Reding 			irq->parent_domain = irq_find_host(np);
9712a365505SThierry Reding 			of_node_put(np);
9722a365505SThierry Reding 
9732a365505SThierry Reding 			if (!irq->parent_domain)
9742a365505SThierry Reding 				return -EPROBE_DEFER;
9755cc9525bSPrathamesh Shete 		} else {
9765cc9525bSPrathamesh Shete 			of_node_put(np);
9775cc9525bSPrathamesh Shete 		}
9782a365505SThierry Reding 	}
9792a365505SThierry Reding 
9805b2b135aSThierry Reding 	irq->map = devm_kcalloc(&pdev->dev, gpio->gpio.ngpio,
9815b2b135aSThierry Reding 				sizeof(*irq->map), GFP_KERNEL);
9825b2b135aSThierry Reding 	if (!irq->map)
9835b2b135aSThierry Reding 		return -ENOMEM;
9845b2b135aSThierry Reding 
9855b2b135aSThierry Reding 	for (i = 0, offset = 0; i < gpio->soc->num_ports; i++) {
9865b2b135aSThierry Reding 		const struct tegra_gpio_port *port = &gpio->soc->ports[i];
9875b2b135aSThierry Reding 
9885b2b135aSThierry Reding 		for (j = 0; j < port->pins; j++)
98913a62a56SThierry Reding 			irq->map[offset + j] = irq->parents[port->bank];
9905b2b135aSThierry Reding 
9915b2b135aSThierry Reding 		offset += port->pins;
9925b2b135aSThierry Reding 	}
9935b2b135aSThierry Reding 
9946e153938SAlexandru Ardelean 	return devm_gpiochip_add_data(&pdev->dev, &gpio->gpio, gpio);
9955b2b135aSThierry Reding }
9965b2b135aSThierry Reding 
99713a62a56SThierry Reding #define TEGRA186_MAIN_GPIO_PORT(_name, _bank, _port, _pins)	\
99813a62a56SThierry Reding 	[TEGRA186_MAIN_GPIO_PORT_##_name] = {			\
99913a62a56SThierry Reding 		.name = #_name,					\
100013a62a56SThierry Reding 		.bank = _bank,					\
100113a62a56SThierry Reding 		.port = _port,					\
100213a62a56SThierry Reding 		.pins = _pins,					\
10035b2b135aSThierry Reding 	}
10045b2b135aSThierry Reding 
10055b2b135aSThierry Reding static const struct tegra_gpio_port tegra186_main_ports[] = {
100613a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT( A, 2, 0, 7),
100713a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT( B, 3, 0, 7),
100813a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT( C, 3, 1, 7),
100913a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT( D, 3, 2, 6),
101013a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT( E, 2, 1, 8),
101113a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT( F, 2, 2, 6),
101213a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT( G, 4, 1, 6),
101313a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT( H, 1, 0, 7),
101413a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT( I, 0, 4, 8),
101513a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT( J, 5, 0, 8),
101613a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT( K, 5, 1, 1),
101713a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT( L, 1, 1, 8),
101813a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT( M, 5, 3, 6),
101913a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT( N, 0, 0, 7),
102013a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT( O, 0, 1, 4),
102113a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT( P, 4, 0, 7),
102213a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT( Q, 0, 2, 6),
102313a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT( R, 0, 5, 6),
102413a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT( T, 0, 3, 4),
102513a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT( X, 1, 2, 8),
102613a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT( Y, 1, 3, 7),
102713a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT(BB, 2, 3, 2),
102813a62a56SThierry Reding 	TEGRA186_MAIN_GPIO_PORT(CC, 5, 2, 4),
10295b2b135aSThierry Reding };
10305b2b135aSThierry Reding 
10315b2b135aSThierry Reding static const struct tegra_gpio_soc tegra186_main_soc = {
10325b2b135aSThierry Reding 	.num_ports = ARRAY_SIZE(tegra186_main_ports),
10335b2b135aSThierry Reding 	.ports = tegra186_main_ports,
10345b2b135aSThierry Reding 	.name = "tegra186-gpio",
10352a365505SThierry Reding 	.instance = 0,
103621038680SThierry Reding 	.num_irqs_per_bank = 1,
1037b2b56a16SPrathamesh Shete 	.has_vm_support = false,
10385b2b135aSThierry Reding };
10395b2b135aSThierry Reding 
104013a62a56SThierry Reding #define TEGRA186_AON_GPIO_PORT(_name, _bank, _port, _pins)	\
104113a62a56SThierry Reding 	[TEGRA186_AON_GPIO_PORT_##_name] = {			\
104213a62a56SThierry Reding 		.name = #_name,					\
104313a62a56SThierry Reding 		.bank = _bank,					\
104413a62a56SThierry Reding 		.port = _port,					\
104513a62a56SThierry Reding 		.pins = _pins,					\
10465b2b135aSThierry Reding 	}
10475b2b135aSThierry Reding 
10485b2b135aSThierry Reding static const struct tegra_gpio_port tegra186_aon_ports[] = {
104913a62a56SThierry Reding 	TEGRA186_AON_GPIO_PORT( S, 0, 1, 5),
105013a62a56SThierry Reding 	TEGRA186_AON_GPIO_PORT( U, 0, 2, 6),
105113a62a56SThierry Reding 	TEGRA186_AON_GPIO_PORT( V, 0, 4, 8),
105213a62a56SThierry Reding 	TEGRA186_AON_GPIO_PORT( W, 0, 5, 8),
105313a62a56SThierry Reding 	TEGRA186_AON_GPIO_PORT( Z, 0, 7, 4),
105413a62a56SThierry Reding 	TEGRA186_AON_GPIO_PORT(AA, 0, 6, 8),
105513a62a56SThierry Reding 	TEGRA186_AON_GPIO_PORT(EE, 0, 3, 3),
105613a62a56SThierry Reding 	TEGRA186_AON_GPIO_PORT(FF, 0, 0, 5),
10575b2b135aSThierry Reding };
10585b2b135aSThierry Reding 
10595b2b135aSThierry Reding static const struct tegra_gpio_soc tegra186_aon_soc = {
10605b2b135aSThierry Reding 	.num_ports = ARRAY_SIZE(tegra186_aon_ports),
10615b2b135aSThierry Reding 	.ports = tegra186_aon_ports,
10625b2b135aSThierry Reding 	.name = "tegra186-gpio-aon",
10632a365505SThierry Reding 	.instance = 1,
106421038680SThierry Reding 	.num_irqs_per_bank = 1,
1065b2b56a16SPrathamesh Shete 	.has_vm_support = false,
10665b2b135aSThierry Reding };
10675b2b135aSThierry Reding 
106813a62a56SThierry Reding #define TEGRA194_MAIN_GPIO_PORT(_name, _bank, _port, _pins)	\
106913a62a56SThierry Reding 	[TEGRA194_MAIN_GPIO_PORT_##_name] = {			\
107013a62a56SThierry Reding 		.name = #_name,					\
107113a62a56SThierry Reding 		.bank = _bank,					\
107213a62a56SThierry Reding 		.port = _port,					\
107313a62a56SThierry Reding 		.pins = _pins,					\
1074bac5c3b8SMikko Perttunen 	}
1075bac5c3b8SMikko Perttunen 
1076bac5c3b8SMikko Perttunen static const struct tegra_gpio_port tegra194_main_ports[] = {
107713a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( A, 1, 2, 8),
107813a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( B, 4, 7, 2),
107913a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( C, 4, 3, 8),
108013a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( D, 4, 4, 4),
108113a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( E, 4, 5, 8),
108213a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( F, 4, 6, 6),
108313a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( G, 4, 0, 8),
108413a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( H, 4, 1, 8),
108513a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( I, 4, 2, 5),
108613a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( J, 5, 1, 6),
108713a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( K, 3, 0, 8),
108813a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( L, 3, 1, 4),
108913a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( M, 2, 3, 8),
109013a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( N, 2, 4, 3),
109113a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( O, 5, 0, 6),
109213a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( P, 2, 5, 8),
109313a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( Q, 2, 6, 8),
109413a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( R, 2, 7, 6),
109513a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( S, 3, 3, 8),
109613a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( T, 3, 4, 8),
109713a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( U, 3, 5, 1),
109813a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( V, 1, 0, 8),
109913a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( W, 1, 1, 2),
110013a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( X, 2, 0, 8),
110113a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( Y, 2, 1, 8),
110213a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT( Z, 2, 2, 8),
110313a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT(FF, 3, 2, 2),
110413a62a56SThierry Reding 	TEGRA194_MAIN_GPIO_PORT(GG, 0, 0, 2)
1105bac5c3b8SMikko Perttunen };
1106bac5c3b8SMikko Perttunen 
1107ffa91e7cSThierry Reding static const struct tegra186_pin_range tegra194_main_pin_ranges[] = {
1108ffa91e7cSThierry Reding 	{ TEGRA194_MAIN_GPIO(GG, 0), "pex_l5_clkreq_n_pgg0" },
1109ffa91e7cSThierry Reding 	{ TEGRA194_MAIN_GPIO(GG, 1), "pex_l5_rst_n_pgg1" },
1110ffa91e7cSThierry Reding };
1111ffa91e7cSThierry Reding 
1112bac5c3b8SMikko Perttunen static const struct tegra_gpio_soc tegra194_main_soc = {
1113bac5c3b8SMikko Perttunen 	.num_ports = ARRAY_SIZE(tegra194_main_ports),
1114bac5c3b8SMikko Perttunen 	.ports = tegra194_main_ports,
1115bac5c3b8SMikko Perttunen 	.name = "tegra194-gpio",
11162a365505SThierry Reding 	.instance = 0,
111721038680SThierry Reding 	.num_irqs_per_bank = 8,
1118ffa91e7cSThierry Reding 	.num_pin_ranges = ARRAY_SIZE(tegra194_main_pin_ranges),
1119ffa91e7cSThierry Reding 	.pin_ranges = tegra194_main_pin_ranges,
1120ffa91e7cSThierry Reding 	.pinmux = "nvidia,tegra194-pinmux",
1121b2b56a16SPrathamesh Shete 	.has_vm_support = true,
1122bac5c3b8SMikko Perttunen };
1123bac5c3b8SMikko Perttunen 
112413a62a56SThierry Reding #define TEGRA194_AON_GPIO_PORT(_name, _bank, _port, _pins)	\
112513a62a56SThierry Reding 	[TEGRA194_AON_GPIO_PORT_##_name] = {			\
112613a62a56SThierry Reding 		.name = #_name,					\
112713a62a56SThierry Reding 		.bank = _bank,					\
112813a62a56SThierry Reding 		.port = _port,					\
112913a62a56SThierry Reding 		.pins = _pins,					\
1130bac5c3b8SMikko Perttunen 	}
1131bac5c3b8SMikko Perttunen 
1132bac5c3b8SMikko Perttunen static const struct tegra_gpio_port tegra194_aon_ports[] = {
113313a62a56SThierry Reding 	TEGRA194_AON_GPIO_PORT(AA, 0, 3, 8),
113413a62a56SThierry Reding 	TEGRA194_AON_GPIO_PORT(BB, 0, 4, 4),
113513a62a56SThierry Reding 	TEGRA194_AON_GPIO_PORT(CC, 0, 1, 8),
113613a62a56SThierry Reding 	TEGRA194_AON_GPIO_PORT(DD, 0, 2, 3),
113713a62a56SThierry Reding 	TEGRA194_AON_GPIO_PORT(EE, 0, 0, 7)
1138bac5c3b8SMikko Perttunen };
1139bac5c3b8SMikko Perttunen 
1140bac5c3b8SMikko Perttunen static const struct tegra_gpio_soc tegra194_aon_soc = {
1141bac5c3b8SMikko Perttunen 	.num_ports = ARRAY_SIZE(tegra194_aon_ports),
1142bac5c3b8SMikko Perttunen 	.ports = tegra194_aon_ports,
1143bac5c3b8SMikko Perttunen 	.name = "tegra194-gpio-aon",
11442a365505SThierry Reding 	.instance = 1,
114521038680SThierry Reding 	.num_irqs_per_bank = 8,
114610e4afd6SDipen Patel 	.has_gte = true,
1147b2b56a16SPrathamesh Shete 	.has_vm_support = false,
1148bac5c3b8SMikko Perttunen };
1149bac5c3b8SMikko Perttunen 
11501db9b241SPrathamesh Shete #define TEGRA234_MAIN_GPIO_PORT(_name, _bank, _port, _pins)	\
11511db9b241SPrathamesh Shete 	[TEGRA234_MAIN_GPIO_PORT_##_name] = {			\
11521db9b241SPrathamesh Shete 		.name = #_name,					\
11531db9b241SPrathamesh Shete 		.bank = _bank,					\
11541db9b241SPrathamesh Shete 		.port = _port,					\
11551db9b241SPrathamesh Shete 		.pins = _pins,					\
11561db9b241SPrathamesh Shete 	}
11571db9b241SPrathamesh Shete 
11581db9b241SPrathamesh Shete static const struct tegra_gpio_port tegra234_main_ports[] = {
11591db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT( A, 0, 0, 8),
11601db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT( B, 0, 3, 1),
11611db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT( C, 5, 1, 8),
11621db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT( D, 5, 2, 4),
11631db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT( E, 5, 3, 8),
11641db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT( F, 5, 4, 6),
11651db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT( G, 4, 0, 8),
11661db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT( H, 4, 1, 8),
11671db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT( I, 4, 2, 7),
11681db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT( J, 5, 0, 6),
11691db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT( K, 3, 0, 8),
11701db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT( L, 3, 1, 4),
11711db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT( M, 2, 0, 8),
11721db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT( N, 2, 1, 8),
11731db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT( P, 2, 2, 8),
11741db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT( Q, 2, 3, 8),
11751db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT( R, 2, 4, 6),
11761db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT( X, 1, 0, 8),
11771db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT( Y, 1, 1, 8),
11781db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT( Z, 1, 2, 8),
11791db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT(AC, 0, 1, 8),
11801db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT(AD, 0, 2, 4),
11811db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT(AE, 3, 3, 2),
11821db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT(AF, 3, 4, 4),
11831db9b241SPrathamesh Shete 	TEGRA234_MAIN_GPIO_PORT(AG, 3, 2, 8),
11841db9b241SPrathamesh Shete };
11851db9b241SPrathamesh Shete 
11861db9b241SPrathamesh Shete static const struct tegra_gpio_soc tegra234_main_soc = {
11871db9b241SPrathamesh Shete 	.num_ports = ARRAY_SIZE(tegra234_main_ports),
11881db9b241SPrathamesh Shete 	.ports = tegra234_main_ports,
11891db9b241SPrathamesh Shete 	.name = "tegra234-gpio",
11901db9b241SPrathamesh Shete 	.instance = 0,
11911db9b241SPrathamesh Shete 	.num_irqs_per_bank = 8,
1192b2b56a16SPrathamesh Shete 	.has_vm_support = true,
11931db9b241SPrathamesh Shete };
11941db9b241SPrathamesh Shete 
11951db9b241SPrathamesh Shete #define TEGRA234_AON_GPIO_PORT(_name, _bank, _port, _pins)	\
11961db9b241SPrathamesh Shete 	[TEGRA234_AON_GPIO_PORT_##_name] = {			\
11971db9b241SPrathamesh Shete 		.name = #_name,					\
11981db9b241SPrathamesh Shete 		.bank = _bank,					\
11991db9b241SPrathamesh Shete 		.port = _port,					\
12001db9b241SPrathamesh Shete 		.pins = _pins,					\
12011db9b241SPrathamesh Shete 	}
12021db9b241SPrathamesh Shete 
12031db9b241SPrathamesh Shete static const struct tegra_gpio_port tegra234_aon_ports[] = {
12041db9b241SPrathamesh Shete 	TEGRA234_AON_GPIO_PORT(AA, 0, 4, 8),
12051db9b241SPrathamesh Shete 	TEGRA234_AON_GPIO_PORT(BB, 0, 5, 4),
12061db9b241SPrathamesh Shete 	TEGRA234_AON_GPIO_PORT(CC, 0, 2, 8),
12071db9b241SPrathamesh Shete 	TEGRA234_AON_GPIO_PORT(DD, 0, 3, 3),
12081db9b241SPrathamesh Shete 	TEGRA234_AON_GPIO_PORT(EE, 0, 0, 8),
12091db9b241SPrathamesh Shete 	TEGRA234_AON_GPIO_PORT(GG, 0, 1, 1),
12101db9b241SPrathamesh Shete };
12111db9b241SPrathamesh Shete 
12121db9b241SPrathamesh Shete static const struct tegra_gpio_soc tegra234_aon_soc = {
12131db9b241SPrathamesh Shete 	.num_ports = ARRAY_SIZE(tegra234_aon_ports),
12141db9b241SPrathamesh Shete 	.ports = tegra234_aon_ports,
12151db9b241SPrathamesh Shete 	.name = "tegra234-gpio-aon",
12161db9b241SPrathamesh Shete 	.instance = 1,
12171db9b241SPrathamesh Shete 	.num_irqs_per_bank = 8,
12187d507452SDipen Patel 	.has_gte = true,
1219b2b56a16SPrathamesh Shete 	.has_vm_support = false,
12201db9b241SPrathamesh Shete };
12211db9b241SPrathamesh Shete 
1222d1056b77SAkhil R #define TEGRA241_MAIN_GPIO_PORT(_name, _bank, _port, _pins)	\
1223d1056b77SAkhil R 	[TEGRA241_MAIN_GPIO_PORT_##_name] = {			\
1224d1056b77SAkhil R 		.name = #_name,					\
1225d1056b77SAkhil R 		.bank = _bank,					\
1226d1056b77SAkhil R 		.port = _port,					\
1227d1056b77SAkhil R 		.pins = _pins,					\
1228d1056b77SAkhil R 	}
1229d1056b77SAkhil R 
1230d1056b77SAkhil R static const struct tegra_gpio_port tegra241_main_ports[] = {
1231d1056b77SAkhil R 	TEGRA241_MAIN_GPIO_PORT(A, 0, 0, 8),
1232d1056b77SAkhil R 	TEGRA241_MAIN_GPIO_PORT(B, 0, 1, 8),
1233d1056b77SAkhil R 	TEGRA241_MAIN_GPIO_PORT(C, 0, 2, 2),
1234d1056b77SAkhil R 	TEGRA241_MAIN_GPIO_PORT(D, 0, 3, 6),
1235d1056b77SAkhil R 	TEGRA241_MAIN_GPIO_PORT(E, 0, 4, 8),
1236d1056b77SAkhil R 	TEGRA241_MAIN_GPIO_PORT(F, 1, 0, 8),
1237d1056b77SAkhil R 	TEGRA241_MAIN_GPIO_PORT(G, 1, 1, 8),
1238d1056b77SAkhil R 	TEGRA241_MAIN_GPIO_PORT(H, 1, 2, 8),
1239d1056b77SAkhil R 	TEGRA241_MAIN_GPIO_PORT(J, 1, 3, 8),
1240d1056b77SAkhil R 	TEGRA241_MAIN_GPIO_PORT(K, 1, 4, 4),
1241d1056b77SAkhil R 	TEGRA241_MAIN_GPIO_PORT(L, 1, 5, 6),
1242d1056b77SAkhil R };
1243d1056b77SAkhil R 
1244d1056b77SAkhil R static const struct tegra_gpio_soc tegra241_main_soc = {
1245d1056b77SAkhil R 	.num_ports = ARRAY_SIZE(tegra241_main_ports),
1246d1056b77SAkhil R 	.ports = tegra241_main_ports,
1247d1056b77SAkhil R 	.name = "tegra241-gpio",
1248d1056b77SAkhil R 	.instance = 0,
12495f84e73fSAkhil R 	.num_irqs_per_bank = 8,
1250b2b56a16SPrathamesh Shete 	.has_vm_support = false,
1251d1056b77SAkhil R };
1252d1056b77SAkhil R 
1253d1056b77SAkhil R #define TEGRA241_AON_GPIO_PORT(_name, _bank, _port, _pins)	\
1254d1056b77SAkhil R 	[TEGRA241_AON_GPIO_PORT_##_name] = {			\
1255d1056b77SAkhil R 		.name = #_name,					\
1256d1056b77SAkhil R 		.bank = _bank,					\
1257d1056b77SAkhil R 		.port = _port,					\
1258d1056b77SAkhil R 		.pins = _pins,					\
1259d1056b77SAkhil R 	}
1260d1056b77SAkhil R 
1261d1056b77SAkhil R static const struct tegra_gpio_port tegra241_aon_ports[] = {
1262d1056b77SAkhil R 	TEGRA241_AON_GPIO_PORT(AA, 0, 0, 8),
1263d1056b77SAkhil R 	TEGRA241_AON_GPIO_PORT(BB, 0, 0, 4),
1264d1056b77SAkhil R };
1265d1056b77SAkhil R 
1266d1056b77SAkhil R static const struct tegra_gpio_soc tegra241_aon_soc = {
1267d1056b77SAkhil R 	.num_ports = ARRAY_SIZE(tegra241_aon_ports),
1268d1056b77SAkhil R 	.ports = tegra241_aon_ports,
1269d1056b77SAkhil R 	.name = "tegra241-gpio-aon",
1270d1056b77SAkhil R 	.instance = 1,
12715f84e73fSAkhil R 	.num_irqs_per_bank = 8,
1272b2b56a16SPrathamesh Shete 	.has_vm_support = false,
1273d1056b77SAkhil R };
1274d1056b77SAkhil R 
12755b2b135aSThierry Reding static const struct of_device_id tegra186_gpio_of_match[] = {
12765b2b135aSThierry Reding 	{
12775b2b135aSThierry Reding 		.compatible = "nvidia,tegra186-gpio",
12785b2b135aSThierry Reding 		.data = &tegra186_main_soc
12795b2b135aSThierry Reding 	}, {
12805b2b135aSThierry Reding 		.compatible = "nvidia,tegra186-gpio-aon",
12815b2b135aSThierry Reding 		.data = &tegra186_aon_soc
12825b2b135aSThierry Reding 	}, {
1283bac5c3b8SMikko Perttunen 		.compatible = "nvidia,tegra194-gpio",
1284bac5c3b8SMikko Perttunen 		.data = &tegra194_main_soc
1285bac5c3b8SMikko Perttunen 	}, {
1286bac5c3b8SMikko Perttunen 		.compatible = "nvidia,tegra194-gpio-aon",
1287bac5c3b8SMikko Perttunen 		.data = &tegra194_aon_soc
1288bac5c3b8SMikko Perttunen 	}, {
12891db9b241SPrathamesh Shete 		.compatible = "nvidia,tegra234-gpio",
12901db9b241SPrathamesh Shete 		.data = &tegra234_main_soc
12911db9b241SPrathamesh Shete 	}, {
12921db9b241SPrathamesh Shete 		.compatible = "nvidia,tegra234-gpio-aon",
12931db9b241SPrathamesh Shete 		.data = &tegra234_aon_soc
12941db9b241SPrathamesh Shete 	}, {
12955b2b135aSThierry Reding 		/* sentinel */
12965b2b135aSThierry Reding 	}
12975b2b135aSThierry Reding };
1298fef2d3bbSMian Yousaf Kaukab MODULE_DEVICE_TABLE(of, tegra186_gpio_of_match);
12995b2b135aSThierry Reding 
13002606e7c9SAkhil R static const struct acpi_device_id  tegra186_gpio_acpi_match[] = {
13012606e7c9SAkhil R 	{ .id = "NVDA0108", .driver_data = (kernel_ulong_t)&tegra186_main_soc },
13022606e7c9SAkhil R 	{ .id = "NVDA0208", .driver_data = (kernel_ulong_t)&tegra186_aon_soc },
13032606e7c9SAkhil R 	{ .id = "NVDA0308", .driver_data = (kernel_ulong_t)&tegra194_main_soc },
13042606e7c9SAkhil R 	{ .id = "NVDA0408", .driver_data = (kernel_ulong_t)&tegra194_aon_soc },
1305d1056b77SAkhil R 	{ .id = "NVDA0508", .driver_data = (kernel_ulong_t)&tegra241_main_soc },
1306d1056b77SAkhil R 	{ .id = "NVDA0608", .driver_data = (kernel_ulong_t)&tegra241_aon_soc },
13072606e7c9SAkhil R 	{}
13082606e7c9SAkhil R };
13092606e7c9SAkhil R MODULE_DEVICE_TABLE(acpi, tegra186_gpio_acpi_match);
13102606e7c9SAkhil R 
13115b2b135aSThierry Reding static struct platform_driver tegra186_gpio_driver = {
13125b2b135aSThierry Reding 	.driver = {
13135b2b135aSThierry Reding 		.name = "tegra186-gpio",
13145b2b135aSThierry Reding 		.of_match_table = tegra186_gpio_of_match,
13152606e7c9SAkhil R 		.acpi_match_table = tegra186_gpio_acpi_match,
13165b2b135aSThierry Reding 	},
13175b2b135aSThierry Reding 	.probe = tegra186_gpio_probe,
13185b2b135aSThierry Reding };
13195b2b135aSThierry Reding module_platform_driver(tegra186_gpio_driver);
13205b2b135aSThierry Reding 
13215b2b135aSThierry Reding MODULE_DESCRIPTION("NVIDIA Tegra186 GPIO controller driver");
13225b2b135aSThierry Reding MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
13235b2b135aSThierry Reding MODULE_LICENSE("GPL v2");
1324