lcd.c revision 1.5 1 /* $NetBSD: lcd.c,v 1.5 2009/03/14 15:36:08 dsl 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 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
33
34 __KERNEL_RCSID(0, "$NetBSD: lcd.c,v 1.5 2009/03/14 15:36:08 dsl Exp $");
35
36 /*
37 * XXX
38 * Following code segments are subject to change.
39 * XXX
40 */
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/device.h>
45
46 #define PIO1_MODE_OUTPUT 0x84
47 #define PIO1_MODE_INPUT 0x94
48
49 #define POWER 0x10
50
51 #define ENABLE 0x80
52 #define DISABLE 0x00
53
54 #define WRITE_CMD (0x00 | 0x00)
55 #define WRITE_DATA (0x00 | 0x40)
56 #define READ_BUSY (0x20 | 0x00)
57 #define READ_DATA (0x20 | 0x40)
58
59 #define LCD_INIT 0x38
60 #define LCD_ENTRY 0x06
61 #define LCD_ON 0x0c
62 #define LCD_CLS 0x01
63 #define LCD_HOME 0x02
64 #define LCD_LOCATE(X, Y) (((Y) & 1 ? 0xc0 : 0x80) | ((X) & 0x0f))
65
66 struct pio {
67 volatile u_int8_t portA;
68 volatile u_int8_t portB;
69 volatile u_int8_t portC;
70 volatile u_int8_t cntrl;
71 };
72
73 void lcdbusywait(void);
74 void lcdput(int);
75 void lcdctrl(int);
76 void lcdshow(char *);
77 void greeting(void);
78 /* "1234567890123456" */
79 static char lcd_boot_message1[] = " NetBSD/luna68k ";
80 static char lcd_boot_message2[] = " SX-9100/DT ";
81
82 void
83 lcdbusywait()
84 {
85 struct pio *p1 = (struct pio *)0x4D000000;
86 int msb, s;
87
88 s = splhigh();
89 p1->cntrl = PIO1_MODE_INPUT;
90 p1->portC = POWER | READ_BUSY | ENABLE;
91 splx(s);
92
93 do {
94 msb = p1->portA & ENABLE;
95 delay(5);
96 } while (msb != 0);
97
98 s = splhigh();
99 p1->portC = POWER | READ_BUSY | DISABLE;
100 splx(s);
101 }
102
103 void
104 lcdput(int cc)
105 {
106 struct pio *p1 = (struct pio *)0x4D000000;
107 int s;
108
109 lcdbusywait();
110
111 s = splhigh();
112 p1->cntrl = PIO1_MODE_OUTPUT;
113
114 p1->portC = POWER | WRITE_DATA | ENABLE;
115 p1->portA = cc;
116 p1->portC = POWER | WRITE_DATA | DISABLE;
117 splx(s);
118 }
119
120 void
121 lcdctrl(int cc)
122 {
123 struct pio *p1 = (struct pio *)0x4D000000;
124 int s;
125
126 lcdbusywait();
127
128 s = splhigh();
129 p1->cntrl = PIO1_MODE_OUTPUT;
130
131 p1->portC = POWER | WRITE_CMD | ENABLE;
132 p1->portA = cc;
133 p1->portC = POWER | WRITE_CMD | DISABLE;
134 splx(s);
135 }
136
137 void
138 lcdshow(char *s)
139 {
140 int cc;
141
142 while ((cc = *s++) != '\0')
143 lcdput(cc);
144 }
145
146 void
147 greeting()
148 {
149 lcdctrl(LCD_INIT);
150 lcdctrl(LCD_ENTRY);
151 lcdctrl(LCD_ON);
152
153 lcdctrl(LCD_CLS);
154 lcdctrl(LCD_HOME);
155
156 lcdctrl(LCD_LOCATE(0, 0));
157 lcdshow(lcd_boot_message1);
158 lcdctrl(LCD_LOCATE(0, 1));
159 lcdshow(lcd_boot_message2);
160 }
161