blob: 76c983a0c74581e66face452b4b34614fa07affb [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>
Paul Menzelbf725b42016-02-07 22:14:29 +010024#include <arch/acpi.h>
Felix Held14be0da2014-07-19 00:24:06 +020025#include <superio/conf_mode.h>
26
27#include "nct5572d.h"
28
Nico Huber9faae2b2018-11-14 00:00:35 +010029#define MAINBOARD_POWER_OFF 0
30#define MAINBOARD_POWER_ON 1
31#define MAINBOARD_POWER_KEEP 2
Timothy Pearson907ea332015-09-05 18:26:30 -050032
Felix Held14be0da2014-07-19 00:24:06 +020033static void nct5572d_init(struct device *dev)
34{
Timothy Pearson907ea332015-09-05 18:26:30 -050035 uint8_t byte;
36 uint8_t power_status;
Paul Menzelbf725b42016-02-07 22:14:29 +010037 uint8_t mouse_detected;
Timothy Pearson907ea332015-09-05 18:26:30 -050038
Felix Held14be0da2014-07-19 00:24:06 +020039 if (!dev->enabled)
40 return;
41
Elyes HAOUAS0ce41f12018-11-13 10:03:31 +010042 switch (dev->path.pnp.device) {
Felix Held14be0da2014-07-19 00:24:06 +020043 /* TODO: Might potentially need code for HWM or FDC etc. */
44 case NCT5572D_KBC:
Paul Menzelbf725b42016-02-07 22:14:29 +010045 /* Enable mouse controller */
Patrick Rudolph98b72da2019-12-10 12:08:37 +010046 pnp_enter_conf_mode(dev);
Paul Menzelbf725b42016-02-07 22:14:29 +010047 byte = pnp_read_config(dev, 0x2a);
48 byte &= ~(0x1 << 1);
49 pnp_write_config(dev, 0x2a, byte);
Patrick Rudolph98b72da2019-12-10 12:08:37 +010050 pnp_exit_conf_mode(dev);
Paul Menzelbf725b42016-02-07 22:14:29 +010051
52 mouse_detected = pc_keyboard_init(PROBE_AUX_DEVICE);
53
Paul Menzel88a61bb2017-10-31 17:21:23 +010054 if (!mouse_detected) {
Paul Menzel6ff10782017-10-31 17:21:23 +010055 printk(BIOS_INFO, "%s: Disable mouse controller.",
56 __func__);
Patrick Rudolph98b72da2019-12-10 12:08:37 +010057 pnp_enter_conf_mode(dev);
Paul Menzelbf725b42016-02-07 22:14:29 +010058 byte = pnp_read_config(dev, 0x2a);
59 byte |= 0x1 << 1;
60 pnp_write_config(dev, 0x2a, byte);
Patrick Rudolph98b72da2019-12-10 12:08:37 +010061 pnp_exit_conf_mode(dev);
Paul Menzelbf725b42016-02-07 22:14:29 +010062 }
Felix Held14be0da2014-07-19 00:24:06 +020063 break;
Timothy Pearson907ea332015-09-05 18:26:30 -050064 case NCT5572D_ACPI:
65 /* Set power state after power fail */
Nico Huber9faae2b2018-11-14 00:00:35 +010066 power_status = CONFIG_MAINBOARD_POWER_FAILURE_STATE;
Timothy Pearson907ea332015-09-05 18:26:30 -050067 get_option(&power_status, "power_on_after_fail");
Patrick Rudolph98b72da2019-12-10 12:08:37 +010068 pnp_enter_conf_mode(dev);
Timothy Pearson907ea332015-09-05 18:26:30 -050069 pnp_set_logical_device(dev);
70 byte = pnp_read_config(dev, 0xe4);
71 byte &= ~0x60;
Nico Huber9faae2b2018-11-14 00:00:35 +010072 if (power_status == MAINBOARD_POWER_ON)
73 byte |= (0x1 << 5);
74 else if (power_status == MAINBOARD_POWER_KEEP)
75 byte |= (0x2 << 5);
Timothy Pearson907ea332015-09-05 18:26:30 -050076 pnp_write_config(dev, 0xe4, byte);
Patrick Rudolph98b72da2019-12-10 12:08:37 +010077 pnp_exit_conf_mode(dev);
Timothy Pearson907ea332015-09-05 18:26:30 -050078 printk(BIOS_INFO, "set power %s after power fail\n", power_status ? "on" : "off");
79 break;
Felix Held14be0da2014-07-19 00:24:06 +020080 }
81}
82
83static struct device_operations ops = {
84 .read_resources = pnp_read_resources,
85 .set_resources = pnp_set_resources,
86 .enable_resources = pnp_enable_resources,
87 .enable = pnp_alt_enable,
88 .init = nct5572d_init,
89 .ops_pnp_mode = &pnp_conf_mode_8787_aa,
90};
91
92static struct pnp_info pnp_dev_info[] = {
Felix Held9911d642018-07-06 20:55:53 +020093 { NULL, NCT5572D_FDC}, /* no pins, removed from datasheet */
94 { NULL, NCT5572D_PP}, /* no pins, removed from datasheet */
95 { NULL, NCT5572D_SP1, PNP_IO0 | PNP_IRQ0, 0x0FF8, },
96 { NULL, NCT5572D_IR, PNP_IO0 | PNP_IRQ0, 0x0FF8, },
97 { NULL, NCT5572D_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1,
98 0x0FFF, 0x0FFF, },
99 { NULL, NCT5572D_CIR, PNP_IO0 | PNP_IRQ0, 0x0FF8, },
100 { NULL, NCT5572D_WDT1},
101 { NULL, NCT5572D_ACPI},
102 { NULL, NCT5572D_HWM_TSI_FPLED, PNP_IO0 | PNP_IO1 | PNP_IRQ0,
103 0x0FFE, 0x0FFE, },
104 { NULL, NCT5572D_PECI},
105 { NULL, NCT5572D_SUSLED},
106 { NULL, NCT5572D_CIRWKUP, PNP_IO0 | PNP_IRQ0, 0x0FF8, },
107 { NULL, NCT5572D_GPIO_PP_OD},
108 { NULL, NCT5572D_GPIO2},
109 { NULL, NCT5572D_GPIO3},
110 { NULL, NCT5572D_GPIO4}, /* no pins, removed from datasheet */
111 { NULL, NCT5572D_GPIO5},
112 { NULL, NCT5572D_GPIO6},
113 { NULL, NCT5572D_GPIO7}, /* no pins, removed from datasheet */
114 { NULL, NCT5572D_GPIO8},
115 { NULL, NCT5572D_GPIO9},
Felix Held14be0da2014-07-19 00:24:06 +0200116};
117
118static void enable_dev(struct device *dev)
119{
120 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
121}
122
123struct chip_operations superio_nuvoton_nct5572d_ops = {
124 CHIP_NAME("NUVOTON NCT5572D Super I/O")
125 .enable_dev = enable_dev,
126};