Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 4 | * |
| 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 Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 13 | */ |
| 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älkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 20 | #include <device/mmio.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 21 | #include <soc/intel/common/hda_verb.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 22 | #include <soc/ramstage.h> |
Matt DeVillier | f8960a6 | 2016-11-16 23:37:43 -0600 | [diff] [blame] | 23 | #include <soc/igd.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 24 | |
| 25 | static const u32 minihd_verb_table[] = { |
| 26 | /* coreboot specific header */ |
Matt DeVillier | eafa203 | 2019-12-19 19:39:25 -0600 | [diff] [blame] | 27 | 0x80862808, // Codec Vendor / Device ID: Intel Broadwell Mini-HD |
| 28 | 0x80860101, // Subsystem ID |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 29 | 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 | |
| 60 | static void minihd_init(struct device *dev) |
| 61 | { |
| 62 | struct resource *res; |
Jacob Garber | ea61c0e | 2019-07-22 12:53:27 -0600 | [diff] [blame] | 63 | u8 *base; |
| 64 | u32 reg32; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 65 | 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 Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 72 | base = res2mmio(res, 0, 0); |
| 73 | printk(BIOS_DEBUG, "Mini-HD: base = %p\n", base); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 74 | |
| 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 DeVillier | f8960a6 | 2016-11-16 23:37:43 -0600 | [diff] [blame] | 101 | |
| 102 | /* Set EM4/EM5 registers */ |
| 103 | write32(base + 0x0100c, igd_get_reg_em4()); |
| 104 | write32(base + 0x01010, igd_get_reg_em5()); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static 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 | |
| 115 | static const unsigned short pci_device_ids[] = { |
| 116 | 0x0a0c, /* Haswell */ |
| 117 | 0x160c, /* Broadwell */ |
| 118 | 0 |
| 119 | }; |
| 120 | |
| 121 | static const struct pci_driver minihd_driver __pci_driver = { |
| 122 | .ops = &minihd_ops, |
| 123 | .vendor = PCI_VENDOR_ID_INTEL, |
| 124 | .devices = pci_device_ids, |
| 125 | }; |