Last active
March 7, 2017 14:38
-
-
Save tsutsui/4bda7d1d19e0015936d1f75734ff1976 to your computer and use it in GitHub Desktop.
Porting LCD (on LUNA's front panel) driver for NetBSD/luna68k from OpenBSD/luna88k
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Index: etc/etc.luna68k/MAKEDEV.conf | |
| =================================================================== | |
| RCS file: /cvsroot/src/etc/etc.luna68k/MAKEDEV.conf,v | |
| retrieving revision 1.8.10.2 | |
| diff -u -p -d -r1.8.10.2 MAKEDEV.conf | |
| --- etc/etc.luna68k/MAKEDEV.conf 19 Feb 2017 07:42:37 -0000 1.8.10.2 | |
| +++ etc/etc.luna68k/MAKEDEV.conf 4 Mar 2017 18:10:18 -0000 | |
| @@ -4,7 +4,7 @@ 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 | |
| + ;; | |
| Index: distrib/sets/lists/comp/md.luna68k | |
| =================================================================== | |
| RCS file: /cvsroot/src/distrib/sets/lists/comp/md.luna68k,v | |
| retrieving revision 1.19.22.1 | |
| diff -u -p -d -r1.19.22.1 md.luna68k | |
| --- distrib/sets/lists/comp/md.luna68k 6 Dec 2016 06:50:23 -0000 1.19.22.1 | |
| +++ distrib/sets/lists/comp/md.luna68k 4 Mar 2017 18:10:18 -0000 | |
| @@ -26,6 +26,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 | |
| Index: sys/arch/luna68k/conf/GENERIC | |
| =================================================================== | |
| RCS file: /cvsroot/src/sys/arch/luna68k/conf/GENERIC,v | |
| retrieving revision 1.113.2.4 | |
| diff -u -p -d -r1.113.2.4 GENERIC | |
| --- sys/arch/luna68k/conf/GENERIC 6 Dec 2016 06:50:23 -0000 1.113.2.4 | |
| +++ sys/arch/luna68k/conf/GENERIC 4 Mar 2017 18:10:19 -0000 | |
| @@ -150,6 +150,9 @@ mainbus0 at root | |
| clock0 at mainbus0 | |
| +# LCD on front panel | |
| +lcd0 at mainbus0 | |
| + | |
| # uPD7201 SIO | |
| sio0 at mainbus0 | |
| siotty0 at sio0 # ttya | |
| Index: sys/arch/luna68k/conf/INSTALL | |
| =================================================================== | |
| RCS file: /cvsroot/src/sys/arch/luna68k/conf/INSTALL,v | |
| retrieving revision 1.16 | |
| diff -u -p -d -r1.16 INSTALL | |
| --- sys/arch/luna68k/conf/INSTALL 5 Aug 2014 15:52:38 -0000 1.16 | |
| +++ sys/arch/luna68k/conf/INSTALL 4 Mar 2017 18:10:19 -0000 | |
| @@ -129,6 +129,9 @@ mainbus0 at root | |
| clock0 at mainbus0 | |
| +# LCD on front panel | |
| +lcd0 at mainbus0 | |
| + | |
| # uPD7201 SIO | |
| sio0 at mainbus0 | |
| siotty0 at sio0 # ttya | |
| Index: sys/arch/luna68k/conf/files.luna68k | |
| =================================================================== | |
| RCS file: /cvsroot/src/sys/arch/luna68k/conf/files.luna68k,v | |
| retrieving revision 1.24.2.1 | |
| diff -u -p -d -r1.24.2.1 files.luna68k | |
| --- sys/arch/luna68k/conf/files.luna68k 6 Dec 2016 06:50:23 -0000 1.24.2.1 | |
| +++ sys/arch/luna68k/conf/files.luna68k 4 Mar 2017 18:10:19 -0000 | |
| @@ -22,7 +22,6 @@ file arch/m68k/m68k/procfs_machdep.c pro | |
| 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 | |
| Index: sys/arch/luna68k/conf/majors.luna68k | |
| =================================================================== | |
| RCS file: /cvsroot/src/sys/arch/luna68k/conf/majors.luna68k,v | |
| retrieving revision 1.20.28.1 | |
| diff -u -p -d -r1.20.28.1 majors.luna68k | |
| --- sys/arch/luna68k/conf/majors.luna68k 6 Dec 2016 06:50:23 -0000 1.20.28.1 | |
| +++ sys/arch/luna68k/conf/majors.luna68k 4 Mar 2017 18:10:19 -0000 | |
| @@ -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 | |
| Index: sys/arch/luna68k/dev/lcd.c | |
| =================================================================== | |
| RCS file: /cvsroot/src/sys/arch/luna68k/dev/lcd.c,v | |
| retrieving revision 1.7 | |
| diff -u -p -d -r1.7 lcd.c | |
| --- sys/arch/luna68k/dev/lcd.c 12 Nov 2011 13:44:26 -0000 1.7 | |
| +++ sys/arch/luna68k/dev/lcd.c 7 Mar 2017 14:36:43 -0000 | |
| @@ -1,4 +1,5 @@ | |
| /* $NetBSD: lcd.c,v 1.7 2011/11/12 13:44:26 tsutsui Exp $ */ | |
| +/* $OpenBSD: lcd.c,v 1.7 2015/02/10 22:42:35 miod Exp $ */ | |
| /*- | |
| * Copyright (c) 2000 The NetBSD Foundation, Inc. | |
| @@ -33,17 +34,19 @@ | |
| __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 | |
| - */ | |
| - | |
| #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 | |
| #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) | |
| { | |
| Index: sys/arch/luna68k/include/Makefile | |
| =================================================================== | |
| RCS file: /cvsroot/src/sys/arch/luna68k/include/Makefile,v | |
| retrieving revision 1.17.28.1 | |
| diff -u -p -d -r1.17.28.1 Makefile | |
| --- sys/arch/luna68k/include/Makefile 6 Dec 2016 06:50:23 -0000 1.17.28.1 | |
| +++ sys/arch/luna68k/include/Makefile 4 Mar 2017 18:10:19 -0000 | |
| @@ -12,7 +12,7 @@ INCS= ansi.h aout_machdep.h asm.h autoco | |
| 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 \ | |
| Index: sys/arch/luna68k/luna68k/machdep.c | |
| =================================================================== | |
| RCS file: /cvsroot/src/sys/arch/luna68k/luna68k/machdep.c,v | |
| retrieving revision 1.98 | |
| diff -u -p -d -r1.98 machdep.c | |
| --- sys/arch/luna68k/luna68k/machdep.c 24 Mar 2014 19:46:24 -0000 1.98 | |
| +++ sys/arch/luna68k/luna68k/machdep.c 4 Mar 2017 18:10:19 -0000 | |
| @@ -318,7 +318,6 @@ cpu_startup(void) | |
| { | |
| vaddr_t minaddr, maxaddr; | |
| char pbuf[9]; | |
| - extern void greeting(void); | |
| if (fputype != FPU_NONE) | |
| m68k_make_fpu_idle_frame(); | |
| @@ -347,11 +346,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 | |
| Index: sys/arch/luna68k/luna68k/mainbus.c | |
| =================================================================== | |
| RCS file: /cvsroot/src/sys/arch/luna68k/luna68k/mainbus.c,v | |
| retrieving revision 1.13.4.1 | |
| diff -u -p -d -r1.13.4.1 mainbus.c | |
| --- sys/arch/luna68k/luna68k/mainbus.c 6 Dec 2016 06:50:23 -0000 1.13.4.1 | |
| +++ sys/arch/luna68k/luna68k/mainbus.c 4 Mar 2017 18:10:19 -0000 | |
| @@ -42,6 +42,7 @@ __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v | |
| 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 | |
| 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 */ | |
| --- /dev/null 2017-03-05 03:06:43.000000000 +0900 | |
| +++ sys/arch/luna68k/include/lcd.h 2017-03-05 02:29:51.000000000 +0900 | |
| @@ -0,0 +1,67 @@ | |
| +/* $NetBSD$ */ | |
| +/* $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_ */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment