Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Documentation/devicetree/bindings/sound/ti,tas2770.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ description: |

allOf:
- $ref: dai-common.yaml#
- if:
properties:
compatible:
not:
contains:
const: ti,tas5770l
then:
properties:
apple,speaker-config: false

properties:
compatible:
Expand Down Expand Up @@ -45,6 +54,16 @@ properties:
interrupts:
maxItems: 1

apple,speaker-config:
$ref: /schemas/types.yaml#/definitions/uint8-array
minItems: 4
maxItems: 4
description:
This amplifier's speaker-config row from Apple's device tree, copied
by the bootloader. The second byte specifies the analog operating
gain. The other bytes are RX and sense slot selections in the source
format. Linux uses its own DAI and sense-slot properties for routing.

ti,imon-slot-no:
$ref: /schemas/types.yaml#/definitions/uint32
description: TDM TX current sense time slot.
Expand Down
58 changes: 37 additions & 21 deletions sound/soc/apple/macaudio-amp-level-test.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* KUnit tests of the SN012776 amp levels: each amp's level is the second byte
* KUnit tests of the SN012776 and TAS5770L amp levels: each amp's level is the second byte
* of its apple,speaker-config, which the boot loader copies from the Mac's
* ADT, and the speakers stay off when any amp lacks it, or under a fixed
* ceiling when any amp has another level than the ceiling was computed for.
Expand All @@ -22,7 +22,7 @@ static bool macaudio_level_test_present(struct kunit *test, struct device *dev,
const struct macaudio_platform_cfg *cfg,
const char *name)
{
return macaudio_sn012776_levels_present(dev, cfg, macaudio_level_test_node(test, name));
return macaudio_amp_level_count(dev, cfg, macaudio_level_test_node(test, name)) > 0;
}

/* The level is the row's second byte, its low five bits */
Expand Down Expand Up @@ -83,8 +83,16 @@ static void macaudio_levels_fixed_ceiling(struct kunit *test)
"macaudio-kunit-codec-good"));
KUNIT_EXPECT_FALSE(test, macaudio_level_test_present(test, dev, cfg,
"macaudio-kunit-codec-one-missing"));
KUNIT_EXPECT_FALSE(test, macaudio_sn012776_level_allowed(cfg, 14));
KUNIT_EXPECT_FALSE(test, macaudio_sn012776_level_allowed(cfg, 16));
KUNIT_EXPECT_FALSE(test, macaudio_amp_level_allowed(cfg, 14));
KUNIT_EXPECT_FALSE(test, macaudio_amp_level_allowed(cfg, 16));
}

static void macaudio_tas_level_from_row(struct kunit *test)
{
KUNIT_EXPECT_EQ(test, macaudio_tas5770_level(
macaudio_level_test_node(test, "macaudio-kunit-tas-a")), 4);
KUNIT_EXPECT_EQ(test, macaudio_tas5770_level(
macaudio_level_test_node(test, "macaudio-kunit-tas-b")), 14);
}

/* A v2-only SN012776 machine also requires DC-blocker config from the boot loader */
Expand All @@ -104,23 +112,29 @@ static void macaudio_levels_v2_only_requires_dcblocker(struct kunit *test)
"macaudio-kunit-codec-v2-no-dcblk"));
}

/* No board table carries an SN012776 gain any more */
static void macaudio_level_no_table(struct kunit *test)
static void macaudio_tas_level_rejects(struct kunit *test)
{
const struct macaudio_platform_cfg *cfgs[] = {
&macaudio_j180_cfg, &macaudio_j314_cfg, &macaudio_j316_cfg,
&macaudio_j37x_j47x_cfg, &macaudio_j413_cfg, &macaudio_j415_cfg,
&macaudio_j493_cfg, &macaudio_j575c_j773_cfg, &macaudio_j604_cfg,
&macaudio_j614_cfg, &macaudio_j616_cfg, &macaudio_j713_cfg,
&macaudio_j714_cfg, &macaudio_j715_cfg, &macaudio_j716_cfg,
&macaudio_j813_cfg, &macaudio_j775_cfg, &macaudio_j873_cfg,
};
unsigned int i;

for (i = 0; i < ARRAY_SIZE(cfgs); i++) {
KUNIT_EXPECT_EQ(test, cfgs[i]->amp, AMP_SN012776);
KUNIT_EXPECT_EQ(test, cfgs[i]->amp_gain, 0);
}
KUNIT_EXPECT_EQ(test, macaudio_tas5770_level(
macaudio_level_test_node(test, "macaudio-kunit-tas-zero")), -ERANGE);
KUNIT_EXPECT_EQ(test, macaudio_tas5770_level(
macaudio_level_test_node(test, "macaudio-kunit-tas-high")), -ERANGE);
KUNIT_EXPECT_EQ(test, macaudio_tas5770_level(
macaudio_level_test_node(test, "macaudio-kunit-tas-short")), -ENOENT);
KUNIT_EXPECT_EQ(test, macaudio_tas5770_level(
macaudio_level_test_node(test, "macaudio-kunit-tas-none")), -ENOENT);
}

static void macaudio_tas_levels_every_amp(struct kunit *test)
{
struct device *dev = kunit_kzalloc(test, sizeof(*dev), GFP_KERNEL);

KUNIT_ASSERT_NOT_NULL(test, dev);
KUNIT_EXPECT_TRUE(test, macaudio_level_test_present(test, dev, &macaudio_j313_cfg,
"macaudio-kunit-tas-codec-good"));
KUNIT_EXPECT_FALSE(test, macaudio_level_test_present(test, dev, &macaudio_j313_cfg,
"macaudio-kunit-tas-codec-missing"));
KUNIT_EXPECT_FALSE(test, macaudio_level_test_present(test, dev, &macaudio_j313_cfg,
"macaudio-kunit-tas-codec-wrong"));
}

static int macaudio_level_test_init(struct kunit *test)
Expand All @@ -133,8 +147,10 @@ static struct kunit_case macaudio_level_cases[] = {
KUNIT_CASE(macaudio_level_rejects),
KUNIT_CASE(macaudio_levels_every_amp),
KUNIT_CASE(macaudio_levels_fixed_ceiling),
KUNIT_CASE(macaudio_tas_level_from_row),
KUNIT_CASE(macaudio_tas_level_rejects),
KUNIT_CASE(macaudio_tas_levels_every_amp),
KUNIT_CASE(macaudio_levels_v2_only_requires_dcblocker),
KUNIT_CASE(macaudio_level_no_table),
{}
};

Expand Down
47 changes: 47 additions & 0 deletions sound/soc/apple/macaudio-kunit.dtso
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,53 @@
sound-dai = <&ma_amp_a>;
};

ma_tas_a: macaudio-kunit-tas-a {
compatible = "ti,tas5770l", "ti,tas2770";
#sound-dai-cells = <0>;
apple,speaker-config = [00 04 00 00];
};

ma_tas_b: macaudio-kunit-tas-b {
compatible = "ti,tas5770l", "ti,tas2770";
#sound-dai-cells = <0>;
apple,speaker-config = [01 0e 00 00];
};

ma_tas_zero: macaudio-kunit-tas-zero {
compatible = "ti,tas5770l", "ti,tas2770";
#sound-dai-cells = <0>;
apple,speaker-config = [00 00 00 00];
};

ma_tas_high: macaudio-kunit-tas-high {
compatible = "ti,tas5770l", "ti,tas2770";
#sound-dai-cells = <0>;
apple,speaker-config = [00 1f 00 00];
};

ma_tas_short: macaudio-kunit-tas-short {
compatible = "ti,tas5770l", "ti,tas2770";
#sound-dai-cells = <0>;
apple,speaker-config = [00 04 00];
};

ma_tas_none: macaudio-kunit-tas-none {
compatible = "ti,tas5770l", "ti,tas2770";
#sound-dai-cells = <0>;
};

macaudio-kunit-tas-codec-good {
sound-dai = <&ma_tas_a>, <&ma_tas_b>;
};

macaudio-kunit-tas-codec-missing {
sound-dai = <&ma_tas_a>, <&ma_tas_none>;
};

macaudio-kunit-tas-codec-wrong {
sound-dai = <&ma_tas_a>, <&ma_amp_a>;
};

macaudio-kunit-codec-v2-good {
sound-dai = <&ma_amp_dcblk_a>;
};
Expand Down
Loading
Loading