| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * MAX732x I2C Port Expander with 8/16 I/O |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 7 | 8 | * Copyright (C) 2015 Linus Walleij <linus.walleij@linaro.org> |
|---|
| 8 | 9 | * |
|---|
| 9 | 10 | * Derived from drivers/gpio/pca953x.c |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 12 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 13 | | - * the Free Software Foundation; version 2 of the License. |
|---|
| 14 | 11 | */ |
|---|
| 15 | 12 | |
|---|
| 16 | 13 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 506 | 503 | |
|---|
| 507 | 504 | if (((pdata && pdata->irq_base) || client->irq) |
|---|
| 508 | 505 | && has_irq != INT_NONE) { |
|---|
| 506 | + struct gpio_irq_chip *girq; |
|---|
| 507 | + |
|---|
| 509 | 508 | if (pdata) |
|---|
| 510 | 509 | irq_base = pdata->irq_base; |
|---|
| 511 | 510 | chip->irq_features = has_irq; |
|---|
| .. | .. |
|---|
| 520 | 519 | client->irq); |
|---|
| 521 | 520 | return ret; |
|---|
| 522 | 521 | } |
|---|
| 523 | | - ret = gpiochip_irqchip_add_nested(&chip->gpio_chip, |
|---|
| 524 | | - &max732x_irq_chip, |
|---|
| 525 | | - irq_base, |
|---|
| 526 | | - handle_simple_irq, |
|---|
| 527 | | - IRQ_TYPE_NONE); |
|---|
| 528 | | - if (ret) { |
|---|
| 529 | | - dev_err(&client->dev, |
|---|
| 530 | | - "could not connect irqchip to gpiochip\n"); |
|---|
| 531 | | - return ret; |
|---|
| 532 | | - } |
|---|
| 533 | | - gpiochip_set_nested_irqchip(&chip->gpio_chip, |
|---|
| 534 | | - &max732x_irq_chip, |
|---|
| 535 | | - client->irq); |
|---|
| 522 | + |
|---|
| 523 | + girq = &chip->gpio_chip.irq; |
|---|
| 524 | + girq->chip = &max732x_irq_chip; |
|---|
| 525 | + /* This will let us handle the parent IRQ in the driver */ |
|---|
| 526 | + girq->parent_handler = NULL; |
|---|
| 527 | + girq->num_parents = 0; |
|---|
| 528 | + girq->parents = NULL; |
|---|
| 529 | + girq->default_type = IRQ_TYPE_NONE; |
|---|
| 530 | + girq->handler = handle_simple_irq; |
|---|
| 531 | + girq->threaded = true; |
|---|
| 532 | + girq->first = irq_base; /* FIXME: get rid of this */ |
|---|
| 536 | 533 | } |
|---|
| 537 | 534 | |
|---|
| 538 | 535 | return 0; |
|---|
| .. | .. |
|---|
| 652 | 649 | case 0x60: |
|---|
| 653 | 650 | chip->client_group_a = client; |
|---|
| 654 | 651 | if (nr_port > 8) { |
|---|
| 655 | | - c = i2c_new_dummy(client->adapter, addr_b); |
|---|
| 656 | | - if (!c) { |
|---|
| 652 | + c = devm_i2c_new_dummy_device(&client->dev, |
|---|
| 653 | + client->adapter, addr_b); |
|---|
| 654 | + if (IS_ERR(c)) { |
|---|
| 657 | 655 | dev_err(&client->dev, |
|---|
| 658 | 656 | "Failed to allocate I2C device\n"); |
|---|
| 659 | | - ret = -ENODEV; |
|---|
| 660 | | - goto out_failed; |
|---|
| 657 | + return PTR_ERR(c); |
|---|
| 661 | 658 | } |
|---|
| 662 | 659 | chip->client_group_b = chip->client_dummy = c; |
|---|
| 663 | 660 | } |
|---|
| .. | .. |
|---|
| 665 | 662 | case 0x50: |
|---|
| 666 | 663 | chip->client_group_b = client; |
|---|
| 667 | 664 | if (nr_port > 8) { |
|---|
| 668 | | - c = i2c_new_dummy(client->adapter, addr_a); |
|---|
| 669 | | - if (!c) { |
|---|
| 665 | + c = devm_i2c_new_dummy_device(&client->dev, |
|---|
| 666 | + client->adapter, addr_a); |
|---|
| 667 | + if (IS_ERR(c)) { |
|---|
| 670 | 668 | dev_err(&client->dev, |
|---|
| 671 | 669 | "Failed to allocate I2C device\n"); |
|---|
| 672 | | - ret = -ENODEV; |
|---|
| 673 | | - goto out_failed; |
|---|
| 670 | + return PTR_ERR(c); |
|---|
| 674 | 671 | } |
|---|
| 675 | 672 | chip->client_group_a = chip->client_dummy = c; |
|---|
| 676 | 673 | } |
|---|
| .. | .. |
|---|
| 678 | 675 | default: |
|---|
| 679 | 676 | dev_err(&client->dev, "invalid I2C address specified %02x\n", |
|---|
| 680 | 677 | client->addr); |
|---|
| 681 | | - ret = -EINVAL; |
|---|
| 682 | | - goto out_failed; |
|---|
| 678 | + return -EINVAL; |
|---|
| 683 | 679 | } |
|---|
| 684 | 680 | |
|---|
| 685 | 681 | if (nr_port > 8 && !chip->client_dummy) { |
|---|
| 686 | 682 | dev_err(&client->dev, |
|---|
| 687 | 683 | "Failed to allocate second group I2C device\n"); |
|---|
| 688 | | - ret = -ENODEV; |
|---|
| 689 | | - goto out_failed; |
|---|
| 684 | + return -ENODEV; |
|---|
| 690 | 685 | } |
|---|
| 691 | 686 | |
|---|
| 692 | 687 | mutex_init(&chip->lock); |
|---|
| 693 | 688 | |
|---|
| 694 | 689 | ret = max732x_readb(chip, is_group_a(chip, 0), &chip->reg_out[0]); |
|---|
| 695 | 690 | if (ret) |
|---|
| 696 | | - goto out_failed; |
|---|
| 691 | + return ret; |
|---|
| 697 | 692 | if (nr_port > 8) { |
|---|
| 698 | 693 | ret = max732x_readb(chip, is_group_a(chip, 8), &chip->reg_out[1]); |
|---|
| 699 | 694 | if (ret) |
|---|
| 700 | | - goto out_failed; |
|---|
| 695 | + return ret; |
|---|
| 701 | 696 | } |
|---|
| 702 | | - |
|---|
| 703 | | - ret = gpiochip_add_data(&chip->gpio_chip, chip); |
|---|
| 704 | | - if (ret) |
|---|
| 705 | | - goto out_failed; |
|---|
| 706 | 697 | |
|---|
| 707 | 698 | ret = max732x_irq_setup(chip, id); |
|---|
| 708 | | - if (ret) { |
|---|
| 709 | | - gpiochip_remove(&chip->gpio_chip); |
|---|
| 710 | | - goto out_failed; |
|---|
| 711 | | - } |
|---|
| 699 | + if (ret) |
|---|
| 700 | + return ret; |
|---|
| 712 | 701 | |
|---|
| 713 | | - if (pdata && pdata->setup) { |
|---|
| 702 | + ret = devm_gpiochip_add_data(&client->dev, &chip->gpio_chip, chip); |
|---|
| 703 | + if (ret) |
|---|
| 704 | + return ret; |
|---|
| 705 | + |
|---|
| 706 | + if (pdata->setup) { |
|---|
| 714 | 707 | ret = pdata->setup(client, chip->gpio_chip.base, |
|---|
| 715 | 708 | chip->gpio_chip.ngpio, pdata->context); |
|---|
| 716 | 709 | if (ret < 0) |
|---|
| .. | .. |
|---|
| 719 | 712 | |
|---|
| 720 | 713 | i2c_set_clientdata(client, chip); |
|---|
| 721 | 714 | return 0; |
|---|
| 722 | | - |
|---|
| 723 | | -out_failed: |
|---|
| 724 | | - i2c_unregister_device(chip->client_dummy); |
|---|
| 725 | | - return ret; |
|---|
| 726 | 715 | } |
|---|
| 727 | 716 | |
|---|
| 728 | 717 | static int max732x_remove(struct i2c_client *client) |
|---|
| .. | .. |
|---|
| 741 | 730 | return ret; |
|---|
| 742 | 731 | } |
|---|
| 743 | 732 | } |
|---|
| 744 | | - |
|---|
| 745 | | - gpiochip_remove(&chip->gpio_chip); |
|---|
| 746 | | - |
|---|
| 747 | | - /* unregister any dummy i2c_client */ |
|---|
| 748 | | - i2c_unregister_device(chip->client_dummy); |
|---|
| 749 | 733 | |
|---|
| 750 | 734 | return 0; |
|---|
| 751 | 735 | } |
|---|