@@ -68,7 +68,7 @@ MODULE_AUTHOR("Bruno Ducrot");
6868MODULE_DESCRIPTION ("ACPI Video Driver" );
6969MODULE_LICENSE ("GPL" );
7070
71- static bool brightness_switch_enabled = 1 ;
71+ static bool brightness_switch_enabled ;
7272module_param (brightness_switch_enabled , bool , 0644 );
7373
7474/*
@@ -150,6 +150,8 @@ struct acpi_video_enumerated_device {
150150
151151struct acpi_video_bus {
152152 struct acpi_device * device ;
153+ bool backlight_registered ;
154+ bool backlight_notifier_registered ;
153155 u8 dos_setting ;
154156 struct acpi_video_enumerated_device * attached_array ;
155157 u8 attached_count ;
@@ -161,6 +163,7 @@ struct acpi_video_bus {
161163 struct input_dev * input ;
162164 char phys [32 ]; /* for input device */
163165 struct notifier_block pm_nb ;
166+ struct notifier_block backlight_nb ;
164167};
165168
166169struct acpi_video_device_flags {
@@ -471,6 +474,14 @@ static struct dmi_system_id video_dmi_table[] __initdata = {
471474 DMI_MATCH (DMI_PRODUCT_VERSION , "ThinkPad X230" ),
472475 },
473476 },
477+ {
478+ .callback = video_set_use_native_backlight ,
479+ .ident = "ThinkPad W530" ,
480+ .matches = {
481+ DMI_MATCH (DMI_SYS_VENDOR , "LENOVO" ),
482+ DMI_MATCH (DMI_PRODUCT_VERSION , "ThinkPad W530" ),
483+ },
484+ },
474485 {
475486 .callback = video_set_use_native_backlight ,
476487 .ident = "ThinkPad X1 Carbon" ,
@@ -487,6 +498,14 @@ static struct dmi_system_id video_dmi_table[] __initdata = {
487498 DMI_MATCH (DMI_PRODUCT_VERSION , "Lenovo IdeaPad Yoga 13" ),
488499 },
489500 },
501+ {
502+ .callback = video_set_use_native_backlight ,
503+ .ident = "Lenovo Yoga 2 11" ,
504+ .matches = {
505+ DMI_MATCH (DMI_SYS_VENDOR , "LENOVO" ),
506+ DMI_MATCH (DMI_PRODUCT_VERSION , "Lenovo Yoga 2 11" ),
507+ },
508+ },
490509 {
491510 .callback = video_set_use_native_backlight ,
492511 .ident = "Thinkpad Helix" ,
@@ -519,6 +538,14 @@ static struct dmi_system_id video_dmi_table[] __initdata = {
519538 DMI_MATCH (DMI_PRODUCT_NAME , "Aspire 5742G" ),
520539 },
521540 },
541+ {
542+ .callback = video_set_use_native_backlight ,
543+ .ident = "Acer Aspire V5-171" ,
544+ .matches = {
545+ DMI_MATCH (DMI_SYS_VENDOR , "Acer" ),
546+ DMI_MATCH (DMI_PRODUCT_NAME , "V5-171" ),
547+ },
548+ },
522549 {
523550 .callback = video_set_use_native_backlight ,
524551 .ident = "Acer Aspire V5-431" ,
@@ -527,6 +554,14 @@ static struct dmi_system_id video_dmi_table[] __initdata = {
527554 DMI_MATCH (DMI_PRODUCT_NAME , "Aspire V5-431" ),
528555 },
529556 },
557+ {
558+ .callback = video_set_use_native_backlight ,
559+ .ident = "Acer Aspire V5-471G" ,
560+ .matches = {
561+ DMI_MATCH (DMI_BOARD_VENDOR , "Acer" ),
562+ DMI_MATCH (DMI_PRODUCT_NAME , "Aspire V5-471G" ),
563+ },
564+ },
530565 {
531566 .callback = video_set_use_native_backlight ,
532567 .ident = "HP ProBook 4340s" ,
@@ -579,6 +614,14 @@ static struct dmi_system_id video_dmi_table[] __initdata = {
579614 },
580615 {
581616 .callback = video_set_use_native_backlight ,
617+ .ident = "HP EliteBook 8470p" ,
618+ .matches = {
619+ DMI_MATCH (DMI_SYS_VENDOR , "Hewlett-Packard" ),
620+ DMI_MATCH (DMI_PRODUCT_NAME , "HP EliteBook 8470p" ),
621+ },
622+ },
623+ {
624+ .callback = video_set_use_native_backlight ,
582625 .ident = "HP EliteBook 8780w" ,
583626 .matches = {
584627 DMI_MATCH (DMI_SYS_VENDOR , "Hewlett-Packard" ),
@@ -1658,88 +1701,92 @@ acpi_video_bus_match(acpi_handle handle, u32 level, void *context,
16581701
16591702static void acpi_video_dev_register_backlight (struct acpi_video_device * device )
16601703{
1661- if (acpi_video_verify_backlight_support ()) {
1662- struct backlight_properties props ;
1663- struct pci_dev * pdev ;
1664- acpi_handle acpi_parent ;
1665- struct device * parent = NULL ;
1666- int result ;
1667- static int count ;
1668- char * name ;
1669-
1670- result = acpi_video_init_brightness (device );
1671- if (result )
1672- return ;
1673- name = kasprintf (GFP_KERNEL , "acpi_video%d" , count );
1674- if (!name )
1675- return ;
1676- count ++ ;
1704+ struct backlight_properties props ;
1705+ struct pci_dev * pdev ;
1706+ acpi_handle acpi_parent ;
1707+ struct device * parent = NULL ;
1708+ int result ;
1709+ static int count ;
1710+ char * name ;
16771711
1678- acpi_get_parent (device -> dev -> handle , & acpi_parent );
1712+ result = acpi_video_init_brightness (device );
1713+ if (result )
1714+ return ;
1715+ name = kasprintf (GFP_KERNEL , "acpi_video%d" , count );
1716+ if (!name )
1717+ return ;
1718+ count ++ ;
16791719
1680- pdev = acpi_get_pci_dev (acpi_parent );
1681- if (pdev ) {
1682- parent = & pdev -> dev ;
1683- pci_dev_put (pdev );
1684- }
1720+ acpi_get_parent (device -> dev -> handle , & acpi_parent );
16851721
1686- memset (& props , 0 , sizeof (struct backlight_properties ));
1687- props .type = BACKLIGHT_FIRMWARE ;
1688- props .max_brightness = device -> brightness -> count - 3 ;
1689- device -> backlight = backlight_device_register (name ,
1690- parent ,
1691- device ,
1692- & acpi_backlight_ops ,
1693- & props );
1694- kfree (name );
1695- if (IS_ERR (device -> backlight ))
1696- return ;
1722+ pdev = acpi_get_pci_dev (acpi_parent );
1723+ if (pdev ) {
1724+ parent = & pdev -> dev ;
1725+ pci_dev_put (pdev );
1726+ }
16971727
1698- /*
1699- * Save current brightness level in case we have to restore it
1700- * before acpi_video_device_lcd_set_level() is called next time.
1701- */
1702- device -> backlight -> props .brightness =
1703- acpi_video_get_brightness (device -> backlight );
1728+ memset (& props , 0 , sizeof (struct backlight_properties ));
1729+ props .type = BACKLIGHT_FIRMWARE ;
1730+ props .max_brightness = device -> brightness -> count - 3 ;
1731+ device -> backlight = backlight_device_register (name ,
1732+ parent ,
1733+ device ,
1734+ & acpi_backlight_ops ,
1735+ & props );
1736+ kfree (name );
1737+ if (IS_ERR (device -> backlight ))
1738+ return ;
17041739
1705- device -> cooling_dev = thermal_cooling_device_register ("LCD" ,
1706- device -> dev , & video_cooling_ops );
1707- if (IS_ERR (device -> cooling_dev )) {
1708- /*
1709- * Set cooling_dev to NULL so we don't crash trying to
1710- * free it.
1711- * Also, why the hell we are returning early and
1712- * not attempt to register video output if cooling
1713- * device registration failed?
1714- * -- dtor
1715- */
1716- device -> cooling_dev = NULL ;
1717- return ;
1718- }
1740+ /*
1741+ * Save current brightness level in case we have to restore it
1742+ * before acpi_video_device_lcd_set_level() is called next time.
1743+ */
1744+ device -> backlight -> props .brightness =
1745+ acpi_video_get_brightness (device -> backlight );
17191746
1720- dev_info ( & device -> dev -> dev , "registered as cooling_device%d\n " ,
1721- device -> cooling_dev -> id );
1722- result = sysfs_create_link ( & device -> dev -> dev . kobj ,
1723- & device -> cooling_dev -> device . kobj ,
1724- "thermal_cooling" );
1725- if ( result )
1726- printk ( KERN_ERR PREFIX "Create sysfs link\n" );
1727- result = sysfs_create_link ( & device -> cooling_dev -> device . kobj ,
1728- & device -> dev -> dev . kobj , "device" );
1729- if ( result )
1730- printk ( KERN_ERR PREFIX "Create sysfs link\n" ) ;
1747+ device -> cooling_dev = thermal_cooling_device_register ( "LCD " ,
1748+ device -> dev , & video_cooling_ops );
1749+ if ( IS_ERR ( device -> cooling_dev )) {
1750+ /*
1751+ * Set cooling_dev to NULL so we don't crash trying to free it.
1752+ * Also, why the hell we are returning early and not attempt to
1753+ * register video output if cooling device registration failed?
1754+ * -- dtor
1755+ */
1756+ device -> cooling_dev = NULL ;
1757+ return ;
17311758 }
1759+
1760+ dev_info (& device -> dev -> dev , "registered as cooling_device%d\n" ,
1761+ device -> cooling_dev -> id );
1762+ result = sysfs_create_link (& device -> dev -> dev .kobj ,
1763+ & device -> cooling_dev -> device .kobj ,
1764+ "thermal_cooling" );
1765+ if (result )
1766+ printk (KERN_ERR PREFIX "Create sysfs link\n" );
1767+ result = sysfs_create_link (& device -> cooling_dev -> device .kobj ,
1768+ & device -> dev -> dev .kobj , "device" );
1769+ if (result )
1770+ printk (KERN_ERR PREFIX "Create sysfs link\n" );
17321771}
17331772
17341773static int acpi_video_bus_register_backlight (struct acpi_video_bus * video )
17351774{
17361775 struct acpi_video_device * dev ;
17371776
1777+ if (video -> backlight_registered )
1778+ return 0 ;
1779+
1780+ if (!acpi_video_verify_backlight_support ())
1781+ return 0 ;
1782+
17381783 mutex_lock (& video -> device_list_lock );
17391784 list_for_each_entry (dev , & video -> video_device_list , entry )
17401785 acpi_video_dev_register_backlight (dev );
17411786 mutex_unlock (& video -> device_list_lock );
17421787
1788+ video -> backlight_registered = true;
1789+
17431790 video -> pm_nb .notifier_call = acpi_video_resume ;
17441791 video -> pm_nb .priority = 0 ;
17451792 return register_pm_notifier (& video -> pm_nb );
@@ -1767,13 +1814,20 @@ static void acpi_video_dev_unregister_backlight(struct acpi_video_device *device
17671814static int acpi_video_bus_unregister_backlight (struct acpi_video_bus * video )
17681815{
17691816 struct acpi_video_device * dev ;
1770- int error = unregister_pm_notifier (& video -> pm_nb );
1817+ int error ;
1818+
1819+ if (!video -> backlight_registered )
1820+ return 0 ;
1821+
1822+ error = unregister_pm_notifier (& video -> pm_nb );
17711823
17721824 mutex_lock (& video -> device_list_lock );
17731825 list_for_each_entry (dev , & video -> video_device_list , entry )
17741826 acpi_video_dev_unregister_backlight (dev );
17751827 mutex_unlock (& video -> device_list_lock );
17761828
1829+ video -> backlight_registered = false;
1830+
17771831 return error ;
17781832}
17791833
@@ -1867,6 +1921,56 @@ static void acpi_video_bus_remove_notify_handler(struct acpi_video_bus *video)
18671921 video -> input = NULL ;
18681922}
18691923
1924+ static int acpi_video_backlight_notify (struct notifier_block * nb ,
1925+ unsigned long val , void * bd )
1926+ {
1927+ struct backlight_device * backlight = bd ;
1928+ struct acpi_video_bus * video ;
1929+
1930+ /* acpi_video_verify_backlight_support only cares about raw devices */
1931+ if (backlight -> props .type != BACKLIGHT_RAW )
1932+ return NOTIFY_DONE ;
1933+
1934+ video = container_of (nb , struct acpi_video_bus , backlight_nb );
1935+
1936+ switch (val ) {
1937+ case BACKLIGHT_REGISTERED :
1938+ if (!acpi_video_verify_backlight_support ())
1939+ acpi_video_bus_unregister_backlight (video );
1940+ break ;
1941+ case BACKLIGHT_UNREGISTERED :
1942+ acpi_video_bus_register_backlight (video );
1943+ break ;
1944+ }
1945+
1946+ return NOTIFY_OK ;
1947+ }
1948+
1949+ static int acpi_video_bus_add_backlight_notify_handler (
1950+ struct acpi_video_bus * video )
1951+ {
1952+ int error ;
1953+
1954+ video -> backlight_nb .notifier_call = acpi_video_backlight_notify ;
1955+ video -> backlight_nb .priority = 0 ;
1956+ error = backlight_register_notifier (& video -> backlight_nb );
1957+ if (error == 0 )
1958+ video -> backlight_notifier_registered = true;
1959+
1960+ return error ;
1961+ }
1962+
1963+ static int acpi_video_bus_remove_backlight_notify_handler (
1964+ struct acpi_video_bus * video )
1965+ {
1966+ if (!video -> backlight_notifier_registered )
1967+ return 0 ;
1968+
1969+ video -> backlight_notifier_registered = false;
1970+
1971+ return backlight_unregister_notifier (& video -> backlight_nb );
1972+ }
1973+
18701974static int acpi_video_bus_put_devices (struct acpi_video_bus * video )
18711975{
18721976 struct acpi_video_device * dev , * next ;
@@ -1948,6 +2052,7 @@ static int acpi_video_bus_add(struct acpi_device *device)
19482052
19492053 acpi_video_bus_register_backlight (video );
19502054 acpi_video_bus_add_notify_handler (video );
2055+ acpi_video_bus_add_backlight_notify_handler (video );
19512056
19522057 return 0 ;
19532058
@@ -1971,6 +2076,7 @@ static int acpi_video_bus_remove(struct acpi_device *device)
19712076
19722077 video = acpi_driver_data (device );
19732078
2079+ acpi_video_bus_remove_backlight_notify_handler (video );
19742080 acpi_video_bus_remove_notify_handler (video );
19752081 acpi_video_bus_unregister_backlight (video );
19762082 acpi_video_bus_put_devices (video );
@@ -2061,6 +2167,20 @@ void acpi_video_unregister(void)
20612167}
20622168EXPORT_SYMBOL (acpi_video_unregister );
20632169
2170+ void acpi_video_unregister_backlight (void )
2171+ {
2172+ struct acpi_video_bus * video ;
2173+
2174+ if (!register_count )
2175+ return ;
2176+
2177+ mutex_lock (& video_list_lock );
2178+ list_for_each_entry (video , & video_bus_head , entry )
2179+ acpi_video_bus_unregister_backlight (video );
2180+ mutex_unlock (& video_list_lock );
2181+ }
2182+ EXPORT_SYMBOL (acpi_video_unregister_backlight );
2183+
20642184/*
20652185 * This is kind of nasty. Hardware using Intel chipsets may require
20662186 * the video opregion code to be run first in order to initialise
0 commit comments