qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Miles Glenn <milesg@linux.vnet.ibm.com>
To: Andrew Jeffery <andrew@codeconstruct.com.au>, qemu-devel@nongnu.org
Cc: qemu-arm@nongnu.org, "Cédric Le Goater" <clg@kaod.org>,
	"Joel Stanley" <joel@jms.id.au>,
	philmd@linaro.org
Subject: Re: [PATCH v2 3/3] misc/pca9552: Only update output GPIOs if state changed
Date: Tue, 24 Oct 2023 11:48:11 -0500	[thread overview]
Message-ID: <84497c0ac05f830879745ab4916cb5357a31a09d.camel@linux.vnet.ibm.com> (raw)
In-Reply-To: <7ba3d0298be8edbfbbc16882aa17fa38e70662be.camel@codeconstruct.com.au>

On Tue, 2023-10-24 at 10:13 +1030, Andrew Jeffery wrote:
> On Fri, 2023-10-20 at 13:23 -0500, Glenn Miles wrote:
> > 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.
> 
> Given this is intertwined with patch 2/3 that adds the input mode
> capability, I think they should be squashed together?
> 

Sure, no problem.

> > 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);
> > +            }
> 
> Slightly code-golf-y, but the inner if-else here may be compressed
> to:
> 
>     qemu_set_irq(s->gpio_out[i], !!new_value);
> 
> Andrew

I like it!

Glenn



      reply	other threads:[~2023-10-24 16:49 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 ` [PATCH v2 3/3] misc/pca9552: Only update output GPIOs if state changed Glenn Miles
2023-10-23 23:43   ` Andrew Jeffery
2023-10-24 16:48     ` Miles Glenn [this message]

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=84497c0ac05f830879745ab4916cb5357a31a09d.camel@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).