Module Name: src Committed By: christos Date: Mon Apr 9 20:16:16 UTC 2018
Modified Files: src/sys/arch/cobalt/conf: GENERIC INSTALL files.cobalt src/sys/arch/cobalt/include: cpu.h Added Files: src/sys/arch/cobalt/dev: lcdpanel.c Removed Files: src/sys/arch/cobalt/dev: panel.c Log Message: rename panel to lcdpanel. To generate a diff of this commit: cvs rdiff -u -r1.157 -r1.158 src/sys/arch/cobalt/conf/GENERIC cvs rdiff -u -r1.66 -r1.67 src/sys/arch/cobalt/conf/INSTALL cvs rdiff -u -r1.40 -r1.41 src/sys/arch/cobalt/conf/files.cobalt cvs rdiff -u -r0 -r1.1 src/sys/arch/cobalt/dev/lcdpanel.c cvs rdiff -u -r1.24 -r0 src/sys/arch/cobalt/dev/panel.c cvs rdiff -u -r1.15 -r1.16 src/sys/arch/cobalt/include/cpu.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/cobalt/conf/GENERIC diff -u src/sys/arch/cobalt/conf/GENERIC:1.157 src/sys/arch/cobalt/conf/GENERIC:1.158 --- src/sys/arch/cobalt/conf/GENERIC:1.157 Mon Apr 9 15:05:26 2018 +++ src/sys/arch/cobalt/conf/GENERIC Mon Apr 9 16:16:16 2018 @@ -1,4 +1,4 @@ -# $NetBSD: GENERIC,v 1.157 2018/04/09 19:05:26 christos Exp $ +# $NetBSD: GENERIC,v 1.158 2018/04/09 20:16:16 christos Exp $ # # GENERIC machine description file # @@ -22,7 +22,7 @@ include "arch/cobalt/conf/std.cobalt" options INCLUDE_CONFIG_FILE # embed config file in kernel binary -#ident "GENERIC-$Revision: 1.157 $" +#ident "GENERIC-$Revision: 1.158 $" maxusers 32 @@ -146,7 +146,7 @@ zsc0 at mainbus? addr 0x1c800000 irq 4 zstty0 at zsc0 channel 0 zstty1 at zsc0 channel 1 -ledpanel0 at mainbus? addr 0x1f000000 +lcdpanel0 at mainbus? addr 0x1f000000 gt0 at mainbus? addr 0x14000000 Index: src/sys/arch/cobalt/conf/INSTALL diff -u src/sys/arch/cobalt/conf/INSTALL:1.66 src/sys/arch/cobalt/conf/INSTALL:1.67 --- src/sys/arch/cobalt/conf/INSTALL:1.66 Mon Apr 9 15:05:26 2018 +++ src/sys/arch/cobalt/conf/INSTALL Mon Apr 9 16:16:16 2018 @@ -1,4 +1,4 @@ -# $NetBSD: INSTALL,v 1.66 2018/04/09 19:05:26 christos Exp $ +# $NetBSD: INSTALL,v 1.67 2018/04/09 20:16:16 christos Exp $ # # INSTALL -- installation and rescue kernel. # @@ -10,7 +10,7 @@ include "arch/cobalt/conf/std.cobalt" options INCLUDE_CONFIG_FILE # embed config file in kernel binary -#ident "INSTALL-$Revision: 1.66 $" +#ident "INSTALL-$Revision: 1.67 $" makeoptions COPTS="-Os -mmemcpy" makeoptions CPUFLAGS="-march=vr5000 -mabi=32" @@ -135,7 +135,7 @@ zsc0 at mainbus? addr 0x1c800000 irq 4 zstty0 at zsc0 channel 0 #zstty1 at zsc0 channel 1 -ledpanel0 at mainbus? addr 0x1f000000 +lcdpanel0 at mainbus? addr 0x1f000000 gt0 at mainbus? addr 0x14000000 Index: src/sys/arch/cobalt/conf/files.cobalt diff -u src/sys/arch/cobalt/conf/files.cobalt:1.40 src/sys/arch/cobalt/conf/files.cobalt:1.41 --- src/sys/arch/cobalt/conf/files.cobalt:1.40 Mon Apr 9 15:05:26 2018 +++ src/sys/arch/cobalt/conf/files.cobalt Mon Apr 9 16:16:16 2018 @@ -1,4 +1,4 @@ -# $NetBSD: files.cobalt,v 1.40 2018/04/09 19:05:26 christos Exp $ +# $NetBSD: files.cobalt,v 1.41 2018/04/09 20:16:16 christos Exp $ maxpartitions 16 @@ -31,9 +31,9 @@ device mcclock: mc146818 attach mcclock at mainbus file arch/cobalt/dev/mcclock.c mcclock needs-flag -device ledpanel: hd44780 -attach ledpanel at mainbus -file arch/cobalt/dev/panel.c ledpanel +device lcdpanel: hd44780 +attach lcdpanel at mainbus +file arch/cobalt/dev/lcdpanel.c lcdpanel device gt: pcibus attach gt at mainbus Index: src/sys/arch/cobalt/include/cpu.h diff -u src/sys/arch/cobalt/include/cpu.h:1.15 src/sys/arch/cobalt/include/cpu.h:1.16 --- src/sys/arch/cobalt/include/cpu.h:1.15 Tue May 3 05:15:20 2011 +++ src/sys/arch/cobalt/include/cpu.h Mon Apr 9 16:16:16 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.h,v 1.15 2011/05/03 09:15:20 tsutsui Exp $ */ +/* $NetBSD: cpu.h,v 1.16 2018/04/09 20:16:16 christos Exp $ */ #ifndef _COBALT_CPU_H_ #define _COBALT_CPU_H_ @@ -25,7 +25,7 @@ extern u_int cobalt_id; #define LED_POWEROFF 3 #define COM_BASE 0x1c800000 #define ZS_BASE 0x1c800000 -#define PANEL_BASE 0x1d000000 +#define LCDPANEL_BASE 0x1d000000 #define LCD_BASE 0x1f000000 #endif /* !_LOCORE */ Added files: Index: src/sys/arch/cobalt/dev/lcdpanel.c diff -u /dev/null src/sys/arch/cobalt/dev/lcdpanel.c:1.1 --- /dev/null Mon Apr 9 16:16:16 2018 +++ src/sys/arch/cobalt/dev/lcdpanel.c Mon Apr 9 16:16:16 2018 @@ -0,0 +1,334 @@ +/* $NetBSD: lcdpanel.c,v 1.1 2018/04/09 20:16:16 christos Exp $ */ + +/* + * Copyright (c) 2002 Dennis I. Chernoivanov + * 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. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. + */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: lcdpanel.c,v 1.1 2018/04/09 20:16:16 christos Exp $"); + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/proc.h> +#include <sys/poll.h> +#include <sys/conf.h> +#include <sys/uio.h> +#include <sys/types.h> +#include <sys/kernel.h> +#include <sys/device.h> +#include <sys/callout.h> +#include <sys/select.h> +#include <sys/reboot.h> + +#include <sys/bus.h> +#include <machine/autoconf.h> + +#include <dev/ic/hd44780reg.h> +#include <dev/ic/hd44780var.h> +#include <dev/ic/lcdkp_subr.h> + +#include "ioconf.h" + +#define LCDPANEL_POLLRATE (hz / 10) +#define LCDPANEL_REGION 0x20 +#define DATA_OFFSET 0x10 +#define LCDPANEL_COLS 16 +#define LCDPANEL_VCOLS 40 +#define LCDPANEL_ROWS 2 + +struct lcdpanel_softc { + device_t sc_dev; + + struct hd44780_chip sc_lcd; + struct lcdkp_chip sc_kp; + + struct selinfo sc_selq; + struct callout sc_callout; +}; + +struct lcd_message { + const char firstcol[LCDPANEL_VCOLS]; + const char secondcol[LCDPANEL_VCOLS]; +}; +static const struct lcd_message startup_message = { + "NetBSD/cobalt ", + "Starting up... " +}; +static const struct lcd_message halt_message = { + "NetBSD/cobalt ", + "Halting... " +}; +static const struct lcd_message reboot_message = { + "NetBSD/cobalt ", + "Rebooting... " +}; + +static int lcdpanel_match(device_t, cfdata_t, void *); +static void lcdpanel_attach(device_t, device_t, void *); +static bool lcdpanel_shutdown(device_t, int); + +static void lcdpanel_soft(void *); + +static uint8_t lcdpanel_cbt_kprread(bus_space_tag_t, bus_space_handle_t); +static uint8_t lcdpanel_cbt_hdreadreg(struct hd44780_chip *, uint32_t, uint32_t); +static void lcdpanel_cbt_hdwritereg(struct hd44780_chip *, uint32_t, uint32_t, + uint8_t); + +dev_type_open(lcdpanelopen); +dev_type_close(lcdpanelclose); +dev_type_read(lcdpanelread); +dev_type_write(lcdpanelwrite); +dev_type_ioctl(lcdpanelioctl); +dev_type_poll(lcdpanelpoll); + +const struct cdevsw lcdpanel_cdevsw = { + .d_open = lcdpanelopen, + .d_close = lcdpanelclose, + .d_read = lcdpanelread, + .d_write = lcdpanelwrite, + .d_ioctl = lcdpanelioctl, + .d_stop = nostop, + .d_tty = notty, + .d_poll = lcdpanelpoll, + .d_mmap = nommap, + .d_kqfilter = nokqfilter, + .d_discard = nodiscard, + .d_flag = 0 +}; + +CFATTACH_DECL_NEW(lcdpanel, sizeof(struct lcdpanel_softc), + lcdpanel_match, lcdpanel_attach, NULL, NULL); + +static int +lcdpanel_match(device_t parent, cfdata_t cf, void *aux) +{ + + return 1; +} + +static void +lcdpanel_attach(device_t parent, device_t self, void *aux) +{ + struct lcdpanel_softc *sc = device_private(self); + struct mainbus_attach_args *maa = aux; + struct hd44780_io io; + static struct lcdkp_xlate keys[] = { + { 0xfa, 'h' }, + { 0xf6, 'k' }, + { 0xde, 'l' }, + { 0xee, 'j' }, + { 0x7e, 's' }, + { 0xbe, 'e' } + }; + + sc->sc_lcd.sc_dev = self; + sc->sc_lcd.sc_iot = maa->ma_iot; + if (bus_space_map(sc->sc_lcd.sc_iot, maa->ma_addr, LCDPANEL_REGION, + 0, &sc->sc_lcd.sc_ioir)) { + aprint_error(": unable to map registers\n"); + return; + } + bus_space_subregion(sc->sc_lcd.sc_iot, sc->sc_lcd.sc_ioir, DATA_OFFSET, + 1, &sc->sc_lcd.sc_iodr); + + printf("\n"); + + sc->sc_lcd.sc_dev_ok = 1; + sc->sc_lcd.sc_cols = LCDPANEL_COLS; + sc->sc_lcd.sc_vcols = LCDPANEL_VCOLS; + sc->sc_lcd.sc_flags = HD_8BIT | HD_MULTILINE | HD_KEYPAD; + + sc->sc_lcd.sc_writereg = lcdpanel_cbt_hdwritereg; + sc->sc_lcd.sc_readreg = lcdpanel_cbt_hdreadreg; + + hd44780_attach_subr(&sc->sc_lcd); + + /* Hello World */ + io.dat = 0; + io.len = LCDPANEL_VCOLS * LCDPANEL_ROWS; + memcpy(io.buf, &startup_message, io.len); + hd44780_ddram_io(&sc->sc_lcd, sc->sc_lcd.sc_curchip, &io, + HD_DDRAM_WRITE); + + pmf_device_register1(self, NULL, NULL, lcdpanel_shutdown); + + sc->sc_kp.sc_iot = maa->ma_iot; + sc->sc_kp.sc_ioh = MIPS_PHYS_TO_KSEG1(LCDPANEL_BASE); /* XXX */ + + sc->sc_kp.sc_knum = sizeof(keys) / sizeof(struct lcdkp_xlate); + sc->sc_kp.sc_kpad = keys; + sc->sc_kp.sc_rread = lcdpanel_cbt_kprread; + + lcdkp_attach_subr(&sc->sc_kp); + + callout_init(&sc->sc_callout, 0); + selinit(&sc->sc_selq); +} + +static bool +lcdpanel_shutdown(device_t self, int howto) +{ + struct lcdpanel_softc *sc = device_private(self); + struct hd44780_io io; + + /* Goodbye World */ + io.dat = 0; + io.len = LCDPANEL_VCOLS * LCDPANEL_ROWS; + if (howto & RB_HALT) + memcpy(io.buf, &halt_message, io.len); + else + memcpy(io.buf, &reboot_message, io.len); + hd44780_ddram_io(&sc->sc_lcd, sc->sc_lcd.sc_curchip, &io, + HD_DDRAM_WRITE); + + return true; +} + +static uint8_t +lcdpanel_cbt_kprread(bus_space_tag_t iot, bus_space_handle_t ioh) +{ + + delay(HD_TIMEOUT_NORMAL); + return (bus_space_read_4(iot, ioh, 0x00) >> 24) & 0xff; +} + + +static void +lcdpanel_cbt_hdwritereg(struct hd44780_chip *hd, uint32_t en, uint32_t rs, + uint8_t dat) +{ + + if (rs) + bus_space_write_4(hd->sc_iot, hd->sc_iodr, 0x00, dat << 24); + else + bus_space_write_4(hd->sc_iot, hd->sc_ioir, 0x00, dat << 24); + delay(HD_TIMEOUT_NORMAL); +} + +static uint8_t +lcdpanel_cbt_hdreadreg(struct hd44780_chip *hd, uint32_t en, uint32_t rs) +{ + + delay(HD_TIMEOUT_NORMAL); + if (rs) + return (bus_space_read_4(hd->sc_iot, hd->sc_iodr, 0x00) >> 24) + & 0xff; + else + return (bus_space_read_4(hd->sc_iot, hd->sc_ioir, 0x00) >> 24) + & 0xff; +} + +int +lcdpanelopen(dev_t dev, int flag, int mode, struct lwp *l) +{ + struct lcdpanel_softc *sc = device_lookup_private(&lcdpanel_cd, minor(dev)); + + return (sc->sc_lcd.sc_dev_ok == 0) ? ENXIO : 0; +} + +int +lcdpanelclose(dev_t dev, int flag, int mode, struct lwp *l) +{ + struct lcdpanel_softc *sc = device_lookup_private(&lcdpanel_cd, minor(dev)); + + selnotify(&sc->sc_selq, 0, 0); + return 0; +} + +int +lcdpanelread(dev_t dev, struct uio *uio, int flag) +{ + int error; + uint8_t b; + struct lcdpanel_softc *sc = device_lookup_private(&lcdpanel_cd, minor(dev)); + + if (uio->uio_resid < sizeof(b)) + return EIO; + + if ((error = lcdkp_readkey(&sc->sc_kp, &b)) != 0) + return error; + + return uiomove((void*)&b, sizeof(b), uio); +} + +int +lcdpanelwrite(dev_t dev, struct uio *uio, int flag) +{ + int error; + struct hd44780_io io; + struct lcdpanel_softc *sc = device_lookup_private(&lcdpanel_cd, minor(dev)); + + io.dat = 0; + io.len = uio->uio_resid; + if (io.len > HD_MAX_CHARS) + io.len = HD_MAX_CHARS; + + if ((error = uiomove((void*)io.buf, io.len, uio)) != 0) + return error; + + hd44780_ddram_redraw(&sc->sc_lcd, 0, &io); + return 0; +} + +int +lcdpanelioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) +{ + struct lcdpanel_softc *sc = device_lookup_private(&lcdpanel_cd, minor(dev)); + + return hd44780_ioctl_subr(&sc->sc_lcd, cmd, data); +} + +int +lcdpanelpoll(dev_t dev, int events, struct lwp *l) +{ + int revents = 0; + + if ((events & (POLLIN | POLLRDNORM)) != 0) { + struct lcdpanel_softc *sc; + + sc = device_lookup_private(&lcdpanel_cd, minor(dev)); + if (lcdkp_scankey(&sc->sc_kp) != 0) { + revents = events & (POLLIN | POLLRDNORM); + } else { + selrecord(l, &sc->sc_selq); + callout_reset(&sc->sc_callout, LCDPANEL_POLLRATE, + lcdpanel_soft, sc); + } + } + + return revents; +} + +static void +lcdpanel_soft(void *arg) +{ + struct lcdpanel_softc *sc = arg; + + if (lcdkp_scankey(&sc->sc_kp) != 0) + selnotify(&sc->sc_selq, 0, 0); + else + callout_reset(&sc->sc_callout, LCDPANEL_POLLRATE, lcdpanel_soft, sc); +}