Skip to content

Commit

Permalink
device: Extend device_set_power_state API to support async requests
Browse files Browse the repository at this point in the history
The existing device_set_power_state() API works only in synchronous
mode and this is not desirable for devices(ex: Gyro) which take
longer time (few 100 mSec) to suspend/resume.

To support async mode, a new callback argument is added to the API.
The device drivers can asynchronously suspend/resume and call the
callback function upon completion of the async request.

This commit adds the missing callback parameter to all the drivers
to make it compliant with the new API.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
  • Loading branch information
Ramakrishna Pallala committed Mar 1, 2019
1 parent 9c2c115 commit c3b0da8
Show file tree
Hide file tree
Showing 29 changed files with 246 additions and 120 deletions.
2 changes: 1 addition & 1 deletion doc/reference/power_management/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ Device Set Power State

.. code-block:: c
int device_set_power_state(struct device *device, u32_t device_power_state);
int device_set_power_state(struct device *device, u32_t device_power_state, device_pm_cb cb, void *arg);
Calls the :c:func:`device_pm_control()` handler function implemented by the
device driver with DEVICE_PM_SET_POWER_STATE command.
Expand Down
15 changes: 10 additions & 5 deletions drivers/counter/counter_qmsi_aonpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,25 @@ static int aonpt_resume_device_from_suspend(struct device *dev)
* the *context may include IN data or/and OUT data
*/
static int aonpt_qmsi_device_ctrl(struct device *dev, u32_t ctrl_command,
void *context)
void *context, device_pm_cb cb, void *arg)
{
int ret = 0;

if (ctrl_command == DEVICE_PM_SET_POWER_STATE) {
if (*((u32_t *)context) == DEVICE_PM_SUSPEND_STATE) {
return aonpt_suspend_device(dev);
ret = aonpt_suspend_device(dev);
} else if (*((u32_t *)context) == DEVICE_PM_ACTIVE_STATE) {
return aonpt_resume_device_from_suspend(dev);
ret = aonpt_resume_device_from_suspend(dev);
}
} else if (ctrl_command == DEVICE_PM_GET_POWER_STATE) {
*((u32_t *)context) = aonpt_qmsi_get_power_state(dev);
return 0;
}

return 0;
if (cb) {
cb(dev, ret, context, arg);
}

return ret;
}
#else
#define aonpt_qmsi_set_power_state(...)
Expand Down
15 changes: 10 additions & 5 deletions drivers/counter/counter_rtc_qmsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,25 @@ static int rtc_resume_device(struct device *dev)
* the *context may include IN data or/and OUT data
*/
static int rtc_qmsi_device_ctrl(struct device *dev, u32_t ctrl_command,
void *context)
void *context, device_pm_cb cb, void *arg)
{
int ret = 0;

if (ctrl_command == DEVICE_PM_SET_POWER_STATE) {
if (*((u32_t *)context) == DEVICE_PM_SUSPEND_STATE) {
return rtc_suspend_device(dev);
ret = rtc_suspend_device(dev);
} else if (*((u32_t *)context) == DEVICE_PM_ACTIVE_STATE) {
return rtc_resume_device(dev);
ret = rtc_resume_device(dev);
}
} else if (ctrl_command == DEVICE_PM_GET_POWER_STATE) {
*((u32_t *)context) = rtc_qmsi_get_power_state(dev);
return 0;
}

return 0;
if (cb) {
cb(dev, ret, context, arg);
}

return ret;
}
#endif

Expand Down
13 changes: 9 additions & 4 deletions drivers/dma/dma_qmsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,19 +279,24 @@ static int dma_resume_device(struct device *dev)
}

static int dma_qmsi_device_ctrl(struct device *dev, u32_t ctrl_command,
void *context)
void *context, device_pm_cb cb, void *arg)
{
int ret = 0;

if (ctrl_command == DEVICE_PM_SET_POWER_STATE) {
if (*((u32_t *)context) == DEVICE_PM_SUSPEND_STATE) {
return dma_suspend_device(dev);
ret = dma_suspend_device(dev);
} else if (*((u32_t *)context) == DEVICE_PM_ACTIVE_STATE) {
return dma_resume_device(dev);
ret = dma_resume_device(dev);
}
} else if (ctrl_command == DEVICE_PM_GET_POWER_STATE) {
*((u32_t *)context) = dma_qmsi_get_power_state(dev);
}

return 0;
if (cb) {
cb(dev, ret, context, arg);
}
return ret;
}
#endif

Expand Down
14 changes: 10 additions & 4 deletions drivers/flash/soc_flash_qmsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,19 +303,25 @@ static int flash_qmsi_resume_device(struct device *dev)
}

static int flash_qmsi_device_ctrl(struct device *dev, u32_t ctrl_command,
void *context)
void *context, device_pm_cb cb, void *arg)
{
int ret = 0;

if (ctrl_command == DEVICE_PM_SET_POWER_STATE) {
if (*((u32_t *)context) == DEVICE_PM_SUSPEND_STATE) {
return flash_qmsi_suspend_device(dev);
ret = flash_qmsi_suspend_device(dev);
} else if (*((u32_t *)context) == DEVICE_PM_ACTIVE_STATE) {
return flash_qmsi_resume_device(dev);
ret = flash_qmsi_resume_device(dev);
}
} else if (ctrl_command == DEVICE_PM_GET_POWER_STATE) {
*((u32_t *)context) = flash_qmsi_get_power_state(dev);
}

return 0;
if (cb) {
cb(dev, ret, context, arg);
}

return ret;
}
#else
#define flash_qmsi_set_power_state(...)
Expand Down
15 changes: 10 additions & 5 deletions drivers/gpio/gpio_dw.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,19 +363,24 @@ static inline int gpio_dw_resume_from_suspend_port(struct device *port)
* the *context may include IN data or/and OUT data
*/
static int gpio_dw_device_ctrl(struct device *port, u32_t ctrl_command,
void *context)
void *context, device_pm_cb cb, void *arg)
{
int ret = 0;

if (ctrl_command == DEVICE_PM_SET_POWER_STATE) {
if (*((u32_t *)context) == DEVICE_PM_SUSPEND_STATE) {
return gpio_dw_suspend_port(port);
ret = gpio_dw_suspend_port(port);
} else if (*((u32_t *)context) == DEVICE_PM_ACTIVE_STATE) {
return gpio_dw_resume_from_suspend_port(port);
ret = gpio_dw_resume_from_suspend_port(port);
}
} else if (ctrl_command == DEVICE_PM_GET_POWER_STATE) {
*((u32_t *)context) = gpio_dw_get_power_state(port);
return 0;
}
return 0;

if (cb) {
cb(port, ret, context, arg);
}
return ret;
}

#else
Expand Down
21 changes: 15 additions & 6 deletions drivers/gpio/gpio_qmsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,24 @@ static int gpio_resume_device_from_suspend(struct device *dev)
* the *context may include IN data or/and OUT data
*/
static int gpio_qmsi_device_ctrl(struct device *port, u32_t ctrl_command,
void *context)
void *context, device_pm_cb cb, void *arg)
{
int ret = 0;

if (ctrl_command == DEVICE_PM_SET_POWER_STATE) {
if (*((u32_t *)context) == DEVICE_PM_SUSPEND_STATE) {
return gpio_suspend_device(port);
ret = gpio_suspend_device(port);
} else if (*((u32_t *)context) == DEVICE_PM_ACTIVE_STATE) {
return gpio_resume_device_from_suspend(port);
ret = gpio_resume_device_from_suspend(port);
}
} else if (ctrl_command == DEVICE_PM_GET_POWER_STATE) {
*((u32_t *)context) = gpio_qmsi_get_power_state(port);
return 0;
}
return 0;

if (cb) {
cb(port, ret, context, arg);
}
return ret;
}
#endif

Expand All @@ -138,7 +143,7 @@ static struct gpio_qmsi_runtime gpio_aon_runtime;
* the *context may include IN data or/and OUT data
*/
static int gpio_aon_device_ctrl(struct device *port, u32_t ctrl_command,
void *context)
void *context, device_pm_cb cb, void *arg)
{
if (ctrl_command == DEVICE_PM_SET_POWER_STATE) {
u32_t device_pm_state = *(u32_t *)context;
Expand All @@ -150,6 +155,10 @@ static int gpio_aon_device_ctrl(struct device *port, u32_t ctrl_command,
} else if (ctrl_command == DEVICE_PM_GET_POWER_STATE) {
*((u32_t *)context) = gpio_qmsi_get_power_state(port);
}

if (cb) {
cb(port, 0, context, arg);
}
return 0;
}
#endif
Expand Down
14 changes: 10 additions & 4 deletions drivers/gpio/gpio_qmsi_ss.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,24 @@ static int ss_gpio_resume_device_from_suspend(struct device *dev)
* the *context may include IN data or/and OUT data
*/
static int ss_gpio_qmsi_device_ctrl(struct device *port, u32_t ctrl_command,
void *context)
void *context, device_pm_cb cb, void *arg)
{
int ret = 0;

if (ctrl_command == DEVICE_PM_SET_POWER_STATE) {
if (*((u32_t *)context) == DEVICE_PM_SUSPEND_STATE) {
return ss_gpio_suspend_device(port);
ret = ss_gpio_suspend_device(port);
} else if (*((u32_t *)context) == DEVICE_PM_ACTIVE_STATE) {
return ss_gpio_resume_device_from_suspend(port);
ret = ss_gpio_resume_device_from_suspend(port);
}
} else if (ctrl_command == DEVICE_PM_GET_POWER_STATE) {
*((u32_t *)context) = ss_gpio_qmsi_get_power_state(port);
}
return 0;
if (cb) {
cb(port, ret, context, arg);
}

return ret;
}
#else
#define ss_gpio_qmsi_set_power_state(...)
Expand Down
15 changes: 10 additions & 5 deletions drivers/i2c/i2c_qmsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,25 @@ static int i2c_resume_device_from_suspend(struct device *dev)
* the *context may include IN data or/and OUT data
*/
static int i2c_device_ctrl(struct device *dev, u32_t ctrl_command,
void *context)
void *context, device_pm_cb cb, void *arg)
{
int ret = 0;

if (ctrl_command == DEVICE_PM_SET_POWER_STATE) {
if (*((u32_t *)context) == DEVICE_PM_SUSPEND_STATE) {
return i2c_suspend_device(dev);
ret = i2c_suspend_device(dev);
} else if (*((u32_t *)context) == DEVICE_PM_ACTIVE_STATE) {
return i2c_resume_device_from_suspend(dev);
ret = i2c_resume_device_from_suspend(dev);
}
} else if (ctrl_command == DEVICE_PM_GET_POWER_STATE) {
*((u32_t *)context) = i2c_qmsi_get_power_state(dev);
return 0;
}

return 0;
if (cb) {
cb(dev, ret, context, arg);
}

return ret;
}
#else
#define i2c_qmsi_set_power_state(...)
Expand Down
14 changes: 10 additions & 4 deletions drivers/i2c/i2c_qmsi_ss.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,25 @@ static int ss_i2c_resume_device_from_suspend(struct device *dev)
* the *context may include IN data or/and OUT data
*/
static int ss_i2c_device_ctrl(struct device *dev, u32_t ctrl_command,
void *context)
void *context, device_pm_cb cb, void *arg)
{
int ret = 0;

if (ctrl_command == DEVICE_PM_SET_POWER_STATE) {
if (*((u32_t *)context) == DEVICE_PM_SUSPEND_STATE) {
return ss_i2c_suspend_device(dev);
ret = ss_i2c_suspend_device(dev);
} else if (*((u32_t *)context) == DEVICE_PM_ACTIVE_STATE) {
return ss_i2c_resume_device_from_suspend(dev);
ret = ss_i2c_resume_device_from_suspend(dev);
}
} else if (ctrl_command == DEVICE_PM_GET_POWER_STATE) {
*((u32_t *)context) = ss_i2c_qmsi_get_power_state(dev);
}

return 0;
if (cb) {
cb(dev, ret, context, arg);
}

return ret;
}
#else
#define ss_i2c_qmsi_set_power_state(...)
Expand Down
16 changes: 11 additions & 5 deletions drivers/interrupt_controller/arcv2_irq_unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,25 @@ static int _arc_v2_irq_unit_get_state(struct device *dev)
* the *context may include IN data or/and OUT data
*/
static int _arc_v2_irq_unit_device_ctrl(struct device *device,
u32_t ctrl_command, void *context)
u32_t ctrl_command, void *context, device_pm_cb cb, void *arg)
{
int ret = 0;

if (ctrl_command == DEVICE_PM_SET_POWER_STATE) {
if (*((u32_t *)context) == DEVICE_PM_SUSPEND_STATE) {
return _arc_v2_irq_unit_suspend(device);
ret = _arc_v2_irq_unit_suspend(device);
} else if (*((u32_t *)context) == DEVICE_PM_ACTIVE_STATE) {
return _arc_v2_irq_unit_resume(device);
ret = _arc_v2_irq_unit_resume(device);
}
} else if (ctrl_command == DEVICE_PM_GET_POWER_STATE) {
*((u32_t *)context) = _arc_v2_irq_unit_get_state(device);
return 0;
}
return 0;

if (cb) {
cb(device, ret, context, arg);
}

return ret;
}

SYS_DEVICE_DEFINE("arc_v2_irq_unit", _arc_v2_irq_unit_init,
Expand Down
16 changes: 11 additions & 5 deletions drivers/interrupt_controller/ioapic_intr.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,19 +254,25 @@ int ioapic_resume_from_suspend(struct device *port)
* the *context may include IN data or/and OUT data
*/
static int ioapic_device_ctrl(struct device *device, u32_t ctrl_command,
void *context)
void *context, device_pm_cb cb, void *arg)
{
int ret = 0;

if (ctrl_command == DEVICE_PM_SET_POWER_STATE) {
if (*((u32_t *)context) == DEVICE_PM_SUSPEND_STATE) {
return ioapic_suspend(device);
ret = ioapic_suspend(device);
} else if (*((u32_t *)context) == DEVICE_PM_ACTIVE_STATE) {
return ioapic_resume_from_suspend(device);
ret = ioapic_resume_from_suspend(device);
}
} else if (ctrl_command == DEVICE_PM_GET_POWER_STATE) {
*((u32_t *)context) = ioapic_device_power_state;
return 0;
}
return 0;

if (cb) {
cb(device, ret, context, arg);
}

return ret;
}


Expand Down
15 changes: 10 additions & 5 deletions drivers/interrupt_controller/loapic_intr.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,20 +486,25 @@ int loapic_resume(struct device *port)
* the *context may include IN data or/and OUT data
*/
static int loapic_device_ctrl(struct device *port, u32_t ctrl_command,
void *context)
void *context, device_pm_cb cb, void *arg)
{
int ret = 0;

if (ctrl_command == DEVICE_PM_SET_POWER_STATE) {
if (*((u32_t *)context) == DEVICE_PM_SUSPEND_STATE) {
return loapic_suspend(port);
ret = loapic_suspend(port);
} else if (*((u32_t *)context) == DEVICE_PM_ACTIVE_STATE) {
return loapic_resume(port);
ret = loapic_resume(port);
}
} else if (ctrl_command == DEVICE_PM_GET_POWER_STATE) {
*((u32_t *)context) = loapic_device_power_state;
return 0;
}

return 0;
if (cb) {
cb(port, ret, context, arg);
}

return ret;
}

SYS_DEVICE_DEFINE("loapic", _loapic_init, loapic_device_ctrl, PRE_KERNEL_1,
Expand Down
Loading

0 comments on commit c3b0da8

Please sign in to comment.