Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [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. |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 13 | */ |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 14 | #include <console/console.h> |
| 15 | #include <device/device.h> |
| 16 | #include <device/pci.h> |
| 17 | #include <device/pci_def.h> |
| 18 | #include <device/pci_ids.h> |
| 19 | #include <reg_script.h> |
| 20 | |
Duncan Laurie | f0aaa29 | 2014-04-22 10:48:29 -0700 | [diff] [blame] | 21 | #include <soc/intel/common/hda_verb.h> |
Julius Werner | 18ea2d3 | 2014-10-07 16:42:17 -0700 | [diff] [blame] | 22 | #include <soc/iomap.h> |
| 23 | #include <soc/iosf.h> |
| 24 | #include <soc/pci_devs.h> |
| 25 | #include <soc/ramstage.h> |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 26 | |
| 27 | static const struct reg_script init_ops[] = { |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 28 | /* Enable no snoop traffic. */ |
| 29 | REG_PCI_OR16(0x78, 1 << 11), |
| 30 | /* Configure HDMI codec connection. */ |
| 31 | REG_PCI_OR32(0xc4, 1 << 1), |
| 32 | REG_PCI_OR8(0x43, (1 << 3) | (1 << 6)), |
| 33 | REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_PWRGT_CONTROL, 0xc0), |
| 34 | REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_PWRGT_CONTROL, 0x00), |
| 35 | /* Configure internal settings. */ |
| 36 | REG_PCI_OR32(0xc0, 0x7 << 21), |
| 37 | REG_PCI_OR32(0xc4, (0x3 << 26) | (1 << 13) | (1 << 10)), |
| 38 | REG_PCI_WRITE32(0xc8, 0x82a30000), |
| 39 | REG_PCI_RMW32(0xd0, ~(1 << 31), 0x0), |
| 40 | /* Disable docking. */ |
| 41 | REG_PCI_RMW8(0x4d, ~(1 << 7), 0), |
| 42 | REG_SCRIPT_END, |
| 43 | }; |
| 44 | |
| 45 | static const uint32_t hdmi_codec_verb_table[] = { |
| 46 | /* coreboot specific header */ |
| 47 | 0x80862882, /* vid did for hdmi codec */ |
| 48 | 0x00000000, /* subsystem id */ |
| 49 | 0x00000003, /* number of jacks */ |
| 50 | |
| 51 | /* pin widget 5 - port B */ |
| 52 | 0x20471c10, |
| 53 | 0x20471d00, |
| 54 | 0x20471e56, |
| 55 | 0x20471f18, |
| 56 | |
| 57 | /* pin widget 6 - port C */ |
| 58 | 0x20571c20, |
| 59 | 0x20571d00, |
| 60 | 0x20571e56, |
| 61 | 0x20571f18, |
| 62 | |
| 63 | /* pin widget 7 - port D */ |
| 64 | 0x20671c30, |
| 65 | 0x20671d00, |
| 66 | 0x20671e56, |
| 67 | 0x20671f58, |
| 68 | }; |
| 69 | |
Elyes HAOUAS | 17a3ceb | 2018-05-22 10:42:28 +0200 | [diff] [blame] | 70 | static void hda_init(struct device *dev) |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 71 | { |
| 72 | struct resource *res; |
| 73 | int codec_mask; |
| 74 | int i; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 75 | u8 *base; |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 76 | |
| 77 | reg_script_run_on_dev(dev, init_ops); |
| 78 | |
| 79 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 80 | if (res == NULL) |
| 81 | return; |
| 82 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 83 | base = res2mmio(res, 0, 0); |
| 84 | codec_mask = hda_codec_detect(base); |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 85 | |
| 86 | printk(BIOS_DEBUG, "codec mask = %x\n", codec_mask); |
| 87 | if (!codec_mask) |
| 88 | return; |
| 89 | |
| 90 | for (i = 3; i >= 0; i--) { |
| 91 | if (!((1 << i) & codec_mask)) |
| 92 | continue; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 93 | hda_codec_init(base, i, sizeof(hdmi_codec_verb_table), |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 94 | hdmi_codec_verb_table); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | static const struct device_operations device_ops = { |
| 99 | .read_resources = pci_dev_read_resources, |
| 100 | .set_resources = pci_dev_set_resources, |
| 101 | .enable_resources = pci_dev_enable_resources, |
| 102 | .init = hda_init, |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 103 | .ops_pci = &soc_pci_ops, |
| 104 | }; |
| 105 | |
| 106 | static const struct pci_driver southcluster __pci_driver = { |
| 107 | .ops = &device_ops, |
| 108 | .vendor = PCI_VENDOR_ID_INTEL, |
| 109 | .device = HDA_DEVID, |
| 110 | }; |