Received: by 2002:a19:771d:0:0:0:0:0 with SMTP id s29csp1242988lfc; Wed, 1 Jun 2022 12:52:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeb60UQETBGp/tK+JG/O98hnULWo+c9L/7zjp8uRqnmGa0bLavXOtGDVf0KCGHPVxjJj3P X-Received: by 2002:a17:902:b215:b0:165:7bdd:a9f1 with SMTP id t21-20020a170902b21500b001657bdda9f1mr1061669plr.41.1654113136259; Wed, 01 Jun 2022 12:52:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654113136; cv=none; d=google.com; s=arc-20160816; b=oYG403wuw93uS5r0oSfcEitG9lVlsTHK+yAUK+opkZlNFe9NnHCdJLVBepg5JkkPNM N3Cl1mJH53suHa0VdkMINO2r/Z2/KTZ7qAnypohs3L2KiMeIEcLTDFb3Amt949T9D7GP ogxpPfV7z5Sb/4pYPB5eHw9XyvhCoMTw5iSnZvd63FgrczJotpSVQr+2gn/DZk+UmbF3 IuuqiYh4CVoLt3YJ8JZQ6k4LC8MYaX/0V2pzz2N0RcKqQDARKRpLA4L7NnTIbYKaYpEJ GJ6+M5fPyxh5N8jJswQt238LgsnaHwtGvl8e9pjC/ROstGUhK6UAm+Hx/A17qhxk/464 xrFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :feedback-id:message-id:subject:reply-to:cc:from:dkim-signature:date; bh=amAPMCCPEklP8iHgRbF8DRtIbafxa6zl2AqTwOTE1cg=; b=GNfoQA/XjKsdQUXJuPRqOkUaNwbpVFkqm10QbHge01JGRcMZHUGF2EfJsOJ8UtkFfI cHfVSzExRwU6wh/LjhoH7elfifFYP2T4l8TnYjVI6pPR079rREEpPAPMQDApAXULnEoM 9Y7/ZMcQJ5X9aNK/Zpt+LQWHb71ZDr2ZbIGTa30hPzOMwVPBG84L8Eg5dgOEHr5zwLNo 9N+lQs/4C1ogQZOcbtibDEGR1pBJEKmn+ZXSd9U4fYgHHHGyZNMw8fy2HJeE4Nqenlww IS0lZHRV2FYzJYhgJz1mzkRvVmS4ctmoF6j8eAR2brET6U41jiBL6T2Z5LeyRE9PwlVB tfzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wujek.eu header.s=protonmail2 header.b=x4DgxkyT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id z4-20020a170902ccc400b0015852f2a130si3181088ple.620.2022.06.01.12.52.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 12:52:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=fail header.i=@wujek.eu header.s=protonmail2 header.b=x4DgxkyT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8492C1FD9F9; Wed, 1 Jun 2022 12:14:18 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348984AbiFABdQ (ORCPT + 99 others); Tue, 31 May 2022 21:33:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231869AbiFABdQ (ORCPT ); Tue, 31 May 2022 21:33:16 -0400 Received: from mail-40136.proton.ch (mail-40136.proton.ch [185.70.40.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB9FB5B3F9 for ; Tue, 31 May 2022 18:33:12 -0700 (PDT) Date: Wed, 01 Jun 2022 01:33:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wujek.eu; s=protonmail2; t=1654047190; x=1654306390; bh=amAPMCCPEklP8iHgRbF8DRtIbafxa6zl2AqTwOTE1cg=; h=Date:From:Cc:Reply-To:Subject:Message-ID:Feedback-ID:From:To:Cc: Date:Subject:Reply-To:Feedback-ID:Message-ID; b=x4DgxkyTsma2V6g67DRZDm+SkE6aDg4HARNg5WsTJI4Vlv1Z9xyn1BipdS3g766w9 lFe6VrFQ1JFQZsvHQH8cMyznB+5dPn1W+V9a9dIud4Cqzus8/3YFXjXAYDolx+Xfc8 om4bgtnag/dvqDwMo9E9v21XryCrNYn83CVsvisA/Yhi5PlLI+k+wasWQUljvr35rL hqybqNPYl/2NPU+7AIP22ZJwRNZfoVV1ziwRy+5QPq8uiVW1ZaJ4VBQskPtXcubdGw bbJVk3yJoEHNB3Ooofb0db2zalyIWgjtCwkkbqmPE46XO8sV2LGdB+AomdaKwRIoxX SgW18fa1grvig== From: Adam Wujek Cc: Adam Wujek , Guenter Roeck , Jean Delvare , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Reply-To: Adam Wujek Subject: [PATCH v3 1/2] hwmon: (pmbus) add a function to check the presence of a block register Message-ID: <20220601013232.801133-1-dev_public@wujek.eu> Feedback-ID: 23425257:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Other functions (like pmbus_check_byte_register) cannot be used to check the presence of a block register, because it will generate error when PEC is used. Signed-off-by: Adam Wujek --- Notes: Changes in v2: - Use Phase 0xff when setting the page Changes in v3: - remove not needed initialization of a buffer - add checking the flag PMBUS_READ_STATUS_AFTER_FAILED_CHECK drivers/hwmon/pmbus/pmbus_core.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_c= ore.c index acf78d0829d9..a1c70877ae68 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -421,6 +421,18 @@ static int _pmbus_read_byte_data(struct i2c_client *cl= ient, int page, int reg) =09return pmbus_read_byte_data(client, page, reg); } +static int pmbus_read_block_data(struct i2c_client *client, int page, u8 r= eg, +=09=09=09=09 char *data_buf) +{ +=09int rv; + +=09rv =3D pmbus_set_page(client, page, 0xff); +=09if (rv < 0) +=09=09return rv; + +=09return i2c_smbus_read_block_data(client, reg, data_buf); +} + static struct pmbus_sensor *pmbus_find_sensor(struct pmbus_data *data, int= page, =09=09=09=09=09 int reg) { @@ -558,6 +570,22 @@ bool pmbus_check_word_register(struct i2c_client *clie= nt, int page, int reg) } EXPORT_SYMBOL_NS_GPL(pmbus_check_word_register, PMBUS); +static bool pmbus_check_block_register(struct i2c_client *client, int page= , +=09=09=09=09 int reg) +{ +=09int rv; +=09struct pmbus_data *data =3D i2c_get_clientdata(client); +=09char data_buf[I2C_SMBUS_BLOCK_MAX + 2]; + +=09rv =3D pmbus_read_block_data(client, page, reg, data_buf); +=09if (rv >=3D 0 && !(data->flags & PMBUS_SKIP_STATUS_CHECK)) +=09=09rv =3D pmbus_check_status_cml(client); +=09if (rv < 0 && (data->flags & PMBUS_READ_STATUS_AFTER_FAILED_CHECK)) +=09=09data->read_status(client, -1); +=09pmbus_clear_fault_page(client, -1); +=09return rv >=3D 0; +} + const struct pmbus_driver_info *pmbus_get_driver_info(struct i2c_client *c= lient) { =09struct pmbus_data *data =3D i2c_get_clientdata(client); -- 2.17.1