.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Pistachio SoC pinctrl driver |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2014 Imagination Technologies Ltd. |
---|
5 | 6 | * Copyright (C) 2014 Google, Inc. |
---|
6 | | - * |
---|
7 | | - * This program is free software; you can redistribute it and/or modify it |
---|
8 | | - * under the terms and conditions of the GNU General Public License, |
---|
9 | | - * version 2, as published by the Free Software Foundation. |
---|
10 | 7 | */ |
---|
11 | 8 | |
---|
12 | | -#include <linux/gpio.h> |
---|
13 | 9 | #include <linux/gpio/driver.h> |
---|
14 | 10 | #include <linux/interrupt.h> |
---|
15 | 11 | #include <linux/io.h> |
---|
.. | .. |
---|
1170 | 1166 | { |
---|
1171 | 1167 | struct pistachio_gpio_bank *bank = gpiochip_get_data(chip); |
---|
1172 | 1168 | |
---|
1173 | | - return !(gpio_readl(bank, GPIO_OUTPUT_EN) & BIT(offset)); |
---|
| 1169 | + if (gpio_readl(bank, GPIO_OUTPUT_EN) & BIT(offset)) |
---|
| 1170 | + return GPIO_LINE_DIRECTION_OUT; |
---|
| 1171 | + |
---|
| 1172 | + return GPIO_LINE_DIRECTION_IN; |
---|
1174 | 1173 | } |
---|
1175 | 1174 | |
---|
1176 | 1175 | static int pistachio_gpio_get(struct gpio_chip *chip, unsigned offset) |
---|
.. | .. |
---|
1356 | 1355 | for (i = 0; i < pctl->nbanks; i++) { |
---|
1357 | 1356 | char child_name[sizeof("gpioXX")]; |
---|
1358 | 1357 | struct device_node *child; |
---|
| 1358 | + struct gpio_irq_chip *girq; |
---|
1359 | 1359 | |
---|
1360 | 1360 | snprintf(child_name, sizeof(child_name), "gpio%d", i); |
---|
1361 | 1361 | child = of_get_child_by_name(node, child_name); |
---|
.. | .. |
---|
1374 | 1374 | } |
---|
1375 | 1375 | |
---|
1376 | 1376 | irq = irq_of_parse_and_map(child, 0); |
---|
1377 | | - if (irq < 0) { |
---|
1378 | | - dev_err(pctl->dev, "No IRQ for bank %u: %d\n", i, irq); |
---|
| 1377 | + if (!irq) { |
---|
| 1378 | + dev_err(pctl->dev, "No IRQ for bank %u\n", i); |
---|
1379 | 1379 | of_node_put(child); |
---|
1380 | | - ret = irq; |
---|
| 1380 | + ret = -EINVAL; |
---|
1381 | 1381 | goto err; |
---|
1382 | 1382 | } |
---|
1383 | 1383 | |
---|
.. | .. |
---|
1387 | 1387 | |
---|
1388 | 1388 | bank->gpio_chip.parent = pctl->dev; |
---|
1389 | 1389 | bank->gpio_chip.of_node = child; |
---|
| 1390 | + |
---|
| 1391 | + girq = &bank->gpio_chip.irq; |
---|
| 1392 | + girq->chip = &bank->irq_chip; |
---|
| 1393 | + girq->parent_handler = pistachio_gpio_irq_handler; |
---|
| 1394 | + girq->num_parents = 1; |
---|
| 1395 | + girq->parents = devm_kcalloc(pctl->dev, 1, |
---|
| 1396 | + sizeof(*girq->parents), |
---|
| 1397 | + GFP_KERNEL); |
---|
| 1398 | + if (!girq->parents) { |
---|
| 1399 | + ret = -ENOMEM; |
---|
| 1400 | + goto err; |
---|
| 1401 | + } |
---|
| 1402 | + girq->parents[0] = irq; |
---|
| 1403 | + girq->default_type = IRQ_TYPE_NONE; |
---|
| 1404 | + girq->handler = handle_level_irq; |
---|
| 1405 | + |
---|
1390 | 1406 | ret = gpiochip_add_data(&bank->gpio_chip, bank); |
---|
1391 | 1407 | if (ret < 0) { |
---|
1392 | 1408 | dev_err(pctl->dev, "Failed to add GPIO chip %u: %d\n", |
---|
1393 | 1409 | i, ret); |
---|
1394 | 1410 | goto err; |
---|
1395 | 1411 | } |
---|
1396 | | - |
---|
1397 | | - ret = gpiochip_irqchip_add(&bank->gpio_chip, &bank->irq_chip, |
---|
1398 | | - 0, handle_level_irq, IRQ_TYPE_NONE); |
---|
1399 | | - if (ret < 0) { |
---|
1400 | | - dev_err(pctl->dev, "Failed to add IRQ chip %u: %d\n", |
---|
1401 | | - i, ret); |
---|
1402 | | - gpiochip_remove(&bank->gpio_chip); |
---|
1403 | | - goto err; |
---|
1404 | | - } |
---|
1405 | | - gpiochip_set_chained_irqchip(&bank->gpio_chip, &bank->irq_chip, |
---|
1406 | | - irq, pistachio_gpio_irq_handler); |
---|
1407 | 1412 | |
---|
1408 | 1413 | ret = gpiochip_add_pin_range(&bank->gpio_chip, |
---|
1409 | 1414 | dev_name(pctl->dev), 0, |
---|
.. | .. |
---|
1433 | 1438 | static int pistachio_pinctrl_probe(struct platform_device *pdev) |
---|
1434 | 1439 | { |
---|
1435 | 1440 | struct pistachio_pinctrl *pctl; |
---|
1436 | | - struct resource *res; |
---|
1437 | 1441 | |
---|
1438 | 1442 | pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL); |
---|
1439 | 1443 | if (!pctl) |
---|
.. | .. |
---|
1441 | 1445 | pctl->dev = &pdev->dev; |
---|
1442 | 1446 | dev_set_drvdata(&pdev->dev, pctl); |
---|
1443 | 1447 | |
---|
1444 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
1445 | | - pctl->base = devm_ioremap_resource(&pdev->dev, res); |
---|
| 1448 | + pctl->base = devm_platform_ioremap_resource(pdev, 0); |
---|
1446 | 1449 | if (IS_ERR(pctl->base)) |
---|
1447 | 1450 | return PTR_ERR(pctl->base); |
---|
1448 | 1451 | |
---|