lkml.org 
[lkml]   [2013]   [Jan]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] i2c-EEPROM: In kernel memory accessor interface
Date
In kernel users need to access the EEPROM using the i2c_client
interface. Extend at24 to use it via the command interface.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>
---
drivers/misc/eeprom/at24.c | 23 ++++++++++++++++++
include/linux/i2c/eeprom.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 82 insertions(+)
create mode 100644 include/linux/i2c/eeprom.h

diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 2baeec5..40b1a95 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -23,6 +23,7 @@
#include <linux/of.h>
#include <linux/i2c.h>
#include <linux/i2c/at24.h>
+#include <linux/i2c/eeprom.h>

/*
* I2C EEPROMs from most vendors are inexpensive and mostly interchangeable.
@@ -672,6 +673,27 @@ static int at24_remove(struct i2c_client *client)
return 0;
}

+static int at24_command(struct i2c_client *client, unsigned int cmd, void *arg)
+{
+ struct at24_data *at24;
+ const struct memory_accessor **maccp;
+
+ /* only supporting a single command */
+ if (cmd != I2C_EEPROM_GET_MEMORY_ACCESSOR)
+ return -ENOTSUPP;
+
+ /* rudimentary check */
+ if (arg == NULL)
+ return -EINVAL;
+
+ at24 = i2c_get_clientdata(client);
+
+ maccp = arg;
+ *maccp = &at24->macc;
+
+ return 0;
+}
+
/*-------------------------------------------------------------------------*/

static struct i2c_driver at24_driver = {
@@ -682,6 +704,7 @@ static struct i2c_driver at24_driver = {
.probe = at24_probe,
.remove = at24_remove,
.id_table = at24_ids,
+ .command = at24_command,
};

static int __init at24_init(void)
diff --git a/include/linux/i2c/eeprom.h b/include/linux/i2c/eeprom.h
new file mode 100644
index 0000000..1393980
--- /dev/null
+++ b/include/linux/i2c/eeprom.h
@@ -0,0 +1,59 @@
+/*
+ * i2c/eeprom.h
+ *
+ * In-kernel interface for accessing eeprom memory.
+ *
+ * Copyright (C) 2012 Texas Instruments Inc.
+ * Pantelis Antoniou <panto@antoniou-consulting.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+#ifndef I2C_EEPROM_H
+#define I2C_EEPROM_H
+
+#include <linux/types.h>
+#include <linux/memory.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+
+/*
+ * The method called in the client is
+ *
+ * int command(struct i2c_client *client, unsigned int cmd, void *arg);
+ *
+ * A single command is supported, which returns a pointer to the memory
+ * accessor already available, but which was only accessible via platform
+ * callbacks. We can't use platform callbacks anymore for device tree
+ * platforms, hence this interface.
+ *
+ */
+
+/* interface commands */
+#define I2C_EEPROM_GET_MEMORY_ACCESSOR 1
+
+static inline struct memory_accessor *
+i2c_eeprom_get_memory_accessor(struct i2c_client *client)
+{
+ int ret;
+ struct memory_accessor *macc;
+
+ /* verify that the i2c client's driver has a command method */
+ if (!client || !client->driver || !client->driver->command)
+ return ERR_PTR(-ENOTSUPP);
+
+ macc = NULL;
+ ret = client->driver->command(client, I2C_EEPROM_GET_MEMORY_ACCESSOR,
+ &macc);
+ if (ret != 0)
+ return ERR_PTR(ret);
+
+ if (macc == NULL)
+ return ERR_PTR(-ENOTSUPP);
+
+ return macc;
+}
+
+#endif
--
1.7.12


\
 
 \ /
  Last update: 2013-01-04 00:21    [W:0.024 / U:0.128 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site