coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
superio.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pnp.h>
6 #include <pc80/keyboard.h>
7 #include <option.h>
8 #include <superio/conf_mode.h>
9 
10 #include "w83667hg-a.h"
11 
12 #define MAINBOARD_POWER_OFF 0
13 #define MAINBOARD_POWER_ON 1
14 #define MAINBOARD_POWER_KEEP 2
15 
16 static void w83667hg_a_init(struct device *dev)
17 {
18  uint8_t byte;
19  uint8_t power_status;
20  uint8_t mouse_detected;
21 
22  if (!dev->enabled)
23  return;
24 
25  switch (dev->path.pnp.device) {
26  /* TODO: Might potentially need code for HWM or FDC etc. */
27  case W83667HG_A_KBC:
28  /* Enable mouse controller */
30  byte = pnp_read_config(dev, 0x2a);
31  byte &= ~(0x1 << 1);
32  pnp_write_config(dev, 0x2a, byte);
33  pnp_exit_conf_mode(dev);
34 
35  mouse_detected = pc_keyboard_init(PROBE_AUX_DEVICE);
36 
37  if (!mouse_detected) {
38  printk(BIOS_INFO, "%s: Disable mouse controller.\n",
39  __func__);
41  byte = pnp_read_config(dev, 0x2a);
42  byte |= 0x1 << 1;
43  pnp_write_config(dev, 0x2a, byte);
44  pnp_exit_conf_mode(dev);
45  }
46  break;
47  case W83667HG_A_ACPI:
48  /* Set power state after power fail */
49  power_status = get_uint_option("power_on_after_fail",
50  CONFIG_MAINBOARD_POWER_FAILURE_STATE);
53  byte = pnp_read_config(dev, 0xe4);
54  byte &= ~0x60;
55  if (power_status == MAINBOARD_POWER_ON)
56  byte |= (0x1 << 5);
57  else if (power_status == MAINBOARD_POWER_KEEP)
58  byte |= (0x2 << 5);
59  pnp_write_config(dev, 0xe4, byte);
60  pnp_exit_conf_mode(dev);
61  printk(BIOS_INFO, "set power %s after power fail\n", power_status ? "on" : "off");
62  break;
63  }
64 }
65 
66 static struct device_operations ops = {
68  .set_resources = pnp_set_resources,
69  .enable_resources = pnp_enable_resources,
70  .enable = pnp_alt_enable,
71  .init = w83667hg_a_init,
72  .ops_pnp_mode = &pnp_conf_mode_8787_aa,
73 };
74 
75 static struct pnp_info pnp_dev_info[] = {
76  { NULL, W83667HG_A_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, 0x0ff8, },
77  { NULL, W83667HG_A_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, 0x0ff8, },
78  { NULL, W83667HG_A_SP1, PNP_IO0 | PNP_IRQ0, 0x0ff8, },
79  { NULL, W83667HG_A_SP2, PNP_IO0 | PNP_IRQ0, 0x0ff8, },
81  0x0fff, 0x0fff, },
82  { NULL, W83667HG_A_SPI1, PNP_IO1, 0, 0x0ff8},
85  { NULL, W83667HG_A_HWM_TSI, PNP_IO0 | PNP_IRQ0, 0x0ffe, },
98 };
99 
100 static void enable_dev(struct device *dev)
101 {
103 }
104 
106  CHIP_NAME("WINBOND W83667HG-A Super I/O")
107  .enable_dev = enable_dev,
108 };
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define printk(level,...)
Definition: stdlib.h:16
const struct pnp_mode_ops pnp_conf_mode_8787_aa
Definition: conf_mode.c:202
#define CHIP_NAME(X)
Definition: device.h:32
uint8_t pc_keyboard_init(uint8_t probe_aux)
Definition: keyboard.c:229
#define PROBE_AUX_DEVICE
Definition: keyboard.h:7
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
unsigned int get_uint_option(const char *name, const unsigned int fallback)
Definition: option.c:116
#define PNP_IRQ1
Definition: pnp.h:48
#define PNP_DRQ0
Definition: pnp.h:49
#define PNP_IO1
Definition: pnp.h:43
#define PNP_IO0
Definition: pnp.h:42
#define PNP_IRQ0
Definition: pnp.h:47
void pnp_exit_conf_mode(struct device *dev)
Definition: pnp_device.c:17
void pnp_read_resources(struct device *dev)
Definition: pnp_device.c:114
void pnp_enable_devices(struct device *base_dev, struct device_operations *ops, unsigned int functions, struct pnp_info *info)
Definition: pnp_device.c:371
void pnp_set_logical_device(struct device *dev)
Definition: pnp_device.c:59
void pnp_set_resources(struct device *dev)
Definition: pnp_device.c:157
void pnp_alt_enable(struct device *dev)
Definition: pnp_device.c:191
u8 pnp_read_config(struct device *dev, u8 reg)
Definition: pnp_device.c:44
void pnp_enter_conf_mode(struct device *dev)
Definition: pnp_device.c:11
void pnp_write_config(struct device *dev, u8 reg, u8 value)
Definition: pnp_device.c:38
void pnp_enable_resources(struct device *dev)
Definition: pnp_device.c:173
#define NULL
Definition: stddef.h:19
unsigned char uint8_t
Definition: stdint.h:8
void(* read_resources)(struct device *dev)
Definition: device.h:39
struct pnp_path pnp
Definition: path.h:117
Definition: device.h:107
struct device_path path
Definition: device.h:115
unsigned int enabled
Definition: device.h:122
Definition: pnp.h:37
unsigned int device
Definition: path.h:59
#define W83667HG_A_SP2
Definition: w83667hg-a.h:17
#define W83667HG_A_GPIO1
Definition: w83667hg-a.h:31
#define W83667HG_A_GPIO5
Definition: w83667hg-a.h:35
#define W83667HG_A_KBC
Definition: w83667hg-a.h:18
#define W83667HG_A_SP1
Definition: w83667hg-a.h:16
#define W83667HG_A_GPIO7
Definition: w83667hg-a.h:37
#define W83667HG_A_WDT1
Definition: w83667hg-a.h:21
#define W83667HG_A_GPIO_PP_OD
Definition: w83667hg-a.h:27
#define W83667HG_A_PECI
Definition: w83667hg-a.h:25
#define W83667HG_A_PP
Definition: w83667hg-a.h:15
#define W83667HG_A_GPIO2
Definition: w83667hg-a.h:32
#define W83667HG_A_GPIO3
Definition: w83667hg-a.h:33
#define W83667HG_A_SPI1
Definition: w83667hg-a.h:30
#define W83667HG_A_GPIO9
Definition: w83667hg-a.h:39
#define W83667HG_A_GPIO4
Definition: w83667hg-a.h:34
#define W83667HG_A_GPIO6
Definition: w83667hg-a.h:36
#define W83667HG_A_VID_BUSSEL
Definition: w83667hg-a.h:26
#define W83667HG_A_FDC
Definition: w83667hg-a.h:14
#define W83667HG_A_ACPI
Definition: w83667hg-a.h:23
#define W83667HG_A_GPIO8
Definition: w83667hg-a.h:38
#define W83667HG_A_HWM_TSI
Definition: w83667hg-a.h:24
#define MAINBOARD_POWER_ON
Definition: superio.c:13
static void w83667hg_a_init(struct device *dev)
Definition: superio.c:16
static void enable_dev(struct device *dev)
Definition: superio.c:100
static struct device_operations ops
Definition: superio.c:66
struct chip_operations superio_winbond_w83667hg_a_ops
Definition: superio.c:105
static struct pnp_info pnp_dev_info[]
Definition: superio.c:75
#define MAINBOARD_POWER_KEEP
Definition: superio.c:14