From: "Marek Behún" <kabel@kernel.org>
To: Arnd Bergmann <arnd@arndb.de>, soc@kernel.org
Cc: arm@kernel.org, "Andy Shevchenko" <andy@kernel.org>,
"Hans de Goede" <hdegoede@redhat.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
linux-crypto@vger.kernel.org,
"Herbert Xu" <herbert@gondor.apana.org.au>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Marek Behún" <kabel@kernel.org>
Subject: [PATCH 1/5] platform: cznic: turris-omnia-mcu: Refactor requesting MCU interrupt
Date: Tue, 4 Feb 2025 14:14:11 +0100 [thread overview]
Message-ID: <20250204131415.27014-2-kabel@kernel.org> (raw)
In-Reply-To: <20250204131415.27014-1-kabel@kernel.org>
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>
---
.../platform/cznic/turris-omnia-mcu-gpio.c | 21 ++++++++++++++++++-
.../platform/cznic/turris-omnia-mcu-trng.c | 17 ++++-----------
drivers/platform/cznic/turris-omnia-mcu.h | 4 +++-
3 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/drivers/platform/cznic/turris-omnia-mcu-gpio.c b/drivers/platform/cznic/turris-omnia-mcu-gpio.c
index 5f35f7c5d5d7..932383f7491a 100644
--- a/drivers/platform/cznic/turris-omnia-mcu-gpio.c
+++ b/drivers/platform/cznic/turris-omnia-mcu-gpio.c
@@ -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);
+}
diff --git a/drivers/platform/cznic/turris-omnia-mcu-trng.c b/drivers/platform/cznic/turris-omnia-mcu-trng.c
index 9a1d9292dc9a..e3826959e6de 100644
--- a/drivers/platform/cznic/turris-omnia-mcu-trng.c
+++ b/drivers/platform/cznic/turris-omnia-mcu-trng.c
@@ -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");
diff --git a/drivers/platform/cznic/turris-omnia-mcu.h b/drivers/platform/cznic/turris-omnia-mcu.h
index 088541be3f4c..f2084880a00c 100644
--- a/drivers/platform/cznic/turris-omnia-mcu.h
+++ b/drivers/platform/cznic/turris-omnia-mcu.h
@@ -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)
{
--
2.45.3
next prev parent reply other threads:[~2025-02-04 13:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-04 13:14 [PATCH 0/5] Turris ECDSA signatures via keyctl() Marek Behún
2025-02-04 13:14 ` Marek Behún [this message]
2025-02-04 13:14 ` [PATCH 2/5] platform: cznic: Add keyctl helpers for Turris platform Marek Behún
2025-02-04 13:14 ` [PATCH 3/5] platform: cznic: turris-omnia-mcu: Add support for digital message signing with HW private key Marek Behún
2025-02-04 13:14 ` [PATCH 4/5] firmware: turris-mox-rwtm: Drop ECDSA signatures via debugfs Marek Behún
2025-02-04 13:14 ` [PATCH 5/5] firmware: turris-mox-rwtm: Add support for ECDSA signatures with HW private key Marek Behún
2025-02-20 12:47 ` [PATCH 0/5] Turris ECDSA signatures via keyctl() Marek Behún
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250204131415.27014-2-kabel@kernel.org \
--to=kabel@kernel.org \
--cc=andy@kernel.org \
--cc=arm@kernel.org \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=hdegoede@redhat.com \
--cc=herbert@gondor.apana.org.au \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-crypto@vger.kernel.org \
--cc=soc@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).