From patchwork Thu Sep 12 06:52:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 827778 Delivered-To: patch@linaro.org Received: by 2002:adf:ab1c:0:b0:367:895a:4699 with SMTP id q28csp1127658wrc; Wed, 11 Sep 2024 23:53:10 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVHJtPS52ksN/tASt+eHcjDeKXBoyh079hZLjuTyFSn03o3djlckL8pFB7REm/n1EWD4Gdi/Q==@linaro.org X-Google-Smtp-Source: AGHT+IGVaDjfawIqXw/84GUJM+EJH8ZNiZTIzD805j7M9Vu9mb4MyBrVW6JfCOmnP0WF/TIYxZWx X-Received: by 2002:ac8:5a8e:0:b0:458:34ee:3a62 with SMTP id d75a77b69052e-458602bbc3fmr24927191cf.7.1726123989931; Wed, 11 Sep 2024 23:53:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726123989; cv=none; d=google.com; s=arc-20240605; b=TKNGbcwOqJzgljAAe89F3xmAyiuwQ2IL4wH07IwFF6l9edlCzGoRY0El7wlJU4PVz5 hUxHrIfPkI37FeuabS/oe9xDC0eTWHe7IWt0mt/KqENl64cI5YyCqtp1wLxJ/yadqXXC ECwRZ7M57cwsrLSnJbmVGDLLlKdEkZeyU7NDkoxyMZcsymVFOwIV34MdW2rqgJJMF1Kr LSUbS4QNyBz8gHYFmVTRTVndX6MsLJN68r6xnzlZHB6mQN+oLm9d9NjrabJwlW34nhOd A/U5PpR5vFoGpI6t6LowDz+fVJSOPYHpC5sRhlJXGfSc1uXv5JA6T7Ul+Q5BExsI6tF0 akqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Botq1S9eMbImFvY+BTnSLblpWc6KEMCJ0flPbOePxcU=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=NAmAyB0KVWkppanoVc3dRd7cKCjGez5bvVH7ez3b8rfTIsMECZUBsmdwIy/dk+PCRy SeX1Lp7VfsTWEvKmqzfUChWn5AKQzc/P99ZvNwTVUo1nZ8gVkgEnitShyQVmGH0GJW13 RMmxMsN8af9npvi8YfmN3g8kIdT1qTzaOKUOgBjyKr9j0i5wyP8vG04I94oX1v+Pp9an 0ai+BNEupBRAGHFsS3q3spv+oBHMK2nHDarGh3eR9WJpYaxwgVeg7KjHcMRPMVzl85Y9 JkhOMFvor57G0eb/HS3m9vSHNC2cnSAETZrlPLto44sY1lV2rjbGoGMCcYlG9ZJJUJv1 3qRQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ITyET9NG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-45822f3eaebsi118170031cf.371.2024.09.11.23.53.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Sep 2024 23:53:09 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ITyET9NG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sodhA-00047S-M3; Thu, 12 Sep 2024 02:52:48 -0400 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 1sodh8-00046Z-Uc for qemu-devel@nongnu.org; Thu, 12 Sep 2024 02:52:47 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sodh6-0003Pz-J3 for qemu-devel@nongnu.org; Thu, 12 Sep 2024 02:52:46 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-42cb0f28bfbso4675265e9.1 for ; Wed, 11 Sep 2024 23:52:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726123963; x=1726728763; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Botq1S9eMbImFvY+BTnSLblpWc6KEMCJ0flPbOePxcU=; b=ITyET9NG1v9LS/5ZY7GOKpj7YqwZoB9F+ijElH/w3l9vtJDT4fn8Veg3p2A6B0fBqI 9MFvQgZ1DPFuuY99QscwjYwjy1oc7JH4FY5cbTgc6ykSWAjBVVGlU63YvW3byrFb9lo1 WTyabpuIsufL7pzSYLRaqHRXQwu0oP3f9RjH6LspV7tSPrnIReLuADzZ+f/mvKSeB5Ig /5+F5g9NTHDiEiWLMM19Gkc8x9YL1Pn/ERHtxLxY5d1ohqLeWSnDWUJtXCd6bNzElRDY U5dE3fj+XUTuqOdKyQz4bJ+vwLb8YZWu4rqd60ll3ft9t41Lo8KyQeg+KCSjp4l22XTb r5Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726123963; x=1726728763; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Botq1S9eMbImFvY+BTnSLblpWc6KEMCJ0flPbOePxcU=; b=oEmrAvWzy0NawNYMwrpiS9u+PdC9SA/z9u0Ryf3rv3BUIsNr7z5JEPbzPxnp9w/ete BjGKQveAGA6Evj/jKEbDFpkxCiPV/r3/EhzP+CUWnUh5c/WKGOjvGXuYGGhfVsnA185q LT0O5YiGkkCAd1Lo0cPl3N9/G5O6qB857vSolzUk7hkq6PocniwK/hMLFOQfBUmy1vt4 iC/+3gHFGgqqilBSArD1jmEo3g4M1N7BlFJ/cQ/xAswwKIqcOAmlGj7oYpsvsGQzGF9N 00Y5H5eq044KaZmB+q5ER+ldPpGX5HV/bR6LA4cI6rJvEq+ehyKqrKVcn9dBtSeNxzms OE2A== X-Gm-Message-State: AOJu0YwU7SB16plYLhOF5K9zjf1N+UVN+hNi1BlwtYGZehJ23aU4Lh18 y/5L0fj+tzcJGVmWpXYtmc/C2duPVdywCM66c8aIOsz6BrA/K9lhKtB99ylzpbSPT3yP/CS311Q c X-Received: by 2002:a05:600c:4e10:b0:42b:a9b4:3f59 with SMTP id 5b1f17b1804b1-42cdb529b15mr13640265e9.14.1726123962664; Wed, 11 Sep 2024 23:52:42 -0700 (PDT) Received: from m1x-phil.lan (mic92-h03-176-184-33-210.dsl.sta.abo.bbox.fr. [176.184.33.210]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956d363asm13523896f8f.72.2024.09.11.23.52.41 for (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 11 Sep 2024 23:52:42 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL v2 45/61] hw/sensor/tmp105: Use registerfields API Date: Thu, 12 Sep 2024 08:52:16 +0200 Message-ID: <20240912065227.67848-3-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240912065227.67848-1-philmd@linaro.org> References: <20240912065227.67848-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=philmd@linaro.org; helo=mail-wm1-x32d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, 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 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org To improve readability, use the registerfields API. Define the register bits with FIELD(), and use the FIELD_EX8() and FIELD_DP8() macros. Remove the abbreviations in comments. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Guenter Roeck Message-Id: <20240906154911.86803-3-philmd@linaro.org> --- hw/sensor/tmp105.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/hw/sensor/tmp105.c b/hw/sensor/tmp105.c index ad97c9684c..150d09b278 100644 --- a/hw/sensor/tmp105.c +++ b/hw/sensor/tmp105.c @@ -26,23 +26,31 @@ #include "qapi/error.h" #include "qapi/visitor.h" #include "qemu/module.h" +#include "hw/registerfields.h" + +FIELD(CONFIG, SHUTDOWN_MODE, 0, 1) +FIELD(CONFIG, THERMOSTAT_MODE, 1, 1) +FIELD(CONFIG, POLARITY, 2, 1) +FIELD(CONFIG, FAULT_QUEUE, 3, 2) +FIELD(CONFIG, CONVERTER_RESOLUTION, 5, 2) +FIELD(CONFIG, ONE_SHOT, 7, 1) static void tmp105_interrupt_update(TMP105State *s) { - qemu_set_irq(s->pin, s->alarm ^ ((~s->config >> 2) & 1)); /* POL */ + qemu_set_irq(s->pin, s->alarm ^ FIELD_EX8(~s->config, CONFIG, POLARITY)); } static void tmp105_alarm_update(TMP105State *s) { - if ((s->config >> 0) & 1) { /* SD */ - if ((s->config >> 7) & 1) { /* OS */ - s->config &= ~(1 << 7); /* OS */ + if (FIELD_EX8(s->config, CONFIG, SHUTDOWN_MODE)) { + if (FIELD_EX8(s->config, CONFIG, ONE_SHOT)) { + s->config = FIELD_DP8(s->config, CONFIG, ONE_SHOT, 0); } else { return; } } - if (s->config >> 1 & 1) { + if (FIELD_EX8(s->config, CONFIG, THERMOSTAT_MODE)) { /* * TM == 1 : Interrupt mode. We signal Alert when the * temperature rises above T_high, and expect the guest to clear @@ -120,7 +128,7 @@ static void tmp105_read(TMP105State *s) { s->len = 0; - if ((s->config >> 1) & 1) { /* TM */ + if (FIELD_EX8(s->config, CONFIG, THERMOSTAT_MODE)) { s->alarm = 0; tmp105_interrupt_update(s); } @@ -129,7 +137,7 @@ static void tmp105_read(TMP105State *s) case TMP105_REG_TEMPERATURE: s->buf[s->len++] = (((uint16_t) s->temperature) >> 8); s->buf[s->len++] = (((uint16_t) s->temperature) >> 0) & - (0xf0 << ((~s->config >> 5) & 3)); /* R */ + (0xf0 << (FIELD_EX8(~s->config, CONFIG, CONVERTER_RESOLUTION))); break; case TMP105_REG_CONFIG: @@ -155,11 +163,11 @@ static void tmp105_write(TMP105State *s) break; case TMP105_REG_CONFIG: - if (s->buf[0] & ~s->config & (1 << 0)) { /* SD */ + if (FIELD_EX8(s->buf[0] & ~s->config, CONFIG, SHUTDOWN_MODE)) { printf("%s: TMP105 shutdown\n", __func__); } s->config = s->buf[0]; - s->faults = tmp105_faultq[(s->config >> 3) & 3]; /* F */ + s->faults = tmp105_faultq[FIELD_EX8(s->config, CONFIG, FAULT_QUEUE)]; tmp105_alarm_update(s); break; @@ -219,7 +227,7 @@ static int tmp105_post_load(void *opaque, int version_id) { TMP105State *s = opaque; - s->faults = tmp105_faultq[(s->config >> 3) & 3]; /* F */ + s->faults = tmp105_faultq[FIELD_EX8(s->config, CONFIG, FAULT_QUEUE)]; tmp105_interrupt_update(s); return 0; @@ -277,7 +285,7 @@ static void tmp105_reset(I2CSlave *i2c) s->temperature = 0; s->pointer = 0; s->config = 0; - s->faults = tmp105_faultq[(s->config >> 3) & 3]; + s->faults = tmp105_faultq[FIELD_EX8(s->config, CONFIG, FAULT_QUEUE)]; s->alarm = 0; s->detect_falling = false;