xref: /netbsd-src/sys/arch/luna68k/dev/lcd.c (revision 6a493d6bc668897c91594964a732d38505b70cbb)
1 /* $NetBSD: lcd.c,v 1.7 2011/11/12 13:44:26 tsutsui 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.7 2011/11/12 13:44:26 tsutsui 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 #include <machine/cpu.h>
47 
48 #define PIO1_MODE_OUTPUT	0x84
49 #define PIO1_MODE_INPUT		0x94
50 
51 #define POWER	0x10
52 
53 #define ENABLE	0x80
54 #define DISABLE	0x00
55 
56 #define WRITE_CMD	(0x00 | 0x00)
57 #define WRITE_DATA	(0x00 | 0x40)
58 #define READ_BUSY	(0x20 | 0x00)
59 #define READ_DATA	(0x20 | 0x40)
60 
61 #define LCD_INIT	0x38
62 #define LCD_ENTRY	0x06
63 #define LCD_ON		0x0c
64 #define LCD_CLS		0x01
65 #define LCD_HOME	0x02
66 #define LCD_LOCATE(X, Y)	(((Y) & 1 ? 0xc0 : 0x80) | ((X) & 0x0f))
67 
68 struct pio {
69 	volatile u_int8_t portA;
70 	volatile u_int8_t portB;
71 	volatile u_int8_t portC;
72 	volatile u_int8_t cntrl;
73 };
74 
75 void lcdbusywait(void);
76 void lcdput(int);
77 void lcdctrl(int);
78 void lcdshow(char *);
79 void greeting(void);
80 			       /* "1234567890123456" */
81 static char lcd_boot_message1[] = " NetBSD/luna68k ";
82 static char lcd_boot_message2[] = "   SX-9100/DT   ";
83 
84 void
85 lcdbusywait(void)
86 {
87 	struct pio *p1 = (struct pio *)0x4D000000;
88 	int msb, s;
89 
90 	s = splhigh();
91 	p1->cntrl = PIO1_MODE_INPUT;
92 	p1->portC = POWER | READ_BUSY | ENABLE;
93 	splx(s);
94 
95 	do {
96 		msb = p1->portA & ENABLE;
97 		delay(5);
98 	} while (msb != 0);
99 
100 	s = splhigh();
101 	p1->portC = POWER | READ_BUSY | DISABLE;
102 	splx(s);
103 }
104 
105 void
106 lcdput(int cc)
107 {
108 	struct pio *p1 = (struct pio *)0x4D000000;
109 	int s;
110 
111 	lcdbusywait();
112 
113 	s = splhigh();
114 	p1->cntrl = PIO1_MODE_OUTPUT;
115 
116 	p1->portC = POWER | WRITE_DATA | ENABLE;
117 	p1->portA = cc;
118 	p1->portC = POWER | WRITE_DATA | DISABLE;
119 	splx(s);
120 }
121 
122 void
123 lcdctrl(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(char *s)
141 {
142 	int cc;
143 
144 	while ((cc = *s++) != '\0')
145 		lcdput(cc);
146 }
147 
148 void
149 greeting(void)
150 {
151 	lcdctrl(LCD_INIT);
152 	lcdctrl(LCD_ENTRY);
153 	lcdctrl(LCD_ON);
154 
155 	lcdctrl(LCD_CLS);
156 	lcdctrl(LCD_HOME);
157 
158 	lcdctrl(LCD_LOCATE(0, 0));
159 	lcdshow(lcd_boot_message1);
160 	lcdctrl(LCD_LOCATE(0, 1));
161 	if (machtype == LUNA_II)
162 		lcd_boot_message2[13] = '2';
163 	lcdshow(lcd_boot_message2);
164 }
165