Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 1 | /* |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 2 | * Copyright (C) 2015 Red Hat Inc. |
| 3 | * Hans de Goede <hdegoede@redhat.com> |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 4 | * Copyright (C) 2008 SuSE Linux Products GmbH |
| 5 | * Thomas Renninger <trenn@suse.de> |
| 6 | * |
| 7 | * May be copied or modified under the terms of the GNU General Public License |
| 8 | * |
| 9 | * video_detect.c: |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 10 | * After PCI devices are glued with ACPI devices |
Alexander Chiang | 1e4cffe | 2009-06-10 19:56:00 +0000 | [diff] [blame] | 11 | * acpi_get_pci_dev() can be called to identify ACPI graphics |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 12 | * devices for which a real graphics card is plugged in |
| 13 | * |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 14 | * Depending on whether ACPI graphics extensions (cmp. ACPI spec Appendix B) |
| 15 | * are available, video.ko should be used to handle the device. |
| 16 | * |
Corentin Chary | 7ec48ce | 2011-12-15 08:27:37 +0100 | [diff] [blame] | 17 | * Otherwise vendor specific drivers like thinkpad_acpi, asus-laptop, |
Zhang Rui | 677bd81 | 2010-12-06 15:04:21 +0800 | [diff] [blame] | 18 | * sony_acpi,... can take care about backlight brightness. |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 19 | * |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 20 | * Backlight drivers can use acpi_video_get_backlight_type() to determine |
| 21 | * which driver should handle the backlight. |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 22 | * |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 23 | * If CONFIG_ACPI_VIDEO is neither set as "compiled in" (y) nor as a module (m) |
| 24 | * this file will not be compiled and acpi_video_get_backlight_type() will |
| 25 | * always return acpi_backlight_vendor. |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 26 | */ |
| 27 | |
Paul Gortmaker | 214f2c9 | 2011-10-26 16:22:14 -0400 | [diff] [blame] | 28 | #include <linux/export.h> |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 29 | #include <linux/acpi.h> |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 30 | #include <linux/backlight.h> |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 31 | #include <linux/dmi.h> |
Hans de Goede | 14ca7a47 | 2015-06-16 16:27:47 +0200 | [diff] [blame] | 32 | #include <linux/module.h> |
Alexander Chiang | 1e4cffe | 2009-06-10 19:56:00 +0000 | [diff] [blame] | 33 | #include <linux/pci.h> |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 34 | #include <linux/types.h> |
| 35 | #include <acpi/video.h> |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 36 | |
| 37 | ACPI_MODULE_NAME("video"); |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 38 | #define _COMPONENT ACPI_VIDEO_COMPONENT |
| 39 | |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 40 | static enum acpi_backlight_type acpi_backlight_cmdline = acpi_backlight_undef; |
| 41 | static enum acpi_backlight_type acpi_backlight_dmi = acpi_backlight_undef; |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 42 | |
Hans de Goede | 14ca7a47 | 2015-06-16 16:27:47 +0200 | [diff] [blame] | 43 | static void acpi_video_parse_cmdline(void) |
| 44 | { |
| 45 | if (!strcmp("vendor", acpi_video_backlight_string)) |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 46 | acpi_backlight_cmdline = acpi_backlight_vendor; |
Hans de Goede | 14ca7a47 | 2015-06-16 16:27:47 +0200 | [diff] [blame] | 47 | if (!strcmp("video", acpi_video_backlight_string)) |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 48 | acpi_backlight_cmdline = acpi_backlight_video; |
| 49 | if (!strcmp("native", acpi_video_backlight_string)) |
| 50 | acpi_backlight_cmdline = acpi_backlight_native; |
| 51 | if (!strcmp("none", acpi_video_backlight_string)) |
| 52 | acpi_backlight_cmdline = acpi_backlight_none; |
Hans de Goede | 14ca7a47 | 2015-06-16 16:27:47 +0200 | [diff] [blame] | 53 | } |
| 54 | |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 55 | static acpi_status |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 56 | find_video(acpi_handle handle, u32 lvl, void *context, void **rv) |
| 57 | { |
| 58 | long *cap = context; |
Alexander Chiang | 1e4cffe | 2009-06-10 19:56:00 +0000 | [diff] [blame] | 59 | struct pci_dev *dev; |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 60 | struct acpi_device *acpi_dev; |
| 61 | |
Mathias Krause | 4a4f01a | 2015-06-13 14:26:59 +0200 | [diff] [blame] | 62 | static const struct acpi_device_id video_ids[] = { |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 63 | {ACPI_VIDEO_HID, 0}, |
| 64 | {"", 0}, |
| 65 | }; |
| 66 | if (acpi_bus_get_device(handle, &acpi_dev)) |
| 67 | return AE_OK; |
| 68 | |
| 69 | if (!acpi_match_device_ids(acpi_dev, video_ids)) { |
Alexander Chiang | 1e4cffe | 2009-06-10 19:56:00 +0000 | [diff] [blame] | 70 | dev = acpi_get_pci_dev(handle); |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 71 | if (!dev) |
| 72 | return AE_OK; |
Alexander Chiang | 1e4cffe | 2009-06-10 19:56:00 +0000 | [diff] [blame] | 73 | pci_dev_put(dev); |
Toshi Kani | d4e1a69 | 2013-03-04 21:30:41 +0000 | [diff] [blame] | 74 | *cap |= acpi_is_video_device(handle); |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 75 | } |
| 76 | return AE_OK; |
| 77 | } |
| 78 | |
Corentin Chary | 084940d | 2012-06-13 09:32:04 +0200 | [diff] [blame] | 79 | /* Force to use vendor driver when the ACPI device is known to be |
| 80 | * buggy */ |
| 81 | static int video_detect_force_vendor(const struct dmi_system_id *d) |
| 82 | { |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 83 | acpi_backlight_dmi = acpi_backlight_vendor; |
Corentin Chary | 084940d | 2012-06-13 09:32:04 +0200 | [diff] [blame] | 84 | return 0; |
| 85 | } |
| 86 | |
Mathias Krause | 4a4f01a | 2015-06-13 14:26:59 +0200 | [diff] [blame] | 87 | static const struct dmi_system_id video_detect_dmi_table[] = { |
Corentin Chary | 084940d | 2012-06-13 09:32:04 +0200 | [diff] [blame] | 88 | /* On Samsung X360, the BIOS will set a flag (VDRV) if generic |
| 89 | * ACPI backlight device is used. This flag will definitively break |
| 90 | * the backlight interface (even the vendor interface) untill next |
| 91 | * reboot. It's why we should prevent video.ko from being used here |
| 92 | * and we can't rely on a later call to acpi_video_unregister(). |
| 93 | */ |
| 94 | { |
| 95 | .callback = video_detect_force_vendor, |
| 96 | .ident = "X360", |
| 97 | .matches = { |
| 98 | DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), |
| 99 | DMI_MATCH(DMI_PRODUCT_NAME, "X360"), |
| 100 | DMI_MATCH(DMI_BOARD_NAME, "X360"), |
| 101 | }, |
| 102 | }, |
Lan Tianyu | d0c2ce1 | 2012-11-30 13:02:50 +0100 | [diff] [blame] | 103 | { |
| 104 | .callback = video_detect_force_vendor, |
| 105 | .ident = "Asus UL30VT", |
| 106 | .matches = { |
| 107 | DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."), |
| 108 | DMI_MATCH(DMI_PRODUCT_NAME, "UL30VT"), |
| 109 | }, |
| 110 | }, |
Bastian Triller | c8f6d83 | 2013-05-19 11:52:33 +0000 | [diff] [blame] | 111 | { |
| 112 | .callback = video_detect_force_vendor, |
| 113 | .ident = "Asus UL30A", |
| 114 | .matches = { |
| 115 | DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."), |
| 116 | DMI_MATCH(DMI_PRODUCT_NAME, "UL30A"), |
| 117 | }, |
| 118 | }, |
Edward Lin | 08a5622 | 2014-06-20 16:13:42 +0800 | [diff] [blame] | 119 | { |
| 120 | .callback = video_detect_force_vendor, |
| 121 | .ident = "Dell Inspiron 5737", |
| 122 | .matches = { |
| 123 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 124 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5737"), |
| 125 | }, |
| 126 | }, |
Corentin Chary | 084940d | 2012-06-13 09:32:04 +0200 | [diff] [blame] | 127 | { }, |
| 128 | }; |
| 129 | |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 130 | /* |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 131 | * Determine which type of backlight interface to use on this system, |
| 132 | * First check cmdline, then dmi quirks, then do autodetect. |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 133 | * |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 134 | * The autodetect order is: |
| 135 | * 1) Is the acpi-video backlight interface supported -> |
| 136 | * no, use a vendor interface |
| 137 | * 2) Is this a win8 "ready" BIOS and do we have a native interface -> |
| 138 | * yes, use a native interface |
| 139 | * 3) Else use the acpi-video interface |
| 140 | * |
| 141 | * Arguably the native on win8 check should be done first, but that would |
| 142 | * be a behavior change, which may causes issues. |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 143 | */ |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 144 | enum acpi_backlight_type acpi_video_get_backlight_type(void) |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 145 | { |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 146 | static DEFINE_MUTEX(init_mutex); |
| 147 | static bool init_done; |
| 148 | static long video_caps; |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 149 | |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 150 | /* Parse cmdline, dmi and acpi only once */ |
| 151 | mutex_lock(&init_mutex); |
| 152 | if (!init_done) { |
| 153 | acpi_video_parse_cmdline(); |
| 154 | dmi_check_system(video_detect_dmi_table); |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 155 | acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, |
Lin Ming | 2263576 | 2009-11-13 10:06:08 +0800 | [diff] [blame] | 156 | ACPI_UINT32_MAX, find_video, NULL, |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 157 | &video_caps, NULL); |
| 158 | init_done = true; |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 159 | } |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 160 | mutex_unlock(&init_mutex); |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 161 | |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 162 | if (acpi_backlight_cmdline != acpi_backlight_undef) |
| 163 | return acpi_backlight_cmdline; |
Corentin Chary | f838eb5 | 2012-06-13 09:32:01 +0200 | [diff] [blame] | 164 | |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 165 | if (acpi_backlight_dmi != acpi_backlight_undef) |
| 166 | return acpi_backlight_dmi; |
| 167 | |
| 168 | if (!(video_caps & ACPI_VIDEO_BACKLIGHT)) |
| 169 | return acpi_backlight_vendor; |
| 170 | |
| 171 | if (acpi_osi_is_win8() && backlight_device_registered(BACKLIGHT_RAW)) |
| 172 | return acpi_backlight_native; |
| 173 | |
| 174 | return acpi_backlight_video; |
| 175 | } |
| 176 | EXPORT_SYMBOL(acpi_video_get_backlight_type); |
| 177 | |
| 178 | /* |
| 179 | * Set the preferred backlight interface type based on DMI info. |
| 180 | * This function allows DMI blacklists to be implemented by external |
Corentin Chary | f838eb5 | 2012-06-13 09:32:01 +0200 | [diff] [blame] | 181 | * platform drivers instead of putting a big blacklist in video_detect.c |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 182 | */ |
| 183 | void acpi_video_set_dmi_backlight_type(enum acpi_backlight_type type) |
| 184 | { |
| 185 | acpi_backlight_dmi = type; |
Hans de Goede | 5fd677b | 2015-06-16 16:27:49 +0200 | [diff] [blame^] | 186 | /* Remove acpi-video backlight interface if it is no longer desired */ |
| 187 | if (acpi_video_get_backlight_type() != acpi_backlight_video) |
| 188 | acpi_video_unregister_backlight(); |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 189 | } |
| 190 | EXPORT_SYMBOL(acpi_video_set_dmi_backlight_type); |
| 191 | |
| 192 | /* |
| 193 | * Compatiblity function, this is going away as soon as all drivers are |
| 194 | * converted to acpi_video_set_dmi_backlight_type(). |
| 195 | * |
| 196 | * Promote the vendor interface instead of the generic video module. |
Corentin Chary | f838eb5 | 2012-06-13 09:32:01 +0200 | [diff] [blame] | 197 | * After calling this function you will probably want to call |
| 198 | * acpi_video_unregister() to make sure the video module is not loaded |
| 199 | */ |
| 200 | void acpi_video_dmi_promote_vendor(void) |
| 201 | { |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 202 | acpi_video_set_dmi_backlight_type(acpi_backlight_vendor); |
Corentin Chary | f838eb5 | 2012-06-13 09:32:01 +0200 | [diff] [blame] | 203 | } |
| 204 | EXPORT_SYMBOL(acpi_video_dmi_promote_vendor); |
| 205 | |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 206 | /* |
| 207 | * Compatiblity function, this is going away as soon as all drivers are |
| 208 | * converted to acpi_video_get_backlight_type(). |
| 209 | * |
| 210 | * Returns true if video.ko can do backlight switching. |
| 211 | */ |
Corentin Chary | f838eb5 | 2012-06-13 09:32:01 +0200 | [diff] [blame] | 212 | int acpi_video_backlight_support(void) |
| 213 | { |
Hans de Goede | 87521e1 | 2015-06-16 16:27:48 +0200 | [diff] [blame] | 214 | /* |
| 215 | * This is done this way since vendor drivers call this to see |
| 216 | * if they should load, and we do not want them to load for both |
| 217 | * the acpi_backlight_video and acpi_backlight_native cases. |
| 218 | */ |
| 219 | return acpi_video_get_backlight_type() != acpi_backlight_vendor; |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 220 | } |
| 221 | EXPORT_SYMBOL(acpi_video_backlight_support); |