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