xref: /netbsd-src/sys/arch/sparc/dev/power.c (revision 8ad8b5528b902ecee850b92b95e10305695fcdc8)
1*8ad8b552Smatt /*	$NetBSD: power.c,v 1.19 2012/07/29 00:04:05 matt Exp $ */
266539854Spk 
366539854Spk /*
466539854Spk  * Copyright (c) 1996
54bbf23d0Sabrown  *	The President and Fellows of Harvard College. All rights reserved.
666539854Spk  *
766539854Spk  * All advertising materials mentioning features or use of this software
866539854Spk  * must display the following acknowledgement:
966539854Spk  *	This product includes software developed by Aaron Brown and
1066539854Spk  *	Harvard University.
1166539854Spk  *
1266539854Spk  * Redistribution and use in source and binary forms, with or without
1366539854Spk  * modification, are permitted provided that the following conditions
1466539854Spk  * are met:
1566539854Spk  *
1666539854Spk  * 1. Redistributions of source code must retain the above copyright
1766539854Spk  *    notice, this list of conditions and the following disclaimer.
1866539854Spk  * 2. Redistributions in binary form must reproduce the above copyright
1966539854Spk  *    notice, this list of conditions and the following disclaimer in the
2066539854Spk  *    documentation and/or other materials provided with the distribution.
2166539854Spk  * 3. All advertising materials mentioning features or use of this software
2266539854Spk  *    must display the following acknowledgement:
2366539854Spk  *	This product includes software developed by Harvard University
2466539854Spk  *	and its contributors.
2566539854Spk  * 4. Neither the name of the University nor the names of its contributors
2666539854Spk  *    may be used to endorse or promote products derived from this software
2766539854Spk  *    without specific prior written permission.
2866539854Spk  *
2966539854Spk  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
3066539854Spk  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3166539854Spk  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3266539854Spk  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3366539854Spk  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3466539854Spk  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3566539854Spk  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3666539854Spk  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3766539854Spk  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3866539854Spk  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3966539854Spk  * SUCH DAMAGE.
4066539854Spk  */
4166539854Spk 
42a4183603Slukem #include <sys/cdefs.h>
43*8ad8b552Smatt __KERNEL_RCSID(0, "$NetBSD: power.c,v 1.19 2012/07/29 00:04:05 matt Exp $");
44a4183603Slukem 
4566539854Spk #include <sys/param.h>
4666539854Spk #include <sys/device.h>
4766539854Spk #include <sys/kernel.h>
4866539854Spk #include <sys/systm.h>
4966539854Spk 
5066539854Spk #include <machine/autoconf.h>
5166539854Spk 
5266539854Spk #include <sparc/dev/power.h>
5366539854Spk 
54*8ad8b552Smatt volatile uint8_t *power_reg;
55*8ad8b552Smatt 
56ace9f0e4Smrg static int powermatch(device_t, cfdata_t, void *);
57ace9f0e4Smrg static void powerattach(device_t, device_t, void *);
5866539854Spk 
59ace9f0e4Smrg CFATTACH_DECL_NEW(power, 0, powermatch, powerattach, NULL, NULL);
6066539854Spk 
6166539854Spk /*
6266539854Spk  * This is the driver for the "power" register available on some Sun4m
6366539854Spk  * machines. This allows the machine to remove power automatically when
6466539854Spk  * shutdown or halted or whatever.
6566539854Spk  */
6666539854Spk 
6766539854Spk static int
powermatch(device_t parent,cfdata_t cf,void * aux)68ace9f0e4Smrg powermatch(device_t parent, cfdata_t cf, void *aux)
6966539854Spk {
7069fe6f24Spk 	union obio_attach_args *uoba = aux;
7169fe6f24Spk 	struct sbus_attach_args *sa = &uoba->uoba_sbus;
7266539854Spk 
7369fe6f24Spk 	if (uoba->uoba_isobio4 != 0)
7466539854Spk 		return (0);
7569fe6f24Spk 
7669fe6f24Spk 	return (strcmp("power", sa->sa_name) == 0);
7766539854Spk }
7866539854Spk 
7966539854Spk /* ARGSUSED */
8066539854Spk static void
powerattach(device_t parent,device_t self,void * aux)81ace9f0e4Smrg powerattach(device_t parent, device_t self, void *aux)
8266539854Spk {
8369fe6f24Spk 	union obio_attach_args *uoba = aux;
8469fe6f24Spk 	struct sbus_attach_args *sa = &uoba->uoba_sbus;
8569fe6f24Spk 	bus_space_handle_t bh;
8666539854Spk 
8769fe6f24Spk 	/* Map the power configuration register. */
8869fe6f24Spk 	if (sbus_bus_map(sa->sa_bustag,
8960ed1ea4Suwe 			 sa->sa_slot, sa->sa_offset, sizeof(uint8_t),
907e8becd6Spk 			 BUS_SPACE_MAP_LINEAR, &bh) != 0) {
91ace9f0e4Smrg 		printf("%s: cannot map register\n", device_xname(self));
9269fe6f24Spk 		return;
9369fe6f24Spk 	}
9460ed1ea4Suwe 	power_reg = (volatile uint8_t *)bh;
9566539854Spk 
968d9699acSchristos 	printf("\n");
9766539854Spk }
9866539854Spk 
9966539854Spk void
powerdown(void)10060ed1ea4Suwe powerdown(void)
10166539854Spk {
1021c6a275eSthorpej 	/* Only try if the power node was attached. */
1031c6a275eSthorpej 	if (power_reg != NULL)
10466539854Spk 		*POWER_REG |= POWER_OFF;
10507302111Sfair 
10607302111Sfair 	/*
10707302111Sfair 	 * don't return too quickly; the PROMs on some sparcs
10807302111Sfair 	 * report the powerdown as failed if we do.
10907302111Sfair 	 */
11007302111Sfair 	DELAY(1000000);
11166539854Spk }
112