Skip to content

Commit 7eba310

Browse files
Flavio Ceolinnashif
Flavio Ceolin
authored andcommitted
power: device: void *context -> uint32_t *state
The context parameter used across device power management is actually the power state. Just use it and avoid a lot of unnecessary casts. Signed-off-by: Flavio Ceolin <[email protected]>
1 parent 9ac646f commit 7eba310

30 files changed

+111
-109
lines changed

drivers/display/display_st7789v.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -409,14 +409,14 @@ static void st7789v_enter_sleep(struct st7789v_data *data)
409409
}
410410

411411
static int st7789v_pm_control(const struct device *dev, uint32_t ctrl_command,
412-
void *context, pm_device_cb cb, void *arg)
412+
uint32_t *state, pm_device_cb cb, void *arg)
413413
{
414414
int ret = 0;
415415
struct st7789v_data *data = (struct st7789v_data *)dev->data;
416416

417417
switch (ctrl_command) {
418-
case PM_DEVICE_STATE_SET:
419-
if (*((uint32_t *)context) == PM_DEVICE_ACTIVE_STATE) {
418+
case DEVICE_PM_SET_POWER_STATE:
419+
if (*state == PM_DEVICE_ACTIVE_STATE) {
420420
st7789v_exit_sleep(data);
421421
data->pm_state = PM_DEVICE_ACTIVE_STATE;
422422
ret = 0;
@@ -427,14 +427,14 @@ static int st7789v_pm_control(const struct device *dev, uint32_t ctrl_command,
427427
}
428428
break;
429429
case PM_DEVICE_STATE_GET:
430-
*((uint32_t *)context) = data->pm_state;
430+
*state = data->pm_state;
431431
break;
432432
default:
433433
ret = -EINVAL;
434434
}
435435

436436
if (cb != NULL) {
437-
cb(dev, ret, context, arg);
437+
cb(dev, ret, state, arg);
438438
}
439439
return ret;
440440
}

drivers/entropy/entropy_cc13xx_cc26xx.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -293,26 +293,26 @@ static int entropy_cc13xx_cc26xx_set_power_state(const struct device *dev,
293293

294294
static int entropy_cc13xx_cc26xx_pm_control(const struct device *dev,
295295
uint32_t ctrl_command,
296-
void *context, pm_device_cb cb,
296+
uint32_t *state, pm_device_cb cb,
297297
void *arg)
298298
{
299299
struct entropy_cc13xx_cc26xx_data *data = get_dev_data(dev);
300300
int ret = 0;
301301

302302
if (ctrl_command == PM_DEVICE_STATE_SET) {
303-
uint32_t new_state = *((const uint32_t *)context);
303+
uint32_t new_state = *state;
304304

305305
if (new_state != data->pm_state) {
306306
ret = entropy_cc13xx_cc26xx_set_power_state(dev,
307307
new_state);
308308
}
309309
} else {
310310
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
311-
*((uint32_t *)context) = data->pm_state;
311+
*state = data->pm_state;
312312
}
313313

314314
if (cb) {
315-
cb(dev, ret, context, arg);
315+
cb(dev, ret, state, arg);
316316
}
317317

318318
return ret;

drivers/ethernet/eth_mcux.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ void eth_mcux_phy_stop(struct eth_context *context);
186186

187187
static int eth_mcux_device_pm_control(const struct device *dev,
188188
uint32_t command,
189-
void *context, pm_device_cb cb, void *arg)
189+
uint32_t *state, pm_device_cb cb,
190+
void *arg)
190191
{
191192
struct eth_context *eth_ctx = (struct eth_context *)dev->data;
192193
int ret = 0;
@@ -199,7 +200,7 @@ static int eth_mcux_device_pm_control(const struct device *dev,
199200
}
200201

201202
if (command == PM_DEVICE_STATE_SET) {
202-
if (*(uint32_t *)context == PM_DEVICE_SUSPEND_STATE) {
203+
if (*state == PM_DEVICE_SUSPEND_STATE) {
203204
LOG_DBG("Suspending");
204205

205206
ret = net_if_suspend(eth_ctx->iface);
@@ -214,7 +215,7 @@ static int eth_mcux_device_pm_control(const struct device *dev,
214215
ENET_Deinit(eth_ctx->base);
215216
clock_control_off(eth_ctx->clock_dev,
216217
(clock_control_subsys_t)eth_ctx->clock);
217-
} else if (*(uint32_t *)context == PM_DEVICE_ACTIVE_STATE) {
218+
} else if (*state == PM_DEVICE_ACTIVE_STATE) {
218219
LOG_DBG("Resuming");
219220

220221
clock_control_on(eth_ctx->clock_dev,
@@ -228,7 +229,7 @@ static int eth_mcux_device_pm_control(const struct device *dev,
228229

229230
out:
230231
if (cb) {
231-
cb(dev, ret, context, arg);
232+
cb(dev, ret, state, arg);
232233
}
233234

234235
return ret;

drivers/flash/spi_flash_at45.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -629,14 +629,15 @@ static int spi_flash_at45_init(const struct device *dev)
629629
#if IS_ENABLED(CONFIG_PM_DEVICE)
630630
static int spi_flash_at45_pm_control(const struct device *dev,
631631
uint32_t ctrl_command,
632-
void *context, pm_device_cb cb, void *arg)
632+
uint32_t *state, pm_device_cb cb,
633+
void *arg)
633634
{
634635
struct spi_flash_at45_data *dev_data = get_dev_data(dev);
635636
const struct spi_flash_at45_config *dev_config = get_dev_config(dev);
636637
int err = 0;
637638

638639
if (ctrl_command == PM_DEVICE_STATE_SET) {
639-
uint32_t new_state = *((const uint32_t *)context);
640+
uint32_t new_state = *state;
640641

641642
if (new_state != dev_data->pm_state) {
642643
switch (new_state) {
@@ -666,11 +667,11 @@ static int spi_flash_at45_pm_control(const struct device *dev,
666667
}
667668
} else {
668669
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
669-
*((uint32_t *)context) = dev_data->pm_state;
670+
*state = dev_data->pm_state;
670671
}
671672

672673
if (cb) {
673-
cb(dev, err, context, arg);
674+
cb(dev, err, state, arg);
674675
}
675676

676677
return err;

drivers/gpio/gpio_stm32.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -605,29 +605,29 @@ static int gpio_stm32_set_power_state(const struct device *dev,
605605

606606
static int gpio_stm32_pm_device_ctrl(const struct device *dev,
607607
uint32_t ctrl_command,
608-
void *context, pm_device_cb cb, void *arg)
608+
uint32_t *state, pm_device_cb cb, void *arg)
609609
{
610610
struct gpio_stm32_data *data = dev->data;
611611
uint32_t new_state;
612612
int ret = 0;
613613

614614
switch (ctrl_command) {
615615
case PM_DEVICE_STATE_SET:
616-
new_state = *((const uint32_t *)context);
616+
new_state = *state;
617617
if (new_state != data->power_state) {
618618
ret = gpio_stm32_set_power_state(dev, new_state);
619619
}
620620
break;
621621
case PM_DEVICE_STATE_GET:
622-
*((uint32_t *)context) = gpio_stm32_get_power_state(dev);
622+
*state = gpio_stm32_get_power_state(dev);
623623
break;
624624
default:
625625
ret = -EINVAL;
626626

627627
}
628628

629629
if (cb) {
630-
cb(dev, ret, context, arg);
630+
cb(dev, ret, state, arg);
631631
}
632632

633633
return ret;

drivers/i2c/i2c_cc13xx_cc26xx.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -368,25 +368,25 @@ static int i2c_cc13xx_cc26xx_set_power_state(const struct device *dev,
368368

369369
static int i2c_cc13xx_cc26xx_pm_control(const struct device *dev,
370370
uint32_t ctrl_command,
371-
void *context, pm_device_cb cb,
371+
uint32_t *state, pm_device_cb cb,
372372
void *arg)
373373
{
374374
int ret = 0;
375375

376376
if (ctrl_command == PM_DEVICE_STATE_SET) {
377-
uint32_t new_state = *((const uint32_t *)context);
377+
uint32_t new_state = *state;
378378

379379
if (new_state != get_dev_data(dev)->pm_state) {
380380
ret = i2c_cc13xx_cc26xx_set_power_state(dev,
381381
new_state);
382382
}
383383
} else {
384384
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
385-
*((uint32_t *)context) = get_dev_data(dev)->pm_state;
385+
*state = get_dev_data(dev)->pm_state;
386386
}
387387

388388
if (cb) {
389-
cb(dev, ret, context, arg);
389+
cb(dev, ret, state, arg);
390390
}
391391

392392
return ret;

drivers/i2c/i2c_nrfx_twi.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,13 @@ static int init_twi(const struct device *dev)
224224
#ifdef CONFIG_PM_DEVICE
225225
static int twi_nrfx_pm_control(const struct device *dev,
226226
uint32_t ctrl_command,
227-
void *context, pm_device_cb cb, void *arg)
227+
uint32_t *state, pm_device_cb cb, void *arg)
228228
{
229229
int ret = 0;
230230
uint32_t pm_current_state = get_dev_data(dev)->pm_state;
231231

232232
if (ctrl_command == PM_DEVICE_STATE_SET) {
233-
uint32_t new_state = *((const uint32_t *)context);
233+
uint32_t new_state = *state;
234234

235235
if (new_state != pm_current_state) {
236236
switch (new_state) {
@@ -260,11 +260,11 @@ static int twi_nrfx_pm_control(const struct device *dev,
260260
}
261261
} else {
262262
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
263-
*((uint32_t *)context) = get_dev_data(dev)->pm_state;
263+
*state = get_dev_data(dev)->pm_state;
264264
}
265265

266266
if (cb) {
267-
cb(dev, ret, context, arg);
267+
cb(dev, ret, state, arg);
268268
}
269269

270270
return ret;

drivers/i2c/i2c_nrfx_twim.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,13 @@ static int init_twim(const struct device *dev)
263263
#ifdef CONFIG_PM_DEVICE
264264
static int twim_nrfx_pm_control(const struct device *dev,
265265
uint32_t ctrl_command,
266-
void *context, pm_device_cb cb, void *arg)
266+
uint32_t *state, pm_device_cb cb, void *arg)
267267
{
268268
int ret = 0;
269269
uint32_t pm_current_state = get_dev_data(dev)->pm_state;
270270

271271
if (ctrl_command == PM_DEVICE_STATE_SET) {
272-
uint32_t new_state = *((const uint32_t *)context);
272+
uint32_t new_state = *state;
273273

274274
if (new_state != pm_current_state) {
275275
switch (new_state) {
@@ -300,11 +300,11 @@ static int twim_nrfx_pm_control(const struct device *dev,
300300
}
301301
} else {
302302
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
303-
*((uint32_t *)context) = get_dev_data(dev)->pm_state;
303+
*state = get_dev_data(dev)->pm_state;
304304
}
305305

306306
if (cb) {
307-
cb(dev, ret, context, arg);
307+
cb(dev, ret, state, arg);
308308
}
309309

310310
return ret;

drivers/interrupt_controller/intc_arcv2_irq_unit.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static int arc_v2_irq_unit_get_state(const struct device *dev)
192192
* @return operation result
193193
*/
194194
static int arc_v2_irq_unit_device_ctrl(const struct device *dev,
195-
uint32_t ctrl_command, void *context,
195+
uint32_t ctrl_command, uint32_t *context,
196196
pm_device_cb cb, void *arg)
197197
{
198198
int ret = 0;

drivers/interrupt_controller/intc_ioapic.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ int ioapic_resume_from_suspend(const struct device *port)
303303
*/
304304
static int ioapic_device_ctrl(const struct device *dev,
305305
uint32_t ctrl_command,
306-
void *context, pm_device_cb cb, void *arg)
306+
uint32_t *context, pm_device_cb cb, void *arg)
307307
{
308308
int ret = 0;
309309

drivers/interrupt_controller/intc_loapic.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -404,18 +404,18 @@ int loapic_resume(const struct device *port)
404404
*/
405405
static int loapic_device_ctrl(const struct device *port,
406406
uint32_t ctrl_command,
407-
void *context, pm_device_cb cb, void *arg)
407+
uint32_t *context, pm_device_cb cb, void *arg)
408408
{
409409
int ret = 0;
410410

411411
if (ctrl_command == PM_DEVICE_STATE_SET) {
412-
if (*((uint32_t *)context) == PM_DEVICE_SUSPEND_STATE) {
412+
if (*context == PM_DEVICE_SUSPEND_STATE) {
413413
ret = loapic_suspend(port);
414-
} else if (*((uint32_t *)context) == PM_DEVICE_ACTIVE_STATE) {
414+
} else if (*context == PM_DEVICE_ACTIVE_STATE) {
415415
ret = loapic_resume(port);
416416
}
417417
} else if (ctrl_command == PM_DEVICE_STATE_GET) {
418-
*((uint32_t *)context) = loapic_device_power_state;
418+
*context = loapic_device_power_state;
419419
}
420420

421421
if (cb) {

drivers/pwm/pwm_nrfx.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -317,25 +317,25 @@ static int pwm_nrfx_set_power_state(uint32_t new_state,
317317

318318
static int pwm_nrfx_pm_control(const struct device *dev,
319319
uint32_t ctrl_command,
320-
void *context,
320+
uint32_t *state,
321321
uint32_t *current_state)
322322
{
323323
int err = 0;
324324

325325
if (ctrl_command == PM_DEVICE_STATE_SET) {
326-
uint32_t new_state = *((const uint32_t *)context);
326+
uint32_t new_state = *((const uint32_t *)state);
327327

328328
if (new_state != (*current_state)) {
329329
err = pwm_nrfx_set_power_state(new_state,
330330
*current_state,
331331
dev);
332332
if (!err) {
333-
(*current_state) = new_state;
333+
*current_state = new_state;
334334
}
335335
}
336336
} else {
337337
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
338-
*((uint32_t *)context) = (*current_state);
338+
*state = *current_state;
339339
}
340340

341341
return err;
@@ -344,16 +344,16 @@ static int pwm_nrfx_pm_control(const struct device *dev,
344344
#define PWM_NRFX_PM_CONTROL(idx) \
345345
static int pwm_##idx##_nrfx_pm_control(const struct device *dev, \
346346
uint32_t ctrl_command, \
347-
void *context, \
347+
uint32_t *state, \
348348
pm_device_cb cb, \
349349
void *arg) \
350350
{ \
351351
static uint32_t current_state = PM_DEVICE_ACTIVE_STATE; \
352352
int ret = 0; \
353-
ret = pwm_nrfx_pm_control(dev, ctrl_command, context, \
353+
ret = pwm_nrfx_pm_control(dev, ctrl_command, state, \
354354
&current_state); \
355355
if (cb) { \
356-
cb(dev, ret, context, arg); \
356+
cb(dev, ret, state, arg); \
357357
} \
358358
return ret; \
359359
}

drivers/sensor/lis2mdl/lis2mdl.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ static int lis2mdl_set_power_state(struct lis2mdl_data *lis2mdl,
520520
}
521521

522522
static int lis2mdl_pm_control(const struct device *dev, uint32_t ctrl_command,
523-
void *context, pm_device_cb cb, void *arg)
523+
uint32_t *state, pm_device_cb cb, void *arg)
524524
{
525525
struct lis2mdl_data *lis2mdl = dev->data;
526526
const struct lis2mdl_config *const config = dev->config;
@@ -530,22 +530,22 @@ static int lis2mdl_pm_control(const struct device *dev, uint32_t ctrl_command,
530530

531531
switch (ctrl_command) {
532532
case PM_DEVICE_STATE_SET:
533-
new_state = *((const uint32_t *)context);
533+
new_state = *state;
534534
if (new_state != current_state) {
535535
status = lis2mdl_set_power_state(lis2mdl, config,
536536
new_state);
537537
}
538538
break;
539539
case PM_DEVICE_STATE_GET:
540-
*((uint32_t *)context) = current_state;
540+
*state = current_state;
541541
break;
542542
default:
543543
LOG_ERR("Got unknown power management control command");
544544
status = -EINVAL;
545545
}
546546

547547
if (cb) {
548-
cb(dev, status, context, arg);
548+
cb(dev, status, state, arg);
549549
}
550550

551551
return status;

0 commit comments

Comments
 (0)