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