blob: cef61263be8bbaec9c98efe049127107698c9fd6 [file] [log] [blame]
Duncan Laurie0a7c49e2013-06-20 12:40:55 -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) 2011 The ChromiumOS Authors. All rights reserved.
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.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <console/console.h>
23#include <device/device.h>
24#include <device/pci.h>
25#include <device/pci_ids.h>
26#include <device/pci_ops.h>
27#include <arch/io.h>
28#include <delay.h>
29#include <stdlib.h>
30#include <southbridge/intel/lynxpoint/hda_verb.h>
31
32static const u32 minihd_verb_table[] = {
33 /* coreboot specific header */
34 0x80862807, // Codec Vendor / Device ID: Intel Haswell Mini-HD
35 0x00000000, // Subsystem ID
36 0x00000004, // Number of jacks
37
38 /* Enable 3rd Pin and Converter Widget */
39 0x00878101,
40
41 /* Pin Widget 5 - PORT B */
42 0x00571C10,
43 0x00571D00,
44 0x00571E56,
45 0x00571F18,
46
47 /* Pin Widget 6 - PORT C */
48 0x00671C20,
49 0x00671D00,
50 0x00671E56,
51 0x00671F18,
52
53 /* Pin Widget 7 - PORT D */
54 0x00771C30,
55 0x00771D00,
56 0x00771E56,
57 0x00771F18,
58
59 /* Disable 3rd Pin and Converter Widget */
60 0x00878100,
61
62 /* Dummy entries to fill out the table */
63 0x00878100,
64 0x00878100,
65};
66
67static void minihd_init(struct device *dev)
68{
69 struct resource *res;
70 u32 base, reg32;
71 int codec_mask, i;
72
73 /* Find base address */
74 res = find_resource(dev, PCI_BASE_ADDRESS_0);
75 if (!res)
76 return;
77
78 base = (u32)res->base;
79 printk(BIOS_DEBUG, "Mini-HD: base = %08x\n", (u32)base);
80
81 /* Set Bus Master */
82 reg32 = pci_read_config32(dev, PCI_COMMAND);
83 pci_write_config32(dev, PCI_COMMAND, reg32 | PCI_COMMAND_MASTER);
84
85 /* Mini-HD configuration */
86 reg32 = read32(base + 0x100c);
87 reg32 &= 0xfffc0000;
88 reg32 |= 0x4;
89 write32(base + 0x100c, reg32);
90
91 reg32 = read32(base + 0x1010);
92 reg32 &= 0xfffc0000;
93 reg32 |= 0x4b;
94 write32(base + 0x1010, reg32);
95
96 /* Init the codec and write the verb table */
97 codec_mask = hda_codec_detect(base);
98
99 if (codec_mask) {
100 for (i = 3; i >= 0; i--) {
101 if (codec_mask & (1 << i))
102 hda_codec_init(base, i,
103 sizeof(minihd_verb_table),
104 minihd_verb_table);
105 }
106 }
107}
108
109static void minihd_set_subsystem(device_t dev, unsigned vendor, unsigned device)
110{
111 if (!vendor || !device) {
112 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
113 pci_read_config32(dev, PCI_VENDOR_ID));
114 } else {
115 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
116 ((device & 0xffff) << 16) | (vendor & 0xffff));
117 }
118}
119
120static struct pci_operations minihd_pci_ops = {
121 .set_subsystem = minihd_set_subsystem,
122};
123
124static struct device_operations minihd_ops = {
125 .read_resources = pci_dev_read_resources,
126 .set_resources = pci_dev_set_resources,
127 .enable_resources = pci_dev_enable_resources,
128 .init = minihd_init,
129 .scan_bus = 0,
130 .ops_pci = &minihd_pci_ops,
131};
132
133static const unsigned short pci_device_ids[] = { 0x0a0c, 0 };
134
135static const struct pci_driver haswell_minihd __pci_driver = {
136 .ops = &minihd_ops,
137 .vendor = PCI_VENDOR_ID_INTEL,
138 .devices = pci_device_ids,
139};
140