Deleted Added
full compact
pmu.c (273009) pmu.c (273113)
1/*-
2 * Copyright (c) 2006 Michael Lorenz
3 * Copyright 2008 by Nathan Whitehorn
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 13 unchanged lines hidden (view full) ---

22 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 */
28
29#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2006 Michael Lorenz
3 * Copyright 2008 by Nathan Whitehorn
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 13 unchanged lines hidden (view full) ---

22 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/sys/powerpc/powermac/pmu.c 273009 2014-10-12 19:12:48Z jhibbits $");
30__FBSDID("$FreeBSD: head/sys/powerpc/powermac/pmu.c 273113 2014-10-15 02:31:14Z jhibbits $");
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/module.h>
35#include <sys/bus.h>
36#include <sys/conf.h>
37#include <sys/kernel.h>
38#include <sys/kthread.h>

--- 60 unchanged lines hidden (view full) ---

99
100static void pmu_shutdown(void *xsc, int howto);
101static void pmu_set_sleepled(void *xsc, int onoff);
102static int pmu_server_mode(SYSCTL_HANDLER_ARGS);
103static int pmu_acline_state(SYSCTL_HANDLER_ARGS);
104static int pmu_query_battery(struct pmu_softc *sc, int batt,
105 struct pmu_battstate *info);
106static int pmu_battquery_sysctl(SYSCTL_HANDLER_ARGS);
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/module.h>
35#include <sys/bus.h>
36#include <sys/conf.h>
37#include <sys/kernel.h>
38#include <sys/kthread.h>

--- 60 unchanged lines hidden (view full) ---

99
100static void pmu_shutdown(void *xsc, int howto);
101static void pmu_set_sleepled(void *xsc, int onoff);
102static int pmu_server_mode(SYSCTL_HANDLER_ARGS);
103static int pmu_acline_state(SYSCTL_HANDLER_ARGS);
104static int pmu_query_battery(struct pmu_softc *sc, int batt,
105 struct pmu_battstate *info);
106static int pmu_battquery_sysctl(SYSCTL_HANDLER_ARGS);
107static int pmu_battmon(SYSCTL_HANDLER_ARGS);
108static void pmu_battquery_proc(void);
109static void pmu_battery_notify(struct pmu_battstate *batt,
110 struct pmu_battstate *old);
107
108/*
109 * List of battery-related sysctls we might ask for
110 */
111
112enum {
113 PMU_BATSYSCTL_PRESENT = 1 << 8,
114 PMU_BATSYSCTL_CHARGING = 2 << 8,

--- 64 unchanged lines hidden (view full) ---

179static void pmu_out(struct pmu_softc *sc);
180static void pmu_ack_on(struct pmu_softc *sc);
181static void pmu_ack_off(struct pmu_softc *sc);
182static int pmu_send(void *cookie, int cmd, int length, uint8_t *in_msg,
183 int rlen, uint8_t *out_msg);
184static uint8_t pmu_read_reg(struct pmu_softc *sc, u_int offset);
185static void pmu_write_reg(struct pmu_softc *sc, u_int offset, uint8_t value);
186static int pmu_intr_state(struct pmu_softc *);
111
112/*
113 * List of battery-related sysctls we might ask for
114 */
115
116enum {
117 PMU_BATSYSCTL_PRESENT = 1 << 8,
118 PMU_BATSYSCTL_CHARGING = 2 << 8,

--- 64 unchanged lines hidden (view full) ---

183static void pmu_out(struct pmu_softc *sc);
184static void pmu_ack_on(struct pmu_softc *sc);
185static void pmu_ack_off(struct pmu_softc *sc);
186static int pmu_send(void *cookie, int cmd, int length, uint8_t *in_msg,
187 int rlen, uint8_t *out_msg);
188static uint8_t pmu_read_reg(struct pmu_softc *sc, u_int offset);
189static void pmu_write_reg(struct pmu_softc *sc, u_int offset, uint8_t value);
190static int pmu_intr_state(struct pmu_softc *);
187static void pmu_battquery_proc(void);
188static void pmu_battery_notify(struct pmu_battstate *batt,
189 struct pmu_battstate *old);
190
191/* these values shows that number of data returned after 'send' cmd is sent */
192static signed char pm_send_cmd_type[] = {
193 -1, -1, -1, -1, -1, -1, -1, -1,
194 -1, -1, -1, -1, -1, -1, -1, -1,
195 0x01, 0x01, -1, -1, -1, -1, -1, -1,
196 0x00, 0x00, -1, -1, -1, -1, -1, 0x00,
197 -1, 0x00, 0x02, 0x01, 0x01, -1, -1, -1,

--- 57 unchanged lines hidden (view full) ---

255 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
256 0x02, 0x02, -1, -1, 0x02, -1, -1, -1,
257 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
258 -1, -1, 0x02, -1, -1, -1, -1, 0x00,
259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
260 -1, -1, -1, -1, -1, -1, -1, -1,
261};
262
191
192/* these values shows that number of data returned after 'send' cmd is sent */
193static signed char pm_send_cmd_type[] = {
194 -1, -1, -1, -1, -1, -1, -1, -1,
195 -1, -1, -1, -1, -1, -1, -1, -1,
196 0x01, 0x01, -1, -1, -1, -1, -1, -1,
197 0x00, 0x00, -1, -1, -1, -1, -1, 0x00,
198 -1, 0x00, 0x02, 0x01, 0x01, -1, -1, -1,

--- 57 unchanged lines hidden (view full) ---

256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
257 0x02, 0x02, -1, -1, 0x02, -1, -1, -1,
258 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
259 -1, -1, 0x02, -1, -1, -1, -1, 0x00,
260 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
261 -1, -1, -1, -1, -1, -1, -1, -1,
262};
263
264static int pmu_battmon_enabled = 1;
263static struct proc *pmubattproc;
264static struct kproc_desc pmu_batt_kp = {
265 "pmu_batt",
266 pmu_battquery_proc,
267 &pmubattproc
268};
269
270/* We only have one of each device, so globals are safe */

--- 158 unchanged lines hidden (view full) ---

429
430 if (sc->sc_batteries > 0) {
431 struct sysctl_oid *oid, *battroot;
432 char battnum[2];
433
434 /* Only start the battery monitor if we have a battery. */
435 kproc_start(&pmu_batt_kp);
436 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
265static struct proc *pmubattproc;
266static struct kproc_desc pmu_batt_kp = {
267 "pmu_batt",
268 pmu_battquery_proc,
269 &pmubattproc
270};
271
272/* We only have one of each device, so globals are safe */

--- 158 unchanged lines hidden (view full) ---

431
432 if (sc->sc_batteries > 0) {
433 struct sysctl_oid *oid, *battroot;
434 char battnum[2];
435
436 /* Only start the battery monitor if we have a battery. */
437 kproc_start(&pmu_batt_kp);
438 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
439 "monitor_batteries", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
440 pmu_battmon, "I", "Post battery events to devd");
441
442
443 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
437 "acline", CTLTYPE_INT | CTLFLAG_RD, sc, 0,
438 pmu_acline_state, "I", "AC Line Status");
439
440 battroot = SYSCTL_ADD_NODE(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
441 "batteries", CTLFLAG_RD, 0, "Battery Information");
442
443 for (i = 0; i < sc->sc_batteries; i++) {
444 battnum[0] = i + '0';

--- 481 unchanged lines hidden (view full) ---

926
927 return (0);
928}
929
930static void
931pmu_battery_notify(struct pmu_battstate *batt, struct pmu_battstate *old)
932{
933 char notify_buf[16];
444 "acline", CTLTYPE_INT | CTLFLAG_RD, sc, 0,
445 pmu_acline_state, "I", "AC Line Status");
446
447 battroot = SYSCTL_ADD_NODE(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
448 "batteries", CTLFLAG_RD, 0, "Battery Information");
449
450 for (i = 0; i < sc->sc_batteries; i++) {
451 battnum[0] = i + '0';

--- 481 unchanged lines hidden (view full) ---

933
934 return (0);
935}
936
937static void
938pmu_battery_notify(struct pmu_battstate *batt, struct pmu_battstate *old)
939{
940 char notify_buf[16];
934 int acline;
941 int new_acline, old_acline;
935
942
936 acline = (batt->state & PMU_PWR_AC_PRESENT) ? 1 : 0;
937 if (acline != (old->state & PMU_PWR_AC_PRESENT)) {
943 new_acline = (batt->state & PMU_PWR_AC_PRESENT) ? 1 : 0;
944 old_acline = (old->state & PMU_PWR_AC_PRESENT) ? 1 : 0;
945
946 if (new_acline != old_acline) {
938 snprintf(notify_buf, sizeof(notify_buf),
947 snprintf(notify_buf, sizeof(notify_buf),
939 "notify=0x%02x", acline);
948 "notify=0x%02x", new_acline);
940 devctl_notify("PMU", "POWER", "ACLINE", notify_buf);
941 }
942}
943
944static void
945pmu_battquery_proc()
946{
947 struct pmu_softc *sc;
948 struct pmu_battstate batt;
949 struct pmu_battstate cur_batt;
950 int error;
951
952 sc = device_get_softc(pmu);
953
949 devctl_notify("PMU", "POWER", "ACLINE", notify_buf);
950 }
951}
952
953static void
954pmu_battquery_proc()
955{
956 struct pmu_softc *sc;
957 struct pmu_battstate batt;
958 struct pmu_battstate cur_batt;
959 int error;
960
961 sc = device_get_softc(pmu);
962
954 error = pmu_query_battery(sc, 0, &cur_batt);
963 bzero(&cur_batt, sizeof(cur_batt));
955 while (1) {
964 while (1) {
965 kproc_suspend_check(curproc);
956 error = pmu_query_battery(sc, 0, &batt);
957 pmu_battery_notify(&batt, &cur_batt);
958 cur_batt = batt;
959 pause("pmu_batt", hz);
960 }
961}
962
963static int
966 error = pmu_query_battery(sc, 0, &batt);
967 pmu_battery_notify(&batt, &cur_batt);
968 cur_batt = batt;
969 pause("pmu_batt", hz);
970 }
971}
972
973static int
974pmu_battmon(SYSCTL_HANDLER_ARGS)
975{
976 struct pmu_softc *sc;
977 int error, result;
978
979 sc = arg1;
980 result = pmu_battmon_enabled;
981
982 error = sysctl_handle_int(oidp, &result, 0, req);
983
984 if (error || !req->newptr)
985 return (error);
986
987 if (!result && pmu_battmon_enabled)
988 error = kproc_suspend(pmubattproc, hz);
989 else if (result && pmu_battmon_enabled == 0)
990 error = kproc_resume(pmubattproc);
991 pmu_battmon_enabled = (result != 0);
992
993 return (error);
994}
995
996static int
964pmu_acline_state(SYSCTL_HANDLER_ARGS)
965{
966 struct pmu_softc *sc;
967 struct pmu_battstate batt;
968 int error, result;
969
970 sc = arg1;
971

--- 130 unchanged lines hidden ---
997pmu_acline_state(SYSCTL_HANDLER_ARGS)
998{
999 struct pmu_softc *sc;
1000 struct pmu_battstate batt;
1001 int error, result;
1002
1003 sc = arg1;
1004

--- 130 unchanged lines hidden ---