xref: /netbsd-src/sys/arch/luna68k/dev/lcd.c (revision 404fbe5fb94ca1e054339640cabb2801ce52dd30)
1 /* $NetBSD: lcd.c,v 1.3 2008/04/28 20:23:26 martin 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.3 2008/04/28 20:23:26 martin 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 __P((void));
74 void lcdput __P((int));
75 void lcdctrl __P((int));
76 void lcdshow __P((char *));
77 void greeting __P((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(cc)
105 	int cc;
106 {
107 	struct pio *p1 = (struct pio *)0x4D000000;
108 	int s;
109 
110 	lcdbusywait();
111 
112 	s = splhigh();
113 	p1->cntrl = PIO1_MODE_OUTPUT;
114 
115 	p1->portC = POWER | WRITE_DATA | ENABLE;
116 	p1->portA = cc;
117 	p1->portC = POWER | WRITE_DATA | DISABLE;
118 	splx(s);
119 }
120 
121 void
122 lcdctrl(cc)
123 	int cc;
124 {
125 	struct pio *p1 = (struct pio *)0x4D000000;
126 	int s;
127 
128 	lcdbusywait();
129 
130 	s = splhigh();
131 	p1->cntrl = PIO1_MODE_OUTPUT;
132 
133 	p1->portC = POWER | WRITE_CMD | ENABLE;
134 	p1->portA = cc;
135 	p1->portC = POWER | WRITE_CMD | DISABLE;
136 	splx(s);
137 }
138 
139 void
140 lcdshow(s)
141 	char *s;
142 {
143 	int cc;
144 
145 	while ((cc = *s++) != '\0')
146 		lcdput(cc);
147 }
148 
149 void
150 greeting()
151 {
152 	lcdctrl(LCD_INIT);
153 	lcdctrl(LCD_ENTRY);
154 	lcdctrl(LCD_ON);
155 
156 	lcdctrl(LCD_CLS);
157 	lcdctrl(LCD_HOME);
158 
159 	lcdctrl(LCD_LOCATE(0, 0));
160 	lcdshow(lcd_boot_message1);
161 	lcdctrl(LCD_LOCATE(0, 1));
162 	lcdshow(lcd_boot_message2);
163 }
164