From patchwork Wed Mar 2 00:22:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 12765295 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 C581CC433F5 for ; Wed, 2 Mar 2022 00:25:43 +0000 (UTC) Received: from localhost ([::1]:44790 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPCoI-00021m-Rn for qemu-devel@archiver.kernel.org; Tue, 01 Mar 2022 19:25:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36900) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3-7geYgYKCv4zoz0yxmuumrk.iuswks0-jk1krtutmt0.uxm@flex--titusr.bounces.google.com>) id 1nPCmB-0008GS-DZ for qemu-devel@nongnu.org; Tue, 01 Mar 2022 19:23:31 -0500 Received: from [2607:f8b0:4864:20::b49] (port=45844 helo=mail-yb1-xb49.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3-7geYgYKCv4zoz0yxmuumrk.iuswks0-jk1krtutmt0.uxm@flex--titusr.bounces.google.com>) id 1nPCm9-0002s4-2v for qemu-devel@nongnu.org; Tue, 01 Mar 2022 19:23:30 -0500 Received: by mail-yb1-xb49.google.com with SMTP id n66-20020a254045000000b0062883b59ddbso7174yba.12 for ; Tue, 01 Mar 2022 16:23:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=psSMCNKv2yqoyBWLtLGO59oWBEWLqDJSO6USW3rcrSM=; b=NrYikGjOJl8t65tlIniPGLOU191nooF40+SCiQeHRIlQNsIHB/wmc5VxsvfsGyB7fL kmHL3VorhDzwnefbDhHZAXTSokO7bD2gAv5qyMuuhPuloD1pLF5PXgtedip0aZ24Nah7 dCBbagpmnd+cyjPbqS3LTvxR7MpD+ZhvgA9UivD6JsljIrnvtVJaCdw8S65gpOvHWgJr R0NEzKbolAOSSWxaQs30ZrzHH2RoKjgpsjRxpPvGJ/AMe0ZVNTB03kOi3oCdAlGQJOXc L0XsiWG/B4LXuDWbxJfYLUbuNL6uI7xpfZK4qCUo7ZcJ+gmQa+0+vUNMXGZZnTbw0pzX GLYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=psSMCNKv2yqoyBWLtLGO59oWBEWLqDJSO6USW3rcrSM=; b=T60W3fqY26EOg35YocT/03epO+5T2a6ztk6CHmsJR9mA2QKXwI8qBaB0Ad9cjddgK6 QxLTxx/AkiDYovgxhIjP4setTU+fEBCKSHnBP/QwI9BG96UlPMobQ9+OlJMyBKjQu7v3 7n3btYcSggSGqKzA9Ls1CBKJydnC15pLoHEgzrBVRmAReeU1wbQrMM85WLxV0YthfS+p nCy72+DYR8mNHrjM7M9eMablTr5mYT3fPm3cyAPYM2AXwdaRl3xePaWOAseEh+FTSylJ B9uCuqGArQhMc0INherU6cJSeY1iw2GnLtsf1dVbx3t/Q94sNcmP+yCStDestLWaPeEg YuCg== X-Gm-Message-State: AOAM530BWxzMjsEDjG9IZMkIBQ6otowz0PbeRg1+u7tNaAx/spat3xgo 5yaCoNtrdYgXGUHqlvLi1Vv2GYEbPUc= X-Google-Smtp-Source: ABdhPJzssL6wQsxQOc3aLaYtkcpY7M4fiVTMC/qk3dAweuffA/NR+ECfLAARZjtFufMsLno3YpahrfrAPe8= X-Received: from titusr.svl.corp.google.com ([2620:15c:2a3:201:3a0a:5449:c096:dc84]) (user=titusr job=sendgmr) by 2002:a25:20c5:0:b0:611:a36c:41d with SMTP id g188-20020a2520c5000000b00611a36c041dmr26196026ybg.71.1646180603724; Tue, 01 Mar 2022 16:23:23 -0800 (PST) Date: Tue, 1 Mar 2022 16:22:59 -0800 In-Reply-To: <20220302002307.1895616-1-titusr@google.com> Message-Id: <20220302002307.1895616-2-titusr@google.com> Mime-Version: 1.0 References: <20220302002307.1895616-1-titusr@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v2 1/9] hw/i2c: pmbus: add registers From: Titus Rwantare To: Corey Minyard Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, f4bug@amsat.org, wuhaotsh@google.com, venture@google.com, Titus Rwantare X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::b49 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::b49; envelope-from=3-7geYgYKCv4zoz0yxmuumrk.iuswks0-jk1krtutmt0.uxm@flex--titusr.bounces.google.com; helo=mail-yb1-xb49.google.com X-Spam_score_int: -81 X-Spam_score: -8.2 X-Spam_bar: -------- X-Spam_report: (-8.2 / 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, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=no 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" - add the VOUT_MIN and STATUS_MFR registers Signed-off-by: Titus Rwantare --- hw/i2c/pmbus_device.c | 24 ++++++++++++++++++++++++ include/hw/i2c/pmbus_device.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/hw/i2c/pmbus_device.c b/hw/i2c/pmbus_device.c index 24f8f522d9..07a45c99f9 100644 --- a/hw/i2c/pmbus_device.c +++ b/hw/i2c/pmbus_device.c @@ -368,6 +368,14 @@ static uint8_t pmbus_receive_byte(SMBusDevice *smd) } break; + case PMBUS_VOUT_MIN: /* R/W word */ + if (pmdev->pages[index].page_flags & PB_HAS_VOUT_RATING) { + pmbus_send16(pmdev, pmdev->pages[index].vout_min); + } else { + goto passthough; + } + break; + /* TODO: implement coefficients support */ case PMBUS_POUT_MAX: /* R/W word */ @@ -708,6 +716,10 @@ static uint8_t pmbus_receive_byte(SMBusDevice *smd) pmbus_send8(pmdev, pmdev->pages[index].status_other); break; + case PMBUS_STATUS_MFR_SPECIFIC: /* R/W byte */ + pmbus_send8(pmdev, pmdev->pages[index].status_mfr_specific); + 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); @@ -1149,6 +1161,14 @@ static int pmbus_write_data(SMBusDevice *smd, uint8_t *buf, uint8_t len) } break; + case PMBUS_VOUT_MIN: /* R/W word */ + if (pmdev->pages[index].page_flags & PB_HAS_VOUT_RATING) { + pmdev->pages[index].vout_min = pmbus_receive16(pmdev); + } else { + goto passthrough; + } + break; + case PMBUS_POUT_MAX: /* R/W word */ if (pmdev->pages[index].page_flags & PB_HAS_VOUT) { pmdev->pages[index].pout_max = pmbus_receive16(pmdev); @@ -1482,6 +1502,10 @@ static int pmbus_write_data(SMBusDevice *smd, uint8_t *buf, uint8_t len) pmdev->pages[index].status_other = pmbus_receive8(pmdev); break; + case PMBUS_STATUS_MFR_SPECIFIC: /* R/W byte */ + pmdev->pages[index].status_mfr_specific = pmbus_receive8(pmdev); + 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 62bd38c83f..72c0483149 100644 --- a/include/hw/i2c/pmbus_device.h +++ b/include/hw/i2c/pmbus_device.h @@ -43,6 +43,7 @@ enum pmbus_registers { PMBUS_VOUT_DROOP = 0x28, /* R/W word */ PMBUS_VOUT_SCALE_LOOP = 0x29, /* R/W word */ PMBUS_VOUT_SCALE_MONITOR = 0x2A, /* R/W word */ + PMBUS_VOUT_MIN = 0x2B, /* R/W word */ PMBUS_COEFFICIENTS = 0x30, /* Read-only block 5 bytes */ PMBUS_POUT_MAX = 0x31, /* R/W word */ PMBUS_MAX_DUTY = 0x32, /* R/W word */ @@ -255,6 +256,7 @@ OBJECT_DECLARE_TYPE(PMBusDevice, PMBusDeviceClass, #define PB_HAS_TEMP3 BIT_ULL(42) #define PB_HAS_TEMP_RATING BIT_ULL(43) #define PB_HAS_MFR_INFO BIT_ULL(50) +#define PB_HAS_STATUS_MFR_SPECIFIC BIT_ULL(51) struct PMBusDeviceClass { SMBusDeviceClass parent_class; @@ -295,6 +297,7 @@ typedef struct PMBusPage { uint16_t vout_droop; /* R/W word */ uint16_t vout_scale_loop; /* R/W word */ uint16_t vout_scale_monitor; /* R/W word */ + uint16_t vout_min; /* R/W word */ uint8_t coefficients[5]; /* Read-only block 5 bytes */ uint16_t pout_max; /* R/W word */ uint16_t max_duty; /* R/W word */ From patchwork Wed Mar 2 00:23:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 12765298 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 2245EC433EF for ; Wed, 2 Mar 2022 00:31:40 +0000 (UTC) Received: from localhost ([::1]:53272 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPCu3-00083t-3q for qemu-devel@archiver.kernel.org; Tue, 01 Mar 2022 19:31:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38342) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3_bgeYgYKCgIvkvwutiqqing.eqosgow-fgxgnpqpipw.qti@flex--titusr.bounces.google.com>) id 1nPCsM-0006Lo-Aa for qemu-devel@nongnu.org; Tue, 01 Mar 2022 19:29:54 -0500 Received: from [2607:f8b0:4864:20::1149] (port=57234 helo=mail-yw1-x1149.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3_bgeYgYKCgIvkvwutiqqing.eqosgow-fgxgnpqpipw.qti@flex--titusr.bounces.google.com>) id 1nPCsK-00085I-7R for qemu-devel@nongnu.org; Tue, 01 Mar 2022 19:29:54 -0500 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2d6d36ec646so143650297b3.23 for ; Tue, 01 Mar 2022 16:29:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Y2EUdWJWmuYng2riwpVs90eiRzjJjFCIkE+E1jmTD+Y=; b=QP2mFJ7P2kORaGo6uuhsS19D0Uy6/4OMoWWS5LqizEHUT1u05R0AVRy2kXQmTHe7xE bqQP29gov2gtVUTjcJqRaf5p8i9fVXo8qctTCevw9TGVmvD8ijOtq53seujGePx/HJ3s b3+CAmG9opTKp/YOoSaI2vaJm4TUuN4Gd2ch6H4aB9SK7n/Id9/sfsAHOYmpUeyd+rI8 VXBU0Bi3HRI2OIB5bvSkDeVveFDHLqWLHzkNxJmnioNHJXS1NVsG/8cX6k8MLTWoKQKX NkURM6IDMlNmdhpSYw/r96+KL1oZZ6zdNau115wFfeSFZs5KZhBVMWau8fdrSMz5FvQv +7EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Y2EUdWJWmuYng2riwpVs90eiRzjJjFCIkE+E1jmTD+Y=; b=FKFPGGvaskA6JtGd2MLK3KaSpnl8NBn8lcDovNHY16bVGYMGPQDOyfDQBPKwavXGWQ EcDYVjA2hKkRFbznNBGLZLJExgd9XH/nOEqwD5FD0pr7ahUK6qPiEdl+kHQaHhRswjtQ MZAdzf0UaEAHGkj8WXd/mrNijvM8wvKJDPMJacfabxiSG9QMJpyWyhUX2jni1LdivFCm eka6W7c4WcdrtthKYDxTUs+IuZNu82QxLa68liHrM3wmE415g37T49LDaziScH/verkh QGP/t7U3XFVH0A7AovDG3JNzuytNbzMVQBVprtkYBiRGI+Ym2BOWa/sJVk2IdakLf8L7 +GAQ== X-Gm-Message-State: AOAM530056KGYl4so5EdZNM0V7d4UwSA6FZwVu3AcFwCabkIjpVbY66E l+6wUC8isxVF3BufIIurcvb4DMLanEk= X-Google-Smtp-Source: ABdhPJwH9k4NyQxg5DHTthz8sMzJhsmvaC0YmnDVaTyIGEHD3bTa8K76ehvzEyNCZORN5qPr4CEQVEwLlmI= X-Received: from titusr.svl.corp.google.com ([2620:15c:2a3:201:3a0a:5449:c096:dc84]) (user=titusr job=sendgmr) by 2002:a0d:cc93:0:b0:2db:931f:1e90 with SMTP id o141-20020a0dcc93000000b002db931f1e90mr11479404ywd.307.1646180605715; Tue, 01 Mar 2022 16:23:25 -0800 (PST) Date: Tue, 1 Mar 2022 16:23:00 -0800 In-Reply-To: <20220302002307.1895616-1-titusr@google.com> Message-Id: <20220302002307.1895616-3-titusr@google.com> Mime-Version: 1.0 References: <20220302002307.1895616-1-titusr@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v2 2/9] hw/i2c: pmbus: guard against out of range accesses From: Titus Rwantare To: Corey Minyard Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, f4bug@amsat.org, wuhaotsh@google.com, venture@google.com, Titus Rwantare X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::1149 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::1149; envelope-from=3_bgeYgYKCgIvkvwutiqqing.eqosgow-fgxgnpqpipw.qti@flex--titusr.bounces.google.com; helo=mail-yw1-x1149.google.com X-Spam_score_int: -81 X-Spam_score: -8.2 X-Spam_bar: -------- X-Spam_report: (-8.2 / 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, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=no 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" Signed-off-by: Titus Rwantare --- hw/i2c/pmbus_device.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/hw/i2c/pmbus_device.c b/hw/i2c/pmbus_device.c index 07a45c99f9..93c746bab3 100644 --- a/hw/i2c/pmbus_device.c +++ b/hw/i2c/pmbus_device.c @@ -243,18 +243,47 @@ void pmbus_check_limits(PMBusDevice *pmdev) } } +/* assert the status_cml error upon receipt of malformed command */ +static void pmbus_cml_error(PMBusDevice *pmdev) +{ + for (int i = 0; i < pmdev->num_pages; i++) { + pmdev->pages[i].status_word |= PMBUS_STATUS_CML; + pmdev->pages[i].status_cml |= PB_CML_FAULT_INVALID_CMD; + } +} + static uint8_t pmbus_receive_byte(SMBusDevice *smd) { PMBusDevice *pmdev = PMBUS_DEVICE(smd); PMBusDeviceClass *pmdc = PMBUS_DEVICE_GET_CLASS(pmdev); uint8_t ret = 0xFF; - uint8_t index = pmdev->page; + uint8_t index; if (pmdev->out_buf_len != 0) { ret = pmbus_out_buf_pop(pmdev); return ret; } + /* + * Reading from all pages will return the value from page 0, + * this is unspecified behaviour in general. + */ + if (pmdev->page == PB_ALL_PAGES) { + index = 0; + qemu_log_mask(LOG_GUEST_ERROR, + "%s: tried to read from all pages\n", + __func__); + pmbus_cml_error(pmdev); + } else if (pmdev->page > pmdev->num_pages - 1) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: page %d is out of range\n", + __func__, pmdev->page); + pmbus_cml_error(pmdev); + return -1; + } else { + index = pmdev->page; + } + switch (pmdev->code) { case PMBUS_PAGE: pmbus_send8(pmdev, pmdev->page); @@ -1038,6 +1067,7 @@ static int pmbus_write_data(SMBusDevice *smd, uint8_t *buf, uint8_t len) pmdev->page = pmbus_receive8(pmdev); return 0; } + /* loop through all the pages when 0xFF is received */ if (pmdev->page == PB_ALL_PAGES) { for (int i = 0; i < pmdev->num_pages; i++) { @@ -1048,6 +1078,15 @@ 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 -1; + } + index = pmdev->page; switch (pmdev->code) { From patchwork Wed Mar 2 00:23:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 12765294 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 C86ACC433FE for ; Wed, 2 Mar 2022 00:25:43 +0000 (UTC) Received: from localhost ([::1]:44784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPCoI-00021f-NU for qemu-devel@archiver.kernel.org; Tue, 01 Mar 2022 19:25:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36948) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3ALkeYgYKCgUynyzxwlttlqj.htrvjrz-ij0jqstslsz.twl@flex--titusr.bounces.google.com>) id 1nPCmD-0008Iu-6u for qemu-devel@nongnu.org; Tue, 01 Mar 2022 19:23:33 -0500 Received: from [2607:f8b0:4864:20::b49] (port=46638 helo=mail-yb1-xb49.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3ALkeYgYKCgUynyzxwlttlqj.htrvjrz-ij0jqstslsz.twl@flex--titusr.bounces.google.com>) id 1nPCmA-000368-Un for qemu-devel@nongnu.org; Tue, 01 Mar 2022 19:23:32 -0500 Received: by mail-yb1-xb49.google.com with SMTP id 11-20020a25030b000000b00628660166e7so4773ybd.13 for ; Tue, 01 Mar 2022 16:23:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=GlIJF2b8Drq45++1hxBTKoEZIPJ8E+QjOj/1FgeYUhM=; b=sn1nKXYaHzsRMxB1TWRuNZo3V+b3m3c5sqABtfOcwgHgmYMYoruKixCjWKdJ8MhvD1 qflGtQbnXthz7Qv2A9r2uGrD/AhDTjFvxqRau02kv+vwD5wRiG+MCdGK1sVx7ZleH9Sn 6qPn19pPXzBO7fOpG/VYKF580j95KYtA3Q+A/j6U3lZJ6/+9YtwWJ6oJ2yUtowEKLozv hzLYE1d5sj8tc2VSVhGB349cHVtgCl17V+PhJddZpE5yrYt+kC4Ay5m3h+UIGH2AI3tL s/6Ewbl96Cl2abf7nhuKcYupa/gw30W/nBPybfGcwEuMN/4k2sRLSKGYqTsl8ldpwX/B SyYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=GlIJF2b8Drq45++1hxBTKoEZIPJ8E+QjOj/1FgeYUhM=; b=uDmRI3ctwYocGGEA9ukpC01/AaRxy4XgM5zcbmhsi1YUGiLI/micwZdu//X9FcHme/ gEkVbeolKTuQNXY0H1BGI+Ctz/vZsjntRuYwh8jH0AyVw8bwBb1bZuf9tLBNbwHrBcde Uvfa2p/1FYW27wAtoqNiU66qlPK6f+I5QRzuX2yIxD21wsZcDFRwAK2J7dJmniV4YRZF 1HTrZhWN3M3UPAf6ma8HobaijsID/3SY1wZT7/2Ugbvcjb7A9R1LI/Uf1Pwb1f9K1s4m BmqCX6UuHAaPm3/nAIUgFoarSI8OLBtvFgaTVOP7Ov3ygJODznzl5Yn61Q2f/R29xDVp j7tA== X-Gm-Message-State: AOAM532AGuT4XFiz6TpFQank94hREm8ffRJ3JfhtvNnsFUUJkLG//rfe 6xQea0CQmK7pKiyTFWdKLjYkDDpP/Gg= X-Google-Smtp-Source: ABdhPJzD+eBhOgOrSrwWoP859a9fFOALAmLPpxt78fOsgG1WB8xBIt+DAq8DD4fVPw2Sjlhs6Y5ya7OL/dY= X-Received: from titusr.svl.corp.google.com ([2620:15c:2a3:201:3a0a:5449:c096:dc84]) (user=titusr job=sendgmr) by 2002:a0d:cac2:0:b0:2db:fc7f:7dfa with SMTP id m185-20020a0dcac2000000b002dbfc7f7dfamr3562025ywd.362.1646180608119; Tue, 01 Mar 2022 16:23:28 -0800 (PST) Date: Tue, 1 Mar 2022 16:23:01 -0800 In-Reply-To: <20220302002307.1895616-1-titusr@google.com> Message-Id: <20220302002307.1895616-4-titusr@google.com> Mime-Version: 1.0 References: <20220302002307.1895616-1-titusr@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v2 3/9] hw/i2c: pmbus: add PEC unsupported warning From: Titus Rwantare To: Corey Minyard Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, f4bug@amsat.org, wuhaotsh@google.com, venture@google.com, Titus Rwantare X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::b49 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::b49; envelope-from=3ALkeYgYKCgUynyzxwlttlqj.htrvjrz-ij0jqstslsz.twl@flex--titusr.bounces.google.com; helo=mail-yb1-xb49.google.com X-Spam_score_int: -81 X-Spam_score: -8.2 X-Spam_bar: -------- X-Spam_report: (-8.2 / 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, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=no 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" 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 93c746bab3..6eeb0731d7 100644 --- a/hw/i2c/pmbus_device.c +++ b/hw/i2c/pmbus_device.c @@ -307,6 +307,11 @@ static uint8_t pmbus_receive_byte(SMBusDevice *smd) case PMBUS_CAPABILITY: pmbus_send8(pmdev, pmdev->capability); + if (pmdev->capability & BIT(7)) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: PEC is enabled but not yet supported.\n", + __func__); + } break; case PMBUS_VOUT_MODE: /* R/W byte */ From patchwork Wed Mar 2 00:23:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 12765296 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 522FCC433EF for ; Wed, 2 Mar 2022 00:28:58 +0000 (UTC) Received: from localhost ([::1]:49190 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPCrQ-0005Ak-V3 for qemu-devel@archiver.kernel.org; Tue, 01 Mar 2022 19:28:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36978) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3ArkeYgYKCgc0p01zynvvnsl.jvtxlt1-kl2lsuvunu1.vyn@flex--titusr.bounces.google.com>) id 1nPCmF-0008KD-Hf for qemu-devel@nongnu.org; Tue, 01 Mar 2022 19:23:35 -0500 Received: from [2607:f8b0:4864:20::b49] (port=35806 helo=mail-yb1-xb49.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3ArkeYgYKCgc0p01zynvvnsl.jvtxlt1-kl2lsuvunu1.vyn@flex--titusr.bounces.google.com>) id 1nPCmC-0003EG-UJ for qemu-devel@nongnu.org; Tue, 01 Mar 2022 19:23:35 -0500 Received: by mail-yb1-xb49.google.com with SMTP id o133-20020a25738b000000b0062872621d0eso58502ybc.2 for ; Tue, 01 Mar 2022 16:23:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=LrEHKcKjE05/g4rjMk0dI58DYJGhZg8t/SLiblxBtcc=; b=M6BaK1VpN83SJom8rZcUTvur1jMW6EEZUrI9XWZfBy6BzmpohmhhdghrQyF5wYKDdO 3OH7gld6CxLtG3wiVc4Jlo3kivMD2Tfqz/qWxOrfv1ojVKk+KW6oFoZub3gL6u4p/NO/ 2i50U9jqajb14wYBVAzd6X1JCKw4O1GR9tZyR9yG7a4rXYjLSHcx8O5I/m3nyrTaCMQ5 BQNhLb2VXpeUNIUtTJONALTF6RZ4NLnLM51RlP+ZLTU/Ou8tT6M+HGDceKEvCeQCHxA/ 9WGqiNGmuDMIJM9ZKqKSAYPCUqsftHU/lrGdZZhJgAq5vr3nLsWWlnkjtSwOaxhqBIeZ 3oJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=LrEHKcKjE05/g4rjMk0dI58DYJGhZg8t/SLiblxBtcc=; b=EtqcOx6mTQ61Jl1aKz+NnHfWpD0Gt9YqkoIQfkJU4dc2AEFCdH+slSwq7wj/ePoZsE 0D62NeoMnnL7yB8ic4XzxzY04zYL2CMBEKkeVgcNQgBfvpQR2eIdBgmAw00D3KYfRaNb vfPEozDG+T2MqN+pBNbI0BxCFsCGYJdOXGygO4R5Oca6PSrsJDGkILPzn3NAauBSMEMd VIX3wphOATEfuRtgfZnjfJ4MaZqKeO0XsL5z2Iwag/hx7J1rGAPc0PS4Fc6cFJbizkot dfn3kS2uA1wGB2pVdKlfN1KC7J73L1zdN/n+tpYn4N2eURHdTRYxNYxSKLZZT394nOoN tQbQ== X-Gm-Message-State: AOAM532XpATbcbSyL0H+5hNVPapgEi4NKuJ2WfmScHmll39kBoXid102 X0On9z+JgWyr6FviqFio77uDfYkRTFo= X-Google-Smtp-Source: ABdhPJy6FXr/256rw2344nE+l5zkTQRY8j/die2Cvll8sh09Wqs+1ddIZM9h05HV3Kw8bM7BjeunkhZTL94= X-Received: from titusr.svl.corp.google.com ([2620:15c:2a3:201:3a0a:5449:c096:dc84]) (user=titusr job=sendgmr) by 2002:a25:d341:0:b0:624:3ec2:b7bf with SMTP id e62-20020a25d341000000b006243ec2b7bfmr26168254ybf.518.1646180610616; Tue, 01 Mar 2022 16:23:30 -0800 (PST) Date: Tue, 1 Mar 2022 16:23:02 -0800 In-Reply-To: <20220302002307.1895616-1-titusr@google.com> Message-Id: <20220302002307.1895616-5-titusr@google.com> Mime-Version: 1.0 References: <20220302002307.1895616-1-titusr@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v2 4/9] hw/i2c: pmbus: refactor uint handling and update MAINTAINERS From: Titus Rwantare To: Corey Minyard Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, f4bug@amsat.org, wuhaotsh@google.com, venture@google.com, Titus Rwantare X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::b49 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::b49; envelope-from=3ArkeYgYKCgc0p01zynvvnsl.jvtxlt1-kl2lsuvunu1.vyn@flex--titusr.bounces.google.com; helo=mail-yb1-xb49.google.com X-Spam_score_int: -81 X-Spam_score: -8.2 X-Spam_bar: -------- X-Spam_report: (-8.2 / 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, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=no 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" Signed-off-by: Titus Rwantare --- MAINTAINERS | 10 ++++++++++ hw/i2c/pmbus_device.c | 18 +++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index fa8adc2618..3601984b5d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3135,6 +3135,16 @@ F: include/hw/i2c/smbus_master.h F: include/hw/i2c/smbus_slave.h F: include/hw/i2c/smbus_eeprom.h +PMBus +M: Titus Rwantare +S: Maintained +F: hw/i2c/pmbus_device.c +F: hw/sensor/adm1272.c +F: hw/sensor/max34451.c +F: include/hw/i2c/pmbus_device.h +F: tests/qtest/adm1272-test.c +F: tests/qtest/max34451-test.c + Firmware schema specifications M: Philippe Mathieu-Daudé R: Daniel P. Berrange diff --git a/hw/i2c/pmbus_device.c b/hw/i2c/pmbus_device.c index 6eeb0731d7..3beb02afad 100644 --- a/hw/i2c/pmbus_device.c +++ b/hw/i2c/pmbus_device.c @@ -89,16 +89,16 @@ void pmbus_send_string(PMBusDevice *pmdev, const char *data) } -static uint64_t pmbus_receive_uint(const uint8_t *buf, uint8_t len) +static uint64_t pmbus_receive_uint(PMBusDevice *pmdev) { uint64_t ret = 0; /* Exclude command code from return value */ - buf++; - len--; + pmdev->in_buf++; + pmdev->in_buf_len--; - for (int i = len - 1; i >= 0; i--) { - ret = ret << 8 | buf[i]; + for (int i = pmdev->in_buf_len - 1; i >= 0; i--) { + ret = ret << 8 | pmdev->in_buf[i]; } return ret; } @@ -110,7 +110,7 @@ uint8_t pmbus_receive8(PMBusDevice *pmdev) "%s: length mismatch. Expected 1 byte, got %d bytes\n", __func__, pmdev->in_buf_len - 1); } - return pmbus_receive_uint(pmdev->in_buf, pmdev->in_buf_len); + return pmbus_receive_uint(pmdev); } uint16_t pmbus_receive16(PMBusDevice *pmdev) @@ -120,7 +120,7 @@ uint16_t pmbus_receive16(PMBusDevice *pmdev) "%s: length mismatch. Expected 2 bytes, got %d bytes\n", __func__, pmdev->in_buf_len - 1); } - return pmbus_receive_uint(pmdev->in_buf, pmdev->in_buf_len); + return pmbus_receive_uint(pmdev); } uint32_t pmbus_receive32(PMBusDevice *pmdev) @@ -130,7 +130,7 @@ uint32_t pmbus_receive32(PMBusDevice *pmdev) "%s: length mismatch. Expected 4 bytes, got %d bytes\n", __func__, pmdev->in_buf_len - 1); } - return pmbus_receive_uint(pmdev->in_buf, pmdev->in_buf_len); + return pmbus_receive_uint(pmdev); } uint64_t pmbus_receive64(PMBusDevice *pmdev) @@ -140,7 +140,7 @@ uint64_t pmbus_receive64(PMBusDevice *pmdev) "%s: length mismatch. Expected 8 bytes, got %d bytes\n", __func__, pmdev->in_buf_len - 1); } - return pmbus_receive_uint(pmdev->in_buf, pmdev->in_buf_len); + return pmbus_receive_uint(pmdev); } static uint8_t pmbus_out_buf_pop(PMBusDevice *pmdev) From patchwork Wed Mar 2 00:23:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 12765297 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 6AA24C433F5 for ; Wed, 2 Mar 2022 00:31:16 +0000 (UTC) Received: from localhost ([::1]:52646 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPCtf-0007Xz-FW for qemu-devel@archiver.kernel.org; Tue, 01 Mar 2022 19:31:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37030) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3BLkeYgYKCgk2r2310pxxpun.lxvznv3-mn4nuwxwpw3.x0p@flex--titusr.bounces.google.com>) id 1nPCmK-0008Mt-2U for qemu-devel@nongnu.org; Tue, 01 Mar 2022 19:23:40 -0500 Received: from [2607:f8b0:4864:20::b49] (port=39429 helo=mail-yb1-xb49.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3BLkeYgYKCgk2r2310pxxpun.lxvznv3-mn4nuwxwpw3.x0p@flex--titusr.bounces.google.com>) id 1nPCmH-0003Ew-51 for qemu-devel@nongnu.org; Tue, 01 Mar 2022 19:23:38 -0500 Received: by mail-yb1-xb49.google.com with SMTP id a12-20020a056902056c00b0061dc0f2a94aso22219ybt.6 for ; Tue, 01 Mar 2022 16:23:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=OuDjxU+Qw15BrOXbTXRNYAwlXoR5HJ4CkiZU3oZNlcE=; b=mO5CUDor+WI9zZ1oHZfOBwMGxSPf6O7bUsACSSTY/eohY7BbMKskHLAYUi0pG5x/yn BnGP41fUlFfNQ8uFsn9dwjDnivBa+7D6yuBMapQPkokb2RO5/TEv6eF7SKm6ofMxW7FV MASkJF/JtxGNdiJropwF8nB4g1jtRtqXvmmFmeX5c4yexYHWIPUflg7S5nLyB7ZOfnwy a+iLoNF5lDuEHFpkG+NrHAXko3y+WDTBIUy5gj8dnhOjmxTPfgsfajsSN1U+ddi82jBG QUGaOZ3EMrYIzTFx+DMeDqRTNle79Iq7dK1rIYjPUbX/VO8oliwr6fFYwCeWzCHbf7XU maSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=OuDjxU+Qw15BrOXbTXRNYAwlXoR5HJ4CkiZU3oZNlcE=; b=eBdeM28gGq2l3lBjcTigqaHyEqQ1szKGQS/lWSGtuRiFsjjsmGMbQlrYbF4zbJ1ay5 PQDgE/fIgpRVuGmfg5jPVdKzmJzGYlDVo3LX2bDSTeOm7KH9FOzGarzp5fdAeZewM0X4 Rk+0s1HVSXXHZOvoExMXTrrq/TqQY0D16mE4qOO+6eQ3atOuODAvuC5HyXRfkix7KWnS DCWlJREHqhwGEfEWFYl7g6gPf/CcP8+lMW3+3hKPiEPfYtegh3BIO7pVPcZc9fmfDDrv czKpbgbPNXW6sG5JFTQwmmmhtp4S68P92SfVLAFNlgWFjr6qgcZc75viHmWpSjKehCXc mjxA== X-Gm-Message-State: AOAM533SZHrInTv0/n5ZM2gwSqUn3E7/NY5VKiXySstYJiITt2Zy18c4 +TkfoLhokqQsXRjgLwm7MfS13IuaG0g= X-Google-Smtp-Source: ABdhPJwW0gm81h/ePVSgzn7Axarntcgd4X+AP2uIsifpWz5yR/aT6pyI0eAzk/ZJrWdED0fKmwPiZnEjyuM= X-Received: from titusr.svl.corp.google.com ([2620:15c:2a3:201:3a0a:5449:c096:dc84]) (user=titusr job=sendgmr) by 2002:a25:b004:0:b0:621:f386:f10a with SMTP id q4-20020a25b004000000b00621f386f10amr25596459ybf.314.1646180612929; Tue, 01 Mar 2022 16:23:32 -0800 (PST) Date: Tue, 1 Mar 2022 16:23:03 -0800 In-Reply-To: <20220302002307.1895616-1-titusr@google.com> Message-Id: <20220302002307.1895616-6-titusr@google.com> Mime-Version: 1.0 References: <20220302002307.1895616-1-titusr@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v2 5/9] hw/i2c: Added linear mode translation for pmbus devices From: Titus Rwantare To: Corey Minyard Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, f4bug@amsat.org, wuhaotsh@google.com, venture@google.com, Shengtan Mao , Titus Rwantare X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::b49 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::b49; envelope-from=3BLkeYgYKCgk2r2310pxxpun.lxvznv3-mn4nuwxwpw3.x0p@flex--titusr.bounces.google.com; helo=mail-yb1-xb49.google.com X-Spam_score_int: -81 X-Spam_score: -8.2 X-Spam_bar: -------- X-Spam_report: (-8.2 / 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, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=no 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" From: Shengtan Mao Signed-off-by: Shengtan Mao Reviewed-by: Titus Rwantare --- hw/i2c/pmbus_device.c | 18 ++++++++++++++++++ include/hw/i2c/pmbus_device.h | 20 +++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/hw/i2c/pmbus_device.c b/hw/i2c/pmbus_device.c index 3beb02afad..1036c41c49 100644 --- a/hw/i2c/pmbus_device.c +++ b/hw/i2c/pmbus_device.c @@ -28,6 +28,24 @@ uint32_t pmbus_direct_mode2data(PMBusCoefficients c, uint16_t value) return x; } +uint16_t pmbus_data2linear_mode(uint16_t value, int exp) +{ + /* L = D * 2^(-e) */ + if (exp < 0) { + return value << (-exp); + } + return value >> exp; +} + +uint16_t pmbus_linear_mode2data(uint16_t value, int exp) +{ + /* D = L * 2^e */ + if (exp < 0) { + return value >> (-exp); + } + return value << exp; +} + void pmbus_send(PMBusDevice *pmdev, const uint8_t *data, uint16_t len) { if (pmdev->out_buf_len + len > SMBUS_DATA_MAX_LEN) { diff --git a/include/hw/i2c/pmbus_device.h b/include/hw/i2c/pmbus_device.h index 72c0483149..9a274247ab 100644 --- a/include/hw/i2c/pmbus_device.h +++ b/include/hw/i2c/pmbus_device.h @@ -446,7 +446,7 @@ typedef struct PMBusCoefficients { * * Y = (m * x - b) * 10^R * - * @return uint32_t + * @return uint16_t */ uint16_t pmbus_data2direct_mode(PMBusCoefficients c, uint32_t value); @@ -459,6 +459,24 @@ uint16_t pmbus_data2direct_mode(PMBusCoefficients c, uint32_t value); */ uint32_t pmbus_direct_mode2data(PMBusCoefficients c, uint16_t value); +/** + * Convert sensor values to linear mode format + * + * L = D * 2^(-e) + * + * @return uint16 + */ +uint16_t pmbus_data2linear_mode(uint16_t value, int exp); + +/** + * Convert linear mode formatted data into sensor reading + * + * D = L * 2^e + * + * @return uint16 + */ +uint16_t pmbus_linear_mode2data(uint16_t value, int exp); + /** * @brief Send a block of data over PMBus * Assumes that the bytes in the block are already ordered correctly, From patchwork Wed Mar 2 00:23:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 12765300 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 79D35C433F5 for ; Wed, 2 Mar 2022 00:34:41 +0000 (UTC) Received: from localhost ([::1]:58912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPCwy-0003ZU-6P for qemu-devel@archiver.kernel.org; Tue, 01 Mar 2022 19:34:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37068) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3B7keYgYKCgw5u5643s00sxq.o0y2qy6-pq7qxz0zsz6.03s@flex--titusr.bounces.google.com>) id 1nPCmM-0008QY-K7 for qemu-devel@nongnu.org; Tue, 01 Mar 2022 19:23:45 -0500 Received: from [2607:f8b0:4864:20::b4a] (port=45846 helo=mail-yb1-xb4a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3B7keYgYKCgw5u5643s00sxq.o0y2qy6-pq7qxz0zsz6.03s@flex--titusr.bounces.google.com>) id 1nPCmJ-0003GQ-Ey for qemu-devel@nongnu.org; Tue, 01 Mar 2022 19:23:42 -0500 Received: by mail-yb1-xb4a.google.com with SMTP id n66-20020a254045000000b0062883b59ddbso7454yba.12 for ; Tue, 01 Mar 2022 16:23:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=ORgyDoOCIEOUL8U3dnyT06mU04ZD6Ohk7/GG6LMS5t4=; b=iPEkWtbtXd3RXJczgUw7zNMR5U+vWtC5rXfDZLw6VgeXfpduhSI3AEavfGqDQA2pVs ufDtwmV56wOwbbXB9Th7HJyjfVnkgrc9DI8p83c6i51tGy1hUYvpXW82OuYuRUVo+K0h mgNj6kV12PGBJjGrkzqvhfxFrfDNtU9IyG1eTJWZcIPzwR0gob9cDyFe53cbPEwH/LWP FdRMTuV/GjVT76N0No/zAgZrJQc88df2nkh1otcL2qiMaF9l7c+MpIyfCnFYTga/JIXu CudL4qGF638S/nZgUVcUnVCQ+CHcS2F6VYS9ZK+za9JiuNrspRUMRF80cQznVTohhvix KdPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=ORgyDoOCIEOUL8U3dnyT06mU04ZD6Ohk7/GG6LMS5t4=; b=bpFLQmqp2LLwX7m037arfPZ3vtHf8gxhFN9MTFmVbxJCnzPxm6/+mLS+HIyfpd/yOb PzBqDGAxZOFh/L38tBXpADlwicB4d4ZIVCrxwpyWtiG7R5M1b0RkkbqywrC1YYZeX8wu 3LOaSthaskxg/4MsMidsctJ9jsSyXP4CpZ+e8kkeZODDa1VWzDhKZFQn2L9U6R1PehaG iffRq9Ag58EpOr64nikGyujlewPo7x5tpUhGiuhjTIxPpfFL9fXuXNWLsh4YTpklYAhN sEVmRxssOCf2kHXWqFKuaQ5EfpwGUcPcezaYzz8FBTWr6CPhbT9iX7iPyDD4904RPHcX tsUg== X-Gm-Message-State: AOAM532TvjW3xDqInYk3DvnfLC5ptByOA4r4q955u6RswTCp3YMtHHig Q0jBSzB1ARr2GUXECyXyZ5UteXx+G2Q= X-Google-Smtp-Source: ABdhPJxwu6uBNiqa97jcufFedZ/c8/Abv8LtMzVoe3tBtuWirZpyR4AwQe5l/+z1A/BpzU+5VY2uZIysljg= X-Received: from titusr.svl.corp.google.com ([2620:15c:2a3:201:3a0a:5449:c096:dc84]) (user=titusr job=sendgmr) by 2002:a81:4a08:0:b0:2d1:19d7:1902 with SMTP id x8-20020a814a08000000b002d119d71902mr27614032ywa.337.1646180615152; Tue, 01 Mar 2022 16:23:35 -0800 (PST) Date: Tue, 1 Mar 2022 16:23:04 -0800 In-Reply-To: <20220302002307.1895616-1-titusr@google.com> Message-Id: <20220302002307.1895616-7-titusr@google.com> Mime-Version: 1.0 References: <20220302002307.1895616-1-titusr@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v2 6/9] hw/sensor: add Intersil ISL69260 device model From: Titus Rwantare To: Corey Minyard Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, f4bug@amsat.org, wuhaotsh@google.com, venture@google.com, Titus Rwantare X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::b4a (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::b4a; envelope-from=3B7keYgYKCgw5u5643s00sxq.o0y2qy6-pq7qxz0zsz6.03s@flex--titusr.bounces.google.com; helo=mail-yb1-xb4a.google.com X-Spam_score_int: -81 X-Spam_score: -8.2 X-Spam_bar: -------- X-Spam_report: (-8.2 / 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, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=no 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" Signed-off-by: Titus Rwantare Reviewed-by: Hao Wu --- MAINTAINERS | 3 + hw/arm/Kconfig | 1 + hw/sensor/Kconfig | 5 + hw/sensor/isl_pmbus.c | 210 ++++++++++++++++++ hw/sensor/meson.build | 1 + include/hw/sensor/isl_pmbus.h | 50 +++++ tests/qtest/isl_pmbus-test.c | 393 ++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 1 + 8 files changed, 664 insertions(+) create mode 100644 hw/sensor/isl_pmbus.c create mode 100644 include/hw/sensor/isl_pmbus.h create mode 100644 tests/qtest/isl_pmbus-test.c diff --git a/MAINTAINERS b/MAINTAINERS index 3601984b5d..3df8e938e0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3140,10 +3140,13 @@ M: Titus Rwantare S: Maintained F: hw/i2c/pmbus_device.c F: hw/sensor/adm1272.c +F: hw/sensor/isl_pmbus.c F: hw/sensor/max34451.c F: include/hw/i2c/pmbus_device.h +F: include/hw/sensor/isl_pmbus.h F: tests/qtest/adm1272-test.c F: tests/qtest/max34451-test.c +F: tests/qtest/isl_pmbus-test.c Firmware schema specifications M: Philippe Mathieu-Daudé diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 6945330030..8047ad6378 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -400,6 +400,7 @@ config NPCM7XX select SMBUS select AT24C # EEPROM select MAX34451 + select ISL_PMBUS select PL310 # cache controller select PMBUS select SERIAL diff --git a/hw/sensor/Kconfig b/hw/sensor/Kconfig index 215944decc..70fb335789 100644 --- a/hw/sensor/Kconfig +++ b/hw/sensor/Kconfig @@ -30,3 +30,8 @@ config LSM303DLHC_MAG bool depends on I2C default y if I2C_DEVICES + +config ISL_PMBUS + bool + depends on I2C + diff --git a/hw/sensor/isl_pmbus.c b/hw/sensor/isl_pmbus.c new file mode 100644 index 0000000000..8cc7220a57 --- /dev/null +++ b/hw/sensor/isl_pmbus.c @@ -0,0 +1,210 @@ +/* + * PMBus device for Renesas Digital Multiphase Voltage Regulators + * + * Copyright 2021 Google LLC + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/sensor/isl_pmbus.h" +#include "hw/qdev-properties.h" +#include "qapi/visitor.h" +#include "qemu/log.h" +#include "qemu/module.h" + +static uint8_t isl_pmbus_read_byte(PMBusDevice *pmdev) +{ + qemu_log_mask(LOG_GUEST_ERROR, + "%s: reading from unsupported register: 0x%02x\n", + __func__, pmdev->code); + return 0xFF; +} + +static int isl_pmbus_write_data(PMBusDevice *pmdev, const uint8_t *buf, + uint8_t len) +{ + qemu_log_mask(LOG_GUEST_ERROR, + "%s: write to unsupported register: 0x%02x\n", + __func__, pmdev->code); + return 0xFF; +} + +/* TODO: Implement coefficients support in pmbus_device.c for qmp */ +static void isl_pmbus_get(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + visit_type_uint16(v, name, (uint16_t *)opaque, errp); +} + +static void isl_pmbus_set(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + PMBusDevice *pmdev = PMBUS_DEVICE(obj); + uint16_t *internal = opaque; + uint16_t value; + if (!visit_type_uint16(v, name, &value, errp)) { + return; + } + + *internal = value; + pmbus_check_limits(pmdev); +} + +static void isl_pmbus_exit_reset(Object *obj) +{ + PMBusDevice *pmdev = PMBUS_DEVICE(obj); + + pmdev->page = 0; + pmdev->capability = ISL_CAPABILITY_DEFAULT; + for (int i = 0; i < pmdev->num_pages; i++) { + pmdev->pages[i].operation = ISL_OPERATION_DEFAULT; + pmdev->pages[i].on_off_config = ISL_ON_OFF_CONFIG_DEFAULT; + pmdev->pages[i].vout_mode = ISL_VOUT_MODE_DEFAULT; + pmdev->pages[i].vout_command = ISL_VOUT_COMMAND_DEFAULT; + pmdev->pages[i].vout_max = ISL_VOUT_MAX_DEFAULT; + pmdev->pages[i].vout_margin_high = ISL_VOUT_MARGIN_HIGH_DEFAULT; + pmdev->pages[i].vout_margin_low = ISL_VOUT_MARGIN_LOW_DEFAULT; + pmdev->pages[i].vout_transition_rate = ISL_VOUT_TRANSITION_RATE_DEFAULT; + pmdev->pages[i].vout_ov_fault_limit = ISL_VOUT_OV_FAULT_LIMIT_DEFAULT; + pmdev->pages[i].ot_fault_limit = ISL_OT_FAULT_LIMIT_DEFAULT; + pmdev->pages[i].ot_warn_limit = ISL_OT_WARN_LIMIT_DEFAULT; + pmdev->pages[i].vin_ov_warn_limit = ISL_VIN_OV_WARN_LIMIT_DEFAULT; + pmdev->pages[i].vin_uv_warn_limit = ISL_VIN_UV_WARN_LIMIT_DEFAULT; + pmdev->pages[i].iin_oc_fault_limit = ISL_IIN_OC_FAULT_LIMIT_DEFAULT; + pmdev->pages[i].ton_delay = ISL_TON_DELAY_DEFAULT; + pmdev->pages[i].ton_rise = ISL_TON_RISE_DEFAULT; + pmdev->pages[i].toff_fall = ISL_TOFF_FALL_DEFAULT; + pmdev->pages[i].revision = ISL_REVISION_DEFAULT; + + pmdev->pages[i].read_vout = ISL_READ_VOUT_DEFAULT; + pmdev->pages[i].read_iout = ISL_READ_IOUT_DEFAULT; + pmdev->pages[i].read_pout = ISL_READ_POUT_DEFAULT; + pmdev->pages[i].read_vin = ISL_READ_VIN_DEFAULT; + pmdev->pages[i].read_iin = ISL_READ_IIN_DEFAULT; + pmdev->pages[i].read_pin = ISL_READ_PIN_DEFAULT; + pmdev->pages[i].read_temperature_1 = ISL_READ_TEMP_DEFAULT; + pmdev->pages[i].read_temperature_2 = ISL_READ_TEMP_DEFAULT; + pmdev->pages[i].read_temperature_3 = ISL_READ_TEMP_DEFAULT; + } +} + +static void isl_pmbus_add_props(Object *obj, uint64_t *flags, uint8_t pages) +{ + PMBusDevice *pmdev = PMBUS_DEVICE(obj); + for (int i = 0; i < pages; i++) { + if (flags[i] & PB_HAS_VIN) { + object_property_add(obj, "vin[*]", "uint16", + isl_pmbus_get, + isl_pmbus_set, + NULL, &pmdev->pages[i].read_vin); + } + + if (flags[i] & PB_HAS_VOUT) { + object_property_add(obj, "vout[*]", "uint16", + isl_pmbus_get, + isl_pmbus_set, + NULL, &pmdev->pages[i].read_vout); + } + + if (flags[i] & PB_HAS_IIN) { + object_property_add(obj, "iin[*]", "uint16", + isl_pmbus_get, + isl_pmbus_set, + NULL, &pmdev->pages[i].read_iin); + } + + if (flags[i] & PB_HAS_IOUT) { + object_property_add(obj, "iout[*]", "uint16", + isl_pmbus_get, + isl_pmbus_set, + NULL, &pmdev->pages[i].read_iout); + } + + if (flags[i] & PB_HAS_PIN) { + object_property_add(obj, "pin[*]", "uint16", + isl_pmbus_get, + isl_pmbus_set, + NULL, &pmdev->pages[i].read_pin); + } + + if (flags[i] & PB_HAS_POUT) { + object_property_add(obj, "pout[*]", "uint16", + isl_pmbus_get, + isl_pmbus_set, + NULL, &pmdev->pages[i].read_pout); + } + + if (flags[i] & PB_HAS_TEMPERATURE) { + object_property_add(obj, "temp1[*]", "uint16", + isl_pmbus_get, + isl_pmbus_set, + NULL, &pmdev->pages[i].read_temperature_1); + } + + if (flags[i] & PB_HAS_TEMP2) { + object_property_add(obj, "temp2[*]", "uint16", + isl_pmbus_get, + isl_pmbus_set, + NULL, &pmdev->pages[i].read_temperature_2); + } + + if (flags[i] & PB_HAS_TEMP3) { + object_property_add(obj, "temp3[*]", "uint16", + isl_pmbus_get, + isl_pmbus_set, + NULL, &pmdev->pages[i].read_temperature_3); + } + } +} + +static void raa22xx_init(Object *obj) +{ + PMBusDevice *pmdev = PMBUS_DEVICE(obj); + uint64_t flags[2]; + + flags[0] = PB_HAS_VIN | PB_HAS_VOUT | PB_HAS_VOUT_MODE | + PB_HAS_VOUT_RATING | PB_HAS_VOUT_MARGIN | PB_HAS_IIN | + PB_HAS_IOUT | PB_HAS_PIN | PB_HAS_POUT | PB_HAS_TEMPERATURE | + PB_HAS_TEMP2 | PB_HAS_TEMP3 | PB_HAS_STATUS_MFR_SPECIFIC; + flags[1] = PB_HAS_IIN | PB_HAS_PIN | PB_HAS_TEMPERATURE | PB_HAS_TEMP3 | + PB_HAS_VOUT | PB_HAS_VOUT_MODE | PB_HAS_VOUT_MARGIN | + PB_HAS_VOUT_RATING | PB_HAS_IOUT | PB_HAS_POUT | + PB_HAS_STATUS_MFR_SPECIFIC; + + pmbus_page_config(pmdev, 0, flags[0]); + pmbus_page_config(pmdev, 1, flags[1]); + isl_pmbus_add_props(obj, flags, 2); +} + +static void isl_pmbus_class_init(ObjectClass *klass, void *data, uint8_t pages) +{ + PMBusDeviceClass *k = PMBUS_DEVICE_CLASS(klass); + k->write_data = isl_pmbus_write_data; + k->receive_byte = isl_pmbus_read_byte; + k->device_num_pages = pages; +} + +static void isl69260_class_init(ObjectClass *klass, void *data) +{ + ResettableClass *rc = RESETTABLE_CLASS(klass); + DeviceClass *dc = DEVICE_CLASS(klass); + dc->desc = "Renesas ISL69260 Digital Multiphase Voltage Regulator"; + rc->phases.exit = isl_pmbus_exit_reset; + isl_pmbus_class_init(klass, data, 2); +} + +static const TypeInfo isl69260_info = { + .name = TYPE_ISL69260, + .parent = TYPE_PMBUS_DEVICE, + .instance_size = sizeof(ISLState), + .instance_init = raa22xx_init, + .class_init = isl69260_class_init, +}; + +static void isl_pmbus_register_types(void) +{ + type_register_static(&isl69260_info); +} + +type_init(isl_pmbus_register_types) diff --git a/hw/sensor/meson.build b/hw/sensor/meson.build index d1bba290da..2e82991ff1 100644 --- a/hw/sensor/meson.build +++ b/hw/sensor/meson.build @@ -5,3 +5,4 @@ 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_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', if_true: files('isl_pmbus.c')) diff --git a/include/hw/sensor/isl_pmbus.h b/include/hw/sensor/isl_pmbus.h new file mode 100644 index 0000000000..8115aaa698 --- /dev/null +++ b/include/hw/sensor/isl_pmbus.h @@ -0,0 +1,50 @@ +/* + * PMBus device for Renesas Digital Multiphase Voltage Regulators + * + * Copyright 2022 Google LLC + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HW_MISC_ISL_PMBUS_H +#define HW_MISC_ISL_PMBUS_H + +#include "hw/i2c/pmbus_device.h" +#include "qom/object.h" + +#define TYPE_ISL69260 "isl69260" + +struct ISLState { + PMBusDevice parent; +}; + +OBJECT_DECLARE_SIMPLE_TYPE(ISLState, ISL69260) + +#define ISL_CAPABILITY_DEFAULT 0x40 +#define ISL_OPERATION_DEFAULT 0x80 +#define ISL_ON_OFF_CONFIG_DEFAULT 0x16 +#define ISL_VOUT_MODE_DEFAULT 0x40 +#define ISL_VOUT_COMMAND_DEFAULT 0x0384 +#define ISL_VOUT_MAX_DEFAULT 0x08FC +#define ISL_VOUT_MARGIN_HIGH_DEFAULT 0x0640 +#define ISL_VOUT_MARGIN_LOW_DEFAULT 0xFA +#define ISL_VOUT_TRANSITION_RATE_DEFAULT 0x64 +#define ISL_VOUT_OV_FAULT_LIMIT_DEFAULT 0x076C +#define ISL_OT_FAULT_LIMIT_DEFAULT 0x7D +#define ISL_OT_WARN_LIMIT_DEFAULT 0x07D0 +#define ISL_VIN_OV_WARN_LIMIT_DEFAULT 0x36B0 +#define ISL_VIN_UV_WARN_LIMIT_DEFAULT 0x1F40 +#define ISL_IIN_OC_FAULT_LIMIT_DEFAULT 0x32 +#define ISL_TON_DELAY_DEFAULT 0x14 +#define ISL_TON_RISE_DEFAULT 0x01F4 +#define ISL_TOFF_FALL_DEFAULT 0x01F4 +#define ISL_REVISION_DEFAULT 0x33 +#define ISL_READ_VOUT_DEFAULT 1000 +#define ISL_READ_IOUT_DEFAULT 40 +#define ISL_READ_POUT_DEFAULT 4 +#define ISL_READ_TEMP_DEFAULT 25 +#define ISL_READ_VIN_DEFAULT 1100 +#define ISL_READ_IIN_DEFAULT 40 +#define ISL_READ_PIN_DEFAULT 4 + +#endif diff --git a/tests/qtest/isl_pmbus-test.c b/tests/qtest/isl_pmbus-test.c new file mode 100644 index 0000000000..59fa67f110 --- /dev/null +++ b/tests/qtest/isl_pmbus-test.c @@ -0,0 +1,393 @@ +/* + * QTests for the ISL_PMBUS digital voltage regulators + * + * Copyright 2021 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "qemu/osdep.h" +#include +#include "hw/i2c/pmbus_device.h" +#include "hw/sensor/isl_pmbus.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 "isl_pmbus-test" +#define TEST_ADDR (0x43) + +static uint16_t qmp_isl_pmbus_get(const char *id, const char *property) +{ + QDict *response; + uint64_t ret; + + response = qmp("{ 'execute': 'qom-get', 'arguments': { 'path': %s, " + "'property': %s } }", id, property); + g_assert(qdict_haskey(response, "return")); + ret = qnum_get_uint(qobject_to(QNum, qdict_get(response, "return"))); + qobject_unref(response); + return ret; +} + +static void qmp_isl_pmbus_set(const char *id, + const char *property, + uint16_t value) +{ + QDict *response; + + response = qmp("{ 'execute': 'qom-set', 'arguments': { 'path': %s, " + "'property': %s, 'value': %u } }", id, property, value); + g_assert(qdict_haskey(response, "return")); + qobject_unref(response); +} + +/* PMBus commands are little endian vs i2c_set16 in i2c.h which is big endian */ +static uint16_t isl_pmbus_i2c_get16(QI2CDevice *i2cdev, uint8_t reg) +{ + uint8_t resp[2]; + i2c_read_block(i2cdev, reg, resp, sizeof(resp)); + return (resp[1] << 8) | resp[0]; +} + +/* PMBus commands are little endian vs i2c_set16 in i2c.h which is big endian */ +static void isl_pmbus_i2c_set16(QI2CDevice *i2cdev, uint8_t reg, uint16_t value) +{ + uint8_t data[2]; + + data[0] = value & 255; + data[1] = value >> 8; + i2c_write_block(i2cdev, reg, data, sizeof(data)); +} + +static void test_defaults(void *obj, void *data, QGuestAllocator *alloc) +{ + uint16_t value, i2c_value; + QI2CDevice *i2cdev = (QI2CDevice *)obj; + + value = qmp_isl_pmbus_get(TEST_ID, "vout[0]"); + g_assert_cmpuint(value, ==, ISL_READ_VOUT_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_IOUT); + g_assert_cmpuint(i2c_value, ==, ISL_READ_IOUT_DEFAULT); + + value = qmp_isl_pmbus_get(TEST_ID, "pout[0]"); + g_assert_cmpuint(value, ==, ISL_READ_POUT_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_VIN); + g_assert_cmpuint(i2c_value, ==, ISL_READ_VIN_DEFAULT); + + value = qmp_isl_pmbus_get(TEST_ID, "iin[0]"); + g_assert_cmpuint(value, ==, ISL_READ_IIN_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_PIN); + g_assert_cmpuint(i2c_value, ==, ISL_READ_PIN_DEFAULT); + + value = qmp_isl_pmbus_get(TEST_ID, "temp1[0]"); + g_assert_cmpuint(value, ==, ISL_READ_TEMP_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_2); + g_assert_cmpuint(i2c_value, ==, ISL_READ_TEMP_DEFAULT); + + i2c_value = i2c_get8(i2cdev, PMBUS_CAPABILITY); + g_assert_cmphex(i2c_value, ==, ISL_CAPABILITY_DEFAULT); + + i2c_value = i2c_get8(i2cdev, PMBUS_OPERATION); + g_assert_cmphex(i2c_value, ==, ISL_OPERATION_DEFAULT); + + i2c_value = i2c_get8(i2cdev, PMBUS_ON_OFF_CONFIG); + g_assert_cmphex(i2c_value, ==, ISL_ON_OFF_CONFIG_DEFAULT); + + i2c_value = i2c_get8(i2cdev, PMBUS_VOUT_MODE); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_MODE_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_COMMAND); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_COMMAND_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_MAX); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_MAX_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_MARGIN_HIGH); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_MARGIN_HIGH_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_MARGIN_LOW); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_MARGIN_LOW_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_TRANSITION_RATE); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_TRANSITION_RATE_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_OV_FAULT_LIMIT); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_OV_FAULT_LIMIT_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_OT_FAULT_LIMIT); + g_assert_cmphex(i2c_value, ==, ISL_OT_FAULT_LIMIT_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_OT_WARN_LIMIT); + g_assert_cmphex(i2c_value, ==, ISL_OT_WARN_LIMIT_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VIN_OV_WARN_LIMIT); + g_assert_cmphex(i2c_value, ==, ISL_VIN_OV_WARN_LIMIT_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VIN_UV_WARN_LIMIT); + g_assert_cmphex(i2c_value, ==, ISL_VIN_UV_WARN_LIMIT_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_IIN_OC_FAULT_LIMIT); + g_assert_cmphex(i2c_value, ==, ISL_IIN_OC_FAULT_LIMIT_DEFAULT); + + i2c_value = i2c_get8(i2cdev, PMBUS_REVISION); + g_assert_cmphex(i2c_value, ==, ISL_REVISION_DEFAULT); +} + +/* test qmp access */ +static void test_tx_rx(void *obj, void *data, QGuestAllocator *alloc) +{ + uint16_t i2c_value, value; + QI2CDevice *i2cdev = (QI2CDevice *)obj; + + qmp_isl_pmbus_set(TEST_ID, "vin[0]", 200); + value = qmp_isl_pmbus_get(TEST_ID, "vin[0]"); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_VIN); + g_assert_cmpuint(value, ==, i2c_value); + + qmp_isl_pmbus_set(TEST_ID, "vout[0]", 2500); + value = qmp_isl_pmbus_get(TEST_ID, "vout[0]"); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_VOUT); + g_assert_cmpuint(value, ==, i2c_value); + + qmp_isl_pmbus_set(TEST_ID, "iin[0]", 300); + value = qmp_isl_pmbus_get(TEST_ID, "iin[0]"); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_IIN); + g_assert_cmpuint(value, ==, i2c_value); + + qmp_isl_pmbus_set(TEST_ID, "iout[0]", 310); + value = qmp_isl_pmbus_get(TEST_ID, "iout[0]"); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_IOUT); + g_assert_cmpuint(value, ==, i2c_value); + + qmp_isl_pmbus_set(TEST_ID, "pin[0]", 100); + value = qmp_isl_pmbus_get(TEST_ID, "pin[0]"); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_PIN); + g_assert_cmpuint(value, ==, i2c_value); + + qmp_isl_pmbus_set(TEST_ID, "pout[0]", 95); + value = qmp_isl_pmbus_get(TEST_ID, "pout[0]"); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_POUT); + g_assert_cmpuint(value, ==, i2c_value); + + qmp_isl_pmbus_set(TEST_ID, "temp1[0]", 26); + value = qmp_isl_pmbus_get(TEST_ID, "temp1[0]"); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_1); + g_assert_cmpuint(value, ==, i2c_value); + + qmp_isl_pmbus_set(TEST_ID, "temp2[0]", 27); + value = qmp_isl_pmbus_get(TEST_ID, "temp2[0]"); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_2); + g_assert_cmpuint(value, ==, i2c_value); + + qmp_isl_pmbus_set(TEST_ID, "temp3[0]", 28); + value = qmp_isl_pmbus_get(TEST_ID, "temp3[0]"); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_3); + g_assert_cmpuint(value, ==, i2c_value); + +} + +/* test r/w registers */ +static void test_rw_regs(void *obj, void *data, QGuestAllocator *alloc) +{ + uint16_t i2c_value; + QI2CDevice *i2cdev = (QI2CDevice *)obj; + + isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_COMMAND, 0x1234); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_COMMAND); + g_assert_cmphex(i2c_value, ==, 0x1234); + + isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_TRIM, 0x4567); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_TRIM); + g_assert_cmphex(i2c_value, ==, 0x4567); + + isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_MAX, 0x9876); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_MAX); + g_assert_cmphex(i2c_value, ==, 0x9876); + + isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_MARGIN_HIGH, 0xABCD); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_MARGIN_HIGH); + g_assert_cmphex(i2c_value, ==, 0xABCD); + + isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_MARGIN_LOW, 0xA1B2); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_MARGIN_LOW); + g_assert_cmphex(i2c_value, ==, 0xA1B2); + + isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_TRANSITION_RATE, 0xDEF1); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_TRANSITION_RATE); + g_assert_cmphex(i2c_value, ==, 0xDEF1); + + isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_DROOP, 0x5678); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_DROOP); + g_assert_cmphex(i2c_value, ==, 0x5678); + + isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_MIN, 0x1234); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_MIN); + g_assert_cmphex(i2c_value, ==, 0x1234); + + isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_OV_FAULT_LIMIT, 0x2345); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_OV_FAULT_LIMIT); + g_assert_cmphex(i2c_value, ==, 0x2345); + + isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_UV_FAULT_LIMIT, 0xFA12); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_UV_FAULT_LIMIT); + g_assert_cmphex(i2c_value, ==, 0xFA12); + + isl_pmbus_i2c_set16(i2cdev, PMBUS_OT_FAULT_LIMIT, 0xF077); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_OT_FAULT_LIMIT); + g_assert_cmphex(i2c_value, ==, 0xF077); + + isl_pmbus_i2c_set16(i2cdev, PMBUS_OT_WARN_LIMIT, 0x7137); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_OT_WARN_LIMIT); + g_assert_cmphex(i2c_value, ==, 0x7137); + + isl_pmbus_i2c_set16(i2cdev, PMBUS_VIN_OV_FAULT_LIMIT, 0x3456); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VIN_OV_FAULT_LIMIT); + g_assert_cmphex(i2c_value, ==, 0x3456); + + isl_pmbus_i2c_set16(i2cdev, PMBUS_VIN_UV_FAULT_LIMIT, 0xBADA); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VIN_UV_FAULT_LIMIT); + g_assert_cmphex(i2c_value, ==, 0xBADA); + + isl_pmbus_i2c_set16(i2cdev, PMBUS_IIN_OC_FAULT_LIMIT, 0xB1B0); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_IIN_OC_FAULT_LIMIT); + g_assert_cmphex(i2c_value, ==, 0xB1B0); + + i2c_set8(i2cdev, PMBUS_OPERATION, 0xA); + i2c_value = i2c_get8(i2cdev, PMBUS_OPERATION); + g_assert_cmphex(i2c_value, ==, 0xA); + + i2c_set8(i2cdev, PMBUS_ON_OFF_CONFIG, 0x42); + i2c_value = i2c_get8(i2cdev, PMBUS_ON_OFF_CONFIG); + g_assert_cmphex(i2c_value, ==, 0x42); +} + +/* test that devices with multiple pages can switch between them */ +static void test_pages_rw(void *obj, void *data, QGuestAllocator *alloc) +{ + uint16_t i2c_value; + QI2CDevice *i2cdev = (QI2CDevice *)obj; + + i2c_set8(i2cdev, PMBUS_PAGE, 1); + i2c_value = i2c_get8(i2cdev, PMBUS_PAGE); + g_assert_cmphex(i2c_value, ==, 1); + + i2c_set8(i2cdev, PMBUS_PAGE, 0); + i2c_value = i2c_get8(i2cdev, PMBUS_PAGE); + g_assert_cmphex(i2c_value, ==, 0); +} + +/* test read-only registers */ +static void test_ro_regs(void *obj, void *data, QGuestAllocator *alloc) +{ + uint16_t i2c_init_value, i2c_value; + QI2CDevice *i2cdev = (QI2CDevice *)obj; + + i2c_init_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_VIN); + isl_pmbus_i2c_set16(i2cdev, PMBUS_READ_VIN, 0xBEEF); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_VIN); + g_assert_cmphex(i2c_init_value, ==, i2c_value); + + i2c_init_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_IIN); + isl_pmbus_i2c_set16(i2cdev, PMBUS_READ_IIN, 0xB00F); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_IIN); + g_assert_cmphex(i2c_init_value, ==, i2c_value); + + i2c_init_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_VOUT); + isl_pmbus_i2c_set16(i2cdev, PMBUS_READ_VOUT, 0x1234); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_VOUT); + g_assert_cmphex(i2c_init_value, ==, i2c_value); + + i2c_init_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_IOUT); + isl_pmbus_i2c_set16(i2cdev, PMBUS_READ_IOUT, 0x6547); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_IOUT); + g_assert_cmphex(i2c_init_value, ==, i2c_value); + + i2c_init_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_1); + isl_pmbus_i2c_set16(i2cdev, PMBUS_READ_TEMPERATURE_1, 0x1597); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_1); + g_assert_cmphex(i2c_init_value, ==, i2c_value); + + i2c_init_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_2); + isl_pmbus_i2c_set16(i2cdev, PMBUS_READ_TEMPERATURE_2, 0x1897); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_2); + g_assert_cmphex(i2c_init_value, ==, i2c_value); + + i2c_init_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_3); + isl_pmbus_i2c_set16(i2cdev, PMBUS_READ_TEMPERATURE_3, 0x1007); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_3); + g_assert_cmphex(i2c_init_value, ==, i2c_value); + + i2c_init_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_PIN); + isl_pmbus_i2c_set16(i2cdev, PMBUS_READ_PIN, 0xDEAD); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_PIN); + g_assert_cmphex(i2c_init_value, ==, i2c_value); + + i2c_init_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_POUT); + isl_pmbus_i2c_set16(i2cdev, PMBUS_READ_POUT, 0xD00D); + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_POUT); + g_assert_cmphex(i2c_init_value, ==, i2c_value); +} + +/* test voltage fault handling */ +static void test_voltage_faults(void *obj, void *data, QGuestAllocator *alloc) +{ + uint16_t i2c_value; + uint8_t i2c_byte; + QI2CDevice *i2cdev = (QI2CDevice *)obj; + + isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_OV_WARN_LIMIT, 5000); + qmp_isl_pmbus_set(TEST_ID, "vout[0]", 5100); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_STATUS_WORD); + i2c_byte = i2c_get8(i2cdev, PMBUS_STATUS_VOUT); + g_assert_true((i2c_value & PB_STATUS_VOUT) != 0); + g_assert_true((i2c_byte & PB_STATUS_VOUT_OV_WARN) != 0); + + qmp_isl_pmbus_set(TEST_ID, "vout[0]", 4500); + i2c_set8(i2cdev, PMBUS_CLEAR_FAULTS, 0); + i2c_byte = i2c_get8(i2cdev, PMBUS_STATUS_VOUT); + g_assert_true((i2c_byte & PB_STATUS_VOUT_OV_WARN) == 0); + + isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_UV_WARN_LIMIT, 4600); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_STATUS_WORD); + i2c_byte = i2c_get8(i2cdev, PMBUS_STATUS_VOUT); + g_assert_true((i2c_value & PB_STATUS_VOUT) != 0); + g_assert_true((i2c_byte & PB_STATUS_VOUT_UV_WARN) != 0); + +} + +static void isl_pmbus_register_nodes(void) +{ + QOSGraphEdgeOptions opts = { + .extra_device_opts = "id=" TEST_ID ",address=0x43" + }; + add_qi2c_address(&opts, &(QI2CAddress) { TEST_ADDR }); + + qos_node_create_driver("isl69260", i2c_device_create); + qos_node_consumes("isl69260", "i2c-bus", &opts); + + qos_add_test("test_defaults", "isl69260", test_defaults, NULL); + qos_add_test("test_tx_rx", "isl69260", test_tx_rx, NULL); + qos_add_test("test_rw_regs", "isl69260", test_rw_regs, NULL); + qos_add_test("test_pages_rw", "isl69260", test_pages_rw, NULL); + qos_add_test("test_ro_regs", "isl69260", test_ro_regs, NULL); + qos_add_test("test_ov_faults", "isl69260", test_voltage_faults, NULL); +} +libqos_init(isl_pmbus_register_nodes); diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index f33d84d19b..9a6cc93c16 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -244,6 +244,7 @@ qos_test_ss.add( 'es1370-test.c', 'ipoctal232-test.c', 'lsm303dlhc-mag-test.c', + 'isl_pmbus-test.c', 'max34451-test.c', 'megasas-test.c', 'ne2000-test.c', From patchwork Wed Mar 2 00:23:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 12765301 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 5650DC433F5 for ; Wed, 2 Mar 2022 00:36:43 +0000 (UTC) Received: from localhost ([::1]:33320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPCyw-0005Wt-8A for qemu-devel@archiver.kernel.org; Tue, 01 Mar 2022 19:36:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38184) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3CbkeYgYKCg47w7865u22uzs.q204s08-rs9sz121u18.25u@flex--titusr.bounces.google.com>) id 1nPCrK-0005Ie-HS for qemu-devel@nongnu.org; Tue, 01 Mar 2022 19:28:50 -0500 Received: from [2607:f8b0:4864:20::949] (port=40729 helo=mail-ua1-x949.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3CbkeYgYKCg47w7865u22uzs.q204s08-rs9sz121u18.25u@flex--titusr.bounces.google.com>) id 1nPCrJ-0007Kl-2t for qemu-devel@nongnu.org; Tue, 01 Mar 2022 19:28:50 -0500 Received: by mail-ua1-x949.google.com with SMTP id z1-20020ab05641000000b00341f2a589deso152326uaa.7 for ; Tue, 01 Mar 2022 16:28:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=y5gTl/dneFYFAvtKtWO9nY0S7K6+kknOpexTazdaxEs=; b=nx8FQfYcIlwYQCKoSNLt4hpEb4Atj3F/pijmn/6Z17dmA2rq113DzDAGqufZKh+jCp je02+us+xkW9DU3SeSEYLadFqpDrCIy87CBXKobyt4jeYjZr39Mri2g/CtONMHH/L6he fYI7Kbrkx/IYasIAKYY3ERukb9+WZnydK4GmrWq3v4yz74gtQqgmZ3LKeodZkrUydsh1 ZDpXrTLOuto58mw32r9ruqofaEYPtktCRsil78J4xgBJA2kDXcLbUdmhkPWx8GiWJgI+ TV8/OCg9aRbu8YYi0v1k9k6y+9gz36NvNyPsVKflkrRT0Gl3p6ONtAXvRgfWlBVcoj7R sp5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=y5gTl/dneFYFAvtKtWO9nY0S7K6+kknOpexTazdaxEs=; b=YE0QVV1KWe0aLd77Gd40deFdiOrjjmTEtTWwdYxwayZFzIm1OVROmZ8VdAPeSbUvkq 5HQTsFmBqj+iVhzwcUzbBYkMkA+bxGnZhTWIM/JLSlg446kco0i8j1tVaNPzX+JgIVAO 4C1tvLx1LIjpccoFhDiYPj+SDUrp+PKGeA0no7H+9kYhFlbkFglrpHEwKz3ijyh5DC9k 3aueZf4hCpqFj1fwMZGMdU/wWxq+5obW7ywyW1J9dMqpA2oDcWGrr86k68Px3n12v46C niGD+KLxuXQEoQWb4+cRPwHbwb9bIylgx8pfkuHgcCswOsROZTOkN/Ijoy4EP7QmTlgM /bTw== X-Gm-Message-State: AOAM5336oN8PDhOcjD6pAId3ZmpuwpAmwzce1hSuB8ksnmyf696taKax PBVsZe1bVoBBVnom7jL5beOgamHFBNI= X-Google-Smtp-Source: ABdhPJxLp5gPDZKtrsPyAEQBy2bqv+kOWuJYMN2bunKWanNPMqkmaRyGCtdt6Lpf3n1SibfVpsDfY8FjZEA= X-Received: from titusr.svl.corp.google.com ([2620:15c:2a3:201:3a0a:5449:c096:dc84]) (user=titusr job=sendgmr) by 2002:a05:6902:102a:b0:614:105b:33a6 with SMTP id x10-20020a056902102a00b00614105b33a6mr26630778ybt.457.1646180617455; Tue, 01 Mar 2022 16:23:37 -0800 (PST) Date: Tue, 1 Mar 2022 16:23:05 -0800 In-Reply-To: <20220302002307.1895616-1-titusr@google.com> Message-Id: <20220302002307.1895616-8-titusr@google.com> Mime-Version: 1.0 References: <20220302002307.1895616-1-titusr@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v2 7/9] hw/sensor: add Renesas raa229004 PMBus device From: Titus Rwantare To: Corey Minyard Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, f4bug@amsat.org, wuhaotsh@google.com, venture@google.com, Titus Rwantare X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::949 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::949; envelope-from=3CbkeYgYKCg47w7865u22uzs.q204s08-rs9sz121u18.25u@flex--titusr.bounces.google.com; helo=mail-ua1-x949.google.com X-Spam_score_int: -81 X-Spam_score: -8.2 X-Spam_bar: -------- X-Spam_report: (-8.2 / 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, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=no 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" The Renesas RAA229004 is a PMBus Multiphase Voltage Regulator Signed-off-by: Titus Rwantare Reviewed-by: Hao Wu --- hw/sensor/isl_pmbus.c | 18 ++++++++++++++++++ include/hw/sensor/isl_pmbus.h | 1 + tests/qtest/isl_pmbus-test.c | 8 ++++++++ 3 files changed, 27 insertions(+) diff --git a/hw/sensor/isl_pmbus.c b/hw/sensor/isl_pmbus.c index 8cc7220a57..4ff848f663 100644 --- a/hw/sensor/isl_pmbus.c +++ b/hw/sensor/isl_pmbus.c @@ -194,6 +194,15 @@ static void isl69260_class_init(ObjectClass *klass, void *data) isl_pmbus_class_init(klass, data, 2); } +static void raa229004_class_init(ObjectClass *klass, void *data) +{ + ResettableClass *rc = RESETTABLE_CLASS(klass); + DeviceClass *dc = DEVICE_CLASS(klass); + dc->desc = "Renesas 229004 Digital Multiphase Voltage Regulator"; + rc->phases.exit = isl_pmbus_exit_reset; + isl_pmbus_class_init(klass, data, 2); +} + static const TypeInfo isl69260_info = { .name = TYPE_ISL69260, .parent = TYPE_PMBUS_DEVICE, @@ -202,9 +211,18 @@ static const TypeInfo isl69260_info = { .class_init = isl69260_class_init, }; +static const TypeInfo raa229004_info = { + .name = TYPE_RAA229004, + .parent = TYPE_PMBUS_DEVICE, + .instance_size = sizeof(ISLState), + .instance_init = raa22xx_init, + .class_init = raa229004_class_init, +}; + static void isl_pmbus_register_types(void) { type_register_static(&isl69260_info); + type_register_static(&raa229004_info); } type_init(isl_pmbus_register_types) diff --git a/include/hw/sensor/isl_pmbus.h b/include/hw/sensor/isl_pmbus.h index 8115aaa698..a947fd3903 100644 --- a/include/hw/sensor/isl_pmbus.h +++ b/include/hw/sensor/isl_pmbus.h @@ -13,6 +13,7 @@ #include "qom/object.h" #define TYPE_ISL69260 "isl69260" +#define TYPE_RAA229004 "raa229004" struct ISLState { PMBusDevice parent; diff --git a/tests/qtest/isl_pmbus-test.c b/tests/qtest/isl_pmbus-test.c index 59fa67f110..80d6c24ec7 100644 --- a/tests/qtest/isl_pmbus-test.c +++ b/tests/qtest/isl_pmbus-test.c @@ -383,11 +383,19 @@ static void isl_pmbus_register_nodes(void) qos_node_create_driver("isl69260", i2c_device_create); qos_node_consumes("isl69260", "i2c-bus", &opts); + qos_node_create_driver("raa229004", i2c_device_create); + qos_node_consumes("raa229004", "i2c-bus", &opts); + qos_add_test("test_defaults", "isl69260", test_defaults, NULL); qos_add_test("test_tx_rx", "isl69260", test_tx_rx, NULL); qos_add_test("test_rw_regs", "isl69260", test_rw_regs, NULL); qos_add_test("test_pages_rw", "isl69260", test_pages_rw, NULL); qos_add_test("test_ro_regs", "isl69260", test_ro_regs, NULL); qos_add_test("test_ov_faults", "isl69260", test_voltage_faults, NULL); + + qos_add_test("test_tx_rx", "raa229004", test_tx_rx, NULL); + qos_add_test("test_rw_regs", "raa229004", test_rw_regs, NULL); + qos_add_test("test_pages_rw", "raa229004", test_pages_rw, NULL); + qos_add_test("test_ov_faults", "raa229004", test_voltage_faults, NULL); } libqos_init(isl_pmbus_register_nodes); From patchwork Wed Mar 2 00:23:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 12765299 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 C44A8C433F5 for ; Wed, 2 Mar 2022 00:32:48 +0000 (UTC) Received: from localhost ([::1]:56718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPCv9-0001ze-VA for qemu-devel@archiver.kernel.org; Tue, 01 Mar 2022 19:32:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37096) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3C7keYgYKChA9y9A87w44w1u.s426u2A-tuBu1343w3A.47w@flex--titusr.bounces.google.com>) id 1nPCmO-0008R1-5C for qemu-devel@nongnu.org; Tue, 01 Mar 2022 19:23:45 -0500 Received: from [2607:f8b0:4864:20::b49] (port=45846 helo=mail-yb1-xb49.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3C7keYgYKChA9y9A87w44w1u.s426u2A-tuBu1343w3A.47w@flex--titusr.bounces.google.com>) id 1nPCmK-0003Hz-TG for qemu-devel@nongnu.org; Tue, 01 Mar 2022 19:23:43 -0500 Received: by mail-yb1-xb49.google.com with SMTP id n66-20020a254045000000b0062883b59ddbso7567yba.12 for ; Tue, 01 Mar 2022 16:23:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=sxHwCFQ7GN3iQdwu0G1IfNe7Yi5+zoqZ7WtImg1yT/U=; b=g8odv4LEGBlbxjoumC6gP90rfFOR6RXtjWoQ8LbyrRdAXVzk3x0q4bjd2VjTm0UWBE 6dKx5pPi0KLrKV4bljJnugi//VErsS9QVevNMfLOQjaBWYOBtX3wfAOcghp+El4IiuY1 DzSv3cY7Vk65WiFEZYJX9xyTmu89QhHahm3OkD6zdxTu5OyAQCmM83qPr0YbPdrou7WM wCr6yMqg8qfUJGLU4lrY6XZeGauWNEU/t4liIJxpK9n+b6PeLUz/Q9LeK6mDvInXVBXn EmA21OPA5jKVQEuSUrzjDPIkLG2EQwNv5pf/j4YxguZyZaVIoF0/xNRUscvp3N4aVxGo 2wxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=sxHwCFQ7GN3iQdwu0G1IfNe7Yi5+zoqZ7WtImg1yT/U=; b=iPydPpnZJC5RK9uv2rK2shyxxWK0DnnxiT8LIwZkHPRjA9kYNXTRNPD2dgWhW/+3oo 1gGawU2P9oxVSmhZzy3zv0Nmf9g0HdyUWYADV6OaZ+TAyfXiRr/eC9iTVAueayEKJmEl 4epzSSJVDvpK8AmA8hZ4usaiT4GBZGJkT0uzilfPsbtRhmHHtZ6H7FnuVswHhEqt9cMF VGY7/9fgOtOiSiYdLoyeEp4DGKeKS56L+PDIa5wu7IK9bf7w4BtFZe8NtvDgOuJSCDD9 Gb/wmz6z6WB6GxxwuRI6GAkrznYhZ4qL/uT1QXeejNc8F4SnVx+GETxlXrc+KEMuqlBM FgYw== X-Gm-Message-State: AOAM532Zler4wZAuI9Gn55I3sJmADzpTEcWFl5kIrFFOrVk1WE4x4DNq j+FtM06+vXl8fhByODaoEqe6ajUL+ck= X-Google-Smtp-Source: ABdhPJylnP5IMlrCZB5RJ8BKFX+BQI6winkyIg8FATCZJrOP6tY5Lsx2G/GatT8auq1Mqg6ODOoNkk5nJK0= X-Received: from titusr.svl.corp.google.com ([2620:15c:2a3:201:3a0a:5449:c096:dc84]) (user=titusr job=sendgmr) by 2002:a05:6902:2:b0:624:4cb5:fd3b with SMTP id l2-20020a056902000200b006244cb5fd3bmr27492489ybh.1.1646180619713; Tue, 01 Mar 2022 16:23:39 -0800 (PST) Date: Tue, 1 Mar 2022 16:23:06 -0800 In-Reply-To: <20220302002307.1895616-1-titusr@google.com> Message-Id: <20220302002307.1895616-9-titusr@google.com> Mime-Version: 1.0 References: <20220302002307.1895616-1-titusr@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v2 8/9] hw/sensor: add Renesas raa228000 device From: Titus Rwantare To: Corey Minyard Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, f4bug@amsat.org, wuhaotsh@google.com, venture@google.com, Titus Rwantare X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::b49 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::b49; envelope-from=3C7keYgYKChA9y9A87w44w1u.s426u2A-tuBu1343w3A.47w@flex--titusr.bounces.google.com; helo=mail-yb1-xb49.google.com X-Spam_score_int: -81 X-Spam_score: -8.2 X-Spam_bar: -------- X-Spam_report: (-8.2 / 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, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=no 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" Signed-off-by: Titus Rwantare Reviewed-by: Hao Wu --- hw/sensor/isl_pmbus.c | 50 ++++++++++++++++++++++ include/hw/sensor/isl_pmbus.h | 1 + tests/qtest/isl_pmbus-test.c | 78 +++++++++++++++++++++++++++++++++-- 3 files changed, 126 insertions(+), 3 deletions(-) diff --git a/hw/sensor/isl_pmbus.c b/hw/sensor/isl_pmbus.c index 4ff848f663..e3b42b119e 100644 --- a/hw/sensor/isl_pmbus.c +++ b/hw/sensor/isl_pmbus.c @@ -89,6 +89,24 @@ static void isl_pmbus_exit_reset(Object *obj) } } +/* The raa228000 uses different direct mode coefficents from most isl devices */ +static void raa228000_exit_reset(Object *obj) +{ + isl_pmbus_exit_reset(obj); + + PMBusDevice *pmdev = PMBUS_DEVICE(obj); + + pmdev->pages[0].read_vout = 0; + pmdev->pages[0].read_iout = 0; + pmdev->pages[0].read_pout = 0; + pmdev->pages[0].read_vin = 0; + pmdev->pages[0].read_iin = 0; + pmdev->pages[0].read_pin = 0; + pmdev->pages[0].read_temperature_1 = 0; + pmdev->pages[0].read_temperature_2 = 0; + pmdev->pages[0].read_temperature_3 = 0; +} + static void isl_pmbus_add_props(Object *obj, uint64_t *flags, uint8_t pages) { PMBusDevice *pmdev = PMBUS_DEVICE(obj); @@ -177,6 +195,20 @@ static void raa22xx_init(Object *obj) isl_pmbus_add_props(obj, flags, 2); } +static void raa228000_init(Object *obj) +{ + PMBusDevice *pmdev = PMBUS_DEVICE(obj); + uint64_t flags[1]; + + flags[0] = PB_HAS_VIN | PB_HAS_VOUT | PB_HAS_VOUT_MODE | + PB_HAS_VOUT_RATING | PB_HAS_VOUT_MARGIN | PB_HAS_IIN | + PB_HAS_IOUT | PB_HAS_PIN | PB_HAS_POUT | PB_HAS_TEMPERATURE | + PB_HAS_TEMP2 | PB_HAS_TEMP3 | PB_HAS_STATUS_MFR_SPECIFIC; + + pmbus_page_config(pmdev, 0, flags[0]); + isl_pmbus_add_props(obj, flags, 1); +} + static void isl_pmbus_class_init(ObjectClass *klass, void *data, uint8_t pages) { PMBusDeviceClass *k = PMBUS_DEVICE_CLASS(klass); @@ -194,6 +226,15 @@ static void isl69260_class_init(ObjectClass *klass, void *data) isl_pmbus_class_init(klass, data, 2); } +static void raa228000_class_init(ObjectClass *klass, void *data) +{ + ResettableClass *rc = RESETTABLE_CLASS(klass); + DeviceClass *dc = DEVICE_CLASS(klass); + dc->desc = "Renesas 228000 Digital Multiphase Voltage Regulator"; + rc->phases.exit = raa228000_exit_reset; + isl_pmbus_class_init(klass, data, 1); +} + static void raa229004_class_init(ObjectClass *klass, void *data) { ResettableClass *rc = RESETTABLE_CLASS(klass); @@ -219,9 +260,18 @@ static const TypeInfo raa229004_info = { .class_init = raa229004_class_init, }; +static const TypeInfo raa228000_info = { + .name = TYPE_RAA228000, + .parent = TYPE_PMBUS_DEVICE, + .instance_size = sizeof(ISLState), + .instance_init = raa228000_init, + .class_init = raa228000_class_init, +}; + static void isl_pmbus_register_types(void) { type_register_static(&isl69260_info); + type_register_static(&raa228000_info); type_register_static(&raa229004_info); } diff --git a/include/hw/sensor/isl_pmbus.h b/include/hw/sensor/isl_pmbus.h index a947fd3903..7ead1dc4a2 100644 --- a/include/hw/sensor/isl_pmbus.h +++ b/include/hw/sensor/isl_pmbus.h @@ -13,6 +13,7 @@ #include "qom/object.h" #define TYPE_ISL69260 "isl69260" +#define TYPE_RAA228000 "raa228000" #define TYPE_RAA229004 "raa229004" struct ISLState { diff --git a/tests/qtest/isl_pmbus-test.c b/tests/qtest/isl_pmbus-test.c index 80d6c24ec7..ea62cd4e07 100644 --- a/tests/qtest/isl_pmbus-test.c +++ b/tests/qtest/isl_pmbus-test.c @@ -149,6 +149,70 @@ static void test_defaults(void *obj, void *data, QGuestAllocator *alloc) g_assert_cmphex(i2c_value, ==, ISL_REVISION_DEFAULT); } +static void raa228000_test_defaults(void *obj, void *data, + QGuestAllocator *alloc) +{ + uint16_t value, i2c_value; + QI2CDevice *i2cdev = (QI2CDevice *)obj; + + value = qmp_isl_pmbus_get(TEST_ID, "vout[0]"); + g_assert_cmpuint(value, ==, 0); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_IOUT); + g_assert_cmpuint(i2c_value, ==, 0); + + value = qmp_isl_pmbus_get(TEST_ID, "pout[0]"); + g_assert_cmpuint(value, ==, 0); + + i2c_value = i2c_get8(i2cdev, PMBUS_CAPABILITY); + g_assert_cmphex(i2c_value, ==, ISL_CAPABILITY_DEFAULT); + + i2c_value = i2c_get8(i2cdev, PMBUS_OPERATION); + g_assert_cmphex(i2c_value, ==, ISL_OPERATION_DEFAULT); + + i2c_value = i2c_get8(i2cdev, PMBUS_ON_OFF_CONFIG); + g_assert_cmphex(i2c_value, ==, ISL_ON_OFF_CONFIG_DEFAULT); + + i2c_value = i2c_get8(i2cdev, PMBUS_VOUT_MODE); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_MODE_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_COMMAND); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_COMMAND_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_MAX); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_MAX_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_MARGIN_HIGH); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_MARGIN_HIGH_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_MARGIN_LOW); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_MARGIN_LOW_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_TRANSITION_RATE); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_TRANSITION_RATE_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_OV_FAULT_LIMIT); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_OV_FAULT_LIMIT_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_OT_FAULT_LIMIT); + g_assert_cmphex(i2c_value, ==, ISL_OT_FAULT_LIMIT_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_OT_WARN_LIMIT); + g_assert_cmphex(i2c_value, ==, ISL_OT_WARN_LIMIT_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VIN_OV_WARN_LIMIT); + g_assert_cmphex(i2c_value, ==, ISL_VIN_OV_WARN_LIMIT_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VIN_UV_WARN_LIMIT); + g_assert_cmphex(i2c_value, ==, ISL_VIN_UV_WARN_LIMIT_DEFAULT); + + i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_IIN_OC_FAULT_LIMIT); + g_assert_cmphex(i2c_value, ==, ISL_IIN_OC_FAULT_LIMIT_DEFAULT); + + i2c_value = i2c_get8(i2cdev, PMBUS_REVISION); + g_assert_cmphex(i2c_value, ==, ISL_REVISION_DEFAULT); +} + /* test qmp access */ static void test_tx_rx(void *obj, void *data, QGuestAllocator *alloc) { @@ -383,9 +447,6 @@ static void isl_pmbus_register_nodes(void) qos_node_create_driver("isl69260", i2c_device_create); qos_node_consumes("isl69260", "i2c-bus", &opts); - qos_node_create_driver("raa229004", i2c_device_create); - qos_node_consumes("raa229004", "i2c-bus", &opts); - qos_add_test("test_defaults", "isl69260", test_defaults, NULL); qos_add_test("test_tx_rx", "isl69260", test_tx_rx, NULL); qos_add_test("test_rw_regs", "isl69260", test_rw_regs, NULL); @@ -393,9 +454,20 @@ static void isl_pmbus_register_nodes(void) qos_add_test("test_ro_regs", "isl69260", test_ro_regs, NULL); qos_add_test("test_ov_faults", "isl69260", test_voltage_faults, NULL); + qos_node_create_driver("raa229004", i2c_device_create); + qos_node_consumes("raa229004", "i2c-bus", &opts); + qos_add_test("test_tx_rx", "raa229004", test_tx_rx, NULL); qos_add_test("test_rw_regs", "raa229004", test_rw_regs, NULL); qos_add_test("test_pages_rw", "raa229004", test_pages_rw, NULL); qos_add_test("test_ov_faults", "raa229004", test_voltage_faults, NULL); + + qos_node_create_driver("raa228000", i2c_device_create); + qos_node_consumes("raa228000", "i2c-bus", &opts); + + qos_add_test("test_defaults", "raa228000", raa228000_test_defaults, NULL); + qos_add_test("test_tx_rx", "raa228000", test_tx_rx, NULL); + qos_add_test("test_rw_regs", "raa228000", test_rw_regs, NULL); + qos_add_test("test_ov_faults", "raa228000", test_voltage_faults, NULL); } libqos_init(isl_pmbus_register_nodes); From patchwork Wed Mar 2 00:23:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 12765328 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 13195C433F5 for ; Wed, 2 Mar 2022 00:50:38 +0000 (UTC) Received: from localhost ([::1]:40262 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPDCO-0002Q0-Ur for qemu-devel@archiver.kernel.org; Tue, 01 Mar 2022 19:50:36 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38950) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3DbkeYgYKChIB0BCA9y66y3w.u648w4C-vwDw3565y5C.69y@flex--titusr.bounces.google.com>) id 1nPCuC-0000kS-WD for qemu-devel@nongnu.org; Tue, 01 Mar 2022 19:31:49 -0500 Received: from [2607:f8b0:4864:20::b4a] (port=41487 helo=mail-yb1-xb4a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3DbkeYgYKChIB0BCA9y66y3w.u648w4C-vwDw3565y5C.69y@flex--titusr.bounces.google.com>) id 1nPCu9-0000Gj-Ly for qemu-devel@nongnu.org; Tue, 01 Mar 2022 19:31:48 -0500 Received: by mail-yb1-xb4a.google.com with SMTP id z15-20020a25bb0f000000b00613388c7d99so31380ybg.8 for ; Tue, 01 Mar 2022 16:31:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=Rsi2sb3KIuB7mW1QTXlIf0TcyFFB1RqtDSydPOsqiIQ=; b=MYLtH8L+TmuPscz3h1h2wAvTfAyOUWNzW0tDd45riDGHcAc3pJq1hXjXx5zTc12HY2 gFs4Vg2CcHeJTIqYJarKF+i0IMod/o60knujqcVbvkzBYaMRArToFrsWqvlg+YGojRBW 3HQX+h3uyeXXuKWUkmtK9OdhUCPncEFPs3lpM85MFdlemqguzAmcitfCh/IupaWWjtNe Ptw+pWiJTm+5jOwMe8iY0nRkg9doSinMMLFDzP9uDaoV0HRpLtZVC5p0gwgqS+gzzXM9 oBXzQQ6i0UXWwAzLoDJU2HI+gcaDXqzwR2Kq2ERc0YSOs/wPoLEUsRapVUZyALqENzRW 9u2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=Rsi2sb3KIuB7mW1QTXlIf0TcyFFB1RqtDSydPOsqiIQ=; b=yNvMqS7YbdRyaQ5M1n3NBM19bbRDIf2RzprS2A2B0reDVaplPdXxB9sL4CxRb7JB8y 1aITmXhIXBj6u41X56TEBiIqb1g5f3wkWopcDLGobIEqHREwoFqW7G7dqErzz+4cYzSl 32lg7mQ0RUBQcpy24GTz0gv+qAZCXITWGDrVQ8Y1FUv8K2erCzywE8cGuVJeLFJFoL4C o5qtkKRTbAew//E7L2Jo4EOnzl3WOit5Bbb+ia4Yjc4wmlRRSxR7QYbPZtUHmIOL+5EP EbKkPVH+c7JB6aCZASY2axidgDimodQCckDatmTQBkYle3MxpYgtNiWCtCvrN8mQyKhp 0tRw== X-Gm-Message-State: AOAM530HoEZDOjyl4yjsNDny3tcl9M3PBHrJjrKWNvO9TaDTM4Q+CGry qO9pvTjL3u+RkC8tg4M3obOdc+TkZnY= X-Google-Smtp-Source: ABdhPJzmz+B/lqKOVESFDsclFY6GQHvi6Cwe9j6UHtlQHcN1+rZEJ4Z+QRZQhvyxO3OGNpJsNRNMSHZwC6U= X-Received: from titusr.svl.corp.google.com ([2620:15c:2a3:201:3a0a:5449:c096:dc84]) (user=titusr job=sendgmr) by 2002:a81:5710:0:b0:2d6:b987:d358 with SMTP id l16-20020a815710000000b002d6b987d358mr27220346ywb.6.1646180621998; Tue, 01 Mar 2022 16:23:41 -0800 (PST) Date: Tue, 1 Mar 2022 16:23:07 -0800 In-Reply-To: <20220302002307.1895616-1-titusr@google.com> Message-Id: <20220302002307.1895616-10-titusr@google.com> Mime-Version: 1.0 References: <20220302002307.1895616-1-titusr@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v2 9/9] hw/sensor: rename isl_pmbus to isl_pmbus_vr From: Titus Rwantare To: Corey Minyard Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, f4bug@amsat.org, wuhaotsh@google.com, venture@google.com, Titus Rwantare X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::b4a (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::b4a; envelope-from=3DbkeYgYKChIB0BCA9y66y3w.u648w4C-vwDw3565y5C.69y@flex--titusr.bounces.google.com; helo=mail-yb1-xb4a.google.com X-Spam_score_int: -81 X-Spam_score: -8.2 X-Spam_bar: -------- X-Spam_report: (-8.2 / 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, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=no 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" Signed-off-by: Titus Rwantare --- MAINTAINERS | 6 +- hw/arm/Kconfig | 2 +- hw/sensor/Kconfig | 2 +- hw/sensor/{isl_pmbus.c => isl_pmbus_vr.c} | 77 ++--- hw/sensor/meson.build | 2 +- .../hw/sensor/{isl_pmbus.h => isl_pmbus_vr.h} | 4 +- .../{isl_pmbus-test.c => isl_pmbus_vr-test.c} | 263 +++++++++--------- tests/qtest/meson.build | 2 +- 8 files changed, 180 insertions(+), 178 deletions(-) rename hw/sensor/{isl_pmbus.c => isl_pmbus_vr.c} (80%) rename include/hw/sensor/{isl_pmbus.h => isl_pmbus_vr.h} (96%) rename tests/qtest/{isl_pmbus-test.c => isl_pmbus_vr-test.c} (55%) diff --git a/MAINTAINERS b/MAINTAINERS index 3df8e938e0..364a844045 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3140,13 +3140,13 @@ M: Titus Rwantare S: Maintained F: hw/i2c/pmbus_device.c F: hw/sensor/adm1272.c -F: hw/sensor/isl_pmbus.c +F: hw/sensor/isl_pmbus_vr.c F: hw/sensor/max34451.c F: include/hw/i2c/pmbus_device.h -F: include/hw/sensor/isl_pmbus.h +F: include/hw/sensor/isl_pmbus_vr.h F: tests/qtest/adm1272-test.c F: tests/qtest/max34451-test.c -F: tests/qtest/isl_pmbus-test.c +F: tests/qtest/isl_pmbus_vr-test.c Firmware schema specifications M: Philippe Mathieu-Daudé diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 8047ad6378..97f3b38019 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -400,7 +400,7 @@ config NPCM7XX select SMBUS select AT24C # EEPROM select MAX34451 - select ISL_PMBUS + select ISL_PMBUS_VR select PL310 # cache controller select PMBUS select SERIAL diff --git a/hw/sensor/Kconfig b/hw/sensor/Kconfig index 70fb335789..a834d2f814 100644 --- a/hw/sensor/Kconfig +++ b/hw/sensor/Kconfig @@ -31,7 +31,7 @@ config LSM303DLHC_MAG depends on I2C default y if I2C_DEVICES -config ISL_PMBUS +config ISL_PMBUS_VR bool depends on I2C diff --git a/hw/sensor/isl_pmbus.c b/hw/sensor/isl_pmbus_vr.c similarity index 80% rename from hw/sensor/isl_pmbus.c rename to hw/sensor/isl_pmbus_vr.c index e3b42b119e..df7c003ea6 100644 --- a/hw/sensor/isl_pmbus.c +++ b/hw/sensor/isl_pmbus_vr.c @@ -7,13 +7,13 @@ */ #include "qemu/osdep.h" -#include "hw/sensor/isl_pmbus.h" +#include "hw/sensor/isl_pmbus_vr.h" #include "hw/qdev-properties.h" #include "qapi/visitor.h" #include "qemu/log.h" #include "qemu/module.h" -static uint8_t isl_pmbus_read_byte(PMBusDevice *pmdev) +static uint8_t isl_pmbus_vr_read_byte(PMBusDevice *pmdev) { qemu_log_mask(LOG_GUEST_ERROR, "%s: reading from unsupported register: 0x%02x\n", @@ -21,7 +21,7 @@ static uint8_t isl_pmbus_read_byte(PMBusDevice *pmdev) return 0xFF; } -static int isl_pmbus_write_data(PMBusDevice *pmdev, const uint8_t *buf, +static int isl_pmbus_vr_write_data(PMBusDevice *pmdev, const uint8_t *buf, uint8_t len) { qemu_log_mask(LOG_GUEST_ERROR, @@ -31,13 +31,13 @@ static int isl_pmbus_write_data(PMBusDevice *pmdev, const uint8_t *buf, } /* TODO: Implement coefficients support in pmbus_device.c for qmp */ -static void isl_pmbus_get(Object *obj, Visitor *v, const char *name, +static void isl_pmbus_vr_get(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { visit_type_uint16(v, name, (uint16_t *)opaque, errp); } -static void isl_pmbus_set(Object *obj, Visitor *v, const char *name, +static void isl_pmbus_vr_set(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { PMBusDevice *pmdev = PMBUS_DEVICE(obj); @@ -51,7 +51,7 @@ static void isl_pmbus_set(Object *obj, Visitor *v, const char *name, pmbus_check_limits(pmdev); } -static void isl_pmbus_exit_reset(Object *obj) +static void isl_pmbus_vr_exit_reset(Object *obj) { PMBusDevice *pmdev = PMBUS_DEVICE(obj); @@ -92,7 +92,7 @@ static void isl_pmbus_exit_reset(Object *obj) /* The raa228000 uses different direct mode coefficents from most isl devices */ static void raa228000_exit_reset(Object *obj) { - isl_pmbus_exit_reset(obj); + isl_pmbus_vr_exit_reset(obj); PMBusDevice *pmdev = PMBUS_DEVICE(obj); @@ -107,70 +107,70 @@ static void raa228000_exit_reset(Object *obj) pmdev->pages[0].read_temperature_3 = 0; } -static void isl_pmbus_add_props(Object *obj, uint64_t *flags, uint8_t pages) +static void isl_pmbus_vr_add_props(Object *obj, uint64_t *flags, uint8_t pages) { PMBusDevice *pmdev = PMBUS_DEVICE(obj); for (int i = 0; i < pages; i++) { if (flags[i] & PB_HAS_VIN) { object_property_add(obj, "vin[*]", "uint16", - isl_pmbus_get, - isl_pmbus_set, + isl_pmbus_vr_get, + isl_pmbus_vr_set, NULL, &pmdev->pages[i].read_vin); } if (flags[i] & PB_HAS_VOUT) { object_property_add(obj, "vout[*]", "uint16", - isl_pmbus_get, - isl_pmbus_set, + isl_pmbus_vr_get, + isl_pmbus_vr_set, NULL, &pmdev->pages[i].read_vout); } if (flags[i] & PB_HAS_IIN) { object_property_add(obj, "iin[*]", "uint16", - isl_pmbus_get, - isl_pmbus_set, + isl_pmbus_vr_get, + isl_pmbus_vr_set, NULL, &pmdev->pages[i].read_iin); } if (flags[i] & PB_HAS_IOUT) { object_property_add(obj, "iout[*]", "uint16", - isl_pmbus_get, - isl_pmbus_set, + isl_pmbus_vr_get, + isl_pmbus_vr_set, NULL, &pmdev->pages[i].read_iout); } if (flags[i] & PB_HAS_PIN) { object_property_add(obj, "pin[*]", "uint16", - isl_pmbus_get, - isl_pmbus_set, + isl_pmbus_vr_get, + isl_pmbus_vr_set, NULL, &pmdev->pages[i].read_pin); } if (flags[i] & PB_HAS_POUT) { object_property_add(obj, "pout[*]", "uint16", - isl_pmbus_get, - isl_pmbus_set, + isl_pmbus_vr_get, + isl_pmbus_vr_set, NULL, &pmdev->pages[i].read_pout); } if (flags[i] & PB_HAS_TEMPERATURE) { object_property_add(obj, "temp1[*]", "uint16", - isl_pmbus_get, - isl_pmbus_set, + isl_pmbus_vr_get, + isl_pmbus_vr_set, NULL, &pmdev->pages[i].read_temperature_1); } if (flags[i] & PB_HAS_TEMP2) { object_property_add(obj, "temp2[*]", "uint16", - isl_pmbus_get, - isl_pmbus_set, + isl_pmbus_vr_get, + isl_pmbus_vr_set, NULL, &pmdev->pages[i].read_temperature_2); } if (flags[i] & PB_HAS_TEMP3) { object_property_add(obj, "temp3[*]", "uint16", - isl_pmbus_get, - isl_pmbus_set, + isl_pmbus_vr_get, + isl_pmbus_vr_set, NULL, &pmdev->pages[i].read_temperature_3); } } @@ -192,7 +192,7 @@ static void raa22xx_init(Object *obj) pmbus_page_config(pmdev, 0, flags[0]); pmbus_page_config(pmdev, 1, flags[1]); - isl_pmbus_add_props(obj, flags, 2); + isl_pmbus_vr_add_props(obj, flags, 2); } static void raa228000_init(Object *obj) @@ -206,14 +206,15 @@ static void raa228000_init(Object *obj) PB_HAS_TEMP2 | PB_HAS_TEMP3 | PB_HAS_STATUS_MFR_SPECIFIC; pmbus_page_config(pmdev, 0, flags[0]); - isl_pmbus_add_props(obj, flags, 1); + isl_pmbus_vr_add_props(obj, flags, 1); } -static void isl_pmbus_class_init(ObjectClass *klass, void *data, uint8_t pages) +static void isl_pmbus_vr_class_init(ObjectClass *klass, void *data, + uint8_t pages) { PMBusDeviceClass *k = PMBUS_DEVICE_CLASS(klass); - k->write_data = isl_pmbus_write_data; - k->receive_byte = isl_pmbus_read_byte; + k->write_data = isl_pmbus_vr_write_data; + k->receive_byte = isl_pmbus_vr_read_byte; k->device_num_pages = pages; } @@ -222,8 +223,8 @@ static void isl69260_class_init(ObjectClass *klass, void *data) ResettableClass *rc = RESETTABLE_CLASS(klass); DeviceClass *dc = DEVICE_CLASS(klass); dc->desc = "Renesas ISL69260 Digital Multiphase Voltage Regulator"; - rc->phases.exit = isl_pmbus_exit_reset; - isl_pmbus_class_init(klass, data, 2); + rc->phases.exit = isl_pmbus_vr_exit_reset; + isl_pmbus_vr_class_init(klass, data, 2); } static void raa228000_class_init(ObjectClass *klass, void *data) @@ -232,7 +233,7 @@ static void raa228000_class_init(ObjectClass *klass, void *data) DeviceClass *dc = DEVICE_CLASS(klass); dc->desc = "Renesas 228000 Digital Multiphase Voltage Regulator"; rc->phases.exit = raa228000_exit_reset; - isl_pmbus_class_init(klass, data, 1); + isl_pmbus_vr_class_init(klass, data, 1); } static void raa229004_class_init(ObjectClass *klass, void *data) @@ -240,8 +241,8 @@ static void raa229004_class_init(ObjectClass *klass, void *data) ResettableClass *rc = RESETTABLE_CLASS(klass); DeviceClass *dc = DEVICE_CLASS(klass); dc->desc = "Renesas 229004 Digital Multiphase Voltage Regulator"; - rc->phases.exit = isl_pmbus_exit_reset; - isl_pmbus_class_init(klass, data, 2); + rc->phases.exit = isl_pmbus_vr_exit_reset; + isl_pmbus_vr_class_init(klass, data, 2); } static const TypeInfo isl69260_info = { @@ -268,11 +269,11 @@ static const TypeInfo raa228000_info = { .class_init = raa228000_class_init, }; -static void isl_pmbus_register_types(void) +static void isl_pmbus_vr_register_types(void) { type_register_static(&isl69260_info); type_register_static(&raa228000_info); type_register_static(&raa229004_info); } -type_init(isl_pmbus_register_types) +type_init(isl_pmbus_vr_register_types) diff --git a/hw/sensor/meson.build b/hw/sensor/meson.build index 2e82991ff1..12b6992bc8 100644 --- a/hw/sensor/meson.build +++ b/hw/sensor/meson.build @@ -5,4 +5,4 @@ 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_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', if_true: files('isl_pmbus.c')) +softmmu_ss.add(when: 'CONFIG_ISL_PMBUS_VR', if_true: files('isl_pmbus_vr.c')) diff --git a/include/hw/sensor/isl_pmbus.h b/include/hw/sensor/isl_pmbus_vr.h similarity index 96% rename from include/hw/sensor/isl_pmbus.h rename to include/hw/sensor/isl_pmbus_vr.h index 7ead1dc4a2..3e47ff7e48 100644 --- a/include/hw/sensor/isl_pmbus.h +++ b/include/hw/sensor/isl_pmbus_vr.h @@ -6,8 +6,8 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef HW_MISC_ISL_PMBUS_H -#define HW_MISC_ISL_PMBUS_H +#ifndef HW_MISC_ISL_PMBUS_VR_H +#define HW_MISC_ISL_PMBUS_VR_H #include "hw/i2c/pmbus_device.h" #include "qom/object.h" diff --git a/tests/qtest/isl_pmbus-test.c b/tests/qtest/isl_pmbus_vr-test.c similarity index 55% rename from tests/qtest/isl_pmbus-test.c rename to tests/qtest/isl_pmbus_vr-test.c index ea62cd4e07..5553ea410a 100644 --- a/tests/qtest/isl_pmbus-test.c +++ b/tests/qtest/isl_pmbus_vr-test.c @@ -17,7 +17,7 @@ #include "qemu/osdep.h" #include #include "hw/i2c/pmbus_device.h" -#include "hw/sensor/isl_pmbus.h" +#include "hw/sensor/isl_pmbus_vr.h" #include "libqtest-single.h" #include "libqos/qgraph.h" #include "libqos/i2c.h" @@ -25,10 +25,10 @@ #include "qapi/qmp/qnum.h" #include "qemu/bitops.h" -#define TEST_ID "isl_pmbus-test" +#define TEST_ID "isl_pmbus_vr-test" #define TEST_ADDR (0x43) -static uint16_t qmp_isl_pmbus_get(const char *id, const char *property) +static uint16_t qmp_isl_pmbus_vr_get(const char *id, const char *property) { QDict *response; uint64_t ret; @@ -41,7 +41,7 @@ static uint16_t qmp_isl_pmbus_get(const char *id, const char *property) return ret; } -static void qmp_isl_pmbus_set(const char *id, +static void qmp_isl_pmbus_vr_set(const char *id, const char *property, uint16_t value) { @@ -54,7 +54,7 @@ static void qmp_isl_pmbus_set(const char *id, } /* PMBus commands are little endian vs i2c_set16 in i2c.h which is big endian */ -static uint16_t isl_pmbus_i2c_get16(QI2CDevice *i2cdev, uint8_t reg) +static uint16_t isl_pmbus_vr_i2c_get16(QI2CDevice *i2cdev, uint8_t reg) { uint8_t resp[2]; i2c_read_block(i2cdev, reg, resp, sizeof(resp)); @@ -62,7 +62,8 @@ static uint16_t isl_pmbus_i2c_get16(QI2CDevice *i2cdev, uint8_t reg) } /* PMBus commands are little endian vs i2c_set16 in i2c.h which is big endian */ -static void isl_pmbus_i2c_set16(QI2CDevice *i2cdev, uint8_t reg, uint16_t value) +static void isl_pmbus_vr_i2c_set16(QI2CDevice *i2cdev, uint8_t reg, + uint16_t value) { uint8_t data[2]; @@ -76,28 +77,28 @@ static void test_defaults(void *obj, void *data, QGuestAllocator *alloc) uint16_t value, i2c_value; QI2CDevice *i2cdev = (QI2CDevice *)obj; - value = qmp_isl_pmbus_get(TEST_ID, "vout[0]"); + value = qmp_isl_pmbus_vr_get(TEST_ID, "vout[0]"); g_assert_cmpuint(value, ==, ISL_READ_VOUT_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_IOUT); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_IOUT); g_assert_cmpuint(i2c_value, ==, ISL_READ_IOUT_DEFAULT); - value = qmp_isl_pmbus_get(TEST_ID, "pout[0]"); + value = qmp_isl_pmbus_vr_get(TEST_ID, "pout[0]"); g_assert_cmpuint(value, ==, ISL_READ_POUT_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_VIN); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_VIN); g_assert_cmpuint(i2c_value, ==, ISL_READ_VIN_DEFAULT); - value = qmp_isl_pmbus_get(TEST_ID, "iin[0]"); + value = qmp_isl_pmbus_vr_get(TEST_ID, "iin[0]"); g_assert_cmpuint(value, ==, ISL_READ_IIN_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_PIN); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_PIN); g_assert_cmpuint(i2c_value, ==, ISL_READ_PIN_DEFAULT); - value = qmp_isl_pmbus_get(TEST_ID, "temp1[0]"); + value = qmp_isl_pmbus_vr_get(TEST_ID, "temp1[0]"); g_assert_cmpuint(value, ==, ISL_READ_TEMP_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_2); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_2); g_assert_cmpuint(i2c_value, ==, ISL_READ_TEMP_DEFAULT); i2c_value = i2c_get8(i2cdev, PMBUS_CAPABILITY); @@ -112,37 +113,37 @@ static void test_defaults(void *obj, void *data, QGuestAllocator *alloc) i2c_value = i2c_get8(i2cdev, PMBUS_VOUT_MODE); g_assert_cmphex(i2c_value, ==, ISL_VOUT_MODE_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_COMMAND); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_COMMAND); g_assert_cmphex(i2c_value, ==, ISL_VOUT_COMMAND_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_MAX); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_MAX); g_assert_cmphex(i2c_value, ==, ISL_VOUT_MAX_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_MARGIN_HIGH); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_MARGIN_HIGH); g_assert_cmphex(i2c_value, ==, ISL_VOUT_MARGIN_HIGH_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_MARGIN_LOW); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_MARGIN_LOW); g_assert_cmphex(i2c_value, ==, ISL_VOUT_MARGIN_LOW_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_TRANSITION_RATE); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_TRANSITION_RATE); g_assert_cmphex(i2c_value, ==, ISL_VOUT_TRANSITION_RATE_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_OV_FAULT_LIMIT); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_OV_FAULT_LIMIT); g_assert_cmphex(i2c_value, ==, ISL_VOUT_OV_FAULT_LIMIT_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_OT_FAULT_LIMIT); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_OT_FAULT_LIMIT); g_assert_cmphex(i2c_value, ==, ISL_OT_FAULT_LIMIT_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_OT_WARN_LIMIT); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_OT_WARN_LIMIT); g_assert_cmphex(i2c_value, ==, ISL_OT_WARN_LIMIT_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VIN_OV_WARN_LIMIT); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VIN_OV_WARN_LIMIT); g_assert_cmphex(i2c_value, ==, ISL_VIN_OV_WARN_LIMIT_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VIN_UV_WARN_LIMIT); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VIN_UV_WARN_LIMIT); g_assert_cmphex(i2c_value, ==, ISL_VIN_UV_WARN_LIMIT_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_IIN_OC_FAULT_LIMIT); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_IIN_OC_FAULT_LIMIT); g_assert_cmphex(i2c_value, ==, ISL_IIN_OC_FAULT_LIMIT_DEFAULT); i2c_value = i2c_get8(i2cdev, PMBUS_REVISION); @@ -155,13 +156,13 @@ static void raa228000_test_defaults(void *obj, void *data, uint16_t value, i2c_value; QI2CDevice *i2cdev = (QI2CDevice *)obj; - value = qmp_isl_pmbus_get(TEST_ID, "vout[0]"); + value = qmp_isl_pmbus_vr_get(TEST_ID, "vout[0]"); g_assert_cmpuint(value, ==, 0); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_IOUT); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_IOUT); g_assert_cmpuint(i2c_value, ==, 0); - value = qmp_isl_pmbus_get(TEST_ID, "pout[0]"); + value = qmp_isl_pmbus_vr_get(TEST_ID, "pout[0]"); g_assert_cmpuint(value, ==, 0); i2c_value = i2c_get8(i2cdev, PMBUS_CAPABILITY); @@ -176,37 +177,37 @@ static void raa228000_test_defaults(void *obj, void *data, i2c_value = i2c_get8(i2cdev, PMBUS_VOUT_MODE); g_assert_cmphex(i2c_value, ==, ISL_VOUT_MODE_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_COMMAND); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_COMMAND); g_assert_cmphex(i2c_value, ==, ISL_VOUT_COMMAND_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_MAX); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_MAX); g_assert_cmphex(i2c_value, ==, ISL_VOUT_MAX_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_MARGIN_HIGH); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_MARGIN_HIGH); g_assert_cmphex(i2c_value, ==, ISL_VOUT_MARGIN_HIGH_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_MARGIN_LOW); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_MARGIN_LOW); g_assert_cmphex(i2c_value, ==, ISL_VOUT_MARGIN_LOW_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_TRANSITION_RATE); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_TRANSITION_RATE); g_assert_cmphex(i2c_value, ==, ISL_VOUT_TRANSITION_RATE_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_OV_FAULT_LIMIT); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_OV_FAULT_LIMIT); g_assert_cmphex(i2c_value, ==, ISL_VOUT_OV_FAULT_LIMIT_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_OT_FAULT_LIMIT); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_OT_FAULT_LIMIT); g_assert_cmphex(i2c_value, ==, ISL_OT_FAULT_LIMIT_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_OT_WARN_LIMIT); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_OT_WARN_LIMIT); g_assert_cmphex(i2c_value, ==, ISL_OT_WARN_LIMIT_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VIN_OV_WARN_LIMIT); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VIN_OV_WARN_LIMIT); g_assert_cmphex(i2c_value, ==, ISL_VIN_OV_WARN_LIMIT_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VIN_UV_WARN_LIMIT); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VIN_UV_WARN_LIMIT); g_assert_cmphex(i2c_value, ==, ISL_VIN_UV_WARN_LIMIT_DEFAULT); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_IIN_OC_FAULT_LIMIT); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_IIN_OC_FAULT_LIMIT); g_assert_cmphex(i2c_value, ==, ISL_IIN_OC_FAULT_LIMIT_DEFAULT); i2c_value = i2c_get8(i2cdev, PMBUS_REVISION); @@ -219,49 +220,49 @@ static void test_tx_rx(void *obj, void *data, QGuestAllocator *alloc) uint16_t i2c_value, value; QI2CDevice *i2cdev = (QI2CDevice *)obj; - qmp_isl_pmbus_set(TEST_ID, "vin[0]", 200); - value = qmp_isl_pmbus_get(TEST_ID, "vin[0]"); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_VIN); + qmp_isl_pmbus_vr_set(TEST_ID, "vin[0]", 200); + value = qmp_isl_pmbus_vr_get(TEST_ID, "vin[0]"); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_VIN); g_assert_cmpuint(value, ==, i2c_value); - qmp_isl_pmbus_set(TEST_ID, "vout[0]", 2500); - value = qmp_isl_pmbus_get(TEST_ID, "vout[0]"); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_VOUT); + qmp_isl_pmbus_vr_set(TEST_ID, "vout[0]", 2500); + value = qmp_isl_pmbus_vr_get(TEST_ID, "vout[0]"); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_VOUT); g_assert_cmpuint(value, ==, i2c_value); - qmp_isl_pmbus_set(TEST_ID, "iin[0]", 300); - value = qmp_isl_pmbus_get(TEST_ID, "iin[0]"); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_IIN); + qmp_isl_pmbus_vr_set(TEST_ID, "iin[0]", 300); + value = qmp_isl_pmbus_vr_get(TEST_ID, "iin[0]"); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_IIN); g_assert_cmpuint(value, ==, i2c_value); - qmp_isl_pmbus_set(TEST_ID, "iout[0]", 310); - value = qmp_isl_pmbus_get(TEST_ID, "iout[0]"); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_IOUT); + qmp_isl_pmbus_vr_set(TEST_ID, "iout[0]", 310); + value = qmp_isl_pmbus_vr_get(TEST_ID, "iout[0]"); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_IOUT); g_assert_cmpuint(value, ==, i2c_value); - qmp_isl_pmbus_set(TEST_ID, "pin[0]", 100); - value = qmp_isl_pmbus_get(TEST_ID, "pin[0]"); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_PIN); + qmp_isl_pmbus_vr_set(TEST_ID, "pin[0]", 100); + value = qmp_isl_pmbus_vr_get(TEST_ID, "pin[0]"); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_PIN); g_assert_cmpuint(value, ==, i2c_value); - qmp_isl_pmbus_set(TEST_ID, "pout[0]", 95); - value = qmp_isl_pmbus_get(TEST_ID, "pout[0]"); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_POUT); + qmp_isl_pmbus_vr_set(TEST_ID, "pout[0]", 95); + value = qmp_isl_pmbus_vr_get(TEST_ID, "pout[0]"); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_POUT); g_assert_cmpuint(value, ==, i2c_value); - qmp_isl_pmbus_set(TEST_ID, "temp1[0]", 26); - value = qmp_isl_pmbus_get(TEST_ID, "temp1[0]"); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_1); + qmp_isl_pmbus_vr_set(TEST_ID, "temp1[0]", 26); + value = qmp_isl_pmbus_vr_get(TEST_ID, "temp1[0]"); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_1); g_assert_cmpuint(value, ==, i2c_value); - qmp_isl_pmbus_set(TEST_ID, "temp2[0]", 27); - value = qmp_isl_pmbus_get(TEST_ID, "temp2[0]"); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_2); + qmp_isl_pmbus_vr_set(TEST_ID, "temp2[0]", 27); + value = qmp_isl_pmbus_vr_get(TEST_ID, "temp2[0]"); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_2); g_assert_cmpuint(value, ==, i2c_value); - qmp_isl_pmbus_set(TEST_ID, "temp3[0]", 28); - value = qmp_isl_pmbus_get(TEST_ID, "temp3[0]"); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_3); + qmp_isl_pmbus_vr_set(TEST_ID, "temp3[0]", 28); + value = qmp_isl_pmbus_vr_get(TEST_ID, "temp3[0]"); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_3); g_assert_cmpuint(value, ==, i2c_value); } @@ -272,64 +273,64 @@ static void test_rw_regs(void *obj, void *data, QGuestAllocator *alloc) uint16_t i2c_value; QI2CDevice *i2cdev = (QI2CDevice *)obj; - isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_COMMAND, 0x1234); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_COMMAND); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_VOUT_COMMAND, 0x1234); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_COMMAND); g_assert_cmphex(i2c_value, ==, 0x1234); - isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_TRIM, 0x4567); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_TRIM); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_VOUT_TRIM, 0x4567); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_TRIM); g_assert_cmphex(i2c_value, ==, 0x4567); - isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_MAX, 0x9876); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_MAX); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_VOUT_MAX, 0x9876); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_MAX); g_assert_cmphex(i2c_value, ==, 0x9876); - isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_MARGIN_HIGH, 0xABCD); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_MARGIN_HIGH); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_VOUT_MARGIN_HIGH, 0xABCD); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_MARGIN_HIGH); g_assert_cmphex(i2c_value, ==, 0xABCD); - isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_MARGIN_LOW, 0xA1B2); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_MARGIN_LOW); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_VOUT_MARGIN_LOW, 0xA1B2); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_MARGIN_LOW); g_assert_cmphex(i2c_value, ==, 0xA1B2); - isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_TRANSITION_RATE, 0xDEF1); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_TRANSITION_RATE); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_VOUT_TRANSITION_RATE, 0xDEF1); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_TRANSITION_RATE); g_assert_cmphex(i2c_value, ==, 0xDEF1); - isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_DROOP, 0x5678); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_DROOP); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_VOUT_DROOP, 0x5678); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_DROOP); g_assert_cmphex(i2c_value, ==, 0x5678); - isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_MIN, 0x1234); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_MIN); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_VOUT_MIN, 0x1234); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_MIN); g_assert_cmphex(i2c_value, ==, 0x1234); - isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_OV_FAULT_LIMIT, 0x2345); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_OV_FAULT_LIMIT); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_VOUT_OV_FAULT_LIMIT, 0x2345); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_OV_FAULT_LIMIT); g_assert_cmphex(i2c_value, ==, 0x2345); - isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_UV_FAULT_LIMIT, 0xFA12); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VOUT_UV_FAULT_LIMIT); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_VOUT_UV_FAULT_LIMIT, 0xFA12); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_UV_FAULT_LIMIT); g_assert_cmphex(i2c_value, ==, 0xFA12); - isl_pmbus_i2c_set16(i2cdev, PMBUS_OT_FAULT_LIMIT, 0xF077); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_OT_FAULT_LIMIT); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_OT_FAULT_LIMIT, 0xF077); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_OT_FAULT_LIMIT); g_assert_cmphex(i2c_value, ==, 0xF077); - isl_pmbus_i2c_set16(i2cdev, PMBUS_OT_WARN_LIMIT, 0x7137); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_OT_WARN_LIMIT); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_OT_WARN_LIMIT, 0x7137); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_OT_WARN_LIMIT); g_assert_cmphex(i2c_value, ==, 0x7137); - isl_pmbus_i2c_set16(i2cdev, PMBUS_VIN_OV_FAULT_LIMIT, 0x3456); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VIN_OV_FAULT_LIMIT); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_VIN_OV_FAULT_LIMIT, 0x3456); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VIN_OV_FAULT_LIMIT); g_assert_cmphex(i2c_value, ==, 0x3456); - isl_pmbus_i2c_set16(i2cdev, PMBUS_VIN_UV_FAULT_LIMIT, 0xBADA); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_VIN_UV_FAULT_LIMIT); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_VIN_UV_FAULT_LIMIT, 0xBADA); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VIN_UV_FAULT_LIMIT); g_assert_cmphex(i2c_value, ==, 0xBADA); - isl_pmbus_i2c_set16(i2cdev, PMBUS_IIN_OC_FAULT_LIMIT, 0xB1B0); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_IIN_OC_FAULT_LIMIT); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_IIN_OC_FAULT_LIMIT, 0xB1B0); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_IIN_OC_FAULT_LIMIT); g_assert_cmphex(i2c_value, ==, 0xB1B0); i2c_set8(i2cdev, PMBUS_OPERATION, 0xA); @@ -362,49 +363,49 @@ static void test_ro_regs(void *obj, void *data, QGuestAllocator *alloc) uint16_t i2c_init_value, i2c_value; QI2CDevice *i2cdev = (QI2CDevice *)obj; - i2c_init_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_VIN); - isl_pmbus_i2c_set16(i2cdev, PMBUS_READ_VIN, 0xBEEF); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_VIN); + i2c_init_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_VIN); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_READ_VIN, 0xBEEF); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_VIN); g_assert_cmphex(i2c_init_value, ==, i2c_value); - i2c_init_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_IIN); - isl_pmbus_i2c_set16(i2cdev, PMBUS_READ_IIN, 0xB00F); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_IIN); + i2c_init_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_IIN); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_READ_IIN, 0xB00F); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_IIN); g_assert_cmphex(i2c_init_value, ==, i2c_value); - i2c_init_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_VOUT); - isl_pmbus_i2c_set16(i2cdev, PMBUS_READ_VOUT, 0x1234); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_VOUT); + i2c_init_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_VOUT); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_READ_VOUT, 0x1234); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_VOUT); g_assert_cmphex(i2c_init_value, ==, i2c_value); - i2c_init_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_IOUT); - isl_pmbus_i2c_set16(i2cdev, PMBUS_READ_IOUT, 0x6547); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_IOUT); + i2c_init_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_IOUT); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_READ_IOUT, 0x6547); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_IOUT); g_assert_cmphex(i2c_init_value, ==, i2c_value); - i2c_init_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_1); - isl_pmbus_i2c_set16(i2cdev, PMBUS_READ_TEMPERATURE_1, 0x1597); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_1); + i2c_init_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_1); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_READ_TEMPERATURE_1, 0x1597); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_1); g_assert_cmphex(i2c_init_value, ==, i2c_value); - i2c_init_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_2); - isl_pmbus_i2c_set16(i2cdev, PMBUS_READ_TEMPERATURE_2, 0x1897); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_2); + i2c_init_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_2); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_READ_TEMPERATURE_2, 0x1897); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_2); g_assert_cmphex(i2c_init_value, ==, i2c_value); - i2c_init_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_3); - isl_pmbus_i2c_set16(i2cdev, PMBUS_READ_TEMPERATURE_3, 0x1007); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_3); + i2c_init_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_3); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_READ_TEMPERATURE_3, 0x1007); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_3); g_assert_cmphex(i2c_init_value, ==, i2c_value); - i2c_init_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_PIN); - isl_pmbus_i2c_set16(i2cdev, PMBUS_READ_PIN, 0xDEAD); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_PIN); + i2c_init_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_PIN); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_READ_PIN, 0xDEAD); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_PIN); g_assert_cmphex(i2c_init_value, ==, i2c_value); - i2c_init_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_POUT); - isl_pmbus_i2c_set16(i2cdev, PMBUS_READ_POUT, 0xD00D); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_READ_POUT); + i2c_init_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_POUT); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_READ_POUT, 0xD00D); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_POUT); g_assert_cmphex(i2c_init_value, ==, i2c_value); } @@ -415,29 +416,29 @@ static void test_voltage_faults(void *obj, void *data, QGuestAllocator *alloc) uint8_t i2c_byte; QI2CDevice *i2cdev = (QI2CDevice *)obj; - isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_OV_WARN_LIMIT, 5000); - qmp_isl_pmbus_set(TEST_ID, "vout[0]", 5100); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_VOUT_OV_WARN_LIMIT, 5000); + qmp_isl_pmbus_vr_set(TEST_ID, "vout[0]", 5100); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_STATUS_WORD); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_STATUS_WORD); i2c_byte = i2c_get8(i2cdev, PMBUS_STATUS_VOUT); g_assert_true((i2c_value & PB_STATUS_VOUT) != 0); g_assert_true((i2c_byte & PB_STATUS_VOUT_OV_WARN) != 0); - qmp_isl_pmbus_set(TEST_ID, "vout[0]", 4500); + qmp_isl_pmbus_vr_set(TEST_ID, "vout[0]", 4500); i2c_set8(i2cdev, PMBUS_CLEAR_FAULTS, 0); i2c_byte = i2c_get8(i2cdev, PMBUS_STATUS_VOUT); g_assert_true((i2c_byte & PB_STATUS_VOUT_OV_WARN) == 0); - isl_pmbus_i2c_set16(i2cdev, PMBUS_VOUT_UV_WARN_LIMIT, 4600); + isl_pmbus_vr_i2c_set16(i2cdev, PMBUS_VOUT_UV_WARN_LIMIT, 4600); - i2c_value = isl_pmbus_i2c_get16(i2cdev, PMBUS_STATUS_WORD); + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_STATUS_WORD); i2c_byte = i2c_get8(i2cdev, PMBUS_STATUS_VOUT); g_assert_true((i2c_value & PB_STATUS_VOUT) != 0); g_assert_true((i2c_byte & PB_STATUS_VOUT_UV_WARN) != 0); } -static void isl_pmbus_register_nodes(void) +static void isl_pmbus_vr_register_nodes(void) { QOSGraphEdgeOptions opts = { .extra_device_opts = "id=" TEST_ID ",address=0x43" @@ -470,4 +471,4 @@ static void isl_pmbus_register_nodes(void) qos_add_test("test_rw_regs", "raa228000", test_rw_regs, NULL); qos_add_test("test_ov_faults", "raa228000", test_voltage_faults, NULL); } -libqos_init(isl_pmbus_register_nodes); +libqos_init(isl_pmbus_vr_register_nodes); diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 9a6cc93c16..98b5969a38 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -244,7 +244,7 @@ qos_test_ss.add( 'es1370-test.c', 'ipoctal232-test.c', 'lsm303dlhc-mag-test.c', - 'isl_pmbus-test.c', + 'isl_pmbus_vr-test.c', 'max34451-test.c', 'megasas-test.c', 'ne2000-test.c',