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