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; From patchwork Fri Feb 17 08:36:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13144425 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 2817CC64ED6 for ; Fri, 17 Feb 2023 08:36:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229582AbjBQIgm (ORCPT ); Fri, 17 Feb 2023 03:36:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbjBQIgk (ORCPT ); Fri, 17 Feb 2023 03:36:40 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A4865F266 for ; Fri, 17 Feb 2023 00:36:39 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id z12-20020a1c4c0c000000b003e21e018039so1866556wmf.3 for ; Fri, 17 Feb 2023 00:36:38 -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=f9x9Bw7Cfb1MO2yxRY3rlgzAgrMsHxUH6aVXxHJBG4I=; b=RKMUw8bEv+N9zoBaIRUPJxC2+B7mvvUUElvmGO9BwKSqfNAHcmmKKJWgpxZake5CFa Qlz0EdMYPQz0WGWJDRpre6e9Xe/LaqS12Ny4QarlV6b6VqSDq7pKFiIvE0jroiMdBob9 vC1riBvvCj8huJdFuDs6yvdkVKa20kTi0+FStksi8jdVWGsxfmsom6xSEcKC7SdmkEh/ 871+DkZtHMLUSiHiFFW0J+Yp5S0mntRH5xDZGTX86/WQAOrifUCWNdd0ABIjLiLHkSQs 2wwYwaRLB4B0dDGzP230ThOKa0RocZnyKW9h0BPpJB0IWWdcXG7v24vQ4rGg5unKWxdU QGxQ== 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=f9x9Bw7Cfb1MO2yxRY3rlgzAgrMsHxUH6aVXxHJBG4I=; b=dohFZiCi6gg86iEgioEfgX5NNM4BY7sN+mgAwvNiIUlh0ROSFV8EBdjbWRDBSQq66x v/NqX977C8DgtyRDvduQ+QEIGKzmfPBtCudl9XcxJINPHWpiQEsY1SI0xX45BuflZCY1 RanDJDE0Q/eBsahoIhHOzqrj60HdMc0NDo5a2J+VaB0/+qjgThgd2UlNisVOAAjXsRwk HVjXki/2xcR6KCYtJsYwjOerhHWixzPY9lNbObxcp2LD1N9D7JFzQhXGbmuwt8YyaLB5 RYfM4jJ2/G3WJbJ34BoZYeURXtNtH4q5K0va7XZ9gs3bRpfFW9JKuW+cGv8ZQPW+KUuq 856A== X-Gm-Message-State: AO0yUKV90OsyszX4RyaXJeOEylpiDYfPj+zugkgtpIHgz8is6WXJmMq7 gli3wocbDX1awPkSLbFnTCeqxQ== X-Google-Smtp-Source: AK7set8+Uw+69X6sqPJNV7Ppn5UPk4jhXokv0xfSnZNHTDC6z1wdhsUG7O7uSbgGyVOb/k1YLfCIHw== X-Received: by 2002:a05:600c:1652:b0:3e0:ffd4:bfb2 with SMTP id o18-20020a05600c165200b003e0ffd4bfb2mr6959699wmn.4.1676622997430; Fri, 17 Feb 2023 00:36:37 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Feb 2023 00:36:37 -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 2/4] hwmon: (pmbus/core) Generalise pmbus get status Date: Fri, 17 Feb 2023 09:36:29 +0100 Message-Id: <20230217083631.657430-2-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230217083631.657430-1-Naresh.Solanki@9elements.com> References: <20230217083631.657430-1-Naresh.Solanki@9elements.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add function pmbus get status that can be used to get both pmbus specific status & regulator status Signed-off-by: Naresh Solanki ... Changes in V3: - Add pmbus_is_enabled function Changes in V2: - Add __maybe attribute for pmbus_get_status function - Remove unrelated changes Reviewed-by: Guenter Roeck --- drivers/hwmon/pmbus/pmbus_core.c | 98 ++++++++++++++++++++------------ 1 file changed, 62 insertions(+), 36 deletions(-) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 1b70cf3be313..f8ac9016ea0e 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -2735,18 +2735,12 @@ static const struct pmbus_status_category __maybe_unused pmbus_status_flag_map[] }, }; -#if IS_ENABLED(CONFIG_REGULATOR) -static int pmbus_regulator_is_enabled(struct regulator_dev *rdev) +static int _pmbus_is_enabled(struct device *dev, u8 page) { - struct device *dev = rdev_get_dev(rdev); struct i2c_client *client = to_i2c_client(dev->parent); - struct pmbus_data *data = i2c_get_clientdata(client); - u8 page = rdev_get_id(rdev); int ret; - mutex_lock(&data->update_lock); ret = _pmbus_read_byte_data(client, page, PMBUS_OPERATION); - mutex_unlock(&data->update_lock); if (ret < 0) return ret; @@ -2754,58 +2748,38 @@ static int pmbus_regulator_is_enabled(struct regulator_dev *rdev) return !!(ret & PB_OPERATION_CONTROL_ON); } -static int _pmbus_regulator_on_off(struct regulator_dev *rdev, bool enable) +static int __maybe_unused pmbus_is_enabled(struct device *dev, u8 page) { - struct device *dev = rdev_get_dev(rdev); struct i2c_client *client = to_i2c_client(dev->parent); struct pmbus_data *data = i2c_get_clientdata(client); - u8 page = rdev_get_id(rdev); int ret; mutex_lock(&data->update_lock); - ret = pmbus_update_byte_data(client, page, PMBUS_OPERATION, - PB_OPERATION_CONTROL_ON, - enable ? PB_OPERATION_CONTROL_ON : 0); + ret = _pmbus_is_enabled(dev, page); mutex_unlock(&data->update_lock); - return ret; -} - -static int pmbus_regulator_enable(struct regulator_dev *rdev) -{ - return _pmbus_regulator_on_off(rdev, 1); -} - -static int pmbus_regulator_disable(struct regulator_dev *rdev) -{ - return _pmbus_regulator_on_off(rdev, 0); + return !!(ret & PB_OPERATION_CONTROL_ON); } -static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned int *flags) +static int _pmbus_get_flags(struct pmbus_data *data, u8 page, unsigned int *flags) { int i, status; 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); - u8 page = rdev_get_id(rdev); + struct device *dev = data->dev; + struct i2c_client *client = to_i2c_client(dev); int func = data->info->func[page]; *flags = 0; - mutex_lock(&data->update_lock); - for (i = 0; i < ARRAY_SIZE(pmbus_status_flag_map); i++) { cat = &pmbus_status_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); + if (status < 0) return status; - } for (bit = cat->bits; bit->pflag; bit++) { if (status & bit->pflag) @@ -2823,11 +2797,10 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned * REGULATOR_ERROR__WARN. */ status = pmbus_get_status(client, page, PMBUS_STATUS_WORD); - mutex_unlock(&data->update_lock); if (status < 0) return status; - if (pmbus_regulator_is_enabled(rdev)) { + if (_pmbus_is_enabled(dev, page)) { if (status & PB_STATUS_OFF) *flags |= REGULATOR_ERROR_FAIL; @@ -2855,6 +2828,59 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned return 0; } +static int __maybe_unused pmbus_get_flags(struct pmbus_data *data, u8 page, unsigned int *flags) +{ + int ret; + + mutex_lock(&data->update_lock); + ret = _pmbus_get_flags(data, page, flags); + mutex_unlock(&data->update_lock); + + return ret; +} + +#if IS_ENABLED(CONFIG_REGULATOR) +static int pmbus_regulator_is_enabled(struct regulator_dev *rdev) +{ + return pmbus_is_enabled(rdev_get_dev(rdev), rdev_get_id(rdev)); +} + +static int _pmbus_regulator_on_off(struct regulator_dev *rdev, bool enable) +{ + struct device *dev = rdev_get_dev(rdev); + struct i2c_client *client = to_i2c_client(dev->parent); + struct pmbus_data *data = i2c_get_clientdata(client); + u8 page = rdev_get_id(rdev); + int ret; + + mutex_lock(&data->update_lock); + ret = pmbus_update_byte_data(client, page, PMBUS_OPERATION, + PB_OPERATION_CONTROL_ON, + enable ? PB_OPERATION_CONTROL_ON : 0); + mutex_unlock(&data->update_lock); + + return ret; +} + +static int pmbus_regulator_enable(struct regulator_dev *rdev) +{ + return _pmbus_regulator_on_off(rdev, 1); +} + +static int pmbus_regulator_disable(struct regulator_dev *rdev) +{ + return _pmbus_regulator_on_off(rdev, 0); +} + +static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned int *flags) +{ + struct device *dev = rdev_get_dev(rdev); + struct i2c_client *client = to_i2c_client(dev->parent); + struct pmbus_data *data = i2c_get_clientdata(client); + + return pmbus_get_flags(data, rdev_get_id(rdev), flags); +} + static int pmbus_regulator_get_status(struct regulator_dev *rdev) { struct device *dev = rdev_get_dev(rdev); From patchwork Fri Feb 17 08:36:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13144426 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 7E207C05027 for ; Fri, 17 Feb 2023 08:36:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229601AbjBQIgn (ORCPT ); Fri, 17 Feb 2023 03:36:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229711AbjBQIgl (ORCPT ); Fri, 17 Feb 2023 03:36:41 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F15475F26A for ; Fri, 17 Feb 2023 00:36:39 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id bg22-20020a05600c3c9600b003dff4480a17so382255wmb.1 for ; Fri, 17 Feb 2023 00:36:39 -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=DY82imEcfFicloUzMXV5t4stt323TuRafcAwVY/x37M=; b=L0EFWAsmTPDVvIQcwiHJCxJPyIxytL4c/GZkFpD8l3FyYHZUcoEVGuKMIiut3shir4 AQyHaFSzCekMWjr9i0vIEs2NKBeApGsuj56vsLHqxlEY4/TtlURRtcWWOqZ+w1Q/DG3Y tZwOcKY4pV66PSfdyD0uc8hVuScivFEN7HHy8LyRQ7+FJ5m5K9xUyTLLiCujcPi7Z7Cm TY1UffdUpqP7pmxr2+sCfr2JyRw1SlC/bSzEJBkfv41UH47PlglBklT6KQRELAtZ/R7D 9kD/+bVoH02D9kphl8JPh4dWYsAwX4TUY/xSX328aEPQ6txcWZ8bBkJg5lw8gCZf9HJz 7qGQ== 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=DY82imEcfFicloUzMXV5t4stt323TuRafcAwVY/x37M=; b=HtOz/PsRPwOzueute44BboSaZRr2U63IjeoCn6n56fze78Bqf2/phWJN0q6jXcHnpH 9G2/F4etNIWCEbpG7heDEst9RRMbs6cc9KSfwKNpFbYv8OY68sz8feRUaN6abXlGDsRy 9pP3ElafIi/bj9FDwCrJzvrRXdOCSoHWLoH3+5iW4TPkVXJF78vvOwF32J7vhf18DRhH nksDnEHw7dGsHkLDLShnBXmSXHFk/pC9aQbAJPKCwPEN266461PQYcfc+LByA5+Z9692 Uts68JuivWyz9hZTQ56LiOwvK1gbq9qQPHGMBqSNOUbnr7ixjxuk0rblyp7sOagfItBo 6S+w== X-Gm-Message-State: AO0yUKUD9ViIIseG37CiFhbZt8wRbijSYVpi9HN6nxgUsJUBh1xTS4Qc Gx7QqiNGDLfkcDqCsgfNSehArA== X-Google-Smtp-Source: AK7set+FbOSuRt29gKRaJ94HI9bbq3cnCFhAIga+tGHofviVqV6kC9S4UvDKZ+w/oFpxJ6fGCjs77Q== X-Received: by 2002:a05:600c:a692:b0:3db:2858:db84 with SMTP id ip18-20020a05600ca69200b003db2858db84mr98499wmb.34.1676622998462; Fri, 17 Feb 2023 00:36:38 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Feb 2023 00:36:38 -0800 (PST) From: Naresh Solanki X-Google-Original-From: Naresh Solanki To: Guenter Roeck , Jean Delvare Cc: linux-hwmon@vger.kernel.org, Patrick Rudolph , Naresh Solanki , linux-kernel@vger.kernel.org Subject: [PATCH v3 3/4] hwmon: (pmbus/core): Add interrupt support Date: Fri, 17 Feb 2023 09:36:30 +0100 Message-Id: <20230217083631.657430-3-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230217083631.657430-1-Naresh.Solanki@9elements.com> References: <20230217083631.657430-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. Signed-off-by: Patrick Rudolph Signed-off-by: Naresh Solanki ... Changes in V3: - Remove pmbus word check for SMBALERT writes - Remove variable ret & use err instead. - Use dev_dbg_once instead of error. - Remove error print when writing to misc_status register. - Move client irq check to pmbus_irq_setup. --- drivers/hwmon/pmbus/pmbus.h | 2 +- drivers/hwmon/pmbus/pmbus_core.c | 78 ++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h index 713ea7915425..11e84e141126 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 f8ac9016ea0e..d0415d5ac7d9 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -3105,6 +3105,80 @@ static int pmbus_regulator_register(struct pmbus_data *data) } #endif +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, status; + + mutex_lock(&data->update_lock); + for (i = 0; i < data->info->pages; i++) { + status = pmbus_read_status_word(client, i); + 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, i); + } + mutex_unlock(&data->update_lock); + + return IRQ_HANDLED; +} + +static int pmbus_irq_setup(struct i2c_client *client, struct pmbus_data *data) +{ + struct device *dev = &client->dev; + const struct pmbus_status_category *cat; + const struct pmbus_status_assoc *bit; + int i, j, err, func; + u8 mask; + + static const u8 misc_status[] = {PMBUS_STATUS_CML, PMBUS_STATUS_OTHER, + PMBUS_STATUS_MFR_SPECIFIC, PMBUS_STATUS_FAN_12, + PMBUS_STATUS_FAN_34}; + + if (!client->irq) + return 0; + + for (i = 0; i < data->info->pages; i++) { + func = data->info->func[i]; + + for (j = 0; j < ARRAY_SIZE(pmbus_status_flag_map); j++) { + cat = &pmbus_status_flag_map[j]; + 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_dbg_once(dev, "Failed to set smbalert for reg 0x%02x\n", + cat->reg); + } + + for (j = 0; j < ARRAY_SIZE(misc_status); j++) + pmbus_write_smbalert_mask(client, i, misc_status[j], 0xff); + } + + /* Register notifiers */ + err = devm_request_threaded_irq(dev, client->irq, NULL, pmbus_fault_handler, 0, + "pmbus-irq", data); + if (err) { + dev_err(dev, "failed to request an irq %d\n", err); + return err; + } + + return 0; +} + static struct dentry *pmbus_debugfs_dir; /* pmbus debugfs directory */ #if IS_ENABLED(CONFIG_DEBUG_FS) @@ -3467,6 +3541,10 @@ int pmbus_do_probe(struct i2c_client *client, struct pmbus_driver_info *info) if (ret) return ret; + 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 Fri Feb 17 08:36: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: 13144427 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 BBA01C636D6 for ; Fri, 17 Feb 2023 08:36:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229780AbjBQIgq (ORCPT ); Fri, 17 Feb 2023 03:36:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229670AbjBQIgm (ORCPT ); Fri, 17 Feb 2023 03:36:42 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F5355F249 for ; Fri, 17 Feb 2023 00:36:41 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id e10so218843wrg.4 for ; Fri, 17 Feb 2023 00:36:40 -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=Glx5PtLD/RY+BLX0OyzHnvMIcdeGlar2Jyclh1azXvQ=; b=N7jRqIvR91vj/CV5RzLtG2QE7kIm/aYaxgaRXcYMG59naPQ3nVlWHTW3shWZnflA6L /41vKHdndtIamb1fdlcp5p8OwMcwpuGpHJe/pUoVyTn8pRQgNMgnBbpZ8TR9UuWHxIKI q8UvQKPtAtjAVhLncmyItdMIDojar95Zw68+Skhi/wfBnekqIrzMNIIlfxfzC1d9oY+8 lgz8YvWjCtTKBtfZJpZZQTqwqoUiyLF7lTfHU6OJZ7cvPLYgro4ADWr+n4DRuRprvzrJ pq0GhGdas63WHhJqJi3caPQaZvXQ7XuuouCz+hVUaIZaFH2zWhKJfEa/olNIgVdJS3Hk EoRw== 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=Glx5PtLD/RY+BLX0OyzHnvMIcdeGlar2Jyclh1azXvQ=; b=nl15BMhdHZUgYedGsbVBeAC596TU5uzBP/jmowqARWhEBaijFqL1Qdb/3AyAJCPR1P 2EEIkHELS5GZlCDFHm1wcc1y9xjI1hZTgEHmb9UbzIa6PuHWDODRuHu4vYQbhe2mHXq6 t0DI0K4XGwXa2V+e1FMeoiRb8mxxa82eBl3nYcyDHbzook1QI5Ybpd/SfSDhTHQv/fTW Fu1XgXr+74XhHrxCiB5VzoSxCfSb0x5G76b+YOXJrOivi58zssAD4A13vC3QCBMODjJ6 O+sXaHKfzuNDbz2+NEvzh8h9a7UDnbsXPi51iFOSP9QXcHu1RFY/TGuLWP3y7FRChAj1 ZJTg== X-Gm-Message-State: AO0yUKVNbvo44KVw+uokWS0fRDjpBxGkRD1Npfp9q7inS7LHtBLxCst+ +xwTbNSFg9oUNOdLVr/FJtZWyg== X-Google-Smtp-Source: AK7set/LFJ7OLSKFvvjRjmtE3GX5xZuj9GYzZL76ygl+9Jzy4IXfFXfpkN3yO3zTFYl6HxDBI9fAHA== X-Received: by 2002:adf:fb44:0:b0:2c5:4ffa:ba62 with SMTP id c4-20020adffb44000000b002c54ffaba62mr248459wrs.17.1676622999337; Fri, 17 Feb 2023 00:36:39 -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.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Feb 2023 00:36:39 -0800 (PST) From: Naresh Solanki X-Google-Original-From: Naresh Solanki To: Guenter Roeck , Jean Delvare Cc: linux-hwmon@vger.kernel.org, Patrick Rudolph , Naresh Solanki , linux-kernel@vger.kernel.org Subject: [PATCH v3 4/4] hwmon: (pmbus/core): Notify hwmon events Date: Fri, 17 Feb 2023 09:36:31 +0100 Message-Id: <20230217083631.657430-4-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230217083631.657430-1-Naresh.Solanki@9elements.com> References: <20230217083631.657430-1-Naresh.Solanki@9elements.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Patrick Rudolph Notify hwmon events using the pmbus irq handler. Signed-off-by: Patrick Rudolph Signed-off-by: Naresh Solanki ... Changes in V3: - Remove empty line - locked version of pmbus_get_flags Changes in V2 - Remove __maybe_unsed attribute as its not needed. --- drivers/hwmon/pmbus/pmbus_core.c | 48 ++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index d0415d5ac7d9..2d10a354fe7a 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -2761,7 +2761,35 @@ static int __maybe_unused pmbus_is_enabled(struct device *dev, u8 page) return !!(ret & PB_OPERATION_CONTROL_ON); } -static int _pmbus_get_flags(struct pmbus_data *data, u8 page, unsigned int *flags) +#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_get_flags(struct pmbus_data *data, u8 page, unsigned int *flags, + bool notify) { int i, status; const struct pmbus_status_category *cat; @@ -2785,6 +2813,10 @@ static int _pmbus_get_flags(struct pmbus_data *data, u8 page, unsigned int *flag if (status & bit->pflag) *flags |= bit->rflag; } + + if (notify && status) + pmbus_notify(data, page, cat->reg, status); + } /* @@ -2828,12 +2860,13 @@ static int _pmbus_get_flags(struct pmbus_data *data, u8 page, unsigned int *flag return 0; } -static int __maybe_unused pmbus_get_flags(struct pmbus_data *data, u8 page, unsigned int *flags) +static int __maybe_unused pmbus_get_flags(struct pmbus_data *data, u8 page, unsigned int *flags, + bool notify) { int ret; mutex_lock(&data->update_lock); - ret = _pmbus_get_flags(data, page, flags); + ret = _pmbus_get_flags(data, page, flags, notify); mutex_unlock(&data->update_lock); return ret; @@ -2878,7 +2911,7 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned struct i2c_client *client = to_i2c_client(dev->parent); struct pmbus_data *data = i2c_get_clientdata(client); - return pmbus_get_flags(data, rdev_get_id(rdev), flags); + return pmbus_get_flags(data, rdev_get_id(rdev), flags, false); } static int pmbus_regulator_get_status(struct regulator_dev *rdev) @@ -3114,10 +3147,14 @@ 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, status; + int i, status, ret; mutex_lock(&data->update_lock); for (i = 0; i < data->info->pages; i++) { + ret = _pmbus_get_flags(data, i, &status, true); + if (ret) + return ret; + status = pmbus_read_status_word(client, i); if (status < 0) { mutex_unlock(&data->update_lock); @@ -3126,6 +3163,7 @@ static irqreturn_t pmbus_fault_handler(int irq, void *pdata) if (status & ~(PB_STATUS_OFF | PB_STATUS_BUSY | PB_STATUS_POWER_GOOD_N)) pmbus_clear_fault_page(client, i); + } mutex_unlock(&data->update_lock);