On Tue, Aug 13, 2013 at 12:00:19AM +0200, Landry Breuil wrote:
> On Mon, Aug 12, 2013 at 06:01:25PM +0200, David Coppa wrote:
> > On Mon, Aug 12, 2013 at 5:40 PM, Landry Breuil <[email protected]>
> > wrote:
> > > Hi,
> > >
> > > this diff adds a sensor for acpibtn to show lid status. This allows
> > > userland to monitor/react on lid close/open events, in case one is not
> > > using machdep.lidsuspend. I know sysutils/upower can make use of this, i
> > > just need to add the corresponding code there.
> > >
> > > comments ? I wonder if/how the case when aml_evalinteger() fails should
> > > be handled in acpibtn_attach()..
> >
> > Where's the diff?
> >
> Err.. here it is.
Anyone willing to actually test this on a selection of laptops before it goes
in ?
Landry
> Index: acpibtn.c
> ===================================================================
> RCS file: /cvs/src/sys/dev/acpi/acpibtn.c,v
> retrieving revision 1.34
> diff -u -r1.34 acpibtn.c
> --- acpibtn.c 2 Jan 2011 04:56:57 -0000 1.34
> +++ acpibtn.c 12 Aug 2013 15:35:35 -0000
> @@ -46,6 +46,9 @@
> struct acpi_softc *sc_acpi;
> struct aml_node *sc_devnode;
>
> + struct ksensor sc_sens;
> + struct ksensordev sc_sensdev;
> +
> int sc_btn_type;
> #define ACPIBTN_UNKNOWN 0
> #define ACPIBTN_LID 1
> @@ -123,6 +126,7 @@
> struct acpibtn_softc *sc = (struct acpibtn_softc *)self;
> struct acpi_attach_args *aa = aux;
> struct acpi_lid *lid;
> + int64_t lid_open;
>
> sc->sc_acpi = (struct acpi_softc *)parent;
> sc->sc_devnode = aa->aaa_node;
> @@ -143,6 +147,20 @@
>
> printf(": %s\n", sc->sc_devnode->name);
>
> + if (sc->sc_btn_type == ACPIBTN_LID) {
> + strlcpy(sc->sc_sensdev.xname, DEVNAME(sc),
> + sizeof(sc->sc_sensdev.xname));
> + strlcpy(sc->sc_sens.desc, "lid open",
> + sizeof(sc->sc_sens.desc));
> + sc->sc_sens.type = SENSOR_INDICATOR;
> + sensor_attach(&sc->sc_sensdev, &sc->sc_sens);
> + sensordev_install(&sc->sc_sensdev);
> +
> + aml_evalinteger(sc->sc_acpi, sc->sc_devnode,
> + "_LID", 0, NULL, &lid_open);
> + sc->sc_sens.value = lid_open;
> + }
> +
> aml_register_notify(sc->sc_devnode, aa->aaa_dev, acpibtn_notify,
> sc, ACPIDEV_NOPOLL);
> }
> @@ -179,11 +197,12 @@
> * _LID method. 0 means the lid is closed and we
> * should go to sleep.
> */
> - if (lid_suspend == 0)
> - break;
> if (aml_evalinteger(sc->sc_acpi, sc->sc_devnode,
> "_LID", 0, NULL, &lid))
> return (0);
> + sc->sc_sens.value = lid;
> + if (lid_suspend == 0)
> + break;
> if (lid == 0)
> goto sleep;
> #endif /* SMALL_KERNEL */
>