From: Pantelis Antoniou <panto@antoniou-consulting.com>
To: Wolfram Sang <w.sang@pengutronix.de>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>,
"Ben Dooks (embedded platforms)" <ben-linux@fluff.org>,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
Koen Kooi <koen@dominion.thruhere.net>,
Matt Porter <mporter@ti.com>, Russ Dill <Russ.Dill@ti.com>,
linux-omap@vger.kernel.org
Subject: [PATCH] i2c-EEPROM: Export memory accessor
Date: Wed, 31 Oct 2012 17:56:49 +0200 [thread overview]
Message-ID: <1351699009-4217-1-git-send-email-panto@antoniou-consulting.com> (raw)
Various platforms need access to the EEPROM in other
places besides their platform registration callbacks.
Export the memory accessor to the i2c_client and implement
it for the at24 driver.
And before you ask, no, the platform callback can't be used
for anything that depends on DT.
Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>
---
drivers/misc/eeprom/at24.c | 5 +++++
include/linux/i2c.h | 24 ++++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index ab1ad41..4f88ae65 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -609,6 +609,9 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
at24->client[0] = client;
+ /* export accessor */
+ client->macc = &at24->macc;
+
/* use dummy devices for multiple-address chips */
for (i = 1; i < num_addresses; i++) {
at24->client[i] = i2c_new_dummy(client->adapter,
@@ -619,6 +622,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
err = -EADDRINUSE;
goto err_clients;
}
+ at24->client[i]->macc = &at24->macc;
}
err = sysfs_create_bin_file(&client->dev.kobj, &at24->bin);
@@ -637,6 +641,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
I2C_SMBUS_WORD_DATA ? "word" : "byte");
}
+
/* export data to kernel code */
if (chip.setup)
chip.setup(&at24->macc, chip.context);
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 800de22..e20ad4e 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -33,6 +33,7 @@
#include <linux/of.h> /* for struct device_node */
#include <linux/swab.h> /* for swab16 */
#include <uapi/linux/i2c.h>
+#include <linux/memory.h>
extern struct bus_type i2c_bus_type;
extern struct device_type i2c_adapter_type;
@@ -229,9 +230,32 @@ struct i2c_client {
struct device dev; /* the device structure */
int irq; /* irq issued by device */
struct list_head detected;
+
+ /* export accessor */
+ struct memory_accessor *macc;
};
#define to_i2c_client(d) container_of(d, struct i2c_client, dev)
+static inline ssize_t i2c_memory_read(struct i2c_client *client, char *buf, off_t offset,
+ size_t count)
+{
+ struct memory_accessor *macc = client->macc;
+
+ if (macc == NULL || macc->read == NULL)
+ return -ENODEV;
+ return (*client->macc->read)(macc, buf, offset, count);
+}
+
+static inline ssize_t i2c_memory_write(struct i2c_client *client, const char *buf, off_t offset,
+ size_t count)
+{
+ struct memory_accessor *macc = client->macc;
+
+ if (macc == NULL || macc->write == NULL)
+ return -ENODEV;
+ return (*client->macc->write)(macc, buf, offset, count);
+}
+
extern struct i2c_client *i2c_verify_client(struct device *dev);
extern struct i2c_adapter *i2c_verify_adapter(struct device *dev);
--
1.7.12
next reply other threads:[~2012-10-31 15:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-31 15:56 Pantelis Antoniou [this message]
[not found] ` <1351699009-4217-1-git-send-email-panto-wVdstyuyKrO8r51toPun2/C9HSW9iNxf@public.gmane.org>
2012-10-30 18:46 ` [PATCH] i2c-EEPROM: Export memory accessor David Daney
2012-10-30 18:51 ` Pantelis Antoniou
[not found] ` <4AF9EE5B-D1C1-45E7-B2FD-E96151F5772A-wVdstyuyKrO8r51toPun2/C9HSW9iNxf@public.gmane.org>
2012-10-30 19:12 ` David Daney
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=1351699009-4217-1-git-send-email-panto@antoniou-consulting.com \
--to=panto@antoniou-consulting.com \
--cc=Russ.Dill@ti.com \
--cc=ben-linux@fluff.org \
--cc=koen@dominion.thruhere.net \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=mporter@ti.com \
--cc=w.sang@pengutronix.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).