summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorJordan Hargrave <jordan@cvs.openbsd.org>2009-03-10 20:36:11 +0000
committerJordan Hargrave <jordan@cvs.openbsd.org>2009-03-10 20:36:11 +0000
commite19d662685b8911900a8d769a933f7d40013f712 (patch)
tree2bbc6a25df8866cd6393bd0b66e005d450429465 /sys/dev
parente023a0dc8509fb134ba3371635dd853127f9c19c (diff)
Added sensor devices for Thinkpad (temp+fan)
Exported aml_evalinteger method ok marco@
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/acpi/acpidev.h25
-rw-r--r--sys/dev/acpi/acpiec.c27
-rw-r--r--sys/dev/acpi/acpithinkpad.c77
-rw-r--r--sys/dev/acpi/dsdt.c4
-rw-r--r--sys/dev/acpi/dsdt.h4
5 files changed, 104 insertions, 33 deletions
diff --git a/sys/dev/acpi/acpidev.h b/sys/dev/acpi/acpidev.h
index b786e0230c9..209e0ad8dac 100644
--- a/sys/dev/acpi/acpidev.h
+++ b/sys/dev/acpi/acpidev.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: acpidev.h,v 1.26 2007/11/12 21:58:14 deraadt Exp $ */
+/* $OpenBSD: acpidev.h,v 1.27 2009/03/10 20:36:10 jordan Exp $ */
/*
* Copyright (c) 2005 Marco Peereboom <marco@openbsd.org>
* Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com>
@@ -314,5 +314,28 @@ struct acpidock_softc {
#define ACPIDOCK_EVENT_INSERT 0
#define ACPIDOCK_EVENT_EJECT 3
+#define ACPIEC_MAX_EVENTS 256
+
+struct acpiec_event {
+ struct aml_node *event;
+};
+
+struct acpiec_softc {
+ struct device sc_dev;
+
+ /* command/status register */
+ bus_space_tag_t sc_cmd_bt;
+ bus_space_handle_t sc_cmd_bh;
+
+ /* data register */
+ bus_space_tag_t sc_data_bt;
+ bus_space_handle_t sc_data_bh;
+
+ struct acpi_softc *sc_acpi;
+ struct aml_node *sc_devnode;
+ u_int32_t sc_gpe;
+ struct acpiec_event sc_events[ACPIEC_MAX_EVENTS];
+ int sc_gotsci;
+};
#endif /* __DEV_ACPI_ACPIDEV_H__ */
diff --git a/sys/dev/acpi/acpiec.c b/sys/dev/acpi/acpiec.c
index 3fb81862c75..2cb642975e6 100644
--- a/sys/dev/acpi/acpiec.c
+++ b/sys/dev/acpi/acpiec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: acpiec.c,v 1.26 2008/11/06 23:41:28 marco Exp $ */
+/* $OpenBSD: acpiec.c,v 1.27 2009/03/10 20:36:10 jordan Exp $ */
/*
* Copyright (c) 2006 Can Erkin Acar <canacar@openbsd.org>
*
@@ -78,31 +78,6 @@ struct aml_node *aml_find_name(struct acpi_softc *, struct aml_node *,
#define REG_TYPE_EC 3
-#define ACPIEC_MAX_EVENTS 256
-
-struct acpiec_event {
- struct aml_node *event;
-};
-
-struct acpiec_softc {
- struct device sc_dev;
-
- /* command/status register */
- bus_space_tag_t sc_cmd_bt;
- bus_space_handle_t sc_cmd_bh;
-
- /* data register */
- bus_space_tag_t sc_data_bt;
- bus_space_handle_t sc_data_bh;
-
- struct acpi_softc *sc_acpi;
- struct aml_node *sc_devnode;
- u_int32_t sc_gpe;
- struct acpiec_event sc_events[ACPIEC_MAX_EVENTS];
- int sc_gotsci;
-};
-
-
int acpiec_reg(struct acpiec_softc *);
struct cfattach acpiec_ca = {
diff --git a/sys/dev/acpi/acpithinkpad.c b/sys/dev/acpi/acpithinkpad.c
index fc48e0d4b9c..a70755073f7 100644
--- a/sys/dev/acpi/acpithinkpad.c
+++ b/sys/dev/acpi/acpithinkpad.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: acpithinkpad.c,v 1.15 2008/12/26 06:35:34 jsg Exp $ */
+/* $OpenBSD: acpithinkpad.c,v 1.16 2009/03/10 20:36:10 jordan Exp $ */
/*
* Copyright (c) 2008 joshua stein <jcs@openbsd.org>
*
@@ -75,13 +75,25 @@
/* type 7 events */
#define THINKPAD_SWITCH_WIRELESS 0x000
+#define THINKPAD_NSENSORS 9
+#define THINKPAD_NTEMPSENSORS 8
+
+#define THINKPAD_ECOFFSET_FANLO 0x84
+#define THINKPAD_ECOFFSET_FANHI 0x85
+
struct acpithinkpad_softc {
struct device sc_dev;
+ struct acpiec_softc *sc_ec;
struct acpi_softc *sc_acpi;
struct aml_node *sc_devnode;
+
+ struct ksensor sc_sens[THINKPAD_NSENSORS];
+ struct ksensordev sc_sensdev;
};
+extern void acpiec_read(struct acpiec_softc *, u_int8_t, int, u_int8_t *);
+
int thinkpad_match(struct device *, void *, void *);
void thinkpad_attach(struct device *, struct device *, void *);
int thinkpad_hotkey(struct aml_node *, int, void *);
@@ -95,6 +107,9 @@ int thinkpad_volume_mute(struct acpithinkpad_softc *);
int thinkpad_brightness_up(struct acpithinkpad_softc *);
int thinkpad_brightness_down(struct acpithinkpad_softc *);
+void thinkpad_sensor_attach(struct acpithinkpad_softc *sc);
+void thinkpad_sensor_refresh(void *);
+
struct cfattach acpithinkpad_ca = {
sizeof(struct acpithinkpad_softc), thinkpad_match, thinkpad_attach
};
@@ -128,6 +143,58 @@ thinkpad_match(struct device *parent, void *match, void *aux)
}
void
+thinkpad_sensor_attach(struct acpithinkpad_softc *sc)
+{
+ int i;
+
+ if (sc->sc_acpi->sc_ec == NULL)
+ return;
+ sc->sc_ec = sc->sc_acpi->sc_ec;
+
+ /* Add temperature probes */
+ strlcpy(sc->sc_sensdev.xname, DEVNAME(sc),
+ sizeof(sc->sc_sensdev.xname));
+ for (i=0; i<THINKPAD_NTEMPSENSORS; i++) {
+ snprintf(sc->sc_sens[i].desc, sizeof(sc->sc_sens[i].desc),
+ "TMP%d", i);
+ sc->sc_sens[i].type = SENSOR_TEMP;
+ sc->sc_sens[i].value = 0;
+ sensor_attach(&sc->sc_sensdev, &sc->sc_sens[i]);
+ }
+
+ /* Add fan probe */
+ strlcpy(sc->sc_sens[i].desc, "fan",
+ sizeof(sc->sc_sens[i].desc));
+ sc->sc_sens[i].type = SENSOR_FANRPM;
+ sc->sc_sens[i].value = 0;
+ sensor_attach(&sc->sc_sensdev, &sc->sc_sens[i]);
+
+ sensordev_install(&sc->sc_sensdev);
+}
+
+void
+thinkpad_sensor_refresh(void *arg)
+{
+ struct acpithinkpad_softc *sc = arg;
+ u_int8_t lo, hi, i;
+ int64_t tmp;
+
+ /* Refresh sensor readings */
+ for (i=0; i<THINKPAD_NTEMPSENSORS; i++) {
+ aml_evalinteger(sc->sc_acpi, sc->sc_ec->sc_devnode,
+ sc->sc_sens[i].desc, 0, 0, &tmp);
+ sc->sc_sens[i].value = (tmp * 1000000) + 273150000;
+ if (tmp > 127 || tmp < -127)
+ sc->sc_sens[i].flags = SENSOR_FINVALID;
+ }
+
+ /* Read fan RPM */
+ acpiec_read(sc->sc_ec, THINKPAD_ECOFFSET_FANLO, 1, &lo);
+ acpiec_read(sc->sc_ec, THINKPAD_ECOFFSET_FANHI, 1, &hi);
+ sc->sc_sens[i].value = ((hi << 8L) + lo);
+}
+
+void
thinkpad_attach(struct device *parent, struct device *self, void *aux)
{
struct acpithinkpad_softc *sc = (struct acpithinkpad_softc *)self;
@@ -140,10 +207,11 @@ thinkpad_attach(struct device *parent, struct device *self, void *aux)
/* set event mask to receive everything */
thinkpad_enable_events(sc);
+ thinkpad_sensor_attach(sc);
/* run thinkpad_hotkey on button presses */
aml_register_notify(sc->sc_devnode, aa->aaa_dev,
- thinkpad_hotkey, sc, ACPIDEV_NOPOLL);
+ thinkpad_hotkey, sc, ACPIDEV_POLL);
}
int
@@ -196,6 +264,11 @@ thinkpad_hotkey(struct aml_node *node, int notify_type, void *arg)
struct aml_value res;
int val, type, event, handled, rv = 1, tot = 0;
+ if (notify_type == 0x00) {
+ /* poll sensors */
+ thinkpad_sensor_refresh(sc);
+ return 0;
+ }
if (notify_type != 0x80)
goto fail;
diff --git a/sys/dev/acpi/dsdt.c b/sys/dev/acpi/dsdt.c
index c0909b6f307..2be52c2d40b 100644
--- a/sys/dev/acpi/dsdt.c
+++ b/sys/dev/acpi/dsdt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dsdt.c,v 1.139 2009/03/07 07:04:38 jordan Exp $ */
+/* $OpenBSD: dsdt.c,v 1.140 2009/03/10 20:36:10 jordan Exp $ */
/*
* Copyright (c) 2005 Jordan Hargrave <jordan@openbsd.org>
*
@@ -68,8 +68,6 @@ void aml_xaddref(struct aml_value *, const char *);
void aml_xdelref(struct aml_value **, const char *);
void aml_bufcpy(void *, int, const void *, int, int);
-int aml_evalinteger(struct acpi_softc *, struct aml_node *,
- const char *, int, struct aml_value *, int64_t *);
int aml_pc(uint8_t *);
diff --git a/sys/dev/acpi/dsdt.h b/sys/dev/acpi/dsdt.h
index 3bdb4c8a503..b1b34bd1204 100644
--- a/sys/dev/acpi/dsdt.h
+++ b/sys/dev/acpi/dsdt.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dsdt.h,v 1.42 2008/10/07 18:02:20 kettenis Exp $ */
+/* $OpenBSD: dsdt.h,v 1.43 2009/03/10 20:36:10 jordan Exp $ */
/*
* Copyright (c) 2005 Marco Peereboom <marco@openbsd.org>
*
@@ -81,6 +81,8 @@ int aml_evalnode(struct acpi_softc *, struct aml_node *,
int aml_evalname(struct acpi_softc *, struct aml_node *,
const char *, int, struct aml_value *,
struct aml_value *);
+int aml_evalinteger(struct acpi_softc *, struct aml_node *,
+ const char *, int, struct aml_value *, int64_t *);
void aml_fixup_dsdt(u_int8_t *, u_int8_t *, int);
void aml_create_defaultobjects(void);