Commit Graph

7 Commits

Author SHA1 Message Date
Ethan Tidmore
4fa26292e8 ASoC: cs35l56-shared-test: Fix possible null pointer dereference
The struct regmap_config is dereferenced before its check. Also, after
it is checked priv->reg_offset is assigned to regmap_config->reg_base,
making the removed line redundant.

Detected by Smatch:
sound/soc/codecs/cs35l56-shared-test.c:681 cs35l56_shared_test_case_base_init()
warn: variable dereferenced before check 'regmap_config' (see line 665)

Signed-off-by: Ethan Tidmore <ethantidmore06@gmail.com>
Link: https://patch.msgid.link/20260523211522.522616-1-ethantidmore06@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2026-05-26 16:37:13 +01:00
Mark Brown
4c433607b6 ASoC: cs35l56: Replace open-coded SoundWire regmap with generic regmap-sdw
Richard Fitzgerald <rf@opensource.cirrus.com> says:

This series replaces the entirely custom SoundWire regmap with the generic
regmap-sdw. The reasons for doing this are:

- Avoid code duplication
- Avoid effort of keeping custom implementation up-to-date
- Prepare for supporting BRA

Link: https://patch.msgid.link/20260521115420.978616-1-rf@opensource.cirrus.com
2026-05-22 00:17:14 +01:00
Richard Fitzgerald
cb9a52b3ab ASoC: cs35l56-shared-test: Subtract reg_base offset in dummy regmap
Subtract the value of cs35l56 regmap_config->reg_base from addresses
passed into the mock regmap bus.

Chip register addresses transferred over SoundWire are offset by 0x8000
to move them after the address range reserved in the SoundWire spec.

This commit prepares for changing the cs35l56-sdw driver to use
regmap_config->reg_base to add this offset. When that is done the
addresses passed into the mock regmap_bus will include this offset.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://patch.msgid.link/20260521115420.978616-2-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2026-05-22 00:17:11 +01:00
Richard Fitzgerald
a6f7c21acc ASoC: cs35l56-shared-test: Subtract reg_base offset in dummy regmap
Subtract the value of cs35l56 regmap_config->reg_base from addresses
passed into the mock regmap bus.

Chip register addresses transferred over SoundWire are offset by 0x8000
to move them after the address range reserved in the SoundWire spec.

This commit prepares for changing the cs35l56-sdw driver to use
regmap_config->reg_base to add this offset. When that is done the
addresses passed into the mock regmap_bus will include this offset.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://patch.msgid.link/20260519135435.479949-2-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2026-05-19 14:59:52 +01:00
Richard Fitzgerald
ef0b4783af ASoC: cs35l56: KUnit tests for reading speaker ID from host GPIOs
Add test cases for the spk-id-gpios property used to read an integer
speaker ID value from a set of GPIO inputs.

There is a single parameterized test function,
cs35l56_shared_test_get_speaker_id_from_host_gpio() that does
the following:

- Create a mock GPIO driver to simulate real GPIO inputs.

- Create an array of struct software_node_ref_args to provide the
  content of the spk-id-gpios property. Each entry is a reference to
  a GPIO on the mock GPIO driver. The GPIO indexes are taken from test
  case parameterization.

- Create a software node containing the spk-id-gpios property and set
  this as the node of the pseudo codec driver device.

- Call cs35l56_get_speaker_id() and assert that the returned value
  matches the expected value defined in the test case parameterization.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://patch.msgid.link/20260304162402.1714759-4-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2026-03-05 15:22:48 +00:00
Richard Fitzgerald
72e1c47048 ASoC: cs35l56: Some KUnit testing of cs35l56_get_speaker_id()
Add some KUnit tests for cs35l56_get_speaker_id().
These only test the simpler cases of reading the speaker ID from
cs_amp_get_vendor_spkid() or the "cirrus,speaker-id" property.

The untested case is reading it from GPIOs, which would require
a dummy implementation of a GPIO driver.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://patch.msgid.link/20260304162402.1714759-3-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2026-03-05 15:22:47 +00:00
Richard Fitzgerald
9bca0f05ce 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: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://patch.msgid.link/20260205164838.1611295-3-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2026-02-05 16:58:12 +00:00