blob: af3cea470b6a2c6848376234f7557e022f013537 [file] [log] [blame]
Duncan Lauriec88c54c2014-04-30 16:36:13 -07001/*
2 * This file is part of the coreboot project.
3 *
Duncan Lauriec88c54c2014-04-30 16:36:13 -07004 *
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.
Duncan Lauriec88c54c2014-04-30 16:36:13 -070013 */
14
15#include <console/console.h>
16#include <device/device.h>
17#include <device/pci.h>
18#include <device/pci_ids.h>
19#include <device/pci_ops.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020020#include <device/mmio.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070021#include <soc/intel/common/hda_verb.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070022#include <soc/ramstage.h>
Matt DeVillierf8960a62016-11-16 23:37:43 -060023#include <soc/igd.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070024
25static const u32 minihd_verb_table[] = {
26 /* coreboot specific header */
Matt DeVilliereafa2032019-12-19 19:39:25 -060027 0x80862808, // Codec Vendor / Device ID: Intel Broadwell Mini-HD
28 0x80860101, // Subsystem ID
Duncan Lauriec88c54c2014-04-30 16:36:13 -070029 0x00000004, // Number of jacks
30
31 /* Enable 3rd Pin and Converter Widget */
32 0x00878101,
33
34 /* Pin Widget 5 - PORT B */
35 0x00571C10,
36 0x00571D00,
37 0x00571E56,
38 0x00571F18,
39
40 /* Pin Widget 6 - PORT C */
41 0x00671C20,
42 0x00671D00,
43 0x00671E56,
44 0x00671F18,
45
46 /* Pin Widget 7 - PORT D */
47 0x00771C30,
48 0x00771D00,
49 0x00771E56,
50 0x00771F18,
51
52 /* Disable 3rd Pin and Converter Widget */
53 0x00878100,
54
55 /* Dummy entries to fill out the table */
56 0x00878100,
57 0x00878100,
58};
59
60static void minihd_init(struct device *dev)
61{
62 struct resource *res;
Jacob Garberea61c0e2019-07-22 12:53:27 -060063 u8 *base;
64 u32 reg32;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070065 int codec_mask, i;
66
67 /* Find base address */
68 res = find_resource(dev, PCI_BASE_ADDRESS_0);
69 if (!res)
70 return;
71
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080072 base = res2mmio(res, 0, 0);
73 printk(BIOS_DEBUG, "Mini-HD: base = %p\n", base);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070074
75 /* Set Bus Master */
76 reg32 = pci_read_config32(dev, PCI_COMMAND);
77 pci_write_config32(dev, PCI_COMMAND, reg32 | PCI_COMMAND_MASTER);
78
79 /* Mini-HD configuration */
80 reg32 = read32(base + 0x100c);
81 reg32 &= 0xfffc0000;
82 reg32 |= 0x4;
83 write32(base + 0x100c, reg32);
84
85 reg32 = read32(base + 0x1010);
86 reg32 &= 0xfffc0000;
87 reg32 |= 0x4b;
88 write32(base + 0x1010, reg32);
89
90 /* Init the codec and write the verb table */
91 codec_mask = hda_codec_detect(base);
92
93 if (codec_mask) {
94 for (i = 3; i >= 0; i--) {
95 if (codec_mask & (1 << i))
96 hda_codec_init(base, i,
97 sizeof(minihd_verb_table),
98 minihd_verb_table);
99 }
100 }
Matt DeVillierf8960a62016-11-16 23:37:43 -0600101
102 /* Set EM4/EM5 registers */
103 write32(base + 0x0100c, igd_get_reg_em4());
104 write32(base + 0x01010, igd_get_reg_em5());
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700105}
106
107static struct device_operations minihd_ops = {
108 .read_resources = &pci_dev_read_resources,
109 .set_resources = &pci_dev_set_resources,
110 .enable_resources = &pci_dev_enable_resources,
111 .init = &minihd_init,
112 .ops_pci = &broadwell_pci_ops,
113};
114
115static const unsigned short pci_device_ids[] = {
116 0x0a0c, /* Haswell */
117 0x160c, /* Broadwell */
118 0
119};
120
121static const struct pci_driver minihd_driver __pci_driver = {
122 .ops = &minihd_ops,
123 .vendor = PCI_VENDOR_ID_INTEL,
124 .devices = pci_device_ids,
125};