Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -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 | 0a7c49e | 2013-06-20 12:40:55 -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 | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 21 | #include <southbridge/intel/lynxpoint/hda_verb.h> |
| 22 | |
| 23 | static const u32 minihd_verb_table[] = { |
| 24 | /* coreboot specific header */ |
Angel Pons | 1db5bc7 | 2020-01-15 00:49:03 +0100 | [diff] [blame] | 25 | 0x80862807, /* Codec Vendor / Device ID: Intel Haswell Mini-HD */ |
| 26 | 0x80860101, /* Subsystem ID */ |
| 27 | 4, /* Number of jacks */ |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 28 | |
| 29 | /* Enable 3rd Pin and Converter Widget */ |
| 30 | 0x00878101, |
| 31 | |
| 32 | /* Pin Widget 5 - PORT B */ |
Angel Pons | 1db5bc7 | 2020-01-15 00:49:03 +0100 | [diff] [blame] | 33 | 0x00571c10, |
| 34 | 0x00571d00, |
| 35 | 0x00571e56, |
| 36 | 0x00571f18, |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 37 | |
| 38 | /* Pin Widget 6 - PORT C */ |
Angel Pons | 1db5bc7 | 2020-01-15 00:49:03 +0100 | [diff] [blame] | 39 | 0x00671c20, |
| 40 | 0x00671d00, |
| 41 | 0x00671e56, |
| 42 | 0x00671f18, |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 43 | |
| 44 | /* Pin Widget 7 - PORT D */ |
Angel Pons | 1db5bc7 | 2020-01-15 00:49:03 +0100 | [diff] [blame] | 45 | 0x00771c30, |
| 46 | 0x00771d00, |
| 47 | 0x00771e56, |
| 48 | 0x00771f18, |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 49 | |
| 50 | /* Disable 3rd Pin and Converter Widget */ |
| 51 | 0x00878100, |
| 52 | |
| 53 | /* Dummy entries to fill out the table */ |
| 54 | 0x00878100, |
| 55 | 0x00878100, |
| 56 | }; |
| 57 | |
| 58 | static void minihd_init(struct device *dev) |
| 59 | { |
| 60 | struct resource *res; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 61 | u32 reg32; |
| 62 | u8 *base; |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 63 | int codec_mask, i; |
| 64 | |
| 65 | /* Find base address */ |
| 66 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 67 | if (!res) |
| 68 | return; |
| 69 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 70 | base = res2mmio(res, 0, 0); |
| 71 | printk(BIOS_DEBUG, "Mini-HD: base = %p\n", base); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 72 | |
| 73 | /* Set Bus Master */ |
| 74 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 75 | pci_write_config32(dev, PCI_COMMAND, reg32 | PCI_COMMAND_MASTER); |
| 76 | |
| 77 | /* Mini-HD configuration */ |
| 78 | reg32 = read32(base + 0x100c); |
| 79 | reg32 &= 0xfffc0000; |
| 80 | reg32 |= 0x4; |
| 81 | write32(base + 0x100c, reg32); |
| 82 | |
| 83 | reg32 = read32(base + 0x1010); |
| 84 | reg32 &= 0xfffc0000; |
| 85 | reg32 |= 0x4b; |
| 86 | write32(base + 0x1010, reg32); |
| 87 | |
| 88 | /* Init the codec and write the verb table */ |
| 89 | codec_mask = hda_codec_detect(base); |
| 90 | |
| 91 | if (codec_mask) { |
| 92 | for (i = 3; i >= 0; i--) { |
| 93 | if (codec_mask & (1 << i)) |
Angel Pons | 1db5bc7 | 2020-01-15 00:49:03 +0100 | [diff] [blame] | 94 | hda_codec_init(base, i, sizeof(minihd_verb_table), |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 95 | minihd_verb_table); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 100 | static struct pci_operations minihd_pci_ops = { |
Angel Pons | 1db5bc7 | 2020-01-15 00:49:03 +0100 | [diff] [blame] | 101 | .set_subsystem = pci_dev_set_subsystem, |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | static struct device_operations minihd_ops = { |
| 105 | .read_resources = pci_dev_read_resources, |
| 106 | .set_resources = pci_dev_set_resources, |
| 107 | .enable_resources = pci_dev_enable_resources, |
| 108 | .init = minihd_init, |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 109 | .ops_pci = &minihd_pci_ops, |
| 110 | }; |
| 111 | |
Tristan Corrick | 3ffbc7c | 2018-10-31 02:22:13 +1300 | [diff] [blame] | 112 | static const unsigned short pci_device_ids[] = { 0x0a0c, 0x0c0c, 0 }; |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 113 | |
| 114 | static const struct pci_driver haswell_minihd __pci_driver = { |
| 115 | .ops = &minihd_ops, |
| 116 | .vendor = PCI_VENDOR_ID_INTEL, |
| 117 | .devices = pci_device_ids, |
| 118 | }; |