Skip to content

Commit b636ac7

Browse files
hoshinolinajannau
authored andcommitted
drm/apple: audio: Create a device link to the DMA device
This works even before the DMA device probes. Might help deal with runtime-pm ordering, though it doesn't solve the deferred ordering problem (since we're creating the link while already probing)... Signed-off-by: Asahi Lina <lina@asahilina.net>
1 parent 92400b7 commit b636ac7

1 file changed

Lines changed: 31 additions & 36 deletions

File tree

drivers/gpu/drm/apple/audio.c

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
struct dcp_audio {
3636
struct device *dev;
3737
struct device *dcp_dev;
38+
struct device *dma_dev;
39+
struct device_link *dma_link;
3840
struct dma_chan *chan;
3941
struct snd_card *card;
4042
struct snd_jack *jack;
@@ -588,40 +590,13 @@ void dcpaud_disconnect(struct platform_device *pdev)
588590
dcpaud_report_hotplug(dcpaud, false);
589591
}
590592

591-
static ssize_t probe_snd_card_store(struct device *dev,
592-
struct device_attribute *attr,
593-
const char *buf, size_t count)
594-
{
595-
int ret;
596-
bool connected = false;
597-
struct dcp_audio *dcpaud = dev_get_drvdata(dev);
598-
599-
mutex_lock(&dcpaud->data_lock);
600-
601-
if (!dcpaud->chan) {
602-
ret = dcpaud_init_snd_card(dcpaud);
603-
if (ret)
604-
goto out_unlock;
605-
606-
connected = dcpaud->dcp_connected;
607-
if (connected) {
608-
dcpaud_report_hotplug(dcpaud, connected);
609-
goto out;
610-
}
611-
}
612-
out_unlock:
613-
mutex_unlock(&dcpaud->data_lock);
614-
out:
615-
return count;
616-
}
617-
618-
static const DEVICE_ATTR_WO(probe_snd_card);
619-
620593
static int dcpaud_comp_bind(struct device *dev, struct device *main, void *data)
621594
{
622595
struct dcp_audio *dcpaud = dev_get_drvdata(dev);
623596
struct device_node *endpoint, *dcp_node = NULL;
624-
struct platform_device *dcp_pdev;
597+
struct platform_device *dcp_pdev, *dma_pdev;
598+
struct of_phandle_args dma_spec;
599+
int index;
625600
int ret;
626601

627602
/* find linked DCP instance */
@@ -636,6 +611,18 @@ static int dcpaud_comp_bind(struct device *dev, struct device *main, void *data)
636611
return 0;
637612
}
638613

614+
index = of_property_match_string(dev->of_node, "dma-names", "tx");
615+
if (index < 0) {
616+
dev_err(dev, "No dma-names property\n");
617+
return 0;
618+
}
619+
620+
if (of_parse_phandle_with_args(dev->of_node, "dmas", "#dma-cells", index,
621+
&dma_spec) || !dma_spec.np) {
622+
dev_err(dev, "Failed to parse dmas property\n");
623+
return 0;
624+
}
625+
639626
dcp_pdev = of_find_device_by_node(dcp_node);
640627
of_node_put(dcp_node);
641628
if (!dcp_pdev) {
@@ -644,12 +631,17 @@ static int dcpaud_comp_bind(struct device *dev, struct device *main, void *data)
644631
}
645632
dcpaud->dcp_dev = &dcp_pdev->dev;
646633

647-
dcpaud_expose_debugfs_blob(dcpaud, "selected_cookie", &dcpaud->selected_cookie,
648-
sizeof(dcpaud->selected_cookie));
649-
dcpaud_expose_debugfs_blob(dcpaud, "elements", dcpaud->elements,
650-
DCPAUD_ELEMENTS_MAXSIZE);
651-
dcpaud_expose_debugfs_blob(dcpaud, "product_attrs", dcpaud->productattrs,
652-
DCPAUD_PRODUCTATTRS_MAXSIZE);
634+
635+
dma_pdev = of_find_device_by_node(dma_spec.np);
636+
of_node_put(dma_spec.np);
637+
if (!dma_pdev) {
638+
dev_info(dev, "No DMA device\n");
639+
return 0;
640+
}
641+
dcpaud->dma_dev = &dma_pdev->dev;
642+
643+
dcpaud->dma_link = device_link_add(dev, dcpaud->dma_dev, DL_FLAG_PM_RUNTIME | DL_FLAG_RPM_ACTIVE |
644+
DL_FLAG_STATELESS);
653645

654646
mutex_lock(&dcpaud->data_lock);
655647
/* ignore errors to prevent audio issues affecting the display side */
@@ -670,6 +662,9 @@ static void dcpaud_comp_unbind(struct device *dev, struct device *main,
670662

671663
/* snd_card_free_when_closed() checks for NULL */
672664
snd_card_free_when_closed(dcpaud->card);
665+
666+
if (dcpaud->dma_link)
667+
device_link_del(dcpaud->dma_link);
673668
}
674669

675670
static const struct component_ops dcpaud_comp_ops = {

0 commit comments

Comments
 (0)