From owner-svn-src-all@FreeBSD.ORG Sun Oct 12 19:12:49 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C8B01EE; Sun, 12 Oct 2014 19:12:49 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B40B0C84; Sun, 12 Oct 2014 19:12:49 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s9CJCnZr021170; Sun, 12 Oct 2014 19:12:49 GMT (envelope-from jhibbits@FreeBSD.org) Received: (from jhibbits@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s9CJCncl021168; Sun, 12 Oct 2014 19:12:49 GMT (envelope-from jhibbits@FreeBSD.org) Message-Id: <201410121912.s9CJCncl021168@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: jhibbits set sender to jhibbits@FreeBSD.org using -f From: Justin Hibbits Date: Sun, 12 Oct 2014 19:12:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r273009 - in head: etc/devd sys/powerpc/powermac X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Oct 2014 19:12:50 -0000 Author: jhibbits Date: Sun Oct 12 19:12:48 2014 New Revision: 273009 URL: https://svnweb.freebsd.org/changeset/base/273009 Log: Add an AC line monitor so power_profile can work Summary: Add a polling loop (1Hz) to monitor the battery and AC status, to notify devd like ACPI does for power monitoring. This allows /etc/rc.d/power_profile to work on PowerPC laptops Test Plan: Tested on a Titanium PowerBook, configuring economy_cpu_freq and performance_cpu_freq, disabling powerd. Reviewers: #powerpc, nwhitehorn Reviewed By: nwhitehorn Subscribers: rpaulo Differential Revision: https://reviews.freebsd.org/D937 Modified: head/etc/devd/apple.conf head/sys/powerpc/powermac/pmu.c Modified: head/etc/devd/apple.conf ============================================================================== --- head/etc/devd/apple.conf Sun Oct 12 18:57:22 2014 (r273008) +++ head/etc/devd/apple.conf Sun Oct 12 19:12:48 2014 (r273009) @@ -71,4 +71,10 @@ notify 0 { action "camcontrol eject cd0"; }; - +# Equivalent to the ACPI/ACAD notify +notify 10 { + match "system" "PMU"; + match "subsystem" "POWER"; + match "type" "ACLINE"; + action "/etc/rc.d/power_profile $notify"; +} Modified: head/sys/powerpc/powermac/pmu.c ============================================================================== --- head/sys/powerpc/powermac/pmu.c Sun Oct 12 18:57:22 2014 (r273008) +++ head/sys/powerpc/powermac/pmu.c Sun Oct 12 19:12:48 2014 (r273009) @@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -183,6 +184,9 @@ static int pmu_send(void *cookie, int cm static uint8_t pmu_read_reg(struct pmu_softc *sc, u_int offset); static void pmu_write_reg(struct pmu_softc *sc, u_int offset, uint8_t value); static int pmu_intr_state(struct pmu_softc *); +static void pmu_battquery_proc(void); +static void pmu_battery_notify(struct pmu_battstate *batt, + struct pmu_battstate *old); /* these values shows that number of data returned after 'send' cmd is sent */ static signed char pm_send_cmd_type[] = { @@ -256,6 +260,13 @@ static signed char pm_receive_cmd_type[] -1, -1, -1, -1, -1, -1, -1, -1, }; +static struct proc *pmubattproc; +static struct kproc_desc pmu_batt_kp = { + "pmu_batt", + pmu_battquery_proc, + &pmubattproc +}; + /* We only have one of each device, so globals are safe */ static device_t pmu = NULL; static device_t pmu_extint = NULL; @@ -420,6 +431,8 @@ pmu_attach(device_t dev) struct sysctl_oid *oid, *battroot; char battnum[2]; + /* Only start the battery monitor if we have a battery. */ + kproc_start(&pmu_batt_kp); SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "acline", CTLTYPE_INT | CTLFLAG_RD, sc, 0, pmu_acline_state, "I", "AC Line Status"); @@ -914,6 +927,39 @@ pmu_query_battery(struct pmu_softc *sc, return (0); } +static void +pmu_battery_notify(struct pmu_battstate *batt, struct pmu_battstate *old) +{ + char notify_buf[16]; + int acline; + + acline = (batt->state & PMU_PWR_AC_PRESENT) ? 1 : 0; + if (acline != (old->state & PMU_PWR_AC_PRESENT)) { + snprintf(notify_buf, sizeof(notify_buf), + "notify=0x%02x", acline); + devctl_notify("PMU", "POWER", "ACLINE", notify_buf); + } +} + +static void +pmu_battquery_proc() +{ + struct pmu_softc *sc; + struct pmu_battstate batt; + struct pmu_battstate cur_batt; + int error; + + sc = device_get_softc(pmu); + + error = pmu_query_battery(sc, 0, &cur_batt); + while (1) { + error = pmu_query_battery(sc, 0, &batt); + pmu_battery_notify(&batt, &cur_batt); + cur_batt = batt; + pause("pmu_batt", hz); + } +} + static int pmu_acline_state(SYSCTL_HANDLER_ARGS) {