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