blob: fa4b695fd65377bd56b79faad41320a46af4f210 [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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
Patrick Georgi25509ee2015-03-26 15:17:45 +010018 * Foundation, Inc.
Lee Leahy77ff0b12015-05-05 15:07:29 -070019 */
20
21#include <arch/io.h>
22#include <cbmem.h>
23#include <console/console.h>
24#include <device/device.h>
25#include <device/pci.h>
26#include <device/pci_ids.h>
27#include <reg_script.h>
28
29#include <soc/iomap.h>
30#include <soc/iosf.h>
31#include <soc/lpc.h>
32#include <soc/nvs.h>
33#include <soc/pattrs.h>
34#include <soc/pci_devs.h>
Lee Leahy32471722015-04-20 15:20:28 -070035#include <soc/pm.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070036#include <soc/ramstage.h>
37#include "chip.h"
38
39
Lee Leahy32471722015-04-20 15:20:28 -070040/*
41 * The LPE audio devices needs 1MiB of memory reserved aligned to a 512MiB
42 * address. Just take 1MiB @ 512MiB.
43 */
Lee Leahy77ff0b12015-05-05 15:07:29 -070044#define FIRMWARE_PHYS_BASE (512 << 20)
45#define FIRMWARE_PHYS_LENGTH (1 << 20)
46#define FIRMWARE_PCI_REG_BASE 0xa8
47#define FIRMWARE_PCI_REG_LENGTH 0xac
48#define FIRMWARE_REG_BASE_C0 0x144000
49#define FIRMWARE_REG_LENGTH_C0 (FIRMWARE_REG_BASE_C0 + 4)
50
51static void assign_device_nvs(device_t dev, u32 *field, unsigned index)
52{
53 struct resource *res;
54
55 res = find_resource(dev, index);
56 if (res)
57 *field = res->base;
58}
59
60static void lpe_enable_acpi_mode(device_t dev)
61{
62 static const struct reg_script ops[] = {
63 /* Disable PCI interrupt, enable Memory and Bus Master */
64 REG_PCI_OR32(PCI_COMMAND,
Lee Leahy32471722015-04-20 15:20:28 -070065 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
66 | PCI_COMMAND_INT_DISABLE),
Lee Leahy77ff0b12015-05-05 15:07:29 -070067 /* Enable ACPI mode */
68 REG_IOSF_OR(IOSF_PORT_0x58, LPE_PCICFGCTR1,
69 LPE_PCICFGCTR1_PCI_CFG_DIS |
70 LPE_PCICFGCTR1_ACPI_INT_EN),
71 REG_SCRIPT_END
72 };
73 global_nvs_t *gnvs;
74
75 /* Find ACPI NVS to update BARs */
Lee Leahy32471722015-04-20 15:20:28 -070076 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
Lee Leahy77ff0b12015-05-05 15:07:29 -070077 if (!gnvs) {
78 printk(BIOS_ERR, "Unable to locate Global NVS\n");
79 return;
80 }
81
82 /* Save BAR0, BAR1, and firmware base to ACPI NVS */
83 assign_device_nvs(dev, &gnvs->dev.lpe_bar0, PCI_BASE_ADDRESS_0);
Lee Leahy32471722015-04-20 15:20:28 -070084 /* LPE seems does not have BAR at PCI_BASE_ADDRESS_1 so disable it. */
85 /* assign_device_nvs(dev, &gnvs->dev.lpe_bar1, PCI_BASE_ADDRESS_1); */
Lee Leahy77ff0b12015-05-05 15:07:29 -070086 assign_device_nvs(dev, &gnvs->dev.lpe_fw, FIRMWARE_PCI_REG_BASE);
87
88 /* Device is enabled in ACPI mode */
89 gnvs->dev.lpe_en = 1;
90
91 /* Put device in ACPI mode */
92 reg_script_run_on_dev(dev, ops);
93}
94
95static void setup_codec_clock(device_t dev)
96{
97 uint32_t reg;
98 u32 *clk_reg;
Lee Leahy32471722015-04-20 15:20:28 -070099 struct soc_intel_braswell_config *config;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700100 const char *freq_str;
101
102 config = dev->chip_info;
103 switch (config->lpe_codec_clk_freq) {
104 case 19:
105 freq_str = "19.2";
106 reg = CLK_FREQ_19P2MHZ;
107 break;
108 case 25:
109 freq_str = "25";
110 reg = CLK_FREQ_25MHZ;
111 break;
112 default:
113 printk(BIOS_DEBUG, "LPE codec clock not required.\n");
114 return;
115 }
116
117 /* Default to always running. */
118 reg |= CLK_CTL_ON;
119
120 if (config->lpe_codec_clk_num < 0 || config->lpe_codec_clk_num > 5) {
121 printk(BIOS_DEBUG, "Invalid LPE codec clock number.\n");
122 return;
123 }
124
125 printk(BIOS_DEBUG, "LPE Audio codec clock set to %sMHz.\n", freq_str);
126
Lee Leahy32471722015-04-20 15:20:28 -0700127 clk_reg = (u32 *) (PMC_BASE_ADDRESS + PLT_CLK_CTL_0);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700128 clk_reg += config->lpe_codec_clk_num;
129
130 write32(clk_reg, (read32(clk_reg) & ~0x7) | reg);
131}
132
133static void lpe_stash_firmware_info(device_t dev)
134{
135 struct resource *res;
136 struct resource *mmio;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700137
138 res = find_resource(dev, FIRMWARE_PCI_REG_BASE);
139 if (res == NULL) {
140 printk(BIOS_DEBUG, "LPE Firmware memory not found.\n");
141 return;
142 }
Lee Leahy32471722015-04-20 15:20:28 -0700143 printk(BIOS_DEBUG, "LPE FW Resource: 0x%08x\n", (u32) res->base);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700144
145 /* Continue using old way of informing firmware address / size. */
146 pci_write_config32(dev, FIRMWARE_PCI_REG_BASE, res->base);
147 pci_write_config32(dev, FIRMWARE_PCI_REG_LENGTH, res->size);
148
Lee Leahy32471722015-04-20 15:20:28 -0700149 /* Also put the address in MMIO space like on C0 BTM */
150 mmio = find_resource(dev, PCI_BASE_ADDRESS_0);
151 write32((void *)(uintptr_t)(mmio->base + FIRMWARE_REG_BASE_C0), \
152 res->base);
153 write32((void *)(uintptr_t)(mmio->base + FIRMWARE_REG_LENGTH_C0), \
154 res->size);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700155}
156
Lee Leahy32471722015-04-20 15:20:28 -0700157
Lee Leahy77ff0b12015-05-05 15:07:29 -0700158static void lpe_init(device_t dev)
159{
Lee Leahy32471722015-04-20 15:20:28 -0700160 struct soc_intel_braswell_config *config = dev->chip_info;
161
162 printk(BIOS_SPEW, "%s/%s ( %s )\n",
163 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700164
165 lpe_stash_firmware_info(dev);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700166 setup_codec_clock(dev);
167
168 if (config->lpe_acpi_mode)
169 lpe_enable_acpi_mode(dev);
170}
171
172static void lpe_read_resources(device_t dev)
173{
174 pci_dev_read_resources(dev);
175
176 reserved_ram_resource(dev, FIRMWARE_PCI_REG_BASE,
177 FIRMWARE_PHYS_BASE >> 10,
178 FIRMWARE_PHYS_LENGTH >> 10);
179}
180
181static const struct device_operations device_ops = {
182 .read_resources = lpe_read_resources,
183 .set_resources = pci_dev_set_resources,
184 .enable_resources = pci_dev_enable_resources,
185 .init = lpe_init,
186 .enable = NULL,
187 .scan_bus = NULL,
188 .ops_pci = &soc_pci_ops,
189};
190
191static const struct pci_driver southcluster __pci_driver = {
192 .ops = &device_ops,
193 .vendor = PCI_VENDOR_ID_INTEL,
194 .device = LPE_DEVID,
195};