1/* 2 * drivers/base/power/runtime.c - Handling dynamic device power management. 3 * 4 * Copyright (c) 2003 Patrick Mochel 5 * Copyright (c) 2003 Open Source Development Lab 6 * 7 */ 8 9#include <linux/device.h> 10#include "power.h" 11 12 13static void runtime_resume(struct device * dev) 14{ 15 dev_dbg(dev, "resuming\n"); 16 if (!dev->power.power_state.event) 17 return; 18 if (!resume_device(dev)) 19 dev->power.power_state = PMSG_ON; 20} 21 22 23 24void dpm_runtime_resume(struct device * dev) 25{ 26 down(&dpm_sem); 27 runtime_resume(dev); 28 up(&dpm_sem); 29} 30EXPORT_SYMBOL(dpm_runtime_resume); 31 32 33/** 34 * dpm_runtime_suspend - Put one device in low-power state. 35 * @dev: Device. 36 * @state: State to enter. 37 */ 38 39int dpm_runtime_suspend(struct device * dev, pm_message_t state) 40{ 41 int error = 0; 42 43 down(&dpm_sem); 44 if (dev->power.power_state.event == state.event) 45 goto Done; 46 47 if (dev->power.power_state.event) 48 runtime_resume(dev); 49 50 if (!(error = suspend_device(dev, state))) 51 dev->power.power_state = state; 52 Done: 53 up(&dpm_sem); 54 return error; 55} 56EXPORT_SYMBOL(dpm_runtime_suspend); 57