From patchwork Wed Mar 22 17:55:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13184452 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B6AC9C6FD1F for ; Wed, 22 Mar 2023 17:57:44 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pf2hQ-00007m-V9; Wed, 22 Mar 2023 13:56:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3UEEbZAYKCmcYNYZXWLTTLQJ.HTRVJRZ-IJaJQSTSLSZ.TWL@flex--titusr.bounces.google.com>) id 1pf2hP-00006M-Is for qemu-devel@nongnu.org; Wed, 22 Mar 2023 13:56:35 -0400 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3UEEbZAYKCmcYNYZXWLTTLQJ.HTRVJRZ-IJaJQSTSLSZ.TWL@flex--titusr.bounces.google.com>) id 1pf2hN-0002Fe-Po for qemu-devel@nongnu.org; Wed, 22 Mar 2023 13:56:35 -0400 Received: by mail-yb1-xb4a.google.com with SMTP id e129-20020a251e87000000b00b56598237f5so20273742ybe.16 for ; Wed, 22 Mar 2023 10:56:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679507792; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=2T5B4kmhyEWAy1vn/gaQP2yNmdYM7rv0n//EHdFKaCI=; b=N8QTU+1ND/S+CLRk0HAnO7gylmQ/p2Z2t57NotAO7i2MkzX6Nk7KZaCH7QJme6t8Vz VGrVpqOmxdbavLeD8ZgoADOB8sb5a5tEumgtxxwH3jTWdu+FY7ogmauJx4DxZ2t/+PoA cKHVryYcHXffymaOn7NogEAJTbgMVRFRN85ir1UTb4rKLshWvGqepO4bRR2d9fci+aKB MHe2U23Ij8lGRSktyRp4AWOptGP7uUuKLX/dLfckoe5fTmBoMRBc8uFanhppMeqkYKeC bTs7W1YSk0qE/Uu7VR6WRj1Mpp/7xyH1olMZbJ0tWzkA/BHH/blsfGy/P6X6EgKUM3Jp TpFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679507792; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2T5B4kmhyEWAy1vn/gaQP2yNmdYM7rv0n//EHdFKaCI=; b=QNgvp8T4P3Qgeu28wUf9KPaLLawwt9X/aRDoOp9U2MC0u032SpGrs61gTvifI8Q2db B6oGJ2elANKu2LfpcB//SHX2b3hb7KPyS1wvT/bnzH71gyv5Z+e8f1LxXUrJlpw81oB0 zCBYfqUYewndmxMB+PYe6C8raZ2/3k1xLqHx/LX7RRcUVxa9mow8bZgt0dkG8zUYl8AP 9Sdmoey6jtoVrKy69+faAN4Kb3eA9hsE5InK/iH3OB9LCzFKdGIvU4yx0oxitd1jxXeE N5aiNtH3Pu4feO/ZgE+mxeUZL054u1s3gMHw5gEdFBvxB3kANUWpOPIzYHfwtPOui4jj 2dXA== X-Gm-Message-State: AAQBX9ev0O7e1I7agHx8djHA194cFTIh0LCQDw0eQixE74Pdgv5fIooF eIRQMlCUwlspX07rkTd/to078CW0msY= X-Google-Smtp-Source: AKy350YeZFYzpyAjNphOgXMSyKXpnOReDaT5+D0XX7sAgGl/yVUle6ZgCrjjtr/WMo4tQLR7B1D+ND4ATds= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:22b8]) (user=titusr job=sendgmr) by 2002:a81:b203:0:b0:545:64c4:7701 with SMTP id q3-20020a81b203000000b0054564c47701mr386939ywh.3.1679507792164; Wed, 22 Mar 2023 10:56:32 -0700 (PDT) Date: Wed, 22 Mar 2023 17:55:09 +0000 In-Reply-To: <20230322175513.1550412-1-titusr@google.com> Mime-Version: 1.0 References: <20230322175513.1550412-1-titusr@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Message-ID: <20230322175513.1550412-2-titusr@google.com> Subject: [PATCH 1/5] hw/i2c: pmbus add support for block receive From: Titus Rwantare To: philmd@linaro.org, minyard@acm.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, Titus Rwantare , Hao Wu Received-SPF: pass client-ip=2607:f8b0:4864:20::b4a; envelope-from=3UEEbZAYKCmcYNYZXWLTTLQJ.HTRVJRZ-IJaJQSTSLSZ.TWL@flex--titusr.bounces.google.com; helo=mail-yb1-xb4a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Reviewed-by: Hao Wu Signed-off-by: Titus Rwantare --- hw/i2c/pmbus_device.c | 30 +++++++++++++++++++++++++++++- include/hw/i2c/pmbus_device.h | 7 +++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/hw/i2c/pmbus_device.c b/hw/i2c/pmbus_device.c index c3d6046784..02647769cd 100644 --- a/hw/i2c/pmbus_device.c +++ b/hw/i2c/pmbus_device.c @@ -95,7 +95,6 @@ void pmbus_send64(PMBusDevice *pmdev, uint64_t data) void pmbus_send_string(PMBusDevice *pmdev, const char *data) { size_t len = strlen(data); - g_assert(len > 0); g_assert(len + pmdev->out_buf_len < SMBUS_DATA_MAX_LEN); pmdev->out_buf[len + pmdev->out_buf_len] = len; @@ -105,6 +104,35 @@ void pmbus_send_string(PMBusDevice *pmdev, const char *data) pmdev->out_buf_len += len + 1; } +uint8_t pmbus_receive_block(PMBusDevice *pmdev, uint8_t *dest, size_t len) +{ + /* dest may contain data from previous writes */ + memset(dest, 0, len); + + /* Exclude command code from return value */ + pmdev->in_buf++; + pmdev->in_buf_len--; + + /* The byte after the command code denotes the length */ + uint8_t sent_len = pmdev->in_buf[0]; + + if (sent_len != pmdev->in_buf_len - 1) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: length mismatch. Expected %d bytes, got %d bytes\n", + __func__, sent_len, pmdev->in_buf_len - 1); + } + + /* exclude length byte */ + pmdev->in_buf++; + pmdev->in_buf_len--; + + if (pmdev->in_buf_len < len) { + len = pmdev->in_buf_len; + } + memcpy(dest, pmdev->in_buf, len); + return len; +} + static uint64_t pmbus_receive_uint(PMBusDevice *pmdev) { diff --git a/include/hw/i2c/pmbus_device.h b/include/hw/i2c/pmbus_device.h index 93f5d57c9d..7dc00cc4d9 100644 --- a/include/hw/i2c/pmbus_device.h +++ b/include/hw/i2c/pmbus_device.h @@ -501,6 +501,13 @@ void pmbus_send64(PMBusDevice *state, uint64_t data); */ void pmbus_send_string(PMBusDevice *state, const char *data); +/** + * @brief Receive data sent with Block Write. + * @param dest - memory with enough capacity to receive the write + * @param len - the capacity of dest + */ +uint8_t pmbus_receive_block(PMBusDevice *pmdev, uint8_t *dest, size_t len); + /** * @brief Receive data over PMBus * These methods help track how much data is being received over PMBus From patchwork Wed Mar 22 17:55:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13184454 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DFA45C6FD1C for ; Wed, 22 Mar 2023 17:57:56 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pf2hR-00008Z-KI; Wed, 22 Mar 2023 13:56:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3UUEbZAYKCmgZOZaYXMUUMRK.IUSWKSa-JKbKRTUTMTa.UXM@flex--titusr.bounces.google.com>) id 1pf2hP-00006h-PA for qemu-devel@nongnu.org; Wed, 22 Mar 2023 13:56:35 -0400 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3UUEbZAYKCmgZOZaYXMUUMRK.IUSWKSa-JKbKRTUTMTa.UXM@flex--titusr.bounces.google.com>) id 1pf2hO-0002Fn-Ar for qemu-devel@nongnu.org; Wed, 22 Mar 2023 13:56:35 -0400 Received: by mail-yb1-xb49.google.com with SMTP id j11-20020a25230b000000b00b6871c296bdso12952516ybj.5 for ; Wed, 22 Mar 2023 10:56:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679507793; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=kSd+tzkdOJAC3FzLgq2ZSZ8SsB0RX5ytiYdlGTCKyFA=; b=N0xT4vOETnrFNGMRqljK9WP/cKl6H6zYW/fgDL86zMLz56KvJIulslJYzNPhC5TLdp /rMrCo3mLTJa4ghvc93LNfn9OTM4FVeu9GmwbgMQ+ZykTD/OT2eV6gxKnHMHjaWoi3pM UAxEjA0jYJoKBOswagoVfbHiiBziBXVBNY3q7fly4tFyy901mYmYV8wfUtXHJ+03d62D Q7aIhGXz3soQJ9xl8iJPzV0IchOqy+BROmcCIo19KMIcsmuh+vs3d7jmbpWy15ToPRa8 UoZsbJbE+uz231zcxyodcDVN/gqSb2GjoHiGXlA3zTQVtXfhRMtRLo4ydU1ciozINAyz QqHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679507793; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kSd+tzkdOJAC3FzLgq2ZSZ8SsB0RX5ytiYdlGTCKyFA=; b=ZcNYtcjYeL4YzgHpr8fO7QLBAARfKib1hB0jtaLcUUCt7GwNzrHTMUaHCjNx59M9sf mF73YHuzVDdJ+BzeZmHJRh8TQz/w8m+Us880Q1xuFfuAK6OunyDvhndacsPV7cPsPDdk /cK6D6jGJz6dOowehxOJ0tiFTDPS0yJh5Hw0DWmd3/o8pd+Tj66bqsRYehF95P7207qF KihmVEYG0UU/ICHXAWy2oiTfQ3TkQ9S+vq7hCS6TPGzHwJsO8hrsAhq1tCSiOwPWGV20 dVDtu7pSju0D73pCf6H6Ys/li1cSW6BnhytYeFl3xKXLVRPZwQj33QHNitNJrZMFR0Ut v8og== X-Gm-Message-State: AAQBX9ePKV5JaHuLz5dQURMLnA814A6Rwqna1/EKAEDhdyMCKK1PuhyO JZ9ymFqqDscHstdIvtdlW4VN8LtVZdM= X-Google-Smtp-Source: AKy350bgETMJYe4YAJP6/wChva0VTgbXaNxBnQd1KzOn3l+sS2cPVdsb00oLtySGzYfjBgsoTV5a4u+Z23c= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:22b8]) (user=titusr job=sendgmr) by 2002:a81:b611:0:b0:545:4133:fc40 with SMTP id u17-20020a81b611000000b005454133fc40mr357418ywh.9.1679507793108; Wed, 22 Mar 2023 10:56:33 -0700 (PDT) Date: Wed, 22 Mar 2023 17:55:10 +0000 In-Reply-To: <20230322175513.1550412-1-titusr@google.com> Mime-Version: 1.0 References: <20230322175513.1550412-1-titusr@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Message-ID: <20230322175513.1550412-3-titusr@google.com> Subject: [PATCH 2/5] hw/i2c: pmbus: add vout mode bitfields From: Titus Rwantare To: philmd@linaro.org, minyard@acm.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, Titus Rwantare , Hao Wu Received-SPF: pass client-ip=2607:f8b0:4864:20::b49; envelope-from=3UUEbZAYKCmgZOZaYXMUUMRK.IUSWKSa-JKbKRTUTMTa.UXM@flex--titusr.bounces.google.com; helo=mail-yb1-xb49.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Reviewed-by: Hao Wu Signed-off-by: Titus Rwantare --- include/hw/i2c/pmbus_device.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/hw/i2c/pmbus_device.h b/include/hw/i2c/pmbus_device.h index 7dc00cc4d9..2e95164aa1 100644 --- a/include/hw/i2c/pmbus_device.h +++ b/include/hw/i2c/pmbus_device.h @@ -444,6 +444,14 @@ typedef struct PMBusCoefficients { int32_t R; /* exponent */ } PMBusCoefficients; +/** + * VOUT_Mode bit fields + */ +typedef struct PMBusVoutMode { + uint8_t mode:3; + int8_t exp:5; +} PMBusVoutMode; + /** * Convert sensor values to direct mode format * From patchwork Wed Mar 22 17:55:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13184455 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 825D7C6FD1F for ; Wed, 22 Mar 2023 17:57:56 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pf2hV-00009I-Bg; Wed, 22 Mar 2023 13:56:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3UkEbZAYKCmkaPabZYNVVNSL.JVTXLTb-KLcLSUVUNUb.VYN@flex--titusr.bounces.google.com>) id 1pf2hR-000084-5j for qemu-devel@nongnu.org; Wed, 22 Mar 2023 13:56:37 -0400 Received: from mail-vs1-xe49.google.com ([2607:f8b0:4864:20::e49]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3UkEbZAYKCmkaPabZYNVVNSL.JVTXLTb-KLcLSUVUNUb.VYN@flex--titusr.bounces.google.com>) id 1pf2hP-0002FN-Dy for qemu-devel@nongnu.org; Wed, 22 Mar 2023 13:56:36 -0400 Received: by mail-vs1-xe49.google.com with SMTP id i21-20020a05610221b500b004258d5ee8c4so5260123vsb.0 for ; Wed, 22 Mar 2023 10:56:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679507794; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=RY8s82z5rIvVBZrpcsDgJeZ9k05PqbQRPAq95/JGkxM=; b=A3rMQxZaoNOhL+16qZJl+jJNi04BvJr3eTGI2rC0JVKGAl4GigsVqe9/xUTRDApdSP hgQLfBKyrqLptpMvUlG0f4bTwmpCuwODQh+zQ3CxZ/jQAPT4dnoyDT+2qXJCJJOZejNB Ikl2eZGCSojFGTBWtAVce7OT02mQJcy7rp7ZI2BUYa2zYEu1oFjjZkCtqKKOXtzvLQv9 z6VGQllR6NwFXue/xbvYbIBlMEqS0Iq02qAGYCxDKDPnX5R8+h9HNJGQHiWkH2OBi2PO f/G/F3T0k/btc62CLOHF9hPzPOs6eBlvSfar65tE8OGQutaFzcU70T+ZKVrPRdsCcyzT hALw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679507794; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RY8s82z5rIvVBZrpcsDgJeZ9k05PqbQRPAq95/JGkxM=; b=x/yfGFat455+XSQJeYTA4pBt0cmHA/U0JNMExRHWU4fVSdfrd5LHYbSC5/9xXM5GBl OVxqOsR3InRdkdkNFswR34KJGDYbQ/r1wK5oatbHXG16fjAtfaWOoD25aDO9+QNp9rnn Ga/ZK9RRnNE3Ardi45t6lx67rhwgx5xcPxa713reaedCUDXJPX2R618S55K13RekCN/G mql7ivgJ2RQMTE0+ssjgtPqAlKXJb/Kb/cboV5pI1ajdb8DUG5o+rj4uIULW0HPq/cv1 I4bX16hkqQKhtXVPLM6bkNlwx8/5ZE4GuMXWgX9POFVkeEKxf2bRQEofP2TFx7rhWXu1 9BRQ== X-Gm-Message-State: AO0yUKWRaGJ9PmURaT00jvASMKQSic3xp2IFgz6d9jhQxnp/VkypuExX B2VoLyomTWsemRNgz/EcJ0+sLSCl/u8= X-Google-Smtp-Source: AK7set+/rNRDyYXO3HVU89Y44ch+50N+GCEYH/j/rS2N6X5LpJv3hx6+9hpqOhC9it/SnHbG5zdGhM8DIQY= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:22b8]) (user=titusr job=sendgmr) by 2002:a1f:24d2:0:b0:40c:4d1:b550 with SMTP id k201-20020a1f24d2000000b0040c04d1b550mr343704vkk.0.1679507794182; Wed, 22 Mar 2023 10:56:34 -0700 (PDT) Date: Wed, 22 Mar 2023 17:55:11 +0000 In-Reply-To: <20230322175513.1550412-1-titusr@google.com> Mime-Version: 1.0 References: <20230322175513.1550412-1-titusr@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Message-ID: <20230322175513.1550412-4-titusr@google.com> Subject: [PATCH 3/5] hw/i2c: pmbus: add fan support From: Titus Rwantare To: philmd@linaro.org, minyard@acm.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, Titus Rwantare , Stephen Longfield Received-SPF: pass client-ip=2607:f8b0:4864:20::e49; envelope-from=3UkEbZAYKCmkaPabZYNVVNSL.JVTXLTb-KLcLSUVUNUb.VYN@flex--titusr.bounces.google.com; helo=mail-vs1-xe49.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Reviewed-by: Stephen Longfield Signed-off-by: Titus Rwantare Acked-by: Corey Minyard --- hw/i2c/pmbus_device.c | 176 ++++++++++++++++++++++++++++++++++ include/hw/i2c/pmbus_device.h | 1 + 2 files changed, 177 insertions(+) diff --git a/hw/i2c/pmbus_device.c b/hw/i2c/pmbus_device.c index 02647769cd..bb42e410b4 100644 --- a/hw/i2c/pmbus_device.c +++ b/hw/i2c/pmbus_device.c @@ -490,6 +490,54 @@ static uint8_t pmbus_receive_byte(SMBusDevice *smd) } break; + case PMBUS_FAN_CONFIG_1_2: /* R/W byte */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmbus_send8(pmdev, pmdev->pages[index].fan_config_1_2); + } else { + goto passthough; + } + break; + + case PMBUS_FAN_COMMAND_1: /* R/W word */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmbus_send16(pmdev, pmdev->pages[index].fan_command_1); + } else { + goto passthough; + } + break; + + case PMBUS_FAN_COMMAND_2: /* R/W word */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmbus_send16(pmdev, pmdev->pages[index].fan_command_2); + } else { + goto passthough; + } + break; + + case PMBUS_FAN_CONFIG_3_4: /* R/W byte */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmbus_send8(pmdev, pmdev->pages[index].fan_config_3_4); + } else { + goto passthough; + } + break; + + case PMBUS_FAN_COMMAND_3: /* R/W word */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmbus_send16(pmdev, pmdev->pages[index].fan_command_3); + } else { + goto passthough; + } + break; + + case PMBUS_FAN_COMMAND_4: /* R/W word */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmbus_send16(pmdev, pmdev->pages[index].fan_command_4); + } else { + goto passthough; + } + break; + case PMBUS_VOUT_OV_FAULT_LIMIT: /* R/W word */ if (pmdev->pages[index].page_flags & PB_HAS_VOUT) { pmbus_send16(pmdev, pmdev->pages[index].vout_ov_fault_limit); @@ -800,6 +848,22 @@ static uint8_t pmbus_receive_byte(SMBusDevice *smd) pmbus_send8(pmdev, pmdev->pages[index].status_mfr_specific); break; + case PMBUS_STATUS_FANS_1_2: /* R/W byte */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmbus_send8(pmdev, pmdev->pages[index].status_fans_1_2); + } else { + goto passthough; + } + break; + + case PMBUS_STATUS_FANS_3_4: /* R/W byte */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmbus_send8(pmdev, pmdev->pages[index].status_fans_3_4); + } else { + goto passthough; + } + break; + case PMBUS_READ_EIN: /* Read-Only block 5 bytes */ if (pmdev->pages[index].page_flags & PB_HAS_EIN) { pmbus_send(pmdev, pmdev->pages[index].read_ein, 5); @@ -872,6 +936,54 @@ static uint8_t pmbus_receive_byte(SMBusDevice *smd) } break; + case PMBUS_READ_FAN_SPEED_1: /* Read-Only word */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmbus_send16(pmdev, pmdev->pages[index].read_fan_speed_1); + } else { + goto passthough; + } + break; + + case PMBUS_READ_FAN_SPEED_2: /* Read-Only word */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmbus_send16(pmdev, pmdev->pages[index].read_fan_speed_2); + } else { + goto passthough; + } + break; + + case PMBUS_READ_FAN_SPEED_3: /* Read-Only word */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmbus_send16(pmdev, pmdev->pages[index].read_fan_speed_3); + } else { + goto passthough; + } + break; + + case PMBUS_READ_FAN_SPEED_4: /* Read-Only word */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmbus_send16(pmdev, pmdev->pages[index].read_fan_speed_4); + } else { + goto passthough; + } + break; + + case PMBUS_READ_DUTY_CYCLE: /* Read-Only word */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmbus_send16(pmdev, pmdev->pages[index].read_duty_cycle); + } else { + goto passthough; + } + break; + + case PMBUS_READ_FREQUENCY: /* Read-Only word */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmbus_send16(pmdev, pmdev->pages[index].read_frequency); + } else { + goto passthough; + } + break; + case PMBUS_READ_POUT: /* Read-Only word */ if (pmdev->pages[index].page_flags & PB_HAS_POUT) { pmbus_send16(pmdev, pmdev->pages[index].read_pout); @@ -1295,6 +1407,54 @@ static int pmbus_write_data(SMBusDevice *smd, uint8_t *buf, uint8_t len) } break; + case PMBUS_FAN_CONFIG_1_2: /* R/W byte */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmdev->pages[index].fan_config_1_2 = pmbus_receive8(pmdev); + } else { + goto passthrough; + } + break; + + case PMBUS_FAN_COMMAND_1: /* R/W word */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmdev->pages[index].fan_command_1 = pmbus_receive16(pmdev); + } else { + goto passthrough; + } + break; + + case PMBUS_FAN_COMMAND_2: /* R/W word */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmdev->pages[index].fan_command_2 = pmbus_receive16(pmdev); + } else { + goto passthrough; + } + break; + + case PMBUS_FAN_CONFIG_3_4: /* R/W byte */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmdev->pages[index].fan_config_3_4 = pmbus_receive8(pmdev); + } else { + goto passthrough; + } + break; + + case PMBUS_FAN_COMMAND_3: /* R/W word */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmdev->pages[index].fan_command_3 = pmbus_receive16(pmdev); + } else { + goto passthrough; + } + break; + + case PMBUS_FAN_COMMAND_4: /* R/W word */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmdev->pages[index].fan_command_4 = pmbus_receive16(pmdev); + } else { + goto passthrough; + } + break; + case PMBUS_VOUT_OV_FAULT_LIMIT: /* R/W word */ if (pmdev->pages[index].page_flags & PB_HAS_VOUT) { pmdev->pages[index].vout_ov_fault_limit = pmbus_receive16(pmdev); @@ -1600,6 +1760,22 @@ static int pmbus_write_data(SMBusDevice *smd, uint8_t *buf, uint8_t len) pmdev->pages[index].status_mfr_specific = pmbus_receive8(pmdev); break; + case PMBUS_STATUS_FANS_1_2: /* R/W byte */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmbus_send8(pmdev, pmdev->pages[index].status_fans_1_2); + } else { + goto passthrough; + } + break; + + case PMBUS_STATUS_FANS_3_4: /* R/W byte */ + if (pmdev->pages[index].page_flags & PB_HAS_FAN) { + pmbus_send8(pmdev, pmdev->pages[index].status_fans_3_4); + } else { + goto passthrough; + } + break; + case PMBUS_PAGE_PLUS_READ: /* Block Read-only */ case PMBUS_CAPABILITY: /* Read-Only byte */ case PMBUS_COEFFICIENTS: /* Read-only block 5 bytes */ diff --git a/include/hw/i2c/pmbus_device.h b/include/hw/i2c/pmbus_device.h index 2e95164aa1..ad431bdc7c 100644 --- a/include/hw/i2c/pmbus_device.h +++ b/include/hw/i2c/pmbus_device.h @@ -258,6 +258,7 @@ OBJECT_DECLARE_TYPE(PMBusDevice, PMBusDeviceClass, #define PB_HAS_TEMP2 BIT_ULL(41) #define PB_HAS_TEMP3 BIT_ULL(42) #define PB_HAS_TEMP_RATING BIT_ULL(43) +#define PB_HAS_FAN BIT_ULL(44) #define PB_HAS_MFR_INFO BIT_ULL(50) #define PB_HAS_STATUS_MFR_SPECIFIC BIT_ULL(51) From patchwork Wed Mar 22 17:55:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13184456 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9D7ECC6FD1F for ; Wed, 22 Mar 2023 17:58:22 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pf2hW-0000Am-WC; Wed, 22 Mar 2023 13:56:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3U0EbZAYKCmobQbcaZOWWOTM.KWUYMUc-LMdMTVWVOVc.WZO@flex--titusr.bounces.google.com>) id 1pf2hV-00009W-EB for qemu-devel@nongnu.org; Wed, 22 Mar 2023 13:56:41 -0400 Received: from mail-ua1-x94a.google.com ([2607:f8b0:4864:20::94a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3U0EbZAYKCmobQbcaZOWWOTM.KWUYMUc-LMdMTVWVOVc.WZO@flex--titusr.bounces.google.com>) id 1pf2hQ-0002GU-FN for qemu-devel@nongnu.org; Wed, 22 Mar 2023 13:56:37 -0400 Received: by mail-ua1-x94a.google.com with SMTP id c18-20020ab030d2000000b00751d7bbfb13so9506811uam.4 for ; Wed, 22 Mar 2023 10:56:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679507795; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xgLuRZVtqHDGrFFer+S3EY1A5uZ4UquNrXBrasz7AHI=; b=f8AR9nKldyRtL/nSHJK8++JGEBphRh9At6FYSeu/uzGVIPQtKB3PCUd9R35tLjv1IV 8/QxdI0MHCXgUwBIKjo9aOmJibUJhL8AsSSI1DoiTvhC2DO6lA2FcP42XFs0eAHaDVBN i/ZYf7wcnHWMjF6Ze0qon1GdHm7JQJp12Qp6b4+COAI2WN/d4vO6MWhmw6+mgUMzijQ2 mLVjeFPyEVQcoaJO4FbXt9nh/+ASQR1kc60Jp3aW0frCAqbRQoGNk8CYESskrQwfZ0d3 bBX2acVQEuBJu17WL0mTXG3NCwMJWoR1qg4DxE4xoZuD91fYsSdmo1AgbaSq+Yy1pxXh ecbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679507795; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xgLuRZVtqHDGrFFer+S3EY1A5uZ4UquNrXBrasz7AHI=; b=UHqs+mdCq6F72FzDsbT5KO0B9So9ZEWxqozLrmcRgjV4xVyXVrLmVJfhvn3WkyW127 ZqgYXQ5Bal1QlG/QKbSABd9uq6c/rMRVSGB2KnjdlSOTZcOV17W5XxK2cLngsWYTbDMv 3AyDtGZflxY4sjjOnUxVmG0uIYQ53TAzB+pyyGmOrzlUFGEwHS4zxRNz3ZCetDyUxufi wwrGDjSvJ31US8w0QJN78Jp/r0BMQKDc/SO4U8zSjGjnsILOO8htJML5pNvYnj2IKS2t jLq8zGXo52dEykz9mZXcWqwzEywWJpDYSEdY98a4NbH7o1RuJrKbUayG5fiUSPAvoudY XcWA== X-Gm-Message-State: AAQBX9fuYM13IKxfQGm8bIRqK/B63lLN+0MU09hJZ2piBTlk3Mi/Hl/u T7BypdHsexqDLZb36aa3c8y721XJoY0= X-Google-Smtp-Source: AKy350YwenfDHGVc76ZEfiGftk4KeX9JYCqKJ5O6ZUE1US6uXm1VEFMqlgKisJspDChPtVj805mXHapiem0= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:22b8]) (user=titusr job=sendgmr) by 2002:a05:6130:312:b0:68b:817b:eec8 with SMTP id ay18-20020a056130031200b0068b817beec8mr3924877uab.0.1679507795269; Wed, 22 Mar 2023 10:56:35 -0700 (PDT) Date: Wed, 22 Mar 2023 17:55:12 +0000 In-Reply-To: <20230322175513.1550412-1-titusr@google.com> Mime-Version: 1.0 References: <20230322175513.1550412-1-titusr@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Message-ID: <20230322175513.1550412-5-titusr@google.com> Subject: [PATCH 4/5] hw/i2c: pmbus: block uninitialised string reads From: Titus Rwantare To: philmd@linaro.org, minyard@acm.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, Titus Rwantare , Patrick Venture Received-SPF: pass client-ip=2607:f8b0:4864:20::94a; envelope-from=3U0EbZAYKCmobQbcaZOWWOTM.KWUYMUc-LMdMTVWVOVc.WZO@flex--titusr.bounces.google.com; helo=mail-ua1-x94a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Devices models calling pmbus_send_string can't be relied upon to send a non-zero pointer. This logs an error and doesn't segfault. Reviewed-by: Patrick Venture Signed-off-by: Titus Rwantare Reviewed-by: Philippe Mathieu-Daudé Acked-by: Corey Minyard --- hw/i2c/pmbus_device.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/i2c/pmbus_device.c b/hw/i2c/pmbus_device.c index bb42e410b4..18e629eaac 100644 --- a/hw/i2c/pmbus_device.c +++ b/hw/i2c/pmbus_device.c @@ -94,6 +94,13 @@ void pmbus_send64(PMBusDevice *pmdev, uint64_t data) void pmbus_send_string(PMBusDevice *pmdev, const char *data) { + if (!data) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: %s: uninitialised read from 0x%02x\n", + __func__, DEVICE(pmdev)->canonical_path, pmdev->code); + return; + } + size_t len = strlen(data); g_assert(len + pmdev->out_buf_len < SMBUS_DATA_MAX_LEN); pmdev->out_buf[len + pmdev->out_buf_len] = len; From patchwork Wed Mar 22 17:55:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13184451 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2153DC6FD1F for ; Wed, 22 Mar 2023 17:57:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pf2hZ-0000Ba-7a; Wed, 22 Mar 2023 13:56:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3VEEbZAYKCmscRcdbaPXXPUN.LXVZNVd-MNeNUWXWPWd.XaP@flex--titusr.bounces.google.com>) id 1pf2hX-0000B2-EV for qemu-devel@nongnu.org; Wed, 22 Mar 2023 13:56:43 -0400 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3VEEbZAYKCmscRcdbaPXXPUN.LXVZNVd-MNeNUWXWPWd.XaP@flex--titusr.bounces.google.com>) id 1pf2hV-0002H6-Sv for qemu-devel@nongnu.org; Wed, 22 Mar 2023 13:56:43 -0400 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-536d63d17dbso197694457b3.22 for ; Wed, 22 Mar 2023 10:56:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679507796; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=5/Dadg8m/Nn6NEOd+UqaKmTnByQM0BpngrWfhpbEyYg=; b=F1itLqKhKt9whbHkXAzqNSS6zyDHCFIxRjbLNZINzTpJa8BCd9hvDypXX7pxdWglam QZVABlGCcn9409/bor2HXCP38XGldAVfDJvgu7HgFYDVOLj2CYoOGTNFRk6+e2ZZ+473 rPHNfSP4QU4SzN+SZvQnINk6NFtimfQQ98sGq8deUMmZAd1NpQbfoWehh6pQF2WjVT2/ avBfiuyE7wRW8PgAnrD3ziQfeWWIos888NyPyRgLQt0PHhoKSU18dBafcUjKagIrnrFa P8TrO0WNXYxDfpr7vMpP91xPOMYpqgH7BNO8RNKVZGoUi/AGOj7BqQklOhtev72iWSwV lIfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679507796; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5/Dadg8m/Nn6NEOd+UqaKmTnByQM0BpngrWfhpbEyYg=; b=drY64ufKXD9nZLJ3ZTtVJgSPv7dhihRiGwybZUM4xSu1sQJItSJ/PStaLtvI4aek1e o0sNdGiDSLFMnqX72AGPD2Nk9FF1zortjSEaFXnCH4269iPUPcIlYwKzGB99WUpASqGd xO5ltWJf3qwWI9ddMxD1EB52Q1cSvhn1jekFHrYYhVTNkfBDeI6amttnI41z+CA8DVtK JKeKbZy6kA9VbAkwI+dXIoB1OdvgHoBmH+0QTsYn6tbfKvQIaNOfbReYdQD0lPCwhK9z dFbAvrrsoFjVD1MrJH1Tirx7JlleJlhPHx/VH2wUwW3cw4LKT1CtFIZ17QKbC3Q4FlXQ 347Q== X-Gm-Message-State: AAQBX9e0hy38tvdmfmVIW7xT8TjFz1avfuweSh7hd8ZMlugODE7HBP/G x7friQtIluNBNx/hEvaVG1z9crDt78w= X-Google-Smtp-Source: AKy350aNmvCusv7yo1iQBEDZfxLXMV/kgC5N4elF0uNiONFQFcTZ5e3+LJEZGExuw+hKm80f+NQVB+eAxm4= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:22b8]) (user=titusr job=sendgmr) by 2002:a05:6902:1141:b0:91d:98cd:bfe4 with SMTP id p1-20020a056902114100b0091d98cdbfe4mr407835ybu.10.1679507796245; Wed, 22 Mar 2023 10:56:36 -0700 (PDT) Date: Wed, 22 Mar 2023 17:55:13 +0000 In-Reply-To: <20230322175513.1550412-1-titusr@google.com> Mime-Version: 1.0 References: <20230322175513.1550412-1-titusr@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Message-ID: <20230322175513.1550412-6-titusr@google.com> Subject: [PATCH 5/5] hw/i2c: pmbus: add VCAP register From: Titus Rwantare To: philmd@linaro.org, minyard@acm.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, Titus Rwantare , Benjamin Streb Received-SPF: pass client-ip=2607:f8b0:4864:20::114a; envelope-from=3VEEbZAYKCmscRcdbaPXXPUN.LXVZNVd-MNeNUWXWPWd.XaP@flex--titusr.bounces.google.com; helo=mail-yw1-x114a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org VCAP is a register for devices with energy storage capacitors. Reviewed-by: Benjamin Streb Signed-off-by: Titus Rwantare Acked-by: Corey MInyard --- hw/i2c/pmbus_device.c | 8 ++++++++ include/hw/i2c/pmbus_device.h | 1 + 2 files changed, 9 insertions(+) diff --git a/hw/i2c/pmbus_device.c b/hw/i2c/pmbus_device.c index 18e629eaac..ef0314a913 100644 --- a/hw/i2c/pmbus_device.c +++ b/hw/i2c/pmbus_device.c @@ -903,6 +903,14 @@ static uint8_t pmbus_receive_byte(SMBusDevice *smd) } break; + case PMBUS_READ_VCAP: /* Read-Only word */ + if (pmdev->pages[index].page_flags & PB_HAS_VCAP) { + pmbus_send16(pmdev, pmdev->pages[index].read_vcap); + } else { + goto passthough; + } + break; + case PMBUS_READ_VOUT: /* Read-Only word */ if (pmdev->pages[index].page_flags & PB_HAS_VOUT) { pmbus_send16(pmdev, pmdev->pages[index].read_vout); diff --git a/include/hw/i2c/pmbus_device.h b/include/hw/i2c/pmbus_device.h index ad431bdc7c..f195c11384 100644 --- a/include/hw/i2c/pmbus_device.h +++ b/include/hw/i2c/pmbus_device.h @@ -243,6 +243,7 @@ OBJECT_DECLARE_TYPE(PMBusDevice, PMBusDeviceClass, #define PB_HAS_VIN_RATING BIT_ULL(13) #define PB_HAS_VOUT_RATING BIT_ULL(14) #define PB_HAS_VOUT_MODE BIT_ULL(15) +#define PB_HAS_VCAP BIT_ULL(16) #define PB_HAS_IOUT BIT_ULL(21) #define PB_HAS_IIN BIT_ULL(22) #define PB_HAS_IOUT_RATING BIT_ULL(23)