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-only */
2 
3 #include <bootblock_common.h>
4 #include <device/pci_ops.h>
5 #include <device/pnp_ops.h>
6 #include <device/pnp_def.h>
7 #include <option.h>
12 
13 /* Override the default lpc decode ranges */
15 {
16  int lpt_en = 0;
17 
18  if (get_uint_option("lpt", 0))
19  lpt_en = LPT_LPC_EN; /* enable LPT */
20 
21  pci_update_config16(PCI_DEV(0, 0x1f, 0), LPC_EN, ~LPT_LPC_EN, lpt_en);
22 }
23 
24 /* This box has two superios, so enabling serial becomes slightly excessive.
25  * We disable a lot of stuff to make sure that there are no conflicts between
26  * the two. Also set up the GPIOs from the beginning. This is the "no schematic
27  * but safe anyways" method.
28  */
30 {
31  pnp_devfn_t dev;
32 
33  dev = PNP_DEV(0x2e, W83627THG_SP1);
35 
36  pnp_write_config(dev, 0x24, 0xc6); /* PNPCSV */
37 
38  pnp_write_config(dev, 0x29, 0x43); /* GPIO settings */
39  pnp_write_config(dev, 0x2a, 0x40); /* GPIO settings */
40 
41  dev = PNP_DEV(0x2e, W83627THG_SP1);
43  pnp_set_enable(dev, 0);
44  pnp_set_iobase(dev, PNP_IDX_IO0, 0x3f8);
45  pnp_set_irq(dev, PNP_IDX_IRQ0, 4);
46  pnp_set_enable(dev, 1);
47 
48  dev = PNP_DEV(0x2e, W83627THG_SP2);
50  pnp_set_enable(dev, 0);
51  pnp_set_iobase(dev, PNP_IDX_IO0, 0x2f8);
52  pnp_set_irq(dev, PNP_IDX_IRQ0, 3);
53  pnp_set_enable(dev, 1);
54 
55  dev = PNP_DEV(0x2e, W83627THG_KBC);
57  pnp_set_enable(dev, 0);
58  pnp_set_iobase(dev, PNP_IDX_IO0, 0x60);
59  pnp_set_iobase(dev, PNP_IDX_IO1, 0x64);
60  pnp_set_enable(dev, 1);
61 
64  pnp_set_enable(dev, 0);
65  pnp_write_config(dev, PNP_IDX_MSC5, 0xff); /* invert all GPIOs */
66  pnp_set_enable(dev, 1);
67 
68  dev = PNP_DEV(0x2e, W83627THG_GPIO2);
70  pnp_set_enable(dev, 1); /* Just enable it */
71 
72  dev = PNP_DEV(0x2e, W83627THG_GPIO3);
74  pnp_set_enable(dev, 0);
75  pnp_write_config(dev, PNP_IDX_MSC0, 0xfb); /* GPIO bit 2 is output */
76  pnp_write_config(dev, PNP_IDX_MSC1, 0x00); /* GPIO bit 2 is 0 */
77  /* Enable GPIO3+4. pnp_set_enable is not sufficient */
78  pnp_write_config(dev, PNP_IDX_EN, 0x03);
79 
80  dev = PNP_DEV(0x2e, W83627THG_FDC);
82  pnp_set_enable(dev, 0);
83 
84  dev = PNP_DEV(0x2e, W83627THG_PP);
86  pnp_set_enable(dev, 0);
87 
88  /* Enable HWM */
89  dev = PNP_DEV(0x2e, W83627THG_HWM);
91  pnp_set_enable(dev, 0);
92  pnp_set_iobase(dev, PNP_IDX_IO0, 0xa00);
93  pnp_set_enable(dev, 1);
94 
96 
97  dev = PNP_DEV(0x4e, W83627THG_SP1);
99 
100  pnp_set_logical_device(dev); /* Set COM3 to sane non-conflicting values */
101  pnp_set_enable(dev, 0);
102  pnp_set_iobase(dev, PNP_IDX_IO0, 0x3e8);
103  pnp_set_irq(dev, PNP_IDX_IRQ0, 11);
104  pnp_set_enable(dev, 1);
105 
106  dev = PNP_DEV(0x4e, W83627THG_SP2);
107  pnp_set_logical_device(dev); /* Set COM4 to sane non-conflicting values */
108  pnp_set_enable(dev, 0);
109  pnp_set_iobase(dev, PNP_IDX_IO0, 0x2e8);
110  pnp_set_irq(dev, PNP_IDX_IRQ0, 10);
111  pnp_set_enable(dev, 1);
112 
113  dev = PNP_DEV(0x4e, W83627THG_FDC);
115  pnp_set_enable(dev, 0);
116 
117  dev = PNP_DEV(0x4e, W83627THG_PP);
119  pnp_set_enable(dev, 0);
120 
121  dev = PNP_DEV(0x4e, W83627THG_KBC);
123  pnp_set_enable(dev, 0);
124  pnp_set_iobase(dev, PNP_IDX_IO0, 0x00);
125  pnp_set_iobase(dev, PNP_IDX_IO1, 0x00);
126 
127  pnp_exit_conf_state(dev);
128 }
129 
131 {
132  /* Device 1f interrupt pin register */
133  RCBA32(D31IP) = 0x00042210;
134  /* Device 1d interrupt pin register */
135  RCBA32(D28IP) = 0x00214321;
136 
137  /* dev irq route register */
138  RCBA16(D31IR) = 0x0132;
139  RCBA16(D30IR) = 0x3241;
140  RCBA16(D29IR) = 0x0237;
141  RCBA16(D28IR) = 0x3210;
142  RCBA16(D27IR) = 0x3210;
143 
144  /* Enable PCIe Root Port Clock Gate */
145 }
static __always_inline void pci_update_config16(const struct device *dev, u16 reg, u16 mask, u16 or)
Definition: pci_ops.h:104
void bootblock_mainboard_early_init(void)
Definition: early_init.c:11
void mainboard_late_rcba_config(void)
Definition: early_init.c:6
void mainboard_lpc_decode(void)
Definition: early_init.c:34
unsigned int get_uint_option(const char *name, const unsigned int fallback)
Definition: option.c:116
#define PCI_DEV(SEGBUS, DEV, FN)
Definition: pci_type.h:14
#define PNP_IDX_MSC0
Definition: pnp_def.h:14
#define PNP_IDX_MSC5
Definition: pnp_def.h:19
#define PNP_IDX_EN
Definition: pnp_def.h:4
#define PNP_IDX_MSC1
Definition: pnp_def.h:15
#define PNP_IDX_IO0
Definition: pnp_def.h:5
#define PNP_IDX_IO1
Definition: pnp_def.h:6
#define PNP_IDX_IRQ0
Definition: pnp_def.h:10
void pnp_set_irq(struct device *dev, u8 index, u8 irq)
Definition: pnp_device.c:100
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
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
#define PNP_DEV(PORT, FUNC)
Definition: pnp_type.h:10
u32 pnp_devfn_t
Definition: pnp_type.h:8
#define LPT_LPC_EN
Definition: lpc.h:44
#define LPC_EN
Definition: lpc.h:36
#define D31IR
Definition: rcba.h:87
#define D30IR
Definition: rcba.h:88
#define D28IR
Definition: rcba.h:90
#define D31IP
Definition: rcba.h:56
#define D29IR
Definition: rcba.h:89
#define D27IR
Definition: rcba.h:91
#define D28IP
Definition: rcba.h:65
#define RCBA16(x)
Definition: rcba.h:13
#define RCBA32(x)
Definition: rcba.h:14
void pnp_exit_conf_state(pnp_devfn_t dev)
Definition: early_init.c:40
void pnp_enter_conf_state(pnp_devfn_t dev)
Definition: early_init.c:32
#define W83627THG_GPIO2
Definition: w83627thg.h:14
#define W83627THG_KBC
Definition: w83627thg.h:12
#define W83627THG_GPIO3
Definition: w83627thg.h:15
#define W83627THG_SP1
Definition: w83627thg.h:10
#define W83627THG_GAME_MIDI_GPIO1
Definition: w83627thg.h:13
#define W83627THG_HWM
Definition: w83627thg.h:17
#define W83627THG_SP2
Definition: w83627thg.h:11
#define W83627THG_PP
Definition: w83627thg.h:9
#define W83627THG_FDC
Definition: w83627thg.h:8