blob: 26144c3072c1b36c7084fce7e6e872654829b219 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Patrick Georgie72a8a32012-11-06 11:05:09 +01002
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>
Patrick Georgie72a8a32012-11-06 11:05:09 +01009#include <delay.h>
Vladimir Serbinenko75c83872014-09-05 01:01:31 +020010#include <device/azalia_device.h>
Kyösti Mälkki12b121c2019-08-18 16:33:39 +030011#include "chip.h"
Patrick Georgie72a8a32012-11-06 11:05:09 +010012#include "i82801ix.h"
13
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080014static int codec_detect(u8 *base)
Patrick Georgie72a8a32012-11-06 11:05:09 +010015{
16 u32 reg32;
17
Angel Pons2e0053b2020-12-05 19:06:55 +010018 if (azalia_enter_reset(base) < 0)
Patrick Georgie72a8a32012-11-06 11:05:09 +010019 goto no_codec;
20
Angel Pons7f839f62020-12-05 19:02:14 +010021 if (azalia_exit_reset(base) < 0)
Patrick Georgie72a8a32012-11-06 11:05:09 +010022 goto no_codec;
23
Elyes HAOUAS6ea24ff2020-08-11 09:21:24 +020024 /* Read in Codec location (BAR + 0xe)[2..0] */
Elyes HAOUASe5954ba2020-08-03 15:35:47 +020025 reg32 = read32(base + HDA_STATESTS_REG);
Patrick Georgie72a8a32012-11-06 11:05:09 +010026 reg32 &= 0x0f;
27 if (!reg32)
28 goto no_codec;
29
30 return reg32;
31
32no_codec:
Angel Pons2e0053b2020-12-05 19:06:55 +010033 /* Codec not found, put HDA back in reset */
34 azalia_enter_reset(base);
Patrick Georgie72a8a32012-11-06 11:05:09 +010035 printk(BIOS_DEBUG, "Azalia: No codec!\n");
36 return 0;
37}
38
Patrick Georgie72a8a32012-11-06 11:05:09 +010039static void azalia_init(struct device *dev)
40{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080041 u8 *base;
Patrick Georgie72a8a32012-11-06 11:05:09 +010042 struct resource *res;
43 u32 codec_mask;
Patrick Georgie72a8a32012-11-06 11:05:09 +010044
Patrick Georgie72a8a32012-11-06 11:05:09 +010045 // ESD
Angel Pons67406472020-06-08 11:13:42 +020046 pci_update_config32(dev, 0x134, ~0x00ff0000, 2 << 16);
Patrick Georgie72a8a32012-11-06 11:05:09 +010047
48 // Link1 description
Angel Pons67406472020-06-08 11:13:42 +020049 pci_update_config32(dev, 0x140, ~0x00ff0000, 2 << 16);
Patrick Georgie72a8a32012-11-06 11:05:09 +010050
51 // Port VC0 Resource Control Register
Angel Pons67406472020-06-08 11:13:42 +020052 pci_update_config32(dev, 0x114, ~0x000000ff, 1);
Patrick Georgie72a8a32012-11-06 11:05:09 +010053
54 // VCi traffic class
Angel Pons67406472020-06-08 11:13:42 +020055 pci_or_config8(dev, 0x44, 7 << 0); // TC7
Patrick Georgie72a8a32012-11-06 11:05:09 +010056
57 // VCi Resource Control
Angel Pons67406472020-06-08 11:13:42 +020058 pci_or_config32(dev, 0x120, (1 << 31) | (1 << 24) | (0x80 << 0)); /* VCi ID and map */
Patrick Georgie72a8a32012-11-06 11:05:09 +010059
60 /* Set Bus Master */
Elyes HAOUASb9d2e222020-04-28 10:25:12 +020061 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER);
Patrick Georgie72a8a32012-11-06 11:05:09 +010062
Angel Pons67406472020-06-08 11:13:42 +020063 // Docking not supported
64 pci_and_config8(dev, 0x4d, (u8)~(1 << 7)); // Docking Status
Patrick Georgie72a8a32012-11-06 11:05:09 +010065
66 /* Lock some R/WO bits by writing their current value. */
Angel Pons67406472020-06-08 11:13:42 +020067 pci_update_config32(dev, 0x74, ~0, 0);
Patrick Georgie72a8a32012-11-06 11:05:09 +010068
Angel Ponsf32ae102021-11-03 13:07:14 +010069 res = probe_resource(dev, PCI_BASE_ADDRESS_0);
Patrick Georgie72a8a32012-11-06 11:05:09 +010070 if (!res)
71 return;
72
Martin Roth26f97f92021-10-01 14:53:22 -060073 // NOTE this will break as soon as the Azalia gets a bar above 4G.
Elyes HAOUAS6ea24ff2020-08-11 09:21:24 +020074 // Is there anything we can do about it?
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080075 base = res2mmio(res, 0, 0);
Patrick Rudolph4af2add2018-11-26 15:56:11 +010076 printk(BIOS_DEBUG, "Azalia: base = %p\n", base);
Patrick Georgie72a8a32012-11-06 11:05:09 +010077 codec_mask = codec_detect(base);
78
79 if (codec_mask) {
80 printk(BIOS_DEBUG, "Azalia: codec_mask = %02x\n", codec_mask);
Angel Ponsaae6b552021-11-10 18:10:38 +010081 azalia_codecs_init(base, codec_mask);
Patrick Georgie72a8a32012-11-06 11:05:09 +010082 }
83}
84
Patrick Georgie72a8a32012-11-06 11:05:09 +010085static struct device_operations azalia_ops = {
86 .read_resources = pci_dev_read_resources,
87 .set_resources = pci_dev_set_resources,
88 .enable_resources = pci_dev_enable_resources,
89 .init = azalia_init,
Angel Pons1fc0edd2020-05-31 00:03:28 +020090 .ops_pci = &pci_dev_ops_pci,
Patrick Georgie72a8a32012-11-06 11:05:09 +010091};
92
93/* ICH9DH/ICH9DO/ICH9R/ICH9/ICH9M-E/ICH9M */
94static const struct pci_driver i82801ix_azalia __pci_driver = {
95 .ops = &azalia_ops,
96 .vendor = PCI_VENDOR_ID_INTEL,
Felix Singer7f8b0cd2019-11-10 11:04:08 +010097 .device = PCI_DEVICE_ID_INTEL_82801IB_HD_AUDIO,
Patrick Georgie72a8a32012-11-06 11:05:09 +010098};