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