summaryrefslogtreecommitdiff
path: root/drivers/power/reset/htif-poweroff.c
blob: 106bc44daa210714fd4d1e21d26915f4e2bb17ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2021 Ahmad Fatoum, Pengutronix
 */

#include <common.h>
#include <driver.h>
#include <poweroff.h>
#include <asm/htif.h>

static void __iomem *htif = IOMEM(HTIF_DEFAULT_BASE_ADDR);

static void __noreturn riscvemu_poweroff(struct poweroff_handler *pwr)
{
	shutdown_barebox();

	__htif_tohost(htif, HTIF_DEV_SYSCALL, 0, 1);

	__builtin_unreachable();
}

static int htif_poweroff_probe(struct device *dev)
{
	struct resource *iores;

	iores = dev_request_mem_resource(dev, 0);
	if (!IS_ERR(iores))
		htif = IOMEM(iores->start);
	else if (PTR_ERR(iores) != -ENOENT)
		return PTR_ERR(iores);

	return poweroff_handler_register_fn(riscvemu_poweroff);
}


static const struct of_device_id htif_poweroff_of_match[] = {
	{ .compatible = "ucb,htif0" },
	{}
};

static struct driver_d htif_poweroff_driver = {
	.name = "htif-poweroff",
	.of_compatible = htif_poweroff_of_match,
	.probe = htif_poweroff_probe,
};
coredevice_platform_driver(htif_poweroff_driver);