1*0e79d963Sad /* $NetBSD: apc.c,v 1.2 2019/12/30 22:13:46 ad Exp $ */
23c5e1600Sbouyer
33c5e1600Sbouyer /*
43c5e1600Sbouyer * Copyright (c) 2010 Manuel Bouyer.
53c5e1600Sbouyer *
63c5e1600Sbouyer * Redistribution and use in source and binary forms, with or without
73c5e1600Sbouyer * modification, are permitted provided that the following conditions
83c5e1600Sbouyer * are met:
93c5e1600Sbouyer * 1. Redistributions of source code must retain the above copyright
103c5e1600Sbouyer * notice, this list of conditions and the following disclaimer.
113c5e1600Sbouyer * 2. Redistributions in binary form must reproduce the above copyright
123c5e1600Sbouyer * notice, this list of conditions and the following disclaimer in the
133c5e1600Sbouyer * documentation and/or other materials provided with the distribution.
143c5e1600Sbouyer *
153c5e1600Sbouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
163c5e1600Sbouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
173c5e1600Sbouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
183c5e1600Sbouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
193c5e1600Sbouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
203c5e1600Sbouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
213c5e1600Sbouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
223c5e1600Sbouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
233c5e1600Sbouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
243c5e1600Sbouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
253c5e1600Sbouyer */
263c5e1600Sbouyer
273c5e1600Sbouyer #include <sys/cdefs.h>
28*0e79d963Sad __KERNEL_RCSID(0, "$NetBSD: apc.c,v 1.2 2019/12/30 22:13:46 ad Exp $");
293c5e1600Sbouyer
303c5e1600Sbouyer
313c5e1600Sbouyer /*
323c5e1600Sbouyer * driver for the power management functions of the Aurora Personality Chip
333c5e1600Sbouyer * on SPARCstation-4/5 and derivatives
343c5e1600Sbouyer */
353c5e1600Sbouyer
363c5e1600Sbouyer #include <sys/param.h>
373c5e1600Sbouyer #include <sys/systm.h>
383c5e1600Sbouyer #include <sys/errno.h>
393c5e1600Sbouyer #include <sys/device.h>
403c5e1600Sbouyer #include <sys/bus.h>
413c5e1600Sbouyer
423c5e1600Sbouyer #include <machine/autoconf.h>
433c5e1600Sbouyer
443c5e1600Sbouyer #include <sparc/dev/apcreg.h>
453c5e1600Sbouyer
463c5e1600Sbouyer static int apcmatch(device_t, struct cfdata *, void *);
473c5e1600Sbouyer static void apcattach(device_t, device_t, void *);
48*0e79d963Sad static void apc_cpu_sleep(void);
493c5e1600Sbouyer
503c5e1600Sbouyer struct apc_softc {
513c5e1600Sbouyer device_t sc_dev;
523c5e1600Sbouyer bus_space_tag_t sc_bt;
533c5e1600Sbouyer bus_space_handle_t sc_bh;
543c5e1600Sbouyer };
553c5e1600Sbouyer
563c5e1600Sbouyer struct apc_softc *apc = NULL;
573c5e1600Sbouyer
583c5e1600Sbouyer CFATTACH_DECL_NEW(apc, sizeof(struct apc_softc),
593c5e1600Sbouyer apcmatch, apcattach, NULL, NULL);
603c5e1600Sbouyer
613c5e1600Sbouyer
623c5e1600Sbouyer static int
apcmatch(device_t parent,struct cfdata * cf,void * aux)633c5e1600Sbouyer apcmatch(device_t parent, struct cfdata *cf, void *aux)
643c5e1600Sbouyer {
653c5e1600Sbouyer struct sbus_attach_args *sa = aux;
663c5e1600Sbouyer if (apc != NULL) /* only one instance */
673c5e1600Sbouyer return 0;
683c5e1600Sbouyer return strcmp("power-management", sa->sa_name) == 0;
693c5e1600Sbouyer }
703c5e1600Sbouyer
713c5e1600Sbouyer static void
apcattach(device_t parent,device_t self,void * aux)723c5e1600Sbouyer apcattach(device_t parent, device_t self, void *aux)
733c5e1600Sbouyer {
743c5e1600Sbouyer struct sbus_attach_args *sa = aux;
753c5e1600Sbouyer struct apc_softc *sc = device_private(self);
763c5e1600Sbouyer
773c5e1600Sbouyer sc->sc_bt = sa->sa_bustag;
783c5e1600Sbouyer if (sbus_bus_map(sa->sa_bustag,
793c5e1600Sbouyer sa->sa_slot, sa->sa_offset, APC_REG_SIZE, 0, &sc->sc_bh) != 0) {
803c5e1600Sbouyer aprint_error(": cannot map registers\n");
813c5e1600Sbouyer return;
823c5e1600Sbouyer }
833c5e1600Sbouyer aprint_normal("\n");
843c5e1600Sbouyer apc = sc;
853c5e1600Sbouyer curcpu()->idlespin = apc_cpu_sleep;
863c5e1600Sbouyer }
873c5e1600Sbouyer
883c5e1600Sbouyer static void
apc_cpu_sleep(void)89*0e79d963Sad apc_cpu_sleep(void)
903c5e1600Sbouyer {
913c5e1600Sbouyer uint8_t val;
923c5e1600Sbouyer if (apc == NULL)
933c5e1600Sbouyer return;
943c5e1600Sbouyer val = bus_space_read_1(apc->sc_bt, apc->sc_bh, APC_IDLE_REG);
953c5e1600Sbouyer bus_space_write_1(apc->sc_bt, apc->sc_bh, APC_IDLE_REG,
963c5e1600Sbouyer val | APC_IDLE_REG_IDLE);
973c5e1600Sbouyer }
98