From patchwork Mon Oct 23 23:46:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13433727 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 81149C00A8F for ; Mon, 23 Oct 2023 23:48:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qv4dT-0002nC-5f; Mon, 23 Oct 2023 19:47:03 -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 <38QU3ZQYKCgo3s3421qyyqvo.myw0ow4-no5ovxyxqx4.y1q@flex--titusr.bounces.google.com>) id 1qv4dR-0002mK-5l for qemu-devel@nongnu.org; Mon, 23 Oct 2023 19:47:01 -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 <38QU3ZQYKCgo3s3421qyyqvo.myw0ow4-no5ovxyxqx4.y1q@flex--titusr.bounces.google.com>) id 1qv4dO-0002lM-Ti for qemu-devel@nongnu.org; Mon, 23 Oct 2023 19:47:00 -0400 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-da033914f7cso405911276.0 for ; Mon, 23 Oct 2023 16:46:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698104818; x=1698709618; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=hBi9ecZu+jknETLfEjF91XegZl5B2r+QYOyPgwOcjHE=; b=xoQrMLa9vGOddbcKH0N7gPKv2Ql1h/9i2Gvz6GxuuTxSlugC4WveA1iHquvDZuSYtS Wk+wyydtEsYAOScKzr8jiDgwX57fgCoLj/O9ExSCYbHZj/4l1r+dEsh1tKeIwWmyleCm yT0SPPWEb/8YsdkflUfUCjxvvJSTzd+W6/BuiNH/Ll0fpZdp1mAHIqUFgIQhRmyB8vWG PN0YnCHBood/PUmHl5rexXWxMxNIOptLESiHrjo2aOKxTw1URzdN0Df7oZdyw9q1gk90 +xRw9t9cMjl3ApqheSvmXnVKhPwkzVzBg3V5s9GTbkU26Htk/vxN5TuJrX3UZ6XW1v1h +jfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698104818; x=1698709618; 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=hBi9ecZu+jknETLfEjF91XegZl5B2r+QYOyPgwOcjHE=; b=snpeJMJYU6ZydfM6AzHfhXkgcOPDFKrTSfKDCSbUMcTAw9Xv237+Y+OSaJsn4R+TP4 yYeUBquQpCldKJqKwlv1aO1MvJLW1sLbiIcnTxHdsj8GfvXt8F7ZLFPVkDNH7ves6D+Q F59PdOLA2qOF2t8ZI4/w4oGb3k9uPFaDxzxzhzQSCXWz1kyjPfpUs06Zldkw2SKqDLbN TlZuH8vQ7A7/dh+6hu9BpSmC3Og/ostV5t8VA3KAHoZwTTJ2m3eP6ZXZLCOR5c/hlp0D QVl6iLaLreXlVmsIDMbnrPo2TO2ulg9mqDDd1qPNt7T57DjjDQ5jlOir4B9go38ybbut RGxg== X-Gm-Message-State: AOJu0YzTJ+QLDGugRFw9rXAf5aNNbH47T1wEX8GuqV2J2XTgHudX8qiv 7aGIbUvxi3OtrpmyeeCea3AkTmkbxKY= X-Google-Smtp-Source: AGHT+IE4Qc/4NeP7RNmT6lTSnsSiLzx4hAD0jarRLDQtPo/dU8uGovlL1PBBR/G4sSv6GQ/583Lc0SgeLW8= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:22b8]) (user=titusr job=sendgmr) by 2002:a25:c5cf:0:b0:d9c:a498:c1ef with SMTP id v198-20020a25c5cf000000b00d9ca498c1efmr200160ybe.9.1698104817995; Mon, 23 Oct 2023 16:46:57 -0700 (PDT) Date: Mon, 23 Oct 2023 23:46:40 +0000 In-Reply-To: <20231023-staging-pmbus-v3-v4-0-07a8cb7cd20a@google.com> Mime-Version: 1.0 References: <20231023-staging-pmbus-v3-v4-0-07a8cb7cd20a@google.com> X-Developer-Key: i=titusr@google.com; a=openpgp; fpr=228BD42BAD6A2BCD3865AEA6C41200175CD21E30 X-Developer-Signature: v=1; a=openpgp-sha256; l=2793; i=titusr@google.com; h=from:subject:message-id; bh=DFzZTJTLw0CTmSTx82hBdiA+2byo4JM+5crzjaQBGUE=; b=owEB7QES/pANAwAKAcQSABdc0h4wAcsmYgBlNwXtyT65ehjpk1G3HI0rYb89KGrgO+LHkhvlr pyAHqH7GPmJAbMEAAEKAB0WIQQii9QrrWorzThlrqbEEgAXXNIeMAUCZTcF7QAKCRDEEgAXXNIe MKjlDACPXKl0VvqiIL+xetkQoN/Pr+swT5ig8aeZCkAefyjEa6kKr5g1t7GK5mkIQDmleoL7M5C UmpNxdxBeaczz5K5MydblhmHrAozTo6rkE92sWA15SCu4t2dkCc1Q4NXk4qdPOWxg9L/x356DMS PKhJB85bGNDYPSHTlCPpqOUxHbJCa/vt9aJsQ49iLJgINrXJ0sl9YvZO9Y0mzNjdV85Txc2quD1 Q8YhiYI0NZr5qH6C0tBMK5mUKVrooWwXERJzcciD/8mtHZQLFaYXxR2U+9eXWJzxm8T+pfiWyW6 dPWBA1S1rmIg8H61vVZSKNCJrPvcPXZ7NnzK+Zn58kLaWqBuUFwveZcTwjNHfIo3gbCSAdGigXK rBx/qvZj+cW+imGfMR3SEHxpHytEiTXkIKS7UuwUxmve66zkAk25KA9Uwfc+ZmBn0kk8HRDuJN3 Gnh/nUMiVJDvpmCJMZHb4shXB1Yb7JP2v06P6iXxwKFtuIcdEIqa6txYJYEuHA7JLFni0= X-Mailer: b4 0.12.2 Message-ID: <20231023-staging-pmbus-v3-v4-1-07a8cb7cd20a@google.com> Subject: [PATCH v4 1/8] hw/i2c: pmbus add support for block receive From: titusr@google.com To: philmd@linaro.org, minyard@acm.org Cc: Titus Rwantare , qemu-arm@nongnu.org, qemu-devel@nongnu.org, Hao Wu , Corey Minyard Received-SPF: pass client-ip=2607:f8b0:4864:20::b49; envelope-from=38QU3ZQYKCgo3s3421qyyqvo.myw0ow4-no5ovxyxqx4.y1q@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 PMBus devices can send and receive variable length data using the block read and write format, with the first byte in the payload denoting the length. This is mostly used for strings and on-device logs. Devices can respond to a block read with an empty string. Reviewed-by: Hao Wu Acked-by: Corey Minyard 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 cef51663d0..ea15490720 100644 --- a/hw/i2c/pmbus_device.c +++ b/hw/i2c/pmbus_device.c @@ -102,7 +102,6 @@ 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; @@ -112,6 +111,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 Mon Oct 23 23:46:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13433725 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 0474BC00A8F for ; Mon, 23 Oct 2023 23:48:43 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qv4dW-0002qV-0u; Mon, 23 Oct 2023 19:47:06 -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 <38gU3ZQYKCgs4t4532rzzrwp.nzx1px5-op6pwyzyry5.z2r@flex--titusr.bounces.google.com>) id 1qv4dS-0002n1-EG for qemu-devel@nongnu.org; Mon, 23 Oct 2023 19:47:02 -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 <38gU3ZQYKCgs4t4532rzzrwp.nzx1px5-op6pwyzyry5.z2r@flex--titusr.bounces.google.com>) id 1qv4dQ-0002lb-Uj for qemu-devel@nongnu.org; Mon, 23 Oct 2023 19:47:02 -0400 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a7cf717bacso55355097b3.1 for ; Mon, 23 Oct 2023 16:46:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698104819; x=1698709619; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Y9PqfwJZCklklflJWx1kiMMaSEZM0FI95tSIjALLmPY=; b=wpRdadLeTqWWGw5HUQVXgFYrg6GHr94YO5OeoZHADjWvZkAf6V/Wsfl2do20RFSeEz OI2IRqwBq7uZH3xegbYbTmEIBrjKOfZn+7zaSmHZmjHkSQZiGmENhKGxtT3EzGYXVtIA N7iFPbY4jXDvgK3qr84tTero0To0iG8LfeYZC3GgnbbgTTi/OkAzVb/JEj8tf5wBgqKq ZgN5oDaLf0k4+H0yOL91yYo2ioKP6F5QzPSSov/L++dGGa1nxQ9o9N66CAPlK9r3tDch jw+QU9IxjNoIBPUAMy8TOCJebnUeEfsLaCjWTyLq10FcY8mlNTgrXWvWLMiK1zr2d3DL vRLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698104819; x=1698709619; 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=Y9PqfwJZCklklflJWx1kiMMaSEZM0FI95tSIjALLmPY=; b=ZfJlhq1S+cJeOc25SgN/tESK2sV34Fw7HUQo8i6NmbK3LF0KUe6kRscDqLK5Pkb2Ks tWzK/Wvv7PbvrjWNH7UO6jtBvQ86uZNlVxih3VTR4vwZcWCC8fd9bCTClD/7wAHUgYDr VWvSBcKVbP55CJNFkFTnvJsvfceLDJJFYifr5ZzkUyf62USBrgWyETdOFF0lURpwxfCM ELd9zhmjpN2HZc/LYE2G56ZJkMEoJdh2Wa8znbfx6hV4Be949Xx3bQezv8IO6gujmY2/ C4DauvM7YgVlU8N+EaDdVsPUGj3CEJIoOhOZCFW4u/U0F9P/HqviH5vUeAUGDcYt4Myg qNcQ== X-Gm-Message-State: AOJu0Yy/RpFjdCPb4rRB/w0iQNwZIk6govp6ADsXXNsI+ML2yB5FFptT oqLedupabz8lK8h9y6vIVUQiHwa4iC8= X-Google-Smtp-Source: AGHT+IEk+2N/M0vGvh7Ek8YIq50a7tIxVP8Znvo0/Rdr8CIjU803cDiFJzGHJnvl4bJesHKAVVF4UCg+Z+M= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:22b8]) (user=titusr job=sendgmr) by 2002:a81:4e8e:0:b0:5a7:ba09:44b4 with SMTP id c136-20020a814e8e000000b005a7ba0944b4mr248644ywb.1.1698104818916; Mon, 23 Oct 2023 16:46:58 -0700 (PDT) Date: Mon, 23 Oct 2023 23:46:41 +0000 In-Reply-To: <20231023-staging-pmbus-v3-v4-0-07a8cb7cd20a@google.com> Mime-Version: 1.0 References: <20231023-staging-pmbus-v3-v4-0-07a8cb7cd20a@google.com> X-Developer-Key: i=titusr@google.com; a=openpgp; fpr=228BD42BAD6A2BCD3865AEA6C41200175CD21E30 X-Developer-Signature: v=1; a=openpgp-sha256; l=1101; i=titusr@google.com; h=from:subject:message-id; bh=3ydAUfrEAeZPVQPNXJngklsGr0uuFIogbpEk1CsC6nQ=; b=owEB7QES/pANAwAKAcQSABdc0h4wAcsmYgBlNwXtjtsjf9QmxszIiPGvbc4msOc33M/DF1bOh SS9YkEgHeSJAbMEAAEKAB0WIQQii9QrrWorzThlrqbEEgAXXNIeMAUCZTcF7QAKCRDEEgAXXNIe MDMiC/49DLaShVclciQa158hVXIRKcL1oe7nw6RcZELMEHLXJR7QVC5hJe1eBwHmhJ1hQdbVdrg QEu43M+JHovPUAbQMTpohTiazv2X6iJZ8JTf6JLTofSjIvK3EyGN/jQL4rDVlA8V2aCynIJWuJP mxXNxPcTBTLSINETr+P2GSgqvHqGTzfYJoVidH8iwvdB01TVb9y9+NiKb6f5y2/gFkWG13144Lq U/KQEsKGB9b1C98OtkVuEVR4cSufPK5/QTDFLCme25wwEhQfwM9mPTnJcnZeFNvesd4+3cew+bU Y7GiyPb9e4jZVWRhQNps3t0466Gsw6F6JIcIJZvrvB1iUVqiqaDOKoCYpmpneVyFUF8SxkTKTzc IAptiOBkfU7hs73+6b5BWeBwTXzyjNvjJQQoEhdRUMmT/t15/OmkLMn3o1zgvPtrsNlYXxdp3dy ebAuXjkgcGf8eK8EBkexGE8FjcKEqPR2D6BJRZQHR0kg9I3qXMB+uSRk4v3nIw4OUsK1c= X-Mailer: b4 0.12.2 Message-ID: <20231023-staging-pmbus-v3-v4-2-07a8cb7cd20a@google.com> Subject: [PATCH v4 2/8] hw/i2c: pmbus: add vout mode bitfields From: titusr@google.com To: philmd@linaro.org, minyard@acm.org Cc: Titus Rwantare , qemu-arm@nongnu.org, qemu-devel@nongnu.org, Hao Wu , Corey Minyard Received-SPF: pass client-ip=2607:f8b0:4864:20::114a; envelope-from=38gU3ZQYKCgs4t4532rzzrwp.nzx1px5-op6pwyzyry5.z2r@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 The VOUT_MODE command is described in the PMBus Specification, Part II, Ver 1.3 Section 8.3 VOUT_MODE has a three bit mode and 4 bit parameter, the three bit mode determines whether voltages are formatted as uint16, uint16, VID, and Direct modes. VID and Direct modes use the remaining 5 bits to scale the voltage readings. Reviewed-by: Hao Wu Acked-by: Corey Minyard 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 Mon Oct 23 23:46:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13433724 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 6C5C7C25B67 for ; Mon, 23 Oct 2023 23:48:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qv4dX-0002sS-1l; Mon, 23 Oct 2023 19:47:07 -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 <39AU3ZQYKCg06v6754t11tyr.p1z3rz7-qr8ry010t07.14t@flex--titusr.bounces.google.com>) id 1qv4dT-0002pk-SQ for qemu-devel@nongnu.org; Mon, 23 Oct 2023 19:47:04 -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 <39AU3ZQYKCg06v6754t11tyr.p1z3rz7-qr8ry010t07.14t@flex--titusr.bounces.google.com>) id 1qv4dR-0002lp-SY for qemu-devel@nongnu.org; Mon, 23 Oct 2023 19:47:03 -0400 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-da03c5ae220so153534276.1 for ; Mon, 23 Oct 2023 16:47:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698104820; x=1698709620; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ltiPFA7AykEhStcVaCE5/VxTxx+tCgIE8K92hBhsFWc=; b=e2TdaWrdmJ7utjfSWSu6Cn5ra+1J3A0lVpAxh6bXIYjULJGkjwA8hmPogPayeoG5hO iiCsaJ7QU0cfsyHjjxEbM6adZqzV+E9JZNSccFn3FnMnjJb57zzHpvfFZ/fG81FeMeHa qCUsW/Yeaw+p4y0kva2ZMMArgsDo6yZTNSffOFTrffAEIRZitL+BwdocZ2CHPZfExfl2 iDSLPa+3GlRn0UJmpMI8PwO2JL2+v5O38it6WHE6LI/Kxf67UJgTL3Wv9wpNs7VpO5Ap pCuMzBl8OQnZUQ+NVPiN+2pInPV8WOQfQo7/DgS3iMBUk9Htx00LNeUDl0RM3u7l0piE w12Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698104820; x=1698709620; 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=ltiPFA7AykEhStcVaCE5/VxTxx+tCgIE8K92hBhsFWc=; b=KWYEcTc8ZMcDRCoqbG4r5LBobtUBEyUWfkAzqjrIbY5UG74fiXWwYecj2CQZpn8LV4 jdNabsgl8oGwjpdWvpgRGKDux8TLAJE+RSpMYGbSJAj4ROYgoIf2z7XBnKYkxwvUtrLO TA941qqCMU3+VaQOAcP2vqOZ/u5UDuiB4mNVbEOe9THuWKHlmtU7G5gnJup6UX0gUtPv 1dOdDSTAn1HopFX4sUbCJI9Sb9p03mrpKmv2pn7Ca5yFAQhJ//FeMFRVUqpcLYjxKWQs vloBP1lYtySZwM2iEPbrWOtwMKnAXAMedUOgs9XHKbMYZ0ZVDP6fUeqqHv7wxr3KrxNQ Bm6A== X-Gm-Message-State: AOJu0Yxk9XqFyRHdWs+DlQMK76JcKHpOeEagUEr7ZhEsWjmoAWNhO5Ia 1Ovq1xD/dy36/bKNsMbYVUg8nJ4FRc8= X-Google-Smtp-Source: AGHT+IGrMKLWf2N7R5uLAY/umOT+vzsKodOfaCPnqeLitnOQFDKj8dnlza7vjBO+Z9J+bIWy2d1ABsDObwM= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:22b8]) (user=titusr job=sendgmr) by 2002:a25:6902:0:b0:da0:36a5:97bb with SMTP id e2-20020a256902000000b00da036a597bbmr20949ybc.5.1698104820171; Mon, 23 Oct 2023 16:47:00 -0700 (PDT) Date: Mon, 23 Oct 2023 23:46:42 +0000 In-Reply-To: <20231023-staging-pmbus-v3-v4-0-07a8cb7cd20a@google.com> Mime-Version: 1.0 References: <20231023-staging-pmbus-v3-v4-0-07a8cb7cd20a@google.com> X-Developer-Key: i=titusr@google.com; a=openpgp; fpr=228BD42BAD6A2BCD3865AEA6C41200175CD21E30 X-Developer-Signature: v=1; a=openpgp-sha256; l=9030; i=titusr@google.com; h=from:subject:message-id; bh=xtvVQXZg79IMOuVxQNJZwOLLMDrZH/r2Ohc1ZeKx5G8=; b=owEB7QES/pANAwAKAcQSABdc0h4wAcsmYgBlNwXt5On5JCDZ6UzKYsRmqn5as7lOzXBgdGvmC vhmk0fNOCWJAbMEAAEKAB0WIQQii9QrrWorzThlrqbEEgAXXNIeMAUCZTcF7QAKCRDEEgAXXNIe MOmnDACumsNAH1W9m4ssqP62+NGCszpmHNu/61jTI9KWsCHEDF6P6NG/zD+PoQSP0mhTQ1rhNtU UyXyppK+ESrJGOaisGQLVT8AoE44lvVIAnG35Dw/htr2wCmWbHENfi2ghjbrGmR6IepeZPluO1o 6TSrz7MNMy5qa1zinD0eNBnYEiH+SYIXg7n2MOIZlSqM0ZC1Fh9afGhsodEjhv7ujA/WVynBTdH IDdRGBf1A2TwjKlEYA072RS4XF6DAVVcp3/Rme93Nd2lf+G58Zg82m+Amg+aJhghppgl/deIprW 8YiyGkuMksWcxMggdpcV6TDqez3Qj3ERYVSyVh7mhVvf9gVU9kBS4hzNpBSN4MqMyFhhfhA11kt Y1lTE3Fg3hvvf9Gt3rl/QLt1osLAitHelWRNzvrnq3xi/9Uaake8+2tFZVek0J0OE/vahKsAY2m dzJW4bfIZ654c7FtEgLConusyou9ZX73E+t9HztNV1sGIePJnsPWKSeCq8TO0USNc/7l8= X-Mailer: b4 0.12.2 Message-ID: <20231023-staging-pmbus-v3-v4-3-07a8cb7cd20a@google.com> Subject: [PATCH v4 3/8] hw/i2c: pmbus: add fan support From: titusr@google.com To: philmd@linaro.org, minyard@acm.org Cc: Titus Rwantare , qemu-arm@nongnu.org, qemu-devel@nongnu.org, Stephen Longfield , Corey Minyard Received-SPF: pass client-ip=2607:f8b0:4864:20::b49; envelope-from=39AU3ZQYKCg06v6754t11tyr.p1z3rz7-qr8ry010t07.14t@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=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 PMBus devices may integrate fans whose operation is configurable over PMBus. This commit allows the driver to read and write the fan control registers but does not model the operation of fans. Reviewed-by: Stephen Longfield Acked-by: Corey Minyard Signed-off-by: Titus Rwantare --- 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 ea15490720..c1d8c93056 100644 --- a/hw/i2c/pmbus_device.c +++ b/hw/i2c/pmbus_device.c @@ -500,6 +500,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); @@ -810,6 +858,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); @@ -882,6 +946,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); @@ -1305,6 +1417,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); @@ -1610,6 +1770,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 Mon Oct 23 23:46:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13433723 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 B2178C25B6B for ; Mon, 23 Oct 2023 23:48:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qv4dX-0002sg-O3; Mon, 23 Oct 2023 19:47:07 -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 <39QU3ZQYKCg47w7865u22uzs.q204s08-rs9sz121u18.25u@flex--titusr.bounces.google.com>) id 1qv4dV-0002qh-4F for qemu-devel@nongnu.org; Mon, 23 Oct 2023 19:47:05 -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 <39QU3ZQYKCg47w7865u22uzs.q204s08-rs9sz121u18.25u@flex--titusr.bounces.google.com>) id 1qv4dT-0002mW-5f for qemu-devel@nongnu.org; Mon, 23 Oct 2023 19:47:04 -0400 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a7bbe0a453so48683737b3.0 for ; Mon, 23 Oct 2023 16:47:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698104821; x=1698709621; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=303iPeC6VLFDXurUY29qkpPl/6cL6vaKoSkHpfuH/uM=; b=HVZ4p1iNAk2E+cruAg62FhYAv7TnersQQvZ9c5etP9NkiiHZYzmaQqXlHS1OqENkh1 qCHepygT+wiB75b0Qdd0pc87JfFRkQc8QN6BhsMAvFiBiSdAhkJST47u93aF7Ah2VSWu YwRjwtxw+cEhEFI31hPlJxgAGraqSuz+oK58GghKDSj0quJypW2euKRiR2exiTECDmR5 8fRk9Ij3xnXx7pVC7uI56j6OGZ9d8FkhdJstY4XmwPlbCgRj813yG1Ap0L9iehnoyUgO WhfghUNqGJ/b1Lch+CyUGGfbnF6Q/Z8MOpADJgnzTlw6w4e+ZjN6t1BaaAMId+oEqPvx L8Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698104821; x=1698709621; 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=303iPeC6VLFDXurUY29qkpPl/6cL6vaKoSkHpfuH/uM=; b=MDDLwyR8LihICDsqHAMAS6Shll7QXTzbegh/a+R8wBMSLl24aqOS03YP4mNEImpeVu 0z+nf7KU8SejkwXfCi/XtrHIwYOEMCus5XON3GquV8aEjDnJaL9kKSLAFj9LL0B3tOnQ eI97pnjGY1PkNlXcGh723UUd+K4XiwnzjDa3QMsyJLP+kTHGQuX0yFSOCzDqWp2b5TOi xTTeh3EJBPBrzoksk2eQ8M4tap7vNoQ5/qyTsRHeqk3Xj/8eotNoVuu7fE4FZeatZLEd HeFHe6rbtcI++u4CXyMKeyUSJ9agfL4BMwq7LicCclI6rMCat06uLVMTZjgx3dLMJWzM fdQQ== X-Gm-Message-State: AOJu0YxQW1A7CwfQ39OGgdJOV/rk0ULpdNinCd4BDE1VyyytYljBXRk2 D+bluiEPwUvE9LRCCk+rze9HlyczUos= X-Google-Smtp-Source: AGHT+IHnaCcgaahOvDN/4JU4FHtRrxlkmBinU1yQjbvfrgeQa5lj+EJ9gaCybpGLq2/J0ra1MWZj+dHL4Ow= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:22b8]) (user=titusr job=sendgmr) by 2002:a25:2f94:0:b0:d9a:6633:a799 with SMTP id v142-20020a252f94000000b00d9a6633a799mr189907ybv.13.1698104821566; Mon, 23 Oct 2023 16:47:01 -0700 (PDT) Date: Mon, 23 Oct 2023 23:46:43 +0000 In-Reply-To: <20231023-staging-pmbus-v3-v4-0-07a8cb7cd20a@google.com> Mime-Version: 1.0 References: <20231023-staging-pmbus-v3-v4-0-07a8cb7cd20a@google.com> X-Developer-Key: i=titusr@google.com; a=openpgp; fpr=228BD42BAD6A2BCD3865AEA6C41200175CD21E30 X-Developer-Signature: v=1; a=openpgp-sha256; l=1705; i=titusr@google.com; h=from:subject:message-id; bh=n97rpZwK0i4oWF9iNxYFr4kpVaKZTUXQ3O7PLD7S2I4=; b=owEB7QES/pANAwAKAcQSABdc0h4wAcsmYgBlNwXug+zQskA05Rb4QwH8fIdqaks9Hf3kb5U1f 5uQjCgfjrOJAbMEAAEKAB0WIQQii9QrrWorzThlrqbEEgAXXNIeMAUCZTcF7gAKCRDEEgAXXNIe MPTqDACmh+ROsnXlUogZ90xqoZu/8IRvuyeopZyW4yNBQcq6f8m/vY3R/b8ug/CT6DfTkLvq+hD wqR2jpAJEh4/mcSQs6iaBaAuHO3+aMq9TMhFQGlCo/cNO2G5ZssImmlPbftJ1HPip+cKcDH0nlW WbcGvj9td4pCSewLMx4Q9LZtXRBxay3pmOBuCdG9R92h5cKzmY2KoJYMMm807Wk4ixXqa2eLYYH VqqGIZqac6Hghzo/naU+3tUhEogZmpLd2M3M/z2rFEsCFERRDOoup/FmlKjCqEsLdrFwqshwf2i CGnMb+TY5nHztgahzoHsnCyUlKjTFotR5iq7AeD4l3SrAkeDwiSiNOJxF5paWPg4SrO/0oqCe5r QohyX3rPekeab3zTpkF8MyVtwqFEJnIPjyLFWpk7ecsfn71NcIOurmJelVjO1l8wjhCG272UUCj xw1xriOfxd1dwCWe/TLt1q0/1uHQy/wa2GN7wl6HzkH4u4qdWC+poEto2YfNMR1uobycY= X-Mailer: b4 0.12.2 Message-ID: <20231023-staging-pmbus-v3-v4-4-07a8cb7cd20a@google.com> Subject: [PATCH v4 4/8] hw/i2c: pmbus: add VCAP register From: titusr@google.com To: philmd@linaro.org, minyard@acm.org Cc: Titus Rwantare , qemu-arm@nongnu.org, qemu-devel@nongnu.org, Benjamin Streb , Corey Minyard Received-SPF: pass client-ip=2607:f8b0:4864:20::114a; envelope-from=39QU3ZQYKCg47w7865u22uzs.q204s08-rs9sz121u18.25u@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=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 VCAP is a register for devices with energy storage capacitors. Reviewed-by: Benjamin Streb Acked-by: Corey Minyard Signed-off-by: Titus Rwantare --- 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 c1d8c93056..3bce39e84e 100644 --- a/hw/i2c/pmbus_device.c +++ b/hw/i2c/pmbus_device.c @@ -906,6 +906,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) From patchwork Mon Oct 23 23:46:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13433720 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 1846DC00A8F for ; Mon, 23 Oct 2023 23:47:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qv4dY-0002sw-A6; Mon, 23 Oct 2023 19:47:08 -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 <39gU3ZQYKCg88x8976v33v0t.r315t19-stAt0232v29.36v@flex--titusr.bounces.google.com>) id 1qv4dW-0002rt-M8 for qemu-devel@nongnu.org; Mon, 23 Oct 2023 19:47:06 -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 <39gU3ZQYKCg88x8976v33v0t.r315t19-stAt0232v29.36v@flex--titusr.bounces.google.com>) id 1qv4dU-0002mr-4X for qemu-devel@nongnu.org; Mon, 23 Oct 2023 19:47:06 -0400 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9a5a16fa94so3915709276.0 for ; Mon, 23 Oct 2023 16:47:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698104822; x=1698709622; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=n111QpLYBiuxWwpTUsiNF5S0AAgW3sqw1k0fiUG1aKk=; b=POQCtCsNcNmFe7ZLdmqDOMrNnO/NfRoYg4sm/BdZ1tqNwCio1LiRNax+D+x/mggV6F 6Gt/dh+bnFukiMzyksNALXlIVqhXs/NX/vSJRICManocYBHHHOENF+aVO4C+o9zKbhKx T9xc6PMPH5Y+tnCuFbSV1Elhw9CfAd3Ik7FG4dtwhfIGrH1znpzp3uuIo9cknPHQypWp 35By+2CWOQFyMfA+KWWLZP9yj7EAbaIQ7f6bfVHC+8EfwToibYwvH32r8bu3AKPwoDyF xDBaIvPzS57sp5mOkdWEM5p1Su0gTWHn/n46b70FuKGeAU9pU4lKJEzxBYUJwFRhUwqs M7iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698104822; x=1698709622; 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=n111QpLYBiuxWwpTUsiNF5S0AAgW3sqw1k0fiUG1aKk=; b=C0laGejgaUF5AW9mZJ3CssBq6kRbin5U3ak5lBBJtEm9HKzYBu/21bQ/Z8O1bWtjoS 9TZsW2DcyN+5puo5GaGXSDPrErAUYYL6AkTjQPacOR3/m43G37bx45BnMrfO6IsDx9PX TM8G3KYYkdIn9CJlwjkRymNtTKO5KFVNbzGxb0SOvoney4cwzk10ETDyTCF44zxsVsS1 2qoo1xBI6p7mDfR95lPT4mKcISXyKnZyNn1TrAGCtnwVdT53W+Zmm0x2PfoGJClpHSOx btUu/Dj7/bVjnrVQKTLt5FpxjjyEgJfxIwSnryCS8i8S5lEWHRTfX7Zjhz55NnswQBtz lGSA== X-Gm-Message-State: AOJu0YxbxNszstskj24G1uxgOSPr41Bxc0sxu+5WlKvnd/55//0RMsqu dZpIyjTGCZh110FX99TC2FLGo9ltBKw= X-Google-Smtp-Source: AGHT+IH3igAjOEs/kYIdKlzH56MFdnTk900XgJ9kne4X48Q6+9dxr1I0cP1t/wllgqYygSFVbsgBCx3CiSo= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:22b8]) (user=titusr job=sendgmr) by 2002:a25:fc20:0:b0:d89:42d7:e72d with SMTP id v32-20020a25fc20000000b00d8942d7e72dmr362043ybd.3.1698104822610; Mon, 23 Oct 2023 16:47:02 -0700 (PDT) Date: Mon, 23 Oct 2023 23:46:44 +0000 In-Reply-To: <20231023-staging-pmbus-v3-v4-0-07a8cb7cd20a@google.com> Mime-Version: 1.0 References: <20231023-staging-pmbus-v3-v4-0-07a8cb7cd20a@google.com> X-Developer-Key: i=titusr@google.com; a=openpgp; fpr=228BD42BAD6A2BCD3865AEA6C41200175CD21E30 X-Developer-Signature: v=1; a=openpgp-sha256; l=10300; i=titusr@google.com; h=from:subject:message-id; bh=Pvp88ipg4wcQkca0LNqgx1eKliwgonl8N8UN0HK+lbA=; b=owEB7QES/pANAwAKAcQSABdc0h4wAcsmYgBlNwXuePa9xpXCH/ST7bsMs54GMg0wk0f8+ZB0o ACAB+s5El+JAbMEAAEKAB0WIQQii9QrrWorzThlrqbEEgAXXNIeMAUCZTcF7gAKCRDEEgAXXNIe MOePC/0UAxd70rwS5JqB+nLqUc8T6FvS9ICMhMAico+y0n3VfnqAWbLKf8x+G58giZZW8YA3fDZ AxRPQi3RS0LhQlClswOC6oLk2vHktNQgyrMLbl6M9R134mBV3cHH5d8AqD24YEyBAZLd5onClSq foZbGjm5AGOsPtvAUAfbhBo9q4nJOpMrBloZud+44PJ4LfQXshh/n+OMjqIc4e2kPxH+yj8ajfz X/GgXjn6L+l+sAFGIycN8zSfXBC+muP8s8AqLW51jqcaKLtdDBZzRXN6VBkNMunU081Y/HH1UYe ynXJM92h8T/ECpWRDuhuOKNXU4YtI8Rhs6HT+y7NswM/Vmm6XY2ejC1NwmTfzClvpFfq7Gmet5Q 12ieZ0ooPH7bMF/yBfpp1Eik1ll6Cdk2wZbR/3zgd/bpmKi7wkfBbiKTaIFy9o9o/cfvVERR8w4 /sGEdcm9rWbw+7dqAZ/1UbaqdD9B6U2SCovO31vO0RDTprSmiZt/j7/+UC4Ie9dr0cZM4= X-Mailer: b4 0.12.2 Message-ID: <20231023-staging-pmbus-v3-v4-5-07a8cb7cd20a@google.com> Subject: [PATCH v4 5/8] hw/sensor: add ADM1266 device model From: titusr@google.com To: philmd@linaro.org, minyard@acm.org Cc: Titus Rwantare , qemu-arm@nongnu.org, qemu-devel@nongnu.org, Hao Wu , Corey Minyard Received-SPF: pass client-ip=2607:f8b0:4864:20::b49; envelope-from=39gU3ZQYKCg88x8976v33v0t.r315t19-stAt0232v29.36v@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 The ADM1266 is a cascadable super sequencer with margin control and fault recording. This commit adds basic support for its PMBus commands and models the identification registers that can be modified in a firmware update. Reviewed-by: Hao Wu Acked-by: Corey Minyard Signed-off-by: Titus Rwantare --- hw/arm/Kconfig | 1 + hw/sensor/Kconfig | 5 + hw/sensor/adm1266.c | 254 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/sensor/meson.build | 1 + 4 files changed, 261 insertions(+) diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 7e68348440..b1e8c0e2ac 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -488,6 +488,7 @@ config NPCM7XX default y depends on TCG && ARM select A9MPCORE + select ADM1266 select ADM1272 select ARM_GIC select SMBUS diff --git a/hw/sensor/Kconfig b/hw/sensor/Kconfig index e03bd09b50..bc6331b4ab 100644 --- a/hw/sensor/Kconfig +++ b/hw/sensor/Kconfig @@ -22,6 +22,11 @@ config ADM1272 bool depends on I2C +config ADM1266 + bool + depends on PMBUS + default y if PMBUS + config MAX34451 bool depends on I2C diff --git a/hw/sensor/adm1266.c b/hw/sensor/adm1266.c new file mode 100644 index 0000000000..5ae4f82ba1 --- /dev/null +++ b/hw/sensor/adm1266.c @@ -0,0 +1,254 @@ +/* + * Analog Devices ADM1266 Cascadable Super Sequencer with Margin Control and + * Fault Recording with PMBus + * + * https://www.analog.com/media/en/technical-documentation/data-sheets/adm1266.pdf + * + * Copyright 2023 Google LLC + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/i2c/pmbus_device.h" +#include "hw/irq.h" +#include "migration/vmstate.h" +#include "qapi/error.h" +#include "qapi/visitor.h" +#include "qemu/log.h" +#include "qemu/module.h" + +#define TYPE_ADM1266 "adm1266" +OBJECT_DECLARE_SIMPLE_TYPE(ADM1266State, ADM1266) + +#define ADM1266_BLACKBOX_CONFIG 0xD3 +#define ADM1266_PDIO_CONFIG 0xD4 +#define ADM1266_READ_STATE 0xD9 +#define ADM1266_READ_BLACKBOX 0xDE +#define ADM1266_SET_RTC 0xDF +#define ADM1266_GPIO_SYNC_CONFIGURATION 0xE1 +#define ADM1266_BLACKBOX_INFORMATION 0xE6 +#define ADM1266_PDIO_STATUS 0xE9 +#define ADM1266_GPIO_STATUS 0xEA + +/* Defaults */ +#define ADM1266_OPERATION_DEFAULT 0x80 +#define ADM1266_CAPABILITY_DEFAULT 0xA0 +#define ADM1266_CAPABILITY_NO_PEC 0x20 +#define ADM1266_PMBUS_REVISION_DEFAULT 0x22 +#define ADM1266_MFR_ID_DEFAULT "ADI" +#define ADM1266_MFR_ID_DEFAULT_LEN 32 +#define ADM1266_MFR_MODEL_DEFAULT "ADM1266-A1" +#define ADM1266_MFR_MODEL_DEFAULT_LEN 32 +#define ADM1266_MFR_REVISION_DEFAULT "25" +#define ADM1266_MFR_REVISION_DEFAULT_LEN 8 + +#define ADM1266_NUM_PAGES 17 +/** + * PAGE Index + * Page 0 VH1. + * Page 1 VH2. + * Page 2 VH3. + * Page 3 VH4. + * Page 4 VP1. + * Page 5 VP2. + * Page 6 VP3. + * Page 7 VP4. + * Page 8 VP5. + * Page 9 VP6. + * Page 10 VP7. + * Page 11 VP8. + * Page 12 VP9. + * Page 13 VP10. + * Page 14 VP11. + * Page 15 VP12. + * Page 16 VP13. + */ +typedef struct ADM1266State { + PMBusDevice parent; + + char mfr_id[32]; + char mfr_model[32]; + char mfr_rev[8]; +} ADM1266State; + +static const uint8_t adm1266_ic_device_id[] = {0x03, 0x41, 0x12, 0x66}; +static const uint8_t adm1266_ic_device_rev[] = {0x08, 0x01, 0x08, 0x07, 0x0, + 0x0, 0x07, 0x41, 0x30}; + +static void adm1266_exit_reset(Object *obj) +{ + ADM1266State *s = ADM1266(obj); + PMBusDevice *pmdev = PMBUS_DEVICE(obj); + + pmdev->page = 0; + pmdev->capability = ADM1266_CAPABILITY_NO_PEC; + + for (int i = 0; i < ADM1266_NUM_PAGES; i++) { + pmdev->pages[i].operation = ADM1266_OPERATION_DEFAULT; + pmdev->pages[i].revision = ADM1266_PMBUS_REVISION_DEFAULT; + pmdev->pages[i].vout_mode = 0; + pmdev->pages[i].read_vout = pmbus_data2linear_mode(12, 0); + pmdev->pages[i].vout_margin_high = pmbus_data2linear_mode(15, 0); + pmdev->pages[i].vout_margin_low = pmbus_data2linear_mode(3, 0); + pmdev->pages[i].vout_ov_fault_limit = pmbus_data2linear_mode(16, 0); + pmdev->pages[i].revision = ADM1266_PMBUS_REVISION_DEFAULT; + } + + strncpy(s->mfr_id, ADM1266_MFR_ID_DEFAULT, 4); + strncpy(s->mfr_model, ADM1266_MFR_MODEL_DEFAULT, 11); + strncpy(s->mfr_rev, ADM1266_MFR_REVISION_DEFAULT, 3); +} + +static uint8_t adm1266_read_byte(PMBusDevice *pmdev) +{ + ADM1266State *s = ADM1266(pmdev); + + switch (pmdev->code) { + case PMBUS_MFR_ID: /* R/W block */ + pmbus_send_string(pmdev, s->mfr_id); + break; + + case PMBUS_MFR_MODEL: /* R/W block */ + pmbus_send_string(pmdev, s->mfr_model); + break; + + case PMBUS_MFR_REVISION: /* R/W block */ + pmbus_send_string(pmdev, s->mfr_rev); + break; + + case PMBUS_IC_DEVICE_ID: + pmbus_send(pmdev, adm1266_ic_device_id, sizeof(adm1266_ic_device_id)); + break; + + case PMBUS_IC_DEVICE_REV: + pmbus_send(pmdev, adm1266_ic_device_rev, sizeof(adm1266_ic_device_rev)); + break; + + default: + qemu_log_mask(LOG_UNIMP, + "%s: reading from unimplemented register: 0x%02x\n", + __func__, pmdev->code); + return 0xFF; + } + + return 0; +} + +static int adm1266_write_data(PMBusDevice *pmdev, const uint8_t *buf, + uint8_t len) +{ + ADM1266State *s = ADM1266(pmdev); + + switch (pmdev->code) { + case PMBUS_MFR_ID: /* R/W block */ + pmbus_receive_block(pmdev, (uint8_t *)s->mfr_id, sizeof(s->mfr_id)); + break; + + case PMBUS_MFR_MODEL: /* R/W block */ + pmbus_receive_block(pmdev, (uint8_t *)s->mfr_model, + sizeof(s->mfr_model)); + break; + + case PMBUS_MFR_REVISION: /* R/W block*/ + pmbus_receive_block(pmdev, (uint8_t *)s->mfr_rev, sizeof(s->mfr_rev)); + break; + + case ADM1266_SET_RTC: /* do nothing */ + break; + + default: + qemu_log_mask(LOG_UNIMP, + "%s: writing to unimplemented register: 0x%02x\n", + __func__, pmdev->code); + break; + } + return 0; +} + +static void adm1266_get(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) +{ + uint16_t value; + PMBusDevice *pmdev = PMBUS_DEVICE(obj); + PMBusVoutMode *mode = (PMBusVoutMode *)&pmdev->pages[0].vout_mode; + + if (strcmp(name, "vout") == 0) { + value = pmbus_linear_mode2data(*(uint16_t *)opaque, mode->exp); + } else { + value = *(uint16_t *)opaque; + } + + visit_type_uint16(v, name, &value, errp); +} + +static void adm1266_set(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) +{ + uint16_t *internal = opaque; + uint16_t value; + PMBusDevice *pmdev = PMBUS_DEVICE(obj); + PMBusVoutMode *mode = (PMBusVoutMode *)&pmdev->pages[0].vout_mode; + + if (!visit_type_uint16(v, name, &value, errp)) { + return; + } + + *internal = pmbus_data2linear_mode(value, mode->exp); + pmbus_check_limits(pmdev); +} + +static const VMStateDescription vmstate_adm1266 = { + .name = "ADM1266", + .version_id = 0, + .minimum_version_id = 0, + .fields = (VMStateField[]){ + VMSTATE_PMBUS_DEVICE(parent, ADM1266State), + VMSTATE_END_OF_LIST() + } +}; + +static void adm1266_init(Object *obj) +{ + PMBusDevice *pmdev = PMBUS_DEVICE(obj); + uint64_t flags = PB_HAS_VOUT_MODE | PB_HAS_VOUT | PB_HAS_VOUT_MARGIN | + PB_HAS_VOUT_RATING | PB_HAS_STATUS_MFR_SPECIFIC; + + for (int i = 0; i < ADM1266_NUM_PAGES; i++) { + pmbus_page_config(pmdev, i, flags); + + object_property_add(obj, "vout[*]", "uint16", + adm1266_get, + adm1266_set, NULL, &pmdev->pages[i].read_vout); + } +} + +static void adm1266_class_init(ObjectClass *klass, void *data) +{ + ResettableClass *rc = RESETTABLE_CLASS(klass); + DeviceClass *dc = DEVICE_CLASS(klass); + PMBusDeviceClass *k = PMBUS_DEVICE_CLASS(klass); + + dc->desc = "Analog Devices ADM1266 Hot Swap controller"; + dc->vmsd = &vmstate_adm1266; + k->write_data = adm1266_write_data; + k->receive_byte = adm1266_read_byte; + k->device_num_pages = 17; + + rc->phases.exit = adm1266_exit_reset; +} + +static const TypeInfo adm1266_info = { + .name = TYPE_ADM1266, + .parent = TYPE_PMBUS_DEVICE, + .instance_size = sizeof(ADM1266State), + .instance_init = adm1266_init, + .class_init = adm1266_class_init, +}; + +static void adm1266_register_types(void) +{ + type_register_static(&adm1266_info); +} + +type_init(adm1266_register_types) diff --git a/hw/sensor/meson.build b/hw/sensor/meson.build index 30e20e27b8..420fdc3359 100644 --- a/hw/sensor/meson.build +++ b/hw/sensor/meson.build @@ -2,6 +2,7 @@ system_ss.add(when: 'CONFIG_TMP105', if_true: files('tmp105.c')) system_ss.add(when: 'CONFIG_TMP421', if_true: files('tmp421.c')) system_ss.add(when: 'CONFIG_DPS310', if_true: files('dps310.c')) system_ss.add(when: 'CONFIG_EMC141X', if_true: files('emc141x.c')) +system_ss.add(when: 'CONFIG_ADM1266', if_true: files('adm1266.c')) system_ss.add(when: 'CONFIG_ADM1272', if_true: files('adm1272.c')) system_ss.add(when: 'CONFIG_MAX34451', if_true: files('max34451.c')) system_ss.add(when: 'CONFIG_LSM303DLHC_MAG', if_true: files('lsm303dlhc_mag.c')) From patchwork Mon Oct 23 23:46:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13433722 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 C9DEBC00A8F for ; Mon, 23 Oct 2023 23:48:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qv4dY-0002tB-EN; Mon, 23 Oct 2023 19:47:08 -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 <39wU3ZQYKChA9y9A87w44w1u.s426u2A-tuBu1343w3A.47w@flex--titusr.bounces.google.com>) id 1qv4dX-0002sU-2L for qemu-devel@nongnu.org; Mon, 23 Oct 2023 19:47:07 -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 <39wU3ZQYKChA9y9A87w44w1u.s426u2A-tuBu1343w3A.47w@flex--titusr.bounces.google.com>) id 1qv4dV-0002ob-9Z for qemu-devel@nongnu.org; Mon, 23 Oct 2023 19:47:06 -0400 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5abfa4c10c4so18806587b3.0 for ; Mon, 23 Oct 2023 16:47:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698104823; x=1698709623; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=57kge/OAmHbKAwBdnvGQrFdCdcxs8q+3+0ck+IJJcuA=; b=gtvZ5onV9KpTHCG6lVIo0/lmHP2pa7FtBir0RUHjuJyNuh6Y+CDdo5KoUSVib1UWHo nFLLMlWccnKwvfx0Xpz2ftBh5O0HkelauiMulmT1YsxjGpM7MVwAPyJrxPeUTTrwDDwN 7mm86OJ86CLRzKPCkLr/m4fcR+lixTsuPnAt+F6Q3zTkyA8CEDcZuePwOnXM4zNnuVIy B2M9bgs03p3/NOpLyJzLOt9OVE0Ds7RIsrtIYFfoEMPs4+8cLk089Vhd33+gVPi8nOSJ FzdgcJBrNAsU9gyj+SJZWhyK3w3PRCoEnApfVDljXS1k22L9mzhM6f26UvtFmPgPXpNU v6Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698104823; x=1698709623; 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=57kge/OAmHbKAwBdnvGQrFdCdcxs8q+3+0ck+IJJcuA=; b=SA8DJ7ZUWa6bBYKL1Up5xUFDTXirCdIW7rG3Gmr8UWKmpk5298Ghiv0P0wND7vzL6d 9cHIk7jptiOup4HwHdYDLpb0wOfVRdG7v1ZLuv3wbm1lm9fwRdCFQ+DDdgNwWr+uMqLO fSCkyXKQAcAFbKYLKT2BtfsaKXkK8nvDUiHJTF/dfRrty2thEMteUXk6IV+w+t//pm1J X3AmMa02J6wGWAJD/VvCOe4bJIFgZ1bWAIbKVp0LlNw2gu2DhAd/lvQrXdYh+cvslJrs KvGhBjEHFUNGvt+KBaxmBQ6Xp/mgcv+N1fs7aI1mxq8YOO7C1izWgMXuMenHK9XrOEx+ KkaA== X-Gm-Message-State: AOJu0YzalBDzjzqzw2wA+c2If0M5o5620db7nQiGO+p2rs1RmG7go4IZ mJI0XG5vWU+pBWHi+5oJBNwgB1rpdC4= X-Google-Smtp-Source: AGHT+IGGoIFvDVK9amsstFW7sBHao9wiqaM0KtVi8dIvqpDa6XS9Vs3aOEfjCLZKcMYSLmO8DpQpLkiNrQo= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:22b8]) (user=titusr job=sendgmr) by 2002:a0d:d486:0:b0:5a8:6162:b69 with SMTP id w128-20020a0dd486000000b005a861620b69mr239049ywd.3.1698104823542; Mon, 23 Oct 2023 16:47:03 -0700 (PDT) Date: Mon, 23 Oct 2023 23:46:45 +0000 In-Reply-To: <20231023-staging-pmbus-v3-v4-0-07a8cb7cd20a@google.com> Mime-Version: 1.0 References: <20231023-staging-pmbus-v3-v4-0-07a8cb7cd20a@google.com> X-Developer-Key: i=titusr@google.com; a=openpgp; fpr=228BD42BAD6A2BCD3865AEA6C41200175CD21E30 X-Developer-Signature: v=1; a=openpgp-sha256; l=5481; i=titusr@google.com; h=from:subject:message-id; bh=BnRnug81IWlhfXo1CDxHzzk6FRAPzK5+qz/WkzSPoe0=; b=owEB7QES/pANAwAKAcQSABdc0h4wAcsmYgBlNwXvuSFuqGcnlaTaTfBFDvySr3LmDWMp115W4 fdzK3mqpYmJAbMEAAEKAB0WIQQii9QrrWorzThlrqbEEgAXXNIeMAUCZTcF7wAKCRDEEgAXXNIe MA+4C/kBS8SL7b7POdCA5lf94RC4aejgVt9daAZoEIGtuljrmRfswoT2yxlog3olz6AlVqAK7dl woeJxMwm0noxEp+t+4kcUWG4g4wakzPFxQ+s9xTdY9Y7LAXZQjTON4Y56N2kkY9zc2nAh9pr+Bt 2RVIKRtFYvS030wfGyc7tTqtY6qg5hRJaejJx8RqG/PnFCIb6Q68xIQjek1S30eqVI2AYpRWRvU CQ8+xilT85sbrysCFGs38C6uw/aXugwtq2eVMmR1LMKYV/BMAHQkMhrOEauytakNS+jvnwSPT6m euYwdBY7LW8DRq3PysT6DaaMVHhpqO+eouqZBNqVl5kgpIsom8nGaM/i+cmn0Ar/XVCOwa0v4TJ XtLvwAVI06pOLgyT5tOi36XncrEPlew+eRKEJyo5vhUKK7EoF1uZnmDP6BGgOjDZWsv1kGZp2XL Sug3G+NwJ5TXGcb+UO7viHPqPVMdaPhhPIliKaVwzjinm1Gkcb/xDETXhN0uR6LQDZNPA= X-Mailer: b4 0.12.2 Message-ID: <20231023-staging-pmbus-v3-v4-6-07a8cb7cd20a@google.com> Subject: [PATCH v4 6/8] tests/qtest: add tests for ADM1266 From: titusr@google.com To: philmd@linaro.org, minyard@acm.org Cc: Titus Rwantare , qemu-arm@nongnu.org, qemu-devel@nongnu.org, Hao Wu , Corey Minyard Received-SPF: pass client-ip=2607:f8b0:4864:20::114a; envelope-from=39wU3ZQYKChA9y9A87w44w1u.s426u2A-tuBu1343w3A.47w@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=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 The ADM1266 can have string fields written by the driver, so it's worth specifically testing. Reviewed-by: Hao Wu Acked-by: Corey Minyard Signed-off-by: Titus Rwantare --- tests/qtest/adm1266-test.c | 123 +++++++++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 1 + 2 files changed, 124 insertions(+) diff --git a/tests/qtest/adm1266-test.c b/tests/qtest/adm1266-test.c new file mode 100644 index 0000000000..6431a21de6 --- /dev/null +++ b/tests/qtest/adm1266-test.c @@ -0,0 +1,123 @@ +/* + * Analog Devices ADM1266 Cascadable Super Sequencer with Margin Control and + * Fault Recording with PMBus + * + * Copyright 2022 Google LLC + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include +#include "hw/i2c/pmbus_device.h" +#include "libqtest-single.h" +#include "libqos/qgraph.h" +#include "libqos/i2c.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qnum.h" +#include "qemu/bitops.h" + +#define TEST_ID "adm1266-test" +#define TEST_ADDR (0x12) + +#define ADM1266_BLACKBOX_CONFIG 0xD3 +#define ADM1266_PDIO_CONFIG 0xD4 +#define ADM1266_READ_STATE 0xD9 +#define ADM1266_READ_BLACKBOX 0xDE +#define ADM1266_SET_RTC 0xDF +#define ADM1266_GPIO_SYNC_CONFIGURATION 0xE1 +#define ADM1266_BLACKBOX_INFORMATION 0xE6 +#define ADM1266_PDIO_STATUS 0xE9 +#define ADM1266_GPIO_STATUS 0xEA + +/* Defaults */ +#define ADM1266_OPERATION_DEFAULT 0x80 +#define ADM1266_CAPABILITY_DEFAULT 0xA0 +#define ADM1266_CAPABILITY_NO_PEC 0x20 +#define ADM1266_PMBUS_REVISION_DEFAULT 0x22 +#define ADM1266_MFR_ID_DEFAULT "ADI" +#define ADM1266_MFR_ID_DEFAULT_LEN 32 +#define ADM1266_MFR_MODEL_DEFAULT "ADM1266-A1" +#define ADM1266_MFR_MODEL_DEFAULT_LEN 32 +#define ADM1266_MFR_REVISION_DEFAULT "25" +#define ADM1266_MFR_REVISION_DEFAULT_LEN 8 +#define TEST_STRING_A "a sample" +#define TEST_STRING_B "b sample" +#define TEST_STRING_C "rev c" + +static void compare_string(QI2CDevice *i2cdev, uint8_t reg, + const char *test_str) +{ + uint8_t len = i2c_get8(i2cdev, reg); + char i2c_str[SMBUS_DATA_MAX_LEN] = {0}; + + i2c_read_block(i2cdev, reg, (uint8_t *)i2c_str, len); + g_assert_cmpstr(i2c_str, ==, test_str); +} + +static void write_and_compare_string(QI2CDevice *i2cdev, uint8_t reg, + const char *test_str, uint8_t len) +{ + char buf[SMBUS_DATA_MAX_LEN] = {0}; + buf[0] = len; + strncpy(buf + 1, test_str, len); + i2c_write_block(i2cdev, reg, (uint8_t *)buf, len + 1); + compare_string(i2cdev, reg, test_str); +} + +static void test_defaults(void *obj, void *data, QGuestAllocator *alloc) +{ + uint16_t i2c_value; + QI2CDevice *i2cdev = (QI2CDevice *)obj; + + i2c_value = i2c_get8(i2cdev, PMBUS_OPERATION); + g_assert_cmphex(i2c_value, ==, ADM1266_OPERATION_DEFAULT); + + i2c_value = i2c_get8(i2cdev, PMBUS_REVISION); + g_assert_cmphex(i2c_value, ==, ADM1266_PMBUS_REVISION_DEFAULT); + + compare_string(i2cdev, PMBUS_MFR_ID, ADM1266_MFR_ID_DEFAULT); + compare_string(i2cdev, PMBUS_MFR_MODEL, ADM1266_MFR_MODEL_DEFAULT); + compare_string(i2cdev, PMBUS_MFR_REVISION, ADM1266_MFR_REVISION_DEFAULT); +} + +/* test r/w registers */ +static void test_rw_regs(void *obj, void *data, QGuestAllocator *alloc) +{ + QI2CDevice *i2cdev = (QI2CDevice *)obj; + + /* empty strings */ + i2c_set8(i2cdev, PMBUS_MFR_ID, 0); + compare_string(i2cdev, PMBUS_MFR_ID, ""); + + i2c_set8(i2cdev, PMBUS_MFR_MODEL, 0); + compare_string(i2cdev, PMBUS_MFR_MODEL, ""); + + i2c_set8(i2cdev, PMBUS_MFR_REVISION, 0); + compare_string(i2cdev, PMBUS_MFR_REVISION, ""); + + /* test strings */ + write_and_compare_string(i2cdev, PMBUS_MFR_ID, TEST_STRING_A, + sizeof(TEST_STRING_A)); + write_and_compare_string(i2cdev, PMBUS_MFR_ID, TEST_STRING_B, + sizeof(TEST_STRING_B)); + write_and_compare_string(i2cdev, PMBUS_MFR_ID, TEST_STRING_C, + sizeof(TEST_STRING_C)); +} + +static void adm1266_register_nodes(void) +{ + QOSGraphEdgeOptions opts = { + .extra_device_opts = "id=" TEST_ID ",address=0x12" + }; + add_qi2c_address(&opts, &(QI2CAddress) { TEST_ADDR }); + + qos_node_create_driver("adm1266", i2c_device_create); + qos_node_consumes("adm1266", "i2c-bus", &opts); + + qos_add_test("test_defaults", "adm1266", test_defaults, NULL); + qos_add_test("test_rw_regs", "adm1266", test_rw_regs, NULL); +} + +libqos_init(adm1266_register_nodes); + diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index d6022ebd64..7899537e78 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -241,6 +241,7 @@ qos_test_ss = ss.source_set() qos_test_ss.add( 'ac97-test.c', 'adm1272-test.c', + 'adm1266-test.c', 'ds1338-test.c', 'e1000-test.c', 'eepro100-test.c', From patchwork Mon Oct 23 23:46:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13433721 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 053A0C25B67 for ; Mon, 23 Oct 2023 23:48:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qv4dZ-0002u7-PH; Mon, 23 Oct 2023 19:47:09 -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 <3-AU3ZQYKChEAzAB98x55x2v.t537v3B-uvCv2454x4B.58x@flex--titusr.bounces.google.com>) id 1qv4dY-0002sz-9I for qemu-devel@nongnu.org; Mon, 23 Oct 2023 19:47:08 -0400 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3-AU3ZQYKChEAzAB98x55x2v.t537v3B-uvCv2454x4B.58x@flex--titusr.bounces.google.com>) id 1qv4dW-0002p6-FP for qemu-devel@nongnu.org; Mon, 23 Oct 2023 19:47:08 -0400 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a92864859bso32973777b3.0 for ; Mon, 23 Oct 2023 16:47:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698104825; x=1698709625; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=i3S/ucLUb2EnGxNEuiqhEsJ4HDduUunH8ndOA8IP8mU=; b=zh2wS9vog9psef1WyMHgQ5/kFub43Bg4nWpN6UCjbPqcdY7g1p1JOVX0wx391NxLEG TATTcx7OAVbpxzq3zdPMb5Kf7IIYE1AZ/+oowpXMVFwzlEWmpe4zrSUA+fXbev6duEwd 5+Zx/UXQcpaZIleBnN7v9zqsNEc4WeNhKwAGLcPIXHyvzs98D5g3s+t3RCb1T3TXxl+d t/XGaStB7ckh8TunNIWFH5StdncPi9geRRBDFYRGWQZcyCoVYeO52qoWLDCpFGzcrymT ewyUnrxgiPqI11o3a4m/tRRTS/NoGQzJeYdBIff7vX9PY2KD6sEj99DR6hAjsqwdnQqd oHcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698104825; x=1698709625; 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=i3S/ucLUb2EnGxNEuiqhEsJ4HDduUunH8ndOA8IP8mU=; b=sq9HQReHVWjGiZB7zBMK0GRznSnVciSyHl/KiB3ciwLPRs1YLQAm9P571Z0gOKXFKQ N4C/w2ID+HCFqNOkuz0buhXyD4vzuMAG3s7XKHJuUvwZUrNyYpEhV8ZwegaKp1t6VFIX VTyHAz0kKYGqZ9K98FNrFgbeu+WM9X+6jlw+/rB5daDKQjQvWTTp9S3fFxfgwpU0Avez u1j7DZFw6KoPKqnAEbzYoDVxViyZZmoi2OhC3pO+gQGSFfFGcraKDMYbBHYf/rzhDy1x zCURgWDuqz6g+K3+QudUwC00f1x63t+immRUijo8N13d9WF3FrnpEc2leLnasJWGjfqh 679g== X-Gm-Message-State: AOJu0YyTGMwZLtSWNgVmd01TV88j87mMgmaMdZq5ItN/Ugm+PAAl59Bp nnJfn/xv6o6UYHl0lkFYtj5/SqGg6ws= X-Google-Smtp-Source: AGHT+IHoTKAXXfHoAs81t7qGgF7M/9iLRdfsK2C/0ZRJPaaOctQDqlfi8R/6Zar1GTi5qyEHrNKRS3m7iF8= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:22b8]) (user=titusr job=sendgmr) by 2002:a81:9150:0:b0:592:7bc7:b304 with SMTP id i77-20020a819150000000b005927bc7b304mr229293ywg.8.1698104824868; Mon, 23 Oct 2023 16:47:04 -0700 (PDT) Date: Mon, 23 Oct 2023 23:46:46 +0000 In-Reply-To: <20231023-staging-pmbus-v3-v4-0-07a8cb7cd20a@google.com> Mime-Version: 1.0 References: <20231023-staging-pmbus-v3-v4-0-07a8cb7cd20a@google.com> X-Developer-Key: i=titusr@google.com; a=openpgp; fpr=228BD42BAD6A2BCD3865AEA6C41200175CD21E30 X-Developer-Signature: v=1; a=openpgp-sha256; l=923; i=titusr@google.com; h=from:subject:message-id; bh=F4m2MZ4pwdghWvz/7slFyNSaLFtYH8k3ZV6OH4454yM=; b=owEB7QES/pANAwAKAcQSABdc0h4wAcsmYgBlNwXv+QWP7q7WWM4S6eFZaUTPqOaKKAKE2UGBE SztF6QPQBSJAbMEAAEKAB0WIQQii9QrrWorzThlrqbEEgAXXNIeMAUCZTcF7wAKCRDEEgAXXNIe MFQTC/0dgaa2odAP+quGOBcpc+CEWqAuKpIrSJLIQP+EA7A1y6Wuz99yLdB/FKUgxHMV3570IMB P3u2YEq567vNdD331VzjhzYvtNbXVZWnRMqmw+nmZPvyrPK9CiTfnW9cLp0CgoSMIM2SAs6mLLp tSOXYD//4cM4IMvjzv3ckwU98S/51ig1ZOdC4nkPE93tNvmhJNLo6+bLpzPOnLiJ768fMFNxFl/ yw7bdU20JFCQcMA1TEu51fQfaKl/veD9KSYf/QnVfkHOCEP5lkzuDGd+thhmLC7zFIu1x1kLt65 DjDDgpMn3b254F2zjoUa5qhYE6Uz2UCprIc0tVN1pxKw7BOPm/CM/oJiT5QUsfP8llGenZMJVQI ZodC7DmgxcNAmOW29Z6L6siS1Z1O5WoBJAUR68Uyb65OvTGvLuy6mN1eBr3NUsOwinCEZV3mQU/ wA43Lo+2P4hWrcskGvMyQc+8Yv8DHQhh/8QCRP/46M6+DcRbronmVM50M+WcWXvYLg0+Y= X-Mailer: b4 0.12.2 Message-ID: <20231023-staging-pmbus-v3-v4-7-07a8cb7cd20a@google.com> Subject: [PATCH v4 7/8] hw/i2c: pmbus: immediately clear faults on request From: titusr@google.com To: philmd@linaro.org, minyard@acm.org Cc: Titus Rwantare , qemu-arm@nongnu.org, qemu-devel@nongnu.org, Patrick Venture Received-SPF: pass client-ip=2607:f8b0:4864:20::1149; envelope-from=3-AU3ZQYKChEAzAB98x55x2v.t537v3B-uvCv2454x4B.58x@flex--titusr.bounces.google.com; helo=mail-yw1-x1149.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 The probing process of the generic pmbus driver generates faults to determine if functions are available. These faults were not always cleared resulting in probe failures. Reviewed-by: Patrick Venture Signed-off-by: Titus Rwantare --- hw/i2c/pmbus_device.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/i2c/pmbus_device.c b/hw/i2c/pmbus_device.c index 3bce39e84e..481e158380 100644 --- a/hw/i2c/pmbus_device.c +++ b/hw/i2c/pmbus_device.c @@ -1244,6 +1244,11 @@ static int pmbus_write_data(SMBusDevice *smd, uint8_t *buf, uint8_t len) pmdev->in_buf = buf; pmdev->code = buf[0]; /* PMBus command code */ + + if (pmdev->code == PMBUS_CLEAR_FAULTS) { + pmbus_clear_faults(pmdev); + } + if (len == 1) { /* Single length writes are command codes only */ return 0; } From patchwork Mon Oct 23 23:46:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13433728 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 92339C25B6B for ; Mon, 23 Oct 2023 23:48:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qv4da-0002v6-Iz; Mon, 23 Oct 2023 19:47:10 -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 <3-QU3ZQYKChIB0BCA9y66y3w.u648w4C-vwDw3565y5C.69y@flex--titusr.bounces.google.com>) id 1qv4dZ-0002tv-Bt for qemu-devel@nongnu.org; Mon, 23 Oct 2023 19:47:09 -0400 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3-QU3ZQYKChIB0BCA9y66y3w.u648w4C-vwDw3565y5C.69y@flex--titusr.bounces.google.com>) id 1qv4dX-0002pI-7G for qemu-devel@nongnu.org; Mon, 23 Oct 2023 19:47:09 -0400 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a818c1d2c7so55549857b3.0 for ; Mon, 23 Oct 2023 16:47:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698104826; x=1698709626; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Xq4TevC7P2TtGIT4OtRznC6qcO/COLeRy1+0zTFpX8g=; b=QSinNoxCcad1UFJtGBut1CFkz8mjJSy0c8UyB5VLh1O3Ej53ojcNsv7L7YRYtSqibL PDQrq7WiH6jx4rvJqcf84hslv4Fb1QYb48BimncRymoHY5UembjyttExB+ioxNw8oY2e US3js6e4wdXGQESjongGKoWWyaETrhUYXfeD4tgE4xwG9W77NdW9idxJFpVHgU5Il+FS OG24cSj1RkJ2y2XyZVp0X5aSVkkW/23A+eE0gUWAVR8IH9KR69M7lqiNuaYdOeUjfp4f E8ztBesQUHrz5lO98fnb3thTQSxpaLSxUBne8Lp6v4I/zAgsn2vJiPILWcV95pd7h1F8 e7rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698104826; x=1698709626; 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=Xq4TevC7P2TtGIT4OtRznC6qcO/COLeRy1+0zTFpX8g=; b=uIWo12BAl/zYiU4k2Fe44Dxmb3prPw4bxGwbfNYlWuKeHGb2TSfmSncRj2QW2sW37Z ktgPLOyzGcoENw1TokB/cMn+LmisXPWMRtfQuw2QzvOTGj20wxhfHowoV/Iu5xjEgI5g Utjb68FEELug7V7gOPIolQzOZ7BzKyC96/jlBMiQUxIIt45k/CkIe8VS+2aAZNqsTtfA pqx2W3Z4X85VLckTaJt3vmmiACT7nYWjo9AUrf3h6F6gYeE7zXgLRxn/kddBLoq31sb/ 9qtKI8BhGuNCnfx2esvKaCvBZ5xKq2wmf2M/lXaxeYmXjhyluDcolS2fpO//z8X0SNS5 7Yuw== X-Gm-Message-State: AOJu0YyD/wIQsjyEP5Bzrn1OpMTCiPJf0fb/xKMuzB770BOYw26aOpgl KzF4+VdfmFPZgzEbCRgytwy4NgPekhU= X-Google-Smtp-Source: AGHT+IE5Qoy4GD6iSUUJIIoBZW66Km80SNORck09iqaqDKqvgncSvWU3fsQSoltdV7IvI6VIhnj9mzyRk9k= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:22b8]) (user=titusr job=sendgmr) by 2002:a0d:dd10:0:b0:577:619e:d3c9 with SMTP id g16-20020a0ddd10000000b00577619ed3c9mr240924ywe.10.1698104825871; Mon, 23 Oct 2023 16:47:05 -0700 (PDT) Date: Mon, 23 Oct 2023 23:46:47 +0000 In-Reply-To: <20231023-staging-pmbus-v3-v4-0-07a8cb7cd20a@google.com> Mime-Version: 1.0 References: <20231023-staging-pmbus-v3-v4-0-07a8cb7cd20a@google.com> X-Developer-Key: i=titusr@google.com; a=openpgp; fpr=228BD42BAD6A2BCD3865AEA6C41200175CD21E30 X-Developer-Signature: v=1; a=openpgp-sha256; l=3770; i=titusr@google.com; h=from:subject:message-id; bh=QTYQxWNArHaP0YRgSOq+vqlTWsFPGoLjnzRsYLythkQ=; b=owEB7QES/pANAwAKAcQSABdc0h4wAcsmYgBlNwXvtpqY/8wjwqIskWGObaX37DnLW9ZJyUO0U V0gAfTzKjiJAbMEAAEKAB0WIQQii9QrrWorzThlrqbEEgAXXNIeMAUCZTcF7wAKCRDEEgAXXNIe MDpxC/9BC7/rJztqqTG/tbhYlyeH5h3j3AsvCP7aViP7S0rlOs30LSqs16KW7rY4YVePkyBaUOK HKVTPLu88k6ygeDyMnYbJA2iECJLSRddCUdPFZ8peChF4kuBx+12/wQgGaMtOO1MpCqse2OfvoC K9ZVsYX4o3AIeFLFe5Kxch6rGSMNwb/cwP2F9BtcWQqzDsN0b7KPX9DLzJkNn7KI1OgeyVhtl11 mZqwSU7BTJc2mCKb/olsYCLTOd7fkV59Hs7PcW9GJvUNQSI0otmireZTSWn34eEN4ZLNY9yuDIO 3Dp7oDpEiFH3VVoqXV+zk7DpyaQ5sPTA2zWo1VFNn/pr/L/kjM4qJJYSPBe+/JososQmp2PrIM1 KuLCUIQpjUl6rtKSj6yhihEXCoZ1rfNNaqxmK3slnPgm3k430RV+TB04kUcU1gLOsy3BPts5nzA vsXqMRLAb2U9Pfelbzihly47VwR8d5CWxAPqiEY6mUO84leKFrHGZWE+BT8tc2jwyhR/s= X-Mailer: b4 0.12.2 Message-ID: <20231023-staging-pmbus-v3-v4-8-07a8cb7cd20a@google.com> Subject: [PATCH v4 8/8] hw/i2c: pmbus: reset page register for out of range reads From: titusr@google.com To: philmd@linaro.org, minyard@acm.org Cc: Titus Rwantare , qemu-arm@nongnu.org, qemu-devel@nongnu.org, Hao Wu Received-SPF: pass client-ip=2607:f8b0:4864:20::1149; envelope-from=3-QU3ZQYKChIB0BCA9y66y3w.u648w4C-vwDw3565y5C.69y@flex--titusr.bounces.google.com; helo=mail-yw1-x1149.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 The linux pmbus driver scans all possible pages and does not reset the current page after the scan, making all future page reads fail as out of range on devices with a single page. This change resets out of range pages immediately on write. Also added a qtest for simultaneous writes to all pages. Reviewed-by: Hao Wu Signed-off-by: Titus Rwantare --- hw/i2c/pmbus_device.c | 18 +++++++++--------- tests/qtest/max34451-test.c | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/hw/i2c/pmbus_device.c b/hw/i2c/pmbus_device.c index 481e158380..1b978e588f 100644 --- a/hw/i2c/pmbus_device.c +++ b/hw/i2c/pmbus_device.c @@ -1255,6 +1255,15 @@ static int pmbus_write_data(SMBusDevice *smd, uint8_t *buf, uint8_t len) if (pmdev->code == PMBUS_PAGE) { pmdev->page = pmbus_receive8(pmdev); + + if (pmdev->page > pmdev->num_pages - 1 && pmdev->page != PB_ALL_PAGES) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: page %u is out of range\n", + __func__, pmdev->page); + pmdev->page = 0; /* undefined behaviour - reset to page 0 */ + pmbus_cml_error(pmdev); + return PMBUS_ERR_BYTE; + } return 0; } @@ -1268,15 +1277,6 @@ static int pmbus_write_data(SMBusDevice *smd, uint8_t *buf, uint8_t len) return 0; } - if (pmdev->page > pmdev->num_pages - 1) { - qemu_log_mask(LOG_GUEST_ERROR, - "%s: page %u is out of range\n", - __func__, pmdev->page); - pmdev->page = 0; /* undefined behaviour - reset to page 0 */ - pmbus_cml_error(pmdev); - return PMBUS_ERR_BYTE; - } - index = pmdev->page; switch (pmdev->code) { diff --git a/tests/qtest/max34451-test.c b/tests/qtest/max34451-test.c index 0c98d0764c..dbf6ddc829 100644 --- a/tests/qtest/max34451-test.c +++ b/tests/qtest/max34451-test.c @@ -18,6 +18,7 @@ #define TEST_ID "max34451-test" #define TEST_ADDR (0x4e) +#define MAX34451_MFR_MODE 0xD1 #define MAX34451_MFR_VOUT_PEAK 0xD4 #define MAX34451_MFR_IOUT_PEAK 0xD5 #define MAX34451_MFR_TEMPERATURE_PEAK 0xD6 @@ -315,6 +316,28 @@ static void test_ot_faults(void *obj, void *data, QGuestAllocator *alloc) } } +#define RAND_ON_OFF_CONFIG 0x12 +#define RAND_MFR_MODE 0x3456 + +/* test writes to all pages */ +static void test_all_pages(void *obj, void *data, QGuestAllocator *alloc) +{ + uint16_t i2c_value; + QI2CDevice *i2cdev = (QI2CDevice *)obj; + + i2c_set8(i2cdev, PMBUS_PAGE, PB_ALL_PAGES); + i2c_set8(i2cdev, PMBUS_ON_OFF_CONFIG, RAND_ON_OFF_CONFIG); + max34451_i2c_set16(i2cdev, MAX34451_MFR_MODE, RAND_MFR_MODE); + + for (int i = 0; i < MAX34451_NUM_TEMP_DEVICES + MAX34451_NUM_PWR_DEVICES; + i++) { + i2c_value = i2c_get8(i2cdev, PMBUS_ON_OFF_CONFIG); + g_assert_cmphex(i2c_value, ==, RAND_ON_OFF_CONFIG); + i2c_value = max34451_i2c_get16(i2cdev, MAX34451_MFR_MODE); + g_assert_cmphex(i2c_value, ==, RAND_MFR_MODE); + } +} + static void max34451_register_nodes(void) { QOSGraphEdgeOptions opts = { @@ -332,5 +355,6 @@ static void max34451_register_nodes(void) qos_add_test("test_ro_regs", "max34451", test_ro_regs, NULL); qos_add_test("test_ov_faults", "max34451", test_ov_faults, NULL); qos_add_test("test_ot_faults", "max34451", test_ot_faults, NULL); + qos_add_test("test_all_pages", "max34451", test_all_pages, NULL); } libqos_init(max34451_register_nodes);