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; From patchwork Wed Mar 1 16:44:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13156233 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 D0D5BC64ED6 for ; Wed, 1 Mar 2023 16:44:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229955AbjCAQo6 (ORCPT ); Wed, 1 Mar 2023 11:44:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229940AbjCAQo5 (ORCPT ); Wed, 1 Mar 2023 11:44:57 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFD4741B7C for ; Wed, 1 Mar 2023 08:44:55 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id j19-20020a05600c1c1300b003e9b564fae9so12335357wms.2 for ; Wed, 01 Mar 2023 08:44:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1677689094; 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=azKX1lyv7tMs1R7K/ve0RJJDzM9elnW553diWuTLooQ=; b=dnjnCngKPOMhT2j4ysiutT5Xga5rCcF3eGxhgGH3hWplFQWcUI2lHbTMyAIvSCtGrt FHl166M+CbINjuE0/vtrsz8obGbpUrhYL2fxY6RukL7i2435MEUxnJaWwgSbs4bexPpS jxei/lZoBOnN9nwmr4fG7CEz07ZfMjBPx0MfWCDMMqcfZ3L0jPxIGCOJh7p9cRHZvPbe LP0Y8wut765vDx6zp/WP89Y1biJmVWe2OonuYA5aTAMIoSHEBUzGJFi+aEvcHP3piEiT mQeMwkhgVPXmL3E1Zc5+0A308p8YJrQR2uP2ugYeaKpoQ3phjCIvPYWFGgTUXlwqmM3d 5fNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677689094; 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=azKX1lyv7tMs1R7K/ve0RJJDzM9elnW553diWuTLooQ=; b=OdVfKvHCLixuYoIsAJv/rE4Ho98i5HfML6TVG8KURX55mVTFexjYDZJ6uJKfLS8sDr 9ciF+ZoTC5E+nzJGRzpy0n0/zfk+AGBn61Ff1bHUAJFeBatw/E35Xnlo7SJTLlUkNxsO XLzTvoKTkTi0nyTrPssw3ql9XFpVaAKE6wf5lYq6YkScovmp9eG87VfHrrwbHib9UKuf I3eigZSNYfQBeqAtSI8q9hYU7BfVVaZWjM4FyUeEk1dtpwOvTcTLBtEatNuqHBhKBrUu FsAv+cOMaSQoE+elxsNy0dv/UJgCYIvfZ7vukfpBq3v9iVKex8GRO3uw8C1qLlBh/adh ceTA== X-Gm-Message-State: AO0yUKUTjVp1OdHxDh7Wp4qrzwj4hti3qrmhxn0bt2k0zXxffJmbo1IY nO/wDIOTBCLw4xg6WurWLYk2xA== X-Google-Smtp-Source: AK7set+htUG7Xzgq5EG5XhiYoJmGuUSdC5B2bHFQO7tXvbcc3ZtzrNqdDQBz7UuNl0vRl9Kkm+vS3g== X-Received: by 2002:a05:600c:3417:b0:3eb:38e6:f650 with SMTP id y23-20020a05600c341700b003eb38e6f650mr5024079wmp.41.1677689094308; Wed, 01 Mar 2023 08:44:54 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 08:44:54 -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 2/4] hwmon: (pmbus/core) Generalise pmbus get status Date: Wed, 1 Mar 2023 17:44:32 +0100 Message-Id: <20230301164434.1928237-2-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230301164434.1928237-1-Naresh.Solanki@9elements.com> References: <20230301164434.1928237-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 Reviewed-by: Guenter Roeck ... Change in V4 - None Changes in V3: - Add pmbus_is_enabled function Changes in V2: - Add __maybe attribute for pmbus_get_status function - Remove unrelated changes --- 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 Wed Mar 1 16:44:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13156234 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 E0A13C7EE32 for ; Wed, 1 Mar 2023 16:45:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229940AbjCAQo7 (ORCPT ); Wed, 1 Mar 2023 11:44:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229952AbjCAQo6 (ORCPT ); Wed, 1 Mar 2023 11:44:58 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1027234C03 for ; Wed, 1 Mar 2023 08:44:56 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id o38-20020a05600c512600b003e8320d1c11so903554wms.1 for ; Wed, 01 Mar 2023 08:44:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1677689095; 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=CVVDY8ic1qw0PVkNeQsrCkRxHgDpu5ucByCSMwYa9Ps=; b=IuDP27vbGYs3T4iGMRPV/UvoR9HIzQVOlvo0t2jJ75WRdav5sHFWfqDo8mt4YIvlYx Z3FONtKWwpPuHHUxRFsRu3hT2t+TnsdKwmPQwqKcS8dkvLD2f1JBFdy25vgOkd8RpfPk d8LMj+8gJapLAp2TTkrRyI1N+LycFDczKvEq1bJIZK89lhbdPIFxDdJk3Lbh9Wgm4gR8 acm5ChbCFe2UvT2F6FJBWivN4oEJIGrw0cBqDiazZx3BzAfJiNXirmMUcaCkzGvp/8Ib CfbqkfiUgx6FxzjqWBOvzcpNZ0FZk7u/LefqcMO3iXMPZ6/zs3Y+IBut1utfcK/HHcQ7 jCXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677689095; 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=CVVDY8ic1qw0PVkNeQsrCkRxHgDpu5ucByCSMwYa9Ps=; b=F4AvRpy9Q/stdSOfd3SMPR+oT2NZ1yZyMpUZzpRMcgOIbOIPwcHJoNPAJTZCiZfP2T JchjJmfxFNf5rVAQlwnQPdyoP3PenNoNPpwQ6ptMCZuI1Xbd6KRIMF8b75CmN/g30xT8 TTrON0oWOUCg0AfBIXzlIKkC/F1RjwhI6XqbyIUdvDOEj/De+X3vi4HLK0CyuNqsQ+Fb BfwWoyml3aOgnl9SWwx9Vhb3aoTA3SyItGAIkRIKiuE8wfwUnc2M0l0igvBQSqkYCLLy Ts6TbOJULGvk42rIOT7plIciUUziceUNgjbKus3UPGimvk8lyBs9IOvfPt296gG/11BU ZNLw== X-Gm-Message-State: AO0yUKVIMExEyrmkeZe7FVpX1ZGHstnty3lwrOEc7QsTROkwxUJTY8NQ xiedYirNxxoBGv7mji167NYO2g== X-Google-Smtp-Source: AK7set+XSc/AxQVmgmYK+IYFnOdLK1+ddo53AwtKZqsoGF+O2NwUBhLz+HSungGdFlkmbF7B+C7APA== X-Received: by 2002:a05:600c:5119:b0:3e2:1a01:3a7c with SMTP id o25-20020a05600c511900b003e21a013a7cmr11625048wms.6.1677689095409; Wed, 01 Mar 2023 08:44:55 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 08:44:55 -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 v4 3/4] hwmon: (pmbus/core): Add interrupt support Date: Wed, 1 Mar 2023 17:44:33 +0100 Message-Id: <20230301164434.1928237-3-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230301164434.1928237-1-Naresh.Solanki@9elements.com> References: <20230301164434.1928237-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 V4: - Clear fault using pmbus_clear_faults at end of interrupt handler. - Remove for loop. 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 | 70 ++++++++++++++++++++++++++++++++ 2 files changed, 71 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..dfd227459d8b 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -3105,6 +3105,72 @@ 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); + + mutex_lock(&data->update_lock); + /* TODO: Check status flag & notify hwmon events */ + + pmbus_clear_faults(client); + 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 +3533,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 Wed Mar 1 16:44:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13156235 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 73A44C7EE33 for ; Wed, 1 Mar 2023 16:45:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229974AbjCAQpB (ORCPT ); Wed, 1 Mar 2023 11:45:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229982AbjCAQo7 (ORCPT ); Wed, 1 Mar 2023 11:44:59 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10EB0360B2 for ; Wed, 1 Mar 2023 08:44:57 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id j3so9010500wms.2 for ; Wed, 01 Mar 2023 08:44:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1677689096; 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=iLcZN2988ihhBNvPwnv1tBtUBTQj9QBFY2uBIRKI9Sg=; b=aNAVQgIv3Vy00lGPfD4qRq2kKY9XtZyvMcazWF5GKeKI1CnUYiWnu53gwOq07GP+5w iEf3QrP//BhNzkSKDKoQXvqPxpGvzICY6EdI6XGMdIgcORWKWQYDoBkzd0UEkOTdEXUa cJJ8gvrgwVLej13B8Z1VCGeZoYa5EVxi18E49hdzT8EqJbuptYLq7C75dF57DVqnFxQH HmoMmX15r+bFRAwV6JNeRPR7on57YLIf6CyYl7vdV7p0VlXw95AWH9604XlxTwlQKZyb j33NQDi8S5Hh7CUZkkpdsrvj35L5dX8aX9MEmGR4RHU5xkSKmAGxDlF4Ti3ACCABwX4o RjmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677689096; 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=iLcZN2988ihhBNvPwnv1tBtUBTQj9QBFY2uBIRKI9Sg=; b=j7ynWtU/339OU5M9yEuXpM7dfiVvEAyS1Q6D8abj3OOEPidQjqYwbEtYbs0J0sbS3y CDcrvP4/ElIScQqSaLqdkQ2Ntx28/4dktGN+hivXxhra0yF8JCnZRzfc71Z1cJD/uXuk rST6IJi6ZEg7lbM6VF3gXu+wim+2cthe1awt/hj5MjB9mFhWxyFz1Z3Kb06wRUV6quFt KX6Q2061SJ2FyV//8zyrpdG7I6iWk5Oto14QiQ0NsnCm/AIF03Pd1EEYycL+0vHOPSRr UktwqGLwjknbkER0bxdUL2kC2uKAJrjEecukt3w9fE2nhch3BaGGS6ry5NZisMMSb1Gx M26g== X-Gm-Message-State: AO0yUKVR/e/J1cXw3g6xYtxjjczkw+yBbHUZ9KudF0zcQo+60y5T+XCn hnb+4gJJXEb3nxIsK4fqwbc/1Q== X-Google-Smtp-Source: AK7set/QZ1Z8Yx7b0VTjJtuU0kqrqwy9mCFJ7gjVLxo5ZtqOtPxuqt/h5V0PRdss1adPjwLhNowUIQ== X-Received: by 2002:a05:600c:4d26:b0:3eb:2de8:b743 with SMTP id u38-20020a05600c4d2600b003eb2de8b743mr6083621wmp.12.1677689096340; Wed, 01 Mar 2023 08:44:56 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 08:44:56 -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 v4 4/4] hwmon: (pmbus/core): Notify hwmon events Date: Wed, 1 Mar 2023 17:44:34 +0100 Message-Id: <20230301164434.1928237-4-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230301164434.1928237-1-Naresh.Solanki@9elements.com> References: <20230301164434.1928237-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 V4: - Ignore return error in irq handle & instead continue loop. 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 | 46 +++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index dfd227459d8b..0ddef2c9ba9b 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,9 +3147,10 @@ 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); - /* TODO: Check status flag & notify hwmon events */ + for (i = 0; i < data->info->pages; i++) + _pmbus_get_flags(data, i, &status, true); pmbus_clear_faults(client); mutex_unlock(&data->update_lock);