Commit ff93be5d authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by Len Brown

asus_acpi: convert to seq_file

Signed-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Cc: Corentin Chary <corentincj@iksaif.net>
Cc: Karol Kozimor <sziwan@users.sourceforge.net>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent 2370b5ed
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,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/backlight.h> #include <linux/backlight.h>
#include <acpi/acpi_drivers.h> #include <acpi/acpi_drivers.h>
#include <acpi/acpi_bus.h> #include <acpi/acpi_bus.h>
...@@ -513,26 +514,12 @@ static int read_acpi_int(acpi_handle handle, const char *method, int *val) ...@@ -513,26 +514,12 @@ static int read_acpi_int(acpi_handle handle, const char *method, int *val)
return (status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER); return (status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER);
} }
/* static int asus_info_proc_show(struct seq_file *m, void *v)
* We write our info in page, we begin at offset off and cannot write more
* than count bytes. We set eof to 1 if we handle those 2 values. We return the
* number of bytes written in page
*/
static int
proc_read_info(char *page, char **start, off_t off, int count, int *eof,
void *data)
{ {
int len = 0;
int temp; int temp;
char buf[16]; /* enough for all info */
/*
* We use the easy way, we don't care of off and count,
* so we don't set eof to 1
*/
len += sprintf(page, ACPI_HOTK_NAME " " ASUS_ACPI_VERSION "\n"); seq_printf(m, ACPI_HOTK_NAME " " ASUS_ACPI_VERSION "\n");
len += sprintf(page + len, "Model reference : %s\n", seq_printf(m, "Model reference : %s\n", hotk->methods->name);
hotk->methods->name);
/* /*
* The SFUN method probably allows the original driver to get the list * The SFUN method probably allows the original driver to get the list
* of features supported by a given model. For now, 0x0100 or 0x0800 * of features supported by a given model. For now, 0x0100 or 0x0800
...@@ -540,8 +527,7 @@ proc_read_info(char *page, char **start, off_t off, int count, int *eof, ...@@ -540,8 +527,7 @@ proc_read_info(char *page, char **start, off_t off, int count, int *eof,
* The significance of others is yet to be found. * The significance of others is yet to be found.
*/ */
if (read_acpi_int(hotk->handle, "SFUN", &temp)) if (read_acpi_int(hotk->handle, "SFUN", &temp))
len += seq_printf(m, "SFUN value : 0x%04x\n", temp);
sprintf(page + len, "SFUN value : 0x%04x\n", temp);
/* /*
* Another value for userspace: the ASYM method returns 0x02 for * Another value for userspace: the ASYM method returns 0x02 for
* battery low and 0x04 for battery critical, its readings tend to be * battery low and 0x04 for battery critical, its readings tend to be
...@@ -550,30 +536,34 @@ proc_read_info(char *page, char **start, off_t off, int count, int *eof, ...@@ -550,30 +536,34 @@ proc_read_info(char *page, char **start, off_t off, int count, int *eof,
* silently ignored. * silently ignored.
*/ */
if (read_acpi_int(hotk->handle, "ASYM", &temp)) if (read_acpi_int(hotk->handle, "ASYM", &temp))
len += seq_printf(m, "ASYM value : 0x%04x\n", temp);
sprintf(page + len, "ASYM value : 0x%04x\n", temp);
if (asus_info) { if (asus_info) {
snprintf(buf, 16, "%d", asus_info->length); seq_printf(m, "DSDT length : %d\n", asus_info->length);
len += sprintf(page + len, "DSDT length : %s\n", buf); seq_printf(m, "DSDT checksum : %d\n", asus_info->checksum);
snprintf(buf, 16, "%d", asus_info->checksum); seq_printf(m, "DSDT revision : %d\n", asus_info->revision);
len += sprintf(page + len, "DSDT checksum : %s\n", buf); seq_printf(m, "OEM id : %.*s\n", ACPI_OEM_ID_SIZE, asus_info->oem_id);
snprintf(buf, 16, "%d", asus_info->revision); seq_printf(m, "OEM table id : %.*s\n", ACPI_OEM_TABLE_ID_SIZE, asus_info->oem_table_id);
len += sprintf(page + len, "DSDT revision : %s\n", buf); seq_printf(m, "OEM revision : 0x%x\n", asus_info->oem_revision);
snprintf(buf, 7, "%s", asus_info->oem_id); seq_printf(m, "ASL comp vendor id : %.*s\n", ACPI_NAME_SIZE, asus_info->asl_compiler_id);
len += sprintf(page + len, "OEM id : %s\n", buf); seq_printf(m, "ASL comp revision : 0x%x\n", asus_info->asl_compiler_revision);
snprintf(buf, 9, "%s", asus_info->oem_table_id);
len += sprintf(page + len, "OEM table id : %s\n", buf);
snprintf(buf, 16, "%x", asus_info->oem_revision);
len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
} }
return len; return 0;
}
static int asus_info_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, asus_info_proc_show, NULL);
} }
static const struct file_operations asus_info_proc_fops = {
.owner = THIS_MODULE,
.open = asus_info_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
/* /*
* /proc handlers * /proc handlers
* We write our info in page, we begin at offset off and cannot write more * We write our info in page, we begin at offset off and cannot write more
...@@ -639,34 +629,48 @@ write_led(const char __user *buffer, unsigned long count, ...@@ -639,34 +629,48 @@ write_led(const char __user *buffer, unsigned long count,
/* /*
* Proc handlers for MLED * Proc handlers for MLED
*/ */
static int static int mled_proc_show(struct seq_file *m, void *v)
proc_read_mled(char *page, char **start, off_t off, int count, int *eof,
void *data)
{ {
return sprintf(page, "%d\n", seq_printf(m, "%d\n", read_led(hotk->methods->mled_status, MLED_ON));
read_led(hotk->methods->mled_status, MLED_ON)); return 0;
} }
static int static int mled_proc_open(struct inode *inode, struct file *file)
proc_write_mled(struct file *file, const char __user *buffer, {
unsigned long count, void *data) return single_open(file, mled_proc_show, NULL);
}
static ssize_t mled_proc_write(struct file *file, const char __user *buffer,
size_t count, loff_t *pos)
{ {
return write_led(buffer, count, hotk->methods->mt_mled, MLED_ON, 1); return write_led(buffer, count, hotk->methods->mt_mled, MLED_ON, 1);
} }
static const struct file_operations mled_proc_fops = {
.owner = THIS_MODULE,
.open = mled_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
.write = mled_proc_write,
};
/* /*
* Proc handlers for LED display * Proc handlers for LED display
*/ */
static int static int ledd_proc_show(struct seq_file *m, void *v)
proc_read_ledd(char *page, char **start, off_t off, int count, int *eof,
void *data)
{ {
return sprintf(page, "0x%08x\n", hotk->ledd_status); seq_printf(m, "0x%08x\n", hotk->ledd_status);
return 0;
} }
static int static int ledd_proc_open(struct inode *inode, struct file *file)
proc_write_ledd(struct file *file, const char __user *buffer, {
unsigned long count, void *data) return single_open(file, ledd_proc_show, NULL);
}
static ssize_t ledd_proc_write(struct file *file, const char __user *buffer,
size_t count, loff_t *pos)
{ {
int rv, value; int rv, value;
...@@ -682,61 +686,104 @@ proc_write_ledd(struct file *file, const char __user *buffer, ...@@ -682,61 +686,104 @@ proc_write_ledd(struct file *file, const char __user *buffer,
return rv; return rv;
} }
static const struct file_operations ledd_proc_fops = {
.owner = THIS_MODULE,
.open = ledd_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
.write = ledd_proc_write,
};
/* /*
* Proc handlers for WLED * Proc handlers for WLED
*/ */
static int static int wled_proc_show(struct seq_file *m, void *v)
proc_read_wled(char *page, char **start, off_t off, int count, int *eof,
void *data)
{ {
return sprintf(page, "%d\n", seq_printf(m, "%d\n", read_led(hotk->methods->wled_status, WLED_ON));
read_led(hotk->methods->wled_status, WLED_ON)); return 0;
} }
static int static int wled_proc_open(struct inode *inode, struct file *file)
proc_write_wled(struct file *file, const char __user *buffer, {
unsigned long count, void *data) return single_open(file, wled_proc_show, NULL);
}
static ssize_t wled_proc_write(struct file *file, const char __user *buffer,
size_t count, loff_t *pos)
{ {
return write_led(buffer, count, hotk->methods->mt_wled, WLED_ON, 0); return write_led(buffer, count, hotk->methods->mt_wled, WLED_ON, 0);
} }
static const struct file_operations wled_proc_fops = {
.owner = THIS_MODULE,
.open = wled_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
.write = wled_proc_write,
};
/* /*
* Proc handlers for Bluetooth * Proc handlers for Bluetooth
*/ */
static int static int bluetooth_proc_show(struct seq_file *m, void *v)
proc_read_bluetooth(char *page, char **start, off_t off, int count, int *eof,
void *data)
{ {
return sprintf(page, "%d\n", read_led(hotk->methods->bt_status, BT_ON)); seq_printf(m, "%d\n", read_led(hotk->methods->bt_status, BT_ON));
return 0;
} }
static int static int bluetooth_proc_open(struct inode *inode, struct file *file)
proc_write_bluetooth(struct file *file, const char __user *buffer, {
unsigned long count, void *data) return single_open(file, bluetooth_proc_show, NULL);
}
static ssize_t bluetooth_proc_write(struct file *file,
const char __user *buffer, size_t count, loff_t *pos)
{ {
/* Note: mt_bt_switch controls both internal Bluetooth adapter's /* Note: mt_bt_switch controls both internal Bluetooth adapter's
presence and its LED */ presence and its LED */
return write_led(buffer, count, hotk->methods->mt_bt_switch, BT_ON, 0); return write_led(buffer, count, hotk->methods->mt_bt_switch, BT_ON, 0);
} }
static const struct file_operations bluetooth_proc_fops = {
.owner = THIS_MODULE,
.open = bluetooth_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
.write = bluetooth_proc_write,
};
/* /*
* Proc handlers for TLED * Proc handlers for TLED
*/ */
static int static int tled_proc_show(struct seq_file *m, void *v)
proc_read_tled(char *page, char **start, off_t off, int count, int *eof,
void *data)
{ {
return sprintf(page, "%d\n", seq_printf(m, "%d\n", read_led(hotk->methods->tled_status, TLED_ON));
read_led(hotk->methods->tled_status, TLED_ON)); return 0;
} }
static int static int tled_proc_open(struct inode *inode, struct file *file)
proc_write_tled(struct file *file, const char __user *buffer, {
unsigned long count, void *data) return single_open(file, tled_proc_show, NULL);
}
static ssize_t tled_proc_write(struct file *file, const char __user *buffer,
size_t count, loff_t *pos)
{ {
return write_led(buffer, count, hotk->methods->mt_tled, TLED_ON, 0); return write_led(buffer, count, hotk->methods->mt_tled, TLED_ON, 0);
} }
static const struct file_operations tled_proc_fops = {
.owner = THIS_MODULE,
.open = tled_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
.write = tled_proc_write,
};
static int get_lcd_state(void) static int get_lcd_state(void)
{ {
int lcd = 0; int lcd = 0;
...@@ -829,16 +876,19 @@ static int set_lcd_state(int value) ...@@ -829,16 +876,19 @@ static int set_lcd_state(int value)
} }
static int static int lcd_proc_show(struct seq_file *m, void *v)
proc_read_lcd(char *page, char **start, off_t off, int count, int *eof,
void *data)
{ {
return sprintf(page, "%d\n", get_lcd_state()); seq_printf(m, "%d\n", get_lcd_state());
return 0;
} }
static int static int lcd_proc_open(struct inode *inode, struct file *file)
proc_write_lcd(struct file *file, const char __user *buffer, {
unsigned long count, void *data) return single_open(file, lcd_proc_show, NULL);
}
static ssize_t lcd_proc_write(struct file *file, const char __user *buffer,
size_t count, loff_t *pos)
{ {
int rv, value; int rv, value;
...@@ -848,6 +898,15 @@ proc_write_lcd(struct file *file, const char __user *buffer, ...@@ -848,6 +898,15 @@ proc_write_lcd(struct file *file, const char __user *buffer,
return rv; return rv;
} }
static const struct file_operations lcd_proc_fops = {
.owner = THIS_MODULE,
.open = lcd_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
.write = lcd_proc_write,
};
static int read_brightness(struct backlight_device *bd) static int read_brightness(struct backlight_device *bd)
{ {
int value; int value;
...@@ -907,16 +966,19 @@ static int set_brightness_status(struct backlight_device *bd) ...@@ -907,16 +966,19 @@ static int set_brightness_status(struct backlight_device *bd)
return set_brightness(bd->props.brightness); return set_brightness(bd->props.brightness);
} }
static int static int brn_proc_show(struct seq_file *m, void *v)
proc_read_brn(char *page, char **start, off_t off, int count, int *eof,
void *data)
{ {
return sprintf(page, "%d\n", read_brightness(NULL)); seq_printf(m, "%d\n", read_brightness(NULL));
return 0;
} }
static int static int brn_proc_open(struct inode *inode, struct file *file)
proc_write_brn(struct file *file, const char __user *buffer, {
unsigned long count, void *data) return single_open(file, brn_proc_show, NULL);
}
static ssize_t brn_proc_write(struct file *file, const char __user *buffer,
size_t count, loff_t *pos)
{ {
int rv, value; int rv, value;
...@@ -929,6 +991,15 @@ proc_write_brn(struct file *file, const char __user *buffer, ...@@ -929,6 +991,15 @@ proc_write_brn(struct file *file, const char __user *buffer,
return rv; return rv;
} }
static const struct file_operations brn_proc_fops = {
.owner = THIS_MODULE,
.open = brn_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
.write = brn_proc_write,
};
static void set_display(int value) static void set_display(int value)
{ {
/* no sanity check needed for now */ /* no sanity check needed for now */
...@@ -942,9 +1013,7 @@ static void set_display(int value) ...@@ -942,9 +1013,7 @@ static void set_display(int value)
* Now, *this* one could be more user-friendly, but so far, no-one has * Now, *this* one could be more user-friendly, but so far, no-one has
* complained. The significance of bits is the same as in proc_write_disp() * complained. The significance of bits is the same as in proc_write_disp()
*/ */
static int static int disp_proc_show(struct seq_file *m, void *v)
proc_read_disp(char *page, char **start, off_t off, int count, int *eof,
void *data)
{ {
int value = 0; int value = 0;
...@@ -952,7 +1021,13 @@ proc_read_disp(char *page, char **start, off_t off, int count, int *eof, ...@@ -952,7 +1021,13 @@ proc_read_disp(char *page, char **start, off_t off, int count, int *eof,
printk(KERN_WARNING printk(KERN_WARNING
"Asus ACPI: Error reading display status\n"); "Asus ACPI: Error reading display status\n");
value &= 0x07; /* needed for some models, shouldn't hurt others */ value &= 0x07; /* needed for some models, shouldn't hurt others */
return sprintf(page, "%d\n", value); seq_printf(m, "%d\n", value);
return 0;
}
static int disp_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, disp_proc_show, NULL);
} }
/* /*
...@@ -961,9 +1036,8 @@ proc_read_disp(char *page, char **start, off_t off, int count, int *eof, ...@@ -961,9 +1036,8 @@ proc_read_disp(char *page, char **start, off_t off, int count, int *eof,
* (bitwise) of these will suffice. I never actually tested 3 displays hooked * (bitwise) of these will suffice. I never actually tested 3 displays hooked
* up simultaneously, so be warned. See the acpi4asus README for more info. * up simultaneously, so be warned. See the acpi4asus README for more info.
*/ */
static int static ssize_t disp_proc_write(struct file *file, const char __user *buffer,
proc_write_disp(struct file *file, const char __user *buffer, size_t count, loff_t *pos)
unsigned long count, void *data)
{ {
int rv, value; int rv, value;
...@@ -973,25 +1047,27 @@ proc_write_disp(struct file *file, const char __user *buffer, ...@@ -973,25 +1047,27 @@ proc_write_disp(struct file *file, const char __user *buffer,
return rv; return rv;
} }
typedef int (proc_readfunc) (char *page, char **start, off_t off, int count, static const struct file_operations disp_proc_fops = {
int *eof, void *data); .owner = THIS_MODULE,
typedef int (proc_writefunc) (struct file *file, const char __user *buffer, .open = disp_proc_open,
unsigned long count, void *data); .read = seq_read,
.llseek = seq_lseek,
.release = single_release,
.write = disp_proc_write,
};
static int static int
asus_proc_add(char *name, proc_writefunc *writefunc, asus_proc_add(char *name, const struct file_operations *proc_fops, mode_t mode,
proc_readfunc *readfunc, mode_t mode,
struct acpi_device *device) struct acpi_device *device)
{ {
struct proc_dir_entry *proc = struct proc_dir_entry *proc;
create_proc_entry(name, mode, acpi_device_dir(device));
proc = proc_create_data(name, mode, acpi_device_dir(device),
proc_fops, acpi_driver_data(device));
if (!proc) { if (!proc) {
printk(KERN_WARNING " Unable to create %s fs entry\n", name); printk(KERN_WARNING " Unable to create %s fs entry\n", name);
return -1; return -1;
} }
proc->write_proc = writefunc;
proc->read_proc = readfunc;
proc->data = acpi_driver_data(device);
proc->uid = asus_uid; proc->uid = asus_uid;
proc->gid = asus_gid; proc->gid = asus_gid;
return 0; return 0;
...@@ -1020,10 +1096,9 @@ static int asus_hotk_add_fs(struct acpi_device *device) ...@@ -1020,10 +1096,9 @@ static int asus_hotk_add_fs(struct acpi_device *device)
if (!acpi_device_dir(device)) if (!acpi_device_dir(device))
return -ENODEV; return -ENODEV;
proc = create_proc_entry(PROC_INFO, mode, acpi_device_dir(device)); proc = proc_create(PROC_INFO, mode, acpi_device_dir(device),
&asus_info_proc_fops);
if (proc) { if (proc) {
proc->read_proc = proc_read_info;
proc->data = acpi_driver_data(device);
proc->uid = asus_uid; proc->uid = asus_uid;
proc->gid = asus_gid; proc->gid = asus_gid;
} else { } else {
...@@ -1032,28 +1107,23 @@ static int asus_hotk_add_fs(struct acpi_device *device) ...@@ -1032,28 +1107,23 @@ static int asus_hotk_add_fs(struct acpi_device *device)
} }
if (hotk->methods->mt_wled) { if (hotk->methods->mt_wled) {
asus_proc_add(PROC_WLED, &proc_write_wled, &proc_read_wled, asus_proc_add(PROC_WLED, &wled_proc_fops, mode, device);
mode, device);
} }
if (hotk->methods->mt_ledd) { if (hotk->methods->mt_ledd) {
asus_proc_add(PROC_LEDD, &proc_write_ledd, &proc_read_ledd, asus_proc_add(PROC_LEDD, &ledd_proc_fops, mode, device);
mode, device);
} }
if (hotk->methods->mt_mled) { if (hotk->methods->mt_mled) {
asus_proc_add(PROC_MLED, &proc_write_mled, &proc_read_mled, asus_proc_add(PROC_MLED, &mled_proc_fops, mode, device);
mode, device);
} }
if (hotk->methods->mt_tled) { if (hotk->methods->mt_tled) {
asus_proc_add(PROC_TLED, &proc_write_tled, &proc_read_tled, asus_proc_add(PROC_TLED, &tled_proc_fops, mode, device);
mode, device);
} }
if (hotk->methods->mt_bt_switch) { if (hotk->methods->mt_bt_switch) {
asus_proc_add(PROC_BT, &proc_write_bluetooth, asus_proc_add(PROC_BT, &bluetooth_proc_fops, mode, device);
&proc_read_bluetooth, mode, device);
} }
/* /*
...@@ -1061,19 +1131,16 @@ static int asus_hotk_add_fs(struct acpi_device *device) ...@@ -1061,19 +1131,16 @@ static int asus_hotk_add_fs(struct acpi_device *device)
* accessible from the keyboard * accessible from the keyboard
*/ */
if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status) { if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status) {
asus_proc_add(PROC_LCD, &proc_write_lcd, &proc_read_lcd, mode, asus_proc_add(PROC_LCD, &lcd_proc_fops, mode, device);
device);
} }
if ((hotk->methods->brightness_up && hotk->methods->brightness_down) || if ((hotk->methods->brightness_up && hotk->methods->brightness_down) ||
(hotk->methods->brightness_get && hotk->methods->brightness_set)) { (hotk->methods->brightness_get && hotk->methods->brightness_set)) {
asus_proc_add(PROC_BRN, &proc_write_brn, &proc_read_brn, mode, asus_proc_add(PROC_BRN, &brn_proc_fops, mode, device);
device);
} }
if (hotk->methods->display_set) { if (hotk->methods->display_set) {
asus_proc_add(PROC_DISP, &proc_write_disp, &proc_read_disp, asus_proc_add(PROC_DISP, &disp_proc_fops, mode, device);
mode, device);
} }
return 0; return 0;
......
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