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