From patchwork Mon Nov 20 04:42:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jeffery X-Patchwork-Id: 10065937 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 91C99602B7 for ; Mon, 20 Nov 2017 04:43:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85D8628F47 for ; Mon, 20 Nov 2017 04:43:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7ADD628F4B; Mon, 20 Nov 2017 04:43:32 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D92E828F4A for ; Mon, 20 Nov 2017 04:43:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751203AbdKTEnF (ORCPT ); Sun, 19 Nov 2017 23:43:05 -0500 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:60829 "EHLO out4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751189AbdKTEnD (ORCPT ); Sun, 19 Nov 2017 23:43:03 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 855BB20B97; Sun, 19 Nov 2017 23:43:02 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Sun, 19 Nov 2017 23:43:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aj.id.au; h=cc :date:from:in-reply-to:in-reply-to:message-id:references :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=VfEoyMMmXZnsMn5+2KP7q4zObb2txS69vOFeEuWbuac=; b=oWe3bXjh c6v7GIW1VENdCUHXCrH8d586Lge//W0+++svaOMmuNQBJdTDpS/Mdwi5Zh4C2uoV jtB8wVQBfcEguVsJ6I7qQ9AmDgFi2TlZ61rUgX/0jcUSI0NKTpjixqOpaiDb1QgL iIT84vnFATe0nDQRY/61wd/skYyNICQWGH6tVfphmvv4QMQB2dfb+0CC+VWM3ify McVFoGo03sANzYAUX6KH9d/uU0K5R2CYk9r0d9OikZNhmjPfWaCOCU/ewNjp+hEP KFm3Hf+Tn8L+budfhGOiow1dy+R3IpSeersTOXQb6e4F6khjs4SXG752SKx2INaQ nATwNROUMwM9+g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:in-reply-to :message-id:references:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=VfEoyMMmXZnsMn5+2KP7q4zObb2tx S69vOFeEuWbuac=; b=U2bg5XL/gH/D0MAV55mMkmV/0yQqjrGa2VSAYgD92I39I x3p/AvTeGG+v1oPnFogUgv/j7qioLMpR1bhgn5v4ZtdKxGTZSph40ypSIv2mfqnT DGB55melVsZ4nYk695G08/+6Y6JZCGfNdsz8nN6dUaiX+XMRjn3ETf1iTE+AxDfk 0D5P5lug8ZYpihgvE5WR3Cv+OIcoFaDpHJAWRED/aJrqnKyfLDToHkfVNshl3ltV sXUi2PHggoWTOkC9Ct4vtb+Uk5xgOuR9S6fIh7OegKURiT2F5p0n3jOg1nPisVmc zgUvQifKiaS7olW+JJZ3amt29zOMg9x1bgpd1ZZNQ== X-ME-Sender: Received: from dave.base64.com.au (unknown [203.0.153.9]) by mail.messagingengine.com (Postfix) with ESMTPA id 70DFF2486D; Sun, 19 Nov 2017 23:42:58 -0500 (EST) From: Andrew Jeffery To: linux-hwmon@vger.kernel.org Cc: Andrew Jeffery , linux@roeck-us.net, jdelvare@suse.com, corbet@lwn.net, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, joel@jms.id.au, openbmc@lists.ozlabs.org Subject: [PATCH v6 3/4] pmbus (core): Add virtual page config bit Date: Mon, 20 Nov 2017 15:12:05 +1030 Message-Id: <57d31e056da37bab946a42c30c1aa4f0a0a595f1.1511152748.git-series.andrew@aj.id.au> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some circumstances call for virtual pages, to expose multiple values packed into an extended PMBus register in a manner non-compliant with the PMBus standard. An example of this is the Maxim MAX31785 controller, which extends the READ_FAN_SPEED_1 PMBus register from two to four bytes to support tach readings for both rotors of a dual rotor fan. This extended register contains two word-sized values, one reporting the rate of the fastest rotor, the other the rate of the slowest. The concept of virtual pages aids this situation by mapping the page number onto the value to be selected from the vectored result. We should not try to set virtual pages on the device as such a page explicitly doesn't exist; add a flag so we can avoid doing so. Signed-off-by: Andrew Jeffery --- drivers/hwmon/pmbus/pmbus.h | 2 ++ drivers/hwmon/pmbus/pmbus_core.c | 27 ++++++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h index b54d7604d3ef..d39d506aa63e 100644 --- a/drivers/hwmon/pmbus/pmbus.h +++ b/drivers/hwmon/pmbus/pmbus.h @@ -372,6 +372,8 @@ enum pmbus_sensor_classes { #define PMBUS_HAVE_PWM12 BIT(20) #define PMBUS_HAVE_PWM34 BIT(21) +#define PMBUS_PAGE_VIRTUAL BIT(31) + enum pmbus_data_format { linear = 0, direct, vid }; enum vrm_version { vr11 = 0, vr12, vr13 }; diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index edc25efe7552..e215bbd403a5 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -161,18 +161,27 @@ EXPORT_SYMBOL_GPL(pmbus_clear_cache); int pmbus_set_page(struct i2c_client *client, int page) { struct pmbus_data *data = i2c_get_clientdata(client); - int rv = 0; - int newpage; + int rv; + + if (page < 0 || page == data->currpage) + return 0; - if (page >= 0 && page != data->currpage) { + if (!(data->info->func[page] & PMBUS_PAGE_VIRTUAL)) { rv = i2c_smbus_write_byte_data(client, PMBUS_PAGE, page); - newpage = i2c_smbus_read_byte_data(client, PMBUS_PAGE); - if (newpage != page) - rv = -EIO; - else - data->currpage = page; + if (rv < 0) + return rv; + + rv = i2c_smbus_read_byte_data(client, PMBUS_PAGE); + if (rv < 0) + return rv; + + if (rv != page) + return -EIO; } - return rv; + + data->currpage = page; + + return 0; } EXPORT_SYMBOL_GPL(pmbus_set_page);