All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] cros_ec_i2c: prevent i2c timeout for EC_CMD_FLASH_ERASE
@ 2017-05-15 16:22 Wei-Ning Huang
  2017-05-15 17:15 ` Doug Anderson
  0 siblings, 1 reply; 2+ messages in thread
From: Wei-Ning Huang @ 2017-05-15 16:22 UTC (permalink / raw)
  To: LKML
  Cc: Douglas Anderson, Duncan Laurie, Andrew de los Reyes,
	Wei-Ning Huang, lee.jones

From: Wei-Ning Huang <wnhuang@chromium.org>

Some EC chip has larger flash sector size which requires longer erase
time. During erase the CPU is usually stalled and can't even respond to
interrupts. We sleep a while to block any EC command from executing
during the flash erase period.

Signed-off-by: Wei-Ning Huang <wnhuang@chromium.org>
---
 drivers/mfd/cros_ec_i2c.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/mfd/cros_ec_i2c.c b/drivers/mfd/cros_ec_i2c.c
index 9f70de1e4c70..8f23d5a8cc5b 100644
--- a/drivers/mfd/cros_ec_i2c.c
+++ b/drivers/mfd/cros_ec_i2c.c
@@ -23,6 +23,14 @@
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 
+/*
+ * Some EC chip has larger flash sector size which requires longer erase time.
+ * During erase the CPU is usually stalled and can't even respond to
+ * interrupts. We sleep for a while to block any EC command from executing
+ * during the flash erase period to prevent i2c timeout.
+ */
+#define EC_FLASH_ERASE_DELAY_MS	5000
+
 /**
  * Request format for protocol v3
  * byte 0	0xda (EC_COMMAND_PROTOCOL_3)
@@ -177,6 +185,16 @@ static int cros_ec_pkt_xfer_i2c(struct cros_ec_device *ec_dev,
 
 	ret = ec_response->data_len;
 
+	/*
+	 * If we get EC_RES_IN_PROGRESS for EC_CMD_FLASH_ERASE this means EC
+	 * need a long time to erase flash, during flash erase CPU is stalled
+	 * and can't respond to interrupts, so we sleep for a while to stop new
+	 * EC commands from communicating with EC.
+	 */
+	if (msg->command == EC_CMD_FLASH_ERASE &&
+	    msg->result == EC_RES_IN_PROGRESS)
+		msleep(EC_FLASH_ERASE_DELAY_MS);
+
 done:
 	if (msg->command == EC_CMD_REBOOT_EC)
 		msleep(EC_REBOOT_DELAY_MS);
-- 
2.12.2

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] cros_ec_i2c: prevent i2c timeout for EC_CMD_FLASH_ERASE
  2017-05-15 16:22 [PATCH v2] cros_ec_i2c: prevent i2c timeout for EC_CMD_FLASH_ERASE Wei-Ning Huang
@ 2017-05-15 17:15 ` Doug Anderson
  0 siblings, 0 replies; 2+ messages in thread
From: Doug Anderson @ 2017-05-15 17:15 UTC (permalink / raw)
  To: Wei-Ning Huang
  Cc: LKML, Duncan Laurie, Andrew de los Reyes, Lee Jones, Randall Spangler

Hi,

On Mon, May 15, 2017 at 9:22 AM, Wei-Ning Huang <wnhuang@chromium.org> wrote:
> From: Wei-Ning Huang <wnhuang@chromium.org>
>
> Some EC chip has larger flash sector size which requires longer erase
> time. During erase the CPU is usually stalled and can't even respond to
> interrupts. We sleep a while to block any EC command from executing
> during the flash erase period.
>
> Signed-off-by: Wei-Ning Huang <wnhuang@chromium.org>
> ---
>  drivers/mfd/cros_ec_i2c.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)

A few notes:

* I added Randall to the v1 thread, but you dropped him here.  When
someone gets CCed to a patch, it's nice to add them to future
versions.

* I added my Reviewed-by to v1.  When sending a v2, it's nice to carry
that forward since there were no significant changes from v1 to v2.

* I just talked to Randall, and he has an alternate proposal that
avoids the hardcoded delay.  It looks like discussion will carry
forward on the gerrit review.  Once Randall is happy then it'd be good
to post a v3.


-Doug

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-05-15 17:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-15 16:22 [PATCH v2] cros_ec_i2c: prevent i2c timeout for EC_CMD_FLASH_ERASE Wei-Ning Huang
2017-05-15 17:15 ` Doug Anderson

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.