Omar Pakker | 449fb9b | 2016-07-29 19:05:33 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 Advanced Micro Devices, Inc. |
| 5 | * Copyright (C) 2014 Felix Held <felix-coreboot@felixheld.de> |
| 6 | * Copyright (C) 2014 Edward O'Callaghan <eocallaghan@alterapraxis.com> |
| 7 | * Copyright (C) 2015 Matt DeVillier <matt.devillier@gmail.com> |
| 8 | * Copyright (C) 2016 Omar Pakker <omarpakker+coreboot@gmail.com> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | */ |
| 20 | |
Omar Pakker | 449fb9b | 2016-07-29 19:05:33 +0200 | [diff] [blame] | 21 | #include <device/device.h> |
| 22 | #include <device/pnp.h> |
| 23 | #include <pc80/keyboard.h> |
Omar Pakker | 449fb9b | 2016-07-29 19:05:33 +0200 | [diff] [blame] | 24 | #include <superio/conf_mode.h> |
Maxim Polyakov | facbf47 | 2019-10-27 15:07:00 +0300 | [diff] [blame^] | 25 | #include <superio/common/ssdt.h> |
| 26 | #include <arch/acpi.h> |
Omar Pakker | 449fb9b | 2016-07-29 19:05:33 +0200 | [diff] [blame] | 27 | #include "nct6791d.h" |
| 28 | |
Omar Pakker | 449fb9b | 2016-07-29 19:05:33 +0200 | [diff] [blame] | 29 | static void nct6791d_init(struct device *dev) |
| 30 | { |
| 31 | if (!dev->enabled) |
| 32 | return; |
| 33 | |
| 34 | switch (dev->path.pnp.device) { |
| 35 | case NCT6791D_KBC: |
| 36 | pc_keyboard_init(NO_AUX_DEVICE); |
| 37 | break; |
| 38 | } |
| 39 | } |
| 40 | |
Maxim Polyakov | facbf47 | 2019-10-27 15:07:00 +0300 | [diff] [blame^] | 41 | #if CONFIG(HAVE_ACPI_TABLES) |
| 42 | /* Provide ACPI HIDs for generic Super I/O SSDT */ |
| 43 | static const char *nct6791d_acpi_hid(const struct device *dev) |
| 44 | { |
| 45 | if ((dev->path.type != DEVICE_PATH_PNP) || |
| 46 | (dev->path.pnp.port == 0) || |
| 47 | ((dev->path.pnp.device & 0xff) > NCT6791D_DS)) |
| 48 | return NULL; |
| 49 | |
| 50 | switch (dev->path.pnp.device & 0xff) { |
| 51 | case NCT6791D_SP1: /* falltrough */ |
| 52 | case NCT6791D_SP2: |
| 53 | return ACPI_HID_COM; |
| 54 | case NCT6791D_KBC: |
| 55 | return ACPI_HID_KEYBOARD; |
| 56 | default: |
| 57 | return ACPI_HID_PNP; |
| 58 | } |
| 59 | } |
| 60 | #endif |
| 61 | |
Omar Pakker | 449fb9b | 2016-07-29 19:05:33 +0200 | [diff] [blame] | 62 | static struct device_operations ops = { |
| 63 | .read_resources = pnp_read_resources, |
| 64 | .set_resources = pnp_set_resources, |
| 65 | .enable_resources = pnp_enable_resources, |
| 66 | .enable = pnp_alt_enable, |
| 67 | .init = nct6791d_init, |
| 68 | .ops_pnp_mode = &pnp_conf_mode_8787_aa, |
Maxim Polyakov | facbf47 | 2019-10-27 15:07:00 +0300 | [diff] [blame^] | 69 | #if CONFIG(HAVE_ACPI_TABLES) |
| 70 | .acpi_fill_ssdt_generator = superio_common_fill_ssdt_generator, |
| 71 | .acpi_name = superio_common_ldn_acpi_name, |
| 72 | .acpi_hid = nct6791d_acpi_hid, |
| 73 | #endif |
Omar Pakker | 449fb9b | 2016-07-29 19:05:33 +0200 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | static struct pnp_info pnp_dev_info[] = { |
Felix Held | 9911d64 | 2018-07-06 20:55:53 +0200 | [diff] [blame] | 77 | { NULL, NCT6791D_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 78 | 0x0ff8, }, |
Felix Held | 9911d64 | 2018-07-06 20:55:53 +0200 | [diff] [blame] | 79 | { NULL, NCT6791D_SP1, PNP_IO0 | PNP_IRQ0, |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 80 | 0x0ff8, }, |
Felix Held | 9911d64 | 2018-07-06 20:55:53 +0200 | [diff] [blame] | 81 | { NULL, NCT6791D_SP2, PNP_IO0 | PNP_IRQ0, |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 82 | 0x0ff8, }, |
Felix Held | 9911d64 | 2018-07-06 20:55:53 +0200 | [diff] [blame] | 83 | { NULL, NCT6791D_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 84 | 0x0fff, 0x0fff, }, |
Felix Held | 9911d64 | 2018-07-06 20:55:53 +0200 | [diff] [blame] | 85 | { NULL, NCT6791D_CIR, PNP_IO0 | PNP_IRQ0, |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 86 | 0x0ff8, }, |
Felix Held | 9911d64 | 2018-07-06 20:55:53 +0200 | [diff] [blame] | 87 | { NULL, NCT6791D_ACPI}, |
| 88 | { NULL, NCT6791D_HWM_FPLED, PNP_IO0 | PNP_IO1 | PNP_IRQ0, |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 89 | 0x0ffe, 0x0ffe, }, |
Felix Held | 9911d64 | 2018-07-06 20:55:53 +0200 | [diff] [blame] | 90 | { NULL, NCT6791D_BCLK_WDT2_WDTMEM}, |
| 91 | { NULL, NCT6791D_CIRWUP, PNP_IO0 | PNP_IRQ0, |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 92 | 0x0ff8, }, |
Felix Held | 9911d64 | 2018-07-06 20:55:53 +0200 | [diff] [blame] | 93 | { NULL, NCT6791D_GPIO_PP_OD}, |
| 94 | { NULL, NCT6791D_PORT80}, |
| 95 | { NULL, NCT6791D_WDT1}, |
| 96 | { NULL, NCT6791D_WDTMEM}, |
| 97 | { NULL, NCT6791D_GPIOBASE, PNP_IO0, |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 98 | 0x0ff8, }, |
Felix Held | 9911d64 | 2018-07-06 20:55:53 +0200 | [diff] [blame] | 99 | { NULL, NCT6791D_GPIO0}, |
| 100 | { NULL, NCT6791D_GPIO1}, |
| 101 | { NULL, NCT6791D_GPIO2}, |
| 102 | { NULL, NCT6791D_GPIO3}, |
| 103 | { NULL, NCT6791D_GPIO4}, |
| 104 | { NULL, NCT6791D_GPIO5}, |
| 105 | { NULL, NCT6791D_GPIO6}, |
| 106 | { NULL, NCT6791D_GPIO7}, |
| 107 | { NULL, NCT6791D_GPIO8}, |
| 108 | { NULL, NCT6791D_DS5}, |
| 109 | { NULL, NCT6791D_DS3}, |
| 110 | { NULL, NCT6791D_PCHDSW}, |
| 111 | { NULL, NCT6791D_DSWWOPT}, |
| 112 | { NULL, NCT6791D_DS3OPT}, |
| 113 | { NULL, NCT6791D_DSDSS}, |
| 114 | { NULL, NCT6791D_DSPU}, |
Omar Pakker | 449fb9b | 2016-07-29 19:05:33 +0200 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | static void enable_dev(struct device *dev) |
| 118 | { |
| 119 | pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info); |
| 120 | } |
| 121 | |
| 122 | struct chip_operations superio_nuvoton_nct6791d_ops = { |
| 123 | CHIP_NAME("NUVOTON NCT6791D Super I/O") |
| 124 | .enable_dev = enable_dev, |
| 125 | }; |