From 785c44fa278b7dd7a4b96c64321dc43fa2220f7d Mon Sep 17 00:00:00 2001
From: James Hughes <james.hughes@raspberrypi.org>
Date: Fri, 27 Apr 2018 10:13:35 +0100
Subject: [PATCH 285/454] Reduce log spam when mailbox call not implemented

This changes the logging message when a mailbox call
fails to the dev_dbg level. In addition, it fixes the
low voltage detection logging code so that if the
mailbox call doies fails, it logs at error level
and flags so the call is no longer attempted.

Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
---
 drivers/firmware/raspberrypi.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

--- a/drivers/firmware/raspberrypi.c
+++ b/drivers/firmware/raspberrypi.c
@@ -151,7 +151,7 @@ int rpi_firmware_property_list(struct rp
 		 * error, if there were multiple tags in the request.
 		 * But single-tag is the most common, so go with it.
 		 */
-		dev_err(fw->cl.dev, "Request 0x%08x returned status 0x%08x\n",
+		dev_dbg(fw->cl.dev, "Request 0x%08x returned status 0x%08x\n",
 			buf[2], buf[1]);
 		ret = -EINVAL;
 	}
@@ -204,6 +204,7 @@ EXPORT_SYMBOL_GPL(rpi_firmware_property)
 
 static int rpi_firmware_get_throttled(struct rpi_firmware *fw, u32 *value)
 {
+	static int old_firmware;
 	static ktime_t old_timestamp;
 	static u32 old_value;
 	u32 new_sticky, old_sticky, new_uv, old_uv;
@@ -214,6 +215,9 @@ static int rpi_firmware_get_throttled(st
 	if (!fw)
 		return -EBUSY;
 
+	if (old_firmware)
+		return -EINVAL;
+
 	/*
 	 * We can't run faster than the sticky shift (100ms) since we get
 	 * flipping in the sticky bits that are cleared.
@@ -232,8 +236,17 @@ static int rpi_firmware_get_throttled(st
 
 	ret = rpi_firmware_property(fw, RPI_FIRMWARE_GET_THROTTLED,
 				    value, sizeof(*value));
-	if (ret)
+
+	if (ret) {
+		/* If the mailbox call fails once, then it will continue to
+		 * fail in the future, so no point in continuing to call it
+		 * Usual failure reason is older firmware
+		 */
+		old_firmware = 1;
+		dev_err(fw->cl.dev, "Get Throttled mailbox call failed");
+
 		return ret;
+	}
 
 	new_sticky = *value >> 16;
 	old_sticky = old_value >> 16;
@@ -270,10 +283,10 @@ static void get_throttled_poll(struct wo
 	int ret;
 
 	ret = rpi_firmware_get_throttled(fw, &dummy);
-	if (ret)
-		pr_debug("%s: Failed to read value (%d)", __func__, ret);
 
-	schedule_delayed_work(&fw->get_throttled_poll_work, 2 * HZ);
+	/* Only reschedule if we are getting valid responses */
+	if (!ret)
+		schedule_delayed_work(&fw->get_throttled_poll_work, 2 * HZ);
 }
 
 static ssize_t get_throttled_show(struct device *dev,
