1 /* Based on hw/xfree86/os-support/bsd/bsd_apm.c which bore no explicit
2 * copyright notice, so is covered by the following notice:
4 * Copyright (C) 1994-2003 The XFree86 Project, Inc. All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
21 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Except as contained in this notice, the name of the XFree86 Project shall
25 * not be used in advertising or otherwise to promote the sale, use or other
26 * dealings in this Software without prior written authorization from the
30 /* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
32 * Permission is hereby granted, free of charge, to any person obtaining a
33 * copy of this software and associated documentation files (the
34 * "Software"), to deal in the Software without restriction, including
35 * without limitation the rights to use, copy, modify, merge, publish,
36 * distribute, and/or sell copies of the Software, and to permit persons
37 * to whom the Software is furnished to do so, provided that the above
38 * copyright notice(s) and this permission notice appear in all copies of
39 * the Software and that both the above copyright notice(s) and this
40 * permission notice appear in supporting documentation.
42 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
43 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
45 * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
46 * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
47 * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
48 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
49 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
50 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
52 * Except as contained in this notice, the name of a copyright holder
53 * shall not be used in advertising or otherwise to promote the sale, use
54 * or other dealings in this Software without prior written authorization
55 * of the copyright holder.
58 #ifdef HAVE_XORG_CONFIG_H
59 #include <xorg-config.h>
67 #include "xf86_OSproc.h"
68 #include "xf86_OSlib.h"
70 #ifndef PLEASE_FIX_THIS
71 #define APM_STANDBY_REQ 0xa01
72 #define APM_SUSPEND_REQ 0xa02
73 #define APM_NORMAL_RESUME 0xa03
74 #define APM_CRIT_RESUME 0xa04
75 #define APM_BATTERY_LOW 0xa05
76 #define APM_POWER_CHANGE 0xa06
77 #define APM_UPDATE_TIME 0xa07
78 #define APM_CRIT_SUSPEND_REQ 0xa08
79 #define APM_USER_STANDBY_REQ 0xa09
80 #define APM_USER_SUSPEND_REQ 0xa0a
81 #define APM_SYS_STANDBY_RESUME 0xa0b
82 #define APM_IOC_NEXTEVENT 0xa0c
83 #define APM_IOC_RESUME 0xa0d
84 #define APM_IOC_SUSPEND 0xa0e
85 #define APM_IOC_STANDBY 0xa0f
88 typedef struct apm_event_info
94 This may be replaced with a better device name
97 #define APM_DEVICE "/dev/srn"
98 #define APM_DEVICE1 "/dev/apm"
100 static pointer APMihPtr
= NULL
;
101 static void sunCloseAPM(void);
106 } sunToXF86Array
[] = {
107 { APM_STANDBY_REQ
, XF86_APM_SYS_STANDBY
},
108 { APM_SUSPEND_REQ
, XF86_APM_SYS_SUSPEND
},
109 { APM_NORMAL_RESUME
, XF86_APM_NORMAL_RESUME
},
110 { APM_CRIT_RESUME
, XF86_APM_CRITICAL_RESUME
},
111 { APM_BATTERY_LOW
, XF86_APM_LOW_BATTERY
},
112 { APM_POWER_CHANGE
, XF86_APM_POWER_STATUS_CHANGE
},
113 { APM_UPDATE_TIME
, XF86_APM_UPDATE_TIME
},
114 { APM_CRIT_SUSPEND_REQ
, XF86_APM_CRITICAL_SUSPEND
},
115 { APM_USER_STANDBY_REQ
, XF86_APM_USER_STANDBY
},
116 { APM_USER_SUSPEND_REQ
, XF86_APM_USER_SUSPEND
},
117 { APM_SYS_STANDBY_RESUME
, XF86_APM_STANDBY_RESUME
},
118 #ifdef APM_CAPABILITY_CHANGE
119 { APM_CAPABILITY_CHANGE
, XF86_APM_CAPABILITY_CHANGED
},
123 #define numApmEvents (sizeof(sunToXF86Array) / sizeof(sunToXF86Array[0]))
130 for (i
= 0; i
< numApmEvents
; i
++) {
131 if (type
== sunToXF86Array
[i
].apmBsd
) {
132 return sunToXF86Array
[i
].xf86
;
135 return XF86_APM_UNKNOWN
;
139 * APM events can be requested direclty from /dev/apm
142 sunPMGetEventFromOS(int fd
, pmEvent
*events
, int num
)
144 struct apm_event_info sunEvent
;
147 for (i
= 0; i
< num
; i
++) {
149 if (ioctl(fd
, APM_IOC_NEXTEVENT
, &sunEvent
) < 0) {
150 if (errno
!= EAGAIN
) {
151 xf86Msg(X_WARNING
, "sunPMGetEventFromOS: APM_IOC_NEXTEVENT"
152 " errno = %d\n", errno
);
156 events
[i
] = sunToXF86(sunEvent
.type
);
158 xf86Msg(X_WARNING
, "Got some events\n");
163 sunPMConfirmEventToOs(int fd
, pmEvent event
)
166 /* XXX: NOT CURRENTLY RETURNED FROM OS */
167 case XF86_APM_SYS_STANDBY
:
168 case XF86_APM_USER_STANDBY
:
169 if (ioctl( fd
, APM_IOC_STANDBY
, NULL
) == 0)
170 return PM_WAIT
; /* should we stop the Xserver in standby, too? */
173 case XF86_APM_SYS_SUSPEND
:
174 case XF86_APM_CRITICAL_SUSPEND
:
175 case XF86_APM_USER_SUSPEND
:
176 xf86Msg(X_WARNING
, "Got SUSPENDED\n");
177 if (ioctl( fd
, APM_IOC_SUSPEND
, NULL
) == 0)
180 xf86Msg(X_WARNING
, "sunPMConfirmEventToOs: APM_IOC_SUSPEND"
181 " errno = %d\n", errno
);
184 case XF86_APM_STANDBY_RESUME
:
185 case XF86_APM_NORMAL_RESUME
:
186 case XF86_APM_CRITICAL_RESUME
:
187 case XF86_APM_STANDBY_FAILED
:
188 case XF86_APM_SUSPEND_FAILED
:
189 xf86Msg(X_WARNING
, "Got RESUME\n");
190 if (ioctl( fd
, APM_IOC_RESUME
, NULL
) == 0)
193 xf86Msg(X_WARNING
, "sunPMConfirmEventToOs: APM_IOC_RESUME"
194 " errno = %d\n", errno
);
207 if (APMihPtr
|| !xf86Info
.pmFlag
) {
211 if ((fd
= open(APM_DEVICE
, O_RDWR
)) == -1) {
212 if ((fd
= open(APM_DEVICE1
, O_RDWR
)) == -1) {
216 xf86PMGetEventFromOs
= sunPMGetEventFromOS
;
217 xf86PMConfirmEventToOs
= sunPMConfirmEventToOs
;
218 APMihPtr
= xf86AddInputHandler(fd
, xf86HandlePMEvents
, NULL
);
228 fd
= xf86RemoveInputHandler(APMihPtr
);