diff options
Diffstat (limited to 'drivers/acpi/video.c')
-rw-r--r-- | drivers/acpi/video.c | 67 |
1 files changed, 46 insertions, 21 deletions
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c index 6a0143796772..a0c93b321482 100644 --- a/drivers/acpi/video.c +++ b/drivers/acpi/video.c | |||
@@ -44,6 +44,7 @@ | |||
44 | #include <linux/dmi.h> | 44 | #include <linux/dmi.h> |
45 | #include <acpi/acpi_bus.h> | 45 | #include <acpi/acpi_bus.h> |
46 | #include <acpi/acpi_drivers.h> | 46 | #include <acpi/acpi_drivers.h> |
47 | #include <linux/suspend.h> | ||
47 | 48 | ||
48 | #define PREFIX "ACPI: " | 49 | #define PREFIX "ACPI: " |
49 | 50 | ||
@@ -89,7 +90,6 @@ module_param(allow_duplicates, bool, 0644); | |||
89 | static int register_count = 0; | 90 | static int register_count = 0; |
90 | static int acpi_video_bus_add(struct acpi_device *device); | 91 | static int acpi_video_bus_add(struct acpi_device *device); |
91 | static int acpi_video_bus_remove(struct acpi_device *device, int type); | 92 | static int acpi_video_bus_remove(struct acpi_device *device, int type); |
92 | static int acpi_video_resume(struct acpi_device *device); | ||
93 | static void acpi_video_bus_notify(struct acpi_device *device, u32 event); | 93 | static void acpi_video_bus_notify(struct acpi_device *device, u32 event); |
94 | 94 | ||
95 | static const struct acpi_device_id video_device_ids[] = { | 95 | static const struct acpi_device_id video_device_ids[] = { |
@@ -105,7 +105,6 @@ static struct acpi_driver acpi_video_bus = { | |||
105 | .ops = { | 105 | .ops = { |
106 | .add = acpi_video_bus_add, | 106 | .add = acpi_video_bus_add, |
107 | .remove = acpi_video_bus_remove, | 107 | .remove = acpi_video_bus_remove, |
108 | .resume = acpi_video_resume, | ||
109 | .notify = acpi_video_bus_notify, | 108 | .notify = acpi_video_bus_notify, |
110 | }, | 109 | }, |
111 | }; | 110 | }; |
@@ -160,6 +159,7 @@ struct acpi_video_bus { | |||
160 | struct proc_dir_entry *dir; | 159 | struct proc_dir_entry *dir; |
161 | struct input_dev *input; | 160 | struct input_dev *input; |
162 | char phys[32]; /* for input device */ | 161 | char phys[32]; /* for input device */ |
162 | struct notifier_block pm_nb; | ||
163 | }; | 163 | }; |
164 | 164 | ||
165 | struct acpi_video_device_flags { | 165 | struct acpi_video_device_flags { |
@@ -1021,6 +1021,13 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device) | |||
1021 | if (IS_ERR(device->backlight)) | 1021 | if (IS_ERR(device->backlight)) |
1022 | return; | 1022 | return; |
1023 | 1023 | ||
1024 | /* | ||
1025 | * Save current brightness level in case we have to restore it | ||
1026 | * before acpi_video_device_lcd_set_level() is called next time. | ||
1027 | */ | ||
1028 | device->backlight->props.brightness = | ||
1029 | acpi_video_get_brightness(device->backlight); | ||
1030 | |||
1024 | result = sysfs_create_link(&device->backlight->dev.kobj, | 1031 | result = sysfs_create_link(&device->backlight->dev.kobj, |
1025 | &device->dev->dev.kobj, "device"); | 1032 | &device->dev->dev.kobj, "device"); |
1026 | if (result) | 1033 | if (result) |
@@ -2123,7 +2130,7 @@ static void acpi_video_bus_notify(struct acpi_device *device, u32 event) | |||
2123 | { | 2130 | { |
2124 | struct acpi_video_bus *video = acpi_driver_data(device); | 2131 | struct acpi_video_bus *video = acpi_driver_data(device); |
2125 | struct input_dev *input; | 2132 | struct input_dev *input; |
2126 | int keycode; | 2133 | int keycode = 0; |
2127 | 2134 | ||
2128 | if (!video) | 2135 | if (!video) |
2129 | return; | 2136 | return; |
@@ -2159,17 +2166,19 @@ static void acpi_video_bus_notify(struct acpi_device *device, u32 event) | |||
2159 | break; | 2166 | break; |
2160 | 2167 | ||
2161 | default: | 2168 | default: |
2162 | keycode = KEY_UNKNOWN; | ||
2163 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 2169 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
2164 | "Unsupported event [0x%x]\n", event)); | 2170 | "Unsupported event [0x%x]\n", event)); |
2165 | break; | 2171 | break; |
2166 | } | 2172 | } |
2167 | 2173 | ||
2168 | acpi_notifier_call_chain(device, event, 0); | 2174 | acpi_notifier_call_chain(device, event, 0); |
2169 | input_report_key(input, keycode, 1); | 2175 | |
2170 | input_sync(input); | 2176 | if (keycode) { |
2171 | input_report_key(input, keycode, 0); | 2177 | input_report_key(input, keycode, 1); |
2172 | input_sync(input); | 2178 | input_sync(input); |
2179 | input_report_key(input, keycode, 0); | ||
2180 | input_sync(input); | ||
2181 | } | ||
2173 | 2182 | ||
2174 | return; | 2183 | return; |
2175 | } | 2184 | } |
@@ -2180,7 +2189,7 @@ static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data) | |||
2180 | struct acpi_device *device = NULL; | 2189 | struct acpi_device *device = NULL; |
2181 | struct acpi_video_bus *bus; | 2190 | struct acpi_video_bus *bus; |
2182 | struct input_dev *input; | 2191 | struct input_dev *input; |
2183 | int keycode; | 2192 | int keycode = 0; |
2184 | 2193 | ||
2185 | if (!video_device) | 2194 | if (!video_device) |
2186 | return; | 2195 | return; |
@@ -2221,39 +2230,48 @@ static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data) | |||
2221 | keycode = KEY_DISPLAY_OFF; | 2230 | keycode = KEY_DISPLAY_OFF; |
2222 | break; | 2231 | break; |
2223 | default: | 2232 | default: |
2224 | keycode = KEY_UNKNOWN; | ||
2225 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 2233 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
2226 | "Unsupported event [0x%x]\n", event)); | 2234 | "Unsupported event [0x%x]\n", event)); |
2227 | break; | 2235 | break; |
2228 | } | 2236 | } |
2229 | 2237 | ||
2230 | acpi_notifier_call_chain(device, event, 0); | 2238 | acpi_notifier_call_chain(device, event, 0); |
2231 | input_report_key(input, keycode, 1); | 2239 | |
2232 | input_sync(input); | 2240 | if (keycode) { |
2233 | input_report_key(input, keycode, 0); | 2241 | input_report_key(input, keycode, 1); |
2234 | input_sync(input); | 2242 | input_sync(input); |
2243 | input_report_key(input, keycode, 0); | ||
2244 | input_sync(input); | ||
2245 | } | ||
2235 | 2246 | ||
2236 | return; | 2247 | return; |
2237 | } | 2248 | } |
2238 | 2249 | ||
2239 | static int instance; | 2250 | static int acpi_video_resume(struct notifier_block *nb, |
2240 | static int acpi_video_resume(struct acpi_device *device) | 2251 | unsigned long val, void *ign) |
2241 | { | 2252 | { |
2242 | struct acpi_video_bus *video; | 2253 | struct acpi_video_bus *video; |
2243 | struct acpi_video_device *video_device; | 2254 | struct acpi_video_device *video_device; |
2244 | int i; | 2255 | int i; |
2245 | 2256 | ||
2246 | if (!device || !acpi_driver_data(device)) | 2257 | switch (val) { |
2247 | return -EINVAL; | 2258 | case PM_HIBERNATION_PREPARE: |
2259 | case PM_SUSPEND_PREPARE: | ||
2260 | case PM_RESTORE_PREPARE: | ||
2261 | return NOTIFY_DONE; | ||
2262 | } | ||
2248 | 2263 | ||
2249 | video = acpi_driver_data(device); | 2264 | video = container_of(nb, struct acpi_video_bus, pm_nb); |
2265 | |||
2266 | dev_info(&video->device->dev, "Restoring backlight state\n"); | ||
2250 | 2267 | ||
2251 | for (i = 0; i < video->attached_count; i++) { | 2268 | for (i = 0; i < video->attached_count; i++) { |
2252 | video_device = video->attached_array[i].bind_info; | 2269 | video_device = video->attached_array[i].bind_info; |
2253 | if (video_device && video_device->backlight) | 2270 | if (video_device && video_device->backlight) |
2254 | acpi_video_set_brightness(video_device->backlight); | 2271 | acpi_video_set_brightness(video_device->backlight); |
2255 | } | 2272 | } |
2256 | return AE_OK; | 2273 | |
2274 | return NOTIFY_OK; | ||
2257 | } | 2275 | } |
2258 | 2276 | ||
2259 | static acpi_status | 2277 | static acpi_status |
@@ -2277,6 +2295,8 @@ acpi_video_bus_match(acpi_handle handle, u32 level, void *context, | |||
2277 | return AE_OK; | 2295 | return AE_OK; |
2278 | } | 2296 | } |
2279 | 2297 | ||
2298 | static int instance; | ||
2299 | |||
2280 | static int acpi_video_bus_add(struct acpi_device *device) | 2300 | static int acpi_video_bus_add(struct acpi_device *device) |
2281 | { | 2301 | { |
2282 | struct acpi_video_bus *video; | 2302 | struct acpi_video_bus *video; |
@@ -2358,7 +2378,6 @@ static int acpi_video_bus_add(struct acpi_device *device) | |||
2358 | set_bit(KEY_BRIGHTNESSDOWN, input->keybit); | 2378 | set_bit(KEY_BRIGHTNESSDOWN, input->keybit); |
2359 | set_bit(KEY_BRIGHTNESS_ZERO, input->keybit); | 2379 | set_bit(KEY_BRIGHTNESS_ZERO, input->keybit); |
2360 | set_bit(KEY_DISPLAY_OFF, input->keybit); | 2380 | set_bit(KEY_DISPLAY_OFF, input->keybit); |
2361 | set_bit(KEY_UNKNOWN, input->keybit); | ||
2362 | 2381 | ||
2363 | error = input_register_device(input); | 2382 | error = input_register_device(input); |
2364 | if (error) | 2383 | if (error) |
@@ -2370,6 +2389,10 @@ static int acpi_video_bus_add(struct acpi_device *device) | |||
2370 | video->flags.rom ? "yes" : "no", | 2389 | video->flags.rom ? "yes" : "no", |
2371 | video->flags.post ? "yes" : "no"); | 2390 | video->flags.post ? "yes" : "no"); |
2372 | 2391 | ||
2392 | video->pm_nb.notifier_call = acpi_video_resume; | ||
2393 | video->pm_nb.priority = 0; | ||
2394 | register_pm_notifier(&video->pm_nb); | ||
2395 | |||
2373 | return 0; | 2396 | return 0; |
2374 | 2397 | ||
2375 | err_free_input_dev: | 2398 | err_free_input_dev: |
@@ -2396,6 +2419,8 @@ static int acpi_video_bus_remove(struct acpi_device *device, int type) | |||
2396 | 2419 | ||
2397 | video = acpi_driver_data(device); | 2420 | video = acpi_driver_data(device); |
2398 | 2421 | ||
2422 | unregister_pm_notifier(&video->pm_nb); | ||
2423 | |||
2399 | acpi_video_bus_stop_devices(video); | 2424 | acpi_video_bus_stop_devices(video); |
2400 | acpi_video_bus_put_devices(video); | 2425 | acpi_video_bus_put_devices(video); |
2401 | acpi_video_bus_remove_fs(device); | 2426 | acpi_video_bus_remove_fs(device); |