From patchwork Fri Feb 17 08:36:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13144424 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 5961FC636D4 for ; Fri, 17 Feb 2023 08:36:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229649AbjBQIgj (ORCPT ); Fri, 17 Feb 2023 03:36:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjBQIgi (ORCPT ); Fri, 17 Feb 2023 03:36:38 -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 62D685F81D for ; Fri, 17 Feb 2023 00:36:37 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id m21-20020a05600c3b1500b003e1f5f2a29cso399227wms.4 for ; Fri, 17 Feb 2023 00:36:37 -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=srqtCUqvgw2GALgaYCo2FspSe77rX/vhZEfIW9FiLT8=; b=byVuIPTcFkpLgDpfNkmbC59s9wYKMEOsRWzBuy/8JhVlvIlRoxmsqEN29Qos2BtzeX Kmzik88H77yerWniqgNJ9Q8arryN3cuieN50st3vS7M376KlpoE0pUpbj/PQ9YlsdSXk VS5v5eyZuXw6VquCL8BjbiuEWU/7KM1+/vNffLAiM0sFZsiHcW/3Asq3mjWKjuMhcp+V qGXCRUaTt9FOh3vng4E/ZVAHNIOlpoQwokqZt+1AVEkmPpuGaxsGgyPMdGucbH+c1+sk cZwvrmzN/aait1Zh+YpH/h/r3jNUEZVYyMivwtIJYqFnHIlDOdHFFpqaBvmdO+ihMmQA Q2ug== 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=srqtCUqvgw2GALgaYCo2FspSe77rX/vhZEfIW9FiLT8=; b=lHVLaVlQvzdiVcadjYAWo8JJqCT+XkgmVRgpseLJg6JlDpMkkmPMPqrPyis8p8ypV+ RepD1EL3qOGB34Rnr144g/EiSi68LpVPqFYARQYjjS+zThKkNmQJLjwJaQ0eW1UJS75T 92jf6PEMw8ipAaZI549lB5lE7yEXaR0X4o0HfzDObmJfAqA48+jcrVvRBAdPSi/6WO/3 3RsLNmHeYGcjEoL6KCjm4Daie5DUjK6ZZAGaQt5tbTAJDiGRQQf42t/fCdAeeSF+ZzS9 RQdhn6wZLF5hD/jpWm7Tc4ZpeYCwjNpUJneHalhyy2zw9zOwrZ5P1IvO9i1RFZndhBWZ R/jw== X-Gm-Message-State: AO0yUKUk9irIrSQmsd0EnfFLP1ZWwz/FyaRHTCXKDZ2RhY9F1Y5UfuWN oyYHuKldt5UwPYu+apuFgYhp3A== X-Google-Smtp-Source: AK7set/sM0ukjrE0AxBgexM3oWL41CS99tRb7V71vQZIVVyCQR3zGMNFrjjcWJ2up0DWkTNEpMUzJg== X-Received: by 2002:a05:600c:2ac8:b0:3df:eb5d:fbf with SMTP id t8-20020a05600c2ac800b003dfeb5d0fbfmr555659wme.38.1676622995885; Fri, 17 Feb 2023 00:36:35 -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 m17-20020a7bce11000000b003e209b45f6bsm4857021wmc.29.2023.02.17.00.36.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Feb 2023 00:36:35 -0800 (PST) From: Naresh Solanki X-Google-Original-From: Naresh Solanki To: Guenter Roeck , Jean Delvare Cc: linux-hwmon@vger.kernel.org, Naresh Solanki , linux-kernel@vger.kernel.org Subject: [PATCH v3 1/4] hwmon: (pmbus/core): Generalize pmbus status flag map Date: Fri, 17 Feb 2023 09:36:28 +0100 Message-Id: <20230217083631.657430-1-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org The PMBus status flag map(pmbus_regulator_status_flag_map) is moved outside of the regulator #if block and the associated variable/struct name updated to reflect as generic PMBus status. This will make the PMBus status flag map more versatile and easier to incorporate into different contexts and functions. Signed-off-by: Naresh Solanki Reviewed-by: Guenter Roeck --- drivers/hwmon/pmbus/pmbus_core.c | 94 ++++++++++++++++---------------- 1 file changed, 47 insertions(+), 47 deletions(-) base-commit: 5720a18baa4686d56d0a235e6ecbcc55f8d716d7 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 95e95783972a..1b70cf3be313 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -2692,6 +2692,49 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data, return 0; } +/* A PMBus status flag and the corresponding REGULATOR_ERROR_* flag */ +struct pmbus_status_assoc { + int pflag, rflag; +}; + +/* PMBus->regulator bit mappings for a PMBus status register */ +struct pmbus_status_category { + int func; + int reg; + const struct pmbus_status_assoc *bits; /* zero-terminated */ +}; + +static const struct pmbus_status_category __maybe_unused pmbus_status_flag_map[] = { + { + .func = PMBUS_HAVE_STATUS_VOUT, + .reg = PMBUS_STATUS_VOUT, + .bits = (const struct pmbus_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 }, + { }, + }, + }, { + .func = PMBUS_HAVE_STATUS_IOUT, + .reg = PMBUS_STATUS_IOUT, + .bits = (const struct pmbus_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 }, + { }, + }, + }, { + .func = PMBUS_HAVE_STATUS_TEMP, + .reg = PMBUS_STATUS_TEMPERATURE, + .bits = (const struct pmbus_status_assoc[]) { + { PB_TEMP_OT_WARNING, REGULATOR_ERROR_OVER_TEMP_WARN }, + { PB_TEMP_OT_FAULT, REGULATOR_ERROR_OVER_TEMP }, + { }, + }, + }, +}; + #if IS_ENABLED(CONFIG_REGULATOR) static int pmbus_regulator_is_enabled(struct regulator_dev *rdev) { @@ -2738,54 +2781,11 @@ 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 */ -struct pmbus_regulator_status_assoc { - int pflag, rflag; -}; - -/* PMBus->regulator bit mappings for a PMBus status register */ -struct pmbus_regulator_status_category { - int func; - int reg; - const struct pmbus_regulator_status_assoc *bits; /* zero-terminated */ -}; - -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 }, - { }, - }, - }, { - .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 }, - { }, - }, - }, { - .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 }, - { }, - }, - }, -}; - static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned int *flags) { int i, status; - const struct pmbus_regulator_status_category *cat; - const struct pmbus_regulator_status_assoc *bit; + const struct pmbus_status_category *cat; + const struct pmbus_status_assoc *bit; struct device *dev = rdev_get_dev(rdev); struct i2c_client *client = to_i2c_client(dev->parent); struct pmbus_data *data = i2c_get_clientdata(client); @@ -2796,8 +2796,8 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned mutex_lock(&data->update_lock); - for (i = 0; i < ARRAY_SIZE(pmbus_regulator_flag_map); i++) { - cat = &pmbus_regulator_flag_map[i]; + for (i = 0; i < ARRAY_SIZE(pmbus_status_flag_map); i++) { + cat = &pmbus_status_flag_map[i]; if (!(func & cat->func)) continue;