From: Glenn Miles <milesg@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: "Glenn Miles" <milesg@linux.vnet.ibm.com>,
qemu-arm@nongnu.org, "Cédric Le Goater" <clg@kaod.org>,
andrew@codeconstruct.com.au, "Joel Stanley" <joel@jms.id.au>,
philmd@linaro.org
Subject: [PATCH v2 3/3] misc/pca9552: Only update output GPIOs if state changed
Date: Fri, 20 Oct 2023 13:23:21 -0500 [thread overview]
Message-ID: <20231020182321.163109-4-milesg@linux.vnet.ibm.com> (raw)
In-Reply-To: <20231020182321.163109-1-milesg@linux.vnet.ibm.com>
The pca9552 code was updating output GPIO states whenever
the pin state was updated even if the state did not change.
This commit adds a check so that we only update the GPIO
output when the pin state actually changes.
Signed-off-by: Glenn Miles <milesg@linux.vnet.ibm.com>
---
New commit in v2
hw/misc/pca9552.c | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/hw/misc/pca9552.c b/hw/misc/pca9552.c
index ed814d1f98..4ed6903404 100644
--- a/hw/misc/pca9552.c
+++ b/hw/misc/pca9552.c
@@ -112,14 +112,15 @@ static void pca955x_update_pin_input(PCA955xState *s)
for (i = 0; i < k->pin_count; i++) {
uint8_t input_reg = PCA9552_INPUT0 + (i / 8);
- uint8_t input_shift = (i % 8);
+ uint8_t bit_mask = 1 << (i % 8);
uint8_t config = pca955x_pin_get_config(s, i);
+ uint8_t old_value = s->regs[input_reg] & bit_mask;
+ uint8_t new_value;
switch (config) {
case PCA9552_LED_ON:
/* Pin is set to 0V to turn on LED */
- qemu_set_irq(s->gpio_out[i], 0);
- s->regs[input_reg] &= ~(1 << input_shift);
+ s->regs[input_reg] &= ~bit_mask;
break;
case PCA9552_LED_OFF:
/*
@@ -128,11 +129,9 @@ static void pca955x_update_pin_input(PCA955xState *s)
* external device drives it low.
*/
if (s->ext_state[i] == PCA9552_PIN_LOW) {
- qemu_set_irq(s->gpio_out[i], 0);
- s->regs[input_reg] &= ~(1 << input_shift);
+ s->regs[input_reg] &= ~bit_mask;
} else {
- qemu_set_irq(s->gpio_out[i], 1);
- s->regs[input_reg] |= 1 << input_shift;
+ s->regs[input_reg] |= bit_mask;
}
break;
case PCA9552_LED_PWM0:
@@ -141,6 +140,18 @@ static void pca955x_update_pin_input(PCA955xState *s)
default:
break;
}
+
+ /* update irq state only if pin state changed */
+ new_value = s->regs[input_reg] & bit_mask;
+ if (new_value != old_value) {
+ if (new_value) {
+ /* changed from 0 to 1 */
+ qemu_set_irq(s->gpio_out[i], 1);
+ } else {
+ /* changed from 1 to 0 */
+ qemu_set_irq(s->gpio_out[i], 0);
+ }
+ }
}
}
--
2.31.1
next prev parent reply other threads:[~2023-10-20 18:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-20 18:23 [PATCH v2 0/3] misc/pca9552: Changes to support powernv10 Glenn Miles
2023-10-20 18:23 ` [PATCH v2 1/3] misc/pca9552: Fix inverted input status Glenn Miles
2023-10-23 23:45 ` Andrew Jeffery
2023-10-24 16:49 ` Miles Glenn
2023-10-20 18:23 ` [PATCH v2 2/3] misc/pca9552: Let external devices set pca9552 inputs Glenn Miles
2023-10-20 18:23 ` Glenn Miles [this message]
2023-10-23 23:43 ` [PATCH v2 3/3] misc/pca9552: Only update output GPIOs if state changed Andrew Jeffery
2023-10-24 16:48 ` Miles Glenn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231020182321.163109-4-milesg@linux.vnet.ibm.com \
--to=milesg@linux.vnet.ibm.com \
--cc=andrew@codeconstruct.com.au \
--cc=clg@kaod.org \
--cc=joel@jms.id.au \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).