xref: /aosp_15_r20/external/coreboot/util/superiotool/exar.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "superiotool.h"
4 
5 #define DEVICE_ID_BYTE1_REG	0x20
6 #define DEVICE_ID_BYTE2_REG	0x21
7 
8 #define VENDOR_ID_BYTE1_REG	0x23
9 #define VENDOR_ID_BYTE2_REG	0x24
10 
11 #define EXAR_VENDOR_ID		0xa813
12 
13 static const struct superio_registers reg_table[] = {
14 	{0x8403, "XR28V384", {
15 		/* We assume reserved bits are read as 0. */
16 		{NOLDN, NULL,
17 			{0x02,0x07,0x20,0x21,0x23,0x24,0x25,0x26,0x27,EOT},
18 			{0x00,0x00,0x03,0x84,0x13,0xa8,0x00,0x00,0x00,EOT}},
19 		{0x0, "COM1",
20 			{0x30,0x60,0x61,0x70,0xf0,0xf1,0xf4,0xf5,0xf6,EOT},
21 			{0x01,0x03,0xf8,0x03,0x00,0x44,0x00,0x00,0x00,EOT}},
22 		{0x1, "COM2",
23 			{0x30,0x60,0x61,0x70,0xf0,0xf4,0xf5,0xf6,EOT},
24 			{0x01,0x02,0xf8,0x04,0x00,0x00,0x00,0x00,EOT}},
25 		{0x2, "COM3",
26 			{0x30,0x60,0x61,0x70,0xf0,0xf4,0xf5,0xf6,EOT},
27 			{0x01,0x03,0xe8,0x05,0x00,0x00,0x00,0x00,EOT}},
28 		{0x3, "COM4",
29 			{0x30,0x60,0x61,0x70,0xf0,0xf4,0xf5,0xf6,EOT},
30 			{0x01,0x02,0xe8,0x09,0x00,0x00,0x00,0x00,EOT}},
31 		{0x8, "WDT",
32 			{0x30,0x60,0x61,0x70,0xf0,0xf1,EOT},
33 			{0x01,0x04,0x42,0x00,0x02,0x0a,EOT}},
34 		{EOT}}},
35 	{EOT}
36 };
37 
enter_conf_mode_exar(uint16_t port)38 void enter_conf_mode_exar(uint16_t port)
39 {
40 	OUTB(0x67, port);
41 	OUTB(0x67, port);
42 }
43 
exit_conf_mode_exar(uint16_t port)44 void exit_conf_mode_exar(uint16_t port)
45 {
46 	OUTB(0xaa, port);
47 }
48 
probe_idregs_exar(uint16_t port)49 void probe_idregs_exar(uint16_t port)
50 {
51 	uint16_t vid, did;
52 
53 	probing_for("Exar", "", port);
54 
55 	enter_conf_mode_exar(port);
56 
57 	did = regval(port, DEVICE_ID_BYTE1_REG);
58 	did |= (regval(port, DEVICE_ID_BYTE2_REG) << 8);
59 
60 	vid = regval(port, VENDOR_ID_BYTE1_REG);
61 	vid |= (regval(port, VENDOR_ID_BYTE2_REG) << 8);
62 
63 	if (vid != EXAR_VENDOR_ID || superio_unknown(reg_table, did)) {
64 		if (verbose)
65 			printf(NOTFOUND "vid=0x%04x, id=0x%04x\n", vid, did);
66 		exit_conf_mode_exar(port);
67 		return;
68 	}
69 
70 	printf("Found Exar %s (vid=0x%04x, id=0x%04x) at 0x%x\n",
71 		get_superio_name(reg_table, did), vid, did, port);
72 	chip_found = 1;
73 
74 	dump_superio("Exar", reg_table, port, did, LDN_SEL);
75 
76 	exit_conf_mode_exar(port);
77 }
78 
print_exar_chips(void)79 void print_exar_chips(void)
80 {
81 	print_vendor_chips("Exar", reg_table);
82 }
83