blob: 7c9f30637aea5337e4f9a15a4c04a0a4a8711b40 [file] [log] [blame]
Lee Leahy77ff0b12015-05-05 15:07:29 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 Google Inc.
Lee Leahy32471722015-04-20 15:20:28 -07005 * Copyright (C) 2015 Intel Corp.
Lee Leahy77ff0b12015-05-05 15:07:29 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Lee Leahy77ff0b12015-05-05 15:07:29 -070015 */
16
17#include <arch/io.h>
18#include <cbmem.h>
19#include <console/console.h>
20#include <device/device.h>
21#include <device/pci.h>
22#include <device/pci_ids.h>
23#include <reg_script.h>
24
25#include <soc/iomap.h>
26#include <soc/iosf.h>
27#include <soc/lpc.h>
28#include <soc/nvs.h>
29#include <soc/pattrs.h>
30#include <soc/pci_devs.h>
Lee Leahy32471722015-04-20 15:20:28 -070031#include <soc/pm.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070032#include <soc/ramstage.h>
33#include "chip.h"
34
35
Lee Leahy32471722015-04-20 15:20:28 -070036/*
37 * The LPE audio devices needs 1MiB of memory reserved aligned to a 512MiB
38 * address. Just take 1MiB @ 512MiB.
39 */
Lee Leahy77ff0b12015-05-05 15:07:29 -070040#define FIRMWARE_PHYS_BASE (512 << 20)
Matt DeVillier83ef07a2018-01-21 16:37:24 -060041#define FIRMWARE_PHYS_LENGTH (2 << 20)
Lee Leahy77ff0b12015-05-05 15:07:29 -070042#define FIRMWARE_PCI_REG_BASE 0xa8
43#define FIRMWARE_PCI_REG_LENGTH 0xac
44#define FIRMWARE_REG_BASE_C0 0x144000
45#define FIRMWARE_REG_LENGTH_C0 (FIRMWARE_REG_BASE_C0 + 4)
46
Elyes HAOUASb13fac32018-05-24 22:29:44 +020047static void assign_device_nvs(struct device *dev, u32 *field,
48 unsigned int index)
Lee Leahy77ff0b12015-05-05 15:07:29 -070049{
50 struct resource *res;
51
52 res = find_resource(dev, index);
53 if (res)
54 *field = res->base;
55}
56
Elyes HAOUASb13fac32018-05-24 22:29:44 +020057static void lpe_enable_acpi_mode(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -070058{
59 static const struct reg_script ops[] = {
60 /* Disable PCI interrupt, enable Memory and Bus Master */
61 REG_PCI_OR32(PCI_COMMAND,
Lee Leahy32471722015-04-20 15:20:28 -070062 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
63 | PCI_COMMAND_INT_DISABLE),
Lee Leahy77ff0b12015-05-05 15:07:29 -070064 /* Enable ACPI mode */
65 REG_IOSF_OR(IOSF_PORT_0x58, LPE_PCICFGCTR1,
66 LPE_PCICFGCTR1_PCI_CFG_DIS |
67 LPE_PCICFGCTR1_ACPI_INT_EN),
68 REG_SCRIPT_END
69 };
70 global_nvs_t *gnvs;
71
72 /* Find ACPI NVS to update BARs */
Lee Leahy32471722015-04-20 15:20:28 -070073 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
Lee Leahy77ff0b12015-05-05 15:07:29 -070074 if (!gnvs) {
75 printk(BIOS_ERR, "Unable to locate Global NVS\n");
76 return;
77 }
78
79 /* Save BAR0, BAR1, and firmware base to ACPI NVS */
80 assign_device_nvs(dev, &gnvs->dev.lpe_bar0, PCI_BASE_ADDRESS_0);
Matt DeVillier5d6ab452018-01-17 19:39:52 -060081 assign_device_nvs(dev, &gnvs->dev.lpe_bar1, PCI_BASE_ADDRESS_2);
Lee Leahy77ff0b12015-05-05 15:07:29 -070082 assign_device_nvs(dev, &gnvs->dev.lpe_fw, FIRMWARE_PCI_REG_BASE);
83
84 /* Device is enabled in ACPI mode */
85 gnvs->dev.lpe_en = 1;
86
87 /* Put device in ACPI mode */
88 reg_script_run_on_dev(dev, ops);
89}
90
Elyes HAOUASb13fac32018-05-24 22:29:44 +020091static void setup_codec_clock(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -070092{
93 uint32_t reg;
94 u32 *clk_reg;
Lee Leahy32471722015-04-20 15:20:28 -070095 struct soc_intel_braswell_config *config;
Lee Leahy77ff0b12015-05-05 15:07:29 -070096 const char *freq_str;
97
98 config = dev->chip_info;
fdurairxaff502e2015-08-21 15:36:53 -070099 switch (config->lpe_codec_clk_src) {
100 case LPE_CLK_SRC_XTAL:
101 /* XTAL driven bit2=0 */
102 freq_str = "19.2MHz External Crystal";
103 reg = CLK_SRC_XTAL;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700104 break;
fdurairxaff502e2015-08-21 15:36:53 -0700105 case LPE_CLK_SRC_PLL:
106 /* PLL driven bit2=1 */
107 freq_str = "19.2MHz PLL";
108 reg = CLK_SRC_PLL;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700109 break;
110 default:
fdurairxaff502e2015-08-21 15:36:53 -0700111 reg = CLK_SRC_XTAL;
112 printk(BIOS_DEBUG, "LPE codec clock default to using Crystal\n");
Lee Leahy77ff0b12015-05-05 15:07:29 -0700113 return;
114 }
115
116 /* Default to always running. */
117 reg |= CLK_CTL_ON;
118
Lee Leahy77ff0b12015-05-05 15:07:29 -0700119
120 printk(BIOS_DEBUG, "LPE Audio codec clock set to %sMHz.\n", freq_str);
121
Lee Leahy32471722015-04-20 15:20:28 -0700122 clk_reg = (u32 *) (PMC_BASE_ADDRESS + PLT_CLK_CTL_0);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700123
124 write32(clk_reg, (read32(clk_reg) & ~0x7) | reg);
125}
126
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200127static void lpe_stash_firmware_info(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700128{
129 struct resource *res;
130 struct resource *mmio;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700131
132 res = find_resource(dev, FIRMWARE_PCI_REG_BASE);
133 if (res == NULL) {
134 printk(BIOS_DEBUG, "LPE Firmware memory not found.\n");
135 return;
136 }
Lee Leahy32471722015-04-20 15:20:28 -0700137 printk(BIOS_DEBUG, "LPE FW Resource: 0x%08x\n", (u32) res->base);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700138
139 /* Continue using old way of informing firmware address / size. */
140 pci_write_config32(dev, FIRMWARE_PCI_REG_BASE, res->base);
141 pci_write_config32(dev, FIRMWARE_PCI_REG_LENGTH, res->size);
142
Lee Leahy32471722015-04-20 15:20:28 -0700143 /* Also put the address in MMIO space like on C0 BTM */
144 mmio = find_resource(dev, PCI_BASE_ADDRESS_0);
Lee Leahyd94cff62017-03-16 17:49:42 -0700145 write32((void *)(uintptr_t)(mmio->base + FIRMWARE_REG_BASE_C0),
Lee Leahy32471722015-04-20 15:20:28 -0700146 res->base);
Lee Leahyd94cff62017-03-16 17:49:42 -0700147 write32((void *)(uintptr_t)(mmio->base + FIRMWARE_REG_LENGTH_C0),
Lee Leahy32471722015-04-20 15:20:28 -0700148 res->size);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700149}
150
Lee Leahy32471722015-04-20 15:20:28 -0700151
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200152static void lpe_init(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700153{
Lee Leahy32471722015-04-20 15:20:28 -0700154 struct soc_intel_braswell_config *config = dev->chip_info;
155
156 printk(BIOS_SPEW, "%s/%s ( %s )\n",
157 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700158
159 lpe_stash_firmware_info(dev);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700160 setup_codec_clock(dev);
161
162 if (config->lpe_acpi_mode)
163 lpe_enable_acpi_mode(dev);
164}
165
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200166static void lpe_read_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700167{
Matt DeVillier5d6ab452018-01-17 19:39:52 -0600168 struct resource *res;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700169 pci_dev_read_resources(dev);
170
Matt DeVillier5d6ab452018-01-17 19:39:52 -0600171 /*
172 * Allocate the BAR1 resource at index 2 to fulfil the Windows driver
173 * interface requirements even though the PCI device has only one BAR
174 */
175 res = new_resource(dev, PCI_BASE_ADDRESS_2);
176 res->base = 0;
177 res->size = 0x1000;
178 res->limit = 0xffffffff;
179 res->gran = 12;
180 res->align = 12;
181 res->flags = IORESOURCE_MEM;
182
Lee Leahy77ff0b12015-05-05 15:07:29 -0700183 reserved_ram_resource(dev, FIRMWARE_PCI_REG_BASE,
184 FIRMWARE_PHYS_BASE >> 10,
185 FIRMWARE_PHYS_LENGTH >> 10);
186}
187
Elyes HAOUASb13fac32018-05-24 22:29:44 +0200188static void lpe_set_resources(struct device *dev)
Matt DeVillier5d6ab452018-01-17 19:39:52 -0600189{
190 struct resource *res;
191
192 res = find_resource(dev, PCI_BASE_ADDRESS_2);
193 if (res != NULL)
194 res->flags |= IORESOURCE_STORED;
195
196 pci_dev_set_resources(dev);
197}
198
Lee Leahy77ff0b12015-05-05 15:07:29 -0700199static const struct device_operations device_ops = {
200 .read_resources = lpe_read_resources,
Matt DeVillier5d6ab452018-01-17 19:39:52 -0600201 .set_resources = lpe_set_resources,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700202 .enable_resources = pci_dev_enable_resources,
203 .init = lpe_init,
204 .enable = NULL,
205 .scan_bus = NULL,
206 .ops_pci = &soc_pci_ops,
207};
208
209static const struct pci_driver southcluster __pci_driver = {
210 .ops = &device_ops,
211 .vendor = PCI_VENDOR_ID_INTEL,
212 .device = LPE_DEVID,
213};