ACPI / video: Don't register acpi_video_resume notifier without backlight devices

If we're not going to be registering any backlight devices then
acpi_video_resume is always nop, so don't register it in that case.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Aaron Lu <aaron.lu@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
Hans de Goede 2014-05-15 13:22:33 +02:00 коммит произвёл Rafael J. Wysocki
Родитель 886129a8ee
Коммит 99678ed73a
1 изменённых файлов: 77 добавлений и 68 удалений

Просмотреть файл

@ -150,6 +150,7 @@ struct acpi_video_enumerated_device {
struct acpi_video_bus { struct acpi_video_bus {
struct acpi_device *device; struct acpi_device *device;
bool backlight_registered;
u8 dos_setting; u8 dos_setting;
struct acpi_video_enumerated_device *attached_array; struct acpi_video_enumerated_device *attached_array;
u8 attached_count; u8 attached_count;
@ -1666,88 +1667,89 @@ acpi_video_bus_match(acpi_handle handle, u32 level, void *context,
static void acpi_video_dev_register_backlight(struct acpi_video_device *device) static void acpi_video_dev_register_backlight(struct acpi_video_device *device)
{ {
if (acpi_video_verify_backlight_support()) { struct backlight_properties props;
struct backlight_properties props; struct pci_dev *pdev;
struct pci_dev *pdev; acpi_handle acpi_parent;
acpi_handle acpi_parent; struct device *parent = NULL;
struct device *parent = NULL; int result;
int result; static int count;
static int count; char *name;
char *name;
result = acpi_video_init_brightness(device); result = acpi_video_init_brightness(device);
if (result) if (result)
return; return;
name = kasprintf(GFP_KERNEL, "acpi_video%d", count); name = kasprintf(GFP_KERNEL, "acpi_video%d", count);
if (!name) if (!name)
return; return;
count++; count++;
acpi_get_parent(device->dev->handle, &acpi_parent); acpi_get_parent(device->dev->handle, &acpi_parent);
pdev = acpi_get_pci_dev(acpi_parent); pdev = acpi_get_pci_dev(acpi_parent);
if (pdev) { if (pdev) {
parent = &pdev->dev; parent = &pdev->dev;
pci_dev_put(pdev); pci_dev_put(pdev);
}
memset(&props, 0, sizeof(struct backlight_properties));
props.type = BACKLIGHT_FIRMWARE;
props.max_brightness = device->brightness->count - 3;
device->backlight = backlight_device_register(name,
parent,
device,
&acpi_backlight_ops,
&props);
kfree(name);
if (IS_ERR(device->backlight))
return;
/*
* Save current brightness level in case we have to restore it
* before acpi_video_device_lcd_set_level() is called next time.
*/
device->backlight->props.brightness =
acpi_video_get_brightness(device->backlight);
device->cooling_dev = thermal_cooling_device_register("LCD",
device->dev, &video_cooling_ops);
if (IS_ERR(device->cooling_dev)) {
/*
* Set cooling_dev to NULL so we don't crash trying to
* free it.
* Also, why the hell we are returning early and
* not attempt to register video output if cooling
* device registration failed?
* -- dtor
*/
device->cooling_dev = NULL;
return;
}
dev_info(&device->dev->dev, "registered as cooling_device%d\n",
device->cooling_dev->id);
result = sysfs_create_link(&device->dev->dev.kobj,
&device->cooling_dev->device.kobj,
"thermal_cooling");
if (result)
printk(KERN_ERR PREFIX "Create sysfs link\n");
result = sysfs_create_link(&device->cooling_dev->device.kobj,
&device->dev->dev.kobj, "device");
if (result)
printk(KERN_ERR PREFIX "Create sysfs link\n");
} }
memset(&props, 0, sizeof(struct backlight_properties));
props.type = BACKLIGHT_FIRMWARE;
props.max_brightness = device->brightness->count - 3;
device->backlight = backlight_device_register(name,
parent,
device,
&acpi_backlight_ops,
&props);
kfree(name);
if (IS_ERR(device->backlight))
return;
/*
* Save current brightness level in case we have to restore it
* before acpi_video_device_lcd_set_level() is called next time.
*/
device->backlight->props.brightness =
acpi_video_get_brightness(device->backlight);
device->cooling_dev = thermal_cooling_device_register("LCD",
device->dev, &video_cooling_ops);
if (IS_ERR(device->cooling_dev)) {
/*
* Set cooling_dev to NULL so we don't crash trying to free it.
* Also, why the hell we are returning early and not attempt to
* register video output if cooling device registration failed?
* -- dtor
*/
device->cooling_dev = NULL;
return;
}
dev_info(&device->dev->dev, "registered as cooling_device%d\n",
device->cooling_dev->id);
result = sysfs_create_link(&device->dev->dev.kobj,
&device->cooling_dev->device.kobj,
"thermal_cooling");
if (result)
printk(KERN_ERR PREFIX "Create sysfs link\n");
result = sysfs_create_link(&device->cooling_dev->device.kobj,
&device->dev->dev.kobj, "device");
if (result)
printk(KERN_ERR PREFIX "Create sysfs link\n");
} }
static int acpi_video_bus_register_backlight(struct acpi_video_bus *video) static int acpi_video_bus_register_backlight(struct acpi_video_bus *video)
{ {
struct acpi_video_device *dev; struct acpi_video_device *dev;
if (!acpi_video_verify_backlight_support())
return 0;
mutex_lock(&video->device_list_lock); mutex_lock(&video->device_list_lock);
list_for_each_entry(dev, &video->video_device_list, entry) list_for_each_entry(dev, &video->video_device_list, entry)
acpi_video_dev_register_backlight(dev); acpi_video_dev_register_backlight(dev);
mutex_unlock(&video->device_list_lock); mutex_unlock(&video->device_list_lock);
video->backlight_registered = true;
video->pm_nb.notifier_call = acpi_video_resume; video->pm_nb.notifier_call = acpi_video_resume;
video->pm_nb.priority = 0; video->pm_nb.priority = 0;
return register_pm_notifier(&video->pm_nb); return register_pm_notifier(&video->pm_nb);
@ -1775,13 +1777,20 @@ static void acpi_video_dev_unregister_backlight(struct acpi_video_device *device
static int acpi_video_bus_unregister_backlight(struct acpi_video_bus *video) static int acpi_video_bus_unregister_backlight(struct acpi_video_bus *video)
{ {
struct acpi_video_device *dev; struct acpi_video_device *dev;
int error = unregister_pm_notifier(&video->pm_nb); int error;
if (!video->backlight_registered)
return 0;
error = unregister_pm_notifier(&video->pm_nb);
mutex_lock(&video->device_list_lock); mutex_lock(&video->device_list_lock);
list_for_each_entry(dev, &video->video_device_list, entry) list_for_each_entry(dev, &video->video_device_list, entry)
acpi_video_dev_unregister_backlight(dev); acpi_video_dev_unregister_backlight(dev);
mutex_unlock(&video->device_list_lock); mutex_unlock(&video->device_list_lock);
video->backlight_registered = false;
return error; return error;
} }