Timothy Pearson | 988ee17 | 2015-11-24 14:11:57 -0600 | [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> |
| 6 | * Copyright (C) 2015 - 2016 Raptor Engineering |
| 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. |
| 17 | */ |
| 18 | |
| 19 | #include <console/console.h> |
Timothy Pearson | 988ee17 | 2015-11-24 14:11:57 -0600 | [diff] [blame] | 20 | #include <device/device.h> |
| 21 | #include <device/pnp.h> |
| 22 | #include <pc80/keyboard.h> |
Kyösti Mälkki | cbf9571 | 2020-01-05 08:05:45 +0200 | [diff] [blame] | 23 | #include <option.h> |
Timothy Pearson | 448e386 | 2015-11-24 14:12:01 -0600 | [diff] [blame] | 24 | #include <arch/acpi.h> |
Timothy Pearson | 988ee17 | 2015-11-24 14:11:57 -0600 | [diff] [blame] | 25 | #include <superio/conf_mode.h> |
| 26 | |
| 27 | #include "w83667hg-a.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 | 988ee17 | 2015-11-24 14:11:57 -0600 | [diff] [blame] | 32 | |
| 33 | static void w83667hg_a_init(struct device *dev) |
| 34 | { |
| 35 | uint8_t byte; |
| 36 | uint8_t power_status; |
Timothy Pearson | 448e386 | 2015-11-24 14:12:01 -0600 | [diff] [blame] | 37 | uint8_t mouse_detected; |
Timothy Pearson | 988ee17 | 2015-11-24 14:11:57 -0600 | [diff] [blame] | 38 | |
| 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) { |
Timothy Pearson | 988ee17 | 2015-11-24 14:11:57 -0600 | [diff] [blame] | 43 | /* TODO: Might potentially need code for HWM or FDC etc. */ |
| 44 | case W83667HG_A_KBC: |
Timothy Pearson | 448e386 | 2015-11-24 14:12:01 -0600 | [diff] [blame] | 45 | /* Enable mouse controller */ |
Patrick Rudolph | 98b72da | 2019-12-10 12:08:37 +0100 | [diff] [blame] | 46 | pnp_enter_conf_mode(dev); |
Timothy Pearson | 448e386 | 2015-11-24 14:12:01 -0600 | [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); |
Timothy Pearson | 448e386 | 2015-11-24 14:12:01 -0600 | [diff] [blame] | 51 | |
| 52 | mouse_detected = pc_keyboard_init(PROBE_AUX_DEVICE); |
| 53 | |
| 54 | if (!mouse_detected && !acpi_is_wakeup_s3()) { |
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); |
Timothy Pearson | 448e386 | 2015-11-24 14:12:01 -0600 | [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); |
Timothy Pearson | 448e386 | 2015-11-24 14:12:01 -0600 | [diff] [blame] | 62 | } |
Timothy Pearson | 988ee17 | 2015-11-24 14:11:57 -0600 | [diff] [blame] | 63 | break; |
| 64 | case W83667HG_A_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 | 988ee17 | 2015-11-24 14:11:57 -0600 | [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 | 988ee17 | 2015-11-24 14:11:57 -0600 | [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 | 988ee17 | 2015-11-24 14:11:57 -0600 | [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 | 988ee17 | 2015-11-24 14:11:57 -0600 | [diff] [blame] | 78 | printk(BIOS_INFO, "set power %s after power fail\n", power_status ? "on" : "off"); |
| 79 | break; |
| 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 = w83667hg_a_init, |
| 89 | .ops_pnp_mode = &pnp_conf_mode_8787_aa, |
| 90 | }; |
| 91 | |
| 92 | static struct pnp_info pnp_dev_info[] = { |
Felix Held | 8c85880 | 2018-07-06 20:22:08 +0200 | [diff] [blame] | 93 | { NULL, W83667HG_A_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, 0x0ff8, }, |
| 94 | { NULL, W83667HG_A_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, 0x0ff8, }, |
| 95 | { NULL, W83667HG_A_SP1, PNP_IO0 | PNP_IRQ0, 0x0ff8, }, |
| 96 | { NULL, W83667HG_A_SP2, PNP_IO0 | PNP_IRQ0, 0x0ff8, }, |
| 97 | { NULL, W83667HG_A_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, |
| 98 | 0x0fff, 0x0fff, }, |
| 99 | { NULL, W83667HG_A_SPI1, PNP_IO1, 0, 0x0ff8}, |
| 100 | { NULL, W83667HG_A_WDT1}, |
| 101 | { NULL, W83667HG_A_ACPI}, |
| 102 | { NULL, W83667HG_A_HWM_TSI, PNP_IO0 | PNP_IRQ0, 0x0ffe, }, |
| 103 | { NULL, W83667HG_A_PECI}, |
| 104 | { NULL, W83667HG_A_VID_BUSSEL}, |
| 105 | { NULL, W83667HG_A_GPIO_PP_OD}, |
| 106 | { NULL, W83667HG_A_GPIO1}, |
| 107 | { NULL, W83667HG_A_GPIO2}, |
| 108 | { NULL, W83667HG_A_GPIO3}, |
| 109 | { NULL, W83667HG_A_GPIO4}, |
| 110 | { NULL, W83667HG_A_GPIO5}, |
| 111 | { NULL, W83667HG_A_GPIO6}, |
| 112 | { NULL, W83667HG_A_GPIO7}, |
| 113 | { NULL, W83667HG_A_GPIO8}, |
| 114 | { NULL, W83667HG_A_GPIO9}, |
Timothy Pearson | 988ee17 | 2015-11-24 14:11:57 -0600 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | static void enable_dev(struct device *dev) |
| 118 | { |
| 119 | pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info); |
| 120 | } |
| 121 | |
| 122 | struct chip_operations superio_winbond_w83667hg_a_ops = { |
| 123 | CHIP_NAME("WINBOND W83667HG-A Super I/O") |
| 124 | .enable_dev = enable_dev, |
| 125 | }; |