hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/gpio/gpio-max732x.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * MAX732x I2C Port Expander with 8/16 I/O
34 *
....@@ -7,10 +8,6 @@
78 * Copyright (C) 2015 Linus Walleij <linus.walleij@linaro.org>
89 *
910 * 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.
1411 */
1512
1613 #include <linux/module.h>
....@@ -506,6 +503,8 @@
506503
507504 if (((pdata && pdata->irq_base) || client->irq)
508505 && has_irq != INT_NONE) {
506
+ struct gpio_irq_chip *girq;
507
+
509508 if (pdata)
510509 irq_base = pdata->irq_base;
511510 chip->irq_features = has_irq;
....@@ -520,19 +519,17 @@
520519 client->irq);
521520 return ret;
522521 }
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 */
536533 }
537534
538535 return 0;
....@@ -652,12 +649,12 @@
652649 case 0x60:
653650 chip->client_group_a = client;
654651 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)) {
657655 dev_err(&client->dev,
658656 "Failed to allocate I2C device\n");
659
- ret = -ENODEV;
660
- goto out_failed;
657
+ return PTR_ERR(c);
661658 }
662659 chip->client_group_b = chip->client_dummy = c;
663660 }
....@@ -665,12 +662,12 @@
665662 case 0x50:
666663 chip->client_group_b = client;
667664 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)) {
670668 dev_err(&client->dev,
671669 "Failed to allocate I2C device\n");
672
- ret = -ENODEV;
673
- goto out_failed;
670
+ return PTR_ERR(c);
674671 }
675672 chip->client_group_a = chip->client_dummy = c;
676673 }
....@@ -678,39 +675,35 @@
678675 default:
679676 dev_err(&client->dev, "invalid I2C address specified %02x\n",
680677 client->addr);
681
- ret = -EINVAL;
682
- goto out_failed;
678
+ return -EINVAL;
683679 }
684680
685681 if (nr_port > 8 && !chip->client_dummy) {
686682 dev_err(&client->dev,
687683 "Failed to allocate second group I2C device\n");
688
- ret = -ENODEV;
689
- goto out_failed;
684
+ return -ENODEV;
690685 }
691686
692687 mutex_init(&chip->lock);
693688
694689 ret = max732x_readb(chip, is_group_a(chip, 0), &chip->reg_out[0]);
695690 if (ret)
696
- goto out_failed;
691
+ return ret;
697692 if (nr_port > 8) {
698693 ret = max732x_readb(chip, is_group_a(chip, 8), &chip->reg_out[1]);
699694 if (ret)
700
- goto out_failed;
695
+ return ret;
701696 }
702
-
703
- ret = gpiochip_add_data(&chip->gpio_chip, chip);
704
- if (ret)
705
- goto out_failed;
706697
707698 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;
712701
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) {
714707 ret = pdata->setup(client, chip->gpio_chip.base,
715708 chip->gpio_chip.ngpio, pdata->context);
716709 if (ret < 0)
....@@ -719,10 +712,6 @@
719712
720713 i2c_set_clientdata(client, chip);
721714 return 0;
722
-
723
-out_failed:
724
- i2c_unregister_device(chip->client_dummy);
725
- return ret;
726715 }
727716
728717 static int max732x_remove(struct i2c_client *client)
....@@ -741,11 +730,6 @@
741730 return ret;
742731 }
743732 }
744
-
745
- gpiochip_remove(&chip->gpio_chip);
746
-
747
- /* unregister any dummy i2c_client */
748
- i2c_unregister_device(chip->client_dummy);
749733
750734 return 0;
751735 }