]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
platform: cznic: turris-omnia-mcu: Refactor requesting MCU interrupt
authorMarek Behún <kabel@kernel.org>
Tue, 4 Feb 2025 13:14:11 +0000 (14:14 +0100)
committerArnd Bergmann <arnd@arndb.de>
Thu, 20 Mar 2025 16:56:56 +0000 (17:56 +0100)
Refactor the code that gets and requests the TRNG MCU interrupt in the
TRNG part of the driver into a helper function and put it into the GPIO
part of the driver.

Signed-off-by: Marek Behún <kabel@kernel.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
drivers/platform/cznic/turris-omnia-mcu-gpio.c
drivers/platform/cznic/turris-omnia-mcu-trng.c
drivers/platform/cznic/turris-omnia-mcu.h

index 5f35f7c5d5d7ed041e9e3153ebfaab52ed5dce5f..932383f7491a31db9ab7fee9e5481ec5e534111a 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/device.h>
 #include <linux/devm-helpers.h>
 #include <linux/errno.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio/driver.h>
 #include <linux/i2c.h>
 #include <linux/interrupt.h>
@@ -195,7 +196,7 @@ static const struct omnia_gpio omnia_gpios[64] = {
 };
 
 /* mapping from interrupts to indexes of GPIOs in the omnia_gpios array */
-const u8 omnia_int_to_gpio_idx[32] = {
+static const u8 omnia_int_to_gpio_idx[32] = {
        [__bf_shf(OMNIA_INT_CARD_DET)]                  = 4,
        [__bf_shf(OMNIA_INT_MSATA_IND)]                 = 5,
        [__bf_shf(OMNIA_INT_USB30_OVC)]                 = 6,
@@ -1093,3 +1094,21 @@ int omnia_mcu_register_gpiochip(struct omnia_mcu *mcu)
 
        return 0;
 }
+
+int omnia_mcu_request_irq(struct omnia_mcu *mcu, u32 spec,
+                         irq_handler_t thread_fn, const char *devname)
+{
+       u8 irq_idx;
+       int irq;
+
+       if (!spec)
+               return -EINVAL;
+
+       irq_idx = omnia_int_to_gpio_idx[__bf_shf(spec)];
+       irq = gpiod_to_irq(gpio_device_get_desc(mcu->gc.gpiodev, irq_idx));
+       if (irq < 0)
+               return irq;
+
+       return devm_request_threaded_irq(&mcu->client->dev, irq, NULL,
+                                        thread_fn, IRQF_ONESHOT, devname, mcu);
+}
index 9a1d9292dc9ad3908c87e5c3acdcc28d3cd1bdca..e3826959e6de5a394d7c2482d3cd66859fdabdfc 100644 (file)
@@ -5,12 +5,9 @@
  * 2024 by Marek Behún <kabel@kernel.org>
  */
 
-#include <linux/bitfield.h>
 #include <linux/completion.h>
 #include <linux/container_of.h>
 #include <linux/errno.h>
-#include <linux/gpio/consumer.h>
-#include <linux/gpio/driver.h>
 #include <linux/hw_random.h>
 #include <linux/i2c.h>
 #include <linux/interrupt.h>
@@ -62,17 +59,12 @@ static int omnia_trng_read(struct hwrng *rng, void *data, size_t max, bool wait)
 int omnia_mcu_register_trng(struct omnia_mcu *mcu)
 {
        struct device *dev = &mcu->client->dev;
-       u8 irq_idx, dummy;
-       int irq, err;
+       u8 dummy;
+       int err;
 
        if (!(mcu->features & OMNIA_FEAT_TRNG))
                return 0;
 
-       irq_idx = omnia_int_to_gpio_idx[__bf_shf(OMNIA_INT_TRNG)];
-       irq = gpiod_to_irq(gpio_device_get_desc(mcu->gc.gpiodev, irq_idx));
-       if (irq < 0)
-               return dev_err_probe(dev, irq, "Cannot get TRNG IRQ\n");
-
        /*
         * If someone else cleared the TRNG interrupt but did not read the
         * entropy, a new interrupt won't be generated, and entropy collection
@@ -86,9 +78,8 @@ int omnia_mcu_register_trng(struct omnia_mcu *mcu)
 
        init_completion(&mcu->trng_entropy_ready);
 
-       err = devm_request_threaded_irq(dev, irq, NULL, omnia_trng_irq_handler,
-                                       IRQF_ONESHOT, "turris-omnia-mcu-trng",
-                                       mcu);
+       err = omnia_mcu_request_irq(mcu, OMNIA_INT_TRNG, omnia_trng_irq_handler,
+                                   "turris-omnia-mcu-trng");
        if (err)
                return dev_err_probe(dev, err, "Cannot request TRNG IRQ\n");
 
index 088541be3f4cc045cbce5b5aaeaac8eb6162a8d3..f2084880a00cfb61ae1a329ac1aa143ea76925a9 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/gpio/driver.h>
 #include <linux/hw_random.h>
 #include <linux/if_ether.h>
+#include <linux/interrupt.h>
 #include <linux/mutex.h>
 #include <linux/types.h>
 #include <linux/watchdog.h>
@@ -91,9 +92,10 @@ struct omnia_mcu {
 };
 
 #ifdef CONFIG_TURRIS_OMNIA_MCU_GPIO
-extern const u8 omnia_int_to_gpio_idx[32];
 extern const struct attribute_group omnia_mcu_gpio_group;
 int omnia_mcu_register_gpiochip(struct omnia_mcu *mcu);
+int omnia_mcu_request_irq(struct omnia_mcu *mcu, u32 spec,
+                         irq_handler_t thread_fn, const char *devname);
 #else
 static inline int omnia_mcu_register_gpiochip(struct omnia_mcu *mcu)
 {