Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; version 2 of the License. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <console/console.h> |
| 16 | #include <device/device.h> |
| 17 | #include <device/pci.h> |
| 18 | #include <device/pci_ids.h> |
| 19 | #include <device/pci_ops.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 20 | #include <device/mmio.h> |
Vladimir Serbinenko | 75c8387 | 2014-09-05 01:01:31 +0200 | [diff] [blame] | 21 | #include <device/azalia_device.h> |
Elyes HAOUAS | bf0970e | 2019-03-21 11:10:03 +0100 | [diff] [blame] | 22 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 23 | #include "pch.h" |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 24 | #include "hda_verb.h" |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 25 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 26 | static void codecs_init(u8 *base, u32 codec_mask) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 27 | { |
| 28 | int i; |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 29 | |
| 30 | /* Can support up to 4 codecs */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 31 | for (i = 3; i >= 0; i--) { |
| 32 | if (codec_mask & (1 << i)) |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 33 | hda_codec_init(base, i, |
| 34 | cim_verb_data_size, |
| 35 | cim_verb_data); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 36 | } |
| 37 | |
Vladimir Serbinenko | 75c8387 | 2014-09-05 01:01:31 +0200 | [diff] [blame] | 38 | if (pc_beep_verbs_size) |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 39 | hda_codec_write(base, pc_beep_verbs_size, pc_beep_verbs); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 40 | } |
| 41 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 42 | static void azalia_pch_init(struct device *dev, u8 *base) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 43 | { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 44 | u8 reg8; |
| 45 | u16 reg16; |
| 46 | u32 reg32; |
| 47 | |
Ryan Salsamendi | 0d9b360 | 2017-06-30 17:15:57 -0700 | [diff] [blame] | 48 | if (RCBA32(0x2030) & (1UL << 31)) { |
Kyösti Mälkki | 386b3e6 | 2013-07-26 08:52:49 +0300 | [diff] [blame] | 49 | reg32 = pci_read_config32(dev, 0x120); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 50 | reg32 &= 0xf8ffff01; |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 51 | reg32 |= (1 << 25); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 52 | reg32 |= RCBA32(0x2030) & 0xfe; |
Kyösti Mälkki | 386b3e6 | 2013-07-26 08:52:49 +0300 | [diff] [blame] | 53 | pci_write_config32(dev, 0x120, reg32); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 54 | |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 55 | if (!pch_is_lp()) { |
| 56 | reg16 = pci_read_config16(dev, 0x78); |
| 57 | reg16 &= ~(1 << 11); |
| 58 | pci_write_config16(dev, 0x78, reg16); |
| 59 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 60 | } else |
| 61 | printk(BIOS_DEBUG, "Azalia: V1CTL disabled.\n"); |
| 62 | |
Kyösti Mälkki | 386b3e6 | 2013-07-26 08:52:49 +0300 | [diff] [blame] | 63 | reg32 = pci_read_config32(dev, 0x114); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 64 | reg32 &= ~0xfe; |
Kyösti Mälkki | 386b3e6 | 2013-07-26 08:52:49 +0300 | [diff] [blame] | 65 | pci_write_config32(dev, 0x114, reg32); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 66 | |
| 67 | // Set VCi enable bit |
Kyösti Mälkki | 386b3e6 | 2013-07-26 08:52:49 +0300 | [diff] [blame] | 68 | if (pci_read_config32(dev, 0x120) & ((1 << 24) | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 69 | (1 << 25) | (1 << 26))) { |
Kyösti Mälkki | 386b3e6 | 2013-07-26 08:52:49 +0300 | [diff] [blame] | 70 | reg32 = pci_read_config32(dev, 0x120); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 71 | if (pch_is_lp()) |
Ryan Salsamendi | 0d9b360 | 2017-06-30 17:15:57 -0700 | [diff] [blame] | 72 | reg32 &= ~(1UL << 31); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 73 | else |
Ryan Salsamendi | 0d9b360 | 2017-06-30 17:15:57 -0700 | [diff] [blame] | 74 | reg32 |= (1UL << 31); |
Kyösti Mälkki | 386b3e6 | 2013-07-26 08:52:49 +0300 | [diff] [blame] | 75 | pci_write_config32(dev, 0x120, reg32); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 76 | } |
| 77 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 78 | reg8 = pci_read_config8(dev, 0x43); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 79 | if (pch_is_lp()) |
| 80 | reg8 &= ~(1 << 6); |
| 81 | else |
| 82 | reg8 |= (1 << 4); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 83 | pci_write_config8(dev, 0x43, reg8); |
| 84 | |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 85 | if (!pch_is_lp()) { |
| 86 | reg32 = pci_read_config32(dev, 0xc0); |
| 87 | reg32 |= (1 << 17); |
| 88 | pci_write_config32(dev, 0xc0, reg32); |
| 89 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 90 | |
| 91 | /* Additional programming steps */ |
| 92 | reg32 = pci_read_config32(dev, 0xc4); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 93 | if (pch_is_lp()) |
| 94 | reg32 |= (1 << 24); |
| 95 | else |
| 96 | reg32 |= (1 << 14); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 97 | pci_write_config32(dev, 0xc4, reg32); |
| 98 | |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 99 | if (!pch_is_lp()) { |
| 100 | reg32 = pci_read_config32(dev, 0xd0); |
Ryan Salsamendi | 0d9b360 | 2017-06-30 17:15:57 -0700 | [diff] [blame] | 101 | reg32 &= ~(1UL << 31); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 102 | pci_write_config32(dev, 0xd0, reg32); |
| 103 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 104 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 105 | reg8 = pci_read_config8(dev, 0x40); // Audio Control |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 106 | reg8 |= 1; // Select Azalia mode |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 107 | pci_write_config8(dev, 0x40, reg8); |
| 108 | |
| 109 | reg8 = pci_read_config8(dev, 0x4d); // Docking Status |
| 110 | reg8 &= ~(1 << 7); // Docking not supported |
| 111 | pci_write_config8(dev, 0x4d, reg8); |
| 112 | |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 113 | if (pch_is_lp()) { |
| 114 | reg16 = read32(base + 0x0012); |
| 115 | reg16 |= (1 << 0); |
| 116 | write32(base + 0x0012, reg16); |
| 117 | |
| 118 | /* disable Auto Voltage Detector */ |
| 119 | reg8 = pci_read_config8(dev, 0x42); |
| 120 | reg8 |= (1 << 2); |
| 121 | pci_write_config8(dev, 0x42, reg8); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | static void azalia_init(struct device *dev) |
| 126 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 127 | u8 *base; |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 128 | struct resource *res; |
| 129 | u32 codec_mask; |
| 130 | u32 reg32; |
| 131 | |
| 132 | /* Find base address */ |
| 133 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 134 | if (!res) |
| 135 | return; |
| 136 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 137 | base = res2mmio(res, 0, 0); |
| 138 | printk(BIOS_DEBUG, "Azalia: base = %p\n", base); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 139 | |
| 140 | /* Set Bus Master */ |
| 141 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 142 | pci_write_config32(dev, PCI_COMMAND, reg32 | PCI_COMMAND_MASTER); |
| 143 | |
| 144 | azalia_pch_init(dev, base); |
| 145 | |
| 146 | codec_mask = hda_codec_detect(base); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 147 | |
| 148 | if (codec_mask) { |
| 149 | printk(BIOS_DEBUG, "Azalia: codec_mask = %02x\n", codec_mask); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 150 | codecs_init(base, codec_mask); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 151 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 152 | } |
| 153 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 154 | static struct pci_operations azalia_pci_ops = { |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame] | 155 | .set_subsystem = pci_dev_set_subsystem, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | static struct device_operations azalia_ops = { |
| 159 | .read_resources = pci_dev_read_resources, |
| 160 | .set_resources = pci_dev_set_resources, |
| 161 | .enable_resources = pci_dev_enable_resources, |
| 162 | .init = azalia_init, |
| 163 | .scan_bus = 0, |
| 164 | .ops_pci = &azalia_pci_ops, |
| 165 | }; |
| 166 | |
Aaron Durbin | ed095ca | 2013-05-20 15:57:16 -0500 | [diff] [blame] | 167 | static const unsigned short pci_device_ids[] = { 0x8c20, 0x9c20, 0 }; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 168 | |
| 169 | static const struct pci_driver pch_azalia __pci_driver = { |
| 170 | .ops = &azalia_ops, |
| 171 | .vendor = PCI_VENDOR_ID_INTEL, |
| 172 | .devices = pci_device_ids, |
| 173 | }; |