From nobody Sun Jul 26 10:59:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1783378916; cv=none; d=zohomail.com; s=zohoarc; b=ErDbu5WLeEWia7Y0OgOOH2aUc6CuIPqA/UkI1BdhObkMvn2Rmue3fYOT0ml0P1mmjQILLWvXi2UwLMxcy06FduMx5H8ztyx/mJ1x0YKrhXZwZRrT+GytBSdO2fC0/fBnz8xzucy9ce1qmoNiLU1FT3d5ifmatesytZ3UiCk1QQo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783378916; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=J+qpsqU8VhBrKTgqKD73tYWfvmDVFPfz1aysCbRxf74=; b=WMCIijAuT/C3TGncymuqODFybE8/RQEXN1z5tfI2minqPMWiE3Ql7IHTsvl1QX5xq82XS1iXXX8XAIu+PYlzKRgBpl5YmFbEtqbfvB9cjeB5yox0oF7LYixs+kRR9yU3kxsxE+0wWGvi7IbBjt9LEc8xq2M1HWtrhQgiHjcwCsU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783378916092701.7198753143795; Mon, 6 Jul 2026 16:01:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgsJF-0001PT-2T; Mon, 06 Jul 2026 19:01:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3rDNMagYKCp0QFQRPODLLDIB.9LJNBJR-ABSBIKLKDKR.LOD@flex--titusr.bounces.google.com>) id 1wgsJD-0001Op-Nm for qemu-devel@nongnu.org; Mon, 06 Jul 2026 19:01:03 -0400 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3rDNMagYKCp0QFQRPODLLDIB.9LJNBJR-ABSBIKLKDKR.LOD@flex--titusr.bounces.google.com>) id 1wgsJC-00073H-Ah for qemu-devel@nongnu.org; Mon, 06 Jul 2026 19:01:03 -0400 Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-c894391f000so8880887a12.1 for ; Mon, 06 Jul 2026 16:01:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783378861; x=1783983661; darn=nongnu.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=J+qpsqU8VhBrKTgqKD73tYWfvmDVFPfz1aysCbRxf74=; b=IRDA5c2saCCeTkgQ3qS8lb8oZmmy1LAwCV9YaZF8tqZB5wF/IgfKaVmGwwv/DlJOpW Y2O9siG0iJtAs0VYLux2/cDHMH2GXwwqZ8RMxCyQ2MStfIPRzZ+KLP2RlGzkDFtwC0XT XP9u9sGm0F2g2pcpAg29BqJOuD3n8bacgSC9efPBYxbpz7Qqd8sq3Oj4rWooE7mtCtTx G8QMQr23eND2CvNs6T8FtgRJtkATMKbi4A86JzmVRutUGs+goLB8yP3m/tVC/gCS3SpX LyAOAW52NAXcgXViHo4VwQcReofJRt80DEjMYGb/La8ZOVUp1qZNJJZu2j9pVbVtndpP ra8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783378861; x=1783983661; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=J+qpsqU8VhBrKTgqKD73tYWfvmDVFPfz1aysCbRxf74=; b=lG+iy9+l2wQhoYNqY7/gvl4xjssu7bzrWrRqG1I3HnvKkXFhNCY6UcWhAtwKqrqOgi ISqHj9pKgBTJbZ74eIP+FADXdhaZ585wURh0bTmnyU2l072ZFirbbOSjCBvj2r9o3c51 MLQ2ZvXV/iOlsM9Xq5TEzhiZtA4+xfsIkKnqDj0sGrwU4oBA6PyTszloVy4vn89QEA95 ed9m6mXwcrldsVt8J+HW8/p7j8fZ7OVletgDAcD1MLZ3BsVKEqYg7SkXGlicIuHHE0nn 4q0Vh+RJAZayO/L708NJH6p8+Gzt0dQz/JWZvvH/EyimaVG7J6VQXV7sHlOw1X2m57qw shnQ== X-Forwarded-Encrypted: i=1; AHgh+RoCf3LAeNm7jythiQuUYztwL62Bzq3nnt3XiVAMRpO6h91ta5N6bppQFZ1c1X3C3o3XoHVTcAsbQTwb@nongnu.org X-Gm-Message-State: AOJu0YxEK3axooJ19xDjArR8W7/QHJMzgsnYUC57PPWPcVp8+sdOZOG+ vmVRBuM0DAwzCqU0AqTI+MBdg1IEATNqkVjMeT5gO+3USpy/qTtdCK/cGktNytPQ7YWcAC6Q+8h yV9hIMA== X-Received: from dlbqy20.prod.google.com ([2002:a05:7022:ef14:b0:139:ad69:296f]) (user=titusr job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:684:b0:3b5:6b5a:4f29 with SMTP id adf61e73a8af0-3c08ee38980mr2865681637.30.1783378860644; Mon, 06 Jul 2026 16:01:00 -0700 (PDT) Date: Mon, 6 Jul 2026 23:00:50 +0000 In-Reply-To: <20260706230056.1888992-1-titusr@google.com> Mime-Version: 1.0 References: <20260706230056.1888992-1-titusr@google.com> X-Mailer: git-send-email 2.55.0.rc2.803.g1fd1e6609c-goog Message-ID: <20260706230056.1888992-2-titusr@google.com> Subject: [PATCH 1/5] osdep: add DIV_ROUND_CLOSEST From: Titus Rwantare To: peter.maydell@linaro.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, kfting@nuvoton.com, imaginos32@gmail.com, wuhaotsh@google.com, philmd@mailo.com, Titus Rwantare Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::54a; envelope-from=3rDNMagYKCp0QFQRPODLLDIB.9LJNBJR-ABSBIKLKDKR.LOD@flex--titusr.bounces.google.com; helo=mail-pg1-x54a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1783378917199158500 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This is taken from linux/include/uapi/linux/const.h to match the driver behaviour when reading sensor values. Signed-off-by: Titus Rwantare --- include/qemu/osdep.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 1ec5b42230..a6a40ab8df 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -522,6 +522,20 @@ void QEMU_ERROR("code path is reachable") #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) #endif =20 +#ifndef DIV_ROUND_CLOSEST +#define DIV_ROUND_CLOSEST(n, d) \ +({ \ + typeof(n) __n =3D n; \ + typeof(d) __d =3D d; \ + (((typeof(n))-1) > 0 || \ + ((typeof(d))-1) > 0 || \ + (((__n) > 0) =3D=3D ((__d) > 0))) ? \ + (((__n) + ((__d) / 2)) / (__d)) : \ + (((__n) - ((__d) / 2)) / (__d)); \ +}) +#endif + + /* * &(x)[0] is always a pointer - if it's same type as x then the argument = is a * pointer, not an array. --=20 2.55.0.rc2.803.g1fd1e6609c-goog From nobody Sun Jul 26 10:59:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1783378915; cv=none; d=zohomail.com; s=zohoarc; b=irxE8hfb53CmK42C0CpqWLHfmaz5pfMoh9cDxIrB+PPWOF9ZvNESoE6lVtftGVT+tO1LtAf1sMlqqo6yXVqmPloxq9KB+NMhU3FeGPCLYwX0C/0a5V8eozTFiGKMdpkJyJuO7vP9HJmbxx58jvqcfum1IZLfWoAQjWpWcIn8k0U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783378915; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=m/PAM6KHxAEnovgWt0N1vdKaX4s46SRBVL3bS+2xlns=; b=IEM+jll3YuspB6jJFx680SYSxJEvGzItiqnMRJy1lh6y+gnAXBPuhRcmcC1Yk++nkiDNH0MKsynAJ+kcpQLS7owp92qq84Z6oTyYHkjBq5zQ+TgW7Y90n0EM3JtqV4DghmGVTw/h4HookkMIxITuSdCzNiIkl7FV4hyXYbp0raU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783378915881285.0682688164213; Mon, 6 Jul 2026 16:01:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgsJG-0001Rf-N3; Mon, 06 Jul 2026 19:01:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3rTNMagYKCp4RGRSQPEMMEJC.AMKOCKS-BCTCJLMLELS.MPE@flex--titusr.bounces.google.com>) id 1wgsJF-0001Ph-5q for qemu-devel@nongnu.org; Mon, 06 Jul 2026 19:01:05 -0400 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3rTNMagYKCp4RGRSQPEMMEJC.AMKOCKS-BCTCJLMLELS.MPE@flex--titusr.bounces.google.com>) id 1wgsJD-00073a-9m for qemu-devel@nongnu.org; Mon, 06 Jul 2026 19:01:04 -0400 Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-c88da04b719so2819398a12.2 for ; Mon, 06 Jul 2026 16:01:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783378862; x=1783983662; darn=nongnu.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=m/PAM6KHxAEnovgWt0N1vdKaX4s46SRBVL3bS+2xlns=; b=JEpexdLTMkjmI5n6r+gYDB+r2I7PC+tZzis/chga2Z0GlNM1yxj8MRjD6R5OKDM99s lpMPzKfEAPynuRiQKbXclAK7Rd0ACIyTDXhM5Rz77nZPwmd2B7aF1AGBQEIIN+EGzdry ZZIH81ISCwm2+hANOLtqqsW3m+U0sOmhrfQM3n1eNkQYlYUAe2xFYtPtKZAKXAUCyCpP IIrxBlEtSa9a95IyKQBMar6adb2KYw04UuKScmIMqS132eOK0+k4ooRo6nF9pkUqjFCl bYkRFWiPGl/IRpjGp5WCn88V16GEXZOok6eMQ0YByzpZd0d6FpDczaqDsTOZEJn8FP1r VZ1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783378862; x=1783983662; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=m/PAM6KHxAEnovgWt0N1vdKaX4s46SRBVL3bS+2xlns=; b=jXddYRFbxzoBfbJuO9Gs91OdL2roqOZrQDqxizsb5HAylDpb3/F37V/pjZMFqemi+8 b3MGk7CNEk/heRcw+UEzLNfHVRdPAFJm+rlM+4N8nzeuC/lgJlk/Tqt8kiBvbC+lrA+L VcM3YtTkj0wDu6wZT6l/kaF6Pf8kHw0n0M0dRjqfL2aAqfJ0UPmpYW0e9dU6LL/gBI0b 2FYPTS20R+nSKFoCLn8Kn1pCzfeaZyyitOvwi4paeX/gxMQ7DqMlMZ13qSXJbJFxI7e6 gtZnLAi/eE3X9YyjY1dXDJZsOWVRe6Bor6UHX5a1EIe8YERXZa+RUQv5coKINs1H1stu amKA== X-Forwarded-Encrypted: i=1; AHgh+RoDidOlXSBGaikNNPiyDtopZrWzjbp4C5YS5NYj4B2UQmYTIRoU4llDIzUO+BMf3POKjbQ7cK6J9SnN@nongnu.org X-Gm-Message-State: AOJu0YwSG16vdFIGPTEmPjswT4ICnl7tFeRiFNZyxM9NWG8+GhaLhvLq RHNWklLvyVEs//JpgwZqTp3Pen+eN3ImQ/rfAl3yLjMufdcPu0kWxdsqPZQj63p6S/TBykPieFy /fxpsvw== X-Received: from dyaz13-n2.prod.google.com ([2002:a05:693c:638d:20b0:30f:1818:9ce5]) (user=titusr job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:b94:b0:3c0:9c19:b272 with SMTP id adf61e73a8af0-3c09c19b393mr159280637.64.1783378861604; Mon, 06 Jul 2026 16:01:01 -0700 (PDT) Date: Mon, 6 Jul 2026 23:00:51 +0000 In-Reply-To: <20260706230056.1888992-1-titusr@google.com> Mime-Version: 1.0 References: <20260706230056.1888992-1-titusr@google.com> X-Mailer: git-send-email 2.55.0.rc2.803.g1fd1e6609c-goog Message-ID: <20260706230056.1888992-3-titusr@google.com> Subject: [PATCH 2/5] hw/i2c: pmbus: add milliunits linear mode functions From: Titus Rwantare To: peter.maydell@linaro.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, kfting@nuvoton.com, imaginos32@gmail.com, wuhaotsh@google.com, philmd@mailo.com, Titus Rwantare Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::54a; envelope-from=3rTNMagYKCp4RGRSQPEMMEJC.AMKOCKS-BCTCJLMLELS.MPE@flex--titusr.bounces.google.com; helo=mail-pg1-x54a.google.com X-Spam_score_int: -94 X-Spam_score: -9.5 X-Spam_bar: --------- X-Spam_report: (-9.5 / 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, FUZZY_MILLION=0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1783378917192158500 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Because we are limited by unsigned ints, we need to be able to provide inputs in milliunits which can get scaled up to fit in the linear mode registers. For example: 3.4 is a valid input, and now we can provide 3400 and scale it into the register without losing the 0.4 Signed-off-by: Titus Rwantare --- hw/i2c/pmbus_device.c | 39 +++++++++++++++++++++++++++++++++++ include/hw/i2c/pmbus_device.h | 18 ++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/hw/i2c/pmbus_device.c b/hw/i2c/pmbus_device.c index b1f9843f52..e2e1e0e945 100644 --- a/hw/i2c/pmbus_device.c +++ b/hw/i2c/pmbus_device.c @@ -8,6 +8,7 @@ =20 #include "qemu/osdep.h" #include +#include #include "hw/i2c/pmbus_device.h" #include "migration/vmstate.h" #include "qemu/module.h" @@ -38,6 +39,25 @@ uint16_t pmbus_data2linear_mode(uint16_t value, int exp) return value >> exp; } =20 +uint16_t pmbus_milliunits2linear_mode(uint32_t value, int exp) +{ + uint32_t ret; + + /* L =3D D * 2^(-e) */ + if (exp < 0) { + ret =3D DIV_ROUND_CLOSEST((value << (-exp)), 1000); + } else { + ret =3D DIV_ROUND_CLOSEST((value >> exp), 1000); + } + + /* clamp value to maximum if it exceeds representable value*/ + if (ret > UINT16_MAX) { + return UINT16_MAX; + } + + return ret; +} + uint16_t pmbus_linear_mode2data(uint16_t value, int exp) { /* D =3D L * 2^e */ @@ -47,6 +67,25 @@ uint16_t pmbus_linear_mode2data(uint16_t value, int exp) return value << exp; } =20 +uint32_t pmbus_linear_mode2milliunits(uint16_t value, int exp) +{ + /* D =3D L * 2^e */ + uint64_t v =3D (uint64_t)value; + uint64_t ret; + + if (exp < 0) { + ret =3D (v * 1000) >> (-exp); + } else { + ret =3D (v << exp) * 1000; + } + + if (ret > UINT32_MAX) { + return UINT32_MAX; + } + + return (uint32_t)ret; +} + 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 f195c11384..9f3569e997 100644 --- a/include/hw/i2c/pmbus_device.h +++ b/include/hw/i2c/pmbus_device.h @@ -481,6 +481,15 @@ uint32_t pmbus_direct_mode2data(PMBusCoefficients c, u= int16_t value); */ uint16_t pmbus_data2linear_mode(uint16_t value, int exp); =20 +/** + * Convert milliunit sensor value to linear mode format + * + * L =3D D * 2^(-e) + * + * @return uint16 + */ +uint16_t pmbus_milliunits2linear_mode(uint32_t value, int exp); + /** * Convert linear mode formatted data into sensor reading * @@ -490,6 +499,15 @@ uint16_t pmbus_data2linear_mode(uint16_t value, int ex= p); */ uint16_t pmbus_linear_mode2data(uint16_t value, int exp); =20 +/** + * Convert linear mode formatted data into sensor reading in milliunits + * + * D =3D L * 2^e + * + * @return uint32 value in milliunits + */ +uint32_t pmbus_linear_mode2milliunits(uint16_t value, int exp); + /** * @brief Send a block of data over PMBus * Assumes that the bytes in the block are already ordered correctly, --=20 2.55.0.rc2.803.g1fd1e6609c-goog From nobody Sun Jul 26 10:59:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1783378946; cv=none; d=zohomail.com; s=zohoarc; b=f9iFSavOz+FBEID7km8AK/A62/ilPPrwvGXvJSHTearqzFq//TsuwD5+w7dbcgzT+a0hdvhQw2ts8nNhC53SqtQChrsgvz9CtRfCnWsC6DArGmcLTXBZ6Rn5Zdj/WO3LJ2bBsGuzGYiZAuwDW/hwM4TUxLOdJdGKQSZINWFj92Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783378946; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hW0rGKNwKHNOYrweI11OJbXK2kFKxm3bSkURBVVUrfQ=; b=gyILA/EeTBwR9SRiZP2UoIJzfcGdNL8QghHdRDHmHsyEPGijrBsSDsdslGFFWiJqc5i0+za2xAMJX/x6EMz1vblIJ96/X83VpP7lm8xOfnzDvRsge4+WQk1UZTD9t5aw8OcEy8hTz+Q0NQ7VbXmmX7YAmGxhtnH/s24Xuen/VtM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783378946387101.37949989684296; Mon, 6 Jul 2026 16:02:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgsJH-0001SN-Ie; Mon, 06 Jul 2026 19:01:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3rjNMagYKCp8SHSTRQFNNFKD.BNLPDLT-CDUDKMNMFMT.NQF@flex--titusr.bounces.google.com>) id 1wgsJG-0001RL-HA for qemu-devel@nongnu.org; Mon, 06 Jul 2026 19:01:06 -0400 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3rjNMagYKCp8SHSTRQFNNFKD.BNLPDLT-CDUDKMNMFMT.NQF@flex--titusr.bounces.google.com>) id 1wgsJF-00073l-0o for qemu-devel@nongnu.org; Mon, 06 Jul 2026 19:01:06 -0400 Received: by mail-pj1-x104a.google.com with SMTP id 98e67ed59e1d1-38108fb9d83so2366332a91.2 for ; Mon, 06 Jul 2026 16:01:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783378863; x=1783983663; darn=nongnu.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=hW0rGKNwKHNOYrweI11OJbXK2kFKxm3bSkURBVVUrfQ=; b=TDf4fBvJPbNsq8fotjUQp+M93mQTBSurmNbQniiyX0Z3U+KJ5ib+hcWUO1z9iauRjh nLTq7UV0ZgBr7qJBI1JhJUkW75jd4R3X22BeJe1TRhKH9bddU99RnDHL49NM+MEv7NRR cUiMe5H/K1hYzRnrYPsMCqA7OaRxB4aRyxepYZPOh06eCxMf6oDOSdPIlAWssCQcSuy3 hL4V5FPUxQdZD6ol4zpJKNm4LYK++CqF+TJt5YeuDEKIa//CwxGG9Ar+w6p6wG8p4dOX nsvVSXS21zxX5rnYjEBYQeVpGhPRzps7C68CODaIYGpg0mMtVhznR4uFl07QFID1qRcG DGIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783378863; x=1783983663; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=hW0rGKNwKHNOYrweI11OJbXK2kFKxm3bSkURBVVUrfQ=; b=sA5O7jV4ICO0Ufb62JUK2EL0kOU6UwsJZW3KowRUqSohi3oVIY2RXXpTCtfJjX/XOb TS+PAjVsSmlZeCWzYCQV3NFS8HAWGrCi+dWjgAcY95poZLcl6YXpAh/1+8K8z4OfqqqD 8YceArUUnKVFjfmcbHtN7v3lqxztdD+8pdGA3K9pnWvwgCpTvxBv1BjTV4gvtoVcsbV3 i7izor3s1fs6K65PgOHwEB4j99NNoj9YyIPJN2XWi5C/nIKuhJ/TXgfw9G6foUx8jmaj tURRmP0GSbOnomh7W8x+/tWSP9Ls8AYAWNv4Hv20yVJT3Lq5xTb2ZzH2oA1bm3KgJKfk nUJg== X-Forwarded-Encrypted: i=1; AHgh+Rom0+yBXgObb2jUk/QhTx7nHjhmsjT+qKF5JY0UpGTmqIKYJdJ5nKMZ6EaOFEpmbXK6fqU/uw8h3YYA@nongnu.org X-Gm-Message-State: AOJu0Yx3HtUrfgT+zdI6CeIDF+FFieI67cdUfZCYaTn+a0ymiNfSJLuT 5+PYtVWSnp9wm0TAfnz5vDFxqFr9Pw0PiJcipP1UtgkLio7KeMZAsbzdcusGdC17kIEg/MVc74N 4N7A0lA== X-Received: from dycui10.prod.google.com ([2002:a05:693c:600a:b0:311:525b:8fc9]) (user=titusr job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:562c:b0:37e:2005:6507 with SMTP id 98e67ed59e1d1-38755d3f07bmr2642826a91.15.1783378862518; Mon, 06 Jul 2026 16:01:02 -0700 (PDT) Date: Mon, 6 Jul 2026 23:00:52 +0000 In-Reply-To: <20260706230056.1888992-1-titusr@google.com> Mime-Version: 1.0 References: <20260706230056.1888992-1-titusr@google.com> X-Mailer: git-send-email 2.55.0.rc2.803.g1fd1e6609c-goog Message-ID: <20260706230056.1888992-4-titusr@google.com> Subject: [PATCH 3/5] hw/i2c: pmbus: clear output buffer on write From: Titus Rwantare To: peter.maydell@linaro.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, kfting@nuvoton.com, imaginos32@gmail.com, wuhaotsh@google.com, philmd@mailo.com, titusr Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::104a; envelope-from=3rjNMagYKCp8SHSTRQFNNFKD.BNLPDLT-CDUDKMNMFMT.NQF@flex--titusr.bounces.google.com; helo=mail-pj1-x104a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1783378949308158500 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: titusr Generally we expect a PMBus sensor to issue writes after all pending reads have completed. If a data read needs to be resumed, this state can be tracked in the device model and the pending data placed in the output buffer. Signed-off-by: Titus Rwantare Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/i2c/pmbus_device.c | 10 ++++++++++ tests/qtest/adm1266-test.c | 10 ++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/hw/i2c/pmbus_device.c b/hw/i2c/pmbus_device.c index e2e1e0e945..8befc27895 100644 --- a/hw/i2c/pmbus_device.c +++ b/hw/i2c/pmbus_device.c @@ -1284,6 +1284,16 @@ static int pmbus_write_data(SMBusDevice *smd, uint8_= t *buf, uint8_t len) pmdev->in_buf_len =3D len; pmdev->in_buf =3D buf; =20 + /* clear the output buffer on any new write transaction */ + if (pmdev->out_buf_len !=3D 0) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: previous read was not completed, %d bytes dropp= ed\n", + __func__, pmdev->out_buf_len); + + pmdev->out_buf_len =3D 0; + memset(pmdev->out_buf, 0, sizeof(pmdev->out_buf)); + } + pmdev->code =3D buf[0]; /* PMBus command code */ =20 if (pmdev->code =3D=3D PMBUS_CLEAR_FAULTS) { diff --git a/tests/qtest/adm1266-test.c b/tests/qtest/adm1266-test.c index 5ae8206234..726e475938 100644 --- a/tests/qtest/adm1266-test.c +++ b/tests/qtest/adm1266-test.c @@ -48,11 +48,13 @@ static void compare_string(QI2CDevice *i2cdev, uint8_t reg, const char *test_str) { - uint8_t len =3D i2c_get8(i2cdev, reg); - char i2c_str[SMBUS_DATA_MAX_LEN] =3D {0}; + uint8_t expected_len =3D strlen(test_str); + uint8_t resp[SMBUS_DATA_MAX_LEN] =3D {0}; =20 - i2c_read_block(i2cdev, reg, (uint8_t *)i2c_str, len); - g_assert_cmpstr(i2c_str, =3D=3D, test_str); + g_assert(expected_len + 1 < SMBUS_DATA_MAX_LEN); + i2c_read_block(i2cdev, reg, resp, expected_len + 1); + g_assert_cmpint(resp[0], =3D=3D, expected_len); + g_assert_cmpstr((char *)resp + 1, =3D=3D, test_str); } =20 static void write_and_compare_string(QI2CDevice *i2cdev, uint8_t reg, --=20 2.55.0.rc2.803.g1fd1e6609c-goog From nobody Sun Jul 26 10:59:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1783378915; cv=none; d=zohomail.com; s=zohoarc; b=Z4PRrVfdpcNi5brL5WN9w7a/rro8AzP+Dh1LhsvMtTAAFwGDL/+KdgAtfjgtHiKXU5w8imjsH0S2bcIQuPXMlT/CwoZvaE6shQq5m3wQ/5lbCWyttemZ+e+uYAWwCllZA60lX2AE6sLsfqM9VYBo2L1L0ygcUphwP/Fmhd9UMHg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783378915; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6fU0aRx9V9/Af1UMElRogGHAdUuCSDaABAHFfvVjCok=; b=RaNCS3zxJxpig0kYwI0cT6EmeKMfSAkmClj5E5msGyszYNfv3hzMYkKExRIcrt8mZfBGlXeL7d0DVtW8bUjIfeIx2C3DaYwh2oSgNg5DPMtbWOdn68H9Andzwcckzvxm/Xvbx0UO5Jj/pIsurw5uxXnpvpS5hR94uSx1xaSq5+w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783378915733552.219828505499; Mon, 6 Jul 2026 16:01:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgsJJ-0001Tb-2l; Mon, 06 Jul 2026 19:01:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3rzNMagYKCqATITUSRGOOGLE.COMQEMU-DEVELNONGNU.ORG@flex--titusr.bounces.google.com>) id 1wgsJH-0001SA-7O for qemu-devel@nongnu.org; Mon, 06 Jul 2026 19:01:07 -0400 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3rzNMagYKCqATITUSRGOOGLE.COMQEMU-DEVELNONGNU.ORG@flex--titusr.bounces.google.com>) id 1wgsJF-000746-E3 for qemu-devel@nongnu.org; Mon, 06 Jul 2026 19:01:06 -0400 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-c860544c077so9783845a12.3 for ; Mon, 06 Jul 2026 16:01:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783378864; x=1783983664; darn=nongnu.org; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=6fU0aRx9V9/Af1UMElRogGHAdUuCSDaABAHFfvVjCok=; b=RXTeyjJAb/QcY/5DhSxT8F4TmzZNhx9AgsZFUpNrHdAGfUE0n6LtooNIjAnM+6m/o8 4mFw3wZ+0GH7Va7cGfA3qo2U6lhmRwasJIftDwIZyOjg7LR90Wr0eB1Mfya7Oyrv7lVX uwxwDRdY5jQeA/XgutAWKM57ZqviGah5n0hwmYdi/bSW2fffpHhs+HY8EoogqbPQoq+S YDq2rY10tjNqCz/53gjkhY7WsAKNur7pMBpnZm5zUjr3jJVdAlxEpRM97QS/QIWxiUJv LikJqEpuZ7rakMQQ3hlwRgh2PDRXa1WI0/y0Eyn68QQW+dOCwkR5g0Le20USSoybdpuY GCZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783378864; x=1783983664; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=6fU0aRx9V9/Af1UMElRogGHAdUuCSDaABAHFfvVjCok=; b=EhGcMiH4J12HedbWOHtIAxx7AdOl2eOo4AxaUwG5uWMEPgVcdP4dcAs8MQMPevVg8w Dj3NyKm6qH8HT3u1EA98wjnPjJmJxD41gjeiI5DkCX+mpmPpe92ge/FTer7+BXCyRInn ApEMkZVPhtn3zKEDraOp45zxrVqPHPgEwXefFJgsWOQ6axKhZIbyGKLN+8Xnc/xHJ4u2 aFlIeML6SeKQrsdYCuJmkrlNats48jU7rpO0Ur7kIu81Au/Y+VfB4j6GWMt2pLHiX9Sp S1HkJtCSYe99goEE1oZTFaovVswb3miNeYYD7QsVqf7xp3nr1fgjIyThw4Z6HYUZb83i ZhNg== X-Forwarded-Encrypted: i=1; AHgh+RopEtUE30yPa6lGAFWP1hTyspnXqBRd5+Rw/Cuh2b78scoYK38jDoNK6EPNUJD5OX85N3itrNmoHJZP@nongnu.org X-Gm-Message-State: AOJu0Yy1kIeizX/OsXUPWuiCC7QNhGCLQV8rquFiC6EEVQNJMqfDMzJc d1QUAjGwXaeTw98apW4yd+VFMPNbzgfgzXRmQ+P/XVbEG/4eV+92LXJHIVkBeG977Rk+pcYdG5B dLPXVbA== X-Received: from dybhh38.prod.google.com ([2002:a05:7301:2926:b0:30f:1d9a:8ad6]) (user=titusr job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:a94:b0:3bf:49c8:f63 with SMTP id adf61e73a8af0-3c08ee392edmr3310349637.37.1783378863541; Mon, 06 Jul 2026 16:01:03 -0700 (PDT) Date: Mon, 6 Jul 2026 23:00:53 +0000 In-Reply-To: <20260706230056.1888992-1-titusr@google.com> Mime-Version: 1.0 References: <20260706230056.1888992-1-titusr@google.com> X-Mailer: git-send-email 2.55.0.rc2.803.g1fd1e6609c-goog Message-ID: <20260706230056.1888992-5-titusr@google.com> Subject: [PATCH 4/5] hw/i2c: smbus: increase MAX_DATA_LEN From: Titus Rwantare To: peter.maydell@linaro.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, kfting@nuvoton.com, imaginos32@gmail.com, wuhaotsh@google.com, philmd@mailo.com, titusr Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::549; envelope-from=3rzNMagYKCqATITUSRGOOGLE.COMQEMU-DEVELNONGNU.ORG@flex--titusr.bounces.google.com; helo=mail-pg1-x549.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1783378917214158500 Content-Type: text/plain; charset="utf-8" From: titusr The 32 byte payload was raised to 255 for block reads in the SMBus 3.0 specification. SMBus does not provide a way for devices to declare which version of the spec they are designed to so we must allow newer devices to return as much data as they allow. Specification: https://smbus.org/specs/SMBus_3_3_20240512.pdf > 6.5.7 Block Write/Read The Block Write begins with a slave address and a write condition. After th= e command code the host issues a byte count which describes how many more b= ytes will follow in the message. If a slave has 20 bytes to send, the byte = count field will have the value 20 (14h), followed by the 20 bytes of data.= The byte count does not include the PEC byte. The byte count may be 0. A B= lock Read or Block Write is allowed to transfer a maximum of 255 data bytes. Signed-off-by: Titus Rwantare Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/i2c/smbus_slave.c | 4 ++-- include/hw/i2c/smbus_slave.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/i2c/smbus_slave.c b/hw/i2c/smbus_slave.c index cfb61c879e..407a118d24 100644 --- a/hw/i2c/smbus_slave.c +++ b/hw/i2c/smbus_slave.c @@ -217,8 +217,8 @@ bool smbus_vmstate_needed(SMBusDevice *dev) =20 const VMStateDescription vmstate_smbus_device =3D { .name =3D TYPE_SMBUS_DEVICE, - .version_id =3D 1, - .minimum_version_id =3D 1, + .version_id =3D 2, + .minimum_version_id =3D 2, .fields =3D (const VMStateField[]) { VMSTATE_I2C_SLAVE(i2c, SMBusDevice), VMSTATE_INT32(mode, SMBusDevice), diff --git a/include/hw/i2c/smbus_slave.h b/include/hw/i2c/smbus_slave.h index 86bfe0a79e..59522ff1b1 100644 --- a/include/hw/i2c/smbus_slave.h +++ b/include/hw/i2c/smbus_slave.h @@ -64,7 +64,7 @@ struct SMBusDeviceClass { uint8_t (*receive_byte)(SMBusDevice *dev); }; =20 -#define SMBUS_DATA_MAX_LEN 34 /* command + len + 32 bytes of data. */ +#define SMBUS_DATA_MAX_LEN 257 /* command + len + 255 bytes of data. */ =20 struct SMBusDevice { /* The SMBus protocol is implemented on top of I2C. */ --=20 2.55.0.rc2.803.g1fd1e6609c-goog From nobody Sun Jul 26 10:59:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1783378921; cv=none; d=zohomail.com; s=zohoarc; b=V6/+PzfFulRsK5RoAdAh8IuTgAyf7TvjHIEnzA8eSWakq+EpgKn85OEUBlXbF2DiiUzXJH23HKy5JrdNmNQ+vA2t5/2mGba5GCZArjL2N8gu9VFI886nmhOU/3A/vT7wXBmTr/vSdSa/qjssFj0tYXhjMzDhSPfOHyvD8m7up2A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783378921; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OLTxskLBXDENLFyN1dtTBrLCPkP5BiKim3I9wu6aM8I=; b=f1kcgIHIXDk1j9hrHbx0aU6sJ5QR3gpgt9Bua0PHZc7j3qQFScdTOzHVCxJoNesJWLcUevuSGaP1Yu05I1I01mVnFV9U35YB6rodG9XBbXU/98y8pRXXqSu4pJo1/5Dcirx63E8Utl7J0rHg81FrP2ixHF7EktNoARlu5XiAn/U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783378921642546.3009011092446; Mon, 6 Jul 2026 16:02:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wgsJK-0001Uo-F0; Mon, 06 Jul 2026 19:01:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3sDNMagYKCqEUJUVTSHPPHMF.DPNRFNV-EFWFMOPOHOV.PSH@flex--titusr.bounces.google.com>) id 1wgsJI-0001Sr-Fu for qemu-devel@nongnu.org; Mon, 06 Jul 2026 19:01:08 -0400 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3sDNMagYKCqEUJUVTSHPPHMF.DPNRFNV-EFWFMOPOHOV.PSH@flex--titusr.bounces.google.com>) id 1wgsJG-00074Z-V8 for qemu-devel@nongnu.org; Mon, 06 Jul 2026 19:01:08 -0400 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-c891ed872ddso5608860a12.2 for ; Mon, 06 Jul 2026 16:01:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783378865; x=1783983665; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=OLTxskLBXDENLFyN1dtTBrLCPkP5BiKim3I9wu6aM8I=; b=eK8IDoXn2tYfArPwudUQm3xcm2eekmsquiVXnBrkHpbk2+sMQ3OxOEVs2saQXHzg7y PO88NxajZYJ1idE6tslnBd/26k3UmKMH6XXiGGwuDe11V6raPTRCuiJPv+dFmRr1z7cn xCCjXBDIlnqgVW3mIg6Pm2YqdRc0vdUyWIuC+jZk+PXCwOpeOjc2L3Him7+5P112vf6+ N9KH6Mg2ZWnpWJoSER6bqKBvyOs2MX1LkcUeWlRGfpJHtUS33mk8J3dFP9xsELe9doNw Vepofy11j899W9Vo2Ya43OdArXOx9Mhk9xdAlwGrpHw6RR9QobMI/ImPEj29n54DFzsn kx8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783378865; x=1783983665; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OLTxskLBXDENLFyN1dtTBrLCPkP5BiKim3I9wu6aM8I=; b=XU1r7LppgxgaTc+lGULBU8C0u/UBSG/xbtSeVI0YMu9wGZhMSM/O5WfjObwo/WEliU jJ6D4pM9cEfp8vm7stIXINNfVa2+MTcrS+WYmN2GoPzkQtFNmEtXnpJyOPjafstbaET/ eT3CcDEYhmfGdb/wEwlGHekBL1OWG779paZepbeUTXCOl5SJ5As35c7KwWa3mpkl9fQM xrLxsn4VXLmSjyYK+RoCxvo0MVTlxY9sgcUmK8IEwyQBNuvkKPa5IM08W/BGxh+Z5dL+ J30+AKXtwenvxOySYgpG7KTESlLiXfLhlOjSxtkrs6NuJM9KRNVPlbSHc6V/cSuB4ew+ seyQ== X-Forwarded-Encrypted: i=1; AHgh+RoGIB7Ydp2pqRuUPXg6ySYorsXZ5y/zhCIleL1DztjUkI4mPKUaFxd52wu335PZCzfhmzPi9vmFAysR@nongnu.org X-Gm-Message-State: AOJu0YwzoGfyfNkyj9cIQtU1bkSD6tI/H+rfQZibyWxjphUQEMRugJPJ 06dVNJm8nGkD1jQLlKseKifWEAf5VZTSVmScJZn1LstV48qBZU2XHWvOF/9waMb14Vt5DpWXhhJ oGRROhA== X-Received: from dlea16-n1.prod.google.com ([2002:a05:701b:4210:10b0:13b:3fa1:5d80]) (user=titusr job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:7116:b0:3bf:e291:496c with SMTP id adf61e73a8af0-3c08edb1d45mr3167471637.17.1783378864356; Mon, 06 Jul 2026 16:01:04 -0700 (PDT) Date: Mon, 6 Jul 2026 23:00:54 +0000 In-Reply-To: <20260706230056.1888992-1-titusr@google.com> Mime-Version: 1.0 References: <20260706230056.1888992-1-titusr@google.com> X-Mailer: git-send-email 2.55.0.rc2.803.g1fd1e6609c-goog Message-ID: <20260706230056.1888992-6-titusr@google.com> Subject: [PATCH 5/5] hw/i2c: pmbus: add Linear11 format helpers From: Titus Rwantare To: peter.maydell@linaro.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, kfting@nuvoton.com, imaginos32@gmail.com, wuhaotsh@google.com, philmd@mailo.com, Titus Rwantare Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::549; envelope-from=3sDNMagYKCqEUJUVTSHPPHMF.DPNRFNV-EFWFMOPOHOV.PSH@flex--titusr.bounces.google.com; helo=mail-pg1-x549.google.com X-Spam_score_int: -94 X-Spam_score: -9.5 X-Spam_bar: --------- X-Spam_report: (-9.5 / 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, FUZZY_MILLION=0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1783378922750158500 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Titus Rwantare --- hw/i2c/pmbus_device.c | 12 +++++++++ include/hw/i2c/pmbus_device.h | 46 +++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/hw/i2c/pmbus_device.c b/hw/i2c/pmbus_device.c index 8befc27895..5039975520 100644 --- a/hw/i2c/pmbus_device.c +++ b/hw/i2c/pmbus_device.c @@ -39,6 +39,12 @@ uint16_t pmbus_data2linear_mode(uint16_t value, int exp) return value >> exp; } =20 +uint16_t pmbus_data2linear11(uint16_t value, int exp) +{ + return (uint16_t)((exp & 0x1F) << 11 | + (pmbus_data2linear_mode(value, exp) & 0x7FF)); +} + uint16_t pmbus_milliunits2linear_mode(uint32_t value, int exp) { uint32_t ret; @@ -58,6 +64,12 @@ uint16_t pmbus_milliunits2linear_mode(uint32_t value, in= t exp) return ret; } =20 +uint16_t pmbus_milliunits2linear11(uint32_t value, int exp) +{ + return (uint16_t)((exp & 0x1F) << 11 | + (pmbus_milliunits2linear_mode(value, exp) & 0x7FF)); +} + uint16_t pmbus_linear_mode2data(uint16_t value, int exp) { /* D =3D L * 2^e */ diff --git a/include/hw/i2c/pmbus_device.h b/include/hw/i2c/pmbus_device.h index 9f3569e997..44cd908fe7 100644 --- a/include/hw/i2c/pmbus_device.h +++ b/include/hw/i2c/pmbus_device.h @@ -477,10 +477,56 @@ uint32_t pmbus_direct_mode2data(PMBusCoefficients c, = uint16_t value); * * L =3D D * 2^(-e) * + * Exponent is retrieved from VOUT_MODE register + * + * 7 6 5 4 3 2 1 0 + * +---+---+---+---+---+---+---+---+ + * | 0 | 0 | 0 | N | + * +---+---+---+---+---+---+---+---+ + * |_______| |_______________| + * Mode Exponent (N) + * =3D 000b + * * @return uint16 */ uint16_t pmbus_data2linear_mode(uint16_t value, int exp); =20 +/** + * Convert sensor values to linear11 format + * + * L =3D e << 11 | D * 2^(-e) + * + * | Data Byte High | Data Byte Low | + * +---+---+---+---+---+ +---+---+---+---+---+---+---+---+---+---+---+ + * | 7 | 6 | 5 | 4 | 3 | | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | + * +---+---+---+---+---+ +---+---+---+---+---+---+---+---+---+---+---+ + * | MSB | | MSB | + * |_________ _________| |_____________________ _____________________| + * N Y + * Exponent Mantissa + * + * @return uint16 + */ +uint16_t pmbus_data2linear11(uint16_t value, int exp); + +/** + * Convert sensor values in milliunits to linear11 format + * + * L =3D e << 11 | D * 2^(-e) + * + * | Data Byte High | Data Byte Low | + * +---+---+---+---+---+ +---+---+---+---+---+---+---+---+---+---+---+ + * | 7 | 6 | 5 | 4 | 3 | | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | + * +---+---+---+---+---+ +---+---+---+---+---+---+---+---+---+---+---+ + * | MSB | | MSB | + * |_________ _________| |_____________________ _____________________| + * N Y + * Exponent Mantissa + * + * @return uint16 + */ +uint16_t pmbus_milliunits2linear11(uint32_t value, int exp); + /** * Convert milliunit sensor value to linear mode format * --=20 2.55.0.rc2.803.g1fd1e6609c-goog