| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Driver for NEC VR4100 series General-purpose I/O Unit. |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2002 MontaVista Software Inc. |
|---|
| 5 | 6 | * Author: Yoichi Yuasa <source@mvista.com> |
|---|
| 6 | 7 | * Copyright (C) 2003-2009 Yoichi Yuasa <yuasa@linux-mips.org> |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 9 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 10 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 11 | | - * (at your option) any later version. |
|---|
| 12 | | - * |
|---|
| 13 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 14 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | | - * GNU General Public License for more details. |
|---|
| 17 | | - * |
|---|
| 18 | | - * You should have received a copy of the GNU General Public License |
|---|
| 19 | | - * along with this program; if not, write to the Free Software |
|---|
| 20 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 21 | 8 | */ |
|---|
| 22 | 9 | #include <linux/errno.h> |
|---|
| 23 | 10 | #include <linux/fs.h> |
|---|
| 24 | | -#include <linux/gpio.h> |
|---|
| 11 | +#include <linux/gpio/driver.h> |
|---|
| 25 | 12 | #include <linux/init.h> |
|---|
| 26 | 13 | #include <linux/interrupt.h> |
|---|
| 27 | 14 | #include <linux/io.h> |
|---|
| .. | .. |
|---|
| 230 | 217 | printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n", |
|---|
| 231 | 218 | maskl, pendl, maskh, pendh); |
|---|
| 232 | 219 | |
|---|
| 233 | | - atomic_inc(&irq_err_count); |
|---|
| 234 | | - |
|---|
| 235 | 220 | return -EINVAL; |
|---|
| 236 | 221 | } |
|---|
| 237 | 222 | |
|---|
| .. | .. |
|---|
| 384 | 369 | return 0; |
|---|
| 385 | 370 | } |
|---|
| 386 | 371 | |
|---|
| 387 | | -int vr41xx_gpio_pullupdown(unsigned int pin, gpio_pull_t pull) |
|---|
| 388 | | -{ |
|---|
| 389 | | - u16 reg, mask; |
|---|
| 390 | | - unsigned long flags; |
|---|
| 391 | | - |
|---|
| 392 | | - if ((giu_flags & GPIO_HAS_PULLUPDOWN_IO) != GPIO_HAS_PULLUPDOWN_IO) |
|---|
| 393 | | - return -EPERM; |
|---|
| 394 | | - |
|---|
| 395 | | - if (pin >= 15) |
|---|
| 396 | | - return -EINVAL; |
|---|
| 397 | | - |
|---|
| 398 | | - mask = 1 << pin; |
|---|
| 399 | | - |
|---|
| 400 | | - spin_lock_irqsave(&giu_lock, flags); |
|---|
| 401 | | - |
|---|
| 402 | | - if (pull == GPIO_PULL_UP || pull == GPIO_PULL_DOWN) { |
|---|
| 403 | | - reg = giu_read(GIUTERMUPDN); |
|---|
| 404 | | - if (pull == GPIO_PULL_UP) |
|---|
| 405 | | - reg |= mask; |
|---|
| 406 | | - else |
|---|
| 407 | | - reg &= ~mask; |
|---|
| 408 | | - giu_write(GIUTERMUPDN, reg); |
|---|
| 409 | | - |
|---|
| 410 | | - reg = giu_read(GIUUSEUPDN); |
|---|
| 411 | | - reg |= mask; |
|---|
| 412 | | - giu_write(GIUUSEUPDN, reg); |
|---|
| 413 | | - } else { |
|---|
| 414 | | - reg = giu_read(GIUUSEUPDN); |
|---|
| 415 | | - reg &= ~mask; |
|---|
| 416 | | - giu_write(GIUUSEUPDN, reg); |
|---|
| 417 | | - } |
|---|
| 418 | | - |
|---|
| 419 | | - spin_unlock_irqrestore(&giu_lock, flags); |
|---|
| 420 | | - |
|---|
| 421 | | - return 0; |
|---|
| 422 | | -} |
|---|
| 423 | | -EXPORT_SYMBOL_GPL(vr41xx_gpio_pullupdown); |
|---|
| 424 | | - |
|---|
| 425 | 372 | static int vr41xx_gpio_get(struct gpio_chip *chip, unsigned pin) |
|---|
| 426 | 373 | { |
|---|
| 427 | 374 | u16 reg, mask; |
|---|
| .. | .. |
|---|
| 518 | 465 | |
|---|
| 519 | 466 | static int giu_probe(struct platform_device *pdev) |
|---|
| 520 | 467 | { |
|---|
| 521 | | - struct resource *res; |
|---|
| 522 | 468 | unsigned int trigger, i, pin; |
|---|
| 523 | 469 | struct irq_chip *chip; |
|---|
| 524 | | - int irq, ret; |
|---|
| 470 | + int irq; |
|---|
| 525 | 471 | |
|---|
| 526 | 472 | switch (pdev->id) { |
|---|
| 527 | 473 | case GPIO_50PINS_PULLUPDOWN: |
|---|
| .. | .. |
|---|
| 540 | 486 | return -ENODEV; |
|---|
| 541 | 487 | } |
|---|
| 542 | 488 | |
|---|
| 543 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 544 | | - if (!res) |
|---|
| 545 | | - return -EBUSY; |
|---|
| 546 | | - |
|---|
| 547 | | - giu_base = ioremap(res->start, resource_size(res)); |
|---|
| 548 | | - if (!giu_base) |
|---|
| 549 | | - return -ENOMEM; |
|---|
| 489 | + giu_base = devm_platform_ioremap_resource(pdev, 0); |
|---|
| 490 | + if (IS_ERR(giu_base)) |
|---|
| 491 | + return PTR_ERR(giu_base); |
|---|
| 550 | 492 | |
|---|
| 551 | 493 | vr41xx_gpio_chip.parent = &pdev->dev; |
|---|
| 552 | 494 | |
|---|
| 553 | | - ret = gpiochip_add_data(&vr41xx_gpio_chip, NULL); |
|---|
| 554 | | - if (!ret) { |
|---|
| 555 | | - iounmap(giu_base); |
|---|
| 495 | + if (gpiochip_add_data(&vr41xx_gpio_chip, NULL)) |
|---|
| 556 | 496 | return -ENODEV; |
|---|
| 557 | | - } |
|---|
| 558 | 497 | |
|---|
| 559 | 498 | giu_write(GIUINTENL, 0); |
|---|
| 560 | 499 | giu_write(GIUINTENH, 0); |
|---|
| .. | .. |
|---|
| 585 | 524 | static int giu_remove(struct platform_device *pdev) |
|---|
| 586 | 525 | { |
|---|
| 587 | 526 | if (giu_base) { |
|---|
| 588 | | - iounmap(giu_base); |
|---|
| 589 | 527 | giu_base = NULL; |
|---|
| 590 | 528 | } |
|---|
| 591 | 529 | |
|---|