Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1364316 > unrolled thread
| Started by | Bartosz Golaszewski <bgolaszewski@baylibre.com> |
|---|---|
| First post | 2016-03-24 17:30 +0100 |
| Last post | 2016-03-24 17:30 +0100 |
| Articles | 7 — 1 participant |
Back to article view | Back to linux.kernel
[PATCH v2 00/13] eeprom: support for at24cs and at24mac Bartosz Golaszewski <bgolaszewski@baylibre.com> - 2016-03-24 17:30 +0100
[PATCH v2 01/13] eeprom: at24: remove a reduntant if Bartosz Golaszewski <bgolaszewski@baylibre.com> - 2016-03-24 17:30 +0100
[PATCH v2 12/13] eeprom: at24: add support for at24mac series Bartosz Golaszewski <bgolaszewski@baylibre.com> - 2016-03-24 17:30 +0100
[PATCH v2 13/13] eeprom: at24: add at24mac chips to the list of supported devices Bartosz Golaszewski <bgolaszewski@baylibre.com> - 2016-03-24 17:30 +0100
[PATCH v2 04/13] eeprom: at24: make locking more fine-grained Bartosz Golaszewski <bgolaszewski@baylibre.com> - 2016-03-24 17:30 +0100
[PATCH v2 09/13] eeprom: at24: use at24cs_serial_read() Bartosz Golaszewski <bgolaszewski@baylibre.com> - 2016-03-24 17:30 +0100
[PATCH v2 06/13] eeprom: at24: add serial number flag Bartosz Golaszewski <bgolaszewski@baylibre.com> - 2016-03-24 17:30 +0100
| From | Bartosz Golaszewski <bgolaszewski@baylibre.com> |
|---|---|
| Date | 2016-03-24 17:30 +0100 |
| Subject | [PATCH v2 00/13] eeprom: support for at24cs and at24mac |
| Message-ID | <rggj0-5dz-5@gated-at.bofh.it> |
Chips from the at24cs EEPROM series have an additional read-only memory area containing a factory pre-programmed serial number. In order to access it, a dummy write must be executed before reading the serial number bytes. Chips from the at24mac familiy, apart from the serial number, have a second special memory area containing a factory programmed EUI-48/EUI64 mac address. The read-only serial/mac memory area is accessible on a different i2c slave address (addr + 0x08). This patchset makes it possible to instantiate a separate at24 device on this second address and access the read-only area through the regular eeprom sysfs attribute or the new nvmem subsystem. This series also contains several patches intoducing some minor tweaks and refactoring. Tested with at24cs32 and at24cs02 chips (for both 16 and 8 bit address pointers). I have no means of testing the support for at24mac chips, I relied solely on the datasheet. v2: - fixed the 'assignment from incompatible pointer type' bug reported by kbuild v1: https://lkml.org/lkml/2016/3/24/337 Bartosz Golaszewski (13): eeprom: at24: remove a reduntant if eeprom: at24: improve the device_id table readability eeprom: at24: platform_data: use BIT() macro eeprom: at24: make locking more fine-grained eeprom: at24: replace msleep() with usleep_range() eeprom: at24: add serial number flag eeprom: at24: support reading of the serial number eeprom: at24: call read and write routines via function pointers eeprom: at24: use at24cs_serial_read() eeprom: at24: add the at24cs series to the list of supported devices eeprom: at24: add at24mac series flag eeprom: at24: add support for at24mac series eeprom: at24: add at24mac chips to the list of supported devices drivers/misc/eeprom/at24.c | 201 ++++++++++++++++++++++++++++--------- include/linux/platform_data/at24.h | 10 +- 2 files changed, 162 insertions(+), 49 deletions(-) -- 2.7.4
[toc] | [next] | [standalone]
| From | Bartosz Golaszewski <bgolaszewski@baylibre.com> |
|---|---|
| Date | 2016-03-24 17:30 +0100 |
| Subject | [PATCH v2 01/13] eeprom: at24: remove a reduntant if |
| Message-ID | <rggj0-5dz-23@gated-at.bofh.it> |
| In reply to | #1364316 |
It seems as if the second check for I2C_FUNC_I2C functionality had
been introduced accidentally during a merge. Tt's reduntant, so
remove it.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
drivers/misc/eeprom/at24.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 089d694..001a9af 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -544,10 +544,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
} else {
return -EPFNOSUPPORT;
}
- }
- /* Use I2C operations unless we're stuck with SMBus extensions. */
- if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
if (i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {
use_smbus_write = I2C_SMBUS_I2C_BLOCK_DATA;
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Bartosz Golaszewski <bgolaszewski@baylibre.com> |
|---|---|
| Date | 2016-03-24 17:30 +0100 |
| Subject | [PATCH v2 12/13] eeprom: at24: add support for at24mac series |
| Message-ID | <rggj1-5dz-27@gated-at.bofh.it> |
| In reply to | #1364316 |
Add a new read function to the at24 driver allowing to retrieve the
factory-programmed mac address embedded in chips from the at24mac
family.
These chips can be instantiated similarily to the at24cs family,
except that there's no way of having access to both the serial number
and the mac address at the same time - the user must instantiate
either an at24cs or at24mac device as both special memory areas are
accessible on the same slave address.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
drivers/misc/eeprom/at24.c | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 281dd48..edec236 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -239,6 +239,41 @@ static ssize_t at24cs_serial_read(struct at24_data *at24,
return -ETIMEDOUT;
}
+static ssize_t at24mac_mac_read(struct at24_data *at24,
+ char *buf, loff_t off, size_t count)
+{
+ unsigned long timeout, read_time;
+ struct i2c_client *client;
+ unsigned int offset = off;
+ struct i2c_msg msg[2];
+ u8 addrbuf[2];
+ int status;
+
+ client = at24_translate_offset(at24, &offset);
+
+ memset(msg, 0, sizeof(msg));
+ msg[0].addr = client->addr;
+ msg[0].buf = addrbuf;
+ addrbuf[0] = 0x90 + offset;
+ msg[0].len = 1;
+ msg[1].addr = client->addr;
+ msg[1].flags = I2C_M_RD;
+ msg[1].buf = buf;
+ msg[1].len = count;
+
+ timeout = jiffies + msecs_to_jiffies(write_timeout);
+ do {
+ read_time = jiffies;
+ status = i2c_transfer(client->adapter, msg, 2);
+ if (status == 2)
+ return count;
+
+ usleep_range(1000, 1500);
+ } while (time_before(read_time, timeout));
+
+ return -ETIMEDOUT;
+}
+
static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf,
unsigned offset, size_t count)
{
@@ -632,8 +667,16 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
at24->chip = chip;
at24->num_addresses = num_addresses;
+ if ((chip.flags & AT24_FLAG_SERIAL) && (chip.flags & AT24_FLAG_MAC)) {
+ dev_err(&client->dev,
+ "invalid device data - cannot have both AT24_FLAG_SERIAL & AT24_FLAG_MAC.");
+ return -EINVAL;
+ }
+
if (chip.flags & AT24_FLAG_SERIAL) {
at24->read_func = at24cs_serial_read;
+ } else if (chip.flags & AT24_FLAG_MAC) {
+ at24->read_func = at24mac_mac_read;
} else {
at24->read_func = at24_read;
at24->write_func = at24_write;
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Bartosz Golaszewski <bgolaszewski@baylibre.com> |
|---|---|
| Date | 2016-03-24 17:30 +0100 |
| Subject | [PATCH v2 13/13] eeprom: at24: add at24mac chips to the list of supported devices |
| Message-ID | <rggj1-5dz-29@gated-at.bofh.it> |
| In reply to | #1364316 |
Now with the infrastructue for reading the factory-programmed mac
address in place, add the two available chips from the at24mac
family: at24mac402 and at24mac602 to the device ID list.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
drivers/misc/eeprom/at24.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index edec236..558b498 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -120,6 +120,10 @@ static const struct i2c_device_id at24_ids[] = {
{ "24c02", AT24_DEVICE_MAGIC(2048 / 8, 0) },
{ "24cs02", AT24_DEVICE_MAGIC(128 / 8,
AT24_FLAG_SERIAL | AT24_FLAG_READONLY) },
+ { "24mac402", AT24_DEVICE_MAGIC(48 / 8,
+ AT24_FLAG_MAC | AT24_FLAG_READONLY) },
+ { "24mac602", AT24_DEVICE_MAGIC(64 / 8,
+ AT24_FLAG_MAC | AT24_FLAG_READONLY) },
/* spd is a 24c02 in memory DIMMs */
{ "spd", AT24_DEVICE_MAGIC(2048 / 8,
AT24_FLAG_READONLY | AT24_FLAG_IRUGO) },
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Bartosz Golaszewski <bgolaszewski@baylibre.com> |
|---|---|
| Date | 2016-03-24 17:30 +0100 |
| Subject | [PATCH v2 04/13] eeprom: at24: make locking more fine-grained |
| Message-ID | <rggj2-5dz-37@gated-at.bofh.it> |
| In reply to | #1364316 |
The only field in struct at24_data that needs locking in the module
code is u8 *writebuf. Other data is already protected by i2c core.
Rename the lock in at24_data to wrbuf_lock and only use it where
writebuf is accessed.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
drivers/misc/eeprom/at24.c | 28 +++++-----------------------
1 file changed, 5 insertions(+), 23 deletions(-)
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 744c526..9e01428 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -59,13 +59,8 @@ struct at24_data {
int use_smbus;
int use_smbus_write;
- /*
- * Lock protects against activities from other Linux tasks,
- * but not from changes by other I2C masters.
- */
- struct mutex lock;
-
u8 *writebuf;
+ struct mutex wrbuf_lock;
unsigned write_max;
unsigned num_addresses;
@@ -260,12 +255,6 @@ static ssize_t at24_read(struct at24_data *at24,
if (unlikely(!count))
return count;
- /*
- * Read data from chip, protecting against concurrent updates
- * from this host, but not from other I2C masters.
- */
- mutex_lock(&at24->lock);
-
while (count) {
ssize_t status;
@@ -281,8 +270,6 @@ static ssize_t at24_read(struct at24_data *at24,
retval += status;
}
- mutex_unlock(&at24->lock);
-
return retval;
}
@@ -322,6 +309,8 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf,
msg.addr = client->addr;
msg.flags = 0;
+ mutex_lock(&at24->wrbuf_lock);
+
/* msg.buf is u8 and casts will mask the values */
msg.buf = at24->writebuf;
if (at24->chip.flags & AT24_FLAG_ADDR16)
@@ -356,6 +345,7 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf,
status = count;
} else {
status = i2c_transfer(client->adapter, &msg, 1);
+ mutex_unlock(&at24->wrbuf_lock);
if (status == 1)
status = count;
}
@@ -380,12 +370,6 @@ static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off,
if (unlikely(!count))
return count;
- /*
- * Write data to chip, protecting against concurrent updates
- * from this host, but not from other I2C masters.
- */
- mutex_lock(&at24->lock);
-
while (count) {
ssize_t status;
@@ -401,8 +385,6 @@ static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off,
retval += status;
}
- mutex_unlock(&at24->lock);
-
return retval;
}
@@ -566,7 +548,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
if (!at24)
return -ENOMEM;
- mutex_init(&at24->lock);
+ mutex_init(&at24->wrbuf_lock);
at24->use_smbus = use_smbus;
at24->use_smbus_write = use_smbus_write;
at24->chip = chip;
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Bartosz Golaszewski <bgolaszewski@baylibre.com> |
|---|---|
| Date | 2016-03-24 17:30 +0100 |
| Subject | [PATCH v2 09/13] eeprom: at24: use at24cs_serial_read() |
| Message-ID | <rggj2-5dz-41@gated-at.bofh.it> |
| In reply to | #1364316 |
Assign at24cs_serial_read() to at24->read_func if the chip allows serial
number read operation.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
drivers/misc/eeprom/at24.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 4c868a2..d3e4d66 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -163,9 +163,8 @@ static struct i2c_client *at24_translate_offset(struct at24_data *at24,
return at24->client[i];
}
-static ssize_t __attribute__((unused))
-at24cs_serial_read(struct at24_data *at24,
- char *buf, loff_t off, size_t count)
+static ssize_t at24cs_serial_read(struct at24_data *at24,
+ char *buf, loff_t off, size_t count)
{
unsigned long timeout, read_time;
struct i2c_client *client;
@@ -615,8 +614,12 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
at24->chip = chip;
at24->num_addresses = num_addresses;
- at24->read_func = at24_read;
- at24->write_func = at24_write;
+ if (chip.flags & AT24_FLAG_SERIAL) {
+ at24->read_func = at24cs_serial_read;
+ } else {
+ at24->read_func = at24_read;
+ at24->write_func = at24_write;
+ }
writable = !(chip.flags & AT24_FLAG_READONLY);
if (writable) {
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Bartosz Golaszewski <bgolaszewski@baylibre.com> |
|---|---|
| Date | 2016-03-24 17:30 +0100 |
| Subject | [PATCH v2 06/13] eeprom: at24: add serial number flag |
| Message-ID | <rggj2-5dz-43@gated-at.bofh.it> |
| In reply to | #1364316 |
In preparation for supporting the at24cs EEPROM series add a new flag
to platform data. When set, it should tell the driver that the chip
has an additional read-only memory area that holds a factory
pre-programmed serial number.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
include/linux/platform_data/at24.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/linux/platform_data/at24.h b/include/linux/platform_data/at24.h
index a543b93..5bc02fe 100644
--- a/include/linux/platform_data/at24.h
+++ b/include/linux/platform_data/at24.h
@@ -47,6 +47,7 @@ struct at24_platform_data {
#define AT24_FLAG_READONLY BIT(6) /* sysfs-entry will be read-only */
#define AT24_FLAG_IRUGO BIT(5) /* sysfs-entry will be world-readable */
#define AT24_FLAG_TAKE8ADDR BIT(4) /* take always 8 addresses (24c00) */
+#define AT24_FLAG_SERIAL BIT(3) /* factory-programmed serial number */
void (*setup)(struct nvmem_device *nvmem, void *context);
void *context;
--
2.7.4
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web