Felix Held | 14be0da | 2014-07-19 00:24:06 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2014 Felix Held <felix-coreboot@felixheld.de> |
| 5 | * Copyright (C) 2014 Edward O'Callaghan <eocallaghan@alterapraxis.com> |
Timothy Pearson | 907ea33 | 2015-09-05 18:26:30 -0500 | [diff] [blame^] | 6 | * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering |
Felix Held | 14be0da | 2014-07-19 00:24:06 +0200 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 20 | * Foundation, Inc. |
Felix Held | 14be0da | 2014-07-19 00:24:06 +0200 | [diff] [blame] | 21 | */ |
| 22 | |
Timothy Pearson | 907ea33 | 2015-09-05 18:26:30 -0500 | [diff] [blame^] | 23 | #include <console/console.h> |
Felix Held | 14be0da | 2014-07-19 00:24:06 +0200 | [diff] [blame] | 24 | #include <arch/io.h> |
| 25 | #include <device/device.h> |
| 26 | #include <device/pnp.h> |
| 27 | #include <pc80/keyboard.h> |
Timothy Pearson | 907ea33 | 2015-09-05 18:26:30 -0500 | [diff] [blame^] | 28 | #include <pc80/mc146818rtc.h> |
Felix Held | 14be0da | 2014-07-19 00:24:06 +0200 | [diff] [blame] | 29 | #include <stdlib.h> |
| 30 | #include <superio/conf_mode.h> |
| 31 | |
| 32 | #include "nct5572d.h" |
| 33 | |
Timothy Pearson | 907ea33 | 2015-09-05 18:26:30 -0500 | [diff] [blame^] | 34 | #define MAINBOARD_POWER_OFF 0 |
| 35 | #define MAINBOARD_POWER_ON 1 |
| 36 | |
| 37 | #ifndef CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL |
| 38 | #define CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL MAINBOARD_POWER_ON |
| 39 | #endif |
| 40 | |
Felix Held | 14be0da | 2014-07-19 00:24:06 +0200 | [diff] [blame] | 41 | static void nct5572d_init(struct device *dev) |
| 42 | { |
Timothy Pearson | 907ea33 | 2015-09-05 18:26:30 -0500 | [diff] [blame^] | 43 | uint8_t byte; |
| 44 | uint8_t power_status; |
| 45 | |
Felix Held | 14be0da | 2014-07-19 00:24:06 +0200 | [diff] [blame] | 46 | if (!dev->enabled) |
| 47 | return; |
| 48 | |
| 49 | switch(dev->path.pnp.device) { |
| 50 | /* TODO: Might potentially need code for HWM or FDC etc. */ |
| 51 | case NCT5572D_KBC: |
| 52 | pc_keyboard_init(); |
| 53 | break; |
Timothy Pearson | 907ea33 | 2015-09-05 18:26:30 -0500 | [diff] [blame^] | 54 | case NCT5572D_ACPI: |
| 55 | /* Set power state after power fail */ |
| 56 | power_status = CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL; |
| 57 | get_option(&power_status, "power_on_after_fail"); |
| 58 | pnp_enter_conf_mode_8787(dev); |
| 59 | pnp_set_logical_device(dev); |
| 60 | byte = pnp_read_config(dev, 0xe4); |
| 61 | byte &= ~0x60; |
| 62 | if (power_status == 1) |
| 63 | byte |= (0x1 << 5); /* Force power on */ |
| 64 | else if (power_status == 2) |
| 65 | byte |= (0x2 << 5); /* Use last power state */ |
| 66 | pnp_write_config(dev, 0xe4, byte); |
| 67 | pnp_exit_conf_mode_aa(dev); |
| 68 | printk(BIOS_INFO, "set power %s after power fail\n", power_status ? "on" : "off"); |
| 69 | break; |
Felix Held | 14be0da | 2014-07-19 00:24:06 +0200 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
| 73 | static struct device_operations ops = { |
| 74 | .read_resources = pnp_read_resources, |
| 75 | .set_resources = pnp_set_resources, |
| 76 | .enable_resources = pnp_enable_resources, |
| 77 | .enable = pnp_alt_enable, |
| 78 | .init = nct5572d_init, |
| 79 | .ops_pnp_mode = &pnp_conf_mode_8787_aa, |
| 80 | }; |
| 81 | |
| 82 | static struct pnp_info pnp_dev_info[] = { |
| 83 | { &ops, NCT5572D_SP1, PNP_IO0 | PNP_IRQ0, {0x0FF8, 0}, }, |
| 84 | { &ops, NCT5572D_IR, PNP_IO0 | PNP_IRQ0, {0x0FF8, 0}, }, |
| 85 | { &ops, NCT5572D_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, {0x0FFF, 0}, {0x0FFF, 4}, }, |
| 86 | { &ops, NCT5572D_CIR, PNP_IO0 | PNP_IRQ0, {0x0FF8, 0}, }, |
| 87 | { &ops, NCT5572D_WDT1}, |
| 88 | { &ops, NCT5572D_ACPI}, |
| 89 | { &ops, NCT5572D_HWM_TSI_FPLED, PNP_IO0 | PNP_IO1 | PNP_IRQ0, {0x0FFE, 0}, {0x0FFE, 4}, }, |
| 90 | { &ops, NCT5572D_PECI}, |
| 91 | { &ops, NCT5572D_SUSLED}, |
| 92 | { &ops, NCT5572D_CIRWKUP, PNP_IO0 | PNP_IRQ0, {0x0FF8, 0}, }, |
| 93 | { &ops, NCT5572D_GPIO_PP_OD}, |
| 94 | { &ops, NCT5572D_GPIO2}, |
| 95 | { &ops, NCT5572D_GPIO3}, |
| 96 | { &ops, NCT5572D_GPIO5}, |
| 97 | { &ops, NCT5572D_GPIO6}, |
| 98 | { &ops, NCT5572D_GPIO8}, |
| 99 | { &ops, NCT5572D_GPIO9}, |
| 100 | }; |
| 101 | |
| 102 | static void enable_dev(struct device *dev) |
| 103 | { |
| 104 | pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info); |
| 105 | } |
| 106 | |
| 107 | struct chip_operations superio_nuvoton_nct5572d_ops = { |
| 108 | CHIP_NAME("NUVOTON NCT5572D Super I/O") |
| 109 | .enable_dev = enable_dev, |
| 110 | }; |