blob: 6cd54ef9fcf98be7426fd2c2f640745c1a4ee252 [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()) {
60 /* Disable mouse controller */
61 pnp_enter_conf_mode_8787(dev);
62 byte = pnp_read_config(dev, 0x2a);
63 byte |= 0x1 << 1;
64 pnp_write_config(dev, 0x2a, byte);
65 pnp_exit_conf_mode_aa(dev);
66 }
Timothy Pearson988ee172015-11-24 14:11:57 -060067 break;
68 case W83667HG_A_ACPI:
69 /* Set power state after power fail */
70 power_status = CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL;
71 get_option(&power_status, "power_on_after_fail");
72 pnp_enter_conf_mode_8787(dev);
73 pnp_set_logical_device(dev);
74 byte = pnp_read_config(dev, 0xe4);
75 byte &= ~0x60;
76 if (power_status == 1)
77 byte |= (0x1 << 5); /* Force power on */
78 else if (power_status == 2)
79 byte |= (0x2 << 5); /* Use last power state */
80 pnp_write_config(dev, 0xe4, byte);
81 pnp_exit_conf_mode_aa(dev);
82 printk(BIOS_INFO, "set power %s after power fail\n", power_status ? "on" : "off");
83 break;
84 }
85}
86
87static struct device_operations ops = {
88 .read_resources = pnp_read_resources,
89 .set_resources = pnp_set_resources,
90 .enable_resources = pnp_enable_resources,
91 .enable = pnp_alt_enable,
92 .init = w83667hg_a_init,
93 .ops_pnp_mode = &pnp_conf_mode_8787_aa,
94};
95
96static struct pnp_info pnp_dev_info[] = {
97 { &ops, W83667HG_A_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x0ff8, 0}, },
98 { &ops, W83667HG_A_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x0ff8, 0}, },
99 { &ops, W83667HG_A_SP1, PNP_IO0 | PNP_IRQ0, {0x0ff8, 0}, },
100 { &ops, W83667HG_A_SP2, PNP_IO0 | PNP_IRQ0, {0x0ff8, 0}, },
101 { &ops, W83667HG_A_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, {0x0fff, 0}, {0x0fff, 4}, },
102 { &ops, W83667HG_A_SPI, PNP_IO1, {0x0ff8, 0}},
103 { &ops, W83667HG_A_WDT1},
104 { &ops, W83667HG_A_ACPI},
105 { &ops, W83667HG_A_HWM_TSI, PNP_IO0 | PNP_IRQ0, {0x0ffe, 0}, },
106 { &ops, W83667HG_A_PECI},
107 { &ops, W83667HG_A_VID_BUSSEL},
108 { &ops, W83667HG_A_GPIO_PP_OD},
109 { &ops, W83667HG_A_GPIO1},
110 { &ops, W83667HG_A_GPIO2},
111 { &ops, W83667HG_A_GPIO3},
112 { &ops, W83667HG_A_GPIO4},
113 { &ops, W83667HG_A_GPIO5},
114 { &ops, W83667HG_A_GPIO6},
115 { &ops, W83667HG_A_GPIO7},
116 { &ops, W83667HG_A_GPIO8},
117 { &ops, W83667HG_A_GPIO9},
118};
119
120static void enable_dev(struct device *dev)
121{
122 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
123}
124
125struct chip_operations superio_winbond_w83667hg_a_ops = {
126 CHIP_NAME("WINBOND W83667HG-A Super I/O")
127 .enable_dev = enable_dev,
128};