Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/arm/allwinner hardware cursor support



details:   https://anonhg.NetBSD.org/src/rev/ee1fa1ae5c8d
branches:  trunk
changeset: 334669:ee1fa1ae5c8d
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Nov 30 19:15:53 2014 +0000

description:
hardware cursor support

diffstat:

 sys/arch/arm/allwinner/awin_debe.c |  150 +++++++++++++-
 sys/arch/arm/allwinner/awin_fb.c   |    8 +-
 sys/arch/arm/allwinner/awin_mp.c   |  398 +++++++++++++++++++++++++++++++++++++
 sys/arch/arm/allwinner/awin_reg.h  |   19 +
 4 files changed, 571 insertions(+), 4 deletions(-)

diffs (truncated from 674 to 300 lines):

diff -r d2f6e04883e4 -r ee1fa1ae5c8d sys/arch/arm/allwinner/awin_debe.c
--- a/sys/arch/arm/allwinner/awin_debe.c        Sun Nov 30 19:15:03 2014 +0000
+++ b/sys/arch/arm/allwinner/awin_debe.c        Sun Nov 30 19:15:53 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: awin_debe.c,v 1.8 2014/11/14 23:45:02 jmcneill Exp $ */
+/* $NetBSD: awin_debe.c,v 1.9 2014/11/30 19:15:53 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -33,8 +33,10 @@
 #define AWIN_DEBE_VIDEOMEM     (16 * 1024 * 1024)
 #endif
 
+#define AWIN_DEBE_CURMAX       64
+
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: awin_debe.c,v 1.8 2014/11/14 23:45:02 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: awin_debe.c,v 1.9 2014/11/30 19:15:53 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -66,6 +68,11 @@
        void *sc_dmap;
 
        uint16_t sc_margin;
+
+       int sc_cursor_x, sc_cursor_y;
+       int sc_hot_x, sc_hot_y;
+       uint8_t sc_cursor_bitmap[8 * AWIN_DEBE_CURMAX];
+       uint8_t sc_cursor_mask[8 * AWIN_DEBE_CURMAX];
 };
 
 #define DEBE_READ(sc, reg) \
@@ -80,6 +87,10 @@
 static void    awin_debe_setup_fbdev(struct awin_debe_softc *,
                                      const struct videomode *);
 
+static int     awin_debe_set_curpos(struct awin_debe_softc *, int, int);
+static int     awin_debe_set_cursor(struct awin_debe_softc *,
+                                    struct wsdisplay_cursor *);
+
 CFATTACH_DECL_NEW(awin_debe, sizeof(struct awin_debe_softc),
        awin_debe_match, awin_debe_attach, NULL, NULL);
 
@@ -177,6 +188,8 @@
 
        DEBE_WRITE(sc, AWIN_DEBE_MODCTL_REG, AWIN_DEBE_MODCTL_EN);
 
+       DEBE_WRITE(sc, AWIN_DEBE_HWC_PALETTE_TABLE, 0);
+
        error = awin_debe_alloc_videomem(sc);
        if (error) {
                aprint_error_dev(sc->sc_dev,
@@ -255,6 +268,123 @@
 #endif
 }
 
+static int
+awin_debe_set_curpos(struct awin_debe_softc *sc, int x, int y)
+{
+       int xx, yy;
+       u_int yoff, xoff;
+
+       xoff = yoff = 0;
+       xx = x - sc->sc_hot_x + sc->sc_margin;
+       yy = y - sc->sc_hot_y + sc->sc_margin;
+       if (xx < 0) {
+               xoff -= xx;
+               xx = 0;
+       }
+       if (yy < 0) {
+               yoff -= yy;
+               yy = 0;
+       }
+
+       DEBE_WRITE(sc, AWIN_DEBE_HWCCTL_REG,
+           __SHIFTIN(yy, AWIN_DEBE_HWCCTL_YCOOR) |
+           __SHIFTIN(xx, AWIN_DEBE_HWCCTL_XCOOR));
+       DEBE_WRITE(sc, AWIN_DEBE_HWCFBCTL_REG,
+#if AWIN_DEBE_CURMAX == 32
+           __SHIFTIN(AWIN_DEBE_HWCFBCTL_YSIZE_32, AWIN_DEBE_HWCFBCTL_YSIZE) |
+           __SHIFTIN(AWIN_DEBE_HWCFBCTL_XSIZE_32, AWIN_DEBE_HWCFBCTL_XSIZE) |
+#else
+           __SHIFTIN(AWIN_DEBE_HWCFBCTL_YSIZE_64, AWIN_DEBE_HWCFBCTL_YSIZE) |
+           __SHIFTIN(AWIN_DEBE_HWCFBCTL_XSIZE_64, AWIN_DEBE_HWCFBCTL_XSIZE) |
+#endif
+           __SHIFTIN(AWIN_DEBE_HWCFBCTL_FBFMT_2BPP, AWIN_DEBE_HWCFBCTL_FBFMT) |
+           __SHIFTIN(yoff, AWIN_DEBE_HWCFBCTL_YCOOROFF) |
+           __SHIFTIN(xoff, AWIN_DEBE_HWCFBCTL_XCOOROFF));
+
+       return 0;
+}
+
+static int
+awin_debe_set_cursor(struct awin_debe_softc *sc, struct wsdisplay_cursor *cur)
+{
+       uint32_t val;
+       uint8_t r[4], g[4], b[4];
+       u_int index, count, shift, off, pcnt;
+       int i, j, idx, error;
+       uint8_t mask;
+
+       if (cur->which & WSDISPLAY_CURSOR_DOCUR) {
+               val = DEBE_READ(sc, AWIN_DEBE_MODCTL_REG);
+               if (cur->enable)
+                       val |= AWIN_DEBE_MODCTL_HWC_EN;
+               else
+                       val &= ~AWIN_DEBE_MODCTL_HWC_EN;
+               DEBE_WRITE(sc, AWIN_DEBE_MODCTL_REG, val);
+       }
+
+       if (cur->which & WSDISPLAY_CURSOR_DOHOT) {
+               sc->sc_hot_x = cur->hot.x;
+               sc->sc_hot_y = cur->hot.y;
+               cur->which |= WSDISPLAY_CURSOR_DOPOS;
+       }
+
+       if (cur->which & WSDISPLAY_CURSOR_DOPOS) {
+               awin_debe_set_curpos(sc, cur->pos.x, cur->pos.y);
+       }
+
+       if (cur->which & WSDISPLAY_CURSOR_DOCMAP) {
+               index = cur->cmap.index;
+               count = cur->cmap.count;
+               if (index >= 2 || (index + count) > 2)
+                       return EINVAL;
+               error = copyin(cur->cmap.red, &r[index], count);
+               if (error)
+                       return error;
+               error = copyin(cur->cmap.green, &g[index], count);
+               if (error)
+                       return error;
+               error = copyin(cur->cmap.blue, &b[index], count);
+               if (error)
+                       return error;
+
+               for (i = index; i < (index + count); i++) {
+                       DEBE_WRITE(sc,
+                           AWIN_DEBE_HWC_PALETTE_TABLE + (4 * (i + 2)),
+                           (r[i] << 16) | (g[i] << 8) | b[i] | 0xff000000);
+               }
+       }
+
+       if (cur->which & WSDISPLAY_CURSOR_DOSHAPE) {
+               error = copyin(cur->mask, sc->sc_cursor_mask,
+                   AWIN_DEBE_CURMAX * 8);
+               if (error)
+                       return error;
+               error = copyin(cur->image, sc->sc_cursor_bitmap,
+                   AWIN_DEBE_CURMAX * 8);
+               if (error)
+                       return error;
+       }
+
+       if (cur->which & (WSDISPLAY_CURSOR_DOCMAP|WSDISPLAY_CURSOR_DOSHAPE)) {
+               for (i = 0, pcnt = 0; i < AWIN_DEBE_CURMAX * 8; i++) {
+                       for (j = 0, mask = 1; j < 8; j++, mask <<= 1, pcnt++) {
+                               idx = ((sc->sc_cursor_mask[i] & mask) ? 2 : 0) |
+                                   ((sc->sc_cursor_bitmap[i] & mask) ? 1 : 0);
+                               off = (pcnt >> 4) * 4;
+                               shift = (pcnt & 0xf) * 2;
+                               val = DEBE_READ(sc,
+                                   AWIN_DEBE_HWC_PATTERN_BLOCK + off);
+                               val &= ~(3 << shift);
+                               val |= (idx << shift);
+                               DEBE_WRITE(sc,
+                                   AWIN_DEBE_HWC_PATTERN_BLOCK + off, val);
+                       }
+               }
+       }
+
+       return 0;
+}
+
 void
 awin_debe_enable(bool enable)
 {
@@ -366,6 +496,7 @@
 awin_debe_ioctl(device_t self, u_long cmd, void *data)
 {
        struct awin_debe_softc *sc = device_private(self);
+       struct wsdisplay_curpos *cp;
        uint32_t val;
        int enable;
 
@@ -383,6 +514,21 @@
                val = DEBE_READ(sc, AWIN_DEBE_MODCTL_REG);
                *(int *)data = !!(val & AWIN_DEBE_MODCTL_LAY0_EN);
                return 0;
+       case WSDISPLAYIO_GCURPOS:
+               cp = data;
+               cp->x = sc->sc_cursor_x;
+               cp->y = sc->sc_cursor_y;
+               return 0;
+       case WSDISPLAYIO_SCURPOS:
+               cp = data;
+               return awin_debe_set_curpos(sc, cp->x, cp->y);
+       case WSDISPLAYIO_GCURMAX:
+               cp = data;
+               cp->x = AWIN_DEBE_CURMAX;
+               cp->y = AWIN_DEBE_CURMAX;
+               return 0;
+       case WSDISPLAYIO_SCURSOR:
+               return awin_debe_set_cursor(sc, data);
        }
 
        return EPASSTHROUGH;
diff -r d2f6e04883e4 -r ee1fa1ae5c8d sys/arch/arm/allwinner/awin_fb.c
--- a/sys/arch/arm/allwinner/awin_fb.c  Sun Nov 30 19:15:03 2014 +0000
+++ b/sys/arch/arm/allwinner/awin_fb.c  Sun Nov 30 19:15:53 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: awin_fb.c,v 1.6 2014/11/14 23:45:02 jmcneill Exp $ */
+/* $NetBSD: awin_fb.c,v 1.7 2014/11/30 19:15:53 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: awin_fb.c,v 1.6 2014/11/14 23:45:02 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: awin_fb.c,v 1.7 2014/11/30 19:15:53 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -148,6 +148,10 @@
                return error;
        case WSDISPLAYIO_SVIDEO:
        case WSDISPLAYIO_GVIDEO:
+       case WSDISPLAYIO_GCURPOS:
+       case WSDISPLAYIO_SCURPOS:
+       case WSDISPLAYIO_GCURMAX:
+       case WSDISPLAYIO_SCURSOR:
                return awin_debe_ioctl(sc->sc_debedev, cmd, data);
        default:
                return EPASSTHROUGH;
diff -r d2f6e04883e4 -r ee1fa1ae5c8d sys/arch/arm/allwinner/awin_mp.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/allwinner/awin_mp.c  Sun Nov 30 19:15:53 2014 +0000
@@ -0,0 +1,398 @@
+/* $NetBSD: awin_mp.c,v 1.1 2014/11/30 19:15:53 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2014 Jared D. McNeill <jmcneill%invisible.ca@localhost>
+ * 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 ``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 "opt_ddb.h"
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: awin_mp.c,v 1.1 2014/11/30 19:15:53 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/device.h>
+#include <sys/intr.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/mutex.h>
+#include <sys/condvar.h>
+
+#include <arm/allwinner/awin_reg.h>
+#include <arm/allwinner/awin_var.h>
+
+#include <dev/wscons/wsconsio.h>
+
+struct awin_mp_softc {
+       device_t sc_dev;
+       bus_space_tag_t sc_bst;
+       bus_space_handle_t sc_bsh;
+       kmutex_t sc_lock;
+       kcondvar_t sc_cv;
+       void *sc_ih;
+
+       paddr_t sc_membase;
+       size_t sc_memsize;
+
+       uint32_t sc_intr_sts;
+};



Home | Main Index | Thread Index | Old Index