19890ff83SToomas Soome /*
2199767f8SToomas Soome  * spinconsole.c
3199767f8SToomas Soome  *
4199767f8SToomas Soome  * Author: Maksym Sobolyev <sobomax@sippysoft.com>
5199767f8SToomas Soome  * Copyright (c) 2009 Sippy Software, Inc.
6199767f8SToomas Soome  * All rights reserved.
79890ff83SToomas Soome  *
8199767f8SToomas Soome  * Subject to the following obligations and disclaimer of warranty, use and
9199767f8SToomas Soome  * redistribution of this software, in source or object code forms, with or
10199767f8SToomas Soome  * without modifications are expressly permitted by Whistle Communications;
11199767f8SToomas Soome  * provided, however, that:
12199767f8SToomas Soome  * 1. Any and all reproductions of the source or object code must include the
13199767f8SToomas Soome  *    copyright notice above and the following disclaimer of warranties; and
14199767f8SToomas Soome  * 2. No rights are granted, in any manner or form, to use Whistle
15199767f8SToomas Soome  *    Communications, Inc. trademarks, including the mark "WHISTLE
16199767f8SToomas Soome  *    COMMUNICATIONS" on advertising, endorsements, or otherwise except as
17199767f8SToomas Soome  *    such appears in the above copyright notice or in the software.
189890ff83SToomas Soome  *
19199767f8SToomas Soome  * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
20199767f8SToomas Soome  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
21199767f8SToomas Soome  * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
22199767f8SToomas Soome  * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
23199767f8SToomas Soome  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
24199767f8SToomas Soome  * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
25199767f8SToomas Soome  * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
26199767f8SToomas Soome  * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
27199767f8SToomas Soome  * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
28199767f8SToomas Soome  * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
29199767f8SToomas Soome  * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
30199767f8SToomas Soome  * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
31199767f8SToomas Soome  * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
32199767f8SToomas Soome  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33199767f8SToomas Soome  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34199767f8SToomas Soome  * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
35199767f8SToomas Soome  * OF SUCH DAMAGE.
36199767f8SToomas Soome  */
37199767f8SToomas Soome 
38199767f8SToomas Soome #include <sys/cdefs.h>
39199767f8SToomas Soome 
40199767f8SToomas Soome #include <stand.h>
41199767f8SToomas Soome #include <bootstrap.h>
42199767f8SToomas Soome 
43199767f8SToomas Soome 
44199767f8SToomas Soome static void	spinc_probe(struct console *cp);
45199767f8SToomas Soome static int	spinc_init(struct console *cp, int arg);
46199767f8SToomas Soome static void	spinc_putchar(struct console *cp, int c);
47199767f8SToomas Soome static int	spinc_getchar(struct console *cp);
48199767f8SToomas Soome static int	spinc_ischar(struct console *cp);
4980e47917SToomas Soome static void	spinc_devinfo(struct console *cp);
50199767f8SToomas Soome 
51199767f8SToomas Soome struct console spinconsole = {
5230c75cb0SToomas Soome 	.c_name = "spin",
5330c75cb0SToomas Soome 	.c_desc = "spin port",
5430c75cb0SToomas Soome 	.c_flags = 0,
5530c75cb0SToomas Soome 	.c_probe = spinc_probe,
5630c75cb0SToomas Soome 	.c_init = spinc_init,
5730c75cb0SToomas Soome 	.c_out = spinc_putchar,
5830c75cb0SToomas Soome 	.c_in = spinc_getchar,
5930c75cb0SToomas Soome 	.c_ready = spinc_ischar,
609890ff83SToomas Soome 	.c_ioctl = NULL,
6180e47917SToomas Soome 	.c_devinfo = spinc_devinfo,
6230c75cb0SToomas Soome 	.c_private = NULL
63199767f8SToomas Soome };
64199767f8SToomas Soome 
6580e47917SToomas Soome static void
spinc_devinfo(struct console * cp __unused)6680e47917SToomas Soome spinc_devinfo(struct console *cp __unused)
6780e47917SToomas Soome {
6880e47917SToomas Soome 	printf("\tsoftware device");
6980e47917SToomas Soome }
7080e47917SToomas Soome 
71199767f8SToomas Soome static void
spinc_probe(struct console * cp)72199767f8SToomas Soome spinc_probe(struct console *cp)
73199767f8SToomas Soome {
7490c559d0SToomas Soome 	int i;
7590c559d0SToomas Soome 	struct console *parent;
7690c559d0SToomas Soome 
7790c559d0SToomas Soome 	if (cp->c_private == NULL) {
7890c559d0SToomas Soome 		for (i = 0; consoles[i] != NULL; i++)
7990c559d0SToomas Soome 			if (strcmp(consoles[i]->c_name, "text") == 0)
8090c559d0SToomas Soome 				break;
8190c559d0SToomas Soome 		cp->c_private = consoles[i];
8290c559d0SToomas Soome 	}
8390c559d0SToomas Soome 
8490c559d0SToomas Soome 	parent = cp->c_private;
8590c559d0SToomas Soome 	if (parent != NULL)
8690c559d0SToomas Soome 		parent->c_probe(cp);
87199767f8SToomas Soome }
88199767f8SToomas Soome 
89199767f8SToomas Soome static int
spinc_init(struct console * cp,int arg)9090c559d0SToomas Soome spinc_init(struct console *cp, int arg)
91199767f8SToomas Soome {
9290c559d0SToomas Soome 	struct console *parent;
9390c559d0SToomas Soome 
9490c559d0SToomas Soome 	parent = cp->c_private;
9590c559d0SToomas Soome 	if (parent != NULL)
9690c559d0SToomas Soome 		return (parent->c_init(cp, arg));
9790c559d0SToomas Soome 	else
9890c559d0SToomas Soome 		return (0);
99199767f8SToomas Soome }
100199767f8SToomas Soome 
101199767f8SToomas Soome static void
spinc_putchar(struct console * cp,int c __unused)10290c559d0SToomas Soome spinc_putchar(struct console *cp, int c __unused)
103199767f8SToomas Soome {
104199767f8SToomas Soome 	static unsigned tw_chars = 0x5C2D2F7C;    /* "\-/|" */
10590c559d0SToomas Soome 	static time_t lasttime = 0;
10690c559d0SToomas Soome 	struct console *parent;
107199767f8SToomas Soome 	time_t now;
108199767f8SToomas Soome 
109199767f8SToomas Soome 	now = time(NULL);
110199767f8SToomas Soome 	if (now < (lasttime + 1))
111199767f8SToomas Soome 		return;
112199767f8SToomas Soome 	lasttime = now;
11390c559d0SToomas Soome 	parent = cp->c_private;
11490c559d0SToomas Soome 	if (parent == NULL)
1159890ff83SToomas Soome 		return;
1169890ff83SToomas Soome 
11790c559d0SToomas Soome 	parent->c_out(parent, (char)tw_chars);
11890c559d0SToomas Soome 	parent->c_out(parent, '\b');
119199767f8SToomas Soome 	tw_chars = (tw_chars >> 8) | ((tw_chars & (unsigned long)0xFF) << 24);
120199767f8SToomas Soome }
121199767f8SToomas Soome 
122199767f8SToomas Soome static int
spinc_getchar(struct console * cp __unused)1239890ff83SToomas Soome spinc_getchar(struct console *cp __unused)
124199767f8SToomas Soome {
12590c559d0SToomas Soome 
12690c559d0SToomas Soome 	return (-1);
127199767f8SToomas Soome }
128199767f8SToomas Soome 
129199767f8SToomas Soome static int
spinc_ischar(struct console * cp __unused)1309890ff83SToomas Soome spinc_ischar(struct console *cp __unused)
131199767f8SToomas Soome {
13290c559d0SToomas Soome 
13390c559d0SToomas Soome 	return (0);
134199767f8SToomas Soome }
135