From patchwork Tue Apr 16 18:45:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ruslan Babayev (fib)" X-Patchwork-Id: 10903869 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5B1F914DB for ; Tue, 16 Apr 2019 19:00:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B92F28A24 for ; Tue, 16 Apr 2019 19:00:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BC1028A28; Tue, 16 Apr 2019 19:00:45 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 B90C328A19 for ; Tue, 16 Apr 2019 19:00:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728373AbfDPTAo (ORCPT ); Tue, 16 Apr 2019 15:00:44 -0400 Received: from alln-iport-6.cisco.com ([173.37.142.93]:38066 "EHLO alln-iport-6.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727136AbfDPTAo (ORCPT ); Tue, 16 Apr 2019 15:00:44 -0400 X-Greylist: delayed 426 seconds by postgrey-1.27 at vger.kernel.org; Tue, 16 Apr 2019 15:00:43 EDT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=3075; q=dns/txt; s=iport; t=1555441243; x=1556650843; h=from:to:cc:subject:date:message-id; bh=+ziyYOrGFOxYwYIkbsuRKrlf1AgxIqu6pCnnwpnCIyQ=; b=Z9zHZVtZ05bQC7PCNK+Kay2At09DBy0pubxGSFSOLiVMbzcoCMODxCAo QjLg4E4k0Bq7w4/VDx0NRJkjGqjmpNevCoVLkrwu80EGboe43G1XFlW/f VYfz/I34a0NsiMNRPv7p1ue/PzbcbWVeVmytX4vWWBQVqrQyC63wFFOKG o=; X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BEAABrJLZc/4gNJK1mGwEBAQEDAQEBBwMBAQGBVAMBAQELAYIQgTkzKJgMBop8kH0QhG2GCSM3Bg4BAwEBCgECAQJtKIZKKQeBDhODIoF1FKwAijAUgR4BhnOEVhd4gQeEYYQ5hWwDkwqTLAmCCJINDBuCCIoBiG2gLoFlIoFWMxoIGxWDJ5BsHwMwkHIBAQ X-IronPort-AV: E=Sophos;i="5.60,358,1549929600"; d="scan'208";a="262846191" Received: from alln-core-3.cisco.com ([173.36.13.136]) by alln-iport-6.cisco.com with ESMTP/TLS/DHE-RSA-SEED-SHA; 16 Apr 2019 18:53:35 +0000 Received: from tusi.cisco.com (tusi.cisco.com [172.24.98.27]) by alln-core-3.cisco.com (8.15.2/8.15.2) with ESMTP id x3GIrUMq020521; Tue, 16 Apr 2019 18:53:34 GMT From: Ruslan Babayev To: Guenter Roeck Cc: Ruslan Babayev , xe-linux-external@cisco.com, Jean Delvare , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] hwmon: (pmbus/tps40422) add support for output voltage margining Date: Tue, 16 Apr 2019 11:45:46 -0700 Message-Id: <20190416184547.40128-4-fib@cisco.com> X-Mailer: git-send-email 2.17.1 X-Auto-Response-Suppress: DR, OOF, AutoReply X-Outbound-SMTP-Client: 172.24.98.27, tusi.cisco.com X-Outbound-Node: alln-core-3.cisco.com 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 From: Ruslan Babayev TPS40422 has MFR_SPECIFIC registers STEP_VREF_MARGIN_HIGH and STEP_VREF_MARGIN_LOW, which are signed 16-bit in units of 2mV. This value is an offset from the nominal reference voltage of 600mV. For instance, the default value of STEP_VREF_MARGIN_LOW is -30 (decimal), which corresponds to a default margin low voltage of 600 - 30 * 2 = 540mV. Introduce tps40422_{read/write}_word_data() callbacks to map the MFR_SPECIFIC registers to standard PMBUS_VOUT_MARGIN_HIGH and PMBUS_VOUT_MARGIN_LOW. For the latter, pmbus_core stores sensor data in linear16 format as specified in VOUT_MODE. Note, that on TPS40422 the exponent is fixed at (-9). The callbacks will perform the necessary conversions. Cc: xe-linux-external@cisco.com Signed-off-by: Ruslan Babayev --- drivers/hwmon/pmbus/tps40422.c | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/drivers/hwmon/pmbus/tps40422.c b/drivers/hwmon/pmbus/tps40422.c index 32803825d47e..129d1b0e6b43 100644 --- a/drivers/hwmon/pmbus/tps40422.c +++ b/drivers/hwmon/pmbus/tps40422.c @@ -21,16 +21,70 @@ #include #include "pmbus.h" +#define TPS40422_STEP_VREF_MARGIN_HIGH 0xd5 +#define TPS40422_STEP_VREF_MARGIN_LOW 0xd6 +#define TPS40422_VREF 600 + +static int tps40422_read_word_data(struct i2c_client *client, int page, int reg) +{ + int ret; + + switch (reg) { + case PMBUS_VOUT_MARGIN_HIGH: + reg = TPS40422_STEP_VREF_MARGIN_HIGH; + break; + case PMBUS_VOUT_MARGIN_LOW: + reg = TPS40422_STEP_VREF_MARGIN_LOW; + break; + default: + return -ENODATA; + } + + ret = pmbus_read_word_data(client, page, reg); + if (ret < 0) + return ret; + + ret = (TPS40422_VREF + ((s16)ret) * 2) << 9; + ret = DIV_ROUND_CLOSEST(ret, 1000); + + return ret; +} + +static int tps40422_write_word_data(struct i2c_client *client, int page, + int reg, u16 word) +{ + u16 val; + + switch (reg) { + case PMBUS_VOUT_MARGIN_HIGH: + reg = TPS40422_STEP_VREF_MARGIN_HIGH; + break; + case PMBUS_VOUT_MARGIN_LOW: + reg = TPS40422_STEP_VREF_MARGIN_LOW; + break; + default: + return -ENODATA; + } + + val = ((((long)word * 1000) >> 9) - TPS40422_VREF + 1) / 2; + return pmbus_write_word_data(client, page, reg, val); +} + + static struct pmbus_driver_info tps40422_info = { .pages = 2, + .read_word_data = tps40422_read_word_data, + .write_word_data = tps40422_write_word_data, .format[PSC_VOLTAGE_IN] = linear, .format[PSC_VOLTAGE_OUT] = linear, .format[PSC_TEMPERATURE] = linear, .func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_TEMP + | PMBUS_HAVE_VOUT_MARGIN_HIGH | PMBUS_HAVE_VOUT_MARGIN_LOW | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT, .func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_TEMP2 | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_TEMP + | PMBUS_HAVE_VOUT_MARGIN_HIGH | PMBUS_HAVE_VOUT_MARGIN_LOW | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT, };