aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2009-09-21 20:04:50 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-09-22 10:17:49 -0400
commita976f150a6953da5ccbd40fa6dba3bd7d56f9f67 (patch)
tree36c0c1b9d424649421dde1f1d553bd17179a5264 /drivers/hwmon
parent560a64a2b501add585b494b2b9cd9f68c0636b50 (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>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/applesmc.c38
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;
178static struct platform_device *pdev; 178static struct platform_device *pdev;
179static s16 rest_x; 179static s16 rest_x;
180static s16 rest_y; 180static s16 rest_y;
181static u8 backlight_state[2];
182
181static struct device *hwmon_dev; 183static struct device *hwmon_dev;
182static struct input_polled_dev *applesmc_idev; 184static 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
500static int applesmc_resume(struct platform_device *dev) 502/* Synchronize device with memorized backlight state */
503static 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 */
513static 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
521static struct dev_pm_ops applesmc_pm_ops = {
522 .resume = applesmc_pm_resume,
523 .restore = applesmc_pm_restore,
524};
525
505static struct platform_driver applesmc_driver = { 526static 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 */
808static unsigned int backlight_value;
809
810static void applesmc_backlight_set(struct work_struct *work) 828static 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}
820static DECLARE_WORK(backlight_work, &applesmc_backlight_set); 834static 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))