From patchwork Wed Mar 2 01:50:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 12765368 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 22AFFC433F5 for ; Wed, 2 Mar 2022 01:53:09 +0000 (UTC) Received: from localhost ([::1]:42380 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPEAu-0001Th-0Q for qemu-devel@archiver.kernel.org; Tue, 01 Mar 2022 20:53:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59738) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3h80eYgYKCrQncnomlaiiafY.WigkYgo-XYpYfhihaho.ila@flex--titusr.bounces.google.com>) id 1nPE90-0007M2-Pt for qemu-devel@nongnu.org; Tue, 01 Mar 2022 20:51:10 -0500 Received: from [2607:f8b0:4864:20::b4a] (port=56150 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 <3h80eYgYKCrQncnomlaiiafY.WigkYgo-XYpYfhihaho.ila@flex--titusr.bounces.google.com>) id 1nPE8x-0004xX-Bd for qemu-devel@nongnu.org; Tue, 01 Mar 2022 20:51:10 -0500 Received: by mail-yb1-xb4a.google.com with SMTP id b18-20020a25fa12000000b0062412a8200eso153507ybe.22 for ; Tue, 01 Mar 2022 17:51:03 -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=qbAA0sUfF1cD7Aex3ZpkZvhuGVfeNsbCKuFI2FSM8NVDF3kUX/zdo+h8BC9J1uSSui RFuMF/4OZ/Hzi3t/2eT0awPiaf/XBJ5ewgSlF3o7qBoxk0LmmWzFB9dx2uVdfkKP1C8p Q0BX9a2H8NWffhNHkulwgQA+Os8at++jkdXGukbXLbCh4M1bHdC0jltR1Eivr9PjuoxM OUAG5RX09mSy9CYEvpdIySEGkW38TF3AyT9az7hqyntHEF9Q46URLgWB3kY8umQTzIKW +1LEbc+lx/6vkF9i0GCC5H/iQfzL8FMcKrC/Y2zdpokMzVotAYo3uvUNjeNCSeUQpKOv 07NA== 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=esbydNq75Fb93DAZuoz5NcWFfNbtejQniMU8g75+C7axWirCFfZr2FQw0Ck6rylgil s8d/CHrJ1F9IbwwyhpLXGALLu9fNCGl4Wadkx+SSaFNW3TOPCMRNAz5Smu0s/d5xObe/ IeNVNYxe3/dpRr3MGQjHbs2TqqyhT5LXJCR5ttVE94g9FPgl+A/t27plpUgw3b9VaM1j YLDBkjO9M/nCUf85pkXKWhb70QYoF/+kfPyZXuFbZCj7SUMvria2XEKdmSaWO1gu8XKQ pBUmCeqnMrjinWXqkLMObl8Q6lrjnZcM468B65uDwF0M6yUHLJLFU3w+7YvZTCc1MViR 0okA== X-Gm-Message-State: AOAM530agixzGjqdnDW0cHI1SSima2LYF5kvpCHBTX+JnMyR5VNTPH/P 7JiMcZ11TharusRzx3dEhogVZnPQfhg= X-Google-Smtp-Source: ABdhPJzU6hZp5dQ4LzuPqKAk4pIFHD4SUNz1xeljzM3NeiGoxdRdS7Um/FtnTllq3ICySAY9UobHVi71X7k= X-Received: from titusr.svl.corp.google.com ([2620:15c:2a3:201:3a0a:5449:c096:dc84]) (user=titusr job=sendgmr) by 2002:a25:a1e4:0:b0:620:f638:3eeb with SMTP id a91-20020a25a1e4000000b00620f6383eebmr27581480ybi.392.1646185863148; Tue, 01 Mar 2022 17:51:03 -0800 (PST) Date: Tue, 1 Mar 2022 17:50:45 -0800 In-Reply-To: <20220302015053.1984165-1-titusr@google.com> Message-Id: <20220302015053.1984165-2-titusr@google.com> Mime-Version: 1.0 References: <20220302015053.1984165-1-titusr@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v3 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, peter.maydell@linaro.org, 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=3h80eYgYKCrQncnomlaiiafY.WigkYgo-XYpYfhihaho.ila@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" - add the VOUT_MIN and STATUS_MFR registers Signed-off-by: Titus Rwantare Reviewed-by: Philippe Mathieu-Daudé --- 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 01:50:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 12765373 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 2F70AC433EF for ; Wed, 2 Mar 2022 01:58:57 +0000 (UTC) Received: from localhost ([::1]:52618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPEGV-0000DT-Re for qemu-devel@archiver.kernel.org; Tue, 01 Mar 2022 20:58:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34598) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3ic0eYgYKCrYpepqonckkcha.Ykimaiq-Zarahjkjcjq.knc@flex--titusr.bounces.google.com>) id 1nPEEI-0006tZ-2f for qemu-devel@nongnu.org; Tue, 01 Mar 2022 20:56:38 -0500 Received: from [2607:f8b0:4864:20::114a] (port=49593 helo=mail-yw1-x114a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3ic0eYgYKCrYpepqonckkcha.Ykimaiq-Zarahjkjcjq.knc@flex--titusr.bounces.google.com>) id 1nPEEG-00071l-If for qemu-devel@nongnu.org; Tue, 01 Mar 2022 20:56:37 -0500 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2d7b96d74f8so1601827b3.16 for ; Tue, 01 Mar 2022 17:56:32 -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=qEl+OFcT9yLNf7Mf4ZBx0+iKJjmHzm1punbcHsKE3Fe7aiFV5geWkEG69ADOph1W56 9govhiEtUvun7rCaJ9mdMfxi/u5XTX6ThAic9HabYDHl9KMICSMhHE34Rrj/tt180wWm wlvo1//imQ8NqsiPfhVy+9QuM+D7grqMgPe+9xRhSRkDhM6fSBE2raixHCJ/SZx7EmaT HXw1rf81m1C5doG3AjrZXLQnlrEowppQ4jl8k/ppttmCMBKju68hU6vWuWbtZ3Q58fBL 9bL/7G7kAXwrE2YkgGhSfSlyfKG146l7AuTqBFai5WJaKXxo+MInjSaVRyBgmXIaSOCv yp3Q== 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=1mccq0AQ3jrpyDaFVROb8T/nYj3lQ4zI8nW234HR/Ga1xJLEVofnkobTx5DqzNdRKv ussIU2RhPhLdSzlq0pb9LaT6J2vN98/XsxRCNYptZKH1YTrZ/jHPBRYSo9VndaovitUw IlBHI4ugo5t2EwFNsvDnZrU5YpE1PO8BXQ6tSokaTXkWaUn9imZRxjhyLQTNj8D6Aru8 IzyOgV5gDop3IglUMmH5PKII1l/brAfVNrLDP5kcOt49isQPeaPX4fhpNdHk8eFYLbxQ gG2qTni4nFNQSbKquDsADCzklGRKBF9k9NIQXfRLBqnFWYrdyBrrBYLObqEozPD7aojx niBw== X-Gm-Message-State: AOAM530g9P/cJxoU9Dq3Agld5goSdxPA4lsJkah468HP/qd0wrcMketf +yA/dIXbXhj+Ipd4LAHd2jO+N0G5t5s= X-Google-Smtp-Source: ABdhPJx/pQGSg/+LZ29MTtHE/N1NzNx5y8viPa2IBFNK7VBoQz5W40W3dcu0LbDFx3EBjAgrWXGnLCqTGfk= X-Received: from titusr.svl.corp.google.com ([2620:15c:2a3:201:3a0a:5449:c096:dc84]) (user=titusr job=sendgmr) by 2002:a25:8886:0:b0:624:50e0:3428 with SMTP id d6-20020a258886000000b0062450e03428mr26995177ybl.552.1646185865540; Tue, 01 Mar 2022 17:51:05 -0800 (PST) Date: Tue, 1 Mar 2022 17:50:46 -0800 In-Reply-To: <20220302015053.1984165-1-titusr@google.com> Message-Id: <20220302015053.1984165-3-titusr@google.com> Mime-Version: 1.0 References: <20220302015053.1984165-1-titusr@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v3 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, peter.maydell@linaro.org, Titus Rwantare X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::114a (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::114a; envelope-from=3ic0eYgYKCrYpepqonckkcha.Ykimaiq-Zarahjkjcjq.knc@flex--titusr.bounces.google.com; helo=mail-yw1-x114a.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: Philippe Mathieu-Daudé --- 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 01:50:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 12765369 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 06F14C433EF for ; Wed, 2 Mar 2022 01:53:13 +0000 (UTC) Received: from localhost ([::1]:42490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPEAy-0001Xv-1O for qemu-devel@archiver.kernel.org; Tue, 01 Mar 2022 20:53:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59750) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3i80eYgYKCrgrgrsqpemmejc.amkocks-bctcjlmlels.mpe@flex--titusr.bounces.google.com>) id 1nPE91-0007MM-L9 for qemu-devel@nongnu.org; Tue, 01 Mar 2022 20:51:11 -0500 Received: from [2607:f8b0:4864:20::b49] (port=54141 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 <3i80eYgYKCrgrgrsqpemmejc.amkocks-bctcjlmlels.mpe@flex--titusr.bounces.google.com>) id 1nPE8z-0004yf-Bo for qemu-devel@nongnu.org; Tue, 01 Mar 2022 20:51:11 -0500 Received: by mail-yb1-xb49.google.com with SMTP id b12-20020a056902030c00b0061d720e274aso158852ybs.20 for ; Tue, 01 Mar 2022 17:51:08 -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=muZibxf298oqgP//MOYsu0QhspwgRNMM8vkRn4vvB7vgRQHKIzCmCC3uU4FZ1vofWp KO4g98tDJ+gja7v0FznfIjKaanStB0xifyxM2PxVW+Do0vqf+yC5L44ZwK7FVt2Gr1at JWYi3ybZ7lmxjUzeDSgKYc/JkBZ5lkwpAZSm17eNdztcmvQSgrv5D97vFz0pNa/P4FPc XpvQvuOeAF4Nf1l7fGXLq0hzITvNSAIVqjO/2ZgTLpOTrPgAGEjG+jW+aVejWGm1+CHt JYdkQC+lp89bqpWofbjKCLxOGZbv4GgqK3pHojV3tYZBxw3ffSy3FDFABs/ZaDA+kIjO xIaA== 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=W+OCgMGRM1p03Xa5sE+qqRZwmACyiRjkJCZzaKPnWxauuw1UprbUwtmEfE7iMAXU8U wWaPDqJy0BqeST8umUT8JcpyjOCLErm3WUKadopXKOfYFwO0luvi9dEH8gbgGRcYge+/ JvgV6MtFjTxlVnLZuUf7rW3l5vXPqROjKljS3Vq9kRAOfU0tG/HHMmdpVzM92+4wcus/ LmAsTu9AhXCWmBWj+nrxm7F5mFeC8LEljKOrBs7udgU9gdiu0LAGuBcRoo16gLZfIA0a lDFE4XVBiTUWfdlqBdZnbIbH+DBaY+JYAUiI0XJ7wQZ4GAOl7bxoPrvs0Se6hJ1F0/B6 DaSA== X-Gm-Message-State: AOAM533a1yqAVPV3p9eBcLxLBuc00pfCRzAe2cOjbB7APAje7XV7k7qf 2kDDrkUxussNhuD+HWVkeUb9jRWcVdY= X-Google-Smtp-Source: ABdhPJxZpHg//+IbUsCWxFujNDCKNSdTLz9hwZQRA8yNedVdJVYKfEFvtcsHTaD9eHJ5UGK38dAVJMA/DDM= X-Received: from titusr.svl.corp.google.com ([2620:15c:2a3:201:3a0a:5449:c096:dc84]) (user=titusr job=sendgmr) by 2002:a25:b18e:0:b0:624:62c1:be56 with SMTP id h14-20020a25b18e000000b0062462c1be56mr26991882ybj.624.1646185867848; Tue, 01 Mar 2022 17:51:07 -0800 (PST) Date: Tue, 1 Mar 2022 17:50:47 -0800 In-Reply-To: <20220302015053.1984165-1-titusr@google.com> Message-Id: <20220302015053.1984165-4-titusr@google.com> Mime-Version: 1.0 References: <20220302015053.1984165-1-titusr@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v3 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, peter.maydell@linaro.org, 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=3i80eYgYKCrgrgrsqpemmejc.amkocks-bctcjlmlels.mpe@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 01:50:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 12765372 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 B603AC433EF for ; Wed, 2 Mar 2022 01:55:42 +0000 (UTC) Received: from localhost ([::1]:49148 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPEDN-00064M-OE for qemu-devel@archiver.kernel.org; Tue, 01 Mar 2022 20:55:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59782) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3js0eYgYKCrsujuvtshpphmf.dpnrfnv-efwfmopohov.psh@flex--titusr.bounces.google.com>) id 1nPE93-0007Ol-58 for qemu-devel@nongnu.org; Tue, 01 Mar 2022 20:51:13 -0500 Received: from [2607:f8b0:4864:20::b49] (port=50796 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 <3js0eYgYKCrsujuvtshpphmf.dpnrfnv-efwfmopohov.psh@flex--titusr.bounces.google.com>) id 1nPE91-0004z7-K0 for qemu-devel@nongnu.org; Tue, 01 Mar 2022 20:51:12 -0500 Received: by mail-yb1-xb49.google.com with SMTP id l3-20020a25ad43000000b0062462e2af34so169523ybe.17 for ; Tue, 01 Mar 2022 17:51:10 -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=ApmW83I1y/dWKJM+pAqI6WOG1YyRSlMqjhVaQd8jSwk=; b=SqIoliy3lDusv4uqOdSc0uOQoZy32GKDrdvHUOEkJ00ezi/isXq+XJNHxj1U2RlswW 6Y7Op4BYTD3ADaHy/6uRHn6KtjYYDvIxuOMPvI5lkyu5pDTZNl/nejQ1jUqICWVKy/xz RrwIzKo0AOoHk22JULXfQD9F3d/gz592yentVM9pBy3bqVApjuI7+/q2IeIbt0FhRg2S gZMU7kYn7b4Tq5cGIk71OUq4Z0M9UXXzhCqxEALiGbXI3/U84g70oQZ7ZrE02dP9YNzs ysAd5cUFXcOP/yjEfI4pZNP+As1r2G3UbTg7PqEgLdJOog4lQX/Tgb5rPeLKh0DVoK78 QEgA== 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=ApmW83I1y/dWKJM+pAqI6WOG1YyRSlMqjhVaQd8jSwk=; b=VnxsDAlN8/ukTCNcZ7QT4OxX1PmoEb2ZhlSFq9NuQUmelxc4AtxflfNGz9hCrrLu2g CNJCp7oB7xVYxIHXZ500PF2UgRpLXDfrve9NcL2x9zvxk1Zq9r/vC36BWODXV0YmHB+n x+kcDHhVbmb3eBeDouT8sJY+L+ty9wFLii+sC3e94PxU71M9CHMDhl5GdcohKFxNeVb1 ESEMPzYDjCHJNiD9rTND+MISXlCCcq6g5jirgw5+gDEKd7R9O/2LEg0LrjpwWn/MBpJw zwJAUd0vxWiV/FKMIV3TaG7oWY9oGzP/ToS1xR3Vu5Q1e9vxN6Eaeo+52EkkQ87TyyCv DL+w== X-Gm-Message-State: AOAM533siLgtJki6SVo+t2AyChNv0eG/Sgae/6RD3lookWPshGXftlVq TlgRaYxVfA5kDf6z04mRWiDyyilj7a8= X-Google-Smtp-Source: ABdhPJz+hcQ92onN6QTRxuA0BF2kKMXR1yd+RoVPzm+RWtRdxAh6aQG5sWtuWYjn4dztuzOY84uWzGQncpg= X-Received: from titusr.svl.corp.google.com ([2620:15c:2a3:201:3a0a:5449:c096:dc84]) (user=titusr job=sendgmr) by 2002:a25:ae06:0:b0:624:42b0:3c7b with SMTP id a6-20020a25ae06000000b0062442b03c7bmr27615822ybj.535.1646185870175; Tue, 01 Mar 2022 17:51:10 -0800 (PST) Date: Tue, 1 Mar 2022 17:50:48 -0800 In-Reply-To: <20220302015053.1984165-1-titusr@google.com> Message-Id: <20220302015053.1984165-5-titusr@google.com> Mime-Version: 1.0 References: <20220302015053.1984165-1-titusr@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v3 4/9] hw/i2c: pmbus: refactor uint handling From: Titus Rwantare To: Corey Minyard Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, f4bug@amsat.org, wuhaotsh@google.com, venture@google.com, peter.maydell@linaro.org, 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=3js0eYgYKCrsujuvtshpphmf.dpnrfnv-efwfmopohov.psh@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" This change cleans up the inputs to pmbus_receive uint, the length of received data is contained in PMBusDevice state and doesn't need to be passed around. Signed-off-by: Titus Rwantare Reviewed-by: Philippe Mathieu-Daudé --- hw/i2c/pmbus_device.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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 01:50:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 12765376 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 2AB09C433EF for ; Wed, 2 Mar 2022 02:03:12 +0000 (UTC) Received: from localhost ([::1]:60180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPEKd-0005Xb-8W for qemu-devel@archiver.kernel.org; Tue, 01 Mar 2022 21:03:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35468) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3kM0eYgYKCr0wlwxvujrrjoh.frpthpx-ghyhoqrqjqx.ruj@flex--titusr.bounces.google.com>) id 1nPEH1-0001tP-Og for qemu-devel@nongnu.org; Tue, 01 Mar 2022 20:59:29 -0500 Received: from [2607:f8b0:4864:20::c49] (port=36377 helo=mail-oo1-xc49.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3kM0eYgYKCr0wlwxvujrrjoh.frpthpx-ghyhoqrqjqx.ruj@flex--titusr.bounces.google.com>) id 1nPEH0-0008Kn-Hb for qemu-devel@nongnu.org; Tue, 01 Mar 2022 20:59:27 -0500 Received: by mail-oo1-xc49.google.com with SMTP id t26-20020a4ac89a000000b0031c5daeddb4so242252ooq.3 for ; Tue, 01 Mar 2022 17:59: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:content-transfer-encoding; bh=SsuwZhWo+ed7nVZvOpG/H3KPAbRwMjbTiNEUiQeQcno=; b=je6Ogwc0aUtFCzQUa/h4EBtoFJY8KIyyIqElzA2HgJz0x4u4zcwNzny3T3AOlWTdej 6r8MfwGys6lFwgIai8dEVIHzAdUoCbo9UFT7TI6r+6aV3z+SA29978Mo2CqMyd9RyE6f fPUF42Kxii4ITceibIJqGvZ0sW+z5y8mQT91uFhEZSUqwyVc6KW1rDhgobpOBcvK/S+F iafBSHVTnZYAmt5tF0Pa9QunASYubO++T6ees55xcI2XvXPylC2ZRcRVkl7AgsLnVRXU mCqhXD5MqKClBW0wf8gG32JtqPieknznf3U7TKpkmk8IaaehZ85CKPnzSKWn4dNWVuAb oklQ== 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=SsuwZhWo+ed7nVZvOpG/H3KPAbRwMjbTiNEUiQeQcno=; b=f/W+jR6KnbJ+unDZTZIcSNc5m7/6MT/YwgmLvoxTg2zLlA+BZ60T+tl2uL0+QXKAJC yPykTxSv1CHNa5mVBKZE0tAXUdfSdQllUeb1cpyLOJ5Nj58Cj8US3tHkuyID064azK++ CtjFFgggzTcgvIZ75dkW722/YgpsCevpLFOeNAHiLbM216s3HT7EERy0m0NaX9wAp4KB Ge5QKlVyYDkH602AK/O6UW4aKbij4uCnr4DBjvr6wwn1OmbK9PThtzUV2Y0nVtzb+mz0 2LIEhgK+UBxK8x09YL1nVvFt2HLgVfkIR0d7rEkQimaGckhyf389yCRDc0LGB6FPfJul +MAQ== X-Gm-Message-State: AOAM531bxuCNIjq247zt+kajhYs7w2igAT38GwhylbT+fsAPbsx3MENe HzRRKKr0VcBA1RTho46lIro0u7jEr3E= X-Google-Smtp-Source: ABdhPJy/uwhxOrqaK7vLsjLNQKQWXmfglIUKYpFsTobCx+G7A4gl3VohDxGNCox9dtbakvwckQWGxL2x4aE= X-Received: from titusr.svl.corp.google.com ([2620:15c:2a3:201:3a0a:5449:c096:dc84]) (user=titusr job=sendgmr) by 2002:a25:2087:0:b0:623:249a:73b6 with SMTP id g129-20020a252087000000b00623249a73b6mr26619843ybg.139.1646185872616; Tue, 01 Mar 2022 17:51:12 -0800 (PST) Date: Tue, 1 Mar 2022 17:50:49 -0800 In-Reply-To: <20220302015053.1984165-1-titusr@google.com> Message-Id: <20220302015053.1984165-6-titusr@google.com> Mime-Version: 1.0 References: <20220302015053.1984165-1-titusr@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v3 5/9] hw/i2c: pmbus: 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, peter.maydell@linaro.org, Titus Rwantare X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::c49 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::c49; envelope-from=3kM0eYgYKCr0wlwxvujrrjoh.frpthpx-ghyhoqrqjqx.ruj@flex--titusr.bounces.google.com; helo=mail-oo1-xc49.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 self to MAINTAINERS for the PMBus subsystem and related sensors, and set PMBus as maintained. Signed-off-by: Titus Rwantare Reviewed-by: Philippe Mathieu-Daudé --- MAINTAINERS | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 From patchwork Wed Mar 2 01:50:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 12765370 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 DF399C433F5 for ; Wed, 2 Mar 2022 01:53:36 +0000 (UTC) Received: from localhost ([::1]:43580 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPEBL-0002Gc-Tf for qemu-devel@archiver.kernel.org; Tue, 01 Mar 2022 20:53:36 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3ks0eYgYKCr8ynyzxwlttlqj.htrvjrz-ij0jqstslsz.twl@flex--titusr.bounces.google.com>) id 1nPE97-0007cx-WE for qemu-devel@nongnu.org; Tue, 01 Mar 2022 20:51:18 -0500 Received: from [2607:f8b0:4864:20::b49] (port=55251 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 <3ks0eYgYKCr8ynyzxwlttlqj.htrvjrz-ij0jqstslsz.twl@flex--titusr.bounces.google.com>) id 1nPE96-0004zt-FA for qemu-devel@nongnu.org; Tue, 01 Mar 2022 20:51:17 -0500 Received: by mail-yb1-xb49.google.com with SMTP id x11-20020a5b0f0b000000b0062277953037so156082ybr.21 for ; Tue, 01 Mar 2022 17:51:15 -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=PrPSE+alUxesQE9QCHPpKglatXwma04vyfRTLAysKvatKxN9oo1nHmGL4Fmy5i445q BAhSppH+QyB1oIB9JPxXHTrzibhsbLGXQcCmkWAavVYkShilJ9g54sz+oq6fxDz1cRvk 78IyHrwshOpRcohd6nU/gp8i/uH3PW9LKjBqzJ/gZY+wDL2De8moT7MRalnFcI4NcDzo hUO/V2wd4XXwSkj9xKE9D9c8rY713QaqGd2copJ4EwGpgobKCkXyX+R6idwiVhathY6m noruaEPkKEw6Ix41GtF+7PYvgjykXwPjYi8sSTkA7qqApyfAH+hiv/sWzRlgF8nxqtmo 2DuA== 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=2GKmr41WlSpkGYGtOm5akUicBgQyfrnM+ca2dP618ZIGMPmAB3nP1QH6PlD5i1FX+I TVCUr3gFZGztJ22ioQ0JKXXIcwRgtGgT/mGSRNxQJq/tCmzKML4mNioRZ6IjSlDGnUPE pLkQp4vNaWu6H4NByY5p9yUxoHBGb+3UAp4EsDdYYYIAEHeol4jF29gpouGRYDBWmJ0n 31qE7P/ncHuBvBJByVuiPIPcib82PzyOrLfZJBPscqzHZLWZc9ExcQsJgky0vBAi5vm9 WiWZW0HaeGUpQJJMfYqDC0Lh08VR7tb8fgA8gD0FecGTg9cGzpF5q5np0pLWM38g+Hym adJQ== X-Gm-Message-State: AOAM531G8GVvwDljSO01r3Pk7Ho9ERyEV/h8mHxembKUwq4uxxSWDZBS Rz7gpNZFNgPjqeaKb3clPxj1t8xziec= X-Google-Smtp-Source: ABdhPJyoV5I0jVXj9QFzW1RqDgFl0QEw1yXEAr2ze9FQJ6t5PDDomSQLIFB6A0W22RPPxp61Z/+20bqsmuI= X-Received: from titusr.svl.corp.google.com ([2620:15c:2a3:201:3a0a:5449:c096:dc84]) (user=titusr job=sendgmr) by 2002:a0d:ca8f:0:b0:2d6:b8dc:13f5 with SMTP id m137-20020a0dca8f000000b002d6b8dc13f5mr28277501ywd.323.1646185874896; Tue, 01 Mar 2022 17:51:14 -0800 (PST) Date: Tue, 1 Mar 2022 17:50:50 -0800 In-Reply-To: <20220302015053.1984165-1-titusr@google.com> Message-Id: <20220302015053.1984165-7-titusr@google.com> Mime-Version: 1.0 References: <20220302015053.1984165-1-titusr@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v3 6/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, peter.maydell@linaro.org, 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=3ks0eYgYKCr8ynyzxwlttlqj.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" From: Shengtan Mao Signed-off-by: Shengtan Mao Reviewed-by: Titus Rwantare Reviewed-by: Philippe Mathieu-Daudé --- 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 01:50:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 12765378 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 683F2C433EF for ; Wed, 2 Mar 2022 02:03:59 +0000 (UTC) Received: from localhost ([::1]:33484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPELO-0006X0-HK for qemu-devel@archiver.kernel.org; Tue, 01 Mar 2022 21:03:58 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35488) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3lc0eYgYKCsI1q120zowwotm.kwuymu2-lm3mtvwvov2.wzo@flex--titusr.bounces.google.com>) id 1nPEH9-0002Hs-5h for qemu-devel@nongnu.org; Tue, 01 Mar 2022 20:59:35 -0500 Received: from [2607:f8b0:4864:20::b4a] (port=43838 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 <3lc0eYgYKCsI1q120zowwotm.kwuymu2-lm3mtvwvov2.wzo@flex--titusr.bounces.google.com>) id 1nPEH6-0008L9-Bl for qemu-devel@nongnu.org; Tue, 01 Mar 2022 20:59:34 -0500 Received: by mail-yb1-xb4a.google.com with SMTP id m10-20020a25800a000000b0061daa5b7151so196317ybk.10 for ; Tue, 01 Mar 2022 17:59:30 -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=5DK0Am6U9VxB/2pb799x/7KWDp88VYzxvJkBczLEb94=; b=ZXISZRDAixGcCjg6bMbMLnEg4tql8F5Q8TkRPxHqD/I6bIKhrMkARtCJiuB+/57BRM 8f2pRAK3/PhEnnsnL3AjwilXI9iMgQNX+lg3YgSxrwVNqzGBnVq77x7szLEBcEUMwZ7P oRe4PY8He1xqxo418xPFZlzbVkBT2miGa3CnAoRgRuJzBE2Qfd/fhCCS0hbFT44KDLQ+ CjCXsTaRLt4Q+P5lwsTCKOiZBPJX/ahGkCGrbX/p5ffSrIPN5sKU+Y8hQ2ktTYwHMQr/ FV46wIoMv0ArcJUR7QxxJq5HIP3FUC7fBxuQYIvVLlSYDdl1svjXsax40sWNso/vmNZq 74NQ== 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=5DK0Am6U9VxB/2pb799x/7KWDp88VYzxvJkBczLEb94=; b=YIPtdLPZIA4DVvf9GWiOcHdYb6CGT1vGlmWqYwL0AE8jgAd7JcdTDeezXoH1qc+PNz wWm0m4e6zqRPEbZHkEU8XUU0QgoEVzaAE5sosnW0ZWIS7gob93rKXxY2oroyuTQua922 5KPlep/uz0kCMXYRz7mTr/BNmSUOkEFyoUazoHz+5GAkYvrsK/rNAGKSC1ZLo1AhEotv zV2IllOOryAkupuxBUyC1Mhep/CZHBMzFgeAgYl5FCXuHs33OtXUYmAaeZyp7n/X1YNY upGe4cKwi1UqZ15k+uHEr4CN4G/mXz39D0bYLvNp5b+0rjWH+L+Wrk2omK8LaVbQ7o22 NVxA== X-Gm-Message-State: AOAM531umpvC1eGdHoJ9lLZPEkdrmIuGeDTcgA8WTk4ZnMxHdnblhZ3F bf1eGZ584BVVQVGmkf9EIO/rmjYuezw= X-Google-Smtp-Source: ABdhPJw79xlhAfnh9/SfF6ih6B1n9dzaCsYP1OrCJWUHkS+n6dKQA9ZmRhFzn1/N18cd8JwtdbasyRJ0BNo= X-Received: from titusr.svl.corp.google.com ([2620:15c:2a3:201:3a0a:5449:c096:dc84]) (user=titusr job=sendgmr) by 2002:a25:2bc5:0:b0:628:71cf:99c with SMTP id r188-20020a252bc5000000b0062871cf099cmr7925028ybr.553.1646185877249; Tue, 01 Mar 2022 17:51:17 -0800 (PST) Date: Tue, 1 Mar 2022 17:50:51 -0800 In-Reply-To: <20220302015053.1984165-1-titusr@google.com> Message-Id: <20220302015053.1984165-8-titusr@google.com> Mime-Version: 1.0 References: <20220302015053.1984165-1-titusr@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v3 7/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, peter.maydell@linaro.org, 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=3lc0eYgYKCsI1q120zowwotm.kwuymu2-lm3mtvwvov2.wzo@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 Reviewed-by: Philippe Mathieu-Daudé --- MAINTAINERS | 3 + hw/arm/Kconfig | 1 + hw/sensor/Kconfig | 5 + hw/sensor/isl_pmbus_vr.c | 211 +++++++++++++++++ hw/sensor/meson.build | 1 + include/hw/sensor/isl_pmbus_vr.h | 50 ++++ tests/qtest/isl_pmbus_vr-test.c | 394 +++++++++++++++++++++++++++++++ tests/qtest/meson.build | 1 + 8 files changed, 666 insertions(+) create mode 100644 hw/sensor/isl_pmbus_vr.c create mode 100644 include/hw/sensor/isl_pmbus_vr.h create mode 100644 tests/qtest/isl_pmbus_vr-test.c diff --git a/MAINTAINERS b/MAINTAINERS index 3601984b5d..364a844045 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_vr.c F: hw/sensor/max34451.c F: include/hw/i2c/pmbus_device.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_vr-test.c Firmware schema specifications M: Philippe Mathieu-Daudé diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 6945330030..97f3b38019 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_VR select PL310 # cache controller select PMBUS select SERIAL diff --git a/hw/sensor/Kconfig b/hw/sensor/Kconfig index 215944decc..a834d2f814 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_VR + bool + depends on I2C + diff --git a/hw/sensor/isl_pmbus_vr.c b/hw/sensor/isl_pmbus_vr.c new file mode 100644 index 0000000000..b3d24e40ab --- /dev/null +++ b/hw/sensor/isl_pmbus_vr.c @@ -0,0 +1,211 @@ +/* + * 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_vr.h" +#include "hw/qdev-properties.h" +#include "qapi/visitor.h" +#include "qemu/log.h" +#include "qemu/module.h" + +static uint8_t isl_pmbus_vr_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_vr_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_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_vr_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_vr_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_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_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_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_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_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_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_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_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_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_vr_get, + isl_pmbus_vr_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_vr_add_props(obj, flags, 2); +} + +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_vr_write_data; + k->receive_byte = isl_pmbus_vr_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_vr_exit_reset; + isl_pmbus_vr_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_vr_register_types(void) +{ + type_register_static(&isl69260_info); +} + +type_init(isl_pmbus_vr_register_types) diff --git a/hw/sensor/meson.build b/hw/sensor/meson.build index d1bba290da..12b6992bc8 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_VR', if_true: files('isl_pmbus_vr.c')) diff --git a/include/hw/sensor/isl_pmbus_vr.h b/include/hw/sensor/isl_pmbus_vr.h new file mode 100644 index 0000000000..4e12e95efb --- /dev/null +++ b/include/hw/sensor/isl_pmbus_vr.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_VR_H +#define HW_MISC_ISL_PMBUS_VR_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_vr-test.c b/tests/qtest/isl_pmbus_vr-test.c new file mode 100644 index 0000000000..f77732ae96 --- /dev/null +++ b/tests/qtest/isl_pmbus_vr-test.c @@ -0,0 +1,394 @@ +/* + * 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_vr.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_vr-test" +#define TEST_ADDR (0x43) + +static uint16_t qmp_isl_pmbus_vr_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_vr_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_vr_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_vr_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_vr_get(TEST_ID, "vout[0]"); + g_assert_cmpuint(value, ==, ISL_READ_VOUT_DEFAULT); + + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_IOUT); + g_assert_cmpuint(i2c_value, ==, ISL_READ_IOUT_DEFAULT); + + value = qmp_isl_pmbus_vr_get(TEST_ID, "pout[0]"); + g_assert_cmpuint(value, ==, ISL_READ_POUT_DEFAULT); + + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_VIN); + g_assert_cmpuint(i2c_value, ==, ISL_READ_VIN_DEFAULT); + + value = qmp_isl_pmbus_vr_get(TEST_ID, "iin[0]"); + g_assert_cmpuint(value, ==, ISL_READ_IIN_DEFAULT); + + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_PIN); + g_assert_cmpuint(i2c_value, ==, ISL_READ_PIN_DEFAULT); + + value = qmp_isl_pmbus_vr_get(TEST_ID, "temp1[0]"); + g_assert_cmpuint(value, ==, ISL_READ_TEMP_DEFAULT); + + 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); + 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_vr_i2c_get16(i2cdev, PMBUS_VOUT_COMMAND); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_COMMAND_DEFAULT); + + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_MAX); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_MAX_DEFAULT); + + 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_vr_i2c_get16(i2cdev, PMBUS_VOUT_MARGIN_LOW); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_MARGIN_LOW_DEFAULT); + + 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_vr_i2c_get16(i2cdev, PMBUS_VOUT_OV_FAULT_LIMIT); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_OV_FAULT_LIMIT_DEFAULT); + + 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_vr_i2c_get16(i2cdev, PMBUS_OT_WARN_LIMIT); + g_assert_cmphex(i2c_value, ==, ISL_OT_WARN_LIMIT_DEFAULT); + + 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_vr_i2c_get16(i2cdev, PMBUS_VIN_UV_WARN_LIMIT); + g_assert_cmphex(i2c_value, ==, ISL_VIN_UV_WARN_LIMIT_DEFAULT); + + 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); + 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_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_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_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_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_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_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_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_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_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); + +} + +/* 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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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); + 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_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_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_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_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_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_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_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_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_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); +} + +/* 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_vr_i2c_set16(i2cdev, PMBUS_VOUT_OV_WARN_LIMIT, 5000); + qmp_isl_pmbus_vr_set(TEST_ID, "vout[0]", 5100); + + 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_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_vr_i2c_set16(i2cdev, PMBUS_VOUT_UV_WARN_LIMIT, 4600); + + 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_vr_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_vr_register_nodes); diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index f33d84d19b..98b5969a38 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_vr-test.c', 'max34451-test.c', 'megasas-test.c', 'ne2000-test.c', From patchwork Wed Mar 2 01:50:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 12765371 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 1B652C433EF for ; Wed, 2 Mar 2022 01:53:52 +0000 (UTC) Received: from localhost ([::1]:43948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPEBb-0002Vp-8q for qemu-devel@archiver.kernel.org; Tue, 01 Mar 2022 20:53:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59968) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3l80eYgYKCsQ3s3421qyyqvo.myw0ow4-no5ovxyxqx4.y1q@flex--titusr.bounces.google.com>) id 1nPE9E-000805-RB for qemu-devel@nongnu.org; Tue, 01 Mar 2022 20:51:25 -0500 Received: from [2607:f8b0:4864:20::b49] (port=34564 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 <3l80eYgYKCsQ3s3421qyyqvo.myw0ow4-no5ovxyxqx4.y1q@flex--titusr.bounces.google.com>) id 1nPE9A-00052F-NW for qemu-devel@nongnu.org; Tue, 01 Mar 2022 20:51:24 -0500 Received: by mail-yb1-xb49.google.com with SMTP id w6-20020a25c706000000b006287a0164f2so233710ybe.1 for ; Tue, 01 Mar 2022 17:51:19 -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=XYN59VvRX2AT2pHQ1lvOa3ZDRpcLJvwu4TLeEW0HOpM=; b=MV+po+e/sBetw1KkpnnzutywaPCPIZtFE/1tcNOBan4KGh/Q7ODhe62/a2tfvSl96w NS1I0UvJE4sx3FuIg3jr0oZG654mni+rU6ua3G07hl7Uc6XAtldIVuX6uJ5BbjnGjUF0 /FOV0Xko5BbZ2DKuSY7ZKTlLsNOVyggU51pWgJGWBIW8nYjAJjhucTjz48VuU6SvpKHS dNIJm9UX+rkSlkSheu3d6RgMrA++Rb8VjPKKsM5T0usoyaj/aO+0eRfKljkjOqQGPYPI 8pdoLuir+/a3pMV3gGcG+ivy1kXWmbT5Q2DBJ+Lt8tfXH8Kec2z9hu9s3LYShWWXKrj3 fFFQ== 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=XYN59VvRX2AT2pHQ1lvOa3ZDRpcLJvwu4TLeEW0HOpM=; b=UENxp5u78pqg/tSmWvDu2yorduhPOTIHBaqy9Z1ioP4CgH7VuZopaBuXr2+N1a6P5b UcmssKrcnGEzr4aJrCYAhxA2AWFOqpMdnZ7dZjqB077MkCFB7oPpR4NmseQMpRtOY4Qe JFs5jPI7JOPs4Tc0X7ngm0fy6bMpF7WsfStfeZWbV2Rx/jUqBaWjkoHog2cuyItRHQV8 354rT4EboOv1fq9nwqy6vuvCvPISXXTExS8C5GRmMzejBfENTMjGKM4dQTuq+hpzFtmC OkLnKnFPVXMUHS5kxdDWWwYoNHjed5aNcIljXM4/2c5a/8yyEGxo7NI8xJsvzU1mhv8O cYqw== X-Gm-Message-State: AOAM533R7IjmhAd0AWrmJqckVht9CxLOYBk55gjQlbhlsijMpnbp8nOq E/Pc8+2HaNXbQXnJt/msiNajWxFBKE8= X-Google-Smtp-Source: ABdhPJxwuXOiIF5S8l+OWtMOH1DG0O40Iutehef/9KZCW00ALu7xDjHmxwMc/ePdSOI9lVTFJeF35O2a6JQ= X-Received: from titusr.svl.corp.google.com ([2620:15c:2a3:201:3a0a:5449:c096:dc84]) (user=titusr job=sendgmr) by 2002:a81:d85:0:b0:2d1:1b8d:f236 with SMTP id 127-20020a810d85000000b002d11b8df236mr27961440ywn.212.1646185879400; Tue, 01 Mar 2022 17:51:19 -0800 (PST) Date: Tue, 1 Mar 2022 17:50:52 -0800 In-Reply-To: <20220302015053.1984165-1-titusr@google.com> Message-Id: <20220302015053.1984165-9-titusr@google.com> Mime-Version: 1.0 References: <20220302015053.1984165-1-titusr@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v3 8/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, peter.maydell@linaro.org, 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=3l80eYgYKCsQ3s3421qyyqvo.myw0ow4-no5ovxyxqx4.y1q@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" The Renesas RAA229004 is a PMBus Multiphase Voltage Regulator Signed-off-by: Titus Rwantare Reviewed-by: Hao Wu Reviewed-by: Philippe Mathieu-Daudé --- hw/sensor/isl_pmbus_vr.c | 18 ++++++++++++++++++ include/hw/sensor/isl_pmbus_vr.h | 1 + tests/qtest/isl_pmbus_vr-test.c | 8 ++++++++ 3 files changed, 27 insertions(+) diff --git a/hw/sensor/isl_pmbus_vr.c b/hw/sensor/isl_pmbus_vr.c index b3d24e40ab..e260faeac3 100644 --- a/hw/sensor/isl_pmbus_vr.c +++ b/hw/sensor/isl_pmbus_vr.c @@ -195,6 +195,15 @@ static void isl69260_class_init(ObjectClass *klass, void *data) isl_pmbus_vr_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_vr_exit_reset; + isl_pmbus_vr_class_init(klass, data, 2); +} + static const TypeInfo isl69260_info = { .name = TYPE_ISL69260, .parent = TYPE_PMBUS_DEVICE, @@ -203,9 +212,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_vr_register_types(void) { type_register_static(&isl69260_info); + type_register_static(&raa229004_info); } type_init(isl_pmbus_vr_register_types) diff --git a/include/hw/sensor/isl_pmbus_vr.h b/include/hw/sensor/isl_pmbus_vr.h index 4e12e95efb..233916f70a 100644 --- a/include/hw/sensor/isl_pmbus_vr.h +++ b/include/hw/sensor/isl_pmbus_vr.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_vr-test.c b/tests/qtest/isl_pmbus_vr-test.c index f77732ae96..a33dfb6135 100644 --- a/tests/qtest/isl_pmbus_vr-test.c +++ b/tests/qtest/isl_pmbus_vr-test.c @@ -384,11 +384,19 @@ static void isl_pmbus_vr_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_vr_register_nodes); From patchwork Wed Mar 2 01:50:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Titus Rwantare X-Patchwork-Id: 12765374 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 B8E94C433EF for ; Wed, 2 Mar 2022 01:59:13 +0000 (UTC) Received: from localhost ([::1]:53354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nPEGm-0000kP-SN for qemu-devel@archiver.kernel.org; Tue, 01 Mar 2022 20:59:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34800) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3mc0eYgYKCsY5u5643s00sxq.o0y2qy6-pq7qxz0zsz6.03s@flex--titusr.bounces.google.com>) id 1nPEF4-0007Lh-OK for qemu-devel@nongnu.org; Tue, 01 Mar 2022 20:57:26 -0500 Received: from [2607:f8b0:4864:20::1049] (port=47020 helo=mail-pj1-x1049.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3mc0eYgYKCsY5u5643s00sxq.o0y2qy6-pq7qxz0zsz6.03s@flex--titusr.bounces.google.com>) id 1nPEF2-00077t-Vl for qemu-devel@nongnu.org; Tue, 01 Mar 2022 20:57:26 -0500 Received: by mail-pj1-x1049.google.com with SMTP id m3-20020a17090a3f8300b001bd33af55f2so342681pjc.1 for ; Tue, 01 Mar 2022 17:57:07 -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=iGy5AoMooNtuvyOeDJtUyYLQNLcqWDLIcHmLmUhSrng=; b=emM/uglxYA8a1mQ4OM6kZupI/AnoPIzZpWwJTEQJzJVv1LXNolOhIEk+Sxikmo3ahJ MWNvMgk5El5OajGL3KzRwtQOFlRrfSZgaQmxSELxfbhWjFiZ/mbYB1DeTGCN8CoE6bGt zCpF12t3vLXh0JiQztIWntEV4nBSLEgKlxsJomCxaH4C39qF4KxHEz7L3SgZUeQjO+6k lstu8KVPM+kFX9ZtXvyxLgKjtqoJUEc5rlplkGex7xP9R/3c1br/bXxNAxGR5BTpgSBS zfZx+r+QQzbSEcZ44kqlTOv2uihPmMoojPDAJj8uRo3FSvNFdanbqcAZn8u210dycQlH m+sg== 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=iGy5AoMooNtuvyOeDJtUyYLQNLcqWDLIcHmLmUhSrng=; b=ZXxuwtw5iRmSUMmoZBfyrPoF/3brCmV/Si36UwCIN4/JSdNl/EAFehH4gYB3t5Y1Ol eO2hx6wXcEbnv/cG9ULMmOJBn05fbubLL21ewuE0Hc+FTnF/t45E9ywU0nzdsiF1v50g izA51fiWnJfrk93sQQrFCyb9dxXDZK8MLbQHcEe1aI7UGuLTg7/KZpXVuCHCEJUZ2rbn /dd7IQNHDOMepKermHP4BNCnliPTHszvuc3U/ss7mHNVIQIva2tUqO6lVeMkRFK0sIQ3 MV12gAm8vFgCvmhF7135BjeUkLgBq9RIDcj7MoLq6WCMesvqGNiq3DVbfgQksw5+XbIN SP/A== X-Gm-Message-State: AOAM5313zTMmynMy/wxD6QbDrUNHPvYgC3WoINEL9PqLgWax2QWcwGTg ruAnoDAQSPp9zSMpk9LfXnymuX1KlmM= X-Google-Smtp-Source: ABdhPJwZ9micqb0wVgy59V8MBiSDoOs3eV0FQc9t+QLQrPsxFZ9OdUne4OpSLNpGxdf0nzyuNDHe44aIhQQ= X-Received: from titusr.svl.corp.google.com ([2620:15c:2a3:201:3a0a:5449:c096:dc84]) (user=titusr job=sendgmr) by 2002:a63:1f42:0:b0:378:7fb4:6491 with SMTP id q2-20020a631f42000000b003787fb46491mr13665534pgm.478.1646185881975; Tue, 01 Mar 2022 17:51:21 -0800 (PST) Date: Tue, 1 Mar 2022 17:50:53 -0800 In-Reply-To: <20220302015053.1984165-1-titusr@google.com> Message-Id: <20220302015053.1984165-10-titusr@google.com> Mime-Version: 1.0 References: <20220302015053.1984165-1-titusr@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v3 9/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, peter.maydell@linaro.org, Titus Rwantare X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::1049 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::1049; envelope-from=3mc0eYgYKCsY5u5643s00sxq.o0y2qy6-pq7qxz0zsz6.03s@flex--titusr.bounces.google.com; helo=mail-pj1-x1049.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 Reviewed-by: Philippe Mathieu-Daudé --- hw/sensor/isl_pmbus_vr.c | 50 ++++++++++++++++++++ include/hw/sensor/isl_pmbus_vr.h | 1 + tests/qtest/isl_pmbus_vr-test.c | 78 ++++++++++++++++++++++++++++++-- 3 files changed, 126 insertions(+), 3 deletions(-) diff --git a/hw/sensor/isl_pmbus_vr.c b/hw/sensor/isl_pmbus_vr.c index e260faeac3..df7c003ea6 100644 --- a/hw/sensor/isl_pmbus_vr.c +++ b/hw/sensor/isl_pmbus_vr.c @@ -89,6 +89,24 @@ static void isl_pmbus_vr_exit_reset(Object *obj) } } +/* The raa228000 uses different direct mode coefficents from most isl devices */ +static void raa228000_exit_reset(Object *obj) +{ + isl_pmbus_vr_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_vr_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_vr_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_vr_add_props(obj, flags, 1); +} + static void isl_pmbus_vr_class_init(ObjectClass *klass, void *data, uint8_t pages) { @@ -195,6 +227,15 @@ static void isl69260_class_init(ObjectClass *klass, void *data) isl_pmbus_vr_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_vr_class_init(klass, data, 1); +} + static void raa229004_class_init(ObjectClass *klass, void *data) { ResettableClass *rc = RESETTABLE_CLASS(klass); @@ -220,9 +261,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_vr_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_vr.h b/include/hw/sensor/isl_pmbus_vr.h index 233916f70a..3e47ff7e48 100644 --- a/include/hw/sensor/isl_pmbus_vr.h +++ b/include/hw/sensor/isl_pmbus_vr.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_vr-test.c b/tests/qtest/isl_pmbus_vr-test.c index a33dfb6135..5553ea410a 100644 --- a/tests/qtest/isl_pmbus_vr-test.c +++ b/tests/qtest/isl_pmbus_vr-test.c @@ -150,6 +150,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_vr_get(TEST_ID, "vout[0]"); + g_assert_cmpuint(value, ==, 0); + + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_READ_IOUT); + g_assert_cmpuint(i2c_value, ==, 0); + + value = qmp_isl_pmbus_vr_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_vr_i2c_get16(i2cdev, PMBUS_VOUT_COMMAND); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_COMMAND_DEFAULT); + + i2c_value = isl_pmbus_vr_i2c_get16(i2cdev, PMBUS_VOUT_MAX); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_MAX_DEFAULT); + + 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_vr_i2c_get16(i2cdev, PMBUS_VOUT_MARGIN_LOW); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_MARGIN_LOW_DEFAULT); + + 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_vr_i2c_get16(i2cdev, PMBUS_VOUT_OV_FAULT_LIMIT); + g_assert_cmphex(i2c_value, ==, ISL_VOUT_OV_FAULT_LIMIT_DEFAULT); + + 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_vr_i2c_get16(i2cdev, PMBUS_OT_WARN_LIMIT); + g_assert_cmphex(i2c_value, ==, ISL_OT_WARN_LIMIT_DEFAULT); + + 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_vr_i2c_get16(i2cdev, PMBUS_VIN_UV_WARN_LIMIT); + g_assert_cmphex(i2c_value, ==, ISL_VIN_UV_WARN_LIMIT_DEFAULT); + + 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); + g_assert_cmphex(i2c_value, ==, ISL_REVISION_DEFAULT); +} + /* test qmp access */ static void test_tx_rx(void *obj, void *data, QGuestAllocator *alloc) { @@ -384,9 +448,6 @@ static void isl_pmbus_vr_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); @@ -394,9 +455,20 @@ static void isl_pmbus_vr_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_vr_register_nodes);