blob: 45430070d244e49689e74adf60764eea06e3b81b [file] [log] [blame]
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -08001/*
2 * This file is part of the coreboot project.
3 *
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -08004 *
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.
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080013 */
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080014#include <console/console.h>
15#include <device/device.h>
16#include <device/pci.h>
17#include <device/pci_def.h>
18#include <device/pci_ids.h>
19#include <reg_script.h>
20
Duncan Laurief0aaa292014-04-22 10:48:29 -070021#include <soc/intel/common/hda_verb.h>
Julius Werner18ea2d32014-10-07 16:42:17 -070022#include <soc/iomap.h>
23#include <soc/iosf.h>
24#include <soc/pci_devs.h>
25#include <soc/ramstage.h>
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080026
27static const struct reg_script init_ops[] = {
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080028 /* Enable no snoop traffic. */
29 REG_PCI_OR16(0x78, 1 << 11),
30 /* Configure HDMI codec connection. */
31 REG_PCI_OR32(0xc4, 1 << 1),
32 REG_PCI_OR8(0x43, (1 << 3) | (1 << 6)),
33 REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_PWRGT_CONTROL, 0xc0),
34 REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_PWRGT_CONTROL, 0x00),
35 /* Configure internal settings. */
36 REG_PCI_OR32(0xc0, 0x7 << 21),
37 REG_PCI_OR32(0xc4, (0x3 << 26) | (1 << 13) | (1 << 10)),
38 REG_PCI_WRITE32(0xc8, 0x82a30000),
39 REG_PCI_RMW32(0xd0, ~(1 << 31), 0x0),
40 /* Disable docking. */
41 REG_PCI_RMW8(0x4d, ~(1 << 7), 0),
42 REG_SCRIPT_END,
43};
44
45static const uint32_t hdmi_codec_verb_table[] = {
46 /* coreboot specific header */
47 0x80862882, /* vid did for hdmi codec */
48 0x00000000, /* subsystem id */
49 0x00000003, /* number of jacks */
50
51 /* pin widget 5 - port B */
52 0x20471c10,
53 0x20471d00,
54 0x20471e56,
55 0x20471f18,
56
57 /* pin widget 6 - port C */
58 0x20571c20,
59 0x20571d00,
60 0x20571e56,
61 0x20571f18,
62
63 /* pin widget 7 - port D */
64 0x20671c30,
65 0x20671d00,
66 0x20671e56,
67 0x20671f58,
68};
69
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020070static void hda_init(struct device *dev)
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080071{
72 struct resource *res;
73 int codec_mask;
74 int i;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080075 u8 *base;
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080076
77 reg_script_run_on_dev(dev, init_ops);
78
79 res = find_resource(dev, PCI_BASE_ADDRESS_0);
80 if (res == NULL)
81 return;
82
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080083 base = res2mmio(res, 0, 0);
84 codec_mask = hda_codec_detect(base);
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080085
86 printk(BIOS_DEBUG, "codec mask = %x\n", codec_mask);
87 if (!codec_mask)
88 return;
89
90 for (i = 3; i >= 0; i--) {
91 if (!((1 << i) & codec_mask))
92 continue;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080093 hda_codec_init(base, i, sizeof(hdmi_codec_verb_table),
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080094 hdmi_codec_verb_table);
95 }
96}
97
98static const struct device_operations device_ops = {
99 .read_resources = pci_dev_read_resources,
100 .set_resources = pci_dev_set_resources,
101 .enable_resources = pci_dev_enable_resources,
102 .init = hda_init,
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800103 .ops_pci = &soc_pci_ops,
104};
105
106static const struct pci_driver southcluster __pci_driver = {
107 .ops = &device_ops,
108 .vendor = PCI_VENDOR_ID_INTEL,
109 .device = HDA_DEVID,
110};