Skip to content

Commit d67a578

Browse files
Flavio Ceolinnashif
authored andcommitted
pm: device_runtime: Change API behavior s/_sync/_async
Most APIs have the default synchronous and an asynchronous version with the sufix _async because that is the most common use. All devices in tree right now are using the synchronous version, so just change it to be consistent with the rest of the system. Signed-off-by: Flavio Ceolin <[email protected]>
1 parent 4528906 commit d67a578

File tree

10 files changed

+37
-39
lines changed

10 files changed

+37
-39
lines changed

doc/reference/power_management/index.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ Resume Device asynchronously API
440440

441441
.. code-block:: c
442442
443-
int pm_device_get(const struct device *dev);
443+
int pm_device_get_async(const struct device *dev);
444444
445445
Marks the device as being used. This API will asynchronously
446446
bring the device to resume state if it was suspended. If the device
@@ -455,7 +455,7 @@ Resume Device synchronously API
455455

456456
.. code-block:: c
457457
458-
int pm_device_get_sync(const struct device *dev);
458+
int pm_device_get(const struct device *dev);
459459
460460
Marks the device as being used. It will bring up or resume
461461
the device if it is in suspended state based on the device
@@ -467,7 +467,7 @@ Suspend Device asynchronously API
467467

468468
.. code-block:: c
469469
470-
int pm_device_put(const struct device *dev);
470+
int pm_device_put_async(const struct device *dev);
471471
472472
Releases a device. This API asynchronously puts the device to suspend
473473
state if not already in suspend state if the usage count of this device
@@ -481,7 +481,7 @@ Suspend Device synchronously API
481481

482482
.. code-block:: c
483483
484-
int pm_device_put_sync(const struct device *dev);
484+
int pm_device_put(const struct device *dev);
485485
486486
Marks the device as being released. It will put the device to
487487
suspended state if is is in active state based on the device

drivers/gpio/gpio_stm32.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ static int gpio_stm32_config(const struct device *dev,
467467
#ifdef CONFIG_PM_DEVICE_RUNTIME
468468
/* Enable device clock before configuration (requires bank writes) */
469469
if (data->power_state != PM_DEVICE_STATE_ACTIVE) {
470-
err = pm_device_get_sync(dev);
470+
err = pm_device_get(dev);
471471
if (err < 0) {
472472
return err;
473473
}
@@ -488,7 +488,7 @@ static int gpio_stm32_config(const struct device *dev,
488488
#ifdef CONFIG_PM_DEVICE_RUNTIME
489489
/* Release clock only if configuration doesn't require bank writes */
490490
if ((flags & GPIO_OUTPUT) == 0) {
491-
err = pm_device_put(dev);
491+
err = pm_device_put_async(dev);
492492
if (err < 0) {
493493
return err;
494494
}

drivers/pinmux/stm32/pinmux_stm32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ int stm32_dt_pinctrl_configure(const struct soc_gpio_pinctrl *pinctrl,
129129
port_device = gpio_ports[STM32_PORT(pin)];
130130

131131
#ifdef CONFIG_PM_DEVICE_RUNTIME
132-
ret = pm_device_get_sync(port_device);
132+
ret = pm_device_get(port_device);
133133
#else
134134
ret = gpio_stm32_clock_request(port_device, true);
135135
/* Note, we don't use pm_constraint_foo functions here */

include/pm/device_runtime.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void pm_device_disable(const struct device *dev);
6868
* pm signal mechanism to know the completion of resume operation.
6969
* @retval Errno Negative errno code if failure.
7070
*/
71-
int pm_device_get(const struct device *dev);
71+
int pm_device_get_async(const struct device *dev);
7272

7373
/**
7474
* @brief Call device resume synchronously based on usage count
@@ -83,7 +83,7 @@ int pm_device_get(const struct device *dev);
8383
* @retval 0 If successful.
8484
* @retval Errno Negative errno code if failure.
8585
*/
86-
int pm_device_get_sync(const struct device *dev);
86+
int pm_device_get(const struct device *dev);
8787

8888
/**
8989
* @brief Call device suspend asynchronously based on usage count
@@ -101,7 +101,7 @@ int pm_device_get_sync(const struct device *dev);
101101
* signal mechanism to know the completion of suspend operation.
102102
* @retval Errno Negative errno code if failure.
103103
*/
104-
int pm_device_put(const struct device *dev);
104+
int pm_device_put_async(const struct device *dev);
105105

106106
/**
107107
* @brief Call device suspend synchronously based on usage count
@@ -116,14 +116,14 @@ int pm_device_put(const struct device *dev);
116116
* @retval 0 If successful.
117117
* @retval Errno Negative errno code if failure.
118118
*/
119-
int pm_device_put_sync(const struct device *dev);
119+
int pm_device_put(const struct device *dev);
120120

121121
/**
122122
* @brief Wait on a device to finish an operation.
123123
*
124-
* The calling thread blocks until the device finishes a @ref pm_device_put or
125-
* @ref pm_device_get operation. If there is no operation in progress
126-
* this function will return immediately.
124+
* The calling thread blocks until the device finishes a
125+
* @ref pm_device_put_async or @ref pm_device_get_async operation. If there is
126+
* no operation in progress this function will return immediately.
127127
*
128128
* @param dev Pointer to device structure of the specific device driver
129129
* the caller is interested in.
@@ -138,9 +138,9 @@ int pm_device_wait(const struct device *dev, k_timeout_t timeout);
138138
static inline void pm_device_enable(const struct device *dev) { }
139139
static inline void pm_device_disable(const struct device *dev) { }
140140
static inline int pm_device_get(const struct device *dev) { return -ENOSYS; }
141-
static inline int pm_device_get_sync(const struct device *dev) { return -ENOSYS; }
141+
static inline int pm_device_get_async(const struct device *dev) { return -ENOSYS; }
142142
static inline int pm_device_put(const struct device *dev) { return -ENOSYS; }
143-
static inline int pm_device_put_sync(const struct device *dev) { return -ENOSYS; }
143+
static inline int pm_device_put_async(const struct device *dev) { return -ENOSYS; }
144144
static inline int pm_device_wait(const struct device *dev,
145145
k_timeout_t timeout) { return -ENOSYS; }
146146
#endif

samples/subsys/pm/device_pm/src/dummy_driver.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ static int dummy_open(const struct device *dev)
1919
printk("open()\n");
2020

2121
/* Make sure parent is resumed */
22-
ret = pm_device_get_sync(parent);
22+
ret = pm_device_get(parent);
2323
if (ret < 0) {
2424
return ret;
2525
}
2626

27-
ret = pm_device_get(dev);
27+
ret = pm_device_get_async(dev);
2828
if (ret < 0) {
2929
return ret;
3030
}
@@ -72,14 +72,14 @@ static int dummy_close(const struct device *dev)
7272
int ret;
7373

7474
printk("close()\n");
75-
ret = pm_device_put_sync(dev);
75+
ret = pm_device_put(dev);
7676
if (ret == 1) {
7777
printk("Async suspend request ququed\n");
7878
}
7979

8080
/* Parent can be suspended */
8181
if (parent) {
82-
pm_device_put_sync(parent);
82+
pm_device_put(parent);
8383
}
8484

8585
return ret;

subsys/pm/device_runtime.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,24 +178,22 @@ static int pm_device_request(const struct device *dev,
178178

179179
int pm_device_get(const struct device *dev)
180180
{
181-
return pm_device_request(dev,
182-
PM_DEVICE_STATE_ACTIVE, PM_DEVICE_ASYNC);
181+
return pm_device_request(dev, PM_DEVICE_STATE_ACTIVE, 0);
183182
}
184183

185-
int pm_device_get_sync(const struct device *dev)
184+
int pm_device_get_async(const struct device *dev)
186185
{
187-
return pm_device_request(dev, PM_DEVICE_STATE_ACTIVE, 0);
186+
return pm_device_request(dev, PM_DEVICE_STATE_ACTIVE, PM_DEVICE_ASYNC);
188187
}
189188

190189
int pm_device_put(const struct device *dev)
191190
{
192-
return pm_device_request(dev,
193-
PM_DEVICE_STATE_SUSPEND, PM_DEVICE_ASYNC);
191+
return pm_device_request(dev, PM_DEVICE_STATE_SUSPEND, 0);
194192
}
195193

196-
int pm_device_put_sync(const struct device *dev)
194+
int pm_device_put_async(const struct device *dev)
197195
{
198-
return pm_device_request(dev, PM_DEVICE_STATE_SUSPEND, 0);
196+
return pm_device_request(dev, PM_DEVICE_STATE_SUSPEND, PM_DEVICE_ASYNC);
199197
}
200198

201199
void pm_device_enable(const struct device *dev)

tests/subsys/pm/device_runtime/src/dummy_driver.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ static int dummy_wait(const struct device *dev)
1818

1919
static int dummy_open(const struct device *dev)
2020
{
21-
return pm_device_get(dev);
21+
return pm_device_get_async(dev);
2222
}
2323

2424
static int dummy_open_sync(const struct device *dev)
2525
{
26-
return pm_device_get_sync(dev);
26+
return pm_device_get(dev);
2727
}
2828

2929
static int dummy_close(const struct device *dev)
3030
{
31-
return pm_device_put(dev);
31+
return pm_device_put_async(dev);
3232
}
3333

3434
static int dummy_close_sync(const struct device *dev)
3535
{
36-
return pm_device_put_sync(dev);
36+
return pm_device_put(dev);
3737
}
3838

3939
static uint32_t dummy_get_power_state(const struct device *dev)

tests/subsys/pm/device_runtime/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void threadB_func(void *arg1, void *arg2, void *arg3)
9494
* in favor of threadA. At this point the device should reflect these
9595
* operations and be suspended.
9696
*
97-
* @see pm_device_get(), pm_device_put()
97+
* @see pm_device_get_async(), pm_device_put_async()
9898
*
9999
* @ingroup power_tests
100100
*/
@@ -144,7 +144,7 @@ void test_teardown(void)
144144
* @details
145145
* - Just bring up and put down the device using the synchronous API.
146146
*
147-
* @see pm_device_get_sync(), pm_device_put_sync()
147+
* @see pm_device_get_async(), pm_device_put()
148148
*
149149
* @ingroup power_tests
150150
*/

tests/subsys/pm/power_mgmt/src/dummy_driver.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ static uint32_t device_power_state;
1313

1414
static int dummy_open(const struct device *dev)
1515
{
16-
return pm_device_get_sync(dev);
16+
return pm_device_get(dev);
1717
}
1818

1919
static int dummy_close(const struct device *dev)
2020
{
21-
return pm_device_put_sync(dev);
21+
return pm_device_put(dev);
2222
}
2323

2424
static uint32_t dummy_get_power_state(const struct device *dev)

tests/subsys/pm/power_mgmt/src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ void test_power_state_trans(void)
165165
* @brief notification between system and device
166166
*
167167
* @details
168-
* - device driver notify its power state change by pm_device_get and
169-
* pm_device_put
168+
* - device driver notify its power state change by pm_device_get_async and
169+
* pm_device_put_async
170170
* - system inform device system power state change through device interface
171171
* pm_control
172172
*
173-
* @see pm_device_get(), pm_device_put(), pm_device_state_set(),
173+
* @see pm_device_get_async(), pm_device_put_async(), pm_device_state_set(),
174174
* pm_device_state_get()
175175
*
176176
* @ingroup power_tests

0 commit comments

Comments
 (0)