xref: /haiku/src/add-ons/accelerants/ati/mach64_dpms.cpp (revision 80829ec813241c9a702a45e39929286f13c55093)
1*80829ec8SRene Gollent /*
2*80829ec8SRene Gollent 	Haiku ATI video driver adapted from the X.org ATI driver.
3*80829ec8SRene Gollent 
4*80829ec8SRene Gollent 	Copyright 1992,1993,1994,1995,1996,1997 by Kevin E. Martin, Chapel Hill, North Carolina.
5*80829ec8SRene Gollent 	Copyright 1997 through 2004 by Marc Aurele La France (TSI @ UQV), tsi@xfree86.org
6*80829ec8SRene Gollent 
7*80829ec8SRene Gollent 	Copyright 2009 Haiku, Inc.  All rights reserved.
8*80829ec8SRene Gollent 	Distributed under the terms of the MIT license.
9*80829ec8SRene Gollent 
10*80829ec8SRene Gollent 	Authors:
11*80829ec8SRene Gollent 	Gerald Zajac 2009
12*80829ec8SRene Gollent */
13*80829ec8SRene Gollent 
14*80829ec8SRene Gollent 
15*80829ec8SRene Gollent #include "accelerant.h"
16*80829ec8SRene Gollent #include "mach64.h"
17*80829ec8SRene Gollent 
18*80829ec8SRene Gollent 
19*80829ec8SRene Gollent 
20*80829ec8SRene Gollent uint32
Mach64_DPMSCapabilities(void)21*80829ec8SRene Gollent Mach64_DPMSCapabilities(void)
22*80829ec8SRene Gollent {
23*80829ec8SRene Gollent 	// Return DPMS modes supported by this device.
24*80829ec8SRene Gollent 
25*80829ec8SRene Gollent 	return B_DPMS_ON | B_DPMS_STAND_BY | B_DPMS_SUSPEND | B_DPMS_OFF;
26*80829ec8SRene Gollent }
27*80829ec8SRene Gollent 
28*80829ec8SRene Gollent 
29*80829ec8SRene Gollent uint32
Mach64_GetDPMSMode(void)30*80829ec8SRene Gollent Mach64_GetDPMSMode(void)
31*80829ec8SRene Gollent {
32*80829ec8SRene Gollent 	// Return the current DPMS mode.
33*80829ec8SRene Gollent 
34*80829ec8SRene Gollent 	uint32 tmp = INREG(CRTC_GEN_CNTL);
35*80829ec8SRene Gollent 	uint32 mode;
36*80829ec8SRene Gollent 
37*80829ec8SRene Gollent 	if( (tmp & CRTC_DISPLAY_DIS) == 0 )
38*80829ec8SRene Gollent 		mode = B_DPMS_ON;
39*80829ec8SRene Gollent 	else if( (tmp & CRTC_VSYNC_DIS) == 0 )
40*80829ec8SRene Gollent 		mode = B_DPMS_STAND_BY;
41*80829ec8SRene Gollent 	else if( (tmp & CRTC_HSYNC_DIS) == 0 )
42*80829ec8SRene Gollent 		mode = B_DPMS_SUSPEND;
43*80829ec8SRene Gollent 	else
44*80829ec8SRene Gollent 		mode = B_DPMS_OFF;
45*80829ec8SRene Gollent 
46*80829ec8SRene Gollent 	TRACE("Mach64_DPMSMode() mode: %d\n", mode);
47*80829ec8SRene Gollent 	return mode;
48*80829ec8SRene Gollent }
49*80829ec8SRene Gollent 
50*80829ec8SRene Gollent 
51*80829ec8SRene Gollent status_t
Mach64_SetDPMSMode(uint32 dpmsMode)52*80829ec8SRene Gollent Mach64_SetDPMSMode(uint32 dpmsMode)
53*80829ec8SRene Gollent {
54*80829ec8SRene Gollent 	// Set the display into one of the Display Power Management modes,
55*80829ec8SRene Gollent 	// and return B_OK if successful, else return B_ERROR.
56*80829ec8SRene Gollent 
57*80829ec8SRene Gollent 	TRACE("Mach64_SetDPMSMode() mode: %d, display type: %d\n", dpmsMode, gInfo.sharedInfo->displayType);
58*80829ec8SRene Gollent 
59*80829ec8SRene Gollent 	int mask = (CRTC_HSYNC_DIS | CRTC_VSYNC_DIS);
60*80829ec8SRene Gollent 
61*80829ec8SRene Gollent 	switch (dpmsMode) {
62*80829ec8SRene Gollent 		case B_DPMS_ON:
63*80829ec8SRene Gollent 			// Screen: On; HSync: On, VSync: On.
64*80829ec8SRene Gollent 			OUTREGM(CRTC_GEN_CNTL, 0, mask);
65*80829ec8SRene Gollent 			break;
66*80829ec8SRene Gollent 
67*80829ec8SRene Gollent 		case B_DPMS_STAND_BY:
68*80829ec8SRene Gollent 			// Screen: Off; HSync: Off, VSync: On.
69*80829ec8SRene Gollent 			OUTREGM(CRTC_GEN_CNTL, CRTC_HSYNC_DIS, mask);
70*80829ec8SRene Gollent 			break;
71*80829ec8SRene Gollent 
72*80829ec8SRene Gollent 		case B_DPMS_SUSPEND:
73*80829ec8SRene Gollent 			// Screen: Off; HSync: On, VSync: Off.
74*80829ec8SRene Gollent 			OUTREGM(CRTC_GEN_CNTL, CRTC_VSYNC_DIS, mask);
75*80829ec8SRene Gollent 			break;
76*80829ec8SRene Gollent 
77*80829ec8SRene Gollent 		case B_DPMS_OFF:
78*80829ec8SRene Gollent 			// Screen: Off; HSync: Off, VSync: Off.
79*80829ec8SRene Gollent 			OUTREGM(CRTC_GEN_CNTL, mask, mask);
80*80829ec8SRene Gollent 			break;
81*80829ec8SRene Gollent 
82*80829ec8SRene Gollent 		default:
83*80829ec8SRene Gollent 			TRACE("Invalid DPMS mode %d\n", dpmsMode);
84*80829ec8SRene Gollent 			return B_ERROR;
85*80829ec8SRene Gollent 	}
86*80829ec8SRene Gollent 
87*80829ec8SRene Gollent 	if (gInfo.sharedInfo->displayType == MT_LAPTOP) {
88*80829ec8SRene Gollent 		uint32 powerMgmt = (Mach64_GetLCDReg(LCD_POWER_MANAGEMENT)
89*80829ec8SRene Gollent 			& ~(STANDBY_NOW | SUSPEND_NOW | POWER_BLON | AUTO_POWER_UP));
90*80829ec8SRene Gollent 
91*80829ec8SRene Gollent 		switch (dpmsMode) {
92*80829ec8SRene Gollent 		case B_DPMS_ON:
93*80829ec8SRene Gollent 			powerMgmt |= (POWER_BLON | AUTO_POWER_UP);
94*80829ec8SRene Gollent 			break;
95*80829ec8SRene Gollent 
96*80829ec8SRene Gollent 		case B_DPMS_STAND_BY:
97*80829ec8SRene Gollent 			powerMgmt |= STANDBY_NOW;
98*80829ec8SRene Gollent 			break;
99*80829ec8SRene Gollent 
100*80829ec8SRene Gollent 		case B_DPMS_SUSPEND:
101*80829ec8SRene Gollent 			powerMgmt |= SUSPEND_NOW;
102*80829ec8SRene Gollent 			break;
103*80829ec8SRene Gollent 
104*80829ec8SRene Gollent 		case B_DPMS_OFF:
105*80829ec8SRene Gollent 			powerMgmt |= STANDBY_NOW | SUSPEND_NOW;
106*80829ec8SRene Gollent 			break;
107*80829ec8SRene Gollent 		}
108*80829ec8SRene Gollent 
109*80829ec8SRene Gollent 		Mach64_PutLCDReg(LCD_POWER_MANAGEMENT, powerMgmt);
110*80829ec8SRene Gollent 	}
111*80829ec8SRene Gollent 
112*80829ec8SRene Gollent 	return B_OK;
113*80829ec8SRene Gollent }
114*80829ec8SRene Gollent 
115