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. |
Felix Held | 14be0da | 2014-07-19 00:24:06 +0200 | [diff] [blame] | 17 | */ |
| 18 | |
Timothy Pearson | 907ea33 | 2015-09-05 18:26:30 -0500 | [diff] [blame] | 19 | #include <console/console.h> |
Felix Held | 14be0da | 2014-07-19 00:24:06 +0200 | [diff] [blame] | 20 | #include <device/device.h> |
| 21 | #include <device/pnp.h> |
| 22 | #include <pc80/keyboard.h> |
Timothy Pearson | 907ea33 | 2015-09-05 18:26:30 -0500 | [diff] [blame] | 23 | #include <pc80/mc146818rtc.h> |
Paul Menzel | bf725b4 | 2016-02-07 22:14:29 +0100 | [diff] [blame] | 24 | #include <arch/acpi.h> |
Felix Held | 14be0da | 2014-07-19 00:24:06 +0200 | [diff] [blame] | 25 | #include <superio/conf_mode.h> |
| 26 | |
| 27 | #include "nct5572d.h" |
| 28 | |
Nico Huber | 9faae2b | 2018-11-14 00:00:35 +0100 | [diff] [blame] | 29 | #define MAINBOARD_POWER_OFF 0 |
| 30 | #define MAINBOARD_POWER_ON 1 |
| 31 | #define MAINBOARD_POWER_KEEP 2 |
Timothy Pearson | 907ea33 | 2015-09-05 18:26:30 -0500 | [diff] [blame] | 32 | |
Felix Held | 14be0da | 2014-07-19 00:24:06 +0200 | [diff] [blame] | 33 | static void nct5572d_init(struct device *dev) |
| 34 | { |
Timothy Pearson | 907ea33 | 2015-09-05 18:26:30 -0500 | [diff] [blame] | 35 | uint8_t byte; |
| 36 | uint8_t power_status; |
Paul Menzel | bf725b4 | 2016-02-07 22:14:29 +0100 | [diff] [blame] | 37 | uint8_t mouse_detected; |
Timothy Pearson | 907ea33 | 2015-09-05 18:26:30 -0500 | [diff] [blame] | 38 | |
Felix Held | 14be0da | 2014-07-19 00:24:06 +0200 | [diff] [blame] | 39 | if (!dev->enabled) |
| 40 | return; |
| 41 | |
Elyes HAOUAS | 0ce41f1 | 2018-11-13 10:03:31 +0100 | [diff] [blame] | 42 | switch (dev->path.pnp.device) { |
Felix Held | 14be0da | 2014-07-19 00:24:06 +0200 | [diff] [blame] | 43 | /* TODO: Might potentially need code for HWM or FDC etc. */ |
| 44 | case NCT5572D_KBC: |
Paul Menzel | bf725b4 | 2016-02-07 22:14:29 +0100 | [diff] [blame] | 45 | /* Enable mouse controller */ |
Patrick Rudolph | 98b72da | 2019-12-10 12:08:37 +0100 | [diff] [blame^] | 46 | pnp_enter_conf_mode(dev); |
Paul Menzel | bf725b4 | 2016-02-07 22:14:29 +0100 | [diff] [blame] | 47 | byte = pnp_read_config(dev, 0x2a); |
| 48 | byte &= ~(0x1 << 1); |
| 49 | pnp_write_config(dev, 0x2a, byte); |
Patrick Rudolph | 98b72da | 2019-12-10 12:08:37 +0100 | [diff] [blame^] | 50 | pnp_exit_conf_mode(dev); |
Paul Menzel | bf725b4 | 2016-02-07 22:14:29 +0100 | [diff] [blame] | 51 | |
| 52 | mouse_detected = pc_keyboard_init(PROBE_AUX_DEVICE); |
| 53 | |
Paul Menzel | 88a61bb | 2017-10-31 17:21:23 +0100 | [diff] [blame] | 54 | if (!mouse_detected) { |
Paul Menzel | 6ff1078 | 2017-10-31 17:21:23 +0100 | [diff] [blame] | 55 | printk(BIOS_INFO, "%s: Disable mouse controller.", |
| 56 | __func__); |
Patrick Rudolph | 98b72da | 2019-12-10 12:08:37 +0100 | [diff] [blame^] | 57 | pnp_enter_conf_mode(dev); |
Paul Menzel | bf725b4 | 2016-02-07 22:14:29 +0100 | [diff] [blame] | 58 | byte = pnp_read_config(dev, 0x2a); |
| 59 | byte |= 0x1 << 1; |
| 60 | pnp_write_config(dev, 0x2a, byte); |
Patrick Rudolph | 98b72da | 2019-12-10 12:08:37 +0100 | [diff] [blame^] | 61 | pnp_exit_conf_mode(dev); |
Paul Menzel | bf725b4 | 2016-02-07 22:14:29 +0100 | [diff] [blame] | 62 | } |
Felix Held | 14be0da | 2014-07-19 00:24:06 +0200 | [diff] [blame] | 63 | break; |
Timothy Pearson | 907ea33 | 2015-09-05 18:26:30 -0500 | [diff] [blame] | 64 | case NCT5572D_ACPI: |
| 65 | /* Set power state after power fail */ |
Nico Huber | 9faae2b | 2018-11-14 00:00:35 +0100 | [diff] [blame] | 66 | power_status = CONFIG_MAINBOARD_POWER_FAILURE_STATE; |
Timothy Pearson | 907ea33 | 2015-09-05 18:26:30 -0500 | [diff] [blame] | 67 | get_option(&power_status, "power_on_after_fail"); |
Patrick Rudolph | 98b72da | 2019-12-10 12:08:37 +0100 | [diff] [blame^] | 68 | pnp_enter_conf_mode(dev); |
Timothy Pearson | 907ea33 | 2015-09-05 18:26:30 -0500 | [diff] [blame] | 69 | pnp_set_logical_device(dev); |
| 70 | byte = pnp_read_config(dev, 0xe4); |
| 71 | byte &= ~0x60; |
Nico Huber | 9faae2b | 2018-11-14 00:00:35 +0100 | [diff] [blame] | 72 | if (power_status == MAINBOARD_POWER_ON) |
| 73 | byte |= (0x1 << 5); |
| 74 | else if (power_status == MAINBOARD_POWER_KEEP) |
| 75 | byte |= (0x2 << 5); |
Timothy Pearson | 907ea33 | 2015-09-05 18:26:30 -0500 | [diff] [blame] | 76 | pnp_write_config(dev, 0xe4, byte); |
Patrick Rudolph | 98b72da | 2019-12-10 12:08:37 +0100 | [diff] [blame^] | 77 | pnp_exit_conf_mode(dev); |
Timothy Pearson | 907ea33 | 2015-09-05 18:26:30 -0500 | [diff] [blame] | 78 | printk(BIOS_INFO, "set power %s after power fail\n", power_status ? "on" : "off"); |
| 79 | break; |
Felix Held | 14be0da | 2014-07-19 00:24:06 +0200 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
| 83 | static 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 | |
| 92 | static struct pnp_info pnp_dev_info[] = { |
Felix Held | 9911d64 | 2018-07-06 20:55:53 +0200 | [diff] [blame] | 93 | { 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 Held | 14be0da | 2014-07-19 00:24:06 +0200 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | static void enable_dev(struct device *dev) |
| 119 | { |
| 120 | pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info); |
| 121 | } |
| 122 | |
| 123 | struct chip_operations superio_nuvoton_nct5572d_ops = { |
| 124 | CHIP_NAME("NUVOTON NCT5572D Super I/O") |
| 125 | .enable_dev = enable_dev, |
| 126 | }; |