blob: 0941663e2b89b67921c7d04c5dae905e1801ff98 [file] [log] [blame]
Felix Held3f3eca92020-01-23 17:12:32 +01001/* SPDX-License-Identifier: GPL-2.0-or-later */
2/* This file is part of the coreboot project. */
Frans Hendriks2e1fea42018-11-26 10:33:00 +01003
Frans Hendriks2e1fea42018-11-26 10:33:00 +01004#include <device/device.h>
5#include <device/pnp.h>
6#include <superio/conf_mode.h>
Frans Hendriks2e1fea42018-11-26 10:33:00 +01007#include <pc80/keyboard.h>
Christian Waltera8a9fb02019-06-06 15:09:49 +02008#include <superio/common/ssdt.h>
9#include <arch/acpi.h>
Frans Hendriks2e1fea42018-11-26 10:33:00 +010010#include "ast2400.h"
Patrick Rudolpha4e93952019-12-10 14:53:00 +010011#include "chip.h"
Frans Hendriks2e1fea42018-11-26 10:33:00 +010012
13static void ast2400_init(struct device *dev)
14{
Patrick Rudolpha4e93952019-12-10 14:53:00 +010015 struct superio_aspeed_ast2400_config *conf = dev->chip_info;
16
Frans Hendriks2e1fea42018-11-26 10:33:00 +010017 if (!dev->enabled)
18 return;
19
Patrick Rudolpha4e93952019-12-10 14:53:00 +010020 if (conf && conf->use_espi) {
21 pnp_enter_conf_mode(dev);
22 pnp_set_logical_device(dev);
23 /* In ESPI mode must write 0 to IRQ level on every LDN */
Christian Walterda609582020-01-25 13:42:53 +010024 pnp_write_config(dev, 0x71, 0);
Patrick Rudolpha4e93952019-12-10 14:53:00 +010025 pnp_exit_conf_mode(dev);
26 }
27
Frans Hendriks2e1fea42018-11-26 10:33:00 +010028 switch (dev->path.pnp.device) {
29 case AST2400_KBC:
30 pc_keyboard_init(NO_AUX_DEVICE);
31 break;
32 }
33}
34
Christian Waltera8a9fb02019-06-06 15:09:49 +020035#if CONFIG(HAVE_ACPI_TABLES)
36/* Provide ACPI HIDs for generic Super I/O SSDT */
37static const char *ast2400_acpi_hid(const struct device *dev)
38{
39 /* Sanity checks */
40 if (dev->path.type != DEVICE_PATH_PNP)
41 return NULL;
42 if (dev->path.pnp.port == 0)
43 return NULL;
44 if ((dev->path.pnp.device & 0xff) > AST2400_MAILBOX)
45 return NULL;
46
47 switch (dev->path.pnp.device & 0xff) {
Elyes HAOUAS9a669b12019-12-05 09:14:30 +010048 case AST2400_SUART1: /* fallthrough */
49 case AST2400_SUART2: /* fallthrough */
50 case AST2400_SUART3: /* fallthrough */
Christian Waltera8a9fb02019-06-06 15:09:49 +020051 case AST2400_SUART4:
52 return ACPI_HID_COM;
53 case AST2400_KBC:
54 return ACPI_HID_KEYBOARD;
55 default:
56 return ACPI_HID_PNP;
57 }
58}
59#endif
60
Frans Hendriks2e1fea42018-11-26 10:33:00 +010061static struct device_operations ops = {
62 .read_resources = pnp_read_resources,
63 .set_resources = pnp_set_resources,
64 .enable_resources = pnp_enable_resources,
65 .enable = pnp_enable,
66 .init = ast2400_init,
67 .ops_pnp_mode = &pnp_conf_mode_a5a5_aa,
Christian Waltera8a9fb02019-06-06 15:09:49 +020068#if CONFIG(HAVE_ACPI_TABLES)
69 .acpi_fill_ssdt_generator = superio_common_fill_ssdt_generator,
70 .acpi_name = superio_common_ldn_acpi_name,
71 .acpi_hid = ast2400_acpi_hid,
72#endif
Frans Hendriks2e1fea42018-11-26 10:33:00 +010073};
74
75static struct pnp_info pnp_dev_info[] = {
76 { NULL, AST2400_SUART1, PNP_IO0 | PNP_IRQ0 | PNP_MSC0, 0xfff8, },
77 { NULL, AST2400_SUART2, PNP_IO0 | PNP_IRQ0 | PNP_MSC0, 0xfff8, },
78 { NULL, AST2400_SWAK, PNP_IO0 | PNP_IO1 | PNP_IO2 | PNP_IO3
79 | PNP_IRQ0, 0xfff8, 0xfff8, 0xfff8, 0xfff8, },
80 { NULL, AST2400_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1
81 | PNP_MSC0, 0xffff, 0xffff, },
82 { NULL, AST2400_GPIO, PNP_IRQ0, }, // GPIO LDN has no IO Region
83 { NULL, AST2400_SUART3, PNP_IO0 | PNP_IRQ0 | PNP_MSC0, 0xfff8, },
84 { NULL, AST2400_SUART4, PNP_IO0 | PNP_IRQ0 | PNP_MSC0, 0xfff8, },
85 { NULL, AST2400_ILPC2AHB, PNP_IRQ0 | PNP_MSC0 | PNP_MSC1 | PNP_MSC2
86 | PNP_MSC3 | PNP_MSC4 | PNP_MSC5 | PNP_MSC6 | PNP_MSC7
87 | PNP_MSC8 | PNP_MSC9 | PNP_MSCA | PNP_MSCB | PNP_MSCC
88 | PNP_MSCD | PNP_MSCE, },
89 { NULL, AST2400_MAILBOX, PNP_IO0 | PNP_IRQ0, 0xfffe, },
90};
91
92static void enable_dev(struct device *dev)
93{
Patrick Rudolpha4e93952019-12-10 14:53:00 +010094 struct superio_aspeed_ast2400_config *conf = dev->chip_info;
95
96 if (conf && conf->use_espi) {
97 /* UART3 and UART4 are not usable in ESPI mode */
98 for (size_t i = 0; i < ARRAY_SIZE(pnp_dev_info); i++) {
99 if ((pnp_dev_info[i].function == AST2400_SUART3) ||
100 (pnp_dev_info[i].function == AST2400_SUART4))
101 pnp_dev_info[i].function = PNP_SKIP_FUNCTION;
102 }
103 }
104
Frans Hendriks2e1fea42018-11-26 10:33:00 +0100105 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info),
106 pnp_dev_info);
107}
108
109struct chip_operations superio_aspeed_ast2400_ops = {
Patrick Rudolpha4e93952019-12-10 14:53:00 +0100110 CHIP_NAME("ASpeed AST2400/AST2500 Super I/O")
Frans Hendriks2e1fea42018-11-26 10:33:00 +0100111 .enable_dev = enable_dev,
112};