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