diff options
author | Björn Ardö <bjorn.ardo@axis.com> | 2020-04-24 14:30:36 +0300 |
---|---|---|
committer | Wolfram Sang <wsa@the-dreams.de> | 2020-04-26 10:39:55 +0300 |
commit | e804f0a78e9e43f0105e1bc3e264894b3898e970 (patch) | |
tree | f087949d2d91a985f84d8283d5303b18c8b3dd05 /drivers/i2c/i2c-slave-eeprom.c | |
parent | e42688ed5cf5936fb55c78cc365dbe0944af7c63 (diff) | |
download | linux-e804f0a78e9e43f0105e1bc3e264894b3898e970.tar.xz |
i2c: slave-eeprom: Make it possible to pre-load eeprom data
If the slave eeprom has a "firmware-name" in devicetree, then pre-load
the data in the eeprom with this file. Otherwise we init the eeprom with
0xFF.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Signed-off-by: Björn Ardö <bjorn.ardo@axis.com>
[wsa: some cosmetic changes]
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'drivers/i2c/i2c-slave-eeprom.c')
-rw-r--r-- | drivers/i2c/i2c-slave-eeprom.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/drivers/i2c/i2c-slave-eeprom.c b/drivers/i2c/i2c-slave-eeprom.c index cb415b10642f..f868dfc362a6 100644 --- a/drivers/i2c/i2c-slave-eeprom.c +++ b/drivers/i2c/i2c-slave-eeprom.c @@ -18,6 +18,7 @@ */ #include <linux/bitfield.h> +#include <linux/firmware.h> #include <linux/i2c.h> #include <linux/init.h> #include <linux/module.h> @@ -120,6 +121,26 @@ static ssize_t i2c_slave_eeprom_bin_write(struct file *filp, struct kobject *kob return count; } +static int i2c_slave_init_eeprom_data(struct eeprom_data *eeprom, struct i2c_client *client, + unsigned int size) +{ + const struct firmware *fw; + const char *eeprom_data; + int ret = device_property_read_string(&client->dev, "firmware-name", &eeprom_data); + + if (!ret) { + ret = request_firmware_into_buf(&fw, eeprom_data, &client->dev, + eeprom->buffer, size); + if (ret) + return ret; + release_firmware(fw); + } else { + /* An empty eeprom typically has all bits set to 1 */ + memset(eeprom->buffer, 0xff, size); + } + return 0; +} + static int i2c_slave_eeprom_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct eeprom_data *eeprom; @@ -138,6 +159,10 @@ static int i2c_slave_eeprom_probe(struct i2c_client *client, const struct i2c_de spin_lock_init(&eeprom->buffer_lock); i2c_set_clientdata(client, eeprom); + ret = i2c_slave_init_eeprom_data(eeprom, client, size); + if (ret) + return ret; + sysfs_bin_attr_init(&eeprom->bin); eeprom->bin.attr.name = "slave-eeprom"; eeprom->bin.attr.mode = S_IRUSR | S_IWUSR; |