blob: 03dce827cb676b21202ba8f2017b3a12bbdb150f [file] [log] [blame]
Felix Held3f3eca92020-01-23 17:12:32 +01001/* SPDX-License-Identifier: GPL-2.0-only */
Yinghai Lubc7ceb12007-02-03 15:28:20 +00002
Yinghai Lubc7ceb12007-02-03 15:28:20 +00003#include <device/device.h>
4#include <device/pnp.h>
Nico Huber1c811282013-06-15 20:33:44 +02005#include <superio/conf_mode.h>
Felix Held08abfa32019-10-07 19:41:57 +02006#include <superio/hwm5_conf.h>
Yinghai Lubc7ceb12007-02-03 15:28:20 +00007#include <console/console.h>
Yinghai Lubc7ceb12007-02-03 15:28:20 +00008#include <pc80/keyboard.h>
Kyösti Mälkkicbf95712020-01-05 08:05:45 +02009#include <option.h>
Elyes HAOUAS2329a252019-05-15 22:11:18 +020010
Yinghai Lubc7ceb12007-02-03 15:28:20 +000011#include "w83627ehg.h"
12
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +110013static void enable_hwm_smbus(struct device *dev)
Zheng Bao9db833b2009-12-28 09:59:44 +000014{
Uwe Hermann340fa932010-11-10 14:53:36 +000015 u8 reg8;
16
Elyes HAOUAS2b2325e2019-01-31 20:53:10 +010017 /* Configure pins 89/90 as SDA/SCL (I2C bus). */
Uwe Hermann340fa932010-11-10 14:53:36 +000018 reg8 = pnp_read_config(dev, 0x2a);
19 reg8 |= (1 << 1);
20 pnp_write_config(dev, 0x2a, reg8);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000021}
22
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +110023static void init_acpi(struct device *dev)
Yinghai Lubc7ceb12007-02-03 15:28:20 +000024{
Elyes HAOUAS09ec9e72016-10-17 21:51:12 +020025 u8 value;
Angel Pons88dcb312021-04-26 17:10:28 +020026 unsigned int power_on = get_uint_option("power_on_after_fail", 1);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000027
Nico Huber13dc9762013-06-15 19:33:15 +020028 pnp_enter_conf_mode(dev);
Uwe Hermann340fa932010-11-10 14:53:36 +000029 pnp_set_logical_device(dev);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000030 value = pnp_read_config(dev, 0xe4);
31 value &= ~(3 << 5);
Uwe Hermann340fa932010-11-10 14:53:36 +000032 if (power_on)
Yinghai Lubc7ceb12007-02-03 15:28:20 +000033 value |= (1 << 5);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000034 pnp_write_config(dev, 0xe4, value);
Nico Huber13dc9762013-06-15 19:33:15 +020035 pnp_exit_conf_mode(dev);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000036}
37
Uwe Hermann340fa932010-11-10 14:53:36 +000038static void init_hwm(u16 base)
Yinghai Lubc7ceb12007-02-03 15:28:20 +000039{
40 int i;
Uwe Hermann340fa932010-11-10 14:53:36 +000041 u8 reg, value;
Yinghai Lubc7ceb12007-02-03 15:28:20 +000042
43 /* reg mask data */
Uwe Hermann340fa932010-11-10 14:53:36 +000044 u8 hwm_reg_values[] = {
Yinghai Lubc7ceb12007-02-03 15:28:20 +000045 0x40, 0xff, 0x81, /* Start HWM. */
Uwe Hermann340fa932010-11-10 14:53:36 +000046 0x48, 0x7f, 0x2a, /* Set SMBus base to 0x2a (0x54 >> 1). */
Yinghai Lubc7ceb12007-02-03 15:28:20 +000047 };
48
Uwe Hermann340fa932010-11-10 14:53:36 +000049 for (i = 0; i < ARRAY_SIZE(hwm_reg_values); i += 3) {
Yinghai Lubc7ceb12007-02-03 15:28:20 +000050 reg = hwm_reg_values[i];
Felix Held08abfa32019-10-07 19:41:57 +020051 value = pnp_read_hwm5_index(base, reg);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000052 value &= 0xff & (~(hwm_reg_values[i + 1]));
53 value |= 0xff & hwm_reg_values[i + 2];
Uwe Hermann340fa932010-11-10 14:53:36 +000054 printk(BIOS_DEBUG, "base = 0x%04x, reg = 0x%02x, "
55 "value = 0x%02x\n", base, reg, value);
Felix Held08abfa32019-10-07 19:41:57 +020056 pnp_write_hwm5_index(base, reg, value);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000057 }
58}
59
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +110060static void w83627ehg_init(struct device *dev)
Yinghai Lubc7ceb12007-02-03 15:28:20 +000061{
Uwe Hermann5330dd92010-11-11 13:14:55 +000062 struct resource *res0;
Uwe Hermann340fa932010-11-10 14:53:36 +000063
64 if (!dev->enabled)
Yinghai Lubc7ceb12007-02-03 15:28:20 +000065 return;
Uwe Hermann340fa932010-11-10 14:53:36 +000066
Elyes HAOUAS0ce41f12018-11-13 10:03:31 +010067 switch (dev->path.pnp.device) {
Yinghai Lubc7ceb12007-02-03 15:28:20 +000068 case W83627EHG_KBC:
Timothy Pearson448e3862015-11-24 14:12:01 -060069 pc_keyboard_init(NO_AUX_DEVICE);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000070 break;
71 case W83627EHG_HWM:
72 res0 = find_resource(dev, PNP_IDX_IO0);
Felix Held08abfa32019-10-07 19:41:57 +020073 init_hwm(res0->base);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000074 break;
75 case W83627EHG_ACPI:
76 init_acpi(dev);
77 break;
78 }
79}
80
Edward O'Callaghanf21bdc32014-10-21 07:43:41 +110081static void w83627ehg_pnp_enable_resources(struct device *dev)
Yinghai Lubc7ceb12007-02-03 15:28:20 +000082{
Yinghai Lubc7ceb12007-02-03 15:28:20 +000083 pnp_enable_resources(dev);
84
Nico Huber13dc9762013-06-15 19:33:15 +020085 pnp_enter_conf_mode(dev);
Stefan Reinauer2b34db82009-02-28 20:10:20 +000086 switch (dev->path.pnp.device) {
Yinghai Lubc7ceb12007-02-03 15:28:20 +000087 case W83627EHG_HWM:
Uwe Hermann340fa932010-11-10 14:53:36 +000088 printk(BIOS_DEBUG, "W83627EHG HWM SMBus enabled\n");
Yinghai Lubc7ceb12007-02-03 15:28:20 +000089 enable_hwm_smbus(dev);
90 break;
91 }
Nico Huber13dc9762013-06-15 19:33:15 +020092 pnp_exit_conf_mode(dev);
Yinghai Lubc7ceb12007-02-03 15:28:20 +000093}
94
Yinghai Lubc7ceb12007-02-03 15:28:20 +000095static struct device_operations ops = {
96 .read_resources = pnp_read_resources,
Nico Huber0b2ee932013-06-15 19:58:35 +020097 .set_resources = pnp_set_resources,
Yinghai Lubc7ceb12007-02-03 15:28:20 +000098 .enable_resources = w83627ehg_pnp_enable_resources,
Nico Huber0b2ee932013-06-15 19:58:35 +020099 .enable = pnp_alt_enable,
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000100 .init = w83627ehg_init,
Nico Huber1c811282013-06-15 20:33:44 +0200101 .ops_pnp_mode = &pnp_conf_mode_8787_aa,
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000102};
103
104static struct pnp_info pnp_dev_info[] = {
Felix Held8c858802018-07-06 20:22:08 +0200105 { NULL, W83627EHG_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, 0x07f8, },
106 { NULL, W83627EHG_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, 0x07f8, },
107 { NULL, W83627EHG_SP1, PNP_IO0 | PNP_IRQ0, 0x07f8, },
108 { NULL, W83627EHG_SP2, PNP_IO0 | PNP_IRQ0, 0x07f8, },
109 { NULL, W83627EHG_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1,
110 0x07ff, 0x07ff, },
111 { NULL, W83627EHG_SFI, PNP_IO0 | PNP_IRQ0, 0x07f8, },
112 { NULL, W83627EHG_WDTO_PLED, },
113 { NULL, W83627EHG_ACPI, PNP_IRQ0, },
114 { NULL, W83627EHG_HWM, PNP_IO0 | PNP_IRQ0, 0x07fe, },
Uwe Hermann3a4ed152010-12-05 22:36:14 +0000115
Felix Held8c858802018-07-06 20:22:08 +0200116 { NULL, W83627EHG_GAME, PNP_IO0, 0x07ff, },
117 { NULL, W83627EHG_MIDI, PNP_IO1 | PNP_IRQ0, 0, 0x07fe, },
118 { NULL, W83627EHG_GPIO1, },
119 { NULL, W83627EHG_GPIO2, },
120 { NULL, W83627EHG_GPIO3, },
121 { NULL, W83627EHG_GPIO4, },
122 { NULL, W83627EHG_GPIO5, },
123 { NULL, W83627EHG_GPIO6, },
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000124};
125
126static void enable_dev(struct device *dev)
127{
Uwe Hermann340fa932010-11-10 14:53:36 +0000128 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000129}
130
131struct chip_operations superio_winbond_w83627ehg_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900132 .name = "Winbond W83627EHG Super I/O",
Yinghai Lubc7ceb12007-02-03 15:28:20 +0000133 .enable_dev = enable_dev,
134};