Commit 8584cf05 authored by Andy Grover's avatar Andy Grover

ACPI: Toshiba ACPI device update (John Belmonte)

parent b4304c67
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* toshiba_acpi.c - Toshiba Laptop ACPI Extras * toshiba_acpi.c - Toshiba Laptop ACPI Extras
* *
* *
* Copyright (C) 2002 John Belmonte * Copyright (C) 2002-2003 John Belmonte
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
* *
*/ */
#define TOSHIBA_ACPI_VERSION "0.13" #define TOSHIBA_ACPI_VERSION "0.14"
#define PROC_INTERFACE_VERSION 1 #define PROC_INTERFACE_VERSION 1
#include <linux/kernel.h> #include <linux/kernel.h>
...@@ -41,19 +41,9 @@ ...@@ -41,19 +41,9 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/version.h> #include <linux/version.h>
#include <acpi/acconfig.h>
#define OLD_ACPI_INTERFACE (ACPI_CA_VERSION < 0x20020000)
#if OLD_ACPI_INTERFACE
#include <acpi.h>
extern struct proc_dir_entry* bm_proc_root;
#define acpi_root_dir bm_proc_root
#else
#include <acpi/acpi_drivers.h> #include <acpi/acpi_drivers.h>
#endif
MODULE_AUTHOR("John Belmonte"); MODULE_AUTHOR("John Belmonte");
MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver"); MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
...@@ -101,47 +91,6 @@ MODULE_LICENSE("GPL"); ...@@ -101,47 +91,6 @@ MODULE_LICENSE("GPL");
#define HCI_VIDEO_OUT_CRT 0x2 #define HCI_VIDEO_OUT_CRT 0x2
#define HCI_VIDEO_OUT_TV 0x4 #define HCI_VIDEO_OUT_TV 0x4
static int toshiba_lcd_open_fs(struct inode *inode, struct file *file);
static int toshiba_video_open_fs(struct inode *inode, struct file *file);
static int toshiba_fan_open_fs(struct inode *inode, struct file *file);
static int toshiba_keys_open_fs(struct inode *inode, struct file *file);
static int toshiba_version_open_fs(struct inode *inode, struct file *file);
static struct file_operations toshiba_lcd_fops = {
.open = toshiba_lcd_open_fs,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static struct file_operations toshiba_video_fops = {
.open = toshiba_video_open_fs,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static struct file_operations toshiba_fan_fops = {
.open = toshiba_fan_open_fs,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static struct file_operations toshiba_keys_fops = {
.open = toshiba_keys_open_fs,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static struct file_operations toshiba_version_fops = {
.open = toshiba_version_open_fs,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
/* utility /* utility
*/ */
...@@ -191,8 +140,8 @@ write_acpi_int(const char* methodName, int val) ...@@ -191,8 +140,8 @@ write_acpi_int(const char* methodName, int val)
static int static int
read_acpi_int(const char* methodName, int* pVal) read_acpi_int(const char* methodName, int* pVal)
{ {
acpi_buffer results; struct acpi_buffer results;
acpi_object out_objs[1]; union acpi_object out_objs[1];
acpi_status status; acpi_status status;
results.length = sizeof(out_objs); results.length = sizeof(out_objs);
...@@ -270,22 +219,50 @@ hci_read1(u32 reg, u32* out1, u32* result) ...@@ -270,22 +219,50 @@ hci_read1(u32 reg, u32* out1, u32* result)
return status; return status;
} }
#define PROC_TOSHIBA "toshiba"
#define PROC_LCD "lcd"
#define PROC_VIDEO "video"
#define PROC_FAN "fan"
#define PROC_KEYS "keys"
#define PROC_VERSION "version"
static struct proc_dir_entry* toshiba_proc_dir = NULL; static struct proc_dir_entry* toshiba_proc_dir = NULL;
static int force_fan; static int force_fan;
static int last_key_event; static int last_key_event;
static int key_event_valid; static int key_event_valid;
typedef struct _ProcItem
{
char* name;
char* (*read_func)(char*);
unsigned long (*write_func)(const char*, unsigned long);
} ProcItem;
/* proc file handlers /* proc file handlers
*/ */
static int toshiba_lcd_seq_show(struct seq_file *seq, void *offset) static int
dispatch_read(char* page, char** start, off_t off, int count, int* eof,
ProcItem* item)
{
char* p = page;
int len;
if (off == 0)
p = item->read_func(p);
/* ISSUE: I don't understand this code */
len = (p - page);
if (len <= off+count) *eof = 1;
*start = page + off;
len -= off;
if (len>count) len = count;
if (len<0) len = 0;
return len;
}
static int
dispatch_write(struct file* file, const char* buffer, unsigned long count,
ProcItem* item)
{
return item->write_func(buffer, count);
}
static char*
read_lcd(char* p)
{ {
u32 hci_result; u32 hci_result;
u32 value; u32 value;
...@@ -293,24 +270,18 @@ static int toshiba_lcd_seq_show(struct seq_file *seq, void *offset) ...@@ -293,24 +270,18 @@ static int toshiba_lcd_seq_show(struct seq_file *seq, void *offset)
hci_read1(HCI_LCD_BRIGHTNESS, &value, &hci_result); hci_read1(HCI_LCD_BRIGHTNESS, &value, &hci_result);
if (hci_result == HCI_SUCCESS) { if (hci_result == HCI_SUCCESS) {
value = value >> HCI_LCD_BRIGHTNESS_SHIFT; value = value >> HCI_LCD_BRIGHTNESS_SHIFT;
seq_printf(seq, "brightness: %d\n" p += sprintf(p, "brightness: %d\n", value);
"brightness_levels: %d\n", p += sprintf(p, "brightness_levels: %d\n",
value,
HCI_LCD_BRIGHTNESS_LEVELS); HCI_LCD_BRIGHTNESS_LEVELS);
} else } else {
seq_puts(seq, "ERROR\n"); p += sprintf(p, "ERROR\n");
}
return 0;
}
static int toshiba_lcd_open_fs(struct inode *inode, struct file *file) return p;
{
return single_open(file, toshiba_lcd_seq_show, NULL);
} }
static int static unsigned long
proc_write_lcd(struct file* file, const char* buffer, size_t count, write_lcd(const char* buffer, unsigned long count)
loff_t* data)
{ {
int value; int value;
/*int byte_count;*/ /*int byte_count;*/
...@@ -330,7 +301,8 @@ proc_write_lcd(struct file* file, const char* buffer, size_t count, ...@@ -330,7 +301,8 @@ proc_write_lcd(struct file* file, const char* buffer, size_t count,
return count; return count;
} }
static int toshiba_video_seq_show(struct seq_file *seq, void *offset) static char*
read_video(char* p)
{ {
u32 hci_result; u32 hci_result;
u32 value; u32 value;
...@@ -340,26 +312,18 @@ static int toshiba_video_seq_show(struct seq_file *seq, void *offset) ...@@ -340,26 +312,18 @@ static int toshiba_video_seq_show(struct seq_file *seq, void *offset)
int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0; int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0; int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
int is_tv = (value & HCI_VIDEO_OUT_TV ) ? 1 : 0; int is_tv = (value & HCI_VIDEO_OUT_TV ) ? 1 : 0;
seq_printf(seq, "lcd_out: %d\n" p += sprintf(p, "lcd_out: %d\n", is_lcd);
"crt_out: %d\n" p += sprintf(p, "crt_out: %d\n", is_crt);
"tv_out: %d\n", p += sprintf(p, "tv_out: %d\n", is_tv);
is_lcd, } else {
is_crt, p += sprintf(p, "ERROR\n");
is_tv); }
} else
seq_puts(seq, "ERROR\n");
return 0;
}
static int toshiba_video_open_fs(struct inode *inode, struct file *file) return p;
{
return single_open(file, toshiba_video_seq_show, NULL);
} }
static int static unsigned long
proc_write_video(struct file* file, const char* buffer, size_t count, write_video(const char* buffer, unsigned long count)
loff_t* data)
{ {
int value; int value;
const char* buffer_end = buffer + count; const char* buffer_end = buffer + count;
...@@ -400,31 +364,25 @@ proc_write_video(struct file* file, const char* buffer, size_t count, ...@@ -400,31 +364,25 @@ proc_write_video(struct file* file, const char* buffer, size_t count,
return count; return count;
} }
static int toshiba_fan_seq_show(struct seq_file *seq, void *offset) static char*
read_fan(char* p)
{ {
u32 hci_result; u32 hci_result;
u32 value; u32 value;
hci_read1(HCI_FAN, &value, &hci_result); hci_read1(HCI_FAN, &value, &hci_result);
if (hci_result == HCI_SUCCESS) { if (hci_result == HCI_SUCCESS) {
seq_printf(seq, "running: %d\n" p += sprintf(p, "running: %d\n", (value > 0));
"force_on: %d\n", p += sprintf(p, "force_on: %d\n", force_fan);
(value > 0), } else {
force_fan); p += sprintf(p, "ERROR\n");
} else }
seq_puts(seq, "ERROR\n");
return 0;
}
static int toshiba_fan_open_fs(struct inode *inode, struct file *file) return p;
{
return single_open(file, toshiba_fan_seq_show, NULL);
} }
static int static unsigned long
proc_write_fan(struct file* file, const char* buffer, size_t count, write_fan(const char* buffer, unsigned long count)
loff_t* data)
{ {
int value; int value;
u32 hci_result; u32 hci_result;
...@@ -443,7 +401,8 @@ proc_write_fan(struct file* file, const char* buffer, size_t count, ...@@ -443,7 +401,8 @@ proc_write_fan(struct file* file, const char* buffer, size_t count,
return count; return count;
} }
static int toshiba_keys_seq_show(struct seq_file *seq, void *offset) static char*
read_keys(char* p)
{ {
u32 hci_result; u32 hci_result;
u32 value; u32 value;
...@@ -456,28 +415,20 @@ static int toshiba_keys_seq_show(struct seq_file *seq, void *offset) ...@@ -456,28 +415,20 @@ static int toshiba_keys_seq_show(struct seq_file *seq, void *offset)
} else if (hci_result == HCI_EMPTY) { } else if (hci_result == HCI_EMPTY) {
/* better luck next time */ /* better luck next time */
} else { } else {
seq_puts(seq, "ERROR\n"); p += sprintf(p, "ERROR\n");
goto end; goto end;
} }
} }
seq_printf(seq, "hotkey_ready: %d\n" p += sprintf(p, "hotkey_ready: %d\n", key_event_valid);
"hotkey: 0x%04x\n", p += sprintf(p, "hotkey: 0x%04x\n", last_key_event);
key_event_valid,
last_key_event);
end: end:
return 0; return p;
}
static int toshiba_keys_open_fs(struct inode *inode, struct file *file)
{
return single_open(file, toshiba_keys_seq_show, NULL);
} }
static int static unsigned long
proc_write_keys(struct file* file, const char* buffer, size_t count, write_keys(const char* buffer, unsigned long count)
loff_t* data)
{ {
int value; int value;
...@@ -491,73 +442,55 @@ proc_write_keys(struct file* file, const char* buffer, size_t count, ...@@ -491,73 +442,55 @@ proc_write_keys(struct file* file, const char* buffer, size_t count,
return count; return count;
} }
static int toshiba_version_seq_show(struct seq_file *seq, void *offset) static char*
read_version(char* p)
{ {
seq_printf(seq, "driver: %s\n" p += sprintf(p, "driver: %s\n", TOSHIBA_ACPI_VERSION);
"proc_interface: %d\n", p += sprintf(p, "proc_interface: %d\n",
TOSHIBA_ACPI_VERSION,
PROC_INTERFACE_VERSION); PROC_INTERFACE_VERSION);
return p;
return 0;
}
static int toshiba_version_open_fs(struct inode *inode, struct file *file)
{
return single_open(file, toshiba_version_seq_show, NULL);
} }
/* proc and module init /* proc and module init
*/ */
#define PROC_TOSHIBA "toshiba"
ProcItem proc_items[] =
{
{ "lcd" , read_lcd , write_lcd },
{ "video" , read_video , write_video },
{ "fan" , read_fan , write_fan },
{ "keys" , read_keys , write_keys },
{ "version" , read_version , 0 },
{ 0 , 0 , 0 },
};
static acpi_status static acpi_status
add_device(void) add_device(void)
{ {
struct proc_dir_entry* proc; struct proc_dir_entry* proc;
ProcItem* item;
proc = create_proc_entry(PROC_LCD, S_IFREG | S_IRUGO | S_IWUSR,
toshiba_proc_dir); for (item = proc_items; item->name; ++item)
if (proc) { {
proc->proc_fops = &toshiba_lcd_fops; proc = create_proc_read_entry(item->name,
proc->proc_fops->write = proc_write_lcd; S_IFREG | S_IRUGO | S_IWUSR,
toshiba_proc_dir, (read_proc_t*)dispatch_read, item);
if (proc && item->write_func)
proc->write_proc = (write_proc_t*)dispatch_write;
} }
proc = create_proc_entry(PROC_VIDEO, S_IFREG | S_IRUGO | S_IWUSR,
toshiba_proc_dir);
if (proc) {
proc->proc_fops = &toshiba_video_fops;
proc->proc_fops->write = proc_write_video;
}
proc = create_proc_entry(PROC_FAN, S_IFREG | S_IRUGO | S_IWUSR,
toshiba_proc_dir);
if (proc) {
proc->proc_fops = &toshiba_fan_fops;
proc->proc_fops->write = proc_write_fan;
}
proc = create_proc_entry(PROC_KEYS, S_IFREG | S_IRUGO | S_IWUSR,
toshiba_proc_dir);
if (proc) {
proc->proc_fops = &toshiba_keys_fops;
proc->proc_fops->write = proc_write_keys;
}
proc = create_proc_entry(PROC_VERSION, S_IFREG | S_IRUGO | S_IWUSR,
toshiba_proc_dir);
if (proc)
proc->proc_fops = &toshiba_version_fops;
return(AE_OK); return(AE_OK);
} }
static acpi_status static acpi_status
remove_device(void) remove_device(void)
{ {
remove_proc_entry(PROC_LCD, toshiba_proc_dir); ProcItem* item;
remove_proc_entry(PROC_VIDEO, toshiba_proc_dir);
remove_proc_entry(PROC_FAN, toshiba_proc_dir); for (item = proc_items; item->name; ++item)
remove_proc_entry(PROC_KEYS, toshiba_proc_dir); remove_proc_entry(item->name, toshiba_proc_dir);
remove_proc_entry(PROC_VERSION, toshiba_proc_dir);
return(AE_OK); return(AE_OK);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment