Frans Hendriks | 2e1fea4 | 2018-11-26 10:33:00 +0100 | [diff] [blame] | 1 | /* |
| 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 Hendriks | 2e1fea4 | 2018-11-26 10:33:00 +0100 | [diff] [blame] | 18 | #include <device/device.h> |
| 19 | #include <device/pnp.h> |
| 20 | #include <superio/conf_mode.h> |
Frans Hendriks | 2e1fea4 | 2018-11-26 10:33:00 +0100 | [diff] [blame] | 21 | #include <pc80/keyboard.h> |
Christian Walter | a8a9fb0 | 2019-06-06 15:09:49 +0200 | [diff] [blame] | 22 | #include <superio/common/ssdt.h> |
| 23 | #include <arch/acpi.h> |
Frans Hendriks | 2e1fea4 | 2018-11-26 10:33:00 +0100 | [diff] [blame] | 24 | #include "ast2400.h" |
Patrick Rudolph | a4e9395 | 2019-12-10 14:53:00 +0100 | [diff] [blame] | 25 | #include "chip.h" |
Frans Hendriks | 2e1fea4 | 2018-11-26 10:33:00 +0100 | [diff] [blame] | 26 | |
| 27 | static void ast2400_init(struct device *dev) |
| 28 | { |
Patrick Rudolph | a4e9395 | 2019-12-10 14:53:00 +0100 | [diff] [blame] | 29 | struct superio_aspeed_ast2400_config *conf = dev->chip_info; |
| 30 | |
Frans Hendriks | 2e1fea4 | 2018-11-26 10:33:00 +0100 | [diff] [blame] | 31 | if (!dev->enabled) |
| 32 | return; |
| 33 | |
Patrick Rudolph | a4e9395 | 2019-12-10 14:53:00 +0100 | [diff] [blame] | 34 | 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 Walter | da60958 | 2020-01-25 13:42:53 +0100 | [diff] [blame] | 38 | pnp_write_config(dev, 0x71, 0); |
Patrick Rudolph | a4e9395 | 2019-12-10 14:53:00 +0100 | [diff] [blame] | 39 | pnp_exit_conf_mode(dev); |
| 40 | } |
| 41 | |
Frans Hendriks | 2e1fea4 | 2018-11-26 10:33:00 +0100 | [diff] [blame] | 42 | switch (dev->path.pnp.device) { |
| 43 | case AST2400_KBC: |
| 44 | pc_keyboard_init(NO_AUX_DEVICE); |
| 45 | break; |
| 46 | } |
| 47 | } |
| 48 | |
Christian Walter | a8a9fb0 | 2019-06-06 15:09:49 +0200 | [diff] [blame] | 49 | #if CONFIG(HAVE_ACPI_TABLES) |
| 50 | /* Provide ACPI HIDs for generic Super I/O SSDT */ |
| 51 | static 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 HAOUAS | 9a669b1 | 2019-12-05 09:14:30 +0100 | [diff] [blame] | 62 | case AST2400_SUART1: /* fallthrough */ |
| 63 | case AST2400_SUART2: /* fallthrough */ |
| 64 | case AST2400_SUART3: /* fallthrough */ |
Christian Walter | a8a9fb0 | 2019-06-06 15:09:49 +0200 | [diff] [blame] | 65 | 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 Hendriks | 2e1fea4 | 2018-11-26 10:33:00 +0100 | [diff] [blame] | 75 | static 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 Walter | a8a9fb0 | 2019-06-06 15:09:49 +0200 | [diff] [blame] | 82 | #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 Hendriks | 2e1fea4 | 2018-11-26 10:33:00 +0100 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | static 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 | |
| 106 | static void enable_dev(struct device *dev) |
| 107 | { |
Patrick Rudolph | a4e9395 | 2019-12-10 14:53:00 +0100 | [diff] [blame] | 108 | 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 Hendriks | 2e1fea4 | 2018-11-26 10:33:00 +0100 | [diff] [blame] | 119 | pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), |
| 120 | pnp_dev_info); |
| 121 | } |
| 122 | |
| 123 | struct chip_operations superio_aspeed_ast2400_ops = { |
Patrick Rudolph | a4e9395 | 2019-12-10 14:53:00 +0100 | [diff] [blame] | 124 | CHIP_NAME("ASpeed AST2400/AST2500 Super I/O") |
Frans Hendriks | 2e1fea4 | 2018-11-26 10:33:00 +0100 | [diff] [blame] | 125 | .enable_dev = enable_dev, |
| 126 | }; |