Message ID | 1567781706-2191-1-git-send-email-bjorn.ardo@axis.com |
---|---|
State | Superseded |
Headers | show |
Series | i2c: slave-eeprom: Make it possible to pre-load eeprom data | expand |
On Fri, Sep 06, 2019 at 04:55:06PM +0200, Björn Ardö wrote: > If the slave eeprom has a "firmware-name" in devicetree, then > pre-load the data in the eeprom with this file. > > Signed-off-by: Björn Ardö <bjorn.ardo@axis.com> Sorry that it got postponed so many times :( > +static int i2c_slave_preload_eeprom_data(struct eeprom_data *eeprom, struct i2c_client *client, unsigned int size) I totally agree with merging the patch "i2c: slave-eeprom: initialize empty eeprom properly" [1] into this one, so we get proper memory init at the end of this function. It should be renamed to "i2c_slave_init_eeprom_data" then, probably... > +{ > + if (client->dev.of_node) { > + const struct firmware *fw; > + const char *eeprom_data; > + if (!of_property_read_string(client->dev.of_node, "firmware-name", &eeprom_data)) { Can you switch to device_property_read_string() and friends? I think the ACPI world may also be interested in this feature. All the rest looks good, thanks!
diff --git a/drivers/i2c/i2c-slave-eeprom.c b/drivers/i2c/i2c-slave-eeprom.c index db9763c..40e7d48 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,21 @@ static ssize_t i2c_slave_eeprom_bin_write(struct file *filp, struct kobject *kob return count; } +static int i2c_slave_preload_eeprom_data(struct eeprom_data *eeprom, struct i2c_client *client, unsigned int size) +{ + if (client->dev.of_node) { + const struct firmware *fw; + const char *eeprom_data; + if (!of_property_read_string(client->dev.of_node, "firmware-name", &eeprom_data)) { + int ret = request_firmware_into_buf(&fw, eeprom_data, &client->dev, eeprom->buffer, size); + if (ret) + return ret; + release_firmware(fw); + } + } + return 0; +} + static int i2c_slave_eeprom_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct eeprom_data *eeprom; @@ -138,6 +154,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_preload_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;
If the slave eeprom has a "firmware-name" in devicetree, then pre-load the data in the eeprom with this file. Signed-off-by: Björn Ardö <bjorn.ardo@axis.com> --- drivers/i2c/i2c-slave-eeprom.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)