blob: a9fc3d688b595ea333a885fa0d75cbe3823ab4f6 [file] [log] [blame]
Duncan Lauriec88c54c2014-04-30 16:36:13 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
5 * Copyright (C) 2008-2009 coresystems GmbH
6 * Copyright (C) 2014 Google Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Duncan Lauriec88c54c2014-04-30 16:36:13 -070016 */
17
18#include <console/console.h>
19#include <device/device.h>
20#include <device/pci.h>
21#include <device/pci_ids.h>
22#include <device/pci_ops.h>
23#include <arch/io.h>
24#include <delay.h>
25#include <stdlib.h>
26#include <soc/intel/common/hda_verb.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070027#include <soc/ramstage.h>
Matt DeVillierf8960a62016-11-16 23:37:43 -060028#include <soc/igd.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070029
30static const u32 minihd_verb_table[] = {
31 /* coreboot specific header */
32 0x80862807, // Codec Vendor / Device ID: Intel Mini-HD
33 0x00000000, // Subsystem ID
34 0x00000004, // Number of jacks
35
36 /* Enable 3rd Pin and Converter Widget */
37 0x00878101,
38
39 /* Pin Widget 5 - PORT B */
40 0x00571C10,
41 0x00571D00,
42 0x00571E56,
43 0x00571F18,
44
45 /* Pin Widget 6 - PORT C */
46 0x00671C20,
47 0x00671D00,
48 0x00671E56,
49 0x00671F18,
50
51 /* Pin Widget 7 - PORT D */
52 0x00771C30,
53 0x00771D00,
54 0x00771E56,
55 0x00771F18,
56
57 /* Disable 3rd Pin and Converter Widget */
58 0x00878100,
59
60 /* Dummy entries to fill out the table */
61 0x00878100,
62 0x00878100,
63};
64
65static void minihd_init(struct device *dev)
66{
67 struct resource *res;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080068 u8 *base, reg32;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070069 int codec_mask, i;
70
71 /* Find base address */
72 res = find_resource(dev, PCI_BASE_ADDRESS_0);
73 if (!res)
74 return;
75
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080076 base = res2mmio(res, 0, 0);
77 printk(BIOS_DEBUG, "Mini-HD: base = %p\n", base);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070078
79 /* Set Bus Master */
80 reg32 = pci_read_config32(dev, PCI_COMMAND);
81 pci_write_config32(dev, PCI_COMMAND, reg32 | PCI_COMMAND_MASTER);
82
83 /* Mini-HD configuration */
84 reg32 = read32(base + 0x100c);
85 reg32 &= 0xfffc0000;
86 reg32 |= 0x4;
87 write32(base + 0x100c, reg32);
88
89 reg32 = read32(base + 0x1010);
90 reg32 &= 0xfffc0000;
91 reg32 |= 0x4b;
92 write32(base + 0x1010, reg32);
93
94 /* Init the codec and write the verb table */
95 codec_mask = hda_codec_detect(base);
96
97 if (codec_mask) {
98 for (i = 3; i >= 0; i--) {
99 if (codec_mask & (1 << i))
100 hda_codec_init(base, i,
101 sizeof(minihd_verb_table),
102 minihd_verb_table);
103 }
104 }
Matt DeVillierf8960a62016-11-16 23:37:43 -0600105
106 /* Set EM4/EM5 registers */
107 write32(base + 0x0100c, igd_get_reg_em4());
108 write32(base + 0x01010, igd_get_reg_em5());
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700109}
110
111static struct device_operations minihd_ops = {
112 .read_resources = &pci_dev_read_resources,
113 .set_resources = &pci_dev_set_resources,
114 .enable_resources = &pci_dev_enable_resources,
115 .init = &minihd_init,
116 .ops_pci = &broadwell_pci_ops,
117};
118
119static const unsigned short pci_device_ids[] = {
120 0x0a0c, /* Haswell */
121 0x160c, /* Broadwell */
122 0
123};
124
125static const struct pci_driver minihd_driver __pci_driver = {
126 .ops = &minihd_ops,
127 .vendor = PCI_VENDOR_ID_INTEL,
128 .devices = pci_device_ids,
129};