blob: 37f2d9f8e6009e7d09196fc7feec221019b0fa06 [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>
Julius Werner4ee4bd52014-10-20 13:46:39 -070010#include <soc/pch.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070011#include <soc/rcba.h>
Angel Ponsb5d56f92021-06-23 12:47:49 +020012#include <southbridge/intel/lynxpoint/hda_verb.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070013
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080014static void codecs_init(u8 *base, u32 codec_mask)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070015{
16 int i;
17
18 /* Can support up to 4 codecs */
19 for (i = 3; i >= 0; i--) {
20 if (codec_mask & (1 << i))
21 hda_codec_init(base, i,
22 cim_verb_data_size,
23 cim_verb_data);
24 }
25
Jonathan A. Kollaschec505ad22015-07-07 12:57:46 -050026 if (pc_beep_verbs_size)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070027 hda_codec_write(base, pc_beep_verbs_size, pc_beep_verbs);
28}
29
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080030static void hda_pch_init(struct device *dev, u8 *base)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070031{
32 u8 reg8;
33 u16 reg16;
34 u32 reg32;
35
36 if (RCBA32(0x2030) & (1 << 31)) {
37 reg32 = pci_read_config32(dev, 0x120);
38 reg32 &= 0xf8ffff01;
39 reg32 |= (1 << 25);
40 reg32 |= RCBA32(0x2030) & 0xfe;
41 pci_write_config32(dev, 0x120, reg32);
42 } else
43 printk(BIOS_DEBUG, "HDA: V1CTL disabled.\n");
44
45 reg32 = pci_read_config32(dev, 0x114);
46 reg32 &= ~0xfe;
47 pci_write_config32(dev, 0x114, reg32);
48
49 // Set VCi enable bit
50 if (pci_read_config32(dev, 0x120) & ((1 << 24) |
51 (1 << 25) | (1 << 26))) {
52 reg32 = pci_read_config32(dev, 0x120);
53 reg32 &= ~(1 << 31);
54 pci_write_config32(dev, 0x120, reg32);
55 }
56
Duncan Lauriec88c54c2014-04-30 16:36:13 -070057 /* Additional programming steps */
58 reg32 = pci_read_config32(dev, 0xc4);
59 reg32 |= (1 << 24);
60 pci_write_config32(dev, 0xc4, reg32);
61
Duncan Lauriec88c54c2014-04-30 16:36:13 -070062 reg8 = pci_read_config8(dev, 0x4d); // Docking Status
63 reg8 &= ~(1 << 7); // Docking not supported
64 pci_write_config8(dev, 0x4d, reg8);
65
66 reg16 = read32(base + 0x0012);
67 reg16 |= (1 << 0);
68 write32(base + 0x0012, reg16);
69
70 /* disable Auto Voltage Detector */
71 reg8 = pci_read_config8(dev, 0x42);
72 reg8 |= (1 << 2);
73 pci_write_config8(dev, 0x42, reg8);
74}
75
76static void hda_init(struct device *dev)
77{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080078 u8 *base;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070079 struct resource *res;
80 u32 codec_mask;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070081
82 /* Find base address */
Angel Ponsc1bfbe02021-11-03 13:18:53 +010083 res = probe_resource(dev, PCI_BASE_ADDRESS_0);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070084 if (!res)
85 return;
86
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080087 base = res2mmio(res, 0, 0);
88 printk(BIOS_DEBUG, "HDA: base = %p\n", base);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070089
90 /* Set Bus Master */
Elyes HAOUASb887adf2020-04-29 10:42:34 +020091 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070092
93 hda_pch_init(dev, base);
94
95 codec_mask = hda_codec_detect(base);
96
97 if (codec_mask) {
98 printk(BIOS_DEBUG, "HDA: codec_mask = %02x\n", codec_mask);
99 codecs_init(base, codec_mask);
100 }
101}
102
Duncan Laurie61680272014-05-05 12:42:35 -0500103static void hda_enable(struct device *dev)
104{
Elyes HAOUASb887adf2020-04-29 10:42:34 +0200105 u16 reg16;
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700106 u8 reg8;
107
108 reg8 = pci_read_config8(dev, 0x43);
109 reg8 |= 0x6f;
110 pci_write_config8(dev, 0x43, reg8);
Duncan Laurie61680272014-05-05 12:42:35 -0500111
112 if (!dev->enabled) {
113 /* Route I/O buffers to ADSP function */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700114 reg8 = pci_read_config8(dev, 0x42);
115 reg8 |= (1 << 7) | (1 << 6);
116 pci_write_config8(dev, 0x42, reg8);
Duncan Laurie61680272014-05-05 12:42:35 -0500117
118 printk(BIOS_INFO, "HDA disabled, I/O buffers routed to ADSP\n");
119
120 /* Ensure memory, io, and bus master are all disabled */
Elyes HAOUASb887adf2020-04-29 10:42:34 +0200121 reg16 = pci_read_config16(dev, PCI_COMMAND);
122 reg16 &= ~(PCI_COMMAND_MASTER |
Duncan Laurie61680272014-05-05 12:42:35 -0500123 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
Elyes HAOUASb887adf2020-04-29 10:42:34 +0200124 pci_write_config16(dev, PCI_COMMAND, reg16);
Duncan Laurie61680272014-05-05 12:42:35 -0500125
126 /* Disable this device */
127 pch_disable_devfn(dev);
128 }
129}
130
Angel Ponsc1301dd2021-03-18 20:35:19 +0100131static void hda_final(struct device *dev)
132{
133 /* Set HDCFG.BCLD */
134 pci_or_config16(dev, 0x40, 1 << 1);
135}
136
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700137static struct device_operations hda_ops = {
138 .read_resources = &pci_dev_read_resources,
139 .set_resources = &pci_dev_set_resources,
140 .enable_resources = &pci_dev_enable_resources,
141 .init = &hda_init,
Duncan Laurie61680272014-05-05 12:42:35 -0500142 .enable = &hda_enable,
Angel Ponsc1301dd2021-03-18 20:35:19 +0100143 .final = &hda_final,
Angel Ponscb2080f2020-10-23 15:45:44 +0200144 .ops_pci = &pci_dev_ops_pci,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700145};
146
147static const unsigned short pci_device_ids[] = {
148 0x9c20, /* LynxPoint-LP */
149 0x9ca0, /* WildcatPoint */
150 0
151};
152
153static const struct pci_driver pch_hda __pci_driver = {
154 .ops = &hda_ops,
155 .vendor = PCI_VENDOR_ID_INTEL,
156 .devices = pci_device_ids,
157};