blob: 9cd7ad488935dd8df3de5c242afd84f317c13c7f [file] [log] [blame]
Duncan Laurie0a7c49e2013-06-20 12:40:55 -07001/*
2 * This file is part of the coreboot project.
3 *
Duncan Laurie0a7c49e2013-06-20 12:40:55 -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 Laurie0a7c49e2013-06-20 12:40:55 -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 Laurie0a7c49e2013-06-20 12:40:55 -070021#include <southbridge/intel/lynxpoint/hda_verb.h>
22
23static const u32 minihd_verb_table[] = {
24 /* coreboot specific header */
Angel Pons1db5bc72020-01-15 00:49:03 +010025 0x80862807, /* Codec Vendor / Device ID: Intel Haswell Mini-HD */
26 0x80860101, /* Subsystem ID */
27 4, /* Number of jacks */
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070028
29 /* Enable 3rd Pin and Converter Widget */
30 0x00878101,
31
32 /* Pin Widget 5 - PORT B */
Angel Pons1db5bc72020-01-15 00:49:03 +010033 0x00571c10,
34 0x00571d00,
35 0x00571e56,
36 0x00571f18,
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070037
38 /* Pin Widget 6 - PORT C */
Angel Pons1db5bc72020-01-15 00:49:03 +010039 0x00671c20,
40 0x00671d00,
41 0x00671e56,
42 0x00671f18,
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070043
44 /* Pin Widget 7 - PORT D */
Angel Pons1db5bc72020-01-15 00:49:03 +010045 0x00771c30,
46 0x00771d00,
47 0x00771e56,
48 0x00771f18,
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070049
50 /* Disable 3rd Pin and Converter Widget */
51 0x00878100,
52
53 /* Dummy entries to fill out the table */
54 0x00878100,
55 0x00878100,
56};
57
58static void minihd_init(struct device *dev)
59{
60 struct resource *res;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080061 u32 reg32;
62 u8 *base;
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070063 int codec_mask, i;
64
65 /* Find base address */
66 res = find_resource(dev, PCI_BASE_ADDRESS_0);
67 if (!res)
68 return;
69
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080070 base = res2mmio(res, 0, 0);
71 printk(BIOS_DEBUG, "Mini-HD: base = %p\n", base);
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070072
73 /* Set Bus Master */
74 reg32 = pci_read_config32(dev, PCI_COMMAND);
75 pci_write_config32(dev, PCI_COMMAND, reg32 | PCI_COMMAND_MASTER);
76
77 /* Mini-HD configuration */
78 reg32 = read32(base + 0x100c);
79 reg32 &= 0xfffc0000;
80 reg32 |= 0x4;
81 write32(base + 0x100c, reg32);
82
83 reg32 = read32(base + 0x1010);
84 reg32 &= 0xfffc0000;
85 reg32 |= 0x4b;
86 write32(base + 0x1010, reg32);
87
88 /* Init the codec and write the verb table */
89 codec_mask = hda_codec_detect(base);
90
91 if (codec_mask) {
92 for (i = 3; i >= 0; i--) {
93 if (codec_mask & (1 << i))
Angel Pons1db5bc72020-01-15 00:49:03 +010094 hda_codec_init(base, i, sizeof(minihd_verb_table),
Duncan Laurie0a7c49e2013-06-20 12:40:55 -070095 minihd_verb_table);
96 }
97 }
98}
99
Duncan Laurie0a7c49e2013-06-20 12:40:55 -0700100static struct pci_operations minihd_pci_ops = {
Angel Pons1db5bc72020-01-15 00:49:03 +0100101 .set_subsystem = pci_dev_set_subsystem,
Duncan Laurie0a7c49e2013-06-20 12:40:55 -0700102};
103
104static struct device_operations minihd_ops = {
105 .read_resources = pci_dev_read_resources,
106 .set_resources = pci_dev_set_resources,
107 .enable_resources = pci_dev_enable_resources,
108 .init = minihd_init,
Duncan Laurie0a7c49e2013-06-20 12:40:55 -0700109 .ops_pci = &minihd_pci_ops,
110};
111
Tristan Corrick3ffbc7c2018-10-31 02:22:13 +1300112static const unsigned short pci_device_ids[] = { 0x0a0c, 0x0c0c, 0 };
Duncan Laurie0a7c49e2013-06-20 12:40:55 -0700113
114static const struct pci_driver haswell_minihd __pci_driver = {
115 .ops = &minihd_ops,
116 .vendor = PCI_VENDOR_ID_INTEL,
117 .devices = pci_device_ids,
118};