Unverified Commit 9bca0f05 authored by Richard Fitzgerald's avatar Richard Fitzgerald Committed by Mark Brown
Browse files

ASoC: cs35l56-shared: KUnit tests for onchip speaker ID gpios



Add KUnit testing of:
 cs35l56_check_and_save_onchip_spkid_gpios()
 cs35l56_configure_onchip_spkid_pads()
 cs35l56_read_onchip_spkid()

The test consists of:

- A mock regmap that simulates the pad and pin config registers.

- Parameterization of the pin list, pulls list, a simulated value for
  each pin and the speaker ID value that this should produce.

- A self-test of the simulated pin and GPIO registers.

- A test that the value returned by cs35l56_read_onchip_spkid() is
  correct.

- A test that the pin pull-up/down are set correctly by
  cs35l56_configure_onchip_spkid_pads()

- A test that cs35l56_configure_onchip_spkid_pads() and
  cs35l56_read_onchip_spkid(0 return the expected values if
  cs35l56_base->num_onchip_spkid_gpios == 0.

- A test that cs35l56_check_and_save_onchip_spkid_gpios() saves
  the configuration.

- A test that cs35l56_check_and_save_onchip_spkid_gpios() rejects
  illegal GPIO numbers.

- A test that cs35l56_check_and_save_onchip_spkid_gpios() rejects
  illegal pull types.

Signed-off-by: default avatarRichard Fitzgerald <rf@opensource.cirrus.com>
Link: https://patch.msgid.link/20260205164838.1611295-3-rf@opensource.cirrus.com


Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 4d1e3e2c
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -936,6 +936,20 @@ config SND_SOC_CS35L56_TEST
	help
	  This builds KUnit tests for the Cirrus Logic cs35l56
	  codec driver.

	  For more information on KUnit and unit tests in general,
	  please refer to the KUnit documentation in
	  Documentation/dev-tools/kunit/.
	  If in doubt, say "N".

config SND_SOC_CS35L56_SHARED_TEST
	tristate "KUnit test for Cirrus Logic cs35l56-shared" if !KUNIT_ALL_TESTS
	depends on SND_SOC_CS35L56_SHARED && KUNIT
	default KUNIT_ALL_TESTS
	help
	  This builds KUnit tests for the Cirrus Logic cs35l56-shared
	  module.

	  For more information on KUnit and unit tests in general,
	  please refer to the KUnit documentation in
	  Documentation/dev-tools/kunit/.
+2 −0
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ snd-soc-cs35l45-spi-y := cs35l45-spi.o
snd-soc-cs35l45-i2c-y := cs35l45-i2c.o
snd-soc-cs35l56-y := cs35l56.o
snd-soc-cs35l56-shared-y := cs35l56-shared.o
snd-soc-cs35l56-shared-test-y := cs35l56-shared-test.o
snd-soc-cs35l56-i2c-y := cs35l56-i2c.o
snd-soc-cs35l56-spi-y := cs35l56-spi.o
snd-soc-cs35l56-sdw-y := cs35l56-sdw.o
@@ -512,6 +513,7 @@ obj-$(CONFIG_SND_SOC_CS35L45_SPI) += snd-soc-cs35l45-spi.o
obj-$(CONFIG_SND_SOC_CS35L45_I2C)	+= snd-soc-cs35l45-i2c.o
obj-$(CONFIG_SND_SOC_CS35L56)	+= snd-soc-cs35l56.o
obj-$(CONFIG_SND_SOC_CS35L56_SHARED)	+= snd-soc-cs35l56-shared.o
obj-$(CONFIG_SND_SOC_CS35L56_SHARED_TEST) += snd-soc-cs35l56-shared-test.o
obj-$(CONFIG_SND_SOC_CS35L56_I2C)	+= snd-soc-cs35l56-i2c.o
obj-$(CONFIG_SND_SOC_CS35L56_SPI)	+= snd-soc-cs35l56-spi.o
obj-$(CONFIG_SND_SOC_CS35L56_SDW)	+= snd-soc-cs35l56-sdw.o
+680 −0

File added.

Preview size limit exceeded, changes collapsed.

+5 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
// Copyright (C) 2023 Cirrus Logic, Inc. and
//                    Cirrus Logic International Semiconductor Ltd.

#include <kunit/static_stub.h>
#include <linux/array_size.h>
#include <linux/bitfield.h>
#include <linux/cleanup.h>
@@ -1630,6 +1631,8 @@ int cs35l56_configure_onchip_spkid_pads(struct cs35l56_base *cs35l56_base)
	int num_gpios, num_pulls;
	int i, ret;

	KUNIT_STATIC_STUB_REDIRECT(cs35l56_configure_onchip_spkid_pads, cs35l56_base);

	if (cs35l56_base->num_onchip_spkid_gpios == 0)
		return 0;

@@ -1680,6 +1683,8 @@ int cs35l56_read_onchip_spkid(struct cs35l56_base *cs35l56_base)
	int speaker_id = 0;
	int i, ret;

	KUNIT_STATIC_STUB_REDIRECT(cs35l56_read_onchip_spkid, cs35l56_base);

	if (cs35l56_base->num_onchip_spkid_gpios == 0)
		return -ENOENT;