vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / accelerants / ati / mach64_dpms.cpp
blob6fc8b741056e37c5c1f3cf106e111d04ab4ecbb7
1 /*
2 Haiku ATI video driver adapted from the X.org ATI driver.
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
7 Copyright 2009 Haiku, Inc. All rights reserved.
8 Distributed under the terms of the MIT license.
10 Authors:
11 Gerald Zajac 2009
15 #include "accelerant.h"
16 #include "mach64.h"
20 uint32
21 Mach64_DPMSCapabilities(void)
23 // Return DPMS modes supported by this device.
25 return B_DPMS_ON | B_DPMS_STAND_BY | B_DPMS_SUSPEND | B_DPMS_OFF;
29 uint32
30 Mach64_GetDPMSMode(void)
32 // Return the current DPMS mode.
34 uint32 tmp = INREG(CRTC_GEN_CNTL);
35 uint32 mode;
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;
46 TRACE("Mach64_DPMSMode() mode: %d\n", mode);
47 return mode;
51 status_t
52 Mach64_SetDPMSMode(uint32 dpmsMode)
54 // Set the display into one of the Display Power Management modes,
55 // and return B_OK if successful, else return B_ERROR.
57 TRACE("Mach64_SetDPMSMode() mode: %d, display type: %d\n", dpmsMode, gInfo.sharedInfo->displayType);
59 int mask = (CRTC_HSYNC_DIS | CRTC_VSYNC_DIS);
61 switch (dpmsMode) {
62 case B_DPMS_ON:
63 // Screen: On; HSync: On, VSync: On.
64 OUTREGM(CRTC_GEN_CNTL, 0, mask);
65 break;
67 case B_DPMS_STAND_BY:
68 // Screen: Off; HSync: Off, VSync: On.
69 OUTREGM(CRTC_GEN_CNTL, CRTC_HSYNC_DIS, mask);
70 break;
72 case B_DPMS_SUSPEND:
73 // Screen: Off; HSync: On, VSync: Off.
74 OUTREGM(CRTC_GEN_CNTL, CRTC_VSYNC_DIS, mask);
75 break;
77 case B_DPMS_OFF:
78 // Screen: Off; HSync: Off, VSync: Off.
79 OUTREGM(CRTC_GEN_CNTL, mask, mask);
80 break;
82 default:
83 TRACE("Invalid DPMS mode %d\n", dpmsMode);
84 return B_ERROR;
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));
91 switch (dpmsMode) {
92 case B_DPMS_ON:
93 powerMgmt |= (POWER_BLON | AUTO_POWER_UP);
94 break;
96 case B_DPMS_STAND_BY:
97 powerMgmt |= STANDBY_NOW;
98 break;
100 case B_DPMS_SUSPEND:
101 powerMgmt |= SUSPEND_NOW;
102 break;
104 case B_DPMS_OFF:
105 powerMgmt |= STANDBY_NOW | SUSPEND_NOW;
106 break;
109 Mach64_PutLCDReg(LCD_POWER_MANAGEMENT, powerMgmt);
112 return B_OK;