Commit 564a39dd authored by Aristeu Sergio Rozanski Filho's avatar Aristeu Sergio Rozanski Filho Committed by Arnaldo Carvalho de Melo

o acpi: convert drivers/acpi/toshiba_acpi.c to seq_file

parent 7bd630ef
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#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 <acconfig.h> #include <acconfig.h>
...@@ -100,6 +101,47 @@ MODULE_LICENSE("GPL"); ...@@ -100,6 +101,47 @@ 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
*/ */
...@@ -126,22 +168,6 @@ snscanf(const char* str, int n, const char* format, ...) ...@@ -126,22 +168,6 @@ snscanf(const char* str, int n, const char* format, ...)
return result; return result;
} }
/* This is the common code at the end of every proc read handler. I don't
* understand it yet.
*/
static int
end_proc_read(const char* p, char* page, off_t off, int count,
char** start, int* eof)
{
int 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;
}
/* acpi interface wrappers /* acpi interface wrappers
*/ */
...@@ -259,29 +285,27 @@ static int key_event_valid; ...@@ -259,29 +285,27 @@ static int key_event_valid;
/* proc file handlers /* proc file handlers
*/ */
static int static int toshiba_lcd_seq_show(struct seq_file *seq, void *offset)
proc_read_lcd(char* page, char** start, off_t off, int count, int* eof,
void* context)
{ {
char* p = page;
u32 hci_result; u32 hci_result;
u32 value; u32 value;
if (off != 0) goto end;
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;
p += sprintf(p, "brightness: %d\n", value); seq_printf(seq, "brightness: %d\n"
p += sprintf(p, "brightness_levels: %d\n", "brightness_levels: %d\n",
HCI_LCD_BRIGHTNESS_LEVELS); value,
} else { HCI_LCD_BRIGHTNESS_LEVELS);
p += sprintf(p, "ERROR\n"); } else
goto end; seq_puts(seq, "ERROR\n");
}
return 0;
}
end: static int toshiba_lcd_open_fs(struct inode *inode, struct file *file)
return end_proc_read(p, page, off, count, start, eof); {
return single_open(file, toshiba_lcd_seq_show, NULL);
} }
static int static int
...@@ -306,31 +330,31 @@ proc_write_lcd(struct file* file, const char* buffer, unsigned long count, ...@@ -306,31 +330,31 @@ proc_write_lcd(struct file* file, const char* buffer, unsigned long count,
return count; return count;
} }
static int static int toshiba_video_seq_show(struct seq_file *seq, void *offset)
proc_read_video(char* page, char** start, off_t off, int count, int* eof,
void* context)
{ {
char* p = page;
u32 hci_result; u32 hci_result;
u32 value; u32 value;
if (off != 0) goto end;
hci_read1(HCI_VIDEO_OUT, &value, &hci_result); hci_read1(HCI_VIDEO_OUT, &value, &hci_result);
if (hci_result == HCI_SUCCESS) { if (hci_result == HCI_SUCCESS) {
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;
p += sprintf(p, "lcd_out: %d\n", is_lcd); seq_printf(seq, "lcd_out: %d\n"
p += sprintf(p, "crt_out: %d\n", is_crt); "crt_out: %d\n"
p += sprintf(p, "tv_out: %d\n", is_tv); "tv_out: %d\n",
} else { is_lcd,
p += sprintf(p, "ERROR\n"); is_crt,
goto end; is_tv);
} } else
seq_puts(seq, "ERROR\n");
return 0;
}
end: static int toshiba_video_open_fs(struct inode *inode, struct file *file)
return end_proc_read(p, page, off, count, start, eof); {
return single_open(file, toshiba_video_seq_show, NULL);
} }
static int static int
...@@ -376,27 +400,26 @@ proc_write_video(struct file* file, const char* buffer, unsigned long count, ...@@ -376,27 +400,26 @@ proc_write_video(struct file* file, const char* buffer, unsigned long count,
return count; return count;
} }
static int static int toshiba_fan_seq_show(struct seq_file *seq, void *offset)
proc_read_fan(char* page, char** start, off_t off, int count, int* eof,
void* context)
{ {
char* p = page;
u32 hci_result; u32 hci_result;
u32 value; u32 value;
if (off != 0) goto end;
hci_read1(HCI_FAN, &value, &hci_result); hci_read1(HCI_FAN, &value, &hci_result);
if (hci_result == HCI_SUCCESS) { if (hci_result == HCI_SUCCESS) {
p += sprintf(p, "running: %d\n", (value > 0)); seq_printf(seq, "running: %d\n"
p += sprintf(p, "force_on: %d\n", force_fan); "force_on: %d\n",
} else { (value > 0),
p += sprintf(p, "ERROR\n"); force_fan);
goto end; } else
} seq_puts(seq, "ERROR\n");
return 0;
}
end: static int toshiba_fan_open_fs(struct inode *inode, struct file *file)
return end_proc_read(p, page, off, count, start, eof); {
return single_open(file, toshiba_fan_seq_show, NULL);
} }
static int static int
...@@ -420,16 +443,11 @@ proc_write_fan(struct file* file, const char* buffer, unsigned long count, ...@@ -420,16 +443,11 @@ proc_write_fan(struct file* file, const char* buffer, unsigned long count,
return count; return count;
} }
static int static int toshiba_keys_seq_show(struct seq_file *seq, void *offset)
proc_read_keys(char* page, char** start, off_t off, int count, int* eof,
void* context)
{ {
char* p = page;
u32 hci_result; u32 hci_result;
u32 value; u32 value;
if (off != 0) goto end;
if (!key_event_valid) { if (!key_event_valid) {
hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result); hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result);
if (hci_result == HCI_SUCCESS) { if (hci_result == HCI_SUCCESS) {
...@@ -438,16 +456,23 @@ proc_read_keys(char* page, char** start, off_t off, int count, int* eof, ...@@ -438,16 +456,23 @@ proc_read_keys(char* page, char** start, off_t off, int count, int* eof,
} else if (hci_result == HCI_EMPTY) { } else if (hci_result == HCI_EMPTY) {
/* better luck next time */ /* better luck next time */
} else { } else {
p += sprintf(p, "ERROR\n"); seq_puts(seq, "ERROR\n");
goto end; goto end;
} }
} }
p += sprintf(p, "hotkey_ready: %d\n", key_event_valid); seq_printf(seq, "hotkey_ready: %d\n"
p += sprintf(p, "hotkey: 0x%04x\n", last_key_event); "hotkey: 0x%04x\n",
key_event_valid,
last_key_event);
end: end:
return end_proc_read(p, page, off, count, start, eof); return 0;
}
static int toshiba_keys_open_fs(struct inode *inode, struct file *file)
{
return single_open(file, toshiba_keys_seq_show, NULL);
} }
static int static int
...@@ -466,20 +491,19 @@ proc_write_keys(struct file* file, const char* buffer, unsigned long count, ...@@ -466,20 +491,19 @@ proc_write_keys(struct file* file, const char* buffer, unsigned long count,
return count; return count;
} }
static int static int toshiba_version_seq_show(struct seq_file *seq, void *offset)
proc_read_version(char* page, char** start, off_t off, int count, int* eof,
void* context)
{ {
char* p = page; seq_printf(seq, "driver: %s\n"
"proc_interface: %d\n",
if (off != 0) goto end; TOSHIBA_ACPI_VERSION,
PROC_INTERFACE_VERSION);
p += sprintf(p, "driver: %s\n", TOSHIBA_ACPI_VERSION); return 0;
p += sprintf(p, "proc_interface: %d\n", }
PROC_INTERFACE_VERSION);
end: static int toshiba_version_open_fs(struct inode *inode, struct file *file)
return end_proc_read(p, page, off, count, start, eof); {
return single_open(file, toshiba_version_seq_show, NULL);
} }
/* proc and module init /* proc and module init
...@@ -490,24 +514,38 @@ add_device(void) ...@@ -490,24 +514,38 @@ add_device(void)
{ {
struct proc_dir_entry* proc; struct proc_dir_entry* proc;
proc = create_proc_read_entry(PROC_LCD, S_IFREG | S_IRUGO | S_IWUSR, proc = create_proc_entry(PROC_LCD, S_IFREG | S_IRUGO | S_IWUSR,
toshiba_proc_dir, proc_read_lcd, 0); toshiba_proc_dir);
if (proc) proc->write_proc = proc_write_lcd; if (proc) {
proc->proc_fops = &toshiba_lcd_fops;
proc->write_proc = proc_write_lcd;
}
proc = create_proc_read_entry(PROC_VIDEO, S_IFREG | S_IRUGO | S_IWUSR, proc = create_proc_entry(PROC_VIDEO, S_IFREG | S_IRUGO | S_IWUSR,
toshiba_proc_dir, proc_read_video, 0); toshiba_proc_dir);
if (proc) proc->write_proc = proc_write_video; if (proc) {
proc->proc_fops = &toshiba_video_fops;
proc->write_proc = proc_write_video;
}
proc = create_proc_read_entry(PROC_FAN, S_IFREG | S_IRUGO | S_IWUSR, proc = create_proc_entry(PROC_FAN, S_IFREG | S_IRUGO | S_IWUSR,
toshiba_proc_dir, proc_read_fan, 0); toshiba_proc_dir);
if (proc) proc->write_proc = proc_write_fan; if (proc) {
proc->proc_fops = &toshiba_fan_fops;
proc->write_proc = proc_write_fan;
}
proc = create_proc_read_entry(PROC_KEYS, S_IFREG | S_IRUGO | S_IWUSR, proc = create_proc_entry(PROC_KEYS, S_IFREG | S_IRUGO | S_IWUSR,
toshiba_proc_dir, proc_read_keys, 0); toshiba_proc_dir);
if (proc) proc->write_proc = proc_write_keys; if (proc) {
proc->proc_fops = &toshiba_keys_fops;
proc->write_proc = proc_write_keys;
}
proc = create_proc_read_entry(PROC_VERSION, S_IFREG | S_IRUGO | S_IWUSR, proc = create_proc_entry(PROC_VERSION, S_IFREG | S_IRUGO | S_IWUSR,
toshiba_proc_dir, proc_read_version, 0); toshiba_proc_dir);
if (proc)
proc->proc_fops = &toshiba_version_fops;
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