1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
/***************************************************************************
* *
* Powersave Daemon *
* *
* Copyright (C) 2004,2005 SUSE Linux Products GmbH *
* *
* Author(s): Holger Macht <hmacht@suse.de> *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at you *
* option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
* *
***************************************************************************/
#include <stdlib.h>
#include <linux/types.h>
#include <linux/apm_bios.h>
#include <sys/ioctl.h>
#include "globals.h"
#include "apm.h"
#include "fcntl.h"
#include "cpufreq_management.h"
#include "event_management.h"
APM_Interface::APM_Interface():PM_Interface()
{
pDebug(DBG_INFO, "APM constructor");
/* disable temperature control for apm only acpi is supported */
Powersave::Globals::config_obj->current_scheme->ENABLE_THERMAL_MANAGEMENT = OFF;
/* nothing of this exists in apm */
_cooling_mode_supported = false;
_throttleInterface.disableThrottling();
_thermal_trip_points_supported = false;
}
APM_Interface::~APM_Interface()
{
close(_hwEvent_fd);
}
int APM_Interface::openHWEventFD()
{
/* from apmd ... */
/* Return a file descriptor for the apm_bios device, or -1 if there is an
* error. */
if ((_hwEvent_fd = open(APM_BIOS_DEV, O_RDWR)) < 0) {
/* Try to create it.
* Expect major and minor number 10/134
* This should work with driver version 1 and above
* (cannot access version number here)
* power lib does not provide it -> parse /proc/apm for version
* number. Old bios versions may need other major/minor numbers
* These can be read out from /proc/devices.
* do it yourself and send patch if you have such an old system ...
*/
if (mknod(APM_BIOS_DEV, S_IFCHR | S_IRUSR | S_IWUSR, makedev(10, 134))) {
unlink(APM_BIOS_DEV);
return -1;
}
if ((_hwEvent_fd = open(APM_BIOS_DEV, O_RDWR)) < 0) {
/* this should never happen */
pDebug(DBG_DIAG, "Could not open APM device " APM_BIOS_DEV);
return -1;
}
}
return _hwEvent_fd;
}
int APM_Interface::openAcpidSocket()
{
return 1;
}
int APM_Interface::handleHWEventRequest(int fd)
{
int nr;
// from /usr/include/linux/apm_bios.h
/* Be careful this event structure has nothing to do
with the powersave events. */
apm_event_t events[MAX_EVENTS];
nr = read(_hwEvent_fd, events, MAX_EVENTS * sizeof(apm_event_t)) / sizeof(apm_event_t);
if (nr < 0) {
pDebug(DBG_WARN, "Error reading from apm event file");
return nr;
}
// process events
for (int x = 0; x < nr; x++) {
// code partly pasted from apmd...
switch (events[x]) {
case APM_POWER_STATUS_CHANGE:
pDebug(DBG_INFO, "APM - Power status change event occured");
break;
case APM_LOW_BATTERY:
pDebug(DBG_INFO,
"APM - Low Battery event occured");
checkBatteryStateChanges();
break;
#ifdef APM_CAPABILITY_CHANGE
case APM_CAPABILITY_CHANGE:
pDebug(DBG_INFO,
"APM - Capability change event occured");
checkACStateChanges();
checkBatteryStateChanges();
break;
#endif // APM_CAPABILITY_CHANGE
default:
/* other events are not errors,
see the APM BIOS 1.2 spec or apmd.
*/
pDebug(DBG_DIAG,
"Received unknown APM event: 0x%04x.", events[x]);
}
}
// never returns an error at the moment
return 1;
}
void APM_Interface::activateSettings()
{
/* nothing special to do for apm */
PM_Interface::activateSettings();
}
|