From patchwork Sun Dec 11 21:14:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 9469865 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 963D560760 for ; Sun, 11 Dec 2016 21:15:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 889142835E for ; Sun, 11 Dec 2016 21:15:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BE9528358; Sun, 11 Dec 2016 21:15:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2E30628358 for ; Sun, 11 Dec 2016 21:15:44 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cGBT7-0005IV-Lu; Sun, 11 Dec 2016 21:15:37 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cGBSa-0003xm-Iw; Sun, 11 Dec 2016 21:15:06 +0000 Received: by mail-wm0-x243.google.com with SMTP id g23so7120015wme.1; Sun, 11 Dec 2016 13:14:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=c9ESDde0EYrLXHQMz1EJ+bE+XY+4q0o413/rvHjnFbU=; b=x0Gw0Med2YD4RDD4zr+/P9O9yBVkagGFXOZX77NBLSYVoDOYegW/9Xtv98nWGqeBRF UVZt2z+f6IjDEcTOgtXYlQDm8OQTiK+snz4oKfLI/anL+AnvQ8GCtrSkcSPH4VIlYUSy ejKWIEJ2aVNrZ6DwBFdUQoi7U6/CuEUsfHWjumuQM/Wzh2DK6A0rYunvC7BAIMHx+FBQ f9yekMHWW072z5ru5NYdEahxJVins/ylAYOiwB6+pgdRxIv6h/Tp6qL55vKYNUPb3IKM tVpzlePe88AlJeyw7UFUFVJCIZnbH/bupG6qeEG6gZTL3M5k73ukHiPNrSoXsjpEVjKA pDJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=c9ESDde0EYrLXHQMz1EJ+bE+XY+4q0o413/rvHjnFbU=; b=cYcMhJaQLmtnjqYHabgPajm+Kvf/NDiyodwKCQejLNDAhSRpNGP5ua6Y3Tp6/RndG6 gRDzrGZchTeFHxgPga3t9pNPfiGuAveXLGvm69fOTz6l9WPfuxu9QTzM3TCdeaCB390T 2R4xEAy0ISjAPEjExB8K3l8BEoRAjkMbKXSLPSQN6V7+hXVbbrojFbMq/98kNOj7xLz7 Ad8lioUNSkPyfvAtkz5802985HHLfTUotlImcOuI/4PGExHdcVw8vv58GtqkZJ8D3ZXy QIUS2A888835eM4EjZeOBVO0zUKf/5MiUjz+VUxN0LamlL8HzFhCw++IoDefwGK5Bwkq 3Lqw== X-Gm-Message-State: AKaTC00t54FEvHKoonsNyg7eFV70DliZjo1SQ9N/E9ZDNiY9MXr8WwvwEgALNBLCAxX2+w== X-Received: by 10.28.24.74 with SMTP id 71mr15485573wmy.74.1481490882826; Sun, 11 Dec 2016 13:14:42 -0800 (PST) Received: from blackbox.darklights.net (p5DE38254.dip0.t-ipconnect.de. [93.227.130.84]) by smtp.googlemail.com with ESMTPSA id 197sm32201614wmy.16.2016.12.11.13.14.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Dec 2016 13:14:41 -0800 (PST) From: Martin Blumenstingl To: sudeep.holla@arm.com, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org Subject: [PATCH v3] firmware: arm_scpi: fix reading sensor values on pre-1.0 SCPI firmwares Date: Sun, 11 Dec 2016 22:14:32 +0100 Message-Id: <20161211211432.13252-2-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161211211432.13252-1-martin.blumenstingl@googlemail.com> References: <20161125005432.1205-1-martin.blumenstingl@googlemail.com> <20161211211432.13252-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161211_131504_855115_BECE5EAF X-CRM114-Status: GOOD ( 10.17 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , narmstrong@baylibre.com MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The pre-1.0 SCPI firmwares are using one __le32 as sensor value, while the 1.0 SCPI protocol uses two __le32 as sensor values (a total of 64bit, split into 32bit upper and 32bit lower value). Using an "struct sensor_value" to read the sensor value on a pre-1.0 SCPI firmware gives garbage in the "hi_val" field. Introducing a separate function which handles scpi_ops.sensor_get_value for pre-1.0 SCPI firmware implementations ensures that we do not read memory which was not written by the SCPI firmware (which fixes for example the temperature reported by scpi-hwmon). Suggested-by: Sudeep Holla Signed-off-by: Martin Blumenstingl --- drivers/firmware/arm_scpi.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c index 70e1323..9ad0b19 100644 --- a/drivers/firmware/arm_scpi.c +++ b/drivers/firmware/arm_scpi.c @@ -721,11 +721,17 @@ static int scpi_sensor_get_value(u16 sensor, u64 *val) ret = scpi_send_message(CMD_SENSOR_VALUE, &id, sizeof(id), &buf, sizeof(buf)); - if (!ret) + if (ret) + return ret; + + if (scpi_info->is_legacy) + /* only 32-bits supported, hi_val can be junk */ + *val = le32_to_cpu(buf.lo_val); + else *val = (u64)le32_to_cpu(buf.hi_val) << 32 | le32_to_cpu(buf.lo_val); - return ret; + return 0; } static int scpi_device_get_power_state(u16 dev_id)