Let me clarify some.

On Thu, 17 Aug 2023 16:12:07 +0900 (JST)
YASUOKA Masahiko <yasu...@openbsd.org> wrote:
> Update the AC status when the battery notification is happened.
> Because the AC status notification doesn't happen on some machines.

At that time (plugging or unpluggin the AC), a battery notification
always happens.  So the diff is to use the battery notification
instead of the AC status notification.

> My vaio actually has this problem.
> 
> Also Linux is doing the same thing
> 
> https://github.com/torvalds/linux/blob/v6.4/drivers/acpi/ac.c#L165-L183
> 
> ok? comments?
> 
> Index: sys/dev/acpi/acpiac.c
> ===================================================================
> RCS file: /cvs/src/sys/dev/acpi/acpiac.c,v
> retrieving revision 1.36
> diff -u -p -r1.36 acpiac.c
> --- sys/dev/acpi/acpiac.c     6 Apr 2022 18:59:27 -0000       1.36
> +++ sys/dev/acpi/acpiac.c     17 Aug 2023 06:57:44 -0000
> @@ -140,6 +140,8 @@ acpiac_getpsr(struct acpiac_softc *sc)
>       return (0);
>  }
>  
> +static int acpiac_notify_triggered = 0;
> +
>  int
>  acpiac_notify(struct aml_node *node, int notify_type, void *arg)
>  {
> @@ -148,6 +150,8 @@ acpiac_notify(struct aml_node *node, int
>       dnprintf(10, "acpiac_notify: %.2x %s\n", notify_type,
>           DEVNAME(sc));
>  
> +     acpiac_notify_triggered = 1;
> +
>       switch (notify_type) {
>       case 0x00:
>       case 0x01:
> @@ -164,4 +168,22 @@ acpiac_notify(struct aml_node *node, int
>               break;
>       }
>       return (0);
> +}
> +
> +void
> +acpiac_battery_notify(void)
> +{
> +     struct acpi_softc *sc = acpi_softc;
> +     struct acpi_ac *ac;
> +
> +     if (acpiac_notify_triggered)
> +             return;
> +     /*
> +      * On some machines (vaio VJPK23 at least) AC status notifications
> +      * are not triggered.  Update the AC status when battery notifications.
> +      */
> +     SLIST_FOREACH(ac, &sc->sc_ac, aac_link) {
> +             acpiac_refresh(ac->aac_softc);
> +             acpi_record_event(sc, APM_POWER_CHANGE);
> +     }
>  }
> Index: sys/dev/acpi/acpibat.c
> ===================================================================
> RCS file: /cvs/src/sys/dev/acpi/acpibat.c,v
> retrieving revision 1.70
> diff -u -p -r1.70 acpibat.c
> --- sys/dev/acpi/acpibat.c    6 Apr 2022 18:59:27 -0000       1.70
> +++ sys/dev/acpi/acpibat.c    17 Aug 2023 06:57:45 -0000
> @@ -536,5 +536,7 @@ acpibat_notify(struct aml_node *node, in
>       acpibat_refresh(sc);
>       acpi_record_event(sc->sc_acpi, APM_POWER_CHANGE);
>  
> +     acpiac_battery_notify();
> +
>       return (0);
>  }
> Index: sys/dev/acpi/acpidev.h
> ===================================================================
> RCS file: /cvs/src/sys/dev/acpi/acpidev.h,v
> retrieving revision 1.44
> diff -u -p -r1.44 acpidev.h
> --- sys/dev/acpi/acpidev.h    29 Jun 2018 17:39:18 -0000      1.44
> +++ sys/dev/acpi/acpidev.h    17 Aug 2023 06:57:45 -0000
> @@ -306,6 +306,8 @@ struct acpiac_softc {
>       struct ksensordev       sc_sensdev;
>  };
>  
> +void acpiac_battery_notify(void);
> +
>  struct acpibat_softc {
>       struct device           sc_dev;
>  
> 

Reply via email to