Commit ae7cb441 authored by Len Brown's avatar Len Brown Committed by Len Brown

[ACPI4ASUS] globalize hotk structure

This cleans the code up a bit, but mainly allows most functions
to be called externally when need (read: video driver) arises.

Signed-off-by: Karol Kozimor <sziwan@hell.org.pl
parent 2d71f5f5
...@@ -386,6 +386,9 @@ static struct proc_dir_entry *asus_proc_dir; ...@@ -386,6 +386,9 @@ static struct proc_dir_entry *asus_proc_dir;
*/ */
static struct acpi_table_header *asus_info; static struct acpi_table_header *asus_info;
/* The actual device the driver binds to */
static struct asus_hotk *hotk;
/* /*
* The hotkey driver declaration * The hotkey driver declaration
*/ */
...@@ -450,7 +453,6 @@ proc_read_info(char *page, char **start, off_t off, int count, int *eof, ...@@ -450,7 +453,6 @@ proc_read_info(char *page, char **start, off_t off, int count, int *eof,
{ {
int len = 0; int len = 0;
int temp; int temp;
struct asus_hotk *hotk = (struct asus_hotk *) data;
char buf[16]; //enough for all info 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 * We use the easy way, we don't care of off and count, so we don't set eof
...@@ -509,7 +511,7 @@ proc_read_info(char *page, char **start, off_t off, int count, int *eof, ...@@ -509,7 +511,7 @@ proc_read_info(char *page, char **start, off_t off, int count, int *eof,
/* Generic LED functions */ /* Generic LED functions */
static int static int
read_led(struct asus_hotk *hotk, const char *ledname, int ledmask) read_led(const char *ledname, int ledmask)
{ {
if (ledname) { if (ledname) {
int led_status; int led_status;
...@@ -540,7 +542,7 @@ static int parse_arg(const char __user *buf, unsigned long count, int *val) ...@@ -540,7 +542,7 @@ static int parse_arg(const char __user *buf, unsigned long count, int *val)
/* FIXME: kill extraneous args so it can be called independently */ /* FIXME: kill extraneous args so it can be called independently */
static int static int
write_led(const char __user *buffer, unsigned long count, struct asus_hotk *hotk, write_led(const char __user *buffer, unsigned long count,
char *ledname, int ledmask, int invert) char *ledname, int ledmask, int invert)
{ {
int value; int value;
...@@ -570,8 +572,7 @@ static int ...@@ -570,8 +572,7 @@ static int
proc_read_mled(char *page, char **start, off_t off, int count, int *eof, proc_read_mled(char *page, char **start, off_t off, int count, int *eof,
void *data) void *data)
{ {
struct asus_hotk *hotk = (struct asus_hotk *) data; return sprintf(page, "%d\n", read_led(hotk->methods->mled_status, MLED_ON));
return sprintf(page, "%d\n", read_led(hotk, hotk->methods->mled_status, MLED_ON));
} }
...@@ -579,8 +580,7 @@ static int ...@@ -579,8 +580,7 @@ static int
proc_write_mled(struct file *file, const char __user *buffer, proc_write_mled(struct file *file, const char __user *buffer,
unsigned long count, void *data) unsigned long count, void *data)
{ {
struct asus_hotk *hotk = (struct asus_hotk *) data; return write_led(buffer, count, hotk->methods->mt_mled, MLED_ON, 1);
return write_led(buffer, count, hotk, hotk->methods->mt_mled, MLED_ON, 1);
} }
/* /*
...@@ -590,16 +590,14 @@ static int ...@@ -590,16 +590,14 @@ static int
proc_read_wled(char *page, char **start, off_t off, int count, int *eof, proc_read_wled(char *page, char **start, off_t off, int count, int *eof,
void *data) void *data)
{ {
struct asus_hotk *hotk = (struct asus_hotk *) data; return sprintf(page, "%d\n", read_led(hotk->methods->wled_status, WLED_ON));
return sprintf(page, "%d\n", read_led(hotk, hotk->methods->wled_status, WLED_ON));
} }
static int static int
proc_write_wled(struct file *file, const char __user *buffer, proc_write_wled(struct file *file, const char __user *buffer,
unsigned long count, void *data) unsigned long count, void *data)
{ {
struct asus_hotk *hotk = (struct asus_hotk *) data; return write_led(buffer, count, hotk->methods->mt_wled, WLED_ON, 0);
return write_led(buffer, count, hotk, hotk->methods->mt_wled, WLED_ON, 0);
} }
/* /*
...@@ -609,20 +607,18 @@ static int ...@@ -609,20 +607,18 @@ static int
proc_read_tled(char *page, char **start, off_t off, int count, int *eof, proc_read_tled(char *page, char **start, off_t off, int count, int *eof,
void *data) void *data)
{ {
struct asus_hotk *hotk = (struct asus_hotk *) data; return sprintf(page, "%d\n", read_led(hotk->methods->tled_status, TLED_ON));
return sprintf(page, "%d\n", read_led(hotk, hotk->methods->tled_status, TLED_ON));
} }
static int static int
proc_write_tled(struct file *file, const char __user *buffer, proc_write_tled(struct file *file, const char __user *buffer,
unsigned long count, void *data) unsigned long count, void *data)
{ {
struct asus_hotk *hotk = (struct asus_hotk *) data; return write_led(buffer, count, hotk->methods->mt_tled, TLED_ON, 0);
return write_led(buffer, count, hotk, hotk->methods->mt_tled, TLED_ON, 0);
} }
static int get_lcd_state(struct asus_hotk *hotk) static int get_lcd_state(void)
{ {
int lcd = 0; int lcd = 0;
...@@ -663,13 +659,13 @@ static int get_lcd_state(struct asus_hotk *hotk) ...@@ -663,13 +659,13 @@ static int get_lcd_state(struct asus_hotk *hotk)
return (lcd & 1); return (lcd & 1);
} }
static int set_lcd_state(struct asus_hotk *hotk, int value) static int set_lcd_state(int value)
{ {
int lcd = 0; int lcd = 0;
acpi_status status = 0; acpi_status status = 0;
lcd = value ? 1 : 0; lcd = value ? 1 : 0;
if (lcd != get_lcd_state(hotk)) { if (lcd != get_lcd_state()) {
/* switch */ /* switch */
if (hotk->model != L3H) { if (hotk->model != L3H) {
status = status =
...@@ -692,7 +688,7 @@ static int ...@@ -692,7 +688,7 @@ static int
proc_read_lcd(char *page, char **start, off_t off, int count, int *eof, proc_read_lcd(char *page, char **start, off_t off, int count, int *eof,
void *data) void *data)
{ {
return sprintf(page, "%d\n", get_lcd_state((struct asus_hotk *) data)); return sprintf(page, "%d\n", get_lcd_state());
} }
...@@ -701,16 +697,15 @@ proc_write_lcd(struct file *file, const char __user *buffer, ...@@ -701,16 +697,15 @@ proc_write_lcd(struct file *file, const char __user *buffer,
unsigned long count, void *data) unsigned long count, void *data)
{ {
int value; int value;
struct asus_hotk *hotk = (struct asus_hotk *) data;
count = parse_arg(buffer, count, &value); count = parse_arg(buffer, count, &value);
if (count > 0) if (count > 0)
set_lcd_state(hotk, value); set_lcd_state(value);
return count; return count;
} }
static int read_brightness(struct asus_hotk *hotk) static int read_brightness(void)
{ {
int value; int value;
...@@ -730,7 +725,7 @@ static int read_brightness(struct asus_hotk *hotk) ...@@ -730,7 +725,7 @@ static int read_brightness(struct asus_hotk *hotk)
/* /*
* Change the brightness level * Change the brightness level
*/ */
static void set_brightness(int value, struct asus_hotk *hotk) static void set_brightness(int value)
{ {
acpi_status status = 0; acpi_status status = 0;
...@@ -743,7 +738,7 @@ static void set_brightness(int value, struct asus_hotk *hotk) ...@@ -743,7 +738,7 @@ static void set_brightness(int value, struct asus_hotk *hotk)
} }
/* No SPLV method if we are here, act as appropriate */ /* No SPLV method if we are here, act as appropriate */
value -= read_brightness(hotk); value -= read_brightness();
while (value != 0) { while (value != 0) {
status = acpi_evaluate_object(NULL, (value > 0) ? status = acpi_evaluate_object(NULL, (value > 0) ?
hotk->methods->brightness_up : hotk->methods->brightness_up :
...@@ -760,8 +755,7 @@ static int ...@@ -760,8 +755,7 @@ static int
proc_read_brn(char *page, char **start, off_t off, int count, int *eof, proc_read_brn(char *page, char **start, off_t off, int count, int *eof,
void *data) void *data)
{ {
struct asus_hotk *hotk = (struct asus_hotk *) data; return sprintf(page, "%d\n", read_brightness());
return sprintf(page, "%d\n", read_brightness(hotk));
} }
static int static int
...@@ -769,13 +763,12 @@ proc_write_brn(struct file *file, const char __user *buffer, ...@@ -769,13 +763,12 @@ proc_write_brn(struct file *file, const char __user *buffer,
unsigned long count, void *data) unsigned long count, void *data)
{ {
int value; int value;
struct asus_hotk *hotk = (struct asus_hotk *) data;
count = parse_arg(buffer, count, &value); count = parse_arg(buffer, count, &value);
if (count > 0) { if (count > 0) {
value = (0 < value) ? ((15 < value) ? 15 : value) : 0; value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
/* 0 <= value <= 15 */ /* 0 <= value <= 15 */
set_brightness(value, hotk); set_brightness(value);
} else if (count < 0) { } else if (count < 0) {
printk(KERN_WARNING "Asus ACPI: Error reading user input\n"); printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
} }
...@@ -783,7 +776,7 @@ proc_write_brn(struct file *file, const char __user *buffer, ...@@ -783,7 +776,7 @@ proc_write_brn(struct file *file, const char __user *buffer,
return count; return count;
} }
static void set_display(int value, struct asus_hotk *hotk) static void set_display(int value)
{ {
/* no sanity check needed for now */ /* no sanity check needed for now */
if (!write_acpi_int(hotk->handle, hotk->methods->display_set, if (!write_acpi_int(hotk->handle, hotk->methods->display_set,
...@@ -801,7 +794,6 @@ proc_read_disp(char *page, char **start, off_t off, int count, int *eof, ...@@ -801,7 +794,6 @@ proc_read_disp(char *page, char **start, off_t off, int count, int *eof,
void *data) void *data)
{ {
int value = 0; int value = 0;
struct asus_hotk *hotk = (struct asus_hotk *) data;
if (!read_acpi_int(hotk->handle, hotk->methods->display_get, &value)) if (!read_acpi_int(hotk->handle, hotk->methods->display_get, &value))
printk(KERN_WARNING "Asus ACPI: Error reading display status\n"); printk(KERN_WARNING "Asus ACPI: Error reading display status\n");
...@@ -820,11 +812,10 @@ proc_write_disp(struct file *file, const char __user *buffer, ...@@ -820,11 +812,10 @@ proc_write_disp(struct file *file, const char __user *buffer,
unsigned long count, void *data) unsigned long count, void *data)
{ {
int value; int value;
struct asus_hotk *hotk = (struct asus_hotk *) data;
count = parse_arg(buffer, count, &value); count = parse_arg(buffer, count, &value);
if (count > 0) if (count > 0)
set_display(value, hotk); set_display(value);
else if (count < 0) else if (count < 0)
printk(KERN_WARNING "Asus ACPI: Error reading user input\n"); printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
...@@ -859,7 +850,6 @@ __init asus_proc_add(char *name, proc_writefunc *writefunc, ...@@ -859,7 +850,6 @@ __init asus_proc_add(char *name, proc_writefunc *writefunc,
static int __init asus_hotk_add_fs(struct acpi_device *device) static int __init asus_hotk_add_fs(struct acpi_device *device)
{ {
struct proc_dir_entry *proc; struct proc_dir_entry *proc;
struct asus_hotk *hotk = acpi_driver_data(device);
mode_t mode; mode_t mode;
/* /*
...@@ -924,9 +914,6 @@ static int __init asus_hotk_add_fs(struct acpi_device *device) ...@@ -924,9 +914,6 @@ static int __init asus_hotk_add_fs(struct acpi_device *device)
static int asus_hotk_remove_fs(struct acpi_device* device) static int asus_hotk_remove_fs(struct acpi_device* device)
{ {
struct asus_hotk* hotk = acpi_driver_data(device);
if(acpi_device_dir(device)) { if(acpi_device_dir(device)) {
remove_proc_entry(PROC_INFO,acpi_device_dir(device)); remove_proc_entry(PROC_INFO,acpi_device_dir(device));
if (hotk->methods->mt_wled) if (hotk->methods->mt_wled)
...@@ -949,11 +936,7 @@ static int asus_hotk_remove_fs(struct acpi_device* device) ...@@ -949,11 +936,7 @@ static int asus_hotk_remove_fs(struct acpi_device* device)
static void asus_hotk_notify(acpi_handle handle, u32 event, void *data) static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
{ {
/* TODO Find a better way to handle events count. Here, in data, we receive /* TODO Find a better way to handle events count.*/
* the hotk, so we can do anything!
*/
struct asus_hotk *hotk = (struct asus_hotk *) data;
if (!hotk) if (!hotk)
return; return;
...@@ -973,7 +956,7 @@ static void asus_hotk_notify(acpi_handle handle, u32 event, void *data) ...@@ -973,7 +956,7 @@ static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
* This function is used to initialize the hotk with right values. In this * This function is used to initialize the hotk with right values. In this
* method, we can make all the detection we want, and modify the hotk struct * method, we can make all the detection we want, and modify the hotk struct
*/ */
static int __init asus_hotk_get_info(struct asus_hotk *hotk) static int __init asus_hotk_get_info(void)
{ {
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL }; struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL };
...@@ -1109,19 +1092,16 @@ static int __init asus_hotk_get_info(struct asus_hotk *hotk) ...@@ -1109,19 +1092,16 @@ static int __init asus_hotk_get_info(struct asus_hotk *hotk)
} }
static int __init asus_hotk_check(struct asus_hotk *hotk) static int __init asus_hotk_check(void)
{ {
int result = 0; int result = 0;
if (!hotk)
return(-EINVAL);
result = acpi_bus_get_status(hotk->device); result = acpi_bus_get_status(hotk->device);
if (result) if (result)
return(result); return(result);
if (hotk->device->status.present) { if (hotk->device->status.present) {
result = asus_hotk_get_info(hotk); result = asus_hotk_get_info();
} else { } else {
printk(KERN_ERR " Hotkey device not present, aborting\n"); printk(KERN_ERR " Hotkey device not present, aborting\n");
return(-EINVAL); return(-EINVAL);
...@@ -1133,7 +1113,6 @@ static int __init asus_hotk_check(struct asus_hotk *hotk) ...@@ -1133,7 +1113,6 @@ static int __init asus_hotk_check(struct asus_hotk *hotk)
static int __init asus_hotk_add(struct acpi_device *device) static int __init asus_hotk_add(struct acpi_device *device)
{ {
struct asus_hotk *hotk = NULL;
acpi_status status = AE_OK; acpi_status status = AE_OK;
int result; int result;
...@@ -1156,7 +1135,7 @@ static int __init asus_hotk_add(struct acpi_device *device) ...@@ -1156,7 +1135,7 @@ static int __init asus_hotk_add(struct acpi_device *device)
hotk->device = device; hotk->device = device;
result = asus_hotk_check(hotk); result = asus_hotk_check();
if (result) if (result)
goto end; goto end;
...@@ -1201,13 +1180,10 @@ static int __init asus_hotk_add(struct acpi_device *device) ...@@ -1201,13 +1180,10 @@ static int __init asus_hotk_add(struct acpi_device *device)
static int asus_hotk_remove(struct acpi_device *device, int type) static int asus_hotk_remove(struct acpi_device *device, int type)
{ {
acpi_status status = 0; acpi_status status = 0;
struct asus_hotk *hotk = NULL;
if (!device || !acpi_driver_data(device)) if (!device || !acpi_driver_data(device))
return(-EINVAL); return(-EINVAL);
hotk = (struct asus_hotk *) acpi_driver_data(device);
status = acpi_remove_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY, status = acpi_remove_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
asus_hotk_notify); asus_hotk_notify);
if (ACPI_FAILURE(status)) if (ACPI_FAILURE(status))
......
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