blob: 12b1c78e3a7d7e3b22cc58206e78b89a41e14499 [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>
Paul Menzelbf725b42016-02-07 22:14:29 +010026#include <arch/acpi.h>
Felix Held14be0da2014-07-19 00:24:06 +020027#include <superio/conf_mode.h>
28
29#include "nct5572d.h"
30
Timothy Pearson907ea332015-09-05 18:26:30 -050031#define MAINBOARD_POWER_OFF 0
32#define MAINBOARD_POWER_ON 1
33
34#ifndef CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL
35#define CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL MAINBOARD_POWER_ON
36#endif
37
Felix Held14be0da2014-07-19 00:24:06 +020038static void nct5572d_init(struct device *dev)
39{
Timothy Pearson907ea332015-09-05 18:26:30 -050040 uint8_t byte;
41 uint8_t power_status;
Paul Menzelbf725b42016-02-07 22:14:29 +010042 uint8_t mouse_detected;
Timothy Pearson907ea332015-09-05 18:26:30 -050043
Felix Held14be0da2014-07-19 00:24:06 +020044 if (!dev->enabled)
45 return;
46
47 switch(dev->path.pnp.device) {
48 /* TODO: Might potentially need code for HWM or FDC etc. */
49 case NCT5572D_KBC:
Paul Menzelbf725b42016-02-07 22:14:29 +010050 /* Enable mouse controller */
51 pnp_enter_conf_mode_8787(dev);
52 byte = pnp_read_config(dev, 0x2a);
53 byte &= ~(0x1 << 1);
54 pnp_write_config(dev, 0x2a, byte);
55 pnp_exit_conf_mode_aa(dev);
56
57 mouse_detected = pc_keyboard_init(PROBE_AUX_DEVICE);
58
Paul Menzel88a61bb2017-10-31 17:21:23 +010059 if (!mouse_detected) {
Paul Menzel6ff10782017-10-31 17:21:23 +010060 printk(BIOS_INFO, "%s: Disable mouse controller.",
61 __func__);
Paul Menzelbf725b42016-02-07 22:14:29 +010062 pnp_enter_conf_mode_8787(dev);
63 byte = pnp_read_config(dev, 0x2a);
64 byte |= 0x1 << 1;
65 pnp_write_config(dev, 0x2a, byte);
66 pnp_exit_conf_mode_aa(dev);
67 }
Felix Held14be0da2014-07-19 00:24:06 +020068 break;
Timothy Pearson907ea332015-09-05 18:26:30 -050069 case NCT5572D_ACPI:
70 /* Set power state after power fail */
71 power_status = CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL;
72 get_option(&power_status, "power_on_after_fail");
73 pnp_enter_conf_mode_8787(dev);
74 pnp_set_logical_device(dev);
75 byte = pnp_read_config(dev, 0xe4);
76 byte &= ~0x60;
77 if (power_status == 1)
78 byte |= (0x1 << 5); /* Force power on */
79 else if (power_status == 2)
80 byte |= (0x2 << 5); /* Use last power state */
81 pnp_write_config(dev, 0xe4, byte);
82 pnp_exit_conf_mode_aa(dev);
83 printk(BIOS_INFO, "set power %s after power fail\n", power_status ? "on" : "off");
84 break;
Felix Held14be0da2014-07-19 00:24:06 +020085 }
86}
87
88static struct device_operations ops = {
89 .read_resources = pnp_read_resources,
90 .set_resources = pnp_set_resources,
91 .enable_resources = pnp_enable_resources,
92 .enable = pnp_alt_enable,
93 .init = nct5572d_init,
94 .ops_pnp_mode = &pnp_conf_mode_8787_aa,
95};
96
97static struct pnp_info pnp_dev_info[] = {
Kyösti Mälkki3b01cf12015-10-27 18:00:57 +020098 { &ops, NCT5572D_FDC}, /* no pins, removed from datasheet */
99 { &ops, NCT5572D_PP}, /* no pins, removed from datasheet */
Samuel Holland7daac912017-06-06 22:55:01 -0500100 { &ops, NCT5572D_SP1, PNP_IO0 | PNP_IRQ0, 0x0FF8, },
101 { &ops, NCT5572D_IR, PNP_IO0 | PNP_IRQ0, 0x0FF8, },
102 { &ops, NCT5572D_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, 0x0FFF, 0x0FFF, },
103 { &ops, NCT5572D_CIR, PNP_IO0 | PNP_IRQ0, 0x0FF8, },
Felix Held14be0da2014-07-19 00:24:06 +0200104 { &ops, NCT5572D_WDT1},
105 { &ops, NCT5572D_ACPI},
Samuel Holland7daac912017-06-06 22:55:01 -0500106 { &ops, NCT5572D_HWM_TSI_FPLED, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x0FFE, 0x0FFE, },
Felix Held14be0da2014-07-19 00:24:06 +0200107 { &ops, NCT5572D_PECI},
108 { &ops, NCT5572D_SUSLED},
Samuel Holland7daac912017-06-06 22:55:01 -0500109 { &ops, NCT5572D_CIRWKUP, PNP_IO0 | PNP_IRQ0, 0x0FF8, },
Felix Held14be0da2014-07-19 00:24:06 +0200110 { &ops, NCT5572D_GPIO_PP_OD},
111 { &ops, NCT5572D_GPIO2},
112 { &ops, NCT5572D_GPIO3},
Kyösti Mälkki3b01cf12015-10-27 18:00:57 +0200113 { &ops, NCT5572D_GPIO4}, /* no pins, removed from datasheet */
Felix Held14be0da2014-07-19 00:24:06 +0200114 { &ops, NCT5572D_GPIO5},
115 { &ops, NCT5572D_GPIO6},
Kyösti Mälkki3b01cf12015-10-27 18:00:57 +0200116 { &ops, NCT5572D_GPIO7}, /* no pins, removed from datasheet */
Felix Held14be0da2014-07-19 00:24:06 +0200117 { &ops, NCT5572D_GPIO8},
118 { &ops, NCT5572D_GPIO9},
119};
120
121static void enable_dev(struct device *dev)
122{
123 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
124}
125
126struct chip_operations superio_nuvoton_nct5572d_ops = {
127 CHIP_NAME("NUVOTON NCT5572D Super I/O")
128 .enable_dev = enable_dev,
129};