drivers/firmware/cirrus/test/cs_dsp_mock_regmap.c

Source file repositories/reference/linux-study-clean/drivers/firmware/cirrus/test/cs_dsp_mock_regmap.c

File Facts

System
Linux kernel
Corpus path
drivers/firmware/cirrus/test/cs_dsp_mock_regmap.c
Extension
.c
Size
12040 bytes
Lines
368
Domain
Driver Families
Bucket
drivers/firmware
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

if (priv->dsp->base) {
			regcache_drop_region(priv->dsp->regmap,
					     priv->dsp->base,
					     priv->dsp->base + 0x7c);
		}
		return;
	case WMFW_HALO:
		if (priv->dsp->base) {
			regcache_drop_region(priv->dsp->regmap,
					     priv->dsp->base,
					     priv->dsp->base + 0x47000);
		}

		/* sysinfo registers are read-only so don't drop them */
		return;
	default:
		return;
	}
}
EXPORT_SYMBOL_NS_GPL(cs_dsp_mock_regmap_drop_system_regs, "FW_CS_DSP_KUNIT_TEST_UTILS");

/**
 * cs_dsp_mock_regmap_is_dirty() - Test for dirty registers in the cache.
 *
 * @priv:		Pointer to struct cs_dsp_test object.
 * @drop_system_regs:	If true the DSP system regs will be dropped from
 *			the cache before checking for dirty.
 *
 * All registers that are expected to be written must have been dropped
 * from the cache (DSP system registers can be dropped by passing
 * drop_system_regs == true). If any unexpected registers were written
 * there will still be dirty entries in the cache and a cache sync will
 * cause a write.
 *
 * Returns: true if there were dirty entries, false if not.
 */
bool cs_dsp_mock_regmap_is_dirty(struct cs_dsp_test *priv, bool drop_system_regs)
{
	if (drop_system_regs)
		cs_dsp_mock_regmap_drop_system_regs(priv);

	priv->saw_bus_write = false;
	regcache_cache_only(priv->dsp->regmap, false);
	regcache_sync(priv->dsp->regmap);
	regcache_cache_only(priv->dsp->regmap, true);

	return priv->saw_bus_write;
}
EXPORT_SYMBOL_NS_GPL(cs_dsp_mock_regmap_is_dirty, "FW_CS_DSP_KUNIT_TEST_UTILS");

/**
 * cs_dsp_mock_regmap_init() - Initialize a mock regmap.
 *
 * @priv:	Pointer to struct cs_dsp_test object. This must have a
 *		valid pointer to a struct cs_dsp in which the type and
 *		rev fields are set to the type of DSP to be simulated.
 *
 * On success the priv->dsp->regmap will point to the created
 * regmap instance.
 *
 * Return: zero on success, else negative error code.
 */
int cs_dsp_mock_regmap_init(struct cs_dsp_test *priv)
{
	const struct regmap_config *config;
	int ret;

	switch (priv->dsp->type) {
	case WMFW_HALO:
		config = &cs_dsp_mock_regmap_halo;
		break;
	case WMFW_ADSP2:
		if (priv->dsp->rev == 0)
			config = &cs_dsp_mock_regmap_adsp2_16bit;
		else
			config = &cs_dsp_mock_regmap_adsp2_32bit;
		break;
	default:
		config = NULL;
		break;
	}

	priv->dsp->regmap = devm_regmap_init(priv->dsp->dev,
					     &cs_dsp_mock_regmap_bus,
					     priv,
					     config);
	if (IS_ERR(priv->dsp->regmap)) {
		ret = PTR_ERR(priv->dsp->regmap);
		kunit_err(priv->test, "Failed to allocate register map: %d\n", ret);
		return ret;

Annotation

Implementation Notes