Home | History | Annotate | Line # | Download | only in boot
lcd.c revision 1.2
      1  1.2  tsutsui /*	$NetBSD: lcd.c,v 1.2 2008/05/29 14:25:01 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.2  tsutsui #if 0
     40  1.1  tsutsui #define CSR_READ(base, reg)						\
     41  1.2  tsutsui 	(((*(volatile uint32_t *)((base) + (reg))) >> 24), delay(10))
     42  1.2  tsutsui #endif
     43  1.1  tsutsui 
     44  1.1  tsutsui #define CSR_WRITE(base, reg, val)					\
     45  1.1  tsutsui 	do {								\
     46  1.1  tsutsui 		*(volatile uint32_t *)((base) + (reg)) = ((val) << 24);	\
     47  1.1  tsutsui 		delay(10);						\
     48  1.1  tsutsui 	} while (/* CONSTCOND */ 0)
     49  1.1  tsutsui 
     50  1.1  tsutsui #define NCOLS	16
     51  1.1  tsutsui 
     52  1.1  tsutsui struct lcd_message {
     53  1.1  tsutsui 	char row1[NCOLS];
     54  1.1  tsutsui 	char row2[NCOLS];
     55  1.1  tsutsui };
     56  1.1  tsutsui 
     57  1.1  tsutsui static uint32_t lcd_base;
     58  1.1  tsutsui static const struct lcd_message banner_message = {
     59  1.1  tsutsui 	"NetBSD/cobalt   ",
     60  1.1  tsutsui 	"Bootloader      "
     61  1.1  tsutsui };
     62  1.2  tsutsui static const struct lcd_message failed_message = {
     63  1.2  tsutsui 	"Boot failed!    ",
     64  1.2  tsutsui 	"Rebooting...    "
     65  1.2  tsutsui };
     66  1.2  tsutsui static struct lcd_message loadfile_message = {
     67  1.2  tsutsui 	"Loading:        ",
     68  1.2  tsutsui 	"                "
     69  1.2  tsutsui };
     70  1.1  tsutsui 
     71  1.1  tsutsui static void lcd_puts(const struct lcd_message *);
     72  1.1  tsutsui 
     73  1.1  tsutsui void
     74  1.1  tsutsui lcd_init(void)
     75  1.1  tsutsui {
     76  1.1  tsutsui 
     77  1.1  tsutsui 	lcd_base = MIPS_PHYS_TO_KSEG1(LCD_BASE);
     78  1.1  tsutsui }
     79  1.1  tsutsui 
     80  1.1  tsutsui void
     81  1.1  tsutsui lcd_banner(void)
     82  1.1  tsutsui {
     83  1.1  tsutsui 
     84  1.1  tsutsui 	lcd_puts(&banner_message);
     85  1.1  tsutsui }
     86  1.1  tsutsui 
     87  1.1  tsutsui void
     88  1.1  tsutsui lcd_loadfile(const char *file)
     89  1.1  tsutsui {
     90  1.1  tsutsui 
     91  1.1  tsutsui 	memcpy(loadfile_message.row2, file, min(NCOLS, strlen(file)));
     92  1.1  tsutsui 
     93  1.1  tsutsui 	lcd_puts(&loadfile_message);
     94  1.1  tsutsui }
     95  1.1  tsutsui 
     96  1.2  tsutsui void
     97  1.2  tsutsui lcd_failed(void)
     98  1.2  tsutsui {
     99  1.2  tsutsui 
    100  1.2  tsutsui 	lcd_puts(&failed_message);
    101  1.2  tsutsui }
    102  1.2  tsutsui 
    103  1.1  tsutsui static void
    104  1.1  tsutsui lcd_puts(const struct lcd_message *message)
    105  1.1  tsutsui {
    106  1.1  tsutsui 	int i;
    107  1.1  tsutsui 
    108  1.1  tsutsui 	for (i = 0; i < NCOLS; i++) {
    109  1.1  tsutsui 		CSR_WRITE(lcd_base, IREG, cmd_ddramset(HD_ROW1_ADDR + i));
    110  1.1  tsutsui 		CSR_WRITE(lcd_base, DREG, message->row1[i]);
    111  1.1  tsutsui 	}
    112  1.1  tsutsui 	for (i = 0; i < NCOLS; i++) {
    113  1.1  tsutsui 		CSR_WRITE(lcd_base, IREG, cmd_ddramset(HD_ROW2_ADDR + i));
    114  1.1  tsutsui 		CSR_WRITE(lcd_base, DREG, message->row2[i]);
    115  1.1  tsutsui 	}
    116  1.1  tsutsui }
    117