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