From: Wolfram Sang <w.sang@pengutronix.de>
To: linuxppc-dev@ozlabs.org
Cc: devicetree-discuss@ozlabs.org, linux-i2c@vger.kernel.org
Subject: [RFC] misc/at24: add experimental OF support for the generic eeprom driver
Date: Thu, 8 Oct 2009 16:04:32 +0200 [thread overview]
Message-ID: <1255010672-21656-1-git-send-email-w.sang@pengutronix.de> (raw)
As Anton introduced archdata support, I wondered if this is a suitable way to
handle the platform_data/devicetree_property-dualism (at least for some
drivers).
If considered suitable, I would document the bindings properly. I really think
that pagesize deserves its own property as it is specific to the hardware and I
have seen devices with equal name and still having different pagesizes. Not too
sure about 'read-only' though, I just copied it from flash-partitions :)
Tested on a phyCORE-MPC5200-IO and build-tested on x86.
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Cc: Grant Likely <grant.likely@secretlab.ca>
Cc: Anton Vorontsov <avorontsov@ru.mvista.com>
---
drivers/misc/eeprom/at24.c | 25 +++++++++++++++++++++++++
1 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index db39f4a..4e543e6 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -22,6 +22,9 @@
#include <linux/jiffies.h>
#include <linux/i2c.h>
#include <linux/i2c/at24.h>
+#ifdef CONFIG_OF_I2C
+#include <linux/of.h>
+#endif
/*
* I2C EEPROMs from most vendors are inexpensive and mostly interchangeable.
@@ -414,6 +417,25 @@ static ssize_t at24_macc_write(struct memory_accessor *macc, const char *buf,
return at24_write(at24, buf, offset, count);
}
+#ifdef CONFIG_OF_I2C
+static void at24_get_ofdata(struct i2c_client *client, struct at24_platform_data *chip)
+{
+ const u32 *val;
+ struct device_node *node = dev_archdata_get_node(&client->dev.archdata);
+
+ 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 = *val;
+ }
+}
+#else
+static void at24_get_ofdata(struct i2c_client *client, struct at24_platform_data *chip)
+{ }
+#endif
+
/*-------------------------------------------------------------------------*/
static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
@@ -444,6 +466,9 @@ 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);
+
chip.setup = NULL;
chip.context = NULL;
}
--
1.6.3.3
next reply other threads:[~2009-10-08 14:04 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-08 14:04 Wolfram Sang [this message]
2009-10-08 14:33 ` [RFC] misc/at24: add experimental OF support for the generic eeprom driver Anton Vorontsov
2009-10-08 14:53 ` Grant Likely
2009-10-08 15:10 ` Anton Vorontsov
2009-10-08 15:48 ` Grant Likely
2009-10-08 20:27 ` Wolfram Sang
2009-10-09 5:14 ` Wolfram Sang
2009-10-09 5:40 ` Grant Likely
2009-10-09 14:01 ` Nate Case
2009-10-09 16:09 ` Grant Likely
2009-10-09 16:20 ` Wolfram Sang
2009-10-09 13:43 ` Nate Case
2009-10-09 16:12 ` Wolfram Sang
2009-10-09 16:13 ` Grant Likely
2009-10-08 22:20 ` Anton Vorontsov
2009-10-09 6:37 ` Grant Likely
2009-10-08 14:37 ` Grant Likely
2009-10-08 20:48 ` Wolfram Sang
2009-10-08 22:59 ` 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=1255010672-21656-1-git-send-email-w.sang@pengutronix.de \
--to=w.sang@pengutronix.de \
--cc=devicetree-discuss@ozlabs.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linuxppc-dev@ozlabs.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).