summaryrefslogtreecommitdiff
path: root/sysutils/klaptopdaemon/files/extrapatch-acpi-support
blob: 915d452907fe894cef6276c387d04bf25d732013 (plain) (blame)
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
--- klaptopdaemon/portable.cpp.orig	2007-09-14 18:54:04.000000000 +0400
+++ klaptopdaemon/portable.cpp	2007-09-14 18:54:18.000000000 +0400
@@ -2001,7 +2001,488 @@
 	return(0);
 }
 
-#elif defined(__FreeBSD__) && HAVE_MACHINE_APM_BIOS_H
+#elif defined(__FreeBSD__) 
+
+#include <osreldate.h>
+
+#if __FreeBSD_version >= 502010 
+
+/*
+** This is the FreeBSD-specific code for FreeBSD newer than 5.2.1.
+*/
+
+#include <sys/param.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sysexits.h>
+#include <unistd.h>
+
+#include <dev/acpica/acpiio.h>
+
+#define ACPIDEV         "/dev/acpi"
+
+
+#include <qpushbutton.h>
+#include <qobject.h>
+#include <kactivelabel.h>
+#include <kprocess.h>
+
+//
+//	returns 1 if we support power management
+//
+/*
+791:int laptop_portable::has_apm(int type)
+806:int laptop_portable::has_acpi(int type)
+857:int laptop_portable::has_power_management()
+873:int laptop_portable::has_battery_time()
+886:int laptop_portable::has_suspend()
+903:int laptop_portable::has_standby()
+921:int laptop_portable::has_hibernation()
+940:KActiveLabel *laptop_portable::no_power_management_explanation(QWidget *parent)
+955:QLabel *laptop_portable::how_to_do_suspend_resume(QWidget *parent)
+1041:QLabel *laptop_portable::pcmcia_info(int x, QWidget *parent)
+1062:void laptop_portable::invoke_standby()
+1096:void laptop_portable::invoke_suspend()
+1135:void laptop_portable::invoke_hibernation()
+1184:struct power_result laptop_portable::poll_battery_state()
+1264:bool laptop_portable::has_lav()
+1269:float laptop_portable::get_load_average()
+1287:int laptop_portable::has_cpufreq() {
+1301:QString laptop_portable::cpu_frequency() {
+
+2067:int laptop_portable::has_battery_time()
+2092:int laptop_portable::has_suspend()
+2113:int laptop_portable::has_standby()
+2136:int laptop_portable::has_hibernation()
+2147:KActiveLabel *laptop_portable::no_power_management_explanation(QWidget *parent)
+2180:QLabel *laptop_portable::how_to_do_suspend_resume(QWidget *parent)
+2191:QLabel *laptop_portable::pcmcia_info(int x, QWidget *parent)
+2200:void laptop_portable::invoke_standby()
+2216:void laptop_portable::invoke_suspend()
+2231:void laptop_portable::invoke_hibernation()
+2252:int laptop_portable::has_acpi(int)
+2258:int laptop_portable::has_apm(int type)
+2285:struct power_result laptop_portable::poll_battery_state()
+2326:bool laptop_portable::has_lav() { return 0; }
+2328:float laptop_portable::get_load_average()
+2334:int laptop_portable::has_cpufreq() {
+2339:QString laptop_portable::cpu_frequency()
+*/
+#include <iostream>
+using namespace std;
+
+//
+//	something changed maybe we need to check out environment again
+//
+void
+laptop_portable::power_management_restart()
+{
+	// INSERT HERE
+}
+
+int
+laptop_portable::has_power_management()
+{
+	/*int ret, fd;
+	 
+	fd = ::open(ACPIDEV, O_RDWR);
+	if (fd == -1)
+	    fd = ::open(ACPIDEV, O_RDONLY);
+	if (fd == -1) {
+	    return 0;
+	}
+	else {
+	    ::close(fd);
+	    return 1;
+	}*/
+	if (::access(ACPIDEV, O_RDWR) == -1)
+		if (::access(ACPIDEV, O_RDONLY) == -1) {
+			return 0;
+		}
+		else	return 1;
+}
+//
+//	returns 1 if the BIOS returns the time left in the battery rather than a % of full
+//
+int laptop_portable::has_battery_time()
+{
+	int ret, fd;
+	union acpi_battery_ioctl_arg battio;
+	
+	battio.unit = 0;
+	
+	fd = ::open(ACPIDEV, O_RDWR);
+	if (fd == -1)
+	    fd = ::open(ACPIDEV, O_RDONLY);
+	if (fd == -1) {
+	    return 0;
+	}
+	
+	if (ioctl(fd, ACPIIO_BATT_GET_BIF, &battio) == -1) {
+	    return (0);
+	}
+	::close(fd);
+	return 1;
+}
+
+//
+//	returns 1 if we can perform a change-to-suspend-mode operation for the user
+//	(has_power_management() has already returned 1)
+//
+int laptop_portable::has_suspend()
+{
+	/*int ret, fd = ::open(APMDEV, O_RDWR);
+
+	if (fd == -1)
+	  return 0;
+
+	struct apm_info info;
+	ret=ioctl(fd, APMIO_GETINFO, &info);
+	::close(fd);
+
+	if (ret == -1)
+	  return 0;
+
+	return (info.ai_capabilities & 0x02);*/
+	return 0;
+}
+//
+//	returns 1 if we can perform a change-to-standby-mode operation for the user
+//	(has_power_management() has already returned 1)
+//
+int laptop_portable::has_standby()
+{
+	/*int ret, fd = ::open(APMDEV, O_RDWR);
+
+	if (fd == -1)
+	  return 0;
+
+	struct apm_info info;
+	ret=ioctl(fd, APMIO_GETINFO, &info);
+	::close(fd);
+
+	if (ret == -1)
+	  return 0;
+
+	return (info.ai_capabilities & 0x01);*/
+	return 0;
+}
+//
+//	returns 1 if we can perform a change-to-hibernate-mode for a user
+//      (has_power_management() has already returned 1)  [hibernate is the save-to-disk mode
+//	not supported by linux - different laptops have their own - the first here is for 
+//	a ThinkPad]
+//
+int laptop_portable::has_hibernation()
+{
+	if (::access(PATH_TPCTL, X_OK)==0)
+		return(1);
+	return(0);
+}
+
+//
+//	explain to the user what they need to do if has_power_management() returned 0
+//	to get any software they lack
+//
+KActiveLabel *laptop_portable::no_power_management_explanation(QWidget *parent)
+{
+  int fd;
+  KActiveLabel *explain;
+
+  fd = ::open(ACPIDEV, O_RDWR);
+  if (fd == -1) {
+    switch (errno) {
+    case ENOENT:
+      explain = new KActiveLabel(i18n("There is no /dev/acpi file on this system. Please review the FreeBSD handbook on how to add acpi support to your kernel(man 4 acpi)."), parent);
+      break;
+    case EACCES:
+      explain = new KActiveLabel(i18n("Your system has the proper device node for ACPI support, however you cannot access it. If you are logged in as root right now, you have a problem, otherwise contact your local sysadmin and ask for read/write access to /dev/acpi."), parent);
+      break;
+    case ENXIO:
+      explain = new KActiveLabel(i18n("Your kernel lacks support for ACPI."), parent);
+      break;
+      break;
+    default:
+      explain = new KActiveLabel(i18n("There was a generic error while opening /dev/acpi."), parent);
+      break;
+    }
+  } else {
+    close(fd);
+    explain = new KActiveLabel(i18n("ACPI has most likely been disabled."), parent);
+  }
+  
+  return(explain);
+}
+
+//
+//	explain to the user what they need to do to get suspend/resume to work from user mode
+//
+QLabel *laptop_portable::how_to_do_suspend_resume(QWidget *parent)
+{
+ 	QLabel* note = new QLabel(" ", parent);
+	return(note);
+}
+
+
+//
+//	pcmcia support - this will be replaced by better - pcmcia support being worked on by
+//	others
+//
+QLabel *laptop_portable::pcmcia_info(int x, QWidget *parent)
+{
+      	if (x == 0)
+		return(new QLabel(i18n("No PCMCIA controller detected"), parent));
+      	return(new QLabel(i18n(""), parent));
+}
+//
+//	puts us into standby mode
+//
+void laptop_portable::invoke_standby()
+{
+  	/*int fd = ::open(APMDEV, O_RDWR);
+
+	if (fd == -1)
+	  return;
+
+	ioctl(fd, APMIO_STANDBY, NULL);
+	::close(fd);*/
+
+	return;
+}
+
+//
+//	puts us into suspend mode
+//
+void laptop_portable::invoke_suspend()
+{
+  	/*int fd = ::open(APMDEV, O_RDWR);
+
+	if (fd == -1)
+	  return;
+
+	ioctl(fd, APMIO_SUSPEND, NULL);
+	::close(fd);*/
+
+	return;
+}
+//
+//	puts us into hibernate mode
+//
+void laptop_portable::invoke_hibernation()
+{
+	KProcess thisProc;
+
+	if (::access(PATH_TPCTL, X_OK)==0) {
+		thisProc << PATH_TPCTL;
+		thisProc << "---hibernate";
+		thisProc.start(KProcess::Block);
+		return;
+	}
+}
+
+void
+laptop_portable::acpi_set_mask(bool, bool, bool, bool, bool )
+{
+	// INSERT HERE
+}
+
+int laptop_portable::has_acpi(int)
+{
+	if (::access(ACPIDEV, O_RDONLY) != 0) return 0;
+	return (1);
+}
+
+int laptop_portable::has_apm(int type)
+{
+	if (type == 1)		// implement me .... this is the hook that pops up the panel for making /usr/sbin/apm setuid
+		return 0;
+	return (0);
+}
+
+void
+laptop_portable::apm_set_mask(bool , bool )
+{
+}
+
+
+//
+//	adds extra widgets to the battery panel
+//
+void
+laptop_portable::extra_config(QWidget * /*parent*/, KConfig * /*config*/, QVBoxLayout * /*layout*/)
+{
+	// INSERT HERE
+}
+
+
+
+//
+//	return current battery state
+//
+struct power_result laptop_portable::poll_battery_state()
+{
+	struct power_result p;
+       	
+	int ret, fd;
+	union acpi_battery_ioctl_arg battio;
+	
+	battio.unit = ACPI_BATTERY_ALL_UNITS;
+	ret = 0;
+	
+	fd = ::open(ACPIDEV, O_RDONLY);
+	if (fd == -1) {
+	    goto bad;
+	}
+	
+	if (ioctl(fd, ACPIIO_BATT_GET_BATTINFO, &battio) == -1) {
+	    goto bad;
+	}
+	
+	if (ioctl(fd, ACPIIO_ACAD_GET_STATUS, &ret) == -1) {
+	    goto bad;
+	}
+	
+       	::close(fd);
+	
+       	p.powered = ret;
+       	p.percentage = battio.battinfo.cap;
+       	p.time = battio.battinfo.min;
+       	return(p);
+
+bad:
+       	p.powered = 1; 
+	p.percentage = 100;
+	p.time = 0;
+	return(p);
+}
+
+//
+//	return the system load 
+//	
+
+bool laptop_portable::has_lav() { return 1; }
+
+float laptop_portable::get_load_average()
+{
+	// INSERT HERE
+	return(-1);
+}
+
+int laptop_portable::has_cpufreq() {
+	// INSERT HERE
+	return 0;
+}
+
+QString laptop_portable::cpu_frequency() {
+	// INSERT HERE
+	return "";
+}
+
+int
+laptop_portable::has_brightness()
+{
+	// INSERT HERE
+	return 0;
+}
+
+void 
+laptop_portable::set_brightness(bool /*blank*/, int /*val*/)	// val = 0-255 255 brightest, 0 means dimmest (if !blank it must be still visible), 
+{
+	// INSERT HERE
+}
+
+int 
+laptop_portable::get_brightness()
+{
+	// INSERT HERE
+	return(-1);	// means can't extract it
+}
+
+bool
+laptop_portable::get_system_performance(bool, int &current, QStringList &s, bool *&)	 // do something to help get system profiles from places like ACPI
+{
+	// INSERT HERE
+	current = 0;
+	s.clear();
+	return(0);	// if no profiles are available
+}
+
+bool
+laptop_portable::get_system_throttling(bool, int &current, QStringList &s, bool *&)   // do something to help get system throttling data from places like ACPI
+{
+	// INSERT HERE
+	current = 0;
+	s.clear();
+	return(0);
+}
+
+void
+laptop_portable::set_system_performance(QString)
+{
+	// INSERT HERE
+}
+
+void
+laptop_portable::set_system_throttling(QString)
+{
+	// INSERT HERE
+}
+
+bool
+laptop_portable::has_button(LaptopButton)	// true if we have support for a particular button
+{
+	// INSERT HERE
+	return(0);
+}
+
+bool
+laptop_portable::get_button(LaptopButton)	// true if a button is pressed
+{
+	// INSERT HERE
+	return(0);
+}
+
+void
+laptop_portable::get_battery_status(int &num_batteries, QStringList &names, QStringList &state, QStringList &values) // get multiple battery status
+{
+	struct power_result r;
+
+	if (!has_power_management()) {
+		num_batteries = 0;
+		names.clear();
+		state.clear();
+		values.clear();
+		return;
+	}
+
+	// INSERT HERE
+	
+	num_batteries = 1;
+	r = poll_battery_state();
+	names.append("BAT1");
+	state.append("yes");
+	QString s;
+	s.setNum(r.percentage);
+	values.append(s);
+}
+
+bool
+laptop_portable::has_software_suspend(int /*type*/)
+{
+	return false; // (::has_software_suspend(type));
+}
+
+void
+laptop_portable::software_suspend_set_mask(bool /*hibernate*/)
+{
+	// software_suspend_is_preferred = hibernate;
+}
+
+#endif
+
+#if defined(__FreeBSD__) && defined(HAVE_MACHINE_APM_BIOS_H) && (__FreeBSD_version < 502010)
 
 /*
 ** This is the FreeBSD-specific code.
@@ -2426,6 +2907,7 @@
 	// software_suspend_is_preferred = hibernate;
 }
 
+#endif
 
 #elif  defined(__NetBSD_APM__)