linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Daney <ddaney.cavm@gmail.com>
To: devicetree-discuss@lists.ozlabs.org,
	Grant Likely <grant.likely@secretlab.ca>,
	Rob Herring <rob.herring@calxeda.com>,
	spi-devel-general@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org, linux-mips@linux-mips.org,
	linux-doc@vger.kernel.org, David Daney <david.daney@cavium.com>
Subject: [PATCH 2/3] spi: Use consistent MODALIAS values.
Date: Fri, 11 May 2012 15:05:22 -0700	[thread overview]
Message-ID: <1336773923-17866-3-git-send-email-ddaney.cavm@gmail.com> (raw)
In-Reply-To: <1336773923-17866-1-git-send-email-ddaney.cavm@gmail.com>

From: David Daney <david.daney@cavium.com>

For SPI devices, the MODALIAS should start with "spi:" so that the
modprobe can find the proper drivers.

Be consistent, for devices added via spi_new_device(), make sure
"spi:" is added if it is not already there.  In spi_match_device()
handle matching when the "spi:" prefix is present.

Signed-off-by: David Daney <david.daney@cavium.com>
---
 drivers/spi/spi.c |   39 ++++++++++++++++++++++++++++++++++-----
 1 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 3d8f662..8c49964 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -59,6 +59,16 @@ static struct device_attribute spi_dev_attrs[] = {
 	__ATTR_NULL,
 };
 
+/*
+ * modalias will be of the form "spi:name" or "name", match on just
+ * the name portion.
+ */
+static const char *spi_device_spidev2name(const struct spi_device *sdev)
+{
+	const char *p = strchr(sdev->modalias, ':');
+	return p ? p + 1 : sdev->modalias;
+}
+
 /* modalias support makes "modprobe $MODALIAS" new-style hotplug work,
  * and the sysfs version makes coldplug work too.
  */
@@ -66,8 +76,10 @@ static struct device_attribute spi_dev_attrs[] = {
 static const struct spi_device_id *spi_match_id(const struct spi_device_id *id,
 						const struct spi_device *sdev)
 {
+	const char *name = spi_device_spidev2name(sdev);
+
 	while (id->name[0]) {
-		if (!strcmp(sdev->modalias, id->name))
+		if (!strcmp(name, id->name))
 			return id;
 		id++;
 	}
@@ -94,14 +106,20 @@ static int spi_match_device(struct device *dev, struct device_driver *drv)
 	if (sdrv->id_table)
 		return !!spi_match_id(sdrv->id_table, spi);
 
-	return strcmp(spi->modalias, drv->name) == 0;
+	return strcmp(spi_device_spidev2name(spi), drv->name) == 0;
 }
 
 static int spi_uevent(struct device *dev, struct kobj_uevent_env *env)
 {
 	const struct spi_device		*spi = to_spi_device(dev);
 
-	add_uevent_var(env, "MODALIAS=%s%s", SPI_MODULE_PREFIX, spi->modalias);
+	if (strncmp(SPI_MODULE_PREFIX, spi->modalias,
+		    strlen(SPI_MODULE_PREFIX)) == 0)
+		add_uevent_var(env, "MODALIAS=%s", spi->modalias);
+	else
+		add_uevent_var(env, "MODALIAS=%s%s",
+			       SPI_MODULE_PREFIX, spi->modalias);
+
 	return 0;
 }
 
@@ -418,6 +436,7 @@ struct spi_device *spi_new_device(struct spi_master *master,
 {
 	struct spi_device	*proxy;
 	int			status;
+	size_t			l;
 
 	/* NOTE:  caller did any chip->bus_num checks necessary.
 	 *
@@ -430,13 +449,23 @@ struct spi_device *spi_new_device(struct spi_master *master,
 	if (!proxy)
 		return NULL;
 
-	WARN_ON(strlen(chip->modalias) >= sizeof(proxy->modalias));
+	if (strncmp(SPI_MODULE_PREFIX, chip->modalias,
+		    strlen(SPI_MODULE_PREFIX)) == 0) {
+		proxy->modalias[0] = 0;
+	} else {
+		l = strlcpy(proxy->modalias, SPI_MODULE_PREFIX,
+			    sizeof(proxy->modalias));
+		WARN_ON(l >= sizeof(proxy->modalias));
+	}
+
+	l = strlcat(proxy->modalias, chip->modalias, sizeof(proxy->modalias));
+
+	WARN_ON(l >= sizeof(proxy->modalias));
 
 	proxy->chip_select = chip->chip_select;
 	proxy->max_speed_hz = chip->max_speed_hz;
 	proxy->mode = chip->mode;
 	proxy->irq = chip->irq;
-	strlcpy(proxy->modalias, chip->modalias, sizeof(proxy->modalias));
 	proxy->dev.platform_data = (void *) chip->platform_data;
 	proxy->controller_data = chip->controller_data;
 	proxy->controller_state = NULL;
-- 
1.7.2.3


  parent reply	other threads:[~2012-05-11 22:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-11 22:05 [PATCH 0/3] of/spi/eeprom: Configure at25 from device tree and autoload its driver David Daney
2012-05-11 22:05 ` [PATCH 1/3] of: Add prefix parameter to of_modalias_node() David Daney
2012-05-20  5:54   ` Grant Likely
2012-05-20  6:08     ` Grant Likely
2012-05-22 19:45       ` David Daney
2012-05-22 20:09         ` Grant Likely
2012-05-22 22:49           ` David Daney
2012-05-22 23:01             ` Grant Likely
2012-05-11 22:05 ` David Daney [this message]
2012-05-11 22:05 ` [PATCH 3/3] eeprom/of: Add device tree bindings to at25 David Daney
2012-05-15 15:47   ` Greg Kroah-Hartman
2012-05-20  6:14   ` Grant Likely

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=1336773923-17866-3-git-send-email-ddaney.cavm@gmail.com \
    --to=ddaney.cavm@gmail.com \
    --cc=david.daney@cavium.com \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=rob.herring@calxeda.com \
    --cc=spi-devel-general@lists.sourceforge.net \
    /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).