From patchwork Sun Oct 4 03:14:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chu Lin X-Patchwork-Id: 11815479 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4B53292C for ; Sun, 4 Oct 2020 03:14:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2EBC8206B8 for ; Sun, 4 Oct 2020 03:14:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SNfZWE8c" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726519AbgJDDO4 (ORCPT ); Sat, 3 Oct 2020 23:14:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726442AbgJDDOx (ORCPT ); Sat, 3 Oct 2020 23:14:53 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40CECC0613D0 for ; Sat, 3 Oct 2020 20:14:52 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id m13so4060986qtu.10 for ; Sat, 03 Oct 2020 20:14:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to; bh=K74BKx9bHZWGmWfzS1oHKSxZQ1iYmkRG86K+uoTE8Mw=; b=SNfZWE8cO6qr70BBBZzBKrn6Bz/dkBA6GcN6/4R5MWkUY1R0f44cYmd5szTuEkez34 PPrXCgbDPW3oPBTvUs9iv8nvsWHsxVInb9of3koDmt66BHzaIhxS75J1G881Vt9u07iv /hafahl0jj1lQ9IQxInia9kxYL2K2jersPIfv7UaBSbWb3RBo3fKpM6avbQ5pbZhtrTD weirjS2I3vIGGZZvqeEU9iiBdYwoH7Qh/RSPHJNodYFIJ6LyBFqchCZEcs/HT7FKYhw1 sxTgFxXRevaT30omW8ewh4TJrGEz/F6aJy0LcSP/o7rsk1gF8kT7cgP+eH5DjQgOGM8E 4bKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to; bh=K74BKx9bHZWGmWfzS1oHKSxZQ1iYmkRG86K+uoTE8Mw=; b=qnGMhCxWXxlgMkB8QdjtEuaVUNp56y9zCI53IRAmo5eYwNiI5ryjsh7Gd7dQ6Mb/1f TpHlI6+DtqYxA/kxgVjkawMMP1gfITZIL4rCwxnRSfm97wGTKO+BZTNYAW7OM83K37WG XGGijc8tqMupt/IT/7uqm3cX5TDT1HkRNrfOU9FlXBWW6sEeHU7Vsntj4zPZzIJBmzne obD1/kD4SO/Rdp7J3zqgXefbZ7gxMye4eY5kuLYjTKgJYyPU33ZWOkljkyDDxNoQMyBc c+Aiv1G22IxL3ESq8wtd1jf1ULB+48ghy19Cpql6AHs/1abxWubmYIKJrqbUyKDEIsBU BWAg== X-Gm-Message-State: AOAM532gQH12WZgKbCSkGoYQAEtaO7/X5x9AjCcLMLaQSIOgC6O8cYNp RzE9DLq5UUJos4kWzf4jUjN/p97YGXcZi5Ew X-Google-Smtp-Source: ABdhPJyPnDtt5SCSPZndKt6/zvIc82XFv4am1sypXmgSD/rEZvswkokB14SVVN08/uq7LjfJTZNOtOsuvd2yBUTQ Sender: "linchuyuan via sendgmr" X-Received: from chu-dev.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:3cfb]) (user=linchuyuan job=sendgmr) by 2002:a05:6214:401:: with SMTP id z1mr3148495qvx.53.1601781291176; Sat, 03 Oct 2020 20:14:51 -0700 (PDT) Date: Sun, 4 Oct 2020 03:14:44 +0000 In-Reply-To: <20201004031445.2321090-1-linchuyuan@google.com> Message-Id: <20201004031445.2321090-2-linchuyuan@google.com> Mime-Version: 1.0 References: <20201004031445.2321090-1-linchuyuan@google.com> X-Mailer: git-send-email 2.28.0.806.g8561365e88-goog Subject: [PATCH v4 1/2] dt-bindings: hwmon: max20730: adding device tree doc for max20730 From: Chu Lin To: linchuyuan@google.com, jdelvare@suse.com, linux@roeck-us.net, robh+dt@kernel.org, linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org max20730 Integrated, Step-Down Switching Regulator with PMBus Signed-off-by: Chu Lin Reviewed-by: Rob Herring --- ChangeLog v1 -> v2 hwmon: pmbus: max20730: - Don't do anything to the ret if an error is returned from pmbus_read_word - avoid overflow when doing multiplication ChangeLog v2 -> v3 dt-bindings: hwmon: max20730: - Provide the binding documentation in yaml format hwmon: pmbus: max20730: - No change ChangeLog v3 -> v4 dt-bindings: hwmon: max20730: - Fix highefficiency to high efficiency in description - Fix presents to present in vout-voltage-divider - Add additionalProperties: false hwmon: pmbus: max20730: - No change .../bindings/hwmon/maxim,max20730.yaml | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/maxim,max20730.yaml diff --git a/Documentation/devicetree/bindings/hwmon/maxim,max20730.yaml b/Documentation/devicetree/bindings/hwmon/maxim,max20730.yaml new file mode 100644 index 000000000000..93e86e3b4602 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/maxim,max20730.yaml @@ -0,0 +1,65 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- + +$id: http://devicetree.org/schemas/hwmon/maxim,max20730.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Maxim max20730 + +maintainers: + - Jean Delvare + - Guenter Roeck + +description: | + The MAX20730 is a fully integrated, highly efficient switching regulator + with PMBus for applications operating from 4.5V to 16V and requiring + up to 25A (max) load. This single-chip regulator provides extremely + compact, high efficiency power-delivery solutions with high-precision + output voltages and excellent transient response. + + Datasheets: + https://datasheets.maximintegrated.com/en/ds/MAX20730.pdf + https://datasheets.maximintegrated.com/en/ds/MAX20734.pdf + https://datasheets.maximintegrated.com/en/ds/MAX20743.pdf + +properties: + compatible: + enum: + - maxim,max20730 + - maxim,max20734 + - maxim,max20743 + + reg: + maxItems: 1 + + vout-voltage-divider: + description: | + If voltage divider present at vout, the voltage at voltage sensor pin + will be scaled. The properties will convert the raw reading to a more + meaningful number if voltage divider present. It has two numbers, + the first number is the output resistor, the second number is the total + resistance. Therefore, the adjusted vout is equal to + Vout = Vout * output_resistance / total resistance. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 2 + maxItems: 2 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + max20730@10 { + compatible = "maxim,max20730"; + reg = <0x10>; + vout-voltage-divider = <1000 2000>; // vout would be scaled to 0.5 + }; + }; From patchwork Sun Oct 4 03:14:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chu Lin X-Patchwork-Id: 11815477 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2448A6CB for ; Sun, 4 Oct 2020 03:14:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0A621206B8 for ; Sun, 4 Oct 2020 03:14:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bAzh9QPy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726499AbgJDDO4 (ORCPT ); Sat, 3 Oct 2020 23:14:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726497AbgJDDOz (ORCPT ); Sat, 3 Oct 2020 23:14:55 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25A31C0613E7 for ; Sat, 3 Oct 2020 20:14:55 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id b13so638151pgr.4 for ; Sat, 03 Oct 2020 20:14:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to; bh=LhQBM6coR58Co/ZAPA0BFc3M4Mk5vH1MxVZJV9ls2vA=; b=bAzh9QPy/8+oA04boCqNdkX9voAP/+Gg756k4vP8HjMlDBZ2nMYJSINilK52c1NBez q31UZmbwzvjug2Q0mmo/iOB0pErHbhLKpnX7RpVvOUjq+adQfQHjzgPFvaNwzE8USvMZ Guh8IPPr51x8M9+F6QYQjsbzHNOjGopcZaSZaur+vqIN53nJWpTlwkj73EXl9dcvbrTG eqquSXE5F0qaVh8hIOxHPuOP7hhHirFxcXaWA7ovnvMdC3D1O8KhQUoLKFZhasL2iKtC 0WBHitfyKkreWL0ePFIGykj+vZuGJRaN8kvVoh3CneyY8Puw69/q9TcplQdVm9mMAqEa InTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to; bh=LhQBM6coR58Co/ZAPA0BFc3M4Mk5vH1MxVZJV9ls2vA=; b=UmnxxVy68TtkYCJQxKXahBngDvyLNwjMmRW1sBivhGIF+i+fjTZziVpxZApio37Nb2 Nfim8MPVyn4WwzwMnyFvMaQa4XkOUf1eJJ/7EgjxsapYCxDHuPjrRdr9iYTksnaqQn2v 5tbxT8otjdOhJlAMEEKhq/N4WhhW7Y/7xWUoz1r1VwEsomKr0Llh3DjZtOMz+oy93b4K W3/FyxLvJP2mGoTlp8Us8srPquHWh2AQBeaN0/QQqJ41cirj9Qw1tNFYadihyBpPUZyJ WkNWf6f/9QW01UWo8w2DmBLQSOVwU190DXJfY9/GkyTiz0EyZXzskOJZP9Y1kb0gm22D cPKg== X-Gm-Message-State: AOAM531MjDt/MIJgPY1jBIrAC929g2Xgy3osDmEqJ6rcJ8nU2SBQZKqo 8x/XBoSrPKrWAbf6fGfk1OnrpRWY4dWDQ94T X-Google-Smtp-Source: ABdhPJwzzMxNDTk6r9V6wNabUs9CJ15rB1Am55ZHxJYf8iqp+g/GkSnAUj9Ajd4XZxCWHO/XflZpBBlIIstATRSz Sender: "linchuyuan via sendgmr" X-Received: from chu-dev.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:3cfb]) (user=linchuyuan job=sendgmr) by 2002:a17:90a:990c:: with SMTP id b12mr233850pjp.0.1601781294305; Sat, 03 Oct 2020 20:14:54 -0700 (PDT) Date: Sun, 4 Oct 2020 03:14:45 +0000 In-Reply-To: <20201004031445.2321090-1-linchuyuan@google.com> Message-Id: <20201004031445.2321090-3-linchuyuan@google.com> Mime-Version: 1.0 References: <20201004031445.2321090-1-linchuyuan@google.com> X-Mailer: git-send-email 2.28.0.806.g8561365e88-goog Subject: [PATCH v4 2/2] hwmon: pmbus: max20730: adjust the vout reading given voltage divider From: Chu Lin To: linchuyuan@google.com, jdelvare@suse.com, linux@roeck-us.net, robh+dt@kernel.org, linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Problem: We use voltage dividers so that the voltage presented at the voltage sense pins is confusing. We might need to convert these readings to more meaningful readings given the voltage divider. Solution: Read the voltage divider resistance from dts and convert the voltage reading to a more meaningful reading. Testing: max20730 with voltage divider Signed-off-by: Chu Lin Reviewed-by: Guenter Roeck --- ChangeLog v1 -> v2 hwmon: pmbus: max20730: - Don't do anything to the ret if an error is returned from pmbus_read_word - avoid overflow when doing multiplication ChangeLog v2 -> v3 dt-bindings: hwmon: max20730: - Provide the binding documentation in yaml format hwmon: pmbus: max20730: - No change ChangeLog v3 -> v4 dt-bindings: hwmon: max20730: - Fix highefficiency to high efficiency in description - Fix presents to present in vout-voltage-divider - Add additionalProperties: false hwmon: pmbus: max20730: - No change drivers/hwmon/pmbus/max20730.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/hwmon/pmbus/max20730.c b/drivers/hwmon/pmbus/max20730.c index a151a2b588a5..fbf2f1e6c969 100644 --- a/drivers/hwmon/pmbus/max20730.c +++ b/drivers/hwmon/pmbus/max20730.c @@ -31,6 +31,7 @@ struct max20730_data { struct pmbus_driver_info info; struct mutex lock; /* Used to protect against parallel writes */ u16 mfr_devset1; + u32 vout_voltage_divider[2]; }; #define to_max20730_data(x) container_of(x, struct max20730_data, info) @@ -114,6 +115,14 @@ static int max20730_read_word_data(struct i2c_client *client, int page, max_c = max_current[data->id][(data->mfr_devset1 >> 5) & 0x3]; ret = val_to_direct(max_c, PSC_CURRENT_OUT, info); break; + case PMBUS_READ_VOUT: + ret = pmbus_read_word_data(client, page, phase, reg); + if (ret > 0 && data->vout_voltage_divider[0] && data->vout_voltage_divider[1]) { + u64 temp = DIV_ROUND_CLOSEST_ULL((u64)ret * data->vout_voltage_divider[1], + data->vout_voltage_divider[0]); + ret = clamp_val(temp, 0, 0xffff); + } + break; default: ret = -ENODATA; break; @@ -364,6 +373,15 @@ static int max20730_probe(struct i2c_client *client, data->id = chip_id; mutex_init(&data->lock); memcpy(&data->info, &max20730_info[chip_id], sizeof(data->info)); + if (of_property_read_u32_array(client->dev.of_node, "vout-voltage-divider", + data->vout_voltage_divider, + ARRAY_SIZE(data->vout_voltage_divider)) != 0) + memset(data->vout_voltage_divider, 0, sizeof(data->vout_voltage_divider)); + if (data->vout_voltage_divider[1] < data->vout_voltage_divider[0]) { + dev_err(dev, + "The total resistance of voltage divider is less than output resistance\n"); + return -ENODEV; + } ret = i2c_smbus_read_word_data(client, MAX20730_MFR_DEVSET1); if (ret < 0)