| 1 |
|
| 2 |
|
| 3 |
#include <console/console.h> |
| 4 |
#include <device/device.h> |
| 5 |
#include <device/azalia_device.h> |
| 6 |
#include <device/pci.h> |
| 7 |
#include <device/pci_ids.h> |
| 8 |
#include <device/pci_ops.h> |
| 9 |
#include <device/mmio.h> |
| 10 |
#include <soc/pch.h> |
| 11 |
#include <soc/rcba.h> |
| 12 |
#include <southbridge/intel/lynxpoint/hda_verb.h> |
| 13 |
|
| 14 |
static void hda_pch_init(struct device *dev, u8 *base) |
| 15 |
{ |
| 16 |
u8 reg8; |
| 17 |
u16 reg16; |
| 18 |
u32 reg32; |
| 19 |
|
| 20 |
if (RCBA32(0x2030) & (1 << 31)) { |
| 21 |
reg32 = pci_read_config32(dev, 0x120); |
| 22 |
reg32 &= 0xf8ffff01; |
| 23 |
reg32 |= (1 << 25); |
| 24 |
reg32 |= RCBA32(0x2030) & 0xfe; |
| 25 |
pci_write_config32(dev, 0x120, reg32); |
| 26 |
} else |
| 27 |
printk(BIOS_DEBUG, "HDA: V1CTL disabled.\n"); |
| 28 |
|
| 29 |
reg32 = pci_read_config32(dev, 0x114); |
| 30 |
reg32 &= ~0xfe; |
| 31 |
pci_write_config32(dev, 0x114, reg32); |
| 32 |
|
| 33 |
|
| 34 |
if (pci_read_config32(dev, 0x120) & ((1 << 24) | |
| 35 |
(1 << 25) | (1 << 26))) { |
| 36 |
reg32 = pci_read_config32(dev, 0x120); |
| 37 |
reg32 &= ~(1 << 31); |
| 38 |
pci_write_config32(dev, 0x120, reg32); |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
reg32 = pci_read_config32(dev, 0xc4); |
| 43 |
reg32 |= (1 << 24); |
| 44 |
pci_write_config32(dev, 0xc4, reg32); |
| 45 |
|
| 46 |
reg8 = pci_read_config8(dev, 0x4d); |
| 47 |
reg8 &= ~(1 << 7); |
| 48 |
pci_write_config8(dev, 0x4d, reg8); |
| 49 |
|
| 50 |
reg16 = read32(base + 0x0012); |
| 51 |
reg16 |= (1 << 0); |
| 52 |
write32(base + 0x0012, reg16); |
| 53 |
|
| 54 |
|
| 55 |
reg8 = pci_read_config8(dev, 0x42); |
| 56 |
reg8 |= (1 << 2); |
| 57 |
pci_write_config8(dev, 0x42, reg8); |
| 58 |
} |
| 59 |
|
| 60 |
static void hda_init(struct device *dev) |
| 61 |
{ |
| 62 |
u8 *base; |
| 63 |
struct resource *res; |
| 64 |
u32 codec_mask; |
| 65 |
|
| 66 |
|
| 67 |
res = probe_resource(dev, PCI_BASE_ADDRESS_0); |
| 68 |
if (!res) |
| 69 |
return; |
| 70 |
|
| 71 |
base = res2mmio(res, 0, 0); |
| 72 |
printk(BIOS_DEBUG, "HDA: base = %p\n", base); |
| 73 |
|
| 74 |
|
| 75 |
pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER); |
| 76 |
|
| 77 |
hda_pch_init(dev, base); |
| 78 |
|
| 79 |
codec_mask = hda_codec_detect(base); |
| 80 |
|
| 81 |
if (codec_mask) { |
| 82 |
printk(BIOS_DEBUG, "HDA: codec_mask = %02x\n", codec_mask); |
| 83 |
azalia_codecs_init(base, codec_mask); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
static void hda_enable(struct device *dev) |
| 88 |
{ |
| 89 |
u16 reg16; |
| 90 |
u8 reg8; |
| 91 |
|
| 92 |
reg8 = pci_read_config8(dev, 0x43); |
| 93 |
reg8 |= 0x6f; |
| 94 |
pci_write_config8(dev, 0x43, reg8); |
| 95 |
|
| 96 |
if (!dev->enabled) { |
| 97 |
|
| 98 |
reg8 = pci_read_config8(dev, 0x42); |
| 99 |
reg8 |= (1 << 7) | (1 << 6); |
| 100 |
pci_write_config8(dev, 0x42, reg8); |
| 101 |
|
| 102 |
printk(BIOS_INFO, "HDA disabled, I/O buffers routed to ADSP\n"); |
| 103 |
|
| 104 |
|
| 105 |
reg16 = pci_read_config16(dev, PCI_COMMAND); |
| 106 |
reg16 &= ~(PCI_COMMAND_MASTER | |
| 107 |
PCI_COMMAND_MEMORY | PCI_COMMAND_IO); |
| 108 |
pci_write_config16(dev, PCI_COMMAND, reg16); |
| 109 |
|
| 110 |
|
| 111 |
pch_disable_devfn(dev); |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
static void hda_final(struct device *dev) |
| 116 |
{ |
| 117 |
|
| 118 |
pci_or_config16(dev, 0x40, 1 << 1); |
| 119 |
} |
| 120 |
|
| 121 |
static struct device_operations hda_ops = { |
| 122 |
.read_resources = &pci_dev_read_resources, |
| 123 |
.set_resources = &pci_dev_set_resources, |
| 124 |
.enable_resources = &pci_dev_enable_resources, |
| 125 |
.init = &hda_init, |
| 126 |
.enable = &hda_enable, |
| 127 |
.final = &hda_final, |
| 128 |
.ops_pci = &pci_dev_ops_pci, |
| 129 |
}; |
| 130 |
|
| 131 |
static const unsigned short pci_device_ids[] = { |
| 132 |
0x9c20, |
| 133 |
0x9ca0, |
| 134 |
0 |
| 135 |
}; |
| 136 |
|
| 137 |
static const struct pci_driver pch_hda __pci_driver = { |
| 138 |
.ops = &hda_ops, |
| 139 |
.vendor = PCI_VID_INTEL, |
| 140 |
.devices = pci_device_ids, |
| 141 |
}; |