xref: /linux/arch/mips/jazz/reset.c (revision 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2)
1*1da177e4SLinus Torvalds /*
2*1da177e4SLinus Torvalds  * Reset a Jazz machine.
3*1da177e4SLinus Torvalds  *
4*1da177e4SLinus Torvalds  * We don't trust the firmware so we do it the classic way by poking and
5*1da177e4SLinus Torvalds  * stabbing at the keyboard controller ...
6*1da177e4SLinus Torvalds  */
7*1da177e4SLinus Torvalds #include <linux/jiffies.h>
8*1da177e4SLinus Torvalds #include <asm/jazz.h>
9*1da177e4SLinus Torvalds #include <asm/io.h>
10*1da177e4SLinus Torvalds #include <asm/system.h>
11*1da177e4SLinus Torvalds #include <asm/reboot.h>
12*1da177e4SLinus Torvalds #include <asm/delay.h>
13*1da177e4SLinus Torvalds 
14*1da177e4SLinus Torvalds #define KBD_STAT_IBF		0x02	/* Keyboard input buffer full */
15*1da177e4SLinus Torvalds 
16*1da177e4SLinus Torvalds static void jazz_write_output(unsigned char val)
17*1da177e4SLinus Torvalds {
18*1da177e4SLinus Torvalds 	int status;
19*1da177e4SLinus Torvalds 
20*1da177e4SLinus Torvalds 	do {
21*1da177e4SLinus Torvalds 		status = jazz_kh->command;
22*1da177e4SLinus Torvalds 	} while (status & KBD_STAT_IBF);
23*1da177e4SLinus Torvalds 	jazz_kh->data = val;
24*1da177e4SLinus Torvalds }
25*1da177e4SLinus Torvalds 
26*1da177e4SLinus Torvalds static void jazz_write_command(unsigned char val)
27*1da177e4SLinus Torvalds {
28*1da177e4SLinus Torvalds 	int status;
29*1da177e4SLinus Torvalds 
30*1da177e4SLinus Torvalds 	do {
31*1da177e4SLinus Torvalds 		status = jazz_kh->command;
32*1da177e4SLinus Torvalds 	} while (status & KBD_STAT_IBF);
33*1da177e4SLinus Torvalds 	jazz_kh->command = val;
34*1da177e4SLinus Torvalds }
35*1da177e4SLinus Torvalds 
36*1da177e4SLinus Torvalds static unsigned char jazz_read_status(void)
37*1da177e4SLinus Torvalds {
38*1da177e4SLinus Torvalds 	return jazz_kh->command;
39*1da177e4SLinus Torvalds }
40*1da177e4SLinus Torvalds 
41*1da177e4SLinus Torvalds static inline void kb_wait(void)
42*1da177e4SLinus Torvalds {
43*1da177e4SLinus Torvalds 	unsigned long start = jiffies;
44*1da177e4SLinus Torvalds 	unsigned long timeout = start + HZ/2;
45*1da177e4SLinus Torvalds 
46*1da177e4SLinus Torvalds 	do {
47*1da177e4SLinus Torvalds 		if (! (jazz_read_status() & 0x02))
48*1da177e4SLinus Torvalds 			return;
49*1da177e4SLinus Torvalds 	} while (time_before_eq(jiffies, timeout));
50*1da177e4SLinus Torvalds }
51*1da177e4SLinus Torvalds 
52*1da177e4SLinus Torvalds void jazz_machine_restart(char *command)
53*1da177e4SLinus Torvalds {
54*1da177e4SLinus Torvalds 	while(1) {
55*1da177e4SLinus Torvalds 		kb_wait();
56*1da177e4SLinus Torvalds 		jazz_write_command (0xd1);
57*1da177e4SLinus Torvalds 		kb_wait();
58*1da177e4SLinus Torvalds 		jazz_write_output (0x00);
59*1da177e4SLinus Torvalds 	}
60*1da177e4SLinus Torvalds }
61*1da177e4SLinus Torvalds 
62*1da177e4SLinus Torvalds void jazz_machine_halt(void)
63*1da177e4SLinus Torvalds {
64*1da177e4SLinus Torvalds }
65*1da177e4SLinus Torvalds 
66*1da177e4SLinus Torvalds void jazz_machine_power_off(void)
67*1da177e4SLinus Torvalds {
68*1da177e4SLinus Torvalds 	/* Jazz machines don't have a software power switch */
69*1da177e4SLinus Torvalds }
70