Hello,

As jsg@ mentioned, HP 2140 Mini-Note PC has its SMBus hidden from us, 
but we can still interface with the accelerometer through ACPI.

This patch provides such acpi(4) interfacing for lisa(4), 
similarly to how spdmem(4) can attach on mem(4) on OpenBSD/macppc. 
It also includes a part where we ensure that only one type of 
attachment is possible, similarly to how the situation is with 
lm(4) at iic(4) and isa(4).

Please test, especially if you have 2140, but testing on other HP 
laptops would be very welcome, too -- you might as well find you 
have an accelerometer you are not aware of. :)

For convenience, I have made some kernel snapshots available for testing 
that already contain this patch.  Note that you should not be using these 
snapshots for anything other than testing; the i386 one, for example, 
is cross-compiled on an amd64 box; and more importantly, both are likely 
to be out of sync with certain parts of your userland.

        cd /tmp
        rm bsd{,.gz}
        ftp http://bsd.cnst.su/OpenBSD/hptd.4/bsd.`uname -m`.gz
        gunzip bsd.gz
        rm /obsd; ln /bsd /obsd && cp bsd /nbsd && mv /nbsd /bsd


Please send the following in your test reports:

        dmesg
        sysctl hw
        acpidump


As well as results of some interactive testing:

        sh -c "while(true)do sysctl -n hw.sensors.lisa0|xargs;sleep 1;done"


Cheers,
Constantine.
Index: arch/i386/conf/GENERIC
===================================================================
RCS file: /share/OpenBSD/cvs/src/sys/arch/i386/conf/GENERIC,v
retrieving revision 1.669
diff -u -d -p -4 -r1.669 GENERIC
--- arch/i386/conf/GENERIC      14 Aug 2009 20:39:02 -0000      1.669
+++ arch/i386/conf/GENERIC      29 Aug 2009 16:32:08 -0000
@@ -66,8 +66,10 @@ acpithinkpad*        at acpi?
 acpivideo*     at acpi?
 acpivout*      at acpivideo?
 acpipwrres*    at acpi?
 #aibs*         at acpi?
+hptd*          at acpi?
+lisa*          at hptd?
 
 option         PCIVERBOSE
 option         EISAVERBOSE
 option         USBVERBOSE
Index: arch/amd64/conf/GENERIC
===================================================================
RCS file: /share/OpenBSD/cvs/src/sys/arch/amd64/conf/GENERIC,v
retrieving revision 1.272
diff -u -d -p -4 -r1.272 GENERIC
--- arch/amd64/conf/GENERIC     14 Aug 2009 20:39:02 -0000      1.272
+++ arch/amd64/conf/GENERIC     29 Aug 2009 16:32:08 -0000
@@ -54,8 +54,10 @@ acpithinkpad*        at acpi?
 acpivideo*     at acpi?
 acpivout*      at acpivideo?
 acpipwrres*    at acpi?
 #aibs*         at acpi?
+hptd*          at acpi?
+lisa*          at hptd?
 
 mpbios0                at bios0
 
 ipmi0  at mainbus? disable     # IPMI
Index: dev/acpi/acpi.c
===================================================================
RCS file: /share/OpenBSD/cvs/src/sys/dev/acpi/acpi.c,v
retrieving revision 1.141
diff -u -d -p -4 -r1.141 acpi.c
--- dev/acpi/acpi.c     23 Jul 2009 01:38:16 -0000      1.141
+++ dev/acpi/acpi.c     29 Aug 2009 16:32:08 -0000
@@ -2245,8 +2245,10 @@ acpi_foundhid(struct aml_node *node, voi
                aaa.aaa_name = "acpithinkpad";
                acpi_thinkpad_enabled = 1;
        } else if (!strcmp(dev, ACPI_DEV_ASUSAIBOOSTER))
                aaa.aaa_name = "aibs";
+       else if (!strcmp(dev, ACPI_DEV_HPACEL))
+               aaa.aaa_name = "hptd";
 
        if (aaa.aaa_name)
                config_found(self, &aaa, acpi_print);
 
Index: dev/acpi/acpireg.h
===================================================================
RCS file: /share/OpenBSD/cvs/src/sys/dev/acpi/acpireg.h,v
retrieving revision 1.18
diff -u -d -p -4 -r1.18 acpireg.h
--- dev/acpi/acpireg.h  23 Jul 2009 01:38:16 -0000      1.18
+++ dev/acpi/acpireg.h  29 Aug 2009 16:32:08 -0000
@@ -494,6 +494,7 @@ struct acpi_facs {
 #define ACPI_DEV_FFB   "FIXEDBUTTON"   /* Fixed Feature Button */
 #define ACPI_DEV_ASUS  "ASUS010"       /* ASUS Hotkeys */
 #define ACPI_DEV_THINKPAD "IBM0068"    /* ThinkPad support */
 #define ACPI_DEV_ASUSAIBOOSTER "ATK0110"       /* ASUSTeK AI Booster */
+#define ACPI_DEV_HPACEL        "HPQ0004"       /* HP 3D DriveGuard */
 
 #endif /* !_DEV_ACPI_ACPIREG_H_ */
Index: dev/acpi/files.acpi
===================================================================
RCS file: /share/OpenBSD/cvs/src/sys/dev/acpi/files.acpi,v
retrieving revision 1.23
diff -u -d -p -4 -r1.23 files.acpi
--- dev/acpi/files.acpi 23 Jul 2009 01:38:16 -0000      1.23
+++ dev/acpi/files.acpi 29 Aug 2009 16:32:08 -0000
@@ -95,4 +95,9 @@ file  dev/acpi/acpipwrres.c           acpipwrres
 # ASUSTeK AI Booster ATK0110
 device aibs
 attach aibs at acpi
 file   dev/acpi/atk0110.c              aibs
+
+# HP 3D DriveGuard accelerometer
+device hptd: i2c
+attach hptd at acpi
+file   dev/acpi/hp3d.c                 hptd
Index: dev/acpi/hp3d.c
===================================================================
RCS file: dev/acpi/hp3d.c
diff -N dev/acpi/hp3d.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ dev/acpi/hp3d.c     29 Aug 2009 16:32:08 -0000
@@ -0,0 +1,145 @@
+/*     $OpenBSD: atk0110.c,v 1.1 2009/07/23 01:38:16 cnst Exp $        */
+
+/*
+ * Copyright (c) 2009 Constantine A. Murenin <[email protected]>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/malloc.h>
+#include <sys/sensors.h>
+
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpivar.h>
+#include <dev/acpi/acpidev.h>
+#include <dev/acpi/amltypes.h>
+#include <dev/acpi/dsdt.h>
+
+#include <dev/i2c/i2cvar.h>
+
+/*
+ * HP 3D DriveGuard accelerometer support.
+ */
+
+struct hp3d_softc {
+       struct device           sc_dev;
+
+       struct acpi_softc       *sc_acpi;
+       struct aml_node         *sc_alrd;
+
+       struct i2c_controller   sc_ic;
+};
+
+int    hp3d_match(struct device *, void *, void *);
+void   hp3d_attach(struct device *, struct device *, void *);
+
+int    hp3d_i2c_acquire_bus(void *, int);
+void   hp3d_i2c_release_bus(void *, int);
+int    hp3d_i2c_exec(void *, i2c_op_t, i2c_addr_t,
+    const void *, size_t, void *, size_t, int);
+
+struct cfattach hptd_ca = {
+       sizeof(struct hp3d_softc), hp3d_match, hp3d_attach
+};
+
+struct cfdriver hptd_cd = {
+       NULL, "hptd", DV_DULL
+};
+
+static const char* hp3d_hids[] = {
+       ACPI_DEV_HPACEL,
+       NULL
+};
+
+int
+hp3d_match(struct device *parent, void *match, void *aux)
+{
+       struct acpi_attach_args *aa = aux;
+       struct cfdata           *cf = match;
+
+       return acpi_matchhids(aa, hp3d_hids, cf->cf_driver->cd_name);
+}
+
+void
+hp3d_attach(struct device *parent, struct device *self, void *aux)
+{
+       struct hp3d_softc       *sc = (struct hp3d_softc *)self;
+       struct acpi_attach_args *aa = aux;
+       struct i2c_attach_args  ia;
+
+       sc->sc_acpi = (struct acpi_softc *)parent;
+       sc->sc_alrd = aml_searchname(aa->aaa_node, "ALRD");
+       if (sc->sc_alrd == NULL || sc->sc_alrd->value == NULL ||
+           sc->sc_alrd->value->type != AML_OBJTYPE_METHOD) {
+               printf(": ALRD method node not found\n");
+               return;
+       }
+       printf("\n");
+
+       sc->sc_ic.ic_cookie = sc;
+       sc->sc_ic.ic_acquire_bus = hp3d_i2c_acquire_bus;
+       sc->sc_ic.ic_release_bus = hp3d_i2c_release_bus;
+       sc->sc_ic.ic_exec = hp3d_i2c_exec;
+
+       bzero(&ia, sizeof ia);
+       ia.ia_tag = &sc->sc_ic;
+       ia.ia_name = "hp3d";
+       config_found(self, &ia, NULL);
+}
+
+int
+hp3d_i2c_acquire_bus(void *cookie, int flags)
+{
+       return 0;
+}
+
+void
+hp3d_i2c_release_bus(void *cookie, int flags)
+{
+}
+
+int
+hp3d_i2c_exec(void *cookie, i2c_op_t op, i2c_addr_t addr,
+    const void *cmdbuf, size_t cmdlen, void *buf, size_t len, int flags)
+{
+       struct hp3d_softc       *sc = cookie;
+       int8_t                  c = *(int8_t *)cmdbuf;
+       uint8_t                 *b = buf;
+       struct aml_value        req, res;
+
+       if (op != I2C_OP_READ_WITH_STOP || cmdlen != 1 || len != 1)
+               return 1;
+
+       req.type = AML_OBJTYPE_INTEGER;
+       req.v_integer = c;
+       if (aml_evalnode(sc->sc_acpi, sc->sc_alrd, 1, &req, &res)) {
+               dprintf("%s: ALRD %hhi evaluation failed\n",
+                   DEVNAME(sc), c);
+               *b = 0;
+               aml_freevalue(&res);
+               return 1;
+       }
+       if (res.type != AML_OBJTYPE_INTEGER) {
+               dprintf("%s: ALRD %hhi: not an integer: type %i\n",
+                   DEVNAME(sc), c, res.type);
+               *b = 0;
+               aml_freevalue(&res);
+               return 1;
+       }
+       *b = res.v_integer;
+       aml_freevalue(&res);
+       return 0;
+}
Index: dev/i2c/lis331dl.c
===================================================================
RCS file: /share/OpenBSD/cvs/src/sys/dev/i2c/lis331dl.c,v
retrieving revision 1.1
diff -u -d -p -4 -r1.1 lis331dl.c
--- dev/i2c/lis331dl.c  12 Aug 2009 14:51:20 -0000      1.1
+++ dev/i2c/lis331dl.c  29 Aug 2009 16:32:08 -0000
@@ -72,9 +72,10 @@ int
 lisa_match(struct device *parent, void *match, void *aux)
 {
        struct i2c_attach_args *ia = aux;
 
-       if (strcmp(ia->ia_name, "lis331dl") == 0)
+       if (strcmp(ia->ia_name, "lis331dl") == 0 ||
+           strcmp(ia->ia_name, "hp3d") == 0)
                return 1;
        return 0;
 }
 
@@ -88,8 +89,23 @@ lisa_attach(struct device *parent, struc
        sc->sc_tag = ia->ia_tag;
        sc->sc_addr = ia->ia_addr;
 
        printf(": %s", ia->ia_name);
+
+       /*
+        * When there is at least one attachment at hptd(4) through acpi(4),
+        * don't attach a single instance through iic(4).
+        */
+       if (!(strcmp(ia->ia_name, "hp3d") == 0))
+               for (i = 0; i < lisa_cd.cd_ndevs; i++) {
+                       const struct lisa_softc *l = lisa_cd.cd_devs[i];
+
+                       if (l != NULL && strcmp(l->sc_dev.dv_parent->dv_xname,
+                           "hptd0") == 0) {
+                               printf(": skipping sensors due to hptd0\n");
+                               return; 
+                       }
+               }
 
        strlcpy(sc->sc_sensordev.xname, sc->sc_dev.dv_xname,
            sizeof(sc->sc_sensordev.xname));
Index: Makefile
===================================================================
RCS file: /share/OpenBSD/cvs/src/share/man/man4/Makefile,v
retrieving revision 1.489
diff -u -d -p -4 -r1.489 Makefile
--- Makefile    12 Aug 2009 14:58:34 -0000      1.489
+++ Makefile    29 Aug 2009 00:21:13 -0000
@@ -21,9 +21,9 @@ MAN=  aac.4 ac97.4 acphy.4 \
        eso.4 ess.4 et.4 etphy.4 ex.4 exphy.4 \
        faith.4 fd.4 fdc.4 fins.4 fintek.4 fms.4 fpa.4 fxp.4 gdt.4 \
        gentbi.4 gem.4 gif.4 \
        glenv.4 gpio.4 gpiodcf.4 gpioiic.4 gpioow.4 gpr.4 gre.4 gscsio.4 gtp.4 \
-       hifn.4 hil.4 hilid.4 hilkbd.4 hilms.4 hme.4 hotplug.4 hsq.4 \
+       hifn.4 hil.4 hilid.4 hilkbd.4 hilms.4 hme.4 hotplug.4 hptd.4 hsq.4 \
        ichiic.4 ichwdt.4 icmp.4 icmp6.4 icsphy.4 ifmedia.4 \
        iha.4 iic.4 inet.4 inet6.4 inphy.4 iop.4 iophy.4 ioprbs.4 \
        iopsp.4 ip.4 ip6.4 ipcomp.4 ipgphy.4 ipmi.4 ips.4 ipsec.4 ipw.4 \
        isa.4 isagpio.4 isapnp.4 isp.4 it.4 iwi.4 iwn.4 ix.4 ixgb.4 \
Index: acpi.4
===================================================================
RCS file: /share/OpenBSD/cvs/src/share/man/man4/acpi.4,v
retrieving revision 1.37
diff -u -d -p -4 -r1.37 acpi.4
--- acpi.4      23 Jul 2009 06:42:27 -0000      1.37
+++ acpi.4      29 Aug 2009 00:21:13 -0000
@@ -71,8 +71,10 @@ ACPI video
 .It Xr acpivout 4
 ACPI video output
 .It Xr aibs 4
 ASUSTeK AI Booster ACPI ATK0110 temperature, voltage, and fan sensor
+.It Xr hptd 4
+HP 3D DriveGuard accelerometer support
 .El
 .Sh FILES
 .Bl -tag -width "/dev/apmctlXXX"
 .It /dev/apm
Index: hptd.4
===================================================================
RCS file: hptd.4
diff -N hptd.4
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ hptd.4      29 Aug 2009 00:21:13 -0000
@@ -0,0 +1,47 @@
+.\"    $OpenBSD: lisa.4,v 1.1 2009/08/12 14:58:34 cnst Exp $
+.\"
+.\" Copyright (c) 2009 Constantine A. Murenin <[email protected]>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd $Mdocdate: August 12 2009 $
+.Dt HPTD 4
+.Os
+.Sh NAME
+.Nm hptd
+.Nd HP 3D DriveGuard accelerometer support
+.Sh SYNOPSIS
+.Cd "hptd* at acpi?"
+.Cd "lisa* at hptd?"
+.Sh DESCRIPTION
+The
+.Nm
+driver provides support for
+.Xr lisa 4
+attachment through
+.Xr acpi 4 .
+.Sh SEE ALSO
+.Xr acpi 4 ,
+.Xr intro 4 ,
+.Xr lisa 4
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Ox 4.7 .
+.Sh AUTHORS
+The
+.Nm
+driver was written by
+.An Constantine A. Murenin Aq [email protected] ,
+University of Waterloo.
Index: lisa.4
===================================================================
RCS file: /share/OpenBSD/cvs/src/share/man/man4/lisa.4,v
retrieving revision 1.1
diff -u -d -p -4 -r1.1 lisa.4
--- lisa.4      12 Aug 2009 14:58:34 -0000      1.1
+++ lisa.4      29 Aug 2009 00:21:13 -0000
@@ -21,8 +21,9 @@
 .Nm lisa
 .Nd STMicroelectronics LIS331DL MEMS motion sensor
 .Sh SYNOPSIS
 .Cd "lisa* at iic?"
+.Cd "lisa* at hptd?"
 .Sh DESCRIPTION
 The
 .Nm
 driver provides support for the ST LIS331DL
@@ -43,11 +44,27 @@ view,
 .Xr sensorsd 8
 and
 .Xr sysctl 8
 .Ar hw.sensors .
+.Pp
+Some HP laptops don't have a visible
+.Xr iic 4 ,
+but attachment through
+.Xr hptd 4
+ACPI device is possible.
+To avoid duplicated readings,
+if there is at least one
+.Nm
+attachment through
+.Xr hptd 4 ,
+then
+.Nm
+would not register any sensors when attached directly through
+.Xr iic 4 .
 .Sh SEE ALSO
 .Xr systat 1 ,
 .Xr sysctl 3 ,
+.Xr hptd 4 ,
 .Xr iic 4 ,
 .Xr intro 4 ,
 .Xr sensorsd 8 ,
 .Xr sysctl 8

Reply via email to