blob: 6f2cbcdb702b06e7843b1bb674ec84b56dd8b412 [file] [log] [blame]
Frans Hendriks2e1fea42018-11-26 10:33:00 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008 Corey Osgood <corey.osgood@gmail.com>
5 * Copyright (C) 2018 Eltan B.V.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
Frans Hendriks2e1fea42018-11-26 10:33:00 +010018#include <device/device.h>
19#include <device/pnp.h>
20#include <superio/conf_mode.h>
Frans Hendriks2e1fea42018-11-26 10:33:00 +010021#include <pc80/keyboard.h>
Christian Waltera8a9fb02019-06-06 15:09:49 +020022#include <superio/common/ssdt.h>
23#include <arch/acpi.h>
Frans Hendriks2e1fea42018-11-26 10:33:00 +010024#include "ast2400.h"
Patrick Rudolpha4e93952019-12-10 14:53:00 +010025#include "chip.h"
Frans Hendriks2e1fea42018-11-26 10:33:00 +010026
27static void ast2400_init(struct device *dev)
28{
Patrick Rudolpha4e93952019-12-10 14:53:00 +010029 struct superio_aspeed_ast2400_config *conf = dev->chip_info;
30
Frans Hendriks2e1fea42018-11-26 10:33:00 +010031 if (!dev->enabled)
32 return;
33
Patrick Rudolpha4e93952019-12-10 14:53:00 +010034 if (conf && conf->use_espi) {
35 pnp_enter_conf_mode(dev);
36 pnp_set_logical_device(dev);
37 /* In ESPI mode must write 0 to IRQ level on every LDN */
Christian Walterda609582020-01-25 13:42:53 +010038 pnp_write_config(dev, 0x71, 0);
Patrick Rudolpha4e93952019-12-10 14:53:00 +010039 pnp_exit_conf_mode(dev);
40 }
41
Frans Hendriks2e1fea42018-11-26 10:33:00 +010042 switch (dev->path.pnp.device) {
43 case AST2400_KBC:
44 pc_keyboard_init(NO_AUX_DEVICE);
45 break;
46 }
47}
48
Christian Waltera8a9fb02019-06-06 15:09:49 +020049#if CONFIG(HAVE_ACPI_TABLES)
50/* Provide ACPI HIDs for generic Super I/O SSDT */
51static const char *ast2400_acpi_hid(const struct device *dev)
52{
53 /* Sanity checks */
54 if (dev->path.type != DEVICE_PATH_PNP)
55 return NULL;
56 if (dev->path.pnp.port == 0)
57 return NULL;
58 if ((dev->path.pnp.device & 0xff) > AST2400_MAILBOX)
59 return NULL;
60
61 switch (dev->path.pnp.device & 0xff) {
Elyes HAOUAS9a669b12019-12-05 09:14:30 +010062 case AST2400_SUART1: /* fallthrough */
63 case AST2400_SUART2: /* fallthrough */
64 case AST2400_SUART3: /* fallthrough */
Christian Waltera8a9fb02019-06-06 15:09:49 +020065 case AST2400_SUART4:
66 return ACPI_HID_COM;
67 case AST2400_KBC:
68 return ACPI_HID_KEYBOARD;
69 default:
70 return ACPI_HID_PNP;
71 }
72}
73#endif
74
Frans Hendriks2e1fea42018-11-26 10:33:00 +010075static struct device_operations ops = {
76 .read_resources = pnp_read_resources,
77 .set_resources = pnp_set_resources,
78 .enable_resources = pnp_enable_resources,
79 .enable = pnp_enable,
80 .init = ast2400_init,
81 .ops_pnp_mode = &pnp_conf_mode_a5a5_aa,
Christian Waltera8a9fb02019-06-06 15:09:49 +020082#if CONFIG(HAVE_ACPI_TABLES)
83 .acpi_fill_ssdt_generator = superio_common_fill_ssdt_generator,
84 .acpi_name = superio_common_ldn_acpi_name,
85 .acpi_hid = ast2400_acpi_hid,
86#endif
Frans Hendriks2e1fea42018-11-26 10:33:00 +010087};
88
89static struct pnp_info pnp_dev_info[] = {
90 { NULL, AST2400_SUART1, PNP_IO0 | PNP_IRQ0 | PNP_MSC0, 0xfff8, },
91 { NULL, AST2400_SUART2, PNP_IO0 | PNP_IRQ0 | PNP_MSC0, 0xfff8, },
92 { NULL, AST2400_SWAK, PNP_IO0 | PNP_IO1 | PNP_IO2 | PNP_IO3
93 | PNP_IRQ0, 0xfff8, 0xfff8, 0xfff8, 0xfff8, },
94 { NULL, AST2400_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1
95 | PNP_MSC0, 0xffff, 0xffff, },
96 { NULL, AST2400_GPIO, PNP_IRQ0, }, // GPIO LDN has no IO Region
97 { NULL, AST2400_SUART3, PNP_IO0 | PNP_IRQ0 | PNP_MSC0, 0xfff8, },
98 { NULL, AST2400_SUART4, PNP_IO0 | PNP_IRQ0 | PNP_MSC0, 0xfff8, },
99 { NULL, AST2400_ILPC2AHB, PNP_IRQ0 | PNP_MSC0 | PNP_MSC1 | PNP_MSC2
100 | PNP_MSC3 | PNP_MSC4 | PNP_MSC5 | PNP_MSC6 | PNP_MSC7
101 | PNP_MSC8 | PNP_MSC9 | PNP_MSCA | PNP_MSCB | PNP_MSCC
102 | PNP_MSCD | PNP_MSCE, },
103 { NULL, AST2400_MAILBOX, PNP_IO0 | PNP_IRQ0, 0xfffe, },
104};
105
106static void enable_dev(struct device *dev)
107{
Patrick Rudolpha4e93952019-12-10 14:53:00 +0100108 struct superio_aspeed_ast2400_config *conf = dev->chip_info;
109
110 if (conf && conf->use_espi) {
111 /* UART3 and UART4 are not usable in ESPI mode */
112 for (size_t i = 0; i < ARRAY_SIZE(pnp_dev_info); i++) {
113 if ((pnp_dev_info[i].function == AST2400_SUART3) ||
114 (pnp_dev_info[i].function == AST2400_SUART4))
115 pnp_dev_info[i].function = PNP_SKIP_FUNCTION;
116 }
117 }
118
Frans Hendriks2e1fea42018-11-26 10:33:00 +0100119 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info),
120 pnp_dev_info);
121}
122
123struct chip_operations superio_aspeed_ast2400_ops = {
Patrick Rudolpha4e93952019-12-10 14:53:00 +0100124 CHIP_NAME("ASpeed AST2400/AST2500 Super I/O")
Frans Hendriks2e1fea42018-11-26 10:33:00 +0100125 .enable_dev = enable_dev,
126};