From patchwork Fri Sep 6 15:49:08 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: 825999 Delivered-To: patch@linaro.org Received: by 2002:adf:a345:0:b0:367:895a:4699 with SMTP id d5csp872915wrb; Fri, 6 Sep 2024 08:50:17 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWq0GI02g32WP/Lp3tQkqXluHR8zNkj2c2SfQUFO4X9uWe/+Fx1FAiYfZOnnUHd8NhReXW/jA==@linaro.org X-Google-Smtp-Source: AGHT+IFWiqJRT06ovvE39mQJ3cKoYZ8FrSKqHQIU25VLoeMiKnXg0E2eSyPZSpjQHXpWntssTovq X-Received: by 2002:ac8:7dc7:0:b0:453:7706:75b1 with SMTP id d75a77b69052e-4580c6705a3mr27610731cf.5.1725637816825; Fri, 06 Sep 2024 08:50:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725637816; cv=none; d=google.com; s=arc-20240605; b=awKpidOkMC9KkvIAZhANDVfyZh7AhVCU0x2Ouh0mholXpWob00aKH7aCprK+RBnKr8 /6NwVHfjz2uTQy7zrSvJmrs643bJUeEz2lAPVplKMYLFJ6SVW/PfxI7ABThcsNoh9bf/ 9PaFCdrYyKin4H8/IDFX7OHL8STZRNr93g2Ui0b3mTC57jzERAX1JqnDM23E/1tF6EnV p4aUSRoRiNzBXjrltsYxAXKTqTWTh7ui+3pBv4/NI19RzBBnOVGX2A9Pg4RDRBoHG4eJ Fp26NSAO4objZnYgvB4J5+k1pu3/pwsOeZmY2kUYiGmPK29igeRAjv6yQXI92+JQ6yl5 yeLw== 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:cc:to :from:dkim-signature; bh=TW+gKU0Fbu3XeokU7+BEDwC7NasKVljAZ5Retp9xJ60=; fh=47msMfzOjBGiKb3INv90kT6VVtfGm4mbiwj44lYpN5M=; b=DYWysikrtycCrZYkxypHlUKvZyY1MCAaFpCiivQyIZm3ohIg6sZQ0IjG5NpLZuiAt/ dQn0d2a6J/ic5QCWTrEstIEL9C6ZbhG0zSeb7qGllDQ3KqqR7K4hs6uiCjLsecmUKD7c SiXiMkuuKDHoyKnSvmho6H8Tr2BSHBUa606Xb8oxBvgm6zFAcAD7hp4RhLRlh42iq7zE xLCs1E9Jm5GhJnlmRcMTuTovjF+9syu7Vjm5R6LIerUMUcEqJ7vcN5hLyElAIPPfES57 09iMYbDvAVz5e0UGlVdZ6qrUGuFAkKl8JJ15TCR4sxs9Ihg9COr2pns662DaqTdsN++w veyw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TeaYyO3F; 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-4581d3ae806si4420861cf.42.2024.09.06.08.50.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 06 Sep 2024 08:50:16 -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=TeaYyO3F; 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 1smbDF-0008IJ-1S; Fri, 06 Sep 2024 11:49:29 -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 1smbDE-0008Hl-8q for qemu-devel@nongnu.org; Fri, 06 Sep 2024 11:49:28 -0400 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1smbDC-0008Av-Jf for qemu-devel@nongnu.org; Fri, 06 Sep 2024 11:49:28 -0400 Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-a89c8db505bso300447366b.0 for ; Fri, 06 Sep 2024 08:49:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725637765; x=1726242565; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TW+gKU0Fbu3XeokU7+BEDwC7NasKVljAZ5Retp9xJ60=; b=TeaYyO3Fpw34pVk3kE7HRDM8do4Fpwx4UCQ6BJnCIdQtmHZx3eKB/px8GINs5qYGlJ 5T5puCYFVWgxt3GM0ws+0d/DAqK9C/AVIL5KSncibP5IDNSXU8H0VXa2sLK/U7m2nN/M Gh36vhLC3DL7wNogIUXSgIJNwUoYWGRrx0JKB0jdIaQKAocSl4ioWTA4DbJwTsoWoOCU SbNfgt+xdclTJWPwaX3HKa647yrmb94p8F5hJvmBN0ZHHLrEl0AEAV/V0gtFrRHCQpX0 qxlmG2xltLSHfodwHPwm+EuqudvNaIsl9E164ymjHBl9jEyKX4ZxM70daZAyoHdR8NkA S4xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725637765; x=1726242565; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TW+gKU0Fbu3XeokU7+BEDwC7NasKVljAZ5Retp9xJ60=; b=PzsLBc5oJHnQt0FVXujXSZ4JJesTg692IDFMPpMrxUjsHaInh4i9/PzqZgCCRXEBvb KsAlSWS0/wj7+WzQmf/yXPC2uRTzNroVHnSg60v0kBgmWse4cDKVP9RGJnNGWpkDTqKI mHt974fulv6Lk/jk3FtIJqUkgzpxDxh2CS2KZtVrhWU0w0fBX5MVBQOJHRMq0dA3WubB kbQVLiyvTiSPl4D7x1afTzsZsfGnqvUpc6FNIKVzCco4KdkOmsP/AOaamqtjRZ4wPBKv 423IhAq7giJHOYqgs3jpAgjWC31mmrGT8mi0D20qLZPEsR6+juwL4YL+b4Hf/RCsc5SU akZQ== X-Forwarded-Encrypted: i=1; AJvYcCUzHHb+DR8bWr3MVLreambaB1sAD08n7/2ufzJwAJstGQwmgaHlyr7E9RPcQgAKmN+3XTlNDUZc9Vpv@nongnu.org X-Gm-Message-State: AOJu0YxzA8yuVbpJZ7dVvoeFToERa1Eel/3YpHyc9XdHFo526hZVEGZd n15Iwz+YMtDLjsfgCxaKN4NruAhUD4hGQqhG1JbjtScOyrrkG/R+51aQu8aUmNs= X-Received: by 2002:a17:907:ea4:b0:a86:99e9:ffa1 with SMTP id a640c23a62f3a-a8a888f11a7mr237329666b.64.1725637764786; Fri, 06 Sep 2024 08:49:24 -0700 (PDT) Received: from localhost.localdomain (225.13.23.93.rev.sfr.net. [93.23.13.225]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8a6236d16fsm292217866b.99.2024.09.06.08.49.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 06 Sep 2024 08:49:24 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Guenter Roeck , qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PATCH v2 2/5] hw/sensor/tmp105: Use registerfields API Date: Fri, 6 Sep 2024 17:49:08 +0200 Message-ID: <20240906154911.86803-3-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240906154911.86803-1-philmd@linaro.org> References: <20240906154911.86803-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62d; envelope-from=philmd@linaro.org; helo=mail-ej1-x62d.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, T_SCC_BODY_TEXT_LINE=-0.01 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 --- 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;