sound/soc/codecs/cs35l56-shared-test.c

Source file repositories/reference/linux-study-clean/sound/soc/codecs/cs35l56-shared-test.c

File Facts

System
Linux kernel
Corpus path
sound/soc/codecs/cs35l56-shared-test.c
Extension
.c
Size
32716 bytes
Lines
927
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 cs35l56_shared_test_mock_gpio {
	unsigned int pin_state;
	struct gpio_chip chip;
};

struct cs35l56_shared_test_priv {
	struct kunit *test;
	struct faux_device *amp_dev;
	struct faux_device *gpio_dev;
	struct cs35l56_shared_test_mock_gpio *gpio_priv;
	struct regmap *registers;
	unsigned int reg_offset;
	struct cs35l56_base *cs35l56_base;
	u8 applied_pad_pull_state[CS35L56_MAX_GPIO];
};

struct cs35l56_shared_test_param {
	int spkid_gpios[4];
	int spkid_pulls[4];
	unsigned long gpio_status;
	int spkid;
};

KUNIT_DEFINE_ACTION_WRAPPER(faux_device_destroy_wrapper, faux_device_destroy,
			    struct faux_device *)

KUNIT_DEFINE_ACTION_WRAPPER(regmap_exit_wrapper, regmap_exit, struct regmap *)

KUNIT_DEFINE_ACTION_WRAPPER(device_remove_software_node_wrapper,
			    device_remove_software_node,
			    struct device *)

static int cs35l56_shared_test_mock_gpio_get_direction(struct gpio_chip *chip,
						       unsigned int offset)
{
	return GPIO_LINE_DIRECTION_IN;
}

static int cs35l56_shared_test_mock_gpio_direction_in(struct gpio_chip *chip,
						      unsigned int offset)
{
	return 0;
}

static int cs35l56_shared_test_mock_gpio_get(struct gpio_chip *chip, unsigned int offset)
{
	struct cs35l56_shared_test_mock_gpio *gpio_priv = gpiochip_get_data(chip);

	return !!(gpio_priv->pin_state & BIT(offset));
}

static const struct gpio_chip cs35l56_shared_test_mock_gpio_chip = {
	.label			= "cs35l56_shared_test_mock_gpio",
	.owner			= THIS_MODULE,
	.get_direction		= cs35l56_shared_test_mock_gpio_get_direction,
	.direction_input	= cs35l56_shared_test_mock_gpio_direction_in,
	.get			= cs35l56_shared_test_mock_gpio_get,
	.base			= -1,
	.ngpio			= 32,
};

/* software_node referencing the gpio driver */
static const struct software_node cs35l56_shared_test_mock_gpio_swnode = {
	.name = "cs35l56_shared_test_mock_gpio",
};

static int cs35l56_shared_test_mock_gpio_probe(struct faux_device *fdev)
{
	struct cs35l56_shared_test_mock_gpio *gpio_priv;
	struct device *dev = &fdev->dev;
	int ret;

	gpio_priv = devm_kzalloc(dev, sizeof(*gpio_priv), GFP_KERNEL);
	if (!gpio_priv)
		return -ENOMEM;

	ret = device_add_software_node(dev, &cs35l56_shared_test_mock_gpio_swnode);
	if (ret)
		return ret;

	ret = devm_add_action_or_reset(dev, device_remove_software_node_wrapper, dev);
	if (ret)
		return ret;

	/* GPIO core modifies our struct gpio_chip so use a copy */
	gpio_priv->chip = cs35l56_shared_test_mock_gpio_chip;
	gpio_priv->chip.parent = dev;
	ret = devm_gpiochip_add_data(dev, &gpio_priv->chip, gpio_priv);
	if (ret)
		return dev_err_probe(dev, ret, "Failed to add gpiochip\n");

Annotation

Implementation Notes