1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37#include <linux/acpi.h>
38#include <linux/dmi.h>
39
40ACPI_MODULE_NAME("video");
41#define _COMPONENT ACPI_VIDEO_COMPONENT
42
43static long acpi_video_support;
44static bool acpi_video_caps_checked;
45
46static acpi_status
47acpi_backlight_cap_match(acpi_handle handle, u32 level, void *context,
48 void **retyurn_value)
49{
50 long *cap = context;
51 acpi_handle h_dummy;
52
53 if (ACPI_SUCCESS(acpi_get_handle(handle, "_BCM", &h_dummy)) &&
54 ACPI_SUCCESS(acpi_get_handle(handle, "_BCL", &h_dummy))) {
55 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found generic backlight "
56 "support\n"));
57 *cap |= ACPI_VIDEO_BACKLIGHT;
58 if (ACPI_FAILURE(acpi_get_handle(handle, "_BQC", &h_dummy)))
59 printk(KERN_WARNING FW_BUG PREFIX "ACPI brightness "
60 "control misses _BQC function\n");
61
62 return AE_CTRL_TERMINATE;
63 }
64 return 0;
65}
66
67
68
69
70
71
72
73
74
75long acpi_is_video_device(struct acpi_device *device)
76{
77 acpi_handle h_dummy;
78 long video_caps = 0;
79
80 if (!device)
81 return 0;
82
83
84 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOD", &h_dummy)) &&
85 ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy)))
86 video_caps |= ACPI_VIDEO_OUTPUT_SWITCHING;
87
88
89 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy)))
90 video_caps |= ACPI_VIDEO_ROM_AVAILABLE;
91
92
93 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy)) &&
94 ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy)) &&
95 ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy)))
96 video_caps |= ACPI_VIDEO_DEVICE_POSTING;
97
98
99 if (video_caps)
100 acpi_walk_namespace(ACPI_TYPE_DEVICE, device->handle,
101 ACPI_UINT32_MAX, acpi_backlight_cap_match,
102 &video_caps, NULL);
103
104 return video_caps;
105}
106EXPORT_SYMBOL(acpi_is_video_device);
107
108static acpi_status
109find_video(acpi_handle handle, u32 lvl, void *context, void **rv)
110{
111 long *cap = context;
112 struct device *dev;
113 struct acpi_device *acpi_dev;
114
115 const struct acpi_device_id video_ids[] = {
116 {ACPI_VIDEO_HID, 0},
117 {"", 0},
118 };
119 if (acpi_bus_get_device(handle, &acpi_dev))
120 return AE_OK;
121
122 if (!acpi_match_device_ids(acpi_dev, video_ids)) {
123 dev = acpi_get_physical_pci_device(handle);
124 if (!dev)
125 return AE_OK;
126 put_device(dev);
127 *cap |= acpi_is_video_device(acpi_dev);
128 }
129 return AE_OK;
130}
131
132
133
134
135
136
137
138
139long acpi_video_get_capabilities(acpi_handle graphics_handle)
140{
141 long caps = 0;
142 struct acpi_device *tmp_dev;
143 acpi_status status;
144
145 if (acpi_video_caps_checked && graphics_handle == NULL)
146 return acpi_video_support;
147
148 if (!graphics_handle) {
149
150 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
151 ACPI_UINT32_MAX, find_video,
152 &caps, NULL);
153
154 acpi_video_support |= caps;
155 acpi_video_caps_checked = 1;
156
157
158
159
160
161
162
163
164
165
166 } else {
167 status = acpi_bus_get_device(graphics_handle, &tmp_dev);
168 if (ACPI_FAILURE(status)) {
169 ACPI_EXCEPTION((AE_INFO, status, "Invalid device"));
170 return 0;
171 }
172 acpi_walk_namespace(ACPI_TYPE_DEVICE, graphics_handle,
173 ACPI_UINT32_MAX, find_video,
174 &caps, NULL);
175 }
176 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "We have 0x%lX video support %s %s\n",
177 graphics_handle ? caps : acpi_video_support,
178 graphics_handle ? "on device " : "in general",
179 graphics_handle ? acpi_device_bid(tmp_dev) : ""));
180 return caps;
181}
182EXPORT_SYMBOL(acpi_video_get_capabilities);
183
184
185int acpi_video_backlight_support(void)
186{
187
188
189
190
191 if (!acpi_video_caps_checked)
192 acpi_video_get_capabilities(NULL);
193
194
195 if (acpi_video_support & ACPI_VIDEO_BACKLIGHT_FORCE_VENDOR)
196 return 0;
197 else if (acpi_video_support & ACPI_VIDEO_BACKLIGHT_FORCE_VIDEO)
198 return 1;
199
200
201 if (acpi_video_support & ACPI_VIDEO_BACKLIGHT_DMI_VENDOR)
202 return 0;
203 else if (acpi_video_support & ACPI_VIDEO_BACKLIGHT_DMI_VIDEO)
204 return 1;
205
206
207 return acpi_video_support & ACPI_VIDEO_BACKLIGHT;
208}
209EXPORT_SYMBOL(acpi_video_backlight_support);
210
211
212
213
214
215
216int acpi_video_display_switch_support(void)
217{
218 if (!acpi_video_caps_checked)
219 acpi_video_get_capabilities(NULL);
220
221 if (acpi_video_support & ACPI_VIDEO_OUTPUT_SWITCHING_FORCE_VENDOR)
222 return 0;
223 else if (acpi_video_support & ACPI_VIDEO_OUTPUT_SWITCHING_FORCE_VIDEO)
224 return 1;
225
226 if (acpi_video_support & ACPI_VIDEO_OUTPUT_SWITCHING_DMI_VENDOR)
227 return 0;
228 else if (acpi_video_support & ACPI_VIDEO_OUTPUT_SWITCHING_DMI_VIDEO)
229 return 1;
230
231 return acpi_video_support & ACPI_VIDEO_OUTPUT_SWITCHING;
232}
233EXPORT_SYMBOL(acpi_video_display_switch_support);
234
235
236
237
238
239
240static int __init acpi_backlight(char *str)
241{
242 if (str == NULL || *str == '\0')
243 return 1;
244 else {
245 if (!strcmp("vendor", str))
246 acpi_video_support |=
247 ACPI_VIDEO_BACKLIGHT_FORCE_VENDOR;
248 if (!strcmp("video", str))
249 acpi_video_support |=
250 ACPI_VIDEO_OUTPUT_SWITCHING_FORCE_VIDEO;
251 }
252 return 1;
253}
254__setup("acpi_backlight=", acpi_backlight);
255
256static int __init acpi_display_output(char *str)
257{
258 if (str == NULL || *str == '\0')
259 return 1;
260 else {
261 if (!strcmp("vendor", str))
262 acpi_video_support |=
263 ACPI_VIDEO_OUTPUT_SWITCHING_FORCE_VENDOR;
264 if (!strcmp("video", str))
265 acpi_video_support |=
266 ACPI_VIDEO_OUTPUT_SWITCHING_FORCE_VIDEO;
267 }
268 return 1;
269}
270__setup("acpi_display_output=", acpi_display_output);
271