Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2000 AG Electronics Ltd. |
| 5 | * Copyright (C) 2003-2004 Linux Networx |
Zheng Bao | 9db833b | 2009-12-28 09:59:44 +0000 | [diff] [blame] | 6 | * Copyright (C) 2004 Tyan |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 7 | * Copyright (C) 2007 AMD |
| 8 | * Written by Yinghai Lu <yinghai.lu@amd.com> for AMD. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 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. |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 20 | #include <device/device.h> |
| 21 | #include <device/pnp.h> |
Nico Huber | 1c81128 | 2013-06-15 20:33:44 +0200 | [diff] [blame] | 22 | #include <superio/conf_mode.h> |
Felix Held | 08abfa3 | 2019-10-07 19:41:57 +0200 | [diff] [blame] | 23 | #include <superio/hwm5_conf.h> |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 24 | #include <console/console.h> |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 25 | #include <pc80/keyboard.h> |
| 26 | #include <pc80/mc146818rtc.h> |
Carl-Daniel Hailfinger | 2ee6779 | 2008-10-01 12:52:52 +0000 | [diff] [blame] | 27 | #include <stdlib.h> |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 28 | #include "w83627ehg.h" |
| 29 | |
Edward O'Callaghan | f21bdc3 | 2014-10-21 07:43:41 +1100 | [diff] [blame] | 30 | static void enable_hwm_smbus(struct device *dev) |
Zheng Bao | 9db833b | 2009-12-28 09:59:44 +0000 | [diff] [blame] | 31 | { |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 32 | u8 reg8; |
| 33 | |
Elyes HAOUAS | 2b2325e | 2019-01-31 20:53:10 +0100 | [diff] [blame] | 34 | /* Configure pins 89/90 as SDA/SCL (I2C bus). */ |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 35 | reg8 = pnp_read_config(dev, 0x2a); |
| 36 | reg8 |= (1 << 1); |
| 37 | pnp_write_config(dev, 0x2a, reg8); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Edward O'Callaghan | f21bdc3 | 2014-10-21 07:43:41 +1100 | [diff] [blame] | 40 | static void init_acpi(struct device *dev) |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 41 | { |
Elyes HAOUAS | 09ec9e7 | 2016-10-17 21:51:12 +0200 | [diff] [blame] | 42 | u8 value; |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 43 | int power_on = 1; |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 44 | |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 45 | get_option(&power_on, "power_on_after_fail"); |
Nico Huber | 13dc976 | 2013-06-15 19:33:15 +0200 | [diff] [blame] | 46 | pnp_enter_conf_mode(dev); |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 47 | pnp_set_logical_device(dev); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 48 | value = pnp_read_config(dev, 0xe4); |
| 49 | value &= ~(3 << 5); |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 50 | if (power_on) |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 51 | value |= (1 << 5); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 52 | pnp_write_config(dev, 0xe4, value); |
Nico Huber | 13dc976 | 2013-06-15 19:33:15 +0200 | [diff] [blame] | 53 | pnp_exit_conf_mode(dev); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 56 | static void init_hwm(u16 base) |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 57 | { |
| 58 | int i; |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 59 | u8 reg, value; |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 60 | |
| 61 | /* reg mask data */ |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 62 | u8 hwm_reg_values[] = { |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 63 | 0x40, 0xff, 0x81, /* Start HWM. */ |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 64 | 0x48, 0x7f, 0x2a, /* Set SMBus base to 0x2a (0x54 >> 1). */ |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 67 | for (i = 0; i < ARRAY_SIZE(hwm_reg_values); i += 3) { |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 68 | reg = hwm_reg_values[i]; |
Felix Held | 08abfa3 | 2019-10-07 19:41:57 +0200 | [diff] [blame] | 69 | value = pnp_read_hwm5_index(base, reg); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 70 | value &= 0xff & (~(hwm_reg_values[i + 1])); |
| 71 | value |= 0xff & hwm_reg_values[i + 2]; |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 72 | printk(BIOS_DEBUG, "base = 0x%04x, reg = 0x%02x, " |
| 73 | "value = 0x%02x\n", base, reg, value); |
Felix Held | 08abfa3 | 2019-10-07 19:41:57 +0200 | [diff] [blame] | 74 | pnp_write_hwm5_index(base, reg, value); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
Edward O'Callaghan | f21bdc3 | 2014-10-21 07:43:41 +1100 | [diff] [blame] | 78 | static void w83627ehg_init(struct device *dev) |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 79 | { |
Uwe Hermann | 5330dd9 | 2010-11-11 13:14:55 +0000 | [diff] [blame] | 80 | struct resource *res0; |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 81 | |
| 82 | if (!dev->enabled) |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 83 | return; |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 84 | |
Elyes HAOUAS | 0ce41f1 | 2018-11-13 10:03:31 +0100 | [diff] [blame] | 85 | switch (dev->path.pnp.device) { |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 86 | case W83627EHG_KBC: |
Timothy Pearson | 448e386 | 2015-11-24 14:12:01 -0600 | [diff] [blame] | 87 | pc_keyboard_init(NO_AUX_DEVICE); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 88 | break; |
| 89 | case W83627EHG_HWM: |
| 90 | res0 = find_resource(dev, PNP_IDX_IO0); |
Felix Held | 08abfa3 | 2019-10-07 19:41:57 +0200 | [diff] [blame] | 91 | init_hwm(res0->base); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 92 | break; |
| 93 | case W83627EHG_ACPI: |
| 94 | init_acpi(dev); |
| 95 | break; |
| 96 | } |
| 97 | } |
| 98 | |
Edward O'Callaghan | f21bdc3 | 2014-10-21 07:43:41 +1100 | [diff] [blame] | 99 | static void w83627ehg_pnp_enable_resources(struct device *dev) |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 100 | { |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 101 | pnp_enable_resources(dev); |
| 102 | |
Nico Huber | 13dc976 | 2013-06-15 19:33:15 +0200 | [diff] [blame] | 103 | pnp_enter_conf_mode(dev); |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 104 | switch (dev->path.pnp.device) { |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 105 | case W83627EHG_HWM: |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 106 | printk(BIOS_DEBUG, "W83627EHG HWM SMBus enabled\n"); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 107 | enable_hwm_smbus(dev); |
| 108 | break; |
| 109 | } |
Nico Huber | 13dc976 | 2013-06-15 19:33:15 +0200 | [diff] [blame] | 110 | pnp_exit_conf_mode(dev); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 113 | static struct device_operations ops = { |
| 114 | .read_resources = pnp_read_resources, |
Nico Huber | 0b2ee93 | 2013-06-15 19:58:35 +0200 | [diff] [blame] | 115 | .set_resources = pnp_set_resources, |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 116 | .enable_resources = w83627ehg_pnp_enable_resources, |
Nico Huber | 0b2ee93 | 2013-06-15 19:58:35 +0200 | [diff] [blame] | 117 | .enable = pnp_alt_enable, |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 118 | .init = w83627ehg_init, |
Nico Huber | 1c81128 | 2013-06-15 20:33:44 +0200 | [diff] [blame] | 119 | .ops_pnp_mode = &pnp_conf_mode_8787_aa, |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | static struct pnp_info pnp_dev_info[] = { |
Felix Held | 8c85880 | 2018-07-06 20:22:08 +0200 | [diff] [blame] | 123 | { NULL, W83627EHG_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, 0x07f8, }, |
| 124 | { NULL, W83627EHG_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, 0x07f8, }, |
| 125 | { NULL, W83627EHG_SP1, PNP_IO0 | PNP_IRQ0, 0x07f8, }, |
| 126 | { NULL, W83627EHG_SP2, PNP_IO0 | PNP_IRQ0, 0x07f8, }, |
| 127 | { NULL, W83627EHG_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, |
| 128 | 0x07ff, 0x07ff, }, |
| 129 | { NULL, W83627EHG_SFI, PNP_IO0 | PNP_IRQ0, 0x07f8, }, |
| 130 | { NULL, W83627EHG_WDTO_PLED, }, |
| 131 | { NULL, W83627EHG_ACPI, PNP_IRQ0, }, |
| 132 | { NULL, W83627EHG_HWM, PNP_IO0 | PNP_IRQ0, 0x07fe, }, |
Uwe Hermann | 3a4ed15 | 2010-12-05 22:36:14 +0000 | [diff] [blame] | 133 | |
Felix Held | 8c85880 | 2018-07-06 20:22:08 +0200 | [diff] [blame] | 134 | { NULL, W83627EHG_GAME, PNP_IO0, 0x07ff, }, |
| 135 | { NULL, W83627EHG_MIDI, PNP_IO1 | PNP_IRQ0, 0, 0x07fe, }, |
| 136 | { NULL, W83627EHG_GPIO1, }, |
| 137 | { NULL, W83627EHG_GPIO2, }, |
| 138 | { NULL, W83627EHG_GPIO3, }, |
| 139 | { NULL, W83627EHG_GPIO4, }, |
| 140 | { NULL, W83627EHG_GPIO5, }, |
| 141 | { NULL, W83627EHG_GPIO6, }, |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | static void enable_dev(struct device *dev) |
| 145 | { |
Uwe Hermann | 340fa93 | 2010-11-10 14:53:36 +0000 | [diff] [blame] | 146 | pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info); |
Yinghai Lu | bc7ceb1 | 2007-02-03 15:28:20 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | struct chip_operations superio_winbond_w83627ehg_ops = { |
| 150 | CHIP_NAME("Winbond W83627EHG Super I/O") |
| 151 | .enable_dev = enable_dev, |
| 152 | }; |