Deleted Added
full compact
pmu.c (194027) pmu.c (205506)
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 194027 2009-06-11 17:16:04Z avg $");
30__FBSDID("$FreeBSD: head/sys/powerpc/powermac/pmu.c 205506 2010-03-23 03:14:44Z nwhitehorn $");
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>
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/clock.h>
38#include <sys/sysctl.h>
39
40#include <dev/ofw/ofw_bus.h>
41#include <dev/ofw/openfirm.h>
42#include <dev/led/led.h>
43
44#include <machine/bus.h>
45#include <machine/intr.h>

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

50
51#include <vm/vm.h>
52#include <vm/pmap.h>
53
54#include <sys/rman.h>
55
56#include <dev/adb/adb.h>
57
39#include <sys/sysctl.h>
40
41#include <dev/ofw/ofw_bus.h>
42#include <dev/ofw/openfirm.h>
43#include <dev/led/led.h>
44
45#include <machine/bus.h>
46#include <machine/intr.h>

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

51
52#include <vm/vm.h>
53#include <vm/pmap.h>
54
55#include <sys/rman.h>
56
57#include <dev/adb/adb.h>
58
59#include "clock_if.h"
58#include "pmuvar.h"
59#include "viareg.h"
60
61/*
60#include "pmuvar.h"
61#include "viareg.h"
62
63/*
62 * MacIO interface
64 * Bus interface
63 */
64static int pmu_probe(device_t);
65static int pmu_attach(device_t);
66static int pmu_detach(device_t);
67
65 */
66static int pmu_probe(device_t);
67static int pmu_attach(device_t);
68static int pmu_detach(device_t);
69
70/*
71 * Clock interface
72 */
73static int pmu_gettime(device_t dev, struct timespec *ts);
74static int pmu_settime(device_t dev, struct timespec *ts);
75
76/*
77 * ADB Interface
78 */
79
68static u_int pmu_adb_send(device_t dev, u_char command_byte, int len,
69 u_char *data, u_char poll);
70static u_int pmu_adb_autopoll(device_t dev, uint16_t mask);
71static u_int pmu_poll(device_t dev);
72
73static void pmu_set_sleepled(void *xsc, int onoff);
74static int pmu_server_mode(SYSCTL_HANDLER_ARGS);
75static int pmu_acline_state(SYSCTL_HANDLER_ARGS);

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

105 DEVMETHOD(bus_print_child, bus_generic_print_child),
106 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
107
108 /* ADB bus interface */
109 DEVMETHOD(adb_hb_send_raw_packet, pmu_adb_send),
110 DEVMETHOD(adb_hb_controller_poll, pmu_poll),
111 DEVMETHOD(adb_hb_set_autopoll_mask, pmu_adb_autopoll),
112
80static u_int pmu_adb_send(device_t dev, u_char command_byte, int len,
81 u_char *data, u_char poll);
82static u_int pmu_adb_autopoll(device_t dev, uint16_t mask);
83static u_int pmu_poll(device_t dev);
84
85static void pmu_set_sleepled(void *xsc, int onoff);
86static int pmu_server_mode(SYSCTL_HANDLER_ARGS);
87static int pmu_acline_state(SYSCTL_HANDLER_ARGS);

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

117 DEVMETHOD(bus_print_child, bus_generic_print_child),
118 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
119
120 /* ADB bus interface */
121 DEVMETHOD(adb_hb_send_raw_packet, pmu_adb_send),
122 DEVMETHOD(adb_hb_controller_poll, pmu_poll),
123 DEVMETHOD(adb_hb_set_autopoll_mask, pmu_adb_autopoll),
124
125 /* Clock interface */
126 DEVMETHOD(clock_gettime, pmu_gettime),
127 DEVMETHOD(clock_settime, pmu_settime),
128
113 { 0, 0 },
114};
115
116static driver_t pmu_driver = {
117 "pmu",
118 pmu_methods,
119 sizeof(struct pmu_softc),
120};

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

448 }
449
450 /*
451 * Set up LED interface
452 */
453
454 sc->sc_leddev = led_create(pmu_set_sleepled, sc, "sleepled");
455
129 { 0, 0 },
130};
131
132static driver_t pmu_driver = {
133 "pmu",
134 pmu_methods,
135 sizeof(struct pmu_softc),
136};

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

464 }
465
466 /*
467 * Set up LED interface
468 */
469
470 sc->sc_leddev = led_create(pmu_set_sleepled, sc, "sleepled");
471
472 /*
473 * Register RTC
474 */
475
476 clock_register(dev, 1000);
477
456 return (bus_generic_attach(dev));
457}
458
459static int
460pmu_detach(device_t dev)
461{
462 struct pmu_softc *sc;
463

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

921 result = -1;
922 };
923
924 error = sysctl_handle_int(oidp, &result, 0, req);
925
926 return (error);
927}
928
478 return (bus_generic_attach(dev));
479}
480
481static int
482pmu_detach(device_t dev)
483{
484 struct pmu_softc *sc;
485

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

943 result = -1;
944 };
945
946 error = sysctl_handle_int(oidp, &result, 0, req);
947
948 return (error);
949}
950
951#define DIFF19041970 2082844800
952
953static int
954pmu_gettime(device_t dev, struct timespec *ts)
955{
956 struct pmu_softc *sc = device_get_softc(dev);
957 uint8_t resp[16];
958 uint32_t sec;
959
960 mtx_lock(&sc->sc_mutex);
961 pmu_send(sc, PMU_READ_RTC, 0, NULL, 16, resp);
962 mtx_unlock(&sc->sc_mutex);
963
964 memcpy(&sec, &resp[1], 4);
965 ts->tv_sec = sec - DIFF19041970;
966 ts->tv_nsec = 0;
967
968 return (0);
969}
970
971static int
972pmu_settime(device_t dev, struct timespec *ts)
973{
974 struct pmu_softc *sc = device_get_softc(dev);
975 uint32_t sec;
976
977 sec = ts->tv_sec + DIFF19041970;
978
979 mtx_lock(&sc->sc_mutex);
980 pmu_send(sc, PMU_SET_RTC, sizeof(sec), (uint8_t *)&sec, 0, NULL);
981 mtx_unlock(&sc->sc_mutex);
982
983 return (0);
984}
985