lcd.c revision 1.1 1 1.1 tsutsui /* $NetBSD: lcd.c,v 1.1 2008/05/28 14:04:07 tsutsui Exp $ */
2 1.1 tsutsui
3 1.1 tsutsui /*-
4 1.1 tsutsui * Copyright (c) 2008 Izumi Tsutsui. All rights reserved.
5 1.1 tsutsui *
6 1.1 tsutsui * Redistribution and use in source and binary forms, with or without
7 1.1 tsutsui * modification, are permitted provided that the following conditions
8 1.1 tsutsui * are met:
9 1.1 tsutsui * 1. Redistributions of source code must retain the above copyright
10 1.1 tsutsui * notice, this list of conditions and the following disclaimer.
11 1.1 tsutsui * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 tsutsui * notice, this list of conditions and the following disclaimer in the
13 1.1 tsutsui * documentation and/or other materials provided with the distribution.
14 1.1 tsutsui *
15 1.1 tsutsui * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.1 tsutsui * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 1.1 tsutsui * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 1.1 tsutsui * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 1.1 tsutsui * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 1.1 tsutsui * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 1.1 tsutsui * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 1.1 tsutsui * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 1.1 tsutsui * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 1.1 tsutsui * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 1.1 tsutsui */
26 1.1 tsutsui
27 1.1 tsutsui #include <lib/libsa/stand.h>
28 1.1 tsutsui #include <lib/libkern/libkern.h>
29 1.1 tsutsui
30 1.1 tsutsui #include <dev/ic/hd44780reg.h>
31 1.1 tsutsui
32 1.1 tsutsui #include <machine/cpu.h>
33 1.1 tsutsui
34 1.1 tsutsui #include "boot.h"
35 1.1 tsutsui
36 1.1 tsutsui #define IREG 0x00
37 1.1 tsutsui #define DREG 0x10
38 1.1 tsutsui
39 1.1 tsutsui #define CSR_READ(base, reg) \
40 1.1 tsutsui do { \
41 1.1 tsutsui ((*(volatile uint32_t *)((base) + (reg))) >> 24) \
42 1.1 tsutsui delay(10); \
43 1.1 tsutsui } while (/* CONSTCOND */ 0)
44 1.1 tsutsui
45 1.1 tsutsui #define CSR_WRITE(base, reg, val) \
46 1.1 tsutsui do { \
47 1.1 tsutsui *(volatile uint32_t *)((base) + (reg)) = ((val) << 24); \
48 1.1 tsutsui delay(10); \
49 1.1 tsutsui } while (/* CONSTCOND */ 0)
50 1.1 tsutsui
51 1.1 tsutsui #define NCOLS 16
52 1.1 tsutsui
53 1.1 tsutsui struct lcd_message {
54 1.1 tsutsui char row1[NCOLS];
55 1.1 tsutsui char row2[NCOLS];
56 1.1 tsutsui };
57 1.1 tsutsui
58 1.1 tsutsui static uint32_t lcd_base;
59 1.1 tsutsui static const struct lcd_message banner_message = {
60 1.1 tsutsui "NetBSD/cobalt ",
61 1.1 tsutsui "Bootloader "
62 1.1 tsutsui };
63 1.1 tsutsui static const char load[NCOLS] = "Loading: ";
64 1.1 tsutsui
65 1.1 tsutsui static void lcd_puts(const struct lcd_message *);
66 1.1 tsutsui
67 1.1 tsutsui void
68 1.1 tsutsui lcd_init(void)
69 1.1 tsutsui {
70 1.1 tsutsui
71 1.1 tsutsui lcd_base = MIPS_PHYS_TO_KSEG1(LCD_BASE);
72 1.1 tsutsui }
73 1.1 tsutsui
74 1.1 tsutsui void
75 1.1 tsutsui lcd_banner(void)
76 1.1 tsutsui {
77 1.1 tsutsui
78 1.1 tsutsui lcd_puts(&banner_message);
79 1.1 tsutsui }
80 1.1 tsutsui
81 1.1 tsutsui void
82 1.1 tsutsui lcd_loadfile(const char *file)
83 1.1 tsutsui {
84 1.1 tsutsui struct lcd_message loadfile_message;
85 1.1 tsutsui
86 1.1 tsutsui memset(loadfile_message.row1, ' ', NCOLS);
87 1.1 tsutsui memcpy(loadfile_message.row1, load, min(NCOLS, strlen(load)));
88 1.1 tsutsui memset(loadfile_message.row2, ' ', NCOLS);
89 1.1 tsutsui memcpy(loadfile_message.row2, file, min(NCOLS, strlen(file)));
90 1.1 tsutsui
91 1.1 tsutsui lcd_puts(&loadfile_message);
92 1.1 tsutsui }
93 1.1 tsutsui
94 1.1 tsutsui static void
95 1.1 tsutsui lcd_puts(const struct lcd_message *message)
96 1.1 tsutsui {
97 1.1 tsutsui int i;
98 1.1 tsutsui
99 1.1 tsutsui for (i = 0; i < NCOLS; i++) {
100 1.1 tsutsui CSR_WRITE(lcd_base, IREG, cmd_ddramset(HD_ROW1_ADDR + i));
101 1.1 tsutsui CSR_WRITE(lcd_base, DREG, message->row1[i]);
102 1.1 tsutsui }
103 1.1 tsutsui for (i = 0; i < NCOLS; i++) {
104 1.1 tsutsui CSR_WRITE(lcd_base, IREG, cmd_ddramset(HD_ROW2_ADDR + i));
105 1.1 tsutsui CSR_WRITE(lcd_base, DREG, message->row2[i]);
106 1.1 tsutsui }
107 1.1 tsutsui }
108