diff options
author | Ming Lei <ming.lei@canonical.com> | 2012-08-04 00:01:29 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-08-16 16:44:44 -0400 |
commit | 07646d9c0938d40b943c592dd1c6435ab24c4e2f (patch) | |
tree | 1b86d489f25f22d60dc29467c4b8aae727dbc72d | |
parent | ffe53f6f388a3aaa208e7c45065ce096d5d2f4e9 (diff) |
firmware loader: cache devices firmware during suspend/resume cycle
This patch implements caching devices' firmware automatically
during system syspend/resume cycle, so any device drivers can
call request_firmware or request_firmware_nowait inside resume
path to get the cached firmware if they have loaded firmwares
successfully at least once before entering suspend.
Signed-off-by: Ming Lei <ming.lei@canonical.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/base/firmware_class.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index 8ca00524d58f..5bd2100a4dcf 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/list.h> | 24 | #include <linux/list.h> |
25 | #include <linux/async.h> | 25 | #include <linux/async.h> |
26 | #include <linux/pm.h> | 26 | #include <linux/pm.h> |
27 | #include <linux/suspend.h> | ||
27 | 28 | ||
28 | #include "base.h" | 29 | #include "base.h" |
29 | #include "power/power.h" | 30 | #include "power/power.h" |
@@ -108,6 +109,8 @@ struct firmware_cache { | |||
108 | wait_queue_head_t wait_queue; | 109 | wait_queue_head_t wait_queue; |
109 | int cnt; | 110 | int cnt; |
110 | struct delayed_work work; | 111 | struct delayed_work work; |
112 | |||
113 | struct notifier_block pm_notify; | ||
111 | }; | 114 | }; |
112 | 115 | ||
113 | struct firmware_buf { | 116 | struct firmware_buf { |
@@ -1217,6 +1220,31 @@ static void device_uncache_fw_images_delay(unsigned long delay) | |||
1217 | msecs_to_jiffies(delay)); | 1220 | msecs_to_jiffies(delay)); |
1218 | } | 1221 | } |
1219 | 1222 | ||
1223 | #ifdef CONFIG_PM | ||
1224 | static int fw_pm_notify(struct notifier_block *notify_block, | ||
1225 | unsigned long mode, void *unused) | ||
1226 | { | ||
1227 | switch (mode) { | ||
1228 | case PM_HIBERNATION_PREPARE: | ||
1229 | case PM_SUSPEND_PREPARE: | ||
1230 | device_cache_fw_images(); | ||
1231 | break; | ||
1232 | |||
1233 | case PM_POST_SUSPEND: | ||
1234 | case PM_POST_HIBERNATION: | ||
1235 | case PM_POST_RESTORE: | ||
1236 | device_uncache_fw_images_delay(10 * MSEC_PER_SEC); | ||
1237 | break; | ||
1238 | } | ||
1239 | |||
1240 | return 0; | ||
1241 | } | ||
1242 | #else | ||
1243 | static int fw_pm_notify(struct notifier_block *notify_block, | ||
1244 | unsigned long mode, void *unused) | ||
1245 | {} | ||
1246 | #endif | ||
1247 | |||
1220 | static void __init fw_cache_init(void) | 1248 | static void __init fw_cache_init(void) |
1221 | { | 1249 | { |
1222 | spin_lock_init(&fw_cache.lock); | 1250 | spin_lock_init(&fw_cache.lock); |
@@ -1229,6 +1257,9 @@ static void __init fw_cache_init(void) | |||
1229 | init_waitqueue_head(&fw_cache.wait_queue); | 1257 | init_waitqueue_head(&fw_cache.wait_queue); |
1230 | INIT_DELAYED_WORK(&fw_cache.work, | 1258 | INIT_DELAYED_WORK(&fw_cache.work, |
1231 | device_uncache_fw_images_work); | 1259 | device_uncache_fw_images_work); |
1260 | |||
1261 | fw_cache.pm_notify.notifier_call = fw_pm_notify; | ||
1262 | register_pm_notifier(&fw_cache.pm_notify); | ||
1232 | } | 1263 | } |
1233 | 1264 | ||
1234 | static int __init firmware_class_init(void) | 1265 | static int __init firmware_class_init(void) |
@@ -1239,6 +1270,7 @@ static int __init firmware_class_init(void) | |||
1239 | 1270 | ||
1240 | static void __exit firmware_class_exit(void) | 1271 | static void __exit firmware_class_exit(void) |
1241 | { | 1272 | { |
1273 | unregister_pm_notifier(&fw_cache.pm_notify); | ||
1242 | class_unregister(&firmware_class); | 1274 | class_unregister(&firmware_class); |
1243 | } | 1275 | } |
1244 | 1276 | ||