Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp513929ybz; Fri, 24 Apr 2020 04:33:42 -0700 (PDT) X-Google-Smtp-Source: APiQypLdoELyl/6jBQLxSuaEdy8lqLezd7fnCT91MqTwMSwnJtyAnv9M0qP0tL5+ztBMCrllirT4 X-Received: by 2002:a17:906:25cb:: with SMTP id n11mr6901311ejb.37.1587728021911; Fri, 24 Apr 2020 04:33:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587728021; cv=none; d=google.com; s=arc-20160816; b=k2QVziyhs3sPuS/ETFJqaUUb0HxTzEbqEWwMA6/cf7SsQokUZ9oU0FT3R8GHPw9kYU VkfEwM6jjoTkZOKOldbtRvmMuky1SJIncSnRq79O/FI0nl2nuT6qEnrs3gZi5eID/v8q 6V3Z/YG222mdBPZGtX4LR6xvka5T9AYkAZRTVS5JfyIE0+unarZmrqu/j8R/0jGmGYff PNU5Zr1CJqqPLjfV2ary8FgduovIErCAlOILjdkzC5Y7BAszZZQZMt2yi5vBMGv/cWKP I2TvSVQ4eH0OXGJ6AMIb9quoWJfh7zg+FA13tqmYnT8173bK/nUGsKw5qGB63lrS9Bdt YtMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:ironport-sdr:dkim-signature; bh=tamrexV4OWrlM7Wl4jj2JSBcp9yOh7DTXPmsR1xB0mo=; b=aZ7XRfgIfgbtt+5KPUvvAptptKDXiUGdCW5z7Sz+0Z93SWpkJik8VjNVvIT3kr5Kns yl40r1DS51B3Fv2SIBSgLnHIQLHVR5eAjIQKhZbvRmBaUnm2OP0wXcSQ+A7zBkWcAoN0 O3zH8rRWthorO7D/4bI6+ymryz51Bz3M6SixlI8wtzRJSsF0W+uuZXamglWBKbHME7CZ rirQ1nM3qNRuci1zhdIKlCQ4tH9wiWo/6dKEMRDFWwk/POwilZG4D1o6zhr0elcgkOWW c+dRI2GxZoXrMCw5TDD3ZJ3mqvbAt0gQBWKNlmv7z5jj5LeoFi8R/JlUu7t1C0zszABb BXnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=Sonq2jpc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b26si3047899edr.228.2020.04.24.04.33.18; Fri, 24 Apr 2020 04:33:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=Sonq2jpc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726932AbgDXLak (ORCPT + 99 others); Fri, 24 Apr 2020 07:30:40 -0400 Received: from smtp2.axis.com ([195.60.68.18]:3661 "EHLO smtp2.axis.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726698AbgDXLak (ORCPT ); Fri, 24 Apr 2020 07:30:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; l=1906; q=dns/txt; s=axis-central1; t=1587727839; x=1619263839; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=tamrexV4OWrlM7Wl4jj2JSBcp9yOh7DTXPmsR1xB0mo=; b=Sonq2jpcP53RohE8nnFQ4TA8vIgj/OFxcT/0YEfm37W08r7Z8VvrCfK+ Z3Vk/Hc/IDsq3UmExeTNPwOa2POVQGxBKQCZZgqYzopWe5exlIlYV9UXP 8Ze8JSzuUwMRTqKJPg3yp9X4DhRm03orAYC2/7AmTfKXAyabIhk6Urt3F I9CljPE74J5W0MxVcOE0vrAmsAsj/vxuXsxuKffOGBfOgV8Ye9zC3umR6 qH8KdVLP1l4Kxm/3ScbJce9JceEwEQqhIRrkhZhLIzDU9A5CR3eAzmoZb 71xRLVZk/TiaaQgoi3wvKoA8xHfZ/nf69NiUetIRgEmmZbmfgJiT5S+p4 w==; IronPort-SDR: QBW1UsdwJkdX+L6Q3IBWBKo85vacTqeOzOe9md8XEA23dlWnx7Hv5J2W6na8r+MnJND6yWa00K vpV0S2VYIyYRnuVMmQJNJmFeblA6OCoQxVY9V/DJMG780HWLJBd3dPiG1Tw2u+0AJqEfjATqOk /S+ymLYZgbDU8IurBqJuI4yWoA3ZfTlIOnhxkGnCu4TNDMJ6S1Klj1uh4senzbHJ7y9uum6qGT mNz32U0YmYJdXAtcfopsp85P9grV/G0nUo7+8I8O7jgocqN4U6QMwB30eBrKww1ZlqPI9lXxQc LxM= X-IronPort-AV: E=Sophos;i="5.73,311,1583190000"; d="scan'208";a="7791894" From: =?UTF-8?q?Bj=C3=B6rn=20Ard=C3=B6?= To: CC: , , , , =?UTF-8?q?Bj=C3=B6rn=20Ard=C3=B6?= Subject: [PATCHv3] i2c: slave-eeprom: Make it possible to pre-load eeprom data Date: Fri, 24 Apr 2020 13:30:36 +0200 Message-ID: <20200424113036.15109-1-bjorn.ardo@axis.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: Björn Ardö --- drivers/i2c/i2c-slave-eeprom.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/i2c/i2c-slave-eeprom.c b/drivers/i2c/i2c-slave-eeprom.c index cb415b10642f..b425cefea92c 100644 --- a/drivers/i2c/i2c-slave-eeprom.c +++ b/drivers/i2c/i2c-slave-eeprom.c @@ -18,6 +18,7 @@ */ #include +#include #include #include #include @@ -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 error = device_property_read_string(&client->dev, "firmware-name", &eeprom_data); + + if (!error) { + error = request_firmware_into_buf(&fw, eeprom_data, &client->dev, + eeprom->buffer, size); + if (error) + return error; + 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; -- 2.11.0