drivers/base/regmap/regmap-kunit.c

Source file repositories/reference/linux-study-clean/drivers/base/regmap/regmap-kunit.c

File Facts

System
Linux kernel
Corpus path
drivers/base/regmap/regmap-kunit.c
Extension
.c
Size
66842 bytes
Lines
2223
Domain
Driver Families
Bucket
drivers/base
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 regmap_test_priv {
	struct device *dev;
	bool *reg_default_called;
	unsigned int reg_default_max;
};

struct regmap_test_param {
	enum regcache_type cache;
	enum regmap_endian val_endian;

	unsigned int from_reg;
	bool fast_io;
};

static void get_changed_bytes(void *orig, void *new, size_t size)
{
	char *o = orig;
	char *n = new;
	int i;

	get_random_bytes(new, size);

	/*
	 * This could be nicer and more efficient but we shouldn't
	 * super care.
	 */
	for (i = 0; i < size; i++)
		while (n[i] == o[i])
			get_random_bytes(&n[i], 1);
}

static const struct regmap_config test_regmap_config = {
	.reg_stride = 1,
	.val_bits = sizeof(unsigned int) * 8,
};

static const char *regcache_type_name(enum regcache_type type)
{
	switch (type) {
	case REGCACHE_NONE:
		return "none";
	case REGCACHE_FLAT:
		return "flat";
	case REGCACHE_FLAT_S:
		return "flat-sparse";
	case REGCACHE_RBTREE:
		return "rbtree";
	case REGCACHE_MAPLE:
		return "maple";
	default:
		return NULL;
	}
}

static const char *regmap_endian_name(enum regmap_endian endian)
{
	switch (endian) {
	case REGMAP_ENDIAN_BIG:
		return "big";
	case REGMAP_ENDIAN_LITTLE:
		return "little";
	case REGMAP_ENDIAN_DEFAULT:
		return "default";
	case REGMAP_ENDIAN_NATIVE:
		return "native";
	default:
		return NULL;
	}
}

static void param_to_desc(const struct regmap_test_param *param, char *desc)
{
	snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s-%s%s @%#x",
		 regcache_type_name(param->cache),
		 regmap_endian_name(param->val_endian),
		 param->fast_io ? " fast I/O" : "",
		 param->from_reg);
}

static const struct regmap_test_param regcache_types_list[] = {
	{ .cache = REGCACHE_NONE },
	{ .cache = REGCACHE_NONE, .fast_io = true },
	{ .cache = REGCACHE_FLAT },
	{ .cache = REGCACHE_FLAT, .fast_io = true },
	{ .cache = REGCACHE_FLAT_S },
	{ .cache = REGCACHE_FLAT_S, .fast_io = true },
	{ .cache = REGCACHE_RBTREE },
	{ .cache = REGCACHE_RBTREE, .fast_io = true },
	{ .cache = REGCACHE_MAPLE },
	{ .cache = REGCACHE_MAPLE, .fast_io = true },

Annotation

Implementation Notes