diff options
author | Henrik Rydberg <rydberg@euromail.se> | 2009-09-21 20:04:50 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-09-22 10:17:49 -0400 |
commit | a976f150a6953da5ccbd40fa6dba3bd7d56f9f67 (patch) | |
tree | 36c0c1b9d424649421dde1f1d553bd17179a5264 | |
parent | 560a64a2b501add585b494b2b9cd9f68c0636b50 (diff) |
hwmon: applesmc: restore accelerometer and keyboard backlight on resume
On resume from suspend, the driver currently resets the logical state as
if it was brought up from halt. This patch uses the
dev_pm_ops.resume/restore methods to synchronize the hardware with the
memorized logical state, in effect bringing back the accelerometer and
backlight to the state prior to suspend. Works for both suspend to ram
and hibernation. The patch has zero effect on the running state.
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Cc: Nicolas Boichat <nicolas@boichat.ch>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | drivers/hwmon/applesmc.c | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c index 753b34885f9d..7ea6a8f66056 100644 --- a/drivers/hwmon/applesmc.c +++ b/drivers/hwmon/applesmc.c | |||
@@ -178,6 +178,8 @@ static const int debug; | |||
178 | static struct platform_device *pdev; | 178 | static struct platform_device *pdev; |
179 | static s16 rest_x; | 179 | static s16 rest_x; |
180 | static s16 rest_y; | 180 | static s16 rest_y; |
181 | static u8 backlight_state[2]; | ||
182 | |||
181 | static struct device *hwmon_dev; | 183 | static struct device *hwmon_dev; |
182 | static struct input_polled_dev *applesmc_idev; | 184 | static struct input_polled_dev *applesmc_idev; |
183 | 185 | ||
@@ -497,17 +499,36 @@ static int applesmc_probe(struct platform_device *dev) | |||
497 | return 0; | 499 | return 0; |
498 | } | 500 | } |
499 | 501 | ||
500 | static int applesmc_resume(struct platform_device *dev) | 502 | /* Synchronize device with memorized backlight state */ |
503 | static int applesmc_pm_resume(struct device *dev) | ||
501 | { | 504 | { |
502 | return applesmc_device_init(); | 505 | mutex_lock(&applesmc_lock); |
506 | if (applesmc_light) | ||
507 | applesmc_write_key(BACKLIGHT_KEY, backlight_state, 2); | ||
508 | mutex_unlock(&applesmc_lock); | ||
509 | return 0; | ||
503 | } | 510 | } |
504 | 511 | ||
512 | /* Reinitialize device on resume from hibernation */ | ||
513 | static int applesmc_pm_restore(struct device *dev) | ||
514 | { | ||
515 | int ret = applesmc_device_init(); | ||
516 | if (ret) | ||
517 | return ret; | ||
518 | return applesmc_pm_resume(dev); | ||
519 | } | ||
520 | |||
521 | static struct dev_pm_ops applesmc_pm_ops = { | ||
522 | .resume = applesmc_pm_resume, | ||
523 | .restore = applesmc_pm_restore, | ||
524 | }; | ||
525 | |||
505 | static struct platform_driver applesmc_driver = { | 526 | static struct platform_driver applesmc_driver = { |
506 | .probe = applesmc_probe, | 527 | .probe = applesmc_probe, |
507 | .resume = applesmc_resume, | ||
508 | .driver = { | 528 | .driver = { |
509 | .name = "applesmc", | 529 | .name = "applesmc", |
510 | .owner = THIS_MODULE, | 530 | .owner = THIS_MODULE, |
531 | .pm = &applesmc_pm_ops, | ||
511 | }, | 532 | }, |
512 | }; | 533 | }; |
513 | 534 | ||
@@ -804,17 +825,10 @@ static ssize_t applesmc_calibrate_store(struct device *dev, | |||
804 | return count; | 825 | return count; |
805 | } | 826 | } |
806 | 827 | ||
807 | /* Store the next backlight value to be written by the work */ | ||
808 | static unsigned int backlight_value; | ||
809 | |||
810 | static void applesmc_backlight_set(struct work_struct *work) | 828 | static void applesmc_backlight_set(struct work_struct *work) |
811 | { | 829 | { |
812 | u8 buffer[2]; | ||
813 | |||
814 | mutex_lock(&applesmc_lock); | 830 | mutex_lock(&applesmc_lock); |
815 | buffer[0] = backlight_value; | 831 | applesmc_write_key(BACKLIGHT_KEY, backlight_state, 2); |
816 | buffer[1] = 0x00; | ||
817 | applesmc_write_key(BACKLIGHT_KEY, buffer, 2); | ||
818 | mutex_unlock(&applesmc_lock); | 832 | mutex_unlock(&applesmc_lock); |
819 | } | 833 | } |
820 | static DECLARE_WORK(backlight_work, &applesmc_backlight_set); | 834 | static DECLARE_WORK(backlight_work, &applesmc_backlight_set); |
@@ -824,7 +838,7 @@ static void applesmc_brightness_set(struct led_classdev *led_cdev, | |||
824 | { | 838 | { |
825 | int ret; | 839 | int ret; |
826 | 840 | ||
827 | backlight_value = value; | 841 | backlight_state[0] = value; |
828 | ret = queue_work(applesmc_led_wq, &backlight_work); | 842 | ret = queue_work(applesmc_led_wq, &backlight_work); |
829 | 843 | ||
830 | if (debug && (!ret)) | 844 | if (debug && (!ret)) |