From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: Ben Gardner <gardner.ben@gmail.com>
Cc: linux-acpi@vger.kernel.org
Subject: Re: ACPI: Can I use I2cSerialBus with a PCI I2C controller?
Date: Fri, 23 Oct 2015 11:20:54 +0300 [thread overview]
Message-ID: <20151023082054.GP1526@lahna.fi.intel.com> (raw)
In-Reply-To: <CAE7DoPZfLDEBmeODQv3oEbs033gpq4oSA=Sx15wMajzVUbUinw@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1802 bytes --]
On Thu, Oct 22, 2015 at 12:17:58PM -0500, Ben Gardner wrote:
> > The next issue is that the I2C-core isn't matching the device to the
> > "at24" driver, which has the alias "24c02".
>
> Here is what I found.
> i2c-core is creating the device with the ACPI name "24C02:00".
> The at24 driver uses "24c02" as the alias.
> i2c-code is matching devices to drivers using strcmp().
>
> Result: no match. ("24c02" != "24C02:00").
>
> If I modify acpi_i2c_add_device() to cut off the name at the ':' and
> covert to lowercase when populating info.type, it matches and works.
> I must be missing something here, because this would have never worked as-is.
> I'll ask on the I2C mailing list.
You should either use proper _HID/_CID for the device or put "PRP0001"
to the _HID and let the match happen with DT .compatible strings. I've
attached a hack that I use locally.
The corresponding ASL fragment would look like:
Device (AT24)
{
Name (_HID, "PRP0001")
Method (_CRS, 0, Serialized) {
Name (UBUF, ResourceTemplate () {
I2cSerialBus (0x50, ControllerInitiated, 0x00061A80,
AddressingMode7Bit, "\\_SB.I2C6",
0x00, ResourceConsumer)
})
Return (UBUF)
}
Name (_DSD, Package () {
ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"compatible", "atmel,24c02"},
Package () {"size", 256},
Package () {"pagesize", 32},
Package () {"abs-value", 1},
},
})
Method (_STA, 0, NotSerialized)
{
Return (0xF)
}
}
[-- Attachment #2: 0001-misc-at24-Make-use-of-device-property-API.patch --]
[-- Type: text/plain, Size: 3164 bytes --]
>From 78792d4e759f023975700222caffa7a20f77fcf9 Mon Sep 17 00:00:00 2001
From: Mika Westerberg <mika.westerberg@linux.intel.com>
Date: Mon, 29 Sep 2014 13:11:07 +0300
Subject: [PATCH] misc/at24: Make use of device property API
Not-Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
drivers/misc/eeprom/at24.c | 44 ++++++++++++++++++++++++--------------------
1 file changed, 24 insertions(+), 20 deletions(-)
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index c6cb7f8f325e..d2963b5632d4 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -20,9 +20,9 @@
#include <linux/log2.h>
#include <linux/bitops.h>
#include <linux/jiffies.h>
-#include <linux/of.h>
#include <linux/i2c.h>
#include <linux/platform_data/at24.h>
+#include <linux/property.h>
/*
* I2C EEPROMs from most vendors are inexpensive and mostly interchangeable.
@@ -443,26 +443,24 @@ static ssize_t at24_macc_write(struct memory_accessor *macc, const char *buf,
/*-------------------------------------------------------------------------*/
-#ifdef CONFIG_OF
-static void at24_get_ofdata(struct i2c_client *client,
+static int at24_get_fwdata(struct i2c_client *client,
struct at24_platform_data *chip)
{
- const __be32 *val;
- struct device_node *node = client->dev.of_node;
-
- if (node) {
- if (of_get_property(node, "read-only", NULL))
- chip->flags |= AT24_FLAG_READONLY;
- val = of_get_property(node, "pagesize", NULL);
- if (val)
- chip->page_size = be32_to_cpup(val);
- }
+ if (device_property_present(&client->dev, "read-only"))
+ chip->flags |= AT24_FLAG_READONLY;
+ if (device_property_read_u16(&client->dev, "pagesize", &chip->page_size))
+ return -ENODEV;
+ if (device_property_read_u32(&client->dev, "size", &chip->byte_len))
+ return -ENODEV;
+
+ return 0;
}
-#else
-static void at24_get_ofdata(struct i2c_client *client,
- struct at24_platform_data *chip)
-{ }
-#endif /* CONFIG_OF */
+
+static const struct of_device_id at24_of_match[] = {
+ { .compatible = "atmel,24c02" },
+ { },
+};
+MODULE_DEVICE_TABLE(of, at24_of_match);
static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
@@ -477,7 +475,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
if (client->dev.platform_data) {
chip = *(struct at24_platform_data *)client->dev.platform_data;
- } else {
+ } else if (id) {
if (!id->driver_data)
return -ENODEV;
@@ -493,10 +491,15 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
chip.page_size = 1;
/* update chipdata if OF is present */
- at24_get_ofdata(client, &chip);
+ at24_get_fwdata(client, &chip);
chip.setup = NULL;
chip.context = NULL;
+ } else {
+ memset(&chip, 0, sizeof(chip));
+ err = at24_get_fwdata(client, &chip);
+ if (err)
+ return err;
}
if (!is_power_of_2(chip.byte_len))
@@ -661,6 +664,7 @@ static int at24_remove(struct i2c_client *client)
static struct i2c_driver at24_driver = {
.driver = {
.name = "at24",
+ .of_match_table = at24_of_match,
},
.probe = at24_probe,
.remove = at24_remove,
--
2.6.1
next prev parent reply other threads:[~2015-10-23 8:20 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-20 19:47 ACPI: Can I use I2cSerialBus with a PCI I2C controller? Ben Gardner
2015-10-21 8:50 ` Mika Westerberg
2015-10-21 23:14 ` Ben Gardner
2015-10-22 8:01 ` Mika Westerberg
2015-10-22 16:19 ` Ben Gardner
2015-10-22 17:17 ` Ben Gardner
2015-10-23 8:20 ` Mika Westerberg [this message]
2015-10-23 9:43 ` Mika Westerberg
2015-10-23 17:24 ` Ben Gardner
2015-10-26 19:56 ` Ben Gardner
2015-10-27 10:49 ` Mika Westerberg
2015-10-27 21:11 ` Dustin Byford
2015-10-28 9:01 ` Mika Westerberg
2015-10-30 16:51 ` Ben Gardner
2015-11-02 10:25 ` Mika Westerberg
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=20151023082054.GP1526@lahna.fi.intel.com \
--to=mika.westerberg@linux.intel.com \
--cc=gardner.ben@gmail.com \
--cc=linux-acpi@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 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).