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