Skip to content

Commit 0428d4b

Browse files
committed
drivers: shell: ldsw: remove unexpected enablement of LDSW
On mode change first check the current state of the LDSW instance. Disable and re-enable it only if it was already previously enabled. Signed-off-by: Sergei Ovchinnikov <sergei.ovchinnikov@nordicsemi.no>
1 parent f17eac5 commit 0428d4b

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

drivers/npmx/shell/ldsw.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ static int cmd_ldsw_mode_set(const struct shell *shell, size_t argc, char **argv
319319
return 0;
320320
}
321321

322-
npmx_ldsw_t *ldsw_instance = ldsw_instance_get(shell, args_info.arg[0].result.uvalue);
322+
uint8_t ldsw_idx = (uint8_t)args_info.arg[0].result.uvalue;
323+
npmx_ldsw_t *ldsw_instance = ldsw_instance_get(shell, ldsw_idx);
323324
if (ldsw_instance == NULL) {
324325
return 0;
325326
}
@@ -356,16 +357,32 @@ static int cmd_ldsw_mode_set(const struct shell *shell, size_t argc, char **argv
356357
}
357358

358359
/* LDSW reset is required to apply mode change. */
359-
err_code = npmx_ldsw_task_trigger(ldsw_instance, NPMX_LDSW_TASK_DISABLE);
360+
/* Check the current status first */
361+
uint8_t status_mask;
362+
err_code = npmx_ldsw_status_get(ldsw_instance, &status_mask);
360363
if (!check_error_code(shell, err_code)) {
361-
shell_error(shell, "Error: reset error while disabling LDSW to change mode.");
364+
shell_error(shell, "Error: failed to get LDSW status");
362365
return 0;
363366
}
364367

365-
err_code = npmx_ldsw_task_trigger(ldsw_instance, NPMX_LDSW_TASK_ENABLE);
366-
if (!check_error_code(shell, err_code)) {
367-
shell_error(shell, "Error: reset error while enabling LDSW to change mode.");
368-
return 0;
368+
uint8_t check_mask = ldsw_idx == 0 ? (NPMX_LDSW_STATUS_POWERUP_LDSW_1_MASK |
369+
NPMX_LDSW_STATUS_POWERUP_LDO_1_MASK) :
370+
(NPMX_LDSW_STATUS_POWERUP_LDSW_2_MASK |
371+
NPMX_LDSW_STATUS_POWERUP_LDO_2_MASK);
372+
373+
if (status_mask & check_mask) {
374+
/* Enabled - need to reset */
375+
err_code = npmx_ldsw_task_trigger(ldsw_instance, NPMX_LDSW_TASK_DISABLE);
376+
if (!check_error_code(shell, err_code)) {
377+
shell_error(shell, "Error: reset error while disabling LDSW to change mode.");
378+
return 0;
379+
}
380+
381+
err_code = npmx_ldsw_task_trigger(ldsw_instance, NPMX_LDSW_TASK_ENABLE);
382+
if (!check_error_code(shell, err_code)) {
383+
shell_error(shell, "Error: reset error while enabling LDSW to change mode.");
384+
return 0;
385+
}
369386
}
370387

371388
print_success(shell, mode, UNIT_TYPE_NONE);

0 commit comments

Comments
 (0)