1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright 2019 Google LLC
5 * From coreboot Apollo Lake support lpc.c
12 #include <acpi/acpi_table.h>
13 #include <asm/cpu_common.h>
14 #include <asm/intel_acpi.h>
15 #include <asm/lpc_common.h>
17 #include <asm/arch/iomap.h>
18 #include <asm/arch/lpc.h>
20 #include <linux/log2.h>
22 void lpc_enable_fixed_io_ranges(uint io_enables)
24 pci_x86_clrset_config(PCH_DEV_LPC, LPC_IO_ENABLES, 0, io_enables,
29 * Find the first unused IO window.
30 * Returns -1 if not found, 0 for reg 0x84, 1 for reg 0x88 ...
32 static int find_unused_pmio_window(void)
37 for (i = 0; i < LPC_NUM_GENERIC_IO_RANGES; i++) {
38 pci_x86_read_config(PCH_DEV_LPC, LPC_GENERIC_IO_RANGE(i),
41 if (!(lgir & LPC_LGIR_EN))
48 int lpc_open_pmio_window(uint base, uint size)
51 u32 lgir_reg_offset, lgir, window_size, alignment;
52 ulong bridged_size, bridge_base;
55 log_debug("LPC: Trying to open IO window from %x size %x\n", base,
61 while (bridged_size < size) {
62 /* Each IO range register can only open a 256-byte window */
63 window_size = min(size, (uint)LPC_LGIR_MAX_WINDOW_SIZE);
65 /* Window size must be a power of two for the AMASK to work */
66 alignment = 1UL << (order_base_2(window_size));
67 window_size = ALIGN(window_size, alignment);
69 /* Address[15:2] in LGIR[15:12] and Mask[7:2] in LGIR[23:18] */
70 lgir = (bridge_base & LPC_LGIR_ADDR_MASK) | LPC_LGIR_EN;
71 lgir |= ((window_size - 1) << 16) & LPC_LGIR_AMASK_MASK;
73 /* Skip programming if same range already programmed */
74 for (i = 0; i < LPC_NUM_GENERIC_IO_RANGES; i++) {
75 pci_x86_read_config(PCH_DEV_LPC,
76 LPC_GENERIC_IO_RANGE(i), ®,
82 lgir_reg_num = find_unused_pmio_window();
83 if (lgir_reg_num < 0) {
84 log_err("LPC: Cannot open IO window: %lx size %lx\n",
85 bridge_base, size - bridged_size);
86 log_err("No more IO windows\n");
90 lgir_reg_offset = LPC_GENERIC_IO_RANGE(lgir_reg_num);
92 pci_x86_write_config(PCH_DEV_LPC, lgir_reg_offset, lgir,
95 log_debug("LPC: Opened IO window LGIR%d: base %lx size %x\n",
96 lgir_reg_num, bridge_base, window_size);
98 bridged_size += window_size;
99 bridge_base += window_size;
105 void lpc_io_setup_comm_a_b(void)
107 /* ComA Range 3F8h-3FFh [2:0] */
108 u16 com_ranges = LPC_IOD_COMA_RANGE;
109 u16 com_enable = LPC_IOE_COMA_EN;
111 /* Setup I/O Decode Range Register for LPC */
112 pci_write_config16(PCH_DEV_LPC, LPC_IO_DECODE, com_ranges);
113 /* Enable ComA and ComB Port */
114 lpc_enable_fixed_io_ranges(com_enable);
117 static int apl_acpi_lpc_get_name(const struct udevice *dev, char *out_name)
119 return acpi_copy_name(out_name, "LPCB");
122 struct acpi_ops apl_lpc_acpi_ops = {
123 .get_name = apl_acpi_lpc_get_name,
124 #ifdef CONFIG_GENERATE_ACPI_TABLE
125 .write_tables = intel_southbridge_write_acpi_tables,
127 .inject_dsdt = southbridge_inject_dsdt,
130 static const struct udevice_id apl_lpc_ids[] = {
131 { .compatible = "intel,apl-lpc" },
135 /* All pads are LPC already configured by the hostbridge, so no probing here */
136 U_BOOT_DRIVER(intel_apl_lpc) = {
137 .name = "intel_apl_lpc",
139 .of_match = apl_lpc_ids,
140 ACPI_OPS_PTR(&apl_lpc_acpi_ops)