1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
4  *
5  * Generic reset driver for x86 processor
6  */
7 
8 #include <common.h>
9 #include <dm.h>
10 #include <sysreset.h>
11 #include <asm/io.h>
12 #include <asm/processor.h>
13 
14 static int x86_sysreset_request(struct udevice *dev, enum sysreset_t type)
15 {
16 	int value;
17 
18 	switch (type) {
19 	case SYSRESET_WARM:
20 		value = SYS_RST | RST_CPU;
21 		break;
22 	case SYSRESET_COLD:
23 		value = SYS_RST | RST_CPU | FULL_RST;
24 		break;
25 	default:
26 		return -ENOSYS;
27 	}
28 
29 	outb(value, IO_PORT_RESET);
30 
31 	return -EINPROGRESS;
32 }
33 
34 static const struct udevice_id x86_sysreset_ids[] = {
35 	{ .compatible = "x86,reset" },
36 	{ }
37 };
38 
39 static struct sysreset_ops x86_sysreset_ops = {
40 	.request = x86_sysreset_request,
41 };
42 
43 U_BOOT_DRIVER(x86_sysreset) = {
44 	.name = "x86-sysreset",
45 	.id = UCLASS_SYSRESET,
46 	.of_match = x86_sysreset_ids,
47 	.ops = &x86_sysreset_ops,
48 	.flags = DM_FLAG_PRE_RELOC,
49 };
50