1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright 2019 Google LLC
8 #include <dt-structs.h>
10 #include <asm/intel_pinctrl.h>
11 #include <asm/intel_regs.h>
13 #include <asm/arch/systemagent.h>
16 * struct apl_hostbridge_platdata - platform data for hostbridge
18 * @dtplat: Platform data for of-platdata
19 * @early_pads: Early pad data to set up, each (pad, cfg0, cfg1)
20 * @early_pads_count: Number of pads to process
21 * @pciex_region_size: BAR length in bytes
22 * @bdf: Bus/device/function of hostbridge
24 struct apl_hostbridge_platdata {
25 #if CONFIG_IS_ENABLED(OF_PLATDATA)
26 struct dtd_intel_apl_hostbridge dtplat;
30 uint pciex_region_size;
36 PCIEXBAR_LENGTH_256MB = 0,
37 PCIEXBAR_LENGTH_128MB,
40 PCIEXBAR_PCIEXBAREN = 1 << 0,
42 TSEG = 0xb8, /* TSEG base */
45 static int apl_hostbridge_early_init_pinctrl(struct udevice *dev)
47 struct apl_hostbridge_platdata *plat = dev_get_platdata(dev);
48 struct udevice *pinctrl;
51 ret = uclass_first_device_err(UCLASS_PINCTRL, &pinctrl);
53 return log_msg_ret("no hostbridge pinctrl", ret);
55 return pinctrl_config_pads(pinctrl, plat->early_pads,
56 plat->early_pads_count);
59 static int apl_hostbridge_early_init(struct udevice *dev)
61 struct apl_hostbridge_platdata *plat = dev_get_platdata(dev);
67 /* Set up the MCHBAR */
68 pci_x86_read_config(plat->bdf, MCHBAR, &base, PCI_SIZE_32);
69 base = MCH_BASE_ADDRESS;
70 pci_x86_write_config(plat->bdf, MCHBAR, base | 1, PCI_SIZE_32);
73 * The PCIEXBAR is assumed to live in the memory mapped IO space under
76 pci_x86_write_config(plat->bdf, PCIEXBAR + 4, 0, PCI_SIZE_32);
78 switch (plat->pciex_region_size >> 20) {
81 region_size = PCIEXBAR_LENGTH_256MB;
84 region_size = PCIEXBAR_LENGTH_128MB;
87 region_size = PCIEXBAR_LENGTH_64MB;
91 reg = CONFIG_MMCONF_BASE_ADDRESS | (region_size << 1)
92 | PCIEXBAR_PCIEXBAREN;
93 pci_x86_write_config(plat->bdf, PCIEXBAR, reg, PCI_SIZE_32);
96 * TSEG defines the base of SMM range. BIOS determines the base
97 * of TSEG memory which must be at or below Graphics base of GTT
98 * Stolen memory, hence its better to clear TSEG register early
99 * to avoid power on default non-zero value (if any).
101 pci_x86_write_config(plat->bdf, TSEG, 0, PCI_SIZE_32);
103 ret = apl_hostbridge_early_init_pinctrl(dev);
105 return log_msg_ret("pinctrl", ret);
110 static int apl_hostbridge_ofdata_to_platdata(struct udevice *dev)
112 struct apl_hostbridge_platdata *plat = dev_get_platdata(dev);
113 struct udevice *pinctrl;
117 * The host bridge holds the early pad data needed to get through TPL.
118 * This is a small amount of data, enough to fit in TPL, so we keep it
119 * separate from the full pad data, stored in the fsp-s subnode. That
120 * subnode is not present in TPL, to save space.
122 ret = uclass_first_device_err(UCLASS_PINCTRL, &pinctrl);
124 return log_msg_ret("no hostbridge PINCTRL", ret);
125 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
128 /* Get length of PCI Express Region */
129 plat->pciex_region_size = dev_read_u32_default(dev, "pciex-region-size",
132 root = pci_get_devfn(dev);
134 return log_msg_ret("Cannot get host-bridge PCI address", root);
137 ret = pinctrl_read_pads(pinctrl, dev_ofnode(dev), "early-pads",
138 &plat->early_pads, &plat->early_pads_count);
140 return log_msg_ret("early-pads", ret);
142 struct dtd_intel_apl_hostbridge *dtplat = &plat->dtplat;
145 plat->pciex_region_size = dtplat->pciex_region_size;
146 plat->bdf = pci_ofplat_get_devfn(dtplat->reg[0]);
148 /* Assume that if everything is 0, it is empty */
149 plat->early_pads = dtplat->early_pads;
150 size = ARRAY_SIZE(dtplat->early_pads);
151 plat->early_pads_count = pinctrl_count_pads(pinctrl, plat->early_pads,
159 static int apl_hostbridge_probe(struct udevice *dev)
161 if (spl_phase() == PHASE_TPL)
162 return apl_hostbridge_early_init(dev);
167 static const struct udevice_id apl_hostbridge_ids[] = {
168 { .compatible = "intel,apl-hostbridge" },
172 U_BOOT_DRIVER(apl_hostbridge_drv) = {
173 .name = "intel_apl_hostbridge",
174 .id = UCLASS_NORTHBRIDGE,
175 .of_match = apl_hostbridge_ids,
176 .ofdata_to_platdata = apl_hostbridge_ofdata_to_platdata,
177 .probe = apl_hostbridge_probe,
178 .platdata_auto_alloc_size = sizeof(struct apl_hostbridge_platdata),