blob: 69ab91bf9829eeba642a422e6ab0b097d878c340 [file] [log] [blame]
Timothy Pearson988ee172015-11-24 14:11:57 -06001/*
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 Pearson988ee172015-11-24 14:11:57 -060020#include <device/device.h>
21#include <device/pnp.h>
22#include <pc80/keyboard.h>
23#include <pc80/mc146818rtc.h>
Timothy Pearson448e3862015-11-24 14:12:01 -060024#include <arch/acpi.h>
Timothy Pearson988ee172015-11-24 14:11:57 -060025#include <superio/conf_mode.h>
26
27#include "w83667hg-a.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 Pearson988ee172015-11-24 14:11:57 -060032
33static void w83667hg_a_init(struct device *dev)
34{
35 uint8_t byte;
36 uint8_t power_status;
Timothy Pearson448e3862015-11-24 14:12:01 -060037 uint8_t mouse_detected;
Timothy Pearson988ee172015-11-24 14:11:57 -060038
39 if (!dev->enabled)
40 return;
41
Elyes HAOUAS0ce41f12018-11-13 10:03:31 +010042 switch (dev->path.pnp.device) {
Timothy Pearson988ee172015-11-24 14:11:57 -060043 /* TODO: Might potentially need code for HWM or FDC etc. */
44 case W83667HG_A_KBC:
Timothy Pearson448e3862015-11-24 14:12:01 -060045 /* Enable mouse controller */
Patrick Rudolph98b72da2019-12-10 12:08:37 +010046 pnp_enter_conf_mode(dev);
Timothy Pearson448e3862015-11-24 14:12:01 -060047 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);
Timothy Pearson448e3862015-11-24 14:12:01 -060051
52 mouse_detected = pc_keyboard_init(PROBE_AUX_DEVICE);
53
54 if (!mouse_detected && !acpi_is_wakeup_s3()) {
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);
Timothy Pearson448e3862015-11-24 14:12:01 -060058 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);
Timothy Pearson448e3862015-11-24 14:12:01 -060062 }
Timothy Pearson988ee172015-11-24 14:11:57 -060063 break;
64 case W83667HG_A_ACPI:
65 /* Set power state after power fail */
Nico Huber9faae2b2018-11-14 00:00:35 +010066 power_status = CONFIG_MAINBOARD_POWER_FAILURE_STATE;
Timothy Pearson988ee172015-11-24 14:11:57 -060067 get_option(&power_status, "power_on_after_fail");
Patrick Rudolph98b72da2019-12-10 12:08:37 +010068 pnp_enter_conf_mode(dev);
Timothy Pearson988ee172015-11-24 14:11:57 -060069 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 Pearson988ee172015-11-24 14:11:57 -060076 pnp_write_config(dev, 0xe4, byte);
Patrick Rudolph98b72da2019-12-10 12:08:37 +010077 pnp_exit_conf_mode(dev);
Timothy Pearson988ee172015-11-24 14:11:57 -060078 printk(BIOS_INFO, "set power %s after power fail\n", power_status ? "on" : "off");
79 break;
80 }
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 = w83667hg_a_init,
89 .ops_pnp_mode = &pnp_conf_mode_8787_aa,
90};
91
92static struct pnp_info pnp_dev_info[] = {
Felix Held8c858802018-07-06 20:22:08 +020093 { 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 Pearson988ee172015-11-24 14:11:57 -0600115};
116
117static void enable_dev(struct device *dev)
118{
119 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
120}
121
122struct chip_operations superio_winbond_w83667hg_a_ops = {
123 CHIP_NAME("WINBOND W83667HG-A Super I/O")
124 .enable_dev = enable_dev,
125};