All of lore.kernel.org
 help / color / mirror / Atom feed
From: Baruch Siach <baruch@tkos.co.il>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/2] misc: i2c_eeprom: add eeprom write support
Date: Sun,  7 Apr 2019 12:38:49 +0300	[thread overview]
Message-ID: <7d3ea700c3af62d8ac9b3664610134805018c382.1554629929.git.baruch@tkos.co.il> (raw)
In-Reply-To: <ec4da552adae09ec85b73c06b079b0b8a59bac2e.1554629929.git.baruch@tkos.co.il>

Write up to page size in each i2c transfer.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
 drivers/misc/i2c_eeprom.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/i2c_eeprom.c b/drivers/misc/i2c_eeprom.c
index ce2cad44d8d4..f25d0540075d 100644
--- a/drivers/misc/i2c_eeprom.c
+++ b/drivers/misc/i2c_eeprom.c
@@ -5,6 +5,7 @@
 
 #include <common.h>
 #include <linux/err.h>
+#include <linux/kernel.h>
 #include <dm.h>
 #include <i2c.h>
 #include <i2c_eeprom.h>
@@ -38,7 +39,24 @@ static int i2c_eeprom_std_read(struct udevice *dev, int offset, uint8_t *buf,
 static int i2c_eeprom_std_write(struct udevice *dev, int offset,
 				const uint8_t *buf, int size)
 {
-	return -ENODEV;
+	struct i2c_eeprom *priv = dev_get_priv(dev);
+	int ret;
+
+	while (size > 0) {
+		int write_size = min_t(int, size, priv->pagesize);
+
+		ret = dm_i2c_write(dev, offset, buf, write_size);
+		if (ret)
+			return ret;
+
+		offset += write_size;
+		buf += write_size;
+		size -= write_size;
+
+		udelay(10000);
+	}
+
+	return 0;
 }
 
 static const struct i2c_eeprom_ops i2c_eeprom_std_ops = {
-- 
2.20.1

  reply	other threads:[~2019-04-07  9:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-07  9:38 [U-Boot] [PATCH 1/2] misc: i2c_eeprom: support DT pagesize property Baruch Siach
2019-04-07  9:38 ` Baruch Siach [this message]
2019-04-10  5:30   ` [U-Boot] [PATCH 2/2] misc: i2c_eeprom: add eeprom write support Heiko Schocher
2019-04-10  5:39   ` Heiko Schocher
2019-04-10  5:25 ` [U-Boot] [PATCH 1/2] misc: i2c_eeprom: support DT pagesize property Heiko Schocher
2019-04-10  5:39 ` Heiko Schocher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7d3ea700c3af62d8ac9b3664610134805018c382.1554629929.git.baruch@tkos.co.il \
    --to=baruch@tkos.co.il \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.