coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
hda.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #include <console/console.h>
3 #include <device/device.h>
4 #include <device/pci.h>
5 #include <device/pci_def.h>
6 #include <device/pci_ids.h>
7 #include <reg_script.h>
8 
10 #include <soc/iomap.h>
11 #include <soc/iosf.h>
12 #include <soc/pci_devs.h>
13 #include <soc/ramstage.h>
14 
15 static const struct reg_script init_ops[] = {
16  /* Enable no snoop traffic. */
17  REG_PCI_OR16(0x78, 1 << 11),
18  /* Configure HDMI codec connection. */
19  REG_PCI_OR32(0xc4, 1 << 1),
20  REG_PCI_OR8(0x43, (1 << 3) | (1 << 6)),
21  REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_PWRGT_CONTROL, 0xc0),
22  REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_PWRGT_CONTROL, 0x00),
23  /* Configure internal settings. */
24  REG_PCI_OR32(0xc0, 0x7 << 21),
25  REG_PCI_OR32(0xc4, (0x3 << 26) | (1 << 13) | (1 << 10)),
26  REG_PCI_WRITE32(0xc8, 0x82a30000),
27  REG_PCI_RMW32(0xd0, ~(1 << 31), 0x0),
28  /* Disable docking. */
29  REG_PCI_RMW8(0x4d, ~(1 << 7), 0),
31 };
32 
33 static const uint32_t hdmi_codec_verb_table[] = {
34  /* coreboot specific header */
35  0x80862882, /* vid did for hdmi codec */
36  0x00000000, /* subsystem id */
37  0x00000003, /* number of jacks */
38 
39  /* pin widget 5 - port B */
40  0x20471c10,
41  0x20471d00,
42  0x20471e56,
43  0x20471f18,
44 
45  /* pin widget 6 - port C */
46  0x20571c20,
47  0x20571d00,
48  0x20571e56,
49  0x20571f18,
50 
51  /* pin widget 7 - port D */
52  0x20671c30,
53  0x20671d00,
54  0x20671e56,
55  0x20671f58,
56 };
57 
58 static void hda_init(struct device *dev)
59 {
60  struct resource *res;
61  int codec_mask;
62  int i;
63  u8 *base;
64 
66 
68  if (res == NULL)
69  return;
70 
71  base = res2mmio(res, 0, 0);
72  codec_mask = hda_codec_detect(base);
73 
74  printk(BIOS_DEBUG, "codec mask = %x\n", codec_mask);
75  if (!codec_mask)
76  return;
77 
78  for (i = 3; i >= 0; i--) {
79  if (!((1 << i) & codec_mask))
80  continue;
83  }
84 }
85 
86 static const struct device_operations device_ops = {
88  .set_resources = pci_dev_set_resources,
89  .enable_resources = pci_dev_enable_resources,
90  .init = hda_init,
91  .ops_pci = &soc_pci_ops,
92 };
93 
94 static const struct pci_driver southcluster __pci_driver = {
95  .ops = &device_ops,
96  .vendor = PCI_VID_INTEL,
97  .device = HDA_DEVID,
98 };
#define IOSF_PORT_PMC
Definition: iosf.h:93
#define PUNIT_PWRGT_CONTROL
Definition: iosf.h:236
#define printk(level,...)
Definition: stdlib.h:16
struct resource * probe_resource(const struct device *dev, unsigned int index)
See if a resource structure already exists for a given index.
Definition: device_util.c:323
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define PCI_BASE_ADDRESS_0
Definition: pci_def.h:63
void pci_dev_enable_resources(struct device *dev)
Definition: pci_device.c:721
void pci_dev_read_resources(struct device *dev)
Definition: pci_device.c:534
void pci_dev_set_resources(struct device *dev)
Definition: pci_device.c:691
#define PCI_VID_INTEL
Definition: pci_ids.h:2157
#define REG_PCI_OR8(reg_, value_)
Definition: reg_script.h:183
#define REG_PCI_OR32(reg_, value_)
Definition: reg_script.h:187
void reg_script_run_on_dev(struct device *dev, const struct reg_script *step)
Definition: reg_script.c:689
#define REG_PCI_RMW8(reg_, mask_, value_)
Definition: reg_script.h:171
#define REG_PCI_OR16(reg_, value_)
Definition: reg_script.h:185
#define REG_PCI_RMW32(reg_, mask_, value_)
Definition: reg_script.h:175
#define REG_PCI_WRITE32(reg_, value_)
Definition: reg_script.h:169
#define REG_SCRIPT_END
Definition: reg_script.h:427
static void * res2mmio(const struct resource *res, unsigned long offset, unsigned long mask)
Definition: resource.h:87
uintptr_t base
Definition: uart.c:17
struct pci_operations soc_pci_ops
Definition: chip.c:51
static void hda_init(struct device *dev)
Definition: hda.c:58
static const struct reg_script init_ops[]
Definition: hda.c:15
static const struct device_operations device_ops
Definition: hda.c:86
static const struct pci_driver southcluster __pci_driver
Definition: hda.c:94
static const uint32_t hdmi_codec_verb_table[]
Definition: hda.c:33
#define HDA_DEVID
Definition: pci_devs.h:129
int hda_codec_detect(u8 *base)
Definition: hda_verb.c:10
int hda_codec_init(u8 *base, int addr, int verb_size, const u32 *verb_data)
Definition: hda_verb.c:111
#define NULL
Definition: stddef.h:19
unsigned int uint32_t
Definition: stdint.h:14
uint8_t u8
Definition: stdint.h:45
void(* read_resources)(struct device *dev)
Definition: device.h:39
Definition: device.h:107
struct device * dev
Definition: reg_script.h:78