From patchwork Sat Nov 18 03:26: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: 10064321 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 483BE602B8 for ; Sat, 18 Nov 2017 03:27:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24B022ADA7 for ; Sat, 18 Nov 2017 03:27:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19A5A2ADB4; Sat, 18 Nov 2017 03:27:39 +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=ham 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 7D5582ADA7 for ; Sat, 18 Nov 2017 03:27:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760658AbdKRD1h (ORCPT ); Fri, 17 Nov 2017 22:27:37 -0500 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:33793 "EHLO out4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760263AbdKRD04 (ORCPT ); Fri, 17 Nov 2017 22:26:56 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id ACDF420B56; Fri, 17 Nov 2017 22:26:55 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Fri, 17 Nov 2017 22:26:55 -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=R/Dw2YXzaD4KXl0H+29GL/6kHc1RzJ3yzxp/bHIpO08=; b=iRC6P8Aw wkjT/6baxhIfW4/ja16ARiMs3cu2hj4aQu7bw42BX3GKa+lZz/J0VJoEeflNPyBx 0QPTiqWkLbF4CnOp5bvRvdRXJLD4veFeX3iNF9KSwIeDpPCDvedke5frYI9QgZFx jWEqbRTfKvM32LOo6gO7OCTHViTSnLhs3K/bRNgb8TkMrgesybzSC6dFNFgKLN4Y 0kupAtmE3xoFPFHs+mmQRFhxl/TFiBMLG07PmJYERD5CDY/fwf+3XfVZXS1yGGKH cmC3UHkc2Zb3WF93tke5trhSNrSaytOxFSgbHR+8Mi16ooxee3jKpu5fSZRExyrk ffgpYeh+ZKc8kw== 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=R/Dw2YXzaD4KXl0H+29GL/6kHc1Rz J3yzxp/bHIpO08=; b=YpgpuLBTpMts7dQxc3qqs7kxX5YHXXFCF2aGTSzpOqCA8 XqlajGJNfNGzFF4To0XlvZ/6QeyfFKmHnF3LhzU7D2TuEXiC7686t+ukdqssSLIi /3hfVhZcDxuD1YecE1aQDTdCTZQXk6rwFgalIKXk8H68iSaETT0yfHEw+UkZpv6q obNzUbmH80VEJA6CZLDcFVaDyu60N4yOIm1zAfG+fJj14pciW7q6Nj/8NTs4HuUO QLpmoPp/K9lG6KGWlhJ2TD70fv0FOCXyAzHdshIhEjqBtIUwkCn8UzILjCZyauDb Wrws+jb+3Cwd8jOghQAmTXpoVZdk05CsYiBPFX0Hg== X-ME-Sender: Received: from dave.aj.id.au (220-253-52-107.dyn.iinet.net.au [220.253.52.107]) by mail.messagingengine.com (Postfix) with ESMTPA id 88072240F8; Fri, 17 Nov 2017 22:26:51 -0500 (EST) From: Andrew Jeffery To: linux-hwmon@vger.kernel.org Cc: Andrew Jeffery , linux@roeck-us.net, robh+dt@kernel.org, mark.rutland@arm.com, 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 v5 3/4] pmbus (core): Add virtual page config bit Date: Sat, 18 Nov 2017 13:56:05 +1030 Message-Id: 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 | 10 +++++++--- 2 files changed, 9 insertions(+), 3 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 631db88526b6..ba97230fcde7 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -164,14 +164,18 @@ int pmbus_set_page(struct i2c_client *client, int page) int rv = 0; int newpage; - if (page >= 0 && page != data->currpage) { + if (page < 0 || page == data->currpage) + return 0; + + 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; } + + data->currpage = page; + return rv; } EXPORT_SYMBOL_GPL(pmbus_set_page);