From patchwork Thu Nov 24 08:34:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 25371 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3266538wrr; Thu, 24 Nov 2022 00:36:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Tlvb2VauBu6BOiG3icOQ/Dm0ZRFk4XrHPwB72lgcVDyiAznlyEo7HmkXs/EsK358vwpCB X-Received: by 2002:a17:90a:a381:b0:218:6dc3:55b8 with SMTP id x1-20020a17090aa38100b002186dc355b8mr34480754pjp.189.1669278999685; Thu, 24 Nov 2022 00:36:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669278999; cv=none; d=google.com; s=arc-20160816; b=qztk5vgPYS+K+8Ew4y7YkaUe9AKztrY2K8GJXO1QaP+FCdDxxZktag5MWQ0zW2X4UV t8DJiPVMhjrp+NLUAOaC6nkyzelPBTUhEBTYHm7i6V9edibhxu76SkSmFSFFEabV6sxC BZ+s3HN15IFD0f9tIHGCgT9yR6yUiYnR5YUWPJg1G/gl5OaLMvoL36ozM3ueVH7x7ktd eR+M4badJVbRo4PqZbEU0agvE6KtsBNff46SFJKhliqahY3e+SPsLvSfHrvQiR8mvBY1 9iEFGa8wObx2viqoGACBT45hxt0rZFK5ZauaSwe83JJ+Q+1TI0Q7jl9dH5AZgygp792U Mr1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=JW7FLp8EfvNtL1XZPl1vzh58Pu217kjL61ohaey6idw=; b=z7CBjpRAoIcN/Uqvo5MLEM5tXiMsf9NFcv4IMW34WTD9PRo8mVhc2tuiazRs9FC3Sg GXgmKeI/teXOnOSX3AuDrwqY92RMuyfPKZFrKEY0SzZKX0XR+aE4Y8K88WriQYZET7V1 q6UOMQXiUBPJwPE0X9GBo2dmrl4rEvUFqQzXFb4HItyM3jHmX6kRm0obEcPjjOrubn9v 5ytUPB3NCjfVnDlKP8TkwoXES3nt+pBFKqNG1mXtyinXR6oCt8EOgk8DUqRTLgqYmEp4 +DTdGDHlc2zvPIIEcgfB3rqKEMJ7B1irPAv/k7uHQqrrU//IizhEZldp1twuchl7QCZ3 EPow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@9elements.com header.s=google header.b="GcCGKg/A"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=9elements.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a15-20020a170902eccf00b00189240585a8si486579plh.292.2022.11.24.00.36.27; Thu, 24 Nov 2022 00:36:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@9elements.com header.s=google header.b="GcCGKg/A"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=9elements.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229666AbiKXIfA (ORCPT + 99 others); Thu, 24 Nov 2022 03:35:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229875AbiKXIez (ORCPT ); Thu, 24 Nov 2022 03:34:55 -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 47FA7DA4D6 for ; Thu, 24 Nov 2022 00:34:54 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id m7-20020a05600c090700b003cf8a105d9eso698394wmp.5 for ; Thu, 24 Nov 2022 00:34:54 -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=JW7FLp8EfvNtL1XZPl1vzh58Pu217kjL61ohaey6idw=; b=GcCGKg/AY5KiyMo9lr9z+0Of6TgjF2FQsaHsWLYrGL0n8YzhroF3H//kQJXFP9ZZ8M q3V/nUxNwc9ZOdrGlpotzenR8KygjjSydZalMmL7pqGRLxXhBJKIXRlzEIr9L9Q8EafA +c7LK5LTB72YcsG2smQuF4g8Er2Y1Cka6wT6+9Z+chx62I+s3225b3rImPNtpPEIQC9U AwsrwGBgKcgjJUNSTb3KdfsXHJVs5gYT36r0dOvbK4BLs1eDCfatLQP61GZdnNt6enu9 gOWTFt3iER8MxKSzGzdDgHHlM0vLUt0BCDdqHK/Pc6F0VVUhwYFcKqaRI9bdH9wodf0D N8VA== 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=JW7FLp8EfvNtL1XZPl1vzh58Pu217kjL61ohaey6idw=; b=7D5Vv5xT+YLRAcKBk0JFBY6hzFP1oAhYj6wvhCukjMnEyPEk/5HuldHyiVKJ0NkoNT KpEjdwCxfk/gBiRQAaPGfkGIeznGj3Pcl0Tbv5RkU2xZilSEpvbuzv25dRkjXHsRi9ZU qBQ8sHOUbKs9iBwyuRgUjuwCI+K4+RJq0bWeESlQzaT7K4ubfYr1Gl5V4kyijHTvRUGW HSDOXhhNull9UP7R02fe+mP5q6CHd8fKwmSWTfI+2jXlC2nZN5kSSHxrtYX0I6FZvZlA wAMRBRnf1cIU4tB3edRymDdMcTv07NpxTGEWH54Aq7VuIKufZvyXf9OaXuU4rlRkk5kd Flug== X-Gm-Message-State: ANoB5pk22Tlf254P7dPMoM8UAijoeLtlnRppHFqgasjKUNgld7KM/QDF hF/tgsqiZKpeG2/yrNnmKjGBqtKC4fU50leu X-Received: by 2002:a05:600c:3586:b0:3cf:a3b0:df6a with SMTP id p6-20020a05600c358600b003cfa3b0df6amr25923934wmq.126.1669278892794; Thu, 24 Nov 2022 00:34:52 -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 o5-20020a05600c510500b003b4ff30e566sm10028095wms.3.2022.11.24.00.34.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Nov 2022 00:34:52 -0800 (PST) From: Naresh Solanki X-Google-Original-From: Naresh Solanki To: Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare Cc: Patrick Rudolph , Naresh Solanki , linux-kernel@vger.kernel.org Subject: [PATCH v5] hwmon: (pmbus/core): Implement regulator get_status Date: Thu, 24 Nov 2022 09:34:39 +0100 Message-Id: <20221124083439.3840025-1-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750365896687641673?= X-GMAIL-MSGID: =?utf-8?q?1750365896687641673?= From: Patrick Rudolph Add get_status for pmbus_regulator_ops. --- Changes: - use lock throughout the function - Avoid line continuation upto 100 column - Optimize use of & and | operator - Check for VOUT, IOUT, TEMPERATURE bit in status word before checking respective status register for fault. - Report regulator current status. - Utilize get_error_flag to check for regulator errors. - Check for return value of function get_error_flag Signed-off-by: Patrick Rudolph Signed-off-by: Naresh Solanki --- drivers/hwmon/pmbus/pmbus_core.c | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) base-commit: 2c71b3246ec3246522e8cb7c8191dc7a5d62cc70 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 20ca26e19db7..0b13214c662f 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -2855,6 +2855,49 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned return 0; } +static int pmbus_regulator_get_status(struct regulator_dev *rdev) +{ + 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 status, ret; + + mutex_lock(&data->update_lock); + status = pmbus_get_status(client, page, PMBUS_STATUS_WORD); + if (status < 0) { + ret = status; + goto unlock; + } + + if (status & PB_STATUS_OFF) { + ret = REGULATOR_STATUS_OFF; + goto unlock; + } + + /* If regulator is ON & reports power good then return ON */ + if (!(status & PB_STATUS_POWER_GOOD_N)) { + ret = REGULATOR_STATUS_ON; + goto unlock; + } + + if (rdev->desc->ops->get_error_flags) { + ret = rdev->desc->ops->get_error_flags(rdev, &status); + if (ret) + goto unlock; + + if (status & (REGULATOR_ERROR_UNDER_VOLTAGE | REGULATOR_ERROR_OVER_CURRENT | + REGULATOR_ERROR_REGULATION_OUT | REGULATOR_ERROR_FAIL | + REGULATOR_ERROR_OVER_TEMP)) + ret = REGULATOR_STATUS_ERROR; + } else + ret = REGULATOR_STATUS_UNDEFINED; + +unlock: + mutex_unlock(&data->update_lock); + return ret; +} + static int pmbus_regulator_get_low_margin(struct i2c_client *client, int page) { struct pmbus_data *data = i2c_get_clientdata(client); @@ -2995,6 +3038,7 @@ const struct regulator_ops pmbus_regulator_ops = { .disable = pmbus_regulator_disable, .is_enabled = pmbus_regulator_is_enabled, .get_error_flags = pmbus_regulator_get_error_flags, + .get_status = pmbus_regulator_get_status, .get_voltage = pmbus_regulator_get_voltage, .set_voltage = pmbus_regulator_set_voltage, .list_voltage = pmbus_regulator_list_voltage,