All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Matti Vaittinen <mazziesaccount@gmail.com>, Lee Jones <lee@kernel.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Arnd Bergmann <arnd@kernel.org>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	Linus Walleij <linus.walleij@linaro.org>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] mfd: rohm-bd71828: Use software nodes for gpio-keys
Date: Sun, 17 Aug 2025 15:47:27 -0700	[thread overview]
Message-ID: <20250817224731.1911207-2-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20250817224731.1911207-1-dmitry.torokhov@gmail.com>

Refactor the rohm-bd71828 MFD driver to use software nodes for
instantiating the gpio-keys child device, replacing the old
platform_data mechanism.

The power key's properties are now defined using software nodes and
property entries. The IRQ is passed as a resource attached to the
platform device.

This will allow dropping support for using platform data for configuring
gpio-keys in the future.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/mfd/rohm-bd71828.c | 81 +++++++++++++++++++++++++++-----------
 1 file changed, 58 insertions(+), 23 deletions(-)

diff --git a/drivers/mfd/rohm-bd71828.c b/drivers/mfd/rohm-bd71828.c
index a14b7aa69c3c..c29dde9996b7 100644
--- a/drivers/mfd/rohm-bd71828.c
+++ b/drivers/mfd/rohm-bd71828.c
@@ -4,7 +4,6 @@
 //
 // ROHM BD71828/BD71815 PMIC driver
 
-#include <linux/gpio_keys.h>
 #include <linux/i2c.h>
 #include <linux/input.h>
 #include <linux/interrupt.h>
@@ -16,21 +15,32 @@
 #include <linux/mfd/rohm-generic.h>
 #include <linux/module.h>
 #include <linux/of.h>
+#include <linux/property.h>
 #include <linux/regmap.h>
 #include <linux/types.h>
 
-static struct gpio_keys_button button = {
-	.code = KEY_POWER,
-	.gpio = -1,
-	.type = EV_KEY,
+static const struct software_node bd71828_pwrkey_node = {
+	.name = "bd71828-power-key",
 };
 
-static const struct gpio_keys_platform_data bd71828_powerkey_data = {
-	.buttons = &button,
-	.nbuttons = 1,
-	.name = "bd71828-pwrkey",
+static const struct property_entry bd71828_powerkey_props[] = {
+	PROPERTY_ENTRY_U32("linux,code", KEY_POWER),
+	PROPERTY_ENTRY_STRING("label", "bd71828-pwrkey"),
+	{ }
 };
 
+static const struct software_node bd71828_powerkey_key_node = {
+	.properties = bd71828_powerkey_props,
+	.parent = &bd71828_pwrkey_node,
+};
+
+static const struct software_node *bd71828_swnodes[] = {
+	&bd71828_pwrkey_node,
+	&bd71828_powerkey_key_node,
+	NULL,
+};
+
+
 static const struct resource bd71815_rtc_irqs[] = {
 	DEFINE_RES_IRQ_NAMED(BD71815_INT_RTC0, "bd70528-rtc-alm-0"),
 	DEFINE_RES_IRQ_NAMED(BD71815_INT_RTC1, "bd70528-rtc-alm-1"),
@@ -93,6 +103,10 @@ static const struct resource bd71815_power_irqs[] = {
 	DEFINE_RES_IRQ_NAMED(BD71815_INT_TEMP_BAT_HI_DET, "bd71815-bat-hi-det"),
 };
 
+static const struct resource bd71828_powerkey_irq_resources[] = {
+	DEFINE_RES_IRQ_NAMED(BD71828_INT_SHORTPUSH, "bd71828-pwrkey"),
+};
+
 static const struct mfd_cell bd71815_mfd_cells[] = {
 	{ .name = "bd71815-pmic", },
 	{ .name = "bd71815-clk", },
@@ -125,8 +139,9 @@ static const struct mfd_cell bd71828_mfd_cells[] = {
 		.num_resources = ARRAY_SIZE(bd71828_rtc_irqs),
 	}, {
 		.name = "gpio-keys",
-		.platform_data = &bd71828_powerkey_data,
-		.pdata_size = sizeof(bd71828_powerkey_data),
+		.swnode = &bd71828_pwrkey_node,
+		.resources = bd71828_powerkey_irq_resources,
+		.num_resources = ARRAY_SIZE(bd71828_powerkey_irq_resources),
 	},
 };
 
@@ -464,6 +479,30 @@ static int set_clk_mode(struct device *dev, struct regmap *regmap,
 				  OUT32K_MODE_CMOS);
 }
 
+static int bd71828_reg_cnt;
+
+static int bd71828_i2c_register_swnodes(void)
+{
+	int error;
+
+	if (bd71828_reg_cnt == 0) {
+		error = software_node_register_node_group(bd71828_swnodes);
+		if (error)
+			return error;
+	}
+
+	bd71828_reg_cnt++;
+	return 0;
+}
+
+static void bd71828_i2c_unregister_swnodes(void *dummy)
+{
+	if (bd71828_reg_cnt != 0) {
+		software_node_unregister_node_group(bd71828_swnodes);
+		bd71828_reg_cnt--;
+	}
+}
+
 static struct i2c_client *bd71828_dev;
 static void bd71828_power_off(void)
 {
@@ -495,7 +534,6 @@ static int bd71828_i2c_probe(struct i2c_client *i2c)
 	unsigned int chip_type;
 	const struct mfd_cell *mfd;
 	int cells;
-	int button_irq;
 	int clkmode_reg;
 
 	if (!i2c->irq) {
@@ -512,7 +550,14 @@ static int bd71828_i2c_probe(struct i2c_client *i2c)
 		regmap_config = &bd71828_regmap;
 		irqchip = &bd71828_irq_chip;
 		clkmode_reg = BD71828_REG_OUT32K;
-		button_irq = BD71828_INT_SHORTPUSH;
+		ret = bd71828_i2c_register_swnodes();
+		if (ret)
+			return dev_err_probe(&i2c->dev, ret, "Failed to register swnodes\n");
+
+		ret = devm_add_action_or_reset(&i2c->dev, bd71828_i2c_unregister_swnodes, NULL);
+		if (ret)
+			return ret;
+
 		break;
 	case ROHM_CHIP_TYPE_BD71815:
 		mfd = bd71815_mfd_cells;
@@ -526,7 +571,6 @@ static int bd71828_i2c_probe(struct i2c_client *i2c)
 		 * BD71815 data-sheet does not list the power-button IRQ so we
 		 * don't use it.
 		 */
-		button_irq = 0;
 		break;
 	default:
 		dev_err(&i2c->dev, "Unknown device type");
@@ -547,15 +591,6 @@ static int bd71828_i2c_probe(struct i2c_client *i2c)
 	dev_dbg(&i2c->dev, "Registered %d IRQs for chip\n",
 		irqchip->num_irqs);
 
-	if (button_irq) {
-		ret = regmap_irq_get_virq(irq_data, button_irq);
-		if (ret < 0)
-			return dev_err_probe(&i2c->dev, ret,
-					     "Failed to get the power-key IRQ\n");
-
-		button.irq = ret;
-	}
-
 	ret = set_clk_mode(&i2c->dev, regmap, clkmode_reg);
 	if (ret)
 		return ret;
-- 
2.51.0.rc1.163.g2494970778-goog


  reply	other threads:[~2025-08-17 22:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-17 22:47 [PATCH 1/3] Input: gpio_keys - fall back to platform_get_irq() for interrupt-only keys Dmitry Torokhov
2025-08-17 22:47 ` Dmitry Torokhov [this message]
2025-08-18  6:54   ` [PATCH 2/3] mfd: rohm-bd71828: Use software nodes for gpio-keys Matti Vaittinen
2025-08-18  6:56     ` Matti Vaittinen
2025-08-18 17:11       ` Dmitry Torokhov
2025-08-19 10:49         ` Matti Vaittinen
2025-08-17 22:47 ` [PATCH 3/3] mfd: rohm-bd718x7: " Dmitry Torokhov
2025-08-18  6:57   ` Matti Vaittinen
2025-08-20 13:37 ` [PATCH 1/3] Input: gpio_keys - fall back to platform_get_irq() for interrupt-only keys Andy Shevchenko

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=20250817224731.1911207-2-dmitry.torokhov@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=arnd@kernel.org \
    --cc=brgl@bgdev.pl \
    --cc=lee@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mazziesaccount@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.