sound/soc/codecs/cs4349.c

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

File Facts

System
Linux kernel
Corpus path
sound/soc/codecs/cs4349.c
Extension
.c
Size
9743 bytes
Lines
383
Domain
Driver Families
Bucket
sound/soc
Inferred role
Driver Families: implementation source
Status
source 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

struct  cs4349_private {
	struct regmap			*regmap;
	struct gpio_desc		*reset_gpio;
	unsigned int			mode;
	int				rate;
};

static bool cs4349_readable_register(struct device *dev, unsigned int reg)
{
	switch (reg) {
	case CS4349_CHIPID ... CS4349_MISC:
		return true;
	default:
		return false;
	}
}

static bool cs4349_writeable_register(struct device *dev, unsigned int reg)
{
	switch (reg) {
	case CS4349_MODE ...  CS4349_MISC:
		return true;
	default:
		return false;
	}
}

static int cs4349_set_dai_fmt(struct snd_soc_dai *codec_dai,
			      unsigned int format)
{
	struct snd_soc_component *component = codec_dai->component;
	struct cs4349_private *cs4349 = snd_soc_component_get_drvdata(component);
	unsigned int fmt;

	fmt = format & SND_SOC_DAIFMT_FORMAT_MASK;

	switch (fmt) {
	case SND_SOC_DAIFMT_I2S:
	case SND_SOC_DAIFMT_LEFT_J:
	case SND_SOC_DAIFMT_RIGHT_J:
		cs4349->mode = format & SND_SOC_DAIFMT_FORMAT_MASK;
		break;
	default:
		return -EINVAL;
	}

	return 0;
}

static int cs4349_pcm_hw_params(struct snd_pcm_substream *substream,
			    struct snd_pcm_hw_params *params,
			    struct snd_soc_dai *dai)
{
	struct snd_soc_component *component = dai->component;
	struct cs4349_private *cs4349 = snd_soc_component_get_drvdata(component);
	int fmt, ret;

	cs4349->rate = params_rate(params);

	switch (cs4349->mode) {
	case SND_SOC_DAIFMT_I2S:
		fmt = DIF_I2S;
		break;
	case SND_SOC_DAIFMT_LEFT_J:
		fmt = DIF_LEFT_JST;
		break;
	case SND_SOC_DAIFMT_RIGHT_J:
		switch (params_width(params)) {
		case 16:
			fmt = DIF_RGHT_JST16;
			break;
		case 24:
			fmt = DIF_RGHT_JST24;
			break;
		default:
			return -EINVAL;
		}
		break;
	default:
		return -EINVAL;
	}

	ret = snd_soc_component_update_bits(component, CS4349_MODE, DIF_MASK,
				  MODE_FORMAT(fmt));
	if (ret < 0)
		return ret;

	return 0;
}

Annotation

Implementation Notes