Skip to content

Instantly share code, notes, and snippets.

@classilla classilla/pmu.diff
Created Jun 27, 2019

Embed
What would you like to do?
Hack to enable automatic reboot after a power failure for NetBSD/macppc machines with pmu(4). Based on FreeBSD's.
--- pmu.c.orig 2019-06-26 19:18:48.350013535 -0700
+++ pmu.c 2019-06-26 19:30:25.636761664 -0700
@@ -148,16 +148,17 @@
/* i2c stuff */
#if 0
static int pmu_i2c_acquire_bus(void *, int);
static void pmu_i2c_release_bus(void *, int);
static int pmu_i2c_exec(void *, i2c_op_t, i2c_addr_t, const void *, size_t,
void *, size_t, int);
#endif
+static void pmu_server_mode(struct pmu_softc *);
static void pmu_attach_legacy_battery(struct pmu_softc *);
static void pmu_attach_smart_battery(struct pmu_softc *, int);
static int pmu_print(void *, const char *);
/* these values shows that number of data returned after 'send' cmd is sent */
static signed char pm_send_cmd_type[] = {
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
@@ -406,16 +407,19 @@
if (OF_getprop(pmnode, "prim-info", regs, sizeof(regs)) < 24)
goto bat_done;
nbat = regs[6] >> 16;
for (i = 0; i < nbat; i++)
pmu_attach_smart_battery(sc, i);
}
bat_done:
+ /* try to enable power fail mode */
+ pmu_server_mode(sc);
+
#if notyet
memset(&iba, 0, sizeof(iba));
iba.iba_tag = &sc->sc_i2c;
sc->sc_i2c.ic_cookie = sc;
sc->sc_i2c.ic_acquire_bus = pmu_i2c_acquire_bus;
sc->sc_i2c.ic_release_bus = pmu_i2c_release_bus;
sc->sc_i2c.ic_send_start = NULL;
sc->sc_i2c.ic_send_stop = NULL;
@@ -1081,16 +1085,38 @@
static int
pmu_print(void *aux, const char *what)
{
return 0;
}
static void
+pmu_server_mode(struct pmu_softc *sc)
+{
+ uint8_t getcmd[] = {PMU_PWR_GET_POWERUP_EVENTS};
+ uint8_t setcmd[3];
+ uint8_t resp[3];
+ int len;
+
+ len = pmu_send(sc, PMU_POWER_EVENTS, 1, getcmd, 3, resp);
+ if (len != 3) {
+ DPRINTF("pmu_server_mode query abnormal return length: %d\n",
+ len);
+ return;
+ }
+
+ setcmd[0] = PMU_PWR_SET_POWERUP_EVENTS;
+ setcmd[1] = resp[1];
+ setcmd[2] = PMU_PWR_WAKEUP_AC_INSERT;
+
+ (void)pmu_send(sc, PMU_POWER_EVENTS, 3, setcmd, 2, resp);
+}
+
+static void
pmu_attach_legacy_battery(struct pmu_softc *sc)
{
struct battery_attach_args baa;
baa.baa_type = BATTERY_TYPE_LEGACY;
baa.baa_pmu_ops = &sc->sc_pmu_ops;
config_found_ia(sc->sc_dev, "pmu_bus", &baa, pmu_print);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.