1 #ifdef HAVE_XORG_CONFIG_H
2 #include "xorg-config.h"
9 #include "xf86_OSproc.h"
10 #include <sys/ioctl.h>
11 #include <sys/types.h>
12 #include <sys/socket.h>
18 #define ACPI_SOCKET "/var/run/acpid.socket"
20 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
21 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
22 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
23 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
24 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
26 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
27 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
28 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
29 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
30 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
32 #define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
33 #define ACPI_VIDEO_HEAD_END (~0u)
35 static void lnxCloseACPI(void);
36 static pointer ACPIihPtr
= NULL
;
37 PMClose
lnxACPIOpen(void);
40 #define ACPI_REOPEN_DELAY 1000
43 lnxACPIReopen(OsTimerPtr timer
, CARD32 time
, pointer arg
)
50 return ACPI_REOPEN_DELAY
;
53 #define LINE_LENGTH 80
56 lnxACPIGetEventFromOs(int fd
, pmEvent
* events
, int num
)
61 memset(ev
, 0, LINE_LENGTH
);
64 n
= read(fd
, ev
, LINE_LENGTH
);
65 } while ((n
== -1) && (errno
== EAGAIN
|| errno
== EINTR
));
69 TimerSet(NULL
, 0, ACPI_REOPEN_DELAY
, lnxACPIReopen
, NULL
);
72 /* FIXME: this only processes the first read ACPI event & might break
73 * with interrupted reads. */
75 /* Check that we have a video event */
76 if (!strncmp(ev
, "video", 5)) {
80 char *data
= NULL
; /* doesn't appear to be used in the kernel */
81 unsigned long int notify_l
, data_l
;
83 video
= strtok(ev
, " ");
85 if (!(GFX
= strtok(NULL
, " ")))
88 ErrorF("GFX: %s\n", GFX
);
91 if (!(notify
= strtok(NULL
, " ")))
93 notify_l
= strtoul(notify
, NULL
, 16);
95 ErrorF("notify: 0x%lx\n", notify_l
);
98 if (!(data
= strtok(NULL
, " ")))
100 data_l
= strtoul(data
, NULL
, 16);
102 ErrorF("data: 0x%lx\n", data_l
);
105 /* Differentiate between events */
107 case ACPI_VIDEO_NOTIFY_SWITCH
:
108 case ACPI_VIDEO_NOTIFY_CYCLE
:
109 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT
:
110 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT
:
111 events
[0] = XF86_APM_CAPABILITY_CHANGED
;
113 case ACPI_VIDEO_NOTIFY_PROBE
:
124 lnxACPIConfirmEventToOs(int fd
, pmEvent event
)
126 /* No ability to send back to the kernel in ACPI */
137 struct sockaddr_un addr
;
139 static int warned
= 0;
141 DebugF("ACPI: OSPMOpen called\n");
142 if (ACPIihPtr
|| !xf86Info
.pmFlag
)
145 DebugF("ACPI: Opening device\n");
146 if ((fd
= socket(AF_UNIX
, SOCK_STREAM
, 0)) > -1) {
147 memset(&addr
, 0, sizeof(addr
));
148 addr
.sun_family
= AF_UNIX
;
149 strcpy(addr
.sun_path
, ACPI_SOCKET
);
150 if ((r
= connect(fd
, (struct sockaddr
*) &addr
, sizeof(addr
))) == -1) {
152 xf86MsgVerb(X_WARNING
, 3, "Open ACPI failed (%s) (%s)\n",
153 ACPI_SOCKET
, strerror(errno
));
161 xf86PMGetEventFromOs
= lnxACPIGetEventFromOs
;
162 xf86PMConfirmEventToOs
= lnxACPIConfirmEventToOs
;
163 ACPIihPtr
= xf86AddGeneralHandler(fd
, xf86HandlePMEvents
, NULL
);
164 xf86MsgVerb(X_INFO
, 3, "Open ACPI successful (%s)\n", ACPI_SOCKET
);
175 DebugF("ACPI: Closing device\n");
177 fd
= xf86RemoveGeneralHandler(ACPIihPtr
);