Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/hp700 Add the lcd(4) driver from OpenBSD. Thanks t...



details:   https://anonhg.NetBSD.org/src/rev/c6334bad91e0
branches:  trunk
changeset: 755319:c6334bad91e0
user:      skrll <skrll%NetBSD.org@localhost>
date:      Tue Jun 01 10:20:28 2010 +0000

description:
Add the lcd(4) driver from OpenBSD.  Thanks to Adam Hoka for doing most of
the work.

diffstat:

 sys/arch/hp700/conf/GENERIC     |    5 +-
 sys/arch/hp700/conf/files.hp700 |    6 +-
 sys/arch/hp700/dev/lcd.c        |  146 ++++++++++++++++++++++++++++++++++++++++
 sys/arch/hp700/hp700/machdep.c  |   92 ++++++++++++++++++++++++-
 sys/arch/hp700/hp700/mainbus.c  |   40 +++++++++-
 sys/arch/hp700/include/cpu.h    |   16 +++-
 6 files changed, 291 insertions(+), 14 deletions(-)

diffs (truncated from 454 to 300 lines):

diff -r 378f11e522b9 -r c6334bad91e0 sys/arch/hp700/conf/GENERIC
--- a/sys/arch/hp700/conf/GENERIC       Tue Jun 01 08:53:20 2010 +0000
+++ b/sys/arch/hp700/conf/GENERIC       Tue Jun 01 10:20:28 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.99 2010/05/08 22:16:27 mrg Exp $
+# $NetBSD: GENERIC,v 1.100 2010/06/01 10:20:28 skrll Exp $
 #
 # GENERIC machine description file
 #
@@ -23,7 +23,7 @@
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 options        SYSCTL_INCLUDE_DESCR    # Include sysctl descriptions in kernel
 
-#ident                 "GENERIC-$Revision: 1.99 $"
+#ident                 "GENERIC-$Revision: 1.100 $"
 
 maxusers       32              # estimated number of users
 
@@ -226,6 +226,7 @@
 # Miscellaneous
 pdc0   at mainbus0             # PDC/IODC wrapper for boot console
 power0 at mainbus0             # power/fail manager
+lcd0   at mainbus0             # LCD
 
 # STI graphics
 sti*   at mainbus0             # [H]CRX-{8,24,48}[Z] and Visualize graphics
diff -r 378f11e522b9 -r c6334bad91e0 sys/arch/hp700/conf/files.hp700
--- a/sys/arch/hp700/conf/files.hp700   Tue Jun 01 08:53:20 2010 +0000
+++ b/sys/arch/hp700/conf/files.hp700   Tue Jun 01 10:20:28 2010 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.hp700,v 1.22 2009/05/28 08:41:29 skrll Exp $
+#      $NetBSD: files.hp700,v 1.23 2010/06/01 10:20:28 skrll Exp $
 #
 #      $OpenBSD: files.hp700,v 1.31 2001/06/26 02:41:25 mickey Exp $
 #
@@ -77,6 +77,10 @@
 attach power at gedoens
 file   arch/hp700/dev/power.c          power needs-flag
 
+device lcd
+attach lcd at gedoens
+file   arch/hp700/dev/lcd.c            lcd needs-flag
+
 device mem
 attach mem at gedoens
 file   arch/hp700/dev/mem.c            mem
diff -r 378f11e522b9 -r c6334bad91e0 sys/arch/hp700/dev/lcd.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/hp700/dev/lcd.c  Tue Jun 01 10:20:28 2010 +0000
@@ -0,0 +1,146 @@
+/*     $NetBSD: lcd.c,v 1.1 2010/06/01 10:20:29 skrll Exp $    */
+/*     OpenBSD: lcd.c,v 1.2 2007/07/20 22:13:45 kettenis Exp   */
+
+/*
+ * Copyright (c) 2007 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/kernel.h>
+#include <sys/systm.h>
+#include <sys/callout.h>
+
+#include <machine/autoconf.h>
+#include <machine/bus.h>
+#include <machine/cpu.h>
+#include <machine/pdc.h>
+
+#define LCD_CLS                0x01
+#define LCD_HOME       0x02
+#define LCD_LOCATE(X, Y)       (((Y) & 1 ? 0xc0 : 0x80) | ((X) & 0x0f))
+
+struct lcd_softc {
+       device_t                sc_dv;
+
+       bus_space_tag_t         sc_iot;
+       bus_space_handle_t      sc_cmdh, sc_datah;
+
+       u_int                   sc_delay;
+       uint8_t                 sc_heartbeat[3];
+
+       struct callout          sc_to;
+       int                     sc_on;
+       struct blink_lcd        sc_blink;
+};
+
+int    lcd_match(device_t, cfdata_t, void *);
+void   lcd_attach(device_t, device_t, void *);
+
+CFATTACH_DECL_NEW(lcd, sizeof(struct lcd_softc), lcd_match,
+    lcd_attach, NULL, NULL);
+
+void   lcd_write(struct lcd_softc *, const char *);
+void   lcd_blink(void *, int);
+void   lcd_blink_finish(void *);
+
+int
+lcd_match(device_t parent, cfdata_t match, void *aux)
+{
+       struct confargs *ca = aux;
+
+       if (strcmp(ca->ca_name, "lcd") == 0)
+               return 1;
+
+       return 0;
+}
+
+void
+lcd_attach(device_t parent, device_t self, void *aux)
+{
+       struct lcd_softc *sc = device_private(self);
+       struct confargs *ca = aux;
+       struct pdc_chassis_lcd *pdc_lcd = (void *)ca->ca_pdc_iodc_read;
+       int i;
+
+       sc->sc_dv = self;
+       sc->sc_iot = ca->ca_iot;
+
+       if (bus_space_map(sc->sc_iot, pdc_lcd->cmd_addr,
+               1, 0, &sc->sc_cmdh)) {
+               aprint_error(": cannot map cmd register\n");
+               return;
+       }
+
+       if (bus_space_map(sc->sc_iot, pdc_lcd->data_addr,
+               1, 0, &sc->sc_datah)) {
+               aprint_error(": cannot map data register\n");
+               bus_space_unmap(sc->sc_iot, sc->sc_cmdh, 1);
+               return;
+       }
+
+       aprint_normal(": model %d\n", pdc_lcd->model);
+
+       sc->sc_delay = pdc_lcd->delay;
+       for (i = 0; i < 3; i++)
+               sc->sc_heartbeat[i] = pdc_lcd->heartbeat[i];
+
+       bus_space_write_1(sc->sc_iot, sc->sc_cmdh, 0, LCD_CLS);
+       delay(100 * sc->sc_delay);
+
+       bus_space_write_1(sc->sc_iot, sc->sc_cmdh, 0, LCD_LOCATE(0, 0));
+       delay(sc->sc_delay);
+       lcd_write(sc, "NetBSD/" MACHINE);
+
+       callout_init(&sc->sc_to, 0);
+       callout_setfunc(&sc->sc_to, lcd_blink_finish, sc);
+
+       sc->sc_blink.bl_func = lcd_blink;
+       sc->sc_blink.bl_arg = sc;
+       blink_lcd_register(&sc->sc_blink);
+}
+
+void
+lcd_write(struct lcd_softc *sc, const char *str)
+{
+       while (*str) {
+               bus_space_write_1(sc->sc_iot, sc->sc_datah, 0, *str++);
+               delay(sc->sc_delay);
+       }
+}
+
+void
+lcd_blink(void *v, int on)
+{
+       struct lcd_softc *sc = v;
+
+       sc->sc_on = on;
+       bus_space_write_1(sc->sc_iot, sc->sc_cmdh, 0, sc->sc_heartbeat[0]);
+       callout_schedule(&sc->sc_to, max(1, (sc->sc_delay * hz) / 1000000));
+}
+
+void
+lcd_blink_finish(void *v)
+{
+       struct lcd_softc *sc = v;
+       uint8_t data;
+
+       if (sc->sc_on)
+               data = sc->sc_heartbeat[1];
+       else
+               data = sc->sc_heartbeat[2];
+
+       bus_space_write_1(sc->sc_iot, sc->sc_datah, 0, data);
+}
diff -r 378f11e522b9 -r c6334bad91e0 sys/arch/hp700/hp700/machdep.c
--- a/sys/arch/hp700/hp700/machdep.c    Tue Jun 01 08:53:20 2010 +0000
+++ b/sys/arch/hp700/hp700/machdep.c    Tue Jun 01 10:20:28 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.84 2010/04/30 15:36:45 skrll Exp $       */
+/*     $NetBSD: machdep.c,v 1.85 2010/06/01 10:20:29 skrll Exp $       */
 
 /*-
  * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.84 2010/04/30 15:36:45 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.85 2010/06/01 10:20:29 skrll Exp $");
 
 #include "opt_cputype.h"
 #include "opt_ddb.h"
@@ -130,6 +130,7 @@
 #endif
 
 #include "ksyms.h"
+#include "lcd.h"
 
 /*
  * Different kinds of flags used throughout the kernel.
@@ -205,6 +206,10 @@
 int    cpu_hvers;
 int    cpu_revision;
 
+#if NLCD > 0
+int    lcd_blink_p;
+#endif
+
 /*
  * exported methods for cpus
  */
@@ -265,6 +270,9 @@
 void dumpsys(void);
 void cpuid(void);
 enum hppa_cpu_type cpu_model_cpuid(int);
+#if NLCD > 0
+void blink_lcd_timeout(void *);
+#endif
 
 /*
  * wide used hardware params
@@ -1910,6 +1918,29 @@
        return (sysctl_lookup(SYSCTLFN_CALL(&node)));
 }
 
+#if NLCD > 0
+static int
+sysctl_machdep_heartbeat(SYSCTLFN_ARGS)
+{
+       int oldval, error;
+       struct sysctlnode node = *rnode;
+       
+       oldval = lcd_blink_p;
+       /*
+        * If we were false and are now true, start the timer.
+        */
+       error = sysctl_lookup(SYSCTLFN_CALL(&node));
+
+       if (error || newp == NULL)
+               return (error);
+
+       if (!oldval && lcd_blink_p > oldval)
+               blink_lcd_timeout(NULL);
+
+       return 0;
+}
+#endif
+
 /*
  * machine dependent system variables.
  */
@@ -1933,6 +1964,13 @@
                       CTLTYPE_STRING, "booted_kernel", NULL,
                       sysctl_machdep_boot, 0, NULL, 0,
                       CTL_MACHDEP, CPU_BOOTED_KERNEL, CTL_EOL);
+#if NLCD > 0
+       sysctl_createv(clog, 0, NULL, NULL,
+                      CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+                      CTLTYPE_BOOL, "lcd_blink", "Display heartbeat on the LCD display",
+                      sysctl_machdep_heartbeat, 0, &lcd_blink_p, 0,
+                      CTL_MACHDEP, CPU_LCD_BLINK, CTL_EOL);
+#endif
 }
 
 /*
@@ -1973,6 +2011,56 @@
        }
 }
 
+#if NLCD > 0
+struct blink_lcd_softc {
+       SLIST_HEAD(, blink_lcd) bls_head;
+       int bls_on;
+       struct callout bls_to;
+} blink_sc = { SLIST_HEAD_INITIALIZER(bls_head), 0 };
+
+void
+blink_lcd_register(struct blink_lcd *l)



Home | Main Index | Thread Index | Old Index