blob: 1a3be44941a9de8a6e4e727a2b08a7fe0b4e5899 [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>
20#include <arch/io.h>
21#include <device/device.h>
22#include <device/pnp.h>
23#include <pc80/keyboard.h>
24#include <pc80/mc146818rtc.h>
25#include <stdlib.h>
Timothy Pearson448e3862015-11-24 14:12:01 -060026#include <arch/acpi.h>
Timothy Pearson988ee172015-11-24 14:11:57 -060027#include <superio/conf_mode.h>
28
29#include "w83667hg-a.h"
30
31#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
38static void w83667hg_a_init(struct device *dev)
39{
40 uint8_t byte;
41 uint8_t power_status;
Timothy Pearson448e3862015-11-24 14:12:01 -060042 uint8_t mouse_detected;
Timothy Pearson988ee172015-11-24 14:11:57 -060043
44 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 W83667HG_A_KBC:
Timothy Pearson448e3862015-11-24 14:12:01 -060050 /* 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
59 if (!mouse_detected && !acpi_is_wakeup_s3()) {
Paul Menzel6ff10782017-10-31 17:21:23 +010060 printk(BIOS_INFO, "%s: Disable mouse controller.",
61 __func__);
Timothy Pearson448e3862015-11-24 14:12:01 -060062 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 }
Timothy Pearson988ee172015-11-24 14:11:57 -060068 break;
69 case W83667HG_A_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;
85 }
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 = w83667hg_a_init,
94 .ops_pnp_mode = &pnp_conf_mode_8787_aa,
95};
96
97static struct pnp_info pnp_dev_info[] = {
Samuel Holland7daac912017-06-06 22:55:01 -050098 { &ops, W83667HG_A_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, 0x0ff8, },
99 { &ops, W83667HG_A_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, 0x0ff8, },
100 { &ops, W83667HG_A_SP1, PNP_IO0 | PNP_IRQ0, 0x0ff8, },
101 { &ops, W83667HG_A_SP2, PNP_IO0 | PNP_IRQ0, 0x0ff8, },
102 { &ops, W83667HG_A_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, 0x0fff, 0x0fff, },
103 { &ops, W83667HG_A_SPI1, PNP_IO1, 0, 0x0ff8},
Timothy Pearson988ee172015-11-24 14:11:57 -0600104 { &ops, W83667HG_A_WDT1},
105 { &ops, W83667HG_A_ACPI},
Samuel Holland7daac912017-06-06 22:55:01 -0500106 { &ops, W83667HG_A_HWM_TSI, PNP_IO0 | PNP_IRQ0, 0x0ffe, },
Timothy Pearson988ee172015-11-24 14:11:57 -0600107 { &ops, W83667HG_A_PECI},
108 { &ops, W83667HG_A_VID_BUSSEL},
109 { &ops, W83667HG_A_GPIO_PP_OD},
110 { &ops, W83667HG_A_GPIO1},
111 { &ops, W83667HG_A_GPIO2},
112 { &ops, W83667HG_A_GPIO3},
113 { &ops, W83667HG_A_GPIO4},
114 { &ops, W83667HG_A_GPIO5},
115 { &ops, W83667HG_A_GPIO6},
116 { &ops, W83667HG_A_GPIO7},
117 { &ops, W83667HG_A_GPIO8},
118 { &ops, W83667HG_A_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_winbond_w83667hg_a_ops = {
127 CHIP_NAME("WINBOND W83667HG-A Super I/O")
128 .enable_dev = enable_dev,
129};