diff options
author | Samu Onkalo <samu.p.onkalo@nokia.com> | 2010-10-22 07:57:24 -0400 |
---|---|---|
committer | Guenter Roeck <guenter.roeck@ericsson.com> | 2010-10-25 17:11:38 -0400 |
commit | f9deb41f91c41d9d91a24c84a555ec7fe82620da (patch) | |
tree | c301a8324c3bbc779b752cdf47236575a87a26d2 /drivers/hwmon/lis3lv02d.c | |
parent | 2a346996626ecbb4269c239e9ff7372a182907e9 (diff) |
hwmon: lis3: regulator control
Based on pm_runtime control, turn lis3 regulators on and off.
Perform context save and restore on transitions.
Feature is optional and must be enabled in platform data.
Signed-off-by: Samu Onkalo <samu.p.onkalo@nokia.com>
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
Acked-by: Eric Piel <eric.piel@tremplin-utc.net>
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Diffstat (limited to 'drivers/hwmon/lis3lv02d.c')
-rw-r--r-- | drivers/hwmon/lis3lv02d.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c index 383a84938a9..159e402ddec 100644 --- a/drivers/hwmon/lis3lv02d.c +++ b/drivers/hwmon/lis3lv02d.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/delay.h> | 31 | #include <linux/delay.h> |
32 | #include <linux/wait.h> | 32 | #include <linux/wait.h> |
33 | #include <linux/poll.h> | 33 | #include <linux/poll.h> |
34 | #include <linux/slab.h> | ||
34 | #include <linux/freezer.h> | 35 | #include <linux/freezer.h> |
35 | #include <linux/uaccess.h> | 36 | #include <linux/uaccess.h> |
36 | #include <linux/miscdevice.h> | 37 | #include <linux/miscdevice.h> |
@@ -257,10 +258,46 @@ fail: | |||
257 | return ret; | 258 | return ret; |
258 | } | 259 | } |
259 | 260 | ||
261 | /* | ||
262 | * Order of registers in the list affects to order of the restore process. | ||
263 | * Perhaps it is a good idea to set interrupt enable register as a last one | ||
264 | * after all other configurations | ||
265 | */ | ||
266 | static u8 lis3_wai8_regs[] = { FF_WU_CFG_1, FF_WU_THS_1, FF_WU_DURATION_1, | ||
267 | FF_WU_CFG_2, FF_WU_THS_2, FF_WU_DURATION_2, | ||
268 | CLICK_CFG, CLICK_SRC, CLICK_THSY_X, CLICK_THSZ, | ||
269 | CLICK_TIMELIMIT, CLICK_LATENCY, CLICK_WINDOW, | ||
270 | CTRL_REG1, CTRL_REG2, CTRL_REG3}; | ||
271 | |||
272 | static u8 lis3_wai12_regs[] = {FF_WU_CFG, FF_WU_THS_L, FF_WU_THS_H, | ||
273 | FF_WU_DURATION, DD_CFG, DD_THSI_L, DD_THSI_H, | ||
274 | DD_THSE_L, DD_THSE_H, | ||
275 | CTRL_REG1, CTRL_REG3, CTRL_REG2}; | ||
276 | |||
277 | static inline void lis3_context_save(struct lis3lv02d *lis3) | ||
278 | { | ||
279 | int i; | ||
280 | for (i = 0; i < lis3->regs_size; i++) | ||
281 | lis3->read(lis3, lis3->regs[i], &lis3->reg_cache[i]); | ||
282 | lis3->regs_stored = true; | ||
283 | } | ||
284 | |||
285 | static inline void lis3_context_restore(struct lis3lv02d *lis3) | ||
286 | { | ||
287 | int i; | ||
288 | if (lis3->regs_stored) | ||
289 | for (i = 0; i < lis3->regs_size; i++) | ||
290 | lis3->write(lis3, lis3->regs[i], lis3->reg_cache[i]); | ||
291 | } | ||
292 | |||
260 | void lis3lv02d_poweroff(struct lis3lv02d *lis3) | 293 | void lis3lv02d_poweroff(struct lis3lv02d *lis3) |
261 | { | 294 | { |
295 | if (lis3->reg_ctrl) | ||
296 | lis3_context_save(lis3); | ||
262 | /* disable X,Y,Z axis and power down */ | 297 | /* disable X,Y,Z axis and power down */ |
263 | lis3->write(lis3, CTRL_REG1, 0x00); | 298 | lis3->write(lis3, CTRL_REG1, 0x00); |
299 | if (lis3->reg_ctrl) | ||
300 | lis3->reg_ctrl(lis3, LIS3_REG_OFF); | ||
264 | } | 301 | } |
265 | EXPORT_SYMBOL_GPL(lis3lv02d_poweroff); | 302 | EXPORT_SYMBOL_GPL(lis3lv02d_poweroff); |
266 | 303 | ||
@@ -283,6 +320,8 @@ void lis3lv02d_poweron(struct lis3lv02d *lis3) | |||
283 | reg |= CTRL2_BDU; | 320 | reg |= CTRL2_BDU; |
284 | lis3->write(lis3, CTRL_REG2, reg); | 321 | lis3->write(lis3, CTRL_REG2, reg); |
285 | } | 322 | } |
323 | if (lis3->reg_ctrl) | ||
324 | lis3_context_restore(lis3); | ||
286 | } | 325 | } |
287 | EXPORT_SYMBOL_GPL(lis3lv02d_poweron); | 326 | EXPORT_SYMBOL_GPL(lis3lv02d_poweron); |
288 | 327 | ||
@@ -674,6 +713,7 @@ int lis3lv02d_remove_fs(struct lis3lv02d *lis3) | |||
674 | pm_runtime_disable(lis3->pm_dev); | 713 | pm_runtime_disable(lis3->pm_dev); |
675 | pm_runtime_set_suspended(lis3->pm_dev); | 714 | pm_runtime_set_suspended(lis3->pm_dev); |
676 | } | 715 | } |
716 | kfree(lis3->reg_cache); | ||
677 | return 0; | 717 | return 0; |
678 | } | 718 | } |
679 | EXPORT_SYMBOL_GPL(lis3lv02d_remove_fs); | 719 | EXPORT_SYMBOL_GPL(lis3lv02d_remove_fs); |
@@ -753,6 +793,8 @@ int lis3lv02d_init_device(struct lis3lv02d *dev) | |||
753 | dev->odrs = lis3_12_rates; | 793 | dev->odrs = lis3_12_rates; |
754 | dev->odr_mask = CTRL1_DF0 | CTRL1_DF1; | 794 | dev->odr_mask = CTRL1_DF0 | CTRL1_DF1; |
755 | dev->scale = LIS3_SENSITIVITY_12B; | 795 | dev->scale = LIS3_SENSITIVITY_12B; |
796 | dev->regs = lis3_wai12_regs; | ||
797 | dev->regs_size = ARRAY_SIZE(lis3_wai12_regs); | ||
756 | break; | 798 | break; |
757 | case WAI_8B: | 799 | case WAI_8B: |
758 | printk(KERN_INFO DRIVER_NAME ": 8 bits sensor found\n"); | 800 | printk(KERN_INFO DRIVER_NAME ": 8 bits sensor found\n"); |
@@ -762,6 +804,8 @@ int lis3lv02d_init_device(struct lis3lv02d *dev) | |||
762 | dev->odrs = lis3_8_rates; | 804 | dev->odrs = lis3_8_rates; |
763 | dev->odr_mask = CTRL1_DR; | 805 | dev->odr_mask = CTRL1_DR; |
764 | dev->scale = LIS3_SENSITIVITY_8B; | 806 | dev->scale = LIS3_SENSITIVITY_8B; |
807 | dev->regs = lis3_wai8_regs; | ||
808 | dev->regs_size = ARRAY_SIZE(lis3_wai8_regs); | ||
765 | break; | 809 | break; |
766 | case WAI_3DC: | 810 | case WAI_3DC: |
767 | printk(KERN_INFO DRIVER_NAME ": 8 bits 3DC sensor found\n"); | 811 | printk(KERN_INFO DRIVER_NAME ": 8 bits 3DC sensor found\n"); |
@@ -778,6 +822,14 @@ int lis3lv02d_init_device(struct lis3lv02d *dev) | |||
778 | return -EINVAL; | 822 | return -EINVAL; |
779 | } | 823 | } |
780 | 824 | ||
825 | dev->reg_cache = kzalloc(max(sizeof(lis3_wai8_regs), | ||
826 | sizeof(lis3_wai12_regs)), GFP_KERNEL); | ||
827 | |||
828 | if (dev->reg_cache == NULL) { | ||
829 | printk(KERN_ERR DRIVER_NAME "out of memory\n"); | ||
830 | return -ENOMEM; | ||
831 | } | ||
832 | |||
781 | mutex_init(&dev->mutex); | 833 | mutex_init(&dev->mutex); |
782 | 834 | ||
783 | lis3lv02d_add_fs(dev); | 835 | lis3lv02d_add_fs(dev); |