public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Vladimir Oltean <vladimir.oltean@nxp.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Daniel Scally <djrscally@gmail.com>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: Implementation of fwnode_operations :: device_get_match_data() for software nodes?
Date: Mon, 27 Feb 2023 14:18:59 +0200	[thread overview]
Message-ID: <Y/yfs3Zo70gV/V9b@kuha.fi.intel.com> (raw)
In-Reply-To: <20230223203713.hcse3mkbq3m6sogb@skbuf>

Hi Vladimir,

On Thu, Feb 23, 2023 at 10:37:13PM +0200, Vladimir Oltean wrote:
> Hi,
> 
> I have a need to instantiate a driver written for OF which calls
> device_get_match_data(dev) to get various information based on the
> compatible string.
> 
> I am creating a software node based on the following properties:
> 
> 	struct property_entry props[2] = {
> 		PROPERTY_ENTRY_STRING("compatible", compatible),
> 		{},
> 	};
> 
> (I see I'm not the only one doing this, some drivers/platform/x86/x86-android-tablets.c
> and drivers/platform/chrome/chromeos_laptop.c also do it)
> 
> and the driver in question does begin to probe, but its match_data is
> NULL, because the operation from the title isn't implemented for
> software nodes. So probing ultimately fails.
> 
> Is there some sort or reason why this doesn't exist, other than a lack
> of need?

There has not been any need for it before.

> Can someone please help me with an implementation of this feature?

Try this - I'm sorry, I don't know does it actually work:

diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index 1886995a0b3a3..5262b49c7c790 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -9,6 +9,7 @@
 #include <linux/device.h>
 #include <linux/kernel.h>
 #include <linux/property.h>
+#include <linux/mod_devicetable.h>
 #include <linux/slab.h>
 
 #include "base.h"
@@ -379,6 +380,25 @@ static void software_node_put(struct fwnode_handle *fwnode)
        kobject_put(&swnode->kobj);
 }
 
+static const void *
+software_node_get_match_data(const struct fwnode_handle *fwnode, const struct device *dev)
+{
+       const struct of_device_id *id;
+       const char *compat;
+
+       if (!dev->driver || !dev->driver->of_match_table)
+               return NULL;
+
+       if (fwnode_property_read_string(fwnode, "compatible", &compat))
+               return NULL;
+
+       for (id = dev->driver->of_match_table; id->compatible[0]; id++)
+               if (!strcmp(compat, id->compatible))
+                       return id->data;
+
+       return NULL;
+}
+
 static bool software_node_property_present(const struct fwnode_handle *fwnode,
                                           const char *propname)
 {
@@ -662,6 +682,7 @@ software_node_graph_parse_endpoint(const struct fwnode_handle *fwnode,
 static const struct fwnode_operations software_node_ops = {
        .get = software_node_get,
        .put = software_node_put,
+       .device_get_match_data = software_node_get_match_data,
        .property_present = software_node_property_present,
        .property_read_int_array = software_node_read_int_array,
        .property_read_string_array = software_node_read_string_array,

-- 
heikki

  reply	other threads:[~2023-02-27 12:19 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-23 20:37 Implementation of fwnode_operations :: device_get_match_data() for software nodes? Vladimir Oltean
2023-02-27 12:18 ` Heikki Krogerus [this message]
2023-02-27 23:07   ` Vladimir Oltean
2023-02-27 22:26 ` Andy Shevchenko
2023-02-27 23:44   ` Vladimir Oltean
2023-03-01 14:33     ` Andy Shevchenko
2023-03-01 14:36       ` Vladimir Oltean
2023-03-01 15:09         ` Andy Shevchenko
2023-03-01 15:25           ` Vladimir Oltean
2023-03-01 15:34             ` Andy Shevchenko
2023-03-01 17:18               ` Vladimir Oltean
2023-03-01 17:33                 ` Andy Shevchenko
2023-03-01 17:43                   ` Vladimir Oltean
2024-03-25 13:41                     ` Andy Shevchenko
2024-03-25 15:16                       ` Herve Codina
2024-03-25 15:39                         ` Andy Shevchenko
2024-03-25 15:57                           ` Herve Codina

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=Y/yfs3Zo70gV/V9b@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=djrscally@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=vladimir.oltean@nxp.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox