linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] eeprom: add non-cached sysfs read access to EEPROM data
@ 2009-09-01 23:15 Petri Gynther
  2009-09-01 23:39 ` Greg KH
  2009-09-02  8:30 ` Jean Delvare
  0 siblings, 2 replies; 7+ messages in thread
From: Petri Gynther @ 2009-09-01 23:15 UTC (permalink / raw)
  To: Jean Delvare, Greg Kroah-Hartman; +Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA

Add "eeprom-nc" sysfs attribute to provide non-cached read access
to EEPROM data. This is needed because some EEPROM-like devices
contain constantly changing real-time diagnostic data that cannot
be cached in kernel memory.

Signed-off-by: Petri Gynther <pgynther-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
---
 drivers/misc/eeprom/eeprom.c |   30 +++++++++++++++++++++++++++---
 1 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/drivers/misc/eeprom/eeprom.c b/drivers/misc/eeprom/eeprom.c
index 2c27193..101260b 100644
--- a/drivers/misc/eeprom/eeprom.c
+++ b/drivers/misc/eeprom/eeprom.c
@@ -39,6 +39,10 @@ I2C_CLIENT_INSMOD_1(eeprom);
 /* Size of EEPROM in bytes */
 #define EEPROM_SIZE		256
 
+/* EEPROM read modes */
+#define EEPROM_READ_CACHED      0
+#define EEPROM_READ_NONCACHED   1
+
 /* possible types of eeprom devices */
 enum eeprom_nature {
 	UNKNOWN,
@@ -55,14 +59,16 @@ struct eeprom_data {
 };
 
 
-static void eeprom_update_client(struct i2c_client *client, u8 slice)
+static void eeprom_update_client(struct i2c_client *client, u8 slice,
+				 int eeprom_read_mode)
 {
 	struct eeprom_data *data = i2c_get_clientdata(client);
 	int i;
 
 	mutex_lock(&data->update_lock);
 
-	if (!(data->valid & (1 << slice)) ||
+	if (eeprom_read_mode == EEPROM_READ_NONCACHED ||
+	    !(data->valid & (1 << slice)) ||
 	    time_after(jiffies, data->last_updated[slice] + 300 * HZ)) {
 		dev_dbg(&client->dev, "Starting eeprom update, slice %u\n", slice);
 
@@ -102,7 +108,7 @@ static ssize_t eeprom_read(struct kobject *kobj, struct bin_attribute *bin_attr,
 
 	/* Only refresh slices which contain requested bytes */
 	for (slice = off >> 5; slice <= (off + count - 1) >> 5; slice++)
-		eeprom_update_client(client, slice);
+		eeprom_update_client(client, slice, (int)bin_attr->private);
 
 	/* Hide Vaio private settings to regular users:
 	   - BIOS passwords: bytes 0x00 to 0x0f
@@ -132,6 +138,17 @@ static struct bin_attribute eeprom_attr = {
 	},
 	.size = EEPROM_SIZE,
 	.read = eeprom_read,
+	.private = (void *)EEPROM_READ_CACHED,
+};
+
+static struct bin_attribute eeprom_nc_attr = {
+	.attr = {
+		.name = "eeprom-nc",
+		.mode = S_IRUGO,
+	},
+	.size = EEPROM_SIZE,
+	.read = eeprom_read,
+	.private = (void *)EEPROM_READ_NONCACHED,
 };
 
 /* Return 0 if detection is successful, -ENODEV otherwise */
@@ -202,8 +219,14 @@ static int eeprom_probe(struct i2c_client *client,
 	if (err)
 		goto exit_kfree;
 
+	err = sysfs_create_bin_file(&client->dev.kobj, &eeprom_nc_attr);
+	if (err)
+		goto exit_sysfs_clean;
+
 	return 0;
 
+exit_sysfs_clean:
+	sysfs_remove_bin_file(&client->dev.kobj, &eeprom_attr);
 exit_kfree:
 	kfree(data);
 exit:
@@ -212,6 +235,7 @@ exit:
 
 static int eeprom_remove(struct i2c_client *client)
 {
+	sysfs_remove_bin_file(&client->dev.kobj, &eeprom_nc_attr);
 	sysfs_remove_bin_file(&client->dev.kobj, &eeprom_attr);
 	kfree(i2c_get_clientdata(client));
 
-- 
1.5.4.3

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-09-03 18:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-01 23:15 [PATCH] eeprom: add non-cached sysfs read access to EEPROM data Petri Gynther
2009-09-01 23:39 ` Greg KH
     [not found]   ` <20090901233948.GA3828-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2009-09-02 19:28     ` Petri Gynther
2009-09-02  8:30 ` Jean Delvare
     [not found]   ` <20090902103034.15f13e4d-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-09-02 19:45     ` Petri Gynther
     [not found]       ` <fc21faff0909021245k44e27206t65a268470065431a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-09-02 20:16         ` Jean Delvare
     [not found]           ` <20090902221651.10b13a5b-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-09-03 18:42             ` Petri Gynther

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).