Skip to content

Commit a5a57c2

Browse files
committed
pmgr: Add pmgr_adt_reset()
This isn't actually useful for NVMe, but let's keep it... Signed-off-by: Hector Martin <[email protected]>
1 parent c6e9565 commit a5a57c2

2 files changed

Lines changed: 50 additions & 18 deletions

File tree

src/pmgr.c

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -206,44 +206,75 @@ int pmgr_adt_power_disable(const char *path)
206206
return pmgr_adt_devices_set_mode(path, PMGR_PS_PWRGATE, false);
207207
}
208208

209-
int pmgr_reset(int die, const char *name)
209+
static int pmgr_reset_device(int die, const struct pmgr_device *dev)
210210
{
211-
const struct pmgr_device *dev = NULL;
212-
213-
for (unsigned int i = 0; i < pmgr_devices_len; ++i) {
214-
if (strncmp(pmgr_devices[i].name, name, 0x10) == 0) {
215-
dev = &pmgr_devices[i];
216-
break;
217-
}
218-
}
219-
220-
if (!dev) {
221-
printf("pmgr: unable to find device %s\n", name);
222-
return -1;
223-
}
224-
225211
if (die < 0 || die > 16) {
226-
printf("pmgr: invalid die id %d for devicece %s\n", die, name);
212+
printf("pmgr: invalid die id %d for device %s\n", die, dev->name);
227213
return -1;
228214
}
229215

230216
uintptr_t addr = pmgr_device_get_addr(die, dev);
231217

232218
u32 reg = read32(addr);
233219
if (FIELD_GET(PMGR_PS_ACTUAL, reg) != PMGR_PS_ACTIVE) {
234-
printf("pmgr: will not reset disabled device %s\n", name);
220+
printf("pmgr: will not reset disabled device %d.%s\n", die, dev->name);
235221
return -1;
236222
}
237223

224+
printf("pmgr: resetting device %d.%s\n", die, dev->name);
225+
238226
set32(addr, PMGR_DEV_DISABLE);
239227
set32(addr, PMGR_RESET);
240-
udelay(1);
228+
udelay(10);
241229
clear32(addr, PMGR_RESET);
242230
clear32(addr, PMGR_DEV_DISABLE);
243231

244232
return 0;
245233
}
246234

235+
int pmgr_adt_reset(const char *path)
236+
{
237+
const u32 *devices;
238+
u32 n_devices;
239+
int ret = 0;
240+
241+
if (pmgr_adt_find_devices(path, &devices, &n_devices) < 0)
242+
return -1;
243+
244+
for (u32 i = 0; i < n_devices; ++i) {
245+
const struct pmgr_device *device;
246+
u16 id = FIELD_GET(PMGR_DEVICE_ID, devices[i]);
247+
u8 die = FIELD_GET(PMGR_DIE_ID, devices[i]);
248+
249+
if (pmgr_find_device(id, &device)) {
250+
ret = -1;
251+
continue;
252+
}
253+
254+
if (pmgr_reset_device(die, device))
255+
ret = -1;
256+
}
257+
258+
return ret;
259+
}
260+
261+
int pmgr_reset(int die, const char *name)
262+
{
263+
const struct pmgr_device *dev = NULL;
264+
265+
for (unsigned int i = 0; i < pmgr_devices_len; ++i) {
266+
if (strncmp(pmgr_devices[i].name, name, 0x10) == 0) {
267+
dev = &pmgr_devices[i];
268+
break;
269+
}
270+
}
271+
272+
if (!dev)
273+
return -1;
274+
275+
return pmgr_reset_device(die, dev);
276+
}
277+
247278
int pmgr_init(void)
248279
{
249280
int node = adt_path_offset(adt, "/arm-io");

src/pmgr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ int pmgr_power_disable(u32 id);
1717

1818
int pmgr_adt_power_enable(const char *path);
1919
int pmgr_adt_power_disable(const char *path);
20+
int pmgr_adt_reset(const char *path);
2021

2122
int pmgr_reset(int die, const char *name);
2223

0 commit comments

Comments
 (0)