Skip to content

Commit 0a0bcca

Browse files
ydamigosnashif
authored andcommitted
drivers/smartbond: Fix PM device runtime support
Removed PM device runtime support from drivers in PD_SYS domain. Update the rest device drivers to call pm_device_runtime_get/put() functions when CONFIG_PM_DEVICE_RUNTIME is enabled. Signed-off-by: Ioannis Damigos <[email protected]>
1 parent 1fc26b8 commit 0a0bcca

File tree

13 files changed

+238
-208
lines changed

13 files changed

+238
-208
lines changed

drivers/adc/adc_smartbond_gpadc.c

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ struct adc_smartbond_data {
4141
uint8_t sequence_channel_count;
4242
/* Index in buffer to store current value to */
4343
uint8_t result_index;
44-
#if defined(CONFIG_PM_DEVICE)
45-
/* Flag to prevent sleep */
46-
ATOMIC_DEFINE(pm_policy_state_flag, 1);
47-
#endif
4844
};
4945

5046
#define SMARTBOND_ADC_CHANNEL_COUNT 8
@@ -115,37 +111,25 @@ static int adc_smartbond_channel_setup(const struct device *dev,
115111
static inline void gpadc_smartbond_pm_policy_state_lock_get(const struct device *dev,
116112
struct adc_smartbond_data *data)
117113
{
118-
119114
#if defined(CONFIG_PM_DEVICE)
120-
#if defined(CONFIG_PM_DEVICE_RUNTIME)
121115
pm_device_runtime_get(dev);
122-
#endif
123-
124-
if (!atomic_test_and_set_bit(data->pm_policy_state_flag, 0)) {
125-
/*
126-
* Prevent the SoC from entering the normal sleep state.
127-
*/
128-
pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
129-
}
130-
116+
/*
117+
* Prevent the SoC from entering the normal sleep state.
118+
*/
119+
pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
131120
#endif
132121
}
133122

134123
static inline void gpadc_smartbond_pm_policy_state_lock_put(const struct device *dev,
135124
struct adc_smartbond_data *data)
136125
{
137126
#if defined(CONFIG_PM_DEVICE)
138-
#if defined(CONFIG_PM_DEVICE_RUNTIME)
127+
/*
128+
* Allow the SoC to enter the normal sleep state once GPADC is done.
129+
*/
130+
pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
139131
pm_device_runtime_put(dev);
140132
#endif
141-
142-
if (atomic_test_and_clear_bit(data->pm_policy_state_flag, 0)) {
143-
/*
144-
* Allow the SoC to enter the normal sleep state once GPADC is done.
145-
*/
146-
pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
147-
}
148-
#endif
149133
}
150134

151135
#define PER_CHANNEL_ADC_CONFIG_MASK (GPADC_GP_ADC_CTRL_REG_GP_ADC_SEL_Msk | \
@@ -259,8 +243,8 @@ static void adc_smartbond_isr(const struct device *dev)
259243
data->channel_read_mask ^= 1 << current_channel;
260244

261245
if (data->channel_read_mask == 0) {
262-
adc_context_on_sampling_done(&data->ctx, dev);
263246
gpadc_smartbond_pm_policy_state_lock_put(dev, data);
247+
adc_context_on_sampling_done(&data->ctx, dev);
264248
} else {
265249
adc_context_start_sampling(&data->ctx);
266250
}
@@ -275,8 +259,8 @@ static int adc_smartbond_read(const struct device *dev,
275259
int error;
276260
struct adc_smartbond_data *data = dev->data;
277261

278-
gpadc_smartbond_pm_policy_state_lock_get(dev, data);
279262
adc_context_lock(&data->ctx, false, NULL);
263+
gpadc_smartbond_pm_policy_state_lock_get(dev, data);
280264
error = start_read(dev, sequence);
281265
adc_context_release(&data->ctx, error);
282266

@@ -292,8 +276,8 @@ static int adc_smartbond_read_async(const struct device *dev,
292276
struct adc_smartbond_data *data = dev->data;
293277
int error;
294278

295-
gpadc_smartbond_pm_policy_state_lock_get(dev, data);
296279
adc_context_lock(&data->ctx, true, async);
280+
gpadc_smartbond_pm_policy_state_lock_get(dev, data);
297281
error = start_read(dev, sequence);
298282
adc_context_release(&data->ctx, error);
299283

drivers/adc/adc_smartbond_sdadc.c

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ struct sdadc_smartbond_data {
4040
uint8_t sequence_channel_count;
4141
/* Index in buffer to store current value to */
4242
uint8_t result_index;
43-
#if defined(CONFIG_PM_DEVICE)
44-
/* Flag to prevent sleep */
45-
ATOMIC_DEFINE(pm_policy_state_flag, 1);
46-
#endif
4743
};
4844

4945
#define SMARTBOND_SDADC_CHANNEL_COUNT 8
@@ -119,34 +115,24 @@ static inline void sdadc_smartbond_pm_policy_state_lock_get(const struct device
119115
struct sdadc_smartbond_data *data)
120116
{
121117
#if defined(CONFIG_PM_DEVICE)
122-
#if defined(CONFIG_PM_DEVICE_RUNTIME)
123118
pm_device_runtime_get(dev);
124-
#endif
125-
126-
if (!atomic_test_and_set_bit(data->pm_policy_state_flag, 0)) {
127-
/*
128-
* Prevent the SoC from entering the normal sleep state.
129-
*/
130-
pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
131-
}
119+
/*
120+
* Prevent the SoC from entering the normal sleep state.
121+
*/
122+
pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
132123
#endif
133124
}
134125

135126
static inline void sdadc_smartbond_pm_policy_state_lock_put(const struct device *dev,
136127
struct sdadc_smartbond_data *data)
137128
{
138129
#if defined(CONFIG_PM_DEVICE)
139-
#if defined(CONFIG_PM_DEVICE_RUNTIME)
130+
/*
131+
* Allow the SoC to enter the normal sleep state once sdadc is done.
132+
*/
133+
pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
140134
pm_device_runtime_put(dev);
141135
#endif
142-
143-
if (atomic_test_and_clear_bit(data->pm_policy_state_flag, 0)) {
144-
/*
145-
* Allow the SoC to enter the normal sleep state once sdadc is done.
146-
*/
147-
pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
148-
}
149-
#endif
150136
}
151137

152138

@@ -262,8 +248,8 @@ static void sdadc_smartbond_isr(const struct device *dev)
262248
data->channel_read_mask ^= 1 << current_channel;
263249

264250
if (data->channel_read_mask == 0) {
265-
adc_context_on_sampling_done(&data->ctx, dev);
266251
sdadc_smartbond_pm_policy_state_lock_put(dev, data);
252+
adc_context_on_sampling_done(&data->ctx, dev);
267253
} else {
268254
adc_context_start_sampling(&data->ctx);
269255
}
@@ -278,8 +264,8 @@ static int sdadc_smartbond_read(const struct device *dev,
278264
int error;
279265
struct sdadc_smartbond_data *data = dev->data;
280266

281-
sdadc_smartbond_pm_policy_state_lock_get(dev, data);
282267
adc_context_lock(&data->ctx, false, NULL);
268+
sdadc_smartbond_pm_policy_state_lock_get(dev, data);
283269
error = start_read(dev, sequence);
284270
adc_context_release(&data->ctx, error);
285271

@@ -295,8 +281,8 @@ static int sdadc_smartbond_read_async(const struct device *dev,
295281
struct sdadc_smartbond_data *data = dev->data;
296282
int error;
297283

298-
sdadc_smartbond_pm_policy_state_lock_get(dev, data);
299284
adc_context_lock(&data->ctx, true, async);
285+
sdadc_smartbond_pm_policy_state_lock_get(dev, data);
300286
error = start_read(dev, sequence);
301287
adc_context_release(&data->ctx, error);
302288

drivers/counter/counter_smartbond_timer.c

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ struct counter_smartbond_data {
3535
void *user_data;
3636
uint32_t guard_period;
3737
uint32_t freq;
38-
#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME)
39-
ATOMIC_DEFINE(pm_policy_state_flag, 1);
38+
#if defined(CONFIG_PM_DEVICE)
4039
uint8_t pdc_idx;
4140
#endif
4241
};
@@ -59,19 +58,17 @@ struct counter_smartbond_config {
5958
LOG_INSTANCE_PTR_DECLARE(log);
6059
};
6160

62-
#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME)
63-
static void counter_smartbond_pm_policy_state_lock_get(struct counter_smartbond_data *data)
61+
#if defined(CONFIG_PM_DEVICE)
62+
static void counter_smartbond_pm_policy_state_lock_get(const struct device *dev)
6463
{
65-
if (!atomic_test_and_set_bit(data->pm_policy_state_flag, 0)) {
66-
pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
67-
}
64+
pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
65+
pm_device_runtime_get(dev);
6866
}
6967

70-
static void counter_smartbond_pm_policy_state_lock_put(struct counter_smartbond_data *data)
68+
static void counter_smartbond_pm_policy_state_lock_put(const struct device *dev)
7169
{
72-
if (atomic_test_and_clear_bit(data->pm_policy_state_flag, 0)) {
73-
pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
74-
}
70+
pm_device_runtime_put(dev);
71+
pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
7572
}
7673

7774
/*
@@ -120,23 +117,18 @@ static void counter_smartbond_pdc_add(const struct device *dev)
120117
struct counter_smartbond_data *data = dev->data;
121118
uint8_t trigger = counter_smartbond_pdc_trigger_get(dev);
122119

123-
if (!atomic_test_and_set_bit(data->pm_policy_state_flag, 0)) {
120+
data->pdc_idx = da1469x_pdc_add(trigger, MCU_PDC_MASTER_M33, PDC_XTAL_EN);
121+
__ASSERT_NO_MSG(data->pdc_idx >= 0);
124122

125-
data->pdc_idx = da1469x_pdc_add(trigger, MCU_PDC_MASTER_M33, PDC_XTAL_EN);
126-
__ASSERT_NO_MSG(data->pdc_idx >= 0);
127-
128-
da1469x_pdc_set(data->pdc_idx);
129-
da1469x_pdc_ack(data->pdc_idx);
130-
}
123+
da1469x_pdc_set(data->pdc_idx);
124+
da1469x_pdc_ack(data->pdc_idx);
131125
}
132126

133127
static void counter_smartbond_pdc_del(const struct device *dev)
134128
{
135129
struct counter_smartbond_data *data = dev->data;
136130

137-
if (atomic_test_and_clear_bit(data->pm_policy_state_flag, 0)) {
138-
da1469x_pdc_del(data->pdc_idx);
139-
}
131+
da1469x_pdc_del(data->pdc_idx);
140132
}
141133
#endif
142134

@@ -145,24 +137,23 @@ static int counter_smartbond_start(const struct device *dev)
145137
const struct counter_smartbond_config *config = dev->config;
146138
TIMER2_Type *timer = config->timer;
147139

148-
/* Enable counter in free running mode */
149-
timer->TIMER2_CTRL_REG |= (TIMER2_TIMER2_CTRL_REG_TIM_CLK_EN_Msk |
150-
TIMER2_TIMER2_CTRL_REG_TIM_EN_Msk |
151-
TIMER2_TIMER2_CTRL_REG_TIM_FREE_RUN_MODE_EN_Msk);
152-
153-
#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME)
140+
#if defined(CONFIG_PM_DEVICE)
154141
if (!counter_smartbond_is_sleep_allowed(dev)) {
155-
struct counter_smartbond_data *data = dev->data;
156142
/*
157143
* Power mode constraints should be applied as long as the device
158144
* is up and running.
159145
*/
160-
counter_smartbond_pm_policy_state_lock_get(data);
146+
counter_smartbond_pm_policy_state_lock_get(dev);
161147
} else {
162148
counter_smartbond_pdc_add(dev);
163149
}
164150
#endif
165151

152+
/* Enable counter in free running mode */
153+
timer->TIMER2_CTRL_REG |= (TIMER2_TIMER2_CTRL_REG_TIM_CLK_EN_Msk |
154+
TIMER2_TIMER2_CTRL_REG_TIM_EN_Msk |
155+
TIMER2_TIMER2_CTRL_REG_TIM_FREE_RUN_MODE_EN_Msk);
156+
166157
return 0;
167158
}
168159

@@ -178,9 +169,9 @@ static int counter_smartbond_stop(const struct device *dev)
178169
TIMER2_TIMER2_CTRL_REG_TIM_CLK_EN_Msk);
179170
data->callback = NULL;
180171

181-
#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME)
172+
#if defined(CONFIG_PM_DEVICE)
182173
if (!counter_smartbond_is_sleep_allowed(dev)) {
183-
counter_smartbond_pm_policy_state_lock_put(data);
174+
counter_smartbond_pm_policy_state_lock_put(dev);
184175
} else {
185176
counter_smartbond_pdc_del(dev);
186177
}
@@ -421,7 +412,7 @@ static uint32_t counter_smartbond_get_freq(const struct device *dev)
421412
return data->freq;
422413
}
423414

424-
#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME)
415+
#if defined(CONFIG_PM_DEVICE)
425416
static void counter_smartbond_resume(const struct device *dev)
426417
{
427418
const struct counter_smartbond_config *cfg = dev->config;

drivers/crypto/crypto_smartbond.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <da1469x_pd.h>
1616
#include <zephyr/sys/byteorder.h>
1717
#include <zephyr/pm/device.h>
18-
#include <zephyr/pm/device_runtime.h>
1918
#include <zephyr/pm/policy.h>
2019
#include <zephyr/logging/log.h>
2120

@@ -936,7 +935,7 @@ static const struct crypto_driver_api crypto_smartbond_driver_api = {
936935
.query_hw_caps = crypto_smartbond_query_hw_caps
937936
};
938937

939-
#if defined(CONFIG_PM_DEVICE) || defined(CONFIG_PM_DEVICE_RUNTIME)
938+
#if defined(CONFIG_PM_DEVICE)
940939
static int crypto_smartbond_pm_action(const struct device *dev,
941940
enum pm_device_action action)
942941
{
@@ -984,14 +983,7 @@ static int crypto_smartbond_init(const struct device *dev)
984983
/* Controller should be initialized once a crypyographic session is requested */
985984
crypto_smartbond_set_status(false);
986985

987-
#ifdef CONFIG_PM_DEVICE_RUNTIME
988-
/* Make sure device state is marked as suspended */
989-
pm_device_init_suspended(dev);
990-
991-
return pm_device_runtime_enable(dev);
992-
#else
993986
return 0;
994-
#endif
995987
}
996988

997989
/*

0 commit comments

Comments
 (0)