Index: src/sys/arch/sparc64/conf/files.sparc64
===================================================================
RCS file: /cvsroot/src/sys/arch/sparc64/conf/files.sparc64,v
retrieving revision 1.170
diff -u -r1.170 files.sparc64
--- src/sys/arch/sparc64/conf/files.sparc64	4 Jun 2026 13:57:03 -0000	1.170
+++ src/sys/arch/sparc64/conf/files.sparc64	8 Jun 2026 16:01:57 -0000
@@ -95,7 +95,7 @@
 attach rtc at ebus with rtc_ebus
 file	arch/sparc64/dev/rtc.c			rtc
 
-device bq4802rtc
+device bq4802rtc: sysmon_envsys
 attach bq4802rtc at ebus with bq4802rtc_ebus
 file	arch/sparc64/dev/bq4802_ebus.c		bq4802rtc
 
Index: src/sys/arch/sparc64/dev/bq4802_ebus.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sparc64/dev/bq4802_ebus.c,v
retrieving revision 1.2
diff -u -r1.2 bq4802_ebus.c
--- src/sys/arch/sparc64/dev/bq4802_ebus.c	16 Feb 2026 16:29:59 -0000	1.2
+++ src/sys/arch/sparc64/dev/bq4802_ebus.c	8 Jun 2026 16:01:57 -0000
@@ -39,6 +39,7 @@
 #include <sys/device.h>
 #include <sys/proc.h>
 #include <sys/types.h>
+#include <sys/sysctl.h>
 
 #include <sys/bus.h>
 #include <machine/autoconf.h>
@@ -49,13 +50,22 @@
 #include <dev/ebus/ebusreg.h>
 #include <dev/ebus/ebusvar.h>
 
+#include <dev/sysmon/sysmonvar.h>
+
+
 struct bq4802rtc_softc {
 	device_t	sc_dev;
 
-	struct		todr_chip_handle sc_tch;
+	struct todr_chip_handle	sc_tch;
+
+	bus_space_tag_t		sc_bst;	
+	bus_space_handle_t	sc_bsh;
+
+	struct sysmon_envsys    *sc_sme;	/* envsys config. */
+	envsys_data_t		sc_sensor;
+	int			sc_bvf;		/* Battery valid flag */
 
-	bus_space_tag_t sc_bst;	
-	bus_space_handle_t sc_bsh;
+	int			sc_osc_stp;	/* Oscillator stop (sysctl) */
 };
 
 static int	bq4802rtc_ebus_match(device_t, cfdata_t, void *);
@@ -64,6 +74,8 @@
 		    struct clock_ymdhms *);
 static int	bq4802_settime_ymdhms(struct todr_chip_handle *,
 		    struct clock_ymdhms *);
+void		bq4802_refresh(struct sysmon_envsys *, envsys_data_t *);
+static int	sysctl_bq4802_osc(SYSCTLFN_ARGS);
 
 CFATTACH_DECL_NEW(bq4802rtc_ebus, sizeof(struct bq4802rtc_softc),
     bq4802rtc_ebus_match, bq4802rtc_ebus_attach, NULL, NULL);
@@ -96,8 +108,9 @@
 	struct bq4802rtc_softc *sc = device_private(self);
 	struct ebus_attach_args *ea = aux;
 	todr_chip_handle_t tch = &sc->sc_tch;
+	const struct sysctlnode *me = NULL, *node = NULL;
 	int sz;
-	uint8_t ctrl;
+	uint8_t flags, ctrl;
 
 	sc->sc_dev = self;
 	sc->sc_bst = ea->ea_bustag;
@@ -121,10 +134,62 @@
 	/* Setup: alarms off, disable DST, enable updates, 24-hour mode */
 	ctrl = bq4802_read(sc, BQ4802_CTRL);
 	ctrl = ctrl & ~(BQ4802_CTRL_DSE | BQ4802_CTRL_UTI);
-	ctrl = ctrl | BQ4802_CTRL_24 | BQ4802_CTRL_STP;
+	ctrl = ctrl | BQ4802_CTRL_24;
 	bq4802_write(sc, BQ4802_CTRL, ctrl);
+	if (ctrl & BQ4802_CTRL_STP)
+		sc->sc_osc_stp = 0;
+	else {
+		aprint_error_dev(self,
+		    "WARNING: oscillator is stopped (0x%02x)\n", ctrl);
+		sc->sc_osc_stp = 1;
+	}
 
 	todr_attach(tch);
+
+	/* Setup envsys for the battery valid flag */
+	sc->sc_sme = sysmon_envsys_create();
+
+	sc->sc_sensor.units = ENVSYS_INDICATOR;
+	sc->sc_sensor.state = ENVSYS_SINVALID;
+	sc->sc_sensor.flags |= ENVSYS_FMONCRITICAL;
+	(void)strlcpy(sc->sc_sensor.desc, "battery low",
+	    sizeof(sc->sc_sensor.desc));
+	if (sysmon_envsys_sensor_attach(sc->sc_sme, &sc->sc_sensor)) {
+		sysmon_envsys_destroy(sc->sc_sme);
+		sc->sc_sme = NULL;
+		aprint_error_dev(self,
+		    "unable to attach sensor to sysmon\n");
+	} else {
+		sc->sc_sme->sme_name = device_xname(self);
+		sc->sc_sme->sme_cookie = sc;
+		sc->sc_sme->sme_refresh = bq4802_refresh;
+		flags = bq4802_read(sc, BQ4802_FLAGS);
+		sc->sc_bvf = flags & BQ4802_FLG_BVF;
+		if (sysmon_envsys_register(sc->sc_sme)) {
+			sysmon_envsys_destroy(sc->sc_sme);
+			sc->sc_sme = NULL;
+			aprint_error_dev(self,
+			    "unable to register with sysmon\n");
+		}
+	}
+
+	/* Setup sysctl for the oscillator control */
+	sysctl_createv(NULL, 0, NULL, &me,
+	    CTLFLAG_READWRITE,
+	    CTLTYPE_NODE, device_xname(self), NULL,
+	    NULL, 0, NULL, 0,
+	    CTL_HW, CTL_CREATE, CTL_EOL);
+	if (me == NULL)
+		aprint_error_dev(self, "unable to add sysctl root\n");
+	else {
+		sysctl_createv(NULL, 0, NULL, &node,
+		    CTLFLAG_READWRITE | CTLFLAG_OWNDESC,
+		    CTLTYPE_INT, "stop_oscillator", "Stop the chip oscillator",
+		    sysctl_bq4802_osc, 1, (void *)sc, 0,
+		    CTL_HW, me->sysctl_num, CTL_CREATE, CTL_EOL);
+		if (node == NULL)
+			aprint_error_dev(self, "unable to add sysctl node\n");
+	}
 }
 
 static int
@@ -182,3 +247,67 @@
 
 	return 0;
 }
+
+void
+bq4802_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
+{
+	struct bq4802rtc_softc *sc = sme->sme_cookie;
+
+	/*
+	 * The Battery valid flag is only set at power-up,
+	 * so we always return the saved value.
+	 */
+	if (sc->sc_bvf)
+		edata->state = ENVSYS_SVALID;
+	else
+		edata->state = ENVSYS_SCRITICAL;
+
+}
+
+static int
+sysctl_bq4802_osc(SYSCTLFN_ARGS)
+{
+	struct sysctlnode node = *rnode;
+	struct bq4802rtc_softc *sc = node.sysctl_data;
+	int stp;
+	uint8_t ctrl;
+
+	if (newp) {
+		/* write */
+		stp = sc->sc_osc_stp;
+		node.sysctl_data = &stp;
+		if (sysctl_lookup(SYSCTLFN_CALL(&node)) == 0) {
+			if (stp != 0 && stp != 1)
+				return EINVAL;
+
+			if (stp != sc->sc_osc_stp) {
+				sc->sc_osc_stp = stp;
+				ctrl = bq4802_read(sc, BQ4802_CTRL);
+				if (stp)
+					ctrl &= ~BQ4802_CTRL_STP;
+				else
+					ctrl |= BQ4802_CTRL_STP;
+				bq4802_write(sc, BQ4802_CTRL, ctrl);
+			}
+
+			return 0;
+		}
+		return EINVAL;
+	} else {
+		node.sysctl_data = &sc->sc_osc_stp;
+		node.sysctl_size = 4;
+		return (sysctl_lookup(SYSCTLFN_CALL(&node)));
+	}
+
+	return 0;
+}
+
+SYSCTL_SETUP(sysctl_bq4802_setup, "sysctl bq4802 subtree setup")
+{
+
+	sysctl_createv(NULL, 0, NULL, NULL,
+		       CTLFLAG_PERMANENT,
+		       CTLTYPE_NODE, "hw", NULL,
+		       NULL, 0, NULL, 0,
+		       CTL_HW, CTL_EOL);
+}
Index: src/distrib/sets/lists/man/mi
===================================================================
RCS file: /cvsroot/src/distrib/sets/lists/man/mi,v
retrieving revision 1.1833
diff -u -r1.1833 mi
--- src/distrib/sets/lists/man/mi	4 Jun 2026 14:22:21 -0000	1.1833
+++ src/distrib/sets/lists/man/mi	8 Jun 2026 16:01:58 -0000
@@ -1070,6 +1070,7 @@
 ./usr/share/man/cat4/bochsfb.0			man-sys-catman		.cat
 ./usr/share/man/cat4/bpf.0			man-sys-catman		.cat
 ./usr/share/man/cat4/bpfjit.0			man-sys-catman		.cat
+./usr/share/man/cat4/bq4802rtc.0		man-sys-catman		.cat
 ./usr/share/man/cat4/brgphy.0			man-sys-catman		.cat
 ./usr/share/man/cat4/bridge.0			man-sys-catman		.cat
 ./usr/share/man/cat4/bt.0			man-sys-catman		.cat
@@ -4670,6 +4671,7 @@
 ./usr/share/man/man4/bochsfb.4			man-sys-man		.man
 ./usr/share/man/man4/bpf.4			man-sys-man		.man
 ./usr/share/man/man4/bpfjit.4			man-sys-man		.man
+./usr/share/man/man4/bq4802rtc.4		man-sys-man		.man
 ./usr/share/man/man4/brgphy.4			man-sys-man		.man
 ./usr/share/man/man4/bridge.4			man-sys-man		.man
 ./usr/share/man/man4/bt.4			man-sys-man		.man
Index: src/distrib/sets/lists/manhtml/mi
===================================================================
RCS file: /cvsroot/src/distrib/sets/lists/manhtml/mi,v
retrieving revision 1.51
diff -u -r1.51 mi
--- src/distrib/sets/lists/manhtml/mi	4 Jun 2026 14:22:21 -0000	1.51
+++ src/distrib/sets/lists/manhtml/mi	8 Jun 2026 16:01:58 -0000
@@ -953,6 +953,7 @@
 ./usr/share/man/html4/bochsfb.html		man-sys-htmlman		html
 ./usr/share/man/html4/bpf.html			man-sys-htmlman		html
 ./usr/share/man/html4/bpfjit.html		man-sys-htmlman		html
+./usr/share/man/html4/bq4802rtc.html		man-sys-htmlman		html
 ./usr/share/man/html4/brgphy.html		man-sys-htmlman		html
 ./usr/share/man/html4/bridge.html		man-sys-htmlman		html
 ./usr/share/man/html4/bt.html			man-sys-htmlman		html
Index: src/share/man/man4/Makefile
===================================================================
RCS file: /cvsroot/src/share/man/man4/Makefile,v
retrieving revision 1.752
diff -u -r1.752 Makefile
--- src/share/man/man4/Makefile	3 Jun 2026 15:23:44 -0000	1.752
+++ src/share/man/man4/Makefile	8 Jun 2026 16:01:58 -0000
@@ -13,7 +13,7 @@
 	auixp.4 autri.4 auvia.4 awi.4 \
 	battery_pmu.4 bba.4 bce.4 bcsp.4 be.4 bge.4 bnx.4 bha.4 \
 	bio.4 bktr.4 bochsfb.4 bluetooth.4 bmx280thp.4 bmtphy.4 bpf.4 bpfjit.4 \
-	brgphy.4 bridge.4 bthidev.4 bthub.4 btkbd.4 \
+	bq4802rtc.4 brgphy.4 bridge.4 bthidev.4 bthub.4 btkbd.4 \
 	btmagic.4 btms.4 btsco.4 btuart.4 \
 	bwfm.4 bwi.4 \
 	cac.4 can.4 canloop.4 cardbus.4 carp.4 cas.4 ccd.4 cd.4 \
