Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 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> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 8 | #include <device/mmio.h> |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 9 | #include <delay.h> |
Vladimir Serbinenko | 75c8387 | 2014-09-05 01:01:31 +0200 | [diff] [blame] | 10 | #include <device/azalia_device.h> |
Kyösti Mälkki | 12b121c | 2019-08-18 16:33:39 +0300 | [diff] [blame] | 11 | #include "chip.h" |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 12 | #include "i82801ix.h" |
| 13 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 14 | static int codec_detect(u8 *base) |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 15 | { |
| 16 | u32 reg32; |
| 17 | |
Angel Pons | 2e0053b | 2020-12-05 19:06:55 +0100 | [diff] [blame] | 18 | if (azalia_enter_reset(base) < 0) |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 19 | goto no_codec; |
| 20 | |
Angel Pons | 7f839f6 | 2020-12-05 19:02:14 +0100 | [diff] [blame] | 21 | if (azalia_exit_reset(base) < 0) |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 22 | goto no_codec; |
| 23 | |
Elyes HAOUAS | 6ea24ff | 2020-08-11 09:21:24 +0200 | [diff] [blame] | 24 | /* Read in Codec location (BAR + 0xe)[2..0] */ |
Elyes HAOUAS | e5954ba | 2020-08-03 15:35:47 +0200 | [diff] [blame] | 25 | reg32 = read32(base + HDA_STATESTS_REG); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 26 | reg32 &= 0x0f; |
| 27 | if (!reg32) |
| 28 | goto no_codec; |
| 29 | |
| 30 | return reg32; |
| 31 | |
| 32 | no_codec: |
Angel Pons | 2e0053b | 2020-12-05 19:06:55 +0100 | [diff] [blame] | 33 | /* Codec not found, put HDA back in reset */ |
| 34 | azalia_enter_reset(base); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 35 | printk(BIOS_DEBUG, "Azalia: No codec!\n"); |
| 36 | return 0; |
| 37 | } |
| 38 | |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 39 | static void azalia_init(struct device *dev) |
| 40 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 41 | u8 *base; |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 42 | struct resource *res; |
| 43 | u32 codec_mask; |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 44 | |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 45 | // ESD |
Angel Pons | 6740647 | 2020-06-08 11:13:42 +0200 | [diff] [blame] | 46 | pci_update_config32(dev, 0x134, ~0x00ff0000, 2 << 16); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 47 | |
| 48 | // Link1 description |
Angel Pons | 6740647 | 2020-06-08 11:13:42 +0200 | [diff] [blame] | 49 | pci_update_config32(dev, 0x140, ~0x00ff0000, 2 << 16); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 50 | |
| 51 | // Port VC0 Resource Control Register |
Angel Pons | 6740647 | 2020-06-08 11:13:42 +0200 | [diff] [blame] | 52 | pci_update_config32(dev, 0x114, ~0x000000ff, 1); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 53 | |
| 54 | // VCi traffic class |
Angel Pons | 6740647 | 2020-06-08 11:13:42 +0200 | [diff] [blame] | 55 | pci_or_config8(dev, 0x44, 7 << 0); // TC7 |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 56 | |
| 57 | // VCi Resource Control |
Angel Pons | 6740647 | 2020-06-08 11:13:42 +0200 | [diff] [blame] | 58 | pci_or_config32(dev, 0x120, (1 << 31) | (1 << 24) | (0x80 << 0)); /* VCi ID and map */ |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 59 | |
| 60 | /* Set Bus Master */ |
Elyes HAOUAS | b9d2e22 | 2020-04-28 10:25:12 +0200 | [diff] [blame] | 61 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 62 | |
Angel Pons | 6740647 | 2020-06-08 11:13:42 +0200 | [diff] [blame] | 63 | // Docking not supported |
| 64 | pci_and_config8(dev, 0x4d, (u8)~(1 << 7)); // Docking Status |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 65 | |
| 66 | /* Lock some R/WO bits by writing their current value. */ |
Angel Pons | 6740647 | 2020-06-08 11:13:42 +0200 | [diff] [blame] | 67 | pci_update_config32(dev, 0x74, ~0, 0); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 68 | |
Angel Pons | f32ae10 | 2021-11-03 13:07:14 +0100 | [diff] [blame] | 69 | res = probe_resource(dev, PCI_BASE_ADDRESS_0); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 70 | if (!res) |
| 71 | return; |
| 72 | |
Martin Roth | 26f97f9 | 2021-10-01 14:53:22 -0600 | [diff] [blame] | 73 | // NOTE this will break as soon as the Azalia gets a bar above 4G. |
Elyes HAOUAS | 6ea24ff | 2020-08-11 09:21:24 +0200 | [diff] [blame] | 74 | // Is there anything we can do about it? |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 75 | base = res2mmio(res, 0, 0); |
Patrick Rudolph | 4af2add | 2018-11-26 15:56:11 +0100 | [diff] [blame] | 76 | printk(BIOS_DEBUG, "Azalia: base = %p\n", base); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 77 | codec_mask = codec_detect(base); |
| 78 | |
| 79 | if (codec_mask) { |
| 80 | printk(BIOS_DEBUG, "Azalia: codec_mask = %02x\n", codec_mask); |
Angel Pons | 12f2bb6 | 2021-11-10 17:31:43 +0100 | [diff] [blame] | 81 | azalia_codecs_init(dev, base, codec_mask); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 85 | static 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 Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 90 | .ops_pci = &pci_dev_ops_pci, |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | /* ICH9DH/ICH9DO/ICH9R/ICH9/ICH9M-E/ICH9M */ |
| 94 | static const struct pci_driver i82801ix_azalia __pci_driver = { |
| 95 | .ops = &azalia_ops, |
| 96 | .vendor = PCI_VENDOR_ID_INTEL, |
Felix Singer | 7f8b0cd8 | 2019-11-10 11:04:08 +0100 | [diff] [blame] | 97 | .device = PCI_DEVICE_ID_INTEL_82801IB_HD_AUDIO, |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 98 | }; |