blob: 3f87fccf7f8031cc3a339e3ace303854edce1a13 [file] [log] [blame]
Duncan Laurie93142a42018-01-08 17:41:58 -08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2017 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <console/console.h>
17#include <device/device.h>
18#include <device/azalia_device.h>
19#include <device/pci.h>
20#include <device/pci_ids.h>
21#include <device/pci_ops.h>
22#include <soc/intel/common/hda_verb.h>
23#include <soc/ramstage.h>
24
25static void codecs_init(uint8_t *base, u32 codec_mask)
26{
27 int i;
28
29 /* Can support up to 4 codecs */
30 for (i = 3; i >= 0; i--) {
31 if (codec_mask & (1 << i))
32 hda_codec_init(base, i,
33 cim_verb_data_size, cim_verb_data);
34 }
35
36 if (pc_beep_verbs_size)
37 hda_codec_write(base, pc_beep_verbs_size, pc_beep_verbs);
38}
39
40static void hda_init(struct device *dev)
41{
42 struct resource *res;
43 int codec_mask;
44 uint8_t *base;
45
46 res = find_resource(dev, PCI_BASE_ADDRESS_0);
47 if (!res)
48 return;
49
50 base = res2mmio(res, 0, 0);
51 if (!base)
52 return;
53
54 codec_mask = hda_codec_detect(base);
55 if (codec_mask) {
56 printk(BIOS_INFO, "HDA: codec_mask = %02x\n", codec_mask);
57 codecs_init(base, codec_mask);
58 }
59}
60
61static struct device_operations hda_ops = {
62 .read_resources = &pci_dev_read_resources,
63 .set_resources = &pci_dev_set_resources,
64 .enable_resources = &pci_dev_enable_resources,
65 .init = &hda_init,
66 .ops_pci = &pci_dev_ops_pci,
67};
68
69static const unsigned short pci_device_ids[] = {
70 PCI_DEVICE_ID_INTEL_SKL_AUDIO,
71 PCI_DEVICE_ID_INTEL_KBL_AUDIO,
72 PCI_DEVICE_ID_INTEL_CNL_AUDIO,
73 0
74};
75
76static const struct pci_driver pch_hda __pci_driver = {
77 .ops = &hda_ops,
78 .vendor = PCI_VENDOR_ID_INTEL,
79 .devices = pci_device_ids,
80};