Skip to content

Commit d91779f

Browse files
author
Avenger-285714
authored
Merge pull request #312 from Avenger-285714/phytium-hda
hda: phytium: Add Phytium hda driver support [New]
2 parents 03d0c96 + 7e4e566 commit d91779f

File tree

7 files changed

+1184
-2
lines changed

7 files changed

+1184
-2
lines changed

include/sound/hdaudio.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,9 @@ struct hdac_bus {
348348
bool corbrp_self_clear:1; /* CORBRP clears itself after reset */
349349
bool polling_mode:1;
350350
bool needs_damn_long_delay:1;
351-
bool not_use_interrupts:1; /* prohibiting the RIRB IRQ */
352-
bool access_sdnctl_in_dword:1; /* accessing the sdnctl register by dword */
351+
bool not_use_interrupts:1; /* prohibiting the RIRB IRQ */
352+
bool access_sdnctl_in_dword:1; /* accessing the sdnctl register by dword */
353+
bool cmd_resend:1; /* command resend */
353354
bool hygon_dword_access:1;
354355

355356
int poll_count;

sound/hda/hdac_controller.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ int snd_hdac_bus_send_cmd(struct hdac_bus *bus, unsigned int val)
146146
{
147147
unsigned int addr = azx_command_addr(val);
148148
unsigned int wp, rp;
149+
unsigned long timeout;
150+
unsigned int rirb_wp;
151+
int i = 0;
149152

150153
spin_lock_irq(&bus->reg_lock);
151154

@@ -172,6 +175,42 @@ int snd_hdac_bus_send_cmd(struct hdac_bus *bus, unsigned int val)
172175
bus->corb.buf[wp] = cpu_to_le32(val);
173176
snd_hdac_chip_writew(bus, CORBWP, wp);
174177

178+
if (bus->cmd_resend) {
179+
timeout = jiffies + msecs_to_jiffies(1000);
180+
udelay(80);
181+
rirb_wp = snd_hdac_chip_readw(bus, RIRBWP);
182+
while (rirb_wp == bus->rirb.wp) {
183+
udelay(80);
184+
rirb_wp = snd_hdac_chip_readw(bus, RIRBWP);
185+
if (rirb_wp != bus->rirb.wp)
186+
break;
187+
if (i > 5)
188+
break;
189+
if (time_after(jiffies, timeout))
190+
break;
191+
192+
/* add command to corb */
193+
wp = snd_hdac_chip_readw(bus, CORBWP);
194+
if (wp == 0xffff) {
195+
/* something wrong, controller likely turned to D3 */
196+
spin_unlock_irq(&bus->reg_lock);
197+
return -EIO;
198+
}
199+
wp++;
200+
wp %= AZX_MAX_CORB_ENTRIES;
201+
202+
rp = snd_hdac_chip_readw(bus, CORBRP);
203+
if (wp == rp) {
204+
/* oops, it's full */
205+
spin_unlock_irq(&bus->reg_lock);
206+
return -EAGAIN;
207+
}
208+
bus->corb.buf[wp] = cpu_to_le32(val);
209+
snd_hdac_chip_writew(bus, CORBWP, wp);
210+
i++;
211+
}
212+
}
213+
175214
spin_unlock_irq(&bus->reg_lock);
176215

177216
return 0;

sound/pci/hda/Kconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ config SND_HDA_INTEL
2626
To compile this driver as a module, choose M here: the module
2727
will be called snd-hda-intel.
2828

29+
config SND_HDA_PHYTIUM
30+
tristate "PHYTIUM HD Audio"
31+
depends on SOUND
32+
select SND_HDA
33+
select SND_HDA_ALIGNED_MMIO
34+
help
35+
Say Y here to support the HDA controller present in PHYTIUM
36+
SoCs
37+
38+
This options enables support for the HD Audio controller
39+
present in some PHYTIUM SoCs, used to communicate audio
40+
to the "High Definition Audio" codec.
41+
42+
To compile this driver as a module, choose M here: the module
43+
will be called snd-hda-phytium.
44+
2945
config SND_HDA_TEGRA
3046
tristate "NVIDIA Tegra HD Audio"
3147
depends on ARCH_TEGRA

sound/pci/hda/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0
22
snd-hda-intel-objs := hda_intel.o
33
snd-hda-tegra-objs := hda_tegra.o
4+
snd-hda-phytium-objs := hda_phytium.o
45

56
snd-hda-codec-y := hda_bind.o hda_codec.o hda_jack.o hda_auto_parser.o hda_sysfs.o
67
snd-hda-codec-y += hda_controller.o
@@ -70,3 +71,4 @@ obj-$(CONFIG_SND_HDA_SCODEC_TAS2781_I2C) += snd-hda-scodec-tas2781-i2c.o
7071
# when built in kernel
7172
obj-$(CONFIG_SND_HDA_INTEL) += snd-hda-intel.o
7273
obj-$(CONFIG_SND_HDA_TEGRA) += snd-hda-tegra.o
74+
obj-$(CONFIG_SND_HDA_PHYTIUM) += snd-hda-phytium.o

sound/pci/hda/hda_controller.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <linux/pm_runtime.h>
1818
#include <linux/slab.h>
1919

20+
#include "hda_phytium.h"
21+
2022
#ifdef CONFIG_X86
2123
/* for art-tsc conversion */
2224
#include <asm/tsc.h>
@@ -156,6 +158,9 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
156158
struct hda_spdif_out *spdif =
157159
snd_hda_spdif_out_of_nid(apcm->codec, hinfo->nid);
158160
unsigned short ctls = spdif ? spdif->ctls : 0;
161+
struct hda_ft *hda = container_of(chip, struct hda_ft, chip);
162+
163+
hda->substream = substream;
159164

160165
trace_azx_pcm_prepare(chip, azx_dev);
161166
dsp_lock(azx_dev);

0 commit comments

Comments
 (0)