linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jarkko Nikula <jarkko.nikula@linux.intel.com>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Mark Brown <broonie@kernel.org>, Wolfram Sang <wsa@the-dreams.de>
Cc: linux-spi@vger.kernel.org, linux-i2c@vger.kernel.org,
	alsa-devel@alsa-project.org, linux-acpi@vger.kernel.org,
	Jarkko Nikula <jarkko.nikula@linux.intel.com>
Subject: [PATCHv2 2/3] i2c: Use stable dev_name for ACPI enumerated I2C slaves
Date: Fri,  1 Nov 2013 14:35:55 +0200	[thread overview]
Message-ID: <1383309356-25430-3-git-send-email-jarkko.nikula@linux.intel.com> (raw)
In-Reply-To: <1383309356-25430-1-git-send-email-jarkko.nikula@linux.intel.com>

Current I2C adapter id - client address "x-00yy" based device naming scheme
is not always stable enough to be used in name based matching, for instance
within ALSA SoC subsystem.

This is problematic in PC kind of platforms where I2C adapter numbers can
change due variable amount of bus controllers, probe order, add-on cards or
just because of BIOS settings.

This patch addresses the problem by using the ACPI device name with
"i2c-" prefix for ACPI enumerated I2C slaves. For them device name
"x-00yz" becomes "i2c-INTABCD:ij" after this patch.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---
 drivers/i2c/i2c-core.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 75ba860..9126c2e 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -48,6 +48,7 @@
 #include <linux/rwsem.h>
 #include <linux/pm_runtime.h>
 #include <linux/acpi.h>
+#include <acpi/acpi_bus.h>
 #include <asm/uaccess.h>
 
 #include "i2c-core.h"
@@ -618,6 +619,24 @@ void i2c_unlock_adapter(struct i2c_adapter *adapter)
 }
 EXPORT_SYMBOL_GPL(i2c_unlock_adapter);
 
+static void i2c_dev_set_name(struct i2c_adapter *adap,
+			     struct i2c_client *client)
+{
+	if (ACPI_HANDLE(&client->dev)) {
+		struct acpi_device *adev;
+		if (!acpi_bus_get_device(ACPI_HANDLE(&client->dev), &adev)) {
+			dev_set_name(&client->dev, "i2c-%s",
+				     dev_name(&adev->dev));
+			return;
+		}
+	}
+
+	/* For 10-bit clients, add an arbitrary offset to avoid collisions */
+	dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap),
+		     client->addr | ((client->flags & I2C_CLIENT_TEN)
+				     ? 0xa000 : 0));
+}
+
 /**
  * i2c_new_device - instantiate an i2c device
  * @adap: the adapter managing the device
@@ -676,10 +695,7 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
 	client->dev.of_node = info->of_node;
 	ACPI_HANDLE_SET(&client->dev, info->acpi_node.handle);
 
-	/* For 10-bit clients, add an arbitrary offset to avoid collisions */
-	dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap),
-		     client->addr | ((client->flags & I2C_CLIENT_TEN)
-				     ? 0xa000 : 0));
+	i2c_dev_set_name(adap, client);
 	status = device_register(&client->dev);
 	if (status)
 		goto out_err;
-- 
1.8.4.rc3


  parent reply	other threads:[~2013-11-01 12:35 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-25 12:18 [RFC 0/2] I2C and SPI dev_name change for ACPI enumerated slaves Jarkko Nikula
     [not found] ` <1382703540-3769-1-git-send-email-jarkko.nikula-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2013-10-25 12:18   ` [RFC 1/2] i2c: Use stable dev_name for ACPI enumerated I2C slaves Jarkko Nikula
2013-10-25 12:52     ` Rafael J. Wysocki
     [not found]       ` <6032482.JJ4PNSSnIp-sKB8Sp2ER+y1GS7QM15AGw@public.gmane.org>
2013-10-25 12:55         ` Jarkko Nikula
     [not found]           ` <526A6A41.6020909-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2013-10-25 13:18             ` Rafael J. Wysocki
2013-10-25 13:30               ` Jarkko Nikula
     [not found]                 ` <526A726F.1030407-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2013-10-25 14:08                   ` Rafael J. Wysocki
     [not found]                     ` <2889412.bEKBLJtgSW-sKB8Sp2ER+y1GS7QM15AGw@public.gmane.org>
2013-10-28 13:15                       ` Jarkko Nikula
2013-10-28 16:10                         ` Mark Brown
     [not found]                         ` <526E636D.3070005-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2013-11-01  0:08                           ` Rafael J. Wysocki
     [not found]                             ` <1433914.mn8USodCgb-sKB8Sp2ER+y1GS7QM15AGw@public.gmane.org>
2013-11-01  0:26                               ` Rafael J. Wysocki
2013-10-25 12:19   ` [RFC 2/2] spi: Use stable dev_name for ACPI enumerated SPI slaves Jarkko Nikula
2013-10-25 12:59     ` Mark Brown
2013-10-25 14:09       ` Rafael J. Wysocki
2013-11-01 12:35 ` [PATCHv2 0/3] I2C and SPI dev_name change for ACPI enumerated slaves Jarkko Nikula
     [not found]   ` <1383309356-25430-1-git-send-email-jarkko.nikula-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2013-11-01 12:35     ` [PATCHv2 1/3] ACPI: Expose struct acpi_device and acpi_bus_get_device() to non-ACPI builds Jarkko Nikula
2013-11-02 22:18       ` Rafael J. Wysocki
     [not found]         ` <3858838.4tAO673dDi-sKB8Sp2ER+y1GS7QM15AGw@public.gmane.org>
2013-11-04  1:00           ` Rafael J. Wysocki
2013-11-04 21:15             ` Jarkko Nikula
2013-11-07 13:34               ` Rafael J. Wysocki
2013-11-01 12:35     ` [PATCHv2 3/3] spi: Use stable dev_name for ACPI enumerated SPI slaves Jarkko Nikula
     [not found]       ` <1383309356-25430-4-git-send-email-jarkko.nikula-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2013-11-01 18:03         ` Mark Brown
2013-11-01 13:18     ` [PATCHv2 0/3] I2C and SPI dev_name change for ACPI enumerated slaves Rafael J. Wysocki
     [not found]       ` <1601125.4tFOPicoTX-sKB8Sp2ER+y1GS7QM15AGw@public.gmane.org>
2013-11-01 13:20         ` Wolfram Sang
2013-11-01 13:44           ` Jarkko Nikula
2013-11-01 22:58             ` Rafael J. Wysocki
     [not found]               ` <3989164.GAoLSa6qzM-sKB8Sp2ER+y1GS7QM15AGw@public.gmane.org>
2013-11-02  0:13                 ` Wolfram Sang
2013-11-14  9:00     ` [PATCHv3 " Jarkko Nikula
     [not found]       ` <1384419661-28293-1-git-send-email-jarkko.nikula-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2013-11-14  9:00         ` [PATCHv3 1/3] ACPI: Provide struct acpi_device stub for !CONFIG_ACPI builds Jarkko Nikula
2013-11-14 10:03           ` [alsa-devel] " Takashi Iwai
2013-11-14 11:14             ` Jarkko Nikula
2013-11-14  9:01         ` [PATCHv3 2/3] i2c: Use stable dev_name for ACPI enumerated I2C slaves Jarkko Nikula
2013-11-14  9:01         ` [PATCHv3 3/3] spi: Use stable dev_name for ACPI enumerated SPI slaves Jarkko Nikula
     [not found]           ` <1384419661-28293-4-git-send-email-jarkko.nikula-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2013-11-14 10:10             ` Mark Brown
2013-11-14 12:03         ` [PATCHv4 0/3] I2C and SPI dev_name change for ACPI enumerated slaves Jarkko Nikula
     [not found]           ` <1384430633-23426-1-git-send-email-jarkko.nikula-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2013-11-14 12:03             ` [PATCHv4 1/3] ACPI: Provide acpi_dev_name accessor for struct acpi_device device name Jarkko Nikula
2013-11-14 12:03             ` [PATCHv4 2/3] i2c: Use stable dev_name for ACPI enumerated I2C slaves Jarkko Nikula
     [not found]               ` <1384430633-23426-3-git-send-email-jarkko.nikula-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2013-11-14 17:22                 ` Wolfram Sang
2013-11-14 12:03             ` [PATCHv4 3/3] spi: Use stable dev_name for ACPI enumerated SPI slaves Jarkko Nikula
2013-11-16  1:30           ` [PATCHv4 0/3] I2C and SPI dev_name change for ACPI enumerated slaves Rafael J. Wysocki
2013-11-01 12:35   ` Jarkko Nikula [this message]
     [not found]     ` <1383309356-25430-3-git-send-email-jarkko.nikula-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2013-11-02  0:15       ` [PATCHv2 2/3] i2c: Use stable dev_name for ACPI enumerated I2C slaves Wolfram Sang

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=1383309356-25430-3-git-send-email-jarkko.nikula@linux.intel.com \
    --to=jarkko.nikula@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=wsa@the-dreams.de \
    /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).