Deleted Added
full compact
pmu.c (184473) pmu.c (185727)
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:

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

24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 */
30
31#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:

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

24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/powerpc/powermac/pmu.c 184473 2008-10-30 15:27:13Z nwhitehorn $");
32__FBSDID("$FreeBSD: head/sys/powerpc/powermac/pmu.c 185727 2008-12-07 00:42:15Z nwhitehorn $");
33
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/module.h>
37#include <sys/bus.h>
38#include <sys/conf.h>
39#include <sys/kernel.h>
33
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/module.h>
37#include <sys/bus.h>
38#include <sys/conf.h>
39#include <sys/kernel.h>
40#include <sys/sysctl.h>
40
41#include <dev/ofw/ofw_bus.h>
42#include <dev/ofw/openfirm.h>
43
44#include <machine/bus.h>
45#include <machine/intr.h>
46#include <machine/intr_machdep.h>
47#include <machine/md_var.h>

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

60
61/*
62 * MacIO interface
63 */
64static int pmu_probe(device_t);
65static int pmu_attach(device_t);
66static int pmu_detach(device_t);
67
41
42#include <dev/ofw/ofw_bus.h>
43#include <dev/ofw/openfirm.h>
44
45#include <machine/bus.h>
46#include <machine/intr.h>
47#include <machine/intr_machdep.h>
48#include <machine/md_var.h>

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

61
62/*
63 * MacIO interface
64 */
65static int pmu_probe(device_t);
66static int pmu_attach(device_t);
67static int pmu_detach(device_t);
68
68static u_int pmu_adb_send(device_t dev, u_char command_byte, int len,
69static u_int pmu_adb_send(device_t dev, u_char command_byte, int len,
69 u_char *data, u_char poll);
70 u_char *data, u_char poll);
70static u_int pmu_adb_autopoll(device_t dev, uint16_t mask);
71static void pmu_poll(device_t dev);
71static u_int pmu_adb_autopoll(device_t dev, uint16_t mask);
72static void pmu_poll(device_t dev);
73static int pmu_server_mode(SYSCTL_HANDLER_ARGS);
72
73static device_method_t pmu_methods[] = {
74 /* Device interface */
75 DEVMETHOD(device_probe, pmu_probe),
76 DEVMETHOD(device_attach, pmu_attach),
77 DEVMETHOD(device_detach, pmu_detach),
78 DEVMETHOD(device_shutdown, bus_generic_shutdown),
79 DEVMETHOD(device_suspend, bus_generic_suspend),

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

277pmu_attach(device_t dev)
278{
279 struct pmu_softc *sc;
280
281 uint8_t reg;
282 uint8_t cmd[2] = {2, 0};
283 uint8_t resp[16];
284 phandle_t node,child;
74
75static device_method_t pmu_methods[] = {
76 /* Device interface */
77 DEVMETHOD(device_probe, pmu_probe),
78 DEVMETHOD(device_attach, pmu_attach),
79 DEVMETHOD(device_detach, pmu_detach),
80 DEVMETHOD(device_shutdown, bus_generic_shutdown),
81 DEVMETHOD(device_suspend, bus_generic_suspend),

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

279pmu_attach(device_t dev)
280{
281 struct pmu_softc *sc;
282
283 uint8_t reg;
284 uint8_t cmd[2] = {2, 0};
285 uint8_t resp[16];
286 phandle_t node,child;
287 struct sysctl_ctx_list *ctx;
288 struct sysctl_oid *tree;
285
286 sc = device_get_softc(dev);
287 sc->sc_dev = dev;
288
289 sc->sc_memrid = 0;
290 sc->sc_memr = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
291 &sc->sc_memrid, RF_ACTIVE);
292

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

336 if (bootverbose)
337 device_printf(dev, "PMU child <%s>\n",name);
338
339 if (strncmp(name, "adb", 4) == 0) {
340 sc->adb_bus = device_add_child(dev,"adb",-1);
341 }
342 }
343
289
290 sc = device_get_softc(dev);
291 sc->sc_dev = dev;
292
293 sc->sc_memrid = 0;
294 sc->sc_memr = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
295 &sc->sc_memrid, RF_ACTIVE);
296

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

340 if (bootverbose)
341 device_printf(dev, "PMU child <%s>\n",name);
342
343 if (strncmp(name, "adb", 4) == 0) {
344 sc->adb_bus = device_add_child(dev,"adb",-1);
345 }
346 }
347
348 /*
349 * Set up sysctls
350 */
351
352 ctx = device_get_sysctl_ctx(dev);
353 tree = device_get_sysctl_tree(dev);
354
355 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
356 "server_mode", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
357 pmu_server_mode, "I", "Enable reboot after power failure");
358
344 return (bus_generic_attach(dev));
345}
346
347static int
348pmu_detach(device_t dev)
349{
350 struct pmu_softc *sc;
351

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

608 pmu_send(sc, PMU_ADB_CMD, 4, cmd, 16, resp);
609 else
610 pmu_send(sc, PMU_ADB_POLL_OFF, 0, NULL, 16, resp);
611
612 mtx_unlock(&sc->sc_mutex);
613
614 return 0;
615}
359 return (bus_generic_attach(dev));
360}
361
362static int
363pmu_detach(device_t dev)
364{
365 struct pmu_softc *sc;
366

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

623 pmu_send(sc, PMU_ADB_CMD, 4, cmd, 16, resp);
624 else
625 pmu_send(sc, PMU_ADB_POLL_OFF, 0, NULL, 16, resp);
626
627 mtx_unlock(&sc->sc_mutex);
628
629 return 0;
630}
631
632static int
633pmu_server_mode(SYSCTL_HANDLER_ARGS)
634{
635 struct pmu_softc *sc = arg1;
636
637 u_int server_mode = 0;
638 uint8_t getcmd[] = {PMU_PWR_GET_POWERUP_EVENTS};
639 uint8_t setcmd[] = {0, 0, PMU_PWR_WAKEUP_AC_INSERT};
640 uint8_t resp[3];
641 int error, len;
642
643 mtx_lock(&sc->sc_mutex);
644 len = pmu_send(sc, PMU_POWER_EVENTS, 1, getcmd, 3, resp);
645 mtx_unlock(&sc->sc_mutex);
646
647 if (len == 3)
648 server_mode = (resp[2] & PMU_PWR_WAKEUP_AC_INSERT) ? 1 : 0;
649
650 error = sysctl_handle_int(oidp, &server_mode, 0, req);
651
652 if (len != 3)
653 return (EINVAL);
654
655 if (error || !req->newptr)
656 return (error);
657
658 if (server_mode == 1)
659 setcmd[0] = PMU_PWR_SET_POWERUP_EVENTS;
660 else if (server_mode == 0)
661 setcmd[0] = PMU_PWR_CLR_POWERUP_EVENTS;
662 else
663 return (EINVAL);
664
665 setcmd[1] = resp[1];
666
667 mtx_lock(&sc->sc_mutex);
668 pmu_send(sc, PMU_POWER_EVENTS, 3, setcmd, 2, resp);
669 mtx_unlock(&sc->sc_mutex);
670
671 return (0);
672}
673