From: Javier Martinez Canillas <javierm@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Luis Oliveira <Luis.Oliveira@synopsys.com>,
Javier Martinez Canillas <javierm@redhat.com>,
Wolfram Sang <wsa@the-dreams.de>,
linux-i2c@vger.kernel.org
Subject: [PATCH] i2c: slave-eeprom: Add an OF device ID table
Date: Wed, 9 Aug 2017 12:12:56 +0200 [thread overview]
Message-ID: <20170809101256.31204-1-javierm@redhat.com> (raw)
The driver doesn't have a struct of_device_id table but supported devices
are registered via Device Trees as shown in the following DT binding doc:
Documentation/devicetree/bindings/i2c/i2c-designware.txt
But this works on the assumption that a I2C device registered via OF will
always match a legacy I2C device ID and that the MODALIAS reported will
always be of the form i2c:<device>.
And this could change in the future so the correct approach is to have an
OF device ID table if the devices are registered via OF.
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
drivers/i2c/i2c-slave-eeprom.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/i2c-slave-eeprom.c b/drivers/i2c/i2c-slave-eeprom.c
index b2039f94c9d8..20226860cfe7 100644
--- a/drivers/i2c/i2c-slave-eeprom.c
+++ b/drivers/i2c/i2c-slave-eeprom.c
@@ -17,6 +17,7 @@
#include <linux/i2c.h>
#include <linux/init.h>
#include <linux/module.h>
+#include <linux/of_device.h>
#include <linux/of.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
@@ -108,7 +109,12 @@ static int i2c_slave_eeprom_probe(struct i2c_client *client, const struct i2c_de
{
struct eeprom_data *eeprom;
int ret;
- unsigned size = id->driver_data;
+ unsigned size;
+
+ if (client->dev.of_node)
+ size = (kernel_ulong_t)of_device_get_match_data(&client->dev);
+ else
+ size = id->driver_data;
eeprom = devm_kzalloc(&client->dev, sizeof(struct eeprom_data) + size, GFP_KERNEL);
if (!eeprom)
@@ -154,9 +160,16 @@ static const struct i2c_device_id i2c_slave_eeprom_id[] = {
};
MODULE_DEVICE_TABLE(i2c, i2c_slave_eeprom_id);
+static const struct of_device_id i2c_slave_eeprom_of_match[] = {
+ { .compatible = "linux,slave-24c02", .data = (void *)(2048 / 8) },
+ { }
+};
+MODULE_DEVICE_TABLE(of, i2c_slave_eeprom_of_match);
+
static struct i2c_driver i2c_slave_eeprom_driver = {
.driver = {
.name = "i2c-slave-eeprom",
+ .of_match_table = i2c_slave_eeprom_of_match,
},
.probe = i2c_slave_eeprom_probe,
.remove = i2c_slave_eeprom_remove,
--
2.13.3
next reply other threads:[~2017-08-09 10:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-09 10:12 Javier Martinez Canillas [this message]
2017-08-14 19:52 ` [PATCH] i2c: slave-eeprom: Add an OF device ID table Wolfram Sang
2017-08-16 9:36 ` Javier Martinez Canillas
2017-08-16 13:41 ` 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=20170809101256.31204-1-javierm@redhat.com \
--to=javierm@redhat.com \
--cc=Luis.Oliveira@synopsys.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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).