1 // SPDX-License-Identifier: GPL-2.0+
3 * Power Domain test commands
5 * Copyright (C) 2020 Texas Instruments Incorporated, <www.ti.com>
13 static const struct udevice_id ti_pd_of_match[] = {
14 { .compatible = "ti,sci-pm-domain" },
18 static struct ti_k3_pd_platdata *ti_pd_find_data(void)
24 uclass_get_device(UCLASS_POWER_DOMAIN, i++, &dev);
28 if (device_is_compatible(dev,
29 ti_pd_of_match[0].compatible))
30 return dev_get_priv(dev);
36 static void dump_lpsc(struct ti_k3_pd_platdata *data, struct ti_pd *pd)
41 static const char * const lpsc_states[] = {
42 "swrstdis", "syncrst", "disable", "enable", "autosleep",
43 "autowake", "unknown",
46 for (i = 0; i < data->num_lpsc; i++) {
47 lpsc = &data->lpsc[i];
50 state = lpsc_get_state(lpsc);
51 if (state > ARRAY_SIZE(lpsc_states))
52 state = ARRAY_SIZE(lpsc_states) - 1;
53 printf(" LPSC%d: state=%s, usecount=%d\n",
54 lpsc->id, lpsc_states[state], lpsc->usecount);
58 static void dump_pd(struct ti_k3_pd_platdata *data, struct ti_psc *psc)
63 static const char * const pd_states[] = {
64 "off", "on", "unknown"
67 for (i = 0; i < data->num_pd; i++) {
71 state = ti_pd_state(pd);
72 if (state > ARRAY_SIZE(pd_states))
73 state = ARRAY_SIZE(pd_states) - 1;
74 printf(" PD%d: state=%s, usecount=%d:\n",
75 pd->id, pd_states[state], pd->usecount);
80 static void dump_psc(struct ti_k3_pd_platdata *data)
85 for (i = 0; i < data->num_psc; i++) {
87 printf("PSC%d [%p]:\n", psc->id, psc->base);
92 static int do_pd_dump(struct cmd_tbl *cmdtp, int flag, int argc,
95 struct ti_k3_pd_platdata *data;
97 data = ti_pd_find_data();
99 return CMD_RET_FAILURE;
106 static int do_pd_endis(int argc, char *const argv[], u8 state)
111 struct ti_k3_pd_platdata *data;
112 struct ti_lpsc *lpsc;
116 return CMD_RET_FAILURE;
118 data = ti_pd_find_data();
120 return CMD_RET_FAILURE;
122 psc_id = dectoul(argv[1], NULL);
123 lpsc_id = dectoul(argv[2], NULL);
125 for (i = 0; i < data->num_lpsc; i++) {
126 lpsc = &data->lpsc[i];
127 if (lpsc->pd->psc->id != psc_id)
129 if (lpsc->id != lpsc_id)
131 printf("%s pd [PSC:%d,LPSC:%d]...\n",
132 state == MDSTAT_STATE_ENABLE ? "Enabling" : "Disabling",
134 ret = ti_lpsc_transition(lpsc, state);
136 return CMD_RET_FAILURE;
141 printf("No matching psc/lpsc found.\n");
143 return CMD_RET_FAILURE;
146 static int do_pd_enable(struct cmd_tbl *cmdtp, int flag, int argc,
149 return do_pd_endis(argc, argv, MDSTAT_STATE_ENABLE);
152 static int do_pd_disable(struct cmd_tbl *cmdtp, int flag, int argc,
155 return do_pd_endis(argc, argv, MDSTAT_STATE_SWRSTDISABLE);
158 static struct cmd_tbl cmd_pd[] = {
159 U_BOOT_CMD_MKENT(dump, 1, 0, do_pd_dump, "", ""),
160 U_BOOT_CMD_MKENT(enable, 3, 0, do_pd_enable, "", ""),
161 U_BOOT_CMD_MKENT(disable, 3, 0, do_pd_disable, "", ""),
164 static int ti_do_pd(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
171 c = find_cmd_tbl(argv[0], cmd_pd, ARRAY_SIZE(cmd_pd));
173 return c->cmd(cmdtp, flag, argc, argv);
175 return CMD_RET_USAGE;
178 U_BOOT_CMD(pd, 4, 1, ti_do_pd,
179 "TI power domain control",
180 #if CONFIG_IS_ENABLED(SYS_LONGHELP)
181 "dump - show power domain status\n"
182 "enable [psc] [lpsc] - enable power domain\n"
183 "disable [psc] [lpsc] - disable power domain\n"