Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/sparc64/dev - use interrupts
details: https://anonhg.NetBSD.org/src/rev/2db1c96d83fc
branches: trunk
changeset: 993980:2db1c96d83fc
user: macallan <macallan%NetBSD.org@localhost>
date: Sat Oct 13 19:53:43 2018 +0000
description:
- use interrupts
- report power button to sysmon
diffstat:
sys/arch/sparc64/dev/tadpmu.c | 77 ++++++++++++++++++++++++++++++++++-----
sys/arch/sparc64/dev/tadpmureg.h | 11 +++--
sys/arch/sparc64/dev/tadpmuvar.h | 5 +-
3 files changed, 77 insertions(+), 16 deletions(-)
diffs (185 lines):
diff -r 65ec983e4312 -r 2db1c96d83fc sys/arch/sparc64/dev/tadpmu.c
--- a/sys/arch/sparc64/dev/tadpmu.c Sat Oct 13 15:38:28 2018 +0000
+++ b/sys/arch/sparc64/dev/tadpmu.c Sat Oct 13 19:53:43 2018 +0000
@@ -1,4 +1,4 @@
-/*/* $NetBSD: tadpmu.c,v 1.1 2018/10/12 21:44:32 macallan Exp $ */
+/*/* $NetBSD: tadpmu.c,v 1.2 2018/10/13 19:53:43 macallan Exp $ */
/*-
* Copyright (c) 2018 Michael Lorenz <macallan%netbsd.org@localhost>
@@ -33,19 +33,31 @@
#include <sys/kernel.h>
#include <sys/device.h>
#include <sys/malloc.h>
+#include <sys/proc.h>
#include <sys/bus.h>
#include <sys/intr.h>
#include <dev/sysmon/sysmonvar.h>
+#include <dev/sysmon/sysmon_taskq.h>
#include <sparc64/dev/tadpmureg.h>
#include <sparc64/dev/tadpmuvar.h>
+#ifdef TADPMU_DEBUG
+#define DPRINTF printf
+#else
+#define DPRINTF while (0) printf
+#endif
+
static bus_space_tag_t tadpmu_iot;
static bus_space_handle_t tadpmu_hcmd;
static bus_space_handle_t tadpmu_hdata;
static struct sysmon_envsys *tadpmu_sme;
static envsys_data_t tadpmu_sensors[5];
+static uint8_t idata = 0xff;
+static uint8_t ivalid = 0;
+static wchan_t tadpmu;
+static struct sysmon_pswitch tadpmu_pbutton;
static inline void
tadpmu_cmd(uint8_t d)
@@ -111,6 +123,7 @@
int bail = 0;
uint8_t d;
+ ivalid = 0;
tadpmu_cmd(cmd);
d = tadpmu_status();
@@ -132,17 +145,24 @@
int bail = 0;
uint8_t d;
- d = tadpmu_status();
- while ((d & STATUS_HAVE_DATA) == 0) {
- delay(10);
- bail++;
- if (bail > 1000) {
- printf("%s: timeout waiting for data %02x\n", __func__, d);
- break;
+ if (cold) {
+ d = tadpmu_status();
+ while ((d & STATUS_HAVE_DATA) == 0) {
+ delay(10);
+ bail++;
+ if (bail > 1000) {
+ printf("%s: timeout waiting for data %02x\n",
+ __func__, d);
+ break;
+ }
+ d = tadpmu_status();
}
- d = tadpmu_status();
+ return bus_space_read_1(tadpmu_iot, tadpmu_hdata, 0);
+ } else {
+ while (ivalid == 0)
+ tsleep(tadpmu, 0, "pmucmd", 1);
+ return idata;
}
- return bus_space_read_1(tadpmu_iot, tadpmu_hdata, 0);
}
static void
@@ -194,6 +214,35 @@
}
}
+int
+tadpmu_intr(void *cookie)
+{
+ uint8_t s = tadpmu_status(), d;
+ if (s & STATUS_INTR) {
+ /* interrupt message */
+ d = tadpmu_data();
+ DPRINTF("status change %02x\n", d);
+ switch (d) {
+ case TADPMU_POWERBUTTON:
+ sysmon_pswitch_event(&tadpmu_pbutton,
+ PSWITCH_EVENT_PRESSED);
+ break;
+ case TADPMU_LID:
+ /* read genstat and report lid */
+ break;
+ }
+ }
+ s = tadpmu_status();
+ if (s & STATUS_HAVE_DATA) {
+ idata = tadpmu_data();
+ ivalid = 1;
+ wakeup(tadpmu);
+ DPRINTF("%s data %02x\n", __func__, idata);
+ }
+
+ return 1;
+}
+
int
tadpmu_init(bus_space_tag_t t, bus_space_handle_t hcmd, bus_space_handle_t hdata)
{
@@ -256,6 +305,14 @@
#endif
sysmon_envsys_register(tadpmu_sme);
+ sysmon_task_queue_init();
+ memset(&tadpmu_pbutton, 0, sizeof(struct sysmon_pswitch));
+ tadpmu_pbutton.smpsw_name = "tadpmu";
+ tadpmu_pbutton.smpsw_type = PSWITCH_TYPE_POWER;
+ if (sysmon_pswitch_register(&tadpmu_pbutton) != 0)
+ aprint_error(
+ "unable to register power button with sysmon\n");
+
return 0;
}
diff -r 65ec983e4312 -r 2db1c96d83fc sys/arch/sparc64/dev/tadpmureg.h
--- a/sys/arch/sparc64/dev/tadpmureg.h Sat Oct 13 15:38:28 2018 +0000
+++ b/sys/arch/sparc64/dev/tadpmureg.h Sat Oct 13 19:53:43 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tadpmureg.h,v 1.1 2018/10/12 21:44:32 macallan Exp $ */
+/* $NetBSD: tadpmureg.h,v 1.2 2018/10/13 19:53:43 macallan Exp $ */
/*-
* Copyright (c) 2018 Michael Lorenz <macallan%netbsd.org@localhost>
@@ -38,9 +38,10 @@
#define TADPMU_STATUS 0x6
#define TADPMU_DATA 0x2
-#define STATUS_HAVE_DATA 0x01
+#define STATUS_HAVE_DATA 0x01 /* response from command */
#define STATUS_CMD_IN_PROGRESS 0x02
-#define STATUS_SEND_DATA 0x08
+#define STATUS_INTR 0x04 /* interrupt happened, read data to ack */
+#define STATUS_SEND_DATA 0x08 /* cmd waiting for data */
#define CMD_SET_OPMODE 0x41 /* not sure what exactly this does... */
#define OPMODE_UNIX 0x75 /* other than toggling the UNIX mode */
@@ -80,6 +81,8 @@
#define GENSTAT2_MUTE 0x02
-
+/* messages from interrupts */
+#define TADPMU_LID 0x05
+#define TADPMU_POWERBUTTON 0x06
#endif /* TADPMUREG_H */
\ No newline at end of file
diff -r 65ec983e4312 -r 2db1c96d83fc sys/arch/sparc64/dev/tadpmuvar.h
--- a/sys/arch/sparc64/dev/tadpmuvar.h Sat Oct 13 15:38:28 2018 +0000
+++ b/sys/arch/sparc64/dev/tadpmuvar.h Sat Oct 13 19:53:43 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tadpmuvar.h,v 1.1 2018/10/12 21:44:32 macallan Exp $ */
+/* $NetBSD: tadpmuvar.h,v 1.2 2018/10/13 19:53:43 macallan Exp $ */
/*-
* Copyright (c) 2018 Michael Lorenz <macallan%netbsd.org@localhost>
@@ -32,5 +32,6 @@
#define TADPMUVAR_H
int tadpmu_init(bus_space_tag_t, bus_space_handle_t, bus_space_handle_t);
-
+int tadpmu_intr(void *);
+
#endif /* TADPMUVAR_H */
\ No newline at end of file
Home |
Main Index |
Thread Index |
Old Index