blob: dd1ba1556b96fba74c71cd50bc65edd49894c7e0 [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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19#include <arch/io.h>
20#include <console/console.h>
21#include <device/device.h>
22#include <device/pci.h>
23#include <device/pci_def.h>
24#include <device/pci_ids.h>
25#include <reg_script.h>
26
Duncan Laurief0aaa292014-04-22 10:48:29 -070027#include <soc/intel/common/hda_verb.h>
Julius Werner18ea2d32014-10-07 16:42:17 -070028#include <soc/iomap.h>
29#include <soc/iosf.h>
30#include <soc/pci_devs.h>
31#include <soc/ramstage.h>
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080032
33static const struct reg_script init_ops[] = {
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080034 /* Enable no snoop traffic. */
35 REG_PCI_OR16(0x78, 1 << 11),
36 /* Configure HDMI codec connection. */
37 REG_PCI_OR32(0xc4, 1 << 1),
38 REG_PCI_OR8(0x43, (1 << 3) | (1 << 6)),
39 REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_PWRGT_CONTROL, 0xc0),
40 REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_PWRGT_CONTROL, 0x00),
41 /* Configure internal settings. */
42 REG_PCI_OR32(0xc0, 0x7 << 21),
43 REG_PCI_OR32(0xc4, (0x3 << 26) | (1 << 13) | (1 << 10)),
44 REG_PCI_WRITE32(0xc8, 0x82a30000),
45 REG_PCI_RMW32(0xd0, ~(1 << 31), 0x0),
46 /* Disable docking. */
47 REG_PCI_RMW8(0x4d, ~(1 << 7), 0),
48 REG_SCRIPT_END,
49};
50
51static const uint32_t hdmi_codec_verb_table[] = {
52 /* coreboot specific header */
53 0x80862882, /* vid did for hdmi codec */
54 0x00000000, /* subsystem id */
55 0x00000003, /* number of jacks */
56
57 /* pin widget 5 - port B */
58 0x20471c10,
59 0x20471d00,
60 0x20471e56,
61 0x20471f18,
62
63 /* pin widget 6 - port C */
64 0x20571c20,
65 0x20571d00,
66 0x20571e56,
67 0x20571f18,
68
69 /* pin widget 7 - port D */
70 0x20671c30,
71 0x20671d00,
72 0x20671e56,
73 0x20671f58,
74};
75
76static void hda_init(device_t dev)
77{
78 struct resource *res;
79 int codec_mask;
80 int i;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080081 u8 *base;
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080082
83 reg_script_run_on_dev(dev, init_ops);
84
85 res = find_resource(dev, PCI_BASE_ADDRESS_0);
86 if (res == NULL)
87 return;
88
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080089 base = res2mmio(res, 0, 0);
90 codec_mask = hda_codec_detect(base);
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080091
92 printk(BIOS_DEBUG, "codec mask = %x\n", codec_mask);
93 if (!codec_mask)
94 return;
95
96 for (i = 3; i >= 0; i--) {
97 if (!((1 << i) & codec_mask))
98 continue;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080099 hda_codec_init(base, i, sizeof(hdmi_codec_verb_table),
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800100 hdmi_codec_verb_table);
101 }
102}
103
104static const struct device_operations device_ops = {
105 .read_resources = pci_dev_read_resources,
106 .set_resources = pci_dev_set_resources,
107 .enable_resources = pci_dev_enable_resources,
108 .init = hda_init,
109 .enable = NULL,
110 .scan_bus = NULL,
111 .ops_pci = &soc_pci_ops,
112};
113
114static const struct pci_driver southcluster __pci_driver = {
115 .ops = &device_ops,
116 .vendor = PCI_VENDOR_ID_INTEL,
117 .device = HDA_DEVID,
118};