提交 a3f104c0 编写于 作者: H Henrique de Moraes Holschuh 提交者: Len Brown

ACPI: thinkpad-acpi: support 16 levels of brightness (v3)

Lenovo ThinkPads often have 16 brightness levels in EC, and not just eight
levels like older ThinkPads.  They also have standard ACPI backlight
brightness control.

We detect the number of brightness levels by the presence of a BCLL package
with 16 entries.  If BCLL is not there, we assume eight levels (Z6*).  If
it is there, but it doesn't have 16 entries, we assume eight levels (T60).
Otherwise we assume sixteen levels (T61, X61, etc).

We don't use _BCL because it can have side-effects in thinkpads.  Thanks to
Thomas Renninger <trenn@suse.de> for notifying me of this potential
problem.

Using the standard ACPI backlight brightness control *instead* of the
native thinkpad backlight control is a better idea, though.  A different
patch will take care of this.
Signed-off-by: NHenrique de Moraes Holschuh <hmh@hmh.eng.br>
Cc: Thomas Renninger <trenn@suse.de>
Signed-off-by: NLen Brown <len.brown@intel.com>
上级 e927c08d
...@@ -923,19 +923,26 @@ sysfs backlight device "thinkpad_screen" ...@@ -923,19 +923,26 @@ sysfs backlight device "thinkpad_screen"
This feature allows software control of the LCD brightness on ThinkPad This feature allows software control of the LCD brightness on ThinkPad
models which don't have a hardware brightness slider. models which don't have a hardware brightness slider.
It has some limitations: the LCD backlight cannot be actually turned on or off It has some limitations: the LCD backlight cannot be actually turned on or
by this interface, and in many ThinkPad models, the "dim while on battery" off by this interface, and in many ThinkPad models, the "dim while on
functionality will be enabled by the BIOS when this interface is used, and battery" functionality will be enabled by the BIOS when this interface is
cannot be controlled. used, and cannot be controlled.
The backlight control has eight levels, ranging from 0 to 7. Some of the On IBM (and some of the earlier Lenovo) ThinkPads, the backlight control
levels may not be distinct. has eight brightness levels, ranging from 0 to 7. Some of the levels
may not be distinct. Later Lenovo models that implement the ACPI
There are two interfaces to the firmware for brightness control, EC and CMOS. display backlight brightness control methods have 16 levels, ranging
To select which one should be used, use the brightness_mode module parameter: from 0 to 15.
brightness_mode=1 selects EC mode, brightness_mode=2 selects CMOS mode,
brightness_mode=3 selects both EC and CMOS. The driver tries to autodetect There are two interfaces to the firmware for direct brightness control,
which interface to use. EC and CMOS. To select which one should be used, use the
brightness_mode module parameter: brightness_mode=1 selects EC mode,
brightness_mode=2 selects CMOS mode, brightness_mode=3 selects both EC
and CMOS. The driver tries to autodetect which interface to use.
When display backlight brightness controls are available through the
standard ACPI interface, it is best to use it instead of this direct
ThinkPad-specific interface.
Procfs notes: Procfs notes:
...@@ -947,11 +954,11 @@ Procfs notes: ...@@ -947,11 +954,11 @@ Procfs notes:
Sysfs notes: Sysfs notes:
The interface is implemented through the backlight sysfs class, which is poorly The interface is implemented through the backlight sysfs class, which is
documented at this time. poorly documented at this time.
Locate the thinkpad_screen device under /sys/class/backlight, and inside it Locate the thinkpad_screen device under /sys/class/backlight, and inside
there will be the following attributes: it there will be the following attributes:
max_brightness: max_brightness:
Reads the maximum brightness the hardware can be set to. Reads the maximum brightness the hardware can be set to.
...@@ -961,17 +968,19 @@ there will be the following attributes: ...@@ -961,17 +968,19 @@ there will be the following attributes:
Reads what brightness the screen is set to at this instant. Reads what brightness the screen is set to at this instant.
brightness: brightness:
Writes request the driver to change brightness to the given Writes request the driver to change brightness to the
value. Reads will tell you what brightness the driver is trying given value. Reads will tell you what brightness the
to set the display to when "power" is set to zero and the display driver is trying to set the display to when "power" is set
has not been dimmed by a kernel power management event. to zero and the display has not been dimmed by a kernel
power management event.
power: power:
power management mode, where 0 is "display on", and 1 to 3 will power management mode, where 0 is "display on", and 1 to 3
dim the display backlight to brightness level 0 because will dim the display backlight to brightness level 0
thinkpad-acpi cannot really turn the backlight off. Kernel because thinkpad-acpi cannot really turn the backlight
power management events can temporarily increase the current off. Kernel power management events can temporarily
power management level, i.e. they can dim the display. increase the current power management level, i.e. they can
dim the display.
Volume control -- /proc/acpi/ibm/volume Volume control -- /proc/acpi/ibm/volume
......
...@@ -3114,6 +3114,66 @@ static struct backlight_ops ibm_backlight_data = { ...@@ -3114,6 +3114,66 @@ static struct backlight_ops ibm_backlight_data = {
static struct mutex brightness_mutex; static struct mutex brightness_mutex;
static int __init tpacpi_query_bcll_levels(acpi_handle handle)
{
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
union acpi_object *obj;
int rc;
if (ACPI_SUCCESS(acpi_evaluate_object(handle, NULL, NULL, &buffer))) {
obj = (union acpi_object *)buffer.pointer;
if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
printk(IBM_ERR "Unknown BCLL data, "
"please report this to %s\n", IBM_MAIL);
rc = 0;
} else {
rc = obj->package.count;
}
} else {
return 0;
}
kfree(buffer.pointer);
return rc;
}
static acpi_status __init brightness_find_bcll(acpi_handle handle, u32 lvl,
void *context, void **rv)
{
char name[ACPI_PATH_SEGMENT_LENGTH];
struct acpi_buffer buffer = { sizeof(name), &name };
if (ACPI_SUCCESS(acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer)) &&
!strncmp("BCLL", name, sizeof(name) - 1)) {
if (tpacpi_query_bcll_levels(handle) == 16) {
*rv = handle;
return AE_CTRL_TERMINATE;
} else {
return AE_OK;
}
} else {
return AE_OK;
}
}
static int __init brightness_check_levels(void)
{
int status;
void *found_node = NULL;
if (!vid_handle) {
IBM_ACPIHANDLE_INIT(vid);
}
if (!vid_handle)
return 0;
/* Search for a BCLL package with 16 levels */
status = acpi_walk_namespace(ACPI_TYPE_PACKAGE, vid_handle, 3,
brightness_find_bcll, NULL, &found_node);
return (ACPI_SUCCESS(status) && found_node != NULL);
}
static int __init brightness_init(struct ibm_init_struct *iibm) static int __init brightness_init(struct ibm_init_struct *iibm)
{ {
int b; int b;
...@@ -3135,10 +3195,17 @@ static int __init brightness_init(struct ibm_init_struct *iibm) ...@@ -3135,10 +3195,17 @@ static int __init brightness_init(struct ibm_init_struct *iibm)
if (brightness_mode > 3) if (brightness_mode > 3)
return -EINVAL; return -EINVAL;
tp_features.bright_16levels =
thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO &&
brightness_check_levels();
b = brightness_get(NULL); b = brightness_get(NULL);
if (b < 0) if (b < 0)
return 1; return 1;
if (tp_features.bright_16levels)
printk(IBM_INFO "detected a 16-level brightness capable ThinkPad\n");
ibm_backlight_device = backlight_device_register( ibm_backlight_device = backlight_device_register(
TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL, TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL,
&ibm_backlight_data); &ibm_backlight_data);
...@@ -3148,7 +3215,8 @@ static int __init brightness_init(struct ibm_init_struct *iibm) ...@@ -3148,7 +3215,8 @@ static int __init brightness_init(struct ibm_init_struct *iibm)
} }
vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n"); vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n");
ibm_backlight_device->props.max_brightness = 7; ibm_backlight_device->props.max_brightness =
(tp_features.bright_16levels)? 15 : 7;
ibm_backlight_device->props.brightness = b; ibm_backlight_device->props.brightness = b;
backlight_update_status(ibm_backlight_device); backlight_update_status(ibm_backlight_device);
...@@ -3184,13 +3252,14 @@ static int brightness_get(struct backlight_device *bd) ...@@ -3184,13 +3252,14 @@ static int brightness_get(struct backlight_device *bd)
if (brightness_mode & 1) { if (brightness_mode & 1) {
if (!acpi_ec_read(brightness_offset, &lec)) if (!acpi_ec_read(brightness_offset, &lec))
return -EIO; return -EIO;
lec &= 7; lec &= (tp_features.bright_16levels)? 0x0f : 0x07;
level = lec; level = lec;
}; };
if (brightness_mode & 2) { if (brightness_mode & 2) {
lcmos = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) lcmos = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS)
& TP_NVRAM_MASK_LEVEL_BRIGHTNESS) & TP_NVRAM_MASK_LEVEL_BRIGHTNESS)
>> TP_NVRAM_POS_LEVEL_BRIGHTNESS; >> TP_NVRAM_POS_LEVEL_BRIGHTNESS;
lcmos &= (tp_features.bright_16levels)? 0x0f : 0x07;
level = lcmos; level = lcmos;
} }
...@@ -3211,7 +3280,7 @@ static int brightness_set(int value) ...@@ -3211,7 +3280,7 @@ static int brightness_set(int value)
int cmos_cmd, inc, i, res; int cmos_cmd, inc, i, res;
int current_value; int current_value;
if (value > 7) if (value > ((tp_features.bright_16levels)? 15 : 7))
return -EINVAL; return -EINVAL;
res = mutex_lock_interruptible(&brightness_mutex); res = mutex_lock_interruptible(&brightness_mutex);
...@@ -3227,7 +3296,7 @@ static int brightness_set(int value) ...@@ -3227,7 +3296,7 @@ static int brightness_set(int value)
cmos_cmd = value > current_value ? cmos_cmd = value > current_value ?
TP_CMOS_BRIGHTNESS_UP : TP_CMOS_BRIGHTNESS_UP :
TP_CMOS_BRIGHTNESS_DOWN; TP_CMOS_BRIGHTNESS_DOWN;
inc = value > current_value ? 1 : -1; inc = (value > current_value)? 1 : -1;
res = 0; res = 0;
for (i = current_value; i != value; i += inc) { for (i = current_value; i != value; i += inc) {
...@@ -3256,10 +3325,11 @@ static int brightness_read(char *p) ...@@ -3256,10 +3325,11 @@ static int brightness_read(char *p)
if ((level = brightness_get(NULL)) < 0) { if ((level = brightness_get(NULL)) < 0) {
len += sprintf(p + len, "level:\t\tunreadable\n"); len += sprintf(p + len, "level:\t\tunreadable\n");
} else { } 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:\tup, down\n");
len += sprintf(p + len, "commands:\tlevel <level>" len += sprintf(p + len, "commands:\tlevel <level>"
" (<level> is 0-7)\n"); " (<level> is 0-%d)\n",
(tp_features.bright_16levels) ? 15 : 7);
} }
return len; return len;
...@@ -3270,18 +3340,19 @@ static int brightness_write(char *buf) ...@@ -3270,18 +3340,19 @@ static int brightness_write(char *buf)
int level; int level;
int new_level; int new_level;
char *cmd; char *cmd;
int max_level = (tp_features.bright_16levels) ? 15 : 7;
while ((cmd = next_cmd(&buf))) { while ((cmd = next_cmd(&buf))) {
if ((level = brightness_get(NULL)) < 0) if ((level = brightness_get(NULL)) < 0)
return level; return level;
level &= 7;
if (strlencmp(cmd, "up") == 0) { if (strlencmp(cmd, "up") == 0) {
new_level = level == 7 ? 7 : level + 1; new_level = level == (max_level)?
max_level : level + 1;
} else if (strlencmp(cmd, "down") == 0) { } else if (strlencmp(cmd, "down") == 0) {
new_level = level == 0 ? 0 : level - 1; new_level = level == 0? 0 : level - 1;
} else if (sscanf(cmd, "level %d", &new_level) == 1 && } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
new_level >= 0 && new_level <= 7) { new_level >= 0 && new_level <= max_level) {
/* new_level set */ /* new_level set */
} else } else
return -EINVAL; return -EINVAL;
......
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
/* ThinkPad CMOS NVRAM constants */ /* ThinkPad CMOS NVRAM constants */
#define TP_NVRAM_ADDR_BRIGHTNESS 0x5e #define TP_NVRAM_ADDR_BRIGHTNESS 0x5e
#define TP_NVRAM_MASK_LEVEL_BRIGHTNESS 0x07 #define TP_NVRAM_MASK_LEVEL_BRIGHTNESS 0x0f
#define TP_NVRAM_POS_LEVEL_BRIGHTNESS 0 #define TP_NVRAM_POS_LEVEL_BRIGHTNESS 0
#define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off") #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
...@@ -246,6 +246,7 @@ static struct { ...@@ -246,6 +246,7 @@ static struct {
u32 hotkey_wlsw:1; u32 hotkey_wlsw:1;
u32 light:1; u32 light:1;
u32 light_status:1; u32 light_status:1;
u32 bright_16levels:1;
u32 wan:1; u32 wan:1;
u32 fan_ctrl_status_undef:1; u32 fan_ctrl_status_undef:1;
u32 input_device_registered:1; u32 input_device_registered:1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册