patch-1.3.85 linux/drivers/char/apm_bios.c
Next file: linux/drivers/char/mem.c
Previous file: linux/drivers/char/Makefile
Back to the patch index
Back to the overall index
- Lines: 231
- Date:
Mon Apr 8 11:10:35 1996
- Orig file:
v1.3.84/linux/drivers/char/apm_bios.c
- Orig date:
Sat Mar 16 20:17:27 1996
diff -u --recursive --new-file v1.3.84/linux/drivers/char/apm_bios.c linux/drivers/char/apm_bios.c
@@ -1,6 +1,7 @@
/* -*- linux-c -*-
* APM BIOS driver for Linux
- * Copyright 1994, 1995 Stephen Rothwell (Stephen.Rothwell@pd.necisa.oz.au)
+ * Copyright 1994, 1995, 1996 Stephen Rothwell
+ * (Stephen.Rothwell@canb.auug.org.au)
*
* 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
@@ -22,12 +23,16 @@
* March 1996, Rik Faith (faith@cs.unc.edu):
* Prohibit APM BIOS calls unless apm_enabled.
* (Thanks to Ulrich Windl <Ulrich.Windl@rz.uni-regensburg.de>)
+ * April 1996, Stephen Rothwell (Stephen.Rothwell@canb.auug.org.au)
+ * Version 1.0
*
* History:
* 0.6b: first version in official kernel, Linux 1.3.46
* 0.7: changed /proc/apm format, Linux 1.3.58
* 0.8: fixed gcc 2.7.[12] compilation problems, Linux 1.3.59
* 0.9: only call bios if bios is present, Linux 1.3.72
+ * 1.0: use fixed device number, consolidate /proc/apm into
+ * this file, Linux 1.3.85
*
* Reference:
*
@@ -54,6 +59,11 @@
#include <linux/fcntl.h>
#include <linux/malloc.h>
#include <linux/linkage.h>
+#ifdef CONFIG_PROC_FS
+#include <linux/stat.h>
+#include <linux/proc_fs.h>
+#endif
+#include <linux/miscdevice.h>
#include <linux/apm_bios.h>
static struct symbol_table apm_syms = {
@@ -65,6 +75,12 @@
extern unsigned long get_cmos_time(void);
+/*
+ * The apm_bios device is one of the misc char devices.
+ * This is its minor number.
+ */
+#define APM_MINOR_DEV 134
+
/* Configurable options:
*
* CONFIG_APM_IGNORE_USER_SUSPEND: define to ignore USER SUSPEND requests.
@@ -285,6 +301,10 @@
select_table *);
static int do_ioctl(struct inode *, struct file *, u_int, u_long);
+#ifdef CONFIG_PROC_FS
+static int apm_get_info(char *, char **, off_t, int, int);
+#endif
+
extern int apm_register_callback(int (*)(apm_event_t));
extern void apm_unregister_callback(int (*)(apm_event_t));
@@ -311,7 +331,7 @@
static struct timer_list apm_timer;
-static char driver_version[] = "0.9";/* no spaces */
+static char driver_version[] = "1.0";/* no spaces */
#ifdef APM_DEBUG
static char * apm_event_name[] = {
@@ -345,6 +365,18 @@
NULL /* fasync */
};
+static struct miscdevice apm_device = {
+ APM_MINOR_DEV,
+ "apm",
+ &apm_bios_fops
+};
+
+#ifdef CONFIG_PROC_FS
+static struct proc_dir_entry apm_proc_entry = {
+ 0, 3, "apm", S_IFREG | S_IRUGO, 1, 0, 0, 0, 0, apm_get_info
+};
+#endif
+
typedef struct callback_list_t {
int (* callback)(apm_event_t);
struct callback_list_t * next;
@@ -472,7 +504,7 @@
#ifdef CONFIG_APM_DISPLAY_BLANK
int error;
- if (!apm_enabled || apm_bios_info.version == 0)
+ if (!apm_enabled)
return 0;
error = apm_set_display_power_state(APM_STATE_STANDBY);
if (error == APM_SUCCESS)
@@ -488,7 +520,7 @@
#ifdef CONFIG_APM_DISPLAY_BLANK
int error;
- if (!apm_enabled || apm_bios_info.version == 0)
+ if (!apm_enabled)
return 0;
error = apm_set_display_power_state(APM_STATE_READY);
if (error == APM_SUCCESS)
@@ -914,7 +946,8 @@
return 0;
}
-int apm_proc(char *buf)
+#ifdef CONFIG_PROC_FS
+int apm_get_info(char *buf, char **start, off_t fpos, int length, int dummy)
{
char * p;
unsigned short bx;
@@ -924,31 +957,29 @@
unsigned short ac_line_status = 0xff;
unsigned short battery_status = 0xff;
unsigned short battery_flag = 0xff;
- unsigned short percentage = -1;
+ int percentage = -1;
int time_units = -1;
char *units = "?";
- if (apm_bios_info.version == 0)
+ if (!apm_enabled)
return 0;
p = buf;
- if ((apm_bios_info.flags & APM_32_BIT_SUPPORT) != 0) {
- if (!(error = apm_get_power_status(&bx, &cx, &dx))) {
- ac_line_status = (bx >> 8) & 0xff;
- battery_status = bx & 0xff;
- if ((cx & 0xff) != 0xff)
- percentage = cx & 0xff;
-
- if (apm_bios_info.version > 0x100) {
- battery_flag = (cx >> 8) & 0xff;
- if (dx != 0xffff) {
- if ((dx & 0x8000) == 0x8000) {
- units = "min";
- time_units = dx & 0x7ffe;
- } else {
- units = "sec";
- time_units = dx & 0x7fff;
- }
+ if (!(error = apm_get_power_status(&bx, &cx, &dx))) {
+ ac_line_status = (bx >> 8) & 0xff;
+ battery_status = bx & 0xff;
+ if ((cx & 0xff) != 0xff)
+ percentage = cx & 0xff;
+
+ if (apm_bios_info.version > 0x100) {
+ battery_flag = (cx >> 8) & 0xff;
+ if (dx != 0xffff) {
+ if ((dx & 0x8000) == 0x8000) {
+ units = "min";
+ time_units = dx & 0x7ffe;
+ } else {
+ units = "sec";
+ time_units = dx & 0x7fff;
}
}
}
@@ -1000,12 +1031,13 @@
battery_flag,
percentage,
time_units,
- units );
+ units);
return p - buf;
}
+#endif
-static int apm_setup(void)
+void apm_bios_init(void)
{
unsigned short bx;
unsigned short cx;
@@ -1016,7 +1048,7 @@
if (apm_bios_info.version == 0) {
printk("APM BIOS not found.\n");
- return -1;
+ return;
}
printk("APM BIOS version %c.%c Flags 0x%02x (Driver version %s)\n",
((apm_bios_info.version >> 8) & 0xff) + '0',
@@ -1025,7 +1057,7 @@
driver_version);
if ((apm_bios_info.flags & APM_32_BIT_SUPPORT) == 0) {
printk(" No 32 bit BIOS support\n");
- return -1;
+ return;
}
/*
@@ -1128,7 +1160,7 @@
if (error)
apm_error("enable power management", error);
if (error == APM_DISABLED)
- return -1;
+ return;
#endif
init_timer(&apm_timer);
@@ -1138,15 +1170,11 @@
register_symtab(&apm_syms);
- apm_enabled = 1;
-
- if ((apm_major = register_chrdev(0, "apm_bios", &apm_bios_fops)) < 0)
- printk("APM BIOS: Cannot allocate major device number\n");
+#ifdef CONFIG_PROC_FS
+ proc_register_dynamic(&proc_root, &apm_proc_entry);
+#endif
- return 0;
-}
+ misc_register(&apm_device);
-void apm_bios_init(void)
-{
- apm_setup();
+ apm_enabled = 1;
}
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov
with Sam's (original) version of this