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#include <linux/acpi.h>
37#include <linux/dmi.h>
38#include <linux/pci.h>
39
40#define PREFIX "ACPI: "
41
42ACPI_MODULE_NAME("video");
43#define _COMPONENT ACPI_VIDEO_COMPONENT
44
45static long acpi_video_support;
46static bool acpi_video_caps_checked;
47
48static acpi_status
49acpi_backlight_cap_match(acpi_handle handle, u32 level, void *context,
50 void **retyurn_value)
51{
52 long *cap = context;
53 acpi_handle h_dummy;
54
55 if (ACPI_SUCCESS(acpi_get_handle(handle, "_BCM", &h_dummy)) &&
56 ACPI_SUCCESS(acpi_get_handle(handle, "_BCL", &h_dummy))) {
57 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found generic backlight "
58 "support\n"));
59 *cap |= ACPI_VIDEO_BACKLIGHT;
60 if (ACPI_FAILURE(acpi_get_handle(handle, "_BQC", &h_dummy)))
61 printk(KERN_WARNING FW_BUG PREFIX "No _BQC method, "
62 "cannot determine initial brightness\n");
63
64 return AE_CTRL_TERMINATE;
65 }
66 return 0;
67}
68
69
70
71
72
73
74
75
76
77long acpi_is_video_device(struct acpi_device *device)
78{
79 acpi_handle h_dummy;
80 long video_caps = 0;
81
82 if (!device)
83 return 0;
84
85
86 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOD", &h_dummy)) ||
87 ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy)))
88 video_caps |= ACPI_VIDEO_OUTPUT_SWITCHING;
89
90
91 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy)))
92 video_caps |= ACPI_VIDEO_ROM_AVAILABLE;
93
94
95 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy)) &&
96 ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy)) &&
97 ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy)))
98 video_caps |= ACPI_VIDEO_DEVICE_POSTING;
99
100
101 if (video_caps)
102 acpi_walk_namespace(ACPI_TYPE_DEVICE, device->handle,
103 ACPI_UINT32_MAX, acpi_backlight_cap_match, NULL,
104 &video_caps, NULL);
105
106 return video_caps;
107}
108EXPORT_SYMBOL(acpi_is_video_device);
109
110static acpi_status
111find_video(acpi_handle handle, u32 lvl, void *context, void **rv)
112{
113 long *cap = context;
114 struct pci_dev *dev;
115 struct acpi_device *acpi_dev;
116
117 const struct acpi_device_id video_ids[] = {
118 {ACPI_VIDEO_HID, 0},
119 {"", 0},
120 };
121 if (acpi_bus_get_device(handle, &acpi_dev))
122 return AE_OK;
123
124 if (!acpi_match_device_ids(acpi_dev, video_ids)) {
125 dev = acpi_get_pci_dev(handle);
126 if (!dev)
127 return AE_OK;
128 pci_dev_put(dev);
129 *cap |= acpi_is_video_device(acpi_dev);
130 }
131 return AE_OK;
132}
133
134
135
136
137
138
139
140
141long acpi_video_get_capabilities(acpi_handle graphics_handle)
142{
143 long caps = 0;
144 struct acpi_device *tmp_dev;
145 acpi_status status;
146
147 if (acpi_video_caps_checked && graphics_handle == NULL)
148 return acpi_video_support;
149
150 if (!graphics_handle) {
151
152 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
153 ACPI_UINT32_MAX, find_video, NULL,
154 &caps, NULL);
155
156 acpi_video_support |= caps;
157 acpi_video_caps_checked = 1;
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, NULL,
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
215static int __init acpi_backlight(char *str)
216{
217 if (str == NULL || *str == '\0')
218 return 1;
219 else {
220 if (!strcmp("vendor", str))
221 acpi_video_support |=
222 ACPI_VIDEO_BACKLIGHT_FORCE_VENDOR;
223 if (!strcmp("video", str))
224 acpi_video_support |=
225 ACPI_VIDEO_BACKLIGHT_FORCE_VIDEO;
226 }
227 return 1;
228}
229__setup("acpi_backlight=", acpi_backlight);
230