Home | History | Annotate | Line # | Download | only in pci
radeonfb.c revision 1.7.2.3
      1  1.7.2.3     pavel /* $NetBSD: radeonfb.c,v 1.7.2.3 2007/05/12 15:44:38 pavel Exp $ */
      2      1.1   gdamore 
      3      1.1   gdamore /*-
      4      1.1   gdamore  * Copyright (c) 2006 Itronix Inc.
      5      1.1   gdamore  * All rights reserved.
      6      1.1   gdamore  *
      7      1.1   gdamore  * Written by Garrett D'Amore for Itronix Inc.
      8      1.1   gdamore  *
      9      1.1   gdamore  * Redistribution and use in source and binary forms, with or without
     10      1.1   gdamore  * modification, are permitted provided that the following conditions
     11      1.1   gdamore  * are met:
     12      1.1   gdamore  * 1. Redistributions of source code must retain the above copyright
     13      1.1   gdamore  *    notice, this list of conditions and the following disclaimer.
     14      1.1   gdamore  * 2. Redistributions in binary form must reproduce the above copyright
     15      1.1   gdamore  *    notice, this list of conditions and the following disclaimer in the
     16      1.1   gdamore  *    documentation and/or other materials provided with the distribution.
     17      1.1   gdamore  * 3. The name of Itronix Inc. may not be used to endorse
     18      1.1   gdamore  *    or promote products derived from this software without specific
     19      1.1   gdamore  *    prior written permission.
     20      1.1   gdamore  *
     21      1.1   gdamore  * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND ANY EXPRESS
     22      1.1   gdamore  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     23      1.1   gdamore  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24      1.1   gdamore  * ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
     25      1.1   gdamore  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26      1.1   gdamore  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     27      1.1   gdamore  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28      1.1   gdamore  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     29      1.1   gdamore  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     30      1.1   gdamore  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     31      1.1   gdamore  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.7.2.2    bouyer  */
     33      1.1   gdamore 
     34      1.1   gdamore /*
     35      1.1   gdamore  * ATI Technologies Inc. ("ATI") has not assisted in the creation of, and
     36      1.1   gdamore  * does not endorse, this software.  ATI will not be responsible or liable
     37      1.1   gdamore  * for any actual or alleged damage or loss caused by or in connection with
     38      1.1   gdamore  * the use of or reliance on this software.
     39      1.1   gdamore  */
     40      1.1   gdamore 
     41      1.1   gdamore /*
     42      1.1   gdamore  * Portions of this code were taken from XFree86's Radeon driver, which bears
     43      1.1   gdamore  * this notice:
     44      1.1   gdamore  *
     45      1.1   gdamore  * Copyright 2000 ATI Technologies Inc., Markham, Ontario, and
     46      1.1   gdamore  *                VA Linux Systems Inc., Fremont, California.
     47      1.1   gdamore  *
     48      1.1   gdamore  * All Rights Reserved.
     49      1.1   gdamore  *
     50      1.1   gdamore  * Permission is hereby granted, free of charge, to any person obtaining
     51      1.1   gdamore  * a copy of this software and associated documentation files (the
     52      1.1   gdamore  * "Software"), to deal in the Software without restriction, including
     53      1.1   gdamore  * without limitation on the rights to use, copy, modify, merge,
     54      1.1   gdamore  * publish, distribute, sublicense, and/or sell copies of the Software,
     55      1.1   gdamore  * and to permit persons to whom the Software is furnished to do so,
     56      1.1   gdamore  * subject to the following conditions:
     57      1.1   gdamore  *
     58      1.1   gdamore  * The above copyright notice and this permission notice (including the
     59      1.1   gdamore  * next paragraph) shall be included in all copies or substantial
     60      1.1   gdamore  * portions of the Software.
     61      1.1   gdamore  *
     62      1.1   gdamore  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     63      1.1   gdamore  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     64      1.1   gdamore  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     65      1.1   gdamore  * NON-INFRINGEMENT.  IN NO EVENT SHALL ATI, VA LINUX SYSTEMS AND/OR
     66      1.1   gdamore  * THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
     67      1.1   gdamore  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     68      1.1   gdamore  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     69      1.1   gdamore  * DEALINGS IN THE SOFTWARE.
     70      1.1   gdamore  */
     71      1.1   gdamore 
     72      1.1   gdamore #include <sys/cdefs.h>
     73  1.7.2.3     pavel __KERNEL_RCSID(0, "$NetBSD: radeonfb.c,v 1.7.2.3 2007/05/12 15:44:38 pavel Exp $");
     74      1.2  macallan 
     75      1.2  macallan #define RADEONFB_DEFAULT_DEPTH 32
     76      1.1   gdamore 
     77      1.1   gdamore #include <sys/param.h>
     78      1.1   gdamore #include <sys/systm.h>
     79      1.1   gdamore #include <sys/device.h>
     80      1.1   gdamore #include <sys/malloc.h>
     81      1.1   gdamore #include <machine/bus.h>
     82      1.5  macallan #include <sys/kernel.h>
     83      1.5  macallan #include <sys/lwp.h>
     84      1.5  macallan #include <sys/kauth.h>
     85      1.1   gdamore 
     86      1.1   gdamore #include <dev/wscons/wsdisplayvar.h>
     87      1.1   gdamore #include <dev/wscons/wsconsio.h>
     88      1.1   gdamore #include <dev/wsfont/wsfont.h>
     89      1.1   gdamore #include <dev/rasops/rasops.h>
     90      1.1   gdamore #include <dev/videomode/videomode.h>
     91      1.1   gdamore #include <dev/videomode/edidvar.h>
     92      1.1   gdamore #include <dev/wscons/wsdisplay_vconsvar.h>
     93      1.1   gdamore 
     94      1.1   gdamore #include <dev/pci/pcidevs.h>
     95      1.1   gdamore #include <dev/pci/pcireg.h>
     96      1.1   gdamore #include <dev/pci/pcivar.h>
     97      1.1   gdamore #include <dev/pci/radeonfbreg.h>
     98      1.1   gdamore #include <dev/pci/radeonfbvar.h>
     99      1.1   gdamore 
    100      1.1   gdamore static int radeonfb_match(struct device *, struct cfdata *, void *);
    101      1.1   gdamore static void radeonfb_attach(struct device *, struct device *, void *);
    102      1.1   gdamore static int radeonfb_ioctl(void *, void *, unsigned long, caddr_t, int,
    103      1.1   gdamore     struct lwp *);
    104      1.1   gdamore static paddr_t radeonfb_mmap(void *, void *, off_t, int);
    105      1.1   gdamore static int radeonfb_scratch_test(struct radeonfb_softc *, int, uint32_t);
    106      1.1   gdamore static void radeonfb_loadbios(struct radeonfb_softc *,
    107      1.1   gdamore     struct pci_attach_args *);
    108      1.1   gdamore 
    109      1.1   gdamore static uintmax_t radeonfb_getprop_num(struct radeonfb_softc *, const char *,
    110      1.1   gdamore     uintmax_t);
    111      1.1   gdamore static int radeonfb_getclocks(struct radeonfb_softc *);
    112      1.1   gdamore static int radeonfb_gettmds(struct radeonfb_softc *);
    113      1.1   gdamore static int radeonfb_calc_dividers(struct radeonfb_softc *, uint32_t,
    114      1.1   gdamore     uint32_t *, uint32_t *);
    115      1.1   gdamore static int radeonfb_getconnectors(struct radeonfb_softc *);
    116      1.1   gdamore static const struct videomode *radeonfb_modelookup(const char *);
    117      1.1   gdamore static void radeonfb_init_screen(void *, struct vcons_screen *, int, long *);
    118      1.1   gdamore static void radeonfb_pllwriteupdate(struct radeonfb_softc *, int);
    119      1.1   gdamore static void radeonfb_pllwaitatomicread(struct radeonfb_softc *, int);
    120      1.1   gdamore static void radeonfb_program_vclk(struct radeonfb_softc *, int, int);
    121      1.1   gdamore static void radeonfb_modeswitch(struct radeonfb_display *);
    122      1.1   gdamore static void radeonfb_setcrtc(struct radeonfb_display *, int);
    123      1.1   gdamore static void radeonfb_init_misc(struct radeonfb_softc *);
    124      1.1   gdamore static void radeonfb_set_fbloc(struct radeonfb_softc *);
    125      1.1   gdamore static void radeonfb_init_palette(struct radeonfb_softc *, int);
    126      1.1   gdamore static void radeonfb_r300cg_workaround(struct radeonfb_softc *);
    127      1.1   gdamore 
    128      1.1   gdamore static int radeonfb_isblank(struct radeonfb_display *);
    129      1.1   gdamore static void radeonfb_blank(struct radeonfb_display *, int);
    130      1.1   gdamore static int radeonfb_set_cursor(struct radeonfb_display *,
    131      1.1   gdamore     struct wsdisplay_cursor *);
    132      1.1   gdamore static int radeonfb_set_curpos(struct radeonfb_display *,
    133      1.1   gdamore     struct wsdisplay_curpos *);
    134      1.1   gdamore 
    135      1.1   gdamore /* acceleration support */
    136      1.2  macallan static void  radeonfb_rectfill(struct radeonfb_display *, int dstx, int dsty,
    137      1.1   gdamore     int width, int height, uint32_t color);
    138      1.1   gdamore static void radeonfb_bitblt(struct radeonfb_display *, int srcx, int srcy,
    139      1.1   gdamore     int dstx, int dsty, int width, int height, int rop, uint32_t mask);
    140      1.1   gdamore static void radeonfb_feed_bytes(struct radeonfb_display *, int, uint8_t *);
    141      1.1   gdamore static void radeonfb_setup_mono(struct radeonfb_display *, int, int, int,
    142      1.1   gdamore     int, uint32_t, uint32_t);
    143      1.2  macallan 
    144      1.1   gdamore /* hw cursor support */
    145      1.1   gdamore static void radeonfb_cursor_cmap(struct radeonfb_display *);
    146      1.1   gdamore static void radeonfb_cursor_shape(struct radeonfb_display *);
    147      1.1   gdamore static void radeonfb_cursor_position(struct radeonfb_display *);
    148      1.1   gdamore static void radeonfb_cursor_visible(struct radeonfb_display *);
    149      1.1   gdamore static void radeonfb_cursor_update(struct radeonfb_display *, unsigned);
    150      1.1   gdamore 
    151      1.1   gdamore static void radeonfb_wait_fifo(struct radeonfb_softc *, int);
    152      1.1   gdamore static void radeonfb_engine_idle(struct radeonfb_softc *);
    153      1.1   gdamore static void radeonfb_engine_flush(struct radeonfb_softc *);
    154      1.1   gdamore static void radeonfb_engine_reset(struct radeonfb_softc *);
    155      1.1   gdamore static void radeonfb_engine_init(struct radeonfb_display *);
    156      1.2  macallan static inline void radeonfb_unclip(struct radeonfb_softc *);
    157      1.1   gdamore 
    158      1.1   gdamore static void radeonfb_eraserows(void *, int, int, long);
    159      1.1   gdamore static void radeonfb_erasecols(void *, int, int, int, long);
    160      1.1   gdamore static void radeonfb_copyrows(void *, int, int, int);
    161      1.1   gdamore static void radeonfb_copycols(void *, int, int, int, int);
    162      1.1   gdamore static void radeonfb_cursor(void *, int, int, int);
    163      1.2  macallan static void radeonfb_putchar(void *, int, int, unsigned, long);
    164      1.1   gdamore static int radeonfb_allocattr(void *, int, int, int, long *);
    165      1.1   gdamore 
    166  1.7.2.1    bouyer static int radeonfb_get_backlight(struct radeonfb_display *);
    167  1.7.2.1    bouyer static int radeonfb_set_backlight(struct radeonfb_display *, int);
    168  1.7.2.1    bouyer static void radeonfb_lvds_callout(void *);
    169  1.7.2.1    bouyer 
    170      1.1   gdamore static struct videomode *radeonfb_best_refresh(struct videomode *,
    171      1.1   gdamore     struct videomode *);
    172      1.1   gdamore static void radeonfb_pickres(struct radeonfb_display *, uint16_t *,
    173      1.1   gdamore     uint16_t *, int);
    174  1.7.2.2    bouyer static const struct videomode *radeonfb_port_mode(struct radeonfb_softc *,
    175  1.7.2.1    bouyer     struct radeonfb_port *, int, int);
    176      1.1   gdamore 
    177      1.1   gdamore #ifdef	RADEON_DEBUG
    178      1.1   gdamore int	radeon_debug = 1;
    179      1.1   gdamore #define	DPRINTF(x)	\
    180      1.1   gdamore 	if (radeon_debug) printf x
    181      1.1   gdamore #define	PRINTREG(r)	DPRINTF((#r " = %08x\n", GET32(sc, r)))
    182      1.1   gdamore #define	PRINTPLL(r)	DPRINTF((#r " = %08x\n", GETPLL(sc, r)))
    183      1.1   gdamore #else
    184      1.1   gdamore #define	DPRINTF(x)
    185      1.1   gdamore #define	PRINTREG(r)
    186      1.1   gdamore #define	PRINTPLL(r)
    187      1.1   gdamore #endif
    188      1.1   gdamore 
    189      1.1   gdamore #define	ROUNDUP(x,y)	(((x) + ((y) - 1)) & ~((y) - 1))
    190      1.1   gdamore 
    191      1.1   gdamore #ifndef	RADEON_DEFAULT_MODE
    192      1.1   gdamore /* any reasonably modern display should handle this */
    193      1.1   gdamore #define	RADEON_DEFAULT_MODE	"1024x768x60"
    194      1.1   gdamore #endif
    195      1.1   gdamore 
    196      1.1   gdamore const char	*radeonfb_default_mode = RADEON_DEFAULT_MODE;
    197      1.1   gdamore 
    198      1.1   gdamore static struct {
    199      1.1   gdamore 	int		size;		/* minimum memory size (MB) */
    200      1.1   gdamore 	int		maxx;		/* maximum x dimension */
    201      1.1   gdamore 	int		maxy;		/* maximum y dimension */
    202      1.1   gdamore 	int		maxbpp;		/* maximum bpp */
    203      1.1   gdamore 	int		maxdisp;	/* maximum logical display count */
    204      1.1   gdamore } radeonfb_limits[] = {
    205      1.1   gdamore 	{ 32,	2048, 1536, 32, 2 },
    206      1.1   gdamore 	{ 16,	1600, 1200, 32, 2 },
    207      1.1   gdamore 	{ 8,	1600, 1200, 32, 1 },
    208      1.7  christos 	{ 0,	0, 0, 0, 0 },
    209      1.1   gdamore };
    210      1.1   gdamore 
    211      1.1   gdamore static struct wsscreen_descr radeonfb_stdscreen = {
    212      1.1   gdamore 	"fb",		/* name */
    213      1.1   gdamore 	0, 0,		/* ncols, nrows */
    214      1.1   gdamore 	NULL,		/* textops */
    215      1.2  macallan 	8, 16,		/* fontwidth, fontheight */
    216      1.7  christos 	WSSCREEN_WSCOLORS, /* capabilities */
    217      1.7  christos 	0,		/* modecookie */
    218      1.1   gdamore };
    219      1.1   gdamore 
    220      1.1   gdamore struct wsdisplay_accessops radeonfb_accessops = {
    221      1.1   gdamore 	radeonfb_ioctl,
    222      1.1   gdamore 	radeonfb_mmap,
    223      1.1   gdamore 	NULL,		/* vcons_alloc_screen */
    224      1.1   gdamore 	NULL,		/* vcons_free_screen */
    225      1.1   gdamore 	NULL,		/* vcons_show_screen */
    226      1.7  christos 	NULL,		/* load_font */
    227      1.7  christos 	NULL,		/* pollc */
    228      1.7  christos 	NULL,		/* scroll */
    229      1.1   gdamore };
    230      1.1   gdamore 
    231      1.1   gdamore static struct {
    232      1.1   gdamore 	uint16_t	devid;
    233      1.1   gdamore 	uint16_t	family;
    234      1.1   gdamore 	uint16_t	flags;
    235  1.7.2.2    bouyer } radeonfb_devices[] =
    236      1.1   gdamore {
    237      1.1   gdamore 	/* R100 family */
    238      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R100_QD,	RADEON_R100, 0 },
    239      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R100_QE,	RADEON_R100, 0 },
    240      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R100_QF,	RADEON_R100, 0 },
    241      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R100_QG,	RADEON_R100, 0 },
    242      1.1   gdamore 
    243      1.1   gdamore 	/* RV100 family */
    244      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV100_LY,	RADEON_RV100, RFB_MOB },
    245      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV100_LZ,	RADEON_RV100, RFB_MOB },
    246      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV100_QY,	RADEON_RV100, 0 },
    247      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV100_QZ,	RADEON_RV100, 0 },
    248      1.1   gdamore 
    249      1.1   gdamore 	/* RS100 family */
    250      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RS100_4136,	RADEON_RS100, 0 },
    251      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RS100_4336,	RADEON_RS100, RFB_MOB },
    252      1.1   gdamore 
    253      1.1   gdamore 	/* RS200/RS250 family */
    254      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RS200_4337,	RADEON_RS200, RFB_MOB },
    255      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RS200_A7,	RADEON_RS200, 0 },
    256      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RS250_B7,	RADEON_RS200, RFB_MOB },
    257      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RS250_D7,	RADEON_RS200, 0 },
    258      1.1   gdamore 
    259      1.1   gdamore 	/* R200 family */
    260      1.1   gdamore 	/* add more R200 products? , 5148 */
    261      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R200_BB,	RADEON_R200, 0 },
    262      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R200_BC,	RADEON_R200, 0 },
    263      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R200_QH,	RADEON_R200, 0 },
    264      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R200_QL,	RADEON_R200, 0 },
    265      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R200_QM,	RADEON_R200, 0 },
    266      1.1   gdamore 
    267      1.1   gdamore 	/* RV200 family */
    268      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV200_LW,	RADEON_RV200, RFB_MOB },
    269      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV200_LX,	RADEON_RV200, RFB_MOB },
    270      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV200_QW,	RADEON_RV200, 0 },
    271      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV200_QX,	RADEON_RV200, 0 },
    272      1.1   gdamore 
    273      1.1   gdamore 	/* RV250 family */
    274      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV250_4966,	RADEON_RV250, 0 },
    275      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV250_4967,	RADEON_RV250, 0 },
    276      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV250_4C64,	RADEON_RV250, RFB_MOB },
    277      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV250_4C66,	RADEON_RV250, RFB_MOB },
    278      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV250_4C67,	RADEON_RV250, RFB_MOB },
    279      1.1   gdamore 
    280      1.1   gdamore 	/* RS300 family */
    281      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RS300_X5,	RADEON_RS300, 0 },
    282      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RS300_X4,	RADEON_RS300, 0 },
    283      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RS300_7834,	RADEON_RS300, 0 },
    284      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RS300_7835,	RADEON_RS300, RFB_MOB },
    285      1.1   gdamore 
    286      1.1   gdamore 	/* RV280 family */
    287      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV280_5960,	RADEON_RV280, 0 },
    288      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV280_5961,	RADEON_RV280, 0 },
    289      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV280_5962,	RADEON_RV280, 0 },
    290      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV280_5963,	RADEON_RV280, 0 },
    291      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV280_5964,	RADEON_RV280, 0 },
    292      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV280_5C61,	RADEON_RV280, RFB_MOB },
    293      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV280_5C63,	RADEON_RV280, RFB_MOB },
    294      1.1   gdamore 
    295      1.1   gdamore 	/* R300 family */
    296      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R300_AD,	RADEON_R300, 0 },
    297      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R300_AE,	RADEON_R300, 0 },
    298      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R300_AF,	RADEON_R300, 0 },
    299      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R300_AG,	RADEON_R300, 0 },
    300      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R300_ND,	RADEON_R300, 0 },
    301      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R300_NE,	RADEON_R300, 0 },
    302      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R300_NF,	RADEON_R300, 0 },
    303      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R300_NG,	RADEON_R300, 0 },
    304      1.1   gdamore 
    305      1.1   gdamore 	/* RV350/RV360 family */
    306      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV350_AP,	RADEON_RV350, 0 },
    307      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV350_AQ,	RADEON_RV350, 0 },
    308      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV360_AR,	RADEON_RV350, 0 },
    309      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV350_AS,	RADEON_RV350, 0 },
    310      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV350_AT,	RADEON_RV350, 0 },
    311      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV350_AV,	RADEON_RV350, 0 },
    312      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV350_NP,	RADEON_RV350, RFB_MOB },
    313      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV350_NQ,	RADEON_RV350, RFB_MOB },
    314      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV350_NR,	RADEON_RV350, RFB_MOB },
    315      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV350_NS,	RADEON_RV350, RFB_MOB },
    316      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV350_NT,	RADEON_RV350, RFB_MOB },
    317      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV350_NV,	RADEON_RV350, RFB_MOB },
    318      1.1   gdamore 
    319      1.1   gdamore 	/* R350/R360 family */
    320      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R350_AH,	RADEON_R350, 0 },
    321      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R350_AI,	RADEON_R350, 0 },
    322      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R350_AJ,	RADEON_R350, 0 },
    323      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R350_AK,	RADEON_R350, 0 },
    324      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R350_NH,	RADEON_R350, 0 },
    325      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R350_NI,	RADEON_R350, 0 },
    326      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R350_NK,	RADEON_R350, 0 },
    327      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R360_NJ,	RADEON_R350, 0 },
    328      1.1   gdamore 
    329      1.1   gdamore 	/* RV380/RV370 family */
    330      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV380_3150,	RADEON_RV380, RFB_MOB },
    331      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV380_3154,	RADEON_RV380, RFB_MOB },
    332      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV380_3E50,	RADEON_RV380, 0 },
    333      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV380_3E54,	RADEON_RV380, 0 },
    334      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV370_5460,	RADEON_RV380, RFB_MOB },
    335      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV370_5464,	RADEON_RV380, RFB_MOB },
    336      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV370_5B60,	RADEON_RV380, 0 },
    337      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV370_5B64,	RADEON_RV380, 0 },
    338      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_RV370_5B65,	RADEON_RV380, 0 },
    339      1.1   gdamore 
    340      1.1   gdamore 	/* R420/R423 family */
    341      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R420_JH,	RADEON_R420, 0 },
    342      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R420_JI,	RADEON_R420, 0 },
    343      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R420_JJ,	RADEON_R420, 0 },
    344      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R420_JK,	RADEON_R420, 0 },
    345      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R420_JL,	RADEON_R420, 0 },
    346      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R420_JM,	RADEON_R420, 0 },
    347      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R420_JN,	RADEON_R420, RFB_MOB },
    348      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R420_JP,	RADEON_R420, 0 },
    349      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R423_UH,	RADEON_R420, 0 },
    350      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R423_UI,	RADEON_R420, 0 },
    351      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R423_UJ,	RADEON_R420, 0 },
    352      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R423_UK,	RADEON_R420, 0 },
    353      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R423_UQ,	RADEON_R420, 0 },
    354      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R423_UR,	RADEON_R420, 0 },
    355      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R423_UT,	RADEON_R420, 0 },
    356      1.1   gdamore 	{ PCI_PRODUCT_ATI_RADEON_R423_5D57,	RADEON_R420, 0 },
    357      1.1   gdamore 
    358      1.1   gdamore 	{ 0, 0, 0 }
    359      1.1   gdamore };
    360      1.1   gdamore 
    361      1.1   gdamore static struct {
    362      1.1   gdamore 	int divider;
    363      1.1   gdamore 	int mask;
    364      1.1   gdamore } radeonfb_dividers[] = {
    365      1.1   gdamore 	{  1, 0 },
    366      1.1   gdamore 	{  2, 1 },
    367      1.1   gdamore 	{  3, 4 },
    368      1.1   gdamore 	{  4, 2 },
    369      1.1   gdamore 	{  6, 6 },
    370      1.1   gdamore 	{  8, 3 },
    371      1.1   gdamore 	{ 12, 7 },
    372      1.1   gdamore 	{  0, 0 }
    373      1.1   gdamore };
    374      1.1   gdamore 
    375      1.1   gdamore /*
    376      1.1   gdamore  * This table taken from X11.
    377      1.1   gdamore  */
    378      1.1   gdamore static const struct {
    379      1.1   gdamore 	int			family;
    380      1.1   gdamore 	struct radeon_tmds_pll	plls[4];
    381      1.1   gdamore } radeonfb_tmds_pll[] = {
    382      1.1   gdamore 	{ RADEON_R100,	{{12000, 0xa1b}, {-1, 0xa3f}}},
    383      1.1   gdamore 	{ RADEON_RV100,	{{12000, 0xa1b}, {-1, 0xa3f}}},
    384      1.1   gdamore 	{ RADEON_RS100, {{0, 0}}},
    385      1.1   gdamore 	{ RADEON_RV200,	{{15000, 0xa1b}, {-1, 0xa3f}}},
    386      1.1   gdamore 	{ RADEON_RS200,	{{15000, 0xa1b}, {-1, 0xa3f}}},
    387      1.1   gdamore 	{ RADEON_R200,	{{15000, 0xa1b}, {-1, 0xa3f}}},
    388      1.1   gdamore 	{ RADEON_RV250,	{{15500, 0x81b}, {-1, 0x83f}}},
    389      1.1   gdamore 	{ RADEON_RS300, {{0, 0}}},
    390      1.1   gdamore 	{ RADEON_RV280,	{{13000, 0x400f4}, {15000, 0x400f7}}},
    391      1.1   gdamore 	{ RADEON_R300,	{{-1, 0xb01cb}}},
    392      1.1   gdamore 	{ RADEON_R350,	{{-1, 0xb01cb}}},
    393      1.1   gdamore 	{ RADEON_RV350,	{{15000, 0xb0155}, {-1, 0xb01cb}}},
    394      1.1   gdamore 	{ RADEON_RV380,	{{15000, 0xb0155}, {-1, 0xb01cb}}},
    395      1.1   gdamore 	{ RADEON_R420,	{{-1, 0xb01cb}}},
    396      1.1   gdamore };
    397      1.1   gdamore 
    398  1.7.2.1    bouyer #define RADEONFB_BACKLIGHT_MAX    255  /* Maximum backlight level. */
    399  1.7.2.1    bouyer 
    400      1.1   gdamore 
    401      1.1   gdamore CFATTACH_DECL(radeonfb, sizeof (struct radeonfb_softc),
    402      1.1   gdamore     radeonfb_match, radeonfb_attach, NULL, NULL);
    403      1.1   gdamore 
    404      1.1   gdamore static int
    405      1.1   gdamore radeonfb_match(struct device *parent, struct cfdata *match, void *aux)
    406      1.1   gdamore {
    407      1.1   gdamore 	struct pci_attach_args	*pa = aux;
    408      1.1   gdamore 	int			i;
    409      1.1   gdamore 
    410      1.1   gdamore 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_ATI)
    411      1.1   gdamore 		return 0;
    412      1.1   gdamore 
    413      1.1   gdamore 	for (i = 0; radeonfb_devices[i].devid; i++) {
    414      1.1   gdamore 		if (PCI_PRODUCT(pa->pa_id) == radeonfb_devices[i].devid)
    415      1.1   gdamore 			return 100;	/* high to defeat VGA/VESA */
    416      1.1   gdamore 	}
    417      1.1   gdamore 
    418      1.1   gdamore 	return 0;
    419      1.1   gdamore }
    420      1.1   gdamore 
    421      1.1   gdamore static void
    422      1.1   gdamore radeonfb_attach(struct device *parent, struct device *dev, void *aux)
    423      1.1   gdamore {
    424      1.1   gdamore 	struct radeonfb_softc	*sc = (struct radeonfb_softc *)dev;
    425      1.1   gdamore 	struct pci_attach_args	*pa = aux;
    426  1.7.2.1    bouyer 	const char		*mptr;
    427      1.1   gdamore 	bus_size_t		bsz;
    428      1.5  macallan 	pcireg_t		screg;
    429      1.1   gdamore 	int			i, j;
    430      1.1   gdamore 	uint32_t		v;
    431      1.1   gdamore 
    432      1.1   gdamore 	sc->sc_id = pa->pa_id;
    433      1.1   gdamore 	for (i = 0; radeonfb_devices[i].devid; i++) {
    434      1.1   gdamore 		if (PCI_PRODUCT(sc->sc_id) == radeonfb_devices[i].devid)
    435      1.1   gdamore 			break;
    436      1.1   gdamore 	}
    437      1.1   gdamore 
    438      1.1   gdamore 	pci_devinfo(sc->sc_id, pa->pa_class, 0, sc->sc_devinfo,
    439      1.1   gdamore 	    sizeof(sc->sc_devinfo));
    440      1.1   gdamore 
    441      1.1   gdamore 	aprint_naive("\n");
    442      1.1   gdamore 	aprint_normal(": %s\n", sc->sc_devinfo);
    443      1.1   gdamore 
    444  1.7.2.2    bouyer 	DPRINTF((prop_dictionary_externalize(device_properties(dev))));
    445  1.7.2.2    bouyer 
    446      1.1   gdamore 	KASSERT(radeonfb_devices[i].devid != 0);
    447      1.1   gdamore 	sc->sc_pt = pa->pa_tag;
    448      1.1   gdamore 	sc->sc_pc = pa->pa_pc;
    449      1.1   gdamore 	sc->sc_family = radeonfb_devices[i].family;
    450      1.1   gdamore 	sc->sc_flags = radeonfb_devices[i].flags;
    451      1.1   gdamore 
    452      1.5  macallan 	/* enable memory and IO access */
    453      1.5  macallan 	screg = pci_conf_read(sc->sc_pc, sc->sc_pt, PCI_COMMAND_STATUS_REG);
    454      1.5  macallan 	screg |= PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
    455      1.5  macallan 	pci_conf_write(sc->sc_pc, sc->sc_pt, PCI_COMMAND_STATUS_REG, screg);
    456      1.5  macallan 
    457      1.1   gdamore 	/*
    458      1.1   gdamore 	 * Some flags are general to entire chip families, and rather
    459      1.1   gdamore 	 * than clutter up the table with them, we go ahead and set
    460      1.1   gdamore 	 * them here.
    461      1.1   gdamore 	 */
    462      1.1   gdamore 	switch (sc->sc_family) {
    463      1.1   gdamore 	case RADEON_RS100:
    464      1.1   gdamore 	case RADEON_RS200:
    465      1.1   gdamore 		sc->sc_flags |= RFB_IGP | RFB_RV100;
    466      1.1   gdamore 		break;
    467      1.1   gdamore 
    468      1.1   gdamore 	case RADEON_RV100:
    469      1.1   gdamore 	case RADEON_RV200:
    470      1.1   gdamore 	case RADEON_RV250:
    471      1.1   gdamore 	case RADEON_RV280:
    472      1.1   gdamore 		sc->sc_flags |= RFB_RV100;
    473      1.1   gdamore 		break;
    474      1.1   gdamore 
    475      1.1   gdamore 	case RADEON_RS300:
    476      1.1   gdamore 		sc->sc_flags |= RFB_SDAC | RFB_IGP | RFB_RV100;
    477      1.1   gdamore 		break;
    478      1.1   gdamore 
    479      1.1   gdamore 	case RADEON_R300:
    480      1.1   gdamore 	case RADEON_RV350:
    481      1.1   gdamore 	case RADEON_R350:
    482      1.1   gdamore 	case RADEON_RV380:
    483      1.1   gdamore 	case RADEON_R420:
    484      1.1   gdamore 		/* newer chips */
    485      1.1   gdamore 		sc->sc_flags |= RFB_R300;
    486      1.1   gdamore 		break;
    487      1.1   gdamore 
    488      1.1   gdamore 	case RADEON_R100:
    489      1.1   gdamore 		sc->sc_flags |= RFB_NCRTC2;
    490      1.1   gdamore 		break;
    491      1.1   gdamore 	}
    492      1.1   gdamore 
    493  1.7.2.2    bouyer 	if ((sc->sc_family == RADEON_RV200) ||
    494  1.7.2.2    bouyer 	    (sc->sc_family == RADEON_RV250) ||
    495  1.7.2.2    bouyer 	    (sc->sc_family == RADEON_RV280) ||
    496  1.7.2.2    bouyer 	    (sc->sc_family == RADEON_RV350)) {
    497  1.7.2.2    bouyer 		int inverted = 0;
    498  1.7.2.2    bouyer 		/* backlight level is linear */
    499  1.7.2.2    bouyer 		DPRINTF(("found RV* chip, backlight is supposedly linear\n"));
    500  1.7.2.2    bouyer 		prop_dictionary_get_bool(device_properties(&sc->sc_dev),
    501  1.7.2.2    bouyer 		    "backlight_level_reverted", &inverted);
    502  1.7.2.2    bouyer 		if (inverted) {
    503  1.7.2.2    bouyer 			DPRINTF(("nope, it's inverted\n"));
    504  1.7.2.2    bouyer 			sc->sc_flags |= RFB_INV_BLIGHT;
    505  1.7.2.2    bouyer 		}
    506  1.7.2.2    bouyer 	} else
    507  1.7.2.2    bouyer 		sc->sc_flags |= RFB_INV_BLIGHT;
    508  1.7.2.2    bouyer 
    509      1.1   gdamore 	/*
    510      1.1   gdamore 	 * XXX: to support true multihead, this must change.
    511      1.1   gdamore 	 */
    512      1.1   gdamore 	sc->sc_ndisplays = 1;
    513      1.1   gdamore 
    514      1.1   gdamore 	/* XXX: */
    515      1.1   gdamore 	if (!HAS_CRTC2(sc)) {
    516      1.1   gdamore 		sc->sc_ndisplays = 1;
    517      1.1   gdamore 	}
    518      1.1   gdamore 
    519      1.1   gdamore 	if (pci_mapreg_map(pa, RADEON_MAPREG_MMIO, PCI_MAPREG_TYPE_MEM,	0,
    520      1.1   gdamore 		&sc->sc_regt, &sc->sc_regh, &sc->sc_regaddr,
    521      1.1   gdamore 		&sc->sc_regsz) != 0) {
    522      1.1   gdamore 		aprint_error("%s: unable to map registers!\n", XNAME(sc));
    523      1.1   gdamore 		goto error;
    524      1.1   gdamore 	}
    525      1.1   gdamore 
    526      1.5  macallan 	if (pci_mapreg_map(pa, RADEON_MAPREG_IO, PCI_MAPREG_TYPE_IO,	0,
    527      1.5  macallan 		&sc->sc_iot, &sc->sc_ioh, &sc->sc_ioaddr,
    528      1.5  macallan 		&sc->sc_iosz) != 0) {
    529      1.5  macallan 		aprint_error("%s: unable to map IO registers!\n", XNAME(sc));
    530      1.5  macallan 	}
    531      1.5  macallan 
    532      1.1   gdamore 	/* scratch register test... */
    533      1.1   gdamore 	if (radeonfb_scratch_test(sc, RADEON_BIOS_0_SCRATCH, 0x55555555) ||
    534      1.1   gdamore 	    radeonfb_scratch_test(sc, RADEON_BIOS_0_SCRATCH, 0xaaaaaaaa)) {
    535      1.1   gdamore 		aprint_error("%s: scratch register test failed!\n", XNAME(sc));
    536      1.1   gdamore 		goto error;
    537      1.1   gdamore 	}
    538      1.1   gdamore 
    539      1.1   gdamore 	PRINTREG(RADEON_BIOS_4_SCRATCH);
    540      1.1   gdamore 	PRINTREG(RADEON_FP_GEN_CNTL);
    541      1.1   gdamore 	PRINTREG(RADEON_FP2_GEN_CNTL);
    542      1.1   gdamore 	PRINTREG(RADEON_TMDS_CNTL);
    543      1.1   gdamore 	PRINTREG(RADEON_TMDS_TRANSMITTER_CNTL);
    544      1.1   gdamore 	PRINTREG(RADEON_TMDS_PLL_CNTL);
    545      1.1   gdamore 	PRINTREG(RADEON_LVDS_GEN_CNTL);
    546      1.1   gdamore 	PRINTREG(RADEON_FP_HORZ_STRETCH);
    547      1.1   gdamore 	PRINTREG(RADEON_FP_VERT_STRETCH);
    548      1.1   gdamore 
    549      1.1   gdamore 	/* XXX: RV100 specific */
    550      1.1   gdamore 	PUT32(sc, RADEON_TMDS_PLL_CNTL, 0xa27);
    551      1.1   gdamore 
    552      1.1   gdamore 	PATCH32(sc, RADEON_TMDS_TRANSMITTER_CNTL,
    553      1.1   gdamore 	    RADEON_TMDS_TRANSMITTER_PLLEN,
    554      1.1   gdamore 	    RADEON_TMDS_TRANSMITTER_PLLEN | RADEON_TMDS_TRANSMITTER_PLLRST);
    555      1.1   gdamore 
    556      1.1   gdamore 	radeonfb_i2c_init(sc);
    557      1.1   gdamore 
    558      1.1   gdamore 	radeonfb_loadbios(sc, pa);
    559      1.1   gdamore 
    560      1.1   gdamore #ifdef	RADEON_BIOS_INIT
    561      1.1   gdamore 	if (radeonfb_bios_init(sc)) {
    562      1.1   gdamore 		aprint_error("%s: BIOS inititialization failed\n", XNAME(sc));
    563      1.1   gdamore 		goto error;
    564      1.1   gdamore 	}
    565      1.1   gdamore #endif
    566      1.1   gdamore 
    567      1.1   gdamore 	if (radeonfb_getclocks(sc)) {
    568      1.1   gdamore 		aprint_error("%s: Unable to get reference clocks from BIOS\n",
    569      1.1   gdamore 		    XNAME(sc));
    570      1.1   gdamore 		goto error;
    571      1.1   gdamore 	}
    572      1.1   gdamore 
    573      1.1   gdamore 	if (radeonfb_gettmds(sc)) {
    574      1.1   gdamore 		aprint_error("%s: Unable to identify TMDS PLL settings\n",
    575      1.1   gdamore 		    XNAME(sc));
    576      1.1   gdamore 		goto error;
    577      1.1   gdamore 	}
    578      1.1   gdamore 
    579      1.1   gdamore 	aprint_verbose("%s: refclk = %d.%03d MHz, refdiv = %d "
    580      1.1   gdamore 	    "minpll = %d, maxpll = %d\n", XNAME(sc),
    581      1.1   gdamore 	    (int)sc->sc_refclk / 1000, (int)sc->sc_refclk % 1000,
    582      1.1   gdamore 	    (int)sc->sc_refdiv, (int)sc->sc_minpll, (int)sc->sc_maxpll);
    583      1.1   gdamore 
    584      1.1   gdamore 	radeonfb_getconnectors(sc);
    585      1.1   gdamore 
    586      1.1   gdamore 	radeonfb_set_fbloc(sc);
    587      1.1   gdamore 
    588      1.1   gdamore 	for (i = 0; radeonfb_limits[i].size; i++) {
    589      1.1   gdamore 		if (sc->sc_memsz >= radeonfb_limits[i].size) {
    590      1.1   gdamore 			sc->sc_maxx = radeonfb_limits[i].maxx;
    591      1.1   gdamore 			sc->sc_maxy = radeonfb_limits[i].maxy;
    592      1.1   gdamore 			sc->sc_maxbpp = radeonfb_limits[i].maxbpp;
    593      1.1   gdamore 			/* framebuffer offset, start at a 4K page */
    594      1.1   gdamore 			sc->sc_fboffset = sc->sc_memsz /
    595      1.1   gdamore 			    radeonfb_limits[i].maxdisp;
    596      1.1   gdamore 			/*
    597      1.1   gdamore 			 * we use the fbsize to figure out where we can store
    598      1.1   gdamore 			 * things like cursor data.
    599      1.1   gdamore 			 */
    600      1.1   gdamore 			sc->sc_fbsize =
    601      1.1   gdamore 			    ROUNDUP(ROUNDUP(sc->sc_maxx * sc->sc_maxbpp / 8 ,
    602      1.1   gdamore 					RADEON_STRIDEALIGN) * sc->sc_maxy,
    603      1.1   gdamore 				4096);
    604      1.1   gdamore 			break;
    605      1.1   gdamore 		}
    606      1.1   gdamore 	}
    607      1.1   gdamore 
    608      1.1   gdamore 
    609      1.1   gdamore 	radeonfb_init_misc(sc);
    610      1.1   gdamore 	radeonfb_init_palette(sc, 0);
    611      1.1   gdamore 	if (HAS_CRTC2(sc))
    612      1.1   gdamore 		radeonfb_init_palette(sc, 1);
    613      1.1   gdamore 
    614      1.1   gdamore 	/* program the DAC wirings */
    615      1.1   gdamore 	for (i = 0; i < (HAS_CRTC2(sc) ? 2 : 1); i++) {
    616      1.1   gdamore 		switch (sc->sc_ports[i].rp_dac_type) {
    617      1.1   gdamore 		case RADEON_DAC_PRIMARY:
    618      1.1   gdamore 			PATCH32(sc, RADEON_DAC_CNTL2,
    619      1.1   gdamore 			    i ? RADEON_DAC2_DAC_CLK_SEL : 0,
    620      1.1   gdamore 			    ~RADEON_DAC2_DAC_CLK_SEL);
    621      1.1   gdamore 			break;
    622      1.1   gdamore 		case RADEON_DAC_TVDAC:
    623      1.1   gdamore 			/* we always use the TVDAC to drive a secondary analog
    624      1.1   gdamore 			 * CRT for now.  if we ever support TV-out this will
    625      1.1   gdamore 			 * have to change.
    626      1.1   gdamore 			 */
    627      1.1   gdamore 			SET32(sc, RADEON_DAC_CNTL2,
    628      1.1   gdamore 			    RADEON_DAC2_DAC2_CLK_SEL);
    629      1.1   gdamore 			PATCH32(sc, RADEON_DISP_HW_DEBUG,
    630      1.1   gdamore 			    i ? 0 : RADEON_CRT2_DISP1_SEL,
    631      1.1   gdamore 			    ~RADEON_CRT2_DISP1_SEL);
    632      1.1   gdamore 			break;
    633      1.1   gdamore 		}
    634      1.1   gdamore 	}
    635      1.1   gdamore 	PRINTREG(RADEON_DAC_CNTL2);
    636      1.1   gdamore 	PRINTREG(RADEON_DISP_HW_DEBUG);
    637      1.1   gdamore 
    638      1.1   gdamore 	/* other DAC programming */
    639      1.1   gdamore 	v = GET32(sc, RADEON_DAC_CNTL);
    640      1.1   gdamore 	v &= (RADEON_DAC_RANGE_CNTL_MASK | RADEON_DAC_BLANKING);
    641      1.1   gdamore 	v |= RADEON_DAC_MASK_ALL | RADEON_DAC_8BIT_EN;
    642      1.1   gdamore 	PUT32(sc, RADEON_DAC_CNTL, v);
    643      1.1   gdamore 	PRINTREG(RADEON_DAC_CNTL);
    644  1.7.2.2    bouyer 
    645      1.1   gdamore 	/* XXX: this may need more investigation */
    646      1.1   gdamore 	PUT32(sc, RADEON_TV_DAC_CNTL, 0x00280203);
    647      1.1   gdamore 	PRINTREG(RADEON_TV_DAC_CNTL);
    648      1.1   gdamore 
    649      1.1   gdamore 	/* enable TMDS */
    650      1.1   gdamore 	SET32(sc, RADEON_FP_GEN_CNTL,
    651      1.1   gdamore 	    RADEON_FP_TMDS_EN |
    652      1.1   gdamore 		RADEON_FP_CRTC_DONT_SHADOW_VPAR |
    653      1.1   gdamore 		RADEON_FP_CRTC_DONT_SHADOW_HEND);
    654      1.1   gdamore 	CLR32(sc, RADEON_FP_GEN_CNTL, RADEON_FP_SEL_CRTC2);
    655      1.1   gdamore 	if (HAS_CRTC2(sc))
    656      1.1   gdamore 		SET32(sc, RADEON_FP2_GEN_CNTL, RADEON_FP2_SRC_SEL_CRTC2);
    657      1.1   gdamore 
    658      1.1   gdamore 	/*
    659      1.1   gdamore 	 * we use bus_space_map instead of pci_mapreg, because we don't
    660      1.1   gdamore 	 * need the full aperature space.  no point in wasting virtual
    661      1.1   gdamore 	 * address space we don't intend to use, right?
    662      1.1   gdamore 	 */
    663      1.1   gdamore 	if ((sc->sc_memsz < (4096 * 1024)) ||
    664      1.1   gdamore 	    (pci_mapreg_info(sc->sc_pc, sc->sc_pt, RADEON_MAPREG_VRAM,
    665      1.1   gdamore 		PCI_MAPREG_TYPE_MEM, &sc->sc_memaddr, &bsz, NULL) != 0) ||
    666      1.1   gdamore 	    (bsz < sc->sc_memsz)) {
    667      1.1   gdamore 		sc->sc_memsz = 0;
    668      1.1   gdamore 		aprint_error("%s: Bad frame buffer configuration\n",
    669      1.1   gdamore 		    XNAME(sc));
    670      1.1   gdamore 		goto error;
    671      1.1   gdamore 	}
    672      1.1   gdamore 
    673      1.1   gdamore 	/* 64 MB should be enough -- more just wastes map entries */
    674      1.1   gdamore 	if (sc->sc_memsz > (64 << 20))
    675      1.1   gdamore 		sc->sc_memsz = (64 << 20);
    676      1.1   gdamore 
    677      1.1   gdamore 	sc->sc_memt = pa->pa_memt;
    678      1.1   gdamore 	if (bus_space_map(sc->sc_memt, sc->sc_memaddr, sc->sc_memsz,
    679      1.1   gdamore 		BUS_SPACE_MAP_LINEAR, &sc->sc_memh) != 0) {
    680      1.1   gdamore 		sc->sc_memsz = 0;
    681      1.1   gdamore 		aprint_error("%s: Unable to map frame buffer\n", XNAME(sc));
    682      1.1   gdamore 		goto error;
    683      1.1   gdamore 	}
    684      1.1   gdamore 
    685      1.1   gdamore 	aprint_normal("%s: %d MB aperture at 0x%08x, "
    686      1.1   gdamore 	    "%d KB registers at 0x%08x\n", XNAME(sc),
    687      1.1   gdamore 	    (int)sc->sc_memsz >> 20, (unsigned)sc->sc_memaddr,
    688      1.1   gdamore 	    (int)sc->sc_regsz >> 10, (unsigned)sc->sc_regaddr);
    689      1.1   gdamore 
    690      1.1   gdamore 	/* setup default video mode from devprop (allows PROM override) */
    691      1.1   gdamore 	sc->sc_defaultmode = radeonfb_default_mode;
    692  1.7.2.1    bouyer 	if (prop_dictionary_get_cstring_nocopy(device_properties(&sc->sc_dev),
    693  1.7.2.1    bouyer 	    "videomode", &mptr)) {
    694  1.7.2.1    bouyer 
    695  1.7.2.1    bouyer 		strncpy(sc->sc_modebuf, mptr, sizeof(sc->sc_modebuf));
    696  1.7.2.1    bouyer 		sc->sc_defaultmode = sc->sc_modebuf;
    697      1.1   gdamore 	}
    698      1.1   gdamore 
    699      1.1   gdamore 	/* initialize some basic display parameters */
    700      1.1   gdamore 	for (i = 0; i < sc->sc_ndisplays; i++) {
    701      1.1   gdamore 		struct radeonfb_display *dp = &sc->sc_displays[i];
    702      1.1   gdamore 		struct rasops_info *ri;
    703      1.1   gdamore 		long defattr;
    704      1.1   gdamore 		struct wsemuldisplaydev_attach_args aa;
    705  1.7.2.2    bouyer 
    706      1.1   gdamore 		/*
    707      1.1   gdamore 		 * Figure out how many "displays" (desktops) we are going to
    708      1.1   gdamore 		 * support.  If more than one, then each CRTC gets its own
    709      1.1   gdamore 		 * programming.
    710      1.1   gdamore 		 *
    711      1.1   gdamore 		 * XXX: this code needs to change to support mergedfb.
    712      1.1   gdamore 		 * XXX: would be nice to allow this to be overridden
    713      1.1   gdamore 		 */
    714      1.1   gdamore 		if (HAS_CRTC2(sc) && (sc->sc_ndisplays == 1)) {
    715      1.1   gdamore 			DPRINTF(("dual crtcs!\n"));
    716      1.1   gdamore 			dp->rd_ncrtcs = 2;
    717      1.1   gdamore 			dp->rd_crtcs[0].rc_number = 0;
    718      1.1   gdamore 			dp->rd_crtcs[1].rc_number = 1;
    719      1.1   gdamore 		} else {
    720      1.1   gdamore 			dp->rd_ncrtcs = 1;
    721      1.1   gdamore 			dp->rd_crtcs[0].rc_number = i;
    722      1.1   gdamore 		}
    723      1.1   gdamore 
    724      1.1   gdamore 		/* set up port pointer */
    725      1.1   gdamore 		for (j = 0; j < dp->rd_ncrtcs; j++) {
    726      1.1   gdamore 			dp->rd_crtcs[j].rc_port =
    727      1.1   gdamore 			    &sc->sc_ports[dp->rd_crtcs[j].rc_number];
    728      1.1   gdamore 		}
    729      1.1   gdamore 
    730      1.1   gdamore 		dp->rd_softc = sc;
    731      1.1   gdamore 		dp->rd_wsmode = WSDISPLAYIO_MODE_EMUL;
    732      1.1   gdamore 		dp->rd_bg = WS_DEFAULT_BG;
    733      1.2  macallan #if 0
    734      1.1   gdamore 		dp->rd_bpp = sc->sc_maxbpp;	/* XXX: for now */
    735      1.2  macallan #else
    736      1.2  macallan 		dp->rd_bpp = RADEONFB_DEFAULT_DEPTH;	/* XXX */
    737      1.2  macallan #endif
    738      1.1   gdamore 		/* for text mode, we pick a resolution that won't
    739      1.1   gdamore 		 * require panning */
    740      1.1   gdamore 		radeonfb_pickres(dp, &dp->rd_virtx, &dp->rd_virty, 0);
    741      1.1   gdamore 
    742      1.1   gdamore 		aprint_normal("%s: display %d: "
    743      1.1   gdamore 		    "virtual resolution %dx%d at %d bpp\n",
    744      1.1   gdamore 		    XNAME(sc), i, dp->rd_virtx, dp->rd_virty, dp->rd_bpp);
    745      1.1   gdamore 
    746      1.1   gdamore 		/* now select the *video mode* that we will use */
    747      1.1   gdamore 		for (j = 0; j < dp->rd_ncrtcs; j++) {
    748      1.1   gdamore 			const struct videomode *vmp;
    749  1.7.2.1    bouyer 			vmp = radeonfb_port_mode(sc, dp->rd_crtcs[j].rc_port,
    750      1.1   gdamore 			    dp->rd_virtx, dp->rd_virty);
    751      1.1   gdamore 			dp->rd_crtcs[j].rc_videomode = *vmp;
    752      1.1   gdamore 			printf("%s: port %d: physical %dx%d %dHz\n",
    753      1.1   gdamore 			    XNAME(sc), j, vmp->hdisplay, vmp->vdisplay,
    754      1.1   gdamore 			    DIVIDE(DIVIDE(vmp->dot_clock * 1000,
    755      1.1   gdamore 				       vmp->htotal), vmp->vtotal));
    756      1.1   gdamore 		}
    757      1.1   gdamore 
    758      1.1   gdamore 		/* N.B.: radeon wants 64-byte aligned stride */
    759      1.2  macallan 		dp->rd_stride = dp->rd_virtx * dp->rd_bpp / 8;
    760      1.2  macallan 		//dp->rd_stride = sc->sc_maxx * sc->sc_maxbpp / 8;
    761      1.1   gdamore 		dp->rd_stride = ROUNDUP(dp->rd_stride, RADEON_STRIDEALIGN);
    762      1.1   gdamore 
    763      1.1   gdamore 		dp->rd_offset = sc->sc_fboffset * i;
    764      1.1   gdamore 		dp->rd_fbptr = (vaddr_t)bus_space_vaddr(sc->sc_memt,
    765      1.1   gdamore 		    sc->sc_memh) + dp->rd_offset;
    766      1.1   gdamore 		dp->rd_curoff = sc->sc_fbsize;
    767      1.1   gdamore 		dp->rd_curptr = dp->rd_fbptr + dp->rd_curoff;
    768      1.1   gdamore 
    769      1.1   gdamore 		DPRINTF(("fpbtr = %p\n", (void *)dp->rd_fbptr));
    770      1.1   gdamore 
    771      1.1   gdamore 		switch (dp->rd_bpp) {
    772      1.1   gdamore 		case 8:
    773      1.1   gdamore 			dp->rd_format = 2;
    774      1.1   gdamore 			break;
    775      1.1   gdamore 		case 32:
    776      1.1   gdamore 			dp->rd_format = 6;
    777      1.1   gdamore 			break;
    778      1.1   gdamore 		default:
    779      1.1   gdamore 			aprint_error("%s: bad depth %d\n", XNAME(sc),
    780      1.1   gdamore 			    dp->rd_bpp);
    781      1.1   gdamore 			goto error;
    782      1.1   gdamore 		}
    783      1.1   gdamore 
    784      1.2  macallan 		printf("init engine\n");
    785      1.2  macallan 		/* XXX: this seems suspicious - per display engine
    786      1.2  macallan 		   initialization? */
    787      1.2  macallan 		radeonfb_engine_init(dp);
    788      1.2  macallan 
    789      1.1   gdamore 		/* copy the template into place */
    790      1.1   gdamore 		dp->rd_wsscreens_storage[0] = radeonfb_stdscreen;
    791      1.1   gdamore 		dp->rd_wsscreens = dp->rd_wsscreens_storage;
    792      1.1   gdamore 
    793      1.1   gdamore 		/* and make up the list */
    794      1.1   gdamore 		dp->rd_wsscreenlist.nscreens = 1;
    795      1.1   gdamore 		dp->rd_wsscreenlist.screens =
    796      1.1   gdamore 		    (const struct wsscreen_descr **)&dp->rd_wsscreens;
    797      1.1   gdamore 
    798      1.1   gdamore 		vcons_init(&dp->rd_vd, dp, dp->rd_wsscreens,
    799      1.1   gdamore 		    &radeonfb_accessops);
    800      1.1   gdamore 
    801      1.1   gdamore 		dp->rd_vd.init_screen = radeonfb_init_screen;
    802      1.1   gdamore 
    803      1.2  macallan 		dp->rd_console = 1;
    804      1.1   gdamore 
    805      1.1   gdamore 		dp->rd_vscreen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    806      1.1   gdamore 
    807      1.1   gdamore 		vcons_init_screen(&dp->rd_vd, &dp->rd_vscreen,
    808      1.1   gdamore 		    dp->rd_console, &defattr);
    809      1.1   gdamore 
    810      1.1   gdamore 		ri = &dp->rd_vscreen.scr_ri;
    811      1.1   gdamore 		dp->rd_wsscreens->textops = &ri->ri_ops;
    812      1.1   gdamore 		dp->rd_wsscreens->capabilities = ri->ri_caps;
    813      1.1   gdamore 		dp->rd_wsscreens->nrows = ri->ri_rows;
    814      1.1   gdamore 		dp->rd_wsscreens->ncols = ri->ri_cols;
    815      1.1   gdamore 
    816      1.1   gdamore #ifdef SPLASHSCREEN
    817      1.1   gdamore 		dp->rd_splash.si_depth = ri->ri_depth;
    818      1.1   gdamore 		dp->rd_splash.si_bits = ri->ri_bits;
    819      1.1   gdamore 		dp->rd_splash.si_hwbits = ri->ri_hwbits;
    820      1.1   gdamore 		dp->rd_splash.si_width = ri->ri_width;
    821      1.1   gdamore 		dp->rd_splash.si_height = ri->ri_height;
    822      1.1   gdamore 		dp->rd_splash.si_stride = ri->ri_stride;
    823      1.1   gdamore 		dp->rd_splash.si_fillrect = NULL;
    824      1.1   gdamore #endif
    825      1.1   gdamore 		if (dp->rd_console) {
    826      1.1   gdamore 
    827      1.1   gdamore 			wsdisplay_cnattach(dp->rd_wsscreens, ri, 0, 0,
    828      1.1   gdamore 			    defattr);
    829      1.1   gdamore #ifdef SPLASHSCREEN
    830      1.1   gdamore 			splash_render(&dp->rd_splash,
    831      1.1   gdamore 			    SPLASH_F_CENTER|SPLASH_F_FILL);
    832      1.1   gdamore #endif
    833      1.1   gdamore 
    834      1.1   gdamore #ifdef SPLASHSCREEN_PROGRESS
    835      1.1   gdamore 			dp->rd_progress.sp_top = (dp->rd_virty / 8) * 7;
    836      1.1   gdamore 			dp->rd_progress.sp_width = (dp->rd_virtx / 4) * 3;
    837      1.1   gdamore 			dp->rd_progress.sp_left = (dp->rd_virtx -
    838      1.1   gdamore 			    dp->rd_progress.sp_width) / 2;
    839      1.1   gdamore 			dp->rd_progress.sp_height = 20;
    840      1.1   gdamore 			dp->rd_progress.sp_state = -1;
    841      1.1   gdamore 			dp->rd_progress.sp_si = &dp->rd_splash;
    842      1.1   gdamore 			splash_progress_init(&dp->rd_progress);
    843      1.1   gdamore 			SCREEN_DISABLE_DRAWING(&dp->rd_vscreen);
    844      1.1   gdamore #endif
    845      1.1   gdamore 
    846      1.1   gdamore 		} else {
    847      1.1   gdamore 
    848      1.1   gdamore 			/*
    849      1.1   gdamore 			 * since we're not the console we can postpone
    850      1.1   gdamore 			 * the rest until someone actually allocates a
    851      1.1   gdamore 			 * screen for us.  but we do clear the screen
    852      1.1   gdamore 			 * at least.
    853      1.1   gdamore 			 */
    854      1.1   gdamore 			memset(ri->ri_bits, 0, 1024);
    855      1.1   gdamore 
    856      1.1   gdamore 			radeonfb_modeswitch(dp);
    857      1.1   gdamore #ifdef SPLASHSCREEN
    858      1.1   gdamore 			splash_render(&dp->rd_splash,
    859      1.1   gdamore 			    SPLASH_F_CENTER|SPLASH_F_FILL);
    860      1.1   gdamore 			SCREEN_DISABLE_DRAWING(&dp->rd_vscreen);
    861      1.1   gdamore #endif
    862      1.1   gdamore 		}
    863      1.1   gdamore 
    864      1.1   gdamore 		aa.console = dp->rd_console;
    865      1.1   gdamore 		aa.scrdata = &dp->rd_wsscreenlist;
    866      1.1   gdamore 		aa.accessops = &radeonfb_accessops;
    867      1.1   gdamore 		aa.accesscookie = &dp->rd_vd;
    868      1.1   gdamore 
    869      1.1   gdamore 		config_found(&sc->sc_dev, &aa, wsemuldisplaydevprint);
    870      1.2  macallan 		radeonfb_blank(dp, 0);
    871  1.7.2.2    bouyer 
    872  1.7.2.1    bouyer 		/* Initialise delayed lvds operations for backlight. */
    873  1.7.2.1    bouyer 		callout_init(&dp->rd_bl_lvds_co);
    874  1.7.2.1    bouyer 		callout_setfunc(&dp->rd_bl_lvds_co,
    875  1.7.2.1    bouyer 				radeonfb_lvds_callout, dp);
    876      1.1   gdamore 	}
    877      1.1   gdamore 
    878      1.1   gdamore 	return;
    879      1.1   gdamore 
    880      1.1   gdamore error:
    881      1.1   gdamore 	if (sc->sc_biossz)
    882      1.1   gdamore 		free(sc->sc_bios, M_DEVBUF);
    883      1.1   gdamore 
    884      1.1   gdamore 	if (sc->sc_regsz)
    885      1.1   gdamore 		bus_space_unmap(sc->sc_regt, sc->sc_regh, sc->sc_regsz);
    886      1.1   gdamore 
    887      1.1   gdamore 	if (sc->sc_memsz)
    888      1.1   gdamore 		bus_space_unmap(sc->sc_memt, sc->sc_memh, sc->sc_memsz);
    889      1.1   gdamore }
    890      1.1   gdamore 
    891      1.1   gdamore int
    892      1.1   gdamore radeonfb_ioctl(void *v, void *vs,
    893      1.1   gdamore     unsigned long cmd, caddr_t d, int flag, struct lwp *l)
    894      1.1   gdamore {
    895      1.1   gdamore 	struct vcons_data	*vd;
    896      1.1   gdamore 	struct radeonfb_display	*dp;
    897      1.1   gdamore 	struct radeonfb_softc	*sc;
    898  1.7.2.1    bouyer 	struct wsdisplay_param  *param;
    899      1.1   gdamore 
    900      1.1   gdamore 	vd = (struct vcons_data *)v;
    901      1.1   gdamore 	dp = (struct radeonfb_display *)vd->cookie;
    902      1.1   gdamore 	sc = dp->rd_softc;
    903      1.1   gdamore 
    904      1.1   gdamore 	switch (cmd) {
    905      1.1   gdamore 	case WSDISPLAYIO_GTYPE:
    906      1.1   gdamore 		*(unsigned *)d = WSDISPLAY_TYPE_PCIMISC;
    907      1.1   gdamore 		return 0;
    908      1.1   gdamore 
    909      1.1   gdamore 	case WSDISPLAYIO_GINFO:
    910      1.1   gdamore 		if (vd->active != NULL) {
    911      1.1   gdamore 			struct wsdisplay_fbinfo *fb;
    912      1.1   gdamore 			fb = (struct wsdisplay_fbinfo *)d;
    913  1.7.2.2    bouyer 			fb->width = dp->rd_virtx;
    914  1.7.2.2    bouyer 			fb->height = dp->rd_virty;
    915      1.1   gdamore 			fb->depth = dp->rd_bpp;
    916      1.1   gdamore 			fb->cmsize = 256;
    917      1.1   gdamore 			return 0;
    918      1.1   gdamore 		} else
    919      1.1   gdamore 			return ENODEV;
    920      1.1   gdamore 	case WSDISPLAYIO_GVIDEO:
    921      1.1   gdamore 		if (radeonfb_isblank(dp))
    922      1.1   gdamore 			*(unsigned *)d = WSDISPLAYIO_VIDEO_OFF;
    923      1.1   gdamore 		else
    924      1.1   gdamore 			*(unsigned *)d = WSDISPLAYIO_VIDEO_ON;
    925      1.1   gdamore 		return 0;
    926      1.1   gdamore 
    927      1.1   gdamore 	case WSDISPLAYIO_SVIDEO:
    928      1.1   gdamore 		radeonfb_blank(dp,
    929      1.1   gdamore 		    (*(unsigned int *)d == WSDISPLAYIO_VIDEO_OFF));
    930      1.1   gdamore 		return 0;
    931      1.1   gdamore 
    932      1.1   gdamore 	case WSDISPLAYIO_GETCMAP:
    933      1.1   gdamore #if 0
    934      1.1   gdamore 		if (dp->rd_bpp == 8)
    935      1.1   gdamore 			return radeonfb_getcmap(sc,
    936      1.1   gdamore 			    (struct wsdisplay_cmap *)d);
    937      1.1   gdamore #endif
    938      1.1   gdamore 		return EINVAL;
    939  1.7.2.2    bouyer 
    940      1.1   gdamore 	case WSDISPLAYIO_PUTCMAP:
    941      1.1   gdamore #if 0
    942      1.1   gdamore 		if (dp->rd_bpp == 8)
    943      1.1   gdamore 			return radeonfb_putcmap(sc,
    944      1.1   gdamore 			    (struct wsdisplay_cmap *)d);
    945      1.1   gdamore #endif
    946      1.1   gdamore 		return EINVAL;
    947  1.7.2.2    bouyer 
    948      1.1   gdamore 	case WSDISPLAYIO_LINEBYTES:
    949      1.1   gdamore 		*(unsigned *)d = dp->rd_stride;
    950      1.1   gdamore 		return 0;
    951      1.1   gdamore 
    952      1.1   gdamore 	case WSDISPLAYIO_SMODE:
    953      1.1   gdamore 		if (*(int *)d != dp->rd_wsmode) {
    954      1.1   gdamore 			dp->rd_wsmode = *(int *)d;
    955      1.1   gdamore 			if ((dp->rd_wsmode == WSDISPLAYIO_MODE_EMUL) &&
    956      1.1   gdamore 			    (dp->rd_vd.active)) {
    957      1.1   gdamore 				vcons_redraw_screen(dp->rd_vd.active);
    958      1.1   gdamore 			}
    959      1.1   gdamore 		}
    960      1.1   gdamore 		return 0;
    961      1.1   gdamore 
    962      1.1   gdamore 	case WSDISPLAYIO_GCURMAX:
    963      1.1   gdamore 		((struct wsdisplay_curpos *)d)->x = RADEON_CURSORMAXX;
    964      1.1   gdamore 		((struct wsdisplay_curpos *)d)->y = RADEON_CURSORMAXY;
    965      1.1   gdamore 		return 0;
    966      1.1   gdamore 
    967      1.1   gdamore 	case WSDISPLAYIO_SCURSOR:
    968      1.1   gdamore 		return radeonfb_set_cursor(dp, (struct wsdisplay_cursor *)d);
    969      1.1   gdamore 
    970      1.1   gdamore 	case WSDISPLAYIO_GCURSOR:
    971      1.1   gdamore 		return EPASSTHROUGH;
    972      1.1   gdamore 
    973      1.1   gdamore 	case WSDISPLAYIO_GCURPOS:
    974      1.1   gdamore 		((struct wsdisplay_curpos *)d)->x = dp->rd_cursor.rc_pos.x;
    975      1.1   gdamore 		((struct wsdisplay_curpos *)d)->y = dp->rd_cursor.rc_pos.y;
    976      1.1   gdamore 		return 0;
    977      1.1   gdamore 
    978      1.1   gdamore 	case WSDISPLAYIO_SCURPOS:
    979      1.1   gdamore 		return radeonfb_set_curpos(dp, (struct wsdisplay_curpos *)d);
    980      1.1   gdamore 
    981      1.1   gdamore 	case WSDISPLAYIO_SSPLASH:
    982      1.1   gdamore #if defined(SPLASHSCREEN)
    983      1.1   gdamore 		if (*(int *)d == 1) {
    984      1.1   gdamore 			SCREEN_DISABLE_DRAWING(&dp->rd_vscreen);
    985      1.1   gdamore 			splash_render(&dp->rd_splash,
    986      1.1   gdamore 			    SPLASH_F_CENTER|SPLASH_F_FILL);
    987      1.1   gdamore 		} else
    988      1.1   gdamore 			SCREEN_ENABLE_DRAWING(&dp->rd_vscreen);
    989      1.1   gdamore 		return 0;
    990      1.1   gdamore #else
    991      1.1   gdamore 		return ENODEV;
    992      1.1   gdamore #endif
    993      1.1   gdamore 	case WSDISPLAYIO_SPROGRESS:
    994      1.1   gdamore #if defined(SPLASHSCREEN) && defined(SPLASHSCREEN_PROGRESS)
    995      1.1   gdamore 		dp->rd_progress.sp_force = 1;
    996      1.1   gdamore 		splash_progress_update(&dp->rd_progress);
    997      1.1   gdamore 		dp->rd_progress.sp_force = 0;
    998      1.1   gdamore 		return 0;
    999      1.1   gdamore #else
   1000      1.1   gdamore 		return ENODEV;
   1001      1.1   gdamore #endif
   1002  1.7.2.1    bouyer 	case WSDISPLAYIO_GETPARAM:
   1003  1.7.2.1    bouyer 		param = (struct wsdisplay_param *)d;
   1004  1.7.2.1    bouyer 		if (param->param == WSDISPLAYIO_PARAM_BACKLIGHT) {
   1005  1.7.2.1    bouyer 			param->min = 0;
   1006  1.7.2.1    bouyer 			param->max = RADEONFB_BACKLIGHT_MAX;
   1007  1.7.2.1    bouyer 			param->curval = radeonfb_get_backlight(dp);
   1008  1.7.2.1    bouyer 			return 0;
   1009  1.7.2.1    bouyer 		}
   1010  1.7.2.1    bouyer 		return EPASSTHROUGH;
   1011  1.7.2.1    bouyer 
   1012  1.7.2.1    bouyer 	case WSDISPLAYIO_SETPARAM:
   1013  1.7.2.1    bouyer 		param = (struct wsdisplay_param *)d;
   1014  1.7.2.1    bouyer 		if (param->param == WSDISPLAYIO_PARAM_BACKLIGHT) {
   1015  1.7.2.1    bouyer 			return radeonfb_set_backlight(dp, param->curval);
   1016  1.7.2.1    bouyer 		}
   1017  1.7.2.1    bouyer 		return EPASSTHROUGH;
   1018      1.1   gdamore 
   1019      1.1   gdamore 	default:
   1020      1.1   gdamore 		return EPASSTHROUGH;
   1021      1.1   gdamore 	}
   1022      1.1   gdamore }
   1023      1.1   gdamore 
   1024      1.1   gdamore paddr_t
   1025      1.1   gdamore radeonfb_mmap(void *v, void *vs, off_t offset, int prot)
   1026      1.1   gdamore {
   1027      1.1   gdamore 	struct vcons_data	*vd;
   1028      1.1   gdamore 	struct radeonfb_display	*dp;
   1029      1.1   gdamore 	struct radeonfb_softc	*sc;
   1030      1.5  macallan #ifdef RADEONFB_MMAP_BARS
   1031      1.5  macallan 	struct lwp *me;
   1032      1.5  macallan #endif
   1033      1.1   gdamore 	paddr_t			pa;
   1034      1.1   gdamore 
   1035      1.1   gdamore 	vd = (struct vcons_data *)v;
   1036      1.1   gdamore 	dp = (struct radeonfb_display *)vd->cookie;
   1037      1.1   gdamore 	sc = dp->rd_softc;
   1038      1.1   gdamore 
   1039      1.1   gdamore 	/* XXX: note that we don't allow mapping of registers right now */
   1040      1.1   gdamore 	/* XXX: this means that the XFree86 radeon driver won't work */
   1041      1.1   gdamore 
   1042      1.1   gdamore 	if ((offset >= 0) && (offset < (dp->rd_virty * dp->rd_stride))) {
   1043      1.1   gdamore 		pa = bus_space_mmap(sc->sc_memt,
   1044      1.1   gdamore 		    sc->sc_memaddr + dp->rd_offset + offset, 0,
   1045      1.1   gdamore 		    prot, BUS_SPACE_MAP_LINEAR);
   1046      1.1   gdamore 		return pa;
   1047      1.1   gdamore 	}
   1048      1.1   gdamore 
   1049      1.3  macallan #ifdef RADEONFB_MMAP_BARS
   1050      1.5  macallan 	/*
   1051      1.5  macallan 	 * restrict all other mappings to processes with superuser privileges
   1052      1.5  macallan 	 * or the kernel itself
   1053      1.5  macallan 	 */
   1054      1.5  macallan 	me = curlwp;
   1055      1.5  macallan 	if (me != NULL) {
   1056      1.5  macallan 		if (kauth_authorize_generic(me->l_cred, KAUTH_GENERIC_ISSUSER,
   1057      1.5  macallan 		    NULL) != 0) {
   1058      1.5  macallan 			printf("%s: mmap() rejected.\n", sc->sc_dev.dv_xname);
   1059      1.5  macallan 			return -1;
   1060      1.5  macallan 		}
   1061      1.5  macallan 	}
   1062      1.5  macallan 
   1063  1.7.2.2    bouyer 	if ((offset >= sc->sc_regaddr) &&
   1064      1.3  macallan 	    (offset < sc->sc_regaddr + sc->sc_regsz)) {
   1065  1.7.2.2    bouyer 		return bus_space_mmap(sc->sc_regt, offset, 0, prot,
   1066      1.3  macallan 		    BUS_SPACE_MAP_LINEAR);
   1067      1.3  macallan 	}
   1068      1.3  macallan 
   1069  1.7.2.2    bouyer 	if ((offset >= sc->sc_memaddr) &&
   1070      1.3  macallan 	    (offset < sc->sc_memaddr + sc->sc_memsz)) {
   1071  1.7.2.2    bouyer 		return bus_space_mmap(sc->sc_memt, offset, 0, prot,
   1072      1.3  macallan 		    BUS_SPACE_MAP_LINEAR);
   1073      1.3  macallan 	}
   1074      1.5  macallan 
   1075      1.5  macallan #ifdef macppc
   1076      1.5  macallan 	/* allow mapping of IO space */
   1077      1.5  macallan 	if ((offset >= 0xf2000000) && (offset < 0xf2800000)) {
   1078  1.7.2.2    bouyer 		pa = bus_space_mmap(sc->sc_iot, offset-0xf2000000, 0, prot,
   1079  1.7.2.2    bouyer 		    BUS_SPACE_MAP_LINEAR);
   1080      1.5  macallan 		return pa;
   1081  1.7.2.2    bouyer 	}
   1082      1.5  macallan #endif /* macppc */
   1083      1.5  macallan 
   1084      1.3  macallan #endif /* RADEONFB_MMAP_BARS */
   1085      1.3  macallan 
   1086      1.1   gdamore 	return -1;
   1087      1.1   gdamore }
   1088      1.1   gdamore 
   1089      1.2  macallan static void
   1090      1.1   gdamore radeonfb_loadbios(struct radeonfb_softc *sc, struct pci_attach_args *pa)
   1091      1.1   gdamore {
   1092      1.1   gdamore 	bus_space_tag_t		romt;
   1093      1.1   gdamore 	bus_space_handle_t	romh, biosh;
   1094      1.1   gdamore 	bus_size_t		romsz;
   1095      1.1   gdamore 	bus_addr_t		ptr;
   1096      1.1   gdamore 
   1097      1.1   gdamore 	if (pci_mapreg_map(pa, PCI_MAPREG_ROM, PCI_MAPREG_TYPE_ROM,
   1098      1.1   gdamore 		BUS_SPACE_MAP_PREFETCHABLE, &romt, &romh, NULL, &romsz) != 0) {
   1099      1.1   gdamore 		aprint_verbose("%s: unable to map BIOS!\n", XNAME(sc));
   1100      1.1   gdamore 		return;
   1101      1.1   gdamore 	}
   1102      1.1   gdamore 
   1103      1.1   gdamore 	pci_find_rom(pa, romt, romh, PCI_ROM_CODE_TYPE_X86, &biosh,
   1104      1.1   gdamore 	    &sc->sc_biossz);
   1105      1.1   gdamore 	if (sc->sc_biossz == 0) {
   1106      1.1   gdamore 		aprint_verbose("%s: Video BIOS not present\n", XNAME(sc));
   1107      1.1   gdamore 		return;
   1108      1.1   gdamore 	}
   1109      1.1   gdamore 
   1110      1.1   gdamore 	sc->sc_bios = malloc(sc->sc_biossz, M_DEVBUF, M_WAITOK);
   1111      1.1   gdamore 	bus_space_read_region_1(romt, biosh, 0, sc->sc_bios, sc->sc_biossz);
   1112      1.1   gdamore 
   1113      1.1   gdamore 	/* unmap the PCI expansion rom */
   1114      1.1   gdamore 	bus_space_unmap(romt, romh, romsz);
   1115      1.1   gdamore 
   1116      1.1   gdamore 	/* turn off rom decoder now */
   1117      1.1   gdamore 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM,
   1118      1.1   gdamore 	    pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM) &
   1119      1.1   gdamore 	    ~PCI_MAPREG_ROM_ENABLE);
   1120      1.1   gdamore 
   1121      1.1   gdamore 	ptr = GETBIOS16(sc, 0x48);
   1122      1.1   gdamore 	if ((GETBIOS32(sc, ptr + 4) == 0x41544f4d /* "ATOM" */) ||
   1123      1.1   gdamore 	    (GETBIOS32(sc, ptr + 4) == 0x4d4f5441 /* "MOTA" */)) {
   1124      1.1   gdamore 		sc->sc_flags |= RFB_ATOM;
   1125      1.1   gdamore 	}
   1126      1.1   gdamore 
   1127      1.1   gdamore 	aprint_verbose("%s: Found %d KB %s BIOS\n", XNAME(sc),
   1128      1.1   gdamore 	    (unsigned)sc->sc_biossz >> 10, IS_ATOM(sc) ? "ATOM" : "Legacy");
   1129      1.1   gdamore }
   1130      1.1   gdamore 
   1131      1.1   gdamore 
   1132      1.1   gdamore uint32_t
   1133      1.1   gdamore radeonfb_get32(struct radeonfb_softc *sc, uint32_t reg)
   1134      1.1   gdamore {
   1135      1.1   gdamore 
   1136      1.1   gdamore 	return bus_space_read_4(sc->sc_regt, sc->sc_regh, reg);
   1137      1.1   gdamore }
   1138      1.1   gdamore 
   1139      1.1   gdamore void
   1140      1.1   gdamore radeonfb_put32(struct radeonfb_softc *sc, uint32_t reg, uint32_t val)
   1141      1.1   gdamore {
   1142      1.1   gdamore 
   1143      1.1   gdamore 	bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, val);
   1144      1.1   gdamore }
   1145      1.1   gdamore 
   1146      1.1   gdamore void
   1147      1.1   gdamore radeonfb_mask32(struct radeonfb_softc *sc, uint32_t reg,
   1148      1.1   gdamore     uint32_t andmask, uint32_t ormask)
   1149      1.1   gdamore {
   1150      1.1   gdamore 	int		s;
   1151      1.1   gdamore 	uint32_t	val;
   1152      1.1   gdamore 
   1153      1.1   gdamore 	s = splhigh();
   1154      1.1   gdamore 	val = radeonfb_get32(sc, reg);
   1155      1.1   gdamore 	val = (val & andmask) | ormask;
   1156      1.1   gdamore 	radeonfb_put32(sc, reg, val);
   1157      1.1   gdamore 	splx(s);
   1158      1.1   gdamore }
   1159      1.1   gdamore 
   1160      1.1   gdamore uint32_t
   1161      1.1   gdamore radeonfb_getindex(struct radeonfb_softc *sc, uint32_t idx)
   1162      1.1   gdamore {
   1163      1.1   gdamore 	int		s;
   1164      1.1   gdamore 	uint32_t	val;
   1165      1.1   gdamore 
   1166      1.1   gdamore 	s = splhigh();
   1167      1.1   gdamore 	radeonfb_put32(sc, RADEON_MM_INDEX, idx);
   1168      1.1   gdamore 	val = radeonfb_get32(sc, RADEON_MM_DATA);
   1169      1.1   gdamore 	splx(s);
   1170      1.1   gdamore 
   1171      1.1   gdamore 	return (val);
   1172      1.1   gdamore }
   1173      1.1   gdamore 
   1174      1.1   gdamore void
   1175      1.1   gdamore radeonfb_putindex(struct radeonfb_softc *sc, uint32_t idx, uint32_t val)
   1176      1.1   gdamore {
   1177      1.1   gdamore 	int	s;
   1178      1.1   gdamore 
   1179      1.1   gdamore 	s = splhigh();
   1180      1.1   gdamore 	radeonfb_put32(sc, RADEON_MM_INDEX, idx);
   1181      1.1   gdamore 	radeonfb_put32(sc, RADEON_MM_DATA, val);
   1182      1.1   gdamore 	splx(s);
   1183      1.1   gdamore }
   1184      1.1   gdamore 
   1185      1.1   gdamore void
   1186      1.1   gdamore radeonfb_maskindex(struct radeonfb_softc *sc, uint32_t idx,
   1187      1.1   gdamore     uint32_t andmask, uint32_t ormask)
   1188      1.1   gdamore {
   1189      1.1   gdamore 	int		s;
   1190      1.1   gdamore 	uint32_t	val;
   1191      1.1   gdamore 
   1192      1.1   gdamore 	s = splhigh();
   1193      1.1   gdamore 	radeonfb_put32(sc, RADEON_MM_INDEX, idx);
   1194      1.1   gdamore 	val = radeonfb_get32(sc, RADEON_MM_DATA);
   1195      1.1   gdamore 	val = (val & andmask) | ormask;
   1196      1.1   gdamore 	radeonfb_put32(sc, RADEON_MM_DATA, val);
   1197      1.1   gdamore 	splx(s);
   1198      1.1   gdamore }
   1199      1.1   gdamore 
   1200      1.1   gdamore uint32_t
   1201      1.1   gdamore radeonfb_getpll(struct radeonfb_softc *sc, uint32_t idx)
   1202      1.1   gdamore {
   1203      1.1   gdamore 	int		s;
   1204      1.1   gdamore 	uint32_t	val;
   1205      1.1   gdamore 
   1206      1.1   gdamore 	s = splhigh();
   1207      1.1   gdamore 	radeonfb_put32(sc, RADEON_CLOCK_CNTL_INDEX, idx & 0x3f);
   1208      1.1   gdamore 	val = radeonfb_get32(sc, RADEON_CLOCK_CNTL_DATA);
   1209      1.1   gdamore 	if (HAS_R300CG(sc))
   1210      1.1   gdamore 		radeonfb_r300cg_workaround(sc);
   1211      1.1   gdamore 	splx(s);
   1212      1.1   gdamore 
   1213      1.1   gdamore 	return (val);
   1214      1.1   gdamore }
   1215      1.1   gdamore 
   1216      1.1   gdamore void
   1217      1.1   gdamore radeonfb_putpll(struct radeonfb_softc *sc, uint32_t idx, uint32_t val)
   1218      1.1   gdamore {
   1219      1.1   gdamore 	int	s;
   1220      1.1   gdamore 
   1221      1.1   gdamore 	s = splhigh();
   1222      1.1   gdamore 	radeonfb_put32(sc, RADEON_CLOCK_CNTL_INDEX, (idx & 0x3f) |
   1223      1.1   gdamore 	    RADEON_PLL_WR_EN);
   1224      1.1   gdamore 	radeonfb_put32(sc, RADEON_CLOCK_CNTL_DATA, val);
   1225      1.1   gdamore 	radeonfb_put32(sc, RADEON_CLOCK_CNTL_INDEX, 0);
   1226      1.1   gdamore 	splx(s);
   1227      1.1   gdamore }
   1228      1.1   gdamore 
   1229      1.1   gdamore void
   1230      1.1   gdamore radeonfb_maskpll(struct radeonfb_softc *sc, uint32_t idx,
   1231      1.1   gdamore     uint32_t andmask, uint32_t ormask)
   1232      1.1   gdamore {
   1233      1.1   gdamore 	int		s;
   1234      1.1   gdamore 	uint32_t	val;
   1235      1.1   gdamore 
   1236      1.1   gdamore 	s = splhigh();
   1237      1.1   gdamore 	radeonfb_put32(sc, RADEON_CLOCK_CNTL_INDEX, (idx & 0x3f) |
   1238      1.1   gdamore 		RADEON_PLL_WR_EN);
   1239      1.1   gdamore 	val = radeonfb_get32(sc, RADEON_CLOCK_CNTL_DATA);
   1240      1.1   gdamore 	val = (val & andmask) | ormask;
   1241      1.1   gdamore 	radeonfb_put32(sc, RADEON_CLOCK_CNTL_DATA, val);
   1242      1.1   gdamore 	radeonfb_put32(sc, RADEON_CLOCK_CNTL_INDEX, 0);
   1243      1.1   gdamore 	splx(s);
   1244      1.1   gdamore }
   1245      1.1   gdamore 
   1246      1.1   gdamore int
   1247      1.1   gdamore radeonfb_scratch_test(struct radeonfb_softc *sc, int reg, uint32_t v)
   1248      1.1   gdamore {
   1249      1.1   gdamore 	uint32_t	saved;
   1250      1.1   gdamore 
   1251      1.1   gdamore 	saved = GET32(sc, reg);
   1252      1.1   gdamore 	PUT32(sc, reg, v);
   1253      1.1   gdamore 	if (GET32(sc, reg) != v) {
   1254      1.1   gdamore 		return -1;
   1255      1.1   gdamore 	}
   1256      1.1   gdamore 	PUT32(sc, reg, saved);
   1257      1.1   gdamore 	return 0;
   1258      1.1   gdamore }
   1259      1.1   gdamore 
   1260      1.1   gdamore uintmax_t
   1261      1.1   gdamore radeonfb_getprop_num(struct radeonfb_softc *sc, const char *name,
   1262      1.1   gdamore     uintmax_t defval)
   1263      1.1   gdamore {
   1264      1.1   gdamore 	prop_number_t	pn;
   1265      1.1   gdamore 	pn = prop_dictionary_get(device_properties(&sc->sc_dev), name);
   1266      1.1   gdamore 	if (pn == NULL) {
   1267      1.1   gdamore 		return defval;
   1268      1.1   gdamore 	}
   1269      1.1   gdamore 	KASSERT(prop_object_type(pn) == PROP_TYPE_NUMBER);
   1270      1.1   gdamore 	return (prop_number_integer_value(pn));
   1271      1.1   gdamore }
   1272      1.1   gdamore 
   1273      1.1   gdamore int
   1274      1.1   gdamore radeonfb_getclocks(struct radeonfb_softc *sc)
   1275      1.1   gdamore {
   1276      1.1   gdamore 	bus_addr_t	ptr;
   1277      1.1   gdamore 	int		refclk = 0;
   1278      1.1   gdamore 	int		refdiv = 0;
   1279      1.1   gdamore 	int		minpll = 0;
   1280      1.1   gdamore 	int		maxpll = 0;
   1281      1.1   gdamore 
   1282      1.1   gdamore 	/* load initial property values if port/board provides them */
   1283      1.1   gdamore 	refclk = radeonfb_getprop_num(sc, "refclk", 0) & 0xffff;
   1284      1.1   gdamore 	refdiv = radeonfb_getprop_num(sc, "refdiv", 0) & 0xffff;
   1285      1.1   gdamore 	minpll = radeonfb_getprop_num(sc, "minpll", 0) & 0xffffffffU;
   1286      1.1   gdamore 	maxpll = radeonfb_getprop_num(sc, "maxpll", 0) & 0xffffffffU;
   1287      1.1   gdamore 
   1288      1.1   gdamore 	if (refclk && refdiv && minpll && maxpll)
   1289      1.1   gdamore 		goto dontprobe;
   1290      1.1   gdamore 
   1291      1.1   gdamore 	if (!sc->sc_biossz) {
   1292      1.1   gdamore 		/* no BIOS */
   1293      1.1   gdamore 		aprint_verbose("%s: No video BIOS, using default clocks\n",
   1294      1.1   gdamore 		    XNAME(sc));
   1295      1.1   gdamore 		if (IS_IGP(sc))
   1296      1.1   gdamore 			refclk = refclk ? refclk : 1432;
   1297      1.1   gdamore 		else
   1298      1.1   gdamore 			refclk = refclk ? refclk : 2700;
   1299      1.1   gdamore 		refdiv = refdiv ? refdiv : 12;
   1300      1.1   gdamore 		minpll = minpll ? minpll : 12500;
   1301      1.1   gdamore 		maxpll = maxpll ? maxpll : 35000;
   1302      1.1   gdamore 	} else if (IS_ATOM(sc)) {
   1303      1.1   gdamore 		/* ATOM BIOS */
   1304      1.1   gdamore 		ptr = GETBIOS16(sc, 0x48);
   1305      1.1   gdamore 		ptr = GETBIOS16(sc, ptr + 32);	/* aka MasterDataStart */
   1306      1.1   gdamore 		ptr = GETBIOS16(sc, ptr + 12);	/* pll info block */
   1307      1.1   gdamore 		refclk = refclk ? refclk : GETBIOS16(sc, ptr + 82);
   1308      1.1   gdamore 		minpll = minpll ? minpll : GETBIOS16(sc, ptr + 78);
   1309      1.1   gdamore 		maxpll = maxpll ? maxpll : GETBIOS16(sc, ptr + 32);
   1310      1.1   gdamore 		/*
   1311      1.1   gdamore 		 * ATOM BIOS doesn't supply a reference divider, so we
   1312      1.1   gdamore 		 * have to probe for it.
   1313      1.1   gdamore 		 */
   1314      1.1   gdamore 		if (refdiv < 2)
   1315      1.1   gdamore 			refdiv = GETPLL(sc, RADEON_PPLL_REF_DIV) &
   1316      1.1   gdamore 			    RADEON_PPLL_REF_DIV_MASK;
   1317      1.1   gdamore 		/*
   1318      1.1   gdamore 		 * if probe is zero, just assume one that should work
   1319      1.1   gdamore 		 * for most parts
   1320      1.1   gdamore 		 */
   1321      1.1   gdamore 		if (refdiv < 2)
   1322      1.1   gdamore 			refdiv = 12;
   1323  1.7.2.2    bouyer 
   1324      1.1   gdamore 	} else {
   1325      1.1   gdamore 		/* Legacy BIOS */
   1326      1.1   gdamore 		ptr = GETBIOS16(sc, 0x48);
   1327      1.1   gdamore 		ptr = GETBIOS16(sc, ptr + 0x30);
   1328      1.1   gdamore 		refclk = refclk ? refclk : GETBIOS16(sc, ptr + 0x0E);
   1329      1.1   gdamore 		refdiv = refdiv ? refdiv : GETBIOS16(sc, ptr + 0x10);
   1330      1.1   gdamore 		minpll = minpll ? minpll : GETBIOS32(sc, ptr + 0x12);
   1331      1.1   gdamore 		maxpll = maxpll ? maxpll : GETBIOS32(sc, ptr + 0x16);
   1332      1.1   gdamore 	}
   1333      1.1   gdamore 
   1334      1.1   gdamore 
   1335      1.1   gdamore dontprobe:
   1336      1.1   gdamore 	sc->sc_refclk = refclk * 10;
   1337      1.1   gdamore 	sc->sc_refdiv = refdiv;
   1338      1.1   gdamore 	sc->sc_minpll = minpll * 10;
   1339      1.1   gdamore 	sc->sc_maxpll = maxpll * 10;
   1340      1.1   gdamore 	return 0;
   1341      1.1   gdamore }
   1342      1.1   gdamore 
   1343      1.1   gdamore int
   1344      1.1   gdamore radeonfb_calc_dividers(struct radeonfb_softc *sc, uint32_t dotclock,
   1345      1.1   gdamore     uint32_t *postdivbit, uint32_t *feedbackdiv)
   1346      1.1   gdamore {
   1347      1.1   gdamore 	int		i;
   1348      1.1   gdamore 	uint32_t	outfreq;
   1349      1.1   gdamore 	int		div;
   1350      1.1   gdamore 
   1351      1.1   gdamore 	DPRINTF(("dot clock: %u\n", dotclock));
   1352      1.1   gdamore 	for (i = 0; (div = radeonfb_dividers[i].divider) != 0; i++) {
   1353      1.1   gdamore 		outfreq = div * dotclock;
   1354      1.1   gdamore 		if ((outfreq >= sc->sc_minpll) &&
   1355      1.1   gdamore 		    (outfreq <= sc->sc_maxpll)) {
   1356      1.1   gdamore 			DPRINTF(("outfreq: %u\n", outfreq));
   1357      1.1   gdamore 			*postdivbit =
   1358      1.1   gdamore 			    ((uint32_t)radeonfb_dividers[i].mask << 16);
   1359      1.1   gdamore 			DPRINTF(("post divider: %d (mask %x)\n", div,
   1360      1.1   gdamore 				    *postdivbit));
   1361      1.1   gdamore 			break;
   1362      1.1   gdamore 		}
   1363      1.1   gdamore 	}
   1364      1.1   gdamore 
   1365      1.1   gdamore 	if (div == 0)
   1366      1.1   gdamore 		return 1;
   1367      1.1   gdamore 
   1368      1.1   gdamore 	*feedbackdiv = DIVIDE(sc->sc_refdiv * outfreq, sc->sc_refclk);
   1369      1.1   gdamore 	DPRINTF(("feedback divider: %d\n", *feedbackdiv));
   1370      1.1   gdamore 	return 0;
   1371      1.1   gdamore }
   1372      1.1   gdamore 
   1373      1.1   gdamore #if 0
   1374      1.1   gdamore #ifdef RADEON_DEBUG
   1375      1.1   gdamore static void
   1376      1.1   gdamore dump_buffer(const char *pfx, void *buffer, unsigned int size)
   1377      1.1   gdamore {
   1378      1.1   gdamore 	char		asc[17];
   1379      1.1   gdamore 	unsigned	ptr = (unsigned)buffer;
   1380      1.1   gdamore 	char		*start = (char *)(ptr & ~0xf);
   1381      1.1   gdamore 	char		*end = (char *)(ptr + size);
   1382      1.1   gdamore 
   1383      1.1   gdamore 	end = (char *)(((unsigned)end + 0xf) & ~0xf);
   1384      1.1   gdamore 
   1385      1.1   gdamore 	if (pfx == NULL) {
   1386      1.1   gdamore 		pfx = "";
   1387      1.1   gdamore 	}
   1388      1.1   gdamore 
   1389      1.1   gdamore 	while (start < end) {
   1390      1.1   gdamore 		unsigned offset = (unsigned)start & 0xf;
   1391      1.1   gdamore 		if (offset == 0) {
   1392      1.1   gdamore 			printf("%s%x: ", pfx, (unsigned)start);
   1393      1.1   gdamore 		}
   1394      1.1   gdamore 		if (((unsigned)start < ptr) ||
   1395      1.1   gdamore 		    ((unsigned)start >= (ptr + size))) {
   1396      1.1   gdamore 			printf("  ");
   1397      1.1   gdamore 			asc[offset] = ' ';
   1398      1.1   gdamore 		} else {
   1399      1.1   gdamore 			printf("%02x", *(unsigned char *)start);
   1400      1.1   gdamore 			if ((*start >= ' ') && (*start <= '~')) {
   1401      1.1   gdamore 				asc[offset] = *start;
   1402      1.1   gdamore 			} else {
   1403      1.1   gdamore 				asc[offset] = '.';
   1404      1.1   gdamore 			}
   1405      1.1   gdamore 		}
   1406      1.1   gdamore 		asc[offset + 1] = 0;
   1407      1.1   gdamore 		if (offset % 2) {
   1408      1.1   gdamore 			printf(" ");
   1409      1.1   gdamore 		}
   1410      1.1   gdamore 		if (offset == 15) {
   1411      1.1   gdamore 			printf(" %s\n", asc);
   1412      1.1   gdamore 		}
   1413      1.1   gdamore 		start++;
   1414      1.1   gdamore 	}
   1415      1.1   gdamore }
   1416      1.1   gdamore #endif
   1417      1.1   gdamore #endif
   1418      1.1   gdamore 
   1419      1.1   gdamore int
   1420      1.1   gdamore radeonfb_getconnectors(struct radeonfb_softc *sc)
   1421      1.1   gdamore {
   1422      1.1   gdamore 	int	i;
   1423      1.1   gdamore 	int	found = 0;
   1424      1.1   gdamore 
   1425      1.1   gdamore 	for (i = 0; i < 2; i++) {
   1426      1.1   gdamore 		sc->sc_ports[i].rp_mon_type = RADEON_MT_UNKNOWN;
   1427      1.1   gdamore 		sc->sc_ports[i].rp_ddc_type = RADEON_DDC_NONE;
   1428      1.1   gdamore 		sc->sc_ports[i].rp_dac_type = RADEON_DAC_UNKNOWN;
   1429      1.1   gdamore 		sc->sc_ports[i].rp_conn_type = RADEON_CONN_NONE;
   1430      1.1   gdamore 		sc->sc_ports[i].rp_tmds_type = RADEON_TMDS_UNKNOWN;
   1431      1.1   gdamore 	}
   1432      1.1   gdamore 
   1433      1.1   gdamore 	/*
   1434      1.1   gdamore 	 * This logic is borrowed from Xorg's radeon driver.
   1435      1.1   gdamore 	 */
   1436      1.1   gdamore 	if (!sc->sc_biossz)
   1437      1.1   gdamore 		goto nobios;
   1438      1.1   gdamore 
   1439      1.1   gdamore 	if (IS_ATOM(sc)) {
   1440      1.1   gdamore 		/* not done yet */
   1441      1.1   gdamore 	} else {
   1442      1.1   gdamore 		uint16_t	ptr;
   1443      1.1   gdamore 		int		port = 0;
   1444      1.1   gdamore 
   1445      1.1   gdamore 		ptr = GETBIOS16(sc, 0x48);
   1446      1.1   gdamore 		ptr = GETBIOS16(sc, ptr + 0x50);
   1447      1.1   gdamore 		for (i = 1; i < 4; i++) {
   1448      1.1   gdamore 			uint16_t	entry;
   1449      1.1   gdamore 			uint8_t		conn, ddc, dac, tmds;
   1450      1.1   gdamore 
   1451      1.1   gdamore 			/*
   1452      1.1   gdamore 			 * Parse the connector table.  From reading the code,
   1453      1.1   gdamore 			 * it appears to made up of 16-bit entries for each
   1454      1.1   gdamore 			 * connector.  The 16-bits are defined as:
   1455      1.1   gdamore 			 *
   1456      1.1   gdamore 			 * bits 12-15	- connector type (0 == end of table)
   1457      1.1   gdamore 			 * bits 8-11	- DDC type
   1458      1.1   gdamore 			 * bits 5-7	- ???
   1459      1.1   gdamore 			 * bit 4	- TMDS type (1 = EXT, 0 = INT)
   1460      1.1   gdamore 			 * bits 1-3	- ???
   1461      1.1   gdamore 			 * bit 0	- DAC, 1 = TVDAC, 0 = primary
   1462      1.1   gdamore 			 */
   1463      1.1   gdamore 			if (!GETBIOS8(sc, ptr + i * 2) && i > 1)
   1464      1.1   gdamore 				break;
   1465      1.1   gdamore 			entry = GETBIOS16(sc, ptr + i * 2);
   1466      1.1   gdamore 
   1467      1.1   gdamore 			conn = (entry >> 12) & 0xf;
   1468      1.1   gdamore 			ddc = (entry >> 8) & 0xf;
   1469      1.1   gdamore 			dac = (entry & 0x1) ? RADEON_DAC_TVDAC :
   1470      1.1   gdamore 			    RADEON_DAC_PRIMARY;
   1471      1.1   gdamore 			tmds = ((entry >> 4) & 0x1) ? RADEON_TMDS_EXT :
   1472      1.1   gdamore 			    RADEON_TMDS_INT;
   1473      1.1   gdamore 
   1474      1.1   gdamore 			if (conn == RADEON_CONN_NONE)
   1475      1.1   gdamore 				continue;	/* no connector */
   1476      1.1   gdamore 
   1477      1.1   gdamore 			if ((found > 0) &&
   1478      1.1   gdamore 			    (sc->sc_ports[port].rp_ddc_type == ddc)) {
   1479      1.1   gdamore 				/* duplicate entry for same connector */
   1480      1.1   gdamore 				continue;
   1481      1.1   gdamore 			}
   1482      1.1   gdamore 
   1483      1.1   gdamore 			/* internal DDC_DVI port gets priority */
   1484      1.1   gdamore 			if ((ddc == RADEON_DDC_DVI) || (port == 1))
   1485      1.1   gdamore 				port = 0;
   1486      1.1   gdamore 			else
   1487      1.1   gdamore 				port = 1;
   1488      1.1   gdamore 
   1489      1.1   gdamore 			sc->sc_ports[port].rp_ddc_type =
   1490      1.1   gdamore 			    ddc > RADEON_DDC_CRT2 ? RADEON_DDC_NONE : ddc;
   1491      1.1   gdamore 			sc->sc_ports[port].rp_dac_type = dac;
   1492      1.1   gdamore 			sc->sc_ports[port].rp_conn_type =
   1493      1.1   gdamore 			    min(conn, RADEON_CONN_UNSUPPORTED) ;
   1494      1.1   gdamore 
   1495      1.1   gdamore 			sc->sc_ports[port].rp_tmds_type = tmds;
   1496      1.1   gdamore 
   1497      1.1   gdamore 			if ((conn != RADEON_CONN_DVI_I) &&
   1498      1.1   gdamore 			    (conn != RADEON_CONN_DVI_D) &&
   1499      1.1   gdamore 			    (tmds == RADEON_TMDS_INT))
   1500      1.1   gdamore 				sc->sc_ports[port].rp_tmds_type =
   1501      1.1   gdamore 				    RADEON_TMDS_UNKNOWN;
   1502      1.1   gdamore 
   1503      1.1   gdamore 			found += (port + 1);
   1504      1.1   gdamore 		}
   1505      1.1   gdamore 	}
   1506      1.1   gdamore 
   1507      1.1   gdamore nobios:
   1508      1.1   gdamore 	if (!found) {
   1509      1.1   gdamore 		DPRINTF(("No connector info in BIOS!\n"));
   1510      1.1   gdamore 		/* default, port 0 = internal TMDS, port 1 = CRT */
   1511      1.1   gdamore 		sc->sc_ports[0].rp_mon_type = RADEON_MT_UNKNOWN;
   1512      1.1   gdamore 		sc->sc_ports[0].rp_ddc_type = RADEON_DDC_DVI;
   1513      1.1   gdamore 		sc->sc_ports[0].rp_dac_type = RADEON_DAC_TVDAC;
   1514      1.1   gdamore 		sc->sc_ports[0].rp_conn_type = RADEON_CONN_DVI_D;
   1515      1.1   gdamore 		sc->sc_ports[0].rp_tmds_type = RADEON_TMDS_INT;
   1516      1.1   gdamore 
   1517      1.1   gdamore 		sc->sc_ports[1].rp_mon_type = RADEON_MT_UNKNOWN;
   1518      1.1   gdamore 		sc->sc_ports[1].rp_ddc_type = RADEON_DDC_VGA;
   1519      1.1   gdamore 		sc->sc_ports[1].rp_dac_type = RADEON_DAC_PRIMARY;
   1520      1.1   gdamore 		sc->sc_ports[1].rp_conn_type = RADEON_CONN_CRT;
   1521      1.1   gdamore 		sc->sc_ports[1].rp_tmds_type = RADEON_TMDS_EXT;
   1522      1.1   gdamore 	}
   1523      1.1   gdamore 
   1524      1.1   gdamore 	/*
   1525      1.1   gdamore 	 * Fixup for RS300/RS350/RS400 chips, that lack a primary DAC.
   1526      1.1   gdamore 	 * these chips should use TVDAC for the VGA port.
   1527      1.1   gdamore 	 */
   1528      1.1   gdamore 	if (HAS_SDAC(sc)) {
   1529      1.1   gdamore 		if (sc->sc_ports[0].rp_conn_type == RADEON_CONN_CRT) {
   1530      1.1   gdamore 			sc->sc_ports[0].rp_dac_type = RADEON_DAC_TVDAC;
   1531      1.1   gdamore 			sc->sc_ports[1].rp_dac_type = RADEON_DAC_PRIMARY;
   1532      1.1   gdamore 		} else {
   1533      1.1   gdamore 			sc->sc_ports[1].rp_dac_type = RADEON_DAC_TVDAC;
   1534      1.1   gdamore 			sc->sc_ports[0].rp_dac_type = RADEON_DAC_PRIMARY;
   1535      1.1   gdamore 		}
   1536      1.1   gdamore 	} else if (!HAS_CRTC2(sc)) {
   1537      1.1   gdamore 		sc->sc_ports[0].rp_dac_type = RADEON_DAC_PRIMARY;
   1538      1.1   gdamore 	}
   1539      1.1   gdamore 
   1540      1.1   gdamore 	for (i = 0; i < 2; i++) {
   1541      1.1   gdamore 		char	edid[128];
   1542      1.1   gdamore 		uint8_t	ddc;
   1543      1.1   gdamore 		struct edid_info *eip = &sc->sc_ports[i].rp_edid;
   1544  1.7.2.3     pavel 		prop_data_t edid_data;
   1545      1.1   gdamore 
   1546      1.1   gdamore 		DPRINTF(("Port #%d:\n", i));
   1547      1.1   gdamore 		DPRINTF(("    conn = %d\n", sc->sc_ports[i].rp_conn_type));
   1548      1.1   gdamore 		DPRINTF(("    ddc = %d\n", sc->sc_ports[i].rp_ddc_type));
   1549      1.1   gdamore 		DPRINTF(("    dac = %d\n", sc->sc_ports[i].rp_dac_type));
   1550      1.1   gdamore 		DPRINTF(("    tmds = %d\n", sc->sc_ports[i].rp_tmds_type));
   1551      1.1   gdamore 
   1552      1.1   gdamore 		sc->sc_ports[i].rp_edid_valid = 0;
   1553  1.7.2.3     pavel 		/* first look for static EDID data */
   1554  1.7.2.3     pavel 		if ((edid_data = prop_dictionary_get(device_properties(
   1555  1.7.2.3     pavel 		    &sc->sc_dev), "EDID")) != NULL) {
   1556  1.7.2.3     pavel 
   1557  1.7.2.3     pavel 			aprint_normal("%s: using static EDID\n",
   1558  1.7.2.3     pavel 			    sc->sc_dev.dv_xname);
   1559  1.7.2.3     pavel 			memcpy(edid, prop_data_data_nocopy(edid_data), 128);
   1560  1.7.2.3     pavel 			if (edid_parse(edid, eip) == 0) {
   1561  1.7.2.3     pavel 
   1562      1.1   gdamore 				sc->sc_ports[i].rp_edid_valid = 1;
   1563      1.1   gdamore 				edid_print(eip);
   1564      1.1   gdamore 			}
   1565      1.1   gdamore 		}
   1566  1.7.2.3     pavel 		/* if we didn't find any we'll try to talk to the monitor */
   1567  1.7.2.3     pavel 		if (sc->sc_ports[i].rp_edid_valid != 1) {
   1568  1.7.2.3     pavel 
   1569  1.7.2.3     pavel 			ddc = sc->sc_ports[i].rp_ddc_type;
   1570  1.7.2.3     pavel 			if (ddc != RADEON_DDC_NONE) {
   1571  1.7.2.3     pavel 				if ((radeonfb_i2c_read_edid(sc, ddc, edid)
   1572  1.7.2.3     pavel 				    == 0) && (edid_parse(edid, eip) == 0)) {
   1573  1.7.2.3     pavel 
   1574  1.7.2.3     pavel 					sc->sc_ports[i].rp_edid_valid = 1;
   1575  1.7.2.3     pavel 					edid_print(eip);
   1576  1.7.2.3     pavel 				}
   1577  1.7.2.3     pavel 			}
   1578  1.7.2.3     pavel 		}
   1579      1.1   gdamore 	}
   1580      1.1   gdamore 
   1581      1.1   gdamore 	return found;
   1582      1.1   gdamore }
   1583      1.1   gdamore 
   1584      1.1   gdamore int
   1585      1.1   gdamore radeonfb_gettmds(struct radeonfb_softc *sc)
   1586      1.1   gdamore {
   1587      1.1   gdamore 	int	i;
   1588      1.1   gdamore 
   1589      1.1   gdamore 	if (!sc->sc_biossz) {
   1590      1.1   gdamore 		goto nobios;
   1591      1.1   gdamore 	}
   1592      1.1   gdamore 
   1593      1.1   gdamore 	if (IS_ATOM(sc)) {
   1594      1.1   gdamore 		/* XXX: not done yet */
   1595      1.1   gdamore 	} else {
   1596      1.1   gdamore 		uint16_t	ptr;
   1597      1.1   gdamore 		int		n;
   1598      1.1   gdamore 
   1599      1.1   gdamore 		ptr = GETBIOS16(sc, 0x48);
   1600      1.1   gdamore 		ptr = GETBIOS16(sc, ptr + 0x34);
   1601      1.1   gdamore 		DPRINTF(("DFP table revision %d\n", GETBIOS8(sc, ptr)));
   1602  1.7.2.2    bouyer 		if (GETBIOS8(sc, ptr) == 3) {
   1603      1.1   gdamore 			/* revision three table */
   1604      1.1   gdamore 			n = GETBIOS8(sc, ptr + 5) + 1;
   1605      1.1   gdamore 			n = min(n, 4);
   1606      1.1   gdamore 
   1607      1.1   gdamore 			memset(sc->sc_tmds_pll, 0, sizeof (sc->sc_tmds_pll));
   1608      1.1   gdamore 			for (i = 0; i < n; i++) {
   1609      1.1   gdamore 				sc->sc_tmds_pll[i].rtp_pll = GETBIOS32(sc,
   1610      1.1   gdamore 				    ptr + i * 10 + 8);
   1611      1.1   gdamore 				sc->sc_tmds_pll[i].rtp_freq = GETBIOS16(sc,
   1612      1.1   gdamore 				    ptr + i * 10 + 0x10);
   1613      1.1   gdamore 				DPRINTF(("TMDS_PLL dot clock %d pll %x\n",
   1614      1.1   gdamore 					    sc->sc_tmds_pll[i].rtp_freq,
   1615      1.1   gdamore 					    sc->sc_tmds_pll[i].rtp_pll));
   1616      1.1   gdamore 			}
   1617      1.1   gdamore 			return 0;
   1618      1.1   gdamore 		}
   1619      1.1   gdamore 	}
   1620      1.1   gdamore 
   1621      1.1   gdamore nobios:
   1622      1.1   gdamore 	DPRINTF(("no suitable DFP table present\n"));
   1623      1.1   gdamore 	for (i = 0;
   1624      1.1   gdamore 	     i < sizeof (radeonfb_tmds_pll) / sizeof (radeonfb_tmds_pll[0]);
   1625      1.1   gdamore 	     i++) {
   1626      1.1   gdamore 		int	j;
   1627      1.1   gdamore 
   1628      1.1   gdamore 		if (radeonfb_tmds_pll[i].family != sc->sc_family)
   1629      1.1   gdamore 			continue;
   1630      1.1   gdamore 
   1631      1.1   gdamore 		for (j = 0; j < 4; j++) {
   1632      1.1   gdamore 			sc->sc_tmds_pll[j] = radeonfb_tmds_pll[i].plls[j];
   1633      1.1   gdamore 			DPRINTF(("TMDS_PLL dot clock %d pll %x\n",
   1634      1.1   gdamore 				    sc->sc_tmds_pll[j].rtp_freq,
   1635      1.1   gdamore 				    sc->sc_tmds_pll[j].rtp_pll));
   1636      1.1   gdamore 		}
   1637      1.1   gdamore 		return 0;
   1638      1.1   gdamore 	}
   1639      1.1   gdamore 
   1640      1.1   gdamore 	return -1;
   1641      1.1   gdamore }
   1642      1.1   gdamore 
   1643      1.1   gdamore const struct videomode *
   1644      1.1   gdamore radeonfb_modelookup(const char *name)
   1645      1.1   gdamore {
   1646      1.1   gdamore 	int	i;
   1647      1.1   gdamore 
   1648      1.1   gdamore 	for (i = 0; i < videomode_count; i++)
   1649      1.1   gdamore 		if (!strcmp(name, videomode_list[i].name))
   1650      1.1   gdamore 			return &videomode_list[i];
   1651      1.1   gdamore 
   1652      1.1   gdamore 	return NULL;
   1653      1.1   gdamore }
   1654      1.1   gdamore 
   1655      1.1   gdamore void
   1656      1.1   gdamore radeonfb_pllwriteupdate(struct radeonfb_softc *sc, int crtc)
   1657      1.1   gdamore {
   1658      1.1   gdamore 	if (crtc) {
   1659      1.1   gdamore 		while (GETPLL(sc, RADEON_P2PLL_REF_DIV) &
   1660      1.1   gdamore 		    RADEON_P2PLL_ATOMIC_UPDATE_R);
   1661      1.1   gdamore 		SETPLL(sc, RADEON_P2PLL_REF_DIV, RADEON_P2PLL_ATOMIC_UPDATE_W);
   1662      1.1   gdamore 	} else {
   1663      1.1   gdamore 		while (GETPLL(sc, RADEON_PPLL_REF_DIV) &
   1664      1.1   gdamore 		    RADEON_PPLL_ATOMIC_UPDATE_R);
   1665      1.1   gdamore 		SETPLL(sc, RADEON_PPLL_REF_DIV, RADEON_PPLL_ATOMIC_UPDATE_W);
   1666      1.1   gdamore 	}
   1667      1.1   gdamore }
   1668      1.1   gdamore 
   1669      1.1   gdamore void
   1670      1.1   gdamore radeonfb_pllwaitatomicread(struct radeonfb_softc *sc, int crtc)
   1671      1.1   gdamore {
   1672      1.1   gdamore 	int	i;
   1673      1.1   gdamore 
   1674      1.1   gdamore 	for (i = 10000; i; i--) {
   1675      1.1   gdamore 		if (crtc) {
   1676      1.1   gdamore 			if (GETPLL(sc, RADEON_P2PLL_REF_DIV) &
   1677      1.1   gdamore 			    RADEON_P2PLL_ATOMIC_UPDATE_R)
   1678      1.1   gdamore 				break;
   1679      1.1   gdamore 		} else {
   1680      1.1   gdamore 			if (GETPLL(sc, RADEON_PPLL_REF_DIV) &
   1681      1.1   gdamore 			    RADEON_PPLL_ATOMIC_UPDATE_R)
   1682      1.1   gdamore 				break;
   1683      1.1   gdamore 		}
   1684      1.1   gdamore 	}
   1685      1.1   gdamore }
   1686      1.1   gdamore 
   1687      1.1   gdamore void
   1688      1.1   gdamore radeonfb_program_vclk(struct radeonfb_softc *sc, int dotclock, int crtc)
   1689      1.1   gdamore {
   1690      1.2  macallan 	uint32_t	pbit = 0;
   1691      1.2  macallan 	uint32_t	feed = 0;
   1692      1.1   gdamore 	uint32_t	data;
   1693      1.1   gdamore #if 1
   1694      1.1   gdamore 	int		i;
   1695      1.1   gdamore #endif
   1696      1.1   gdamore 
   1697      1.1   gdamore 	radeonfb_calc_dividers(sc, dotclock, &pbit, &feed);
   1698      1.1   gdamore 
   1699      1.1   gdamore 	if (crtc == 0) {
   1700      1.1   gdamore 
   1701      1.1   gdamore 		/* XXXX: mobility workaround missing */
   1702      1.1   gdamore 		/* XXXX: R300 stuff missing */
   1703      1.1   gdamore 
   1704      1.1   gdamore 		PATCHPLL(sc, RADEON_VCLK_ECP_CNTL,
   1705      1.1   gdamore 		    RADEON_VCLK_SRC_SEL_CPUCLK,
   1706      1.1   gdamore 		    ~RADEON_VCLK_SRC_SEL_MASK);
   1707  1.7.2.2    bouyer 
   1708      1.1   gdamore 		/* put vclk into reset, use atomic updates */
   1709      1.1   gdamore 		SETPLL(sc, RADEON_PPLL_CNTL,
   1710      1.1   gdamore 		    RADEON_PPLL_REFCLK_SEL |
   1711      1.1   gdamore 		    RADEON_PPLL_FBCLK_SEL |
   1712      1.1   gdamore 		    RADEON_PPLL_RESET |
   1713      1.1   gdamore 		    RADEON_PPLL_ATOMIC_UPDATE_EN |
   1714      1.1   gdamore 		    RADEON_PPLL_VGA_ATOMIC_UPDATE_EN);
   1715      1.1   gdamore 
   1716      1.1   gdamore 		/* select clock 3 */
   1717      1.1   gdamore #if 0
   1718      1.1   gdamore 		PATCH32(sc, RADEON_CLOCK_CNTL_INDEX, RADEON_PLL_DIV_SEL,
   1719      1.1   gdamore 		    ~RADEON_PLL_DIV_SEL);
   1720      1.1   gdamore #else
   1721      1.1   gdamore 		PATCH32(sc, RADEON_CLOCK_CNTL_INDEX, 0,
   1722      1.1   gdamore 		    ~RADEON_PLL_DIV_SEL);
   1723      1.1   gdamore #endif
   1724  1.7.2.2    bouyer 
   1725      1.1   gdamore 		/* XXX: R300 family -- program divider differently? */
   1726      1.1   gdamore 
   1727      1.1   gdamore 		/* program reference divider */
   1728      1.1   gdamore 		PATCHPLL(sc, RADEON_PPLL_REF_DIV, sc->sc_refdiv,
   1729      1.1   gdamore 		    ~RADEON_PPLL_REF_DIV_MASK);
   1730      1.1   gdamore 		PRINTPLL(RADEON_PPLL_REF_DIV);
   1731      1.1   gdamore 
   1732      1.1   gdamore #if 0
   1733      1.1   gdamore 		data = GETPLL(sc, RADEON_PPLL_DIV_3);
   1734      1.1   gdamore 		data &= ~(RADEON_PPLL_FB3_DIV_MASK |
   1735      1.1   gdamore 		    RADEON_PPLL_POST3_DIV_MASK);
   1736      1.1   gdamore 		data |= pbit;
   1737      1.1   gdamore 		data |= (feed & RADEON_PPLL_FB3_DIV_MASK);
   1738      1.1   gdamore 		PUTPLL(sc, RADEON_PPLL_DIV_3, data);
   1739      1.1   gdamore #else
   1740      1.1   gdamore 		for (i = 0; i < 4; i++) {
   1741      1.1   gdamore 		}
   1742      1.1   gdamore #endif
   1743      1.1   gdamore 
   1744      1.1   gdamore 		/* use the atomic update */
   1745      1.1   gdamore 		radeonfb_pllwriteupdate(sc, crtc);
   1746      1.1   gdamore 
   1747      1.1   gdamore 		/* and wait for it to complete */
   1748      1.1   gdamore 		radeonfb_pllwaitatomicread(sc, crtc);
   1749      1.1   gdamore 
   1750      1.1   gdamore 		/* program HTOTAL (why?) */
   1751      1.1   gdamore 		PUTPLL(sc, RADEON_HTOTAL_CNTL, 0);
   1752      1.1   gdamore 
   1753      1.1   gdamore 		/* drop reset */
   1754      1.1   gdamore 		CLRPLL(sc, RADEON_PPLL_CNTL,
   1755      1.1   gdamore 		    RADEON_PPLL_RESET | RADEON_PPLL_SLEEP |
   1756      1.1   gdamore 		    RADEON_PPLL_ATOMIC_UPDATE_EN |
   1757      1.1   gdamore 		    RADEON_PPLL_VGA_ATOMIC_UPDATE_EN);
   1758      1.1   gdamore 
   1759      1.1   gdamore 		PRINTPLL(RADEON_PPLL_CNTL);
   1760      1.1   gdamore 
   1761      1.1   gdamore 		/* give clock time to lock */
   1762      1.1   gdamore 		delay(50000);
   1763      1.1   gdamore 
   1764      1.1   gdamore 		PATCHPLL(sc, RADEON_VCLK_ECP_CNTL,
   1765      1.1   gdamore 		    RADEON_VCLK_SRC_SEL_PPLLCLK,
   1766      1.1   gdamore 		    ~RADEON_VCLK_SRC_SEL_MASK);
   1767      1.1   gdamore 
   1768      1.1   gdamore 	} else {
   1769      1.1   gdamore 
   1770      1.1   gdamore 		PATCHPLL(sc, RADEON_PIXCLKS_CNTL,
   1771      1.1   gdamore 		    RADEON_PIX2CLK_SRC_SEL_CPUCLK,
   1772      1.1   gdamore 		    ~RADEON_PIX2CLK_SRC_SEL_MASK);
   1773      1.1   gdamore 
   1774      1.1   gdamore 		/* put vclk into reset, use atomic updates */
   1775      1.1   gdamore 		SETPLL(sc, RADEON_P2PLL_CNTL,
   1776      1.1   gdamore 		    RADEON_P2PLL_RESET |
   1777      1.1   gdamore 		    RADEON_P2PLL_ATOMIC_UPDATE_EN |
   1778      1.1   gdamore 		    RADEON_P2PLL_VGA_ATOMIC_UPDATE_EN);
   1779      1.1   gdamore 
   1780      1.1   gdamore 		/* XXX: R300 family -- program divider differently? */
   1781      1.1   gdamore 
   1782      1.1   gdamore 		/* program reference divider */
   1783      1.1   gdamore 		PATCHPLL(sc, RADEON_P2PLL_REF_DIV, sc->sc_refdiv,
   1784      1.1   gdamore 		    ~RADEON_P2PLL_REF_DIV_MASK);
   1785      1.1   gdamore 
   1786      1.1   gdamore 		/* program feedback and post dividers */
   1787      1.1   gdamore 		data = GETPLL(sc, RADEON_P2PLL_DIV_0);
   1788      1.1   gdamore 		data &= ~(RADEON_P2PLL_FB0_DIV_MASK |
   1789      1.1   gdamore 		    RADEON_P2PLL_POST0_DIV_MASK);
   1790      1.1   gdamore 		data |= pbit;
   1791      1.1   gdamore 		data |= (feed & RADEON_P2PLL_FB0_DIV_MASK);
   1792      1.1   gdamore 		PUTPLL(sc, RADEON_P2PLL_DIV_0, data);
   1793      1.1   gdamore 
   1794      1.1   gdamore 		/* use the atomic update */
   1795      1.1   gdamore 		radeonfb_pllwriteupdate(sc, crtc);
   1796      1.1   gdamore 
   1797      1.1   gdamore 		/* and wait for it to complete */
   1798      1.1   gdamore 		radeonfb_pllwaitatomicread(sc, crtc);
   1799      1.1   gdamore 
   1800      1.1   gdamore 		/* program HTOTAL (why?) */
   1801      1.1   gdamore 		PUTPLL(sc, RADEON_HTOTAL2_CNTL, 0);
   1802      1.1   gdamore 
   1803      1.1   gdamore 		/* drop reset */
   1804      1.1   gdamore 		CLRPLL(sc, RADEON_P2PLL_CNTL,
   1805      1.1   gdamore 		    RADEON_P2PLL_RESET | RADEON_P2PLL_SLEEP |
   1806      1.1   gdamore 		    RADEON_P2PLL_ATOMIC_UPDATE_EN |
   1807      1.1   gdamore 		    RADEON_P2PLL_VGA_ATOMIC_UPDATE_EN);
   1808      1.1   gdamore 
   1809      1.1   gdamore 		/* allow time for clock to lock */
   1810      1.1   gdamore 		delay(50000);
   1811      1.1   gdamore 
   1812      1.1   gdamore 		PATCHPLL(sc, RADEON_PIXCLKS_CNTL,
   1813      1.1   gdamore 		    RADEON_PIX2CLK_SRC_SEL_P2PLLCLK,
   1814      1.1   gdamore 		    ~RADEON_PIX2CLK_SRC_SEL_MASK);
   1815      1.1   gdamore 	}
   1816      1.1   gdamore 	PRINTREG(RADEON_CRTC_MORE_CNTL);
   1817      1.1   gdamore }
   1818      1.1   gdamore 
   1819      1.1   gdamore void
   1820      1.1   gdamore radeonfb_modeswitch(struct radeonfb_display *dp)
   1821      1.1   gdamore {
   1822      1.1   gdamore 	struct radeonfb_softc	*sc = dp->rd_softc;
   1823      1.1   gdamore 	int			i;
   1824      1.1   gdamore 
   1825      1.1   gdamore 	/* blank the display while we switch modes */
   1826      1.2  macallan 	//radeonfb_blank(dp, 1);
   1827      1.1   gdamore 
   1828      1.1   gdamore #if 0
   1829      1.1   gdamore 	SET32(sc, RADEON_CRTC_EXT_CNTL,
   1830      1.1   gdamore 	    RADEON_CRTC_VSYNC_DIS | RADEON_CRTC_HSYNC_DIS |
   1831      1.1   gdamore 	    RADEON_CRTC_DISPLAY_DIS /* | RADEON_CRTC_DISP_REQ_EN_B */);
   1832      1.1   gdamore #endif
   1833      1.1   gdamore 
   1834      1.1   gdamore 	/* these registers might get in the way... */
   1835      1.1   gdamore 	PUT32(sc, RADEON_OVR_CLR, 0);
   1836      1.1   gdamore 	PUT32(sc, RADEON_OVR_WID_LEFT_RIGHT, 0);
   1837      1.1   gdamore 	PUT32(sc, RADEON_OVR_WID_TOP_BOTTOM, 0);
   1838      1.1   gdamore 	PUT32(sc, RADEON_OV0_SCALE_CNTL, 0);
   1839      1.1   gdamore 	PUT32(sc, RADEON_SUBPIC_CNTL, 0);
   1840      1.1   gdamore 	PUT32(sc, RADEON_VIPH_CONTROL, 0);
   1841      1.1   gdamore 	PUT32(sc, RADEON_I2C_CNTL_1, 0);
   1842      1.1   gdamore 	PUT32(sc, RADEON_GEN_INT_CNTL, 0);
   1843      1.1   gdamore 	PUT32(sc, RADEON_CAP0_TRIG_CNTL, 0);
   1844      1.1   gdamore 	PUT32(sc, RADEON_CAP1_TRIG_CNTL, 0);
   1845      1.1   gdamore 	PUT32(sc, RADEON_SURFACE_CNTL, 0);
   1846      1.1   gdamore 
   1847      1.1   gdamore 	for (i = 0; i < dp->rd_ncrtcs; i++)
   1848      1.1   gdamore 		radeonfb_setcrtc(dp, i);
   1849      1.1   gdamore 
   1850      1.1   gdamore 	/* activate the display */
   1851      1.2  macallan 	//radeonfb_blank(dp, 0);
   1852      1.1   gdamore }
   1853      1.1   gdamore 
   1854      1.1   gdamore void
   1855      1.1   gdamore radeonfb_setcrtc(struct radeonfb_display *dp, int index)
   1856      1.1   gdamore {
   1857      1.1   gdamore 	int			crtc;
   1858      1.1   gdamore 	struct videomode	*mode;
   1859      1.1   gdamore 	struct radeonfb_softc	*sc;
   1860      1.1   gdamore 	struct radeonfb_crtc	*cp;
   1861      1.1   gdamore 	uint32_t		v;
   1862      1.1   gdamore 	uint32_t		gencntl;
   1863      1.1   gdamore 	uint32_t		htotaldisp;
   1864      1.1   gdamore 	uint32_t		hsyncstrt;
   1865      1.1   gdamore 	uint32_t		vtotaldisp;
   1866      1.1   gdamore 	uint32_t		vsyncstrt;
   1867      1.1   gdamore 	uint32_t		fphsyncstrt;
   1868      1.1   gdamore 	uint32_t		fpvsyncstrt;
   1869      1.1   gdamore 	uint32_t		fphtotaldisp;
   1870      1.1   gdamore 	uint32_t		fpvtotaldisp;
   1871      1.1   gdamore 	uint32_t		pitch;
   1872      1.1   gdamore 
   1873      1.1   gdamore 	sc = dp->rd_softc;
   1874      1.1   gdamore 	cp = &dp->rd_crtcs[index];
   1875      1.1   gdamore 	crtc = cp->rc_number;
   1876      1.1   gdamore 	mode = &cp->rc_videomode;
   1877      1.1   gdamore 
   1878      1.2  macallan #if 1
   1879      1.1   gdamore 	pitch = (((dp->rd_virtx * dp->rd_bpp) + ((dp->rd_bpp * 8) - 1)) /
   1880      1.1   gdamore 	    (dp->rd_bpp * 8));
   1881      1.1   gdamore #else
   1882      1.1   gdamore 	pitch = (((sc->sc_maxx * sc->sc_maxbpp) + ((sc->sc_maxbpp * 8) - 1)) /
   1883      1.1   gdamore 	    (sc->sc_maxbpp * 8));
   1884      1.1   gdamore #endif
   1885      1.1   gdamore 	//pitch = pitch | (pitch << 16);
   1886      1.1   gdamore 
   1887      1.1   gdamore 	switch (crtc) {
   1888      1.1   gdamore 	case 0:
   1889      1.1   gdamore 		gencntl = RADEON_CRTC_GEN_CNTL;
   1890      1.1   gdamore 		htotaldisp = RADEON_CRTC_H_TOTAL_DISP;
   1891      1.1   gdamore 		hsyncstrt = RADEON_CRTC_H_SYNC_STRT_WID;
   1892      1.1   gdamore 		vtotaldisp = RADEON_CRTC_V_TOTAL_DISP;
   1893      1.1   gdamore 		vsyncstrt = RADEON_CRTC_V_SYNC_STRT_WID;
   1894      1.1   gdamore 		fpvsyncstrt = RADEON_FP_V_SYNC_STRT_WID;
   1895      1.1   gdamore 		fphsyncstrt = RADEON_FP_H_SYNC_STRT_WID;
   1896      1.1   gdamore 		fpvtotaldisp = RADEON_FP_CRTC_V_TOTAL_DISP;
   1897      1.1   gdamore 		fphtotaldisp = RADEON_FP_CRTC_H_TOTAL_DISP;
   1898      1.1   gdamore 		break;
   1899      1.1   gdamore 	case 1:
   1900      1.1   gdamore 		gencntl = RADEON_CRTC2_GEN_CNTL;
   1901      1.1   gdamore 		htotaldisp = RADEON_CRTC2_H_TOTAL_DISP;
   1902      1.1   gdamore 		hsyncstrt = RADEON_CRTC2_H_SYNC_STRT_WID;
   1903      1.1   gdamore 		vtotaldisp = RADEON_CRTC2_V_TOTAL_DISP;
   1904      1.1   gdamore 		vsyncstrt = RADEON_CRTC2_V_SYNC_STRT_WID;
   1905      1.1   gdamore 		fpvsyncstrt = RADEON_FP_V2_SYNC_STRT_WID;
   1906      1.1   gdamore 		fphsyncstrt = RADEON_FP_H2_SYNC_STRT_WID;
   1907      1.1   gdamore 		fpvtotaldisp = RADEON_FP_CRTC2_V_TOTAL_DISP;
   1908      1.1   gdamore 		fphtotaldisp = RADEON_FP_CRTC2_H_TOTAL_DISP;
   1909      1.1   gdamore 		break;
   1910      1.1   gdamore 	default:
   1911      1.1   gdamore 		panic("Bad CRTC!");
   1912      1.1   gdamore 		break;
   1913      1.1   gdamore 	}
   1914      1.1   gdamore 
   1915      1.1   gdamore 	/*
   1916      1.1   gdamore 	 * CRTC_GEN_CNTL - depth, accelerator mode, etc.
   1917      1.1   gdamore 	 */
   1918      1.1   gdamore 	/* only bother with 32bpp and 8bpp */
   1919      1.1   gdamore 	v = dp->rd_format << RADEON_CRTC_PIX_WIDTH_SHIFT;
   1920      1.1   gdamore 
   1921      1.1   gdamore 	if (crtc == 1) {
   1922      1.1   gdamore 		v |= RADEON_CRTC2_CRT2_ON | RADEON_CRTC2_EN;
   1923      1.1   gdamore 	} else {
   1924      1.1   gdamore 		v |= RADEON_CRTC_EXT_DISP_EN | RADEON_CRTC_EN;
   1925      1.1   gdamore 	}
   1926      1.1   gdamore 
   1927      1.1   gdamore 	if (mode->flags & VID_DBLSCAN)
   1928      1.1   gdamore 		v |= RADEON_CRTC2_DBL_SCAN_EN;
   1929      1.1   gdamore 
   1930      1.1   gdamore 	if (mode->flags & VID_INTERLACE)
   1931      1.1   gdamore 		v |= RADEON_CRTC2_INTERLACE_EN;
   1932      1.1   gdamore 
   1933      1.1   gdamore 	if (mode->flags & VID_CSYNC) {
   1934      1.1   gdamore 		v |= RADEON_CRTC2_CSYNC_EN;
   1935      1.1   gdamore 		if (crtc == 1)
   1936      1.1   gdamore 			v |= RADEON_CRTC2_VSYNC_TRISTAT;
   1937      1.1   gdamore 	}
   1938  1.7.2.2    bouyer 
   1939      1.1   gdamore 	PUT32(sc, gencntl, v);
   1940      1.1   gdamore 	DPRINTF(("CRTC%s_GEN_CNTL = %08x\n", crtc ? "2" : "", v));
   1941      1.1   gdamore 
   1942      1.1   gdamore 	/*
   1943      1.1   gdamore 	 * CRTC_EXT_CNTL - preserve disable flags, set ATI linear and EXT_CNT
   1944      1.1   gdamore 	 */
   1945      1.1   gdamore 	v = GET32(sc, RADEON_CRTC_EXT_CNTL);
   1946      1.1   gdamore 	if (crtc == 0) {
   1947      1.1   gdamore 		v &= (RADEON_CRTC_VSYNC_DIS | RADEON_CRTC_HSYNC_DIS |
   1948      1.1   gdamore 		    RADEON_CRTC_DISPLAY_DIS);
   1949      1.1   gdamore 		v |= RADEON_XCRT_CNT_EN | RADEON_VGA_ATI_LINEAR;
   1950      1.1   gdamore 		if (mode->flags & VID_CSYNC)
   1951      1.1   gdamore 			v |= RADEON_CRTC_VSYNC_TRISTAT;
   1952      1.1   gdamore 	}
   1953      1.1   gdamore 	/* unconditional turn on CRT, in case first CRTC is DFP */
   1954      1.1   gdamore 	v |= RADEON_CRTC_CRT_ON;
   1955      1.1   gdamore 	PUT32(sc, RADEON_CRTC_EXT_CNTL, v);
   1956      1.1   gdamore 	PRINTREG(RADEON_CRTC_EXT_CNTL);
   1957      1.1   gdamore 
   1958      1.1   gdamore 	/*
   1959      1.1   gdamore 	 * H_TOTAL_DISP
   1960      1.1   gdamore 	 */
   1961      1.1   gdamore 	v = ((mode->hdisplay / 8) - 1) << 16;
   1962      1.1   gdamore 	v |= (mode->htotal / 8) - 1;
   1963      1.1   gdamore 	PUT32(sc, htotaldisp, v);
   1964      1.1   gdamore 	DPRINTF(("CRTC%s_H_TOTAL_DISP = %08x\n", crtc ? "2" : "", v));
   1965      1.1   gdamore 	PUT32(sc, fphtotaldisp, v);
   1966      1.1   gdamore 	DPRINTF(("FP_H%s_TOTAL_DISP = %08x\n", crtc ? "2" : "", v));
   1967      1.1   gdamore 
   1968      1.1   gdamore 	/*
   1969      1.1   gdamore 	 * H_SYNC_STRT_WID
   1970      1.1   gdamore 	 */
   1971      1.1   gdamore 	v = (((mode->hsync_end - mode->hsync_start) / 8) << 16);
   1972      1.1   gdamore 	v |= mode->hsync_start;
   1973      1.1   gdamore 	if (mode->flags & VID_NHSYNC)
   1974      1.1   gdamore 		v |= RADEON_CRTC_H_SYNC_POL;
   1975      1.1   gdamore 	PUT32(sc, hsyncstrt, v);
   1976      1.1   gdamore 	DPRINTF(("CRTC%s_H_SYNC_STRT_WID = %08x\n", crtc ? "2" : "", v));
   1977      1.1   gdamore 	PUT32(sc, fphsyncstrt, v);
   1978      1.1   gdamore 	DPRINTF(("FP_H%s_SYNC_STRT_WID = %08x\n", crtc ? "2" : "", v));
   1979      1.1   gdamore 
   1980      1.1   gdamore 	/*
   1981      1.1   gdamore 	 * V_TOTAL_DISP
   1982      1.1   gdamore 	 */
   1983      1.1   gdamore 	v = ((mode->vdisplay - 1) << 16);
   1984      1.1   gdamore 	v |= (mode->vtotal - 1);
   1985      1.1   gdamore 	PUT32(sc, vtotaldisp, v);
   1986      1.1   gdamore 	DPRINTF(("CRTC%s_V_TOTAL_DISP = %08x\n", crtc ? "2" : "", v));
   1987      1.1   gdamore 	PUT32(sc, fpvtotaldisp, v);
   1988      1.1   gdamore 	DPRINTF(("FP_V%s_TOTAL_DISP = %08x\n", crtc ? "2" : "", v));
   1989      1.1   gdamore 
   1990      1.1   gdamore 	/*
   1991      1.1   gdamore 	 * V_SYNC_STRT_WID
   1992      1.1   gdamore 	 */
   1993      1.1   gdamore 	v = ((mode->vsync_end - mode->vsync_start) << 16);
   1994      1.1   gdamore 	v |= (mode->vsync_start - 1);
   1995      1.1   gdamore 	if (mode->flags & VID_NVSYNC)
   1996      1.1   gdamore 		v |= RADEON_CRTC_V_SYNC_POL;
   1997      1.1   gdamore 	PUT32(sc, vsyncstrt, v);
   1998      1.1   gdamore 	DPRINTF(("CRTC%s_V_SYNC_STRT_WID = %08x\n", crtc ? "2" : "", v));
   1999      1.1   gdamore 	PUT32(sc, fpvsyncstrt, v);
   2000      1.1   gdamore 	DPRINTF(("FP_V%s_SYNC_STRT_WID = %08x\n", crtc ? "2" : "", v));
   2001      1.1   gdamore 
   2002      1.1   gdamore 	radeonfb_program_vclk(sc, mode->dot_clock, crtc);
   2003      1.1   gdamore 
   2004      1.1   gdamore 	switch (crtc) {
   2005      1.1   gdamore 	case 0:
   2006      1.1   gdamore 		PUT32(sc, RADEON_CRTC_OFFSET, 0);
   2007      1.1   gdamore 		PUT32(sc, RADEON_CRTC_OFFSET_CNTL, 0);
   2008      1.1   gdamore 		PUT32(sc, RADEON_CRTC_PITCH, pitch);
   2009      1.1   gdamore 		CLR32(sc, RADEON_DISP_MERGE_CNTL, RADEON_DISP_RGB_OFFSET_EN);
   2010      1.1   gdamore 
   2011      1.1   gdamore 		CLR32(sc, RADEON_CRTC_EXT_CNTL,
   2012      1.1   gdamore 		    RADEON_CRTC_VSYNC_DIS | RADEON_CRTC_HSYNC_DIS |
   2013      1.1   gdamore 		    RADEON_CRTC_DISPLAY_DIS /* | RADEON_CRTC_DISP_REQ_EN_B */);
   2014      1.1   gdamore 		CLR32(sc, RADEON_CRTC_GEN_CNTL, RADEON_CRTC_DISP_REQ_EN_B);
   2015      1.1   gdamore 		PRINTREG(RADEON_CRTC_EXT_CNTL);
   2016      1.1   gdamore 		PRINTREG(RADEON_CRTC_GEN_CNTL);
   2017      1.1   gdamore 		PRINTREG(RADEON_CLOCK_CNTL_INDEX);
   2018      1.1   gdamore 		break;
   2019      1.1   gdamore 
   2020      1.1   gdamore 	case 1:
   2021      1.1   gdamore 		PUT32(sc, RADEON_CRTC2_OFFSET, 0);
   2022      1.1   gdamore 		PUT32(sc, RADEON_CRTC2_OFFSET_CNTL, 0);
   2023      1.1   gdamore 		PUT32(sc, RADEON_CRTC2_PITCH, pitch);
   2024      1.1   gdamore 		CLR32(sc, RADEON_DISP2_MERGE_CNTL, RADEON_DISP2_RGB_OFFSET_EN);
   2025      1.1   gdamore 		CLR32(sc, RADEON_CRTC2_GEN_CNTL,
   2026      1.1   gdamore 		    RADEON_CRTC2_VSYNC_DIS |
   2027      1.1   gdamore 		    RADEON_CRTC2_HSYNC_DIS |
   2028  1.7.2.2    bouyer 		    RADEON_CRTC2_DISP_DIS | RADEON_CRTC2_DISP_REQ_EN_B);
   2029      1.1   gdamore 		PRINTREG(RADEON_CRTC2_GEN_CNTL);
   2030      1.1   gdamore 		break;
   2031      1.1   gdamore 	}
   2032      1.1   gdamore }
   2033      1.1   gdamore 
   2034      1.1   gdamore int
   2035      1.1   gdamore radeonfb_isblank(struct radeonfb_display *dp)
   2036      1.1   gdamore {
   2037      1.1   gdamore 	uint32_t	reg, mask;
   2038      1.1   gdamore 
   2039      1.1   gdamore 	if (dp->rd_crtcs[0].rc_number) {
   2040      1.1   gdamore 		reg = RADEON_CRTC2_GEN_CNTL;
   2041      1.1   gdamore 		mask = RADEON_CRTC2_DISP_DIS;
   2042      1.1   gdamore 	} else {
   2043      1.1   gdamore 		reg = RADEON_CRTC_EXT_CNTL;
   2044      1.1   gdamore 		mask = RADEON_CRTC_DISPLAY_DIS;
   2045      1.1   gdamore 	}
   2046      1.1   gdamore 	return ((GET32(dp->rd_softc, reg) & mask) ? 1 : 0);
   2047      1.1   gdamore }
   2048      1.1   gdamore 
   2049      1.1   gdamore void
   2050      1.1   gdamore radeonfb_blank(struct radeonfb_display *dp, int blank)
   2051      1.1   gdamore {
   2052      1.1   gdamore 	struct radeonfb_softc	*sc = dp->rd_softc;
   2053      1.1   gdamore 	uint32_t		reg, mask;
   2054      1.1   gdamore 	uint32_t		fpreg, fpval;
   2055      1.1   gdamore 	int			i;
   2056      1.1   gdamore 
   2057      1.1   gdamore 	for (i = 0; i < dp->rd_ncrtcs; i++) {
   2058      1.1   gdamore 
   2059      1.1   gdamore 		if (dp->rd_crtcs[i].rc_number) {
   2060      1.1   gdamore 			reg = RADEON_CRTC2_GEN_CNTL;
   2061      1.1   gdamore 			mask = RADEON_CRTC2_DISP_DIS;
   2062      1.1   gdamore 			fpreg = RADEON_FP2_GEN_CNTL;
   2063      1.1   gdamore 			fpval = RADEON_FP2_ON;
   2064      1.1   gdamore 		} else {
   2065      1.1   gdamore 			reg = RADEON_CRTC_EXT_CNTL;
   2066      1.1   gdamore 			mask = RADEON_CRTC_DISPLAY_DIS;
   2067      1.1   gdamore 			fpreg = RADEON_FP_GEN_CNTL;
   2068      1.1   gdamore 			fpval = RADEON_FP_FPON;
   2069      1.1   gdamore 		}
   2070  1.7.2.2    bouyer 
   2071      1.1   gdamore 		if (blank) {
   2072      1.1   gdamore 			SET32(sc, reg, mask);
   2073      1.1   gdamore 			CLR32(sc, fpreg, fpval);
   2074      1.1   gdamore 		} else {
   2075      1.1   gdamore 			CLR32(sc, reg, mask);
   2076      1.1   gdamore 			SET32(sc, fpreg, fpval);
   2077      1.1   gdamore 		}
   2078      1.1   gdamore 	}
   2079      1.1   gdamore 	PRINTREG(RADEON_FP_GEN_CNTL);
   2080      1.1   gdamore 	PRINTREG(RADEON_FP2_GEN_CNTL);
   2081      1.1   gdamore }
   2082      1.1   gdamore 
   2083      1.1   gdamore void
   2084      1.1   gdamore radeonfb_init_screen(void *cookie, struct vcons_screen *scr, int existing,
   2085      1.1   gdamore     long *defattr)
   2086      1.1   gdamore {
   2087      1.1   gdamore 	struct radeonfb_display *dp = cookie;
   2088      1.1   gdamore 	struct rasops_info *ri = &scr->scr_ri;
   2089      1.1   gdamore 
   2090      1.1   gdamore 	/* initialize font subsystem */
   2091      1.1   gdamore 	wsfont_init();
   2092      1.1   gdamore 
   2093      1.1   gdamore 	DPRINTF(("init screen called, existing %d\n", existing));
   2094      1.1   gdamore 
   2095      1.1   gdamore 	ri->ri_depth = dp->rd_bpp;
   2096      1.1   gdamore 	ri->ri_width = dp->rd_virtx;
   2097      1.1   gdamore 	ri->ri_height = dp->rd_virty;
   2098      1.1   gdamore 	ri->ri_stride = dp->rd_stride;
   2099      1.1   gdamore 	ri->ri_flg = RI_CENTER;
   2100      1.1   gdamore 	ri->ri_bits = (void *)dp->rd_fbptr;
   2101      1.1   gdamore 
   2102      1.1   gdamore 	/* XXX: 32 bpp only */
   2103      1.1   gdamore 	/* this is rgb in "big-endian order..." */
   2104      1.1   gdamore 	ri->ri_rnum = 8;
   2105      1.1   gdamore 	ri->ri_gnum = 8;
   2106      1.1   gdamore 	ri->ri_bnum = 8;
   2107      1.1   gdamore 	ri->ri_rpos = 16;
   2108      1.1   gdamore 	ri->ri_gpos = 8;
   2109      1.1   gdamore 	ri->ri_bpos = 0;
   2110      1.1   gdamore 
   2111      1.1   gdamore 	if (existing) {
   2112      1.1   gdamore 		ri->ri_flg |= RI_CLEAR;
   2113      1.1   gdamore 
   2114      1.1   gdamore 		/* start a modeswitch now */
   2115      1.1   gdamore 		radeonfb_modeswitch(dp);
   2116      1.1   gdamore 	}
   2117      1.1   gdamore 
   2118      1.1   gdamore 	/*
   2119      1.1   gdamore 	 * XXX: font selection should be based on properties, with some
   2120      1.1   gdamore 	 * normal/reasonable default.
   2121      1.1   gdamore 	 */
   2122      1.1   gdamore 	ri->ri_caps = WSSCREEN_WSCOLORS;
   2123      1.1   gdamore 
   2124      1.1   gdamore 	/* initialize and look for an initial font */
   2125      1.1   gdamore 	rasops_init(ri, dp->rd_virty/8, dp->rd_virtx/8);
   2126      1.1   gdamore 
   2127      1.2  macallan 	rasops_reconfig(ri, dp->rd_virty / ri->ri_font->fontheight,
   2128      1.2  macallan 		    dp->rd_virtx / ri->ri_font->fontwidth);
   2129      1.2  macallan 
   2130      1.1   gdamore 	/* enable acceleration */
   2131      1.1   gdamore 	ri->ri_ops.copyrows = radeonfb_copyrows;
   2132      1.1   gdamore 	ri->ri_ops.copycols = radeonfb_copycols;
   2133      1.1   gdamore 	ri->ri_ops.eraserows = radeonfb_eraserows;
   2134      1.1   gdamore 	ri->ri_ops.erasecols = radeonfb_erasecols;
   2135      1.2  macallan 	ri->ri_ops.allocattr = radeonfb_allocattr;
   2136      1.2  macallan 	ri->ri_ops.putchar = radeonfb_putchar;
   2137      1.1   gdamore 	ri->ri_ops.cursor = radeonfb_cursor;
   2138      1.1   gdamore }
   2139      1.1   gdamore 
   2140      1.1   gdamore void
   2141      1.1   gdamore radeonfb_set_fbloc(struct radeonfb_softc *sc)
   2142      1.1   gdamore {
   2143      1.1   gdamore 	uint32_t	gen, ext, gen2 = 0;
   2144      1.1   gdamore 	uint32_t	agploc, aperbase, apersize, mcfbloc;
   2145      1.1   gdamore 
   2146      1.1   gdamore 	gen = GET32(sc, RADEON_CRTC_GEN_CNTL);
   2147      1.1   gdamore 	ext = GET32(sc, RADEON_CRTC_EXT_CNTL);
   2148      1.1   gdamore 	agploc = GET32(sc, RADEON_MC_AGP_LOCATION);
   2149      1.1   gdamore 	aperbase = GET32(sc, RADEON_CONFIG_APER_0_BASE);
   2150      1.1   gdamore 	apersize = GET32(sc, RADEON_CONFIG_APER_SIZE);
   2151      1.1   gdamore 
   2152      1.1   gdamore 	PUT32(sc, RADEON_CRTC_GEN_CNTL, gen | RADEON_CRTC_DISP_REQ_EN_B);
   2153      1.1   gdamore 	PUT32(sc, RADEON_CRTC_EXT_CNTL, ext | RADEON_CRTC_DISPLAY_DIS);
   2154      1.1   gdamore 	//PUT32(sc, RADEON_CRTC_GEN_CNTL, gen | RADEON_CRTC_DISPLAY_DIS);
   2155      1.1   gdamore 	//PUT32(sc, RADEON_CRTC_EXT_CNTL, ext | RADEON_CRTC_DISP_REQ_EN_B);
   2156      1.1   gdamore 
   2157      1.1   gdamore 	if (HAS_CRTC2(sc)) {
   2158      1.1   gdamore 		gen2 = GET32(sc, RADEON_CRTC2_GEN_CNTL);
   2159  1.7.2.2    bouyer 		PUT32(sc, RADEON_CRTC2_GEN_CNTL,
   2160      1.1   gdamore 		    gen2 | RADEON_CRTC2_DISP_REQ_EN_B);
   2161      1.1   gdamore 	}
   2162      1.1   gdamore 
   2163      1.1   gdamore 	delay(100000);
   2164      1.1   gdamore 
   2165      1.1   gdamore 	mcfbloc = (aperbase >> 16) |
   2166      1.1   gdamore 	    ((aperbase + (apersize - 1)) & 0xffff0000);
   2167      1.1   gdamore 
   2168      1.1   gdamore 	sc->sc_aperbase = (mcfbloc & 0xffff) << 16;
   2169      1.1   gdamore 	sc->sc_memsz = apersize;
   2170      1.1   gdamore 
   2171      1.1   gdamore 	if (((agploc & 0xffff) << 16) !=
   2172      1.1   gdamore 	    ((mcfbloc & 0xffff0000U) + 0x10000)) {
   2173      1.1   gdamore 		agploc = mcfbloc & 0xffff0000U;
   2174      1.1   gdamore 		agploc |= ((agploc + 0x10000) >> 16);
   2175      1.1   gdamore 	}
   2176      1.1   gdamore 
   2177      1.1   gdamore 	PUT32(sc, RADEON_HOST_PATH_CNTL, 0);
   2178      1.1   gdamore 
   2179      1.1   gdamore 	PUT32(sc, RADEON_MC_FB_LOCATION, mcfbloc);
   2180      1.1   gdamore 	PUT32(sc, RADEON_MC_AGP_LOCATION, agploc);
   2181      1.1   gdamore 
   2182      1.1   gdamore 	DPRINTF(("aperbase = %u\n", aperbase));
   2183      1.1   gdamore 	PRINTREG(RADEON_MC_FB_LOCATION);
   2184      1.1   gdamore 	PRINTREG(RADEON_MC_AGP_LOCATION);
   2185      1.1   gdamore 
   2186      1.1   gdamore 	PUT32(sc, RADEON_DISPLAY_BASE_ADDR, sc->sc_aperbase);
   2187      1.1   gdamore 
   2188      1.1   gdamore 	if (HAS_CRTC2(sc))
   2189      1.1   gdamore 		PUT32(sc, RADEON_DISPLAY2_BASE_ADDR, sc->sc_aperbase);
   2190      1.1   gdamore 
   2191      1.1   gdamore 	PUT32(sc, RADEON_OV0_BASE_ADDR, sc->sc_aperbase);
   2192      1.1   gdamore 
   2193      1.1   gdamore #if 0
   2194      1.1   gdamore 	/* XXX: what is this AGP garbage? :-) */
   2195      1.1   gdamore 	PUT32(sc, RADEON_AGP_CNTL, 0x00100000);
   2196      1.1   gdamore #endif
   2197      1.1   gdamore 
   2198      1.1   gdamore 	delay(100000);
   2199      1.1   gdamore 
   2200      1.1   gdamore 	PUT32(sc, RADEON_CRTC_GEN_CNTL, gen);
   2201      1.1   gdamore 	PUT32(sc, RADEON_CRTC_EXT_CNTL, ext);
   2202      1.1   gdamore 
   2203      1.1   gdamore 	if (HAS_CRTC2(sc))
   2204      1.1   gdamore 		PUT32(sc, RADEON_CRTC2_GEN_CNTL, gen2);
   2205      1.1   gdamore }
   2206      1.1   gdamore 
   2207      1.1   gdamore void
   2208      1.1   gdamore radeonfb_init_misc(struct radeonfb_softc *sc)
   2209      1.1   gdamore {
   2210      1.1   gdamore 	PUT32(sc, RADEON_BUS_CNTL,
   2211      1.1   gdamore 	    RADEON_BUS_MASTER_DIS |
   2212      1.1   gdamore 	    RADEON_BUS_PREFETCH_MODE_ACT |
   2213      1.1   gdamore 	    RADEON_BUS_PCI_READ_RETRY_EN |
   2214      1.1   gdamore 	    RADEON_BUS_PCI_WRT_RETRY_EN |
   2215      1.1   gdamore 	    (3 << RADEON_BUS_RETRY_WS_SHIFT) |
   2216      1.1   gdamore 	    RADEON_BUS_MSTR_RD_MULT |
   2217      1.1   gdamore 	    RADEON_BUS_MSTR_RD_LINE |
   2218      1.1   gdamore 	    RADEON_BUS_RD_DISCARD_EN |
   2219      1.1   gdamore 	    RADEON_BUS_MSTR_DISCONNECT_EN |
   2220      1.1   gdamore 	    RADEON_BUS_READ_BURST);
   2221      1.1   gdamore 
   2222      1.1   gdamore 	PUT32(sc, RADEON_BUS_CNTL1, 0xf0);
   2223      1.1   gdamore 	/* PUT32(sc, RADEON_SEPROM_CNTL1, 0x09ff0000); */
   2224      1.1   gdamore 	PUT32(sc, RADEON_FCP_CNTL, RADEON_FCP0_SRC_GND);
   2225      1.1   gdamore 	PUT32(sc, RADEON_RBBM_CNTL,
   2226      1.1   gdamore 	    (3 << RADEON_RB_SETTLE_SHIFT) |
   2227      1.1   gdamore 	    (4 << RADEON_ABORTCLKS_HI_SHIFT) |
   2228      1.1   gdamore 	    (4 << RADEON_ABORTCLKS_CP_SHIFT) |
   2229      1.1   gdamore 	    (4 << RADEON_ABORTCLKS_CFIFO_SHIFT));
   2230      1.1   gdamore 
   2231      1.1   gdamore 	/* XXX: figure out what these mean! */
   2232      1.1   gdamore 	PUT32(sc, RADEON_AGP_CNTL, 0x00100000);
   2233      1.1   gdamore 	PUT32(sc, RADEON_HOST_PATH_CNTL, 0);
   2234      1.1   gdamore 	//PUT32(sc, RADEON_DISP_MISC_CNTL, 0x5bb00400);
   2235      1.1   gdamore 
   2236      1.1   gdamore 	PUT32(sc, RADEON_GEN_INT_CNTL, 0);
   2237      1.1   gdamore 	PUT32(sc, RADEON_GEN_INT_STATUS, GET32(sc, RADEON_GEN_INT_STATUS));
   2238      1.1   gdamore }
   2239      1.1   gdamore 
   2240      1.1   gdamore /*
   2241      1.1   gdamore  * This loads a linear color map for true color.
   2242      1.1   gdamore  */
   2243      1.1   gdamore void
   2244      1.1   gdamore radeonfb_init_palette(struct radeonfb_softc *sc, int crtc)
   2245      1.1   gdamore {
   2246      1.1   gdamore 	int		i;
   2247      1.1   gdamore 	uint32_t	vclk;
   2248      1.1   gdamore 
   2249      1.1   gdamore #define	DAC_WIDTH ((1 << 10) - 1)
   2250      1.1   gdamore #define	CLUT_WIDTH ((1 << 8) - 1)
   2251      1.1   gdamore #define	CLUT_COLOR(i)      ((i * DAC_WIDTH * 2 / CLUT_WIDTH + 1) / 2)
   2252      1.1   gdamore 
   2253      1.1   gdamore 	vclk = GETPLL(sc, RADEON_VCLK_ECP_CNTL);
   2254      1.1   gdamore 	PUTPLL(sc, RADEON_VCLK_ECP_CNTL, vclk & ~RADEON_PIXCLK_DAC_ALWAYS_ONb);
   2255      1.1   gdamore 
   2256      1.1   gdamore 	if (crtc)
   2257      1.1   gdamore 		SET32(sc, RADEON_DAC_CNTL2, RADEON_DAC2_PALETTE_ACC_CTL);
   2258      1.1   gdamore 	else
   2259      1.1   gdamore 		CLR32(sc, RADEON_DAC_CNTL2, RADEON_DAC2_PALETTE_ACC_CTL);
   2260      1.1   gdamore 
   2261      1.1   gdamore 	PUT32(sc, RADEON_PALETTE_INDEX, 0);
   2262      1.1   gdamore 	for (i = 0; i <= CLUT_WIDTH; ++i) {
   2263      1.1   gdamore 		PUT32(sc, RADEON_PALETTE_30_DATA,
   2264      1.1   gdamore 		    (CLUT_COLOR(i) << 10) |
   2265      1.1   gdamore 		    (CLUT_COLOR(i) << 20) |
   2266      1.1   gdamore 		    (CLUT_COLOR(i)));
   2267      1.1   gdamore 	}
   2268      1.1   gdamore 
   2269      1.1   gdamore 	CLR32(sc, RADEON_DAC_CNTL2, RADEON_DAC2_PALETTE_ACC_CTL);
   2270      1.1   gdamore 	PRINTREG(RADEON_DAC_CNTL2);
   2271      1.1   gdamore 
   2272      1.1   gdamore 	PUTPLL(sc, RADEON_VCLK_ECP_CNTL, vclk);
   2273      1.1   gdamore }
   2274      1.1   gdamore 
   2275      1.1   gdamore /*
   2276      1.1   gdamore  * Bugs in some R300 hardware requires this when accessing CLOCK_CNTL_INDEX.
   2277      1.1   gdamore  */
   2278      1.1   gdamore void
   2279      1.1   gdamore radeonfb_r300cg_workaround(struct radeonfb_softc *sc)
   2280      1.1   gdamore {
   2281      1.1   gdamore 	uint32_t	tmp, save;
   2282      1.1   gdamore 
   2283      1.1   gdamore 	save = GET32(sc, RADEON_CLOCK_CNTL_INDEX);
   2284      1.1   gdamore 	tmp = save & ~(0x3f | RADEON_PLL_WR_EN);
   2285      1.1   gdamore 	PUT32(sc, RADEON_CLOCK_CNTL_INDEX, tmp);
   2286      1.1   gdamore 	tmp = GET32(sc, RADEON_CLOCK_CNTL_DATA);
   2287      1.1   gdamore 	PUT32(sc, RADEON_CLOCK_CNTL_INDEX, save);
   2288      1.1   gdamore }
   2289      1.1   gdamore 
   2290      1.1   gdamore /*
   2291      1.1   gdamore  * Acceleration entry points.
   2292      1.1   gdamore  */
   2293      1.2  macallan static void
   2294      1.2  macallan radeonfb_putchar(void *cookie, int row, int col, u_int c, long attr)
   2295      1.1   gdamore {
   2296      1.1   gdamore 	struct rasops_info	*ri = cookie;
   2297      1.1   gdamore 	struct vcons_screen	*scr = ri->ri_hw;
   2298      1.1   gdamore 	struct radeonfb_display	*dp = scr->scr_cookie;
   2299      1.1   gdamore 	uint32_t		x, y, w, h;
   2300      1.1   gdamore 	uint32_t		bg, fg;
   2301      1.1   gdamore 	uint8_t			*data;
   2302      1.1   gdamore 
   2303      1.1   gdamore 	if (dp->rd_wsmode != WSDISPLAYIO_MODE_EMUL)
   2304      1.1   gdamore 		return;
   2305      1.1   gdamore 
   2306      1.1   gdamore 	if (!CHAR_IN_FONT(c, ri->ri_font))
   2307      1.1   gdamore 		return;
   2308      1.1   gdamore 
   2309      1.1   gdamore 	w = ri->ri_font->fontwidth;
   2310      1.1   gdamore 	h = ri->ri_font->fontheight;
   2311      1.1   gdamore 
   2312      1.1   gdamore 	bg = ri->ri_devcmap[(attr >> 16) & 0xf];
   2313      1.1   gdamore 	fg = ri->ri_devcmap[(attr >> 24) & 0xf];
   2314      1.1   gdamore 
   2315      1.1   gdamore 	x = ri->ri_xorigin + col * w;
   2316      1.1   gdamore 	y = ri->ri_yorigin + row * h;
   2317      1.1   gdamore 
   2318      1.2  macallan 	if (c == 0x20) {
   2319      1.2  macallan 		radeonfb_rectfill(dp, x, y, w, h, bg);
   2320      1.1   gdamore 	} else {
   2321      1.1   gdamore 		data = (uint8_t *)ri->ri_font->data +
   2322      1.1   gdamore 		    (c - ri->ri_font->firstchar) * ri->ri_fontscale;
   2323      1.1   gdamore 
   2324      1.1   gdamore 		radeonfb_setup_mono(dp, x, y, w, h, fg, bg);
   2325      1.1   gdamore 		radeonfb_feed_bytes(dp, ri->ri_fontscale, data);
   2326      1.1   gdamore 	}
   2327      1.1   gdamore }
   2328      1.1   gdamore 
   2329      1.2  macallan static void
   2330      1.1   gdamore radeonfb_eraserows(void *cookie, int row, int nrows, long fillattr)
   2331      1.1   gdamore {
   2332      1.1   gdamore 	struct rasops_info	*ri = cookie;
   2333      1.1   gdamore 	struct vcons_screen	*scr = ri->ri_hw;
   2334      1.1   gdamore 	struct radeonfb_display	*dp = scr->scr_cookie;
   2335      1.1   gdamore 	uint32_t		x, y, w, h, fg, bg, ul;
   2336      1.1   gdamore 
   2337      1.1   gdamore 	/* XXX: check for full emulation mode? */
   2338      1.1   gdamore 	if (dp->rd_wsmode == WSDISPLAYIO_MODE_EMUL) {
   2339      1.1   gdamore 		x = ri->ri_xorigin;
   2340      1.1   gdamore 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
   2341      1.1   gdamore 		w = ri->ri_emuwidth;
   2342      1.1   gdamore 		h = ri->ri_font->fontheight * nrows;
   2343      1.1   gdamore 
   2344      1.1   gdamore 		rasops_unpack_attr(fillattr, &fg, &bg, &ul);
   2345      1.2  macallan 		radeonfb_rectfill(dp, x, y, w, h, ri->ri_devcmap[bg & 0xf]);
   2346      1.1   gdamore 	}
   2347      1.1   gdamore }
   2348      1.1   gdamore 
   2349      1.2  macallan static void
   2350      1.1   gdamore radeonfb_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
   2351      1.1   gdamore {
   2352      1.1   gdamore 	struct rasops_info	*ri = cookie;
   2353      1.1   gdamore 	struct vcons_screen	*scr = ri->ri_hw;
   2354      1.1   gdamore 	struct radeonfb_display	*dp = scr->scr_cookie;
   2355      1.1   gdamore 	uint32_t		x, ys, yd, w, h;
   2356      1.1   gdamore 
   2357      1.1   gdamore 	if (dp->rd_wsmode == WSDISPLAYIO_MODE_EMUL) {
   2358      1.1   gdamore 		x = ri->ri_xorigin;
   2359      1.1   gdamore 		ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
   2360      1.1   gdamore 		yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
   2361      1.1   gdamore 		w = ri->ri_emuwidth;
   2362      1.1   gdamore 		h = ri->ri_font->fontheight * nrows;
   2363      1.1   gdamore 		radeonfb_bitblt(dp, x, ys, x, yd, w, h,
   2364      1.1   gdamore 		    RADEON_ROP3_S, 0xffffffff);
   2365      1.1   gdamore 	}
   2366      1.1   gdamore }
   2367      1.1   gdamore 
   2368      1.2  macallan static void
   2369      1.1   gdamore radeonfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
   2370      1.1   gdamore {
   2371      1.1   gdamore 	struct rasops_info	*ri = cookie;
   2372      1.1   gdamore 	struct vcons_screen	*scr = ri->ri_hw;
   2373      1.1   gdamore 	struct radeonfb_display	*dp = scr->scr_cookie;
   2374      1.1   gdamore 	uint32_t		xs, xd, y, w, h;
   2375      1.1   gdamore 
   2376      1.1   gdamore 	if (dp->rd_wsmode == WSDISPLAYIO_MODE_EMUL) {
   2377      1.1   gdamore 		xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
   2378      1.1   gdamore 		xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
   2379      1.1   gdamore 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
   2380      1.1   gdamore 		w = ri->ri_font->fontwidth * ncols;
   2381      1.1   gdamore 		h = ri->ri_font->fontheight;
   2382      1.1   gdamore 		radeonfb_bitblt(dp, xs, y, xd, y, w, h,
   2383      1.1   gdamore 		    RADEON_ROP3_S, 0xffffffff);
   2384      1.1   gdamore 	}
   2385      1.1   gdamore }
   2386      1.1   gdamore 
   2387      1.2  macallan static void
   2388      1.1   gdamore radeonfb_erasecols(void *cookie, int row, int startcol, int ncols,
   2389      1.1   gdamore     long fillattr)
   2390      1.1   gdamore {
   2391      1.1   gdamore 	struct rasops_info	*ri = cookie;
   2392      1.1   gdamore 	struct vcons_screen	*scr = ri->ri_hw;
   2393      1.1   gdamore 	struct radeonfb_display	*dp = scr->scr_cookie;
   2394      1.1   gdamore 	uint32_t		x, y, w, h, fg, bg, ul;
   2395      1.1   gdamore 
   2396      1.1   gdamore 	if (dp->rd_wsmode == WSDISPLAYIO_MODE_EMUL) {
   2397      1.1   gdamore 		x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
   2398      1.1   gdamore 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
   2399      1.1   gdamore 		w = ri->ri_font->fontwidth * ncols;
   2400      1.1   gdamore 		h = ri->ri_font->fontheight;
   2401      1.1   gdamore 
   2402      1.1   gdamore 		rasops_unpack_attr(fillattr, &fg, &bg, &ul);
   2403      1.2  macallan 		radeonfb_rectfill(dp, x, y, w, h, ri->ri_devcmap[bg & 0xf]);
   2404      1.1   gdamore 	}
   2405      1.1   gdamore }
   2406      1.1   gdamore 
   2407      1.2  macallan static void
   2408      1.1   gdamore radeonfb_cursor(void *cookie, int on, int row, int col)
   2409      1.1   gdamore {
   2410      1.1   gdamore 	struct rasops_info *ri = cookie;
   2411      1.1   gdamore 	struct vcons_screen *scr = ri->ri_hw;
   2412      1.1   gdamore 	struct radeonfb_display	*dp = scr->scr_cookie;
   2413      1.1   gdamore 	int x, y, wi, he;
   2414  1.7.2.2    bouyer 
   2415      1.1   gdamore 	wi = ri->ri_font->fontwidth;
   2416      1.1   gdamore 	he = ri->ri_font->fontheight;
   2417  1.7.2.2    bouyer 
   2418      1.1   gdamore 	if (dp->rd_wsmode == WSDISPLAYIO_MODE_EMUL) {
   2419      1.1   gdamore 		x = ri->ri_ccol * wi + ri->ri_xorigin;
   2420      1.1   gdamore 		y = ri->ri_crow * he + ri->ri_yorigin;
   2421      1.1   gdamore 		/* first turn off the old cursor */
   2422      1.1   gdamore 		if (ri->ri_flg & RI_CURSOR) {
   2423      1.1   gdamore 			radeonfb_bitblt(dp, x, y, x, y, wi, he,
   2424      1.2  macallan 			    RADEON_ROP3_Dn, 0xffffffff);
   2425      1.1   gdamore 			ri->ri_flg &= ~RI_CURSOR;
   2426      1.1   gdamore 		}
   2427      1.1   gdamore 		ri->ri_crow = row;
   2428      1.1   gdamore 		ri->ri_ccol = col;
   2429      1.1   gdamore 		/* then (possibly) turn on the new one */
   2430      1.1   gdamore 		if (on) {
   2431      1.1   gdamore 			x = ri->ri_ccol * wi + ri->ri_xorigin;
   2432      1.1   gdamore 			y = ri->ri_crow * he + ri->ri_yorigin;
   2433      1.1   gdamore 			radeonfb_bitblt(dp, x, y, x, y, wi, he,
   2434      1.2  macallan 			    RADEON_ROP3_Dn, 0xffffffff);
   2435      1.2  macallan 			ri->ri_flg |= RI_CURSOR;
   2436      1.1   gdamore 		}
   2437      1.1   gdamore 	} else {
   2438      1.1   gdamore 		scr->scr_ri.ri_crow = row;
   2439      1.1   gdamore 		scr->scr_ri.ri_ccol = col;
   2440      1.1   gdamore 		scr->scr_ri.ri_flg &= ~RI_CURSOR;
   2441      1.1   gdamore 	}
   2442      1.1   gdamore }
   2443      1.1   gdamore 
   2444      1.2  macallan static int
   2445      1.2  macallan radeonfb_allocattr(void *cookie, int fg, int bg, int flags, long *attrp)
   2446      1.2  macallan {
   2447      1.2  macallan 	if ((fg == 0) && (bg == 0)) {
   2448      1.2  macallan 		fg = WS_DEFAULT_FG;
   2449      1.2  macallan 		bg = WS_DEFAULT_BG;
   2450      1.2  macallan 	}
   2451      1.2  macallan 	*attrp = ((fg & 0xf) << 24) | ((bg & 0xf) << 16) | (flags & 0xff) << 8;
   2452      1.2  macallan 	return 0;
   2453      1.2  macallan }
   2454      1.1   gdamore 
   2455      1.1   gdamore /*
   2456      1.1   gdamore  * Underlying acceleration support.
   2457      1.1   gdamore  */
   2458      1.2  macallan static void
   2459      1.1   gdamore radeonfb_setup_mono(struct radeonfb_display *dp, int xd, int yd, int width,
   2460      1.1   gdamore     int height, uint32_t fg, uint32_t bg)
   2461      1.1   gdamore {
   2462      1.1   gdamore 	struct radeonfb_softc	*sc = dp->rd_softc;
   2463      1.1   gdamore 	uint32_t		gmc;
   2464      1.2  macallan 	uint32_t 		padded_width = (width+7) & 0xfff8;
   2465      1.2  macallan 	uint32_t		topleft, bottomright;
   2466  1.7.2.2    bouyer 
   2467      1.2  macallan 	gmc = dp->rd_format << RADEON_GMC_DST_DATATYPE_SHIFT;
   2468      1.2  macallan 
   2469      1.2  macallan 	if (width != padded_width) {
   2470      1.1   gdamore 
   2471      1.5  macallan 		radeonfb_wait_fifo(sc, 2);
   2472      1.5  macallan 		topleft = ((yd << 16) & 0x1fff0000) | (xd & 0x1fff);
   2473  1.7.2.2    bouyer 		bottomright = (((yd + height) << 16) & 0x1fff0000) |
   2474      1.5  macallan 		    ((xd + width) & 0x1fff);
   2475      1.2  macallan 		PUT32(sc, RADEON_SC_TOP_LEFT, topleft);
   2476      1.2  macallan 		PUT32(sc, RADEON_SC_BOTTOM_RIGHT, bottomright);
   2477      1.2  macallan 	}
   2478      1.1   gdamore 
   2479      1.1   gdamore 	radeonfb_wait_fifo(sc, 5);
   2480  1.7.2.2    bouyer 
   2481      1.1   gdamore 	PUT32(sc, RADEON_DP_GUI_MASTER_CNTL,
   2482      1.1   gdamore 	    RADEON_GMC_BRUSH_NONE |
   2483      1.1   gdamore 	    RADEON_GMC_SRC_DATATYPE_MONO_FG_BG |
   2484      1.1   gdamore 	    //RADEON_GMC_BYTE_LSB_TO_MSB |
   2485      1.2  macallan 	    RADEON_GMC_DST_CLIPPING |
   2486      1.1   gdamore 	    RADEON_ROP3_S |
   2487      1.1   gdamore 	    RADEON_DP_SRC_SOURCE_HOST_DATA |
   2488      1.1   gdamore 	    RADEON_GMC_CLR_CMP_CNTL_DIS |
   2489      1.1   gdamore 	    RADEON_GMC_WR_MSK_DIS |
   2490      1.1   gdamore 	    gmc);
   2491      1.1   gdamore 
   2492      1.1   gdamore 	PUT32(sc, RADEON_DP_SRC_FRGD_CLR, fg);
   2493      1.1   gdamore 	PUT32(sc, RADEON_DP_SRC_BKGD_CLR, bg);
   2494      1.1   gdamore 
   2495      1.1   gdamore 	PUT32(sc, RADEON_DST_X_Y, (xd << 16) | yd);
   2496      1.2  macallan 	PUT32(sc, RADEON_DST_WIDTH_HEIGHT, (padded_width << 16) | height);
   2497  1.7.2.2    bouyer 
   2498      1.1   gdamore }
   2499      1.1   gdamore 
   2500      1.2  macallan static void
   2501      1.1   gdamore radeonfb_feed_bytes(struct radeonfb_display *dp, int count, uint8_t *data)
   2502      1.1   gdamore {
   2503      1.1   gdamore 	struct radeonfb_softc	*sc = dp->rd_softc;
   2504      1.1   gdamore 	int i;
   2505      1.1   gdamore 	uint32_t latch = 0;
   2506      1.1   gdamore 	int shift = 0;
   2507  1.7.2.2    bouyer 
   2508      1.1   gdamore 	for (i = 0; i < count; i++) {
   2509      1.1   gdamore 		latch |= (data[i] << shift);
   2510      1.1   gdamore 		if (shift == 24) {
   2511      1.1   gdamore 			radeonfb_wait_fifo(sc, 1);
   2512      1.1   gdamore 			PUT32(sc, RADEON_HOST_DATA0, latch);
   2513      1.1   gdamore 			latch = 0;
   2514      1.1   gdamore 			shift = 0;
   2515      1.1   gdamore 		} else
   2516      1.1   gdamore 			shift += 8;
   2517      1.1   gdamore 	}
   2518      1.1   gdamore 	if (shift != 0) {
   2519      1.1   gdamore 		radeonfb_wait_fifo(sc, 1);
   2520      1.1   gdamore 		PUT32(sc, RADEON_HOST_DATA0, latch);
   2521      1.1   gdamore 	}
   2522      1.2  macallan 	radeonfb_unclip(sc);
   2523      1.1   gdamore }
   2524      1.1   gdamore 
   2525      1.2  macallan static void
   2526      1.2  macallan radeonfb_rectfill(struct radeonfb_display *dp, int dstx, int dsty,
   2527      1.1   gdamore     int width, int height, uint32_t color)
   2528      1.1   gdamore {
   2529      1.1   gdamore 	struct radeonfb_softc	*sc = dp->rd_softc;
   2530      1.1   gdamore 	uint32_t		gmc;
   2531      1.1   gdamore 
   2532      1.1   gdamore 	gmc = dp->rd_format << RADEON_GMC_DST_DATATYPE_SHIFT;
   2533      1.1   gdamore 
   2534      1.1   gdamore 	radeonfb_wait_fifo(sc, 6);
   2535      1.1   gdamore 
   2536      1.1   gdamore 	PUT32(sc, RADEON_DP_GUI_MASTER_CNTL,
   2537      1.1   gdamore 	    RADEON_GMC_BRUSH_SOLID_COLOR |
   2538      1.1   gdamore 	    RADEON_GMC_SRC_DATATYPE_COLOR |
   2539      1.1   gdamore 	    RADEON_GMC_CLR_CMP_CNTL_DIS |
   2540      1.1   gdamore 	    RADEON_ROP3_P | gmc);
   2541      1.1   gdamore 
   2542      1.1   gdamore 	PUT32(sc, RADEON_DP_BRUSH_FRGD_CLR, color);
   2543      1.1   gdamore 	PUT32(sc, RADEON_DP_WRITE_MASK, 0xffffffff);
   2544      1.1   gdamore 	PUT32(sc, RADEON_DP_CNTL,
   2545      1.1   gdamore 	    RADEON_DST_X_LEFT_TO_RIGHT |
   2546      1.1   gdamore 	    RADEON_DST_Y_TOP_TO_BOTTOM);
   2547      1.1   gdamore 	PUT32(sc, RADEON_DST_Y_X, (dsty << 16) | dstx);
   2548      1.1   gdamore 	PUT32(sc, RADEON_DST_WIDTH_HEIGHT, (width << 16) | (height));
   2549      1.1   gdamore 
   2550      1.1   gdamore 	/*
   2551      1.1   gdamore 	 * XXX: we don't wait for the fifo to empty -- that would slow
   2552      1.1   gdamore 	 * things down!  The linux radeonfb driver waits, but xfree doesn't
   2553      1.1   gdamore 	 */
   2554      1.1   gdamore 	/* XXX: for now we do, to make it safe for direct drawing */
   2555      1.1   gdamore 	radeonfb_engine_idle(sc);
   2556      1.1   gdamore }
   2557      1.1   gdamore 
   2558      1.2  macallan static void
   2559      1.1   gdamore radeonfb_bitblt(struct radeonfb_display *dp, int srcx, int srcy,
   2560      1.1   gdamore     int dstx, int dsty, int width, int height, int rop, uint32_t mask)
   2561      1.1   gdamore {
   2562      1.1   gdamore 	struct radeonfb_softc	*sc = dp->rd_softc;
   2563      1.1   gdamore 	uint32_t		gmc;
   2564      1.1   gdamore 	uint32_t		dir;
   2565      1.1   gdamore 
   2566      1.1   gdamore 	if (dsty < srcy) {
   2567      1.1   gdamore 		dir = RADEON_DST_Y_TOP_TO_BOTTOM;
   2568      1.1   gdamore 	} else {
   2569      1.1   gdamore 		srcy += height - 1;
   2570      1.1   gdamore 		dsty += height - 1;
   2571      1.1   gdamore 		dir = 0;
   2572      1.1   gdamore 	}
   2573      1.6   gdamore 	if (dstx < srcx) {
   2574      1.1   gdamore 		dir |= RADEON_DST_X_LEFT_TO_RIGHT;
   2575      1.1   gdamore 	} else {
   2576      1.1   gdamore 		srcx += width - 1;
   2577      1.1   gdamore 		dstx += width - 1;
   2578      1.1   gdamore 	}
   2579      1.1   gdamore 
   2580      1.1   gdamore 	gmc = dp->rd_format << RADEON_GMC_DST_DATATYPE_SHIFT;
   2581  1.7.2.2    bouyer 
   2582      1.1   gdamore 	radeonfb_wait_fifo(sc, 6);
   2583      1.1   gdamore 
   2584      1.1   gdamore 	PUT32(sc, RADEON_DP_GUI_MASTER_CNTL,
   2585      1.1   gdamore 	    //RADEON_GMC_SRC_CLIPPING |
   2586      1.1   gdamore 	    RADEON_GMC_BRUSH_SOLID_COLOR |
   2587      1.1   gdamore 	    RADEON_GMC_SRC_DATATYPE_COLOR |
   2588      1.1   gdamore 	    RADEON_GMC_CLR_CMP_CNTL_DIS |
   2589      1.1   gdamore 	    RADEON_DP_SRC_SOURCE_MEMORY |
   2590      1.1   gdamore 	    rop | gmc);
   2591      1.1   gdamore 
   2592      1.1   gdamore 	PUT32(sc, RADEON_DP_WRITE_MASK, mask);
   2593      1.1   gdamore 	PUT32(sc, RADEON_DP_CNTL, dir);
   2594      1.1   gdamore 	PUT32(sc, RADEON_SRC_Y_X, (srcy << 16) | srcx);
   2595      1.1   gdamore 	PUT32(sc, RADEON_DST_Y_X, (dsty << 16) | dstx);
   2596      1.1   gdamore 	PUT32(sc, RADEON_DST_WIDTH_HEIGHT, (width << 16) | (height));
   2597      1.1   gdamore 
   2598      1.1   gdamore 	/*
   2599      1.1   gdamore 	 * XXX: we don't wait for the fifo to empty -- that would slow
   2600      1.1   gdamore 	 * things down!  The linux radeonfb driver waits, but xfree doesn't
   2601      1.1   gdamore 	 */
   2602      1.1   gdamore 	/* XXX: for now we do, to make it safe for direct drawing */
   2603      1.1   gdamore 	radeonfb_engine_idle(sc);
   2604      1.1   gdamore }
   2605      1.1   gdamore 
   2606      1.2  macallan static void
   2607      1.1   gdamore radeonfb_engine_idle(struct radeonfb_softc *sc)
   2608      1.1   gdamore {
   2609      1.1   gdamore 	int	i;
   2610      1.1   gdamore 
   2611      1.1   gdamore 	radeonfb_wait_fifo(sc, 64);
   2612      1.1   gdamore 	for (i = RADEON_TIMEOUT; i; i--) {
   2613      1.1   gdamore 		if ((GET32(sc, RADEON_RBBM_STATUS) &
   2614      1.1   gdamore 			RADEON_RBBM_ACTIVE) == 0) {
   2615      1.1   gdamore 			radeonfb_engine_flush(sc);
   2616      1.1   gdamore 			break;
   2617      1.1   gdamore 		}
   2618      1.1   gdamore 	}
   2619      1.1   gdamore }
   2620      1.1   gdamore 
   2621      1.2  macallan static void
   2622      1.1   gdamore radeonfb_wait_fifo(struct radeonfb_softc *sc, int n)
   2623      1.1   gdamore {
   2624      1.1   gdamore 	int	i;
   2625      1.1   gdamore 
   2626      1.1   gdamore 	for (i = RADEON_TIMEOUT; i; i--) {
   2627      1.1   gdamore 		if ((GET32(sc, RADEON_RBBM_STATUS) &
   2628      1.1   gdamore 			RADEON_RBBM_FIFOCNT_MASK) >= n)
   2629      1.1   gdamore 			return;
   2630      1.1   gdamore 	}
   2631      1.1   gdamore #ifdef	DIAGNOSTIC
   2632      1.1   gdamore 	if (!i)
   2633      1.1   gdamore 		printf("%s: timed out waiting for fifo (%x)\n",
   2634      1.1   gdamore 		    XNAME(sc), GET32(sc, RADEON_RBBM_STATUS));
   2635      1.1   gdamore #endif
   2636      1.1   gdamore }
   2637      1.1   gdamore 
   2638      1.2  macallan static void
   2639      1.1   gdamore radeonfb_engine_flush(struct radeonfb_softc *sc)
   2640      1.1   gdamore {
   2641      1.1   gdamore 	int	i;
   2642      1.1   gdamore 	SET32(sc, RADEON_RB2D_DSTCACHE_CTLSTAT, RADEON_RB2D_DC_FLUSH_ALL);
   2643      1.1   gdamore 	for  (i = RADEON_TIMEOUT; i; i--) {
   2644      1.1   gdamore 		if ((GET32(sc, RADEON_RB2D_DSTCACHE_CTLSTAT) &
   2645      1.1   gdamore 			RADEON_RB2D_DC_BUSY) == 0)
   2646      1.1   gdamore 			break;
   2647      1.1   gdamore 	}
   2648      1.1   gdamore #ifdef DIAGNOSTIC
   2649      1.1   gdamore 	if (!i)
   2650      1.1   gdamore 		printf("%s: engine flush timed out!\n", XNAME(sc));
   2651      1.1   gdamore #endif
   2652      1.1   gdamore }
   2653      1.1   gdamore 
   2654      1.2  macallan static inline void
   2655      1.2  macallan radeonfb_unclip(struct radeonfb_softc *sc)
   2656      1.2  macallan {
   2657      1.2  macallan 
   2658      1.2  macallan 	radeonfb_wait_fifo(sc, 2);
   2659      1.4  macallan 	PUT32(sc, RADEON_SC_TOP_LEFT, 0);
   2660      1.5  macallan 	PUT32(sc, RADEON_SC_BOTTOM_RIGHT, 0x1fff1fff);
   2661      1.2  macallan }
   2662      1.2  macallan 
   2663      1.2  macallan static void
   2664      1.1   gdamore radeonfb_engine_init(struct radeonfb_display *dp)
   2665      1.1   gdamore {
   2666      1.1   gdamore 	struct radeonfb_softc	*sc = dp->rd_softc;
   2667      1.1   gdamore 	uint32_t		pitch;
   2668      1.1   gdamore 
   2669      1.1   gdamore 	/* no 3D */
   2670      1.1   gdamore 	PUT32(sc, RADEON_RB3D_CNTL, 0);
   2671      1.1   gdamore 
   2672      1.1   gdamore 	radeonfb_engine_reset(sc);
   2673      1.2  macallan 	pitch = ((dp->rd_virtx * (dp->rd_bpp / 8) + 0x3f)) >> 6;
   2674      1.2  macallan 	//pitch = ((sc->sc_maxx * (sc->sc_maxbpp / 8) + 0x3f)) >> 6;
   2675      1.1   gdamore 
   2676      1.1   gdamore 	radeonfb_wait_fifo(sc, 1);
   2677      1.1   gdamore 	if (!IS_R300(sc))
   2678      1.1   gdamore 		PUT32(sc, RADEON_RB2D_DSTCACHE_MODE, 0);
   2679      1.1   gdamore 
   2680      1.1   gdamore 	radeonfb_wait_fifo(sc, 3);
   2681      1.1   gdamore 	PUT32(sc, RADEON_DEFAULT_PITCH_OFFSET,
   2682      1.1   gdamore 	    (pitch << 22) | (sc->sc_aperbase >> 10));
   2683      1.1   gdamore 
   2684      1.1   gdamore 
   2685      1.1   gdamore 	PUT32(sc, RADEON_DST_PITCH_OFFSET,
   2686      1.1   gdamore 	    (pitch << 22) | (sc->sc_aperbase >> 10));
   2687      1.1   gdamore 	PUT32(sc, RADEON_SRC_PITCH_OFFSET,
   2688      1.1   gdamore 	    (pitch << 22) | (sc->sc_aperbase >> 10));
   2689      1.1   gdamore 
   2690      1.1   gdamore 	radeonfb_wait_fifo(sc, 1);
   2691      1.1   gdamore #if _BYTE_ORDER == _BIG_ENDIAN
   2692      1.1   gdamore 	SET32(sc, RADEON_DP_DATATYPE, RADEON_HOST_BIG_ENDIAN_EN);
   2693      1.1   gdamore #else
   2694      1.1   gdamore 	CLR32(sc, RADEON_DP_DATATYPE, RADEON_HOST_BIG_ENDIAN_EN);
   2695      1.1   gdamore #endif
   2696      1.1   gdamore 
   2697      1.1   gdamore 	/* default scissors -- no clipping */
   2698      1.1   gdamore 	radeonfb_wait_fifo(sc, 1);
   2699      1.1   gdamore 	PUT32(sc, RADEON_DEFAULT_SC_BOTTOM_RIGHT,
   2700      1.1   gdamore 	    RADEON_DEFAULT_SC_RIGHT_MAX | RADEON_DEFAULT_SC_BOTTOM_MAX);
   2701      1.1   gdamore 
   2702      1.1   gdamore 	radeonfb_wait_fifo(sc, 1);
   2703      1.1   gdamore 	PUT32(sc, RADEON_DP_GUI_MASTER_CNTL,
   2704      1.1   gdamore 	    (dp->rd_format << RADEON_GMC_DST_DATATYPE_SHIFT) |
   2705      1.1   gdamore 	    RADEON_GMC_CLR_CMP_CNTL_DIS |
   2706      1.1   gdamore 	    RADEON_GMC_BRUSH_SOLID_COLOR |
   2707      1.1   gdamore 	    RADEON_GMC_SRC_DATATYPE_COLOR);
   2708      1.1   gdamore 
   2709      1.1   gdamore 	radeonfb_wait_fifo(sc, 7);
   2710      1.1   gdamore 	PUT32(sc, RADEON_DST_LINE_START, 0);
   2711      1.1   gdamore 	PUT32(sc, RADEON_DST_LINE_END, 0);
   2712      1.1   gdamore 	PUT32(sc, RADEON_DP_BRUSH_FRGD_CLR, 0xffffffff);
   2713      1.1   gdamore 	PUT32(sc, RADEON_DP_BRUSH_BKGD_CLR, 0);
   2714      1.1   gdamore 	PUT32(sc, RADEON_DP_SRC_FRGD_CLR, 0xffffffff);
   2715      1.1   gdamore 	PUT32(sc, RADEON_DP_SRC_BKGD_CLR, 0);
   2716      1.1   gdamore 	PUT32(sc, RADEON_DP_WRITE_MASK, 0xffffffff);
   2717      1.1   gdamore 
   2718      1.1   gdamore 	radeonfb_engine_idle(sc);
   2719      1.1   gdamore }
   2720      1.1   gdamore 
   2721      1.2  macallan static void
   2722      1.1   gdamore radeonfb_engine_reset(struct radeonfb_softc *sc)
   2723      1.1   gdamore {
   2724      1.1   gdamore 	uint32_t	hpc, rbbm, mclkcntl, clkindex;
   2725      1.1   gdamore 
   2726      1.1   gdamore 	radeonfb_engine_flush(sc);
   2727      1.1   gdamore 
   2728      1.1   gdamore 	clkindex = GET32(sc, RADEON_CLOCK_CNTL_INDEX);
   2729      1.1   gdamore 	if (HAS_R300CG(sc))
   2730      1.1   gdamore 		radeonfb_r300cg_workaround(sc);
   2731      1.1   gdamore 	mclkcntl = GETPLL(sc, RADEON_MCLK_CNTL);
   2732      1.1   gdamore 
   2733      1.1   gdamore 	/*
   2734      1.1   gdamore 	 * According to comments in XFree code, resetting the HDP via
   2735      1.1   gdamore 	 * the RBBM_SOFT_RESET can cause bad behavior on some systems.
   2736      1.1   gdamore 	 * So we use HOST_PATH_CNTL instead.
   2737      1.1   gdamore 	 */
   2738      1.1   gdamore 
   2739      1.1   gdamore 	hpc = GET32(sc, RADEON_HOST_PATH_CNTL);
   2740      1.1   gdamore 	rbbm = GET32(sc, RADEON_RBBM_SOFT_RESET);
   2741      1.1   gdamore 	if (IS_R300(sc)) {
   2742      1.1   gdamore 		PUT32(sc, RADEON_RBBM_SOFT_RESET, rbbm |
   2743      1.1   gdamore 		    RADEON_SOFT_RESET_CP |
   2744      1.1   gdamore 		    RADEON_SOFT_RESET_HI |
   2745      1.1   gdamore 		    RADEON_SOFT_RESET_E2);
   2746      1.1   gdamore 		GET32(sc, RADEON_RBBM_SOFT_RESET);
   2747      1.1   gdamore 		PUT32(sc, RADEON_RBBM_SOFT_RESET, 0);
   2748      1.1   gdamore 		/*
   2749      1.1   gdamore 		 * XXX: this bit is not defined in any ATI docs I have,
   2750      1.1   gdamore 		 * nor in the XFree code, but XFree does it.  Why?
   2751      1.1   gdamore 		 */
   2752      1.1   gdamore 		SET32(sc, RADEON_RB2D_DSTCACHE_MODE, (1<<17));
   2753      1.1   gdamore 	} else {
   2754      1.1   gdamore 		PUT32(sc, RADEON_RBBM_SOFT_RESET, rbbm |
   2755      1.1   gdamore 		    RADEON_SOFT_RESET_CP |
   2756      1.1   gdamore 		    RADEON_SOFT_RESET_SE |
   2757      1.1   gdamore 		    RADEON_SOFT_RESET_RE |
   2758      1.1   gdamore 		    RADEON_SOFT_RESET_PP |
   2759      1.1   gdamore 		    RADEON_SOFT_RESET_E2 |
   2760      1.1   gdamore 		    RADEON_SOFT_RESET_RB);
   2761      1.1   gdamore 		GET32(sc, RADEON_RBBM_SOFT_RESET);
   2762      1.1   gdamore 		PUT32(sc, RADEON_RBBM_SOFT_RESET, rbbm &
   2763      1.1   gdamore 		    ~(RADEON_SOFT_RESET_CP |
   2764      1.1   gdamore 			RADEON_SOFT_RESET_SE |
   2765      1.1   gdamore 			RADEON_SOFT_RESET_RE |
   2766      1.1   gdamore 			RADEON_SOFT_RESET_PP |
   2767      1.1   gdamore 			RADEON_SOFT_RESET_E2 |
   2768      1.1   gdamore 			RADEON_SOFT_RESET_RB));
   2769      1.1   gdamore 		GET32(sc, RADEON_RBBM_SOFT_RESET);
   2770      1.1   gdamore 	}
   2771      1.1   gdamore 
   2772      1.1   gdamore 	PUT32(sc, RADEON_HOST_PATH_CNTL, hpc | RADEON_HDP_SOFT_RESET);
   2773      1.1   gdamore 	GET32(sc, RADEON_HOST_PATH_CNTL);
   2774      1.1   gdamore 	PUT32(sc, RADEON_HOST_PATH_CNTL, hpc);
   2775      1.1   gdamore 
   2776      1.1   gdamore 	if (IS_R300(sc))
   2777      1.1   gdamore 		PUT32(sc, RADEON_RBBM_SOFT_RESET, rbbm);
   2778      1.1   gdamore 
   2779      1.1   gdamore 	PUT32(sc, RADEON_CLOCK_CNTL_INDEX, clkindex);
   2780      1.1   gdamore 	PUTPLL(sc, RADEON_MCLK_CNTL, mclkcntl);
   2781      1.1   gdamore 
   2782      1.1   gdamore 	if (HAS_R300CG(sc))
   2783      1.1   gdamore 		radeonfb_r300cg_workaround(sc);
   2784      1.1   gdamore }
   2785      1.1   gdamore 
   2786      1.2  macallan static int
   2787      1.1   gdamore radeonfb_set_curpos(struct radeonfb_display *dp, struct wsdisplay_curpos *pos)
   2788      1.1   gdamore {
   2789      1.1   gdamore 	int		x, y;
   2790      1.1   gdamore 
   2791      1.1   gdamore 	x = pos->x;
   2792      1.1   gdamore 	y = pos->y;
   2793      1.1   gdamore 
   2794      1.1   gdamore 	/*
   2795      1.1   gdamore 	 * This doesn't let a cursor move off the screen.  I'm not
   2796      1.1   gdamore 	 * sure if this will have negative effects for e.g. Xinerama.
   2797      1.1   gdamore 	 * I'd guess Xinerama handles it by changing the cursor shape,
   2798      1.1   gdamore 	 * but that needs verification.
   2799      1.1   gdamore 	 */
   2800      1.1   gdamore 	if (x >= dp->rd_virtx)
   2801      1.1   gdamore 		x = dp->rd_virtx - 1;
   2802      1.1   gdamore 	if (x < 0)
   2803      1.1   gdamore 		x = 0;
   2804      1.1   gdamore 	if (y >= dp->rd_virty)
   2805      1.1   gdamore 		y = dp->rd_virty - 1;
   2806      1.1   gdamore 	if (y < 0)
   2807      1.1   gdamore 		y = 0;
   2808      1.1   gdamore 
   2809      1.1   gdamore 	dp->rd_cursor.rc_pos.x = x;
   2810      1.1   gdamore 	dp->rd_cursor.rc_pos.y = y;
   2811      1.1   gdamore 
   2812      1.1   gdamore 	radeonfb_cursor_position(dp);
   2813      1.1   gdamore 	return 0;
   2814      1.1   gdamore }
   2815      1.1   gdamore 
   2816      1.2  macallan static int
   2817      1.1   gdamore radeonfb_set_cursor(struct radeonfb_display *dp, struct wsdisplay_cursor *wc)
   2818      1.1   gdamore {
   2819      1.1   gdamore 	unsigned	flags;
   2820      1.1   gdamore 
   2821      1.1   gdamore 	uint8_t		r[2], g[2], b[2];
   2822      1.1   gdamore 	unsigned	index, count;
   2823      1.1   gdamore 	int		i, err;
   2824      1.1   gdamore 	int		pitch, size;
   2825      1.1   gdamore 	struct radeonfb_cursor	nc;
   2826      1.1   gdamore 
   2827      1.1   gdamore 	flags = wc->which;
   2828      1.1   gdamore 
   2829      1.1   gdamore 	/* copy old values */
   2830      1.1   gdamore 	nc = dp->rd_cursor;
   2831      1.1   gdamore 
   2832      1.1   gdamore 	if (flags & WSDISPLAY_CURSOR_DOCMAP) {
   2833      1.1   gdamore 		index = wc->cmap.index;
   2834      1.1   gdamore 		count = wc->cmap.count;
   2835  1.7.2.2    bouyer 
   2836      1.1   gdamore 		if (index >= 2 || (index + count) > 2)
   2837      1.1   gdamore 			return EINVAL;
   2838      1.1   gdamore 
   2839      1.1   gdamore 		err = copyin(wc->cmap.red, &r[index], count);
   2840      1.1   gdamore 		if (err)
   2841      1.1   gdamore 			return err;
   2842      1.1   gdamore 		err = copyin(wc->cmap.green, &g[index], count);
   2843      1.1   gdamore 		if (err)
   2844      1.1   gdamore 			return err;
   2845      1.1   gdamore 		err = copyin(wc->cmap.blue, &b[index], count);
   2846      1.1   gdamore 		if (err)
   2847      1.1   gdamore 			return err;
   2848      1.1   gdamore 
   2849      1.1   gdamore 		for (i = index; i < index + count; i++) {
   2850      1.1   gdamore 			nc.rc_cmap[i] =
   2851      1.1   gdamore 			    (r[i] << 16) + (g[i] << 8) + (b[i] << 0);
   2852      1.1   gdamore 		}
   2853      1.1   gdamore 	}
   2854      1.1   gdamore 
   2855      1.1   gdamore 	if (flags & WSDISPLAY_CURSOR_DOSHAPE) {
   2856      1.1   gdamore 		if ((wc->size.x > RADEON_CURSORMAXX) ||
   2857      1.1   gdamore 		    (wc->size.y > RADEON_CURSORMAXY))
   2858      1.1   gdamore 			return EINVAL;
   2859      1.1   gdamore 
   2860      1.1   gdamore 		/* figure bytes per line */
   2861      1.1   gdamore 		pitch = (wc->size.x + 7) / 8;
   2862      1.1   gdamore 		size = pitch * wc->size.y;
   2863      1.1   gdamore 
   2864      1.1   gdamore 		/* clear the old cursor and mask */
   2865      1.1   gdamore 		memset(nc.rc_image, 0, 512);
   2866      1.1   gdamore 		memset(nc.rc_mask, 0, 512);
   2867      1.1   gdamore 
   2868      1.1   gdamore 		nc.rc_size = wc->size;
   2869      1.1   gdamore 
   2870      1.1   gdamore 		if ((err = copyin(wc->image, nc.rc_image, size)) != 0)
   2871      1.1   gdamore 			return err;
   2872      1.1   gdamore 
   2873      1.1   gdamore 		if ((err = copyin(wc->mask, nc.rc_mask, size)) != 0)
   2874      1.1   gdamore 			return err;
   2875      1.1   gdamore 	}
   2876      1.1   gdamore 
   2877      1.1   gdamore 	if (flags & WSDISPLAY_CURSOR_DOHOT) {
   2878      1.1   gdamore 		nc.rc_hot = wc->hot;
   2879      1.1   gdamore 		if (nc.rc_hot.x >= nc.rc_size.x)
   2880      1.1   gdamore 			nc.rc_hot.x = nc.rc_size.x - 1;
   2881      1.1   gdamore 		if (nc.rc_hot.y >= nc.rc_size.y)
   2882      1.1   gdamore 			nc.rc_hot.y = nc.rc_size.y - 1;
   2883      1.1   gdamore 	}
   2884      1.1   gdamore 
   2885      1.1   gdamore 	if (flags & WSDISPLAY_CURSOR_DOPOS) {
   2886      1.1   gdamore 		nc.rc_pos = wc->pos;
   2887      1.1   gdamore 		if (nc.rc_pos.x >= dp->rd_virtx)
   2888      1.1   gdamore 			nc.rc_pos.x = dp->rd_virtx - 1;
   2889      1.7  christos #if 0
   2890      1.1   gdamore 		if (nc.rc_pos.x < 0)
   2891      1.1   gdamore 			nc.rc_pos.x = 0;
   2892      1.7  christos #endif
   2893      1.1   gdamore 		if (nc.rc_pos.y >= dp->rd_virty)
   2894      1.1   gdamore 			nc.rc_pos.y = dp->rd_virty - 1;
   2895      1.7  christos #if 0
   2896      1.1   gdamore 		if (nc.rc_pos.y < 0)
   2897      1.1   gdamore 			nc.rc_pos.y = 0;
   2898      1.7  christos #endif
   2899      1.1   gdamore 	}
   2900      1.1   gdamore 	if (flags & WSDISPLAY_CURSOR_DOCUR) {
   2901      1.1   gdamore 		nc.rc_visible = wc->enable;
   2902      1.1   gdamore 	}
   2903      1.1   gdamore 
   2904      1.1   gdamore 	dp->rd_cursor = nc;
   2905      1.1   gdamore 	radeonfb_cursor_update(dp, wc->which);
   2906      1.1   gdamore 
   2907      1.1   gdamore 	return 0;
   2908      1.1   gdamore }
   2909      1.1   gdamore 
   2910      1.1   gdamore /*
   2911      1.1   gdamore  * Change the cursor shape.  Call this with the cursor locked to avoid
   2912      1.1   gdamore  * flickering/tearing.
   2913      1.1   gdamore  */
   2914      1.2  macallan static void
   2915      1.1   gdamore radeonfb_cursor_shape(struct radeonfb_display *dp)
   2916      1.1   gdamore {
   2917      1.1   gdamore 	uint8_t	and[512], xor[512];
   2918      1.1   gdamore 	int	i, j, src, dst, pitch;
   2919      1.1   gdamore 	const uint8_t	*msk = dp->rd_cursor.rc_mask;
   2920      1.1   gdamore 	const uint8_t	*img = dp->rd_cursor.rc_image;
   2921      1.1   gdamore 
   2922      1.1   gdamore 	/*
   2923      1.1   gdamore 	 * Radeon cursor data interleaves one line of AND data followed
   2924      1.1   gdamore 	 * by a line of XOR data.  (Each line corresponds to a whole hardware
   2925      1.1   gdamore 	 * pitch - i.e. 64 pixels or 8 bytes.)
   2926      1.1   gdamore 	 *
   2927      1.1   gdamore 	 * The cursor is displayed using the following table:
   2928      1.1   gdamore 	 *
   2929      1.1   gdamore 	 * AND	XOR	Result
   2930      1.1   gdamore 	 * ----------------------
   2931      1.1   gdamore 	 *  0    0	Cursor color 0
   2932      1.1   gdamore 	 *  0	 1	Cursor color 1
   2933      1.1   gdamore 	 *  1	 0	Transparent
   2934      1.1   gdamore 	 *  1	 1	Complement of background
   2935      1.1   gdamore 	 *
   2936      1.1   gdamore 	 * Our masks are therefore different from what we were passed.
   2937      1.1   gdamore 	 * Passed in, I'm assuming the data represents either color 0 or 1,
   2938      1.1   gdamore 	 * and a mask, so the passed in table looks like:
   2939      1.1   gdamore 	 *
   2940      1.1   gdamore 	 * IMG	Mask	Result
   2941      1.1   gdamore 	 * -----------------------
   2942      1.1   gdamore 	 *  0	 0	Transparent
   2943      1.1   gdamore 	 *  0	 1	Cursor color 0
   2944      1.1   gdamore 	 *  1	 0	Transparent
   2945      1.1   gdamore 	 *  1	 1	Cursor color 1
   2946      1.1   gdamore 	 *
   2947      1.1   gdamore 	 * IF mask bit == 1, AND = 0, XOR = color.
   2948      1.1   gdamore 	 * IF mask bit == 0, AND = 1, XOR = 0.
   2949      1.1   gdamore 	 *
   2950      1.1   gdamore 	 * hence:	AND = ~(mask);	XOR = color & ~(mask);
   2951      1.1   gdamore 	 */
   2952      1.1   gdamore 
   2953      1.1   gdamore 	pitch = ((dp->rd_cursor.rc_size.x + 7) / 8);
   2954      1.1   gdamore 
   2955      1.1   gdamore 	/* start by assuming all bits are transparent */
   2956      1.1   gdamore 	memset(and, 0xff, 512);
   2957      1.1   gdamore 	memset(xor, 0x00, 512);
   2958      1.1   gdamore 
   2959      1.1   gdamore 	src = 0;
   2960      1.1   gdamore 	dst = 0;
   2961      1.1   gdamore 	for (i = 0; i < 64; i++) {
   2962      1.1   gdamore 		for (j = 0; j < 64; j += 8) {
   2963      1.1   gdamore 			if ((i < dp->rd_cursor.rc_size.y) &&
   2964      1.1   gdamore 			    (j < dp->rd_cursor.rc_size.x)) {
   2965      1.1   gdamore 
   2966      1.1   gdamore 				/* take care to leave odd bits alone */
   2967      1.1   gdamore 				and[dst] &= ~(msk[src]);
   2968      1.1   gdamore 				xor[dst] = img[src] & msk[src];
   2969      1.1   gdamore 				src++;
   2970      1.1   gdamore 			}
   2971      1.1   gdamore 			dst++;
   2972      1.1   gdamore 		}
   2973      1.1   gdamore 	}
   2974      1.1   gdamore 
   2975      1.1   gdamore 	/* copy the image into place */
   2976      1.1   gdamore 	for (i = 0; i < 64; i++) {
   2977      1.1   gdamore 		memcpy((uint8_t *)dp->rd_curptr + (i * 16),
   2978      1.1   gdamore 		    &and[i * 8], 8);
   2979      1.1   gdamore 		memcpy((uint8_t *)dp->rd_curptr + (i * 16) + 8,
   2980      1.1   gdamore 		    &xor[i * 8], 8);
   2981      1.1   gdamore 	}
   2982      1.1   gdamore }
   2983      1.1   gdamore 
   2984      1.2  macallan static void
   2985      1.1   gdamore radeonfb_cursor_position(struct radeonfb_display *dp)
   2986      1.1   gdamore {
   2987      1.1   gdamore 	struct radeonfb_softc	*sc = dp->rd_softc;
   2988      1.1   gdamore 	uint32_t		offset, hvoff, hvpos;	/* registers */
   2989      1.1   gdamore 	uint32_t		coff;			/* cursor offset */
   2990      1.1   gdamore 	int			i, x, y, xoff, yoff, crtcoff;
   2991      1.1   gdamore 
   2992      1.1   gdamore 	/*
   2993      1.1   gdamore 	 * XXX: this also needs to handle pan/scan
   2994      1.1   gdamore 	 */
   2995      1.1   gdamore 	for (i = 0; i < dp->rd_ncrtcs; i++) {
   2996      1.1   gdamore 
   2997      1.1   gdamore 		struct radeonfb_crtc	*rcp = &dp->rd_crtcs[i];
   2998      1.1   gdamore 
   2999      1.1   gdamore 		if (rcp->rc_number) {
   3000      1.1   gdamore 			offset = RADEON_CUR2_OFFSET;
   3001      1.1   gdamore 			hvoff = RADEON_CUR2_HORZ_VERT_OFF;
   3002      1.1   gdamore 			hvpos = RADEON_CUR2_HORZ_VERT_POSN;
   3003      1.1   gdamore 			crtcoff = RADEON_CRTC2_OFFSET;
   3004      1.1   gdamore 		} else {
   3005      1.1   gdamore 			offset = RADEON_CUR_OFFSET;
   3006      1.1   gdamore 			hvoff = RADEON_CUR_HORZ_VERT_OFF;
   3007      1.1   gdamore 			hvpos = RADEON_CUR_HORZ_VERT_POSN;
   3008      1.1   gdamore 			crtcoff = RADEON_CRTC_OFFSET;
   3009      1.1   gdamore 		}
   3010      1.1   gdamore 
   3011      1.1   gdamore 		x = dp->rd_cursor.rc_pos.x;
   3012      1.1   gdamore 		y = dp->rd_cursor.rc_pos.y;
   3013      1.1   gdamore 
   3014      1.1   gdamore 		while (y < rcp->rc_yoffset) {
   3015      1.1   gdamore 			rcp->rc_yoffset -= RADEON_PANINCREMENT;
   3016      1.1   gdamore 		}
   3017      1.1   gdamore 		while (y >= (rcp->rc_yoffset + rcp->rc_videomode.vdisplay)) {
   3018      1.1   gdamore 			rcp->rc_yoffset += RADEON_PANINCREMENT;
   3019      1.1   gdamore 		}
   3020      1.1   gdamore 		while (x < rcp->rc_xoffset) {
   3021      1.1   gdamore 			rcp->rc_xoffset -= RADEON_PANINCREMENT;
   3022      1.1   gdamore 		}
   3023      1.1   gdamore 		while (x >= (rcp->rc_xoffset + rcp->rc_videomode.hdisplay)) {
   3024      1.1   gdamore 			rcp->rc_xoffset += RADEON_PANINCREMENT;
   3025      1.1   gdamore 		}
   3026      1.1   gdamore 
   3027      1.1   gdamore 		/* adjust for the cursor's hotspot */
   3028      1.1   gdamore 		x -= dp->rd_cursor.rc_hot.x;
   3029      1.1   gdamore 		y -= dp->rd_cursor.rc_hot.y;
   3030      1.1   gdamore 		xoff = yoff = 0;
   3031      1.1   gdamore 
   3032      1.1   gdamore 		if (x >= dp->rd_virtx)
   3033      1.1   gdamore 			x = dp->rd_virtx - 1;
   3034      1.1   gdamore 		if (y >= dp->rd_virty)
   3035      1.1   gdamore 			y = dp->rd_virty - 1;
   3036      1.1   gdamore 
   3037      1.1   gdamore 		/* now adjust cursor so it is relative to viewport */
   3038      1.1   gdamore 		x -= rcp->rc_xoffset;
   3039      1.1   gdamore 		y -= rcp->rc_yoffset;
   3040      1.1   gdamore 
   3041      1.1   gdamore 		/*
   3042      1.1   gdamore 		 * no need to check for fall off, because we should
   3043      1.1   gdamore 		 * never move off the screen entirely!
   3044      1.1   gdamore 		 */
   3045      1.1   gdamore 		coff = 0;
   3046      1.1   gdamore 		if (x < 0) {
   3047      1.1   gdamore 			xoff = -x;
   3048      1.1   gdamore 			x = 0;
   3049      1.1   gdamore 		}
   3050      1.1   gdamore 		if (y < 0) {
   3051      1.1   gdamore 			yoff = -y;
   3052      1.1   gdamore 			y = 0;
   3053      1.1   gdamore 			coff = (yoff * 2) * 8;
   3054      1.1   gdamore 		}
   3055      1.1   gdamore 
   3056      1.1   gdamore 		/* pan the display */
   3057      1.1   gdamore 		PUT32(sc, crtcoff, (rcp->rc_yoffset * dp->rd_stride) +
   3058      1.1   gdamore 		    rcp->rc_xoffset);
   3059      1.1   gdamore 
   3060      1.1   gdamore 		PUT32(sc, offset, (dp->rd_curoff + coff) | RADEON_CUR_LOCK);
   3061      1.1   gdamore 		PUT32(sc, hvoff, (xoff << 16) | (yoff) | RADEON_CUR_LOCK);
   3062      1.1   gdamore 		/* NB: this unlocks the cursor */
   3063      1.1   gdamore 		PUT32(sc, hvpos, (x << 16) | y);
   3064      1.1   gdamore 	}
   3065      1.1   gdamore }
   3066      1.1   gdamore 
   3067      1.2  macallan static void
   3068      1.1   gdamore radeonfb_cursor_visible(struct radeonfb_display *dp)
   3069      1.1   gdamore {
   3070      1.1   gdamore 	int		i;
   3071      1.1   gdamore 	uint32_t	gencntl, bit;
   3072      1.1   gdamore 
   3073      1.1   gdamore 	for (i = 0; i < dp->rd_ncrtcs; i++) {
   3074      1.1   gdamore 		if (dp->rd_crtcs[i].rc_number) {
   3075      1.1   gdamore 			gencntl = RADEON_CRTC2_GEN_CNTL;
   3076      1.1   gdamore 			bit = RADEON_CRTC2_CUR_EN;
   3077      1.1   gdamore 		} else {
   3078      1.1   gdamore 			gencntl = RADEON_CRTC_GEN_CNTL;
   3079      1.1   gdamore 			bit = RADEON_CRTC_CUR_EN;
   3080      1.1   gdamore 		}
   3081  1.7.2.2    bouyer 
   3082      1.1   gdamore 		if (dp->rd_cursor.rc_visible)
   3083      1.1   gdamore 			SET32(dp->rd_softc, gencntl, bit);
   3084      1.1   gdamore 		else
   3085      1.1   gdamore 			CLR32(dp->rd_softc, gencntl, bit);
   3086      1.1   gdamore 	}
   3087      1.1   gdamore }
   3088      1.1   gdamore 
   3089      1.2  macallan static void
   3090      1.1   gdamore radeonfb_cursor_cmap(struct radeonfb_display *dp)
   3091      1.1   gdamore {
   3092      1.1   gdamore 	int		i;
   3093      1.1   gdamore 	uint32_t	c0reg, c1reg;
   3094      1.1   gdamore 	struct radeonfb_softc	*sc = dp->rd_softc;
   3095      1.1   gdamore 
   3096      1.1   gdamore 	for (i = 0; i < dp->rd_ncrtcs; i++) {
   3097      1.1   gdamore 		if (dp->rd_crtcs[i].rc_number) {
   3098      1.1   gdamore 			c0reg = RADEON_CUR2_CLR0;
   3099      1.1   gdamore 			c1reg = RADEON_CUR2_CLR1;
   3100      1.1   gdamore 		} else {
   3101      1.1   gdamore 			c0reg = RADEON_CUR_CLR0;
   3102      1.1   gdamore 			c1reg = RADEON_CUR_CLR1;
   3103      1.1   gdamore 		}
   3104      1.1   gdamore 
   3105      1.1   gdamore 		PUT32(sc, c0reg, dp->rd_cursor.rc_cmap[0]);
   3106      1.1   gdamore 		PUT32(sc, c1reg, dp->rd_cursor.rc_cmap[1]);
   3107      1.1   gdamore 	}
   3108      1.1   gdamore }
   3109      1.1   gdamore 
   3110      1.2  macallan static void
   3111      1.1   gdamore radeonfb_cursor_update(struct radeonfb_display *dp, unsigned which)
   3112      1.1   gdamore {
   3113      1.1   gdamore 	struct radeonfb_softc	*sc;
   3114      1.1   gdamore 	int		i;
   3115      1.1   gdamore 
   3116      1.1   gdamore 	sc = dp->rd_softc;
   3117      1.1   gdamore 	for (i = 0; i < dp->rd_ncrtcs; i++) {
   3118      1.1   gdamore 		if (dp->rd_crtcs[i].rc_number) {
   3119      1.1   gdamore 			SET32(sc, RADEON_CUR2_OFFSET, RADEON_CUR_LOCK);
   3120      1.1   gdamore 		} else {
   3121      1.1   gdamore 			SET32(sc, RADEON_CUR_OFFSET,RADEON_CUR_LOCK);
   3122      1.1   gdamore 		}
   3123      1.1   gdamore 	}
   3124      1.1   gdamore 
   3125      1.1   gdamore 	if (which & WSDISPLAY_CURSOR_DOCMAP)
   3126      1.1   gdamore 		radeonfb_cursor_cmap(dp);
   3127      1.1   gdamore 
   3128      1.1   gdamore 	if (which & WSDISPLAY_CURSOR_DOSHAPE)
   3129      1.1   gdamore 		radeonfb_cursor_shape(dp);
   3130      1.1   gdamore 
   3131      1.1   gdamore 	if (which & WSDISPLAY_CURSOR_DOCUR)
   3132      1.1   gdamore 		radeonfb_cursor_visible(dp);
   3133      1.1   gdamore 
   3134      1.1   gdamore 	/* this one is unconditional, because it updates other stuff */
   3135      1.1   gdamore 	radeonfb_cursor_position(dp);
   3136      1.1   gdamore }
   3137      1.1   gdamore 
   3138      1.1   gdamore static struct videomode *
   3139      1.1   gdamore radeonfb_best_refresh(struct videomode *m1, struct videomode *m2)
   3140      1.1   gdamore {
   3141      1.1   gdamore 	int	r1, r2;
   3142      1.1   gdamore 
   3143      1.1   gdamore 	/* otherwise pick the higher refresh rate */
   3144      1.1   gdamore 	r1 = DIVIDE(DIVIDE(m1->dot_clock, m1->htotal), m1->vtotal);
   3145      1.1   gdamore 	r2 = DIVIDE(DIVIDE(m2->dot_clock, m2->htotal), m2->vtotal);
   3146      1.1   gdamore 
   3147      1.1   gdamore 	return (r1 < r2 ? m2 : m1);
   3148      1.1   gdamore }
   3149      1.1   gdamore 
   3150      1.1   gdamore static const struct videomode *
   3151  1.7.2.1    bouyer radeonfb_port_mode(struct radeonfb_softc *sc, struct radeonfb_port *rp,
   3152  1.7.2.1    bouyer     int x, int y)
   3153      1.1   gdamore {
   3154      1.1   gdamore 	struct edid_info	*ep = &rp->rp_edid;
   3155      1.1   gdamore 	struct videomode	*vmp = NULL;
   3156      1.1   gdamore 	int			i;
   3157      1.1   gdamore 
   3158      1.1   gdamore 	if (!rp->rp_edid_valid) {
   3159      1.1   gdamore 		/* fallback to safe mode */
   3160  1.7.2.1    bouyer 		return radeonfb_modelookup(sc->sc_defaultmode);
   3161      1.1   gdamore 	}
   3162  1.7.2.2    bouyer 
   3163      1.1   gdamore 	/* always choose the preferred mode first! */
   3164      1.1   gdamore 	if (ep->edid_preferred_mode) {
   3165      1.1   gdamore 
   3166      1.1   gdamore 		/* XXX: add auto-stretching support for native mode */
   3167      1.1   gdamore 
   3168      1.1   gdamore 		/* this may want panning to occur, btw */
   3169      1.1   gdamore 		if ((ep->edid_preferred_mode->hdisplay <= x) &&
   3170      1.1   gdamore 		    (ep->edid_preferred_mode->vdisplay <= y))
   3171      1.1   gdamore 			return ep->edid_preferred_mode;
   3172      1.1   gdamore 	}
   3173      1.1   gdamore 
   3174      1.1   gdamore 	for (i = 0; i < ep->edid_nmodes; i++) {
   3175      1.1   gdamore 		/*
   3176      1.1   gdamore 		 * We elect to pick a resolution that is too large for
   3177      1.1   gdamore 		 * the monitor than one that is too small.  This means
   3178      1.1   gdamore 		 * that we will prefer to pan rather than to try to
   3179      1.1   gdamore 		 * center a smaller display on a larger screen.  In
   3180      1.1   gdamore 		 * practice, this shouldn't matter because if a
   3181      1.1   gdamore 		 * monitor can support a larger resolution, it can
   3182      1.1   gdamore 		 * probably also support the smaller.  A specific
   3183      1.1   gdamore 		 * exception is fixed format panels, but hopefully
   3184      1.1   gdamore 		 * they are properly dealt with by the "autostretch"
   3185      1.1   gdamore 		 * logic above.
   3186      1.1   gdamore 		 */
   3187      1.1   gdamore 		if ((ep->edid_modes[i].hdisplay > x) ||
   3188      1.1   gdamore 		    (ep->edid_modes[i].vdisplay > y)) {
   3189      1.1   gdamore 			continue;
   3190      1.1   gdamore 		}
   3191      1.1   gdamore 
   3192      1.1   gdamore 		/*
   3193      1.1   gdamore 		 * at this point, the display mode is no larger than
   3194      1.1   gdamore 		 * what we've requested.
   3195      1.1   gdamore 		 */
   3196      1.1   gdamore 		if (vmp == NULL)
   3197      1.1   gdamore 			vmp = &ep->edid_modes[i];
   3198      1.1   gdamore 
   3199      1.1   gdamore 		/* eliminate smaller modes */
   3200      1.1   gdamore 		if ((vmp->hdisplay >= ep->edid_modes[i].hdisplay) ||
   3201      1.1   gdamore 		    (vmp->vdisplay >= ep->edid_modes[i].vdisplay))
   3202      1.1   gdamore 			continue;
   3203      1.1   gdamore 
   3204      1.1   gdamore 		if ((vmp->hdisplay < ep->edid_modes[i].hdisplay) ||
   3205      1.1   gdamore 		    (vmp->vdisplay < ep->edid_modes[i].vdisplay)) {
   3206      1.1   gdamore 			vmp = &ep->edid_modes[i];
   3207      1.1   gdamore 			continue;
   3208      1.1   gdamore 		}
   3209      1.1   gdamore 
   3210      1.1   gdamore 		KASSERT(vmp->hdisplay == ep->edid_modes[i].hdisplay);
   3211      1.1   gdamore 		KASSERT(vmp->vdisplay == ep->edid_modes[i].vdisplay);
   3212      1.1   gdamore 
   3213      1.1   gdamore 		vmp = radeonfb_best_refresh(vmp, &ep->edid_modes[i]);
   3214      1.1   gdamore 	}
   3215      1.1   gdamore 
   3216  1.7.2.1    bouyer 	return (vmp ? vmp : radeonfb_modelookup(sc->sc_defaultmode));
   3217      1.1   gdamore }
   3218      1.1   gdamore 
   3219      1.1   gdamore static int
   3220      1.1   gdamore radeonfb_hasres(struct videomode *list, int nlist, int x, int y)
   3221      1.1   gdamore {
   3222      1.1   gdamore 	int	i;
   3223      1.1   gdamore 
   3224      1.1   gdamore 	for (i = 0; i < nlist; i++) {
   3225      1.1   gdamore 		if ((x == list[i].hdisplay) &&
   3226      1.1   gdamore 		    (y == list[i].vdisplay)) {
   3227      1.1   gdamore 			return 1;
   3228      1.1   gdamore 		}
   3229      1.1   gdamore 	}
   3230      1.1   gdamore 	return 0;
   3231      1.1   gdamore }
   3232      1.1   gdamore 
   3233      1.2  macallan static void
   3234      1.1   gdamore radeonfb_pickres(struct radeonfb_display *dp, uint16_t *x, uint16_t *y,
   3235      1.1   gdamore     int pan)
   3236      1.1   gdamore {
   3237      1.1   gdamore 	struct radeonfb_port	*rp;
   3238      1.1   gdamore 	struct edid_info	*ep;
   3239      1.1   gdamore 	int			i, j;
   3240      1.1   gdamore 
   3241      1.1   gdamore 	*x = 0;
   3242      1.1   gdamore 	*y = 0;
   3243      1.1   gdamore 
   3244      1.1   gdamore 	if (pan) {
   3245      1.1   gdamore 		for (i = 0; i < dp->rd_ncrtcs; i++) {
   3246      1.1   gdamore 			rp = dp->rd_crtcs[i].rc_port;
   3247      1.1   gdamore 			ep = &rp->rp_edid;
   3248      1.1   gdamore 			if (!rp->rp_edid_valid) {
   3249      1.1   gdamore 				/* monitor not present */
   3250      1.1   gdamore 				continue;
   3251      1.1   gdamore 			}
   3252      1.1   gdamore 
   3253      1.1   gdamore 			/*
   3254      1.1   gdamore 			 * For now we are ignoring "conflict" that
   3255      1.1   gdamore 			 * could occur when mixing some modes like
   3256      1.1   gdamore 			 * 1280x1024 and 1400x800.  It isn't clear
   3257      1.1   gdamore 			 * which is better, so the first one wins.
   3258      1.1   gdamore 			 */
   3259      1.1   gdamore 			for (j = 0; j < ep->edid_nmodes; j++) {
   3260      1.1   gdamore 				/*
   3261      1.1   gdamore 				 * ignore resolutions that are too big for
   3262      1.1   gdamore 				 * the radeon
   3263      1.1   gdamore 				 */
   3264      1.1   gdamore 				if (ep->edid_modes[j].hdisplay >
   3265      1.1   gdamore 				    dp->rd_softc->sc_maxx)
   3266      1.1   gdamore 					continue;
   3267      1.1   gdamore 				if (ep->edid_modes[j].vdisplay >
   3268      1.1   gdamore 				    dp->rd_softc->sc_maxy)
   3269      1.1   gdamore 					continue;
   3270      1.1   gdamore 
   3271      1.1   gdamore 				/*
   3272      1.1   gdamore 				 * pick largest resolution, the
   3273      1.1   gdamore 				 * smaller monitor will pan
   3274      1.1   gdamore 				 */
   3275      1.1   gdamore 				if ((ep->edid_modes[j].hdisplay >= *x) &&
   3276      1.1   gdamore 				    (ep->edid_modes[j].vdisplay >= *y)) {
   3277      1.1   gdamore 					*x = ep->edid_modes[j].hdisplay;
   3278      1.1   gdamore 					*y = ep->edid_modes[j].vdisplay;
   3279      1.1   gdamore 				}
   3280      1.1   gdamore 			}
   3281      1.1   gdamore 		}
   3282      1.1   gdamore 
   3283      1.1   gdamore 	} else {
   3284      1.1   gdamore 		struct videomode	modes[64];
   3285      1.1   gdamore 		int			nmodes = 0;
   3286      1.1   gdamore 		int			valid = 0;
   3287      1.1   gdamore 
   3288      1.1   gdamore 		for (i = 0; i < dp->rd_ncrtcs; i++) {
   3289      1.1   gdamore 			/*
   3290      1.1   gdamore 			 * pick the largest resolution in common.
   3291      1.1   gdamore 			 */
   3292      1.1   gdamore 			rp = dp->rd_crtcs[i].rc_port;
   3293      1.1   gdamore 			ep = &rp->rp_edid;
   3294      1.1   gdamore 
   3295      1.1   gdamore 			if (!rp->rp_edid_valid)
   3296      1.1   gdamore 				continue;
   3297      1.1   gdamore 
   3298      1.1   gdamore 			if (!valid) {
   3299      1.1   gdamore 				/* initialize starting list */
   3300      1.1   gdamore 				for (j = 0; j < ep->edid_nmodes; j++) {
   3301      1.1   gdamore 					/*
   3302      1.1   gdamore 					 * ignore resolutions that are
   3303      1.1   gdamore 					 * too big for the radeon
   3304      1.1   gdamore 					 */
   3305      1.1   gdamore 					if (ep->edid_modes[j].hdisplay >
   3306      1.1   gdamore 					    dp->rd_softc->sc_maxx)
   3307      1.1   gdamore 						continue;
   3308      1.1   gdamore 					if (ep->edid_modes[j].vdisplay >
   3309      1.1   gdamore 					    dp->rd_softc->sc_maxy)
   3310      1.1   gdamore 						continue;
   3311      1.1   gdamore 
   3312      1.1   gdamore 					modes[nmodes] = ep->edid_modes[j];
   3313      1.1   gdamore 					nmodes++;
   3314      1.1   gdamore 				}
   3315      1.1   gdamore 				valid = 1;
   3316      1.1   gdamore 			} else {
   3317      1.1   gdamore 				/* merge into preexisting list */
   3318      1.1   gdamore 				for (j = 0; j < nmodes; j++) {
   3319      1.1   gdamore 					if (!radeonfb_hasres(ep->edid_modes,
   3320      1.1   gdamore 						ep->edid_nmodes,
   3321      1.1   gdamore 						modes[j].hdisplay,
   3322      1.1   gdamore 						modes[j].vdisplay)) {
   3323      1.1   gdamore 						modes[j] = modes[nmodes];
   3324      1.1   gdamore 						j--;
   3325      1.1   gdamore 						nmodes--;
   3326      1.1   gdamore 					}
   3327      1.1   gdamore 				}
   3328      1.1   gdamore 			}
   3329      1.1   gdamore 		}
   3330      1.1   gdamore 
   3331      1.1   gdamore 		/* now we have to pick from the merged list */
   3332      1.1   gdamore 		for (i = 0; i < nmodes; i++) {
   3333      1.1   gdamore 			if ((modes[i].hdisplay >= *x) &&
   3334      1.1   gdamore 			    (modes[i].vdisplay >= *y)) {
   3335      1.1   gdamore 				*x = modes[i].hdisplay;
   3336      1.1   gdamore 				*y = modes[i].vdisplay;
   3337      1.1   gdamore 			}
   3338      1.1   gdamore 		}
   3339      1.1   gdamore 	}
   3340      1.1   gdamore 
   3341      1.1   gdamore 	if ((*x == 0) || (*y == 0)) {
   3342      1.1   gdamore 		/* fallback to safe mode */
   3343      1.1   gdamore 		*x = 640;
   3344      1.1   gdamore 		*y = 480;
   3345      1.1   gdamore 	}
   3346      1.1   gdamore }
   3347  1.7.2.1    bouyer 
   3348  1.7.2.2    bouyer /*
   3349  1.7.2.2    bouyer  * backlight levels are linear on:
   3350  1.7.2.2    bouyer  * - RV200, RV250, RV280, RV350
   3351  1.7.2.2    bouyer  * - but NOT on PowerBook4,3 6,3 6,5
   3352  1.7.2.2    bouyer  * according to Linux' radeonfb
   3353  1.7.2.2    bouyer  */
   3354  1.7.2.1    bouyer 
   3355  1.7.2.1    bouyer /* Get the current backlight level for the display.  */
   3356  1.7.2.1    bouyer 
   3357  1.7.2.2    bouyer static int
   3358  1.7.2.1    bouyer radeonfb_get_backlight(struct radeonfb_display *dp)
   3359  1.7.2.1    bouyer {
   3360  1.7.2.1    bouyer 	int s;
   3361  1.7.2.1    bouyer 	uint32_t level;
   3362  1.7.2.1    bouyer 
   3363  1.7.2.1    bouyer 	s = spltty();
   3364  1.7.2.1    bouyer 
   3365  1.7.2.1    bouyer 	level = radeonfb_get32(dp->rd_softc, RADEON_LVDS_GEN_CNTL);
   3366  1.7.2.1    bouyer 	level &= RADEON_LVDS_BL_MOD_LEV_MASK;
   3367  1.7.2.1    bouyer 	level >>= RADEON_LVDS_BL_MOD_LEV_SHIFT;
   3368  1.7.2.1    bouyer 
   3369  1.7.2.2    bouyer 	/*
   3370  1.7.2.2    bouyer 	 * On some chips, we should negate the backlight level.
   3371  1.7.2.2    bouyer 	 * XXX Find out on which chips.
   3372  1.7.2.2    bouyer 	 */
   3373  1.7.2.2    bouyer 	if (dp->rd_softc->sc_flags & RFB_INV_BLIGHT)
   3374  1.7.2.2    bouyer 		level = RADEONFB_BACKLIGHT_MAX - level;
   3375  1.7.2.1    bouyer 
   3376  1.7.2.1    bouyer 	splx(s);
   3377  1.7.2.1    bouyer 
   3378  1.7.2.1    bouyer 	return level;
   3379  1.7.2.2    bouyer }
   3380  1.7.2.1    bouyer 
   3381  1.7.2.1    bouyer /* Set the backlight to the given level for the display.  */
   3382  1.7.2.1    bouyer 
   3383  1.7.2.2    bouyer static int
   3384  1.7.2.1    bouyer radeonfb_set_backlight(struct radeonfb_display *dp, int level)
   3385  1.7.2.1    bouyer {
   3386  1.7.2.1    bouyer 	struct radeonfb_softc *sc;
   3387  1.7.2.1    bouyer 	int rlevel, s;
   3388  1.7.2.1    bouyer 	uint32_t lvds;
   3389  1.7.2.1    bouyer 
   3390  1.7.2.1    bouyer 	s = spltty();
   3391  1.7.2.2    bouyer 
   3392  1.7.2.1    bouyer 	if (level < 0)
   3393  1.7.2.1    bouyer 		level = 0;
   3394  1.7.2.1    bouyer 	else if (level >= RADEONFB_BACKLIGHT_MAX)
   3395  1.7.2.1    bouyer 		level = RADEONFB_BACKLIGHT_MAX;
   3396  1.7.2.1    bouyer 
   3397  1.7.2.1    bouyer 	sc = dp->rd_softc;
   3398  1.7.2.1    bouyer 
   3399  1.7.2.1    bouyer 	/* On some chips, we should negate the backlight level. */
   3400  1.7.2.2    bouyer 	if (dp->rd_softc->sc_flags & RFB_INV_BLIGHT) {
   3401  1.7.2.2    bouyer 		rlevel = RADEONFB_BACKLIGHT_MAX - level;
   3402  1.7.2.2    bouyer 	} else
   3403  1.7.2.2    bouyer 		rlevel = level;
   3404  1.7.2.1    bouyer 
   3405  1.7.2.1    bouyer 	callout_stop(&dp->rd_bl_lvds_co);
   3406  1.7.2.1    bouyer 	radeonfb_engine_idle(sc);
   3407  1.7.2.1    bouyer 
   3408  1.7.2.2    bouyer 	/*
   3409  1.7.2.1    bouyer 	 * Turn off the display if the backlight is set to 0, since the
   3410  1.7.2.2    bouyer 	 * display is useless without backlight anyway.
   3411  1.7.2.1    bouyer 	 */
   3412  1.7.2.1    bouyer 	if (level == 0)
   3413  1.7.2.1    bouyer 		radeonfb_blank(dp, 1);
   3414  1.7.2.1    bouyer 	else if (radeonfb_get_backlight(dp) == 0)
   3415  1.7.2.1    bouyer 		radeonfb_blank(dp, 0);
   3416  1.7.2.2    bouyer 
   3417  1.7.2.1    bouyer 	lvds = radeonfb_get32(sc, RADEON_LVDS_GEN_CNTL);
   3418  1.7.2.1    bouyer 	lvds &= ~RADEON_LVDS_DISPLAY_DIS;
   3419  1.7.2.1    bouyer 	if (!(lvds & RADEON_LVDS_BLON) || !(lvds & RADEON_LVDS_ON)) {
   3420  1.7.2.1    bouyer 		lvds |= dp->rd_bl_lvds_val & RADEON_LVDS_DIGON;
   3421  1.7.2.1    bouyer 		lvds |= RADEON_LVDS_BLON | RADEON_LVDS_EN;
   3422  1.7.2.1    bouyer 		radeonfb_put32(sc, RADEON_LVDS_GEN_CNTL, lvds);
   3423  1.7.2.1    bouyer 		lvds &= ~RADEON_LVDS_BL_MOD_LEV_MASK;
   3424  1.7.2.1    bouyer 		lvds |= rlevel << RADEON_LVDS_BL_MOD_LEV_SHIFT;
   3425  1.7.2.1    bouyer 		lvds |= RADEON_LVDS_ON;
   3426  1.7.2.1    bouyer 		lvds |= dp->rd_bl_lvds_val & RADEON_LVDS_BL_MOD_EN;
   3427  1.7.2.1    bouyer 	} else {
   3428  1.7.2.1    bouyer 		lvds &= ~RADEON_LVDS_BL_MOD_LEV_MASK;
   3429  1.7.2.1    bouyer 		lvds |= rlevel << RADEON_LVDS_BL_MOD_LEV_SHIFT;
   3430  1.7.2.1    bouyer 		radeonfb_put32(sc, RADEON_LVDS_GEN_CNTL, lvds);
   3431  1.7.2.1    bouyer 	}
   3432  1.7.2.2    bouyer 
   3433  1.7.2.1    bouyer 	dp->rd_bl_lvds_val &= ~RADEON_LVDS_STATE_MASK;
   3434  1.7.2.1    bouyer 	dp->rd_bl_lvds_val |= lvds & RADEON_LVDS_STATE_MASK;
   3435  1.7.2.1    bouyer 	/* XXX What is the correct delay? */
   3436  1.7.2.2    bouyer 	callout_schedule(&dp->rd_bl_lvds_co, 200 * hz);
   3437  1.7.2.1    bouyer 
   3438  1.7.2.1    bouyer 	splx(s);
   3439  1.7.2.1    bouyer 
   3440  1.7.2.1    bouyer 	return 0;
   3441  1.7.2.1    bouyer }
   3442  1.7.2.1    bouyer 
   3443  1.7.2.2    bouyer /*
   3444  1.7.2.2    bouyer  * Callout function for delayed operations on the LVDS_GEN_CNTL register.
   3445  1.7.2.1    bouyer  * Set the delayed bits in the register, and clear the stored delayed
   3446  1.7.2.1    bouyer  * value.
   3447  1.7.2.1    bouyer  */
   3448  1.7.2.1    bouyer 
   3449  1.7.2.1    bouyer static void radeonfb_lvds_callout(void *arg)
   3450  1.7.2.1    bouyer {
   3451  1.7.2.1    bouyer 	struct radeonfb_display *dp = arg;
   3452  1.7.2.1    bouyer 	int s;
   3453  1.7.2.1    bouyer 
   3454  1.7.2.1    bouyer 	s = splhigh();
   3455  1.7.2.1    bouyer 
   3456  1.7.2.2    bouyer 	radeonfb_mask32(dp->rd_softc, RADEON_LVDS_GEN_CNTL, ~0,
   3457  1.7.2.1    bouyer 			dp->rd_bl_lvds_val);
   3458  1.7.2.1    bouyer 	dp->rd_bl_lvds_val = 0;
   3459  1.7.2.1    bouyer 
   3460  1.7.2.1    bouyer 	splx(s);
   3461  1.7.2.1    bouyer }
   3462