Angel Pons | 4b42983 | 2020-04-02 23:48:50 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 3 | |
| 4 | #include <console/console.h> |
| 5 | #include <device/device.h> |
| 6 | #include <device/pci.h> |
| 7 | #include <device/pci_ids.h> |
| 8 | #include <device/pci_ops.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 9 | #include <device/mmio.h> |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 10 | #include <southbridge/intel/lynxpoint/hda_verb.h> |
| 11 | |
| 12 | static const u32 minihd_verb_table[] = { |
| 13 | /* coreboot specific header */ |
Angel Pons | 1db5bc7 | 2020-01-15 00:49:03 +0100 | [diff] [blame] | 14 | 0x80862807, /* Codec Vendor / Device ID: Intel Haswell Mini-HD */ |
| 15 | 0x80860101, /* Subsystem ID */ |
| 16 | 4, /* Number of jacks */ |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 17 | |
| 18 | /* Enable 3rd Pin and Converter Widget */ |
| 19 | 0x00878101, |
| 20 | |
| 21 | /* Pin Widget 5 - PORT B */ |
Angel Pons | 1db5bc7 | 2020-01-15 00:49:03 +0100 | [diff] [blame] | 22 | 0x00571c10, |
| 23 | 0x00571d00, |
| 24 | 0x00571e56, |
| 25 | 0x00571f18, |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 26 | |
| 27 | /* Pin Widget 6 - PORT C */ |
Angel Pons | 1db5bc7 | 2020-01-15 00:49:03 +0100 | [diff] [blame] | 28 | 0x00671c20, |
| 29 | 0x00671d00, |
| 30 | 0x00671e56, |
| 31 | 0x00671f18, |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 32 | |
| 33 | /* Pin Widget 7 - PORT D */ |
Angel Pons | 1db5bc7 | 2020-01-15 00:49:03 +0100 | [diff] [blame] | 34 | 0x00771c30, |
| 35 | 0x00771d00, |
| 36 | 0x00771e56, |
| 37 | 0x00771f18, |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 38 | |
| 39 | /* Disable 3rd Pin and Converter Widget */ |
| 40 | 0x00878100, |
| 41 | |
| 42 | /* Dummy entries to fill out the table */ |
| 43 | 0x00878100, |
| 44 | 0x00878100, |
| 45 | }; |
| 46 | |
| 47 | static void minihd_init(struct device *dev) |
| 48 | { |
| 49 | struct resource *res; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 50 | u32 reg32; |
| 51 | u8 *base; |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 52 | int codec_mask, i; |
| 53 | |
| 54 | /* Find base address */ |
| 55 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 56 | if (!res) |
| 57 | return; |
| 58 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 59 | base = res2mmio(res, 0, 0); |
| 60 | printk(BIOS_DEBUG, "Mini-HD: base = %p\n", base); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 61 | |
| 62 | /* Set Bus Master */ |
| 63 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 64 | pci_write_config32(dev, PCI_COMMAND, reg32 | PCI_COMMAND_MASTER); |
| 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)) |
Angel Pons | 1db5bc7 | 2020-01-15 00:49:03 +0100 | [diff] [blame] | 83 | hda_codec_init(base, i, sizeof(minihd_verb_table), |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 84 | minihd_verb_table); |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 89 | static struct pci_operations minihd_pci_ops = { |
Angel Pons | 1db5bc7 | 2020-01-15 00:49:03 +0100 | [diff] [blame] | 90 | .set_subsystem = pci_dev_set_subsystem, |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | static struct device_operations minihd_ops = { |
| 94 | .read_resources = pci_dev_read_resources, |
| 95 | .set_resources = pci_dev_set_resources, |
| 96 | .enable_resources = pci_dev_enable_resources, |
| 97 | .init = minihd_init, |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 98 | .ops_pci = &minihd_pci_ops, |
| 99 | }; |
| 100 | |
Tristan Corrick | 3ffbc7c | 2018-10-31 02:22:13 +1300 | [diff] [blame] | 101 | static const unsigned short pci_device_ids[] = { 0x0a0c, 0x0c0c, 0 }; |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 102 | |
| 103 | static const struct pci_driver haswell_minihd __pci_driver = { |
| 104 | .ops = &minihd_ops, |
| 105 | .vendor = PCI_VENDOR_ID_INTEL, |
| 106 | .devices = pci_device_ids, |
| 107 | }; |