xref: /haiku/src/add-ons/accelerants/intel_810/i810_watermark.cpp (revision 579f1dbca962a2a03df54f69fdc6e9423f91f20e)
1 /*
2  * Copyright 2012 Haiku, Inc.  All rights reserved.
3  * Distributed under the terms of the MIT license.
4  *
5  * Authors:
6  *		Gerald Zajac
7  */
8 
9 // The code in this file was adapted from the X.org intel driver which had
10 // the following copyright and license.
11 
12 /**************************************************************************
13 Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
14 All Rights Reserved.
15 
16 Permission is hereby granted, free of charge, to any person obtaining a
17 copy of this software and associated documentation files (the
18 "Software"), to deal in the Software without restriction, including
19 without limitation the rights to use, copy, modify, merge, publish,
20 distribute, sub license, and/or sell copies of the Software, and to
21 permit persons to whom the Software is furnished to do so, subject to
22 the following conditions:
23 
24 The above copyright notice and this permission notice (including the
25 next paragraph) shall be included in all copies or substantial portions
26 of the Software.
27 
28 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
29 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
31 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
32 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
33 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
34 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 **************************************************************************/
36 
37 
38 #include "accelerant.h"
39 
40 
41 struct WatermarkInfo {
42 	double freq;
43 	uint32 watermark;
44 };
45 
46 static WatermarkInfo watermarks_8[] = {
47 	{	0, 0x22003000},
48 	{25.2, 0x22003000},
49 	{28.0, 0x22003000},
50 	{31.5, 0x22003000},
51 	{36.0, 0x22007000},
52 	{40.0, 0x22007000},
53 	{45.0, 0x22007000},
54 	{49.5, 0x22008000},
55 	{50.0, 0x22008000},
56 	{56.3, 0x22008000},
57 	{65.0, 0x22008000},
58 	{75.0, 0x22008000},
59 	{78.8, 0x22008000},
60 	{80.0, 0x22008000},
61 	{94.0, 0x22008000},
62 	{96.0, 0x22107000},
63 	{99.0, 0x22107000},
64 	{108.0, 0x22107000},
65 	{121.0, 0x22107000},
66 	{128.9, 0x22107000},
67 	{132.0, 0x22109000},
68 	{135.0, 0x22109000},
69 	{157.5, 0x2210b000},
70 	{162.0, 0x2210b000},
71 	{175.5, 0x2210b000},
72 	{189.0, 0x2220e000},
73 	{202.5, 0x2220e000}
74 };
75 
76 static WatermarkInfo watermarks_16[] = {
77 	{	0, 0x22004000},
78 	{25.2, 0x22006000},
79 	{28.0, 0x22006000},
80 	{31.5, 0x22007000},
81 	{36.0, 0x22007000},
82 	{40.0, 0x22007000},
83 	{45.0, 0x22007000},
84 	{49.5, 0x22009000},
85 	{50.0, 0x22009000},
86 	{56.3, 0x22108000},
87 	{65.0, 0x2210e000},
88 	{75.0, 0x2210e000},
89 	{78.8, 0x2210e000},
90 	{80.0, 0x22210000},
91 	{94.5, 0x22210000},
92 	{96.0, 0x22210000},
93 	{99.0, 0x22210000},
94 	{108.0, 0x22210000},
95 	{121.0, 0x22210000},
96 	{128.9, 0x22210000},
97 	{132.0, 0x22314000},
98 	{135.0, 0x22314000},
99 	{157.5, 0x22415000},
100 	{162.0, 0x22416000},
101 	{175.5, 0x22416000},
102 	{189.0, 0x22416000},
103 	{195.0, 0x22416000},
104 	{202.5, 0x22416000}
105 };
106 
107 
108 uint32
109 I810_GetWatermark(const DisplayModeEx& mode)
110 {
111 	WatermarkInfo *table;
112 	uint32 tableLen;
113 
114 	// Get burst length and FIFO watermark based upon the bus frequency and
115 	// pixel clock.
116 
117 	switch (mode.bitsPerPixel) {
118 		case 8:
119 			table = watermarks_8;
120 			tableLen = ARRAY_SIZE(watermarks_8);
121 			break;
122 		case 16:
123 			table = watermarks_16;
124 			tableLen = ARRAY_SIZE(watermarks_16);
125 			break;
126 		default:
127 			return 0;
128 	}
129 
130 	uint32 i;
131 	double clockFreq = mode.timing.pixel_clock / 1000.0;
132 
133 	for (i = 0; i < tableLen && table[i].freq < clockFreq; i++)
134 		;
135 
136 	if (i == tableLen)
137 		i--;
138 
139 	TRACE("chosen watermark 0x%lx  (freq %f)\n", table[i].watermark,
140 		table[i].freq);
141 
142 	return table[i].watermark;
143 }
144