1 // SPDX-License-Identifier: GPL-2.0+
3 * Power Domain test commands
5 * Copyright (C) 2020 Texas Instruments Incorporated, <www.ti.com>
12 static const struct udevice_id ti_pd_of_match[] = {
13 { .compatible = "ti,sci-pm-domain" },
17 static struct ti_k3_pd_platdata *ti_pd_find_data(void)
23 uclass_get_device(UCLASS_POWER_DOMAIN, i++, &dev);
27 if (device_is_compatible(dev,
28 ti_pd_of_match[0].compatible))
29 return dev_get_priv(dev);
35 static void dump_lpsc(struct ti_k3_pd_platdata *data, struct ti_pd *pd)
40 static const char * const lpsc_states[] = {
41 "swrstdis", "syncrst", "disable", "enable", "autosleep",
42 "autowake", "unknown",
45 for (i = 0; i < data->num_lpsc; i++) {
46 lpsc = &data->lpsc[i];
49 state = lpsc_get_state(lpsc);
50 if (state > ARRAY_SIZE(lpsc_states))
51 state = ARRAY_SIZE(lpsc_states) - 1;
52 printf(" LPSC%d: state=%s, usecount=%d\n",
53 lpsc->id, lpsc_states[state], lpsc->usecount);
57 static void dump_pd(struct ti_k3_pd_platdata *data, struct ti_psc *psc)
62 static const char * const pd_states[] = {
63 "off", "on", "unknown"
66 for (i = 0; i < data->num_pd; i++) {
70 state = ti_pd_state(pd);
71 if (state > ARRAY_SIZE(pd_states))
72 state = ARRAY_SIZE(pd_states) - 1;
73 printf(" PD%d: state=%s, usecount=%d:\n",
74 pd->id, pd_states[state], pd->usecount);
79 static void dump_psc(struct ti_k3_pd_platdata *data)
84 for (i = 0; i < data->num_psc; i++) {
86 printf("PSC%d [%p]:\n", psc->id, psc->base);
91 static int do_pd_dump(struct cmd_tbl *cmdtp, int flag, int argc,
94 struct ti_k3_pd_platdata *data;
96 data = ti_pd_find_data();
98 return CMD_RET_FAILURE;
105 static int do_pd_endis(int argc, char *const argv[], u8 state)
110 struct ti_k3_pd_platdata *data;
111 struct ti_lpsc *lpsc;
115 return CMD_RET_FAILURE;
117 data = ti_pd_find_data();
119 return CMD_RET_FAILURE;
121 psc_id = dectoul(argv[1], NULL);
122 lpsc_id = dectoul(argv[2], NULL);
124 for (i = 0; i < data->num_lpsc; i++) {
125 lpsc = &data->lpsc[i];
126 if (lpsc->pd->psc->id != psc_id)
128 if (lpsc->id != lpsc_id)
130 printf("%s pd [PSC:%d,LPSC:%d]...\n",
131 state == MDSTAT_STATE_ENABLE ? "Enabling" : "Disabling",
133 ret = ti_lpsc_transition(lpsc, state);
135 return CMD_RET_FAILURE;
140 printf("No matching psc/lpsc found.\n");
142 return CMD_RET_FAILURE;
145 static int do_pd_enable(struct cmd_tbl *cmdtp, int flag, int argc,
148 return do_pd_endis(argc, argv, MDSTAT_STATE_ENABLE);
151 static int do_pd_disable(struct cmd_tbl *cmdtp, int flag, int argc,
154 return do_pd_endis(argc, argv, MDSTAT_STATE_SWRSTDISABLE);
157 static struct cmd_tbl cmd_pd[] = {
158 U_BOOT_CMD_MKENT(dump, 1, 0, do_pd_dump, "", ""),
159 U_BOOT_CMD_MKENT(enable, 3, 0, do_pd_enable, "", ""),
160 U_BOOT_CMD_MKENT(disable, 3, 0, do_pd_disable, "", ""),
163 static int ti_do_pd(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
170 c = find_cmd_tbl(argv[0], cmd_pd, ARRAY_SIZE(cmd_pd));
172 return c->cmd(cmdtp, flag, argc, argv);
174 return CMD_RET_USAGE;
178 "dump - show power domain status\n"
179 "enable [psc] [lpsc] - enable power domain\n"
180 "disable [psc] [lpsc] - disable power domain\n");
182 U_BOOT_CMD(pd, 4, 1, ti_do_pd,
183 "TI power domain control", pd_help_text