Zheng Bao | 9db833b | 2009-12-28 09:59:44 +0000 | [diff] [blame] | 1 | /* |
| 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 Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 6 | * Copyright (C) 2004 Tyan |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 7 | * Copyright (C) 2010 Win Enterprises (anishp@win-ent.com) |
Zheng Bao | 9db833b | 2009-12-28 09:59:44 +0000 | [diff] [blame] | 8 | * |
| 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. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Zheng Bao | 9db833b | 2009-12-28 09:59:44 +0000 | [diff] [blame] | 22 | */ |
Ronald G. Minnich | 142babf | 2004-03-12 16:54:31 +0000 | [diff] [blame] | 23 | |
| 24 | #include <arch/io.h> |
| 25 | #include <device/device.h> |
| 26 | #include <device/pnp.h> |
Nico Huber | 1c81128 | 2013-06-15 20:33:44 +0200 | [diff] [blame] | 27 | #include <superio/conf_mode.h> |
Ronald G. Minnich | 142babf | 2004-03-12 16:54:31 +0000 | [diff] [blame] | 28 | #include <console/console.h> |
| 29 | #include <string.h> |
Ronald G. Minnich | 142babf | 2004-03-12 16:54:31 +0000 | [diff] [blame] | 30 | #include <pc80/keyboard.h> |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 31 | #include <pc80/mc146818rtc.h> |
Carl-Daniel Hailfinger | 2ee6779 | 2008-10-01 12:52:52 +0000 | [diff] [blame] | 32 | #include <stdlib.h> |
Ronald G. Minnich | 142babf | 2004-03-12 16:54:31 +0000 | [diff] [blame] | 33 | #include "w83627hf.h" |
| 34 | |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 35 | static void pnp_write_index(u16 port, u8 reg, u8 value) |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 36 | { |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 37 | outb(reg, port); |
| 38 | outb(value, port + 1); |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 41 | static u8 pnp_read_index(u16 port, u8 reg) |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 42 | { |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 43 | outb(reg, port); |
| 44 | return inb(port + 1); |
Myles Watson | cee9438 | 2008-10-02 19:21:30 +0000 | [diff] [blame] | 45 | } |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 46 | |
Edward O'Callaghan | f21bdc3 | 2014-10-21 07:43:41 +1100 | [diff] [blame] | 47 | static void enable_hwm_smbus(struct device *dev) |
Zheng Bao | 9db833b | 2009-12-28 09:59:44 +0000 | [diff] [blame] | 48 | { |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 49 | u8 reg8; |
| 50 | |
| 51 | /* Configure pins 91/92 as SDA/SCL (I2C bus). */ |
| 52 | reg8 = pnp_read_config(dev, 0x2b); |
| 53 | reg8 &= 0x3f; |
| 54 | pnp_write_config(dev, 0x2b, reg8); |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Edward O'Callaghan | f21bdc3 | 2014-10-21 07:43:41 +1100 | [diff] [blame] | 57 | static void init_acpi(struct device *dev) |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 58 | { |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 59 | u8 value = 0x20; /* FIXME: The 0x20 value here is never used? */ |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 60 | int power_on = 1; |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 61 | |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 62 | get_option(&power_on, "power_on_after_fail"); |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 63 | |
Nico Huber | 13dc976 | 2013-06-15 19:33:15 +0200 | [diff] [blame] | 64 | pnp_enter_conf_mode(dev); |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 65 | pnp_set_logical_device(dev); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 66 | value = pnp_read_config(dev, 0xE4); |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 67 | value &= ~(3 << 5); |
| 68 | if (power_on) |
| 69 | value |= (1 << 5); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 70 | pnp_write_config(dev, 0xE4, value); |
Nico Huber | 13dc976 | 2013-06-15 19:33:15 +0200 | [diff] [blame] | 71 | pnp_exit_conf_mode(dev); |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 72 | } |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 73 | |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 74 | static void init_hwm(u16 base) |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 75 | { |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 76 | u8 reg, value; |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 77 | int i; |
| 78 | |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 79 | u8 hwm_reg_values[] = { |
| 80 | /* reg mask data */ |
| 81 | 0x40, 0xff, 0x81, /* Start HWM. */ |
| 82 | 0x48, 0xaa, 0x2a, /* Set SMBus base to 0x2a (0x54 >> 1). */ |
| 83 | 0x4a, 0x21, 0x21, /* Set T2 SMBus base to 0x92>>1 and T3 SMBus base to 0x94>>1. */ |
Myles Watson | cee9438 | 2008-10-02 19:21:30 +0000 | [diff] [blame] | 84 | 0x4e, 0x80, 0x00, |
| 85 | 0x43, 0x00, 0xff, |
| 86 | 0x44, 0x00, 0x3f, |
| 87 | 0x4c, 0xbf, 0x18, |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 88 | 0x4d, 0xff, 0x80, /* Turn off beep */ |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 91 | for (i = 0; i < ARRAY_SIZE(hwm_reg_values); i += 3) { |
Zheng Bao | 9db833b | 2009-12-28 09:59:44 +0000 | [diff] [blame] | 92 | reg = hwm_reg_values[i]; |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 93 | value = pnp_read_index(base, reg); |
| 94 | value &= 0xff & hwm_reg_values[i + 1]; |
| 95 | value |= 0xff & hwm_reg_values[i + 2]; |
| 96 | printk(BIOS_DEBUG, "base = 0x%04x, reg = 0x%02x, " |
| 97 | "value = 0x%02x\n", base, reg, value); |
Yinghai Lu | 12eb7bc | 2004-11-08 21:16:16 +0000 | [diff] [blame] | 98 | pnp_write_index(base, reg, value); |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | |
Edward O'Callaghan | f21bdc3 | 2014-10-21 07:43:41 +1100 | [diff] [blame] | 102 | static void w83627hf_init(struct device *dev) |
Ronald G. Minnich | 142babf | 2004-03-12 16:54:31 +0000 | [diff] [blame] | 103 | { |
Uwe Hermann | 5330dd9 | 2010-11-11 13:14:55 +0000 | [diff] [blame] | 104 | struct resource *res0; |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 105 | |
| 106 | if (!dev->enabled) |
Ronald G. Minnich | 142babf | 2004-03-12 16:54:31 +0000 | [diff] [blame] | 107 | return; |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 108 | |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 109 | switch(dev->path.pnp.device) { |
Ronald G. Minnich | 142babf | 2004-03-12 16:54:31 +0000 | [diff] [blame] | 110 | case W83627HF_KBC: |
Edward O'Callaghan | def00be | 2014-04-30 05:01:52 +1000 | [diff] [blame] | 111 | pc_keyboard_init(); |
Ronald G. Minnich | 142babf | 2004-03-12 16:54:31 +0000 | [diff] [blame] | 112 | break; |
Myles Watson | cee9438 | 2008-10-02 19:21:30 +0000 | [diff] [blame] | 113 | case W83627HF_HWM: |
| 114 | res0 = find_resource(dev, PNP_IDX_IO0); |
Yinghai Lu | 12eb7bc | 2004-11-08 21:16:16 +0000 | [diff] [blame] | 115 | #define HWM_INDEX_PORT 5 |
Myles Watson | cee9438 | 2008-10-02 19:21:30 +0000 | [diff] [blame] | 116 | init_hwm(res0->base + HWM_INDEX_PORT); |
| 117 | break; |
| 118 | case W83627HF_ACPI: |
| 119 | init_acpi(dev); |
| 120 | break; |
Ronald G. Minnich | 142babf | 2004-03-12 16:54:31 +0000 | [diff] [blame] | 121 | } |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Edward O'Callaghan | f21bdc3 | 2014-10-21 07:43:41 +1100 | [diff] [blame] | 124 | static void w83627hf_pnp_enable_resources(struct device *dev) |
Myles Watson | cee9438 | 2008-10-02 19:21:30 +0000 | [diff] [blame] | 125 | { |
Myles Watson | cee9438 | 2008-10-02 19:21:30 +0000 | [diff] [blame] | 126 | pnp_enable_resources(dev); |
Nico Huber | 13dc976 | 2013-06-15 19:33:15 +0200 | [diff] [blame] | 127 | |
| 128 | pnp_enter_conf_mode(dev); |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 129 | switch(dev->path.pnp.device) { |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 130 | case W83627HF_HWM: |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 131 | printk(BIOS_DEBUG, "W83627HF HWM SMBus enabled\n"); |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 132 | enable_hwm_smbus(dev); |
| 133 | break; |
| 134 | } |
Nico Huber | 13dc976 | 2013-06-15 19:33:15 +0200 | [diff] [blame] | 135 | pnp_exit_conf_mode(dev); |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Ronald G. Minnich | 142babf | 2004-03-12 16:54:31 +0000 | [diff] [blame] | 138 | static struct device_operations ops = { |
| 139 | .read_resources = pnp_read_resources, |
Nico Huber | 0b2ee93 | 2013-06-15 19:58:35 +0200 | [diff] [blame] | 140 | .set_resources = pnp_set_resources, |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 141 | .enable_resources = w83627hf_pnp_enable_resources, |
Nico Huber | 0b2ee93 | 2013-06-15 19:58:35 +0200 | [diff] [blame] | 142 | .enable = pnp_alt_enable, |
Yinghai Lu | 70093f7 | 2004-07-01 03:55:03 +0000 | [diff] [blame] | 143 | .init = w83627hf_init, |
Nico Huber | 1c81128 | 2013-06-15 20:33:44 +0200 | [diff] [blame] | 144 | .ops_pnp_mode = &pnp_conf_mode_8787_aa, |
Ronald G. Minnich | 142babf | 2004-03-12 16:54:31 +0000 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | static struct pnp_info pnp_dev_info[] = { |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 148 | { &ops, W83627HF_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x07f8, 0}, }, |
| 149 | { &ops, W83627HF_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, {0x07f8, 0}, }, |
| 150 | { &ops, W83627HF_SP1, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, }, |
| 151 | { &ops, W83627HF_SP2, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, }, |
| 152 | { &ops, W83627HF_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, {0x07ff, 0}, {0x07ff, 4}, }, |
| 153 | { &ops, W83627HF_CIR, PNP_IO0 | PNP_IRQ0, {0x07f8, 0}, }, |
| 154 | { &ops, W83627HF_GAME_MIDI_GPIO1, PNP_IO0 | PNP_IO1 | PNP_IRQ0, {0x07ff, 0}, {0x07fe, 4}, }, |
Myles Watson | cee9438 | 2008-10-02 19:21:30 +0000 | [diff] [blame] | 155 | { &ops, W83627HF_GPIO2, }, |
| 156 | { &ops, W83627HF_GPIO3, }, |
| 157 | { &ops, W83627HF_ACPI, }, |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 158 | { &ops, W83627HF_HWM, PNP_IO0 | PNP_IRQ0, {0x0ff8, 0}, }, |
Ronald G. Minnich | 142babf | 2004-03-12 16:54:31 +0000 | [diff] [blame] | 159 | }; |
| 160 | |
Yinghai Lu | 6a61d6a | 2004-10-20 05:07:16 +0000 | [diff] [blame] | 161 | static void enable_dev(struct device *dev) |
Ronald G. Minnich | 142babf | 2004-03-12 16:54:31 +0000 | [diff] [blame] | 162 | { |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 163 | pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info); |
Ronald G. Minnich | 142babf | 2004-03-12 16:54:31 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Yinghai Lu | 6a61d6a | 2004-10-20 05:07:16 +0000 | [diff] [blame] | 166 | struct chip_operations superio_winbond_w83627hf_ops = { |
Uwe Hermann | a7aa29b | 2006-11-05 18:50:49 +0000 | [diff] [blame] | 167 | CHIP_NAME("Winbond W83627HF Super I/O") |
Yinghai Lu | 6a61d6a | 2004-10-20 05:07:16 +0000 | [diff] [blame] | 168 | .enable_dev = enable_dev, |
Ronald G. Minnich | 142babf | 2004-03-12 16:54:31 +0000 | [diff] [blame] | 169 | }; |