1 /*	$OpenBSD: cmd_luna88k.c,v 1.1 2023/03/13 11:59:39 aoyama Exp $	*/
2 /*
3  * Copyright (c) 2023 Kenji Aoyama
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #include <sys/param.h>
19 #include <machine/board.h>
20 
21 #include <luna88k/stand/boot/samachdep.h>
22 #include <stand/boot/cmd.h>
23 
24 static int Xpoweroff(void);
25 
26 const struct cmd_table cmd_machine[] = {
27 	{ "poweroff",	CMDT_CMD, Xpoweroff },
28 	{ NULL, 0 }
29 };
30 
31 struct pio {
32 	volatile u_int8_t portA;
33 	volatile unsigned : 24;
34 	volatile u_int8_t portB;
35 	volatile unsigned : 24;
36 	volatile u_int8_t portC;
37 	volatile unsigned : 24;
38 	volatile u_int8_t cntrl;
39 	volatile unsigned : 24;
40 };
41 
42 #define	PIO1_POWER 0x04
43 #define PIO1_DISABLE 0x00
44 
45 static int
Xpoweroff(void)46 Xpoweroff(void)
47 {
48 	struct pio *p1 = (struct pio *)OBIO_PIO1_BASE;
49 
50 	printf("attempting to power down...\n");
51 
52 	p1->cntrl = (PIO1_POWER << 1) | PIO1_DISABLE;
53 	*(volatile u_int8_t *)&p1->portC;
54 
55 	DELAY(1000000);	/* wait for a while */
56 
57 	return 0;
58 }
59