1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright 2019 Google LLC
4 * Copyright (C) 2015 - 2017 Intel Corp.
5 * Copyright (C) 2017 - 2019 Siemens AG
9 * Portions from coreboot soc/intel/apollolake/chip.c
12 #define LOG_CATEGORY UCLASS_NORTHBRIDGE
16 #include <dt-structs.h>
19 #include <tables_csum.h>
20 #include <acpi/acpi_table.h>
21 #include <asm/acpi_nhlt.h>
22 #include <asm/intel_pinctrl.h>
23 #include <asm/intel_regs.h>
26 #include <asm/arch/acpi.h>
27 #include <asm/arch/systemagent.h>
28 #include <dt-bindings/sound/nhlt.h>
33 PCIEXBAR_LENGTH_256MB = 0,
34 PCIEXBAR_LENGTH_128MB,
37 PCIEXBAR_PCIEXBAREN = 1 << 0,
39 BGSM = 0xb4, /* Base GTT Stolen Memory */
40 TSEG = 0xb8, /* TSEG base */
45 * struct apl_hostbridge_platdata - platform data for hostbridge
47 * @dtplat: Platform data for of-platdata
48 * @early_pads: Early pad data to set up, each (pad, cfg0, cfg1)
49 * @early_pads_count: Number of pads to process
50 * @pciex_region_size: BAR length in bytes
51 * @bdf: Bus/device/function of hostbridge
53 struct apl_hostbridge_platdata {
54 #if CONFIG_IS_ENABLED(OF_PLATDATA)
55 struct dtd_intel_apl_hostbridge dtplat;
59 uint pciex_region_size;
63 static const struct nhlt_format_config dmic_1ch_formats[] = {
64 /* 48 KHz 16-bits per sample. */
67 .sample_freq_khz = 48,
68 .container_bits_per_sample = 16,
69 .valid_bits_per_sample = 16,
70 .settings_file = "dmic-1ch-48khz-16b.dat",
74 static const struct nhlt_dmic_array_config dmic_1ch_mic_config = {
76 .config_type = NHLT_TDM_MIC_ARRAY,
78 .array_type = NHLT_MIC_ARRAY_VENDOR_DEFINED,
81 static const struct nhlt_endp_descriptor dmic_1ch_descriptors[] = {
83 .link = NHLT_LINK_PDM,
84 .device = NHLT_PDM_DEV,
85 .direction = NHLT_DIR_CAPTURE,
88 .cfg = &dmic_1ch_mic_config,
89 .cfg_size = sizeof(dmic_1ch_mic_config),
90 .formats = dmic_1ch_formats,
91 .num_formats = ARRAY_SIZE(dmic_1ch_formats),
95 static const struct nhlt_format_config dmic_2ch_formats[] = {
96 /* 48 KHz 16-bits per sample. */
99 .sample_freq_khz = 48,
100 .container_bits_per_sample = 16,
101 .valid_bits_per_sample = 16,
102 .settings_file = "dmic-2ch-48khz-16b.dat",
106 static const struct nhlt_dmic_array_config dmic_2ch_mic_config = {
108 .config_type = NHLT_TDM_MIC_ARRAY,
110 .array_type = NHLT_MIC_ARRAY_2CH_SMALL,
113 static const struct nhlt_endp_descriptor dmic_2ch_descriptors[] = {
115 .link = NHLT_LINK_PDM,
116 .device = NHLT_PDM_DEV,
117 .direction = NHLT_DIR_CAPTURE,
119 .did = NHLT_DID_DMIC,
120 .cfg = &dmic_2ch_mic_config,
121 .cfg_size = sizeof(dmic_2ch_mic_config),
122 .formats = dmic_2ch_formats,
123 .num_formats = ARRAY_SIZE(dmic_2ch_formats),
127 static const struct nhlt_format_config dmic_4ch_formats[] = {
128 /* 48 KHz 16-bits per sample. */
131 .sample_freq_khz = 48,
132 .container_bits_per_sample = 16,
133 .valid_bits_per_sample = 16,
134 .settings_file = "dmic-4ch-48khz-16b.dat",
138 static const struct nhlt_dmic_array_config dmic_4ch_mic_config = {
140 .config_type = NHLT_TDM_MIC_ARRAY,
142 .array_type = NHLT_MIC_ARRAY_4CH_L_SHAPED,
145 static const struct nhlt_endp_descriptor dmic_4ch_descriptors[] = {
147 .link = NHLT_LINK_PDM,
148 .device = NHLT_PDM_DEV,
149 .direction = NHLT_DIR_CAPTURE,
151 .did = NHLT_DID_DMIC,
152 .cfg = &dmic_4ch_mic_config,
153 .cfg_size = sizeof(dmic_4ch_mic_config),
154 .formats = dmic_4ch_formats,
155 .num_formats = ARRAY_SIZE(dmic_4ch_formats),
159 static int apl_hostbridge_early_init_pinctrl(struct udevice *dev)
161 struct apl_hostbridge_platdata *plat = dev_get_plat(dev);
162 struct udevice *pinctrl;
165 ret = uclass_first_device_err(UCLASS_PINCTRL, &pinctrl);
167 return log_msg_ret("no hostbridge pinctrl", ret);
169 return pinctrl_config_pads(pinctrl, plat->early_pads,
170 plat->early_pads_count);
173 static int apl_hostbridge_early_init(struct udevice *dev)
175 struct apl_hostbridge_platdata *plat = dev_get_plat(dev);
181 /* Set up the MCHBAR */
182 pci_x86_read_config(plat->bdf, MCHBAR, &base, PCI_SIZE_32);
183 base = MCH_BASE_ADDRESS;
184 pci_x86_write_config(plat->bdf, MCHBAR, base | 1, PCI_SIZE_32);
187 * The PCIEXBAR is assumed to live in the memory mapped IO space under
190 pci_x86_write_config(plat->bdf, PCIEXBAR + 4, 0, PCI_SIZE_32);
192 switch (plat->pciex_region_size >> 20) {
195 region_size = PCIEXBAR_LENGTH_256MB;
198 region_size = PCIEXBAR_LENGTH_128MB;
201 region_size = PCIEXBAR_LENGTH_64MB;
205 reg = CONFIG_MMCONF_BASE_ADDRESS | (region_size << 1)
206 | PCIEXBAR_PCIEXBAREN;
207 pci_x86_write_config(plat->bdf, PCIEXBAR, reg, PCI_SIZE_32);
210 * TSEG defines the base of SMM range. BIOS determines the base
211 * of TSEG memory which must be at or below Graphics base of GTT
212 * Stolen memory, hence its better to clear TSEG register early
213 * to avoid power on default non-zero value (if any).
215 pci_x86_write_config(plat->bdf, TSEG, 0, PCI_SIZE_32);
217 ret = apl_hostbridge_early_init_pinctrl(dev);
219 return log_msg_ret("pinctrl", ret);
224 static int apl_hostbridge_of_to_plat(struct udevice *dev)
226 struct apl_hostbridge_platdata *plat = dev_get_plat(dev);
227 struct udevice *pinctrl;
231 * The host bridge holds the early pad data needed to get through TPL.
232 * This is a small amount of data, enough to fit in TPL, so we keep it
233 * separate from the full pad data, stored in the fsp-s subnode. That
234 * subnode is not present in TPL, to save space.
236 ret = uclass_first_device_err(UCLASS_PINCTRL, &pinctrl);
238 return log_msg_ret("no hostbridge PINCTRL", ret);
239 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
242 /* Get length of PCI Express Region */
243 plat->pciex_region_size = dev_read_u32_default(dev, "pciex-region-size",
246 root = pci_get_devfn(dev);
248 return log_msg_ret("Cannot get host-bridge PCI address", root);
251 ret = pinctrl_read_pads(pinctrl, dev_ofnode(dev), "early-pads",
252 &plat->early_pads, &plat->early_pads_count);
254 return log_msg_ret("early-pads", ret);
256 struct dtd_intel_apl_hostbridge *dtplat = &plat->dtplat;
259 plat->pciex_region_size = dtplat->pciex_region_size;
260 plat->bdf = pci_ofplat_get_devfn(dtplat->reg[0]);
262 /* Assume that if everything is 0, it is empty */
263 plat->early_pads = dtplat->early_pads;
264 size = ARRAY_SIZE(dtplat->early_pads);
265 plat->early_pads_count = pinctrl_count_pads(pinctrl, plat->early_pads,
273 static int apl_hostbridge_probe(struct udevice *dev)
275 if (spl_phase() == PHASE_TPL)
276 return apl_hostbridge_early_init(dev);
281 static int apl_acpi_hb_get_name(const struct udevice *dev, char *out_name)
283 return acpi_copy_name(out_name, "RHUB");
286 #ifdef CONFIG_GENERATE_ACPI_TABLE
287 static int apl_acpi_hb_write_tables(const struct udevice *dev,
288 struct acpi_ctx *ctx)
290 struct acpi_table_header *header;
291 struct acpi_dmar *dmar;
295 * Create DMAR table only if virtualization is enabled. Due to some
296 * constraints on Apollo Lake SoC (some stepping affected), VTD could
297 * not be enabled together with IPU. Doing so will override and disable
298 * VTD while leaving CAPID0_A still reporting that VTD is available.
299 * As in this case FSP will lock VTD to disabled state, we need to make
300 * sure that DMAR table generation only happens when at least DEFVTBAR
301 * is enabled. Otherwise the DMAR header will be generated while the
302 * content of the table will be missing.
304 dm_pci_read_config32(dev, CAPID0_A, &val);
305 if ((val & VTD_DISABLE) ||
306 !(readl(MCHBAR_REG(DEFVTBAR)) & VTBAR_ENABLED))
309 log_debug("ACPI: * DMAR\n");
310 dmar = (struct acpi_dmar *)ctx->current;
311 header = &dmar->header;
312 acpi_create_dmar(dmar, DMAR_INTR_REMAP);
313 ctx->current += sizeof(struct acpi_dmar);
314 apl_acpi_fill_dmar(ctx);
316 /* (Re)calculate length and checksum */
317 header->length = ctx->current - (void *)dmar;
318 header->checksum = table_compute_checksum((void *)dmar, header->length);
321 acpi_add_table(ctx, dmar);
327 static int apl_acpi_setup_nhlt(const struct udevice *dev, struct acpi_ctx *ctx)
329 struct nhlt *nhlt = ctx->nhlt;
333 node = ofnode_find_subnode(dev_ofnode(dev), "nhlt");
334 if (ofnode_read_u32(node, "intel,dmic-channels", &channels))
335 return log_msg_ret("channels", -EINVAL);
338 return nhlt_add_endpoints(nhlt, dmic_1ch_descriptors,
339 ARRAY_SIZE(dmic_1ch_descriptors));
341 return nhlt_add_endpoints(nhlt, dmic_2ch_descriptors,
342 ARRAY_SIZE(dmic_2ch_descriptors));
344 return nhlt_add_endpoints(nhlt, dmic_4ch_descriptors,
345 ARRAY_SIZE(dmic_4ch_descriptors));
348 return log_msg_ret("channels", -EINVAL);
351 static int apl_hostbridge_remove(struct udevice *dev)
355 * platform_fsp_notify_status()
361 static ulong sa_read_reg(struct udevice *dev, int reg)
365 /* All regions concerned for have 1 MiB alignment */
366 dm_pci_read_config32(dev, BGSM, &val);
368 return ALIGN_DOWN(val, 1 << 20);
371 ulong sa_get_tolud_base(struct udevice *dev)
373 return sa_read_reg(dev, TOLUD);
376 ulong sa_get_gsm_base(struct udevice *dev)
378 return sa_read_reg(dev, BGSM);
381 ulong sa_get_tseg_base(struct udevice *dev)
383 return sa_read_reg(dev, TSEG);
386 struct acpi_ops apl_hostbridge_acpi_ops = {
387 .get_name = apl_acpi_hb_get_name,
388 #ifdef CONFIG_GENERATE_ACPI_TABLE
389 .write_tables = apl_acpi_hb_write_tables,
391 .setup_nhlt = apl_acpi_setup_nhlt,
394 static const struct udevice_id apl_hostbridge_ids[] = {
395 { .compatible = "intel,apl-hostbridge" },
399 U_BOOT_DRIVER(intel_apl_hostbridge) = {
400 .name = "intel_apl_hostbridge",
401 .id = UCLASS_NORTHBRIDGE,
402 .of_match = apl_hostbridge_ids,
403 .of_to_plat = apl_hostbridge_of_to_plat,
404 .probe = apl_hostbridge_probe,
405 .remove = apl_hostbridge_remove,
406 .plat_auto = sizeof(struct apl_hostbridge_platdata),
407 ACPI_OPS_PTR(&apl_hostbridge_acpi_ops)
408 .flags = DM_FLAG_OS_PREPARE,