From patchwork Thu Nov 24 00:18:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 9444523 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 8B95560778 for ; Thu, 24 Nov 2016 00:20:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8944E27E5A for ; Thu, 24 Nov 2016 00:20:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DDA327F0B; Thu, 24 Nov 2016 00:20:03 +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 31DB127EE2 for ; Thu, 24 Nov 2016 00:20:03 +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 1c9hlZ-0004gj-86; Thu, 24 Nov 2016 00:19:53 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c9hl3-0004bN-8k; Thu, 24 Nov 2016 00:19:22 +0000 Received: by mail-wm0-x244.google.com with SMTP id a20so3499359wme.2; Wed, 23 Nov 2016 16:18:59 -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=MvjzGd/O8TjeSzkzRf2tfliMY6Jt4eanpKgq/iI+ylk=; b=tyy0dOAp19OjnDn2pKApyt9BSPaJlQZdgFG9399pSb6dny03hd8TPDTF5XTRCt9Pm9 XQpnaztCD+8c7d8qeA1bGrRjCe7gsQCnaC3YbRoyINTKN6jfxEGM2eveQZyr//M3i5JA L/Sz1l1ibouFNNY1Anv/DCujw0XbU0+JLIpB3VxBkJPefjD5JAOsf5Uo+LjlcxdMfJFv uMHDJ5A5BBr+eew41bTjbJ3AtuumOO7wDtvRqtwm1b8v7sgZ2b3jEOclqYaMoyG6LkzJ 7QKWN4tzF4ZDIxi21NLMT/SDm/dWTfIH/MyPSSyV0ELMYB1yvExvS+YGybnRFipGMQ+H p8iQ== 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=MvjzGd/O8TjeSzkzRf2tfliMY6Jt4eanpKgq/iI+ylk=; b=Vly4DgGvUpaTEq0cpnqkumuJmVkonqlvAJv2uBNCziC2WbZ9hR6s/Ax/uCI0wq5c4m hStblElHe9jk+rHpu3k8BDkfXHeJUtE7Q1C/9LinVBH7uIKegMjgz8eAedXEdYSW2cjf ki5IqtoCl2ucOzJ9Zw9rCEOxPKZk5PNkPqK+7y9qPLF59yQNySAYpBijgWS/a/8A9Wah wgHcXf+pTiMU5Wjs8EahhWAQeo6g3zbbc2D6Hgklb2eV8sn38U8c4/ffu3AqUwjEv6Kj S2JhA9elxKN9Fq+gpd6ejZtoyQ5E6dd0jqIoYkr2fPLG24Tbf1tckwgT/drGy5Uxlisr 3pqw== X-Gm-Message-State: AKaTC02U92ldKbX1BHTjMJjLt3tJ4/fm0IZNQUCaS1GhNG7N1afplYtTvFLNj3zibYmUjQ== X-Received: by 10.28.60.194 with SMTP id j185mr5326475wma.33.1479946738502; Wed, 23 Nov 2016 16:18:58 -0800 (PST) Received: from blackbox.darklights.net (p200300DCD3D392049D26C5DBE30B9342.dip0.t-ipconnect.de. [2003:dc:d3d3:9204:9d26:c5db:e30b:9342]) by smtp.googlemail.com with ESMTPSA id j1sm38900686wjm.26.2016.11.23.16.18.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Nov 2016 16:18:57 -0800 (PST) From: Martin Blumenstingl To: sudeep.holla@arm.com, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org Subject: [PATCH] firmware: arm_scpi: fix reading sensor values on pre-1.0 SCPI firmwares Date: Thu, 24 Nov 2016 01:18:45 +0100 Message-Id: <20161124001845.20830-2-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161124001845.20830-1-martin.blumenstingl@googlemail.com> References: <20161124001845.20830-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161123_161921_530981_A6B2F431 X-CRM114-Status: GOOD ( 10.03 ) 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). Signed-off-by: Martin Blumenstingl --- drivers/firmware/arm_scpi.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c index 70e1323..19f750d 100644 --- a/drivers/firmware/arm_scpi.c +++ b/drivers/firmware/arm_scpi.c @@ -728,6 +728,20 @@ static int scpi_sensor_get_value(u16 sensor, u64 *val) return ret; } +static int legacy_scpi_sensor_get_value(u16 sensor, u64 *val) +{ + __le16 id = cpu_to_le16(sensor); + __le32 value; + int ret; + + ret = scpi_send_message(CMD_SENSOR_VALUE, &id, sizeof(id), + &value, sizeof(value)); + if (!ret) + *val = le32_to_cpu(value); + + return ret; +} + static int scpi_device_get_power_state(u16 dev_id) { int ret; @@ -960,6 +974,7 @@ static int scpi_probe(struct platform_device *pdev) if (scpi_info->is_legacy) { /* Replace with legacy variants */ scpi_ops.clk_set_val = legacy_scpi_clk_set_val; + scpi_ops.sensor_get_value = legacy_scpi_sensor_get_value; scpi_info->commands = scpi_legacy_commands; /* Fill priority bitmap */