From patchwork Wed Nov 30 16:59:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13060119 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 E8CD7C352A1 for ; Wed, 30 Nov 2022 17:05:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231216AbiK3RFm (ORCPT ); Wed, 30 Nov 2022 12:05:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229575AbiK3RFF (ORCPT ); Wed, 30 Nov 2022 12:05:05 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4156F70628 for ; Wed, 30 Nov 2022 09:00:04 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id c65-20020a1c3544000000b003cfffd00fc0so1924916wma.1 for ; Wed, 30 Nov 2022 09:00:04 -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=xm/vpmwhJgDMht8f1OqkuJQbgIo2XHirTX9u59ErmCw=; b=YRIWNKwOKtKOAVADiQlwkkGbVDhFN7bL0mUA71LmY+JBSjuKhPOxzeLxkgQFb6m3rM Pu60RTcJEOLceyYrS6ugloVBqiNKuUzY5HPYruWg0jSoMi7Z+8TPrT/o2jYkvRB2Tqq0 YTxs3ZIO2YNYJ9UerVamih6zqCzRT5qwSSuWzmrjrQmFsZZ5QC/dseAn1rd36uUQMwCZ qJfIPiQhoxCZJi/9QuxwY9P/847Vm8Xl+6w7qG3z1ZGuapVsXynsTngIbVRtir3LNXyD aG08Js6Ilnmj3PA9PjK6Uh1YNJC7MJP7HQXTCuslXY3ALapPSN/w0qLvLNAGHTMIhDUH IY8w== 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=xm/vpmwhJgDMht8f1OqkuJQbgIo2XHirTX9u59ErmCw=; b=ZsLJPdH4cN85G25BkJSnkatmn99q/t9G+Efjo7Iu5AX34Fn8WBK/QgiVa69FukIW+9 lGc6Kr5t5rrSpf2zVfA2IBqWjxkRqGFyr2PK2oB7JV/LrZHoxfJJPwF5dnL8AaPljZU8 YAjy+o8jivHruLSvxG+W6Jju7+YdTrlBo9zVWEQdngoZZPl11IGVqX22Ly7kzRBaXR5x HCfGOoMEHExl53zv+hA4L1XMetU09mce5B5jli9hXDzeInXBKrRo5H7W1b4FzX0mbALl 3psNlRMVMSKLUJe7i6sp1G2xfxzXzZom1U6ibmBqjjJ0Bidan45lrdsKgtD1Eyv1Dz4B ZsdA== X-Gm-Message-State: ANoB5plscHiX8S3mhl/u15i4v3niKRdAQDpz3PmSMDJZkjE+LwysBYDJ 8MYARnDhNj+O6b8naoV7qrgMhkqjzKalI8aw X-Google-Smtp-Source: AA0mqf7bZVp+Eg6fmULlxyfV3Om/6addnJlUPeBJpAiuNlvTfk1CTvzGSCZBLoPHeRpyKTtf8sNTiA== X-Received: by 2002:a1c:6a04:0:b0:3cf:77cc:5f65 with SMTP id f4-20020a1c6a04000000b003cf77cc5f65mr39421824wmc.25.1669827602880; Wed, 30 Nov 2022 09:00:02 -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 fn7-20020a05600c688700b003c6b70a4d69sm2457159wmb.42.2022.11.30.09.00.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 09:00:02 -0800 (PST) From: Naresh Solanki X-Google-Original-From: Naresh Solanki To: devicetree@vger.kernel.org, Guenter Roeck , Jean Delvare , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, Patrick Rudolph , Naresh Solanki Subject: [PATCH v3 1/4] hwmon: (pmbus/core): Add status byte to regulator flag map Date: Wed, 30 Nov 2022 17:59:51 +0100 Message-Id: <20221130165955.3479143-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 PMBus status byte to regulator flag map. Signed-off-by: Naresh Solanki --- Changes: - Remove status input - Add comment for PMBUS status byte. --- drivers/hwmon/pmbus/pmbus_core.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) base-commit: 9494c53e1389b120ba461899207ac8a3aab2632c diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 95e95783972a..a7b4ae0f1f3b 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -2751,7 +2751,16 @@ struct pmbus_regulator_status_category { }; static const struct pmbus_regulator_status_category pmbus_regulator_flag_map[] = { - { + { /* STATUS byte is always present. */ + .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 }, + { }, + }, + }, { .func = PMBUS_HAVE_STATUS_VOUT, .reg = PMBUS_STATUS_VOUT, .bits = (const struct pmbus_regulator_status_assoc[]) { @@ -2768,6 +2777,7 @@ static const struct pmbus_regulator_status_category pmbus_regulator_flag_map[] = { 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_FAIL }, { }, }, }, { @@ -2834,14 +2844,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 From patchwork Wed Nov 30 16:59:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13060120 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 26130C46467 for ; Wed, 30 Nov 2022 17:05:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231247AbiK3RFr (ORCPT ); Wed, 30 Nov 2022 12:05:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230510AbiK3RFJ (ORCPT ); Wed, 30 Nov 2022 12:05:09 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B1B693A55 for ; Wed, 30 Nov 2022 09:00:10 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id w15so14917200wrl.9 for ; Wed, 30 Nov 2022 09:00:10 -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=LsjaiNcbOnAPHJfNdou87+1m3ymlwlqqUN1bnFhs+to=; b=VXKfm9GT2RJzMcTd5Yh71vxzbz1fYLOCc5qdLGU/SCeTHAiHg5CzxhCRCxz0399dlt d3JBLqRT7mMJnCi/YBGBD+kpG6e5RbkBmbIwgBcerkD4k/EYvS8dDLOOUxWsc40Shup4 cWoUfZsx/kCnGrxvwlMe5Va4xahmmvb+jFI6kDHi8dIUJROqaNGEPoDSOVb8lz/O3hC4 PE6kzym7tFV72p0mrSUnUOINR6+dBO67gi4JSwpRl73a2ZbdXnaoVrvxQqvJXVU/Ux7x 7BJfXerl4jeuIniDS2pDCaUmZippD0w/H8Lh+5ZKTAyA/HN49ic6eX4wQ0nsWaKJO+LK kAOw== 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=LsjaiNcbOnAPHJfNdou87+1m3ymlwlqqUN1bnFhs+to=; b=X5yThsUafzsgdJkDhjJ1FLHKWkm2MQUr59MSYWWd6bUWghXq4ipnJJTiGQtRKwyHNz ug0wBqQVmt7+c3nsNpTrhqPsb523xJUpIq5EACRu0nbuMkn4pv4nXoQw0L/nEqeizH5u bPyJysH+AOP9ZngYNx5PUn5h1Rn7k7KeL/A5S7MUUdMErw5FwqZz+eJ9y7DavaCocIME Enuq70lDrd/enDHQbfZt99yEOgFE16albLUtkvg9OxRwZSR8IUjRn/P7frjVlQRpSxHU AWmemFnaLNMUUf8vlQ45uYpddUTOkQ/kjFQcX6yPUkfCvBztfyW++cP5w3kaqQfO93uO M00A== X-Gm-Message-State: ANoB5pmKTZYHiUWdSRjTsTV/TR8JsZcwdTgYMeslzEuu/xFbCzIs+Ja7 glAdx3bBRp5S3k6MSIQkRZT3Wg== X-Google-Smtp-Source: AA0mqf7hsbed8fdlaMvutAG6fj2UMzC3RSLVjvhGTrpz0IR6PizokXEPfp6sm+wqMEEvQu+J75wIJw== X-Received: by 2002:a05:6000:70f:b0:22e:41c5:7ef7 with SMTP id bs15-20020a056000070f00b0022e41c57ef7mr1079565wrb.332.1669827609089; Wed, 30 Nov 2022 09:00:09 -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 fn7-20020a05600c688700b003c6b70a4d69sm2457159wmb.42.2022.11.30.09.00.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 09:00:08 -0800 (PST) From: Naresh Solanki X-Google-Original-From: Naresh Solanki To: devicetree@vger.kernel.org, Guenter Roeck , Jean Delvare , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, Patrick Rudolph , Naresh Solanki Subject: [PATCH v3 2/4] hwmon: (pmbus/core): Add events to regulator flag map Date: Wed, 30 Nov 2022 17:59:52 +0100 Message-Id: <20221130165955.3479143-2-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221130165955.3479143-1-Naresh.Solanki@9elements.com> References: <20221130165955.3479143-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 | 43 +++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index a7b4ae0f1f3b..9a9e380acc23 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,37 +2755,50 @@ static const struct pmbus_regulator_status_category pmbus_regulator_flag_map[] = .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_IOUT_OC, REGULATOR_ERROR_OVER_CURRENT, + REGULATOR_EVENT_OVER_CURRENT }, + { PB_STATUS_VOUT_OV, REGULATOR_ERROR_REGULATION_OUT, + REGULATOR_EVENT_OVER_VOLTAGE_WARN }, + { PB_STATUS_VIN_UV, REGULATOR_ERROR_UNDER_VOLTAGE, + REGULATOR_EVENT_UNDER_VOLTAGE }, { }, }, }, { .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_FAIL }, + { 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_FAIL, + REGULATOR_EVENT_FAIL }, { }, }, }, { .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 }, { }, }, }, From patchwork Wed Nov 30 16:59:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13060121 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 4F89DC46467 for ; Wed, 30 Nov 2022 17:05:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231180AbiK3RFx (ORCPT ); Wed, 30 Nov 2022 12:05:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231132AbiK3RFN (ORCPT ); Wed, 30 Nov 2022 12:05:13 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9907C98963 for ; Wed, 30 Nov 2022 09:00:13 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id v1so28090523wrt.11 for ; Wed, 30 Nov 2022 09:00: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=5CXiZlD2TyqZ7MaMRJu4QFyk6ysF3bJp4l380A/oYl4=; b=Vk1g9N5MtEmS/1qfopQRw1TNtmQiSTBfJ2vUuBLKjdXeRtVwEkWZ2h/9BTjFu5E8er 4mGUak187PqBT9S8JdjxDQocH+rUGaX33U9iHJwnYPU6teL17Y/B2jQqQPbip0TqWZMC DJ741gVu3bdXB+579W6oYTkP2crp+51EerD2N76DvHGh/gTVkZzPu+qICcOVF3ZlzneR CmRWcanxe527GsstQ7KMfwhguIceygpMTHTDXGIKuIFUc5jTqNj5EIk9PclOuVGIt1D4 cFu+n3rcUbN+gW7J4uKh0oxLUtL3R0oyk42dRNSkWxKyudKHu4Qr+x6JSEI2Muqsvlue gsEQ== 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=5CXiZlD2TyqZ7MaMRJu4QFyk6ysF3bJp4l380A/oYl4=; b=yQqz9RVfPcafaAE9SNFGmVdle3cdRv66OwGQ1BCO3FYZgspC/hIidtR9hR36EnZV3L ZNH0KVPCxn9j7tx4K6+sz4DENr3ULYe+9RxIoURRtChVIsWUA0UbQp3MW6+KhZMSds7m fxzYdfcbAGz/IwR5opROUXHedMGbE0X0aW0xEEOKUm2uomVpA0vm/MGOvqDocDre8Ut5 Vj/loDMlVj1VISK5Jm4AEGD0Y3wSNCgOTefo636oKoWdfAwY5BxW1fftGTa+Nu+JuKhn c/oz6dMCV2u7+eqahw5MBh3HhlvH6Y8RJeAuY9/Avu6vaTdDM6wQ1FdzMSFOIt5fI5Xj eb3w== X-Gm-Message-State: ANoB5pkenXyTUtMY0gcvgBOsnpWiFcxurjGsad49U9+V5KXHkrMHg68Z 16tar2VSmyHGoEGOA81v/YTwGQ== X-Google-Smtp-Source: AA0mqf6MtutqlORB9kMF0rRztaLSnkRJQR8hPZejiVjN0pQBkWHRcZUsCEHk3U4XHaNur/0oczfL/Q== X-Received: by 2002:adf:9b84:0:b0:242:2f5d:e27f with SMTP id d4-20020adf9b84000000b002422f5de27fmr2029177wrc.54.1669827612102; Wed, 30 Nov 2022 09:00: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 fn7-20020a05600c688700b003c6b70a4d69sm2457159wmb.42.2022.11.30.09.00.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 09:00:11 -0800 (PST) From: Naresh Solanki X-Google-Original-From: Naresh Solanki To: devicetree@vger.kernel.org, Guenter Roeck , Jean Delvare , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, Patrick Rudolph , Naresh Solanki Subject: [PATCH v3 3/4] hwmon: (pmbus/core): Implement irq support Date: Wed, 30 Nov 2022 17:59:53 +0100 Message-Id: <20221130165955.3479143-3-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221130165955.3479143-1-Naresh.Solanki@9elements.com> References: <20221130165955.3479143-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 PMBUS irq handler to notify regulator events. Signed-off-by: Patrick Rudolph Signed-off-by: Naresh Solanki --- drivers/hwmon/pmbus/pmbus.h | 2 +- drivers/hwmon/pmbus/pmbus_core.c | 151 ++++++++++++++++++++++++++++--- 2 files changed, 137 insertions(+), 16 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 9a9e380acc23..613e2e484a0f 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -81,6 +81,7 @@ struct pmbus_label { struct pmbus_data { struct device *dev; struct device *hwmon_dev; + struct regulator_dev **rdevs; u32 flags; /* from platform data */ @@ -2804,7 +2805,8 @@ static const struct pmbus_regulator_status_category pmbus_regulator_flag_map[] = }, }; -static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned int *flags) +static int pmbus_regulator_get_flags(struct regulator_dev *rdev, unsigned int *error, + unsigned int *event) { int i, status; const struct pmbus_regulator_status_category *cat; @@ -2815,7 +2817,8 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned u8 page = rdev_get_id(rdev); int func = data->info->func[page]; - *flags = 0; + *error = 0; + *event = 0; mutex_lock(&data->update_lock); @@ -2831,8 +2834,10 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned } for (bit = cat->bits; bit->pflag; bit++) { - if (status & bit->pflag) - *flags |= bit->rflag; + if (status & bit->pflag) { + *error |= bit->rflag; + *event |= bit->eflag; + } } } @@ -2851,11 +2856,15 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned return status; if (pmbus_regulator_is_enabled(rdev)) { - if (status & PB_STATUS_OFF) - *flags |= REGULATOR_ERROR_FAIL; + if (status & PB_STATUS_OFF) { + *error |= REGULATOR_ERROR_FAIL; + *event |= REGULATOR_EVENT_FAIL; + } - if (status & PB_STATUS_POWER_GOOD_N) - *flags |= REGULATOR_ERROR_REGULATION_OUT; + if (status & PB_STATUS_POWER_GOOD_N) { + *error |= REGULATOR_ERROR_REGULATION_OUT; + *event |= REGULATOR_EVENT_REGULATION_OUT; + } } /* @@ -2863,13 +2872,22 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned * 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; + if (!(*error & (REGULATOR_ERROR_OVER_TEMP | REGULATOR_ERROR_OVER_TEMP_WARN)) && + (status & PB_STATUS_TEMPERATURE)) { + *error |= REGULATOR_ERROR_OVER_TEMP_WARN; + *event |= REGULATOR_EVENT_OVER_TEMP_WARN; + } return 0; } +static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned int *flags) +{ + unsigned int event; + + return pmbus_regulator_get_flags(rdev, flags, &event); +} + static int pmbus_regulator_get_status(struct regulator_dev *rdev) { struct device *dev = rdev_get_dev(rdev); @@ -3060,14 +3078,61 @@ const struct regulator_ops pmbus_regulator_ops = { }; EXPORT_SYMBOL_NS_GPL(pmbus_regulator_ops, PMBUS); +static int pmbus_write_smbalert_mask(struct i2c_client *client, u8 page, u8 reg, u8 val) +{ + return pmbus_write_word_data(client, page, PMBUS_SMBALERT_MASK, reg | (val << 8)); +} + +static irqreturn_t pmbus_fault_handler(int irq, void *pdata) +{ + struct pmbus_data *data = pdata; + struct i2c_client *client = to_i2c_client(data->dev); + int i, ret = IRQ_NONE, status, event; + u8 page; + + for (i = 0; i < data->info->num_regulators; i++) { + + if (!data->rdevs[i]) + continue; + + ret = pmbus_regulator_get_flags(data->rdevs[i], &status, &event); + if (ret) + return ret; + + if (event) { + regulator_notifier_call_chain(data->rdevs[i], event, NULL); + ret = IRQ_HANDLED; + } + + page = rdev_get_id(data->rdevs[i]); + mutex_lock(&data->update_lock); + status = pmbus_read_status_word(client, page); + if (status < 0) { + mutex_unlock(&data->update_lock); + return status; + } + + if (status & ~(PB_STATUS_OFF | PB_STATUS_BUSY | PB_STATUS_POWER_GOOD_N)) + pmbus_clear_fault_page(client, page); + + mutex_unlock(&data->update_lock); + } + + return ret; +} + static int pmbus_regulator_register(struct pmbus_data *data) { struct device *dev = data->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; + data->rdevs = devm_kzalloc(dev, sizeof(struct regulator_dev *) * info->num_regulators, + GFP_KERNEL); + if (!data->rdevs) + return -ENOMEM; + for (i = 0; i < info->num_regulators; i++) { struct regulator_config config = { }; @@ -3077,21 +3142,71 @@ 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], + data->rdevs[i] = devm_regulator_register(dev, &info->reg_desc[i], &config); - if (IS_ERR(rdev)) - return dev_err_probe(dev, PTR_ERR(rdev), + if (IS_ERR(data->rdevs[i])) + return dev_err_probe(dev, PTR_ERR(data->rdevs[i]), "Failed to register %s regulator\n", info->reg_desc[i].name); } return 0; } + +static int pmbus_irq_setup(struct i2c_client *client, struct pmbus_data *data) +{ + struct device *dev = &client->dev; + const struct pmbus_regulator_status_category *cat; + const struct pmbus_regulator_status_assoc *bit; + int i, j, err, ret; + u8 mask; + int func; + + 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++) + 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); + } + + pmbus_write_smbalert_mask(client, i, PMBUS_STATUS_CML, 0xff); + pmbus_write_smbalert_mask(client, i, PMBUS_STATUS_OTHER, 0xff); + pmbus_write_smbalert_mask(client, i, PMBUS_STATUS_MFR_SPECIFIC, 0xff); + if (data->info->func[i] & PMBUS_HAVE_FAN12) + pmbus_write_smbalert_mask(client, i, PMBUS_STATUS_FAN_12, 0xff); + if (data->info->func[i] & PMBUS_HAVE_FAN34) + pmbus_write_smbalert_mask(client, i, PMBUS_STATUS_FAN_34, 0xff); + + } + + /* Register notifiers - can fail if IRQ is not given */ + ret = devm_request_threaded_irq(dev, client->irq, NULL, pmbus_fault_handler, + 0, "pmbus-irq", data); + if (ret) { + dev_warn(dev, "IRQ disabled %d\n", ret); + return ret; + } + + return 0; +} #else static int pmbus_regulator_register(struct pmbus_data *data) { return 0; } +static int pmbus_irq_setup(struct i2c_client *client, struct pmbus_data *data) +{ + return 0; +} #endif static struct dentry *pmbus_debugfs_dir; /* pmbus debugfs directory */ @@ -3456,6 +3571,12 @@ int pmbus_do_probe(struct i2c_client *client, struct pmbus_driver_info *info) if (ret) return ret; + if (client->irq > 0) { + ret = pmbus_irq_setup(client, data); + if (ret) + return ret; + } + ret = pmbus_init_debugfs(client, data); if (ret) dev_warn(dev, "Failed to register debugfs\n"); From patchwork Wed Nov 30 16:59:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13060122 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 4E374C352A1 for ; Wed, 30 Nov 2022 17:06:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231271AbiK3RF7 (ORCPT ); Wed, 30 Nov 2022 12:05:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231195AbiK3RFR (ORCPT ); Wed, 30 Nov 2022 12:05:17 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D80659894A for ; Wed, 30 Nov 2022 09:00:15 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id ay14-20020a05600c1e0e00b003cf6ab34b61so1915961wmb.2 for ; Wed, 30 Nov 2022 09:00:15 -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=ADo04tg+16fhlHcXEalyoHswqSIikOudDCDm6c2e17k=; b=NKu8S/HWybo5iLmhXLOZ4iQ/6NF9zExmhhZ1XuHdPAD/XvPsE3cuPkUcIXqhhFqoOs OoEcvaa3CZvsbEkiSDX7yopx8HyxBwO+ItxHGrrTl8bUJGSvt8/Db73li2ej+DNKGafy n5mrkCQlx23Nt4KWd8WppTeaPRO/VMy93SeqNgQp5WYIGrKwXvHm2lZoN8JLuJ74QwYV ZtRToEQ+QCegU3LS+1Q29y7fAY8nphbWSnatkHvqR9YCIBSM3ig37Hn2uA1RvMziG+sb Gp9lO+F4CoNkX+tIMhHY7XpmUawd5os3UzmsnnCHsLACgg4whAxz6KJwh5aB2j+NH3jo R0vA== 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=ADo04tg+16fhlHcXEalyoHswqSIikOudDCDm6c2e17k=; b=rat8ANyU3wwXlbPVy2EPWaZCRUk2LAL/1VQRaDkjCMb8vBsyDFz1s00F6YxRS279Af j19xoGhqhQeV8mdoownqPgIFzC480cJWtlcGCDK6f7mo2weWr0L4xjNz226ThY1PUGQG HucbMg3vZE9CB4mecXvGwM+BLUwL/U9Y75xExZJWrUQixnF1x0JqH4aSxOyoCyIjKx5o 2ZRgJl0XZAqSykiem+ZCQign4JCIwGQLI1cfkO7OOPxtOrl6bryw2F3l/SlosGnYNn19 H67YHyvFhC+ylG85xNTPs93Tr++osuP/ROMPUCUopy9Ja/4e5qBNiJ5t0LQsnwuHYPUc qUfg== X-Gm-Message-State: ANoB5pnx2HUJ7jRgBQsZP37KTEMe3fLJgj5ZPukRQyufOPzVjUiWC0RO 5DkF9uN/BjyWp6XVHW8p0S0p2A== X-Google-Smtp-Source: AA0mqf6dFEgTtxymKQ/eqI2nEtCILDoCpgb5WmUZJlpi5KtpxCXvj3P5gCntwYjpnOaQ2dqKxyBMDw== X-Received: by 2002:a05:600c:1e25:b0:3d0:31c9:1d77 with SMTP id ay37-20020a05600c1e2500b003d031c91d77mr29100295wmb.113.1669827614406; Wed, 30 Nov 2022 09:00:14 -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 fn7-20020a05600c688700b003c6b70a4d69sm2457159wmb.42.2022.11.30.09.00.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 09:00:14 -0800 (PST) From: Naresh Solanki X-Google-Original-From: Naresh Solanki To: devicetree@vger.kernel.org, Guenter Roeck , Jean Delvare , Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, Patrick Rudolph , Naresh Solanki Subject: [PATCH v3 4/4] hwmon: (pmbus/core): Notify hwmon events Date: Wed, 30 Nov 2022 17:59:54 +0100 Message-Id: <20221130165955.3479143-4-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221130165955.3479143-1-Naresh.Solanki@9elements.com> References: <20221130165955.3479143-1-Naresh.Solanki@9elements.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Notify hwmon events using the pmbus irq handler. Signed-off-by: Naresh Solanki --- drivers/hwmon/pmbus/pmbus_core.c | 37 +++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 613e2e484a0f..da92a08484c9 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -2805,8 +2805,36 @@ static const struct pmbus_regulator_status_category pmbus_regulator_flag_map[] = }, }; +#define to_dev_attr(_dev_attr) \ + container_of(_dev_attr, struct device_attribute, attr) + +static void pmbus_notify(struct pmbus_data *data, int page, int reg, int flags) +{ + int i; + + for (i = 0; i < data->num_attributes; i++) { + struct device_attribute *da = to_dev_attr(data->group.attrs[i]); + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + int index = attr->index; + u16 smask = pb_index_to_mask(index); + u8 spage = pb_index_to_page(index); + u16 sreg = pb_index_to_reg(index); + + if (reg == sreg && page == spage && (smask & flags)) { + dev_dbg(data->dev, "sysfs notify: %s", da->attr.name); + sysfs_notify(&data->dev->kobj, NULL, da->attr.name); + kobject_uevent(&data->dev->kobj, KOBJ_CHANGE); + } + + flags &= ~smask; + + if (!flags) + break; + } +} + static int pmbus_regulator_get_flags(struct regulator_dev *rdev, unsigned int *error, - unsigned int *event) + unsigned int *event, bool notify) { int i, status; const struct pmbus_regulator_status_category *cat; @@ -2833,6 +2861,9 @@ static int pmbus_regulator_get_flags(struct regulator_dev *rdev, unsigned int *e return status; } + if (notify && status) + pmbus_notify(data, page, cat->reg, status); + for (bit = cat->bits; bit->pflag; bit++) { if (status & bit->pflag) { *error |= bit->rflag; @@ -2885,7 +2916,7 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned { unsigned int event; - return pmbus_regulator_get_flags(rdev, flags, &event); + return pmbus_regulator_get_flags(rdev, flags, &event, false); } static int pmbus_regulator_get_status(struct regulator_dev *rdev) @@ -3095,7 +3126,7 @@ static irqreturn_t pmbus_fault_handler(int irq, void *pdata) if (!data->rdevs[i]) continue; - ret = pmbus_regulator_get_flags(data->rdevs[i], &status, &event); + ret = pmbus_regulator_get_flags(data->rdevs[i], &status, &event, true); if (ret) return ret;