sound/soc/codecs/fs-amp-lib.c

Source file repositories/reference/linux-study-clean/sound/soc/codecs/fs-amp-lib.c

File Facts

System
Linux kernel
Corpus path
sound/soc/codecs/fs-amp-lib.c
Extension
.c
Size
6445 bytes
Lines
266
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+
//
// fs-amp-lib.c --- Common library for FourSemi Audio Amplifiers
//
// Copyright (C) 2016-2025 Shanghai FourSemi Semiconductor Co.,Ltd.

#include <linux/crc16.h>
#include <linux/device.h>
#include <linux/firmware.h>
#include <linux/module.h>
#include <linux/slab.h>

#include "fs-amp-lib.h"

static int fs_get_scene_count(struct fs_amp_lib *amp_lib)
{
	const struct fs_fwm_table *table;
	int count;

	if (!amp_lib || !amp_lib->dev)
		return -EINVAL;

	table = amp_lib->table[FS_INDEX_SCENE];
	if (!table)
		return -EFAULT;

	count = table->size / sizeof(struct fs_scene_index);
	if (count < 1 || count > FS_SCENE_COUNT_MAX) {
		dev_err(amp_lib->dev, "Invalid scene count: %d\n", count);
		return -ERANGE;
	}

	return count;
}

static void fs_get_fwm_string(struct fs_amp_lib *amp_lib,
			      int offset, const char **pstr)
{
	const struct fs_fwm_table *table;

	if (!amp_lib || !amp_lib->dev || !pstr)
		return;

	table = amp_lib->table[FS_INDEX_STRING];
	if (table && offset > 0 && offset < table->size + sizeof(*table))
		*pstr = (char *)table + offset;
	else
		*pstr = NULL;
}

static void fs_get_scene_reg(struct fs_amp_lib *amp_lib,
			     int offset, struct fs_amp_scene *scene)
{
	const struct fs_fwm_table *table;

	if (!amp_lib || !amp_lib->dev || !scene)
		return;

	table = amp_lib->table[FS_INDEX_REG];
	if (table && offset > 0 && offset < table->size + sizeof(*table))
		scene->reg = (struct fs_reg_table *)((char *)table + offset);
	else
		scene->reg = NULL;
}

static void fs_get_scene_model(struct fs_amp_lib *amp_lib,
			       int offset, struct fs_amp_scene *scene)
{
	const struct fs_fwm_table *table;
	const char *ptr;

	if (!amp_lib || !amp_lib->dev || !scene)
		return;

	table = amp_lib->table[FS_INDEX_MODEL];
	ptr = (char *)table;
	if (table && offset > 0 && offset < table->size + sizeof(*table))
		scene->model = (struct fs_file_table *)(ptr + offset);
	else
		scene->model = NULL;
}

static void fs_get_scene_effect(struct fs_amp_lib *amp_lib,
				int offset, struct fs_amp_scene *scene)
{
	const struct fs_fwm_table *table;
	const char *ptr;

	if (!amp_lib || !amp_lib->dev || !scene)
		return;

Annotation

Implementation Notes