From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f179.google.com (mail-dy1-f179.google.com [74.125.82.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58F1D8287E for ; Wed, 25 Mar 2026 00:34:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774398866; cv=none; b=koz48J1GC/KuaQT6YhjSFcnuO5b+Q1ymP0Jvmx/NhRt+MRcrxBz0tkRKRQZkqBCd0ywCCOFFS08nGA4TrdJkSN4lESHUdaVFoCXv6QL5HBkE1fljJvGZUGGzJ2RRKjSlsM5yablJfY4YX1iP5SxRBrvumLPbIsJMp7p+8KDPzeA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774398866; c=relaxed/simple; bh=BQWtrfEQZRTPx/NiRGoxEbFGSLJWtcIA2iAQHjZ2HIU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kEnpPLamPqgnVxJXlgPZCLXq9icvb+ZMeK9YPNK18S4XvgA/+XDqDd1aoTqtqZdtKIHutV7Te/q5DmbCksstUfzwJaWFjsN8W/kM28pFi7kM/vm3x8aWIqS8dy6CnSEK3F91G67RnOjhpu3lbQ7kuo6Fcg01QMegLR9xbgGIo60= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=qYvfE4Wl; arc=none smtp.client-ip=74.125.82.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qYvfE4Wl" Received: by mail-dy1-f179.google.com with SMTP id 5a478bee46e88-2c160308a54so647472eec.0 for ; Tue, 24 Mar 2026 17:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774398864; x=1775003664; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=CMNvY9aMLoSAIxOpCfi2SdsbkNJCVPodaQFnZqM/LXk=; b=qYvfE4Wl6RzlGOYuT78rmu0rTYDLpp0Lv3dle683/pTdQA6j19h2MFotuDRuTWE8oy Asjj311ul4U3aEkHaZJ066d3Y+cGkxNW+MJRcruzMsCQZVYMKYjMuEqITYWBOg+bSyJI eAglKy+LJe3ZPFKCS6bu5LLMgGNuD9yLhHXbWSto4yLlQ8cvxIQupOsCgQzfZVfviHgU ar5B4NqOii2bRCEUEfLOeIN96YI6pplpyRK48qiD80ZtP5mdfxcuQM39P7IVyn1tbb++ aczKQAK9EL0H+e+4aMVXP1jcqIMsba7Tj5nEpjyoCRE/U4/aXcAszI3YrXeeUGPQr1ws lZFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774398864; x=1775003664; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CMNvY9aMLoSAIxOpCfi2SdsbkNJCVPodaQFnZqM/LXk=; b=KGU5Gs62sOUaOWdGQpJyYccgTtnTnsyRgFYbq70lRKsQk+zdEPIxaxS1MYgAQrEMAX QGj4aYudolQLYGNK9GdiRgxMuxunIKGvsaHaJ4Qy3rkc+0jyno+uha6wWDWZFSNtiGvs Y6WqO+qyNnh8txcAKT/j4SuV48WtP1VBvb3Jdh7p5HmkIbgH0lVEStN6Fhnl+pyqd1lw bkWqXf8gWlfn2VlMuWekx3TsQeCQvtjQaTvipxAgWnneO8CRPgkanYN+X/XYEM+3SCM8 6dkAHKvF3GOIOZJhE3gacnnULnkjFNYymBxj/KpnARQkz/gxPJrJJAz2RlwKF40kpJGl 4QGQ== X-Forwarded-Encrypted: i=1; AJvYcCVO+eldB5TRD8v7tVtcnd9cGVN/I16qnwUZW0fxXagmS2szWERpO52HzRZUEFGjCj+ZTB0cQyTPsgKiXUI=@vger.kernel.org X-Gm-Message-State: AOJu0YwhMuk27WJ2Lx5sH2Kto5sgAFn3yIhYTPkeD1JpeaYoquRhLS7E +6hbC/lBGzPRh6UCa4lj4QaBo965nAL2DzVVjmDU00cniDlnXezfB90V X-Gm-Gg: ATEYQzx0183DvaopI6fA9iucwjUFS0oHvWOXfJD84p40TE24p/RmFSNkf9YiD4xL3E2 8Hu5rrtithPJZ7piO7as/6FNRMSn4HsPHeUkA33NMdHBIQkftnat/pMYCPJvkSpIJ8HcvpbCOdQ RoSqyj7U+5Jf5RZRyPY6hZBKAueTcKXiTnfCDH5ZNFofhgkrw+fs4QxXLpRpR8WzJyrRrS7nxKe lAsQPiYNVBs/B7yuMgvFZ5bpJLsfYOfqufffahSvo5G7abuGDjh5KVmYlKyQMlg2tPSWpM7WcgT Bohhh9oG4sxes8J0sluRh9NlAAmw29idactfDUyGC/HH+a76lj6t6e6GEhgDl7jOlJO79Wdb7bD 3pZGQNbq6WA3YsiSiZUrhi1gQxus/Fk3vwzYAIKJbqL1z9wHslQT80NgtfcdCTE4pn+8kmhyse/ ToOTEZX7OmakN5o828w88VK/girlY/XgPL0yEAuYmdFjXe4BIUdZom3oHHZUBhiBBAnlUE0be+d Sc= X-Received: by 2002:a05:7300:72cc:b0:2c0:fec3:fcff with SMTP id 5a478bee46e88-2c15d3809fcmr832321eec.17.1774398863928; Tue, 24 Mar 2026 17:34:23 -0700 (PDT) Received: from google.com ([2a00:79e0:2ebe:8:a686:fd7f:70d3:9156]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2c10b2d673asm20679287eec.24.2026.03.24.17.34.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2026 17:34:23 -0700 (PDT) Date: Tue, 24 Mar 2026 17:34:20 -0700 From: Dmitry Torokhov To: Matti Vaittinen Cc: Lee Jones , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/2] mfd: rohm-bd71828: Use software nodes for gpio-keys Message-ID: References: <20260322-rohm-software-nodes-v2-0-3c7d21336d37@gmail.com> <20260322-rohm-software-nodes-v2-1-3c7d21336d37@gmail.com> <80feeb8f-faad-44f5-827a-def3952037f8@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <80feeb8f-faad-44f5-827a-def3952037f8@gmail.com> On Tue, Mar 24, 2026 at 08:45:15AM +0200, Matti Vaittinen wrote: > On 23/03/2026 03:37, Dmitry Torokhov wrote: > > 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 > > Thanks a lot Dmitry for converting this to the swnodes. I like the idea very > much :) A few minor, (mostly styling related as I am a bit old-fashioned) > comments. > > > --- > > drivers/mfd/rohm-bd71828.c | 117 ++++++++++++++++++++++++++++++++------------- > > 1 file changed, 85 insertions(+), 32 deletions(-) > > > > diff --git a/drivers/mfd/rohm-bd71828.c b/drivers/mfd/rohm-bd71828.c > > index a79f354bf5cb..20b7910e7f63 100644 > > --- a/drivers/mfd/rohm-bd71828.c > > +++ b/drivers/mfd/rohm-bd71828.c > > @@ -5,7 +5,8 @@ > > * ROHM BD718[15/28/79] and BD72720 PMIC driver > > */ > > -#include > > +#include > > +#include > > #include > > #include > > #include > > @@ -18,6 +19,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > @@ -37,19 +39,6 @@ > > }, \ > > } > > -static struct gpio_keys_button button = { > > - .code = KEY_POWER, > > - .gpio = -1, > > - .type = EV_KEY, > > - .wakeup = 1, > > -}; > > - > > -static const struct gpio_keys_platform_data bd71828_powerkey_data = { > > - .buttons = &button, > > - .nbuttons = 1, > > - .name = "bd71828-pwrkey", > > -}; > > - > > 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"), > > @@ -174,11 +163,8 @@ static struct mfd_cell bd71828_mfd_cells[] = { > > .name = "bd71828-rtc", > > .resources = bd71828_rtc_irqs, > > .num_resources = ARRAY_SIZE(bd71828_rtc_irqs), > > - }, { > > - .name = "gpio-keys", > > - .platform_data = &bd71828_powerkey_data, > > - .pdata_size = sizeof(bd71828_powerkey_data), > > }, > > + /* Power button is registered separately */ > > }; > > static const struct resource bd72720_power_irqs[] = { > > @@ -242,11 +228,8 @@ static const struct mfd_cell bd72720_mfd_cells[] = { > > .name = "bd72720-rtc", > > .resources = bd72720_rtc_irqs, > > .num_resources = ARRAY_SIZE(bd72720_rtc_irqs), > > - }, { > > - .name = "gpio-keys", > > - .platform_data = &bd71828_powerkey_data, > > - .pdata_size = sizeof(bd71828_powerkey_data), > > }, > > + /* Power button is registered separately */ > > }; > > static const struct regmap_range bd71815_volatile_ranges[] = { > > @@ -877,6 +860,75 @@ static int set_clk_mode(struct device *dev, struct regmap *regmap, > > OUT32K_MODE_CMOS); > > } > > +static void bd71828_i2c_unregister_swnodes(void *data) > > +{ > > + const struct software_node *nodes = data; > > + > > + software_node_unregister_node_group((const struct software_node *[]){ > > + &nodes[0], > > + &nodes[1], > > + NULL > > + }); > > Perhaps it was possible to use a temporary variable for the software_node > pointer array? It would allow also old-school fellows like me to pick the > meaning by a glance :) Done. > > > +} > > + > > +static int bd71828_i2c_register_pwrbutton(struct device *dev, int button_irq, > > + struct irq_domain *irq_domain) > > +{ > > + static const struct property_entry bd71828_powerkey_parent_props[] = { > > + PROPERTY_ENTRY_STRING("label", "bd71828-pwrkey"), > > + { } > > + }; > > + static const struct property_entry bd71828_powerkey_props[] = { > > + PROPERTY_ENTRY_U32("linux,code", KEY_POWER), > > + PROPERTY_ENTRY_BOOL("wakeup-source"), > > + { } > > + }; > > + struct software_node *nodes; > > + int error; > > + > > + nodes = devm_kcalloc(dev, 2, sizeof(*nodes), GFP_KERNEL); > > + if (!nodes) > > + return -ENOMEM; > > + > > + /* Node corresponding to gpio-keys device itself */ > > + nodes[0].name = devm_kasprintf(dev, GFP_KERNEL, "%s-power-key", dev_name(dev)); > > + if (!nodes[0].name) > > + return -ENOMEM; > > + > > + nodes[0].properties = bd71828_powerkey_parent_props; > > + > > + /* Node representing power button within gpio-keys device */ > > + nodes[1].parent = &nodes[0]; > > + nodes[1].properties = bd71828_powerkey_props; > > + > > + error = software_node_register_node_group((const struct software_node *[]){ > > + &nodes[0], > > + &nodes[1], > > + NULL > > + }); > > I think having a temporary variable might make this to look more familiar. Done. > > > + if (error) > > + return error; > > + > > + error = devm_add_action_or_reset(dev, bd71828_i2c_unregister_swnodes, nodes); > > + if (error) > > + return error; > > + > > + const struct mfd_cell gpio_keys_cell = { > > + .name = "gpio-keys", > > + .resources = (const struct resource[]) { > > + DEFINE_RES_IRQ_NAMED(button_irq, "bd71828-pwrkey"), > > + }, > > + .num_resources = 1, > > + .swnode = &nodes[0], > > + }; > > I don't really love seeing variables declared in the middle of a block. I normally try not to declare in the middle of the code but in this case I opted for it because swnode is not known so we have to split initialization. > Perhaps consider splitting the software-node preparation in own function and > doing something like (completely untested thought): > > ret = alloc_and_prepare_the_swnode_stuff(...); > if (!ret) { > const struct software_node *nodes[] = { ... }; > const struct mfd_cell gpio_keys_cell = { ... }; > > ... > } That is an option but then spreads dealing with nodes across multiple functions. I moved the declaration and partial initialization to the beginning of the function, and assign swnode before calling devm_mfd_add_devices(). > > or alternatively, split the software-node and MFD device registration into > own function? Do you think it would work? > > > + error = devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, &gpio_keys_cell, 1, > > + NULL, 0, irq_domain); > > + if (error) > > + return dev_err_probe(dev, error, "Failed to create power button subdevice"); > > + > > + return 0; > > +} > > + > > static struct i2c_client *bd71828_dev; > > static void bd71828_power_off(void) > > { > > @@ -929,6 +981,7 @@ static struct regmap *bd72720_do_regmaps(struct i2c_client *i2c) > > static int bd71828_i2c_probe(struct i2c_client *i2c) > > { > > struct regmap_irq_chip_data *irq_data; > > + struct irq_domain *irq_domain; > > int ret; > > struct regmap *regmap = NULL; > > const struct regmap_config *regmap_config; > > @@ -1008,6 +1061,8 @@ static int bd71828_i2c_probe(struct i2c_client *i2c) > > dev_dbg(&i2c->dev, "Registered %d IRQs for chip\n", > > irqchip->num_irqs); > > + irq_domain = regmap_irq_get_domain(irq_data); > > nit: Maybe move this call closer to where the irq_domain is actually needed > for the first time. Done. Thanks. -- Dmitry