From patchwork Thu Dec 7 01:41:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 13482565 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 98C89C46CA0 for ; Thu, 7 Dec 2023 01:43:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rB3Oy-0005Y0-Ly; Wed, 06 Dec 2023 20:42:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rB3Ow-0005Xs-L7 for qemu-devel@nongnu.org; Wed, 06 Dec 2023 20:42:06 -0500 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rB3Ou-0005Kn-SE for qemu-devel@nongnu.org; Wed, 06 Dec 2023 20:42:06 -0500 Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-3b9d029b9bbso240962b6e.1 for ; Wed, 06 Dec 2023 17:42:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701913324; x=1702518124; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=hxB4u6iXyAjHiZmyMCxouWpcKxw7TMoA0aLedTAWAQA=; b=hhd0T+ANW5n4vrEOdJdYlSk3PxIlO57dkiQKmz43dtZEKZTiafssBxN49PZp5oJjPX 5TuMCdXrYv6TEBwqHO9JXsb5FWK89HOyDj1tYT8EYU+7G1y4HDLAlVLZDrszUMq7fway /40fl+A0NCE1gqdz3nglfrMBFFt5wlKas6f2ikeZi9p2vhYXz4tOYZUO5oR0kVXGS5LB 05hv91Nl1YeGOET8nqBKCWOLEMZwm0xrJK4GnCWbT+ysjNdwNlkM4ygcw064yYc6IZHN LwmXO6v1/vdb1vHiaelCFR9Z4CxNqCQ2WEQ8XgCiH/ps2nUgNkwCXpmdxb9EZVU1rSqW AErQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701913324; x=1702518124; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=hxB4u6iXyAjHiZmyMCxouWpcKxw7TMoA0aLedTAWAQA=; b=Dp4H2ZpWmj5KdgjocGLP38snQ/BlwjdfcN5D8bpNtK9ChFfiozfIPE6t41c7stgYOF AS/G1qhIK/NT7EVzXRXeB4H0NNa3RF92wUCC6wkGVvje7ZSa1YGa/xU0xx+h+FG+Kkkb hCpC7tBfr4Fi8hKxcmh8IfUKsFDCFcsNbmzSFQyJb7l7r7oYrcP8BxqGT0flTm3aJYkD RNg5iUA7TYFpxStv3pxFEV+wxOzbCmsqlJy9K3UTxc2KEwMPqjiiSliT05i9rSBPlXJc gKREk9FanW9OUpUk7d42KoSOZfa1chyLguFKQT1ym4//qRh2yBjrzJ7/GevcgLXx22Sd PiAg== X-Gm-Message-State: AOJu0Yw4muV6bc3VAM/Yt7Wr6ZLKLtD3EIZX2/RScB2+XKdxqRKGRc/d /aqdEwWP/ozihwxQJNkdfA== X-Google-Smtp-Source: AGHT+IFLgEPNRJG6QWb+mxoeSUKILu/jNVQ+rd8T80r+YrgewqnfwhuGDMxyqNBNjCR5g4l6Drh5mg== X-Received: by 2002:a05:6808:1208:b0:3b8:98f0:3c6 with SMTP id a8-20020a056808120800b003b898f003c6mr1037003oil.14.1701913323758; Wed, 06 Dec 2023 17:42:03 -0800 (PST) Received: from serve.minyard.net ([47.189.89.62]) by smtp.gmail.com with ESMTPSA id 8-20020aca1008000000b003ae3768ba4csm54652oiq.58.2023.12.06.17.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 17:42:02 -0800 (PST) Received: from dell1.minyard.net (unknown [IPv6:2001:470:b8f6:1b:8ff4:f8fd:ca3:53c6]) by serve.minyard.net (Postfix) with ESMTPA id 674CB1800C1; Thu, 7 Dec 2023 01:42:02 +0000 (UTC) From: minyard@acm.org To: qemu-devel@nongnu.org Cc: Potin Lai , Patrick Venture , Hao Wu , Titus Rwantare , Chris Rauer , Corey Minyard Subject: [PULL 1/2] hw/sensor: enable setting adm1272 temperature with qmp Date: Wed, 6 Dec 2023 19:41:47 -0600 Message-Id: <20231207014148.3116889-2-minyard@acm.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231207014148.3116889-1-minyard@acm.org> References: <20231207014148.3116889-1-minyard@acm.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::236; envelope-from=tcminyard@gmail.com; helo=mail-oi1-x236.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Titus Rwantare Reviewed-by: Patrick Venture Reviewed-by: Chris Rauer Reviewed-by: Hao Wu Signed-off-by: Titus Rwantare Message-Id: <20220106173814.3580141-1-venture@google.com> Signed-off-by: Corey Minyard --- hw/sensor/adm1272.c | 27 ++++++++++++++++++++++++++- tests/qtest/adm1272-test.c | 28 +++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/hw/sensor/adm1272.c b/hw/sensor/adm1272.c index 8f4a1c2cd4..6e5ae6e63b 100644 --- a/hw/sensor/adm1272.c +++ b/hw/sensor/adm1272.c @@ -65,6 +65,7 @@ #define ADM1272_VOLTAGE_COEFF_DEFAULT 1 #define ADM1272_CURRENT_COEFF_DEFAULT 3 #define ADM1272_PWR_COEFF_DEFAULT 7 +#define ADM1272_TEMP_COEFF_DEFAULT 8 #define ADM1272_IOUT_OFFSET 0x5000 #define ADM1272_IOUT_OFFSET 0x5000 @@ -185,6 +186,22 @@ static uint32_t adm1272_direct_to_watts(uint16_t value) return pmbus_direct_mode2data(c, value); } +static uint16_t adm1272_millidegrees_to_direct(uint32_t value) +{ + PMBusCoefficients c = adm1272_coefficients[ADM1272_TEMP_COEFF_DEFAULT]; + c.b = c.b * 1000; + c.R = c.R - 3; + return pmbus_data2direct_mode(c, value); +} + +static uint32_t adm1272_direct_to_millidegrees(uint16_t value) +{ + PMBusCoefficients c = adm1272_coefficients[ADM1272_TEMP_COEFF_DEFAULT]; + c.b = c.b * 1000; + c.R = c.R - 3; + return pmbus_direct_mode2data(c, value); +} + static void adm1272_exit_reset(Object *obj) { ADM1272State *s = ADM1272(obj); @@ -219,7 +236,7 @@ static void adm1272_exit_reset(Object *obj) = adm1272_millivolts_to_direct(ADM1272_VOLT_DEFAULT); pmdev->pages[0].read_iout = adm1272_milliamps_to_direct(ADM1272_IOUT_DEFAULT); - pmdev->pages[0].read_temperature_1 = 0; + pmdev->pages[0].read_temperature_1 = adm1272_millidegrees_to_direct(30000); pmdev->pages[0].read_pin = adm1272_watts_to_direct(ADM1272_PWR_DEFAULT); pmdev->pages[0].revision = ADM1272_PMBUS_REVISION_DEFAULT; pmdev->pages[0].mfr_id = ADM1272_MFR_ID_DEFAULT; @@ -422,6 +439,8 @@ static void adm1272_get(Object *obj, Visitor *v, const char *name, void *opaque, value = adm1272_direct_to_milliamps(*(uint16_t *)opaque); } else if (strcmp(name, "pin") == 0) { value = adm1272_direct_to_watts(*(uint16_t *)opaque); + } else if (strcmp(name, "temperature") == 0) { + value = adm1272_direct_to_millidegrees(*(uint16_t *)opaque); } else { value = *(uint16_t *)opaque; } @@ -446,6 +465,8 @@ static void adm1272_set(Object *obj, Visitor *v, const char *name, void *opaque, *internal = adm1272_milliamps_to_direct(value); } else if (strcmp(name, "pin") == 0) { *internal = adm1272_watts_to_direct(value); + } else if (strcmp(name, "temperature") == 0) { + *internal = adm1272_millidegrees_to_direct(value); } else { *internal = value; } @@ -509,6 +530,10 @@ static void adm1272_init(Object *obj) adm1272_get, adm1272_set, NULL, &pmdev->pages[0].read_pin); + object_property_add(obj, "temperature", "uint16", + adm1272_get, + adm1272_set, NULL, &pmdev->pages[0].read_temperature_1); + } static void adm1272_class_init(ObjectClass *klass, void *data) diff --git a/tests/qtest/adm1272-test.c b/tests/qtest/adm1272-test.c index 63f8514801..98134aabd2 100644 --- a/tests/qtest/adm1272-test.c +++ b/tests/qtest/adm1272-test.c @@ -65,6 +65,7 @@ #define ADM1272_VOLTAGE_COEFF_DEFAULT 1 #define ADM1272_CURRENT_COEFF_DEFAULT 3 #define ADM1272_PWR_COEFF_DEFAULT 7 +#define ADM1272_TEMP_COEFF_DEFAULT 8 #define ADM1272_IOUT_OFFSET 0x5000 #define ADM1272_IOUT_OFFSET 0x5000 @@ -144,6 +145,22 @@ static uint32_t adm1272_direct_to_watts(uint16_t value) return pmbus_direct_mode2data(c, value); } +static uint16_t adm1272_millidegrees_to_direct(uint32_t value) +{ + PMBusCoefficients c = adm1272_coefficients[ADM1272_TEMP_COEFF_DEFAULT]; + c.b = c.b * 1000; + c.R = c.R - 3; + return pmbus_data2direct_mode(c, value); +} + +static uint32_t adm1272_direct_to_millidegrees(uint16_t value) +{ + PMBusCoefficients c = adm1272_coefficients[ADM1272_TEMP_COEFF_DEFAULT]; + c.b = c.b * 1000; + c.R = c.R - 3; + return pmbus_direct_mode2data(c, value); +} + static uint16_t qmp_adm1272_get(const char *id, const char *property) { QDict *response; @@ -248,7 +265,7 @@ static void test_defaults(void *obj, void *data, QGuestAllocator *alloc) /* test qmp access */ static void test_tx_rx(void *obj, void *data, QGuestAllocator *alloc) { - uint16_t i2c_value, value, i2c_voltage, i2c_pwr, lossy_value; + uint16_t i2c_value, value, i2c_voltage, i2c_pwr, i2c_temp, lossy_value; QI2CDevice *i2cdev = (QI2CDevice *)obj; /* converting to direct mode is lossy - we generate the same loss here */ @@ -287,6 +304,15 @@ static void test_tx_rx(void *obj, void *data, QGuestAllocator *alloc) i2c_pwr = adm1272_direct_to_watts(i2c_value); g_assert_cmphex(value, ==, i2c_pwr); g_assert_cmphex(i2c_pwr, ==, lossy_value); + + lossy_value = + adm1272_direct_to_millidegrees(adm1272_millidegrees_to_direct(25000)); + qmp_adm1272_set(TEST_ID, "temperature", 25000); + value = qmp_adm1272_get(TEST_ID, "temperature"); + i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_1); + i2c_temp = adm1272_direct_to_millidegrees(i2c_value); + g_assert_cmphex(value, ==, i2c_temp); + g_assert_cmphex(i2c_temp, ==, lossy_value); } /* test r/w registers */ From patchwork Thu Dec 7 01:41:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 13482564 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 80A85C4167B for ; Thu, 7 Dec 2023 01:43:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rB3P0-0005YO-K0; Wed, 06 Dec 2023 20:42:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rB3Oz-0005Y4-97 for qemu-devel@nongnu.org; Wed, 06 Dec 2023 20:42:09 -0500 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rB3Ou-0005Km-Rk for qemu-devel@nongnu.org; Wed, 06 Dec 2023 20:42:09 -0500 Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-3b9de2332e3so76898b6e.1 for ; Wed, 06 Dec 2023 17:42:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701913323; x=1702518123; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=nBxHn8pPY9Z5FdN+k7OtNFF2y23J51ZbRWvqj66+tuw=; b=j3Gv+l2n6iMtg9GIEuLFe4HZZ09jgXTAc5yRwW++45g0W1CN7smuCBwEePpUfL2Izd UOE4HRQYKOkuFJxYWMKjoA14GAtPCrYZaKhVP2X+Ru84JR1jMw/uWqqpmcLXS1i9W1dQ q/sQsb4611Zez6EYB2uzJPC5IxlKeZyFmVUcLZohCLCCQZvsfBPaMVBexmdAJSg3WFcR Q3YsqarzcfARh+ib2BmDJeDDdF3YM6YhMhEjDRi/QPWJP3RjquoENfAFxw/Gg2uxLwoT 689COsxY6EJhlrMtcJeWxt+hsK6Bwo5vOYf5zZvPfmy01+xksbLFsqKdsm+yvKhUnCtD LzAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701913323; x=1702518123; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=nBxHn8pPY9Z5FdN+k7OtNFF2y23J51ZbRWvqj66+tuw=; b=wvO8bpWIuHrjKPXCQQ13X9T4/u5Vxh5ujOzFO1v7lYx2y6JBaewJvTLPmvmSlBEEvU j3avv2D0JNq7SMW42sWz9DHry7piBFRo1+HLTFX7aZFDHnPySlqpZjfX9s7FsSgatpnf +3PevbHvyXM1BhFB6FWdwDtf2y8DMjN8fT7AhJPGltKQ3Avim9Pp937DY3MCCqBxqOz5 YglYgxX8RqLTXH61QLvm1FOlVO/UH4qwWzY55+GS7WeEha0ttU9FptgLeJhQb4MZV92/ Uc6vw2C2wBDv9Y38DTBZCMLqCTWX0xMxe16nx/7Y3EstKcp2K8YhTJq6kFMxpFQYtCuM +t0Q== X-Gm-Message-State: AOJu0YyelVIc50MdZgIL4qKjnfqTNk+T9blcgoaKe4sHWN2Qre5wX4/3 PzUXIiwLNHH05eoZTY0o+w== X-Google-Smtp-Source: AGHT+IECfDKy7qgVt3DrtWqB9mGaRcUWA9H3+6hbTsNc/qT/L9gIimJny/ajs2jYtZClp70dFsBvWQ== X-Received: by 2002:a05:6808:3023:b0:3b8:9906:c267 with SMTP id ay35-20020a056808302300b003b89906c267mr2182417oib.56.1701913323558; Wed, 06 Dec 2023 17:42:03 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id d16-20020a05680813d000b003b9d00ce109sm57795oiw.34.2023.12.06.17.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 17:42:02 -0800 (PST) Received: from dell1.minyard.net (unknown [IPv6:2001:470:b8f6:1b:8ff4:f8fd:ca3:53c6]) by serve.minyard.net (Postfix) with ESMTPA id 78CA51800C6; Thu, 7 Dec 2023 01:42:02 +0000 (UTC) From: minyard@acm.org To: qemu-devel@nongnu.org Cc: Potin Lai , Patrick Venture , Hao Wu , Titus Rwantare , Corey Minyard Subject: [PULL 2/2] hw/i2c: add pca9543 i2c-mux switch Date: Wed, 6 Dec 2023 19:41:48 -0600 Message-Id: <20231207014148.3116889-3-minyard@acm.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231207014148.3116889-1-minyard@acm.org> References: <20231207014148.3116889-1-minyard@acm.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::234; envelope-from=tcminyard@gmail.com; helo=mail-oi1-x234.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Potin Lai Add pca9543 2-channel i2c-mux switch support. Signed-off-by: Potin Lai Reviewed-by: Patrick Venture Message-Id: <20231113063156.2264941-1-potin.lai.pt@gmail.com> Signed-off-by: Corey Minyard --- hw/i2c/i2c_mux_pca954x.c | 12 ++++++++++++ include/hw/i2c/i2c_mux_pca954x.h | 1 + 2 files changed, 13 insertions(+) diff --git a/hw/i2c/i2c_mux_pca954x.c b/hw/i2c/i2c_mux_pca954x.c index db5db956a6..6aace0fc47 100644 --- a/hw/i2c/i2c_mux_pca954x.c +++ b/hw/i2c/i2c_mux_pca954x.c @@ -30,6 +30,7 @@ #define PCA9548_CHANNEL_COUNT 8 #define PCA9546_CHANNEL_COUNT 4 +#define PCA9543_CHANNEL_COUNT 2 /* * struct Pca954xState - The pca954x state object. @@ -172,6 +173,12 @@ I2CBus *pca954x_i2c_get_bus(I2CSlave *mux, uint8_t channel) return pca954x->bus[channel]; } +static void pca9543_class_init(ObjectClass *klass, void *data) +{ + Pca954xClass *s = PCA954X_CLASS(klass); + s->nchans = PCA9543_CHANNEL_COUNT; +} + static void pca9546_class_init(ObjectClass *klass, void *data) { Pca954xClass *s = PCA954X_CLASS(klass); @@ -246,6 +253,11 @@ static const TypeInfo pca954x_info[] = { .class_init = pca954x_class_init, .abstract = true, }, + { + .name = TYPE_PCA9543, + .parent = TYPE_PCA954X, + .class_init = pca9543_class_init, + }, { .name = TYPE_PCA9546, .parent = TYPE_PCA954X, diff --git a/include/hw/i2c/i2c_mux_pca954x.h b/include/hw/i2c/i2c_mux_pca954x.h index 3dd25ec983..1da5508ed5 100644 --- a/include/hw/i2c/i2c_mux_pca954x.h +++ b/include/hw/i2c/i2c_mux_pca954x.h @@ -3,6 +3,7 @@ #include "hw/i2c/i2c.h" +#define TYPE_PCA9543 "pca9543" #define TYPE_PCA9546 "pca9546" #define TYPE_PCA9548 "pca9548"