1 /* $NetBSD: xboxlcd.c,v 1.2 2007/01/07 02:32:10 hubertf Exp $ */
4 * Copyright (c) 2006 Andrew Gillham
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * Driver for Xecuter X3 LCD add-on
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD$");
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <machine/bus.h>
42 #include <machine/xbox.h>
43 #include <machine/pio.h>
45 void xbox_lcd_init(void)
49 outb(X3LCD_O_DIR_DAT
, 0xFF);
50 outb(X3LCD_O_DIR_CMD
, 0x07);
52 xbox_lcd_output(X3LCD_FUNC_SET
| X3LCD_DL_FLAG
, X3LCD_INI
);
54 xbox_lcd_output(X3LCD_FUNC_SET
| X3LCD_DL_FLAG
, X3LCD_INI
);
56 xbox_lcd_output(X3LCD_FUNC_SET
| X3LCD_DL_FLAG
, X3LCD_INI
);
58 xbox_lcd_output(X3LCD_FUNC_SET
, X3LCD_INI
);
60 xbox_lcd_output(X3LCD_FUNC_SET
| X3LCD_DL_FLAG
| X3LCD_N_FLAG
, X3LCD_CMD
);
62 xbox_lcd_output(X3LCD_CONTROL
| X3LCD_D_FLAG
, X3LCD_CMD
);
64 xbox_lcd_output(X3LCD_CLEAR
, X3LCD_CMD
);
66 xbox_lcd_output(X3LCD_ENTRY_MODE
| X3LCD_ID_FLAG
, X3LCD_CMD
);
69 /* xbox_lcd_setpos(0,0); */
71 outb(X3LCD_O_LIGHT
, 81);
75 void xbox_lcd_output(unsigned char data
, unsigned char command
)
77 unsigned char cmd
= 0;
80 if (command
& X3LCD_DAT
)
82 cmd
|= X3LCD_DISPCON_RS
;
85 /* output upper nibble of data */
86 /* outb(X3LCD_O_DAT, data & 0xF0); */
88 outb(X3LCD_O_DAT, data);
89 outb(X3LCD_O_CMD, cmd);
90 outb(X3LCD_O_CMD, X3LCD_DISPCON_E | cmd);
91 outb(X3LCD_O_CMD, cmd);
95 /* only if not init command */
96 if ((command
& X3LCD_INI
) == 0)
98 /* output lower nibble of data */
99 /* outb(X3LCD_O_DAT, (data << 4) & 0xF0); */
100 outb(X3LCD_O_DAT
, data
);
101 outb(X3LCD_O_CMD
, cmd
);
102 outb(X3LCD_O_CMD
, X3LCD_DISPCON_E
| cmd
);
103 outb(X3LCD_O_CMD
, cmd
);
109 void xbox_lcd_writestring(char *lcdstring
)
117 xbox_lcd_output(i
, X3LCD_DAT
);
123 void xbox_lcd_writetext(const char *lcdtext
)
126 while ((i
= *lcdtext
++)) {
127 if ((i
> 31) && (i
< 128)) {
128 xbox_lcd_output(i
, X3LCD_DAT
);
133 void xbox_lcd_putchar(unsigned char data
)
135 if ((data
>= ' ') && (data
<= '~')) {
136 xbox_lcd_output(data
, X3LCD_DAT
);
140 void xbox_lcd_setpos(unsigned int pos
, unsigned int line
)
142 xbox_lcd_output(X3LCD_DDRAM_SET
| 0, X3LCD_CMD
);