Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 139630
b: refs/heads/master
c: 7274ec8
h: refs/heads/master
v: v3
  • Loading branch information
Kevin Hilman authored and Linus Torvalds committed Apr 3, 2009
1 parent 29eebbd commit e7a4354
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 14 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 06c421ee0d5af95c8c6749ca0ba620cd5010707f
refs/heads/master: 7274ec8bd71e99018642f474528ea7de4bb3ae25
67 changes: 54 additions & 13 deletions trunk/drivers/misc/eeprom/at24.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

struct at24_data {
struct at24_platform_data chip;
struct memory_accessor macc;
bool use_smbus;

/*
Expand Down Expand Up @@ -225,14 +226,11 @@ static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf,
return status;
}

static ssize_t at24_bin_read(struct kobject *kobj, struct bin_attribute *attr,
static ssize_t at24_read(struct at24_data *at24,
char *buf, loff_t off, size_t count)
{
struct at24_data *at24;
ssize_t retval = 0;

at24 = dev_get_drvdata(container_of(kobj, struct device, kobj));

if (unlikely(!count))
return count;

Expand Down Expand Up @@ -262,12 +260,14 @@ static ssize_t at24_bin_read(struct kobject *kobj, struct bin_attribute *attr,
return retval;
}

static ssize_t at24_bin_read(struct kobject *kobj, struct bin_attribute *attr,
char *buf, loff_t off, size_t count)
{
struct at24_data *at24;

/*
* REVISIT: export at24_bin{read,write}() to let other kernel code use
* eeprom data. For example, it might hold a board's Ethernet address, or
* board-specific calibration data generated on the manufacturing floor.
*/
at24 = dev_get_drvdata(container_of(kobj, struct device, kobj));
return at24_read(at24, buf, off, count);
}


/*
Expand Down Expand Up @@ -347,14 +347,11 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, char *buf,
return -ETIMEDOUT;
}

static ssize_t at24_bin_write(struct kobject *kobj, struct bin_attribute *attr,
static ssize_t at24_write(struct at24_data *at24,
char *buf, loff_t off, size_t count)
{
struct at24_data *at24;
ssize_t retval = 0;

at24 = dev_get_drvdata(container_of(kobj, struct device, kobj));

if (unlikely(!count))
return count;

Expand Down Expand Up @@ -384,6 +381,39 @@ static ssize_t at24_bin_write(struct kobject *kobj, struct bin_attribute *attr,
return retval;
}

static ssize_t at24_bin_write(struct kobject *kobj, struct bin_attribute *attr,
char *buf, loff_t off, size_t count)
{
struct at24_data *at24;

at24 = dev_get_drvdata(container_of(kobj, struct device, kobj));
return at24_write(at24, buf, off, count);
}

/*-------------------------------------------------------------------------*/

/*
* This lets other kernel code access the eeprom data. For example, it
* might hold a board's Ethernet address, or board-specific calibration
* data generated on the manufacturing floor.
*/

static ssize_t at24_macc_read(struct memory_accessor *macc, char *buf,
off_t offset, size_t count)
{
struct at24_data *at24 = container_of(macc, struct at24_data, macc);

return at24_read(at24, buf, offset, count);
}

static ssize_t at24_macc_write(struct memory_accessor *macc, char *buf,
off_t offset, size_t count)
{
struct at24_data *at24 = container_of(macc, struct at24_data, macc);

return at24_write(at24, buf, offset, count);
}

/*-------------------------------------------------------------------------*/

static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
Expand Down Expand Up @@ -413,6 +443,9 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
* is recommended anyhow.
*/
chip.page_size = 1;

chip.setup = NULL;
chip.context = NULL;
}

if (!is_power_of_2(chip.byte_len))
Expand Down Expand Up @@ -463,13 +496,17 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
at24->bin.read = at24_bin_read;
at24->bin.size = chip.byte_len;

at24->macc.read = at24_macc_read;

writable = !(chip.flags & AT24_FLAG_READONLY);
if (writable) {
if (!use_smbus || i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {

unsigned write_max = chip.page_size;

at24->macc.write = at24_macc_write;

at24->bin.write = at24_bin_write;
at24->bin.attr.mode |= S_IWUSR;

Expand Down Expand Up @@ -520,6 +557,10 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
at24->write_max,
use_smbus ? ", use_smbus" : "");

/* export data to kernel code */
if (chip.setup)
chip.setup(&at24->macc, chip.context);

return 0;

err_clients:
Expand Down
4 changes: 4 additions & 0 deletions trunk/include/linux/i2c/at24.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _LINUX_AT24_H

#include <linux/types.h>
#include <linux/memory.h>

/*
* As seen through Linux I2C, differences between the most common types of I2C
Expand All @@ -23,6 +24,9 @@ struct at24_platform_data {
#define AT24_FLAG_READONLY 0x40 /* sysfs-entry will be read-only */
#define AT24_FLAG_IRUGO 0x20 /* sysfs-entry will be world-readable */
#define AT24_FLAG_TAKE8ADDR 0x10 /* take always 8 addresses (24c00) */

void (*setup)(struct memory_accessor *, void *context);
void *context;
};

#endif /* _LINUX_AT24_H */

0 comments on commit e7a4354

Please sign in to comment.