| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2003-2015 Broadcom Corporation |
|---|
| 3 | 4 | * All Rights Reserved |
|---|
| 4 | | - * |
|---|
| 5 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 6 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 7 | | - * published by the Free Software Foundation. |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 10 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 | | - * GNU General Public License for more details. |
|---|
| 13 | 5 | */ |
|---|
| 14 | 6 | |
|---|
| 15 | | -#include <linux/gpio.h> |
|---|
| 7 | +#include <linux/gpio/driver.h> |
|---|
| 16 | 8 | #include <linux/platform_device.h> |
|---|
| 17 | 9 | #include <linux/of_device.h> |
|---|
| 18 | 10 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 298 | 290 | static int xlp_gpio_probe(struct platform_device *pdev) |
|---|
| 299 | 291 | { |
|---|
| 300 | 292 | struct gpio_chip *gc; |
|---|
| 301 | | - struct resource *iores; |
|---|
| 293 | + struct gpio_irq_chip *girq; |
|---|
| 302 | 294 | struct xlp_gpio_priv *priv; |
|---|
| 303 | 295 | void __iomem *gpio_base; |
|---|
| 304 | 296 | int irq_base, irq, err; |
|---|
| 305 | 297 | int ngpio; |
|---|
| 306 | 298 | u32 soc_type; |
|---|
| 307 | 299 | |
|---|
| 308 | | - iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 309 | | - if (!iores) |
|---|
| 310 | | - return -ENODEV; |
|---|
| 311 | | - |
|---|
| 312 | 300 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
|---|
| 313 | 301 | if (!priv) |
|---|
| 314 | 302 | return -ENOMEM; |
|---|
| 315 | 303 | |
|---|
| 316 | | - gpio_base = devm_ioremap_resource(&pdev->dev, iores); |
|---|
| 304 | + gpio_base = devm_platform_ioremap_resource(pdev, 0); |
|---|
| 317 | 305 | if (IS_ERR(gpio_base)) |
|---|
| 318 | 306 | return PTR_ERR(gpio_base); |
|---|
| 319 | 307 | |
|---|
| .. | .. |
|---|
| 408 | 396 | irq_base = 0; |
|---|
| 409 | 397 | } |
|---|
| 410 | 398 | |
|---|
| 399 | + girq = &gc->irq; |
|---|
| 400 | + girq->chip = &xlp_gpio_irq_chip; |
|---|
| 401 | + girq->parent_handler = xlp_gpio_generic_handler; |
|---|
| 402 | + girq->num_parents = 1; |
|---|
| 403 | + girq->parents = devm_kcalloc(&pdev->dev, 1, |
|---|
| 404 | + sizeof(*girq->parents), |
|---|
| 405 | + GFP_KERNEL); |
|---|
| 406 | + if (!girq->parents) |
|---|
| 407 | + return -ENOMEM; |
|---|
| 408 | + girq->parents[0] = irq; |
|---|
| 409 | + girq->first = irq_base; |
|---|
| 410 | + girq->default_type = IRQ_TYPE_NONE; |
|---|
| 411 | + girq->handler = handle_level_irq; |
|---|
| 412 | + |
|---|
| 411 | 413 | err = gpiochip_add_data(gc, priv); |
|---|
| 412 | 414 | if (err < 0) |
|---|
| 413 | 415 | return err; |
|---|
| 414 | 416 | |
|---|
| 415 | | - err = gpiochip_irqchip_add(gc, &xlp_gpio_irq_chip, irq_base, |
|---|
| 416 | | - handle_level_irq, IRQ_TYPE_NONE); |
|---|
| 417 | | - if (err) { |
|---|
| 418 | | - dev_err(&pdev->dev, "Could not connect irqchip to gpiochip!\n"); |
|---|
| 419 | | - goto out_gpio_remove; |
|---|
| 420 | | - } |
|---|
| 421 | | - |
|---|
| 422 | | - gpiochip_set_chained_irqchip(gc, &xlp_gpio_irq_chip, irq, |
|---|
| 423 | | - xlp_gpio_generic_handler); |
|---|
| 424 | | - |
|---|
| 425 | 417 | dev_info(&pdev->dev, "registered %d GPIOs\n", gc->ngpio); |
|---|
| 426 | 418 | |
|---|
| 427 | 419 | return 0; |
|---|
| 428 | | - |
|---|
| 429 | | -out_gpio_remove: |
|---|
| 430 | | - gpiochip_remove(gc); |
|---|
| 431 | | - return err; |
|---|
| 432 | 420 | } |
|---|
| 433 | 421 | |
|---|
| 434 | 422 | #ifdef CONFIG_ACPI |
|---|