Angel Pons | f94ac9a | 2020-04-05 15:46:48 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 2 | |
| 3 | #include <console/console.h> |
| 4 | #include <device/device.h> |
| 5 | #include <device/pci.h> |
| 6 | #include <device/pci_ids.h> |
| 7 | #include <device/pci_ops.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 8 | #include <device/mmio.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 9 | #include <soc/intel/common/hda_verb.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 10 | #include <soc/ramstage.h> |
Matt DeVillier | f8960a6 | 2016-11-16 23:37:43 -0600 | [diff] [blame] | 11 | #include <soc/igd.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 12 | |
| 13 | static const u32 minihd_verb_table[] = { |
| 14 | /* coreboot specific header */ |
Matt DeVillier | eafa203 | 2019-12-19 19:39:25 -0600 | [diff] [blame] | 15 | 0x80862808, // Codec Vendor / Device ID: Intel Broadwell Mini-HD |
| 16 | 0x80860101, // Subsystem ID |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 17 | 0x00000004, // Number of jacks |
| 18 | |
| 19 | /* Enable 3rd Pin and Converter Widget */ |
| 20 | 0x00878101, |
| 21 | |
| 22 | /* Pin Widget 5 - PORT B */ |
| 23 | 0x00571C10, |
| 24 | 0x00571D00, |
| 25 | 0x00571E56, |
| 26 | 0x00571F18, |
| 27 | |
| 28 | /* Pin Widget 6 - PORT C */ |
| 29 | 0x00671C20, |
| 30 | 0x00671D00, |
| 31 | 0x00671E56, |
| 32 | 0x00671F18, |
| 33 | |
| 34 | /* Pin Widget 7 - PORT D */ |
| 35 | 0x00771C30, |
| 36 | 0x00771D00, |
| 37 | 0x00771E56, |
| 38 | 0x00771F18, |
| 39 | |
| 40 | /* Disable 3rd Pin and Converter Widget */ |
| 41 | 0x00878100, |
| 42 | |
| 43 | /* Dummy entries to fill out the table */ |
| 44 | 0x00878100, |
| 45 | 0x00878100, |
| 46 | }; |
| 47 | |
| 48 | static void minihd_init(struct device *dev) |
| 49 | { |
| 50 | struct resource *res; |
Jacob Garber | ea61c0e | 2019-07-22 12:53:27 -0600 | [diff] [blame] | 51 | u8 *base; |
| 52 | u32 reg32; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 53 | int codec_mask, i; |
| 54 | |
| 55 | /* Find base address */ |
| 56 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 57 | if (!res) |
| 58 | return; |
| 59 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 60 | base = res2mmio(res, 0, 0); |
| 61 | printk(BIOS_DEBUG, "Mini-HD: base = %p\n", base); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 62 | |
| 63 | /* Set Bus Master */ |
Elyes HAOUAS | b887adf | 2020-04-29 10:42:34 +0200 | [diff] [blame] | 64 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 65 | |
| 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)) |
| 83 | hda_codec_init(base, i, |
| 84 | sizeof(minihd_verb_table), |
| 85 | minihd_verb_table); |
| 86 | } |
| 87 | } |
Matt DeVillier | f8960a6 | 2016-11-16 23:37:43 -0600 | [diff] [blame] | 88 | |
| 89 | /* Set EM4/EM5 registers */ |
| 90 | write32(base + 0x0100c, igd_get_reg_em4()); |
| 91 | write32(base + 0x01010, igd_get_reg_em5()); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | static struct device_operations minihd_ops = { |
| 95 | .read_resources = &pci_dev_read_resources, |
| 96 | .set_resources = &pci_dev_set_resources, |
| 97 | .enable_resources = &pci_dev_enable_resources, |
| 98 | .init = &minihd_init, |
| 99 | .ops_pci = &broadwell_pci_ops, |
| 100 | }; |
| 101 | |
| 102 | static const unsigned short pci_device_ids[] = { |
| 103 | 0x0a0c, /* Haswell */ |
| 104 | 0x160c, /* Broadwell */ |
| 105 | 0 |
| 106 | }; |
| 107 | |
| 108 | static const struct pci_driver minihd_driver __pci_driver = { |
| 109 | .ops = &minihd_ops, |
| 110 | .vendor = PCI_VENDOR_ID_INTEL, |
| 111 | .devices = pci_device_ids, |
| 112 | }; |