sound/soc/sunxi/sun8i-codec.c

Source file repositories/reference/linux-study-clean/sound/soc/sunxi/sun8i-codec.c

File Facts

System
Linux kernel
Corpus path
sound/soc/sunxi/sun8i-codec.c
Extension
.c
Size
54812 bytes
Lines
1721
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 sun8i_codec_aif {
	unsigned int	lrck_div_order;
	unsigned int	sample_rate;
	unsigned int	slots;
	unsigned int	slot_width;
	unsigned int	active_streams	: 2;
	unsigned int	open_streams	: 2;
};

struct sun8i_codec_quirks {
	bool	bus_clock	: 1;
	bool	jack_detection	: 1;
	bool	legacy_widgets	: 1;
	bool	lrck_inversion	: 1;
};

enum {
	SUN8I_JACK_STATUS_DISCONNECTED,
	SUN8I_JACK_STATUS_WAITING_HBIAS,
	SUN8I_JACK_STATUS_CONNECTED,
};

struct sun8i_codec {
	struct snd_soc_component	*component;
	struct regmap			*regmap;
	struct clk			*clk_bus;
	struct clk			*clk_module;
	const struct sun8i_codec_quirks	*quirks;
	struct sun8i_codec_aif		aifs[SUN8I_CODEC_NAIFS];
	struct snd_soc_jack		*jack;
	struct delayed_work		jack_work;
	int				jack_irq;
	int				jack_status;
	int				jack_type;
	int				jack_last_sample;
	ktime_t				jack_hbias_ready;
	struct mutex			jack_mutex;
	int				last_hmic_irq;
	unsigned int			sysclk_rate;
	int				sysclk_refcnt;
};

static struct snd_soc_dai_driver sun8i_codec_dais[];

static int sun8i_codec_runtime_resume(struct device *dev)
{
	struct sun8i_codec *scodec = dev_get_drvdata(dev);
	int ret;

	ret = clk_prepare_enable(scodec->clk_bus);
	if (ret) {
		dev_err(dev, "Failed to enable the bus clock\n");
		return ret;
	}

	regcache_cache_only(scodec->regmap, false);

	ret = regcache_sync(scodec->regmap);
	if (ret) {
		dev_err(dev, "Failed to sync regmap cache\n");
		return ret;
	}

	return 0;
}

static int sun8i_codec_runtime_suspend(struct device *dev)
{
	struct sun8i_codec *scodec = dev_get_drvdata(dev);

	regcache_cache_only(scodec->regmap, true);
	regcache_mark_dirty(scodec->regmap);

	clk_disable_unprepare(scodec->clk_bus);

	return 0;
}

static int sun8i_codec_get_hw_rate(unsigned int sample_rate)
{
	switch (sample_rate) {
	case 7350:
	case 8000:
		return 0x0;
	case 11025:
		return 0x1;
	case 12000:
		return 0x2;
	case 14700:
	case 16000:

Annotation

Implementation Notes