Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 SuSE Linux Products GmbH |
| 3 | * Thomas Renninger <trenn@suse.de> |
| 4 | * |
| 5 | * May be copied or modified under the terms of the GNU General Public License |
| 6 | * |
| 7 | * video_detect.c: |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 8 | * After PCI devices are glued with ACPI devices |
Alexander Chiang | 1e4cffe | 2009-06-10 19:56:00 +0000 | [diff] [blame] | 9 | * acpi_get_pci_dev() can be called to identify ACPI graphics |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 10 | * devices for which a real graphics card is plugged in |
| 11 | * |
| 12 | * Now acpi_video_get_capabilities() can be called to check which |
| 13 | * capabilities the graphics cards plugged in support. The check for general |
| 14 | * video capabilities will be triggered by the first caller of |
| 15 | * acpi_video_get_capabilities(NULL); which will happen when the first |
Zhang Rui | 677bd81 | 2010-12-06 15:04:21 +0800 | [diff] [blame] | 16 | * backlight switching supporting driver calls: |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 17 | * acpi_video_backlight_support(); |
| 18 | * |
| 19 | * Depending on whether ACPI graphics extensions (cmp. ACPI spec Appendix B) |
| 20 | * are available, video.ko should be used to handle the device. |
| 21 | * |
Corentin Chary | 7ec48ce | 2011-12-15 08:27:37 +0100 | [diff] [blame] | 22 | * Otherwise vendor specific drivers like thinkpad_acpi, asus-laptop, |
Zhang Rui | 677bd81 | 2010-12-06 15:04:21 +0800 | [diff] [blame] | 23 | * sony_acpi,... can take care about backlight brightness. |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 24 | * |
| 25 | * If CONFIG_ACPI_VIDEO is neither set as "compiled in" (y) nor as a module (m) |
| 26 | * this file will not be compiled, acpi_video_get_capabilities() and |
| 27 | * acpi_video_backlight_support() will always return 0 and vendor specific |
| 28 | * drivers always can handle backlight. |
| 29 | * |
| 30 | */ |
| 31 | |
Paul Gortmaker | 214f2c9 | 2011-10-26 16:22:14 -0400 | [diff] [blame] | 32 | #include <linux/export.h> |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 33 | #include <linux/acpi.h> |
| 34 | #include <linux/dmi.h> |
Hans de Goede | 14ca7a47 | 2015-06-16 16:27:47 +0200 | [diff] [blame^] | 35 | #include <linux/module.h> |
Alexander Chiang | 1e4cffe | 2009-06-10 19:56:00 +0000 | [diff] [blame] | 36 | #include <linux/pci.h> |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 37 | |
| 38 | ACPI_MODULE_NAME("video"); |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 39 | #define _COMPONENT ACPI_VIDEO_COMPONENT |
| 40 | |
| 41 | static long acpi_video_support; |
| 42 | static bool acpi_video_caps_checked; |
| 43 | |
Hans de Goede | 14ca7a47 | 2015-06-16 16:27:47 +0200 | [diff] [blame^] | 44 | static void acpi_video_parse_cmdline(void) |
| 45 | { |
| 46 | if (!strcmp("vendor", acpi_video_backlight_string)) |
| 47 | acpi_video_support |= ACPI_VIDEO_BACKLIGHT_FORCE_VENDOR; |
| 48 | if (!strcmp("video", acpi_video_backlight_string)) |
| 49 | acpi_video_support |= ACPI_VIDEO_BACKLIGHT_FORCE_VIDEO; |
| 50 | } |
| 51 | |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 52 | static acpi_status |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 53 | find_video(acpi_handle handle, u32 lvl, void *context, void **rv) |
| 54 | { |
| 55 | long *cap = context; |
Alexander Chiang | 1e4cffe | 2009-06-10 19:56:00 +0000 | [diff] [blame] | 56 | struct pci_dev *dev; |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 57 | struct acpi_device *acpi_dev; |
| 58 | |
Mathias Krause | 4a4f01a | 2015-06-13 14:26:59 +0200 | [diff] [blame] | 59 | static const struct acpi_device_id video_ids[] = { |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 60 | {ACPI_VIDEO_HID, 0}, |
| 61 | {"", 0}, |
| 62 | }; |
| 63 | if (acpi_bus_get_device(handle, &acpi_dev)) |
| 64 | return AE_OK; |
| 65 | |
| 66 | if (!acpi_match_device_ids(acpi_dev, video_ids)) { |
Alexander Chiang | 1e4cffe | 2009-06-10 19:56:00 +0000 | [diff] [blame] | 67 | dev = acpi_get_pci_dev(handle); |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 68 | if (!dev) |
| 69 | return AE_OK; |
Alexander Chiang | 1e4cffe | 2009-06-10 19:56:00 +0000 | [diff] [blame] | 70 | pci_dev_put(dev); |
Toshi Kani | d4e1a69 | 2013-03-04 21:30:41 +0000 | [diff] [blame] | 71 | *cap |= acpi_is_video_device(handle); |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 72 | } |
| 73 | return AE_OK; |
| 74 | } |
| 75 | |
Corentin Chary | 084940d | 2012-06-13 09:32:04 +0200 | [diff] [blame] | 76 | /* Force to use vendor driver when the ACPI device is known to be |
| 77 | * buggy */ |
| 78 | static int video_detect_force_vendor(const struct dmi_system_id *d) |
| 79 | { |
| 80 | acpi_video_support |= ACPI_VIDEO_BACKLIGHT_DMI_VENDOR; |
| 81 | return 0; |
| 82 | } |
| 83 | |
Mathias Krause | 4a4f01a | 2015-06-13 14:26:59 +0200 | [diff] [blame] | 84 | static const struct dmi_system_id video_detect_dmi_table[] = { |
Corentin Chary | 084940d | 2012-06-13 09:32:04 +0200 | [diff] [blame] | 85 | /* On Samsung X360, the BIOS will set a flag (VDRV) if generic |
| 86 | * ACPI backlight device is used. This flag will definitively break |
| 87 | * the backlight interface (even the vendor interface) untill next |
| 88 | * reboot. It's why we should prevent video.ko from being used here |
| 89 | * and we can't rely on a later call to acpi_video_unregister(). |
| 90 | */ |
| 91 | { |
| 92 | .callback = video_detect_force_vendor, |
| 93 | .ident = "X360", |
| 94 | .matches = { |
| 95 | DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), |
| 96 | DMI_MATCH(DMI_PRODUCT_NAME, "X360"), |
| 97 | DMI_MATCH(DMI_BOARD_NAME, "X360"), |
| 98 | }, |
| 99 | }, |
Lan Tianyu | d0c2ce1 | 2012-11-30 13:02:50 +0100 | [diff] [blame] | 100 | { |
| 101 | .callback = video_detect_force_vendor, |
| 102 | .ident = "Asus UL30VT", |
| 103 | .matches = { |
| 104 | DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."), |
| 105 | DMI_MATCH(DMI_PRODUCT_NAME, "UL30VT"), |
| 106 | }, |
| 107 | }, |
Bastian Triller | c8f6d83 | 2013-05-19 11:52:33 +0000 | [diff] [blame] | 108 | { |
| 109 | .callback = video_detect_force_vendor, |
| 110 | .ident = "Asus UL30A", |
| 111 | .matches = { |
| 112 | DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."), |
| 113 | DMI_MATCH(DMI_PRODUCT_NAME, "UL30A"), |
| 114 | }, |
| 115 | }, |
Edward Lin | 08a5622 | 2014-06-20 16:13:42 +0800 | [diff] [blame] | 116 | { |
| 117 | .callback = video_detect_force_vendor, |
| 118 | .ident = "Dell Inspiron 5737", |
| 119 | .matches = { |
| 120 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 121 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5737"), |
| 122 | }, |
| 123 | }, |
Corentin Chary | 084940d | 2012-06-13 09:32:04 +0200 | [diff] [blame] | 124 | { }, |
| 125 | }; |
| 126 | |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 127 | /* |
| 128 | * Returns the video capabilities of a specific ACPI graphics device |
| 129 | * |
| 130 | * if NULL is passed as argument all ACPI devices are enumerated and |
| 131 | * all graphics capabilities of physically present devices are |
Thadeu Lima de Souza Cascardo | 94e2bd6 | 2009-10-16 15:20:49 +0200 | [diff] [blame] | 132 | * summarized and returned. This is cached and done only once. |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 133 | */ |
Hans de Goede | fb105d9 | 2015-06-16 16:27:44 +0200 | [diff] [blame] | 134 | static long acpi_video_get_capabilities(acpi_handle graphics_handle) |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 135 | { |
| 136 | long caps = 0; |
| 137 | struct acpi_device *tmp_dev; |
| 138 | acpi_status status; |
| 139 | |
| 140 | if (acpi_video_caps_checked && graphics_handle == NULL) |
| 141 | return acpi_video_support; |
| 142 | |
| 143 | if (!graphics_handle) { |
| 144 | /* Only do the global walk through all graphics devices once */ |
| 145 | acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, |
Lin Ming | 2263576 | 2009-11-13 10:06:08 +0800 | [diff] [blame] | 146 | ACPI_UINT32_MAX, find_video, NULL, |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 147 | &caps, NULL); |
| 148 | /* There might be boot param flags set already... */ |
| 149 | acpi_video_support |= caps; |
| 150 | acpi_video_caps_checked = 1; |
| 151 | /* Add blacklists here. Be careful to use the right *DMI* bits |
| 152 | * to still be able to override logic via boot params, e.g.: |
| 153 | * |
| 154 | * if (dmi_name_in_vendors("XY")) { |
| 155 | * acpi_video_support |= |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 156 | * ACPI_VIDEO_BACKLIGHT_DMI_VENDOR; |
| 157 | *} |
| 158 | */ |
Corentin Chary | 084940d | 2012-06-13 09:32:04 +0200 | [diff] [blame] | 159 | |
| 160 | dmi_check_system(video_detect_dmi_table); |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 161 | } else { |
| 162 | status = acpi_bus_get_device(graphics_handle, &tmp_dev); |
| 163 | if (ACPI_FAILURE(status)) { |
| 164 | ACPI_EXCEPTION((AE_INFO, status, "Invalid device")); |
| 165 | return 0; |
| 166 | } |
| 167 | acpi_walk_namespace(ACPI_TYPE_DEVICE, graphics_handle, |
Lin Ming | 2263576 | 2009-11-13 10:06:08 +0800 | [diff] [blame] | 168 | ACPI_UINT32_MAX, find_video, NULL, |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 169 | &caps, NULL); |
| 170 | } |
| 171 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "We have 0x%lX video support %s %s\n", |
| 172 | graphics_handle ? caps : acpi_video_support, |
| 173 | graphics_handle ? "on device " : "in general", |
| 174 | graphics_handle ? acpi_device_bid(tmp_dev) : "")); |
| 175 | return caps; |
| 176 | } |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 177 | |
Corentin Chary | f838eb5 | 2012-06-13 09:32:01 +0200 | [diff] [blame] | 178 | static void acpi_video_caps_check(void) |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 179 | { |
| 180 | /* |
| 181 | * We must check whether the ACPI graphics device is physically plugged |
| 182 | * in. Therefore this must be called after binding PCI and ACPI devices |
| 183 | */ |
Hans de Goede | 14ca7a47 | 2015-06-16 16:27:47 +0200 | [diff] [blame^] | 184 | if (!acpi_video_caps_checked) { |
| 185 | acpi_video_parse_cmdline(); |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 186 | acpi_video_get_capabilities(NULL); |
Hans de Goede | 14ca7a47 | 2015-06-16 16:27:47 +0200 | [diff] [blame^] | 187 | } |
Corentin Chary | f838eb5 | 2012-06-13 09:32:01 +0200 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | /* Promote the vendor interface instead of the generic video module. |
| 191 | * This function allow DMI blacklists to be implemented by externals |
| 192 | * platform drivers instead of putting a big blacklist in video_detect.c |
| 193 | * After calling this function you will probably want to call |
| 194 | * acpi_video_unregister() to make sure the video module is not loaded |
| 195 | */ |
| 196 | void acpi_video_dmi_promote_vendor(void) |
| 197 | { |
| 198 | acpi_video_caps_check(); |
| 199 | acpi_video_support |= ACPI_VIDEO_BACKLIGHT_DMI_VENDOR; |
| 200 | } |
| 201 | EXPORT_SYMBOL(acpi_video_dmi_promote_vendor); |
| 202 | |
Corentin Chary | f838eb5 | 2012-06-13 09:32:01 +0200 | [diff] [blame] | 203 | /* Returns true if video.ko can do backlight switching */ |
| 204 | int acpi_video_backlight_support(void) |
| 205 | { |
| 206 | acpi_video_caps_check(); |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 207 | |
| 208 | /* First check for boot param -> highest prio */ |
| 209 | if (acpi_video_support & ACPI_VIDEO_BACKLIGHT_FORCE_VENDOR) |
| 210 | return 0; |
| 211 | else if (acpi_video_support & ACPI_VIDEO_BACKLIGHT_FORCE_VIDEO) |
| 212 | return 1; |
| 213 | |
| 214 | /* Then check for DMI blacklist -> second highest prio */ |
| 215 | if (acpi_video_support & ACPI_VIDEO_BACKLIGHT_DMI_VENDOR) |
| 216 | return 0; |
| 217 | else if (acpi_video_support & ACPI_VIDEO_BACKLIGHT_DMI_VIDEO) |
| 218 | return 1; |
| 219 | |
| 220 | /* Then go the default way */ |
| 221 | return acpi_video_support & ACPI_VIDEO_BACKLIGHT; |
| 222 | } |
| 223 | EXPORT_SYMBOL(acpi_video_backlight_support); |