Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [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> |
Vladimir Serbinenko | 75c8387 | 2014-09-05 01:01:31 +0200 | [diff] [blame] | 9 | #include <device/azalia_device.h> |
Elyes HAOUAS | bf0970e | 2019-03-21 11:10:03 +0100 | [diff] [blame] | 10 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 11 | #include "pch.h" |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 12 | #include "hda_verb.h" |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 13 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 14 | static void codecs_init(u8 *base, u32 codec_mask) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 15 | { |
| 16 | int i; |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 17 | |
| 18 | /* Can support up to 4 codecs */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 19 | for (i = 3; i >= 0; i--) { |
| 20 | if (codec_mask & (1 << i)) |
Angel Pons | 94b3735 | 2021-11-10 18:05:12 +0100 | [diff] [blame^] | 21 | azalia_codec_init(base, i, cim_verb_data, cim_verb_data_size); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 22 | } |
| 23 | |
Vladimir Serbinenko | 75c8387 | 2014-09-05 01:01:31 +0200 | [diff] [blame] | 24 | if (pc_beep_verbs_size) |
Angel Pons | 5300b03 | 2021-11-10 17:44:51 +0100 | [diff] [blame] | 25 | azalia_program_verb_table(base, pc_beep_verbs, pc_beep_verbs_size); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 26 | } |
| 27 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 28 | static void azalia_pch_init(struct device *dev, u8 *base) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 29 | { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 30 | u8 reg8; |
| 31 | u16 reg16; |
| 32 | u32 reg32; |
| 33 | |
Angel Pons | 8963f7d | 2020-10-24 12:20:28 +0200 | [diff] [blame] | 34 | if (RCBA32(0x2030) & (1 << 31)) { |
Kyösti Mälkki | 386b3e6 | 2013-07-26 08:52:49 +0300 | [diff] [blame] | 35 | reg32 = pci_read_config32(dev, 0x120); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 36 | reg32 &= 0xf8ffff01; |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 37 | reg32 |= (1 << 25); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 38 | reg32 |= RCBA32(0x2030) & 0xfe; |
Kyösti Mälkki | 386b3e6 | 2013-07-26 08:52:49 +0300 | [diff] [blame] | 39 | pci_write_config32(dev, 0x120, reg32); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 40 | |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 41 | if (!pch_is_lp()) { |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 42 | pci_and_config16(dev, 0x78, ~(1 << 11)); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 43 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 44 | } else |
| 45 | printk(BIOS_DEBUG, "Azalia: V1CTL disabled.\n"); |
| 46 | |
Kyösti Mälkki | 386b3e6 | 2013-07-26 08:52:49 +0300 | [diff] [blame] | 47 | reg32 = pci_read_config32(dev, 0x114); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 48 | reg32 &= ~0xfe; |
Kyösti Mälkki | 386b3e6 | 2013-07-26 08:52:49 +0300 | [diff] [blame] | 49 | pci_write_config32(dev, 0x114, reg32); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 50 | |
| 51 | // Set VCi enable bit |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 52 | if (pci_read_config32(dev, 0x120) & ((1 << 24) | (1 << 25) | (1 << 26))) { |
Kyösti Mälkki | 386b3e6 | 2013-07-26 08:52:49 +0300 | [diff] [blame] | 53 | reg32 = pci_read_config32(dev, 0x120); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 54 | if (pch_is_lp()) |
Angel Pons | 8963f7d | 2020-10-24 12:20:28 +0200 | [diff] [blame] | 55 | reg32 &= ~(1 << 31); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 56 | else |
Angel Pons | 8963f7d | 2020-10-24 12:20:28 +0200 | [diff] [blame] | 57 | reg32 |= (1 << 31); |
Kyösti Mälkki | 386b3e6 | 2013-07-26 08:52:49 +0300 | [diff] [blame] | 58 | pci_write_config32(dev, 0x120, reg32); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 59 | } |
| 60 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 61 | reg8 = pci_read_config8(dev, 0x43); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 62 | if (pch_is_lp()) |
| 63 | reg8 &= ~(1 << 6); |
| 64 | else |
| 65 | reg8 |= (1 << 4); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 66 | pci_write_config8(dev, 0x43, reg8); |
| 67 | |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 68 | if (!pch_is_lp()) |
| 69 | pci_or_config32(dev, 0xc0, 1 << 17); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 70 | |
| 71 | /* Additional programming steps */ |
| 72 | reg32 = pci_read_config32(dev, 0xc4); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 73 | if (pch_is_lp()) |
| 74 | reg32 |= (1 << 24); |
| 75 | else |
| 76 | reg32 |= (1 << 14); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 77 | pci_write_config32(dev, 0xc4, reg32); |
| 78 | |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 79 | if (!pch_is_lp()) |
Angel Pons | 8963f7d | 2020-10-24 12:20:28 +0200 | [diff] [blame] | 80 | pci_and_config32(dev, 0xd0, ~(1 << 31)); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 81 | |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 82 | // Docking not supported |
| 83 | pci_and_config8(dev, 0x4d, (u8)~(1 << 7)); // Docking Status |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 84 | |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 85 | if (pch_is_lp()) { |
| 86 | reg16 = read32(base + 0x0012); |
| 87 | reg16 |= (1 << 0); |
| 88 | write32(base + 0x0012, reg16); |
| 89 | |
| 90 | /* disable Auto Voltage Detector */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 91 | pci_or_config8(dev, 0x42, 1 << 2); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | |
| 95 | static void azalia_init(struct device *dev) |
| 96 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 97 | u8 *base; |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 98 | struct resource *res; |
| 99 | u32 codec_mask; |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 100 | |
| 101 | /* Find base address */ |
Angel Pons | f32ae10 | 2021-11-03 13:07:14 +0100 | [diff] [blame] | 102 | res = probe_resource(dev, PCI_BASE_ADDRESS_0); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 103 | if (!res) |
| 104 | return; |
| 105 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 106 | base = res2mmio(res, 0, 0); |
| 107 | printk(BIOS_DEBUG, "Azalia: base = %p\n", base); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 108 | |
| 109 | /* Set Bus Master */ |
Elyes HAOUAS | 73ae076 | 2020-04-28 10:13:05 +0200 | [diff] [blame] | 110 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 111 | |
| 112 | azalia_pch_init(dev, base); |
| 113 | |
| 114 | codec_mask = hda_codec_detect(base); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 115 | |
| 116 | if (codec_mask) { |
| 117 | printk(BIOS_DEBUG, "Azalia: codec_mask = %02x\n", codec_mask); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 118 | codecs_init(base, codec_mask); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 119 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 120 | } |
| 121 | |
Angel Pons | c1301dd | 2021-03-18 20:35:19 +0100 | [diff] [blame] | 122 | static void azalia_final(struct device *dev) |
| 123 | { |
| 124 | /* Set HDCFG.BCLD */ |
| 125 | pci_or_config16(dev, 0x40, 1 << 1); |
| 126 | } |
| 127 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 128 | static struct device_operations azalia_ops = { |
| 129 | .read_resources = pci_dev_read_resources, |
| 130 | .set_resources = pci_dev_set_resources, |
| 131 | .enable_resources = pci_dev_enable_resources, |
| 132 | .init = azalia_init, |
Angel Pons | c1301dd | 2021-03-18 20:35:19 +0100 | [diff] [blame] | 133 | .final = azalia_final, |
Angel Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 134 | .ops_pci = &pci_dev_ops_pci, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 135 | }; |
| 136 | |
Felix Singer | 4ea08f9 | 2020-11-20 12:56:44 +0000 | [diff] [blame] | 137 | static const unsigned short pci_device_ids[] = { |
| 138 | PCI_DEVICE_ID_INTEL_LPT_H_AUDIO, |
| 139 | PCI_DEVICE_ID_INTEL_LPT_LP_AUDIO, |
| 140 | 0 |
| 141 | }; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 142 | |
| 143 | static const struct pci_driver pch_azalia __pci_driver = { |
| 144 | .ops = &azalia_ops, |
| 145 | .vendor = PCI_VENDOR_ID_INTEL, |
| 146 | .devices = pci_device_ids, |
| 147 | }; |