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