1 /* $NetBSD: iris_cons.c,v 1.1 2019/01/12 16:44:47 tsutsui Exp $ */
2
3 /*
4 * Copyright (c) 2018 Naruaki Etomi
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 /*
29 * Silicon Graphics "IRIS" series MIPS processors machine bootloader.
30 * Front end of Zilog Z8530 Dual UART driver.
31 */
32
33 #include <lib/libsa/stand.h>
34
35 #include <machine/cpu.h>
36
37 #include "iris_machdep.h"
38 #include "iris_cons.h"
39 #include "iris_zs.h"
40
41 void zscnprobe(struct consdev *);
42 void zscninit(struct consdev *);
43 void zscnputchar(void *, int);
44 int zscngetchar(void *);
45 int zscnscan(void *);
46
47 #define ZSCHAN 0x0
48 #define ZSSPEED 9600
49
50 struct consdev constab[] = {
51 { "zs", ZSCHAN, ZSSPEED,
52 zscnprobe, zscninit, zscngetchar, zscnputchar, zscnscan },
53 { 0 }
54 };
55
56 struct consdev *cn_tab;
57
58 char *
cninit(int * addr,int * speed)59 cninit(int *addr, int *speed)
60 {
61 struct consdev *cp;
62
63 cn_tab = NULL;
64 for (cp = constab; cp->cn_probe; cp++) {
65 (*cp->cn_probe)(cp);
66 if (cp->cn_pri > CN_DEAD &&
67 (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri))
68 cn_tab = cp;
69 }
70 if (cn_tab) {
71 (*cn_tab->cn_init)(cn_tab);
72 *addr = cn_tab->address;
73 *speed = cn_tab->speed;
74 return cn_tab->cn_name;
75 }
76
77 return NULL;
78 }
79
80 int
cngetc(void)81 cngetc(void)
82 {
83
84 if (cn_tab)
85 return (*cn_tab->cn_getc)(cn_tab->cn_dev);
86 return 0;
87 }
88
89 void
cnputc(int c)90 cnputc(int c)
91 {
92
93 if (cn_tab)
94 (*cn_tab->cn_putc)(cn_tab->cn_dev, c);
95 }
96
97 int
cnscan(void)98 cnscan(void)
99 {
100
101 if (cn_tab)
102 return (*cn_tab->cn_scan)(cn_tab->cn_dev);
103 return -1;
104 }
105
106 void
zscnprobe(struct consdev * cp)107 zscnprobe(struct consdev *cp)
108 {
109
110 cp->cn_pri = CN_REMOTE;
111 }
112
113 void
zscninit(struct consdev * cp)114 zscninit(struct consdev *cp)
115 {
116
117 cp->cn_dev = zs_init(cp->address, cp->speed);
118 }
119
120 int
zscngetchar(void * dev)121 zscngetchar(void *dev)
122 {
123
124 return zscngetc(dev);
125 }
126
127 void
zscnputchar(void * dev,int c)128 zscnputchar(void *dev, int c)
129 {
130
131 if (c == '\n')
132 zscnputc(dev, '\r');
133 zscnputc(dev, c);
134 }
135
136 int
zscnscan(void * dev)137 zscnscan(void *dev)
138 {
139
140 return zscnscanc(dev);
141 }
142