From nobody Sun Feb 8 14:12:16 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=1641511307; cv=none; d=zohomail.com; s=zohoarc; b=asOuhepQMElhqerQFAj+tT8CL8n0M2qumDpwzYLxD8wuhdMdWAGsZPZN5ZVUBExy2OqDhRB95DJ1W3W3hZrE5r6EViukmGbrzB3JG6cIkmcWw/kuFmJYHvojn24vA+ennkdNZCNFnmjjN9oE+MPyQKbBPGvStn8CtbhUK5EePso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641511307; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YbOjq3KDlppshwQpezVsb9MS/E9NuLAoax6A9T70OSQ=; b=YJZg5+M5hauaGPgLc7o0Ypfz8WLYFZd/Y8hCJAIqmkXQfNSPbI7EoTJrXE0/c4+n+tkDzaZquEtIseHpV6DZD+MDWYMKE7pf1Ga7T2LhizLQi8QEUivruTB/ZveEfsQllGzgEY6tkwwpMpAoT+Dr+kZ5Q+1Tw4upnPpIff8vo40= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16415113070281007.1000613192173; Thu, 6 Jan 2022 15:21:47 -0800 (PST) Received: from localhost ([::1]:49554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n5c4n-0000UC-Ro for importer@patchew.org; Thu, 06 Jan 2022 18:21:45 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34542) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3wXbXYQYKCiIRGRSQPEMMEJC.AMKOCKS-BCTCJLMLELS.MPE@flex--titusr.bounces.google.com>) id 1n5bz5-0001eN-U9 for qemu-devel@nongnu.org; Thu, 06 Jan 2022 18:15:51 -0500 Received: from [2607:f8b0:4864:20::b49] (port=39921 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 <3wXbXYQYKCiIRGRSQPEMMEJC.AMKOCKS-BCTCJLMLELS.MPE@flex--titusr.bounces.google.com>) id 1n5bz3-00063F-DZ for qemu-devel@nongnu.org; Thu, 06 Jan 2022 18:15:51 -0500 Received: by mail-yb1-xb49.google.com with SMTP id k130-20020a255688000000b0060c3dcae580so7956338ybb.6 for ; Thu, 06 Jan 2022 15:15:42 -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=YbOjq3KDlppshwQpezVsb9MS/E9NuLAoax6A9T70OSQ=; b=jc5cDr3OREYGEfR5CAaIq3QBrJAl5cWO28XpM4lxNWwQTw+Vy5PYSvXqYX7fbyR52I cWdZw7lCXIzVmaR2kLc9kX3i8yWnJamLHHV5/8s6vmwIsgVWJ1Sd7rNLwBahvgaF+uAm 8F0g8NAgCBNirvUzrv1DmaU4c8uFzPuOqQC4/fzeG3d7rC5uVspPnVB56ERcpk9Guqzf D91DfkF4xaWqWYogM4WySnXvT3PJscbIPOhwUqj1RYVCT4q4MrBX4okH4sZO003fj5Yo qFXCirB6STaz2fazj+eSJohIlFSs1ErdykfB7zsFFUg9EvKeDTgmP7jSgpS331hxLUZV AWDA== 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=YbOjq3KDlppshwQpezVsb9MS/E9NuLAoax6A9T70OSQ=; b=250FTKkMeUHDW5LaZRCSY3nNwgaz+6MNgf3jAxwkehjS+VgV0jwp1Vqhx3Wh92pxEy 04w0gou4XvG+/twOgRR1KzooMLrBgtI5XodG7bMXoQpmv1Ye2lLs6igPxfy4A/0N8Sks BCf6dvg2WRhV8qUG+u95qcMly0XpWnrm6Nbu96afcDX2R8ileHhT834Wo2mVO+tMm1ok Q2I5J/exKnZxSFch2937KQ1pgqGHsHuSOeVV9Z8PL/JFh6U+pd0ZvdXUn4kFTn3K3eNA /YaXHlfphtTSkC3WcAtGoq6bJh7nSEbZKZ3JT2yYvqe9Rf2SRYVvlP+RwHHfiBgnhMVS Rwbw== X-Gm-Message-State: AOAM530wuPetcNSN5lYQMIlngxfRQQAgho0xsxnUIz7aeZjyh3Hg+SPK Q2RBukpMX+L/u6yYmZR85odoXneFm0E= X-Google-Smtp-Source: ABdhPJzAV57Kj61O/DbrIucBNN+T7qurrRe4G/dVtQ76CJfWPi+gbgX5PWIcLuIGXI2nxqpSRCICyUMWRsk= X-Received: from titusr.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:22b8]) (user=titusr job=sendgmr) by 2002:a5b:386:: with SMTP id k6mr32905947ybp.706.1641510593947; Thu, 06 Jan 2022 15:09:53 -0800 (PST) Date: Thu, 6 Jan 2022 23:09:33 +0000 In-Reply-To: <20220106230936.417020-1-titusr@google.com> Message-Id: <20220106230936.417020-3-titusr@google.com> Mime-Version: 1.0 References: <20220106230936.417020-1-titusr@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH 2/5] hw/i2c: Added linear mode translation for pmbus devices From: Titus Rwantare To: f4bug@amsat.org, minyard@acm.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, venture@google.com, Shengtan Mao , Titus Rwantare X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::b49 (failed) Received-SPF: pass (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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::b49; envelope-from=3wXbXYQYKCiIRGRSQPEMMEJC.AMKOCKS-BCTCJLMLELS.MPE@flex--titusr.bounces.google.com; helo=mail-yb1-xb49.google.com X-Spam_score_int: -87 X-Spam_score: -8.8 X-Spam_bar: -------- X-Spam_report: (-8.8 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1641511309691100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Shengtan Mao Signed-off-by: Shengtan Mao Reviewed-by: Titus Rwantare Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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, uin= t16_t value) return x; } =20 +uint16_t pmbus_data2linear_mode(uint16_t value, int exp) +{ + /* L =3D D * 2^(-e) */ + if (exp < 0) { + return value << (-exp); + } + return value >> exp; +} + +uint16_t pmbus_linear_mode2data(uint16_t value, int exp) +{ + /* D =3D 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 =3D (m * x - b) * 10^R * - * @return uint32_t + * @return uint16_t */ uint16_t pmbus_data2direct_mode(PMBusCoefficients c, uint32_t value); =20 @@ -459,6 +459,24 @@ uint16_t pmbus_data2direct_mode(PMBusCoefficients c, u= int32_t value); */ uint32_t pmbus_direct_mode2data(PMBusCoefficients c, uint16_t value); =20 +/** + * Convert sensor values to linear mode format + * + * L =3D D * 2^(-e) + * + * @return uint16 + */ +uint16_t pmbus_data2linear_mode(uint16_t value, int exp); + +/** + * Convert linear mode formatted data into sensor reading + * + * D =3D 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, --=20 2.34.1.448.ga2b2bfdf31-goog