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