Debian Codegraph @

src/southbridge/intel/ibexpeak/azalia.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pci.h>
6 #include <device/pci_ids.h>
7 #include <device/pci_ops.h>
8 #include <device/mmio.h>
9 #include <delay.h>
10 #include <device/azalia_device.h>
11 #include <types.h>
12
13 #include "pch.h"
14
15 static int codec_detect(u8 *base)
16 {
17 u8 reg8;
18
19 if (azalia_exit_reset(base) != CB_SUCCESS)
20 goto no_codec;
21
22 /* Write back the value once reset bit is set. */
23 write16(base + HDA_GCAP_REG, read16(base + HDA_GCAP_REG));
24
25 /* Read in Codec location (BAR + 0xe)[2..0] */
26 reg8 = read8(base + HDA_STATESTS_REG);
27 reg8 &= 0x0f;
28 if (!reg8)
29 goto no_codec;
30
31 return reg8;
32
33 no_codec:
34 /* Codec not found, put HDA back in reset */
35 azalia_enter_reset(base);
36 printk(BIOS_DEBUG, "Azalia: No codec!\n");
37 return 0;
38 }
39
40 static void azalia_init(struct device *dev)
41 {
42 u8 *base;
43 struct resource *res;
44 u32 codec_mask;
45 u32 reg32;
46
47 /* Find base address */
48 res = probe_resource(dev, PCI_BASE_ADDRESS_0);
49 if (!res)
50 return;
51
52 // NOTE this will break as soon as the Azalia gets a bar above 4G.
53 // Is there anything we can do about it?
54 base = res2mmio(res, 0, 0);
55 printk(BIOS_DEBUG, "Azalia: base = %p\n", base);
56
57 if (RCBA32(0x2030) & (1 << 31)) {
58 reg32 = pci_read_config32(dev, 0x120);
59 reg32 &= 0xf8ffff01;
60 reg32 |= (1 << 24); // 2 << 24 for server
61 reg32 |= RCBA32(0x2030) & 0xfe;
62 pci_write_config32(dev, 0x120, reg32);
63
64 pci_or_config16(dev, 0x78, 1 << 11);
65 } else
66 printk(BIOS_DEBUG, "Azalia: V1CTL disabled.\n");
67
68 pci_and_config32(dev, 0x114, ~0xfe);
69
70 // Set VCi enable bit
71 pci_or_config32(dev, 0x120, 1 << 31);
72
73 // Enable HDMI codec:
74 pci_or_config32(dev, 0xc4, 1 << 1);
75
76 pci_or_config8(dev, 0x43, 1 << 6);
77
78 pci_and_config32(dev, 0xd0, ~(1 << 31));
79
80 /* Set Bus Master */
81 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER);
82
83 pci_write_config8(dev, 0x3c, 0x0a); // unused?
84
85 /* Codec Initialization Programming Sequence */
86
87 /* Take controller out of reset */
88 reg32 = read32(base + HDA_GCTL_REG);
89 reg32 |= HDA_GCTL_CRST;
90 write32(base + HDA_GCTL_REG, reg32);
91 /* Wait 1ms */
92 udelay(1000);
93
94 // Select Azalia mode. This needs to be controlled via devicetree.cb
95 pci_or_config8(dev, 0x40, 1); // Audio Control
96
97 // Docking not supported
98 pci_and_config8(dev, 0x4d, (u8)~(1 << 7)); // Docking Status
99
100 codec_mask = codec_detect(base);
101
102 if (codec_mask) {
103 printk(BIOS_DEBUG, "Azalia: codec_mask = %02x\n", codec_mask);
104 azalia_codecs_init(base, codec_mask);
105 }
106
107 /* Enable dynamic clock gating */
108 pci_update_config8(dev, 0x43, ~0x07, (1 << 2) | (1 << 0));
109 }
110
111 static struct device_operations azalia_ops = {
112 .read_resources = pci_dev_read_resources,
113 .set_resources = pci_dev_set_resources,
114 .enable_resources = pci_dev_enable_resources,
115 .init = azalia_init,
116 .ops_pci = &pci_dev_ops_pci,
117 };
118
119 static const unsigned short pci_device_ids[] = {
120 0x1c20,
121 0x1e20,
122 PCI_DID_INTEL_IBEXPEAK_AUDIO,
123 0
124 };
125
126 static const struct pci_driver pch_azalia __pci_driver = {
127 .ops = &azalia_ops,
128 .vendor = PCI_VID_INTEL,
129 .devices = pci_device_ids,
130 };