blob: f446a140b228a3d3d63fda29f86fd1de3a34d51a [file] [log] [blame]
Simon Glass6744c0d2019-02-16 20:24:57 -07001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Intel HDA audio (Azalia) for ivybridge
4 *
5 * Originally from coreboot file bd82x6x/azalia.c
6 *
7 * Copyright (C) 2008 Advanced Micro Devices, Inc.
8 * Copyright (C) 2008-2009 coresystems GmbH
9 * Copyright (C) 2011 The ChromiumOS Authors.
10 * Copyright 2018 Google LLC
11 */
12
13#define LOG_CATEGORY UCLASS_SOUND
14
15#include <common.h>
16#include <dm.h>
17#include <hda_codec.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060018#include <log.h>
Simon Glass6744c0d2019-02-16 20:24:57 -070019#include <pch.h>
20#include <sound.h>
21
22static int bd82x6x_azalia_probe(struct udevice *dev)
23{
24 struct pci_child_platdata *plat;
25 struct hda_codec_priv *priv;
26 struct udevice *pch;
27 u32 codec_mask;
28 int conf;
29 int ret;
30
31 /* Only init after relocation */
32 if (!(gd->flags & GD_FLG_RELOC))
33 return 0;
34
35 ret = hda_codec_init(dev);
36 if (ret) {
37 log_debug("Cannot set up HDA codec (err=%d)\n", ret);
38 return ret;
39 }
40 priv = dev_get_priv(dev);
41
42 ret = uclass_first_device_err(UCLASS_PCH, &pch);
43 log_debug("PCH %p %s\n", pch, pch->name);
44 if (ret)
45 return ret;
46
47 conf = pch_ioctl(pch, PCH_REQ_HDA_CONFIG, NULL, 0);
48 log_debug("conf = %x\n", conf);
49 if (conf >= 0) {
50 dm_pci_clrset_config32(dev, 0x120, 7 << 24 | 0xfe,
51 1 << 24 | /* 2 << 24 for server */
52 conf);
53
54 dm_pci_clrset_config16(dev, 0x78, 0, 1 << 1);
55 } else {
56 log_debug("V1CTL disabled\n");
57 }
58 dm_pci_clrset_config32(dev, 0x114, 0xfe, 0);
59
60 /* Set VCi enable bit */
61 dm_pci_clrset_config32(dev, 0x120, 0, 1U << 31);
62
63 /* Enable HDMI codec */
64 dm_pci_clrset_config32(dev, 0xc4, 0, 1 << 1);
65 dm_pci_clrset_config8(dev, 0x43, 0, 1 << 6);
66
67 /* Additional programming steps */
68 dm_pci_clrset_config32(dev, 0xc4, 0, 1 << 13);
69 dm_pci_clrset_config32(dev, 0xc4, 0, 1 << 10);
70 dm_pci_clrset_config32(dev, 0xd0, 1U << 31, 0);
71
72 /* Additional step on Panther Point */
73 plat = dev_get_parent_platdata(dev);
74 if (plat->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_HDA)
75 dm_pci_clrset_config32(dev, 0xc4, 0, 1 << 17);
76
77 dm_pci_write_config8(dev, 0x3c, 0xa); /* unused? */
78
79 /* Audio Control: Select Azalia mode */
80 dm_pci_clrset_config8(dev, 0x40, 0, 1);
81 dm_pci_clrset_config8(dev, 0x4d, 1 << 7, 0); /* Docking not supported */
82 codec_mask = hda_codec_detect(priv->regs);
83 log_debug("codec_mask = %02x\n", codec_mask);
84
85 if (codec_mask) {
86 ret = hda_codecs_init(dev, priv->regs, codec_mask);
87 if (ret) {
88 log_err("Codec init failed (err=%d)\n", ret);
89 return ret;
90 }
91 }
92
93 /* Enable dynamic clock gating */
94 dm_pci_clrset_config8(dev, 0x43, 7, BIT(2) | BIT(0));
95
96 ret = hda_codec_finish_init(dev);
97 if (ret) {
98 log_debug("Cannot set up HDA codec (err=%d)\n", ret);
99 return ret;
100 }
101
102 return 0;
103}
104
105static int bd82x6x_azalia_setup(struct udevice *dev)
106{
107 return 0;
108}
109
110int bd82x6x_azalia_start_beep(struct udevice *dev, int frequency_hz)
111{
112 return hda_codec_start_beep(dev, frequency_hz);
113}
114
115int bd82x6x_azalia_stop_beep(struct udevice *dev)
116{
117 return hda_codec_stop_beep(dev);
118}
119
120static const struct sound_ops bd82x6x_azalia_ops = {
121 .setup = bd82x6x_azalia_setup,
122 .start_beep = bd82x6x_azalia_start_beep,
123 .stop_beep = bd82x6x_azalia_stop_beep,
124};
125
126static const struct udevice_id bd82x6x_azalia_ids[] = {
127 { .compatible = "intel,hd-audio" },
128 { }
129};
130
131U_BOOT_DRIVER(bd82x6x_azalia_drv) = {
132 .name = "bd82x6x-hda",
133 .id = UCLASS_SOUND,
134 .of_match = bd82x6x_azalia_ids,
135 .probe = bd82x6x_azalia_probe,
136 .ops = &bd82x6x_azalia_ops,
137 .priv_auto_alloc_size = sizeof(struct hda_codec_priv),
138};