blob: 4d76052f7b3a904efa8e8dafcc8b7978b34ccc36 [file] [log] [blame]
Zheng Bao9db833b2009-12-28 09:59:44 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2000 AG Electronics Ltd.
5 * Copyright (C) 2003-2004 Linux Networx
Uwe Hermann340fa932010-11-10 14:53:36 +00006 * Copyright (C) 2004 Tyan
Stefan Reinauer14e22772010-04-27 06:56:47 +00007 * Copyright (C) 2010 Win Enterprises (anishp@win-ent.com)
Zheng Bao9db833b2009-12-28 09:59:44 +00008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
Zheng Bao9db833b2009-12-28 09:59:44 +000018 */
Ronald G. Minnich142babf2004-03-12 16:54:31 +000019
Ronald G. Minnich142babf2004-03-12 16:54:31 +000020#include <device/device.h>
21#include <device/pnp.h>
Nico Huber1c811282013-06-15 20:33:44 +020022#include <superio/conf_mode.h>
Felix Held08abfa32019-10-07 19:41:57 +020023#include <superio/hwm5_conf.h>
Ronald G. Minnich142babf2004-03-12 16:54:31 +000024#include <console/console.h>
Ronald G. Minnich142babf2004-03-12 16:54:31 +000025#include <pc80/keyboard.h>
Kyösti Mälkkicbf95712020-01-05 08:05:45 +020026#include <option.h>
Elyes HAOUAS2329a252019-05-15 22:11:18 +020027
Ronald G. Minnich142babf2004-03-12 16:54:31 +000028#include "w83627hf.h"
29
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +110030static void enable_hwm_smbus(struct device *dev)
Zheng Bao9db833b2009-12-28 09:59:44 +000031{
Uwe Hermann340fa932010-11-10 14:53:36 +000032 u8 reg8;
33
34 /* Configure pins 91/92 as SDA/SCL (I2C bus). */
35 reg8 = pnp_read_config(dev, 0x2b);
36 reg8 &= 0x3f;
37 pnp_write_config(dev, 0x2b, reg8);
Yinghai Lu70093f72004-07-01 03:55:03 +000038}
39
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +110040static void init_acpi(struct device *dev)
Yinghai Lu70093f72004-07-01 03:55:03 +000041{
Elyes HAOUASfd9f4f72018-08-13 14:04:49 +020042 u8 value;
Luc Verhaegena9c5ea02009-06-03 14:19:33 +000043 int power_on = 1;
Yinghai Lu70093f72004-07-01 03:55:03 +000044
Luc Verhaegena9c5ea02009-06-03 14:19:33 +000045 get_option(&power_on, "power_on_after_fail");
Uwe Hermann340fa932010-11-10 14:53:36 +000046
Nico Huber13dc9762013-06-15 19:33:15 +020047 pnp_enter_conf_mode(dev);
Uwe Hermann340fa932010-11-10 14:53:36 +000048 pnp_set_logical_device(dev);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000049 value = pnp_read_config(dev, 0xE4);
Uwe Hermann340fa932010-11-10 14:53:36 +000050 value &= ~(3 << 5);
51 if (power_on)
52 value |= (1 << 5);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000053 pnp_write_config(dev, 0xE4, value);
Nico Huber13dc9762013-06-15 19:33:15 +020054 pnp_exit_conf_mode(dev);
Yinghai Lu70093f72004-07-01 03:55:03 +000055}
Yinghai Lu70093f72004-07-01 03:55:03 +000056
Uwe Hermann340fa932010-11-10 14:53:36 +000057static void init_hwm(u16 base)
Yinghai Lu70093f72004-07-01 03:55:03 +000058{
Uwe Hermann340fa932010-11-10 14:53:36 +000059 u8 reg, value;
Yinghai Lu70093f72004-07-01 03:55:03 +000060 int i;
61
Uwe Hermann340fa932010-11-10 14:53:36 +000062 u8 hwm_reg_values[] = {
63 /* reg mask data */
64 0x40, 0xff, 0x81, /* Start HWM. */
65 0x48, 0xaa, 0x2a, /* Set SMBus base to 0x2a (0x54 >> 1). */
66 0x4a, 0x21, 0x21, /* Set T2 SMBus base to 0x92>>1 and T3 SMBus base to 0x94>>1. */
Myles Watsoncee94382008-10-02 19:21:30 +000067 0x4e, 0x80, 0x00,
68 0x43, 0x00, 0xff,
69 0x44, 0x00, 0x3f,
70 0x4c, 0xbf, 0x18,
Uwe Hermann340fa932010-11-10 14:53:36 +000071 0x4d, 0xff, 0x80, /* Turn off beep */
Yinghai Lu70093f72004-07-01 03:55:03 +000072 };
73
Uwe Hermann340fa932010-11-10 14:53:36 +000074 for (i = 0; i < ARRAY_SIZE(hwm_reg_values); i += 3) {
Zheng Bao9db833b2009-12-28 09:59:44 +000075 reg = hwm_reg_values[i];
Felix Held08abfa32019-10-07 19:41:57 +020076 value = pnp_read_hwm5_index(base, reg);
Uwe Hermann340fa932010-11-10 14:53:36 +000077 value &= 0xff & hwm_reg_values[i + 1];
78 value |= 0xff & hwm_reg_values[i + 2];
79 printk(BIOS_DEBUG, "base = 0x%04x, reg = 0x%02x, "
80 "value = 0x%02x\n", base, reg, value);
Felix Held08abfa32019-10-07 19:41:57 +020081 pnp_write_hwm5_index(base, reg, value);
Yinghai Lu70093f72004-07-01 03:55:03 +000082 }
83}
84
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +110085static void w83627hf_init(struct device *dev)
Ronald G. Minnich142babf2004-03-12 16:54:31 +000086{
Uwe Hermann5330dd92010-11-11 13:14:55 +000087 struct resource *res0;
Uwe Hermann340fa932010-11-10 14:53:36 +000088
89 if (!dev->enabled)
Ronald G. Minnich142babf2004-03-12 16:54:31 +000090 return;
Uwe Hermann340fa932010-11-10 14:53:36 +000091
Elyes HAOUAS0ce41f12018-11-13 10:03:31 +010092 switch (dev->path.pnp.device) {
Ronald G. Minnich142babf2004-03-12 16:54:31 +000093 case W83627HF_KBC:
Timothy Pearson448e3862015-11-24 14:12:01 -060094 pc_keyboard_init(NO_AUX_DEVICE);
Ronald G. Minnich142babf2004-03-12 16:54:31 +000095 break;
Myles Watsoncee94382008-10-02 19:21:30 +000096 case W83627HF_HWM:
97 res0 = find_resource(dev, PNP_IDX_IO0);
Felix Held08abfa32019-10-07 19:41:57 +020098 init_hwm(res0->base);
Myles Watsoncee94382008-10-02 19:21:30 +000099 break;
100 case W83627HF_ACPI:
101 init_acpi(dev);
102 break;
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000103 }
Yinghai Lu70093f72004-07-01 03:55:03 +0000104}
105
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +1100106static void w83627hf_pnp_enable_resources(struct device *dev)
Myles Watsoncee94382008-10-02 19:21:30 +0000107{
Myles Watsoncee94382008-10-02 19:21:30 +0000108 pnp_enable_resources(dev);
Nico Huber13dc9762013-06-15 19:33:15 +0200109
110 pnp_enter_conf_mode(dev);
Elyes HAOUAS0ce41f12018-11-13 10:03:31 +0100111 switch (dev->path.pnp.device) {
Yinghai Lu70093f72004-07-01 03:55:03 +0000112 case W83627HF_HWM:
Uwe Hermann340fa932010-11-10 14:53:36 +0000113 printk(BIOS_DEBUG, "W83627HF HWM SMBus enabled\n");
Yinghai Lu70093f72004-07-01 03:55:03 +0000114 enable_hwm_smbus(dev);
115 break;
116 }
Nico Huber13dc9762013-06-15 19:33:15 +0200117 pnp_exit_conf_mode(dev);
Yinghai Lu70093f72004-07-01 03:55:03 +0000118}
119
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000120static struct device_operations ops = {
121 .read_resources = pnp_read_resources,
Nico Huber0b2ee932013-06-15 19:58:35 +0200122 .set_resources = pnp_set_resources,
Yinghai Lu70093f72004-07-01 03:55:03 +0000123 .enable_resources = w83627hf_pnp_enable_resources,
Nico Huber0b2ee932013-06-15 19:58:35 +0200124 .enable = pnp_alt_enable,
Yinghai Lu70093f72004-07-01 03:55:03 +0000125 .init = w83627hf_init,
Nico Huber1c811282013-06-15 20:33:44 +0200126 .ops_pnp_mode = &pnp_conf_mode_8787_aa,
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000127};
128
129static struct pnp_info pnp_dev_info[] = {
Felix Held8c858802018-07-06 20:22:08 +0200130 { NULL, W83627HF_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, 0x07f8, },
131 { NULL, W83627HF_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, 0x07f8, },
132 { NULL, W83627HF_SP1, PNP_IO0 | PNP_IRQ0, 0x07f8, },
133 { NULL, W83627HF_SP2, PNP_IO0 | PNP_IRQ0, 0x07f8, },
134 { NULL, W83627HF_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1,
135 0x07ff, 0x07ff, },
136 { NULL, W83627HF_CIR, PNP_IO0 | PNP_IRQ0, 0x07f8, },
137 { NULL, W83627HF_GAME_MIDI_GPIO1, PNP_IO0 | PNP_IO1 | PNP_IRQ0,
138 0x07ff, 0x07fe, },
139 { NULL, W83627HF_GPIO2, },
140 { NULL, W83627HF_GPIO3, },
141 { NULL, W83627HF_ACPI, },
142 { NULL, W83627HF_HWM, PNP_IO0 | PNP_IRQ0, 0x0ff8, },
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000143};
144
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000145static void enable_dev(struct device *dev)
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000146{
Uwe Hermann340fa932010-11-10 14:53:36 +0000147 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000148}
149
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000150struct chip_operations superio_winbond_w83627hf_ops = {
Uwe Hermanna7aa29b2006-11-05 18:50:49 +0000151 CHIP_NAME("Winbond W83627HF Super I/O")
Yinghai Lu6a61d6a2004-10-20 05:07:16 +0000152 .enable_dev = enable_dev,
Ronald G. Minnich142babf2004-03-12 16:54:31 +0000153};