Add a driver for LUNA's front panel LCD. Ported from OpenBSD/luna88k.

Reviewed by enami@.  Tested by Naruaki Etomi and me.

A 68k LUNA with this driver will be demonstrated at AsiaBSDCon NetBSD booth
by Etomi-san, with LUNA-88K2 running OpenBSD/luna88k by Kenji Aoyama.
This commit is contained in:
tsutsui 2017-03-09 14:05:58 +00:00
parent 56a39ce52a
commit 9184265ae6
11 changed files with 305 additions and 29 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: md.luna68k,v 1.21 2016/12/03 17:38:02 tsutsui Exp $
# $NetBSD: md.luna68k,v 1.22 2017/03/09 14:05:58 tsutsui Exp $
./usr/include/ieeefp.h comp-c-include
./usr/include/luna68k comp-c-include
./usr/include/luna68k/_G_config.h comp-obsolete obsolete
@ -27,6 +27,7 @@
./usr/include/luna68k/int_types.h comp-c-include
./usr/include/luna68k/intr.h comp-c-include
./usr/include/luna68k/kcore.h comp-c-include
./usr/include/luna68k/lcd.h comp-c-include
./usr/include/luna68k/limits.h comp-c-include
./usr/include/luna68k/lock.h comp-c-include
./usr/include/luna68k/math.h comp-c-include

View File

@ -1,10 +1,10 @@
# $NetBSD: MAKEDEV.conf,v 1.10 2017/02/16 13:13:39 tsutsui Exp $
# $NetBSD: MAKEDEV.conf,v 1.11 2017/03/09 14:05:58 tsutsui Exp $
all_md)
makedev ttya sd0 sd1 sd2 sd3 cd0 cd1 st0 st1
makedev wscons
makedev scsibus0 scsibus1
makedev xp
makedev xp lcd
;;
tty[ab])
@ -26,3 +26,8 @@ xp)
major=40; minor=0; mode=0644
mkdev xp c $major $minor $mode
;;
lcd)
major=41; minor=0; mode=0644
mkdev lcd c $major $minor $mode
;;

View File

@ -1,4 +1,4 @@
# $NetBSD: GENERIC,v 1.120 2016/12/03 17:38:02 tsutsui Exp $
# $NetBSD: GENERIC,v 1.121 2017/03/09 14:05:58 tsutsui Exp $
#
# GENERIC machine description file
#
@ -22,7 +22,7 @@ include "arch/luna68k/conf/std.luna68k"
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
#ident "GENERIC-$Revision: 1.120 $"
#ident "GENERIC-$Revision: 1.121 $"
makeoptions COPTS="-O2 -fno-reorder-blocks" # see share/mk/sys.mk
@ -151,6 +151,9 @@ mainbus0 at root
clock0 at mainbus0
# LCD on front panel
lcd0 at mainbus0
# uPD7201 SIO
sio0 at mainbus0
siotty0 at sio0 # ttya

View File

@ -1,4 +1,4 @@
# $NetBSD: INSTALL,v 1.20 2016/09/18 14:20:23 christos Exp $
# $NetBSD: INSTALL,v 1.21 2017/03/09 14:05:58 tsutsui Exp $
#
# config for installation ramdisk kernel
#
@ -130,6 +130,9 @@ mainbus0 at root
clock0 at mainbus0
# LCD on front panel
lcd0 at mainbus0
# uPD7201 SIO
sio0 at mainbus0
siotty0 at sio0 # ttya

View File

@ -1,5 +1,5 @@
#
# $NetBSD: files.luna68k,v 1.25 2016/12/03 17:38:02 tsutsui Exp $
# $NetBSD: files.luna68k,v 1.26 2017/03/09 14:05:58 tsutsui Exp $
#
maxpartitions 8
maxusers 2 8 64
@ -22,7 +22,6 @@ file arch/m68k/m68k/procfs_machdep.c procfs
file arch/m68k/m68k/sys_machdep.c
file arch/m68k/m68k/vm_machdep.c
file dev/cons.c
file arch/luna68k/dev/lcd.c
device mainbus {}
attach mainbus at root
@ -32,6 +31,10 @@ device clock
attach clock at mainbus
file arch/luna68k/dev/timekeeper.c clock
device lcd
attach lcd at mainbus
file arch/luna68k/dev/lcd.c lcd needs-flag
attach le at mainbus: le24
file arch/luna68k/dev/if_le.c le

View File

@ -1,4 +1,4 @@
# $NetBSD: majors.luna68k,v 1.21 2016/12/03 17:38:02 tsutsui Exp $
# $NetBSD: majors.luna68k,v 1.22 2017/03/09 14:05:58 tsutsui Exp $
#
# Device majors for luna68k
#
@ -37,6 +37,7 @@ device-major cgd char 37 block 15 cgd
device-major ksyms char 38 ksyms
device-major wsfont char 39 wsfont
device-major xp char 40 xp
device-major lcd char 41 lcd
device-major nsmb char 98 nsmb

View File

@ -1,4 +1,5 @@
/* $NetBSD: lcd.c,v 1.7 2011/11/12 13:44:26 tsutsui Exp $ */
/* $NetBSD: lcd.c,v 1.8 2017/03/09 14:05:58 tsutsui Exp $ */
/* $OpenBSD: lcd.c,v 1.7 2015/02/10 22:42:35 miod Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -31,19 +32,21 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: lcd.c,v 1.7 2011/11/12 13:44:26 tsutsui Exp $");
/*
* XXX
* Following code segments are subject to change.
* XXX
*/
__KERNEL_RCSID(0, "$NetBSD: lcd.c,v 1.8 2017/03/09 14:05:58 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <sys/ioctl.h>
#include <sys/fcntl.h>
#include <sys/errno.h>
#include <machine/autoconf.h>
#include <machine/cpu.h>
#include <machine/lcd.h>
#include "ioconf.h"
#define PIO1_MODE_OUTPUT 0x84
#define PIO1_MODE_INPUT 0x94
@ -65,6 +68,8 @@ __KERNEL_RCSID(0, "$NetBSD: lcd.c,v 1.7 2011/11/12 13:44:26 tsutsui Exp $");
#define LCD_HOME 0x02
#define LCD_LOCATE(X, Y) (((Y) & 1 ? 0xc0 : 0x80) | ((X) & 0x0f))
#define LCD_MAXBUFLEN 80
struct pio {
volatile u_int8_t portA;
volatile u_int8_t portB;
@ -72,6 +77,39 @@ struct pio {
volatile u_int8_t cntrl;
};
/* Autoconf stuff */
static int lcd_match(device_t, cfdata_t, void *);
static void lcd_attach(device_t, device_t, void *);
dev_type_open(lcdopen);
dev_type_close(lcdclose);
dev_type_write(lcdwrite);
dev_type_ioctl(lcdioctl);
const struct cdevsw lcd_cdevsw = {
.d_open = lcdopen,
.d_close = lcdclose,
.d_read = noread,
.d_write = lcdwrite,
.d_ioctl = lcdioctl,
.d_stop = nostop,
.d_tty = notty,
.d_poll = nopoll,
.d_mmap = nommap,
.d_kqfilter = nokqfilter,
.d_discard = nodiscard,
.d_flag = 0
};
struct lcd_softc {
device_t sc_dev;
bool sc_opened;
};
CFATTACH_DECL_NEW(lcd, sizeof(struct lcd_softc),
lcd_match, lcd_attach, NULL, NULL);
void lcdbusywait(void);
void lcdput(int);
void lcdctrl(int);
@ -81,6 +119,165 @@ void greeting(void);
static char lcd_boot_message1[] = " NetBSD/luna68k ";
static char lcd_boot_message2[] = " SX-9100/DT ";
/*
* Autoconf functions
*/
static int
lcd_match(device_t parent, cfdata_t cf, void *aux)
{
struct mainbus_attach_args *ma = aux;
if (strcmp(ma->ma_name, lcd_cd.cd_name))
return 0;
if (badaddr((void *)ma->ma_addr, 4))
return 0;
return 1;
}
static void
lcd_attach(device_t parent, device_t self, void *aux)
{
printf("\n");
/* Say hello to the world on LCD. */
greeting();
}
/*
* open/close/write/ioctl
*/
int
lcdopen(dev_t dev, int flags, int fmt, struct lwp *l)
{
int unit;
struct lcd_softc *sc;
unit = minor(dev);
sc = device_lookup_private(&lcd_cd, unit);
if (sc == NULL)
return ENXIO;
if (sc->sc_opened)
return EBUSY;
sc->sc_opened = true;
return 0;
}
int
lcdclose(dev_t dev, int flags, int fmt, struct lwp *l)
{
int unit;
struct lcd_softc *sc;
unit = minor(dev);
sc = device_lookup_private(&lcd_cd, unit);
sc->sc_opened = false;
return 0;
}
int
lcdwrite(dev_t dev, struct uio *uio, int flag)
{
int error;
size_t len, i;
char buf[LCD_MAXBUFLEN];
len = uio->uio_resid;
if (len > LCD_MAXBUFLEN)
return EIO;
error = uiomove(buf, len, uio);
if (error)
return EIO;
for (i = 0; i < len; i++) {
lcdput((int)buf[i]);
}
return 0;
}
int
lcdioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
{
int val;
/* check if the device opened with write mode */
switch (cmd) {
case LCDCLS:
case LCDHOME:
case LCDMODE:
case LCDDISP:
case LCDMOVE:
case LCDSEEK:
case LCDRESTORE:
if ((flag & FWRITE) == 0)
return EACCES;
break;
}
switch (cmd) {
case LCDCLS:
lcdctrl(LCD_CLS);
break;
case LCDHOME:
lcdctrl(LCD_HOME);
break;
case LCDMODE:
val = *(int *)addr;
switch (val) {
case LCDMODE_C_LEFT:
case LCDMODE_C_RIGHT:
case LCDMODE_D_LEFT:
case LCDMODE_D_RIGHT:
lcdctrl(val);
break;
default:
return EINVAL;
}
break;
case LCDDISP:
val = *(int *)addr;
if ((val & 0x7) != val)
return EINVAL;
lcdctrl(val | 0x8);
break;
case LCDMOVE:
val = *(int *)addr;
switch (val) {
case LCDMOVE_C_LEFT:
case LCDMOVE_C_RIGHT:
case LCDMOVE_D_LEFT:
case LCDMOVE_D_RIGHT:
lcdctrl(val);
break;
default:
return EINVAL;
}
break;
case LCDSEEK:
val = *(int *)addr & 0x7f;
lcdctrl(val | 0x80);
break;
case LCDRESTORE:
greeting();
break;
default:
return ENOTTY;
}
return EPASSTHROUGH;
}
void
lcdbusywait(void)
{

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.19 2016/12/03 17:38:02 tsutsui Exp $
# $NetBSD: Makefile,v 1.20 2017/03/09 14:05:58 tsutsui Exp $
INCSDIR= /usr/include/luna68k
@ -12,7 +12,7 @@ INCS= ansi.h aout_machdep.h asm.h autoconf.h \
int_const.h int_fmtio.h int_limits.h int_mwgwtypes.h int_types.h \
intr.h \
kcore.h \
limits.h lock.h \
lcd.h limits.h lock.h \
math.h mcontext.h mutex.h \
param.h pcb.h pmap.h pmc.h proc.h profile.h psl.h pte.h ptrace.h reg.h \
rwlock.h setjmp.h signal.h \

View File

@ -0,0 +1,67 @@
/* $NetBSD: lcd.h,v 1.1 2017/03/09 14:05:58 tsutsui Exp $ */
/* $OpenBSD: lcd.h,v 1.2 2011/03/23 16:54:35 pirofti Exp $ */
/*
* Copyright (c) 2007 Kenji AOYAMA <aoyama@nk-home.net>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _MACHINE_LCD_H_
#define _MACHINE_LCD_H_
/*
* NetBSD/luna68k LCD driver
* (taken from OpenBSD/luna88k LCD driver)
*/
/* The ioctl defines */
#define LCDCLS _IO('L', 1) /* Clear LCD screen */
#define LCDHOME _IO('L', 2) /* Move the cursor to left-upper */
#define LCDMODE _IOW('L', 3, int) /* Set the data entry mode */
#define LCDDISP _IOW('L', 4, int) /* Blink, cursor, and display on/off */
#define LCDMOVE _IOW('L', 5, int) /* Move cursor / shift display area */
#define LCDSEEK _IOW('L', 6, int) /* Move the cursor to specified position */
#define LCDRESTORE _IO('L', 7) /* Restore boot-time LCD message */
/* argument value for each ioctl */
/* LCDMODE; when a character data is written, then ... */
#define LCDMODE_C_LEFT 0x04 /* cursor moves left */
#define LCDMODE_C_RIGHT 0x06 /* cursor moves right */
#define LCDMODE_D_LEFT 0x05 /* display area shifts to left */
#define LCDMODE_D_RIGHT 0x07 /* display area shifts to right */
/* LCDDISP; you can use these values or'ed */
#define LCD_DISPLAY 0x04 /* LCD display on */
#define LCD_CURSOR 0x02 /* Cursor on */
#define LCD_BLINK 0x01 /* Blink on */
/* LCDMOVE; just move the cursor or shift the display area */
#define LCDMOVE_C_LEFT 0x10 /* cursor moves left */
#define LCDMOVE_C_RIGHT 0x14 /* cursor moves right */
#define LCDMOVE_D_LEFT 0x18 /* display area shifts to left */
#define LCDMOVE_D_RIGHT 0x1c /* display area shifts to right */
#endif /* _MACHINE_LCD_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.99 2015/08/21 10:48:06 christos Exp $ */
/* $NetBSD: machdep.c,v 1.100 2017/03/09 14:05:59 tsutsui Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -31,7 +31,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.99 2015/08/21 10:48:06 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.100 2017/03/09 14:05:59 tsutsui Exp $");
#include "opt_ddb.h"
#include "opt_kgdb.h"
@ -319,7 +319,6 @@ cpu_startup(void)
{
vaddr_t minaddr, maxaddr;
char pbuf[9];
extern void greeting(void);
if (fputype != FPU_NONE)
m68k_make_fpu_idle_frame();
@ -348,11 +347,6 @@ cpu_startup(void)
format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
printf("avail memory = %s\n", pbuf);
/*
* Say "Hi" to the world
*/
greeting();
}
void

View File

@ -1,4 +1,4 @@
/* $NetBSD: mainbus.c,v 1.14 2016/12/03 17:38:02 tsutsui Exp $ */
/* $NetBSD: mainbus.c,v 1.15 2017/03/09 14:05:59 tsutsui Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -31,7 +31,7 @@
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.14 2016/12/03 17:38:02 tsutsui Exp $");
__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.15 2017/03/09 14:05:59 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -42,6 +42,7 @@ __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.14 2016/12/03 17:38:02 tsutsui Exp $")
static const struct mainbus_attach_args luna_devs[] = {
{ "clock", 0x45000000, -1 }, /* Mostek TimeKeeper */
{ "lcd", 0x4d000000, -1 }, /* Sharp LM16X212 LCD module */
{ "le", 0xf1000000, 3 }, /* Am7990 */
{ "sio", 0x51000000, 6 }, /* uPD7201A */
{ "xp", 0x71000000, 1 }, /* HD647180XP */
@ -51,6 +52,7 @@ static const struct mainbus_attach_args luna_devs[] = {
static const struct mainbus_attach_args luna2_devs[] = {
{ "clock", 0x45000000, -1 }, /* Dallas TimeKeeper */
{ "lcd", 0x4d000000, -1 }, /* Sharp LM16X212 LCD module */
{ "le", 0xf1000000, 3 }, /* Am7990 */
{ "sio", 0x51000000, 6 }, /* uPD7201A */
{ "xp", 0x71000000, 1 }, /* HD647180XP */