All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Suchanek <hramrach@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Mark Brown <broonie@kernel.org>,
	linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org
Cc: Michal Suchanek <hramrach@gmail.com>
Subject: [PATCH v2 3/3] drivers core: allow id match override when manually binding driver
Date: Mon, 27 Jun 2016 21:02:32 +0200	[thread overview]
Message-ID: <15ff382f699387e2d8f23779db851d0de7e9291e.1467053363.git.hramrach@gmail.com> (raw)
In-Reply-To: <cover.1467053363.git.hramrach@gmail.com>
In-Reply-To: <cover.1467053363.git.hramrach@gmail.com>

The spi bus has no autodetection whatsoever. The 'detection' of the
device that's suposed to be on the other side completely relies on user
supplied information coming from devicetree on many platforms. It is
completely reasonable then to allow the user to supply the information
at runtime by doing echo 'somedevice' >
/sys/bus/spi/drivers/somedriver/bind
This fails if somedriver does not have in its id table compatible of
somedevice so just skip this check for manual driver binding.

This allows binding spidev on any slave device by hand using sysfs
without adding superfluous compatibles or any other needless
complication.

Note that any slave driver that requires configuration will fail to
probe anyway if the configuration is not provided in the devicetree node.
A driver like spidev that requires no configuration can bind to any slave.

Signed-off-by: Michal Suchanek <hramrach@gmail.com>
---

 drivers/base/bus.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 6470eb8..a896aed 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -199,6 +199,28 @@ static ssize_t unbind_store(struct device_driver *drv, const char *buf,
 }
 static DRIVER_ATTR_WO(unbind);
 
+static const char *driver_override_buses[] = {
+	"spi",
+	NULL
+};
+
+static inline bool driver_match_override(struct device_driver *drv,
+					 struct device *dev)
+{
+	struct bus_type *bus = bus_get(drv->bus);
+	int i;
+
+	for (i = 0; driver_override_buses[i]; i++) {
+		if (!strcmp(bus->name, driver_override_buses[i])) {
+			pr_notice("Overriding id match on manual driver binding:\n bus: %s  driver: %s  device: %s\n",
+				  bus->name, drv->name, dev_name(dev));
+			return true;
+		}
+	}
+
+	return false;
+}
+
 /*
  * Manually attach a device to a driver.
  * Note: the driver must want to bind to the device,
@@ -212,7 +234,8 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf,
 	int err = -ENODEV;
 
 	dev = bus_find_device_by_name(bus, NULL, buf);
-	if (dev && dev->driver == NULL && driver_match_device(drv, dev)) {
+	if (dev && dev->driver == NULL && (driver_match_device(drv, dev)
+	    || driver_match_override(drv, dev))) {
 		if (dev->parent)	/* Needed for USB */
 			device_lock(dev->parent);
 		device_lock(dev);
-- 
2.8.1

WARNING: multiple messages have this Message-ID (diff)
From: Michal Suchanek <hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Greg Kroah-Hartman
	<gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>,
	Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Michal Suchanek <hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: [PATCH v2 3/3] drivers core: allow id match override when manually binding driver
Date: Mon, 27 Jun 2016 21:02:32 +0200	[thread overview]
Message-ID: <15ff382f699387e2d8f23779db851d0de7e9291e.1467053363.git.hramrach@gmail.com> (raw)
In-Reply-To: <cover.1467053363.git.hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
In-Reply-To: <cover.1467053363.git.hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

The spi bus has no autodetection whatsoever. The 'detection' of the
device that's suposed to be on the other side completely relies on user
supplied information coming from devicetree on many platforms. It is
completely reasonable then to allow the user to supply the information
at runtime by doing echo 'somedevice' >
/sys/bus/spi/drivers/somedriver/bind
This fails if somedriver does not have in its id table compatible of
somedevice so just skip this check for manual driver binding.

This allows binding spidev on any slave device by hand using sysfs
without adding superfluous compatibles or any other needless
complication.

Note that any slave driver that requires configuration will fail to
probe anyway if the configuration is not provided in the devicetree node.
A driver like spidev that requires no configuration can bind to any slave.

Signed-off-by: Michal Suchanek <hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---

 drivers/base/bus.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 6470eb8..a896aed 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -199,6 +199,28 @@ static ssize_t unbind_store(struct device_driver *drv, const char *buf,
 }
 static DRIVER_ATTR_WO(unbind);
 
+static const char *driver_override_buses[] = {
+	"spi",
+	NULL
+};
+
+static inline bool driver_match_override(struct device_driver *drv,
+					 struct device *dev)
+{
+	struct bus_type *bus = bus_get(drv->bus);
+	int i;
+
+	for (i = 0; driver_override_buses[i]; i++) {
+		if (!strcmp(bus->name, driver_override_buses[i])) {
+			pr_notice("Overriding id match on manual driver binding:\n bus: %s  driver: %s  device: %s\n",
+				  bus->name, drv->name, dev_name(dev));
+			return true;
+		}
+	}
+
+	return false;
+}
+
 /*
  * Manually attach a device to a driver.
  * Note: the driver must want to bind to the device,
@@ -212,7 +234,8 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf,
 	int err = -ENODEV;
 
 	dev = bus_find_device_by_name(bus, NULL, buf);
-	if (dev && dev->driver == NULL && driver_match_device(drv, dev)) {
+	if (dev && dev->driver == NULL && (driver_match_device(drv, dev)
+	    || driver_match_override(drv, dev))) {
 		if (dev->parent)	/* Needed for USB */
 			device_lock(dev->parent);
 		device_lock(dev);
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2016-06-27 19:02 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-27 19:02 [PATCH v2 0/3] Updated spidev usability patchset Michal Suchanek
2016-06-27 19:02 ` Michal Suchanek
2016-06-27 19:02 ` [PATCH v2 1/3] spi: spidev: fix the check for spidev in dt Michal Suchanek
2016-06-27 20:36   ` Mark Brown
2016-06-27 20:36     ` Mark Brown
2016-06-27 19:02 ` [PATCH v2 2/3] spi: of: allow instantiating slaves without a driver Michal Suchanek
2016-06-27 21:14   ` Mark Brown
2016-06-27 21:14     ` Mark Brown
2016-06-27 19:02 ` Michal Suchanek [this message]
2016-06-27 19:02   ` [PATCH v2 3/3] drivers core: allow id match override when manually binding driver Michal Suchanek
2016-06-27 19:09   ` Greg Kroah-Hartman
2016-06-27 19:09     ` Greg Kroah-Hartman
2016-06-27 19:40     ` Michal Suchanek
2016-06-27 19:40       ` Michal Suchanek
2016-06-27 20:32       ` Mark Brown
2016-06-27 20:32         ` Mark Brown
2016-06-27 22:12       ` Greg Kroah-Hartman
2016-06-27 22:12         ` Greg Kroah-Hartman
2016-06-28 12:40         ` Michal Suchanek
2016-06-28 12:40           ` Michal Suchanek
2016-06-28 15:51           ` Mark Brown
2016-06-28 15:51             ` Mark Brown
2016-06-28 16:24             ` Michal Suchanek
2016-06-28 16:24               ` Michal Suchanek
2016-06-28 18:38               ` Mark Brown
2016-06-28 18:38                 ` Mark Brown
2016-06-28 20:02                 ` Michal Suchanek
2016-06-28 20:57                   ` Mark Brown
2016-06-28 20:57                     ` Mark Brown
2016-06-29  3:32                     ` Michal Suchanek
2016-06-29  3:32                       ` Michal Suchanek
2016-06-29 18:02                       ` Mark Brown
2016-06-29 18:02                         ` Mark Brown
2016-06-30  7:47                         ` Michal Suchanek
2016-06-30  7:47                           ` Michal Suchanek
2016-06-30  9:03                           ` Dan O'Donovan
2016-06-30  9:03                             ` Dan O'Donovan
2016-07-01  9:36                             ` Mark Brown
2016-07-01 10:11                               ` Michal Suchanek
2016-07-01 10:11                                 ` Michal Suchanek
2016-07-01  8:25                           ` Mark Brown
2016-07-01  8:58                             ` Michal Suchanek
2016-07-01  8:58                               ` Michal Suchanek
2016-07-01 15:00                               ` Mark Brown
2016-07-01 15:37                                 ` Michal Suchanek
2016-07-01 16:22                                   ` Mark Brown
2016-07-01 18:56                                     ` Michal Suchanek
2016-07-01 18:56                                       ` Michal Suchanek
2016-07-01 19:36                                       ` Michal Suchanek
2016-07-01 19:36                                         ` Michal Suchanek

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=15ff382f699387e2d8f23779db851d0de7e9291e.1467053363.git.hramrach@gmail.com \
    --to=hramrach@gmail.com \
    --cc=broonie@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.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 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.