blob: cf360ffc607a6d39487a4f52e7d259674089ab43 [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
Ryan Salsamendi0d9b3602017-06-30 17:15:57 -070036 if (RCBA32(0x2030) & (1UL << 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())
Ryan Salsamendi0d9b3602017-06-30 17:15:57 -070057 reg32 &= ~(1UL << 31);
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070058 else
Ryan Salsamendi0d9b3602017-06-30 17:15:57 -070059 reg32 |= (1UL << 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())
82 pci_and_config32(dev, 0xd0, ~(1UL << 31));
Aaron Durbin76c37002012-10-30 09:03:43 -050083
Angel Ponsbf9bc502020-06-08 00:12:43 +020084 // Select Azalia mode
85 pci_or_config8(dev, 0x40, 1); // Audio Control
Aaron Durbin76c37002012-10-30 09:03:43 -050086
Angel Ponsbf9bc502020-06-08 00:12:43 +020087 // Docking not supported
88 pci_and_config8(dev, 0x4d, (u8)~(1 << 7)); // Docking Status
Aaron Durbin76c37002012-10-30 09:03:43 -050089
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070090 if (pch_is_lp()) {
91 reg16 = read32(base + 0x0012);
92 reg16 |= (1 << 0);
93 write32(base + 0x0012, reg16);
94
95 /* disable Auto Voltage Detector */
Angel Ponsbf9bc502020-06-08 00:12:43 +020096 pci_or_config8(dev, 0x42, 1 << 2);
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070097 }
98}
99
100static void azalia_init(struct device *dev)
101{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800102 u8 *base;
Duncan Laurie0a7c49e2013-06-20 12:40:55 -0700103 struct resource *res;
104 u32 codec_mask;
Duncan Laurie0a7c49e2013-06-20 12:40:55 -0700105
106 /* Find base address */
107 res = find_resource(dev, PCI_BASE_ADDRESS_0);
108 if (!res)
109 return;
110
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800111 base = res2mmio(res, 0, 0);
112 printk(BIOS_DEBUG, "Azalia: base = %p\n", base);
Duncan Laurie0a7c49e2013-06-20 12:40:55 -0700113
114 /* Set Bus Master */
Elyes HAOUAS73ae0762020-04-28 10:13:05 +0200115 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER);
Duncan Laurie0a7c49e2013-06-20 12:40:55 -0700116
117 azalia_pch_init(dev, base);
118
119 codec_mask = hda_codec_detect(base);
Aaron Durbin76c37002012-10-30 09:03:43 -0500120
121 if (codec_mask) {
122 printk(BIOS_DEBUG, "Azalia: codec_mask = %02x\n", codec_mask);
Duncan Laurie0a7c49e2013-06-20 12:40:55 -0700123 codecs_init(base, codec_mask);
Aaron Durbin76c37002012-10-30 09:03:43 -0500124 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500125}
126
Aaron Durbin76c37002012-10-30 09:03:43 -0500127static struct device_operations azalia_ops = {
128 .read_resources = pci_dev_read_resources,
129 .set_resources = pci_dev_set_resources,
130 .enable_resources = pci_dev_enable_resources,
131 .init = azalia_init,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200132 .ops_pci = &pci_dev_ops_pci,
Aaron Durbin76c37002012-10-30 09:03:43 -0500133};
134
Aaron Durbined095ca2013-05-20 15:57:16 -0500135static const unsigned short pci_device_ids[] = { 0x8c20, 0x9c20, 0 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500136
137static const struct pci_driver pch_azalia __pci_driver = {
138 .ops = &azalia_ops,
139 .vendor = PCI_VENDOR_ID_INTEL,
140 .devices = pci_device_ids,
141};