coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
early_init.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 /*
4  * A generic romstage (pre-ram) driver for various Winbond Super I/O chips.
5  *
6  * The following is derived directly from the vendor Winbond's data-sheets:
7  *
8  * To toggle between `configuration mode` and `normal operation mode` as to
9  * manipulation the various LDN's in Winbond Super I/O's we are required to
10  * pass magic numbers `passwords keys`.
11  *
12  * WINBOUND_ENTRY_KEY := enable configuration : 0x87
13  * WINBOUND_EXIT_KEY := disable configuration : 0xAA
14  *
15  * To modify a LDN's configuration register, we use the index port to select
16  * the index of the LDN and then write to the data port to alter the
17  * parameters. A default index, data port pair is 0x4E, 0x4F respectively, a
18  * user modified pair is 0x2E, 0x2F respectively.
19  *
20  */
21 
22 #include <arch/io.h>
23 #include <device/pnp_ops.h>
24 #include <device/pnp.h>
25 #include <stdint.h>
26 #include "winbond.h"
27 
28 #define WINBOND_ENTRY_KEY 0x87
29 #define WINBOND_EXIT_KEY 0xAA
30 
31 /* Enable configuration: pass entry key '0x87' into index port dev. */
33 {
34  u16 port = dev >> 8;
37 }
38 
39 /* Disable configuration: pass exit key '0xAA' into index port dev. */
41 {
42  u16 port = dev >> 8;
44 }
45 
46 /* Bring up early serial debugging output before the RAM is initialized. */
48 {
51  pnp_set_enable(dev, 0);
52  pnp_set_iobase(dev, PNP_IDX_IO0, iobase);
53  pnp_set_enable(dev, 1);
55 }
56 
58 {
59  uint8_t byte;
60 
61  /* Configure pin mux */
63  byte = pnp_read_config(dev, offset);
64  byte &= ~mask;
65  byte |= state;
66  pnp_write_config(dev, offset, byte);
68 }
69 
71 {
72  u8 reg8;
73 
75  reg8 = pnp_read_config(dev, 0x24);
76  reg8 |= (1 << 6); /* Set the clock input to 48MHz. */
77  pnp_write_config(dev, 0x24, reg8);
79 }
void outb(u8 val, u16 port)
static size_t offset
Definition: flashconsole.c:16
port
Definition: i915.h:29
state
Definition: raminit.c:1787
#define PNP_IDX_IO0
Definition: pnp_def.h:5
void pnp_set_logical_device(struct device *dev)
Definition: pnp_device.c:59
void pnp_set_enable(struct device *dev, int enable)
Definition: pnp_device.c:64
u8 pnp_read_config(struct device *dev, u8 reg)
Definition: pnp_device.c:44
void pnp_set_iobase(struct device *dev, u8 index, u16 iobase)
Definition: pnp_device.c:93
void pnp_write_config(struct device *dev, u8 reg, u8 value)
Definition: pnp_device.c:38
u32 pnp_devfn_t
Definition: pnp_type.h:8
static const int mask[4]
Definition: gpio.c:308
uint16_t u16
Definition: stdint.h:48
uint8_t u8
Definition: stdint.h:45
unsigned char uint8_t
Definition: stdint.h:8
void winbond_enable_serial(pnp_devfn_t dev, u16 iobase)
Definition: early_init.c:47
void winbond_set_pinmux(pnp_devfn_t dev, uint8_t offset, uint8_t mask, uint8_t state)
Definition: early_init.c:57
void pnp_exit_conf_state(pnp_devfn_t dev)
Definition: early_init.c:40
#define WINBOND_ENTRY_KEY
Definition: early_init.c:28
void pnp_enter_conf_state(pnp_devfn_t dev)
Definition: early_init.c:32
#define WINBOND_EXIT_KEY
Definition: early_init.c:29
void winbond_set_clksel_48(pnp_devfn_t dev)
Definition: early_init.c:70