apc.c revision 1.1.6.2 1 1.1.6.2 yamt /* $NetBSD: apc.c,v 1.1.6.2 2010/03/11 15:02:56 yamt Exp $ */
2 1.1.6.2 yamt
3 1.1.6.2 yamt /*
4 1.1.6.2 yamt * Copyright (c) 2010 Manuel Bouyer.
5 1.1.6.2 yamt *
6 1.1.6.2 yamt * Redistribution and use in source and binary forms, with or without
7 1.1.6.2 yamt * modification, are permitted provided that the following conditions
8 1.1.6.2 yamt * are met:
9 1.1.6.2 yamt * 1. Redistributions of source code must retain the above copyright
10 1.1.6.2 yamt * notice, this list of conditions and the following disclaimer.
11 1.1.6.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
12 1.1.6.2 yamt * notice, this list of conditions and the following disclaimer in the
13 1.1.6.2 yamt * documentation and/or other materials provided with the distribution.
14 1.1.6.2 yamt *
15 1.1.6.2 yamt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.1.6.2 yamt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 1.1.6.2 yamt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 1.1.6.2 yamt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 1.1.6.2 yamt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 1.1.6.2 yamt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 1.1.6.2 yamt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 1.1.6.2 yamt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 1.1.6.2 yamt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 1.1.6.2 yamt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 1.1.6.2 yamt */
26 1.1.6.2 yamt
27 1.1.6.2 yamt #include <sys/cdefs.h>
28 1.1.6.2 yamt __KERNEL_RCSID(0, "$NetBSD: apc.c,v 1.1.6.2 2010/03/11 15:02:56 yamt Exp $");
29 1.1.6.2 yamt
30 1.1.6.2 yamt
31 1.1.6.2 yamt /*
32 1.1.6.2 yamt * driver for the power management functions of the Aurora Personality Chip
33 1.1.6.2 yamt * on SPARCstation-4/5 and derivatives
34 1.1.6.2 yamt */
35 1.1.6.2 yamt
36 1.1.6.2 yamt #include <sys/param.h>
37 1.1.6.2 yamt #include <sys/systm.h>
38 1.1.6.2 yamt #include <sys/errno.h>
39 1.1.6.2 yamt #include <sys/device.h>
40 1.1.6.2 yamt #include <sys/bus.h>
41 1.1.6.2 yamt
42 1.1.6.2 yamt #include <machine/autoconf.h>
43 1.1.6.2 yamt
44 1.1.6.2 yamt #include <sparc/dev/apcreg.h>
45 1.1.6.2 yamt
46 1.1.6.2 yamt static int apcmatch(device_t, struct cfdata *, void *);
47 1.1.6.2 yamt static void apcattach(device_t, device_t, void *);
48 1.1.6.2 yamt static void apc_cpu_sleep(struct cpu_info *);
49 1.1.6.2 yamt
50 1.1.6.2 yamt struct apc_softc {
51 1.1.6.2 yamt device_t sc_dev;
52 1.1.6.2 yamt bus_space_tag_t sc_bt;
53 1.1.6.2 yamt bus_space_handle_t sc_bh;
54 1.1.6.2 yamt };
55 1.1.6.2 yamt
56 1.1.6.2 yamt struct apc_softc *apc = NULL;
57 1.1.6.2 yamt
58 1.1.6.2 yamt CFATTACH_DECL_NEW(apc, sizeof(struct apc_softc),
59 1.1.6.2 yamt apcmatch, apcattach, NULL, NULL);
60 1.1.6.2 yamt
61 1.1.6.2 yamt
62 1.1.6.2 yamt static int
63 1.1.6.2 yamt apcmatch(device_t parent, struct cfdata *cf, void *aux)
64 1.1.6.2 yamt {
65 1.1.6.2 yamt struct sbus_attach_args *sa = aux;
66 1.1.6.2 yamt if (apc != NULL) /* only one instance */
67 1.1.6.2 yamt return 0;
68 1.1.6.2 yamt return strcmp("power-management", sa->sa_name) == 0;
69 1.1.6.2 yamt }
70 1.1.6.2 yamt
71 1.1.6.2 yamt static void
72 1.1.6.2 yamt apcattach(device_t parent, device_t self, void *aux)
73 1.1.6.2 yamt {
74 1.1.6.2 yamt struct sbus_attach_args *sa = aux;
75 1.1.6.2 yamt struct apc_softc *sc = device_private(self);
76 1.1.6.2 yamt
77 1.1.6.2 yamt sc->sc_bt = sa->sa_bustag;
78 1.1.6.2 yamt if (sbus_bus_map(sa->sa_bustag,
79 1.1.6.2 yamt sa->sa_slot, sa->sa_offset, APC_REG_SIZE, 0, &sc->sc_bh) != 0) {
80 1.1.6.2 yamt aprint_error(": cannot map registers\n");
81 1.1.6.2 yamt return;
82 1.1.6.2 yamt }
83 1.1.6.2 yamt aprint_normal("\n");
84 1.1.6.2 yamt apc = sc;
85 1.1.6.2 yamt curcpu()->idlespin = apc_cpu_sleep;
86 1.1.6.2 yamt }
87 1.1.6.2 yamt
88 1.1.6.2 yamt static void
89 1.1.6.2 yamt apc_cpu_sleep(struct cpu_info *ci)
90 1.1.6.2 yamt {
91 1.1.6.2 yamt uint8_t val;
92 1.1.6.2 yamt if (apc == NULL)
93 1.1.6.2 yamt return;
94 1.1.6.2 yamt val = bus_space_read_1(apc->sc_bt, apc->sc_bh, APC_IDLE_REG);
95 1.1.6.2 yamt bus_space_write_1(apc->sc_bt, apc->sc_bh, APC_IDLE_REG,
96 1.1.6.2 yamt val | APC_IDLE_REG_IDLE);
97 1.1.6.2 yamt }
98