diff options
author | Hans de Goede <hdegoede@redhat.com> | 2014-05-15 07:22:33 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2014-05-16 09:40:01 -0400 |
commit | 99678ed73a50d2df8b5f3c801e29e9b7a3e5aa85 (patch) | |
tree | d07f918072a64af4d25176b63cec39acdbf0c017 | |
parent | 886129a8eebebec260165741fe31421482371006 (diff) |
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>
-rw-r--r-- | drivers/acpi/video.c | 139 |
1 files changed, 74 insertions, 65 deletions
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c index fced27d8e42f..ff79dff371fd 100644 --- a/drivers/acpi/video.c +++ b/drivers/acpi/video.c | |||
@@ -150,6 +150,7 @@ struct acpi_video_enumerated_device { | |||
150 | 150 | ||
151 | struct acpi_video_bus { | 151 | struct acpi_video_bus { |
152 | struct acpi_device *device; | 152 | struct acpi_device *device; |
153 | bool backlight_registered; | ||
153 | u8 dos_setting; | 154 | u8 dos_setting; |
154 | struct acpi_video_enumerated_device *attached_array; | 155 | struct acpi_video_enumerated_device *attached_array; |
155 | u8 attached_count; | 156 | u8 attached_count; |
@@ -1666,88 +1667,89 @@ acpi_video_bus_match(acpi_handle handle, u32 level, void *context, | |||
1666 | 1667 | ||
1667 | static void acpi_video_dev_register_backlight(struct acpi_video_device *device) | 1668 | static void acpi_video_dev_register_backlight(struct acpi_video_device *device) |
1668 | { | 1669 | { |
1669 | if (acpi_video_verify_backlight_support()) { | 1670 | struct backlight_properties props; |
1670 | struct backlight_properties props; | 1671 | struct pci_dev *pdev; |
1671 | struct pci_dev *pdev; | 1672 | acpi_handle acpi_parent; |
1672 | acpi_handle acpi_parent; | 1673 | struct device *parent = NULL; |
1673 | struct device *parent = NULL; | 1674 | int result; |
1674 | int result; | 1675 | static int count; |
1675 | static int count; | 1676 | char *name; |
1676 | char *name; | ||
1677 | |||
1678 | result = acpi_video_init_brightness(device); | ||
1679 | if (result) | ||
1680 | return; | ||
1681 | name = kasprintf(GFP_KERNEL, "acpi_video%d", count); | ||
1682 | if (!name) | ||
1683 | return; | ||
1684 | count++; | ||
1685 | 1677 | ||
1686 | acpi_get_parent(device->dev->handle, &acpi_parent); | 1678 | result = acpi_video_init_brightness(device); |
1679 | if (result) | ||
1680 | return; | ||
1681 | name = kasprintf(GFP_KERNEL, "acpi_video%d", count); | ||
1682 | if (!name) | ||
1683 | return; | ||
1684 | count++; | ||
1687 | 1685 | ||
1688 | pdev = acpi_get_pci_dev(acpi_parent); | 1686 | acpi_get_parent(device->dev->handle, &acpi_parent); |
1689 | if (pdev) { | ||
1690 | parent = &pdev->dev; | ||
1691 | pci_dev_put(pdev); | ||
1692 | } | ||
1693 | 1687 | ||
1694 | memset(&props, 0, sizeof(struct backlight_properties)); | 1688 | pdev = acpi_get_pci_dev(acpi_parent); |
1695 | props.type = BACKLIGHT_FIRMWARE; | 1689 | if (pdev) { |
1696 | props.max_brightness = device->brightness->count - 3; | 1690 | parent = &pdev->dev; |
1697 | device->backlight = backlight_device_register(name, | 1691 | pci_dev_put(pdev); |
1698 | parent, | 1692 | } |
1699 | device, | ||
1700 | &acpi_backlight_ops, | ||
1701 | &props); | ||
1702 | kfree(name); | ||
1703 | if (IS_ERR(device->backlight)) | ||
1704 | return; | ||
1705 | 1693 | ||
1706 | /* | 1694 | memset(&props, 0, sizeof(struct backlight_properties)); |
1707 | * Save current brightness level in case we have to restore it | 1695 | props.type = BACKLIGHT_FIRMWARE; |
1708 | * before acpi_video_device_lcd_set_level() is called next time. | 1696 | props.max_brightness = device->brightness->count - 3; |
1709 | */ | 1697 | device->backlight = backlight_device_register(name, |
1710 | device->backlight->props.brightness = | 1698 | parent, |
1711 | acpi_video_get_brightness(device->backlight); | 1699 | device, |
1700 | &acpi_backlight_ops, | ||
1701 | &props); | ||
1702 | kfree(name); | ||
1703 | if (IS_ERR(device->backlight)) | ||
1704 | return; | ||
1712 | 1705 | ||
1713 | device->cooling_dev = thermal_cooling_device_register("LCD", | 1706 | /* |
1714 | device->dev, &video_cooling_ops); | 1707 | * Save current brightness level in case we have to restore it |
1715 | if (IS_ERR(device->cooling_dev)) { | 1708 | * before acpi_video_device_lcd_set_level() is called next time. |
1716 | /* | 1709 | */ |
1717 | * Set cooling_dev to NULL so we don't crash trying to | 1710 | device->backlight->props.brightness = |
1718 | * free it. | 1711 | acpi_video_get_brightness(device->backlight); |
1719 | * Also, why the hell we are returning early and | ||
1720 | * not attempt to register video output if cooling | ||
1721 | * device registration failed? | ||
1722 | * -- dtor | ||
1723 | */ | ||
1724 | device->cooling_dev = NULL; | ||
1725 | return; | ||
1726 | } | ||
1727 | 1712 | ||
1728 | dev_info(&device->dev->dev, "registered as cooling_device%d\n", | 1713 | device->cooling_dev = thermal_cooling_device_register("LCD", |
1729 | device->cooling_dev->id); | 1714 | device->dev, &video_cooling_ops); |
1730 | result = sysfs_create_link(&device->dev->dev.kobj, | 1715 | if (IS_ERR(device->cooling_dev)) { |
1731 | &device->cooling_dev->device.kobj, | 1716 | /* |
1732 | "thermal_cooling"); | 1717 | * Set cooling_dev to NULL so we don't crash trying to free it. |
1733 | if (result) | 1718 | * Also, why the hell we are returning early and not attempt to |
1734 | printk(KERN_ERR PREFIX "Create sysfs link\n"); | 1719 | * register video output if cooling device registration failed? |
1735 | result = sysfs_create_link(&device->cooling_dev->device.kobj, | 1720 | * -- dtor |
1736 | &device->dev->dev.kobj, "device"); | 1721 | */ |
1737 | if (result) | 1722 | device->cooling_dev = NULL; |
1738 | printk(KERN_ERR PREFIX "Create sysfs link\n"); | 1723 | return; |
1739 | } | 1724 | } |
1725 | |||
1726 | dev_info(&device->dev->dev, "registered as cooling_device%d\n", | ||
1727 | device->cooling_dev->id); | ||
1728 | result = sysfs_create_link(&device->dev->dev.kobj, | ||
1729 | &device->cooling_dev->device.kobj, | ||
1730 | "thermal_cooling"); | ||
1731 | if (result) | ||
1732 | printk(KERN_ERR PREFIX "Create sysfs link\n"); | ||
1733 | result = sysfs_create_link(&device->cooling_dev->device.kobj, | ||
1734 | &device->dev->dev.kobj, "device"); | ||
1735 | if (result) | ||
1736 | printk(KERN_ERR PREFIX "Create sysfs link\n"); | ||
1740 | } | 1737 | } |
1741 | 1738 | ||
1742 | static int acpi_video_bus_register_backlight(struct acpi_video_bus *video) | 1739 | static int acpi_video_bus_register_backlight(struct acpi_video_bus *video) |
1743 | { | 1740 | { |
1744 | struct acpi_video_device *dev; | 1741 | struct acpi_video_device *dev; |
1745 | 1742 | ||
1743 | if (!acpi_video_verify_backlight_support()) | ||
1744 | return 0; | ||
1745 | |||
1746 | mutex_lock(&video->device_list_lock); | 1746 | mutex_lock(&video->device_list_lock); |
1747 | list_for_each_entry(dev, &video->video_device_list, entry) | 1747 | list_for_each_entry(dev, &video->video_device_list, entry) |
1748 | acpi_video_dev_register_backlight(dev); | 1748 | acpi_video_dev_register_backlight(dev); |
1749 | mutex_unlock(&video->device_list_lock); | 1749 | mutex_unlock(&video->device_list_lock); |
1750 | 1750 | ||
1751 | video->backlight_registered = true; | ||
1752 | |||
1751 | video->pm_nb.notifier_call = acpi_video_resume; | 1753 | video->pm_nb.notifier_call = acpi_video_resume; |
1752 | video->pm_nb.priority = 0; | 1754 | video->pm_nb.priority = 0; |
1753 | return register_pm_notifier(&video->pm_nb); | 1755 | return register_pm_notifier(&video->pm_nb); |
@@ -1775,13 +1777,20 @@ static void acpi_video_dev_unregister_backlight(struct acpi_video_device *device | |||
1775 | static int acpi_video_bus_unregister_backlight(struct acpi_video_bus *video) | 1777 | static int acpi_video_bus_unregister_backlight(struct acpi_video_bus *video) |
1776 | { | 1778 | { |
1777 | struct acpi_video_device *dev; | 1779 | struct acpi_video_device *dev; |
1778 | int error = unregister_pm_notifier(&video->pm_nb); | 1780 | int error; |
1781 | |||
1782 | if (!video->backlight_registered) | ||
1783 | return 0; | ||
1784 | |||
1785 | error = unregister_pm_notifier(&video->pm_nb); | ||
1779 | 1786 | ||
1780 | mutex_lock(&video->device_list_lock); | 1787 | mutex_lock(&video->device_list_lock); |
1781 | list_for_each_entry(dev, &video->video_device_list, entry) | 1788 | list_for_each_entry(dev, &video->video_device_list, entry) |
1782 | acpi_video_dev_unregister_backlight(dev); | 1789 | acpi_video_dev_unregister_backlight(dev); |
1783 | mutex_unlock(&video->device_list_lock); | 1790 | mutex_unlock(&video->device_list_lock); |
1784 | 1791 | ||
1792 | video->backlight_registered = false; | ||
1793 | |||
1785 | return error; | 1794 | return error; |
1786 | } | 1795 | } |
1787 | 1796 | ||