Add Loongson HD Audio support
v2 cover Add Loongson HD Audio support
v2:
* Handling with two new flags added to struct hdac_bus.
v1:
* The Loongson HDA controller is compatible with High Definition Audio Specification Revision 1.0a.
See <https://loongson.github.io/LoongArch-Documentation/Loongson-
7A1000-usermanual-EN.html#hda-controller>
Yanteng Si (4):
ALSA: hda: Add Loongson LS7A HD-Audio support
ALSA: hda: Using polling mode for loongson controller by default
ALSA: hda: Workaround for SDnCTL register on loongson controller
ALSA: hda/intel: Workaround for WALLCLK register for loongson
controller
include/linux/pci_ids.h | 3 +++ include/sound/hdaudio.h | 2 ++ sound/hda/hdac_controller.c | 5 ++++- sound/hda/hdac_device.c | 1 + sound/hda/hdac_stream.c | 6 +++++- sound/pci/hda/hda_intel.c | 15 +++++++++++++++ sound/pci/hda/patch_hdmi.c | 1 + 7 files changed, 31 insertions(+), 2 deletions(-)
Signature · 1 line
2.31.4
PATCH v2 1/4 ALSA: hda: Add Loongson LS7A HD-Audio support
Add the new PCI ID 0x0014 0x7a07 and the new PCI ID 0x0014 0x7a37 Loongson HDA controller.
--- include/linux/pci_ids.h | 3 +++ sound/hda/hdac_device.c | 1 + sound/pci/hda/hda_intel.c | 7 +++++++ sound/pci/hda/patch_hdmi.c | 1 + 4 files changed, 12 insertions(+)
include/linux/pci_ids.h +3 -0
@@ -158,6 +158,9 @@#define PCI_VENDOR_ID_LOONGSON 0x0014 +#define PCI_DEVICE_ID_LOONGSON_HDA 0x7a07 +#define PCI_DEVICE_ID_LOONGSON_HDMI 0x7a37 +#define PCI_VENDOR_ID_SOLIDIGM 0x025e#define PCI_VENDOR_ID_TTTECH 0x0357
sound/hda/hdac_device.c +1 -0
@@ -645,6 +645,7 @@ struct hda_vendor_id { };static const struct hda_vendor_id hda_vendor_ids[] = { + {0x0014 ,"Loongson" }, {0x1002 ,"ATI" }, {0x1013 ,"Cirrus Logic" }, {0x1057 ,"Motorola" },
sound/pci/hda/hda_intel.c +7 -0
@@ -237,6 +237,7 @@ enum {AZX_DRIVER_CTHDA ,AZX_DRIVER_CMEDIA ,AZX_DRIVER_ZHAOXIN , +AZX_DRIVER_LOONGSON ,AZX_DRIVER_GENERIC , AZX_NUM_DRIVERS, /* keep this as last entry */ };
@@ -360,6 +361,7 @@ static const char * const driver_short_names[] = { [AZX_DRIVER_CTHDA] = "HDA Creative", [AZX_DRIVER_CMEDIA] = "HDA C-Media", [AZX_DRIVER_ZHAOXIN] = "HDA Zhaoxin", + [AZX_DRIVER_LOONGSON] = "HDA Loongson", [AZX_DRIVER_GENERIC] = "HD-Audio Generic", };
@@ -2809,6 +2811,11 @@ static const struct pci_device_id azx_ids[] = { .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_HDMI },/* Zhaoxin */ { PCI_DEVICE(0x1d17, 0x3288), .driver_data = AZX_DRIVER_ZHAOXIN }, + /* Loongson HDAudio*/ + {PCI_DEVICE(PCI_VENDOR_ID_LOONGSON, PCI_DEVICE_ID_LOONGSON_HDA), + .driver_data = AZX_DRIVER_LOONGSON }, + {PCI_DEVICE(PCI_VENDOR_ID_LOONGSON, PCI_DEVICE_ID_LOONGSON_HDMI), + .driver_data = AZX_DRIVER_LOONGSON }, { 0, } };MODULE_DEVICE_TABLE (pci, azx_ids);
sound/pci/hda/patch_hdmi.c +1 -0
@@ -4505,6 +4505,7 @@ static int patch_gf_hdmi(struct hda_codec *codec)* patch entries */ static const struct hda_device_id snd_hda_id_hdmi[] = { +HDA_CODEC_ENTRY (0x00147a47 ,"Loongson HDMI" , patch_generic_hdmi),HDA_CODEC_ENTRY (0x1002793c ,"RS600 HDMI" , patch_atihdmi),HDA_CODEC_ENTRY (0x10027919 ,"RS600 HDMI" , patch_atihdmi),HDA_CODEC_ENTRY (0x1002791a ,"RS690/780 HDMI" , patch_atihdmi),
Signature · 1 line
2.31.4
PATCH v2 2/4 ALSA: hda: Using polling mode for loongson controller by default
In reply to Yanteng SiOn loongson controller, RIRBSTS.RINTFL cannot be cleared, azx_interrupt() is called all the time. We disable RIRB interrupt, and use polling mode by default.
--- include/sound/hdaudio.h | 1 + sound/hda/hdac_controller.c | 5 ++++- sound/pci/hda/hda_intel.c | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-)
include/sound/hdaudio.h +1 -0
@@ -346,6 +346,7 @@ struct hdac_bus { bool reverse_assign:1; /* assign devices in reverse order */ bool corbrp_self_clear:1; /* CORBRP clears itself after reset */ bool polling_mode:1; + bool no_intr_polling_mode:1; bool needs_damn_long_delay:1;int poll_count;
sound/hda/hdac_controller.c +4 -1
@@ -79,7 +79,10 @@ void snd_hdac_bus_init_cmd_io(struct hdac_bus *bus)/* set N=1, get RIRB response interrupt for new entry */ snd_hdac_chip_writew (bus,RINTCNT ,1 );/* enable rirb dma and response irq */ -snd_hdac_chip_writeb (bus,RIRBCTL ,AZX_RBCTL_DMA_EN |AZX_RBCTL_IRQ_EN ); +if (bus->no_intr_polling_mode) +snd_hdac_chip_writeb (bus,RIRBCTL ,AZX_RBCTL_DMA_EN ); +else +snd_hdac_chip_writeb (bus,RIRBCTL ,AZX_RBCTL_DMA_EN |AZX_RBCTL_IRQ_EN );/* Accept unsolicited responses */ snd_hdac_chip_updatel (bus,GCTL ,AZX_GCTL_UNSOL ,AZX_GCTL_UNSOL );spin_unlock_irq (&bus->reg_lock);
sound/pci/hda/hda_intel.c +4 -0
@@ -1875,6 +1875,10 @@ static int azx_first_init(struct azx *chip)if (chip->driver_type ==AZX_DRIVER_GFHDMI ) bus->polling_mode =1 ; +if (chip->driver_type ==AZX_DRIVER_LOONGSON ) { + bus->no_intr_polling_mode =1 ; + } + err =pcim_iomap_regions (pci,1 <<0 ,"ICH HD audio" );if (err <0 )return err;
Signature · 1 line
2.31.4
Re: [PATCH v2 2/4] ALSA: hda: Using polling mode for loongson controller by default
Quoted 18 lines · Yanteng Si
On loongson controller, RIRBSTS.RINTFL cannot be cleared,
azx_interrupt()is called all the time. We disable RIRB interrupt, and use polling mode by default.Signed-off-by Yanteng Si <[email protected]>Signed-off-by Yingkun Meng <[email protected]>--- include/sound/hdaudio.h | 1 + sound/hda/hdac_controller.c | 5 ++++- sound/pci/hda/hda_intel.c | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-)include/sound/hdaudio.h +0
-0
include/sound/hdaudio.h struct hdac_bus { · line 349
Quoted 4 lines
include/sound/hdaudio.h +1
-0@@ -346,6 +346,7 @@ struct hdac_bus { bool reverse_assign:1; /* assign devices in reverse order */ bool corbrp_self_clear:1; /* CORBRP clears itself after reset */ bool polling_mode:1; + bool no_intr_polling_mode:1;
It isn't clear enough what this flag does. It's basically prohibiting the RIRB IRQ (hence requiring the polling mode), right? Write it in the comment.
Quoted 21 lines
sound/hda/hdac_controller.c +4
-1@@ -79,7 +79,10 @@ void snd_hdac_bus_init_cmd_io(struct hdac_bus *bus)/* set N=1, get RIRB response interrupt for new entry */ snd_hdac_chip_writew (bus,RINTCNT ,1 );/* enable rirb dma and response irq */ -snd_hdac_chip_writeb (bus,RIRBCTL ,AZX_RBCTL_DMA_EN |AZX_RBCTL_IRQ_EN ); +if (bus->no_intr_polling_mode) +snd_hdac_chip_writeb (bus,RIRBCTL ,AZX_RBCTL_DMA_EN ); +else +snd_hdac_chip_writeb (bus,RIRBCTL ,AZX_RBCTL_DMA_EN |AZX_RBCTL_IRQ_EN );/* Accept unsolicited responses */ snd_hdac_chip_updatel (bus,GCTL ,AZX_GCTL_UNSOL ,AZX_GCTL_UNSOL );spin_unlock_irq (&bus->reg_lock);sound/pci/hda/hda_intel.c +0
-0
sound/pci/hda/hda_intel.c static int azx_first_init(struct azx *chip) · line 1880
Quoted 6 lines
sound/pci/hda/hda_intel.c +3
-0@@ -1875,6 +1875,10 @@ static int azx_first_init(struct azx *chip)if (chip->driver_type ==AZX_DRIVER_GFHDMI ) bus->polling_mode =1 ; +if (chip->driver_type ==AZX_DRIVER_LOONGSON ) { + bus->no_intr_polling_mode =1 ; + }
Don't you need to set the bus->polling_mode?
thanks,
Takashi
Re: [PATCH v2 2/4] ALSA: hda: Using polling mode for loongson controller by default
Quoted 14 lines · Takashi Iwai
Quoted 12 lines · Yanteng Si
On loongson controller, RIRBSTS.RINTFL cannot be cleared,
azx_interrupt()is called all the time. We disable RIRB interrupt, and use polling mode by default.Signed-off-by Yanteng Si <[email protected]>Signed-off-by Yingkun Meng <[email protected]>--- include/sound/hdaudio.h | 1 + sound/hda/hdac_controller.c | 5 ++++- sound/pci/hda/hda_intel.c | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-)
Quoted 12 lines
include/sound/hdaudio.h struct hdac_bus { · line 349
Quoted 9 lines
include/sound/hdaudio.h +1
-0@@ -346,6 +346,7 @@ struct hdac_bus { bool reverse_assign:1; /* assign devices in reverse order */ bool corbrp_self_clear:1; /* CORBRP clears itself after reset */ bool polling_mode:1; + bool no_intr_polling_mode:1;It isn't clear enough what this flag does. It's basically prohibiting the RIRB IRQ (hence requiring the polling mode), right? Write it in the comment.
OK!
Quoted 25 lines
Quoted 25 lines
sound/hda/hdac_controller.c +4
-1@@ -79,7 +79,10 @@ void snd_hdac_bus_init_cmd_io(struct hdac_bus *bus)/* set N=1, get RIRB response interrupt for new entry */ snd_hdac_chip_writew (bus,RINTCNT ,1 );/* enable rirb dma and response irq */ -snd_hdac_chip_writeb (bus,RIRBCTL ,AZX_RBCTL_DMA_EN |AZX_RBCTL_IRQ_EN ); +if (bus->no_intr_polling_mode) +snd_hdac_chip_writeb (bus,RIRBCTL ,AZX_RBCTL_DMA_EN ); +else +snd_hdac_chip_writeb (bus,RIRBCTL ,AZX_RBCTL_DMA_EN |AZX_RBCTL_IRQ_EN );/* Accept unsolicited responses */ snd_hdac_chip_updatel (bus,GCTL ,AZX_GCTL_UNSOL ,AZX_GCTL_UNSOL );spin_unlock_irq (&bus->reg_lock);sound/pci/hda/hda_intel.c +0
-0@@ -1875,6 +1875,10 @@ static int azx_first_init(struct azx *chip)if (chip->driver_type ==AZX_DRIVER_GFHDMI ) bus->polling_mode =1 ;
Quoted 4 lines
sound/pci/hda/hda_intel.c static int azx_first_init(struct azx *chip) · line 1880
Quoted 3 lines
sound/pci/hda/hda_intel.c +3
-0+if (chip->driver_type ==AZX_DRIVER_LOONGSON ) { + bus->no_intr_polling_mode =1 ; + }Don't you need to set the
bus->polling_mode?
Yes, I do.
Although it works now, some messages will print.
Thanks,
Yanteng
Quoted 5 lines
thanks,
Takashi
PATCH v2 3/4 ALSA: hda: Workaround for SDnCTL register on loongson controller
In reply to Yanteng SiOn loongson controller, after calling snd_hdac_stream_updateb() to enable DMA engine, the SDnCTL.STRM will become to zero. We need to access SDnCTL in dword to keep SDnCTL.STRM is not changed.
--- include/sound/hdaudio.h | 1 + sound/hda/hdac_stream.c | 6 +++++- sound/pci/hda/hda_intel.c | 1 + 3 files changed, 7 insertions(+), 1 deletion(-)
include/sound/hdaudio.h +1 -0
@@ -348,6 +348,7 @@ struct hdac_bus { bool polling_mode:1; bool no_intr_polling_mode:1; bool needs_damn_long_delay:1; + bool access_sdnctl_in_dword:1;int poll_count;
sound/hda/hdac_stream.c +5 -1
@@ -150,7 +150,11 @@ void snd_hdac_stream_start(struct hdac_stream *azx_dev) stripe_ctl); }/* set DMA start and interrupt mask */ -snd_hdac_stream_updateb (azx_dev,SD_CTL , +if (bus->access_sdnctl_in_dword) +snd_hdac_stream_updatel (azx_dev,SD_CTL , +0 ,SD_CTL_DMA_START |SD_INT_MASK ); +else +snd_hdac_stream_updateb (azx_dev,SD_CTL ,0 ,SD_CTL_DMA_START |SD_INT_MASK ); azx_dev->running = true; }
sound/pci/hda/hda_intel.c +1 -0
@@ -1877,6 +1877,7 @@ static int azx_first_init(struct azx *chip)if (chip->driver_type ==AZX_DRIVER_LOONGSON ) { bus->no_intr_polling_mode =1 ; + bus->access_sdnctl_in_dword =1 ; } err =pcim_iomap_regions (pci,1 <<0 ,"ICH HD audio" );
Signature · 1 line
2.31.4
Re: [PATCH v2 3/4] ALSA: hda: Workaround for SDnCTL register on loongson controller
Quoted 18 lines · Yanteng Si
On loongson controller, after calling
snd_hdac_stream_updateb()to enable DMA engine, the SDnCTL.STRM will become to zero. We need to access SDnCTL in dword to keep SDnCTL.STRM is not changed.Signed-off-by Yanteng Si <[email protected]>Signed-off-by Yingkun Meng <[email protected]>--- include/sound/hdaudio.h | 1 + sound/hda/hdac_stream.c | 6 +++++- sound/pci/hda/hda_intel.c | 1 + 3 files changed, 7 insertions(+), 1 deletion(-)include/sound/hdaudio.h +0
-0
include/sound/hdaudio.h struct hdac_bus { · line 351
Quoted 4 lines
include/sound/hdaudio.h +1
-0@@ -348,6 +348,7 @@ struct hdac_bus { bool polling_mode:1; bool no_intr_polling_mode:1; bool needs_damn_long_delay:1; + bool access_sdnctl_in_dword:1;
It's worth for the comment here, too.
thanks,
Takashi
PATCH v2 4/4 ALSA: hda/intel: Workaround for WALLCLK register for loongson controller
In reply to Yanteng SiOn loongson controller, the value of WALLCLK register is always 0, which is meaningless, so we return directly.
--- sound/pci/hda/hda_intel.c | 3 +++ 1 file changed, 3 insertions(+)
sound/pci/hda/hda_intel.c +3 -0
@@ -655,6 +655,9 @@ static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)unsigned int pos;snd_pcm_uframes_t hwptr, target; +if (chip->driver_type ==AZX_DRIVER_LOONGSON ) +return 1 ; + wallclk =azx_readl (chip,WALLCLK ) - azx_dev->core.start_wallclk;if (wallclk < (azx_dev->core.period_wallclk *2 ) /3 )return -1 ;/* bogus (too early) interrupt */
Signature · 1 line
2.31.4