blob: 81a83266d0b9d0297bfe4c32718b835b8e766378 [file] [log] [blame]
Felix Held14be0da2014-07-19 00:24:06 +02001/*
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 Pearson907ea332015-09-05 18:26:30 -05006 * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering
Felix Held14be0da2014-07-19 00:24:06 +02007 *
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.
Felix Held14be0da2014-07-19 00:24:06 +020017 */
18
Timothy Pearson907ea332015-09-05 18:26:30 -050019#include <console/console.h>
Felix Held14be0da2014-07-19 00:24:06 +020020#include <arch/io.h>
21#include <device/device.h>
22#include <device/pnp.h>
23#include <pc80/keyboard.h>
Timothy Pearson907ea332015-09-05 18:26:30 -050024#include <pc80/mc146818rtc.h>
Felix Held14be0da2014-07-19 00:24:06 +020025#include <stdlib.h>
26#include <superio/conf_mode.h>
27
28#include "nct5572d.h"
29
Timothy Pearson907ea332015-09-05 18:26:30 -050030#define MAINBOARD_POWER_OFF 0
31#define MAINBOARD_POWER_ON 1
32
33#ifndef CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL
34#define CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL MAINBOARD_POWER_ON
35#endif
36
Felix Held14be0da2014-07-19 00:24:06 +020037static void nct5572d_init(struct device *dev)
38{
Timothy Pearson907ea332015-09-05 18:26:30 -050039 uint8_t byte;
40 uint8_t power_status;
41
Felix Held14be0da2014-07-19 00:24:06 +020042 if (!dev->enabled)
43 return;
44
45 switch(dev->path.pnp.device) {
46 /* TODO: Might potentially need code for HWM or FDC etc. */
47 case NCT5572D_KBC:
48 pc_keyboard_init();
49 break;
Timothy Pearson907ea332015-09-05 18:26:30 -050050 case NCT5572D_ACPI:
51 /* Set power state after power fail */
52 power_status = CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL;
53 get_option(&power_status, "power_on_after_fail");
54 pnp_enter_conf_mode_8787(dev);
55 pnp_set_logical_device(dev);
56 byte = pnp_read_config(dev, 0xe4);
57 byte &= ~0x60;
58 if (power_status == 1)
59 byte |= (0x1 << 5); /* Force power on */
60 else if (power_status == 2)
61 byte |= (0x2 << 5); /* Use last power state */
62 pnp_write_config(dev, 0xe4, byte);
63 pnp_exit_conf_mode_aa(dev);
64 printk(BIOS_INFO, "set power %s after power fail\n", power_status ? "on" : "off");
65 break;
Felix Held14be0da2014-07-19 00:24:06 +020066 }
67}
68
69static struct device_operations ops = {
70 .read_resources = pnp_read_resources,
71 .set_resources = pnp_set_resources,
72 .enable_resources = pnp_enable_resources,
73 .enable = pnp_alt_enable,
74 .init = nct5572d_init,
75 .ops_pnp_mode = &pnp_conf_mode_8787_aa,
76};
77
78static struct pnp_info pnp_dev_info[] = {
Kyösti Mälkki3b01cf12015-10-27 18:00:57 +020079 { &ops, NCT5572D_FDC}, /* no pins, removed from datasheet */
80 { &ops, NCT5572D_PP}, /* no pins, removed from datasheet */
Felix Held14be0da2014-07-19 00:24:06 +020081 { &ops, NCT5572D_SP1, PNP_IO0 | PNP_IRQ0, {0x0FF8, 0}, },
82 { &ops, NCT5572D_IR, PNP_IO0 | PNP_IRQ0, {0x0FF8, 0}, },
83 { &ops, NCT5572D_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, {0x0FFF, 0}, {0x0FFF, 4}, },
84 { &ops, NCT5572D_CIR, PNP_IO0 | PNP_IRQ0, {0x0FF8, 0}, },
85 { &ops, NCT5572D_WDT1},
86 { &ops, NCT5572D_ACPI},
87 { &ops, NCT5572D_HWM_TSI_FPLED, PNP_IO0 | PNP_IO1 | PNP_IRQ0, {0x0FFE, 0}, {0x0FFE, 4}, },
88 { &ops, NCT5572D_PECI},
89 { &ops, NCT5572D_SUSLED},
90 { &ops, NCT5572D_CIRWKUP, PNP_IO0 | PNP_IRQ0, {0x0FF8, 0}, },
91 { &ops, NCT5572D_GPIO_PP_OD},
92 { &ops, NCT5572D_GPIO2},
93 { &ops, NCT5572D_GPIO3},
Kyösti Mälkki3b01cf12015-10-27 18:00:57 +020094 { &ops, NCT5572D_GPIO4}, /* no pins, removed from datasheet */
Felix Held14be0da2014-07-19 00:24:06 +020095 { &ops, NCT5572D_GPIO5},
96 { &ops, NCT5572D_GPIO6},
Kyösti Mälkki3b01cf12015-10-27 18:00:57 +020097 { &ops, NCT5572D_GPIO7}, /* no pins, removed from datasheet */
Felix Held14be0da2014-07-19 00:24:06 +020098 { &ops, NCT5572D_GPIO8},
99 { &ops, NCT5572D_GPIO9},
100};
101
102static void enable_dev(struct device *dev)
103{
104 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
105}
106
107struct chip_operations superio_nuvoton_nct5572d_ops = {
108 CHIP_NAME("NUVOTON NCT5572D Super I/O")
109 .enable_dev = enable_dev,
110};