blob: fe5c4c9fdd8490c091d2ac0ac6c841e9a842f541 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbin76c37002012-10-30 09:03:43 -05002
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>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02008#include <device/mmio.h>
Vladimir Serbinenko75c83872014-09-05 01:01:31 +02009#include <device/azalia_device.h>
Elyes HAOUASbf0970e2019-03-21 11:10:03 +010010
Aaron Durbin76c37002012-10-30 09:03:43 -050011#include "pch.h"
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070012#include "hda_verb.h"
Aaron Durbin76c37002012-10-30 09:03:43 -050013
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080014static void codecs_init(u8 *base, u32 codec_mask)
Aaron Durbin76c37002012-10-30 09:03:43 -050015{
16 int i;
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070017
18 /* Can support up to 4 codecs */
Aaron Durbin76c37002012-10-30 09:03:43 -050019 for (i = 3; i >= 0; i--) {
20 if (codec_mask & (1 << i))
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070021 hda_codec_init(base, i,
22 cim_verb_data_size,
23 cim_verb_data);
Aaron Durbin76c37002012-10-30 09:03:43 -050024 }
25
Vladimir Serbinenko75c83872014-09-05 01:01:31 +020026 if (pc_beep_verbs_size)
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070027 hda_codec_write(base, pc_beep_verbs_size, pc_beep_verbs);
Aaron Durbin76c37002012-10-30 09:03:43 -050028}
29
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080030static void azalia_pch_init(struct device *dev, u8 *base)
Aaron Durbin76c37002012-10-30 09:03:43 -050031{
Aaron Durbin76c37002012-10-30 09:03:43 -050032 u8 reg8;
33 u16 reg16;
34 u32 reg32;
35
Angel Pons8963f7d2020-10-24 12:20:28 +020036 if (RCBA32(0x2030) & (1 << 31)) {
Kyösti Mälkki386b3e62013-07-26 08:52:49 +030037 reg32 = pci_read_config32(dev, 0x120);
Aaron Durbin76c37002012-10-30 09:03:43 -050038 reg32 &= 0xf8ffff01;
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070039 reg32 |= (1 << 25);
Aaron Durbin76c37002012-10-30 09:03:43 -050040 reg32 |= RCBA32(0x2030) & 0xfe;
Kyösti Mälkki386b3e62013-07-26 08:52:49 +030041 pci_write_config32(dev, 0x120, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -050042
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070043 if (!pch_is_lp()) {
Angel Ponsbf9bc502020-06-08 00:12:43 +020044 pci_and_config16(dev, 0x78, ~(1 << 11));
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070045 }
Aaron Durbin76c37002012-10-30 09:03:43 -050046 } else
47 printk(BIOS_DEBUG, "Azalia: V1CTL disabled.\n");
48
Kyösti Mälkki386b3e62013-07-26 08:52:49 +030049 reg32 = pci_read_config32(dev, 0x114);
Aaron Durbin76c37002012-10-30 09:03:43 -050050 reg32 &= ~0xfe;
Kyösti Mälkki386b3e62013-07-26 08:52:49 +030051 pci_write_config32(dev, 0x114, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -050052
53 // Set VCi enable bit
Angel Ponsbf9bc502020-06-08 00:12:43 +020054 if (pci_read_config32(dev, 0x120) & ((1 << 24) | (1 << 25) | (1 << 26))) {
Kyösti Mälkki386b3e62013-07-26 08:52:49 +030055 reg32 = pci_read_config32(dev, 0x120);
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070056 if (pch_is_lp())
Angel Pons8963f7d2020-10-24 12:20:28 +020057 reg32 &= ~(1 << 31);
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070058 else
Angel Pons8963f7d2020-10-24 12:20:28 +020059 reg32 |= (1 << 31);
Kyösti Mälkki386b3e62013-07-26 08:52:49 +030060 pci_write_config32(dev, 0x120, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -050061 }
62
Aaron Durbin76c37002012-10-30 09:03:43 -050063 reg8 = pci_read_config8(dev, 0x43);
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070064 if (pch_is_lp())
65 reg8 &= ~(1 << 6);
66 else
67 reg8 |= (1 << 4);
Aaron Durbin76c37002012-10-30 09:03:43 -050068 pci_write_config8(dev, 0x43, reg8);
69
Angel Ponsbf9bc502020-06-08 00:12:43 +020070 if (!pch_is_lp())
71 pci_or_config32(dev, 0xc0, 1 << 17);
Aaron Durbin76c37002012-10-30 09:03:43 -050072
73 /* Additional programming steps */
74 reg32 = pci_read_config32(dev, 0xc4);
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070075 if (pch_is_lp())
76 reg32 |= (1 << 24);
77 else
78 reg32 |= (1 << 14);
Aaron Durbin76c37002012-10-30 09:03:43 -050079 pci_write_config32(dev, 0xc4, reg32);
80
Angel Ponsbf9bc502020-06-08 00:12:43 +020081 if (!pch_is_lp())
Angel Pons8963f7d2020-10-24 12:20:28 +020082 pci_and_config32(dev, 0xd0, ~(1 << 31));
Aaron Durbin76c37002012-10-30 09:03:43 -050083
Angel Ponsbf9bc502020-06-08 00:12:43 +020084 // Docking not supported
85 pci_and_config8(dev, 0x4d, (u8)~(1 << 7)); // Docking Status
Aaron Durbin76c37002012-10-30 09:03:43 -050086
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070087 if (pch_is_lp()) {
88 reg16 = read32(base + 0x0012);
89 reg16 |= (1 << 0);
90 write32(base + 0x0012, reg16);
91
92 /* disable Auto Voltage Detector */
Angel Ponsbf9bc502020-06-08 00:12:43 +020093 pci_or_config8(dev, 0x42, 1 << 2);
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070094 }
95}
96
97static void azalia_init(struct device *dev)
98{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080099 u8 *base;
Duncan Laurie0a7c49e2013-06-20 12:40:55 -0700100 struct resource *res;
101 u32 codec_mask;
Duncan Laurie0a7c49e2013-06-20 12:40:55 -0700102
103 /* Find base address */
Angel Ponsf32ae102021-11-03 13:07:14 +0100104 res = probe_resource(dev, PCI_BASE_ADDRESS_0);
Duncan Laurie0a7c49e2013-06-20 12:40:55 -0700105 if (!res)
106 return;
107
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800108 base = res2mmio(res, 0, 0);
109 printk(BIOS_DEBUG, "Azalia: base = %p\n", base);
Duncan Laurie0a7c49e2013-06-20 12:40:55 -0700110
111 /* Set Bus Master */
Elyes HAOUAS73ae0762020-04-28 10:13:05 +0200112 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER);
Duncan Laurie0a7c49e2013-06-20 12:40:55 -0700113
114 azalia_pch_init(dev, base);
115
116 codec_mask = hda_codec_detect(base);
Aaron Durbin76c37002012-10-30 09:03:43 -0500117
118 if (codec_mask) {
119 printk(BIOS_DEBUG, "Azalia: codec_mask = %02x\n", codec_mask);
Duncan Laurie0a7c49e2013-06-20 12:40:55 -0700120 codecs_init(base, codec_mask);
Aaron Durbin76c37002012-10-30 09:03:43 -0500121 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500122}
123
Angel Ponsc1301dd2021-03-18 20:35:19 +0100124static void azalia_final(struct device *dev)
125{
126 /* Set HDCFG.BCLD */
127 pci_or_config16(dev, 0x40, 1 << 1);
128}
129
Aaron Durbin76c37002012-10-30 09:03:43 -0500130static struct device_operations azalia_ops = {
131 .read_resources = pci_dev_read_resources,
132 .set_resources = pci_dev_set_resources,
133 .enable_resources = pci_dev_enable_resources,
134 .init = azalia_init,
Angel Ponsc1301dd2021-03-18 20:35:19 +0100135 .final = azalia_final,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200136 .ops_pci = &pci_dev_ops_pci,
Aaron Durbin76c37002012-10-30 09:03:43 -0500137};
138
Felix Singer4ea08f92020-11-20 12:56:44 +0000139static const unsigned short pci_device_ids[] = {
140 PCI_DEVICE_ID_INTEL_LPT_H_AUDIO,
141 PCI_DEVICE_ID_INTEL_LPT_LP_AUDIO,
142 0
143};
Aaron Durbin76c37002012-10-30 09:03:43 -0500144
145static const struct pci_driver pch_azalia __pci_driver = {
146 .ops = &azalia_ops,
147 .vendor = PCI_VENDOR_ID_INTEL,
148 .devices = pci_device_ids,
149};