| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: pm2fb.c,v 1.23 2013/07/30 19:21:50 macallan Exp $ */ | | 1 | /* $NetBSD: pm2fb.c,v 1.24 2013/09/15 09:34:07 martin Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2009, 2012 Michael Lorenz | | 4 | * Copyright (c) 2009, 2012 Michael Lorenz |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -21,27 +21,27 @@ | | | @@ -21,27 +21,27 @@ |
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | | 26 | */ |
27 | | | 27 | |
28 | /* | | 28 | /* |
29 | * A console driver for Permedia 2 graphics controllers | | 29 | * A console driver for Permedia 2 graphics controllers |
30 | * tested on sparc64 only so far | | 30 | * tested on sparc64 only so far |
31 | */ | | 31 | */ |
32 | | | 32 | |
33 | #include <sys/cdefs.h> | | 33 | #include <sys/cdefs.h> |
34 | __KERNEL_RCSID(0, "$NetBSD: pm2fb.c,v 1.23 2013/07/30 19:21:50 macallan Exp $"); | | 34 | __KERNEL_RCSID(0, "$NetBSD: pm2fb.c,v 1.24 2013/09/15 09:34:07 martin Exp $"); |
35 | | | 35 | |
36 | #include <sys/param.h> | | 36 | #include <sys/param.h> |
37 | #include <sys/systm.h> | | 37 | #include <sys/systm.h> |
38 | #include <sys/kernel.h> | | 38 | #include <sys/kernel.h> |
39 | #include <sys/device.h> | | 39 | #include <sys/device.h> |
40 | #include <sys/malloc.h> | | 40 | #include <sys/malloc.h> |
41 | #include <sys/lwp.h> | | 41 | #include <sys/lwp.h> |
42 | #include <sys/kauth.h> | | 42 | #include <sys/kauth.h> |
43 | #include <sys/atomic.h> | | 43 | #include <sys/atomic.h> |
44 | | | 44 | |
45 | #include <dev/videomode/videomode.h> | | 45 | #include <dev/videomode/videomode.h> |
46 | | | 46 | |
47 | #include <dev/pci/pcivar.h> | | 47 | #include <dev/pci/pcivar.h> |
| @@ -849,27 +849,27 @@ pm2fb_rectfill_a(void *cookie, int x, in | | | @@ -849,27 +849,27 @@ pm2fb_rectfill_a(void *cookie, int x, in |
849 | { | | 849 | { |
850 | struct pm2fb_softc *sc = cookie; | | 850 | struct pm2fb_softc *sc = cookie; |
851 | | | 851 | |
852 | pm2fb_rectfill(sc, x, y, wi, he, | | 852 | pm2fb_rectfill(sc, x, y, wi, he, |
853 | sc->vd.active->scr_ri.ri_devcmap[(attr >> 24 & 0xf)]); | | 853 | sc->vd.active->scr_ri.ri_devcmap[(attr >> 24 & 0xf)]); |
854 | } | | 854 | } |
855 | | | 855 | |
856 | static void | | 856 | static void |
857 | pm2fb_bitblt(void *cookie, int xs, int ys, int xd, int yd, | | 857 | pm2fb_bitblt(void *cookie, int xs, int ys, int xd, int yd, |
858 | int wi, int he, int rop) | | 858 | int wi, int he, int rop) |
859 | { | | 859 | { |
860 | struct pm2fb_softc *sc = cookie; | | 860 | struct pm2fb_softc *sc = cookie; |
861 | uint32_t dir = 0; | | 861 | uint32_t dir = 0; |
862 | int rxs, rxd, rwi, rxdelta; | | 862 | int rxd, rwi, rxdelta; |
863 | | | 863 | |
864 | if (yd <= ys) { | | 864 | if (yd <= ys) { |
865 | dir |= PM2RE_INC_Y; | | 865 | dir |= PM2RE_INC_Y; |
866 | } | | 866 | } |
867 | if (xd <= xs) { | | 867 | if (xd <= xs) { |
868 | dir |= PM2RE_INC_X; | | 868 | dir |= PM2RE_INC_X; |
869 | } | | 869 | } |
870 | pm2fb_wait(sc, 8); | | 870 | pm2fb_wait(sc, 8); |
871 | bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_DDA_MODE, 0); | | 871 | bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_DDA_MODE, 0); |
872 | bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_MODE, 0); | | 872 | bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_MODE, 0); |
873 | if (sc->sc_depth == 8) { | | 873 | if (sc->sc_depth == 8) { |
874 | int adjust; | | 874 | int adjust; |
875 | /* | | 875 | /* |
| @@ -881,51 +881,49 @@ pm2fb_bitblt(void *cookie, int xs, int y | | | @@ -881,51 +881,49 @@ pm2fb_bitblt(void *cookie, int xs, int y |
881 | */ | | 881 | */ |
882 | if (rop == 3) { | | 882 | if (rop == 3) { |
883 | bus_space_write_4(sc->sc_memt, sc->sc_regh, | | 883 | bus_space_write_4(sc->sc_memt, sc->sc_regh, |
884 | PM2_RE_CONFIG, | | 884 | PM2_RE_CONFIG, |
885 | PM2RECFG_READ_SRC | PM2RECFG_WRITE_EN | | | 885 | PM2RECFG_READ_SRC | PM2RECFG_WRITE_EN | |
886 | PM2RECFG_ROP_EN | PM2RECFG_PACKED | (rop << 6)); | | 886 | PM2RECFG_ROP_EN | PM2RECFG_PACKED | (rop << 6)); |
887 | } else { | | 887 | } else { |
888 | bus_space_write_4(sc->sc_memt, sc->sc_regh, | | 888 | bus_space_write_4(sc->sc_memt, sc->sc_regh, |
889 | PM2_RE_CONFIG, | | 889 | PM2_RE_CONFIG, |
890 | PM2RECFG_READ_SRC | PM2RECFG_READ_DST | | | 890 | PM2RECFG_READ_SRC | PM2RECFG_READ_DST | |
891 | PM2RECFG_WRITE_EN | PM2RECFG_PACKED | | | 891 | PM2RECFG_WRITE_EN | PM2RECFG_PACKED | |
892 | PM2RECFG_ROP_EN | (rop << 6)); | | 892 | PM2RECFG_ROP_EN | (rop << 6)); |
893 | } | | 893 | } |
894 | rxs = xs >> 2; | | | |
895 | rxd = xd >> 2; | | 894 | rxd = xd >> 2; |
896 | rwi = (wi + 7) >> 2; | | 895 | rwi = (wi + 7) >> 2; |
897 | rxdelta = (xs & 0xffc) - (xd & 0xffc); | | 896 | rxdelta = (xs & 0xffc) - (xd & 0xffc); |
898 | /* adjust for non-aligned x */ | | 897 | /* adjust for non-aligned x */ |
899 | adjust = ((xd & 3) - (xs & 3)); | | 898 | adjust = ((xd & 3) - (xs & 3)); |
900 | bus_space_write_4(sc->sc_memt, sc->sc_regh, | | 899 | bus_space_write_4(sc->sc_memt, sc->sc_regh, |
901 | PM2_RE_PACKEDDATA_LIMIT, | | 900 | PM2_RE_PACKEDDATA_LIMIT, |
902 | (xd << 16) | (xd + wi) | (adjust << 29)); | | 901 | (xd << 16) | (xd + wi) | (adjust << 29)); |
903 | | | 902 | |
904 | } else { | | 903 | } else { |
905 | /* we're in 16 or 32bit mode */ | | 904 | /* we're in 16 or 32bit mode */ |
906 | if (rop == 3) { | | 905 | if (rop == 3) { |
907 | bus_space_write_4(sc->sc_memt, sc->sc_regh, | | 906 | bus_space_write_4(sc->sc_memt, sc->sc_regh, |
908 | PM2_RE_CONFIG, | | 907 | PM2_RE_CONFIG, |
909 | PM2RECFG_READ_SRC | PM2RECFG_WRITE_EN | | | 908 | PM2RECFG_READ_SRC | PM2RECFG_WRITE_EN | |
910 | PM2RECFG_ROP_EN | PM2RECFG_PACKED | (rop << 6)); | | 909 | PM2RECFG_ROP_EN | PM2RECFG_PACKED | (rop << 6)); |
911 | } else { | | 910 | } else { |
912 | bus_space_write_4(sc->sc_memt, sc->sc_regh, | | 911 | bus_space_write_4(sc->sc_memt, sc->sc_regh, |
913 | PM2_RE_CONFIG, | | 912 | PM2_RE_CONFIG, |
914 | PM2RECFG_READ_SRC | PM2RECFG_READ_DST | | | 913 | PM2RECFG_READ_SRC | PM2RECFG_READ_DST | |
915 | PM2RECFG_WRITE_EN | PM2RECFG_PACKED | | | 914 | PM2RECFG_WRITE_EN | PM2RECFG_PACKED | |
916 | PM2RECFG_ROP_EN | (rop << 6)); | | 915 | PM2RECFG_ROP_EN | (rop << 6)); |
917 | } | | 916 | } |
918 | rxs = xs; | | | |
919 | rxd = xd; | | 917 | rxd = xd; |
920 | rwi = wi; | | 918 | rwi = wi; |
921 | rxdelta = xs - xd; | | 919 | rxdelta = xs - xd; |
922 | } | | 920 | } |
923 | bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_RECT_START, | | 921 | bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_RECT_START, |
924 | (yd << 16) | rxd); | | 922 | (yd << 16) | rxd); |
925 | bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_RECT_SIZE, | | 923 | bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_RECT_SIZE, |
926 | (he << 16) | rwi); | | 924 | (he << 16) | rwi); |
927 | bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_SOURCE_DELTA, | | 925 | bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_SOURCE_DELTA, |
928 | (((ys - yd) & 0xfff) << 16) | (rxdelta & 0xfff)); | | 926 | (((ys - yd) & 0xfff) << 16) | (rxdelta & 0xfff)); |
929 | bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_RENDER, | | 927 | bus_space_write_4(sc->sc_memt, sc->sc_regh, PM2_RE_RENDER, |
930 | PM2RE_RECTANGLE | dir); | | 928 | PM2RE_RECTANGLE | dir); |
931 | } | | 929 | } |
| @@ -1440,42 +1438,43 @@ pm2fb_i2c_read_byte(void *cookie, uint8_ | | | @@ -1440,42 +1438,43 @@ pm2fb_i2c_read_byte(void *cookie, uint8_ |
1440 | return (i2c_bitbang_read_byte(cookie, valp, flags, &pm2fb_i2cbb_ops)); | | 1438 | return (i2c_bitbang_read_byte(cookie, valp, flags, &pm2fb_i2cbb_ops)); |
1441 | } | | 1439 | } |
1442 | | | 1440 | |
1443 | static int | | 1441 | static int |
1444 | pm2fb_i2c_write_byte(void *cookie, uint8_t val, int flags) | | 1442 | pm2fb_i2c_write_byte(void *cookie, uint8_t val, int flags) |
1445 | { | | 1443 | { |
1446 | return (i2c_bitbang_write_byte(cookie, val, flags, &pm2fb_i2cbb_ops)); | | 1444 | return (i2c_bitbang_write_byte(cookie, val, flags, &pm2fb_i2cbb_ops)); |
1447 | } | | 1445 | } |
1448 | | | 1446 | |
1449 | #define RefClk 14318 /* all frequencies are in kHz */ | | 1447 | #define RefClk 14318 /* all frequencies are in kHz */ |
1450 | static int | | 1448 | static int |
1451 | pm2fb_set_pll(struct pm2fb_softc *sc, int freq) | | 1449 | pm2fb_set_pll(struct pm2fb_softc *sc, int freq) |
1452 | { | | 1450 | { |
1453 | int m, n, p, diff, out_freq, bm, bn, bp, bdiff = 1000000, bfreq; | | 1451 | int m, n, p, diff, out_freq, bm = 1, bn = 3, bp = 0, |
| | | 1452 | bdiff = 1000000 /* , bfreq */; |
1454 | int fi; | | 1453 | int fi; |
1455 | uint8_t temp; | | 1454 | uint8_t temp; |
1456 | | | 1455 | |
1457 | /* | | 1456 | /* |
1458 | * this should work on PM2V, PM2 needs something slightly different | | 1457 | * this should work on PM2V, PM2 needs something slightly different |
1459 | */ | | 1458 | */ |
1460 | for (m = 1; m < 128; m++) { | | 1459 | for (m = 1; m < 128; m++) { |
1461 | for (n = 2 * m + 1; n < 256; n++) { | | 1460 | for (n = 2 * m + 1; n < 256; n++) { |
1462 | fi = RefClk * n / m; | | 1461 | fi = RefClk * n / m; |
1463 | for (p = 0; p < 2; p++) { | | 1462 | for (p = 0; p < 2; p++) { |
1464 | out_freq = fi >> (p + 1); | | 1463 | out_freq = fi >> (p + 1); |
1465 | diff = abs(out_freq - freq); | | 1464 | diff = abs(out_freq - freq); |
1466 | if (diff < bdiff) { | | 1465 | if (diff < bdiff) { |
1467 | bdiff = diff; | | 1466 | bdiff = diff; |
1468 | bfreq = out_freq; | | 1467 | /* bfreq = out_freq; */ |
1469 | bm = m; | | 1468 | bm = m; |
1470 | bn = n; | | 1469 | bn = n; |
1471 | bp = p; | | 1470 | bp = p; |
1472 | } | | 1471 | } |
1473 | } | | 1472 | } |
1474 | } | | 1473 | } |
1475 | } | | 1474 | } |
1476 | #if 0 | | 1475 | #if 0 |
1477 | /* | | 1476 | /* |
1478 | * XXX | | 1477 | * XXX |
1479 | * output between switching modes and attaching a wsdisplay will | | 1478 | * output between switching modes and attaching a wsdisplay will |
1480 | * go through firmware calls on sparc64 and potentially mess up | | 1479 | * go through firmware calls on sparc64 and potentially mess up |
1481 | * our drawing engine state | | 1480 | * our drawing engine state |