sound/soc/soc-utils.c

Source file repositories/reference/linux-study-clean/sound/soc/soc-utils.c

File Facts

System
Linux kernel
Corpus path
sound/soc/soc-utils.c
Extension
.c
Size
8019 bytes
Lines
307
Domain
Driver Families
Bucket
sound/soc
Inferred role
Driver Families: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0+
//
// soc-util.c  --  ALSA SoC Audio Layer utility functions
//
// Copyright 2009 Wolfson Microelectronics PLC.
//
// Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
//         Liam Girdwood <lrg@slimlogic.co.uk>

#include <linux/device/faux.h>
#include <linux/export.h>
#include <linux/math.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>

int snd_soc_ret(const struct device *dev, int ret, const char *fmt, ...)
{
	struct va_format vaf;
	va_list args;

	/* Positive, Zero values are not errors */
	if (ret >= 0)
		return ret;

	/* Negative values might be errors */
	switch (ret) {
	case -EPROBE_DEFER:
	case -ENOTSUPP:
	case -EOPNOTSUPP:
		break;
	default:
		va_start(args, fmt);
		vaf.fmt = fmt;
		vaf.va = &args;

		dev_err(dev, "ASoC error (%d): %pV", ret, &vaf);
		va_end(args);
	}

	return ret;
}
EXPORT_SYMBOL_GPL(snd_soc_ret);

int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots)
{
	return sample_size * channels * tdm_slots;
}
EXPORT_SYMBOL_GPL(snd_soc_calc_frame_size);

int snd_soc_params_to_frame_size(const struct snd_pcm_hw_params *params)
{
	int sample_size;

	sample_size = snd_pcm_format_width(params_format(params));
	if (sample_size < 0)
		return sample_size;

	return snd_soc_calc_frame_size(sample_size, params_channels(params),
				       1);
}
EXPORT_SYMBOL_GPL(snd_soc_params_to_frame_size);

int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots)
{
	return fs * snd_soc_calc_frame_size(sample_size, channels, tdm_slots);
}
EXPORT_SYMBOL_GPL(snd_soc_calc_bclk);

int snd_soc_params_to_bclk(const struct snd_pcm_hw_params *params)
{
	int ret;

	ret = snd_soc_params_to_frame_size(params);

	if (ret > 0)
		return ret * params_rate(params);
	else
		return ret;
}
EXPORT_SYMBOL_GPL(snd_soc_params_to_bclk);

/**
 * snd_soc_tdm_params_to_bclk - calculate bclk from params and tdm slot info.
 *
 * Calculate the bclk from the params sample rate, the tdm slot count and the
 * tdm slot width. Optionally round-up the slot count to a given multiple.
 * Either or both of tdm_width and tdm_slots can be 0.
 *

Annotation

Implementation Notes