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