blob: 04390d1342aab0042d4da1b68d57d59edbae5515 [file] [log] [blame]
Angel Ponsf94ac9a2020-04-05 15:46:48 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Duncan Lauriec88c54c2014-04-30 16:36:13 -07002
3#include <console/console.h>
4#include <device/device.h>
Jonathan A. Kollaschec505ad22015-07-07 12:57:46 -05005#include <device/azalia_device.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -07006#include <device/pci.h>
7#include <device/pci_ids.h>
8#include <device/pci_ops.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02009#include <device/mmio.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070010#include <soc/intel/common/hda_verb.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070011#include <soc/pch.h>
12#include <soc/ramstage.h>
13#include <soc/rcba.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070014
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080015static void codecs_init(u8 *base, u32 codec_mask)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070016{
17 int i;
18
19 /* Can support up to 4 codecs */
20 for (i = 3; i >= 0; i--) {
21 if (codec_mask & (1 << i))
22 hda_codec_init(base, i,
23 cim_verb_data_size,
24 cim_verb_data);
25 }
26
Jonathan A. Kollaschec505ad22015-07-07 12:57:46 -050027 if (pc_beep_verbs_size)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070028 hda_codec_write(base, pc_beep_verbs_size, pc_beep_verbs);
29}
30
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080031static void hda_pch_init(struct device *dev, u8 *base)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070032{
33 u8 reg8;
34 u16 reg16;
35 u32 reg32;
36
37 if (RCBA32(0x2030) & (1 << 31)) {
38 reg32 = pci_read_config32(dev, 0x120);
39 reg32 &= 0xf8ffff01;
40 reg32 |= (1 << 25);
41 reg32 |= RCBA32(0x2030) & 0xfe;
42 pci_write_config32(dev, 0x120, reg32);
43 } else
44 printk(BIOS_DEBUG, "HDA: V1CTL disabled.\n");
45
46 reg32 = pci_read_config32(dev, 0x114);
47 reg32 &= ~0xfe;
48 pci_write_config32(dev, 0x114, reg32);
49
50 // Set VCi enable bit
51 if (pci_read_config32(dev, 0x120) & ((1 << 24) |
52 (1 << 25) | (1 << 26))) {
53 reg32 = pci_read_config32(dev, 0x120);
54 reg32 &= ~(1 << 31);
55 pci_write_config32(dev, 0x120, reg32);
56 }
57
Duncan Lauriec88c54c2014-04-30 16:36:13 -070058 /* Additional programming steps */
59 reg32 = pci_read_config32(dev, 0xc4);
60 reg32 |= (1 << 24);
61 pci_write_config32(dev, 0xc4, reg32);
62
63 reg8 = pci_read_config8(dev, 0x40); // Audio Control
64 reg8 |= 1; // Select HDA mode
65 pci_write_config8(dev, 0x40, reg8);
66
67 reg8 = pci_read_config8(dev, 0x4d); // Docking Status
68 reg8 &= ~(1 << 7); // Docking not supported
69 pci_write_config8(dev, 0x4d, reg8);
70
71 reg16 = read32(base + 0x0012);
72 reg16 |= (1 << 0);
73 write32(base + 0x0012, reg16);
74
75 /* disable Auto Voltage Detector */
76 reg8 = pci_read_config8(dev, 0x42);
77 reg8 |= (1 << 2);
78 pci_write_config8(dev, 0x42, reg8);
79}
80
81static void hda_init(struct device *dev)
82{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080083 u8 *base;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070084 struct resource *res;
85 u32 codec_mask;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070086
87 /* Find base address */
88 res = find_resource(dev, PCI_BASE_ADDRESS_0);
89 if (!res)
90 return;
91
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080092 base = res2mmio(res, 0, 0);
93 printk(BIOS_DEBUG, "HDA: base = %p\n", base);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070094
95 /* Set Bus Master */
Elyes HAOUASb887adf2020-04-29 10:42:34 +020096 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070097
98 hda_pch_init(dev, base);
99
100 codec_mask = hda_codec_detect(base);
101
102 if (codec_mask) {
103 printk(BIOS_DEBUG, "HDA: codec_mask = %02x\n", codec_mask);
104 codecs_init(base, codec_mask);
105 }
106}
107
Duncan Laurie61680272014-05-05 12:42:35 -0500108static void hda_enable(struct device *dev)
109{
Elyes HAOUASb887adf2020-04-29 10:42:34 +0200110 u16 reg16;
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700111 u8 reg8;
112
113 reg8 = pci_read_config8(dev, 0x43);
114 reg8 |= 0x6f;
115 pci_write_config8(dev, 0x43, reg8);
Duncan Laurie61680272014-05-05 12:42:35 -0500116
117 if (!dev->enabled) {
118 /* Route I/O buffers to ADSP function */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700119 reg8 = pci_read_config8(dev, 0x42);
120 reg8 |= (1 << 7) | (1 << 6);
121 pci_write_config8(dev, 0x42, reg8);
Duncan Laurie61680272014-05-05 12:42:35 -0500122
123 printk(BIOS_INFO, "HDA disabled, I/O buffers routed to ADSP\n");
124
125 /* Ensure memory, io, and bus master are all disabled */
Elyes HAOUASb887adf2020-04-29 10:42:34 +0200126 reg16 = pci_read_config16(dev, PCI_COMMAND);
127 reg16 &= ~(PCI_COMMAND_MASTER |
Duncan Laurie61680272014-05-05 12:42:35 -0500128 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
Elyes HAOUASb887adf2020-04-29 10:42:34 +0200129 pci_write_config16(dev, PCI_COMMAND, reg16);
Duncan Laurie61680272014-05-05 12:42:35 -0500130
131 /* Disable this device */
132 pch_disable_devfn(dev);
133 }
134}
135
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700136static struct device_operations hda_ops = {
137 .read_resources = &pci_dev_read_resources,
138 .set_resources = &pci_dev_set_resources,
139 .enable_resources = &pci_dev_enable_resources,
140 .init = &hda_init,
Duncan Laurie61680272014-05-05 12:42:35 -0500141 .enable = &hda_enable,
Angel Ponscb2080f2020-10-23 15:45:44 +0200142 .ops_pci = &pci_dev_ops_pci,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700143};
144
145static const unsigned short pci_device_ids[] = {
146 0x9c20, /* LynxPoint-LP */
147 0x9ca0, /* WildcatPoint */
148 0
149};
150
151static const struct pci_driver pch_hda __pci_driver = {
152 .ops = &hda_ops,
153 .vendor = PCI_VENDOR_ID_INTEL,
154 .devices = pci_device_ids,
155};