Skip to content
Merged
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
44 changes: 0 additions & 44 deletions drivers/gpu/drm/apple/audio-link-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
struct dcpaud_link_test {
bool link_on;
bool link_live;
bool typec;
/* The error removing the idle transfer returns */
int idle_remove_err;
u64 asked;
Expand Down Expand Up @@ -40,11 +39,6 @@ static bool dcpaud_link_test_live(struct device *dev)
return dcpaud_link_current->link_live;
}

static bool dcpaud_link_test_typec(struct device *dev)
{
return dcpaud_link_current->typec;
}

static int dcpaud_link_test_terminate(struct dma_chan *chan)
{
dcpaud_link_record('X');
Expand Down Expand Up @@ -147,7 +141,6 @@ static struct dcp_audio *dcpaud_link_setup(struct kunit *test, struct platform_d
kunit_activate_static_stub(test, dcp_audiosrv_link_on, dcpaud_link_test_on);
kunit_activate_static_stub(test, dcp_audiosrv_link_live, dcpaud_link_test_live);
kunit_activate_static_stub(test, dcp_audiosrv_link, dcpaud_link_test_call);
kunit_activate_static_stub(test, dcp_audiosrv_typec, dcpaud_link_test_typec);
return dcpaud;
}

Expand Down Expand Up @@ -451,42 +444,6 @@ static void dcpaud_close_keeps_held_silence(struct kunit *test)
pm_runtime_put_noidle(audio->dev);
}

static void dcpaud_link_test_hold_default(void *data)
{
WRITE_ONCE(hold_link, 1);
}

static void dcpaud_typec_stop_ends_stream(struct kunit *test)
{
struct platform_device *pdev;
struct dcp_audio *audio = dcpaud_link_setup(test, &pdev);
struct snd_pcm_substream *sub = dcpaud_link_test_open(test, audio);

KUNIT_ASSERT_EQ(test,
kunit_add_action_or_reset(test, dcpaud_link_test_hold_default, NULL), 0);
sub->runtime->channels = 2;
sub->runtime->dma_area = kunit_kzalloc(test, 64, GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, sub->runtime->dma_area);
sub->runtime->dma_bytes = 64;
dcpaud_link_current->typec = true;

/* USB-C by default: STOP ends the stream's DMA, no link is held */
audio->stream_dma = true;
pm_runtime_get_noresume(audio->dev);
KUNIT_ASSERT_EQ(test, dcp_pcm_native_trigger(sub, SNDRV_PCM_TRIGGER_STOP), 0);
KUNIT_EXPECT_STREQ(test, dcpaud_link_current->sequence, "X");
KUNIT_EXPECT_FALSE(test, audio->dma_cleared);
KUNIT_EXPECT_EQ(test, atomic_read(&audio->dev->power.usage_count), 0);

/* hold_link=2: the DMA plays the cleared buffer on for the held link */
WRITE_ONCE(hold_link, 2);
pm_runtime_get_noresume(audio->dev);
KUNIT_ASSERT_EQ(test, dcp_pcm_native_trigger(sub, SNDRV_PCM_TRIGGER_STOP), 0);
KUNIT_EXPECT_STREQ(test, dcpaud_link_current->sequence, "X");
KUNIT_EXPECT_TRUE(test, audio->dma_cleared);
pm_runtime_put_noidle(audio->dev);
}

static struct kunit_case dcpaud_link_cases[] = {
KUNIT_CASE(dcpaud_link_release_instance),
KUNIT_CASE(dcpaud_disconnect_sync_completes_live_owner),
Expand All @@ -499,7 +456,6 @@ static struct kunit_case dcpaud_link_cases[] = {
KUNIT_CASE(dcpaud_start_after_held_link_went),
KUNIT_CASE(dcpaud_failed_start_keeps_held_link),
KUNIT_CASE(dcpaud_close_keeps_held_silence),
KUNIT_CASE(dcpaud_typec_stop_ends_stream),
{}
};

Expand Down
42 changes: 11 additions & 31 deletions drivers/gpu/drm/apple/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,39 +655,19 @@ struct snd_pcm_ops dcp_playback_ops = {
* service itself is open while the PCM is, or while its link is held.
*/
/*
* The sink behind the J514S HDMI port (PS190 converter and TV) mutes the
* audio of a link that stops and starts again with an unchanged format,
* until the DP link trains again: only a different channel layout brings
* it back. So a stereo link, once started, is held between streams, as
* macOS holds it: silence follows the stopped stream's DMA and the link
* keeps running until the format changes or the display goes off
* The sinks behind the J514S HDMI port (PS190 converter and TV) and its
* Type-C ports mute the audio of a link that stops and starts again with an
* unchanged format, until the DP link trains again: only a different channel
* layout brings it back. So a stereo link, once started, is held between
* streams, as macOS holds it: silence follows the stopped stream's DMA and
* the link keeps running until the format changes or the display goes off
* (dcpaud_release_link()).
*
* The link must not run dry either: a gap of 20 ms in its samples mutes the
* sink the same way. The silence is the SIO channel's idle transfer, which
* the channel issues whenever no stream's DMA does, in descriptor order:
* a stream's DMA takes over from it and hands back to it without a gap.
*/
/*
* Read-only at runtime: a stream opened while it was lower keeps periods
* longer than a held link's synchronize allows for.
*/
static int hold_link = 1;
module_param(hold_link, int, 0444);
MODULE_PARM_DESC(hold_link,
"Hold started audio links between streams (silence): 0 never, 1 on the HDMI port (default), 2 also on USB-C");

/*
* The mute was measured behind the HDMI port. USB-C sinks keep one link per
* stream unless hold_link=2, until they have been qualified with this.
*/
static bool dcpaud_holds(struct dcp_audio *dcpaud)
{
int hold = READ_ONCE(hold_link);

return hold >= 2 || (hold == 1 && !dcp_audiosrv_typec(dcpaud->dcp_dev));
}

/*
* A change of sample rate or sample size with an unchanged channel layout
* replaces the link with a new one, which this sink mutes just as it does a
Expand Down Expand Up @@ -879,7 +859,7 @@ static int dcp_pcm_native_open(struct snd_pcm_substream *substream)
}

ret = dcp_pcm_open(substream);
if (!ret && live && !dcpaud->open_unplugged && dcpaud_holds(dcpaud)) {
if (!ret && live && !dcpaud->open_unplugged) {
ret = dcpaud_pin_rate_format(dcpaud, substream->runtime);
if (!ret)
ret = snd_pcm_hw_constraint_minmax(substream->runtime,
Expand Down Expand Up @@ -1043,8 +1023,8 @@ static int dcp_pcm_native_start(struct snd_pcm_substream *substream, int cmd)
/* The first link of the connection waits for the sink to settle. */
scoped_guard(mutex, &dcpaud->data_lock)
up_ms = ktime_ms_delta(ktime_get(), dcpaud->connected_at);
if (dcpaud_holds(dcpaud) && !READ_ONCE(dcpaud->link_started) &&
up_ms >= 0 && up_ms < DCPAUD_SINK_SETTLE_MS) {
if (!READ_ONCE(dcpaud->link_started) && up_ms >= 0 &&
up_ms < DCPAUD_SINK_SETTLE_MS) {
dev_dbg(dcpaud->dev, "sink up %lld ms, link waits\n", up_ms);
msleep(DCPAUD_SINK_SETTLE_MS - up_ms);
}
Expand Down Expand Up @@ -1117,8 +1097,8 @@ static int dcp_pcm_native_trigger(struct snd_pcm_substream *substream, int cmd)
* reference, until sync_stop hands over to the held link's
* silence: the link must not run dry meanwhile.
*/
if (dcpaud_holds(dcpaud) && READ_ONCE(dcpaud->stream_dma) &&
substream->runtime->channels == 2 && substream->runtime->dma_area) {
if (READ_ONCE(dcpaud->stream_dma) && substream->runtime->channels == 2 &&
substream->runtime->dma_area) {
memset(substream->runtime->dma_area, 0, substream->runtime->dma_bytes);
WRITE_ONCE(dcpaud->dma_cleared, true);
return 0;
Expand Down
2 changes: 0 additions & 2 deletions drivers/gpu/drm/apple/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ void dcpaud_release_link(struct platform_device *pdev, const u64 *gen);
bool dcp_audiosrv_link_on(struct device *dev, u64 gen);
/* The prepared link still belongs to the client of the published instance. */
bool dcp_audiosrv_link_live(struct device *dev);
/* The display processor drives a Type-C route rather than the HDMI port. */
bool dcp_audiosrv_typec(struct device *dev);
#endif

#endif /* __AUDIO_H__ */
6 changes: 0 additions & 6 deletions drivers/gpu/drm/apple/av.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,6 @@ bool dcp_audiosrv_link_live(struct device *dev)
return asrv->link_gen == asrv->open_gen && av_audiosrv_open_published(asrv);
}

bool dcp_audiosrv_typec(struct device *dev)
{
KUNIT_STATIC_STUB_REDIRECT(dcp_audiosrv_typec, dev);
return dcp_is_typec_output(dev_get_drvdata(dev));
}

/*
* The link commands of the 14.7 external role's audio service, the native
* audio driver's: prepare, start, stop and complete all take the selected
Expand Down
Loading