Skip to content

vc4: Set driver_name for card #3656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2020

Conversation

popcornmix
Copy link
Collaborator

Allows use of the same alsa conf file for hdmi1

From suggestion by @HiassofT

Allows use of the same alsa conf file for hdmi1

Signed-off-by: Dom Cobley <[email protected]>
@JamesH65
Copy link
Contributor

JamesH65 commented Jun 3, 2020

Just out of interest, how does it achieve its objective?

@pelwell
Copy link
Contributor

pelwell commented Jun 3, 2020

I would guess that the ALSA configuration file allows you to select by type (driver_name) as well as by instance (name).

@popcornmix
Copy link
Collaborator Author

Currently we need a file /usr/share/alsa/cards/vc4-hdmi.conf

# Configuration for the VC4-HDMI sound card using software IEC958
# subframe conversion

<confdir:pcm/hdmi.conf>
vc4-hdmi.pcm.hdmi.0 {
	@args [ CARD AES0 AES1 AES2 AES3 ]
	@args.CARD {
		type string
	}
	@args.AES0 {
		type integer
	}
	@args.AES1 {
		type integer
	}
	@args.AES2 {
		type integer
	}
	@args.AES3 {
		type integer
	}
	type iec958
	slave {
		format IEC958_SUBFRAME_LE
		pcm {
			type hooks
			slave.pcm {
				type hw
				card $CARD
				device 0
			}
			hooks.0 {
				type ctl_elems
				hook_args [
				{
					name "IEC958 Playback Default"
					optional true
					lock true
					preserve true
					value [ $AES0 $AES1 $AES2 $AES3 ]
				}
				]
			}
		}
	}
	status [ $AES0 $AES1 $AES2 $AES3 ]
}

# default with plug
vc4-hdmi.pcm.default {
	@args [ CARD ]
	@args.CARD {
		type string
	}
	type plug
	slave.pcm {
		type softvol
		slave.pcm {
			@func concat
			strings [ "hdmi:" $CARD ]
		}
		control {
			name "PCM Playback Volume"
			card $CARD
		}
	}
}

to handle its very quirky nature. That doesn't handle the second hdmi port which has the same quirky behaviour. So you either need to duplicate that file, set an alias in /usr/share/alsa/cards/aliases.conf

vc4-hdmi1 cards.vc4-hdmi

or set the driver name which is also considered for matching the conf file.

This PR seems the option that has the least chance for users to get it wrong.

@pelwell pelwell merged commit bb701ae into raspberrypi:rpi-5.4.y Jun 3, 2020
@popcornmix popcornmix deleted the alsadrivername branch June 3, 2020 13:08
@HiassofT
Copy link
Contributor

HiassofT commented Jun 3, 2020

@JamesH65 alsa lib uses the driver name to look up the card configuration file. So a single "HDA-Intel.conf" or "USB-Audio.conf" file can be used for a wide variety of sound cards. As the ALSA drivers usually expose a fixed structure of devices, mixer controls etc that works fine.

The conf file lookup happens in the "load_for_all_cards" block in /usr/share/alsa/alsa.conf https://git.alsa-project.org/?p=alsa-lib.git;a=blob;f=src/conf/alsa.conf;h=0e01c887dc28023cd0f7b75f443bde73443afbe1;hb=HEAD#l35 private_string gets set to the driver name - see also the load_for_all_cards docs https://www.alsa-project.org/alsa-doc/alsa-lib/conf_8c.html#ac64a8c73293ee35ed3f3958d47bdc721

On the kernel side the ALSA driver name is stored in the "driver" member of snd_card https://github.com/raspberrypi/linux/blob/rpi-5.4.y/include/sound/core.h#L84 which is exposed to userspace via the card info control.

For ASoC things are a bit more tricky, as completely different cards could be handled by a single generic driver (eg the simple audio card driver which is configured via DT).

By default the ALSA driver name is set to the ASoC card name (which is either set in the ASoC driver or passed in via DT), but if we set driver_name that takes precendence: https://github.com/raspberrypi/linux/blob/rpi-4.19.y/sound/soc/soc-core.c#L2104-L2105

So, if we are sure that our ASoC driver will always expose the same device/control/... structure we can simply set driver_name to use a single ALSA card conf file.

popcornmix added a commit to raspberrypi/firmware that referenced this pull request Jun 3, 2020
kernel: vc4: Set driver_name for card
See: raspberrypi/linux#3656

kernel: configs: Add SND_SOC_MAX98357A=m
See: https://www.raspberrypi.org/forums/viewtopic.php?f=107&t=275919

kernel: Add Micro Crystal RV-1805 to i2c-rtc overlays
See: raspberrypi/linux#3651

kernel: media: bcm2835-isp: fix bytes per line calculations for some image formats
See: raspberrypi/linux#3645

kernel: media: bcm2835-unicam: change minimum number of vb2_queue buffers to 1
See: raspberrypi/linux#3638

kernel: media: i2c: imx477: Return correct result on sensor id verification
See: raspberrypi/linux#3630

kernel: Clean up the VCHIQ 2711 DMA support
See: raspberrypi/linux#3629

kernel: overlays: i2c-rtc-gpio: Fix trickle-resistor-ohms param
See: raspberrypi/linux#3642

kernel: Enable hwmon for thermal zones
See: raspberrypi/linux#3307
popcornmix added a commit to Hexxeh/rpi-firmware that referenced this pull request Jun 3, 2020
kernel: vc4: Set driver_name for card
See: raspberrypi/linux#3656

kernel: configs: Add SND_SOC_MAX98357A=m
See: https://www.raspberrypi.org/forums/viewtopic.php?f=107&t=275919

kernel: Add Micro Crystal RV-1805 to i2c-rtc overlays
See: raspberrypi/linux#3651

kernel: media: bcm2835-isp: fix bytes per line calculations for some image formats
See: raspberrypi/linux#3645

kernel: media: bcm2835-unicam: change minimum number of vb2_queue buffers to 1
See: raspberrypi/linux#3638

kernel: media: i2c: imx477: Return correct result on sensor id verification
See: raspberrypi/linux#3630

kernel: Clean up the VCHIQ 2711 DMA support
See: raspberrypi/linux#3629

kernel: overlays: i2c-rtc-gpio: Fix trickle-resistor-ohms param
See: raspberrypi/linux#3642

kernel: Enable hwmon for thermal zones
See: raspberrypi/linux#3307
@JamesH65
Copy link
Contributor

JamesH65 commented Jun 3, 2020

Thanks for the explanations everyone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants