blob: ee635019d59c1427fc9b64b74cce8c228477ddc9 [file] [log] [blame]
Angel Ponsf94ac9a2020-04-05 15:46:48 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Duncan Lauriec88c54c2014-04-30 16:36:13 -07002
3#include <console/console.h>
Angel Pons94b37352021-11-10 18:05:12 +01004#include <device/azalia_device.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -07005#include <device/device.h>
6#include <device/pci.h>
7#include <device/pci_ids.h>
8#include <device/pci_ops.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02009#include <device/mmio.h>
Matt DeVillierf8960a62016-11-16 23:37:43 -060010#include <soc/igd.h>
Angel Ponsb5d56f92021-06-23 12:47:49 +020011#include <southbridge/intel/lynxpoint/hda_verb.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070012
13static const u32 minihd_verb_table[] = {
14 /* coreboot specific header */
Angel Pons2ead3632020-09-24 16:50:05 +020015 0x80862808, /* Codec Vendor / Device ID: Intel Broadwell Mini-HD */
16 0x80860101, /* Subsystem ID */
17 4, /* Number of jacks */
Duncan Lauriec88c54c2014-04-30 16:36:13 -070018
19 /* Enable 3rd Pin and Converter Widget */
20 0x00878101,
21
22 /* Pin Widget 5 - PORT B */
Angel Pons2ead3632020-09-24 16:50:05 +020023 0x00571c10,
24 0x00571d00,
25 0x00571e56,
26 0x00571f18,
Duncan Lauriec88c54c2014-04-30 16:36:13 -070027
28 /* Pin Widget 6 - PORT C */
Angel Pons2ead3632020-09-24 16:50:05 +020029 0x00671c20,
30 0x00671d00,
31 0x00671e56,
32 0x00671f18,
Duncan Lauriec88c54c2014-04-30 16:36:13 -070033
34 /* Pin Widget 7 - PORT D */
Angel Pons2ead3632020-09-24 16:50:05 +020035 0x00771c30,
36 0x00771d00,
37 0x00771e56,
38 0x00771f18,
Duncan Lauriec88c54c2014-04-30 16:36:13 -070039
40 /* Disable 3rd Pin and Converter Widget */
41 0x00878100,
42
43 /* Dummy entries to fill out the table */
44 0x00878100,
45 0x00878100,
46};
47
48static void minihd_init(struct device *dev)
49{
50 struct resource *res;
Jacob Garberea61c0e2019-07-22 12:53:27 -060051 u32 reg32;
Angel Pons2ead3632020-09-24 16:50:05 +020052 u8 *base;
Duncan Lauriec88c54c2014-04-30 16:36:13 -070053 int codec_mask, i;
54
55 /* Find base address */
Angel Ponsc1bfbe02021-11-03 13:18:53 +010056 res = probe_resource(dev, PCI_BASE_ADDRESS_0);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070057 if (!res)
58 return;
59
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080060 base = res2mmio(res, 0, 0);
61 printk(BIOS_DEBUG, "Mini-HD: base = %p\n", base);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070062
63 /* Set Bus Master */
Elyes HAOUASb887adf2020-04-29 10:42:34 +020064 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070065
66 /* Mini-HD configuration */
67 reg32 = read32(base + 0x100c);
68 reg32 &= 0xfffc0000;
69 reg32 |= 0x4;
70 write32(base + 0x100c, reg32);
71
72 reg32 = read32(base + 0x1010);
73 reg32 &= 0xfffc0000;
74 reg32 |= 0x4b;
75 write32(base + 0x1010, reg32);
76
77 /* Init the codec and write the verb table */
78 codec_mask = hda_codec_detect(base);
79
80 if (codec_mask) {
81 for (i = 3; i >= 0; i--) {
82 if (codec_mask & (1 << i))
Angel Pons94b37352021-11-10 18:05:12 +010083 azalia_codec_init(base, i, minihd_verb_table,
84 sizeof(minihd_verb_table));
Duncan Lauriec88c54c2014-04-30 16:36:13 -070085 }
86 }
Matt DeVillierf8960a62016-11-16 23:37:43 -060087
88 /* Set EM4/EM5 registers */
89 write32(base + 0x0100c, igd_get_reg_em4());
90 write32(base + 0x01010, igd_get_reg_em5());
Duncan Lauriec88c54c2014-04-30 16:36:13 -070091}
92
93static struct device_operations minihd_ops = {
Angel Pons2ead3632020-09-24 16:50:05 +020094 .read_resources = pci_dev_read_resources,
95 .set_resources = pci_dev_set_resources,
96 .enable_resources = pci_dev_enable_resources,
97 .init = minihd_init,
Angel Ponscb2080f2020-10-23 15:45:44 +020098 .ops_pci = &pci_dev_ops_pci,
Duncan Lauriec88c54c2014-04-30 16:36:13 -070099};
100
101static const unsigned short pci_device_ids[] = {
102 0x0a0c, /* Haswell */
103 0x160c, /* Broadwell */
104 0
105};
106
107static const struct pci_driver minihd_driver __pci_driver = {
108 .ops = &minihd_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100109 .vendor = PCI_VID_INTEL,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700110 .devices = pci_device_ids,
111};