Make ibm_acpi use generic backlight infrastructure
PATCH 1/1 Make ibm_acpi use generic backlight infrastructure
The included patch allows brightness to be controlled through /sys/class/backlight on IBM ACPI machines.
Signed-off-by Matthew Garrett <[email protected]>
drivers/acpi/ibm_acpi.c +58 -12
@@ -78,6 +78,8 @@#include <linux/init.h> #include <linux/types.h> #include <linux/proc_fs.h> +#include <linux/backlight.h> +#include <linux/err.h> #include <asm/uaccess.h> #include <acpi/acpi_drivers.h>
@@ -243,6 +245,8 @@ struct ibm_struct {static struct proc_dir_entry *proc_dir =NULL ; +static struct backlight_device *ibm_backlight_device; +#define onoff (status,bit) ((status) & (1 << (bit)) ? "on" : "off")#define enabled (status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")#define strlencmp (a,b) (strncmp((a), (b), strlen(b)))
@@ -1317,15 +1321,25 @@ static int ecdump_write(char *buf)static int brightness_offset =0x31 ; +static int brightness_read_value (struct backlight_device *bd) +{ +u8 level; +if (!acpi_ec_read (brightness_offset, &level)) +return -EIO ; + + level &=0x7 ; +return level; +} +static int brightness_read (char *p) {int len =0 ; -u8 level; +int level =brightness_read_value (NULL ); -if (!acpi_ec_read (brightness_offset, &level)) { +if (level <0 ) { len +=sprintf (p + len,"level:\t\tunreadable\n" ); }else { - len +=sprintf (p + len,"level:\t\t%d\n" , level &0x7 ); + len +=sprintf (p + len,"level:\t\t%d\n" , level); len +=sprintf (p + len,"commands:\tup, down\n" ); len +=sprintf (p + len,"commands:\tlevel <level>" " (<level> is 0-7)\n" );
@@ -1337,9 +1351,32 @@ static int brightness_read(char *p)#define BRIGHTNESS_UP 4#define BRIGHTNESS_DOWN 5 +static int brightness_write_value (struct backlight_device *bd,int value) +{ +int current_value =brightness_read_value (bd); +int inc; +int cmos_cmd; + + value &=7 ; + + cmos_cmd = value > current_value ?BRIGHTNESS_UP :BRIGHTNESS_DOWN ; + + inc = value > current_value ?1 :-1 ; + +while (value != current_value) { + current_value += inc; + +if (!cmos_eval (cmos_cmd)) +return -EIO ; +if (!acpi_ec_write (brightness_offset, current_value)) +return -EIO ; + } + +return 0 ; +} +static int brightness_write (char *buf) { -int cmos_cmd, inc, i;u8 level;int new_level;char *cmd;
@@ -1359,14 +1396,8 @@ static int brightness_write(char *buf) }else return -EINVAL ; - cmos_cmd = new_level > level ?BRIGHTNESS_UP :BRIGHTNESS_DOWN ; - inc = new_level > level ?1 :-1 ; -for (i = level; i != new_level; i += inc) { -if (!cmos_eval (cmos_cmd)) -return -EIO ; -if (!acpi_ec_write (brightness_offset, i + inc)) -return -EIO ; - } +brightness_write_value (NULL , new_level); + }return 0 ;
@@ -1890,10 +1921,20 @@ IBM_PARAM(brightness);IBM_PARAM (volume);IBM_PARAM (fan); + +static struct backlight_properties ibmbl_data = { + .owner =THIS_MODULE , + .get_brightness = brightness_read_value, + .set_brightness = brightness_write_value, + .max_brightness =7 , +}; +static void acpi_ibm_exit (void ) {int i; +backlight_device_unregister (ibm_backlight_device); +for (i =ARRAY_SIZE (ibms) -1 ; i >=0 ; i--)ibm_exit (&ibms[i]);
@@ -1959,6 +2000,11 @@ static int __init acpi_ibm_init(void) } } + ibm_backlight_device =backlight_device_register ("ibm_bl" ,NULL , + &ibmbl_data); +if (IS_ERR (ibm_backlight_device)) +acpi_ibm_exit (); +return 0 ; }
Signature · 1 line
Matthew Garrett | [email protected]
PATCH 1/1 Make asus_acpi use generic backlight infrastructure
The included patch makes it possible to alter the brightness through /sys/class/backlight on machines which support asus_acpi.
Signed-off-by Matthew Garrett <[email protected]>
drivers/acpi/asus_acpi.c +32 -7
@@ -38,6 +38,8 @@#include <linux/init.h> #include <linux/types.h> #include <linux/proc_fs.h> +#include <linux/backlight.h> +#include <linux/err.h> #include <acpi/acpi_drivers.h> #include <acpi/acpi_bus.h> #include <asm/uaccess.h>
@@ -82,6 +84,8 @@ MODULE_PARM_DESC(uid, "UID for entries imodule_param (asus_gid, uint,0 );MODULE_PARM_DESC (gid,"GID for entries in /proc/acpi/asus.\n" ); +static struct backlight_device *asus_backlight_device; +/* For each model, all features implemented, * those marked with R are relative to HOTK, A for absolute */ struct model_data {
@@ -689,7 +693,7 @@ proc_write_lcd(struct file *file, constreturn count; } -static int read_brightness (void ) +static int read_brightness (struct backlight_device *bd) {int value;
@@ -711,10 +715,13 @@ static int read_brightness(void)/* * Change the brightness level */ -static void set_brightness(int value) +static void set_brightness(struct backlight_device *bd, int value) { acpi_status status = 0; + value = (0 < value) ? ((15 < value) ? 15 : value) : 0; + /* 0 <= value <= 15 */ + /* SPLV laptop */ if (hotk->methods->brightness_set) { if (!write_acpi_int(hotk->handle, hotk->methods->brightness_set,
@@ -725,7 +732,7 @@ static void set_brightness(int value) }/* No SPLV method if we are here, act as appropriate */ - value -=read_brightness (); + value -=read_brightness (NULL );while (value !=0 ) { status = acpi_evaluate_object(NULL, (value > 0) ? hotk->methods->brightness_up :
@@ -743,7 +750,7 @@ static int proc_read_brn(char *page, char **start, off_t off, int count, int *eof, void *data) { -return sprintf (page,"%d\n" ,read_brightness ()); +return sprintf (page,"%d\n" ,read_brightness (NULL )); } static int
@@ -754,9 +761,7 @@ proc_write_brn(struct file *file, const count =parse_arg (buffer, count, &value);if (count >0 ) { - value = (0 < value) ? ((15 < value) ?15 : value) :0 ; -/* 0 <= value <= 15 */ -set_brightness (value); +set_brightness (NULL ,value); }else if (count <0 ) {printk (KERN_WARNING "Asus ACPI: Error reading user input\n" ); }
@@ -1205,6 +1210,13 @@ static int asus_hotk_remove(struct acpi_return 0 ; } +static struct backlight_properties asusbl_data = { + .owner =THIS_MODULE , + .get_brightness = read_brightness, + .set_brightness = set_brightness, + .max_brightness =15 , +}; +static int __init asus_acpi_init (void ) {int result;
@@ -1230,11 +1242,24 @@ static int __init asus_acpi_init(void)return -ENODEV ; } + asus_backlight_device =backlight_device_register ("asus_bl" ,NULL , + &asusbl_data); + +if (IS_ERR (asus_backlight_device)) { +printk ("Unable to register backlight\n" ); +acpi_bus_unregister_driver (&asus_hotk_driver); +remove_proc_entry (PROC_ASUS , acpi_root_dir); + +acpi_os_free (asus_info); +return -ENODEV ; + } +return 0 ; } static void __exit asus_acpi_exit(void) { +backlight_device_unregister (asus_backlight_device);acpi_bus_unregister_driver (&asus_hotk_driver);remove_proc_entry (PROC_ASUS , acpi_root_dir);
Signature · 1 line
Matthew Garrett | [email protected]
Hi Matthew,
Quoted 2 lines · Matthew Garrett
The included patch allows brightness to be controlled through
/sys/class/backlighton IBM ACPI machines.
Looks good to me (except for some extra white space). I won't get a chance for a while to test it or roll it into the out-of-kernel tarball, but go ahead and submit it to Len for inclusion into the kernel.
Thanks,
Boris