lcd.c revision 1.2 1 /* $NetBSD: lcd.c,v 1.2 2000/01/07 05:13:08 nisimura Exp $ */
2
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tohru Nishimura.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
40
41 __KERNEL_RCSID(0, "$NetBSD: lcd.c,v 1.2 2000/01/07 05:13:08 nisimura Exp $");
42
43 /*
44 * XXX
45 * Following code segments are subject to change.
46 * XXX
47 */
48
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/device.h>
52
53 #define PIO1_MODE_OUTPUT 0x84
54 #define PIO1_MODE_INPUT 0x94
55
56 #define POWER 0x10
57
58 #define ENABLE 0x80
59 #define DISABLE 0x00
60
61 #define WRITE_CMD (0x00 | 0x00)
62 #define WRITE_DATA (0x00 | 0x40)
63 #define READ_BUSY (0x20 | 0x00)
64 #define READ_DATA (0x20 | 0x40)
65
66 #define LCD_INIT 0x38
67 #define LCD_ENTRY 0x06
68 #define LCD_ON 0x0c
69 #define LCD_CLS 0x01
70 #define LCD_HOME 0x02
71 #define LCD_LOCATE(X, Y) (((Y) & 1 ? 0xc0 : 0x80) | ((X) & 0x0f))
72
73 struct pio {
74 volatile u_int8_t portA;
75 volatile u_int8_t portB;
76 volatile u_int8_t portC;
77 volatile u_int8_t cntrl;
78 };
79
80 void lcdbusywait __P((void));
81 void lcdput __P((int));
82 void lcdctrl __P((int));
83 void lcdshow __P((char *));
84 void greeting __P((void));
85 /* "1234567890123456" */
86 static char lcd_boot_message1[] = " NetBSD/luna68k ";
87 static char lcd_boot_message2[] = " SX-9100/DT ";
88
89 void
90 lcdbusywait()
91 {
92 struct pio *p1 = (struct pio *)0x4D000000;
93 int msb, s;
94
95 s = splhigh();
96 p1->cntrl = PIO1_MODE_INPUT;
97 p1->portC = POWER | READ_BUSY | ENABLE;
98 splx(s);
99
100 do {
101 msb = p1->portA & ENABLE;
102 delay(5);
103 } while (msb != 0);
104
105 s = splhigh();
106 p1->portC = POWER | READ_BUSY | DISABLE;
107 splx(s);
108 }
109
110 void
111 lcdput(cc)
112 int cc;
113 {
114 struct pio *p1 = (struct pio *)0x4D000000;
115 int s;
116
117 lcdbusywait();
118
119 s = splhigh();
120 p1->cntrl = PIO1_MODE_OUTPUT;
121
122 p1->portC = POWER | WRITE_DATA | ENABLE;
123 p1->portA = cc;
124 p1->portC = POWER | WRITE_DATA | DISABLE;
125 splx(s);
126 }
127
128 void
129 lcdctrl(cc)
130 int cc;
131 {
132 struct pio *p1 = (struct pio *)0x4D000000;
133 int s;
134
135 lcdbusywait();
136
137 s = splhigh();
138 p1->cntrl = PIO1_MODE_OUTPUT;
139
140 p1->portC = POWER | WRITE_CMD | ENABLE;
141 p1->portA = cc;
142 p1->portC = POWER | WRITE_CMD | DISABLE;
143 splx(s);
144 }
145
146 void
147 lcdshow(s)
148 char *s;
149 {
150 int cc;
151
152 while ((cc = *s++) != '\0')
153 lcdput(cc);
154 }
155
156 void
157 greeting()
158 {
159 lcdctrl(LCD_INIT);
160 lcdctrl(LCD_ENTRY);
161 lcdctrl(LCD_ON);
162
163 lcdctrl(LCD_CLS);
164 lcdctrl(LCD_HOME);
165
166 lcdctrl(LCD_LOCATE(0, 0));
167 lcdshow(lcd_boot_message1);
168 lcdctrl(LCD_LOCATE(0, 1));
169 lcdshow(lcd_boot_message2);
170 }
171