From patchwork Wed Mar 1 16:44:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13156232 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 DC3D5C7EE2F for ; Wed, 1 Mar 2023 16:44:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229811AbjCAQo5 (ORCPT ); Wed, 1 Mar 2023 11:44:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229701AbjCAQo4 (ORCPT ); Wed, 1 Mar 2023 11:44:56 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5E083525C for ; Wed, 1 Mar 2023 08:44:54 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id fm20-20020a05600c0c1400b003ead37e6588so12308478wmb.5 for ; Wed, 01 Mar 2023 08:44:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1677689093; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=80hkLcYMepouVtWKST/uM+1yiDynZV+Ko2dpZLCgqAc=; b=P4o1reCqD/QGWTNLgr5aZA4KP3C1RxTCuVRypmk4rJ6L+WA/F7z2VtoVFYdVEGG8cq 3xtCDrs/239g2eRhN95noCAQE+U4qAmwYBaI8GuxDsitIoQjjh/rIOMnl106DEfmX5Zs fXfScTG6mTLTriXZdrEURjdpeLRC1Qxxr3wb8abEyhAQhlp3rB2qf0tNyDnb7bUiGv/t 7eliZDk81qrg9H7ZHA1StlN4tPe/xbc+XvIsuVmvOG7swcdEgd+vu4wtphEDSA4YwqWD lRdMGhfy0raeFgSiLJBVyPy39e0lneBO5giYt+CvtpkjuAX1mfCKR4nc1tZtKcGB8QBA p/KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677689093; 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=80hkLcYMepouVtWKST/uM+1yiDynZV+Ko2dpZLCgqAc=; b=J/U0va2gx75CsAoIbgi2eV55W5x8GUjG9PxfD0ecaCQtRLY3XRuxNCfZMnsOcw3R/O gc69MlAXI+ruxqLubJ7srNG9EpJe4NJnv6Wz/lTsEVCHnPAXGuSgqGD1LKi+ZV2dDuro o5taUO4ipCprJuMKZIyxPTbPJNY2gT1fJmhCOjcMRlMU2Xf9aSLMhkS526UMf8q7UqK/ z551L+57fstsg2O34tbYKs4QOI2cwaKPm25tP71TGfyuVINw6J32thQ7zH+Pp2N8Nc+s sBGYopOFnctswFOY7pxysnwbkX5OZWjQdSap2dGAf116FDg0mPQApIT/V+TfqFUNGgGL +Xtg== X-Gm-Message-State: AO0yUKVoSY1Zxi45zsa+PWOY78rL3sR7jZE3/qxTpCMFlgyFQuH2+zjW 963/0idZVJ1t3D9DMM2KDabYYIT/LsTZMhq6wg8= X-Google-Smtp-Source: AK7set8+pWabP/pAl34UHxmLrR3scR40Q1mWUU11baHLjRK8iCBbCw7sdvcoOhKrmMV3bLQDO3dFQg== X-Received: by 2002:a05:600c:329a:b0:3db:5f1:53a5 with SMTP id t26-20020a05600c329a00b003db05f153a5mr6083636wmp.20.1677689093355; Wed, 01 Mar 2023 08:44:53 -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 p8-20020a7bcde8000000b003dc521f336esm105542wmj.14.2023.03.01.08.44.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 08:44:53 -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 v4 1/4] hwmon: (pmbus/core): Generalize pmbus status flag map Date: Wed, 1 Mar 2023 17:44:31 +0100 Message-Id: <20230301164434.1928237-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: 58326709e8f8122df46d29981eb39896d600c7c4 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;