Home | History | Annotate | Line # | Download | only in videomode
pickmode.c revision 1.1.6.2
      1  1.1.6.2  uebayasi /* $NetBSD: pickmode.c,v 1.1.6.2 2010/08/17 06:46:48 uebayasi Exp $ */
      2  1.1.6.2  uebayasi 
      3  1.1.6.2  uebayasi /*-
      4  1.1.6.2  uebayasi  * Copyright (c) 2006 The NetBSD Foundation
      5  1.1.6.2  uebayasi  * All rights reserved.
      6  1.1.6.2  uebayasi  *
      7  1.1.6.2  uebayasi  * this code was contributed to The NetBSD Foundation by Michael Lorenz
      8  1.1.6.2  uebayasi  *
      9  1.1.6.2  uebayasi  * Redistribution and use in source and binary forms, with or without
     10  1.1.6.2  uebayasi  * modification, are permitted provided that the following conditions
     11  1.1.6.2  uebayasi  * are met:
     12  1.1.6.2  uebayasi  * 1. Redistributions of source code must retain the above copyright
     13  1.1.6.2  uebayasi  *    notice, this list of conditions and the following disclaimer.
     14  1.1.6.2  uebayasi  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1.6.2  uebayasi  *    notice, this list of conditions and the following disclaimer in the
     16  1.1.6.2  uebayasi  *    documentation and/or other materials provided with the distribution.
     17  1.1.6.2  uebayasi  *
     18  1.1.6.2  uebayasi  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS
     19  1.1.6.2  uebayasi  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     20  1.1.6.2  uebayasi  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     21  1.1.6.2  uebayasi  * ARE DISCLAIMED.  IN NO EVENT SHALL THE NETBSD FOUNDATION BE LIABLE
     22  1.1.6.2  uebayasi  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23  1.1.6.2  uebayasi  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     24  1.1.6.2  uebayasi  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25  1.1.6.2  uebayasi  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     26  1.1.6.2  uebayasi  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     27  1.1.6.2  uebayasi  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     28  1.1.6.2  uebayasi  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  1.1.6.2  uebayasi  */
     30  1.1.6.2  uebayasi 
     31  1.1.6.2  uebayasi #include <sys/cdefs.h>
     32  1.1.6.2  uebayasi __KERNEL_RCSID(0, "$NetBSD: pickmode.c,v 1.1.6.2 2010/08/17 06:46:48 uebayasi Exp $");
     33  1.1.6.2  uebayasi 
     34  1.1.6.2  uebayasi #include <sys/param.h>
     35  1.1.6.2  uebayasi #include <dev/videomode/videomode.h>
     36  1.1.6.2  uebayasi #include "opt_videomode.h"
     37  1.1.6.2  uebayasi 
     38  1.1.6.2  uebayasi #ifdef PICKMODE_DEBUG
     39  1.1.6.2  uebayasi #define DPRINTF printf
     40  1.1.6.2  uebayasi #else
     41  1.1.6.2  uebayasi #define DPRINTF while (0) printf
     42  1.1.6.2  uebayasi #endif
     43  1.1.6.2  uebayasi 
     44  1.1.6.2  uebayasi const struct videomode *
     45  1.1.6.2  uebayasi pick_mode_by_dotclock(int width, int height, int dotclock)
     46  1.1.6.2  uebayasi {
     47  1.1.6.2  uebayasi 	const struct videomode *this, *best = NULL;
     48  1.1.6.2  uebayasi 	int i;
     49  1.1.6.2  uebayasi 
     50  1.1.6.2  uebayasi 	DPRINTF("%s: looking for %d x %d at up to %d kHz\n", __func__, width,
     51  1.1.6.2  uebayasi 	    height, dotclock);
     52  1.1.6.2  uebayasi 	for (i = 0; i < videomode_count; i++) {
     53  1.1.6.2  uebayasi 
     54  1.1.6.2  uebayasi 		this = &videomode_list[i];
     55  1.1.6.2  uebayasi 		if ((this->hdisplay != width) || (this->vdisplay != height) ||
     56  1.1.6.2  uebayasi 		    (this->dot_clock > dotclock))
     57  1.1.6.2  uebayasi 			continue;
     58  1.1.6.2  uebayasi 		if (best != NULL) {
     59  1.1.6.2  uebayasi 
     60  1.1.6.2  uebayasi 			if (this->dot_clock > best->dot_clock)
     61  1.1.6.2  uebayasi 				best = this;
     62  1.1.6.2  uebayasi 		} else
     63  1.1.6.2  uebayasi 			best = this;
     64  1.1.6.2  uebayasi 	}
     65  1.1.6.2  uebayasi 	if (best!= NULL)
     66  1.1.6.2  uebayasi 		DPRINTF("found %s\n", best->name);
     67  1.1.6.2  uebayasi 
     68  1.1.6.2  uebayasi 	return best;
     69  1.1.6.2  uebayasi }
     70  1.1.6.2  uebayasi 
     71  1.1.6.2  uebayasi const struct videomode *
     72  1.1.6.2  uebayasi pick_mode_by_ref(int width, int height, int refresh)
     73  1.1.6.2  uebayasi {
     74  1.1.6.2  uebayasi 	const struct videomode *this, *best = NULL;
     75  1.1.6.2  uebayasi 	int mref, closest = 1000, i, diff;
     76  1.1.6.2  uebayasi 
     77  1.1.6.2  uebayasi 	DPRINTF("%s: looking for %d x %d at up to %d Hz\n", __func__, width,
     78  1.1.6.2  uebayasi 	    height, refresh);
     79  1.1.6.2  uebayasi 	for (i = 0; i < videomode_count; i++) {
     80  1.1.6.2  uebayasi 
     81  1.1.6.2  uebayasi 		this = &videomode_list[i];
     82  1.1.6.2  uebayasi 		mref = this->dot_clock * 1000 / (this->htotal * this->vtotal);
     83  1.1.6.2  uebayasi 		diff = abs(mref - refresh);
     84  1.1.6.2  uebayasi 		if ((this->hdisplay != width) || (this->vdisplay != height) ||
     85  1.1.6.2  uebayasi 		    (diff > closest))
     86  1.1.6.2  uebayasi 			continue;
     87  1.1.6.2  uebayasi 		if (best != NULL) {
     88  1.1.6.2  uebayasi 
     89  1.1.6.2  uebayasi 			if (diff < closest) {
     90  1.1.6.2  uebayasi 
     91  1.1.6.2  uebayasi 				best = this;
     92  1.1.6.2  uebayasi 				closest = diff;
     93  1.1.6.2  uebayasi 			}
     94  1.1.6.2  uebayasi 		} else
     95  1.1.6.2  uebayasi 			best = this;
     96  1.1.6.2  uebayasi 	}
     97  1.1.6.2  uebayasi 	if (best!= NULL)
     98  1.1.6.2  uebayasi 		DPRINTF("found %s\n", best->name);
     99  1.1.6.2  uebayasi 
    100  1.1.6.2  uebayasi 	return best;
    101  1.1.6.2  uebayasi }
    102