xref: /haiku/src/add-ons/accelerants/intel_extreme/PanelFitter.cpp (revision 4a32f48e70297d9a634646f01e08c2f451ecd6bd)
1 /*
2  * Copyright 2011, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Michael Lotz, mmlr@mlotz.ch
7  */
8 
9 
10 #include "PanelFitter.h"
11 
12 #include <stdlib.h>
13 #include <string.h>
14 #include <Debug.h>
15 
16 #include "accelerant.h"
17 #include "intel_extreme.h"
18 
19 
20 #undef TRACE
21 #define TRACE_FITTER
22 #ifdef TRACE_FITTER
23 #   define TRACE(x...) _sPrintf("intel_extreme: " x)
24 #else
25 #   define TRACE(x...)
26 #endif
27 
28 #define ERROR(x...) _sPrintf("intel_extreme: " x)
29 #define CALLED(x...) TRACE("CALLED %s\n", __PRETTY_FUNCTION__)
30 
31 
32 // #pragma mark - PanelFitter
33 
34 
35 PanelFitter::PanelFitter(pipe_index pipeIndex)
36 	:
37 	fRegisterBase(PCH_PANEL_FITTER_BASE_REGISTER)
38 {
39 	if (pipeIndex == INTEL_PIPE_B) {
40 		fRegisterBase += PCH_PANEL_FITTER_PIPE_OFFSET;
41 	}
42 	if (pipeIndex == INTEL_PIPE_C) {
43 		fRegisterBase += 2 * PCH_PANEL_FITTER_PIPE_OFFSET;
44 	}
45 }
46 
47 
48 PanelFitter::~PanelFitter()
49 {
50 }
51 
52 
53 bool
54 PanelFitter::IsEnabled()
55 {
56 	return (read32(fRegisterBase + PCH_PANEL_FITTER_CONTROL)
57 		& PANEL_FITTER_ENABLED) != 0;
58 }
59 
60 
61 void
62 PanelFitter::Enable(const display_mode& mode)
63 {
64 	_Enable(true);
65 
66 	// TODO: program the window position based on the mode, setup/select filter
67 	// Note: for now assuming fitter was setup by BIOS and pipeA has fitterA, etc.
68 	TRACE("%s: PCH_PANEL_FITTER_CONTROL, 0x%" B_PRIx32 "\n", __func__, read32(fRegisterBase + PCH_PANEL_FITTER_CONTROL));
69 	TRACE("%s: PCH_PANEL_FITTER_WINDOW_POS, 0x%" B_PRIx32 "\n", __func__, read32(fRegisterBase + PCH_PANEL_FITTER_WINDOW_POS));
70 
71 	// Window size _must_ be the last register programmed as it 'arms'/unlocks all the other ones..
72 	write32(fRegisterBase + PCH_PANEL_FITTER_WINDOW_SIZE, (mode.timing.h_display << 16) | mode.timing.v_display);
73 }
74 
75 
76 void
77 PanelFitter::Disable()
78 {
79 	_Enable(false);
80 
81 	// Window size _must_ be the last register programmed as it 'arms'/unlocks all the other ones..
82 	write32(fRegisterBase + PCH_PANEL_FITTER_WINDOW_SIZE, 0);
83 }
84 
85 
86 void
87 PanelFitter::_Enable(bool enable)
88 {
89 	uint32 targetRegister = fRegisterBase + PCH_PANEL_FITTER_CONTROL;
90 	write32(targetRegister, (read32(targetRegister) & ~PANEL_FITTER_ENABLED)
91 		| (enable ? PANEL_FITTER_ENABLED : 0));
92 	read32(targetRegister);
93 }
94