1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <device/device.h>
4 #include <device/pnp.h>
5 #include <superio/conf_mode.h>
6 #include <superio/hwm5_conf.h>
7 #include <console/console.h>
8 #include <pc80/keyboard.h>
11 #include "w83627ehg.h"
13 static void enable_hwm_smbus(struct device
*dev
)
17 /* Configure pins 89/90 as SDA/SCL (I2C bus). */
18 reg8
= pnp_read_config(dev
, 0x2a);
20 pnp_write_config(dev
, 0x2a, reg8
);
23 static void init_acpi(struct device
*dev
)
26 unsigned int power_on
= get_uint_option("power_on_after_fail", 1);
28 pnp_enter_conf_mode(dev
);
29 pnp_set_logical_device(dev
);
30 value
= pnp_read_config(dev
, 0xe4);
34 pnp_write_config(dev
, 0xe4, value
);
35 pnp_exit_conf_mode(dev
);
38 static void init_hwm(u16 base
)
44 u8 hwm_reg_values
[] = {
45 0x40, 0xff, 0x81, /* Start HWM. */
46 0x48, 0x7f, 0x2a, /* Set SMBus base to 0x2a (0x54 >> 1). */
49 for (i
= 0; i
< ARRAY_SIZE(hwm_reg_values
); i
+= 3) {
50 reg
= hwm_reg_values
[i
];
51 value
= pnp_read_hwm5_index(base
, reg
);
52 value
&= 0xff & (~(hwm_reg_values
[i
+ 1]));
53 value
|= 0xff & hwm_reg_values
[i
+ 2];
54 printk(BIOS_DEBUG
, "base = 0x%04x, reg = 0x%02x, "
55 "value = 0x%02x\n", base
, reg
, value
);
56 pnp_write_hwm5_index(base
, reg
, value
);
60 static void w83627ehg_init(struct device
*dev
)
62 struct resource
*res0
;
67 switch (dev
->path
.pnp
.device
) {
69 pc_keyboard_init(NO_AUX_DEVICE
);
72 res0
= find_resource(dev
, PNP_IDX_IO0
);
81 static void w83627ehg_pnp_enable_resources(struct device
*dev
)
83 pnp_enable_resources(dev
);
85 pnp_enter_conf_mode(dev
);
86 switch (dev
->path
.pnp
.device
) {
88 printk(BIOS_DEBUG
, "W83627EHG HWM SMBus enabled\n");
89 enable_hwm_smbus(dev
);
92 pnp_exit_conf_mode(dev
);
95 static struct device_operations ops
= {
96 .read_resources
= pnp_read_resources
,
97 .set_resources
= pnp_set_resources
,
98 .enable_resources
= w83627ehg_pnp_enable_resources
,
99 .enable
= pnp_alt_enable
,
100 .init
= w83627ehg_init
,
101 .ops_pnp_mode
= &pnp_conf_mode_8787_aa
,
104 static struct pnp_info pnp_dev_info
[] = {
105 { 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
,
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, },
116 { 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
, },
126 static void enable_dev(struct device
*dev
)
128 pnp_enable_devices(dev
, &ops
, ARRAY_SIZE(pnp_dev_info
), pnp_dev_info
);
131 struct chip_operations superio_winbond_w83627ehg_ops
= {
132 CHIP_NAME("Winbond W83627EHG Super I/O")
133 .enable_dev
= enable_dev
,