From nobody Tue May 7 15:09:08 2024 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=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1605020803; cv=none; d=zohomail.com; s=zohoarc; b=Klda5JkeNDztKhWVoNg9oH/eYIHmYbmrNDOnlLKkLLzDxxAsOk/d8I0Bewb86W508j8m7DdU7/UgRCnokM2DT6toEfER+HFH+Bwaf2fa4s8beE7IEKRHFRVGshxYlHeD6K+I3hR0VNXwUx41Ri92cv4sjoMY/ZtIFGWPlT4Wmr4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605020803; h=Content-Transfer-Encoding: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=PzT+Q/TmIovSxDPhfcAm2zUohAaZWdsY+cDjFWvAtVo=; b=HgBzTVBP/ZLBwYSciXpwPeMi+0D3VI1+IV8i0ouK0UQbbyLsJVNF7nnlXdRTuU6ltAnlGF2muc+k0b20SppeXUQ6GoMBhBZxqonbpEIpXSJ1U05sLWXzgT4Yup+NVCK/mccsVbPwuRjYFSBrKnIf5OZtdKi+FU5dIQqkcZ/TRH4= 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=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1605020803923288.7924719943644; Tue, 10 Nov 2020 07:06:43 -0800 (PST) Received: from localhost ([::1]:60556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcVEI-0006fz-Hj for importer@patchew.org; Tue, 10 Nov 2020 10:06:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcV8Y-0002TV-FY for qemu-devel@nongnu.org; Tue, 10 Nov 2020 10:00:46 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:34348) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kcV8J-0007Lv-1Y for qemu-devel@nongnu.org; Tue, 10 Nov 2020 10:00:45 -0500 Received: by mail-wr1-x442.google.com with SMTP id r17so9063850wrw.1 for ; Tue, 10 Nov 2020 07:00:28 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id o205sm3392493wma.25.2020.11.10.07.00.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 07:00:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=PzT+Q/TmIovSxDPhfcAm2zUohAaZWdsY+cDjFWvAtVo=; b=Y02zd7xt7BlRlU2cvgzFE0RD+ubHQQKG9RKwOM8q6Z5ijD2gyJWS1TPn2xCZfTI74Q qkeRhMXWi3zd14/gCwRzQw9xPpd+Xtn8sh//lI211F0oAmTZr1tRNwFCLEtYji2psCMD Gtw0Se0itM7va9NaSq3HJpLlK64u5tMo0ZmKes0061uRiCwkyN9T14ACmA6YaMpKiJ3O eoDgvumZipby6SQBu4aJULjQtsZQtEYnbI2zyXcO6dVFUXD0aKzuIzmHT5tepvZUT+EF JT3VRKmInS3fhQPJNHhgX7V60IzLUED/DW4PcY3NUTDKkgNfVC4i2kWq/2D+/U4AwyFO N/8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PzT+Q/TmIovSxDPhfcAm2zUohAaZWdsY+cDjFWvAtVo=; b=kB2CFa7FIo1/wKnD9fDktVChWa/BPZwhD/qr/3gv6fyk2lF1NRmGmLxQuIKrKTyf32 EC8Tla29oV7VlTuyaKXSV7Zd5WwwPS7wsHHmkzsLC9v0hLV9PE/geUz+zB735NvAAK3M OU+OlG32DOgfQqAfdWJ8dt77iWc/hu7GwxOfg3Ag+7uuLqbq+lDRBYWCzSWVkZhZC7Lw Fh7Smt/qhENVl6Rli7Vq90DUCKke5FILWre7RHXRVwORwKTsnJ1sj4BMmAeRkO5o9o50 AckbVAvh5rhB8TzNekn29eIVETZwZ+QrKaXbK0WrYm2essvyiXJAmBd+C02B/Ivsr6kE uoTw== X-Gm-Message-State: AOAM531+NWORoxBgxJtxSxBT95c+RgvIQqd1xJVEzjaHsbPve1rrfWik UW/1tfk4NsYyVh7ncESfDRWdK9xY5ymOCA== X-Google-Smtp-Source: ABdhPJxQn34kVqIJnrQGtdLHSZ0jxx17Ztq1n1fIlPxOZWWDKk/KiilkvRRcQKbCtkYhkB7AkcpUzQ== X-Received: by 2002:a5d:488b:: with SMTP id g11mr9733422wrq.210.1605020427547; Tue, 10 Nov 2020 07:00:27 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 1/2] hw/misc/tmp105: reset the T_low and T_High registers Date: Tue, 10 Nov 2020 15:00:22 +0000 Message-Id: <20201110150023.25533-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201110150023.25533-1-peter.maydell@linaro.org> References: <20201110150023.25533-1-peter.maydell@linaro.org> MIME-Version: 1.0 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=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::442; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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 @linaro.org) Content-Type: text/plain; charset="utf-8" The TMP105 datasheet (https://www.ti.com/lit/gpn/tmp105) says that the power-up reset values for the T_low and T_high registers are 80 degrees C and 75 degrees C, which are 0x500 and 0x4B0 hex according to table 5. These values are then shifted right by four bits to give the register reset values, since both registers store the 12 bits of temperature data in bits [15..4] of a 16 bit register. We were resetting these registers to zero, which is problematic for Linux guests which enable the alert interrupt and then immediately take an unexpected overtemperature alert because the current temperature is above freezing... Signed-off-by: Peter Maydell Reviewed-by: C=C3=A9dric Le Goater --- hw/misc/tmp105.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/misc/tmp105.c b/hw/misc/tmp105.c index b47120492a..0a4aad4854 100644 --- a/hw/misc/tmp105.c +++ b/hw/misc/tmp105.c @@ -225,6 +225,9 @@ static void tmp105_reset(I2CSlave *i2c) s->faults =3D tmp105_faultq[(s->config >> 3) & 3]; s->alarm =3D 0; =20 + s->limit[0] =3D 0x4b00; /* T_LOW, 75 degrees C */ + s->limit[1] =3D 0x5000; /* T_HIGH, 80 degrees C */ + tmp105_interrupt_update(s); } =20 --=20 2.20.1 From nobody Tue May 7 15:09:08 2024 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=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1605020627; cv=none; d=zohomail.com; s=zohoarc; b=c7BZeQwNFebbFaD9mE7s/1z38tpA11gNcyikjil+fxHn01jnX3Gp++X9ChkPVwrwg5xzvwx4ud7GR/3zM9MnWo9obOlaXoyz4Ukv8znHwCcU4XMYaEcfpNzp632pXywlh1QtgatbzEZDLm/XDKlfDcvSjc5zRtfA4jkRWF8oo70= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605020627; h=Content-Transfer-Encoding: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=+8VBpOq5IPiyukv1r/cJV6FOcSBdmxIoPOlZnr/6lsM=; b=GK/5/mG1HnGA6l2o/zXsnNcNKfrPuEhjx1/KQQWizh6tyja5GH0y/n+I0a46kUMI79V16FGRPT9eiZg7LXANUSbqe0wnyXuKqVY7986wjDiKGH4lcs+K/mp/bI4IvUAlFF7GWH5XXKxI105VkRdybxRCBviHFBdRBY7L6/lsyL0= 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=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1605020627272405.29993585864554; Tue, 10 Nov 2020 07:03:47 -0800 (PST) Received: from localhost ([::1]:54802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcVBR-0004C0-2u for importer@patchew.org; Tue, 10 Nov 2020 10:03:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43690) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcV8W-0002Qb-SD for qemu-devel@nongnu.org; Tue, 10 Nov 2020 10:00:44 -0500 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:44667) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kcV8I-0007Mw-UA for qemu-devel@nongnu.org; Tue, 10 Nov 2020 10:00:44 -0500 Received: by mail-wr1-x42c.google.com with SMTP id c17so12974483wrc.11 for ; Tue, 10 Nov 2020 07:00:29 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id o205sm3392493wma.25.2020.11.10.07.00.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 07:00:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=+8VBpOq5IPiyukv1r/cJV6FOcSBdmxIoPOlZnr/6lsM=; b=zQNVnTP0FVAdicV+y0OfuGzREC3bqKzlccYfz5aCC/5r64auh+sU0C9ocKktYPNqBD TuTGtV0Q00jNPV+EnIZybj5BnRkyVoXwOjMsIfKrFehybGDER5qVr2G76kkS3rqS9wF9 c1HvaSxNLk5g6C/XPuGuil+QqsZcK6srH0HBEYldmLDD4u3HpzlRdUOLOFMRZiTE80Ac 1w8ciGN57ZE+xPRgQ2AVMU5K0/WxYLmgdWCZUlYRVNFW37tdXJY/IruUCd0wYZBsT5ql +UMQbIma8nn4nQhXOS43ZOZPkntKuUmwZxNQCcugnT6nXFyVGn3mD27Kaj2LiJj0/wvV zuKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+8VBpOq5IPiyukv1r/cJV6FOcSBdmxIoPOlZnr/6lsM=; b=eDo8zRtNprV4zXHAMyRXO//vmPKhp758c5mPD+VW2qPI1xWPFwqIvWyNbKF2Yyn8wV 4vMNyTg3NHXZAjmqMZHPPKIh85qvKrZWK/VrnW3Z8LJ+LTl5OajVr4rQ10tnjx+WaWrI v38zuUmFVZdsp90Yv9IYZlSns5c0NpA8xBrwXFK7xa+S6LhZG+R4UN1kMHhSXw1gF0wg /ScjG8dYmIFsQdB3766tQAgJKxf+z1WAsIvx/8egDzkAMMkWKFZJgtD21NywX+3ibZlO Legrf/QgNH+ZlmoJn0LhGHz2RR6Rxt3zWhEBgVgYplOd7HofuE7JVSQ9kerg3/KZRbSh DURg== X-Gm-Message-State: AOAM531gT8bjtlW1W1yuL6bdO3hQjCK7N2EDVoCEtl7OkHHhWNWg6YaA /Bjyx5Ff3L6ebEPbTmczppoa2Q== X-Google-Smtp-Source: ABdhPJyJ4G5fSyPxmvgYhWNlJ5oY652VK7yjuq8KCkCf+/3gyDKbN0PHdQdiEqVr82Kusv7dakgq9A== X-Received: by 2002:a5d:4349:: with SMTP id u9mr24003093wrr.319.1605020428734; Tue, 10 Nov 2020 07:00:28 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 2/2] tmp105: Correct handling of temperature limit checks Date: Tue, 10 Nov 2020 15:00:23 +0000 Message-Id: <20201110150023.25533-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201110150023.25533-1-peter.maydell@linaro.org> References: <20201110150023.25533-1-peter.maydell@linaro.org> MIME-Version: 1.0 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=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42c.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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.23 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 @linaro.org) Content-Type: text/plain; charset="utf-8" The TMP105 datasheet says that in Interrupt Mode (when TM=3D=3D1) the device signals an alert when the temperature equals or exceeds the T_high value and then remains high until a device register is read or the device responds to the SMBUS Alert Response address, or the device is put into Shutdown Mode. Thereafter the Alert pin will only be re-signalled when temperature falls below T_low; alert can then be cleared in the same set of ways, and the device returns to its initial "alert when temperature goes above T_high" mode. (If this textual description is confusing, see figure 3 in the TI datasheet at https://www.ti.com/lit/gpn/tmp105 .) We were misimplementing this as a simple "always alert if temperature is above T_high or below T_low" condition, which gives a spurious alert on startup if using the "T_high =3D 80 degrees C, T_low =3D 75 degrees C" reset limit values. Implement the correct (hysteresis) behaviour by tracking whether we are currently looking for the temperature to rise over T_high or for it to fall below T_low. Our implementation of the comparator mode (TM=3D=3D0) wasn't wrong, but rephrase it to match the way that interrupt mode is now handled for clarity. Signed-off-by: Peter Maydell Reviewed-by: C=C3=A9dric Le Goater --- hw/misc/tmp105.c | 70 +++++++++++++++++++++++++++++++++++++++++------- hw/misc/tmp105.h | 7 +++++ 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/hw/misc/tmp105.c b/hw/misc/tmp105.c index 0a4aad4854..d299d9b21b 100644 --- a/hw/misc/tmp105.c +++ b/hw/misc/tmp105.c @@ -41,16 +41,40 @@ static void tmp105_alarm_update(TMP105State *s) return; } =20 - if ((s->config >> 1) & 1) { /* TM */ - if (s->temperature >=3D s->limit[1]) - s->alarm =3D 1; - else if (s->temperature < s->limit[0]) - s->alarm =3D 1; + if (s->config >> 1 & 1) { + /* + * TM =3D=3D 1 : Interrupt mode. We signal Alert when the + * temperature rises above T_high, and expect the guest to clear + * it (eg by reading a device register). + */ + if (s->detect_falling) { + if (s->temperature < s->limit[0]) { + s->alarm =3D 1; + s->detect_falling =3D false; + } + } else { + if (s->temperature >=3D s->limit[1]) { + s->alarm =3D 1; + s->detect_falling =3D true; + } + } } else { - if (s->temperature >=3D s->limit[1]) - s->alarm =3D 1; - else if (s->temperature < s->limit[0]) - s->alarm =3D 0; + /* + * TM =3D=3D 0 : Comparator mode. We signal Alert when the tempera= ture + * rises above T_high, and stop signalling it when the temperature + * falls below T_low. + */ + if (s->detect_falling) { + if (s->temperature < s->limit[0]) { + s->alarm =3D 0; + s->detect_falling =3D false; + } + } else { + if (s->temperature >=3D s->limit[1]) { + s->alarm =3D 1; + s->detect_falling =3D true; + } + } } =20 tmp105_interrupt_update(s); @@ -197,6 +221,29 @@ static int tmp105_post_load(void *opaque, int version_= id) return 0; } =20 +static bool detect_falling_needed(void *opaque) +{ + TMP105State *s =3D opaque; + + /* + * We only need to migrate the detect_falling bool if it's set; + * for migration from older machines we assume that it is false + * (ie temperature is not out of range). + */ + return s->detect_falling; +} + +static const VMStateDescription vmstate_tmp105_detect_falling =3D { + .name =3D "TMP105/detect-falling", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D detect_falling_needed, + .fields =3D (VMStateField[]) { + VMSTATE_BOOL(detect_falling, TMP105State), + VMSTATE_END_OF_LIST() + } +}; + static const VMStateDescription vmstate_tmp105 =3D { .name =3D "TMP105", .version_id =3D 0, @@ -212,6 +259,10 @@ static const VMStateDescription vmstate_tmp105 =3D { VMSTATE_UINT8(alarm, TMP105State), VMSTATE_I2C_SLAVE(i2c, TMP105State), VMSTATE_END_OF_LIST() + }, + .subsections =3D (const VMStateDescription*[]) { + &vmstate_tmp105_detect_falling, + NULL } }; =20 @@ -224,6 +275,7 @@ static void tmp105_reset(I2CSlave *i2c) s->config =3D 0; s->faults =3D tmp105_faultq[(s->config >> 3) & 3]; s->alarm =3D 0; + s->detect_falling =3D false; =20 s->limit[0] =3D 0x4b00; /* T_LOW, 75 degrees C */ s->limit[1] =3D 0x5000; /* T_HIGH, 80 degrees C */ diff --git a/hw/misc/tmp105.h b/hw/misc/tmp105.h index e5198fce80..7c97071ad7 100644 --- a/hw/misc/tmp105.h +++ b/hw/misc/tmp105.h @@ -43,6 +43,13 @@ struct TMP105State { int16_t limit[2]; int faults; uint8_t alarm; + /* + * The TMP105 initially looks for a temperature rising above T_high; + * once this is detected, the condition it looks for next is the + * temperature falling below T_low. This flag is false when initially + * looking for T_high, true when looking for T_low. + */ + bool detect_falling; }; =20 #endif --=20 2.20.1