From patchwork Tue Nov 22 11:32:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13052255 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 496A6C433FE for ; Tue, 22 Nov 2022 11:38:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232605AbiKVLie (ORCPT ); Tue, 22 Nov 2022 06:38:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232562AbiKVLiP (ORCPT ); Tue, 22 Nov 2022 06:38:15 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FF605F86E for ; Tue, 22 Nov 2022 03:33:12 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id g12so24221872wrs.10 for ; Tue, 22 Nov 2022 03:33:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=EdIBdMp3AF8wTlK3ZbNuetiQCTdvpib+4RwLHSff3bA=; b=Ko3D6qq0X/Q9S/oaND9aZ47sWgBSPYistB0gEGIxAs/CITTsPTijNT5eFpmpcZh4eA pIM9Bk8JxxtYD+gOVdVVLbdzHy89VYPtXmir/Uyg+4Wpv37+9mF2Eyr52kQIgDM6UCSk Suk0CAcq3wf/QwbLXtmZixKOrsTBNBugslp13Ntbds/78RoMSDpm+UQOaDJz2M0smEYx GIibFqnzGWZ/lEXt88+mz4wFbB4L0ypw0M0BIptL/B2OfZHMHwvKaOYerEsTqq2gwLh2 Yx/xDiZOE4prNsky7/lWH+Zvny4jLbOVuFgs+56VeNO8NNuOWWE0B53D8v9NlqDXd4UU Y9pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EdIBdMp3AF8wTlK3ZbNuetiQCTdvpib+4RwLHSff3bA=; b=IOoPeQqSkfGhJEe8NSccjXA7m4OCUmTlCLR5WvVFN1YSICPDIGY5oPr++S+3z9KtC3 tVV0oTqmARXBa6I0Tm1lW3Kzp3Ccz2AMVD8b9BcT1C1hLkbdgxoga3RgDR8n/EoxpvmW 53RsOJXGmpyozGonDPxnq97eRzsIUwkX1FNcXy4MsCjA4yOEjoXnyQJRbQbbmUXmPfkR tTngtNxDw101lncitD8eR1MG5h8SdlR/X/3CEjeXVWxarCcr6nWUKuR0jlbc8n5L4WoP XypULF8Ic9wVwWEnRzNsDmTfPruXCuJK+meScCyG8PYEvrRUmPyVrmGiONYzwoPXrlTJ pxfQ== X-Gm-Message-State: ANoB5pmeJsywoFvxb+/hYDvNqx37pecwOzSQxFhNxBIgYr/+v7k92hX+ 1BwehSizpaj/QdLfhq26C3TDVQ== X-Google-Smtp-Source: AA0mqf4aBa3FK/8gagbzzeR11M3kkvWcGOOe/+bUocyUfgCqYwH5jPzY4hnTutCkv+H1xzXXipNR6w== X-Received: by 2002:adf:fec7:0:b0:236:8d39:6f84 with SMTP id q7-20020adffec7000000b002368d396f84mr13166871wrs.152.1669116791291; Tue, 22 Nov 2022 03:33:11 -0800 (PST) Received: from stroh80.sec.9e.network (ip-078-094-000-051.um19.pools.vodafone-ip.de. [78.94.0.51]) by smtp.gmail.com with ESMTPSA id x11-20020a5d60cb000000b00241bc4880fesm12914086wrt.111.2022.11.22.03.33.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 03:33:10 -0800 (PST) From: Naresh Solanki X-Google-Original-From: Naresh Solanki To: Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare Cc: broonie@kernel.org, Naresh Solanki , linux-kernel@vger.kernel.org Subject: [PATCH 1/3] hwmon: (pmbus/core): Update regulator flag map Date: Tue, 22 Nov 2022 12:32:55 +0100 Message-Id: <20221122113257.3213700-1-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add regulator flag map for PMBUS status byte & status input. Signed-off-by: Naresh Solanki --- drivers/hwmon/pmbus/pmbus_core.c | 52 +++++++++++++++++--------------- 1 file changed, 28 insertions(+), 24 deletions(-) base-commit: 2c71b3246ec3246522e8cb7c8191dc7a5d62cc70 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 20ca26e19db7..08f96e2b4837 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -2756,26 +2756,47 @@ static const struct pmbus_regulator_status_category pmbus_regulator_flag_map[] = .reg = PMBUS_STATUS_VOUT, .bits = (const struct pmbus_regulator_status_assoc[]) { { PB_VOLTAGE_UV_WARNING, REGULATOR_ERROR_UNDER_VOLTAGE_WARN }, - { PB_VOLTAGE_UV_FAULT, REGULATOR_ERROR_UNDER_VOLTAGE }, + { PB_VOLTAGE_UV_FAULT, REGULATOR_ERROR_UNDER_VOLTAGE }, { PB_VOLTAGE_OV_WARNING, REGULATOR_ERROR_OVER_VOLTAGE_WARN }, - { PB_VOLTAGE_OV_FAULT, REGULATOR_ERROR_REGULATION_OUT }, + { PB_VOLTAGE_OV_FAULT, REGULATOR_ERROR_REGULATION_OUT }, { }, }, }, { .func = PMBUS_HAVE_STATUS_IOUT, .reg = PMBUS_STATUS_IOUT, .bits = (const struct pmbus_regulator_status_assoc[]) { - { PB_IOUT_OC_WARNING, REGULATOR_ERROR_OVER_CURRENT_WARN }, - { PB_IOUT_OC_FAULT, REGULATOR_ERROR_OVER_CURRENT }, - { PB_IOUT_OC_LV_FAULT, REGULATOR_ERROR_OVER_CURRENT }, + { PB_IOUT_OC_WARNING, REGULATOR_ERROR_OVER_CURRENT_WARN }, + { PB_IOUT_OC_FAULT, REGULATOR_ERROR_OVER_CURRENT }, + { PB_IOUT_OC_LV_FAULT, REGULATOR_ERROR_OVER_CURRENT }, + { PB_POUT_OP_FAULT, REGULATOR_ERROR_OVER_CURRENT }, { }, }, }, { .func = PMBUS_HAVE_STATUS_TEMP, .reg = PMBUS_STATUS_TEMPERATURE, .bits = (const struct pmbus_regulator_status_assoc[]) { - { PB_TEMP_OT_WARNING, REGULATOR_ERROR_OVER_TEMP_WARN }, - { PB_TEMP_OT_FAULT, REGULATOR_ERROR_OVER_TEMP }, + { PB_TEMP_OT_WARNING, REGULATOR_ERROR_OVER_TEMP_WARN }, + { PB_TEMP_OT_FAULT, REGULATOR_ERROR_OVER_TEMP }, + { }, + }, + }, { + .func = -1, + .reg = PMBUS_STATUS_BYTE, + .bits = (const struct pmbus_regulator_status_assoc[]) { + { PB_STATUS_IOUT_OC, REGULATOR_ERROR_OVER_CURRENT }, + { PB_STATUS_VOUT_OV, REGULATOR_ERROR_REGULATION_OUT }, + { PB_STATUS_VIN_UV, REGULATOR_ERROR_UNDER_VOLTAGE }, + { PB_STATUS_NONE_ABOVE, REGULATOR_ERROR_FAIL }, + { }, + }, + }, { + .func = PMBUS_HAVE_STATUS_INPUT, + .reg = PMBUS_STATUS_INPUT, + .bits = (const struct pmbus_regulator_status_assoc[]) { + { PB_IIN_OC_FAULT, REGULATOR_ERROR_OVER_CURRENT }, + { PB_VOLTAGE_OV_FAULT, REGULATOR_ERROR_OVER_VOLTAGE_WARN }, + { PB_VOLTAGE_OV_WARNING, REGULATOR_ERROR_OVER_VOLTAGE_WARN }, + { PB_VOLTAGE_UV_FAULT, REGULATOR_ERROR_UNDER_VOLTAGE }, { }, }, }, @@ -2834,23 +2855,6 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned if (status & PB_STATUS_POWER_GOOD_N) *flags |= REGULATOR_ERROR_REGULATION_OUT; } - /* - * Unlike most other status bits, PB_STATUS_{IOUT_OC,VOUT_OV} are - * defined strictly as fault indicators (not warnings). - */ - if (status & PB_STATUS_IOUT_OC) - *flags |= REGULATOR_ERROR_OVER_CURRENT; - if (status & PB_STATUS_VOUT_OV) - *flags |= REGULATOR_ERROR_REGULATION_OUT; - - /* - * If we haven't discovered any thermal faults or warnings via - * PMBUS_STATUS_TEMPERATURE, map PB_STATUS_TEMPERATURE to a warning as - * a (conservative) best-effort interpretation. - */ - if (!(*flags & (REGULATOR_ERROR_OVER_TEMP | REGULATOR_ERROR_OVER_TEMP_WARN)) && - (status & PB_STATUS_TEMPERATURE)) - *flags |= REGULATOR_ERROR_OVER_TEMP_WARN; return 0; } From patchwork Tue Nov 22 11:32:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13052254 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD8F6C4332F for ; Tue, 22 Nov 2022 11:38:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232509AbiKVLic (ORCPT ); Tue, 22 Nov 2022 06:38:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232475AbiKVLiN (ORCPT ); Tue, 22 Nov 2022 06:38:13 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70BC3606AB for ; Tue, 22 Nov 2022 03:33:13 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id b12so10456518wrn.2 for ; Tue, 22 Nov 2022 03:33:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=c2zr/3LnDgZvKq+c4XGc3H/8wNdt4pUTOlQ5WTUoXqY=; b=RW5GjrPQStt/3N3wqzjmvb75Xed84o1+oHhxvHAmUMk4kdKH5Js+45eAVEzTJa/MoJ WHbR9YMfwyL11SK1dBBD2CfJHg/SRWRDxz26P9/uAlEeev3jRSzgTSQkc0ntjAN59QG5 fUXwt6dlFo7zPX6HPRslBtwqTbfThHvhfOcRsEZ2qn4FFlrq1dwIjgMZuxSvtb50hEYu tX9kXMlw3pdCdzeHGB0sOlPSxAbXcGDIx7e4C9a+SsI5Vwvk0bGWXqMbEGfg1SREz5r2 Wej3n9C5A1I73QrpK0mUiTi5UI5T6Hygct/QndPtuIiu/5Z6lGegQ6exQ89mt3QJaFb+ NByQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c2zr/3LnDgZvKq+c4XGc3H/8wNdt4pUTOlQ5WTUoXqY=; b=sZ2dPTgjvTvT4uNs/dxBXYI+RqNCEE6zLNRl8AsSLg6SCdPveqqJ7SJFTTYoof/YZu Ka1PDcrYSv0xPyNYE9ZEL2PKnmAawbu4pVCqDckXy4FrpipgLV9APUgQceFXKbNGCjo+ 4BSEyvxKWdo0NLJM2ortnZK/i9lLqCnDkkWtuBDQB1MxRMNU/b39j6t0V+ttzIoPrkZh rkvdq224u43qSbvBRWOqKx+om76T3RMOY/gM9YN3BrlPxqN9G3qlnWB5snNpzSPRMoZs K5socpizojFrUZRNQx7yOZnY6p5/7xvZJkyfN6wbttyZZ2xpwdOEIL56O2NDBt1jUlHi T+qw== X-Gm-Message-State: ANoB5pmB9Jykg9X+vEqUV0MuTCI0e+4dmyBkuseg93uliHFMwtbH5M1K caIZE15HNpBK2HG64c6GyAqfVg== X-Google-Smtp-Source: AA0mqf4CrIPLr/j50ifVlKk7DcR6q7icqtILjB+Y0z5gNVZ2mixNP6S+Ru8dACI0XSNFDe7yBf6ypQ== X-Received: by 2002:adf:dd8c:0:b0:236:63d4:fbbe with SMTP id x12-20020adfdd8c000000b0023663d4fbbemr14008361wrl.574.1669116792346; Tue, 22 Nov 2022 03:33:12 -0800 (PST) Received: from stroh80.sec.9e.network (ip-078-094-000-051.um19.pools.vodafone-ip.de. [78.94.0.51]) by smtp.gmail.com with ESMTPSA id x11-20020a5d60cb000000b00241bc4880fesm12914086wrt.111.2022.11.22.03.33.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 03:33:12 -0800 (PST) From: Naresh Solanki X-Google-Original-From: Naresh Solanki To: Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare Cc: broonie@kernel.org, Patrick Rudolph , Naresh Solanki , linux-kernel@vger.kernel.org Subject: [PATCH 2/3] hwmon: (pmbus/core): Add events to regulator flag map Date: Tue, 22 Nov 2022 12:32:56 +0100 Message-Id: <20221122113257.3213700-2-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221122113257.3213700-1-Naresh.Solanki@9elements.com> References: <20221122113257.3213700-1-Naresh.Solanki@9elements.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Patrick Rudolph Add regulator events corresponding to regulator error in regulator flag map. Signed-off-by: Patrick Rudolph Signed-off-by: Naresh Solanki --- drivers/hwmon/pmbus/pmbus_core.c | 68 ++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 08f96e2b4837..7d7d10039987 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -2738,9 +2738,9 @@ static int pmbus_regulator_disable(struct regulator_dev *rdev) return _pmbus_regulator_on_off(rdev, 0); } -/* A PMBus status flag and the corresponding REGULATOR_ERROR_* flag */ +/* A PMBus status flag and the corresponding REGULATOR_ERROR_* and REGULATOR_EVENTS_* flag */ struct pmbus_regulator_status_assoc { - int pflag, rflag; + int pflag, rflag, eflag; }; /* PMBus->regulator bit mappings for a PMBus status register */ @@ -2755,48 +2755,76 @@ static const struct pmbus_regulator_status_category pmbus_regulator_flag_map[] = .func = PMBUS_HAVE_STATUS_VOUT, .reg = PMBUS_STATUS_VOUT, .bits = (const struct pmbus_regulator_status_assoc[]) { - { PB_VOLTAGE_UV_WARNING, REGULATOR_ERROR_UNDER_VOLTAGE_WARN }, - { PB_VOLTAGE_UV_FAULT, REGULATOR_ERROR_UNDER_VOLTAGE }, - { PB_VOLTAGE_OV_WARNING, REGULATOR_ERROR_OVER_VOLTAGE_WARN }, - { PB_VOLTAGE_OV_FAULT, REGULATOR_ERROR_REGULATION_OUT }, + { PB_VOLTAGE_UV_WARNING, REGULATOR_ERROR_UNDER_VOLTAGE_WARN, + REGULATOR_EVENT_UNDER_VOLTAGE_WARN }, + { PB_VOLTAGE_UV_FAULT, REGULATOR_ERROR_UNDER_VOLTAGE, + REGULATOR_EVENT_UNDER_VOLTAGE }, + { PB_VOLTAGE_OV_WARNING, REGULATOR_ERROR_OVER_VOLTAGE_WARN, + REGULATOR_EVENT_OVER_VOLTAGE_WARN }, + { PB_VOLTAGE_OV_FAULT, REGULATOR_ERROR_REGULATION_OUT, + REGULATOR_EVENT_OVER_VOLTAGE_WARN }, { }, }, }, { .func = PMBUS_HAVE_STATUS_IOUT, .reg = PMBUS_STATUS_IOUT, .bits = (const struct pmbus_regulator_status_assoc[]) { - { PB_IOUT_OC_WARNING, REGULATOR_ERROR_OVER_CURRENT_WARN }, - { PB_IOUT_OC_FAULT, REGULATOR_ERROR_OVER_CURRENT }, - { PB_IOUT_OC_LV_FAULT, REGULATOR_ERROR_OVER_CURRENT }, - { PB_POUT_OP_FAULT, REGULATOR_ERROR_OVER_CURRENT }, + { PB_IOUT_OC_WARNING, REGULATOR_ERROR_OVER_CURRENT_WARN, + REGULATOR_EVENT_OVER_CURRENT_WARN }, + { PB_IOUT_OC_FAULT, REGULATOR_ERROR_OVER_CURRENT, + REGULATOR_EVENT_OVER_CURRENT }, + { PB_IOUT_OC_LV_FAULT, REGULATOR_ERROR_OVER_CURRENT, + REGULATOR_EVENT_OVER_CURRENT }, + { PB_POUT_OP_FAULT, REGULATOR_ERROR_OVER_CURRENT, + REGULATOR_EVENT_OVER_CURRENT }, { }, }, }, { .func = PMBUS_HAVE_STATUS_TEMP, .reg = PMBUS_STATUS_TEMPERATURE, .bits = (const struct pmbus_regulator_status_assoc[]) { - { PB_TEMP_OT_WARNING, REGULATOR_ERROR_OVER_TEMP_WARN }, - { PB_TEMP_OT_FAULT, REGULATOR_ERROR_OVER_TEMP }, + { PB_TEMP_OT_WARNING, REGULATOR_ERROR_OVER_TEMP_WARN, + REGULATOR_EVENT_OVER_TEMP_WARN }, + { PB_TEMP_OT_FAULT, REGULATOR_ERROR_OVER_TEMP, + REGULATOR_EVENT_OVER_TEMP }, { }, }, }, { .func = -1, .reg = PMBUS_STATUS_BYTE, .bits = (const struct pmbus_regulator_status_assoc[]) { - { PB_STATUS_IOUT_OC, REGULATOR_ERROR_OVER_CURRENT }, - { PB_STATUS_VOUT_OV, REGULATOR_ERROR_REGULATION_OUT }, - { PB_STATUS_VIN_UV, REGULATOR_ERROR_UNDER_VOLTAGE }, - { PB_STATUS_NONE_ABOVE, REGULATOR_ERROR_FAIL }, + { PB_STATUS_IOUT_OC, REGULATOR_ERROR_OVER_CURRENT, + REGULATOR_EVENT_OVER_CURRENT }, + { PB_STATUS_VOUT_OV, REGULATOR_ERROR_OVER_VOLTAGE_WARN, + REGULATOR_EVENT_OVER_VOLTAGE_WARN }, + { PB_STATUS_VIN_UV, REGULATOR_ERROR_UNDER_VOLTAGE, + REGULATOR_EVENT_UNDER_VOLTAGE }, + { PB_STATUS_OFF, 0, + REGULATOR_EVENT_DISABLE }, + { PB_STATUS_NONE_ABOVE, REGULATOR_ERROR_FAIL, + REGULATOR_EVENT_FAIL }, + { }, + }, + }, { + .func = -1, + .reg = PMBUS_STATUS_WORD, + .bits = (const struct pmbus_regulator_status_assoc[]) { + { PB_STATUS_POWER_GOOD_N, 0, + REGULATOR_EVENT_REGULATION_OUT }, { }, }, }, { .func = PMBUS_HAVE_STATUS_INPUT, .reg = PMBUS_STATUS_INPUT, .bits = (const struct pmbus_regulator_status_assoc[]) { - { PB_IIN_OC_FAULT, REGULATOR_ERROR_OVER_CURRENT }, - { PB_VOLTAGE_OV_FAULT, REGULATOR_ERROR_OVER_VOLTAGE_WARN }, - { PB_VOLTAGE_OV_WARNING, REGULATOR_ERROR_OVER_VOLTAGE_WARN }, - { PB_VOLTAGE_UV_FAULT, REGULATOR_ERROR_UNDER_VOLTAGE }, + { PB_IIN_OC_FAULT, REGULATOR_ERROR_OVER_CURRENT, + REGULATOR_EVENT_OVER_CURRENT }, + { PB_VOLTAGE_OV_FAULT, REGULATOR_ERROR_OVER_VOLTAGE_WARN, + REGULATOR_EVENT_OVER_VOLTAGE_WARN }, + { PB_VOLTAGE_OV_WARNING, REGULATOR_ERROR_OVER_VOLTAGE_WARN, + REGULATOR_EVENT_OVER_VOLTAGE_WARN }, + { PB_VOLTAGE_UV_FAULT, REGULATOR_ERROR_UNDER_VOLTAGE, + REGULATOR_EVENT_UNDER_VOLTAGE }, { }, }, }, From patchwork Tue Nov 22 11:32:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13052256 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36642C43219 for ; Tue, 22 Nov 2022 11:38:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232583AbiKVLie (ORCPT ); Tue, 22 Nov 2022 06:38:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232586AbiKVLiP (ORCPT ); Tue, 22 Nov 2022 06:38:15 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70E7D606B5 for ; Tue, 22 Nov 2022 03:33:15 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id l14so5379466wrw.13 for ; Tue, 22 Nov 2022 03:33:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sIMthWRv9QH4f8IhwYnbK6rK18ReVZ6lQR3GH4fCpEY=; b=hharGGQN2xOe0HApjcil1RiFHn26qSrEDJyXQg40tzFVPEtUJ0de6zzPwjALG9rZ4z BqeUfV97lPBbROssAOWgqiE4oNZsfuP+Aro9ZVZTLrBv3V2n81Kye9TW4R4PrC3EOzuu 1iWVYbJCMzeSVNKWL3vqWnrKIDUeF+3IDSYtUiTJ0FvSO4Xc9AKZlLGgeMx8zQ8TvrBC tBmtj5r6zMVQ9WZqcOssVCFvtNsomaxEL0EUWdGyMkhweI5WRvjKNG97hqtgDX6fxWZA EO4oY1826fY7K62Q/GJWj5KR0xaSMzyX0FylWSIWlSeiBiIN4Rv29TpVbe5g76+1LAvB M07w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sIMthWRv9QH4f8IhwYnbK6rK18ReVZ6lQR3GH4fCpEY=; b=4PSSn9bLP+SiMCLQUEJBVIJSAKl/WIjXPinvyQsRHzVOEIRGwG7ho9sMYCv+oHTF9A IfTBt50Gb8QFCcPdtbY/U9hhcuSjF7HQnqZEReyjhIm7q2nHwTZc8IfF+vcmEas4xNem X/gErbwLtFLgvStfmqvRYGrEdV5F2nwma5sAvE61xEaVqTXRFucbOBNTxoJ5QgnPnvJa FSdzoQWbaNGDZzSy7rXZXuWhCh9aqRxsn67Owkxp9yt3kV/VmlpWZ6pYLuMNPAxNvHIV 6G1tOSCYEH/y/zh/tgtrbXvGrELRHrdP7dPUqJZewLBu5KIUAxtx+62YO/78DHI4u0Pw B9Zg== X-Gm-Message-State: ANoB5plaxllF8rNOarn9ori2uMT5/1tvugD4mLozRHStqUDGuy3YtElB WGKIAXb8YDm4Mvfp/xOauR48PA== X-Google-Smtp-Source: AA0mqf647JGRBnHPLuoHfAJf2YjY8fCLsFnDMSo3BM+PUmTG+0E4dGr042libqGPqKA/J/axO9zL5g== X-Received: by 2002:a05:6000:107:b0:22e:3460:5e28 with SMTP id o7-20020a056000010700b0022e34605e28mr2247083wrx.211.1669116793581; Tue, 22 Nov 2022 03:33:13 -0800 (PST) Received: from stroh80.sec.9e.network (ip-078-094-000-051.um19.pools.vodafone-ip.de. [78.94.0.51]) by smtp.gmail.com with ESMTPSA id x11-20020a5d60cb000000b00241bc4880fesm12914086wrt.111.2022.11.22.03.33.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 03:33:13 -0800 (PST) From: Naresh Solanki X-Google-Original-From: Naresh Solanki To: Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare Cc: broonie@kernel.org, Patrick Rudolph , Naresh Solanki , linux-kernel@vger.kernel.org Subject: [PATCH 3/3] hwmon: (pmbus/core): Implement IRQ support Date: Tue, 22 Nov 2022 12:32:57 +0100 Message-Id: <20221122113257.3213700-3-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221122113257.3213700-1-Naresh.Solanki@9elements.com> References: <20221122113257.3213700-1-Naresh.Solanki@9elements.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Patrick Rudolph Implement IRQ support to monitor PMBUS regulator events. Signed-off-by: Patrick Rudolph Signed-off-by: Naresh Solanki --- drivers/hwmon/pmbus/pmbus.h | 2 +- drivers/hwmon/pmbus/pmbus_core.c | 155 ++++++++++++++++++++++++++++--- 2 files changed, 144 insertions(+), 13 deletions(-) diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h index 10fb17879f8e..6b2e6cf93b19 100644 --- a/drivers/hwmon/pmbus/pmbus.h +++ b/drivers/hwmon/pmbus/pmbus.h @@ -26,7 +26,7 @@ enum pmbus_regs { PMBUS_CAPABILITY = 0x19, PMBUS_QUERY = 0x1A, - + PMBUS_SMBALERT_MASK = 0x1B, PMBUS_VOUT_MODE = 0x20, PMBUS_VOUT_COMMAND = 0x21, PMBUS_VOUT_TRIM = 0x22, diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 7d7d10039987..4234297813bb 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -3033,13 +3033,110 @@ const struct regulator_ops pmbus_regulator_ops = { }; EXPORT_SYMBOL_NS_GPL(pmbus_regulator_ops, PMBUS); -static int pmbus_regulator_register(struct pmbus_data *data) +static int pmbus_write_smbalert_mask(struct i2c_client *client, u8 page, u8 reg, u8 val) { - struct device *dev = data->dev; + return pmbus_write_word_data(client, page, PMBUS_SMBALERT_MASK, reg | (val << 8)); +} + +static int pmbus_irq_subhandler(struct i2c_client *client, struct regulator_err_state *stat, + unsigned long *dev_mask) +{ + struct pmbus_data *data = i2c_get_clientdata(client); + u8 page = rdev_get_id(stat->rdev); + const struct pmbus_regulator_status_category *cat; + const struct pmbus_regulator_status_assoc *bit; + int status, i; + int func = data->info->func[page]; + + + stat->notifs = 0; + stat->errors = 0; + + for (i = 0; i < ARRAY_SIZE(pmbus_regulator_flag_map); i++) { + cat = &pmbus_regulator_flag_map[i]; + if (!(func & cat->func)) + continue; + + status = _pmbus_read_byte_data(client, page, cat->reg); + if (status < 0) { + mutex_unlock(&data->update_lock); + return status; + } + + for (bit = cat->bits; bit->pflag; bit++) { + if (status & bit->pflag) { + stat->notifs |= bit->eflags; + stat->errors |= bit->rflag; + } + } + } + + return 0; +} + +static int pmbus_fault_handler(int irq, struct regulator_irq_data *rid, unsigned long *dev_mask) +{ + struct regulator_err_state *stat; + struct pmbus_data *data; + struct device *dev; + struct i2c_client *client; + int status; + u8 page; + int i; + int ret = REGULATOR_ERROR_CLEARED; + + *dev_mask = 0; + rid->opaque = 0; + + for (i = 0; i < rid->num_states; i++) { + stat = &rid->states[i]; + dev = rdev_get_dev(stat->rdev); + client = to_i2c_client(dev->parent); + data = i2c_get_clientdata(client); + page = rdev_get_id(stat->rdev); + + mutex_lock(&data->update_lock); + status = pmbus_irq_subhandler(client, stat, dev_mask); + if (status < 0) { + ret = REGULATOR_FAILED_RETRY; + goto unlock; + } + + status = pmbus_read_status_byte(client, page); + if (status < 0) { + ret = REGULATOR_FAILED_RETRY; + goto unlock; + } + + if (status & ~(PB_STATUS_OFF | PB_STATUS_BUSY)) + pmbus_clear_fault_page(client, page); + + } +unlock: + mutex_unlock(&data->update_lock); + return ret; +} + +static int pmbus_regulator_register(struct i2c_client *client, struct pmbus_data *data) +{ + struct device *dev = &client->dev; const struct pmbus_driver_info *info = data->info; const struct pmbus_platform_data *pdata = dev_get_platdata(dev); - struct regulator_dev *rdev; - int i; + const struct pmbus_regulator_status_category *cat; + const struct pmbus_regulator_status_assoc *bit; + int func; + struct regulator_dev **rdevs; + struct regulator_irq_desc pmbus_notif = { + .name = "pmbus-irq", + .map_event = pmbus_fault_handler, + }; + void *irq_helper; + int i, j, err, errs; + u8 mask; + + rdevs = devm_kzalloc(dev, sizeof(*rdevs) * info->num_regulators, GFP_KERNEL); + if (!rdevs) + return -ENOMEM; for (i = 0; i < info->num_regulators; i++) { struct regulator_config config = { }; @@ -3050,18 +3147,52 @@ static int pmbus_regulator_register(struct pmbus_data *data) if (pdata && pdata->reg_init_data) config.init_data = &pdata->reg_init_data[i]; - rdev = devm_regulator_register(dev, &info->reg_desc[i], - &config); - if (IS_ERR(rdev)) - return dev_err_probe(dev, PTR_ERR(rdev), - "Failed to register %s regulator\n", - info->reg_desc[i].name); + rdevs[i] = devm_regulator_register(dev, &info->reg_desc[i], &config); + if (IS_ERR(rdevs[i])) { + dev_err(dev, "Failed to register %s regulator\n", + info->reg_desc[i].name); + return PTR_ERR(rdevs[i]); + } } + if (client->irq > 0) { + pmbus_notif.data = rdevs; + errs = 0; + for (i = 0; i < data->info->pages; i++) { + func = data->info->func[i]; + + for (j = 0; j < ARRAY_SIZE(pmbus_regulator_flag_map); j++) { + cat = &pmbus_regulator_flag_map[i]; + if (!(func & cat->func)) + continue; + mask = 0; + for (bit = cat->bits; bit->pflag; bit++) { + errs |= bit->rflag; + mask |= bit->pflag; + } + err = pmbus_write_smbalert_mask(client, i, cat->reg, ~mask); + if (err) + dev_err(dev, "Failed to set smbalert for reg 0x%02x\n", + cat->reg); + } + + } + + /* Register notifiers - can fail if IRQ is not given */ + irq_helper = devm_regulator_irq_helper(dev, &pmbus_notif, client->irq, 0, errs, + NULL, &rdevs[0], info->num_regulators); + if (IS_ERR(irq_helper)) { + if (PTR_ERR(irq_helper) == -EPROBE_DEFER) { + return -EPROBE_DEFER; + } + dev_warn(dev, "IRQ disabled %pe\n", irq_helper); + } + } + return 0; } #else -static int pmbus_regulator_register(struct pmbus_data *data) +static int pmbus_regulator_register(struct i2c_client *client, struct pmbus_data *data) { return 0; } @@ -3425,7 +3556,7 @@ int pmbus_do_probe(struct i2c_client *client, struct pmbus_driver_info *info) return PTR_ERR(data->hwmon_dev); } - ret = pmbus_regulator_register(data); + ret = pmbus_regulator_register(client, data); if (ret) return ret;