From patchwork Fri Mar 31 00:07:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13195085 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 C5E53C7619A for ; Fri, 31 Mar 2023 00:10:25 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pi2Jr-00076o-4i; Thu, 30 Mar 2023 20:08:39 -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 <3gSQmZAYKCoo7w7865u22uzs.q204s08-rs9sz121u18.25u@flex--titusr.bounces.google.com>) id 1pi2Jo-00075h-TL for qemu-devel@nongnu.org; Thu, 30 Mar 2023 20:08:36 -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 <3gSQmZAYKCoo7w7865u22uzs.q204s08-rs9sz121u18.25u@flex--titusr.bounces.google.com>) id 1pi2Jm-0005m1-H9 for qemu-devel@nongnu.org; Thu, 30 Mar 2023 20:08:35 -0400 Received: by mail-yb1-xb49.google.com with SMTP id j11-20020a25230b000000b00b6871c296bdso20171900ybj.5 for ; Thu, 30 Mar 2023 17:08:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680221313; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=tMsLrklx39gsFoa2tmyIQkWi/3Q/pCg3SBebIkEyC/c=; b=YOR0rQQX40HtnSABalOFeGLmSxX72wjhJWQn/E7Mn+Y3G0t+r/VbP94/DK6gd2HhIt XNIJPZgEARfctJi4seRG9exwvo00KGiLfpNSTwL2L+p2VM7IjmWipmyqSLMmDdmdU2Ba 3REW6czvpc150qPD0PfpR6/jNK+Cmpr3A7rYHRKwLuu0/mbB5ClsAv79lhlHQ30uRtEs LWCApt4nkNzheUFnbJoOv1m5I0YnTbMVLlfqCsKQvecbUQJPrv/fxGBLWl03IjESsxqM +j/Cwyki8ap4ynz2Z6F7fZStEHf1HY30/SlZuiij2gk2AbepJQaBkLFhlv2bhU7MnlCc jfSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680221313; 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=tMsLrklx39gsFoa2tmyIQkWi/3Q/pCg3SBebIkEyC/c=; b=OG97mgI/sDNzC0FJ6JK2hSW7+tsFeZ/Pi0JPHHeZ9YXD3r5aEcgyeM+lL7jrTOSMzs n+hAB35VSb3pfnAd3bBGda78DoDJZcYUJ8DmizoWpu+ihT6myc85zuqeZgvQrnDFrDbQ To0OuKusuLUeK57bqWo5gFh/t0yOHP3Ob+6CNs4KU87iiw/OzKRTLwZreWOILLpepBZS nFbQRitbvATm4FZbqoJeq2xV+zkVsWxn4SUMt5/AIA18NfC/xM96DbL0uF9O8l/U8sUB jnjtm4CuVFvEivM4dSCuiiCl2FoCccJ2aOiqaCk2K/KVFMPV+jd5cN0r1yHjnuA0wY9O 1RCg== X-Gm-Message-State: AAQBX9dpZGpohkfn3EuSUMC51Mocys991m/5M6Obblcen0SbLBj9cCbG YgBi89qQ7mz7DUtdVebVUcWDcWfOo94= X-Google-Smtp-Source: AKy350bw/hFahSrs+G6sM3BryzJuv6Q9tXUQF3OZRIfZsXL2T7mdriUR6uFaWkexuh5hPRLCZP8KdNt4cKc= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:22b8]) (user=titusr job=sendgmr) by 2002:a81:a84a:0:b0:544:bce8:980f with SMTP id f71-20020a81a84a000000b00544bce8980fmr12687664ywh.6.1680221313116; Thu, 30 Mar 2023 17:08:33 -0700 (PDT) Date: Fri, 31 Mar 2023 00:07:50 +0000 In-Reply-To: <20230331000756.1712787-1-titusr@google.com> Mime-Version: 1.0 References: <20230331000756.1712787-1-titusr@google.com> X-Mailer: git-send-email 2.40.0.423.gd6c402a77b-goog Message-ID: <20230331000756.1712787-2-titusr@google.com> Subject: [PATCH 1/7] 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::b49; envelope-from=3gSQmZAYKCoo7w7865u22uzs.q204s08-rs9sz121u18.25u@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 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 Signed-off-by: Titus Rwantare Acked-by: Corey Minyard --- 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 Fri Mar 31 00:07:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13195079 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 EA4ABC7619A for ; Fri, 31 Mar 2023 00:09:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pi2K9-00078u-Ii; Thu, 30 Mar 2023 20:08:57 -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 <3gyQmZAYKCow9y9A87w44w1u.s426u2A-tuBu1343w3A.47w@flex--titusr.bounces.google.com>) id 1pi2K6-00078F-F1 for qemu-devel@nongnu.org; Thu, 30 Mar 2023 20:08:54 -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 <3gyQmZAYKCow9y9A87w44w1u.s426u2A-tuBu1343w3A.47w@flex--titusr.bounces.google.com>) id 1pi2Jq-0005nc-DI for qemu-devel@nongnu.org; Thu, 30 Mar 2023 20:08:41 -0400 Received: by mail-yb1-xb49.google.com with SMTP id e23-20020a25e717000000b00b66ab374ba1so20585024ybh.22 for ; Thu, 30 Mar 2023 17:08:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680221315; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BIiLwLowPEm8vJEjag0ZG940kCvo8Ev0kutlHlOPnEw=; b=ct5Z6vqQczaHdizahQpf7O6tzLEtBdQphN1bLSJ4/KpzYZEWG+Q67iks6i7FEg8wiZ 5o6iIhEUeAsAdc3aFjQeahYQ2CNtucA7865ghzj/K405Q/NzDc1sdxwiiN9mhcOgmetZ UAzvMIN6NSkUsx/Ip6XHfGUuJX35/3KHMEV7JTFssPeYaFMFCL7598v7SUTWuraEEbph UxQkgXYnjXCgeLujKkJzCZXkL5z7xKPMt2vJPpm7kYfHcovr9QO6orE+0bym+AfTKo6u 265xgvLSOaLd1kDpRs4ervwV1AwWmPfbK7ahlaw4TIEOFXR3cHSwMLcMSdCkZPwEext7 VU3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680221315; 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=BIiLwLowPEm8vJEjag0ZG940kCvo8Ev0kutlHlOPnEw=; b=3EhHcYmJvwGe8L3631GIXxWfR6cYzTWo9nd7gNC+fTRcQ24W0EP6rBs/dyi1HtvgMh XVmzObxU2H+VRG4Ip22qx0rjEfZhm37U9eaQCwF3Q1OWA5OCXstIBfY+U5dyBTMaSAbP tLkPctL48EGFPHZzZHXkCQTYTFxPcWluL7KnV6VivjWa0BFQf3SKS1D3waXUIPzJO15I EVf4n87oVcxn3HPQ1qLg0qeQ6vhmsgXiLZ12EHA5e9h/+zZPUirajeBIzv5gKR/MTGMg S3de4Gp2Vn445SQFVK6AhvAOCA1eFJbgENU63oAlQpVyflhbX0bYHMUVZRBdjy8Gj8Ey nF/Q== X-Gm-Message-State: AAQBX9dhbdfx3jSMCaGBp71yv3w4G7MTmaf627wA+k78CPu0d9RxQoiY RiN72VUBMbmUrfxJHSUcrS9z2uk3zOg= X-Google-Smtp-Source: AKy350Ysupozj7NxZnsjGSJWRqVike8ts1Jyq9mgbgtXTg6aCg+1c+5cRMqiJwcRhhHl+5uOn+eSNxvLLxY= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:22b8]) (user=titusr job=sendgmr) by 2002:a25:3485:0:b0:b6b:d3f3:45af with SMTP id b127-20020a253485000000b00b6bd3f345afmr1301898yba.1.1680221315239; Thu, 30 Mar 2023 17:08:35 -0700 (PDT) Date: Fri, 31 Mar 2023 00:07:51 +0000 In-Reply-To: <20230331000756.1712787-1-titusr@google.com> Mime-Version: 1.0 References: <20230331000756.1712787-1-titusr@google.com> X-Mailer: git-send-email 2.40.0.423.gd6c402a77b-goog Message-ID: <20230331000756.1712787-3-titusr@google.com> Subject: [PATCH 2/7] 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=3gyQmZAYKCow9y9A87w44w1u.s426u2A-tuBu1343w3A.47w@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 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 Signed-off-by: Titus Rwantare Acked-by: Corey Minyard --- 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 Fri Mar 31 00:07:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13195083 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 E4912C761AF for ; Fri, 31 Mar 2023 00:10:07 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pi2K7-00078m-NF; Thu, 30 Mar 2023 20:08:55 -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 <3hSQmZAYKCo4B0BCA9y66y3w.u648w4C-vwDw3565y5C.69y@flex--titusr.bounces.google.com>) id 1pi2K6-00078E-F2 for qemu-devel@nongnu.org; Thu, 30 Mar 2023 20:08:54 -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 <3hSQmZAYKCo4B0BCA9y66y3w.u648w4C-vwDw3565y5C.69y@flex--titusr.bounces.google.com>) id 1pi2Js-0005ou-57 for qemu-devel@nongnu.org; Thu, 30 Mar 2023 20:08:51 -0400 Received: by mail-yb1-xb4a.google.com with SMTP id b124-20020a253482000000b00b72947f6a54so20460155yba.14 for ; Thu, 30 Mar 2023 17:08:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680221317; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=g64aGJIyKlA6LYSQVFAep6BH8KUc6VYjHGYJofMi0D8=; b=jv6bIVyFcN9YRuB2EPRd0qkj4lOuLlSmW1ZNuW8BxiG/r3dDrhVZpkQ6+8dCnv0N2U jh+f+8f76J9YHt6S0YpuukhhGKdiBWvbAbP9RPIvjzhimv3suKnvWICzjp27V47WejWM LgOoeQJ8dBA1D3adEuTzUiB7AkHqpT2hZ0Fx2WsNN0AjeVPminAVw6DGV/RKMYgGu1fK cnRhIzSz9psE6P+FGnEnRMW6V3fqAC/KR+1eSCADw2LavjCz3BIcFuHk/hKeZGYnGT8a CbFoj26fOd9FikjQ72LQxNDXUfTOs0t/PGPIC2ujjWoLMKGzw6H7GhzT1accQL9+BjP2 1tnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680221317; 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=g64aGJIyKlA6LYSQVFAep6BH8KUc6VYjHGYJofMi0D8=; b=zAmYwz2NKNoXzMHQcFCC1Vard8X0Zxl8eEqeLGDTrclaymZfkkADr2rJygSsHJmTsU vyBH3G+BVCtvTJG2bVE1dezRmMfzJS6mKAQAwRUURRhctr8mkMM/HWcGRzVz8O7G8Mq8 qBYUin9c0D+CFJ//BYeOlrlH1WJ7y8+a4uP6307nZdzeQjyCRc8M+iFnmZ67Ck0uhF// QZl6paq7I38ykNGkcLMz0Xj7szQWd+fvq10zFB2LyskNHKZKdVAeiOw2kInV2WLnxsCJ ZUTqVV3zX0dJwy6mjC9KFTU87dLyq/5g98hqsV9Ulw5HRD4YeSZck870ULS3F7w7YsOd WR7g== X-Gm-Message-State: AAQBX9cD/65uKbS2yeOA/TTpvrLo5qXhSdGe8Zy350Ojp+uJtLLyTrZB txNDT6MDMv8nJDeR6lO83PFbbNjzttk= X-Google-Smtp-Source: AKy350bHLkS1EqPZ7C81huTapp2/0e/J7h+dPeclF5IW3hG3QQAFaAvPp+JTL7Lx1G8vz1hMqqiX4QBozto= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:22b8]) (user=titusr job=sendgmr) by 2002:a81:b645:0:b0:545:7164:49aa with SMTP id h5-20020a81b645000000b00545716449aamr12657254ywk.1.1680221317044; Thu, 30 Mar 2023 17:08:37 -0700 (PDT) Date: Fri, 31 Mar 2023 00:07:52 +0000 In-Reply-To: <20230331000756.1712787-1-titusr@google.com> Mime-Version: 1.0 References: <20230331000756.1712787-1-titusr@google.com> X-Mailer: git-send-email 2.40.0.423.gd6c402a77b-goog Message-ID: <20230331000756.1712787-4-titusr@google.com> Subject: [PATCH 3/7] 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::b4a; envelope-from=3hSQmZAYKCo4B0BCA9y66y3w.u648w4C-vwDw3565y5C.69y@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=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 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 Fri Mar 31 00:07:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13195084 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 250A5C6FD1D for ; Fri, 31 Mar 2023 00:10:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pi2KU-0007gd-8P; Thu, 30 Mar 2023 20:09:18 -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 <3hiQmZAYKCo8C1CDBAz77z4x.v759x5D-wxEx4676z6D.7Az@flex--titusr.bounces.google.com>) id 1pi2K8-0007CB-Rh for qemu-devel@nongnu.org; Thu, 30 Mar 2023 20:08:57 -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 <3hiQmZAYKCo8C1CDBAz77z4x.v759x5D-wxEx4676z6D.7Az@flex--titusr.bounces.google.com>) id 1pi2K5-0005pa-Sj for qemu-devel@nongnu.org; Thu, 30 Mar 2023 20:08:56 -0400 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5446a91c40cso204677637b3.18 for ; Thu, 30 Mar 2023 17:08:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680221318; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=JVa+ysZi3CwbR24epjsK5up3WFbQnFpyGHTqEQOjKmA=; b=jS6OogHby3xJfSIk1dYJ483RUeggfOoDzT/xsIkiAGmJCb+bqVyfqLjss+Ba8PV8v/ DnEMW8Nk6AYbeKd5E6Va7kGdJy1LE4n+mE5IrECeQDlP98g9NXDLXKQFUbwnQeWD3l58 SfNDhOceC1xuNB3iPnYn/B7VEJ8uIGb5FKMVHUqJRImoYiSMsZpLF2os1l+8KVgUc6NK 5Bhv7/cGty5/QwW64ozf8+rQJ2ZEXnHq4vEc9iOf4u2a4CEEHFBKX3KqC9Rrok5bCPlw 25dn7vU8nlc4YfqOXVOmYAmCSEPyd+BMj0RSAo8sjwLbKlXGNlaEXXy8DIKJBvIQnO30 0vHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680221318; 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=JVa+ysZi3CwbR24epjsK5up3WFbQnFpyGHTqEQOjKmA=; b=b288v+7Jv+QhEJqCYly+X8bie/AdnigzKCXsrcJ2gHNJiWDiDkqqC1h5MnC8YIHqWy dYHhxfQWDGFvpLtjconu+mI9aT7tBENg0o0KMEVXoj0L3nTXggvfsp9LlNMSCBMwH/W5 rjBUZ/SyGpEKCqJnjQ3SbSIwWl7fAO0osRKqxpP+TYpEuB+8oG/LqXxX5DCUfmX9R7u7 1tQmV0DTPTbe5UfMOPpIH9YgoYx+c1vIL0cocEAlbVOpfb9n6/Qns1GZ3H1TKB4Voujv zTOqZ4P3RLttexhJlXms+ZghTeROyD+LFa1aK0gW70absqrcVJVaGw5da+730l6M0DaV FubA== X-Gm-Message-State: AAQBX9cj3XtpBjSCOqaXMv6JeJ36ysEmTlyxftTWIN5qtfkv1NiHB+gV ysV3YsicYxY6WYCtbPJjrgAL/DoknEk= X-Google-Smtp-Source: AKy350b/Y/yWo1RERWHOkBQYfXgNf10mBUf9UM6AggmtpKb+gtFiIQFXinUMn2l0lsay9Ss0Neu0n7WCCME= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:22b8]) (user=titusr job=sendgmr) by 2002:a25:2749:0:b0:b4a:e062:3576 with SMTP id n70-20020a252749000000b00b4ae0623576mr13087476ybn.13.1680221318127; Thu, 30 Mar 2023 17:08:38 -0700 (PDT) Date: Fri, 31 Mar 2023 00:07:53 +0000 In-Reply-To: <20230331000756.1712787-1-titusr@google.com> Mime-Version: 1.0 References: <20230331000756.1712787-1-titusr@google.com> X-Mailer: git-send-email 2.40.0.423.gd6c402a77b-goog Message-ID: <20230331000756.1712787-5-titusr@google.com> Subject: [PATCH 4/7] 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::1149; envelope-from=3hiQmZAYKCo8C1CDBAz77z4x.v759x5D-wxEx4676z6D.7Az@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 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 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 Fri Mar 31 00:07:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13195082 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 2B411C6FD1D for ; Fri, 31 Mar 2023 00:10:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pi2KT-0007ZD-1N; Thu, 30 Mar 2023 20:09:17 -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 <3hiQmZAYKCo8C1CDBAz77z4x.v759x5D-wxEx4676z6D.7Az@flex--titusr.bounces.google.com>) id 1pi2K7-00078k-FT for qemu-devel@nongnu.org; Thu, 30 Mar 2023 20:08:55 -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 <3hiQmZAYKCo8C1CDBAz77z4x.v759x5D-wxEx4676z6D.7Az@flex--titusr.bounces.google.com>) id 1pi2K5-0005q3-So for qemu-devel@nongnu.org; Thu, 30 Mar 2023 20:08:55 -0400 Received: by mail-yb1-xb4a.google.com with SMTP id w5-20020a253005000000b00aedd4305ff2so20521945ybw.13 for ; Thu, 30 Mar 2023 17:08:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680221319; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6MwfbHdxuIOtH0NAbW8vcKKizTpZOCl4cwXr1Kj34SU=; b=XoqaedzahbGh+jdb0RPj/l7LmuvLGh5OLjY9N8gJSQDQZreoS1iqM+GU5+rk4StbyZ FCcD+RcCcFpAChkpL+8M9qivd6zPiw8U3R56U6YLNzqLRB5Xx2bkGOVM1yjbLF8bXu3k btALCziXrptWhtHJeJG9W10VkxyTpQPJlGI1H9T5VK3YqwqaN7ZRX9dnNux0gM2s/pj4 PdVCxund3TjIOd4Gx+bH9gQ+ci3f4LSxW9Zo9SDvQzofryNRW+LvQnlGNGtdMPIFqTK8 xOXIENr52JTgebC3fAWnr85AedJca+xCliAMrxG9ll+rtRpl0lusEXe4pV5oem3uqAiP sKWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680221319; 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=6MwfbHdxuIOtH0NAbW8vcKKizTpZOCl4cwXr1Kj34SU=; b=PBgFl4R74HSzZZkXgkIOHSbrml84kuarvnNhVMWZK3JBBwtRASdy9u6ldx5/QZK69f OfWYuw/S701BkC+MzAJ4L3DHJI0yR9DqjWf976QgysOJ9KUOJLoY//PFPrsRK/LP3gyA bqanLWgINYJfgckt/1bott/x8GYIxpF/6pq7aXh6nz2oE3Rw8oN12aiT2e/nkLz4mRtI 93A6QUBa/0a99Z1Nh9J3QWebPmMqNMk3J6KJWVufBayVSEFvgd/kgsXMbzKbtnyJeLSh CZG2GR3eOkzQ5Lt09yhfpI6uLdepLK3uHjZxLA233FefD6/oEQdVsY24QaKqQfgrPjUi Lrmg== X-Gm-Message-State: AAQBX9dIjjve61HPpTx1MExc6eJsxTi+CqaX+W48ikaJDdF6/sul+uD7 R32aAxqZH/OV85hlWiKw+2n4d4s9GPU= X-Google-Smtp-Source: AKy350a1f89ion6Eqm9uoKjoKMUMuvuZI5MEq1nMoNDe7NwhRJ6DiSyh67J8Iuom+ADiccRJJIIqFKrnV3E= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:22b8]) (user=titusr job=sendgmr) by 2002:a05:6902:168d:b0:98e:6280:90e7 with SMTP id bx13-20020a056902168d00b0098e628090e7mr16740002ybb.13.1680221318928; Thu, 30 Mar 2023 17:08:38 -0700 (PDT) Date: Fri, 31 Mar 2023 00:07:54 +0000 In-Reply-To: <20230331000756.1712787-1-titusr@google.com> Mime-Version: 1.0 References: <20230331000756.1712787-1-titusr@google.com> X-Mailer: git-send-email 2.40.0.423.gd6c402a77b-goog Message-ID: <20230331000756.1712787-6-titusr@google.com> Subject: [PATCH 5/7] 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::b4a; envelope-from=3hiQmZAYKCo8C1CDBAz77z4x.v759x5D-wxEx4676z6D.7Az@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 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) From patchwork Fri Mar 31 00:07:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13195081 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 D6C59C761AF for ; Fri, 31 Mar 2023 00:09:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pi2KS-0007SM-2k; Thu, 30 Mar 2023 20:09:16 -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 <3hyQmZAYKCpAD2DECB08805y.w86Ay6E-xyFy578707E.8B0@flex--titusr.bounces.google.com>) id 1pi2K9-0007Cb-DE for qemu-devel@nongnu.org; Thu, 30 Mar 2023 20:08:57 -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 <3hyQmZAYKCpAD2DECB08805y.w86Ay6E-xyFy578707E.8B0@flex--titusr.bounces.google.com>) id 1pi2K6-0005qQ-6P for qemu-devel@nongnu.org; Thu, 30 Mar 2023 20:08:57 -0400 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5458201ab8cso207036377b3.23 for ; Thu, 30 Mar 2023 17:08:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680221319; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=8gvomdt3DUwUN4FoSBnJV4Ctxju8JwPTYOQalHBdVD4=; b=UEfgoMO4eZQeg9kuztrUq2cXxkWJmLL3WxzcUu/vTNNLbE7hASopSjKN9Lc5UAkL0e fhzkZPiq92TAWvBKIVZtmDOG+2CF+RjCWAhlDa1p/gaBLQzf9TvyMbuXfYtPvYs5DXJ6 O2/S0gUXr6GAwLOjq8C3X/DJ+asKLUBeI6qQ9+KLMotSimFJOpWSkO9JDsqz57Oqk04C GlCByLNnK0sDDrj3+Sjy/ObynhFcYXnHIMZkTppUlX3pGU+95vPZwhSStRkxbH+QXmSK T+xSsh7O5Yg+AnBfF9jha6pPPEEOjU4ea7raDB4q+aGrCVh3ckrmdjR0D1qfHBxQnEjs EjZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680221319; 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=8gvomdt3DUwUN4FoSBnJV4Ctxju8JwPTYOQalHBdVD4=; b=0iJ6t/rlFfJhyqybZewwUt15uyw2HgERuh5jd3cI549VNX0FwLtlEviTPmW0LPjxRd BfXO3Q0La+jTmu40uv+xwgh4qFLf3s7NmIbWXiNHFNd1GrgYqe5REfXDwdWwzPCz42Jh ApaF1Nltqu6XiNX1At7zM+Scxz1y/zD+KGyEfdbfYQ0+6Fq/plAWy25Qd0qSQoLkKSgw kibzHGahRJR96WdxBYZmWxBQrt6Drk7LrPPtx71JDnTiCvtHLF0Gl3lC/RgeukalaPp/ S6KBIdZBe5sd7ekfKA53tDW/GsDGRNWVfmNvQzEABJ2kLlUca8o1eEztZClDADs+50qS DSKA== X-Gm-Message-State: AAQBX9fXyGlb4No0a9Ol6OwIkP8D56pscFW7mIebGtIkCt88XImthYoZ P5HdoOw2q5Eb2IN7LgRgARZTFKzQ2E8= X-Google-Smtp-Source: AKy350bMKwN4e9D5fZq0GnlqP+dMuSeSVPl5UJpB9T0Zsu7bFb1uBlAWqN5xEc5SLF1FP5lwTuEo4bXHCCg= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:22b8]) (user=titusr job=sendgmr) by 2002:a05:6902:18d5:b0:b75:3fd4:1b31 with SMTP id ck21-20020a05690218d500b00b753fd41b31mr17197516ybb.1.1680221319710; Thu, 30 Mar 2023 17:08:39 -0700 (PDT) Date: Fri, 31 Mar 2023 00:07:55 +0000 In-Reply-To: <20230331000756.1712787-1-titusr@google.com> Mime-Version: 1.0 References: <20230331000756.1712787-1-titusr@google.com> X-Mailer: git-send-email 2.40.0.423.gd6c402a77b-goog Message-ID: <20230331000756.1712787-7-titusr@google.com> Subject: [PATCH 6/7] hw/sensor: add ADM1266 device model 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::114a; envelope-from=3hyQmZAYKCpAD2DECB08805y.w86Ay6E-xyFy578707E.8B0@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 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 Signed-off-by: Titus Rwantare Acked-by: Corey Minyard --- hw/arm/Kconfig | 1 + hw/sensor/Kconfig | 5 + hw/sensor/adm1266.c | 255 ++++++++++++++++++++++++++++++++++++++++++ hw/sensor/meson.build | 1 + 4 files changed, 262 insertions(+) create mode 100644 hw/sensor/adm1266.c diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index b5aed4aff5..4e44a7451d 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -407,6 +407,7 @@ config XLNX_VERSAL config NPCM7XX bool 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..0745b12b1d --- /dev/null +++ b/hw/sensor/adm1266.c @@ -0,0 +1,255 @@ +/* + * 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 +#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 9e9be602c3..4528ee6215 100644 --- a/hw/sensor/meson.build +++ b/hw/sensor/meson.build @@ -3,6 +3,7 @@ softmmu_ss.add(when: 'CONFIG_TMP421', if_true: files('tmp421.c')) softmmu_ss.add(when: 'CONFIG_DPS310', if_true: files('dps310.c')) softmmu_ss.add(when: 'CONFIG_EMC141X', if_true: files('emc141x.c')) softmmu_ss.add(when: 'CONFIG_ADM1272', if_true: files('adm1272.c')) +softmmu_ss.add(when: 'CONFIG_ADM1266', if_true: files('adm1266.c')) softmmu_ss.add(when: 'CONFIG_MAX34451', if_true: files('max34451.c')) softmmu_ss.add(when: 'CONFIG_LSM303DLHC_MAG', if_true: files('lsm303dlhc_mag.c')) softmmu_ss.add(when: 'CONFIG_ISL_PMBUS_VR', if_true: files('isl_pmbus_vr.c')) From patchwork Fri Mar 31 00:07:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 13195080 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 283A5C6FD1D for ; Fri, 31 Mar 2023 00:09:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pi2KJ-0007Kv-Uo; Thu, 30 Mar 2023 20:09: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 <3iCQmZAYKCpEE3EFDC19916z.x97Bz7F-yzGz689818F.9C1@flex--titusr.bounces.google.com>) id 1pi2KA-0007EF-2A for qemu-devel@nongnu.org; Thu, 30 Mar 2023 20:08:58 -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 <3iCQmZAYKCpEE3EFDC19916z.x97Bz7F-yzGz689818F.9C1@flex--titusr.bounces.google.com>) id 1pi2K6-0005lw-Bx for qemu-devel@nongnu.org; Thu, 30 Mar 2023 20:08:57 -0400 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5417f156cb9so204774557b3.8 for ; Thu, 30 Mar 2023 17:08:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680221320; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NouqQ4NmgiCSaLa3pSeLTuKCidNI7EomSt2z9bvPEGU=; b=AMxYAwkHnczd45yj2xNoBEGr68L9/s1RuNTSp5HGZRU8kcJXLJn1130p86CM+d2uKu xNp+IsZybJuh1M5rqutT19+G77vX5g1Qlt08uihTf0lwag/PK4JwZ6M8fDZ80YX/m5QE ubruHKhv8Kq+9DKTRkRlnv8VgXvCNPKDHFalZ2PaD5MCP5GVJEAxne469JbRiFeFP5wW Fx481pNErv5JT4Pi5sXuhPzTcDk84odCkxVWenEAiHdxTIjeW7sjUExgwX447Szx8oaN YYI8Su8kCo8dM32hOBzDU7OojnYHOXs6LU7CbnHkXTd4ALIHTnmk7yN5sVYpqs+RrT6Y VZBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680221320; 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=NouqQ4NmgiCSaLa3pSeLTuKCidNI7EomSt2z9bvPEGU=; b=IO9bE9s9D1xk7bhXsqVyBTQ861QMgeSHri4qI2rZw26oPSl8UwfX3bBY+syajmhJve piqLHo9U7M2adrk8AG/rBazJYXpAxfuTDON7eDEyniMuDlot4+qMVDII+K77aYqIXhgf KJ1tGuSRoA54wPe78dxukeE4e17bs4ofWSQHUykCEbdCFlf3+i2D+VwKT0/tvxDVlIOO eN4RTPiUys+BvKsFnce6bLvodkWV5Fee3SDAG2WKOteK99jzovnhMcgCQ+MiomQyMAAg 89czgcapkgKW1/Q52FC4YBIQuLT4PhIxx19CNh1LU4OJ2axzhd99C2rN8Xj/zWHm0AJN CdVQ== X-Gm-Message-State: AAQBX9cK1O0X5rQbAWxWB00pCBT4QWGU7AYcarnMkdNIQl5C+wqwQ4xp lCkGgrp9TWppNft1eWNAoftd8Tc2V1o= X-Google-Smtp-Source: AKy350a7YTlq0qLGYX6aE0G+ztS37B++gdG9HZN1wPly8BD34JQNXQD+69hmx9zYtTGxjo76VrWtlGfB/E0= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:22b8]) (user=titusr job=sendgmr) by 2002:a05:6902:1586:b0:b69:fab9:de39 with SMTP id k6-20020a056902158600b00b69fab9de39mr13681849ybu.2.1680221320642; Thu, 30 Mar 2023 17:08:40 -0700 (PDT) Date: Fri, 31 Mar 2023 00:07:56 +0000 In-Reply-To: <20230331000756.1712787-1-titusr@google.com> Mime-Version: 1.0 References: <20230331000756.1712787-1-titusr@google.com> X-Mailer: git-send-email 2.40.0.423.gd6c402a77b-goog Message-ID: <20230331000756.1712787-8-titusr@google.com> Subject: [PATCH 7/7] tests/qtest: add tests for ADM1266 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::1149; envelope-from=3iCQmZAYKCpEE3EFDC19916z.x97Bz7F-yzGz689818F.9C1@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 ADM1266 can have string fields written by the driver, so it's worth specifically testing. Reviewed-by: Hao Wu Signed-off-by: Titus Rwantare Acked-by: Corey Minyard --- tests/qtest/adm1266-test.c | 123 +++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 1 + 2 files changed, 124 insertions(+) create mode 100644 tests/qtest/adm1266-test.c 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 85ea4e8d99..d3cf7b2287 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -232,6 +232,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',