Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/hpcmips OptPoint on Telios HC-AJ2 (and maybe AJ1) s...



details:   https://anonhg.NetBSD.org/src/rev/7c50cd563aed
branches:  trunk
changeset: 580693:7c50cd563aed
user:      hamajima <hamajima%NetBSD.org@localhost>
date:      Wed May 04 07:54:39 2005 +0000

description:
OptPoint on Telios HC-AJ2 (and maybe AJ1) support

diffstat:

 sys/arch/hpcmips/conf/GENERIC          |    6 +-
 sys/arch/hpcmips/conf/files.hpcmips    |   12 +-
 sys/arch/hpcmips/conf/std.hpcmips.tx39 |    3 +-
 sys/arch/hpcmips/dev/optpoint.c        |  287 +++++++++++++++++++++++++++++++++
 sys/arch/hpcmips/tx/tx39spi.c          |  239 +++++++++++++++++++++++++++
 sys/arch/hpcmips/tx/tx39spivar.h       |   48 +++++
 6 files changed, 591 insertions(+), 4 deletions(-)

diffs (truncated from 666 to 300 lines):

diff -r 6a8905a7deec -r 7c50cd563aed sys/arch/hpcmips/conf/GENERIC
--- a/sys/arch/hpcmips/conf/GENERIC     Wed May 04 06:38:06 2005 +0000
+++ b/sys/arch/hpcmips/conf/GENERIC     Wed May 04 07:54:39 2005 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.166 2005/04/15 17:27:21 itohy Exp $
+# $NetBSD: GENERIC,v 1.167 2005/05/04 07:54:39 hamajima Exp $
 #
 # GENERIC machine description file
 # 
@@ -24,7 +24,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident                 "GENERIC-$Revision: 1.166 $"
+#ident                 "GENERIC-$Revision: 1.167 $"
 
 maxusers       16
 
@@ -407,6 +407,8 @@
 # Sharp Telios HC-AJ1/AJ2/AJ3, HC-VJ1C
 #
 txcsbus1       at tx39biu? platform SHARP_TELIOS
+#optpoint*     at tx39spi? slot 0
+#wsmouse*      at optpoint? mux 0
 
 # IO module manager (virtual bridge) DO NOT DELETE
 txioman* at txsim?
diff -r 6a8905a7deec -r 7c50cd563aed sys/arch/hpcmips/conf/files.hpcmips
--- a/sys/arch/hpcmips/conf/files.hpcmips       Wed May 04 06:38:06 2005 +0000
+++ b/sys/arch/hpcmips/conf/files.hpcmips       Wed May 04 07:54:39 2005 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.hpcmips,v 1.96 2004/07/06 13:09:19 uch Exp $
+#      $NetBSD: files.hpcmips,v 1.97 2005/05/04 07:54:39 hamajima Exp $
 
 # maxpartitions must be first item in files.${ARCH}.
 maxpartitions 8
@@ -234,6 +234,7 @@
 device txcsbusif {[platform = -1]}
 device txcomif {[slot = -1]}
 device txsibif {[slot = -1]}
+device txspiif {[slot = -1]}
 device ucbif { }
 device irif { }
 
@@ -277,6 +278,10 @@
 attach tx39sib at txsim
 file arch/hpcmips/tx/tx39sib.c         tx39sib
 
+device tx39spi: txspiif
+attach tx39spi at txsim
+file arch/hpcmips/tx/tx39spi.c         tx39spi
+
 #      PHILIPS UCB1200 / TOSHIBA TC35413F (modem/audio analog front-end)
 device ucb: ucbif
 attach ucb at txsibif
@@ -444,4 +449,9 @@
 attach flash at vripif with flash_vrip
 file arch/hpcmips/vr/flash_vrip.c      flash_vrip      needs-flag
 
+# OptPoint on Telios HC-AJ2
+device optpoint : wsmousedev
+attach optpoint at txspiif
+file arch/hpcmips/dev/optpoint.c       optpoint
+
 include "arch/hpcmips/conf/majors.hpcmips"
diff -r 6a8905a7deec -r 7c50cd563aed sys/arch/hpcmips/conf/std.hpcmips.tx39
--- a/sys/arch/hpcmips/conf/std.hpcmips.tx39    Wed May 04 06:38:06 2005 +0000
+++ b/sys/arch/hpcmips/conf/std.hpcmips.tx39    Wed May 04 07:54:39 2005 +0000
@@ -1,5 +1,5 @@
 #
-#      $NetBSD: std.hpcmips.tx39,v 1.1 2002/01/02 13:13:19 uch Exp $
+#      $NetBSD: std.hpcmips.tx39,v 1.2 2005/05/04 07:54:39 hamajima Exp $
 #      TX39XX common configuration.
 #
 
@@ -23,3 +23,4 @@
 tx39uart*      at txsim?
 txcom0         at tx39uart? slot 0
 txcom1         at tx39uart? slot 1
+tx39spi*       at txsim?
diff -r 6a8905a7deec -r 7c50cd563aed sys/arch/hpcmips/dev/optpoint.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/hpcmips/dev/optpoint.c   Wed May 04 07:54:39 2005 +0000
@@ -0,0 +1,287 @@
+/*     $NetBSD: optpoint.c,v 1.1 2005/05/04 07:54:39 hamajima Exp $ */
+
+/*-
+ * Copyright (c) 2005 HAMAJIMA Katsuomi. 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.
+ */
+
+/*
+ * OptOpint on Telios HC-AJ2
+ */
+
+#include <sys/cdefs.h>
+
+__KERNEL_RCSID(0, "$NetBSD: optpoint.c,v 1.1 2005/05/04 07:54:39 hamajima Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <machine/bus.h>
+#include <dev/hpc/hpciovar.h>
+#include <dev/wscons/wsconsio.h>
+#include <dev/wscons/wsmousevar.h>
+#include <hpcmips/tx/tx39var.h>
+#include <hpcmips/tx/tx39spivar.h>
+#include <hpcmips/tx/tx39icureg.h>
+
+#undef OPTPOINTDEBUG
+
+#ifdef OPTPOINTDEBUG
+#define        DPRINTF(arg) printf arg
+#else
+#define        DPRINTF(arg)
+#endif
+
+struct optpoint_softc {
+       struct device sc_dev;
+       tx_chipset_tag_t sc_tc;
+       struct tx39spi_softc *sc_spi;
+       struct hpcio_chip *sc_hc;
+       struct device *sc_wsmousedev;
+       char packet[4];
+       int index;      /* number of bytes received for this packet */
+       u_int buttons;  /* mouse button status */
+       int enabled;
+};
+
+static int optpoint_match(struct device *, struct cfdata *, void *);
+static void optpoint_attach(struct device *, struct device *, void *);
+static int optpoint_intr(void *);
+static int optpoint_enable(void *);
+static void optpoint_disable(void *);
+static int optpoint_ioctl(void *, u_long, caddr_t, int, struct proc *);
+static int optpoint_initialize(void *);
+static void optpoint_send(struct optpoint_softc *, int);
+static int optpoint_recv(struct optpoint_softc *);
+
+#define LBUTMASK 0x01
+#define RBUTMASK 0x02
+
+#define TX39_INTRSTATUS4_OPTPOINTINT   TX39_INTRSTATUS4_CARDIORDNEGINT
+#define TX39_IO_MFIO_CARDREG   11
+#define TX39_IO_MFIO_CARDIOWR  10
+#define TX39_IO_MFIO_CARDIORD  9
+#define TELIOS_MFIO_OPTP_T_RDY         TX39_IO_MFIO_CARDREG
+#define TELIOS_MFIO_OPTP_C_REQ         TX39_IO_MFIO_CARDIOWR
+#define TELIOS_MFIO_OPTP_S_ENB_N       TX39_IO_MFIO_CARDIORD
+
+CFATTACH_DECL(optpoint, sizeof(struct optpoint_softc),
+    optpoint_match, optpoint_attach, NULL, NULL);
+
+const struct wsmouse_accessops optpoint_accessops = {
+       optpoint_enable,
+       optpoint_ioctl,
+       optpoint_disable,
+};
+
+int
+optpoint_match(struct device *parent, struct cfdata *cf, void *aux)
+{
+       return (ATTACH_NORMAL);
+}
+
+void
+optpoint_attach(struct device *parent, struct device *self, void *aux)
+{
+       struct txspi_attach_args *ta = aux;
+       struct optpoint_softc *sc = (void*)self;
+       struct tx39spi_softc *spi = sc->sc_spi = (void*)parent;
+       tx_chipset_tag_t tc = sc->sc_tc = ta->sa_tc;
+       struct wsmousedev_attach_args wsmaa;
+
+       sc->sc_hc = tc->tc_iochip[MFIO];
+       sc->enabled = 0;
+
+       /* Specific SPI settings for OptPoint of HC-AJ2 */
+       tx39spi_delayval(spi, 0);
+       tx39spi_baudrate(spi, 4);       /* SPICLK Rate = 737.3 kHz */
+       tx39spi_word(spi, 0);           /* Use 8bits of data */
+       tx39spi_phapol(spi, 0);
+       tx39spi_clkpol(spi, 1);
+       tx39spi_lsb(spi, 0);            /* MSB first */
+
+       optpoint_enable(sc);
+       printf("\n");
+
+       wsmaa.accessops = &optpoint_accessops;
+       wsmaa.accesscookie = sc;
+       /* attach the wsmouse */
+       sc->sc_wsmousedev = config_found(self, &wsmaa, wsmousedevprint);
+}
+
+int
+optpoint_intr(void *self)
+{
+       struct optpoint_softc *sc = (void*)self;
+       tx_chipset_tag_t tc = sc->sc_tc;
+       char data = optpoint_recv(sc) & 0xff;
+
+#ifdef DIAGNOSTIC
+       if (sc->index >= 3){
+               printf("%s: Receive buffer overflow\n", sc->sc_dev.dv_xname);
+               sc->index = 0;
+               memset(sc->packet, 0, 3);
+       }
+#endif
+       if ((sc->index == 1) && (data & 0xcc) != 0x08){
+               DPRINTF(("%s: Bad second byte (0x%02x)\n",
+                        sc->sc_dev.dv_xname, data));
+               tx_conf_write(tc, TX39_INTRCLEAR4_REG,
+                                 TX39_INTRSTATUS4_OPTPOINTINT);
+               return 0;
+       }
+
+       sc->packet[sc->index++] = data;
+       if (sc->index >= 3){
+               u_int newbuttons = ((sc->packet[1] & LBUTMASK) ? 0x1 : 0) |
+                   ((sc->packet[1] & RBUTMASK) ? 0x2 : 0);
+               int dx = sc->packet[2];
+               int dy = sc->packet[0];
+               u_int changed = (sc->buttons ^ newbuttons);
+
+               if (dx || dy || changed){
+                       DPRINTF(("buttons=0x%x, dx=%d, dy=%d\n",
+                                newbuttons, dx, dy));
+                       wsmouse_input(sc->sc_wsmousedev,
+                                     sc->buttons, dx, dy, 0,
+                                     WSMOUSE_INPUT_DELTA);
+               }
+               sc->buttons = newbuttons;
+               sc->index = 0;
+               memset(sc->packet, 0, 3);
+       }
+       tx_conf_write(tc, TX39_INTRCLEAR4_REG, TX39_INTRSTATUS4_OPTPOINTINT);
+
+       return 0;
+}
+
+int
+optpoint_enable(void *self)
+{
+       struct optpoint_softc *sc = (void*)self;
+
+       if (!sc->enabled){
+               tx_chipset_tag_t tc = sc->sc_tc;
+               struct hpcio_chip *hc = sc->sc_hc;
+               int s = spltty();
+
+               sc->enabled = 1;
+               sc->index = 0;
+               sc->buttons = 0;
+               sc->packet[0] = 0xf5;   /* Disable */
+               sc->packet[1] = 0xf2;   /* Set Stream Mode */
+               sc->packet[2] = 0xf8;   /* Stanby */
+               sc->packet[3] = 0xf4;   /* Enable */
+
+               tx39spi_enable(sc->sc_spi, 1);
+               tx_intr_establish(tc, MAKEINTR(4, TX39_INTRSTATUS4_OPTPOINTINT),
+                                 IST_EDGE, IPL_TTY, optpoint_initialize, sc);
+               (*hc->hc_portwrite)(hc, TELIOS_MFIO_OPTP_C_REQ, 1);
+               (*hc->hc_portwrite)(hc, TELIOS_MFIO_OPTP_T_RDY, 1);
+               splx(s);
+       }
+
+        return 0;
+}
+
+void
+optpoint_disable(void *self)
+{
+       struct optpoint_softc *sc = (void*)self;
+
+       if (sc->enabled){
+               tx_chipset_tag_t tc = sc->sc_tc;
+               struct hpcio_chip *hc = sc->sc_hc;
+               int s = spltty();
+



Home | Main Index | Thread Index | Old Index