blob: e8249d4e6926467e5b63903de27465a4b2135c49 [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 <device/device.h>
21#include <device/pnp.h>
22#include <pc80/keyboard.h>
Timothy Pearson907ea332015-09-05 18:26:30 -050023#include <pc80/mc146818rtc.h>
Felix Held14be0da2014-07-19 00:24:06 +020024#include <stdlib.h>
Paul Menzelbf725b42016-02-07 22:14:29 +010025#include <arch/acpi.h>
Felix Held14be0da2014-07-19 00:24:06 +020026#include <superio/conf_mode.h>
27
28#include "nct5572d.h"
29
Nico Huber9faae2b2018-11-14 00:00:35 +010030#define MAINBOARD_POWER_OFF 0
31#define MAINBOARD_POWER_ON 1
32#define MAINBOARD_POWER_KEEP 2
Timothy Pearson907ea332015-09-05 18:26:30 -050033
Felix Held14be0da2014-07-19 00:24:06 +020034static void nct5572d_init(struct device *dev)
35{
Timothy Pearson907ea332015-09-05 18:26:30 -050036 uint8_t byte;
37 uint8_t power_status;
Paul Menzelbf725b42016-02-07 22:14:29 +010038 uint8_t mouse_detected;
Timothy Pearson907ea332015-09-05 18:26:30 -050039
Felix Held14be0da2014-07-19 00:24:06 +020040 if (!dev->enabled)
41 return;
42
Elyes HAOUAS0ce41f12018-11-13 10:03:31 +010043 switch (dev->path.pnp.device) {
Felix Held14be0da2014-07-19 00:24:06 +020044 /* TODO: Might potentially need code for HWM or FDC etc. */
45 case NCT5572D_KBC:
Paul Menzelbf725b42016-02-07 22:14:29 +010046 /* Enable mouse controller */
47 pnp_enter_conf_mode_8787(dev);
48 byte = pnp_read_config(dev, 0x2a);
49 byte &= ~(0x1 << 1);
50 pnp_write_config(dev, 0x2a, byte);
51 pnp_exit_conf_mode_aa(dev);
52
53 mouse_detected = pc_keyboard_init(PROBE_AUX_DEVICE);
54
Paul Menzel88a61bb2017-10-31 17:21:23 +010055 if (!mouse_detected) {
Paul Menzel6ff10782017-10-31 17:21:23 +010056 printk(BIOS_INFO, "%s: Disable mouse controller.",
57 __func__);
Paul Menzelbf725b42016-02-07 22:14:29 +010058 pnp_enter_conf_mode_8787(dev);
59 byte = pnp_read_config(dev, 0x2a);
60 byte |= 0x1 << 1;
61 pnp_write_config(dev, 0x2a, byte);
62 pnp_exit_conf_mode_aa(dev);
63 }
Felix Held14be0da2014-07-19 00:24:06 +020064 break;
Timothy Pearson907ea332015-09-05 18:26:30 -050065 case NCT5572D_ACPI:
66 /* Set power state after power fail */
Nico Huber9faae2b2018-11-14 00:00:35 +010067 power_status = CONFIG_MAINBOARD_POWER_FAILURE_STATE;
Timothy Pearson907ea332015-09-05 18:26:30 -050068 get_option(&power_status, "power_on_after_fail");
69 pnp_enter_conf_mode_8787(dev);
70 pnp_set_logical_device(dev);
71 byte = pnp_read_config(dev, 0xe4);
72 byte &= ~0x60;
Nico Huber9faae2b2018-11-14 00:00:35 +010073 if (power_status == MAINBOARD_POWER_ON)
74 byte |= (0x1 << 5);
75 else if (power_status == MAINBOARD_POWER_KEEP)
76 byte |= (0x2 << 5);
Timothy Pearson907ea332015-09-05 18:26:30 -050077 pnp_write_config(dev, 0xe4, byte);
78 pnp_exit_conf_mode_aa(dev);
79 printk(BIOS_INFO, "set power %s after power fail\n", power_status ? "on" : "off");
80 break;
Felix Held14be0da2014-07-19 00:24:06 +020081 }
82}
83
84static struct device_operations ops = {
85 .read_resources = pnp_read_resources,
86 .set_resources = pnp_set_resources,
87 .enable_resources = pnp_enable_resources,
88 .enable = pnp_alt_enable,
89 .init = nct5572d_init,
90 .ops_pnp_mode = &pnp_conf_mode_8787_aa,
91};
92
93static struct pnp_info pnp_dev_info[] = {
Felix Held9911d642018-07-06 20:55:53 +020094 { NULL, NCT5572D_FDC}, /* no pins, removed from datasheet */
95 { NULL, NCT5572D_PP}, /* no pins, removed from datasheet */
96 { NULL, NCT5572D_SP1, PNP_IO0 | PNP_IRQ0, 0x0FF8, },
97 { NULL, NCT5572D_IR, PNP_IO0 | PNP_IRQ0, 0x0FF8, },
98 { NULL, NCT5572D_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1,
99 0x0FFF, 0x0FFF, },
100 { NULL, NCT5572D_CIR, PNP_IO0 | PNP_IRQ0, 0x0FF8, },
101 { NULL, NCT5572D_WDT1},
102 { NULL, NCT5572D_ACPI},
103 { NULL, NCT5572D_HWM_TSI_FPLED, PNP_IO0 | PNP_IO1 | PNP_IRQ0,
104 0x0FFE, 0x0FFE, },
105 { NULL, NCT5572D_PECI},
106 { NULL, NCT5572D_SUSLED},
107 { NULL, NCT5572D_CIRWKUP, PNP_IO0 | PNP_IRQ0, 0x0FF8, },
108 { NULL, NCT5572D_GPIO_PP_OD},
109 { NULL, NCT5572D_GPIO2},
110 { NULL, NCT5572D_GPIO3},
111 { NULL, NCT5572D_GPIO4}, /* no pins, removed from datasheet */
112 { NULL, NCT5572D_GPIO5},
113 { NULL, NCT5572D_GPIO6},
114 { NULL, NCT5572D_GPIO7}, /* no pins, removed from datasheet */
115 { NULL, NCT5572D_GPIO8},
116 { NULL, NCT5572D_GPIO9},
Felix Held14be0da2014-07-19 00:24:06 +0200117};
118
119static void enable_dev(struct device *dev)
120{
121 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
122}
123
124struct chip_operations superio_nuvoton_nct5572d_ops = {
125 CHIP_NAME("NUVOTON NCT5572D Super I/O")
126 .enable_dev = enable_dev,
127};